Version Description
- Move visual form styler to free version
- Added multiple emails to free version
- Added BCC, CC, and reply to options to emails
- Replaced the reCaptcha with the new no-captcha recaptcha
- Allow multiple roles to be selected for the permissions on the global settings page
- Updated the UI
- Added a trash can for forms as well as draft forms
- Extra security with sanitizing output and prepare database queries extra just to be sure
- Switch to frm_first frm_last frm_half classes for more flexibility
- Added more responsiveness to the styling classes
- Change the field width option from characters to pixels
- Change the user browser info into a more easily readable format, and include it in the lite version
- Add (hidden) legend tag for accessibility
- Fix preview page with 2015 theme
- Reduce duplicate entry check to 1 minute
- Remove a bunch of upgrade messages in the lite version
- Reduce size of indexed db columns for utf8mb4 in WordPress 4.2
- Pro: Added multiple form styling templates, more styling options, and updated the default styling
- Pro: Added repeatable fields and embedded forms
- Pro: Created form actions and consolidated notifications and add-ons
- Pro: All form actions can use conditional logic
- Pro: Added confirmation fields
- Pro: Added read-only radio and check box fields
- Pro: View pagination will automatically take on Genesis theme styling
- Pro: Entire sections can be moved and duplicated
- Pro: Add frm_repeat_start_rows filter to allow the form to start with multiple rows in a repeating section
- Pro: Make the query work for custom code returning a string query on the frm_where_filter hook for reverse compatibility
- Pro: Escape all quotes in CSV
- Pro: Don't require dynamic fields with no options
- Pro: Remove stray div in the calendar view
- Pro: Remove 'no files selected' text if files are selected
- Pro: Add decimal option to calculations
- Pro: Add starts with, ends with, and group by options in View filters
- Pro: Add IP option to view filters
- Pro: Added entry ID to view order options
- Pro: Added hooks: frm_selectable_dates, frm_main_feedback, frm_allowed_times, frm_view_order, frm_csv_headers, frm_map_csv_field
- Pro: Allow min or max in the graph shortcode to be equal to 0
- Pro: Keep users on current page when they click "Save Draft"
- Pro: Add pending for post status options in the post settings
- Pro: Include JS with form when editing in place
- Pro: Fix displaying stats accuracy with partial stars
- Pro: Enqueued scripts right before they are printed for easier integration with more popup plugins
- Pro: Allow slashes in Phone Number Format option
- Pro: Allow default templates to be deleted
- Pro: Reduce the baseline memory load
- Pro: Load the form styling on view pages when set to only load styling on applicable pages
- Pro: Change deletelink so it deletes with ajax
- Pro: Add [user_role] shortcode for current user's role
- Pro: Add read-only option to Dynamic fields
- Pro: Add single row and multiple row options to Dynamic Radio and Checkbox fields
- Pro: Allow arrays in View filters
- Pro: Allow drafts to be searched with the frm-search form
- Pro: Fix sql error when searching by Hebrew characters
- Pro: Allow the use of field keys in the frm-stats shortcode
- Pro: Force tooltip wrapping in graphs
- Pro: Improve frm_total class for number fields
- Lots of other small features, bug fixes, and code cleanup. Too many little features to list!
Download this release
Release Info
Developer | sswells |
Plugin | ![]() |
Version | 2.0 |
Comparing to | |
See all releases |
Code changes from version 1.07.11 to 2.0
- classes/controllers/FrmAppController.php +340 -371
- classes/controllers/FrmEntriesController.php +593 -368
- classes/controllers/FrmFieldsController.php +560 -382
- classes/controllers/FrmFormActionsController.php +355 -0
- classes/controllers/FrmFormsController.php +839 -580
- classes/controllers/FrmHooksController.php +200 -0
- classes/controllers/FrmSettingsController.php +41 -60
- classes/controllers/FrmStatisticsController.php +15 -27
- classes/controllers/FrmStylesController.php +434 -0
- classes/controllers/FrmXMLController.php +188 -220
- classes/helpers/FrmAppHelper.php +1497 -602
- classes/helpers/FrmEntriesHelper.php +664 -134
- classes/helpers/FrmEntriesListHelper.php +264 -0
- classes/helpers/FrmFieldsHelper.php +1001 -333
- classes/helpers/FrmFormActionsHelper.php +107 -0
- classes/helpers/FrmFormsHelper.php +480 -189
- classes/helpers/FrmFormsListHelper.php +370 -0
- classes/helpers/FrmListHelper.php +9 -206
- classes/helpers/FrmStylesHelper.php +193 -0
- classes/helpers/FrmXMLHelper.php +806 -118
- classes/models/FrmDb.php +543 -207
- classes/models/FrmEntry.php +569 -337
- classes/models/FrmEntryMeta.php +258 -180
- classes/models/FrmField.php +359 -175
- classes/models/FrmForm.php +392 -176
- classes/models/FrmFormAction.php +529 -0
- classes/models/FrmNotification.php +344 -92
- classes/models/FrmSettings.php +186 -94
- classes/models/FrmStyle.php +437 -0
- classes/recaptchalib.php +0 -274
- classes/views/frm-entries/_sidebar-shared-pub.php +21 -0
- classes/views/frm-entries/direct.php +7 -11
- classes/views/frm-entries/errors.php +42 -31
- classes/views/frm-entries/form.php +30 -33
- classes/views/frm-entries/frm-entry.php +0 -52
- classes/views/frm-entries/list.php +29 -26
- classes/views/frm-entries/new.php +8 -8
- classes/views/frm-entries/no_entries.php +17 -47
- classes/views/frm-entries/show.php +74 -0
- classes/views/frm-entries/sidebar-shared.php +84 -0
- classes/views/frm-entries/sidebar-show.php +38 -0
- classes/views/frm-fields/import_choices.php +30 -58
- classes/views/frm-fields/input.php +114 -65
- classes/views/frm-fields/radio.php +19 -9
- classes/views/frm-fields/show-build.php +64 -0
- classes/views/frm-fields/show.php +4 -1
- classes/views/frm-fields/single-option.php +11 -15
- classes/views/frm-form-actions/_action_inside.php +57 -0
- classes/views/frm-form-actions/_email_settings.php +64 -0
- classes/views/frm-form-actions/default_actions.php +65 -0
- classes/views/frm-form-actions/email_action.php +40 -0
- classes/views/frm-form-actions/form_action.php +40 -0
- classes/views/frm-forms/_publish_box.php +110 -0
- classes/views/frm-forms/add_field.php +252 -233
- classes/views/frm-forms/add_field_links.php +150 -104
- classes/views/frm-forms/default-templates.php +0 -47
- classes/views/frm-forms/edit.php +26 -31
- classes/views/frm-forms/form.php +42 -14
- classes/views/frm-forms/insert_form_popup.php +46 -66
- classes/views/frm-forms/list.php +18 -11
- classes/views/frm-forms/mb_html_tab.php +30 -31
- classes/views/frm-forms/mb_insert_fields.php +4 -20
- classes/views/frm-forms/new-field-js.php +1 -1
- classes/views/frm-forms/new-selection.php +0 -56
- classes/views/frm-forms/new.php +20 -35
- classes/views/frm-forms/notification.php +0 -94
- classes/views/frm-forms/settings.php +189 -129
- classes/views/frm-forms/shortcode_opts.php +41 -0
- classes/views/frm-forms/sidebar-settings.php +9 -31
- classes/views/frm-settings/form.php +121 -112
- classes/views/frm-settings/license_box.php +6 -6
- classes/views/frm-settings/styling_tab.php +0 -4
- classes/views/frm-statistics/list.php +11 -9
- classes/views/frm-statistics/list_displays.php +8 -7
classes/controllers/FrmAppController.php
CHANGED
@@ -1,482 +1,451 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
|
14 |
-
add_filter('plugin_action_links_formidable/formidable.php', 'FrmAppController::settings_link', 10, 2 );
|
15 |
-
add_filter('update_plugin_complete_actions', 'FrmAppController::update_action_links', 10, 2 );
|
16 |
-
add_action('admin_notices', 'FrmAppController::pro_get_started_headline');
|
17 |
-
add_filter('the_content', 'FrmAppController::page_route', 10);
|
18 |
-
add_action('plugins_loaded', 'FrmAppController::load_lang');
|
19 |
-
add_action('init', 'FrmAppController::front_head');
|
20 |
-
add_action('wp_footer', 'FrmAppController::footer_js', 1, 0);
|
21 |
-
add_action('admin_init', 'FrmAppController::admin_js', 11);
|
22 |
-
register_activation_hook(FrmAppHelper::plugin_path().'/formidable.php', 'FrmAppController::install');
|
23 |
-
add_action('wp_ajax_frm_install', 'FrmAppController::install');
|
24 |
-
add_action('wp_ajax_frm_uninstall', 'FrmAppController::uninstall');
|
25 |
-
add_action('wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize');
|
26 |
-
|
27 |
-
// Used to process standalone requests
|
28 |
-
add_action('init', 'FrmAppController::parse_standalone_request', 40);
|
29 |
-
// Update the session data
|
30 |
-
add_action('init', 'FrmAppController::referer_session', 1);
|
31 |
-
}
|
32 |
-
|
33 |
-
public static function menu(){
|
34 |
-
global $frm_vars, $frm_settings;
|
35 |
-
|
36 |
-
if ( current_user_can('administrator') && !current_user_can('frm_view_forms') ) {
|
37 |
-
global $current_user;
|
38 |
-
$frm_roles = FrmAppHelper::frm_capabilities();
|
39 |
-
foreach($frm_roles as $frm_role => $frm_role_description)
|
40 |
-
$current_user->add_cap( $frm_role );
|
41 |
-
unset($frm_roles);
|
42 |
-
unset($frm_role);
|
43 |
-
unset($frm_role_description);
|
44 |
-
}
|
45 |
-
|
46 |
-
$count = count(get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ));
|
47 |
-
$pos = ((int)$count > 0) ? '22.7' : '29.3';
|
48 |
-
$pos = apply_filters('frm_menu_position', $pos);
|
49 |
-
|
50 |
-
if(current_user_can('frm_view_forms')){
|
51 |
-
add_menu_page('Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos);
|
52 |
-
}else if(current_user_can('frm_view_entries') and $frm_vars['pro_is_installed']){
|
53 |
-
add_menu_page('Formidable', $frm_settings->menu, 'frm_view_entries', 'formidable', 'FrmProEntriesController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos);
|
54 |
}
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
58 |
-
|
59 |
-
public static function load_wp_admin_style(){
|
60 |
-
wp_enqueue_style( 'frm_fonts', FrmAppHelper::plugin_url() .'/css/frm_fonts.css', array(), FrmAppHelper::plugin_version());
|
61 |
}
|
62 |
-
|
63 |
-
public static function get_form_nav($
|
64 |
global $pagenow, $frm_vars;
|
65 |
-
|
66 |
-
$show_nav = FrmAppHelper::get_param('show_nav', $show_nav);
|
67 |
-
if(
|
68 |
return;
|
69 |
-
|
70 |
-
$current_page = (isset($_GET['page'])) ? $_GET['page'] : (isset($_GET['post_type']) ? $_GET['post_type'] : 'None');
|
71 |
-
if($id and is_numeric($id)){
|
72 |
-
$frm_form = new FrmForm();
|
73 |
-
$form = $frm_form->getOne($id);
|
74 |
-
unset($frm_form);
|
75 |
-
}else{
|
76 |
-
$form = false;
|
77 |
}
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
include(FrmAppHelper::plugin_path() .'/classes/views/shared/form-nav.php');
|
80 |
}
|
81 |
|
82 |
// Adds a settings link to the plugins page
|
83 |
-
public static function settings_link($links
|
84 |
-
$settings = '<a href="'. admin_url('admin.php?page=formidable-settings') .'">' . __('Settings', 'formidable') . '</a>';
|
85 |
-
array_unshift($links, $settings);
|
86 |
-
|
87 |
return $links;
|
88 |
}
|
89 |
-
|
90 |
public static function update_action_links( $actions, $plugin ) {
|
91 |
-
|
92 |
-
if (
|
93 |
return $actions;
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
$
|
98 |
-
|
99 |
-
|
100 |
if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
|
101 |
-
(
|
102 |
-
|
103 |
-
return
|
104 |
-
|
105 |
-
} else {
|
106 |
-
return $actions;
|
107 |
}
|
|
|
|
|
108 |
}
|
109 |
|
110 |
-
public static function pro_get_started_headline(){
|
111 |
-
|
112 |
self::install();
|
113 |
?>
|
114 |
-
<div id="message" class="frm_message updated"><?php _e('Congratulations! Formidable is ready to roll.', 'formidable') ?></div>
|
115 |
<?php
|
116 |
return;
|
117 |
}
|
118 |
-
|
119 |
// Don't display this error as we're upgrading the thing... cmon
|
120 |
-
if(
|
121 |
return;
|
122 |
-
|
123 |
-
|
|
|
124 |
return;
|
125 |
}
|
126 |
-
|
127 |
-
if(!isset($_GET['activate'])){
|
128 |
-
|
129 |
-
$
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
?>
|
134 |
-
<div class="error" id="frm_install_message"
|
135 |
-
<script type="text/javascript">
|
136 |
-
jQuery(document).ready(function($){ $('#frm_install_link').click(frm_install_now); });
|
137 |
-
function frm_install_now(){
|
138 |
-
jQuery('#frm_install_message').html('<div style="line-height:24px;"><?php _e("Please wait while your site updates.", "formidable") ?><div class="spinner frm_spinner" style="float:left;display:block;"></div></div>');
|
139 |
-
jQuery.ajax({
|
140 |
-
type:"POST",url:ajaxurl,data:"action=frm_install",
|
141 |
-
success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
|
142 |
-
});
|
143 |
-
}
|
144 |
-
</script>
|
145 |
<?php
|
146 |
}
|
147 |
}
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
150 |
// user is authorized, but running free version
|
151 |
$inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
|
152 |
?>
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
</script>
|
165 |
-
<?php
|
166 |
}
|
167 |
}
|
168 |
-
|
169 |
-
public static function admin_js(){
|
170 |
global $pagenow;
|
171 |
-
|
172 |
-
|
|
|
173 |
return;
|
174 |
}
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
add_thickbox();
|
196 |
-
|
197 |
-
wp_register_script('formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array('jquery'), '2.3.0');
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
$post = get_post($_REQUEST['post']);
|
206 |
-
if(!$post)
|
207 |
return;
|
|
|
208 |
$post_type = $post->post_type;
|
209 |
-
}else{
|
210 |
return;
|
211 |
}
|
212 |
-
|
213 |
-
if($post_type == 'frm_display'){
|
214 |
-
|
215 |
-
wp_enqueue_script('
|
216 |
-
|
217 |
-
|
218 |
-
self::localize_script('admin');
|
219 |
}
|
|
|
|
|
220 |
}
|
221 |
}
|
222 |
-
|
223 |
-
public static function admin_body_class($classes){
|
224 |
global $wp_version;
|
225 |
-
|
226 |
//we only need this class on Formidable pages
|
227 |
-
if(version_compare( $wp_version, '3.4.9', '>'))
|
228 |
$classes .= ' frm_35_trigger';
|
229 |
-
|
|
|
230 |
return $classes;
|
231 |
}
|
232 |
-
|
233 |
-
public static function wp_admin_body_class($classes){
|
234 |
global $wp_version;
|
235 |
//we need this class everywhere in the admin for the menu
|
236 |
-
if(version_compare( $wp_version, '3.7.2', '>'))
|
237 |
$classes .= ' frm_38_trigger';
|
238 |
-
|
|
|
239 |
return $classes;
|
240 |
}
|
241 |
-
|
242 |
-
public static function load_lang(){
|
243 |
-
load_plugin_textdomain('formidable', false, '
|
244 |
}
|
245 |
-
|
246 |
-
public static function front_head(){
|
247 |
-
global $frm_settings;
|
248 |
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) ||
|
254 |
-
(
|
255 |
-
self::install($old_db_version);
|
256 |
}
|
257 |
}
|
258 |
-
|
259 |
$version = FrmAppHelper::plugin_version();
|
260 |
-
wp_register_script('formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array('jquery'), $version, true);
|
261 |
-
wp_register_script('jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array('jquery'), '2.0.7', true);
|
262 |
-
|
263 |
-
|
264 |
-
if ( is_admin() && !defined('DOING_AJAX') ) {
|
265 |
// don't load this in back-end
|
266 |
return;
|
267 |
}
|
268 |
-
|
269 |
-
self::localize_script('front');
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
$style = apply_filters('get_frm_stylesheet',
|
274 |
-
if($style){
|
275 |
-
foreach((array)$style as $k => $file){
|
276 |
-
wp_register_style($k, $file, array(), $version);
|
277 |
if ( 'all' == $frm_settings->load_style ) {
|
278 |
-
wp_enqueue_style($k);
|
279 |
}
|
280 |
-
unset($k, $file);
|
281 |
}
|
282 |
}
|
283 |
-
unset($style);
|
284 |
-
|
285 |
-
if ( $frm_settings->load_style == 'all' ) {
|
286 |
global $frm_vars;
|
287 |
$frm_vars['css_loaded'] = true;
|
288 |
}
|
289 |
}
|
290 |
-
|
291 |
-
|
|
|
|
|
|
|
292 |
wp_localize_script('formidable', 'frm_js', array(
|
293 |
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
294 |
'images_url' => FrmAppHelper::plugin_url() .'/images',
|
295 |
-
'loading' => __('Loading…'),
|
296 |
-
'remove' => __('Remove', 'formidable'),
|
297 |
-
'offset' => apply_filters('frm_scroll_offset', 4),
|
|
|
|
|
298 |
));
|
299 |
-
|
300 |
-
if($location == 'admin'){
|
301 |
-
|
302 |
wp_localize_script('formidable_admin', 'frm_admin_js', array(
|
303 |
-
'confirm_uninstall' => __('Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable'),
|
304 |
-
'
|
305 |
-
'
|
306 |
-
'
|
307 |
-
'saving' => esc_attr(__('Saving', 'formidable')),
|
308 |
-
'saved' => esc_attr(__('Saved', 'formidable')),
|
309 |
-
'ok' => __('OK'),
|
310 |
-
'cancel' => __('Cancel', 'formidable'),
|
311 |
-
'
|
312 |
-
'
|
313 |
-
'
|
314 |
-
'
|
315 |
-
'
|
316 |
-
'confirm' => __('Are you sure?', 'formidable'),
|
|
|
|
|
|
|
317 |
'default_unique' => $frm_settings->unique_msg,
|
318 |
-
'
|
319 |
-
'
|
320 |
-
'
|
321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
}
|
323 |
}
|
324 |
-
|
325 |
-
public static function footer_js($location='footer'){
|
326 |
-
global $frm_settings, $frm_vars;
|
327 |
-
|
328 |
-
if($frm_vars['load_css'] and (!is_admin() or defined('DOING_AJAX')) and ($frm_settings->load_style != 'none')){
|
329 |
-
if(isset($frm_vars['css_loaded']) && $frm_vars['css_loaded'])
|
330 |
-
$css = apply_filters('get_frm_stylesheet', array());
|
331 |
-
else
|
332 |
-
$css = apply_filters('get_frm_stylesheet', array('frm-forms' => FrmAppHelper::plugin_url() .'/css/frm_display.css'));
|
333 |
-
|
334 |
-
if(!empty($css)){
|
335 |
-
echo "\n".'<script type="text/javascript">';
|
336 |
-
foreach((array)$css as $css_key => $file){
|
337 |
-
echo 'jQuery("head").append(unescape("%3Clink rel=\'stylesheet\' id=\''. ($css_key + (isset($frm_vars['css_loaded']) ? $frm_vars['css_loaded'] : false)) .'-css\' href=\''. $file. '\' type=\'text/css\' media=\'all\' /%3E"));';
|
338 |
-
//wp_enqueue_style($css_key);
|
339 |
-
unset($css_key);
|
340 |
-
unset($file);
|
341 |
-
}
|
342 |
-
unset($css);
|
343 |
|
344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
}
|
346 |
}
|
347 |
|
348 |
-
if(
|
349 |
-
|
|
|
|
|
|
|
350 |
}
|
351 |
-
|
352 |
-
public static function
|
353 |
-
|
354 |
-
|
|
|
|
|
355 |
}
|
356 |
-
|
357 |
-
public static function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
check_ajax_referer( 'frm_ajax', 'nonce' );
|
359 |
-
|
360 |
-
if ( current_user_can('administrator') ) {
|
361 |
-
|
362 |
$frmdb->uninstall();
|
363 |
echo true;
|
364 |
} else {
|
365 |
-
|
366 |
-
wp_die($frm_settings->admin_permission);
|
367 |
}
|
368 |
-
|
369 |
}
|
370 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
// Routes for wordpress pages -- we're just replacing content here folks.
|
372 |
-
public static function page_route($content){
|
373 |
-
global $post
|
374 |
|
375 |
-
|
|
|
376 |
$content = FrmFormsController::page_preview();
|
377 |
}
|
378 |
|
379 |
return $content;
|
380 |
}
|
381 |
-
|
382 |
-
public static function
|
383 |
-
|
384 |
-
|
385 |
-
if ( !isset($frm_settings->track) || !$frm_settings->track || defined('WP_IMPORTING') ) {
|
386 |
-
return;
|
387 |
-
}
|
388 |
-
|
389 |
-
// keep the page history below 100
|
390 |
-
$max = 100;
|
391 |
-
|
392 |
-
if ( !isset($_SESSION) )
|
393 |
-
session_start();
|
394 |
-
|
395 |
-
if ( !isset($_SESSION['frm_http_pages']) or !is_array($_SESSION['frm_http_pages']) )
|
396 |
-
$_SESSION['frm_http_pages'] = array("http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']);
|
397 |
-
|
398 |
-
if ( !isset($_SESSION['frm_http_referer']) or !is_array($_SESSION['frm_http_referer']) )
|
399 |
-
$_SESSION['frm_http_referer'] = array();
|
400 |
-
|
401 |
-
if (!isset($_SERVER['HTTP_REFERER']) or (isset($_SERVER['HTTP_REFERER']) and (strpos($_SERVER['HTTP_REFERER'], FrmAppHelper::site_url()) === false) and ! (in_array($_SERVER['HTTP_REFERER'], $_SESSION['frm_http_referer'])) )) {
|
402 |
-
if (! isset($_SERVER['HTTP_REFERER'])){
|
403 |
-
$direct = __('Type-in or bookmark', 'formidable');
|
404 |
-
if(!in_array($direct, $_SESSION['frm_http_referer']))
|
405 |
-
$_SESSION['frm_http_referer'][] = $direct;
|
406 |
-
}else{
|
407 |
-
$_SESSION['frm_http_referer'][] = $_SERVER['HTTP_REFERER'];
|
408 |
-
}
|
409 |
-
}
|
410 |
-
|
411 |
-
if ($_SESSION['frm_http_pages'] and !empty($_SESSION['frm_http_pages']) and (end($_SESSION['frm_http_pages']) != "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']))
|
412 |
-
$_SESSION['frm_http_pages'][] = "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'];
|
413 |
-
|
414 |
-
//keep the page history below the max
|
415 |
-
if(count($_SESSION['frm_http_pages']) > $max){
|
416 |
-
foreach($_SESSION['frm_http_pages'] as $pkey => $ppage){
|
417 |
-
if(count($_SESSION['frm_http_pages']) <= $max)
|
418 |
-
break;
|
419 |
-
|
420 |
-
unset($_SESSION['frm_http_pages'][$pkey]);
|
421 |
-
}
|
422 |
-
}
|
423 |
}
|
424 |
|
425 |
-
public static function
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
if($controller == 'forms')
|
435 |
-
FrmFormsController::preview(FrmAppHelper::get_param('form'));
|
436 |
-
else
|
437 |
-
do_action('frm_standalone_route', $controller, $action);
|
438 |
-
|
439 |
-
do_action('frm_ajax_'. $controller .'_'. $action);
|
440 |
-
die();
|
441 |
-
}
|
442 |
}
|
443 |
-
|
444 |
//formidable shortcode
|
445 |
-
public static function get_form_shortcode($atts){
|
446 |
_deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
|
447 |
-
return FrmFormsController::get_form_shortcode($atts);
|
448 |
}
|
449 |
|
450 |
-
public static function
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
public static function update_message($features){
|
455 |
-
include(FrmAppHelper::plugin_path() .'/classes/views/shared/update_message.php');
|
456 |
-
}
|
457 |
-
|
458 |
-
public static function get_postbox_class(){
|
459 |
-
if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
|
460 |
-
return 'postbox-container';
|
461 |
-
else
|
462 |
-
return 'inner-sidebar';
|
463 |
-
}
|
464 |
-
|
465 |
-
public static function pro_is_installed(){
|
466 |
-
return file_exists(FrmAppHelper::plugin_path() . '/pro/formidable-pro.php');
|
467 |
-
}
|
468 |
-
|
469 |
-
public static function pro_is_authorized(){
|
470 |
-
return get_site_option('frmpro-authorized');
|
471 |
-
}
|
472 |
-
|
473 |
-
public static function deauthorize(){
|
474 |
-
check_ajax_referer( 'frm_ajax', 'nonce' );
|
475 |
-
|
476 |
-
delete_option('frmpro-credentials');
|
477 |
-
delete_option('frmpro-authorized');
|
478 |
-
delete_site_option('frmpro-credentials');
|
479 |
-
delete_site_option('frmpro-authorized');
|
480 |
-
die();
|
481 |
}
|
482 |
}
|
1 |
<?php
|
2 |
+
|
3 |
+
class FrmAppController {
|
4 |
+
|
5 |
+
public static function menu() {
|
6 |
+
add_filter( 'plugin_action_links_'. FrmAppHelper::plugin_folder() .'/formidable.php', 'FrmAppController::settings_link' );
|
7 |
+
add_filter( 'admin_body_class', 'FrmAppController::wp_admin_body_class' );
|
8 |
+
|
9 |
+
FrmAppHelper::maybe_add_permissions();
|
10 |
+
|
11 |
+
if ( ! current_user_can( 'frm_view_forms' ) ) {
|
12 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
}
|
14 |
+
|
15 |
+
$count = count( get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ) );
|
16 |
+
$pos = ( (int) $count > 0 ) ? '22.7' : '29.3';
|
17 |
+
$pos = apply_filters( 'frm_menu_position', $pos );
|
18 |
+
|
19 |
+
$frm_settings = FrmAppHelper::get_settings();
|
20 |
+
add_menu_page( 'Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos );
|
21 |
}
|
22 |
+
|
23 |
+
public static function load_wp_admin_style() {
|
24 |
+
wp_enqueue_style( 'frm_fonts', FrmAppHelper::plugin_url() .'/css/frm_fonts.css', array(), FrmAppHelper::plugin_version() );
|
25 |
}
|
26 |
+
|
27 |
+
public static function get_form_nav( $form, $show_nav = '', $title = 'show' ) {
|
28 |
global $pagenow, $frm_vars;
|
29 |
+
|
30 |
+
$show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav );
|
31 |
+
if ( empty($show_nav) ) {
|
32 |
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
}
|
34 |
+
|
35 |
+
$current_page = isset( $_GET['page'] ) ? FrmAppHelper::simple_get( 'page', 'sanitize_title' ) : ( isset( $_GET['post_type'] ) ? FrmAppHelper::simple_get( 'post_type', 'sanitize_title' ) : 'None' );
|
36 |
+
|
37 |
+
if ( $form ) {
|
38 |
+
FrmFormsHelper::maybe_get_form( $form );
|
39 |
+
|
40 |
+
if ( is_object( $form ) ) {
|
41 |
+
$id = $form->id;
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
if ( ! isset($id) ) {
|
46 |
+
$form = $id = false;
|
47 |
+
}
|
48 |
+
|
49 |
include(FrmAppHelper::plugin_path() .'/classes/views/shared/form-nav.php');
|
50 |
}
|
51 |
|
52 |
// Adds a settings link to the plugins page
|
53 |
+
public static function settings_link($links) {
|
54 |
+
$settings = '<a href="'. admin_url( 'admin.php?page=formidable-settings' ) .'">' . __( 'Settings', 'formidable' ) . '</a>';
|
55 |
+
array_unshift( $links, $settings );
|
56 |
+
|
57 |
return $links;
|
58 |
}
|
59 |
+
|
60 |
public static function update_action_links( $actions, $plugin ) {
|
61 |
+
$frm_plugin = FrmAppHelper::plugin_folder() .'/formidable.php';
|
62 |
+
if ( $frm_plugin != $plugin ) {
|
63 |
return $actions;
|
64 |
+
}
|
65 |
+
|
66 |
+
$db_version = get_option( 'frm_db_version' );
|
67 |
+
$pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
|
68 |
+
|
|
|
69 |
if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
|
70 |
+
( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
|
71 |
+
|
72 |
+
return '<a href="'. add_query_arg( array( 'upgraded' => 'true' ), menu_page_url( 'formidable', 0 ) ) .'">'. __( 'Click here to complete the upgrade', 'formidable' ) .'</a>';
|
73 |
+
|
|
|
|
|
74 |
}
|
75 |
+
|
76 |
+
return $actions;
|
77 |
}
|
78 |
|
79 |
+
public static function pro_get_started_headline() {
|
80 |
+
if ( FrmAppHelper::is_admin_page( 'formidable' ) && isset( $_REQUEST['upgraded'] ) && 'true' == sanitize_title( $_REQUEST['upgraded'] ) ) {
|
81 |
self::install();
|
82 |
?>
|
83 |
+
<div id="message" class="frm_message updated"><?php _e( 'Congratulations! Formidable is ready to roll.', 'formidable' ) ?></div>
|
84 |
<?php
|
85 |
return;
|
86 |
}
|
87 |
+
|
88 |
// Don't display this error as we're upgrading the thing... cmon
|
89 |
+
if ( 'upgrade-plugin' == FrmAppHelper::simple_get( 'action', 'sanitize_title' ) ) {
|
90 |
return;
|
91 |
+
}
|
92 |
+
|
93 |
+
if ( is_multisite() && ! current_user_can( 'administrator' ) ) {
|
94 |
return;
|
95 |
}
|
96 |
+
|
97 |
+
if ( ! isset($_GET['activate']) ) {
|
98 |
+
$db_version = (int) get_option( 'frm_db_version' );
|
99 |
+
$pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
|
100 |
+
$needs_update = ( ( $db_version < FrmAppHelper::$db_version ) || ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < FrmAppHelper::$pro_db_version ) );
|
101 |
+
|
102 |
+
if ( $needs_update ) {
|
103 |
+
FrmAppHelper::load_admin_wide_js();
|
104 |
+
|
105 |
+
$message = FrmAppHelper::kses( __( 'Your update is not complete yet.<br/>Please deactivate and reactivate the plugin to complete the update or %1$s', 'formidable' ), array( 'br' ) );
|
106 |
+
$message = sprintf( $message, '<a href="#" id="frm_install_link">' . FrmAppHelper::kses( __( 'Update Now', 'formidable' ) ) . '</a>' );
|
107 |
+
if ( FrmAppHelper::$db_version >= 21 && $db_version > 1 && $db_version < 21 ) {
|
108 |
+
// if we are moving through #21, show the 2.0 message
|
109 |
+
$message .= '<br/> There are a few things you should know about 2.0. <a href="https://formidablepro.com/things-to-know-about-2-0/">Read more</a>';
|
110 |
+
}
|
111 |
?>
|
112 |
+
<div class="error" id="frm_install_message"><?php echo $message; ?> </div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
<?php
|
114 |
}
|
115 |
}
|
116 |
+
|
117 |
+
global $frm_vars;
|
118 |
+
if ( $frm_vars['pro_is_authorized'] && ! file_exists( FrmAppHelper::plugin_path() . '/pro/formidable-pro.php' ) ) {
|
119 |
+
FrmAppHelper::load_admin_wide_js();
|
120 |
+
|
121 |
// user is authorized, but running free version
|
122 |
$inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
|
123 |
?>
|
124 |
+
<div class="error" class="frm_previous_install">
|
125 |
+
<?php
|
126 |
+
echo wp_kses_post( apply_filters( 'frm_pro_update_msg',
|
127 |
+
sprintf(
|
128 |
+
__( 'This site has been previously authorized to run Formidable Forms.<br/>%1$sInstall the pro version%2$s or %3$sdeauthorize%4$s this site to continue running the free version and remove this message.', 'formidable' ),
|
129 |
+
'<a href="' . esc_url( $inst_install_url ) . '" target="_blank">', '</a>',
|
130 |
+
'<a href="#" class="frm_deauthorize_link">', '</a>'
|
131 |
+
), esc_url( $inst_install_url )
|
132 |
+
) ); ?>
|
133 |
+
</div>
|
134 |
+
<?php
|
|
|
|
|
135 |
}
|
136 |
}
|
137 |
+
|
138 |
+
public static function admin_js() {
|
139 |
global $pagenow;
|
140 |
+
|
141 |
+
$action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
|
142 |
+
if ( 'admin-ajax.php' == $pagenow && $action != 'frm_import_choices' ) {
|
143 |
return;
|
144 |
}
|
145 |
+
unset( $action );
|
146 |
+
|
147 |
+
$version = FrmAppHelper::plugin_version();
|
148 |
+
FrmAppHelper::load_admin_wide_js( false );
|
149 |
+
|
150 |
+
wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array(
|
151 |
+
'formidable_admin_global', 'formidable', 'jquery',
|
152 |
+
'jquery-ui-core', 'jquery-ui-draggable',
|
153 |
+
'jquery-ui-sortable',
|
154 |
+
'bootstrap_tooltip', 'bootstrap-multiselect',
|
155 |
+
), $version, true );
|
156 |
+
wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version );
|
157 |
+
wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array( 'jquery' ), '3.3.2' );
|
158 |
+
|
159 |
+
// load multselect js
|
160 |
+
wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() .'/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip' ), '0.9.8', true );
|
161 |
+
|
162 |
+
$page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
|
163 |
+
$post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
|
164 |
+
if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow == 'edit.php' && $post_type == 'frm_display' ) ) {
|
165 |
+
add_filter( 'admin_body_class', 'FrmAppController::admin_body_class' );
|
166 |
+
|
167 |
+
wp_enqueue_script( 'admin-widgets' );
|
168 |
+
wp_enqueue_style( 'widgets' );
|
169 |
+
wp_enqueue_script( 'formidable' );
|
170 |
+
wp_enqueue_script( 'formidable_admin' );
|
171 |
+
self::localize_script( 'admin' );
|
172 |
+
|
173 |
+
wp_enqueue_style( 'formidable-admin' );
|
174 |
add_thickbox();
|
175 |
+
|
176 |
+
wp_register_script( 'formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array( 'jquery' ), '2.3.0' );
|
177 |
+
|
178 |
+
} else if ( $pagenow == 'post.php' || ( $pagenow == 'post-new.php' && $post_type == 'frm_display' ) ) {
|
179 |
+
if ( isset($_REQUEST['post_type']) ) {
|
180 |
+
$post_type = sanitize_title( $_REQUEST['post_type'] );
|
181 |
+
} else if ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
|
182 |
+
$post = get_post( absint( $_REQUEST['post'] ) );
|
183 |
+
if ( ! $post ) {
|
|
|
|
|
184 |
return;
|
185 |
+
}
|
186 |
$post_type = $post->post_type;
|
187 |
+
} else {
|
188 |
return;
|
189 |
}
|
190 |
+
|
191 |
+
if ( $post_type == 'frm_display' ) {
|
192 |
+
wp_enqueue_script( 'jquery-ui-draggable' );
|
193 |
+
wp_enqueue_script( 'formidable_admin' );
|
194 |
+
wp_enqueue_style( 'formidable-admin' );
|
195 |
+
self::localize_script( 'admin' );
|
|
|
196 |
}
|
197 |
+
} else if ( $pagenow == 'widgets.php' ) {
|
198 |
+
FrmAppHelper::load_admin_wide_js();
|
199 |
}
|
200 |
}
|
201 |
+
|
202 |
+
public static function admin_body_class( $classes ) {
|
203 |
global $wp_version;
|
204 |
+
|
205 |
//we only need this class on Formidable pages
|
206 |
+
if ( version_compare( $wp_version, '3.4.9', '>' ) ) {
|
207 |
$classes .= ' frm_35_trigger';
|
208 |
+
}
|
209 |
+
|
210 |
return $classes;
|
211 |
}
|
212 |
+
|
213 |
+
public static function wp_admin_body_class( $classes ) {
|
214 |
global $wp_version;
|
215 |
//we need this class everywhere in the admin for the menu
|
216 |
+
if ( version_compare( $wp_version, '3.7.2', '>' ) ) {
|
217 |
$classes .= ' frm_38_trigger';
|
218 |
+
}
|
219 |
+
|
220 |
return $classes;
|
221 |
}
|
222 |
+
|
223 |
+
public static function load_lang() {
|
224 |
+
load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() .'/languages/' );
|
225 |
}
|
|
|
|
|
|
|
226 |
|
227 |
+
/**
|
228 |
+
* Filter shortcodes in text widgets
|
229 |
+
*/
|
230 |
+
public static function widget_text_filter( $content ) {
|
231 |
+
$regex = '/\[\s*(formidable|display-frm-data|frm-stats|frm-graph|frm-entry-links|formresults|frm-search)\s+.*\]/';
|
232 |
+
return preg_replace_callback( $regex, 'FrmAppHelper::widget_text_filter_callback', $content );
|
233 |
+
}
|
234 |
+
|
235 |
+
public static function widget_text_filter_callback( $matches ) {
|
236 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::widget_text_filter_callback' );
|
237 |
+
return FrmAppHelper::widget_text_filter_callback( $matches );
|
238 |
+
}
|
239 |
+
|
240 |
+
public static function front_head() {
|
241 |
+
if ( is_multisite() ) {
|
242 |
+
$old_db_version = get_option( 'frm_db_version' );
|
243 |
+
$pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
|
244 |
if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) ||
|
245 |
+
( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
|
246 |
+
self::install( $old_db_version );
|
247 |
}
|
248 |
}
|
249 |
+
|
250 |
$version = FrmAppHelper::plugin_version();
|
251 |
+
wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array( 'jquery' ), $version, true );
|
252 |
+
wp_register_script( 'jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array( 'jquery' ), '2.0.7', true );
|
253 |
+
|
254 |
+
if ( FrmAppHelper::is_admin() ) {
|
|
|
255 |
// don't load this in back-end
|
256 |
return;
|
257 |
}
|
258 |
+
|
259 |
+
self::localize_script( 'front' );
|
260 |
+
|
261 |
+
$frm_settings = FrmAppHelper::get_settings();
|
262 |
+
|
263 |
+
$style = apply_filters( 'get_frm_stylesheet', self::custom_stylesheet() );
|
264 |
+
if ( $style ) {
|
265 |
+
foreach ( (array) $style as $k => $file ) {
|
266 |
+
wp_register_style( $k, $file, array(), $version );
|
267 |
if ( 'all' == $frm_settings->load_style ) {
|
268 |
+
wp_enqueue_style( $k );
|
269 |
}
|
270 |
+
unset( $k, $file );
|
271 |
}
|
272 |
}
|
273 |
+
unset( $style );
|
274 |
+
|
275 |
+
if ( $frm_settings->load_style == 'all' ) {
|
276 |
global $frm_vars;
|
277 |
$frm_vars['css_loaded'] = true;
|
278 |
}
|
279 |
}
|
280 |
+
|
281 |
+
/**
|
282 |
+
* @param string $location
|
283 |
+
*/
|
284 |
+
public static function localize_script($location) {
|
285 |
wp_localize_script('formidable', 'frm_js', array(
|
286 |
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
287 |
'images_url' => FrmAppHelper::plugin_url() .'/images',
|
288 |
+
'loading' => __( 'Loading…' ),
|
289 |
+
'remove' => __( 'Remove', 'formidable' ),
|
290 |
+
'offset' => apply_filters( 'frm_scroll_offset', 4 ),
|
291 |
+
'nonce' => wp_create_nonce( 'frm_ajax' ),
|
292 |
+
'id' => __( 'ID', 'formidable' ),
|
293 |
));
|
294 |
+
|
295 |
+
if ( $location == 'admin' ) {
|
296 |
+
$frm_settings = FrmAppHelper::get_settings();
|
297 |
wp_localize_script('formidable_admin', 'frm_admin_js', array(
|
298 |
+
'confirm_uninstall' => __( 'Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable' ),
|
299 |
+
'desc' => __( '(Click to add description)', 'formidable' ),
|
300 |
+
'blank' => __( '(blank)', 'formidable' ),
|
301 |
+
'no_label' => __( '(no label)', 'formidable' ),
|
302 |
+
'saving' => esc_attr( __( 'Saving', 'formidable' ) ),
|
303 |
+
'saved' => esc_attr( __( 'Saved', 'formidable' ) ),
|
304 |
+
'ok' => __( 'OK' ),
|
305 |
+
'cancel' => __( 'Cancel', 'formidable' ),
|
306 |
+
'default' => __( 'Default', 'formidable' ),
|
307 |
+
'clear_default' => __( 'Clear default value when typing', 'formidable' ),
|
308 |
+
'no_clear_default' => __( 'Do not clear default value when typing', 'formidable' ),
|
309 |
+
'valid_default' => __( 'Default value will pass form validation', 'formidable' ),
|
310 |
+
'no_valid_default' => __( 'Default value will NOT pass form validation', 'formidable' ),
|
311 |
+
'confirm' => __( 'Are you sure?', 'formidable' ),
|
312 |
+
'conf_delete' => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
|
313 |
+
'conf_delete_sec' => __( 'WARNING: This will delete all fields inside of the section as well.', 'formidable' ),
|
314 |
+
'conf_no_repeat' => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
|
315 |
'default_unique' => $frm_settings->unique_msg,
|
316 |
+
'default_conf' => __( 'The entered values do not match', 'formidable' ),
|
317 |
+
'enter_email' => __( 'Enter Email', 'formidable' ),
|
318 |
+
'confirm_email' => __( 'Confirm Email', 'formidable' ),
|
319 |
+
'enter_password' => __( 'Enter Password', 'formidable' ),
|
320 |
+
'confirm_password' => __( 'Confirm Password', 'formidable' ),
|
321 |
+
'import_complete' => __( 'Import Complete', 'formidable' ),
|
322 |
+
'updating' => __( 'Please wait while your site updates.', 'formidable' ),
|
323 |
+
'no_save_warning' => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
|
324 |
+
'jquery_ui_url' => FrmAppHelper::jquery_ui_base_url(),
|
325 |
+
) );
|
326 |
}
|
327 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
|
329 |
+
|
330 |
+
public static function custom_stylesheet() {
|
331 |
+
global $frm_vars;
|
332 |
+
$css_file = array();
|
333 |
+
|
334 |
+
if ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) {
|
335 |
+
//include css in head
|
336 |
+
$uploads = FrmStylesHelper::get_upload_base();
|
337 |
+
if ( is_readable( $uploads['basedir'] .'/formidable/css/formidablepro.css' ) ) {
|
338 |
+
$css_file['formidable'] = $uploads['baseurl'] .'/formidable/css/formidablepro.css';
|
339 |
+
} else {
|
340 |
+
$css_file['formidable'] = admin_url( 'admin-ajax.php' ) . '?action=frmpro_css';
|
341 |
}
|
342 |
}
|
343 |
|
344 |
+
if ( isset($frm_vars['datepicker_loaded']) && ! empty($frm_vars['datepicker_loaded']) ) {
|
345 |
+
FrmStylesHelper::enqueue_jquery_css();
|
346 |
+
}
|
347 |
+
|
348 |
+
return $css_file;
|
349 |
}
|
350 |
+
|
351 |
+
public static function load_css() {
|
352 |
+
$css = get_transient( 'frmpro_css' );
|
353 |
+
|
354 |
+
include(FrmAppHelper::plugin_path() .'/css/custom_theme.css.php');
|
355 |
+
wp_die();
|
356 |
}
|
357 |
+
|
358 |
+
public static function footer_js( $location = 'footer' ) {
|
359 |
+
global $frm_vars;
|
360 |
+
|
361 |
+
$frm_settings = FrmAppHelper::get_settings();
|
362 |
+
if ( $frm_vars['load_css'] && ! FrmAppHelper::is_admin() && $frm_settings->load_style != 'none' ) {
|
363 |
+
$css = apply_filters( 'get_frm_stylesheet', self::custom_stylesheet() );
|
364 |
+
|
365 |
+
if ( ! empty( $css ) ) {
|
366 |
+
foreach ( (array) $css as $css_key => $file ) {
|
367 |
+
wp_enqueue_style( $css_key );
|
368 |
+
unset( $css_key, $file );
|
369 |
+
}
|
370 |
+
}
|
371 |
+
unset( $css );
|
372 |
+
}
|
373 |
+
|
374 |
+
if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
|
375 |
+
//load formidable js
|
376 |
+
wp_enqueue_script( 'formidable' );
|
377 |
+
}
|
378 |
+
}
|
379 |
+
|
380 |
+
public static function activation_install() {
|
381 |
+
FrmAppHelper::delete_cache_and_transient( 'frm_plugin_version' );
|
382 |
+
FrmFormActionsController::actions_init();
|
383 |
+
self::install();
|
384 |
+
}
|
385 |
+
|
386 |
+
public static function install( $old_db_version = false ) {
|
387 |
+
$frmdb = new FrmDb();
|
388 |
+
$frmdb->upgrade( $old_db_version );
|
389 |
+
}
|
390 |
+
|
391 |
+
public static function uninstall() {
|
392 |
check_ajax_referer( 'frm_ajax', 'nonce' );
|
393 |
+
|
394 |
+
if ( current_user_can( 'administrator' ) ) {
|
395 |
+
$frmdb = new FrmDb();
|
396 |
$frmdb->uninstall();
|
397 |
echo true;
|
398 |
} else {
|
399 |
+
$frm_settings = FrmAppHelper::get_settings();
|
400 |
+
wp_die( $frm_settings->admin_permission );
|
401 |
}
|
402 |
+
wp_die();
|
403 |
}
|
404 |
+
|
405 |
+
public static function drop_tables($tables) {
|
406 |
+
global $wpdb;
|
407 |
+
$tables[] = $wpdb->prefix .'frm_fields';
|
408 |
+
$tables[] = $wpdb->prefix .'frm_forms';
|
409 |
+
$tables[] = $wpdb->prefix .'frm_items';
|
410 |
+
$tables[] = $wpdb->prefix .'frm_item_metas';
|
411 |
+
return $tables;
|
412 |
+
}
|
413 |
+
|
414 |
// Routes for wordpress pages -- we're just replacing content here folks.
|
415 |
+
public static function page_route($content) {
|
416 |
+
global $post;
|
417 |
|
418 |
+
$frm_settings = FrmAppHelper::get_settings();
|
419 |
+
if ( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form']) ) {
|
420 |
$content = FrmFormsController::page_preview();
|
421 |
}
|
422 |
|
423 |
return $content;
|
424 |
}
|
425 |
+
|
426 |
+
public static function update_message($features) {
|
427 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::update_message' );
|
428 |
+
return FrmAppHelper::update_message( $features );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
}
|
430 |
|
431 |
+
public static function deauthorize() {
|
432 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
433 |
+
|
434 |
+
delete_option( 'frmpro-credentials' );
|
435 |
+
delete_option( 'frmpro-authorized' );
|
436 |
+
delete_site_option( 'frmpro-credentials' );
|
437 |
+
delete_site_option( 'frmpro-authorized' );
|
438 |
+
wp_die();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
439 |
}
|
440 |
+
|
441 |
//formidable shortcode
|
442 |
+
public static function get_form_shortcode( $atts ) {
|
443 |
_deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
|
444 |
+
return FrmFormsController::get_form_shortcode( $atts );
|
445 |
}
|
446 |
|
447 |
+
public static function get_postbox_class() {
|
448 |
+
_deprecated_function( __FUNCTION__, '2.0' );
|
449 |
+
return 'postbox-container';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
450 |
}
|
451 |
}
|
classes/controllers/FrmEntriesController.php
CHANGED
@@ -1,440 +1,665 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
if(
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
}
|
21 |
-
|
22 |
-
public static function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
global $frm_vars;
|
24 |
-
if(
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
}
|
28 |
-
|
29 |
-
public static function
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
-
|
45 |
-
public static function show_form($id='', $key='', $title=false, $description=false){
|
46 |
_deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
|
47 |
-
return FrmFormsController::show_form($id, $key, $title, $description);
|
48 |
}
|
49 |
-
|
50 |
-
public static function get_form($filename, $form, $title, $description) {
|
51 |
_deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
|
52 |
-
return FrmFormsController::get_form($form, $title, $description);
|
53 |
}
|
54 |
-
|
55 |
-
public static function process_entry($errors='', $ajax=false){
|
56 |
-
|
|
|
57 |
return;
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
$frm_form = new FrmForm();
|
62 |
-
$form = $frm_form->getOne($_POST['form_id']);
|
63 |
-
if(!$form)
|
64 |
return;
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
69 |
$frm_vars['form_params'] = array();
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
73 |
return;
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
80 |
$_POST['frm_skip_cookie'] = 1;
|
81 |
-
if($params['action'] == 'create'){
|
82 |
-
|
83 |
-
|
|
|
84 |
}
|
85 |
-
|
86 |
-
do_action('frm_process_entry', $params, $errors, $form, array('ajax' => $ajax));
|
87 |
-
unset($_POST['frm_skip_cookie']);
|
88 |
}
|
89 |
}
|
90 |
-
|
91 |
-
public static function delete_entry_before_redirect($url, $form, $atts){
|
92 |
-
self::_delete_entry($atts['id'], $form);
|
93 |
return $url;
|
94 |
}
|
95 |
-
|
96 |
//Delete entry if not redirected
|
97 |
-
public static function delete_entry_after_save($atts){
|
98 |
-
self::_delete_entry($atts['entry_id'], $atts['form']);
|
99 |
}
|
100 |
-
|
101 |
-
private static function _delete_entry($entry_id, $form){
|
102 |
-
if(
|
103 |
return;
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
}
|
110 |
}
|
111 |
-
|
112 |
-
public static function show_entry_shortcode($atts){
|
113 |
-
$atts = shortcode_atts(array(
|
114 |
'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
|
115 |
'user_info' => false, 'include_blank' => false, 'default_email' => false,
|
116 |
'form_id' => false, 'format' => 'text', 'direction' => 'ltr',
|
117 |
'font_size' => '', 'text_color' => '',
|
118 |
'border_width' => '', 'border_color' => '',
|
119 |
-
'bg_color' => '', 'alt_bg_color' => '',
|
120 |
-
), $atts);
|
121 |
-
|
122 |
-
|
123 |
-
if ( $format != 'text' ) {
|
124 |
//format options are text, array, or json
|
125 |
-
$plain_text = true;
|
126 |
-
}
|
127 |
-
|
128 |
-
global $frm_entry;
|
129 |
-
|
130 |
-
if ( !$entry || !is_object($entry) ) {
|
131 |
-
if ( !$id && !$default_email ) {
|
132 |
-
return '';
|
133 |
-
}
|
134 |
-
|
135 |
-
if($id)
|
136 |
-
$entry = $frm_entry->getOne($id, true);
|
137 |
-
}
|
138 |
-
|
139 |
-
if ( $entry ) {
|
140 |
-
$form_id = $entry->form_id;
|
141 |
-
$id = $entry->id;
|
142 |
-
}
|
143 |
-
|
144 |
-
if ( !$fields || !is_array($fields) ) {
|
145 |
-
global $frm_field;
|
146 |
-
$fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
|
147 |
-
}
|
148 |
-
|
149 |
-
$content = ( $format != 'text' ) ? array() : '';
|
150 |
-
$odd = true;
|
151 |
-
|
152 |
-
if ( !$plain_text ) {
|
153 |
-
global $frmpro_settings;
|
154 |
-
|
155 |
-
$default_settings = array(
|
156 |
-
'border_color' => 'dddddd',
|
157 |
-
'bg_color' => 'f7f7f7',
|
158 |
-
'text_color' => '444444',
|
159 |
-
'font_size' => '12px',
|
160 |
-
'border_width' => '1px',
|
161 |
-
'alt_bg_color' => 'ffffff',
|
162 |
-
);
|
163 |
-
|
164 |
-
// merge defaults, global settings, and shortcode options
|
165 |
-
foreach ( $default_settings as $key => $setting ) {
|
166 |
-
if ( $atts[$key] != '' ) {
|
167 |
-
continue;
|
168 |
-
}
|
169 |
-
|
170 |
-
if ( $frmpro_settings ) {
|
171 |
-
if ( 'alt_bg_color' == $key ) {
|
172 |
-
$atts[$key] = $frmpro_settings->bg_color_active;
|
173 |
-
} else if ( 'border_width' == $key ) {
|
174 |
-
$atts[$key] = $frmpro_settings->field_border_width;
|
175 |
-
} else {
|
176 |
-
$atts[$key] = $frmpro_settings->{$key};
|
177 |
-
}
|
178 |
-
} else {
|
179 |
-
$atts[$key] = $setting;
|
180 |
-
}
|
181 |
-
unset($key, $setting);
|
182 |
-
}
|
183 |
-
|
184 |
-
unset($default_settings);
|
185 |
-
|
186 |
-
$content .= "<table cellspacing='0' style='font-size:{$atts['font_size']};line-height:135%; border-bottom:{$atts['border_width']} solid #{$atts['border_color']};'><tbody>\r\n";
|
187 |
-
$bg_color = " style='background-color:#{$atts['bg_color']};'";
|
188 |
-
$bg_color_alt = " style='background-color:#{$atts['alt_bg_color']};'";
|
189 |
-
$row_style = "style='text-align:". ( $direction == 'rtl' ? 'right' : 'left' ) .";color:#{$atts['text_color']};padding:7px 9px;border-top:{$atts['border_width']} solid #{$atts['border_color']}'";
|
190 |
-
}
|
191 |
-
|
192 |
-
foreach ( $fields as $f ) {
|
193 |
-
if ( in_array($f->type, array('divider', 'captcha', 'break', 'html')) )
|
194 |
-
continue;
|
195 |
-
|
196 |
-
if ( $entry && !isset($entry->metas[$f->id]) ) {
|
197 |
-
if ( $entry->post_id && ( $f->type == 'tag' || (isset($f->field_options['post_field']) && $f->field_options['post_field'])) ) {
|
198 |
-
$p_val = FrmProEntryMetaHelper::get_post_value($entry->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array(
|
199 |
-
'truncate' => (($f->field_options['post_field'] == 'post_category') ? true : false),
|
200 |
-
'form_id' => $entry->form_id, 'field' => $f, 'type' => $f->type,
|
201 |
-
'exclude_cat' => (isset($f->field_options['exclude_cat']) ? $f->field_options['exclude_cat'] : 0)
|
202 |
-
));
|
203 |
-
if ( $p_val != '' ) {
|
204 |
-
$entry->metas[$f->id] = $p_val;
|
205 |
-
}
|
206 |
-
}
|
207 |
-
|
208 |
-
if ( !isset($entry->metas[$f->id]) && !$include_blank && !$default_email ) {
|
209 |
-
continue;
|
210 |
-
}
|
211 |
-
|
212 |
-
$entry->metas[$f->id] = $default_email ? '['. $f->id .']' : '';
|
213 |
-
}
|
214 |
-
|
215 |
-
$val = '';
|
216 |
-
if ( $entry ) {
|
217 |
-
$prev_val = maybe_unserialize($entry->metas[$f->id]);
|
218 |
-
$meta = array('item_id' => $id, 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
|
219 |
-
|
220 |
-
$val = $default_email ? $prev_val : apply_filters('frm_email_value', $prev_val, (object) $meta, $entry);
|
221 |
-
} else if ( $default_email ) {
|
222 |
-
$val = '['. $f->id .']';
|
223 |
-
}
|
224 |
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
if ( is_array($val) && $format == 'text' ) {
|
235 |
-
$val = implode(', ', $val);
|
236 |
-
}
|
237 |
-
|
238 |
-
$fname = $default_email ? '['. $f->id .' show=field_label]' : $f->name;
|
239 |
-
|
240 |
-
if ( $format != 'text' ){
|
241 |
-
$content[$f->field_key] = $val;
|
242 |
-
} else if ( $plain_text ) {
|
243 |
-
if ( 'rtl' == $direction ) {
|
244 |
-
$content .= $val . ' :' . $fname . "\r\n\r\n";
|
245 |
-
} else {
|
246 |
-
$content .= $fname . ': ' . $val . "\r\n\r\n";
|
247 |
-
}
|
248 |
-
} else {
|
249 |
-
if (!$default_email){
|
250 |
-
$content .= '<tr'. ( $odd ? $bg_color : $bg_color_alt ) .'>';
|
251 |
-
if ( 'rtl' == $direction ) {
|
252 |
-
$content .= "<td $row_style>$val</td><th $row_style>" . $fname ."</th>";
|
253 |
-
} else {
|
254 |
-
$content .= "<th $row_style>" . $fname ."</th><td $row_style>$val</td>";
|
255 |
-
}
|
256 |
-
$content .= '</tr>'. "\r\n";
|
257 |
-
$odd = ($odd) ? false : true;
|
258 |
-
}else{
|
259 |
-
$content .= '[if '. $f->id .']<tr style="[frm-alt-color]">';
|
260 |
-
if ( 'rtl' == $direction ) {
|
261 |
-
$content .= "<td $row_style>$val</td><th $row_style>" . $fname ."</th>";
|
262 |
-
} else {
|
263 |
-
$content .= "<th $row_style>" . $fname ."</th><td $row_style>$val</td>";
|
264 |
-
}
|
265 |
-
$content .= "</tr>\r\n[/if $f->id]";
|
266 |
-
}
|
267 |
-
|
268 |
-
}
|
269 |
-
|
270 |
-
unset($fname, $f);
|
271 |
-
}
|
272 |
-
|
273 |
-
if ( $user_info ) {
|
274 |
-
if ( isset($entry->description) ) {
|
275 |
-
$data = maybe_unserialize($entry->description);
|
276 |
-
} else if ( $default_email ) {
|
277 |
-
$entry->ip = '[ip]';
|
278 |
-
$data = array(
|
279 |
-
'browser' => '[browser]',
|
280 |
-
'referrer' => '[referrer]',
|
281 |
-
);
|
282 |
}
|
283 |
-
|
284 |
-
|
285 |
-
$
|
286 |
-
$content['referrer'] = $data['referrer'];
|
287 |
-
} else if ( $plain_text ) {
|
288 |
-
$content .= "\r\n\r\n" . __('User Information', 'formidable') ."\r\n";
|
289 |
-
if ( 'rtl' == $direction ) {
|
290 |
-
$content .= $entry->ip . ' :'. __('IP Address', 'formidable') ."\r\n";
|
291 |
-
$content .= $data['browser'] .' :'. __('User-Agent (Browser/OS)', 'formidable') ."\r\n";
|
292 |
-
$content .= $data['referrer'] .' :'. __('Referrer', 'formidable') ."\r\n";
|
293 |
-
} else {
|
294 |
-
$content .= __('IP Address', 'formidable') . ': '. $entry->ip ."\r\n";
|
295 |
-
$content .= __('User-Agent (Browser/OS)', 'formidable') . ': '. $data['browser']."\r\n";
|
296 |
-
$content .= __('Referrer', 'formidable') . ': '. $data['referrer']."\r\n";
|
297 |
-
}
|
298 |
-
} else {
|
299 |
-
$content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
|
300 |
-
if ( 'rtl' == $direction ) {
|
301 |
-
$content .= "<td $row_style>". $entry->ip ."</td><th $row_style>". __('IP Address', 'formidable') . "</th>";
|
302 |
-
} else {
|
303 |
-
$content .= "<th $row_style>". __('IP Address', 'formidable') . "</th><td $row_style>". $entry->ip ."</td>";
|
304 |
-
}
|
305 |
-
$content .= '</tr>'. "\r\n";
|
306 |
-
$odd = ($odd) ? false : true;
|
307 |
-
|
308 |
-
if ( isset($data['browser']) ) {
|
309 |
-
$content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
|
310 |
-
if ( 'rtl' == $direction ) {
|
311 |
-
$content .= "<td $row_style>". $data['browser']."</td><th $row_style>". __('User-Agent (Browser/OS)', 'formidable') . "</th>";
|
312 |
-
} else {
|
313 |
-
$content .= "<th $row_style>". __('User-Agent (Browser/OS)', 'formidable') . "</th><td $row_style>". $data['browser']."</td>";
|
314 |
-
}
|
315 |
-
$content .= '</tr>'. "\r\n";
|
316 |
-
}
|
317 |
-
$odd = ($odd) ? false : true;
|
318 |
-
|
319 |
-
if ( isset($data['referrer']) ) {
|
320 |
-
$content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
|
321 |
-
if ( 'rtl' == $direction ) {
|
322 |
-
$content .= "<td $row_style>". str_replace("\r\n", '<br/>', $data['referrer']) ."</td><th $row_style>".__('Referrer', 'formidable') . "</th>";
|
323 |
-
} else {
|
324 |
-
$content .= "<th $row_style>".__('Referrer', 'formidable') . "</th><td $row_style>". str_replace("\r\n", '<br/>', $data['referrer']) ."</td>";
|
325 |
-
}
|
326 |
-
$content .= '</tr>'. "\r\n";
|
327 |
-
}
|
328 |
}
|
329 |
}
|
330 |
|
331 |
-
if (
|
332 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
}
|
334 |
-
|
335 |
-
|
336 |
-
|
|
|
|
|
|
|
337 |
}
|
338 |
-
|
339 |
return $content;
|
340 |
}
|
341 |
-
|
342 |
-
public static function &filter_email_value($value, $meta, $entry, $atts=array()){
|
343 |
-
$
|
344 |
-
$field
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
$value = self::filter_display_value($value, $field, $atts);
|
349 |
return $value;
|
350 |
}
|
351 |
-
|
352 |
-
public static function &
|
353 |
-
$
|
354 |
-
|
355 |
-
|
356 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
return $value;
|
358 |
-
|
359 |
-
|
360 |
-
$f_values = array();
|
361 |
-
|
362 |
-
foreach($field->options as $opt_key => $opt){
|
363 |
-
if(!is_array($opt))
|
364 |
continue;
|
365 |
-
|
366 |
-
$f_labels[$opt_key] = isset($opt['label']) ? $opt['label'] : reset($opt);
|
367 |
-
$f_values[$opt_key] = isset($opt['value']) ? $opt['value'] : $f_labels[$opt_key];
|
368 |
-
if($f_labels[$opt_key] == $f_values[$opt_key]){
|
369 |
-
unset($f_values[$opt_key]);
|
370 |
-
unset($f_labels[$opt_key]);
|
371 |
}
|
372 |
-
|
373 |
-
|
|
|
|
|
|
|
|
|
|
|
374 |
}
|
375 |
|
376 |
-
if(!empty($f_values)){
|
377 |
-
foreach((array)$value as $v_key => $val){
|
378 |
-
if(in_array($val, $f_values)){
|
379 |
$opt = array_search($val, $f_values);
|
380 |
-
if(is_array($value))
|
381 |
-
$value[$v_key] = $f_labels[$opt];
|
382 |
-
else
|
383 |
-
$value = $f_labels[$opt];
|
|
|
384 |
}
|
385 |
-
unset($v_key);
|
386 |
-
unset($val);
|
387 |
}
|
388 |
}
|
389 |
-
|
390 |
return $value;
|
391 |
}
|
392 |
-
|
393 |
-
|
394 |
global $frm_vars;
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
if(isset($frm_vars['form_params']) && is_array($frm_vars['form_params']) && isset($frm_vars['form_params'][$form->id]))
|
403 |
-
return $frm_vars['form_params'][$form->id];
|
404 |
-
|
|
|
405 |
$action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
|
406 |
$action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
|
407 |
-
|
408 |
$default_values = array(
|
409 |
-
'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
|
410 |
-
'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action
|
411 |
);
|
412 |
-
|
|
|
413 |
$values['posted_form_id'] = FrmAppHelper::get_param('form_id');
|
414 |
-
if (!is_numeric($values['posted_form_id']))
|
415 |
$values['posted_form_id'] = FrmAppHelper::get_param('form');
|
|
|
416 |
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
|
|
425 |
}
|
426 |
-
}else{
|
427 |
-
foreach ($default_values as $var => $default){
|
428 |
-
$values[$var] = $default;
|
429 |
-
unset($var);
|
430 |
-
unset($default);
|
431 |
}
|
432 |
}
|
433 |
|
434 |
-
|
435 |
$values['action'] = 'new';
|
|
|
436 |
|
437 |
return $values;
|
438 |
}
|
439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
}
|
1 |
<?php
|
2 |
+
|
3 |
+
class FrmEntriesController {
|
4 |
+
|
5 |
+
public static function menu() {
|
6 |
+
if ( current_user_can( 'administrator' ) && ! current_user_can( 'frm_view_entries' ) ) {
|
7 |
+
global $wp_roles;
|
8 |
+
$wp_roles->add_cap( 'administrator', 'frm_view_entries' );
|
9 |
+
$wp_roles->add_cap( 'administrator', 'frm_delete_entries' );
|
10 |
+
}
|
11 |
+
|
12 |
+
add_submenu_page('formidable', 'Formidable | '. __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
|
13 |
+
|
14 |
+
if ( ! isset( $_GET['frm_action'] ) || ! in_array( $_GET['frm_action'], array( 'edit', 'show' ) ) ) {
|
15 |
+
$frm_settings = FrmAppHelper::get_settings();
|
16 |
+
add_filter( 'manage_' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entries_columns', 'FrmEntriesController::manage_columns' );
|
17 |
+
add_filter( 'manage_' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entries_sortable_columns', 'FrmEntriesController::sortable_columns' );
|
18 |
+
add_filter( 'get_user_option_manage' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entriescolumnshidden', 'FrmEntriesController::hidden_columns' );
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
/* Display in Back End */
|
23 |
+
public static function route() {
|
24 |
+
$action = FrmAppHelper::get_param('frm_action');
|
25 |
+
|
26 |
+
switch ( $action ) {
|
27 |
+
case 'show':
|
28 |
+
case 'destroy':
|
29 |
+
case 'destroy_all':
|
30 |
+
return self::$action();
|
31 |
+
|
32 |
+
default:
|
33 |
+
do_action( 'frm_entry_action_route', $action );
|
34 |
+
if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
|
35 |
+
return;
|
36 |
+
}
|
37 |
+
|
38 |
+
return self::display_list();
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
public static function contextual_help($help, $screen_id, $screen) {
|
43 |
+
// Only add to certain screens. add_help_tab was introduced in WordPress 3.3
|
44 |
+
if ( $screen_id != 'formidable_page_formidable-entries' || ! method_exists( $screen, 'add_help_tab' ) ) {
|
45 |
+
return $help;
|
46 |
+
}
|
47 |
+
|
48 |
+
$action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
|
49 |
+
$page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
|
50 |
+
if ( $page != 'formidable-entries' || ( ! empty( $action ) && $action != 'list' ) ) {
|
51 |
+
return $help;
|
52 |
+
}
|
53 |
+
unset( $action, $page );
|
54 |
+
|
55 |
+
$screen->add_help_tab( array(
|
56 |
+
'id' => 'formidable-entries-tab',
|
57 |
+
'title' => __( 'Overview', 'formidable' ),
|
58 |
+
'content' => '<p>' . esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) .'</p> <p>'. esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) . '</p>',
|
59 |
+
));
|
60 |
+
|
61 |
+
$screen->set_help_sidebar(
|
62 |
+
'<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' .
|
63 |
+
'<p><a href="http://formidablepro.com/knowledgebase/manage-entries-from-the-back-end/" target="_blank">' . esc_html__( 'Documentation on Entries', 'formidable' ) . '</a></p>' .
|
64 |
+
'<p><a href="http://formidablepro.com/help-topics/" target="_blank">' . esc_html__( 'Support', 'formidable' ) . '</a></p>'
|
65 |
+
);
|
66 |
+
|
67 |
+
return $help;
|
68 |
+
}
|
69 |
+
|
70 |
+
public static function manage_columns($columns) {
|
71 |
+
global $frm_vars, $wpdb;
|
72 |
+
$form_id = FrmEntriesHelper::get_current_form_id();
|
73 |
+
|
74 |
+
$columns[ $form_id .'_id' ] = 'ID';
|
75 |
+
$columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' );
|
76 |
+
|
77 |
+
if ( ! $form_id ) {
|
78 |
+
return $columns;
|
79 |
+
}
|
80 |
+
|
81 |
+
$form_cols = FrmField::get_all_for_form($form_id, '', 'include');
|
82 |
+
|
83 |
+
foreach ( $form_cols as $form_col ) {
|
84 |
+
if ( FrmFieldsHelper::is_no_save_field($form_col->type) ) {
|
85 |
+
continue;
|
86 |
+
}
|
87 |
+
|
88 |
+
if ( $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ) ) {
|
89 |
+
$sub_form_cols = FrmField::get_all_for_form( $form_col->field_options['form_select'] );
|
90 |
+
|
91 |
+
if ( $sub_form_cols ) {
|
92 |
+
foreach ( $sub_form_cols as $k => $sub_form_col ) {
|
93 |
+
if ( in_array( $sub_form_col->type, FrmFieldsHelper::no_save_fields() ) ) {
|
94 |
+
unset( $sub_form_cols[ $k ] );
|
95 |
+
continue;
|
96 |
+
}
|
97 |
+
$columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
|
98 |
+
unset($sub_form_col);
|
99 |
+
}
|
100 |
+
}
|
101 |
+
unset($sub_form_cols);
|
102 |
+
} else {
|
103 |
+
$col_id = $form_col->field_key;
|
104 |
+
if ( $form_col->form_id != $form_id ) {
|
105 |
+
$col_id .= '-_-form'. $form_col->form_id;
|
106 |
+
}
|
107 |
+
|
108 |
+
if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) {
|
109 |
+
$columns[ $form_id .'_frmsep_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 );
|
110 |
+
}
|
111 |
+
$columns[ $form_id .'_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 );
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
$columns[ $form_id .'_created_at' ] = __( 'Entry creation date', 'formidable' );
|
116 |
+
$columns[ $form_id .'_updated_at' ] = __( 'Entry update date', 'formidable' );
|
117 |
+
$columns[ $form_id .'_ip' ] = 'IP';
|
118 |
+
|
119 |
+
$frm_vars['cols'] = $columns;
|
120 |
+
|
121 |
+
$action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
|
122 |
+
if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && ( $action == 'list' || $action == 'destroy' ) ) {
|
123 |
+
add_screen_option( 'per_page', array( 'label' => __( 'Entries', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page' ) );
|
124 |
+
}
|
125 |
+
|
126 |
+
return $columns;
|
127 |
+
}
|
128 |
+
|
129 |
+
public static function check_hidden_cols($check, $object_id, $meta_key, $meta_value, $prev_value) {
|
130 |
+
$frm_settings = FrmAppHelper::get_settings();
|
131 |
+
if ( $meta_key != 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden' || $meta_value == $prev_value ) {
|
132 |
+
return $check;
|
133 |
+
}
|
134 |
+
|
135 |
+
if ( empty($prev_value) ) {
|
136 |
+
$prev_value = get_metadata('user', $object_id, $meta_key, true);
|
137 |
+
}
|
138 |
+
|
139 |
+
global $frm_vars;
|
140 |
+
//add a check so we don't create a loop
|
141 |
+
$frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
|
142 |
+
|
143 |
+
return $check;
|
144 |
+
}
|
145 |
+
|
146 |
+
//add hidden columns back from other forms
|
147 |
+
public static function update_hidden_cols($meta_id, $object_id, $meta_key, $meta_value ) {
|
148 |
+
$frm_settings = FrmAppHelper::get_settings();
|
149 |
+
|
150 |
+
$sanitized = sanitize_title($frm_settings->menu);
|
151 |
+
if ( $meta_key != 'manage'. $sanitized .'_page_formidable-entriescolumnshidden' ) {
|
152 |
+
return;
|
153 |
+
}
|
154 |
+
|
155 |
+
global $frm_vars;
|
156 |
+
if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) {
|
157 |
+
return; //don't continue if there's no previous value
|
158 |
+
}
|
159 |
+
|
160 |
+
foreach ( $meta_value as $mk => $mv ) {
|
161 |
+
//remove blank values
|
162 |
+
if ( empty( $mv ) ) {
|
163 |
+
unset( $meta_value[ $mk ] );
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
$cur_form_prefix = reset($meta_value);
|
168 |
+
$cur_form_prefix = explode('_', $cur_form_prefix);
|
169 |
+
$cur_form_prefix = $cur_form_prefix[0];
|
170 |
+
$save = false;
|
171 |
+
|
172 |
+
foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
|
173 |
+
if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
|
174 |
+
//don't add blank cols or process included cols
|
175 |
+
continue;
|
176 |
+
}
|
177 |
+
|
178 |
+
$form_prefix = explode( '_', $prev_hidden );
|
179 |
+
$form_prefix = $form_prefix[0];
|
180 |
+
if ( $form_prefix == $cur_form_prefix ) {
|
181 |
+
//don't add back columns that are meant to be hidden
|
182 |
+
continue;
|
183 |
+
}
|
184 |
+
|
185 |
+
$meta_value[] = $prev_hidden;
|
186 |
+
$save = true;
|
187 |
+
unset($form_prefix);
|
188 |
+
}
|
189 |
+
|
190 |
+
if ( $save ) {
|
191 |
+
$user = wp_get_current_user();
|
192 |
+
update_user_option( $user->ID, 'manage'. $sanitized .'_page_formidable-entriescolumnshidden', $meta_value, true );
|
193 |
+
}
|
194 |
+
}
|
195 |
+
|
196 |
+
public static function save_per_page($save, $option, $value) {
|
197 |
+
if ( $option == 'formidable_page_formidable_entries_per_page' ) {
|
198 |
+
$save = (int) $value;
|
199 |
+
}
|
200 |
+
return $save;
|
201 |
+
}
|
202 |
+
|
203 |
+
public static function sortable_columns() {
|
204 |
+
$form_id = FrmEntriesHelper::get_current_form_id();
|
205 |
+
|
206 |
+
$fields = FrmField::get_all_for_form( $form_id );
|
207 |
+
|
208 |
+
$columns = array(
|
209 |
+
$form_id .'_id' => 'id',
|
210 |
+
$form_id .'_created_at' => 'created_at',
|
211 |
+
$form_id .'_updated_at' => 'updated_at',
|
212 |
+
$form_id .'_ip' => 'ip',
|
213 |
+
$form_id .'_item_key' => 'item_key',
|
214 |
+
$form_id .'_is_draft' => 'is_draft',
|
215 |
+
);
|
216 |
+
|
217 |
+
foreach ( $fields as $field ) {
|
218 |
+
if ( $field->type != 'checkbox' && ( ! isset($field->field_options['post_field']) || $field->field_options['post_field'] == '' ) ) {
|
219 |
+
// Can't sort on checkboxes because they are stored serialized, or post fields
|
220 |
+
$columns[ $form_id .'_'. $field->field_key ] = 'meta_'. $field->id;
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
return $columns;
|
225 |
}
|
226 |
+
|
227 |
+
public static function hidden_columns($result) {
|
228 |
+
global $frm_vars;
|
229 |
+
|
230 |
+
$form_id = FrmEntriesHelper::get_current_form_id();
|
231 |
+
|
232 |
+
$return = false;
|
233 |
+
foreach ( (array) $result as $r ) {
|
234 |
+
if ( ! empty( $r ) ) {
|
235 |
+
$form_prefix = explode( '_', $r );
|
236 |
+
$form_prefix = $form_prefix[0];
|
237 |
+
|
238 |
+
if ( (int) $form_prefix == (int) $form_id ) {
|
239 |
+
$return = true;
|
240 |
+
break;
|
241 |
+
}
|
242 |
+
|
243 |
+
unset($form_prefix);
|
244 |
+
}
|
245 |
+
}
|
246 |
+
|
247 |
+
if ( $return ) {
|
248 |
+
return $result;
|
249 |
+
}
|
250 |
+
|
251 |
+
$i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0;
|
252 |
+
$max_columns = 8;
|
253 |
+
if ( $i <= $max_columns ) {
|
254 |
+
return $result;
|
255 |
+
}
|
256 |
+
|
257 |
global $frm_vars;
|
258 |
+
if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) {
|
259 |
+
$frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options);
|
260 |
+
}
|
261 |
+
|
262 |
+
if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] && isset($frm_vars['current_form']->options['hidden_cols']) && ! empty($frm_vars['current_form']->options['hidden_cols']) ) {
|
263 |
+
$result = $frm_vars['current_form']->options['hidden_cols'];
|
264 |
+
} else {
|
265 |
+
$cols = $frm_vars['cols'];
|
266 |
+
$cols = array_reverse($cols, true);
|
267 |
+
|
268 |
+
$result[] = $form_id .'_id';
|
269 |
+
$i--;
|
270 |
+
|
271 |
+
$result[] = $form_id .'_item_key';
|
272 |
+
$i--;
|
273 |
+
|
274 |
+
foreach ( $cols as $col_key => $col ) {
|
275 |
+
if ( $i > $max_columns ) {
|
276 |
+
$result[] = $col_key;
|
277 |
+
}
|
278 |
+
//remove some columns by default
|
279 |
+
$i--;
|
280 |
+
unset($col_key, $col);
|
281 |
+
}
|
282 |
+
}
|
283 |
+
|
284 |
+
return $result;
|
285 |
+
}
|
286 |
+
|
287 |
+
public static function display_list( $message = '', $errors = array() ) {
|
288 |
+
global $wpdb, $frm_vars;
|
289 |
+
|
290 |
+
$form = FrmEntriesHelper::get_current_form();
|
291 |
+
$params = FrmEntriesHelper::get_admin_params( $form );
|
292 |
+
|
293 |
+
if ( $form ) {
|
294 |
+
$params['form'] = $form->id;
|
295 |
+
$frm_vars['current_form'] = $form;
|
296 |
+
|
297 |
+
if ( 'trash' == $form->status ) {
|
298 |
+
$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
|
299 |
+
$time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
|
300 |
+
$errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete );
|
301 |
+
unset( $time_to_delete, $delete_timestamp );
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
$table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
|
306 |
+
|
307 |
+
$wp_list_table = new $table_class( array( 'params' => $params ) );
|
308 |
+
|
309 |
+
$pagenum = $wp_list_table->get_pagenum();
|
310 |
+
|
311 |
+
$wp_list_table->prepare_items();
|
312 |
+
|
313 |
+
$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
|
314 |
+
if ( $pagenum > $total_pages && $total_pages > 0 ) {
|
315 |
+
$url = add_query_arg( 'paged', $total_pages );
|
316 |
+
if ( headers_sent() ) {
|
317 |
+
echo FrmAppHelper::js_redirect($url);
|
318 |
+
} else {
|
319 |
+
wp_redirect($url);
|
320 |
+
}
|
321 |
+
die();
|
322 |
+
}
|
323 |
+
|
324 |
+
if ( empty($message) && isset($_GET['import-message']) ) {
|
325 |
+
$message = __( 'Your import is complete', 'formidable' );
|
326 |
+
}
|
327 |
+
|
328 |
+
require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php');
|
329 |
+
}
|
330 |
+
|
331 |
+
/* Back End CRUD */
|
332 |
+
public static function show($id = false) {
|
333 |
+
FrmAppHelper::permission_check('frm_view_entries');
|
334 |
+
|
335 |
+
if ( ! $id ) {
|
336 |
+
$id = FrmAppHelper::get_param('id');
|
337 |
+
|
338 |
+
if ( ! $id ) {
|
339 |
+
$id = FrmAppHelper::get_param('item_id');
|
340 |
+
}
|
341 |
}
|
342 |
+
|
343 |
+
$entry = FrmEntry::getOne($id, true);
|
344 |
+
|
345 |
+
$data = maybe_unserialize($entry->description);
|
346 |
+
if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
|
347 |
+
$data = array( 'referrer' => $data );
|
348 |
+
}
|
349 |
+
|
350 |
+
$fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
|
351 |
+
$to_emails = array();
|
352 |
+
|
353 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/show.php');
|
354 |
+
}
|
355 |
+
|
356 |
+
public static function destroy() {
|
357 |
+
FrmAppHelper::permission_check('frm_delete_entries');
|
358 |
+
|
359 |
+
$params = FrmEntriesHelper::get_admin_params();
|
360 |
+
|
361 |
+
if ( isset($params['keep_post']) && $params['keep_post'] ) {
|
362 |
+
//unlink entry from post
|
363 |
+
global $wpdb;
|
364 |
+
$wpdb->update( $wpdb->prefix .'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) );
|
365 |
+
}
|
366 |
+
|
367 |
+
$message = '';
|
368 |
+
if ( FrmEntry::destroy( $params['id'] ) ) {
|
369 |
+
$message = __( 'Entry was Successfully Destroyed', 'formidable' );
|
370 |
+
}
|
371 |
+
|
372 |
+
self::display_list( $message );
|
373 |
}
|
374 |
+
|
375 |
+
public static function destroy_all() {
|
376 |
+
if ( ! current_user_can( 'frm_delete_entries' ) ) {
|
377 |
+
$frm_settings = FrmAppHelper::get_settings();
|
378 |
+
wp_die( $frm_settings->admin_permission );
|
379 |
+
}
|
380 |
+
|
381 |
+
global $wpdb;
|
382 |
+
$params = FrmEntriesHelper::get_admin_params();
|
383 |
+
$message = '';
|
384 |
+
$errors = array();
|
385 |
+
$form_id = (int) $params['form'];
|
386 |
+
|
387 |
+
if ( $form_id ) {
|
388 |
+
$entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) );
|
389 |
+
$action = FrmFormActionsHelper::get_action_for_form( $form_id, 'wppost', 1 );
|
390 |
+
|
391 |
+
if ( $action ) {
|
392 |
+
// this action takes a while, so only trigger it if there are posts to delete
|
393 |
+
foreach ( $entry_ids as $entry_id ) {
|
394 |
+
do_action( 'frm_before_destroy_entry', $entry_id );
|
395 |
+
unset( $entry_id );
|
396 |
+
}
|
397 |
+
}
|
398 |
+
|
399 |
+
$wpdb->query( $wpdb->prepare( "DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id ) );
|
400 |
+
$results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) );
|
401 |
+
if ( $results ) {
|
402 |
+
$message = __( 'Entries were Successfully Destroyed', 'formidable' );
|
403 |
+
}
|
404 |
+
} else {
|
405 |
+
$errors = __( 'No entries were specified', 'formidable' );
|
406 |
+
}
|
407 |
+
|
408 |
+
self::display_list( $message, $errors );
|
409 |
}
|
410 |
+
|
411 |
+
public static function show_form( $id = '', $key = '', $title = false, $description = false ) {
|
412 |
_deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
|
413 |
+
return FrmFormsController::show_form( $id, $key, $title, $description );
|
414 |
}
|
415 |
+
|
416 |
+
public static function get_form( $filename, $form, $title, $description ) {
|
417 |
_deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
|
418 |
+
return FrmFormsController::get_form( $form, $title, $description );
|
419 |
}
|
420 |
+
|
421 |
+
public static function process_entry( $errors = '', $ajax = false ) {
|
422 |
+
$form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
|
423 |
+
if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) {
|
424 |
return;
|
425 |
+
}
|
426 |
+
|
427 |
+
global $frm_vars;
|
428 |
|
429 |
+
$form = FrmForm::getOne( $form_id );
|
430 |
+
if ( ! $form ) {
|
|
|
|
|
|
|
431 |
return;
|
432 |
+
}
|
433 |
+
|
434 |
+
$params = self::get_params( $form );
|
435 |
+
|
436 |
+
if ( ! isset( $frm_vars['form_params'] ) ) {
|
437 |
$frm_vars['form_params'] = array();
|
438 |
+
}
|
439 |
+
$frm_vars['form_params'][ $form->id ] = $params;
|
440 |
+
|
441 |
+
if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
|
442 |
return;
|
443 |
+
}
|
444 |
+
|
445 |
+
if ( $errors == '' ) {
|
446 |
+
$errors = FrmEntry::validate( $_POST );
|
447 |
+
}
|
448 |
+
$frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
|
449 |
+
|
450 |
+
if ( empty( $errors ) ) {
|
451 |
$_POST['frm_skip_cookie'] = 1;
|
452 |
+
if ( $params['action'] == 'create' ) {
|
453 |
+
if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
|
454 |
+
$frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST );
|
455 |
+
}
|
456 |
}
|
457 |
+
|
458 |
+
do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
|
459 |
+
unset( $_POST['frm_skip_cookie'] );
|
460 |
}
|
461 |
}
|
462 |
+
|
463 |
+
public static function delete_entry_before_redirect( $url, $form, $atts ) {
|
464 |
+
self::_delete_entry( $atts['id'], $form );
|
465 |
return $url;
|
466 |
}
|
467 |
+
|
468 |
//Delete entry if not redirected
|
469 |
+
public static function delete_entry_after_save( $atts ) {
|
470 |
+
self::_delete_entry( $atts['entry_id'], $atts['form'] );
|
471 |
}
|
472 |
+
|
473 |
+
private static function _delete_entry( $entry_id, $form ) {
|
474 |
+
if ( ! $form ) {
|
475 |
return;
|
476 |
+
}
|
477 |
+
|
478 |
+
$form->options = maybe_unserialize( $form->options );
|
479 |
+
if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
|
480 |
+
FrmEntry::destroy( $entry_id );
|
481 |
}
|
482 |
}
|
483 |
+
|
484 |
+
public static function show_entry_shortcode( $atts ) {
|
485 |
+
$atts = shortcode_atts( array(
|
486 |
'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
|
487 |
'user_info' => false, 'include_blank' => false, 'default_email' => false,
|
488 |
'form_id' => false, 'format' => 'text', 'direction' => 'ltr',
|
489 |
'font_size' => '', 'text_color' => '',
|
490 |
'border_width' => '', 'border_color' => '',
|
491 |
+
'bg_color' => '', 'alt_bg_color' => '',
|
492 |
+
), $atts );
|
493 |
+
|
494 |
+
if ( $atts['format'] != 'text' ) {
|
|
|
495 |
//format options are text, array, or json
|
496 |
+
$atts['plain_text'] = true;
|
497 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
|
499 |
+
if ( is_object( $atts['entry'] ) && ! isset( $atts['entry']->metas ) ) {
|
500 |
+
// if the entry does not include metas, force it again
|
501 |
+
$atts['entry'] = false;
|
502 |
+
}
|
503 |
+
|
504 |
+
if ( ! $atts['entry'] || ! is_object( $atts['entry'] ) ) {
|
505 |
+
if ( ! $atts['id'] && ! $atts['default_email'] ) {
|
506 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
507 |
}
|
508 |
+
|
509 |
+
if ( $atts['id'] ) {
|
510 |
+
$atts['entry'] = FrmEntry::getOne( $atts['id'], true );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
511 |
}
|
512 |
}
|
513 |
|
514 |
+
if ( $atts['entry'] ) {
|
515 |
+
$atts['form_id'] = $atts['entry']->form_id;
|
516 |
+
$atts['id'] = $atts['entry']->id;
|
517 |
+
}
|
518 |
+
|
519 |
+
if ( ! $atts['fields'] || ! is_array($atts['fields']) ) {
|
520 |
+
$atts['fields'] = FrmField::get_all_for_form( $atts['form_id'], '', 'include' );
|
521 |
+
}
|
522 |
+
|
523 |
+
$values = array();
|
524 |
+
foreach ( $atts['fields'] as $f ) {
|
525 |
+
FrmEntriesHelper::fill_entry_values($atts, $f, $values);
|
526 |
+
unset($f);
|
527 |
+
}
|
528 |
+
|
529 |
+
FrmEntriesHelper::fill_entry_user_info($atts, $values);
|
530 |
+
|
531 |
+
if ( $atts['format'] == 'json' ) {
|
532 |
+
return json_encode($values);
|
533 |
+
} else if ( $atts['format'] == 'array' ) {
|
534 |
+
return $values;
|
535 |
}
|
536 |
+
|
537 |
+
$content = array();
|
538 |
+
FrmEntriesHelper::convert_entry_to_content($values, $atts, $content);
|
539 |
+
|
540 |
+
if ( 'text' == $atts['format'] ) {
|
541 |
+
$content = implode('', $content);
|
542 |
}
|
543 |
+
|
544 |
return $content;
|
545 |
}
|
546 |
+
|
547 |
+
public static function &filter_email_value( $value, $meta, $entry, $atts = array() ) {
|
548 |
+
$field = FrmField::getOne($meta->field_id);
|
549 |
+
if ( ! $field ) {
|
550 |
+
return $value;
|
551 |
+
}
|
552 |
+
|
553 |
$value = self::filter_display_value($value, $field, $atts);
|
554 |
return $value;
|
555 |
}
|
556 |
+
|
557 |
+
public static function &filter_shortcode_value($value, $tag, $atts, $field) {
|
558 |
+
$plain_text = add_filter('frm_plain_text_email', true);
|
559 |
+
FrmEntriesHelper::textarea_display_value( $value, $field->type, $plain_text );
|
560 |
+
|
561 |
+
if ( isset($atts['show']) && $atts['show'] == 'value' ) {
|
562 |
+
return $value;
|
563 |
+
}
|
564 |
+
|
565 |
+
return self::filter_display_value($value, $field, $atts);
|
566 |
+
}
|
567 |
+
|
568 |
+
public static function &filter_display_value( $value, $field, $atts = array() ) {
|
569 |
+
$saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false;
|
570 |
+
if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'radio', 'select' ) ) || ! isset( $field->field_options['separate_value'] ) || ! $field->field_options['separate_value'] || $saved_value ) {
|
571 |
return $value;
|
572 |
+
}
|
573 |
+
|
574 |
+
$f_values = $f_labels = array();
|
575 |
+
|
576 |
+
foreach ( $field->options as $opt_key => $opt ) {
|
577 |
+
if ( ! is_array($opt) ) {
|
578 |
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
579 |
}
|
580 |
+
|
581 |
+
$f_labels[ $opt_key ] = isset( $opt['label'] ) ? $opt['label'] : reset($opt);
|
582 |
+
$f_values[ $opt_key ] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[ $opt_key ];
|
583 |
+
if ( $f_labels[ $opt_key ] == $f_values[ $opt_key ] ) {
|
584 |
+
unset( $f_values[ $opt_key ], $f_labels[ $opt_key ] );
|
585 |
+
}
|
586 |
+
unset($opt_key, $opt);
|
587 |
}
|
588 |
|
589 |
+
if ( ! empty($f_values) ) {
|
590 |
+
foreach ( (array) $value as $v_key => $val ) {
|
591 |
+
if ( in_array($val, $f_values) ) {
|
592 |
$opt = array_search($val, $f_values);
|
593 |
+
if ( is_array($value) ) {
|
594 |
+
$value[ $v_key ] = $f_labels[ $opt ];
|
595 |
+
} else {
|
596 |
+
$value = $f_labels[ $opt ];
|
597 |
+
}
|
598 |
}
|
599 |
+
unset($v_key, $val);
|
|
|
600 |
}
|
601 |
}
|
602 |
+
|
603 |
return $value;
|
604 |
}
|
605 |
+
|
606 |
+
public static function get_params( $form = null ) {
|
607 |
global $frm_vars;
|
608 |
+
|
609 |
+
if ( ! $form ) {
|
610 |
+
$form = FrmForm::getAll( array(), 'name', 1 );
|
611 |
+
} else {
|
612 |
+
FrmFormsHelper::maybe_get_form( $form );
|
613 |
+
}
|
614 |
+
|
615 |
+
if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
|
616 |
+
return $frm_vars['form_params'][ $form->id ];
|
617 |
+
}
|
618 |
+
|
619 |
$action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
|
620 |
$action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
|
621 |
+
|
622 |
$default_values = array(
|
623 |
+
'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
|
624 |
+
'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action,
|
625 |
);
|
626 |
+
|
627 |
+
$values = array();
|
628 |
$values['posted_form_id'] = FrmAppHelper::get_param('form_id');
|
629 |
+
if ( ! is_numeric($values['posted_form_id']) ) {
|
630 |
$values['posted_form_id'] = FrmAppHelper::get_param('form');
|
631 |
+
}
|
632 |
|
633 |
+
if ( $form->id == $values['posted_form_id'] ) {
|
634 |
+
//if there are two forms on the same page, make sure not to submit both
|
635 |
+
foreach ( $default_values as $var => $default ) {
|
636 |
+
if ( $var == 'action' ) {
|
637 |
+
$values[ $var ] = FrmAppHelper::get_param( $action_var, $default );
|
638 |
+
} else {
|
639 |
+
$values[ $var ] = FrmAppHelper::get_param( $var, $default );
|
640 |
+
}
|
641 |
+
unset( $var, $default );
|
642 |
}
|
643 |
+
} else {
|
644 |
+
foreach ( $default_values as $var => $default ) {
|
645 |
+
$values[ $var ] = $default;
|
646 |
+
unset( $var, $default );
|
|
|
647 |
}
|
648 |
}
|
649 |
|
650 |
+
if ( in_array( $values['action'], array( 'create', 'update' ) ) && ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) ) {
|
651 |
$values['action'] = 'new';
|
652 |
+
}
|
653 |
|
654 |
return $values;
|
655 |
}
|
656 |
+
|
657 |
+
public static function entry_sidebar($entry) {
|
658 |
+
$data = maybe_unserialize($entry->description);
|
659 |
+
$date_format = get_option('date_format');
|
660 |
+
$time_format = get_option('time_format');
|
661 |
+
|
662 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/sidebar-shared.php');
|
663 |
+
}
|
664 |
+
|
665 |
}
|
classes/controllers/FrmFieldsController.php
CHANGED
@@ -1,414 +1,506 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
if(class_exists('FrmFieldsController'))
|
9 |
-
return;
|
10 |
-
|
11 |
-
class FrmFieldsController{
|
12 |
-
public static function load_hooks(){
|
13 |
-
add_action('wp_ajax_frm_load_field', 'FrmFieldsController::load_field');
|
14 |
-
add_action('wp_ajax_frm_insert_field', 'FrmFieldsController::create');
|
15 |
-
add_action('wp_ajax_frm_field_name_in_place_edit', 'FrmFieldsController::edit_name');
|
16 |
-
add_action('wp_ajax_frm_field_desc_in_place_edit', 'FrmFieldsController::edit_description');
|
17 |
-
add_action('wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option');
|
18 |
-
add_action('wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate');
|
19 |
-
add_action('wp_ajax_frm_delete_field', 'FrmFieldsController::destroy');
|
20 |
-
add_action('wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option');
|
21 |
-
add_action('wp_ajax_frm_field_option_ipe', 'FrmFieldsController::edit_option');
|
22 |
-
add_action('wp_ajax_frm_delete_field_option', 'FrmFieldsController::delete_option');
|
23 |
-
add_action('wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices');
|
24 |
-
add_action('wp_ajax_frm_import_options', 'FrmFieldsController::import_options');
|
25 |
-
add_action('wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order');
|
26 |
-
add_filter('frm_field_type', 'FrmFieldsController::change_type');
|
27 |
-
add_filter('frm_display_field_options', 'FrmFieldsController::display_field_options');
|
28 |
-
add_action('frm_field_input_html', 'FrmFieldsController::input_html');
|
29 |
-
add_filter('frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3);
|
30 |
-
add_filter('frm_field_label_seen', 'FrmFieldsController::check_label', 10, 3);
|
31 |
-
}
|
32 |
-
|
33 |
-
public static function load_field(){
|
34 |
$fields = $_POST['field'];
|
35 |
-
if ( empty($fields) ) {
|
36 |
-
|
37 |
}
|
38 |
-
|
39 |
$_GET['page'] = 'formidable';
|
40 |
-
$fields = stripslashes_deep($fields);
|
41 |
-
|
42 |
$ajax = true;
|
43 |
$values = array();
|
44 |
$path = FrmAppHelper::plugin_path();
|
45 |
$field_html = array();
|
46 |
-
|
47 |
foreach ( $fields as $field ) {
|
48 |
-
$field = htmlspecialchars_decode(nl2br($field));
|
49 |
-
$field = json_decode($field, true);
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
54 |
$field['value'] = '';
|
55 |
}
|
56 |
-
|
57 |
-
$field_name =
|
58 |
-
|
|
|
59 |
ob_start();
|
60 |
include($path .'/classes/views/frm-forms/add_field.php');
|
61 |
-
$field_html[$field_id] = ob_get_contents();
|
62 |
ob_end_clean();
|
63 |
}
|
64 |
-
|
65 |
unset($path);
|
66 |
-
|
67 |
echo json_encode($field_html);
|
68 |
-
|
69 |
-
|
70 |
}
|
71 |
-
|
72 |
-
public static function create(){
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
$values = array();
|
76 |
-
if(
|
77 |
$values['post_type'] = FrmProFormsHelper::post_type($form_id);
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
$
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
die();
|
91 |
}
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
public static function edit_name($field = 'name', $id = '') {
|
|
|
|
|
94 |
if ( empty($field) ) {
|
95 |
$field = 'name';
|
96 |
}
|
97 |
-
|
98 |
if ( empty($id) ) {
|
99 |
-
|
|
|
100 |
}
|
101 |
-
|
102 |
-
|
|
|
103 |
if ( trim(strip_tags($value)) == '' ) {
|
104 |
// set blank value if there is no content
|
105 |
$value = '';
|
106 |
}
|
107 |
-
|
108 |
-
$frm_field = new FrmField();
|
109 |
-
$form = $frm_field->update($id, array($field => $value));
|
110 |
-
echo stripslashes($value);
|
111 |
-
die();
|
112 |
-
}
|
113 |
-
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
}
|
119 |
-
|
120 |
-
public static function update_ajax_option(){
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
if ( $val == 'separate_value' ) {
|
127 |
-
$new_val = (isset($field->field_options[$val]) && $field->field_options[$val]) ? 0 : 1;
|
128 |
}
|
129 |
-
|
130 |
-
$field->field_options[$val] = $new_val;
|
131 |
-
unset($new_val);
|
132 |
-
}
|
133 |
unset($val);
|
134 |
}
|
135 |
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
138 |
}
|
139 |
-
|
140 |
-
public static function duplicate(){
|
|
|
|
|
141 |
global $wpdb;
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
if (
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
$values = array();
|
148 |
-
$values
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
foreach (array('name', 'description', 'type', 'field_options', 'required') as $col)
|
153 |
-
$values[$col] = $copy_field->{$col};
|
154 |
-
$field_count = FrmAppHelper::getRecordCount(array('form_id' => $copy_field->form_id), $wpdb->prefix . 'frm_fields');
|
155 |
$values['field_order'] = $field_count + 1;
|
156 |
-
|
157 |
-
$field_id =
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
}
|
169 |
-
|
170 |
-
public static function destroy(){
|
171 |
-
$frm_field = new FrmField();
|
172 |
-
$field_id = $frm_field->destroy($_POST['field_id']);
|
173 |
-
die();
|
174 |
-
}
|
175 |
|
176 |
/* Field Options */
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
$last = 0;
|
187 |
-
|
188 |
$opt_key = $last + 1;
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
$
|
193 |
-
|
194 |
-
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
$field_val = $opt;
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
$checked = '';
|
200 |
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
$field_name = "item_meta[$id]";
|
208 |
-
|
209 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
|
210 |
-
die();
|
211 |
}
|
212 |
|
213 |
-
public static function edit_option(){
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
|
|
|
|
|
|
219 |
} else {
|
220 |
-
$new_label =
|
221 |
-
}
|
222 |
-
|
223 |
-
$frm_field = new FrmField();
|
224 |
-
$field = $frm_field->getOne($id);
|
225 |
-
$options = maybe_unserialize($field->options);
|
226 |
-
$this_opt = (array) $options[$ids[1]];
|
227 |
-
|
228 |
-
$label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt);
|
229 |
-
if ( isset($this_opt['value']) ) {
|
230 |
-
$value = $this_opt['value'];
|
231 |
}
|
232 |
-
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
$new_label = $label;
|
235 |
}
|
236 |
-
|
237 |
if ( isset($new_value) || isset($value) ) {
|
238 |
$update_value = isset($new_value) ? $new_value : $value;
|
239 |
}
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
} else {
|
244 |
-
|
245 |
}
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
}
|
251 |
|
252 |
-
public static function delete_option(){
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
}
|
260 |
-
|
261 |
-
public static function import_choices(){
|
262 |
-
if ( !current_user_can('frm_edit_forms') ) {
|
263 |
-
|
264 |
}
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
global $current_screen, $hook_suffix;
|
269 |
|
270 |
// Catch plugins that include admin-header.php before admin.php completes.
|
271 |
-
if ( empty( $current_screen ) && function_exists('set_current_screen') ) {
|
272 |
$hook_suffix = '';
|
273 |
set_current_screen();
|
274 |
}
|
275 |
-
|
276 |
-
if ( function_exists('register_admin_color_schemes') ) {
|
277 |
register_admin_color_schemes();
|
278 |
}
|
279 |
-
|
280 |
$hook_suffix = $admin_body_class = '';
|
281 |
-
|
282 |
-
if ( get_user_setting('mfold') == 'f' )
|
283 |
$admin_body_class .= ' folded';
|
|
|
284 |
|
285 |
-
if ( function_exists('is_admin_bar_showing') && is_admin_bar_showing() ) {
|
286 |
$admin_body_class .= ' admin-bar';
|
287 |
}
|
288 |
|
289 |
-
if ( is_rtl() )
|
290 |
$admin_body_class .= ' rtl';
|
|
|
291 |
|
292 |
$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
|
293 |
$prepop = array();
|
294 |
-
$prepop
|
295 |
-
|
296 |
-
$
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
sort($states);
|
302 |
-
$prepop[__('U.S. States', 'formidable')] = $states;
|
303 |
-
unset($state_abv);
|
304 |
-
unset($states);
|
305 |
-
|
306 |
-
$prepop[__('Age', 'formidable')] = array(
|
307 |
-
__('Under 18', 'formidable'), __('18-24', 'formidable'), __('25-34', 'formidable'),
|
308 |
-
__('35-44', 'formidable'), __('45-54', 'formidable'), __('55-64', 'formidable'),
|
309 |
-
__('65 or Above', 'formidable'), __('Prefer Not to Answer', 'formidable')
|
310 |
-
);
|
311 |
-
|
312 |
-
$prepop[__('Satisfaction', 'formidable')] = array(
|
313 |
-
__('Very Satisfied', 'formidable'), __('Satisfied', 'formidable'), __('Neutral', 'formidable'),
|
314 |
-
__('Unsatisfied', 'formidable'), __('Very Unsatisfied', 'formidable'), __('N/A', 'formidable')
|
315 |
-
);
|
316 |
|
317 |
-
$prepop[__('Importance', 'formidable')] = array(
|
318 |
-
__('Very Important', 'formidable'), __('Important', 'formidable'), __('Neutral', 'formidable'),
|
319 |
-
__('Somewhat Important', 'formidable'), __('Not at all Important', 'formidable'), __('N/A', 'formidable')
|
320 |
-
);
|
321 |
-
|
322 |
-
$prepop[__('Agreement', 'formidable')] = array(
|
323 |
-
__('Strongly Agree', 'formidable'), __('Agree', 'formidable'), __('Neutral', 'formidable'),
|
324 |
-
__('Disagree', 'formidable'), __('Strongly Disagree', 'formidable'), __('N/A', 'formidable')
|
325 |
-
);
|
326 |
-
|
327 |
-
$prepop = apply_filters('frm_bulk_field_choices', $prepop);
|
328 |
-
|
329 |
-
$frm_field = new FrmField();
|
330 |
-
$field = $frm_field->getOne($field_id);
|
331 |
-
|
332 |
include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/import_choices.php');
|
333 |
-
|
334 |
}
|
335 |
-
|
336 |
-
public static function import_options(){
|
337 |
-
|
|
|
|
|
338 |
return;
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
$
|
343 |
-
|
344 |
-
|
345 |
-
if(!in_array($field->type, array('radio', 'checkbox', 'select')))
|
346 |
return;
|
347 |
-
|
|
|
348 |
$field = FrmFieldsHelper::setup_edit_vars($field);
|
|
|
349 |
$opts = explode("\n", rtrim($opts, "\n"));
|
350 |
if ( $field['separate_value'] ) {
|
351 |
foreach ( $opts as $opt_key => $opt ) {
|
352 |
if ( strpos($opt, '|') !== false ) {
|
353 |
$vals = explode('|', $opt);
|
354 |
if ( $vals[0] != $vals[1] ) {
|
355 |
-
$opts[$opt_key] = array('label' => trim($vals[0]), 'value' => trim($vals[1]));
|
356 |
}
|
357 |
unset($vals);
|
358 |
}
|
359 |
-
unset($opt_key);
|
360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
}
|
362 |
}
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
$field['options'] = $opts;
|
367 |
$field_name = $field['name'];
|
368 |
-
|
|
|
|
|
|
|
369 |
if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
|
370 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php');
|
371 |
} else {
|
372 |
-
|
373 |
-
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
|
374 |
-
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
|
375 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
|
376 |
-
}
|
377 |
}
|
378 |
-
|
379 |
-
|
380 |
}
|
381 |
|
382 |
-
public static function update_order(){
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
}
|
389 |
-
|
390 |
}
|
391 |
-
|
392 |
-
public static function change_type($type){
|
393 |
-
global $frm_vars;
|
394 |
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
|
|
|
|
|
|
|
|
402 |
$frm_field_selection = FrmFieldsHelper::field_selection();
|
403 |
$types = array_keys($frm_field_selection);
|
404 |
-
if (!in_array($type, $types) && $type != 'captcha')
|
405 |
$type = 'text';
|
|
|
406 |
|
407 |
return $type;
|
408 |
}
|
409 |
-
|
410 |
-
public static function display_field_options($display){
|
411 |
-
switch($display['type']){
|
412 |
case 'captcha':
|
413 |
$display['required'] = false;
|
414 |
$display['invalid'] = true;
|
@@ -425,107 +517,193 @@ class FrmFieldsController{
|
|
425 |
case 'select':
|
426 |
$display['size'] = true;
|
427 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
}
|
429 |
-
|
430 |
return $display;
|
431 |
}
|
432 |
-
|
433 |
-
public static function input_html($field, $echo=true){
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
$
|
443 |
-
|
444 |
-
if(
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
}
|
482 |
}
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
foreach ( $field['shortcodes'] as $k => $v ) {
|
494 |
-
if ( 'opt' === $k || (!is_numeric($k) && strpos($add_html, " $k=")) ) {
|
495 |
-
continue;
|
496 |
-
}
|
497 |
-
|
498 |
-
if ( is_numeric($k) && strpos($v, '=') ) {
|
499 |
-
$add_html .= ' '. $v;
|
500 |
-
} else {
|
501 |
-
$add_html .= ' '. $k .'="'. $v .'"';
|
502 |
-
}
|
503 |
-
|
504 |
-
unset($k, $v);
|
505 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
}
|
507 |
-
|
508 |
-
if($echo)
|
509 |
-
echo $add_html;
|
510 |
-
|
511 |
-
return $add_html;
|
512 |
}
|
513 |
-
|
514 |
-
public static function check_value($opt, $opt_key, $field){
|
515 |
-
if(is_array($opt)){
|
516 |
-
if(isset($field['separate_value'])
|
517 |
-
$opt = isset($opt['value']) ? $opt['value'] : (isset($opt['label']) ? $opt['label'] : reset($opt));
|
518 |
-
}else{
|
519 |
-
$opt =
|
520 |
}
|
521 |
}
|
522 |
return $opt;
|
523 |
}
|
524 |
-
|
525 |
-
public static function check_label($opt
|
526 |
-
if(is_array($opt))
|
527 |
$opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
|
528 |
-
|
|
|
529 |
return $opt;
|
530 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
}
|
1 |
<?php
|
2 |
+
|
3 |
+
class FrmFieldsController {
|
4 |
+
|
5 |
+
public static function load_field() {
|
6 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
7 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
$fields = $_POST['field'];
|
9 |
+
if ( empty( $fields ) ) {
|
10 |
+
wp_die();
|
11 |
}
|
12 |
+
|
13 |
$_GET['page'] = 'formidable';
|
14 |
+
$fields = stripslashes_deep( $fields );
|
15 |
+
|
16 |
$ajax = true;
|
17 |
$values = array();
|
18 |
$path = FrmAppHelper::plugin_path();
|
19 |
$field_html = array();
|
20 |
+
|
21 |
foreach ( $fields as $field ) {
|
22 |
+
$field = htmlspecialchars_decode( nl2br( $field ) );
|
23 |
+
$field = json_decode( $field, true );
|
24 |
+
if ( ! isset( $field['id'] ) ) {
|
25 |
+
// this field may have already been loaded
|
26 |
+
continue;
|
27 |
+
}
|
28 |
+
|
29 |
+
$field_id = absint( $field['id'] );
|
30 |
+
|
31 |
+
if ( ! isset( $field['value'] ) ) {
|
32 |
$field['value'] = '';
|
33 |
}
|
34 |
+
|
35 |
+
$field_name = 'item_meta['. $field_id .']';
|
36 |
+
$html_id = FrmFieldsHelper::get_html_id($field);
|
37 |
+
|
38 |
ob_start();
|
39 |
include($path .'/classes/views/frm-forms/add_field.php');
|
40 |
+
$field_html[ $field_id ] = ob_get_contents();
|
41 |
ob_end_clean();
|
42 |
}
|
43 |
+
|
44 |
unset($path);
|
45 |
+
|
46 |
echo json_encode($field_html);
|
47 |
+
|
48 |
+
wp_die();
|
49 |
}
|
50 |
+
|
51 |
+
public static function create() {
|
52 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
53 |
+
|
54 |
+
$field_type = FrmAppHelper::get_post_param( 'field', '', 'sanitize_text_field' );
|
55 |
+
$form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
|
56 |
+
|
57 |
+
$field = self::include_new_field($field_type, $form_id);
|
58 |
+
|
59 |
+
// this hook will allow for multiple fields to be added at once
|
60 |
+
do_action('frm_after_field_created', $field, $form_id);
|
61 |
+
|
62 |
+
wp_die();
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* @param integer $form_id
|
67 |
+
*/
|
68 |
+
public static function include_new_field($field_type, $form_id) {
|
69 |
$values = array();
|
70 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
71 |
$values['post_type'] = FrmProFormsHelper::post_type($form_id);
|
72 |
+
}
|
73 |
+
|
74 |
+
$field_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars($field_type, $form_id));
|
75 |
+
$field_id = FrmField::create( $field_values );
|
76 |
+
|
77 |
+
if ( ! $field_id ) {
|
78 |
+
return false;
|
79 |
+
}
|
80 |
+
|
81 |
+
$field = self::include_single_field($field_id, $values, $form_id);
|
82 |
+
|
83 |
+
return $field;
|
|
|
84 |
}
|
85 |
+
|
86 |
+
public static function update_form_id() {
|
87 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
88 |
+
|
89 |
+
$field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
|
90 |
+
$form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
|
91 |
+
|
92 |
+
if ( ! $field_id || ! $form_id ) {
|
93 |
+
return;
|
94 |
+
}
|
95 |
+
|
96 |
+
FrmField::update( $field_id, compact('form_id') );
|
97 |
+
|
98 |
+
wp_die();
|
99 |
+
}
|
100 |
+
|
101 |
public static function edit_name($field = 'name', $id = '') {
|
102 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
103 |
+
|
104 |
if ( empty($field) ) {
|
105 |
$field = 'name';
|
106 |
}
|
107 |
+
|
108 |
if ( empty($id) ) {
|
109 |
+
$id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' );
|
110 |
+
$id = str_replace( 'field_label_', '', $id );
|
111 |
}
|
112 |
+
|
113 |
+
$value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' );
|
114 |
+
$value = trim( $value );
|
115 |
if ( trim(strip_tags($value)) == '' ) {
|
116 |
// set blank value if there is no content
|
117 |
$value = '';
|
118 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
+
FrmField::update( $id, array( $field => $value ) );
|
121 |
+
echo stripslashes($value);
|
122 |
+
wp_die();
|
123 |
}
|
124 |
+
|
125 |
+
public static function update_ajax_option() {
|
126 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
127 |
+
|
128 |
+
$field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
|
129 |
+
if ( ! $field_id ) {
|
130 |
+
wp_die();
|
131 |
+
}
|
132 |
+
|
133 |
+
$field = FrmField::getOne( $field_id );
|
134 |
+
|
135 |
+
foreach ( array( 'clear_on_focus', 'separate_value', 'default_blank' ) as $val ) {
|
136 |
+
if ( isset($_POST[ $val ]) ) {
|
137 |
+
// all three of these options are boolean
|
138 |
+
$new_val = FrmAppHelper::get_post_param( $val, 0, 'absint' );
|
139 |
+
|
140 |
if ( $val == 'separate_value' ) {
|
141 |
+
$new_val = ( isset( $field->field_options[ $val ] ) && $field->field_options[ $val ] ) ? 0 : 1;
|
142 |
}
|
143 |
+
|
144 |
+
$field->field_options[ $val ] = $new_val;
|
145 |
+
unset($new_val);
|
146 |
+
}
|
147 |
unset($val);
|
148 |
}
|
149 |
|
150 |
+
FrmField::update( $field_id, array(
|
151 |
+
'field_options' => $field->field_options,
|
152 |
+
'form_id' => $field->form_id,
|
153 |
+
) );
|
154 |
+
wp_die();
|
155 |
}
|
156 |
+
|
157 |
+
public static function duplicate() {
|
158 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
159 |
+
|
160 |
global $wpdb;
|
161 |
+
|
162 |
+
$field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
|
163 |
+
$copy_field = FrmField::getOne( $field_id );
|
164 |
+
if ( ! $copy_field ) {
|
165 |
+
wp_die();
|
166 |
+
}
|
167 |
+
|
168 |
+
$form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
|
169 |
+
|
170 |
+
do_action('frm_duplicate_field', $copy_field, $form_id);
|
171 |
+
do_action('frm_duplicate_field_'. $copy_field->type, $copy_field, $form_id);
|
172 |
+
|
173 |
$values = array();
|
174 |
+
FrmFieldsHelper::fill_field( $values, $copy_field, $form_id );
|
175 |
+
|
176 |
+
$field_count = FrmDb::get_count( $wpdb->prefix .'frm_fields fi LEFT JOIN '. $wpdb->prefix .'frm_forms fr ON (fi.form_id = fr.id)', array( 'or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id ) );
|
177 |
+
|
|
|
|
|
|
|
178 |
$values['field_order'] = $field_count + 1;
|
179 |
+
|
180 |
+
if ( ! $field_id = FrmField::create($values) ) {
|
181 |
+
wp_die();
|
182 |
+
}
|
183 |
+
|
184 |
+
self::include_single_field($field_id, $values);
|
185 |
+
|
186 |
+
wp_die();
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Load a single field in the form builder along with all needed variables
|
191 |
+
*/
|
192 |
+
public static function include_single_field( $field_id, $values, $form_id = 0 ) {
|
193 |
+
$field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id));
|
194 |
+
$field_name = 'item_meta['. $field_id .']';
|
195 |
+
$html_id = FrmFieldsHelper::get_html_id($field);
|
196 |
+
$id = $form_id ? $form_id : $field['form_id'];
|
197 |
+
if ( $field['type'] == 'html' ) {
|
198 |
+
$field['stop_filter'] = true;
|
199 |
+
}
|
200 |
+
|
201 |
+
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
|
202 |
+
|
203 |
+
return $field;
|
204 |
+
}
|
205 |
+
|
206 |
+
public static function destroy() {
|
207 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
208 |
+
|
209 |
+
$field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
|
210 |
+
FrmField::destroy( $field_id );
|
211 |
+
wp_die();
|
212 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
/* Field Options */
|
215 |
+
|
216 |
+
//Add Single Option or Other Option
|
217 |
+
public static function add_option() {
|
218 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
219 |
+
|
220 |
+
$id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
|
221 |
+
$opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' );
|
222 |
+
|
223 |
+
//Get the field
|
224 |
+
$field = FrmField::getOne($id);
|
225 |
+
|
226 |
+
if ( ! empty( $field->options ) ) {
|
227 |
+
$keys = array_keys( $field->options );
|
228 |
+
$last = str_replace( 'other_', '', end( $keys ) );
|
229 |
+
} else {
|
230 |
$last = 0;
|
231 |
+
}
|
232 |
$opt_key = $last + 1;
|
233 |
+
|
234 |
+
if ( 'other' == $opt_type ) {
|
235 |
+
$opt = esc_html__( 'Other', 'formidable' );
|
236 |
+
$other_val = '';
|
237 |
+
$opt_key = 'other_' . $opt_key;
|
238 |
+
|
239 |
+
//Update value of "other" in DB
|
240 |
+
$field_options = maybe_unserialize( $field->field_options );
|
241 |
+
$field_options['other'] = 1;
|
242 |
+
FrmField::update( $id, array( 'field_options' => maybe_serialize( $field_options ) ) );
|
243 |
+
} else {
|
244 |
+
$first_opt = reset( $field->options );
|
245 |
+
$next_opt = count( $field->options );
|
246 |
+
if ( $first_opt != '' ) {
|
247 |
+
$next_opt++;
|
248 |
+
}
|
249 |
+
$opt = esc_html__( 'Option', 'formidable' ) .' '. $next_opt;
|
250 |
+
unset($next_opt);
|
251 |
+
}
|
252 |
$field_val = $opt;
|
253 |
+
$field->options[ $opt_key ] = $opt;
|
254 |
+
|
255 |
+
//Update options in DB
|
256 |
+
FrmField::update( $id, array( 'options' => $field->options ) );
|
257 |
+
|
258 |
+
$field_data = $field;
|
259 |
+
$field = array(
|
260 |
+
'type' => $field_data->type,
|
261 |
+
'id' => $id,
|
262 |
+
'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0,
|
263 |
+
'form_id' => $field_data->form_id,
|
264 |
+
'field_key' => $field_data->field_key,
|
265 |
+
);
|
266 |
+
|
267 |
+
$field_name = 'item_meta['. $id .']';
|
268 |
+
$html_id = FrmFieldsHelper::get_html_id($field);
|
269 |
$checked = '';
|
270 |
|
271 |
+
if ( 'other' == $opt_type ) {
|
272 |
+
require(FrmAppHelper::plugin_path() .'/pro/classes/views/frmpro-fields/other-option.php');
|
273 |
+
} else {
|
274 |
+
require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
|
275 |
+
}
|
276 |
+
wp_die();
|
|
|
|
|
|
|
|
|
277 |
}
|
278 |
|
279 |
+
public static function edit_option() {
|
280 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
281 |
+
|
282 |
+
$element_id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' );
|
283 |
+
$ids = explode( '-', $element_id );
|
284 |
+
$id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
|
285 |
+
|
286 |
+
$orig_update_value = $update_value = trim( FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' ) );
|
287 |
+
if ( strpos( $element_id, 'key_' ) ) {
|
288 |
+
$new_value = $update_value;
|
289 |
} else {
|
290 |
+
$new_label = $update_value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
}
|
292 |
+
|
293 |
+
$field = FrmField::getOne($id);
|
294 |
+
$separate_values = ( isset($field->field_options['separate_value']) && $field->field_options['separate_value'] );
|
295 |
+
|
296 |
+
$this_opt_id = end($ids);
|
297 |
+
$this_opt = (array) $field->options[ $this_opt_id ];
|
298 |
+
$other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other') !== false ? true : false );
|
299 |
+
|
300 |
+
$label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt);
|
301 |
+
$value = isset($this_opt['value']) ? $this_opt['value'] : '';
|
302 |
+
|
303 |
+
if ( ! isset( $new_label ) ) {
|
304 |
$new_label = $label;
|
305 |
}
|
306 |
+
|
307 |
if ( isset($new_value) || isset($value) ) {
|
308 |
$update_value = isset($new_value) ? $new_value : $value;
|
309 |
}
|
310 |
+
|
311 |
+
if ( $update_value != $new_label && $other_opt === false && $separate_values ) {
|
312 |
+
$field->options[ $this_opt_id ] = array( 'value' => $update_value, 'label' => $new_label );
|
313 |
} else {
|
314 |
+
$field->options[ $this_opt_id ] = $orig_update_value;
|
315 |
}
|
316 |
+
|
317 |
+
FrmField::update( $field->id, array( 'options' => $field->options ) );
|
318 |
+
echo ( $orig_update_value == '' ) ? esc_html__( '(Blank)', 'formidable' ) : stripslashes( $orig_update_value );
|
319 |
+
wp_die();
|
320 |
}
|
321 |
|
322 |
+
public static function delete_option() {
|
323 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
324 |
+
|
325 |
+
$field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
|
326 |
+
$field = FrmField::getOne( $field_id );
|
327 |
+
// Opt key will NOT be numeric for "Other" options
|
328 |
+
$opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'sanitize_title' );
|
329 |
+
|
330 |
+
$options = $field->options;
|
331 |
+
unset( $options[ $opt_key ] );
|
332 |
+
$response = array( 'other' => true );
|
333 |
+
|
334 |
+
//If the deleted option is an "other" option
|
335 |
+
if ( FrmAppHelper::is_other_opt( $opt_key ) ) {
|
336 |
+
//Assume all other options are gone, unless proven otherwise
|
337 |
+
$other = false;
|
338 |
+
|
339 |
+
//Check if all other options are really gone
|
340 |
+
foreach ( $options as $o_key => $o_val ) {
|
341 |
+
//If there is still an other option in the field, set other to true
|
342 |
+
if ( FrmAppHelper::is_other_opt( $o_key ) ) {
|
343 |
+
$other = true;
|
344 |
+
break;
|
345 |
+
}
|
346 |
+
unset( $o_key, $o_val );
|
347 |
+
}
|
348 |
+
|
349 |
+
//If all other options are gone
|
350 |
+
if ( false === $other ) {
|
351 |
+
$field_options = maybe_unserialize( $field->field_options );
|
352 |
+
$field_options['other'] = 0;
|
353 |
+
FrmField::update( $_POST['field_id'], array( 'field_options' => maybe_serialize( $field_options ) ) );
|
354 |
+
$response = array( 'other' => false );
|
355 |
+
}
|
356 |
+
}
|
357 |
+
echo json_encode( $response );
|
358 |
+
|
359 |
+
FrmField::update( $_POST['field_id'], array( 'options' => maybe_serialize( $options ) ) );
|
360 |
+
|
361 |
+
wp_die();
|
362 |
}
|
363 |
+
|
364 |
+
public static function import_choices() {
|
365 |
+
if ( ! current_user_can( 'frm_edit_forms' ) ) {
|
366 |
+
wp_die();
|
367 |
}
|
368 |
+
|
369 |
+
$field_id = absint( $_REQUEST['field_id'] );
|
370 |
+
|
371 |
global $current_screen, $hook_suffix;
|
372 |
|
373 |
// Catch plugins that include admin-header.php before admin.php completes.
|
374 |
+
if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) {
|
375 |
$hook_suffix = '';
|
376 |
set_current_screen();
|
377 |
}
|
378 |
+
|
379 |
+
if ( function_exists( 'register_admin_color_schemes' ) ) {
|
380 |
register_admin_color_schemes();
|
381 |
}
|
382 |
+
|
383 |
$hook_suffix = $admin_body_class = '';
|
384 |
+
|
385 |
+
if ( get_user_setting( 'mfold' ) == 'f' ) {
|
386 |
$admin_body_class .= ' folded';
|
387 |
+
}
|
388 |
|
389 |
+
if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
|
390 |
$admin_body_class .= ' admin-bar';
|
391 |
}
|
392 |
|
393 |
+
if ( is_rtl() ) {
|
394 |
$admin_body_class .= ' rtl';
|
395 |
+
}
|
396 |
|
397 |
$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
|
398 |
$prepop = array();
|
399 |
+
FrmFieldsHelper::get_bulk_prefilled_opts($prepop);
|
400 |
+
|
401 |
+
$field = FrmField::getOne($field_id);
|
402 |
+
|
403 |
+
wp_enqueue_script( 'utils' );
|
404 |
+
wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url(). '/css/frm_admin.css' );
|
405 |
+
FrmAppHelper::load_admin_wide_js();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
407 |
include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/import_choices.php');
|
408 |
+
wp_die();
|
409 |
}
|
410 |
+
|
411 |
+
public static function import_options() {
|
412 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
413 |
+
|
414 |
+
if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) {
|
415 |
return;
|
416 |
+
}
|
417 |
+
|
418 |
+
$field_id = absint( $_POST['field_id'] );
|
419 |
+
$field = FrmField::getOne($field_id);
|
420 |
+
|
421 |
+
if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
|
|
|
422 |
return;
|
423 |
+
}
|
424 |
+
|
425 |
$field = FrmFieldsHelper::setup_edit_vars($field);
|
426 |
+
$opts = stripslashes_deep($_POST['opts']);
|
427 |
$opts = explode("\n", rtrim($opts, "\n"));
|
428 |
if ( $field['separate_value'] ) {
|
429 |
foreach ( $opts as $opt_key => $opt ) {
|
430 |
if ( strpos($opt, '|') !== false ) {
|
431 |
$vals = explode('|', $opt);
|
432 |
if ( $vals[0] != $vals[1] ) {
|
433 |
+
$opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) );
|
434 |
}
|
435 |
unset($vals);
|
436 |
}
|
437 |
+
unset($opt_key, $opt);
|
438 |
+
}
|
439 |
+
}
|
440 |
+
|
441 |
+
//Keep other options after bulk update
|
442 |
+
if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
|
443 |
+
$other_array = array();
|
444 |
+
foreach ( $field['options'] as $opt_key => $opt ) {
|
445 |
+
if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) {
|
446 |
+
$other_array[ $opt_key ] = $opt;
|
447 |
+
}
|
448 |
+
unset($opt_key, $opt);
|
449 |
+
}
|
450 |
+
if ( ! empty($other_array) ) {
|
451 |
+
$opts = array_merge( $opts, $other_array);
|
452 |
}
|
453 |
}
|
454 |
+
|
455 |
+
FrmField::update( $field_id, array( 'options' => maybe_serialize( $opts ) ) );
|
456 |
+
|
457 |
$field['options'] = $opts;
|
458 |
$field_name = $field['name'];
|
459 |
+
|
460 |
+
// Get html_id which will be used in single-option.php
|
461 |
+
$html_id = FrmFieldsHelper::get_html_id( $field );
|
462 |
+
|
463 |
if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
|
464 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php');
|
465 |
} else {
|
466 |
+
FrmFieldsHelper::show_single_option($field);
|
|
|
|
|
|
|
|
|
467 |
}
|
468 |
+
|
469 |
+
wp_die();
|
470 |
}
|
471 |
|
472 |
+
public static function update_order() {
|
473 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
474 |
+
if ( isset($_POST) && isset($_POST['frm_field_id']) ) {
|
475 |
+
foreach ( $_POST['frm_field_id'] as $position => $item ) {
|
476 |
+
FrmField::update( $item, array( 'field_order' => $position ) );
|
477 |
+
}
|
478 |
}
|
479 |
+
wp_die();
|
480 |
}
|
|
|
|
|
|
|
481 |
|
482 |
+
public static function change_type($type) {
|
483 |
+
$type_switch = array(
|
484 |
+
'scale' => 'radio',
|
485 |
+
'10radio' => 'radio',
|
486 |
+
'rte' => 'textarea',
|
487 |
+
'website' => 'url',
|
488 |
+
);
|
489 |
+
if ( isset( $type_switch[ $type ] ) ) {
|
490 |
+
$type = $type_switch[ $type ];
|
491 |
+
}
|
492 |
+
|
493 |
$frm_field_selection = FrmFieldsHelper::field_selection();
|
494 |
$types = array_keys($frm_field_selection);
|
495 |
+
if ( ! in_array($type, $types) && $type != 'captcha' ) {
|
496 |
$type = 'text';
|
497 |
+
}
|
498 |
|
499 |
return $type;
|
500 |
}
|
501 |
+
|
502 |
+
public static function display_field_options($display) {
|
503 |
+
switch($display['type']) {
|
504 |
case 'captcha':
|
505 |
$display['required'] = false;
|
506 |
$display['invalid'] = true;
|
517 |
case 'select':
|
518 |
$display['size'] = true;
|
519 |
break;
|
520 |
+
case 'url':
|
521 |
+
case 'website':
|
522 |
+
case 'email':
|
523 |
+
$display['size'] = true;
|
524 |
+
$display['clear_on_focus'] = true;
|
525 |
+
$display['invalid'] = true;
|
526 |
}
|
527 |
+
|
528 |
return $display;
|
529 |
}
|
530 |
+
|
531 |
+
public static function input_html( $field, $echo = true ) {
|
532 |
+
$class = array(); //$field['type'];
|
533 |
+
self::add_input_classes($field, $class);
|
534 |
+
|
535 |
+
$add_html = array();
|
536 |
+
self::add_html_size($field, $add_html);
|
537 |
+
self::add_html_length($field, $add_html);
|
538 |
+
self::add_html_placeholder($field, $add_html, $class);
|
539 |
+
|
540 |
+
$class = apply_filters('frm_field_classes', implode(' ', $class), $field);
|
541 |
+
|
542 |
+
if ( ! empty($class) ) {
|
543 |
+
$add_html['class'] = 'class="'. trim($class) .'"';
|
544 |
+
}
|
545 |
+
|
546 |
+
self::add_shortcodes_to_html($field, $add_html);
|
547 |
+
|
548 |
+
$add_html = implode(' ', $add_html);
|
549 |
+
|
550 |
+
if ( $echo ) {
|
551 |
+
echo $add_html;
|
552 |
+
}
|
553 |
+
|
554 |
+
return $add_html;
|
555 |
+
}
|
556 |
+
|
557 |
+
private static function add_input_classes($field, array &$class) {
|
558 |
+
if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
|
559 |
+
return;
|
560 |
+
}
|
561 |
+
|
562 |
+
global $frm_vars;
|
563 |
+
if ( is_admin() && ! FrmAppHelper::is_preview_page() && ! in_array( $field['type'], array( 'scale', 'radio', 'checkbox', 'data' ) ) ) {
|
564 |
+
$class[] = 'dyn_default_value';
|
565 |
+
}
|
566 |
+
|
567 |
+
if ( isset($field['size']) && $field['size'] > 0 ) {
|
568 |
+
$class[] = 'auto_width';
|
569 |
+
}
|
570 |
+
|
571 |
+
if ( isset($field['input_class']) && ! empty($field['input_class']) ) {
|
572 |
+
$class[] = $field['input_class'];
|
573 |
+
}
|
574 |
+
}
|
575 |
+
|
576 |
+
private static function add_html_size($field, array &$add_html) {
|
577 |
+
if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden' ) ) ) {
|
578 |
+
return;
|
579 |
+
}
|
580 |
+
|
581 |
+
if ( FrmAppHelper::is_admin_page('formidable' ) ) {
|
582 |
+
return;
|
583 |
+
}
|
584 |
+
|
585 |
+
if ( is_numeric($field['size']) ) {
|
586 |
+
$field['size'] .= 'px';
|
587 |
+
}
|
588 |
+
|
589 |
+
$important = apply_filters('frm_use_important_width', 1, $field);
|
590 |
+
// Note: This inline styling must stay since we cannot realistically set a class for every possible field size
|
591 |
+
$add_html['style'] = 'style="width:'. esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) .'"';
|
592 |
+
|
593 |
+
self::add_html_cols($field, $add_html);
|
594 |
+
}
|
595 |
+
|
596 |
+
private static function add_html_cols($field, array &$add_html) {
|
597 |
+
if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
|
598 |
+
return;
|
599 |
+
}
|
600 |
+
|
601 |
+
// convert to cols for textareas
|
602 |
+
$calc = array(
|
603 |
+
'' => 9,
|
604 |
+
'px' => 9,
|
605 |
+
'rem' => 0.444,
|
606 |
+
'em' => 0.544,
|
607 |
+
);
|
608 |
+
|
609 |
+
// include "col" for valid html
|
610 |
+
$unit = trim(preg_replace('/[0-9]+/', '', $field['size']));
|
611 |
+
|
612 |
+
if ( ! isset( $calc[ $unit ] ) ) {
|
613 |
+
return;
|
614 |
+
}
|
615 |
+
|
616 |
+
$size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
|
617 |
+
|
618 |
+
$add_html['cols'] = 'cols="'. (int) $size .'"';
|
619 |
+
}
|
620 |
+
|
621 |
+
private static function add_html_length($field, array &$add_html) {
|
622 |
+
// check for max setting and if this field accepts maxlength
|
623 |
+
if ( ! isset( $field['max'] ) || empty( $field['max'] ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden' ) ) ) {
|
624 |
+
return;
|
625 |
+
}
|
626 |
+
|
627 |
+
if ( FrmAppHelper::is_admin_page('formidable' ) ) {
|
628 |
+
// don't load on form builder page
|
629 |
+
return;
|
630 |
+
}
|
631 |
+
|
632 |
+
$add_html['maxlength'] = 'maxlength="'. $field['max'] .'"';
|
633 |
+
}
|
634 |
+
|
635 |
+
private static function add_html_placeholder($field, array &$add_html, array &$class) {
|
636 |
+
// check for a default value and placeholder setting
|
637 |
+
if ( ! isset($field['clear_on_focus']) || ! $field['clear_on_focus'] || empty($field['default_value']) ) {
|
638 |
+
return;
|
639 |
+
}
|
640 |
+
|
641 |
+
// don't apply this to the form builder page
|
642 |
+
if ( FrmAppHelper::is_admin_page('formidable' ) ) {
|
643 |
+
return;
|
644 |
+
}
|
645 |
+
|
646 |
+
$frm_settings = FrmAppHelper::get_settings();
|
647 |
+
|
648 |
+
if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) {
|
649 |
+
// use HMTL5 placeholder with js fallback
|
650 |
+
$add_html['placeholder'] = 'placeholder="'. esc_attr($field['default_value']) .'"';
|
651 |
+
wp_enqueue_script('jquery-placeholder');
|
652 |
+
} else if ( ! $frm_settings->use_html ) {
|
653 |
+
$val = str_replace( array("\r\n", "\n"), '\r', addslashes(str_replace(''', "'", esc_attr($field['default_value']))));
|
654 |
+
$add_html['data-frmval'] = 'data-frmval="'. esc_attr($val) .'"';
|
655 |
+
$class[] = 'frm_toggle_default';
|
656 |
+
|
657 |
+
if ( $field['value'] == $field['default_value'] ) {
|
658 |
+
$class[] = 'frm_default';
|
659 |
}
|
660 |
}
|
661 |
+
}
|
662 |
+
|
663 |
+
private static function add_shortcodes_to_html( $field, array &$add_html ) {
|
664 |
+
if ( ! isset( $field['shortcodes'] ) || empty( $field['shortcodes'] ) ) {
|
665 |
+
return;
|
666 |
+
}
|
667 |
+
|
668 |
+
foreach ( $field['shortcodes'] as $k => $v ) {
|
669 |
+
if ( 'opt' === $k ) {
|
670 |
+
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
671 |
}
|
672 |
+
|
673 |
+
if ( is_numeric($k) && strpos($v, '=') ) {
|
674 |
+
$add_html[] = $v;
|
675 |
+
} else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
|
676 |
+
$add_html[ $k ] = str_replace( $k .'="', $k .'="'. $v, $add_html[ $k ] );
|
677 |
+
} else {
|
678 |
+
$add_html[ $k ] = $k .'="'. $v .'"';
|
679 |
+
}
|
680 |
+
|
681 |
+
unset($k, $v);
|
682 |
}
|
|
|
|
|
|
|
|
|
|
|
683 |
}
|
684 |
+
|
685 |
+
public static function check_value( $opt, $opt_key, $field ) {
|
686 |
+
if ( is_array( $opt ) ) {
|
687 |
+
if ( isset( $field['separate_value'] ) && $field['separate_value'] ) {
|
688 |
+
$opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
|
689 |
+
} else {
|
690 |
+
$opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
|
691 |
}
|
692 |
}
|
693 |
return $opt;
|
694 |
}
|
695 |
+
|
696 |
+
public static function check_label($opt) {
|
697 |
+
if ( is_array($opt) ) {
|
698 |
$opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
|
699 |
+
}
|
700 |
+
|
701 |
return $opt;
|
702 |
}
|
703 |
+
|
704 |
+
public static function add_conditional_update_msg() {
|
705 |
+
echo '<tr><td colspan="2">';
|
706 |
+
FrmAppHelper::update_message( 'calculate and conditionally hide and show fields' );
|
707 |
+
echo '</td></tr>';
|
708 |
+
}
|
709 |
}
|
classes/controllers/FrmFormActionsController.php
ADDED
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class FrmFormActionsController {
|
4 |
+
public static $action_post_type = 'frm_form_actions';
|
5 |
+
public static $registered_actions;
|
6 |
+
|
7 |
+
public static function register_post_types() {
|
8 |
+
register_post_type( self::$action_post_type, array(
|
9 |
+
'label' => __( 'Form Actions', 'formidable' ),
|
10 |
+
'description' => '',
|
11 |
+
'public' => false,
|
12 |
+
'show_ui' => false,
|
13 |
+
'exclude_from_search' => true,
|
14 |
+
'show_in_nav_menus' => false,
|
15 |
+
'show_in_menu' => true,
|
16 |
+
'capability_type' => 'page',
|
17 |
+
'supports' => array(
|
18 |
+
'title', 'editor', 'excerpt', 'custom-fields',
|
19 |
+
'page-attributes',
|
20 |
+
),
|
21 |
+
'has_archive' => false,
|
22 |
+
) );
|
23 |
+
|
24 |
+
/**
|
25 |
+
* post_content: json settings
|
26 |
+
* menu_order: form id
|
27 |
+
* post_excerpt: action type
|
28 |
+
*/
|
29 |
+
|
30 |
+
self::actions_init();
|
31 |
+
}
|
32 |
+
|
33 |
+
public static function actions_init() {
|
34 |
+
self::$registered_actions = new Frm_Form_Action_Factory();
|
35 |
+
self::register_actions();
|
36 |
+
do_action( 'frm_form_actions_init' );
|
37 |
+
}
|
38 |
+
|
39 |
+
public static function register_actions() {
|
40 |
+
$action_classes = apply_filters( 'frm_registered_form_actions', array(
|
41 |
+
'email' => 'FrmEmailAction',
|
42 |
+
'wppost' => 'FrmDefPostAction',
|
43 |
+
'register' => 'FrmDefRegAction',
|
44 |
+
'paypal' => 'FrmDefPayPalAction',
|
45 |
+
//'aweber' => 'FrmDefAweberAction',
|
46 |
+
'mailchimp' => 'FrmDefMlcmpAction',
|
47 |
+
'twilio' => 'FrmDefTwilioAction',
|
48 |
+
'highrise' => 'FrmDefHrsAction',
|
49 |
+
) );
|
50 |
+
|
51 |
+
include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php');
|
52 |
+
include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php');
|
53 |
+
|
54 |
+
foreach ( $action_classes as $action_class ) {
|
55 |
+
self::$registered_actions->register($action_class);
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
public static function get_form_actions($action = 'all' ) {
|
60 |
+
$temp_actions = self::$registered_actions;
|
61 |
+
if ( empty($temp_actions) ) {
|
62 |
+
self::actions_init();
|
63 |
+
$temp_actions = self::$registered_actions->actions;
|
64 |
+
} else {
|
65 |
+
$temp_actions = $temp_actions->actions;
|
66 |
+
}
|
67 |
+
|
68 |
+
$actions = array();
|
69 |
+
|
70 |
+
foreach ( $temp_actions as $a ) {
|
71 |
+
if ( 'all' != $action && $a->id_base == $action ) {
|
72 |
+
return $a;
|
73 |
+
}
|
74 |
+
|
75 |
+
$actions[$a->id_base] = $a;
|
76 |
+
}
|
77 |
+
unset( $temp_actions, $a );
|
78 |
+
|
79 |
+
$action_limit = 10;
|
80 |
+
if ( count( $actions ) <= $action_limit ) {
|
81 |
+
return $actions;
|
82 |
+
}
|
83 |
+
|
84 |
+
// remove the last few inactive icons if there are too many
|
85 |
+
$temp_actions = $actions;
|
86 |
+
arsort( $temp_actions );
|
87 |
+
foreach ( $temp_actions as $type => $a ) {
|
88 |
+
if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) {
|
89 |
+
unset( $actions[$type] );
|
90 |
+
if ( count( $actions ) <= $action_limit ) {
|
91 |
+
break;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
unset( $type, $a );
|
95 |
+
}
|
96 |
+
|
97 |
+
return $actions;
|
98 |
+
}
|
99 |
+
|
100 |
+
public static function list_actions( $form, $values ) {
|
101 |
+
if ( empty( $form ) ) {
|
102 |
+
return;
|
103 |
+
}
|
104 |
+
|
105 |
+
do_action( 'frm_before_list_actions', $form ); // use this hook to migrate old settings into a new action
|
106 |
+
|
107 |
+
$form_actions = FrmFormActionsHelper::get_action_for_form( $form->id );
|
108 |
+
|
109 |
+
$action_controls = self::get_form_actions();
|
110 |
+
|
111 |
+
$action_map = array();
|
112 |
+
|
113 |
+
foreach ( $action_controls as $key => $control ) {
|
114 |
+
$action_map[ $control->id_base ] = $key;
|
115 |
+
}
|
116 |
+
|
117 |
+
foreach ( $form_actions as $action ) {
|
118 |
+
if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
|
119 |
+
// don't try and show settings if action no longer exists
|
120 |
+
continue;
|
121 |
+
}
|
122 |
+
|
123 |
+
self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
public static function action_control($form_action, $form, $action_key, $action_control, $values) {
|
128 |
+
$action_control->_set($action_key);
|
129 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php');
|
130 |
+
}
|
131 |
+
|
132 |
+
public static function add_form_action() {
|
133 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
134 |
+
|
135 |
+
global $frm_vars;
|
136 |
+
|
137 |
+
$action_key = absint( $_POST['list_id'] );
|
138 |
+
$action_type = sanitize_text_field( $_POST['type'] );
|
139 |
+
|
140 |
+
$action_control = self::get_form_actions( $action_type );
|
141 |
+
$action_control->_set($action_key);
|
142 |
+
|
143 |
+
$form_id = absint( $_POST['form_id'] );
|
144 |
+
|
145 |
+
$form_action = $action_control->prepare_new($form_id);
|
146 |
+
|
147 |
+
$values = array();
|
148 |
+
$form = self::fields_to_values($form_id, $values);
|
149 |
+
|
150 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php');
|
151 |
+
wp_die();
|
152 |
+
}
|
153 |
+
|
154 |
+
public static function fill_action() {
|
155 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
156 |
+
|
157 |
+
$action_key = absint( $_POST['action_id'] );
|
158 |
+
$action_type = sanitize_text_field( $_POST['action_type'] );
|
159 |
+
|
160 |
+
$action_control = self::get_form_actions( $action_type );
|
161 |
+
if ( empty($action_control) ) {
|
162 |
+
wp_die();
|
163 |
+
}
|
164 |
+
|
165 |
+
$form_action = $action_control->get_single_action( $action_key );
|
166 |
+
|
167 |
+
$values = array();
|
168 |
+
$form = self::fields_to_values($form_action->menu_order, $values);
|
169 |
+
|
170 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/_action_inside.php');
|
171 |
+
wp_die();
|
172 |
+
}
|
173 |
+
|
174 |
+
private static function fields_to_values($form_id, array &$values) {
|
175 |
+
$form = FrmForm::getOne($form_id);
|
176 |
+
|
177 |
+
$values = array( 'fields' => array(), 'id' => $form->id);
|
178 |
+
|
179 |
+
$fields = FrmField::get_all_for_form($form->id);
|
180 |
+
foreach ( $fields as $k => $f ) {
|
181 |
+
$f = (array) $f;
|
182 |
+
$opts = (array) $f['field_options'];
|
183 |
+
$f = array_merge($opts, $f);
|
184 |
+
if ( ! isset( $f['post_field'] ) ) {
|
185 |
+
$f['post_field'] = '';
|
186 |
+
}
|
187 |
+
$values['fields'][] = $f;
|
188 |
+
unset($k, $f);
|
189 |
+
}
|
190 |
+
|
191 |
+
return $form;
|
192 |
+
}
|
193 |
+
|
194 |
+
public static function update_settings($form_id) {
|
195 |
+
global $wpdb;
|
196 |
+
|
197 |
+
$registered_actions = self::$registered_actions->actions;
|
198 |
+
|
199 |
+
$old_actions = FrmDb::get_col( $wpdb->posts, array( 'post_type' => self::$action_post_type, 'menu_order' => $form_id), 'ID' );
|
200 |
+
$new_actions = array();
|
201 |
+
|
202 |
+
foreach ( $registered_actions as $registered_action ) {
|
203 |
+
$action_ids = $registered_action->update_callback($form_id);
|
204 |
+
if ( ! empty( $action_ids ) ) {
|
205 |
+
$new_actions[] = $action_ids;
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
//Only use array_merge if there are new actions
|
210 |
+
if ( ! empty( $new_actions ) ) {
|
211 |
+
$new_actions = call_user_func_array( 'array_merge', $new_actions );
|
212 |
+
}
|
213 |
+
$old_actions = array_diff( $old_actions, $new_actions );
|
214 |
+
|
215 |
+
// delete any actions that were not included on the page
|
216 |
+
if ( ! empty( $old_actions ) ) {
|
217 |
+
foreach ( $old_actions as $old_id ) {
|
218 |
+
wp_delete_post( $old_id );
|
219 |
+
}
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) {
|
224 |
+
self::trigger_actions( 'create', $form_id, $entry_id, 'all', $args );
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* @param string $event
|
229 |
+
*/
|
230 |
+
public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
|
231 |
+
$form_actions = FrmFormActionsHelper::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type );
|
232 |
+
|
233 |
+
if ( empty( $form_actions ) ) {
|
234 |
+
return;
|
235 |
+
}
|
236 |
+
|
237 |
+
FrmFormsHelper::maybe_get_form( $form );
|
238 |
+
|
239 |
+
$link_settings = self::get_form_actions( $type );
|
240 |
+
if ( 'all' != $type ) {
|
241 |
+
$link_settings = array( $type => $link_settings );
|
242 |
+
}
|
243 |
+
|
244 |
+
$stored_actions = $action_priority = array();
|
245 |
+
|
246 |
+
foreach ( $form_actions as $action ) {
|
247 |
+
|
248 |
+
if ( ! in_array( $event, $action->post_content['event'] ) ) {
|
249 |
+
continue;
|
250 |
+
}
|
251 |
+
|
252 |
+
if ( ! is_object( $entry ) ) {
|
253 |
+
$entry = FrmEntry::getOne( $entry, true );
|
254 |
+
}
|
255 |
+
|
256 |
+
$child_entry = ( ! $form || ( is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ! $entry || $entry->form_id != $form->id || $entry->parent_item_id || ( isset( $args['is_child'] ) && $args['is_child'] ) );
|
257 |
+
|
258 |
+
if ( $child_entry ) {
|
259 |
+
//don't trigger actions for sub forms
|
260 |
+
continue;
|
261 |
+
}
|
262 |
+
|
263 |
+
if ( $entry->is_draft ) {
|
264 |
+
// TODO: add trigger actions for drafts
|
265 |
+
continue;
|
266 |
+
}
|
267 |
+
|
268 |
+
// check conditional logic
|
269 |
+
$stop = FrmFormActionsHelper::action_conditions_met($action, $entry);
|
270 |
+
if ( $stop ) {
|
271 |
+
continue;
|
272 |
+
}
|
273 |
+
|
274 |
+
// store actions so they can be triggered with the correct priority
|
275 |
+
$stored_actions[ $action->ID ] = $action;
|
276 |
+
$action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
|
277 |
+
|
278 |
+
unset($action);
|
279 |
+
}
|
280 |
+
|
281 |
+
if ( ! empty( $stored_actions ) ) {
|
282 |
+
asort($action_priority);
|
283 |
+
|
284 |
+
// make sure hooks are loaded
|
285 |
+
new FrmNotification();
|
286 |
+
|
287 |
+
foreach ( $action_priority as $action_id => $priority ) {
|
288 |
+
$action = $stored_actions[ $action_id ];
|
289 |
+
do_action('frm_trigger_'. $action->post_excerpt .'_action', $action, $entry, $form, $event);
|
290 |
+
do_action('frm_trigger_'. $action->post_excerpt .'_'. $event .'_action', $action, $entry, $form);
|
291 |
+
|
292 |
+
// If post is created, get updated $entry object
|
293 |
+
if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
|
294 |
+
$entry = FrmEntry::getOne($entry->id, true);
|
295 |
+
}
|
296 |
+
}
|
297 |
+
}
|
298 |
+
}
|
299 |
+
|
300 |
+
public static function duplicate_form_actions($form_id, $values, $args = array() ) {
|
301 |
+
if ( ! isset($args['old_id']) || empty($args['old_id']) ) {
|
302 |
+
// continue if we know which actions to copy
|
303 |
+
return;
|
304 |
+
}
|
305 |
+
|
306 |
+
$action_controls = self::get_form_actions( );
|
307 |
+
|
308 |
+
foreach ( $action_controls as $action_control ) {
|
309 |
+
$action_control->duplicate_form_actions( $form_id, $args['old_id'] );
|
310 |
+
unset( $action_control );
|
311 |
+
}
|
312 |
+
}
|
313 |
+
|
314 |
+
public static function limit_by_type( $where ) {
|
315 |
+
global $frm_vars, $wpdb;
|
316 |
+
|
317 |
+
if ( ! isset( $frm_vars['action_type'] ) ) {
|
318 |
+
return $where;
|
319 |
+
}
|
320 |
+
|
321 |
+
$where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
|
322 |
+
return $where;
|
323 |
+
}
|
324 |
+
|
325 |
+
}
|
326 |
+
|
327 |
+
|
328 |
+
class Frm_Form_Action_Factory {
|
329 |
+
public $actions = array();
|
330 |
+
|
331 |
+
public function __construct() {
|
332 |
+
add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
|
333 |
+
}
|
334 |
+
|
335 |
+
public function register($action_class) {
|
336 |
+
$this->actions[ $action_class ] = new $action_class();
|
337 |
+
}
|
338 |
+
|
339 |
+
public function unregister($action_class) {
|
340 |
+
if ( isset( $this->actions[ $action_class ] ) ) {
|
341 |
+
unset($this->actions[ $action_class ]);
|
342 |
+
}
|
343 |
+
}
|
344 |
+
|
345 |
+
public function _register_actions() {
|
346 |
+
$keys = array_keys($this->actions);
|
347 |
+
|
348 |
+
foreach ( $keys as $key ) {
|
349 |
+
// don't register new action if old action with the same id is already registered
|
350 |
+
if ( ! isset( $this->actions[ $key ] ) ) {
|
351 |
+
$this->actions[ $key ]->_register();
|
352 |
+
}
|
353 |
+
}
|
354 |
+
}
|
355 |
+
}
|
classes/controllers/FrmFormsController.php
CHANGED
@@ -1,364 +1,474 @@
|
|
1 |
<?php
|
2 |
-
/**
|
3 |
-
* @package Formidable
|
4 |
-
*/
|
5 |
-
|
6 |
-
if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
|
7 |
-
|
8 |
-
if(class_exists('FrmFormsController'))
|
9 |
-
return;
|
10 |
-
|
11 |
-
class FrmFormsController{
|
12 |
-
public static function load_hooks(){
|
13 |
-
add_action('admin_menu', 'FrmFormsController::menu', 10);
|
14 |
-
add_action('admin_menu', 'FrmFormsController::mid_menu', 40);
|
15 |
-
add_action('admin_head-toplevel_page_formidable', 'FrmFormsController::head');
|
16 |
-
add_action('widgets_init', 'FrmFormsController::register_widgets');
|
17 |
-
add_action('wp_ajax_frm_form_key_in_place_edit', 'FrmFormsController::edit_key');
|
18 |
-
add_action('wp_ajax_frm_form_desc_in_place_edit', 'FrmFormsController::edit_description');
|
19 |
-
add_action('wp_ajax_frm_delete_form_wo_fields', 'FrmFormsController::destroy_wo_fields');
|
20 |
-
add_action('frm_after_duplicate_form', 'FrmFormsController::after_duplicate', 10, 2);
|
21 |
-
add_action('wp_ajax_frm_save_form', 'FrmFormsController::route');
|
22 |
-
add_filter('frm_submit_button', 'FrmFormsController::submit_button_label');
|
23 |
-
add_filter('media_buttons_context', 'FrmFormsController::insert_form_button');
|
24 |
-
//add_action('media_buttons', 'FrmFormsController::show_form_button', 20);
|
25 |
-
add_action('admin_footer', 'FrmFormsController::insert_form_popup');
|
26 |
-
|
27 |
-
add_filter('set-screen-option', 'FrmFormsController::save_per_page', 10, 3);
|
28 |
-
|
29 |
-
add_action('wp_ajax_frm_forms_preview', 'FrmFormsController::preview');
|
30 |
-
add_action('wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview');
|
31 |
-
|
32 |
-
add_filter('frm_admin_list_form_action', 'FrmFormsController::process_bulk_form_actions');
|
33 |
-
|
34 |
-
add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' );
|
35 |
-
add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
|
36 |
-
|
37 |
-
//Shortcodes
|
38 |
-
add_shortcode('formidable', 'FrmFormsController::get_form_shortcode');
|
39 |
-
add_filter( 'widget_text', 'FrmFormsController::widget_text_filter', 9 );
|
40 |
-
}
|
41 |
-
|
42 |
-
public static function menu(){
|
43 |
-
global $frm_settings;
|
44 |
-
add_submenu_page('formidable', $frm_settings->menu .' | '. __('Forms', 'formidable'), __('Forms', 'formidable'), 'frm_view_forms', 'formidable', 'FrmFormsController::route');
|
45 |
-
|
46 |
-
add_action('admin_head-'. sanitize_title($frm_settings->menu) .'_page_formidable-templates', 'FrmFormsController::head');
|
47 |
-
|
48 |
-
add_filter('manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
|
49 |
-
add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-templates_columns', 'FrmFormsController::get_columns', 0 );
|
50 |
-
add_filter('manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns');
|
51 |
-
add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-templates_sortable_columns', 'FrmFormsController::get_sortable_columns');
|
52 |
-
add_filter('get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns');
|
53 |
-
add_filter('get_user_option_manage'. sanitize_title($frm_settings->menu) .'_page_formidable-templatescolumnshidden', 'FrmFormsController::hidden_columns');
|
54 |
-
}
|
55 |
-
|
56 |
-
public static function mid_menu(){
|
57 |
-
global $frm_settings;
|
58 |
-
add_submenu_page('formidable', $frm_settings->menu .' | '. __('Templates', 'formidable'), __('Templates', 'formidable'), 'frm_view_forms', 'formidable-templates', 'FrmFormsController::template_list');
|
59 |
-
}
|
60 |
-
|
61 |
-
public static function head(){
|
62 |
-
global $frm_settings;
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
wp_enqueue_script('formidable-editinplace');
|
65 |
-
|
|
|
|
|
|
|
66 |
}
|
67 |
-
|
68 |
-
public static function register_widgets(){
|
69 |
require_once(FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php');
|
70 |
register_widget('FrmShowForm');
|
71 |
}
|
72 |
-
|
73 |
-
public static function list_form(){
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
$
|
81 |
-
$errors = apply_filters('frm_admin_list_form_action', array());
|
82 |
-
return self::display_forms_list();
|
83 |
}
|
84 |
-
|
85 |
-
|
|
|
|
|
86 |
global $frm_vars;
|
87 |
-
|
88 |
$action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
if ($action == 'create'){
|
93 |
return self::create($values);
|
94 |
-
}else if ($action == 'new'){
|
95 |
-
$frm_field_selection = FrmFieldsHelper::field_selection();
|
96 |
$values = FrmFormsHelper::setup_new_vars($values);
|
97 |
-
$id =
|
98 |
-
$form =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
$values['id'] = $id;
|
100 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
|
101 |
-
}else{
|
102 |
-
$all_templates = $frm_form->getAll(array('is_template' => 1), 'name');
|
103 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new-selection.php');
|
104 |
}
|
105 |
}
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
110 |
$values = $_POST;
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
$
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
123 |
$hide_preview = true;
|
124 |
$frm_field_selection = FrmFieldsHelper::field_selection();
|
125 |
-
$form =
|
126 |
-
$fields =
|
|
|
127 |
$values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
|
|
|
|
|
128 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
|
129 |
-
}else{
|
130 |
-
|
131 |
die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id='. $id)));
|
132 |
-
//$message = __('Form was Successfully Created', 'formidable');
|
133 |
-
//return self::settings($record, $message);
|
134 |
}
|
135 |
}
|
136 |
-
|
137 |
-
public static function edit($values=false){
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
}
|
142 |
-
|
143 |
-
$id = isset($values['id']) ? (int)$values['id'] : (int)FrmAppHelper::get_param('id');
|
144 |
return self::get_edit_vars($id);
|
145 |
}
|
146 |
-
|
147 |
-
public static function settings($id=false, $message=''){
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
150 |
return self::get_settings_vars($id, '', $message);
|
151 |
}
|
152 |
-
|
153 |
-
public static function update_settings(){
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
if( count($errors) > 0 ){
|
160 |
return self::get_settings_vars($id, $errors);
|
161 |
-
}else{
|
162 |
-
$record = $frm_form->update( $_POST['id'], $_POST );
|
163 |
-
$message = __('Settings Successfully Updated', 'formidable');
|
164 |
-
return self::get_settings_vars($id, '', $message);
|
165 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
}
|
167 |
-
|
168 |
-
public static function edit_key(){
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
global $wpdb;
|
174 |
-
$values = array('form_key' => trim($_POST['update_value']));
|
175 |
-
|
176 |
-
|
177 |
-
$key =
|
178 |
-
echo stripslashes($key);
|
179 |
-
|
180 |
}
|
181 |
|
182 |
-
public static function edit_description(){
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
$
|
188 |
-
$form = $frm_form->update($_POST['form_id'], array('description' => $_POST['update_value']));
|
189 |
-
$description = stripslashes($_POST['update_value']);
|
190 |
-
if(apply_filters('frm_use_wpautop', true))
|
191 |
-
$description = wpautop(str_replace( '<br>', '<br />', $description));
|
192 |
echo $description;
|
193 |
-
|
194 |
}
|
195 |
-
|
196 |
-
public static function update($values=false){
|
197 |
-
$frm_form = new FrmForm();
|
198 |
|
199 |
-
|
|
|
200 |
$values = $_POST;
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
if (
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
$
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
218 |
}
|
219 |
-
return self::get_edit_vars($id, '', $message);
|
220 |
}
|
221 |
}
|
222 |
-
|
223 |
-
public static function
|
224 |
-
|
225 |
-
|
226 |
-
|
|
|
227 |
}
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
if ( $form ) {
|
235 |
return self::get_edit_vars($form, '', $message, true);
|
236 |
} else {
|
237 |
-
return self::display_forms_list($params, __('There was a problem creating new template.', 'formidable'));
|
238 |
-
}
|
239 |
-
}
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
$
|
249 |
-
|
250 |
-
|
251 |
-
$
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
do_action('frm_wp');
|
259 |
-
|
260 |
-
global $frm_settings, $frm_vars;
|
261 |
$frm_vars['preview'] = true;
|
262 |
-
|
263 |
-
|
264 |
-
if ( !defined( 'ABSPATH' ) && !defined( 'XMLRPC_REQUEST' )) {
|
265 |
global $wp;
|
266 |
-
$root = dirname(dirname(dirname(dirname(__FILE__))));
|
267 |
include_once( $root.'/wp-config.php' );
|
268 |
$wp->init();
|
269 |
$wp->register_globals();
|
270 |
}
|
271 |
-
|
272 |
-
if(
|
273 |
FrmProEntriesController::register_scripts();
|
274 |
-
|
275 |
-
|
|
|
276 |
|
277 |
$plugin = FrmAppHelper::get_param('plugin');
|
278 |
$controller = FrmAppHelper::get_param('controller');
|
279 |
$key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
|
280 |
-
$form =
|
281 |
-
if (
|
282 |
-
|
|
|
|
|
283 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/direct.php');
|
284 |
-
|
285 |
-
}
|
286 |
-
|
287 |
-
public static function
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
$
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
public static function insert_form_button($content){
|
320 |
-
if(current_user_can('frm_view_forms'))
|
321 |
-
$content .= '<a href="#TB_inline?width=450&height=550&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . __("Add Formidable Form", 'formidable') . '"><span class="frm-buttons-icon wp-media-buttons-icon"></span> '. __('Add Form', 'formidable') . '</a>';
|
322 |
-
return $content;
|
323 |
}
|
324 |
-
|
325 |
-
public static function
|
326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
327 |
return;
|
328 |
-
|
|
|
|
|
|
|
|
|
|
|
329 |
}
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
}
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
if(
|
346 |
-
$
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
$
|
361 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
|
363 |
$pagenum = $wp_list_table->get_pagenum();
|
364 |
|
@@ -369,217 +479,313 @@ class FrmFormsController{
|
|
369 |
wp_redirect( add_query_arg( 'paged', $total_pages ) );
|
370 |
die();
|
371 |
}
|
372 |
-
|
373 |
-
if ( ! empty( $_REQUEST['s'] ) )
|
374 |
-
$page_params .= '&s='. urlencode($_REQUEST['s']);
|
375 |
-
|
376 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/list.php');
|
377 |
}
|
378 |
-
|
379 |
-
public static function get_columns($columns){
|
380 |
$columns['cb'] = '<input type="checkbox" />';
|
381 |
-
|
382 |
-
|
383 |
-
$
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
$columns['
|
391 |
-
$columns['
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
|
|
|
|
|
|
397 |
return $columns;
|
398 |
}
|
399 |
-
|
400 |
public static function get_sortable_columns() {
|
401 |
return array(
|
402 |
-
'id'
|
403 |
-
'name'
|
404 |
'description' => 'description',
|
405 |
-
'form_key'
|
406 |
-
'created_at'
|
407 |
);
|
408 |
}
|
409 |
-
|
410 |
-
public static function hidden_columns($result){
|
411 |
$return = false;
|
412 |
-
foreach((array)$result as $r){
|
413 |
-
if(!empty($r)){
|
414 |
$return = true;
|
415 |
break;
|
416 |
}
|
417 |
}
|
418 |
-
|
419 |
-
if($return)
|
420 |
return $result;
|
|
|
|
|
|
|
421 |
|
422 |
$result[] = 'created_at';
|
423 |
-
if($
|
424 |
$result[] = 'id';
|
425 |
$result[] = 'form_key';
|
426 |
-
}
|
427 |
-
|
428 |
return $result;
|
429 |
}
|
430 |
-
|
431 |
-
public static function save_per_page($save, $option, $value){
|
432 |
-
if($option == 'formidable_page_formidable_per_page'
|
433 |
-
$save = (int)$value;
|
|
|
434 |
return $save;
|
435 |
}
|
436 |
|
437 |
-
private static function get_edit_vars($id, $errors = '', $message='', $create_link=false){
|
438 |
-
global $
|
439 |
-
|
440 |
-
$form =
|
441 |
-
if (
|
442 |
-
wp_die( __('You are trying to edit a form that does not exist.', 'formidable') );
|
443 |
}
|
444 |
-
|
|
|
|
|
|
|
|
|
445 |
$frm_field_selection = FrmFieldsHelper::field_selection();
|
446 |
-
$fields =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
$values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
|
448 |
-
|
449 |
-
$edit_message = __('Form was Successfully Updated', 'formidable');
|
450 |
if ( $form->is_template && $message == $edit_message ) {
|
451 |
-
$message = __('Template was Successfully Updated', 'formidable');
|
452 |
}
|
453 |
-
|
|
|
|
|
454 |
if ( $form->default_template ) {
|
455 |
-
wp_die(__('That template cannot be edited', 'formidable'));
|
456 |
} else if ( defined('DOING_AJAX') ) {
|
457 |
-
|
458 |
} else if ( $create_link ) {
|
459 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
|
460 |
} else {
|
461 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/edit.php');
|
462 |
}
|
463 |
}
|
464 |
-
|
465 |
-
public static function get_settings_vars($id, $errors = '', $message=''){
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
|
|
|
|
|
|
470 |
$values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
$sections = apply_filters('frm_add_form_settings_section', array(), $values);
|
472 |
-
$pro_feature =
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
}
|
478 |
-
|
479 |
-
public static function
|
480 |
-
$
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
493 |
}
|
|
|
494 |
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
$bulkaction = $_POST['bulkaction2'];
|
510 |
}
|
|
|
|
|
511 |
}
|
512 |
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
536 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
return $errors;
|
538 |
}
|
539 |
-
|
540 |
-
public static function add_default_templates($path, $default=true, $template=true){
|
541 |
_deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' );
|
542 |
-
|
543 |
-
global $frm_field;
|
544 |
$path = untrailingslashit(trim($path));
|
545 |
-
$templates = glob($path.
|
546 |
-
|
547 |
-
$
|
548 |
-
|
549 |
-
$
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
|
|
|
|
|
|
555 |
$values = FrmFormsHelper::setup_new_vars();
|
556 |
$values['form_key'] = $filename;
|
557 |
$values['is_template'] = $template;
|
558 |
$values['status'] = 'published';
|
559 |
-
if($default)
|
560 |
-
|
561 |
-
|
562 |
-
|
|
|
|
|
563 |
//get updated form
|
564 |
-
if ( isset($form) && $form ) {
|
565 |
-
$
|
|
|
566 |
} else {
|
567 |
-
$
|
|
|
|
|
|
|
|
|
|
|
568 |
}
|
569 |
-
|
570 |
-
if($form)
|
571 |
-
do_action('frm_after_duplicate_form', $form->id, (array)$form);
|
572 |
}
|
573 |
}
|
574 |
|
575 |
-
public static function route(){
|
576 |
$action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
|
577 |
-
$vars =
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
wp_die($frm_settings->admin_permission);
|
582 |
-
}
|
583 |
$json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('"', '\\\"', $_POST['frm_compact_fields'] ))));
|
584 |
$json_vars = json_decode($json_vars, true);
|
585 |
if ( empty($json_vars) ) {
|
@@ -588,100 +794,103 @@ class FrmFormsController{
|
|
588 |
if ( 'edit' == $action ) {
|
589 |
$action = 'update';
|
590 |
}
|
591 |
-
|
592 |
-
add_filter('frm_validate_form',
|
593 |
} else {
|
594 |
$vars = FrmAppHelper::json_to_array($json_vars);
|
595 |
-
$action = $vars[$action];
|
|
|
|
|
596 |
}
|
597 |
-
}else{
|
598 |
$action = FrmAppHelper::get_param($action);
|
|
|
|
|
|
|
|
|
599 |
}
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
if(
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
return self::list_form();
|
635 |
-
}else{
|
636 |
return self::display_forms_list();
|
637 |
-
}
|
638 |
}
|
639 |
}
|
640 |
-
|
641 |
-
public static function json_error($errors) {
|
642 |
-
$errors['json'] = __('Abnormal HTML characters prevented your form from saving correctly', 'formidable');
|
643 |
return $errors;
|
644 |
}
|
645 |
-
|
646 |
-
|
647 |
/* FRONT-END FORMS */
|
648 |
public static function admin_bar_css() {
|
649 |
FrmAppController::load_wp_admin_style();
|
650 |
}
|
651 |
-
|
652 |
public static function admin_bar_configure() {
|
653 |
if ( is_admin() || !current_user_can('frm_edit_forms') ) {
|
654 |
return;
|
655 |
}
|
656 |
-
|
657 |
global $frm_vars;
|
658 |
if ( empty($frm_vars['forms_loaded']) ) {
|
659 |
return;
|
660 |
}
|
661 |
-
|
662 |
$actions = array();
|
663 |
-
foreach ($frm_vars['forms_loaded'] as $form ) {
|
664 |
if ( is_object($form) ) {
|
665 |
-
$actions[$form->id] = $form->name;
|
666 |
}
|
667 |
unset($form);
|
668 |
}
|
669 |
-
|
670 |
if ( empty($actions) ) {
|
671 |
return;
|
672 |
}
|
673 |
-
|
674 |
asort($actions);
|
675 |
-
|
676 |
global $wp_admin_bar;
|
677 |
-
|
678 |
if ( count($actions) == 1 ) {
|
679 |
$wp_admin_bar->add_menu( array(
|
680 |
'title' => 'Edit Form',
|
681 |
'href' => admin_url('admin.php?page=formidable&frm_action=edit&id='. current( array_keys( $actions ) )),
|
682 |
-
'id' => 'frm-forms'
|
683 |
) );
|
684 |
-
} else {
|
685 |
$wp_admin_bar->add_menu( array(
|
686 |
'id' => 'frm-forms',
|
687 |
'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Edit Forms', 'formidable' ) . '</span>',
|
@@ -690,21 +899,19 @@ class FrmFormsController{
|
|
690 |
'title' => __( 'Edit Forms', 'formidable' ),
|
691 |
),
|
692 |
) );
|
693 |
-
|
694 |
foreach ( $actions as $form_id => $name ) {
|
695 |
|
696 |
$wp_admin_bar->add_menu( array(
|
697 |
'parent' => 'frm-forms',
|
698 |
'id' => 'edit_form_'. $form_id,
|
699 |
-
'title' => empty($name) ? __('(no title)') : $name,
|
700 |
'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id='. $form_id )
|
701 |
) );
|
702 |
}
|
703 |
-
}
|
704 |
}
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
//formidable shortcode
|
709 |
public static function get_form_shortcode($atts) {
|
710 |
global $frm_vars;
|
@@ -715,101 +922,153 @@ class FrmFormsController{
|
|
715 |
}
|
716 |
return $sc .']';
|
717 |
}
|
718 |
-
|
719 |
-
$shortcode_atts = shortcode_atts(array(
|
720 |
'id' => '', 'key' => '', 'title' => false, 'description' => false,
|
721 |
'readonly' => false, 'entry_id' => false, 'fields' => array(),
|
722 |
'exclude_fields' => array(), 'minimize' => false,
|
723 |
), $atts);
|
724 |
do_action('formidable_shortcode_atts', $shortcode_atts, $atts);
|
725 |
-
|
726 |
-
return self::show_form(
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
public static function show_form($id = '', $key = '', $title = false, $description = false, $atts = array()) {
|
736 |
-
global $frm_settings, $post;
|
737 |
-
|
738 |
-
$frm_form = new FrmForm();
|
739 |
-
if ( empty($id) ) {
|
740 |
$id = $key;
|
741 |
}
|
742 |
-
|
743 |
// no form id or key set
|
744 |
-
if ( empty($id) ) {
|
745 |
-
return __('Please select a valid form', 'formidable');
|
746 |
}
|
747 |
-
|
748 |
-
$form =
|
749 |
-
if (
|
750 |
-
return __('Please select a valid form', 'formidable');
|
751 |
}
|
752 |
-
|
753 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
754 |
// don't show a draft form on a page
|
755 |
-
|
756 |
-
|
|
|
757 |
}
|
758 |
-
|
759 |
// don't show the form if user should be logged in
|
760 |
-
if ( $form->logged_in && !is_user_logged_in() ) {
|
761 |
-
return do_shortcode($frm_settings->login_msg);
|
762 |
}
|
763 |
-
|
764 |
// don't show the form if user doesn't have permission
|
765 |
-
if ( $form->logged_in && get_current_user_id() && isset($form->options['logged_in_role']) && $form->options['logged_in_role'] != '' && !FrmAppHelper::user_has_permission($form->options['logged_in_role']) ) {
|
766 |
-
return do_shortcode($frm_settings->login_msg);
|
767 |
}
|
768 |
-
|
769 |
-
$form = self::get_form($form, $title, $description, $atts);
|
770 |
-
|
771 |
// check for external shortcodes
|
772 |
-
$form = do_shortcode($form);
|
773 |
-
|
774 |
return $form;
|
775 |
}
|
776 |
-
|
777 |
-
public static function get_form($form, $title, $description, $atts = array()) {
|
778 |
-
global $frm_field, $frm_entry, $frm_entry_meta, $frm_settings, $frm_vars;
|
779 |
-
$form_name = $form->name;
|
780 |
|
781 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
782 |
$submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
|
783 |
-
|
784 |
-
|
785 |
$user_ID = get_current_user_id();
|
786 |
-
|
787 |
$params = FrmEntriesController::get_params($form);
|
788 |
|
789 |
$message = $errors = '';
|
790 |
|
791 |
-
FrmEntriesHelper::enqueue_scripts($params);
|
792 |
-
|
793 |
if ( $params['posted_form_id'] == $form->id && $_POST ) {
|
794 |
-
$errors = isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['errors'] : array();
|
795 |
-
}
|
796 |
-
|
797 |
-
$fields = FrmFieldsHelper::get_form_fields($form->id, (isset($errors) && !empty($errors)));
|
798 |
-
|
799 |
-
$
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
$contents = ob_get_contents();
|
805 |
-
ob_end_clean();
|
806 |
-
// check if minimizing is turned on
|
807 |
-
if ( isset($atts['minimize']) && !empty($atts['minimize']) ) {
|
808 |
-
$contents = str_replace(array("\r\n", "\r", "\n", "\t", " "), '', $contents);
|
809 |
}
|
810 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
811 |
}
|
812 |
-
return false;
|
813 |
-
}
|
814 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
815 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
class FrmFormsController {
|
4 |
+
|
5 |
+
public static function trigger_load_form_hooks() {
|
6 |
+
FrmHooksController::trigger_load_hook( 'load_form_hooks' );
|
7 |
+
}
|
8 |
+
|
9 |
+
/**
|
10 |
+
* The hooks only needed when a form is loaded
|
11 |
+
*/
|
12 |
+
public static function load_form_hooks() {
|
13 |
+
add_filter('frm_form_classes', 'FrmFormsController::form_classes' );
|
14 |
+
}
|
15 |
+
|
16 |
+
public static function menu() {
|
17 |
+
add_submenu_page('formidable', 'Formidable | '. __( 'Forms', 'formidable' ), __( 'Forms', 'formidable' ), 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
|
18 |
+
|
19 |
+
add_filter('get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' );
|
20 |
+
|
21 |
+
add_filter('manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
|
22 |
+
add_filter('manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
|
23 |
+
}
|
24 |
+
|
25 |
+
public static function head() {
|
26 |
wp_enqueue_script('formidable-editinplace');
|
27 |
+
|
28 |
+
if ( wp_is_mobile() ) {
|
29 |
+
wp_enqueue_script( 'jquery-touch-punch' );
|
30 |
+
}
|
31 |
}
|
32 |
+
|
33 |
+
public static function register_widgets() {
|
34 |
require_once(FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php');
|
35 |
register_widget('FrmShowForm');
|
36 |
}
|
37 |
+
|
38 |
+
public static function list_form() {
|
39 |
+
FrmAppHelper::permission_check('frm_view_forms');
|
40 |
+
|
41 |
+
$params = FrmFormsHelper::get_params();
|
42 |
+
$errors = self::process_bulk_form_actions( array());
|
43 |
+
$errors = apply_filters('frm_admin_list_form_action', $errors);
|
44 |
+
|
45 |
+
return self::display_forms_list($params, '', false, $errors);
|
|
|
|
|
46 |
}
|
47 |
+
|
48 |
+
public static function new_form( $values = array() ) {
|
49 |
+
FrmAppHelper::permission_check('frm_edit_forms');
|
50 |
+
|
51 |
global $frm_vars;
|
52 |
+
|
53 |
$action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
|
54 |
+
$action = empty( $values ) ? sanitize_title( FrmAppHelper::get_param( $action ) ) : $values[ $action ];
|
55 |
+
|
56 |
+
if ($action == 'create') {
|
|
|
57 |
return self::create($values);
|
58 |
+
} else if ($action == 'new') {
|
59 |
+
$frm_field_selection = FrmFieldsHelper::field_selection();
|
60 |
$values = FrmFormsHelper::setup_new_vars($values);
|
61 |
+
$id = FrmForm::create( $values );
|
62 |
+
$form = FrmForm::getOne($id);
|
63 |
+
|
64 |
+
// add default email notification
|
65 |
+
$action_control = FrmFormActionsController::get_form_actions( 'email' );
|
66 |
+
$action_control->create($form->id);
|
67 |
+
|
68 |
+
$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
|
69 |
+
|
70 |
$values['id'] = $id;
|
71 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
|
|
|
|
|
|
|
72 |
}
|
73 |
}
|
74 |
+
|
75 |
+
public static function create( $values = array() ) {
|
76 |
+
FrmAppHelper::permission_check('frm_edit_forms');
|
77 |
+
|
78 |
+
global $frm_vars;
|
79 |
+
if ( empty( $values ) ) {
|
80 |
$values = $_POST;
|
81 |
+
}
|
82 |
+
|
83 |
+
//Set radio button and checkbox meta equal to "other" value
|
84 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
85 |
+
$values = FrmProEntry::mod_other_vals( $values, 'back' );
|
86 |
+
}
|
87 |
+
|
88 |
+
$id = isset($values['id']) ? absint( $values['id'] ) : absint( FrmAppHelper::get_param( 'id' ) );
|
89 |
+
|
90 |
+
if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) {
|
91 |
+
$frm_settings = FrmAppHelper::get_settings();
|
92 |
+
$errors = array( 'form' => $frm_settings->admin_permission );
|
93 |
+
} else {
|
94 |
+
$errors = FrmForm::validate($values);
|
95 |
+
}
|
96 |
+
|
97 |
+
if ( count($errors) > 0 ) {
|
98 |
$hide_preview = true;
|
99 |
$frm_field_selection = FrmFieldsHelper::field_selection();
|
100 |
+
$form = FrmForm::getOne( $id );
|
101 |
+
$fields = FrmField::get_all_for_form($id);
|
102 |
+
|
103 |
$values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
|
104 |
+
$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
|
105 |
+
|
106 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
|
107 |
+
} else {
|
108 |
+
FrmForm::update( $id, $values, true );
|
109 |
die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id='. $id)));
|
|
|
|
|
110 |
}
|
111 |
}
|
112 |
+
|
113 |
+
public static function edit( $values = false ) {
|
114 |
+
FrmAppHelper::permission_check('frm_edit_forms');
|
115 |
+
|
116 |
+
$id = isset( $values['id'] ) ? absint( $values['id'] ) : absint( FrmAppHelper::get_param( 'id' ) );
|
|
|
|
|
|
|
117 |
return self::get_edit_vars($id);
|
118 |
}
|
119 |
+
|
120 |
+
public static function settings( $id = false, $message = '' ) {
|
121 |
+
FrmAppHelper::permission_check('frm_edit_forms');
|
122 |
+
|
123 |
+
if ( ! $id || ! is_numeric($id) ) {
|
124 |
+
$id = absint( FrmAppHelper::get_param( 'id' ) );
|
125 |
+
}
|
126 |
return self::get_settings_vars($id, '', $message);
|
127 |
}
|
128 |
+
|
129 |
+
public static function update_settings() {
|
130 |
+
FrmAppHelper::permission_check('frm_edit_forms');
|
131 |
+
|
132 |
+
$id = absint( FrmAppHelper::get_param( 'id' ) );
|
133 |
+
|
134 |
+
$errors = FrmForm::validate($_POST);
|
135 |
+
if ( count($errors) > 0 ) {
|
136 |
return self::get_settings_vars($id, $errors);
|
|
|
|
|
|
|
|
|
137 |
}
|
138 |
+
|
139 |
+
do_action('frm_before_update_form_settings', $id);
|
140 |
+
|
141 |
+
FrmForm::update( $id, $_POST );
|
142 |
+
|
143 |
+
$message = __( 'Settings Successfully Updated', 'formidable' );
|
144 |
+
return self::get_settings_vars($id, '', $message);
|
145 |
}
|
146 |
+
|
147 |
+
public static function edit_key() {
|
148 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
149 |
+
FrmAppHelper::permission_check('frm_edit_forms', 'hide');
|
150 |
+
|
|
|
151 |
global $wpdb;
|
152 |
+
$values = array( 'form_key' => trim($_POST['update_value']));
|
153 |
+
|
154 |
+
FrmForm::update($_POST['form_id'], $values);
|
155 |
+
$key = FrmForm::getKeyById($_POST['form_id']);
|
156 |
+
echo stripslashes($key);
|
157 |
+
wp_die();
|
158 |
}
|
159 |
|
160 |
+
public static function edit_description() {
|
161 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
162 |
+
FrmAppHelper::permission_check('frm_edit_forms', 'hide');
|
163 |
+
|
164 |
+
FrmForm::update($_POST['form_id'], array( 'description' => $_POST['update_value']));
|
165 |
+
$description = FrmAppHelper::use_wpautop(stripslashes($_POST['update_value']));
|
|
|
|
|
|
|
|
|
166 |
echo $description;
|
167 |
+
wp_die();
|
168 |
}
|
|
|
|
|
|
|
169 |
|
170 |
+
public static function update( $values = array() ) {
|
171 |
+
if ( empty( $values ) ) {
|
172 |
$values = $_POST;
|
173 |
+
}
|
174 |
+
|
175 |
+
//Set radio button and checkbox meta equal to "other" value
|
176 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
177 |
+
$values = FrmProEntry::mod_other_vals( $values, 'back' );
|
178 |
+
}
|
179 |
+
|
180 |
+
$errors = FrmForm::validate( $values );
|
181 |
+
$permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
|
182 |
+
if ( $permission_error !== false ) {
|
183 |
+
$errors['form'] = $permission_error;
|
184 |
+
}
|
185 |
+
|
186 |
+
$id = isset( $values['id'] ) ? (int) $values['id'] : (int) FrmAppHelper::get_param( 'id' );
|
187 |
+
|
188 |
+
if ( count( $errors ) > 0 ) {
|
189 |
+
return self::get_edit_vars( $id, $errors );
|
190 |
+
} else {
|
191 |
+
FrmForm::update( $id, $values );
|
192 |
+
$message = __( 'Form was Successfully Updated', 'formidable' );
|
193 |
+
if ( defined( 'DOING_AJAX' ) ) {
|
194 |
+
die( $message );
|
195 |
}
|
196 |
+
return self::get_edit_vars( $id, '', $message );
|
197 |
}
|
198 |
}
|
199 |
+
|
200 |
+
public static function bulk_create_template( $ids ) {
|
201 |
+
FrmAppHelper::permission_check( 'frm_edit_forms' );
|
202 |
+
|
203 |
+
foreach ( $ids as $id ) {
|
204 |
+
FrmForm::duplicate( $id, true, true );
|
205 |
}
|
206 |
+
|
207 |
+
return __( 'Form template was Successfully Created', 'formidable' );
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Redirect to the url for creating from a template
|
212 |
+
* Also delete the current form
|
213 |
+
* @since 2.0
|
214 |
+
*/
|
215 |
+
public static function _create_from_template() {
|
216 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
217 |
+
|
218 |
+
$current_form = (int) FrmAppHelper::get_param( 'this_form' );
|
219 |
+
$template_id = (int) FrmAppHelper::get_param( 'id' );
|
220 |
+
|
221 |
+
if ( $current_form ) {
|
222 |
+
FrmForm::destroy( $current_form );
|
223 |
+
}
|
224 |
+
|
225 |
+
echo admin_url( 'admin.php?page=formidable&action=duplicate&id=' . $template_id );
|
226 |
+
wp_die();
|
227 |
+
}
|
228 |
+
|
229 |
+
public static function duplicate() {
|
230 |
+
FrmAppHelper::permission_check('frm_edit_forms');
|
231 |
+
|
232 |
+
$params = FrmFormsHelper::get_params();
|
233 |
+
$form = FrmForm::duplicate( $params['id'], $params['template'], true );
|
234 |
+
$message = ($params['template']) ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
|
235 |
if ( $form ) {
|
236 |
return self::get_edit_vars($form, '', $message, true);
|
237 |
} else {
|
238 |
+
return self::display_forms_list($params, __( 'There was a problem creating new template.', 'formidable' ));
|
239 |
+
}
|
240 |
+
}
|
241 |
+
|
242 |
+
public static function page_preview() {
|
243 |
+
$params = FrmFormsHelper::get_params();
|
244 |
+
if ( ! $params['form'] ) {
|
245 |
+
return;
|
246 |
+
}
|
247 |
+
|
248 |
+
$form = FrmForm::getOne( $params['form'] );
|
249 |
+
if ( ! $form ) {
|
250 |
+
return;
|
251 |
+
}
|
252 |
+
return self::show_form( $form->id, '', true, true );
|
253 |
+
}
|
254 |
+
|
255 |
+
public static function preview() {
|
256 |
+
do_action( 'frm_wp' );
|
257 |
+
|
258 |
+
global $frm_vars;
|
|
|
|
|
|
|
259 |
$frm_vars['preview'] = true;
|
260 |
+
|
261 |
+
if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) {
|
|
|
262 |
global $wp;
|
263 |
+
$root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
|
264 |
include_once( $root.'/wp-config.php' );
|
265 |
$wp->init();
|
266 |
$wp->register_globals();
|
267 |
}
|
268 |
+
|
269 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
270 |
FrmProEntriesController::register_scripts();
|
271 |
+
}
|
272 |
+
|
273 |
+
header( 'Content-Type: text/html; charset='. get_option( 'blog_charset' ) );
|
274 |
|
275 |
$plugin = FrmAppHelper::get_param('plugin');
|
276 |
$controller = FrmAppHelper::get_param('controller');
|
277 |
$key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
|
278 |
+
$form = FrmForm::getAll( array( 'form_key' => $key), '', 1);
|
279 |
+
if ( empty($form) ) {
|
280 |
+
$form = FrmForm::getAll( array(), '', 1 );
|
281 |
+
}
|
282 |
+
|
283 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/direct.php');
|
284 |
+
wp_die();
|
285 |
+
}
|
286 |
+
|
287 |
+
public static function untrash() {
|
288 |
+
FrmFormsHelper::change_form_status('untrash');
|
289 |
+
}
|
290 |
+
|
291 |
+
public static function bulk_untrash($ids) {
|
292 |
+
FrmAppHelper::permission_check('frm_edit_forms');
|
293 |
+
|
294 |
+
$count = FrmForm::set_status( $ids, 'published' );
|
295 |
+
|
296 |
+
$message = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
|
297 |
+
return $message;
|
298 |
+
}
|
299 |
+
|
300 |
+
public static function trash() {
|
301 |
+
FrmFormsHelper::change_form_status('trash');
|
302 |
+
}
|
303 |
+
|
304 |
+
public static function bulk_trash($ids) {
|
305 |
+
FrmAppHelper::permission_check('frm_delete_forms');
|
306 |
+
|
307 |
+
$count = 0;
|
308 |
+
foreach ( $ids as $id ) {
|
309 |
+
if ( FrmForm::trash( $id ) ) {
|
310 |
+
$count++;
|
311 |
+
}
|
312 |
+
}
|
313 |
+
|
314 |
+
$current_page = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
|
315 |
+
$message = sprintf(_n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="'. esc_url(wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type='. $current_page .'&item-action[]='. implode('item-action[]=', $ids), 'bulk-toplevel_page_formidable' )) .'">', '</a>' );
|
316 |
+
|
317 |
+
return $message;
|
|
|
|
|
|
|
|
|
|
|
318 |
}
|
319 |
+
|
320 |
+
public static function destroy() {
|
321 |
+
FrmAppHelper::permission_check('frm_delete_forms');
|
322 |
+
|
323 |
+
$params = FrmFormsHelper::get_params();
|
324 |
+
|
325 |
+
//check nonce url
|
326 |
+
check_admin_referer('destroy_form_' . $params['id']);
|
327 |
+
|
328 |
+
$count = 0;
|
329 |
+
if ( FrmForm::destroy( $params['id'] ) ) {
|
330 |
+
$count++;
|
331 |
+
}
|
332 |
+
|
333 |
+
$message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
|
334 |
+
|
335 |
+
self::display_forms_list($params, $message, 1);
|
336 |
+
}
|
337 |
+
|
338 |
+
public static function bulk_destroy($ids) {
|
339 |
+
FrmAppHelper::permission_check('frm_delete_forms');
|
340 |
+
|
341 |
+
$count = 0;
|
342 |
+
foreach ( $ids as $id ) {
|
343 |
+
$d = FrmForm::destroy( $id );
|
344 |
+
if ( $d ) {
|
345 |
+
$count++;
|
346 |
+
}
|
347 |
+
}
|
348 |
+
|
349 |
+
$message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
|
350 |
+
|
351 |
+
return $message;
|
352 |
+
}
|
353 |
+
|
354 |
+
private static function delete_all() {
|
355 |
+
//check nonce url
|
356 |
+
$permission_error = FrmAppHelper::permission_nonce_error('frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable');
|
357 |
+
if ( $permission_error !== false ) {
|
358 |
+
self::display_forms_list( array(), '', 1, array( $permission_error ) );
|
359 |
return;
|
360 |
+
}
|
361 |
+
|
362 |
+
$count = self::scheduled_delete(time());
|
363 |
+
$message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
|
364 |
+
|
365 |
+
self::display_forms_list( array(), $message, 1 );
|
366 |
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
* Delete trashed forms based on how long they have been trashed
|
370 |
+
* @return int The number of forms deleted
|
371 |
+
*/
|
372 |
+
public static function scheduled_delete($delete_timestamp = '') {
|
373 |
+
global $wpdb;
|
374 |
+
|
375 |
+
$trash_forms = FrmDb::get_results($wpdb->prefix .'frm_forms', array( 'status' => 'trash'), 'id, options' );
|
376 |
+
|
377 |
+
if ( ! $trash_forms ) {
|
378 |
+
return;
|
379 |
+
}
|
380 |
+
|
381 |
+
if ( empty($delete_timestamp) ) {
|
382 |
+
$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
|
383 |
+
}
|
384 |
+
|
385 |
+
$count = 0;
|
386 |
+
foreach ( $trash_forms as $form ) {
|
387 |
+
$form->options = maybe_unserialize($form->options);
|
388 |
+
if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
|
389 |
+
FrmForm::destroy($form->id);
|
390 |
+
$count++;
|
391 |
}
|
392 |
+
|
393 |
+
unset($form);
|
394 |
+
}
|
395 |
+
return $count;
|
396 |
+
}
|
397 |
+
|
398 |
+
public static function insert_form_button($content) {
|
399 |
+
if ( current_user_can('frm_view_forms') ) {
|
400 |
+
$content .= '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . __( 'Add forms and content', 'formidable' ) . '"><span class="frm-buttons-icon wp-media-buttons-icon"></span> Formidable</a>';
|
401 |
+
|
402 |
+
}
|
403 |
+
return $content;
|
404 |
+
}
|
405 |
+
|
406 |
+
public static function insert_form_popup() {
|
407 |
+
$page = basename($_SERVER['PHP_SELF']);
|
408 |
+
if ( ! in_array($page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php') ) ) {
|
409 |
+
return;
|
410 |
+
}
|
411 |
+
|
412 |
+
FrmAppHelper::load_admin_wide_js();
|
413 |
+
|
414 |
+
$shortcodes = array(
|
415 |
+
'formidable' => array( 'name' => __( 'Form', 'formidable' ), 'label' => __( 'Insert a Form', 'formidable' )),
|
416 |
+
);
|
417 |
+
|
418 |
+
$shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes);
|
419 |
+
|
420 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/insert_form_popup.php');
|
421 |
+
}
|
422 |
+
|
423 |
+
public static function get_shortcode_opts() {
|
424 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
425 |
+
|
426 |
+
$shortcode = sanitize_text_field( $_POST['shortcode'] );
|
427 |
+
if ( empty($shortcode) ) {
|
428 |
+
wp_die();
|
429 |
+
}
|
430 |
+
|
431 |
+
echo '<div id="sc-opts-'. esc_attr( $shortcode ) .'" class="frm_shortcode_option">';
|
432 |
+
echo '<input type="radio" name="frmsc" value="'. esc_attr($shortcode) .'" id="sc-'. esc_attr($shortcode) .'" class="frm_hidden" />';
|
433 |
+
|
434 |
+
$form_id = '';
|
435 |
+
$opts = array();
|
436 |
+
switch( $shortcode ) {
|
437 |
+
case 'formidable':
|
438 |
+
$opts = array(
|
439 |
+
'form_id' => 'id',
|
440 |
+
//'key' => ',
|
441 |
+
'title' => array( 'val' => 1, 'label' => __( 'Display form title', 'formidable' )),
|
442 |
+
'description' => array( 'val' => 1, 'label' => __( 'Display form description', 'formidable' )),
|
443 |
+
'minimize' => array( 'val' => 1, 'label' => __( 'Minimize form HTML', 'formidable' )),
|
444 |
+
);
|
445 |
+
break;
|
446 |
+
}
|
447 |
+
$opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode);
|
448 |
+
|
449 |
+
if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
|
450 |
+
// allow other shortcodes to use the required form id option
|
451 |
+
$form_id = $opts['form_id'];
|
452 |
+
unset( $opts['form_id'] );
|
453 |
+
}
|
454 |
+
|
455 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/shortcode_opts.php');
|
456 |
+
|
457 |
+
echo '</div>';
|
458 |
+
|
459 |
+
wp_die();
|
460 |
+
}
|
461 |
+
|
462 |
+
public static function display_forms_list( $params = array(), $message = '', $current_page_ov = false, $errors = array() ) {
|
463 |
+
FrmAppHelper::permission_check( 'frm_view_forms' );
|
464 |
+
|
465 |
+
global $wpdb, $frm_vars;
|
466 |
+
|
467 |
+
if ( empty( $params ) ) {
|
468 |
+
$params = FrmFormsHelper::get_params();
|
469 |
+
}
|
470 |
+
|
471 |
+
$wp_list_table = new FrmFormsListHelper( compact( 'params' ) );
|
472 |
|
473 |
$pagenum = $wp_list_table->get_pagenum();
|
474 |
|
479 |
wp_redirect( add_query_arg( 'paged', $total_pages ) );
|
480 |
die();
|
481 |
}
|
482 |
+
|
|
|
|
|
|
|
483 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/list.php');
|
484 |
}
|
485 |
+
|
486 |
+
public static function get_columns($columns) {
|
487 |
$columns['cb'] = '<input type="checkbox" />';
|
488 |
+
$columns['id'] = 'ID';
|
489 |
+
|
490 |
+
$type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : 'published';
|
491 |
+
|
492 |
+
if ( 'template' == $type ) {
|
493 |
+
$columns['name'] = __( 'Template Name', 'formidable' );
|
494 |
+
$columns['type'] = __( 'Type', 'formidable' );
|
495 |
+
$columns['form_key'] = __( 'Key', 'formidable' );
|
496 |
+
} else {
|
497 |
+
$columns['name'] = __( 'Form Title', 'formidable' );
|
498 |
+
$columns['entries'] = __( 'Entries', 'formidable' );
|
499 |
+
$columns['form_key'] = __( 'Key', 'formidable' );
|
500 |
+
$columns['shortcode'] = __( 'Shortcodes', 'formidable' );
|
501 |
+
}
|
502 |
+
|
503 |
+
$columns['created_at'] = __( 'Date', 'formidable' );
|
504 |
+
|
505 |
+
add_screen_option( 'per_page', array( 'label' => __( 'Forms', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_per_page' ) );
|
506 |
+
|
507 |
return $columns;
|
508 |
}
|
509 |
+
|
510 |
public static function get_sortable_columns() {
|
511 |
return array(
|
512 |
+
'id' => 'id',
|
513 |
+
'name' => 'name',
|
514 |
'description' => 'description',
|
515 |
+
'form_key' => 'form_key',
|
516 |
+
'created_at' => 'created_at',
|
517 |
);
|
518 |
}
|
519 |
+
|
520 |
+
public static function hidden_columns( $result ) {
|
521 |
$return = false;
|
522 |
+
foreach ( (array) $result as $r ) {
|
523 |
+
if ( ! empty( $r ) ) {
|
524 |
$return = true;
|
525 |
break;
|
526 |
}
|
527 |
}
|
528 |
+
|
529 |
+
if ( $return ) {
|
530 |
return $result;
|
531 |
+
}
|
532 |
+
|
533 |
+
$type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
|
534 |
|
535 |
$result[] = 'created_at';
|
536 |
+
if ( $type == 'template' ) {
|
537 |
$result[] = 'id';
|
538 |
$result[] = 'form_key';
|
539 |
+
}
|
540 |
+
|
541 |
return $result;
|
542 |
}
|
543 |
+
|
544 |
+
public static function save_per_page( $save, $option, $value ) {
|
545 |
+
if ( $option == 'formidable_page_formidable_per_page' ) {
|
546 |
+
$save = (int) $value;
|
547 |
+
}
|
548 |
return $save;
|
549 |
}
|
550 |
|
551 |
+
private static function get_edit_vars( $id, $errors = '', $message = '', $create_link = false ) {
|
552 |
+
global $frm_vars;
|
553 |
+
|
554 |
+
$form = FrmForm::getOne( $id );
|
555 |
+
if ( ! $form ) {
|
556 |
+
wp_die( __( 'You are trying to edit a form that does not exist.', 'formidable' ) );
|
557 |
}
|
558 |
+
|
559 |
+
if ( $form->parent_form_id ) {
|
560 |
+
wp_die( sprintf(__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable&frm_action=edit&id='. $form->parent_form_id) .'">', '</a>' ));
|
561 |
+
}
|
562 |
+
|
563 |
$frm_field_selection = FrmFieldsHelper::field_selection();
|
564 |
+
$fields = FrmField::get_all_for_form($form->id);
|
565 |
+
|
566 |
+
// Automatically add end section fields if they don't exist (2.0 migration)
|
567 |
+
$reset_fields = false;
|
568 |
+
FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
|
569 |
+
|
570 |
+
if ( $reset_fields ) {
|
571 |
+
$fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
|
572 |
+
}
|
573 |
+
|
574 |
+
unset($end_section_values, $last_order, $open, $reset_fields);
|
575 |
+
|
576 |
$values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
|
577 |
+
|
578 |
+
$edit_message = __( 'Form was Successfully Updated', 'formidable' );
|
579 |
if ( $form->is_template && $message == $edit_message ) {
|
580 |
+
$message = __( 'Template was Successfully Updated', 'formidable' );
|
581 |
}
|
582 |
+
|
583 |
+
$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
|
584 |
+
|
585 |
if ( $form->default_template ) {
|
586 |
+
wp_die(__( 'That template cannot be edited', 'formidable' ));
|
587 |
} else if ( defined('DOING_AJAX') ) {
|
588 |
+
wp_die();
|
589 |
} else if ( $create_link ) {
|
590 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
|
591 |
} else {
|
592 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/edit.php');
|
593 |
}
|
594 |
}
|
595 |
+
|
596 |
+
public static function get_settings_vars( $id, $errors = '', $message = '' ) {
|
597 |
+
FrmAppHelper::permission_check( 'frm_edit_forms' );
|
598 |
+
|
599 |
+
global $frm_vars;
|
600 |
+
|
601 |
+
$form = FrmForm::getOne( $id );
|
602 |
+
|
603 |
+
$fields = FrmField::get_all_for_form($id);
|
604 |
$values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
|
605 |
+
|
606 |
+
if ( isset($values['default_template']) && $values['default_template'] ) {
|
607 |
+
wp_die(__( 'That template cannot be edited', 'formidable' ));
|
608 |
+
}
|
609 |
+
|
610 |
+
$action_controls = FrmFormActionsController::get_form_actions();
|
611 |
+
|
612 |
$sections = apply_filters('frm_add_form_settings_section', array(), $values);
|
613 |
+
$pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"';
|
614 |
+
|
615 |
+
$styles = apply_filters('frm_get_style_opts', array());
|
616 |
+
|
617 |
+
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/settings.php');
|
618 |
+
}
|
619 |
+
|
620 |
+
public static function mb_tags_box( $form_id, $class = '' ) {
|
621 |
+
$fields = FrmField::get_all_for_form($form_id, '', 'include');
|
622 |
+
$linked_forms = array();
|
623 |
+
$col = 'one';
|
624 |
+
$settings_tab = FrmAppHelper::is_admin_page('formidable' ) ? true : false;
|
625 |
+
|
626 |
+
$cond_shortcodes = apply_filters('frm_conditional_shortcodes', array());
|
627 |
+
|
628 |
+
$adv_shortcodes = array(
|
629 |
+
'sep=", "' => array( 'label' => __( 'Separator', 'formidable' ), 'title' => __( 'Use a different separator for checkbox fields', 'formidable' ) ),
|
630 |
+
'format="d-m-Y"' => __( 'Date Format', 'formidable' ),
|
631 |
+
'show="field_label"' => __( 'Field Label', 'formidable' ),
|
632 |
+
'wpautop=0' => array( 'label' => __( 'No Auto P', 'formidable' ), 'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' )),
|
633 |
+
);
|
634 |
+
$adv_shortcodes = apply_filters('frm_advanced_shortcodes', $adv_shortcodes);
|
635 |
+
|
636 |
+
// __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
|
637 |
+
|
638 |
+
$user_fields = apply_filters('frm_user_shortcodes', array());
|
639 |
+
|
640 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/shared/mb_adv_info.php');
|
641 |
+
}
|
642 |
+
|
643 |
+
// Insert the form class setting into the form
|
644 |
+
public static function form_classes($form) {
|
645 |
+
if ( isset($form->options['form_class']) ) {
|
646 |
+
echo esc_attr($form->options['form_class']);
|
647 |
}
|
648 |
+
}
|
649 |
|
650 |
+
public static function get_email_html() {
|
651 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
652 |
+
echo FrmEntriesController::show_entry_shortcode( array(
|
653 |
+
'form_id' => $_POST['form_id'],
|
654 |
+
'default_email' => true,
|
655 |
+
'plain_text' => $_POST['plain_text'],
|
656 |
+
) );
|
657 |
+
wp_die();
|
658 |
+
}
|
659 |
+
|
660 |
+
public static function filter_content( $content, $form, $entry = false ) {
|
661 |
+
if ( ! $entry || ! is_object( $entry ) ) {
|
662 |
+
if ( ! $entry || ! is_numeric( $entry ) ) {
|
663 |
+
$entry = ( $_POST && isset( $_POST['id'] ) ) ? $_POST['id'] : false;
|
|
|
664 |
}
|
665 |
+
|
666 |
+
FrmEntriesHelper::maybe_get_entry( $entry );
|
667 |
}
|
668 |
|
669 |
+
if ( ! $entry ) {
|
670 |
+
return $content;
|
671 |
+
}
|
672 |
+
|
673 |
+
if ( is_object( $form ) ) {
|
674 |
+
$form = $form->id;
|
675 |
+
}
|
676 |
+
|
677 |
+
$shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
|
678 |
+
$content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
|
679 |
+
|
680 |
+
return $content;
|
681 |
+
}
|
682 |
+
|
683 |
+
public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
|
684 |
+
return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
|
685 |
+
}
|
686 |
+
|
687 |
+
public static function process_bulk_form_actions( $errors ) {
|
688 |
+
if ( ! $_REQUEST ) {
|
689 |
+
return $errors;
|
690 |
+
}
|
691 |
+
|
692 |
+
$bulkaction = FrmAppHelper::get_param( 'action' );
|
693 |
+
if ( $bulkaction == -1 ) {
|
694 |
+
$bulkaction = FrmAppHelper::get_param( 'action2' );
|
695 |
+
}
|
696 |
+
|
697 |
+
if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
|
698 |
+
FrmAppHelper::remove_get_action();
|
699 |
+
|
700 |
+
$bulkaction = str_replace( 'bulk_', '', $bulkaction );
|
701 |
+
}
|
702 |
+
|
703 |
+
$ids = FrmAppHelper::get_param( 'item-action', '' );
|
704 |
+
if ( empty( $ids ) ) {
|
705 |
+
$errors[] = __( 'No forms were specified', 'formidable' );
|
706 |
+
return $errors;
|
707 |
}
|
708 |
+
|
709 |
+
$permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
|
710 |
+
if ( $permission_error !== false ) {
|
711 |
+
$errors[] = $permission_error;
|
712 |
+
return $errors;
|
713 |
+
}
|
714 |
+
|
715 |
+
if ( ! is_array( $ids ) ) {
|
716 |
+
$ids = explode( ',', $ids );
|
717 |
+
}
|
718 |
+
|
719 |
+
switch ( $bulkaction ) {
|
720 |
+
case 'delete':
|
721 |
+
$message = self::bulk_destroy( $ids );
|
722 |
+
break;
|
723 |
+
case 'trash':
|
724 |
+
$message = self::bulk_trash( $ids );
|
725 |
+
break;
|
726 |
+
case 'untrash':
|
727 |
+
$message = self::bulk_untrash( $ids );
|
728 |
+
break;
|
729 |
+
case 'create_template':
|
730 |
+
$message = self::bulk_create_template( $ids );
|
731 |
+
break;
|
732 |
+
}
|
733 |
+
|
734 |
+
if ( isset( $message ) && ! empty( $message ) ) {
|
735 |
+
echo '<div id="message" class="updated frm_msg_padding">'.$message.'</div>';
|
736 |
+
}
|
737 |
+
|
738 |
return $errors;
|
739 |
}
|
740 |
+
|
741 |
+
public static function add_default_templates( $path, $default = true, $template = true ) {
|
742 |
_deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' );
|
743 |
+
|
|
|
744 |
$path = untrailingslashit(trim($path));
|
745 |
+
$templates = glob( $path .'/*.php' );
|
746 |
+
|
747 |
+
for($i = count($templates) - 1; $i >= 0; $i--) {
|
748 |
+
$filename = str_replace( '.php', '', str_replace( $path.'/', '', $templates[ $i ] ) );
|
749 |
+
$template_query = array( 'form_key' => $filename);
|
750 |
+
if ( $template ) {
|
751 |
+
$template_query['is_template'] = 1;
|
752 |
+
}
|
753 |
+
if ( $default ) {
|
754 |
+
$template_query['default_template'] = 1;
|
755 |
+
}
|
756 |
+
$form = FrmForm::getAll( $template_query, '', 1 );
|
757 |
+
|
758 |
$values = FrmFormsHelper::setup_new_vars();
|
759 |
$values['form_key'] = $filename;
|
760 |
$values['is_template'] = $template;
|
761 |
$values['status'] = 'published';
|
762 |
+
if ( $default ) {
|
763 |
+
$values['default_template'] = 1;
|
764 |
+
}
|
765 |
+
|
766 |
+
include( $templates[ $i ] );
|
767 |
+
|
768 |
//get updated form
|
769 |
+
if ( isset($form) && ! empty($form) ) {
|
770 |
+
$old_id = $form->id;
|
771 |
+
$form = FrmForm::getOne($form->id);
|
772 |
} else {
|
773 |
+
$old_id = false;
|
774 |
+
$form = FrmForm::getAll( $template_query, '', 1 );
|
775 |
+
}
|
776 |
+
|
777 |
+
if ( $form ) {
|
778 |
+
do_action('frm_after_duplicate_form', $form->id, (array) $form, array( 'old_id' => $old_id));
|
779 |
}
|
|
|
|
|
|
|
780 |
}
|
781 |
}
|
782 |
|
783 |
+
public static function route() {
|
784 |
$action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
|
785 |
+
$vars = array();
|
786 |
+
if ( isset( $_POST['frm_compact_fields'] ) ) {
|
787 |
+
FrmAppHelper::permission_check( 'frm_edit_forms' );
|
788 |
+
|
|
|
|
|
789 |
$json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('"', '\\\"', $_POST['frm_compact_fields'] ))));
|
790 |
$json_vars = json_decode($json_vars, true);
|
791 |
if ( empty($json_vars) ) {
|
794 |
if ( 'edit' == $action ) {
|
795 |
$action = 'update';
|
796 |
}
|
797 |
+
|
798 |
+
add_filter('frm_validate_form', 'FrmFormsController::json_error');
|
799 |
} else {
|
800 |
$vars = FrmAppHelper::json_to_array($json_vars);
|
801 |
+
$action = $vars[ $action ];
|
802 |
+
$_REQUEST = array_merge( $_REQUEST, $vars );
|
803 |
+
unset( $_REQUEST['frm_compact_fields'] );
|
804 |
}
|
805 |
+
} else {
|
806 |
$action = FrmAppHelper::get_param($action);
|
807 |
+
if ( isset( $_REQUEST['delete_all'] ) ) {
|
808 |
+
// override the action for this page
|
809 |
+
$action = 'delete_all';
|
810 |
+
}
|
811 |
}
|
812 |
+
|
813 |
+
add_action('frm_load_form_hooks', 'FrmFormsController::trigger_load_form_hooks');
|
814 |
+
FrmAppHelper::trigger_hook_load( 'form' );
|
815 |
+
|
816 |
+
switch ( $action ) {
|
817 |
+
case 'new':
|
818 |
+
return self::new_form($vars);
|
819 |
+
case 'create':
|
820 |
+
case 'edit':
|
821 |
+
case 'update':
|
822 |
+
case 'duplicate':
|
823 |
+
case 'trash':
|
824 |
+
case 'untrash':
|
825 |
+
case 'destroy':
|
826 |
+
case 'delete_all':
|
827 |
+
case 'settings':
|
828 |
+
case 'update_settings':
|
829 |
+
return self::$action( $vars );
|
830 |
+
default:
|
831 |
+
do_action('frm_form_action_'. $action);
|
832 |
+
if ( apply_filters('frm_form_stop_action_'. $action, false) ) {
|
833 |
+
return;
|
834 |
+
}
|
835 |
+
|
836 |
+
$action = FrmAppHelper::get_param('action');
|
837 |
+
if ( $action == -1 ) {
|
838 |
+
$action = FrmAppHelper::get_param('action2');
|
839 |
+
}
|
840 |
+
|
841 |
+
if ( strpos($action, 'bulk_') === 0 ) {
|
842 |
+
FrmAppHelper::remove_get_action();
|
843 |
+
return self::list_form();
|
844 |
+
}
|
845 |
+
|
|
|
|
|
846 |
return self::display_forms_list();
|
|
|
847 |
}
|
848 |
}
|
849 |
+
|
850 |
+
public static function json_error( $errors ) {
|
851 |
+
$errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
|
852 |
return $errors;
|
853 |
}
|
854 |
+
|
855 |
+
|
856 |
/* FRONT-END FORMS */
|
857 |
public static function admin_bar_css() {
|
858 |
FrmAppController::load_wp_admin_style();
|
859 |
}
|
860 |
+
|
861 |
public static function admin_bar_configure() {
|
862 |
if ( is_admin() || !current_user_can('frm_edit_forms') ) {
|
863 |
return;
|
864 |
}
|
865 |
+
|
866 |
global $frm_vars;
|
867 |
if ( empty($frm_vars['forms_loaded']) ) {
|
868 |
return;
|
869 |
}
|
870 |
+
|
871 |
$actions = array();
|
872 |
+
foreach ( $frm_vars['forms_loaded'] as $form ) {
|
873 |
if ( is_object($form) ) {
|
874 |
+
$actions[ $form->id ] = $form->name;
|
875 |
}
|
876 |
unset($form);
|
877 |
}
|
878 |
+
|
879 |
if ( empty($actions) ) {
|
880 |
return;
|
881 |
}
|
882 |
+
|
883 |
asort($actions);
|
884 |
+
|
885 |
global $wp_admin_bar;
|
886 |
+
|
887 |
if ( count($actions) == 1 ) {
|
888 |
$wp_admin_bar->add_menu( array(
|
889 |
'title' => 'Edit Form',
|
890 |
'href' => admin_url('admin.php?page=formidable&frm_action=edit&id='. current( array_keys( $actions ) )),
|
891 |
+
'id' => 'frm-forms',
|
892 |
) );
|
893 |
+
} else {
|
894 |
$wp_admin_bar->add_menu( array(
|
895 |
'id' => 'frm-forms',
|
896 |
'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Edit Forms', 'formidable' ) . '</span>',
|
899 |
'title' => __( 'Edit Forms', 'formidable' ),
|
900 |
),
|
901 |
) );
|
902 |
+
|
903 |
foreach ( $actions as $form_id => $name ) {
|
904 |
|
905 |
$wp_admin_bar->add_menu( array(
|
906 |
'parent' => 'frm-forms',
|
907 |
'id' => 'edit_form_'. $form_id,
|
908 |
+
'title' => empty($name) ? __( '(no title)') : $name,
|
909 |
'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id='. $form_id )
|
910 |
) );
|
911 |
}
|
912 |
+
}
|
913 |
}
|
914 |
+
|
|
|
|
|
915 |
//formidable shortcode
|
916 |
public static function get_form_shortcode($atts) {
|
917 |
global $frm_vars;
|
922 |
}
|
923 |
return $sc .']';
|
924 |
}
|
925 |
+
|
926 |
+
$shortcode_atts = shortcode_atts( array(
|
927 |
'id' => '', 'key' => '', 'title' => false, 'description' => false,
|
928 |
'readonly' => false, 'entry_id' => false, 'fields' => array(),
|
929 |
'exclude_fields' => array(), 'minimize' => false,
|
930 |
), $atts);
|
931 |
do_action('formidable_shortcode_atts', $shortcode_atts, $atts);
|
932 |
+
|
933 |
+
return self::show_form(
|
934 |
+
$shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'],
|
935 |
+
$shortcode_atts['description'], $atts
|
936 |
+
);
|
937 |
+
}
|
938 |
+
|
939 |
+
public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
|
940 |
+
if ( empty( $id ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
941 |
$id = $key;
|
942 |
}
|
943 |
+
|
944 |
// no form id or key set
|
945 |
+
if ( empty( $id ) ) {
|
946 |
+
return __( 'Please select a valid form', 'formidable' );
|
947 |
}
|
948 |
+
|
949 |
+
$form = FrmForm::getOne( $id );
|
950 |
+
if ( ! $form || $form->parent_form_id ) {
|
951 |
+
return __( 'Please select a valid form', 'formidable' );
|
952 |
}
|
953 |
+
|
954 |
+
add_action( 'frm_load_form_hooks', 'FrmFormsController::trigger_load_form_hooks' );
|
955 |
+
FrmAppHelper::trigger_hook_load( 'form', $form );
|
956 |
+
|
957 |
+
$form = apply_filters( 'frm_pre_display_form', $form );
|
958 |
+
|
959 |
+
$frm_settings = FrmAppHelper::get_settings();
|
960 |
+
|
961 |
// don't show a draft form on a page
|
962 |
+
global $post;
|
963 |
+
if ( $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ( ! $post || $post->ID != $frm_settings->preview_page_id ) && ! FrmAppHelper::is_preview_page() ) {
|
964 |
+
return __( 'Please select a valid form', 'formidable' );
|
965 |
}
|
966 |
+
|
967 |
// don't show the form if user should be logged in
|
968 |
+
if ( $form->logged_in && ! is_user_logged_in() ) {
|
969 |
+
return do_shortcode( $frm_settings->login_msg );
|
970 |
}
|
971 |
+
|
972 |
// don't show the form if user doesn't have permission
|
973 |
+
if ( $form->logged_in && get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] ) ) {
|
974 |
+
return do_shortcode( $frm_settings->login_msg );
|
975 |
}
|
976 |
+
|
977 |
+
$form = self::get_form( $form, $title, $description, $atts );
|
978 |
+
|
979 |
// check for external shortcodes
|
980 |
+
$form = do_shortcode( $form );
|
981 |
+
|
982 |
return $form;
|
983 |
}
|
|
|
|
|
|
|
|
|
984 |
|
985 |
+
public static function get_form( $form, $title, $description, $atts = array() ) {
|
986 |
+
ob_start();
|
987 |
+
|
988 |
+
self::get_form_contents( $form, $title, $description, $atts );
|
989 |
+
FrmEntriesHelper::enqueue_scripts( FrmEntriesController::get_params( $form ) );
|
990 |
+
|
991 |
+
$contents = ob_get_contents();
|
992 |
+
ob_end_clean();
|
993 |
+
|
994 |
+
// check if minimizing is turned on
|
995 |
+
if ( isset( $atts['minimize'] ) && ! empty( $atts['minimize'] ) ) {
|
996 |
+
$contents = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $contents );
|
997 |
+
}
|
998 |
+
|
999 |
+
return $contents;
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
public static function get_form_contents($form, $title, $description, $atts) {
|
1003 |
+
global $frm_vars;
|
1004 |
+
|
1005 |
+
$frm_settings = FrmAppHelper::get_settings();
|
1006 |
+
|
1007 |
$submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
|
1008 |
+
|
|
|
1009 |
$user_ID = get_current_user_id();
|
1010 |
+
|
1011 |
$params = FrmEntriesController::get_params($form);
|
1012 |
|
1013 |
$message = $errors = '';
|
1014 |
|
|
|
|
|
1015 |
if ( $params['posted_form_id'] == $form->id && $_POST ) {
|
1016 |
+
$errors = isset( $frm_vars['created_entries'][ $form->id ] ) ? $frm_vars['created_entries'][ $form->id ]['errors'] : array();
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
$fields = FrmFieldsHelper::get_form_fields( $form->id, ( isset( $errors ) && ! empty( $errors ) ) );
|
1020 |
+
|
1021 |
+
if ( $params['action'] != 'create' || $params['posted_form_id'] != $form->id || ! $_POST ) {
|
1022 |
+
do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
|
1023 |
+
if ( apply_filters('frm_continue_to_new', true, $form->id, $params['action']) ) {
|
1024 |
+
$values = FrmEntriesHelper::setup_new_vars($fields, $form);
|
1025 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
|
|
|
|
|
|
|
|
|
|
|
1026 |
}
|
1027 |
+
return;
|
1028 |
+
}
|
1029 |
+
|
1030 |
+
if ( ! empty($errors) ) {
|
1031 |
+
$values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
|
1032 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
|
1033 |
+
return;
|
1034 |
}
|
|
|
|
|
1035 |
|
1036 |
+
do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description);
|
1037 |
+
if ( ! apply_filters('frm_continue_to_create', true, $form->id) ) {
|
1038 |
+
return;
|
1039 |
+
}
|
1040 |
+
|
1041 |
+
$values = FrmEntriesHelper::setup_new_vars($fields, $form, true);
|
1042 |
+
$created = ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form->id ] ) ) ? $frm_vars['created_entries'][ $form->id ]['entry_id'] : 0;
|
1043 |
+
$conf_method = apply_filters('frm_success_filter', 'message', $form, $form->options, 'create');
|
1044 |
+
|
1045 |
+
if ( $created && is_numeric($created) && $conf_method != 'message' ) {
|
1046 |
+
do_action('frm_success_action', $conf_method, $form, $form->options, $created);
|
1047 |
+
do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
|
1048 |
+
return;
|
1049 |
+
}
|
1050 |
+
|
1051 |
+
if ( $created && is_numeric($created) ) {
|
1052 |
+
$message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
|
1053 |
+
$class = 'frm_message';
|
1054 |
+
} else {
|
1055 |
+
$message = $frm_settings->failed_msg;
|
1056 |
+
$class = 'frm_error_style';
|
1057 |
+
}
|
1058 |
+
$message = apply_filters('frm_content', $message, $form, $created);
|
1059 |
+
$message = '<div class="'. $class .'">'. wpautop(do_shortcode($message)) .'</div>';
|
1060 |
+
$message = apply_filters('frm_main_feedback', $message, $form, $created);
|
1061 |
+
|
1062 |
+
if ( ! isset($form->options['show_form']) || $form->options['show_form'] ) {
|
1063 |
+
require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
|
1064 |
+
} else {
|
1065 |
+
global $frm_vars;
|
1066 |
+
FrmFormsHelper::form_loaded($form, $values['custom_style'], $frm_vars['load_css']);
|
1067 |
+
|
1068 |
+
$include_extra_container = 'frm_forms'. FrmFormsHelper::get_form_style_class($values);
|
1069 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
|
1070 |
+
}
|
1071 |
+
|
1072 |
+
do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
|
1073 |
+
}
|
1074 |
}
|
classes/controllers/FrmHooksController.php
ADDED
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class FrmHooksController {
|
4 |
+
/**
|
5 |
+
* Trigger plugin-wide hook loading
|
6 |
+
*/
|
7 |
+
public static function trigger_load_hook( $hooks = 'load_hooks' ) {
|
8 |
+
$controllers = apply_filters( 'frm_load_controllers', array( 'FrmHooksController' ) );
|
9 |
+
|
10 |
+
$trigger_hooks = $hooks;
|
11 |
+
$hooks = (array) $hooks;
|
12 |
+
|
13 |
+
if ( 'load_hooks' == $trigger_hooks ) {
|
14 |
+
if ( is_admin() ) {
|
15 |
+
$hooks[] = 'load_admin_hooks';
|
16 |
+
if ( defined( 'DOING_AJAX' ) ) {
|
17 |
+
$hooks[] = 'load_ajax_hooks';
|
18 |
+
$hooks[] = 'load_form_hooks';
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
if ( is_multisite() ) {
|
23 |
+
$hooks[] = 'load_multisite_hooks';
|
24 |
+
}
|
25 |
+
} else {
|
26 |
+
// Make sure the hooks are only triggered once
|
27 |
+
add_filter('frm'. str_replace('load', '', $trigger_hooks) .'_loaded', '__return_true');
|
28 |
+
}
|
29 |
+
unset($trigger_hooks);
|
30 |
+
|
31 |
+
// Instansiate Controllers
|
32 |
+
foreach ( $controllers as $c ) {
|
33 |
+
foreach ( $hooks as $hook ) {
|
34 |
+
call_user_func( array( $c, $hook ) );
|
35 |
+
unset( $hook );
|
36 |
+
}
|
37 |
+
unset( $c );
|
38 |
+
}
|
39 |
+
|
40 |
+
}
|
41 |
+
|
42 |
+
public static function load_hooks() {
|
43 |
+
if ( ! is_admin() ) {
|
44 |
+
add_filter('the_content', 'FrmAppController::page_route', 10);
|
45 |
+
}
|
46 |
+
|
47 |
+
add_action('plugins_loaded', 'FrmAppController::load_lang' );
|
48 |
+
add_action('init', 'FrmAppController::front_head' );
|
49 |
+
add_filter('widget_text', 'FrmAppController::widget_text_filter', 8 );
|
50 |
+
add_action('wp_footer', 'FrmAppController::footer_js', 1, 0);
|
51 |
+
|
52 |
+
// Entries controller
|
53 |
+
add_action('wp', 'FrmEntriesController::process_entry', 10, 0);
|
54 |
+
add_action('frm_wp', 'FrmEntriesController::process_entry', 10, 0);
|
55 |
+
add_filter('frm_redirect_url', 'FrmEntriesController::delete_entry_before_redirect', 50, 3);
|
56 |
+
add_action('frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100);
|
57 |
+
add_filter('frm_email_value', 'FrmEntriesController::filter_email_value', 10, 3);
|
58 |
+
add_filter('frmpro_fields_replace_shortcodes', 'FrmEntriesController::filter_shortcode_value', 10, 4);
|
59 |
+
|
60 |
+
// Form Actions Controller
|
61 |
+
add_action('init', 'FrmFormActionsController::register_post_types', 1);
|
62 |
+
add_action( 'frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 3 );
|
63 |
+
|
64 |
+
// Forms Controller
|
65 |
+
add_action('widgets_init', 'FrmFormsController::register_widgets' );
|
66 |
+
add_filter('frm_content', 'FrmFormsController::filter_content', 10, 3);
|
67 |
+
add_filter('frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3);
|
68 |
+
add_action('admin_bar_init', 'FrmFormsController::admin_bar_css' );
|
69 |
+
add_action('wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
|
70 |
+
add_action('wp_scheduled_delete', 'FrmFormsController::scheduled_delete' );
|
71 |
+
|
72 |
+
// Form Shortcodes
|
73 |
+
add_shortcode('formidable', 'FrmFormsController::get_form_shortcode' );
|
74 |
+
|
75 |
+
// Styles Controller
|
76 |
+
add_action('init', 'FrmStylesController::register_post_types', 0);
|
77 |
+
add_filter('frm_get_style_opts', 'FrmStylesController::get_style_opts');
|
78 |
+
add_filter('frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2);
|
79 |
+
add_filter('frm_show_entry_styles', 'FrmStylesController::show_entry_styles');
|
80 |
+
}
|
81 |
+
|
82 |
+
public static function load_admin_hooks() {
|
83 |
+
add_action('admin_menu', 'FrmAppController::menu', 1);
|
84 |
+
add_action('admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
|
85 |
+
add_filter('update_plugin_complete_actions', 'FrmAppController::update_action_links', 10, 2 );
|
86 |
+
add_action('admin_notices', 'FrmAppController::pro_get_started_headline' );
|
87 |
+
add_action('admin_init', 'FrmAppController::admin_js', 11);
|
88 |
+
register_activation_hook(FrmAppHelper::plugin_path().'/formidable.php', 'FrmAppController::activation_install' );
|
89 |
+
|
90 |
+
// Entries Controller
|
91 |
+
add_action('admin_menu', 'FrmEntriesController::menu', 12);
|
92 |
+
add_filter('contextual_help', 'FrmEntriesController::contextual_help', 10, 3 );
|
93 |
+
add_filter('set-screen-option', 'FrmEntriesController::save_per_page', 10, 3);
|
94 |
+
add_filter('update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5);
|
95 |
+
add_action('updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4);
|
96 |
+
|
97 |
+
// Fields Controller
|
98 |
+
add_filter('frm_display_field_options', 'FrmFieldsController::display_field_options');
|
99 |
+
add_action('frm_field_options_form', 'FrmFieldsController::add_conditional_update_msg', 50);
|
100 |
+
|
101 |
+
// Form Actions Controller
|
102 |
+
if ( FrmAppHelper::is_admin_page('formidable' ) ) {
|
103 |
+
add_action('frm_before_update_form_settings', 'FrmFormActionsController::update_settings');
|
104 |
+
}
|
105 |
+
add_action('frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3);
|
106 |
+
|
107 |
+
// Forms Controller
|
108 |
+
add_action('admin_menu', 'FrmFormsController::menu', 10);
|
109 |
+
add_action('admin_head-toplevel_page_formidable', 'FrmFormsController::head' );
|
110 |
+
|
111 |
+
add_filter('set-screen-option', 'FrmFormsController::save_per_page', 10, 3);
|
112 |
+
add_action('admin_footer', 'FrmFormsController::insert_form_popup' );
|
113 |
+
add_filter('media_buttons_context', 'FrmFormsController::insert_form_button' );
|
114 |
+
|
115 |
+
// Forms Model
|
116 |
+
add_action('frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2);
|
117 |
+
|
118 |
+
// Settings Controller
|
119 |
+
add_action('admin_menu', 'FrmSettingsController::menu', 45);
|
120 |
+
add_action('frm_before_settings', 'FrmSettingsController::license_box');
|
121 |
+
|
122 |
+
// Stats Controller
|
123 |
+
add_action('admin_menu', 'FrmStatisticsController::menu', 24);
|
124 |
+
add_action('frm_form_action_reports', 'FrmStatisticsController::list_reports');
|
125 |
+
|
126 |
+
// Styles Controller
|
127 |
+
add_action('admin_menu', 'FrmStylesController::menu', 14);
|
128 |
+
add_action('admin_init', 'FrmStylesController::admin_init');
|
129 |
+
|
130 |
+
// XML Controller
|
131 |
+
add_action('admin_menu', 'FrmXMLController::menu', 41);
|
132 |
+
}
|
133 |
+
|
134 |
+
public static function load_ajax_hooks() {
|
135 |
+
add_action('wp_ajax_frm_install', 'FrmAppController::install' );
|
136 |
+
add_action('wp_ajax_frm_uninstall', 'FrmAppController::uninstall' );
|
137 |
+
add_action('wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' );
|
138 |
+
|
139 |
+
add_action('wp_ajax_frmpro_css', 'FrmAppController::load_css' );
|
140 |
+
add_action('wp_ajax_nopriv_frmpro_css', 'FrmAppController::load_css' );
|
141 |
+
|
142 |
+
// Fields Controller
|
143 |
+
add_action('wp_ajax_frm_load_field', 'FrmFieldsController::load_field');
|
144 |
+
add_action('wp_ajax_frm_insert_field', 'FrmFieldsController::create');
|
145 |
+
add_action('wp_ajax_frm_update_field_form_id', 'FrmFieldsController::update_form_id');
|
146 |
+
add_action('wp_ajax_frm_field_name_in_place_edit', 'FrmFieldsController::edit_name');
|
147 |
+
add_action('wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option');
|
148 |
+
add_action('wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate');
|
149 |
+
add_action('wp_ajax_frm_delete_field', 'FrmFieldsController::destroy');
|
150 |
+
add_action('wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option');
|
151 |
+
add_action('wp_ajax_frm_field_option_ipe', 'FrmFieldsController::edit_option');
|
152 |
+
add_action('wp_ajax_frm_delete_field_option', 'FrmFieldsController::delete_option');
|
153 |
+
add_action('wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices');
|
154 |
+
add_action('wp_ajax_frm_import_options', 'FrmFieldsController::import_options');
|
155 |
+
add_action('wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order');
|
156 |
+
|
157 |
+
// Form Actions Controller
|
158 |
+
add_action('wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action');
|
159 |
+
add_action('wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action');
|
160 |
+
|
161 |
+
// Forms Controller
|
162 |
+
add_action( 'wp_ajax_frm_create_from_template', 'FrmFormsController::_create_from_template' );
|
163 |
+
add_action( 'wp_ajax_frm_save_form', 'FrmFormsController::route' );
|
164 |
+
add_action( 'wp_ajax_frm_form_key_in_place_edit', 'FrmFormsController::edit_key' );
|
165 |
+
add_action( 'wp_ajax_frm_form_desc_in_place_edit', 'FrmFormsController::edit_description' );
|
166 |
+
add_action('wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' );
|
167 |
+
add_action('wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' );
|
168 |
+
add_action('wp_ajax_frm_forms_preview', 'FrmFormsController::preview' );
|
169 |
+
add_action('wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' );
|
170 |
+
|
171 |
+
// Styles Controller
|
172 |
+
add_action('wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling');
|
173 |
+
add_action('wp_ajax_frm_change_styling', 'FrmStylesController::change_styling');
|
174 |
+
add_action('wp_ajax_frmpro_load_css', 'FrmStylesController::load_css');
|
175 |
+
add_action('wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css');
|
176 |
+
|
177 |
+
// XML Controller
|
178 |
+
add_action('wp_ajax_frm_export_xml', 'FrmXMLController::export_xml');
|
179 |
+
}
|
180 |
+
|
181 |
+
public static function load_form_hooks() {
|
182 |
+
// Fields Controller
|
183 |
+
add_filter('frm_field_type', 'FrmFieldsController::change_type');
|
184 |
+
add_action('frm_field_input_html', 'FrmFieldsController::input_html');
|
185 |
+
add_filter('frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3);
|
186 |
+
add_filter('frm_field_label_seen', 'FrmFieldsController::check_label');
|
187 |
+
|
188 |
+
// Styles Controller
|
189 |
+
add_filter('frm_use_important_width', 'FrmStylesController::important_style', 10, 2 );
|
190 |
+
}
|
191 |
+
|
192 |
+
public static function load_view_hooks() {
|
193 |
+
// Hooks go here when a view is loaded
|
194 |
+
}
|
195 |
+
|
196 |
+
public static function load_multisite_hooks() {
|
197 |
+
// drop tables when mu site is deleted
|
198 |
+
add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' );
|
199 |
+
}
|
200 |
+
}
|
classes/controllers/FrmSettingsController.php
CHANGED
@@ -1,89 +1,70 @@
|
|
1 |
<?php
|
2 |
-
/**
|
3 |
-
* @package Formidable
|
4 |
-
*/
|
5 |
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
class FrmSettingsController{
|
12 |
-
public static function load_hooks(){
|
13 |
-
add_action('admin_menu', 'FrmSettingsController::menu', 45);
|
14 |
-
add_action('frm_before_settings', 'FrmSettingsController::license_box');
|
15 |
}
|
16 |
|
17 |
-
public static function
|
18 |
-
add_submenu_page('formidable', 'Formidable | '. __('Global Settings', 'formidable'), __('Global Settings', 'formidable'), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route');
|
19 |
-
}
|
20 |
-
|
21 |
-
public static function license_box(){
|
22 |
$a = isset($_GET['t']) ? $_GET['t'] : 'general_settings';
|
23 |
include(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/license_box.php');
|
24 |
}
|
25 |
|
26 |
-
public static function display_form($errors=array(), $message=''){
|
27 |
-
global $
|
28 |
-
|
|
|
29 |
$frm_roles = FrmAppHelper::frm_capabilities();
|
30 |
-
|
31 |
$uploads = wp_upload_dir();
|
32 |
$target_path = $uploads['basedir'] . '/formidable/css';
|
33 |
-
$sections = apply_filters('frm_add_settings_section', array(
|
34 |
-
|
35 |
-
)
|
36 |
-
|
37 |
-
$recaptcha_themes = array(
|
38 |
-
'red' => __('Red', 'formidable'),
|
39 |
-
'white' => __('White', 'formidable'),
|
40 |
-
'blackglass' => __('Black Glass', 'formidable'),
|
41 |
-
'clean' => __('Clean', 'formidable'),
|
42 |
-
//'custom' => __('Custom', 'formidable'),
|
43 |
-
);
|
44 |
-
|
45 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/form.php');
|
46 |
}
|
47 |
|
48 |
-
public static function process_form($stop_load=false){
|
49 |
-
global $
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
54 |
$errors = array();
|
55 |
$message = '';
|
56 |
-
|
57 |
-
if(!isset($frm_vars['settings_routed'])
|
58 |
//$errors = $frm_settings->validate($_POST,array());
|
59 |
-
$frm_settings->update(stripslashes_deep($_POST));
|
60 |
|
61 |
-
if( empty($errors) ){
|
62 |
$frm_settings->store();
|
63 |
-
$message = __('Settings Saved', 'formidable');
|
64 |
}
|
65 |
-
}else{
|
66 |
-
$message = __('Settings Saved', 'formidable');
|
67 |
}
|
68 |
-
|
69 |
-
|
70 |
$frm_vars['settings_routed'] = true;
|
71 |
return;
|
72 |
}
|
73 |
-
|
74 |
-
self::display_form($errors, $message);
|
75 |
-
}
|
76 |
-
|
77 |
-
public static function styling_tab(){
|
78 |
-
include(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/styling_tab.php');
|
79 |
}
|
80 |
-
|
81 |
-
public static function route($stop_load=false){
|
82 |
-
$action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
|
83 |
-
$action = FrmAppHelper::get_param($action);
|
84 |
-
if($action == 'process-form')
|
85 |
-
return self::process_form($stop_load);
|
86 |
-
else if($stop_load != 'stop_load')
|
87 |
return self::display_form();
|
|
|
88 |
}
|
89 |
}
|
1 |
<?php
|
|
|
|
|
|
|
2 |
|
3 |
+
class FrmSettingsController {
|
4 |
|
5 |
+
public static function menu() {
|
6 |
+
add_submenu_page('formidable', 'Formidable | '. __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route');
|
|
|
|
|
|
|
|
|
|
|
7 |
}
|
8 |
|
9 |
+
public static function license_box() {
|
|
|
|
|
|
|
|
|
10 |
$a = isset($_GET['t']) ? $_GET['t'] : 'general_settings';
|
11 |
include(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/license_box.php');
|
12 |
}
|
13 |
|
14 |
+
public static function display_form( $errors = array(), $message = '' ) {
|
15 |
+
global $frm_vars;
|
16 |
+
|
17 |
+
$frm_settings = FrmAppHelper::get_settings();
|
18 |
$frm_roles = FrmAppHelper::frm_capabilities();
|
19 |
+
|
20 |
$uploads = wp_upload_dir();
|
21 |
$target_path = $uploads['basedir'] . '/formidable/css';
|
22 |
+
$sections = apply_filters('frm_add_settings_section', array());
|
23 |
+
|
24 |
+
$captcha_lang = FrmAppHelper::locales('captcha');
|
25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/form.php');
|
27 |
}
|
28 |
|
29 |
+
public static function process_form( $stop_load = false ) {
|
30 |
+
global $frm_vars;
|
31 |
+
|
32 |
+
$frm_settings = FrmAppHelper::get_settings();
|
33 |
+
|
34 |
+
if ( ! isset( $_POST['process_form'] ) || ! wp_verify_nonce( $_POST['process_form'], 'process_form_nonce' ) ) {
|
35 |
+
wp_die( $frm_settings->admin_permission );
|
36 |
+
}
|
37 |
+
|
38 |
$errors = array();
|
39 |
$message = '';
|
40 |
+
|
41 |
+
if ( ! isset( $frm_vars['settings_routed'] ) || ! $frm_vars['settings_routed'] ) {
|
42 |
//$errors = $frm_settings->validate($_POST,array());
|
43 |
+
$frm_settings->update( stripslashes_deep( $_POST ) );
|
44 |
|
45 |
+
if ( empty( $errors ) ) {
|
46 |
$frm_settings->store();
|
47 |
+
$message = __( 'Settings Saved', 'formidable' );
|
48 |
}
|
49 |
+
} else {
|
50 |
+
$message = __( 'Settings Saved', 'formidable' );
|
51 |
}
|
52 |
+
|
53 |
+
if ( $stop_load == 'stop_load' ) {
|
54 |
$frm_vars['settings_routed'] = true;
|
55 |
return;
|
56 |
}
|
57 |
+
|
58 |
+
self::display_form( $errors, $message );
|
|
|
|
|
|
|
|
|
59 |
}
|
60 |
+
|
61 |
+
public static function route( $stop_load = false ) {
|
62 |
+
$action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
|
63 |
+
$action = FrmAppHelper::get_param( $action );
|
64 |
+
if ( $action == 'process-form' ) {
|
65 |
+
return self::process_form( $stop_load );
|
66 |
+
} else if ( $stop_load != 'stop_load' ) {
|
67 |
return self::display_form();
|
68 |
+
}
|
69 |
}
|
70 |
}
|
classes/controllers/FrmStatisticsController.php
CHANGED
@@ -1,32 +1,20 @@
|
|
1 |
<?php
|
2 |
-
if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
|
3 |
|
4 |
-
|
5 |
-
return;
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
public static function list_reports(){
|
23 |
-
$form = FrmAppHelper::get_param('form', false);
|
24 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list.php');
|
25 |
-
}
|
26 |
-
|
27 |
-
public static function list_displays(){
|
28 |
-
$form = FrmAppHelper::get_param('form', false);
|
29 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list_displays.php');
|
30 |
-
}
|
31 |
|
32 |
}
|
1 |
<?php
|
|
|
2 |
|
3 |
+
class FrmStatisticsController {
|
|
|
4 |
|
5 |
+
public static function menu() {
|
6 |
+
add_submenu_page( 'formidable', 'Formidable | '. __( 'Views', 'formidable' ), '<span class="frm_inactive_menu">'. __( 'Views', 'formidable' ) .'</span>', 'administrator', 'formidable-entry-templates', 'FrmStatisticsController::list_displays' );
|
7 |
+
}
|
8 |
+
|
9 |
+
public static function list_reports() {
|
10 |
+
add_filter('frm_form_stop_action_reports', '__return_true');
|
11 |
+
$form = FrmAppHelper::get_param('form', false);
|
12 |
+
require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list.php');
|
13 |
+
}
|
14 |
+
|
15 |
+
public static function list_displays() {
|
16 |
+
$form = FrmAppHelper::get_param('form', false);
|
17 |
+
require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list_displays.php');
|
18 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
}
|
classes/controllers/FrmStylesController.php
ADDED
@@ -0,0 +1,434 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class FrmStylesController {
|
4 |
+
public static $post_type = 'frm_styles';
|
5 |
+
public static $screen = 'formidable_page_formidable-styles';
|
6 |
+
|
7 |
+
public static function load_pro_hooks() {
|
8 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
9 |
+
FrmProStylesController::load_pro_hooks();
|
10 |
+
}
|
11 |
+
}
|
12 |
+
|
13 |
+
public static function register_post_types() {
|
14 |
+
register_post_type( self::$post_type, array(
|
15 |
+
'label' => __( 'Styles', 'formidable' ),
|
16 |
+
'public' => false,
|
17 |
+
'show_ui' => false,
|
18 |
+
'capability_type' => 'page',
|
19 |
+
'capabilities' => array(
|
20 |
+
'edit_post' => 'frm_change_settings',
|
21 |
+
'edit_posts' => 'frm_change_settings',
|
22 |
+
'edit_others_posts' => 'frm_change_settings',
|
23 |
+
'publish_posts' => 'frm_change_settings',
|
24 |
+
'delete_post' => 'frm_change_settings',
|
25 |
+
'delete_posts' => 'frm_change_settings',
|
26 |
+
'read_private_posts' => 'read_private_posts',
|
27 |
+
),
|
28 |
+
'supports' => array(
|
29 |
+
'title',
|
30 |
+
),
|
31 |
+
'has_archive' => false,
|
32 |
+
'labels' => array(
|
33 |
+
'name' => __( 'Styles', 'formidable' ),
|
34 |
+
'singular_name' => __( 'Style', 'formidable' ),
|
35 |
+
'menu_name' => __( 'Style', 'formidable' ),
|
36 |
+
'edit' => __( 'Edit' ),
|
37 |
+
'add_new_item' => __( 'Create a New Style', 'formidable' ),
|
38 |
+
'edit_item' => __( 'Edit Style', 'formidable' )
|
39 |
+
)
|
40 |
+
) );
|
41 |
+
}
|
42 |
+
|
43 |
+
public static function menu() {
|
44 |
+
add_submenu_page('formidable', 'Formidable | '. __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route');
|
45 |
+
}
|
46 |
+
|
47 |
+
public static function admin_init() {
|
48 |
+
if ( ! FrmAppHelper::is_admin_page('formidable-styles') ) {
|
49 |
+
return;
|
50 |
+
}
|
51 |
+
|
52 |
+
self::load_pro_hooks();
|
53 |
+
wp_enqueue_script('jquery-ui-datepicker');
|
54 |
+
|
55 |
+
$version = FrmAppHelper::plugin_version();
|
56 |
+
wp_enqueue_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array( 'jquery'), $version);
|
57 |
+
|
58 |
+
wp_enqueue_style('jquery-ui-base', FrmAppHelper::jquery_ui_base_url() .'/themes/base/ui.all.css');
|
59 |
+
wp_enqueue_style('frm-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_css');
|
60 |
+
|
61 |
+
$style = apply_filters('frm_style_head', false);
|
62 |
+
if ( $style ) {
|
63 |
+
wp_enqueue_style('frm-single-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_load_css&flat=1&'. http_build_query($style->post_content));
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
public static function new_style($return = '') {
|
68 |
+
FrmAppHelper::update_message( __( 'create multiple styling templates', 'formidable' ), 'wrap' );
|
69 |
+
self::load_styler('default');
|
70 |
+
}
|
71 |
+
|
72 |
+
public static function edit($style_id = false, $message = '') {
|
73 |
+
if ( ! $style_id ) {
|
74 |
+
$style_id = FrmAppHelper::get_param('id');
|
75 |
+
if ( empty($style_id) ) {
|
76 |
+
$style_id = 'default';
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
if ( 'default' == $style_id ) {
|
81 |
+
$style = 'default';
|
82 |
+
} else {
|
83 |
+
$frm_style = new FrmStyle($style_id);
|
84 |
+
$style = $frm_style->get_one();
|
85 |
+
$style = $style->ID;
|
86 |
+
}
|
87 |
+
|
88 |
+
self::load_styler($style, $message);
|
89 |
+
}
|
90 |
+
|
91 |
+
public static function save() {
|
92 |
+
$frm_style = new FrmStyle();
|
93 |
+
$message = '';
|
94 |
+
$post_id = ( $_POST && isset($_POST['ID']) ) ? $_POST['ID'] : false;
|
95 |
+
if ( $post_id !== false && isset($_POST['frm_style']) && wp_verify_nonce($_POST['frm_style'], 'frm_style_nonce') ) {
|
96 |
+
$id = $frm_style->update($post_id);
|
97 |
+
if ( empty($post_id) && ! empty($id) ) {
|
98 |
+
// set the post id to the new style so it will be loaded for editing
|
99 |
+
$post_id = reset($id);
|
100 |
+
}
|
101 |
+
// include the CSS that includes this style
|
102 |
+
echo '<link href="'. admin_url('admin-ajax.php') .'?action=frmpro_css" type="text/css" rel="Stylesheet" class="frm-custom-theme" />';
|
103 |
+
$message = __( 'Your styling settings have been saved.', 'formidable' );
|
104 |
+
}
|
105 |
+
|
106 |
+
return self::edit($post_id, $message);
|
107 |
+
}
|
108 |
+
|
109 |
+
public static function load_styler($style, $message = '') {
|
110 |
+
global $frm_settings;
|
111 |
+
|
112 |
+
$frm_style = new FrmStyle();
|
113 |
+
$styles = $frm_style->get_all();
|
114 |
+
|
115 |
+
if ( is_numeric($style) ) {
|
116 |
+
$style = $styles[ $style ];
|
117 |
+
} else if ( 'default' == $style ) {
|
118 |
+
$style = $frm_style->get_default_style($styles);
|
119 |
+
}
|
120 |
+
|
121 |
+
self::add_meta_boxes();
|
122 |
+
|
123 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/styles/show.php');
|
124 |
+
}
|
125 |
+
|
126 |
+
private static function manage($message = '', $forms = array()) {
|
127 |
+
$frm_style = new FrmStyle();
|
128 |
+
$styles = $frm_style->get_all();
|
129 |
+
$default_style = $frm_style->get_default_style($styles);
|
130 |
+
|
131 |
+
if ( empty($forms) ) {
|
132 |
+
$forms = FrmForm::get_published_forms();
|
133 |
+
}
|
134 |
+
|
135 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/styles/manage.php');
|
136 |
+
}
|
137 |
+
|
138 |
+
private static function manage_styles() {
|
139 |
+
if ( ! $_POST || ! isset($_POST['style']) || ! isset($_POST['frm_manage_style']) || ! wp_verify_nonce($_POST['frm_manage_style'], 'frm_manage_style_nonce') ) {
|
140 |
+
return self::manage();
|
141 |
+
}
|
142 |
+
|
143 |
+
global $wpdb;
|
144 |
+
|
145 |
+
$forms = FrmForm::get_published_forms();
|
146 |
+
foreach ( $forms as $form ) {
|
147 |
+
if ( $_POST['style'][ $form->id ] == $_POST['prev_style'][ $form->id ] ) {
|
148 |
+
continue;
|
149 |
+
}
|
150 |
+
|
151 |
+
$form->options['custom_style'] = $_POST['style'][ $form->id ];
|
152 |
+
|
153 |
+
$wpdb->update($wpdb->prefix .'frm_forms', array( 'options' => maybe_serialize($form->options)), array( 'id' => $form->id));
|
154 |
+
unset($form);
|
155 |
+
}
|
156 |
+
|
157 |
+
$message = __( 'Your form styles have been saved.', 'formidable' );
|
158 |
+
return self::manage($message, $forms);
|
159 |
+
}
|
160 |
+
|
161 |
+
public static function custom_css( $message = '', $style = null ) {
|
162 |
+
wp_enqueue_style('codemirror', FrmAppHelper::plugin_url() . '/css/codemirror.css');
|
163 |
+
wp_enqueue_script('codemirror', FrmAppHelper::plugin_url() . '/js/codemirror/codemirror.js', array(), '4.7');
|
164 |
+
wp_enqueue_script( 'codemirror-css', FrmAppHelper::plugin_url() . '/js/codemirror/css.js', array( 'codemirror' ), '4.7' );
|
165 |
+
|
166 |
+
if ( ! isset($style) ) {
|
167 |
+
$frm_style = new FrmStyle();
|
168 |
+
$style = $frm_style->get_default_style();
|
169 |
+
}
|
170 |
+
|
171 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/styles/custom_css.php');
|
172 |
+
}
|
173 |
+
|
174 |
+
public static function save_css() {
|
175 |
+
$frm_style = new FrmStyle();
|
176 |
+
|
177 |
+
$message = '';
|
178 |
+
$post_id = ( $_POST && isset($_POST['ID']) ) ? $_POST['ID'] : false;
|
179 |
+
if ( isset($_POST['frm_custom_css']) && wp_verify_nonce($_POST['frm_custom_css'], 'frm_custom_css_nonce') ) {
|
180 |
+
$frm_style->update($post_id);
|
181 |
+
$message = __( 'Your styling settings have been saved.', 'formidable' );
|
182 |
+
}
|
183 |
+
|
184 |
+
return self::custom_css($message);
|
185 |
+
}
|
186 |
+
|
187 |
+
public static function route() {
|
188 |
+
$action = FrmAppHelper::get_param('frm_action');
|
189 |
+
|
190 |
+
switch ( $action ) {
|
191 |
+
case 'edit':
|
192 |
+
case 'save':
|
193 |
+
case 'manage':
|
194 |
+
case 'manage_styles':
|
195 |
+
case 'custom_css':
|
196 |
+
case 'save_css':
|
197 |
+
return self::$action();
|
198 |
+
default:
|
199 |
+
do_action( 'frm_style_action_route', $action );
|
200 |
+
if ( apply_filters( 'frm_style_stop_action_route', false, $action ) ) {
|
201 |
+
return;
|
202 |
+
}
|
203 |
+
|
204 |
+
if ( 'new_style' == $action ) {
|
205 |
+
return self::$action();
|
206 |
+
}
|
207 |
+
|
208 |
+
return self::edit();
|
209 |
+
}
|
210 |
+
}
|
211 |
+
|
212 |
+
public static function reset_styling() {
|
213 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
214 |
+
|
215 |
+
$frm_style = new FrmStyle();
|
216 |
+
$defaults = $frm_style->get_defaults();
|
217 |
+
|
218 |
+
echo json_encode( $defaults );
|
219 |
+
wp_die();
|
220 |
+
}
|
221 |
+
|
222 |
+
public static function change_styling() {
|
223 |
+
check_ajax_referer( 'frm_ajax', 'nonce' );
|
224 |
+
|
225 |
+
$frm_style = new FrmStyle();
|
226 |
+
$defaults = $frm_style->get_defaults();
|
227 |
+
|
228 |
+
// remove the # from the colors
|
229 |
+
foreach ( $_GET['frm_style_setting']['post_content'] as $k => $v ) {
|
230 |
+
if ( ! is_array($v) && strpos($v, '#') === 0 ) {
|
231 |
+
$_GET['frm_style_setting']['post_content'][ $k ] = str_replace( '#', '', $v );
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
echo '<style type="text/css">';
|
236 |
+
include(FrmAppHelper::plugin_path() .'/css/_single_theme.css.php');
|
237 |
+
echo '</style>';
|
238 |
+
wp_die();
|
239 |
+
}
|
240 |
+
|
241 |
+
private static function add_meta_boxes() {
|
242 |
+
|
243 |
+
// setup meta boxes
|
244 |
+
$meta_boxes = array(
|
245 |
+
'general' => __( 'General', 'formidable' ),
|
246 |
+
'field-labels' => __( 'Field Labels', 'formidable' ),
|
247 |
+
'field-description' => __( 'Field Description', 'formidable' ),
|
248 |
+
'field-colors' => __( 'Field Colors', 'formidable' ),
|
249 |
+
'field-sizes' => __( 'Field Settings', 'formidable' ),
|
250 |
+
'check-box-radio-fields' => __( 'Check Box & Radio Fields', 'formidable' ),
|
251 |
+
'section-fields' => __( 'Section Fields', 'formidable' ),
|
252 |
+
'date-fields' => __( 'Date Fields', 'formidable' ),
|
253 |
+
'buttons' => __( 'Buttons', 'formidable' ),
|
254 |
+
'form-messages' => __( 'Form Messages', 'formidable' ),
|
255 |
+
);
|
256 |
+
|
257 |
+
foreach ( $meta_boxes as $nicename => $name ) {
|
258 |
+
add_meta_box( $nicename .'-style', $name, 'FrmStylesController::include_style_section', self::$screen, 'side', 'default', $nicename );
|
259 |
+
unset($nicename, $name);
|
260 |
+
}
|
261 |
+
}
|
262 |
+
|
263 |
+
public static function include_style_section($atts, $sec) {
|
264 |
+
extract($atts);
|
265 |
+
$current_tab = isset($_GET['page-tab']) ? $_GET['page-tab'] : 'default';
|
266 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/styles/_'. $sec['args'] .'.php');
|
267 |
+
}
|
268 |
+
|
269 |
+
public static function load_css() {
|
270 |
+
header('Content-type: text/css');
|
271 |
+
|
272 |
+
$frm_style = new FrmStyle();
|
273 |
+
$defaults = $frm_style->get_defaults();
|
274 |
+
|
275 |
+
include(FrmAppHelper::plugin_path() .'/css/_single_theme.css.php');
|
276 |
+
wp_die();
|
277 |
+
}
|
278 |
+
|
279 |
+
/**
|
280 |
+
* Check if the Formidable styling should be loaded,
|
281 |
+
* then enqueue it for the footer
|
282 |
+
* @since 2.0
|
283 |
+
*/
|
284 |
+
public static function enqueue_style() {
|
285 |
+
global $frm_vars;
|
286 |
+
|
287 |
+
if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
|
288 |
+
// the CSS has already been loaded
|
289 |
+
return;
|
290 |
+
}
|
291 |
+
|
292 |
+
$frm_settings = FrmAppHelper::get_settings();
|
293 |
+
if ( $frm_settings->load_style != 'none' ) {
|
294 |
+
wp_enqueue_style( 'formidable' );
|
295 |
+
$frm_vars['css_loaded'] = true;
|
296 |
+
}
|
297 |
+
}
|
298 |
+
|
299 |
+
// Get the stylesheets for the form settings page
|
300 |
+
public static function get_style_opts() {
|
301 |
+
$frm_style = new FrmStyle();
|
302 |
+
$styles = $frm_style->get_all();
|
303 |
+
|
304 |
+
return $styles;
|
305 |
+
}
|
306 |
+
|
307 |
+
public static function get_form_style( $form = 'default' ) {
|
308 |
+
$style = FrmFormsHelper::get_form_style( $form );
|
309 |
+
|
310 |
+
if ( empty( $style ) || 1 == $style ) {
|
311 |
+
$style = 'default';
|
312 |
+
}
|
313 |
+
|
314 |
+
$frm_style = new FrmStyle( $style );
|
315 |
+
return $frm_style->get_one();
|
316 |
+
}
|
317 |
+
|
318 |
+
/**
|
319 |
+
* @param string $class
|
320 |
+
* @param string $style
|
321 |
+
*/
|
322 |
+
public static function get_form_style_class($class, $style) {
|
323 |
+
if ( 1 == $style ) {
|
324 |
+
$style = 'default';
|
325 |
+
}
|
326 |
+
|
327 |
+
$frm_style = new FrmStyle($style);
|
328 |
+
$style = $frm_style->get_one();
|
329 |
+
|
330 |
+
if ( $style ) {
|
331 |
+
$class .= ' frm_style_'. $style->post_name;
|
332 |
+
}
|
333 |
+
|
334 |
+
return $class;
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* @param string $val
|
339 |
+
*/
|
340 |
+
public static function get_style_val($val, $form = 'default') {
|
341 |
+
$style = self::get_form_style($form);
|
342 |
+
if ( $style && isset( $style->post_content[ $val ] ) ) {
|
343 |
+
return $style->post_content[ $val ];
|
344 |
+
}
|
345 |
+
}
|
346 |
+
|
347 |
+
public static function show_entry_styles($default_styles) {
|
348 |
+
$frm_style = new FrmStyle('default');
|
349 |
+
$style = $frm_style->get_one();
|
350 |
+
|
351 |
+
if ( ! $style ) {
|
352 |
+
return $default_styles;
|
353 |
+
}
|
354 |
+
|
355 |
+
foreach ( $default_styles as $name => $val ) {
|
356 |
+
$setting = $name;
|
357 |
+
if ( 'border_width' == $name ) {
|
358 |
+
$setting = 'field_border_width';
|
359 |
+
} else if ( 'alt_bg_color' == $name ) {
|
360 |
+
$setting = 'bg_color_active';
|
361 |
+
}
|
362 |
+
$default_styles[ $name ] = $style->post_content[ $setting ];
|
363 |
+
unset($name, $val);
|
364 |
+
}
|
365 |
+
|
366 |
+
return $default_styles;
|
367 |
+
}
|
368 |
+
|
369 |
+
public static function &important_style($important, $field) {
|
370 |
+
$important = self::get_style_val('important_style', $field['form_id']);
|
371 |
+
return $important;
|
372 |
+
}
|
373 |
+
|
374 |
+
/**
|
375 |
+
* Fallback for WP < 3.6
|
376 |
+
*/
|
377 |
+
public static function do_accordion_sections( $screen, $context, $object ) {
|
378 |
+
if ( function_exists( 'do_accordion_sections' ) ) {
|
379 |
+
return do_accordion_sections( $screen, $context, $object );
|
380 |
+
}
|
381 |
+
|
382 |
+
global $wp_meta_boxes;
|
383 |
+
|
384 |
+
$screen = 'formidable_page_formidable-styles';
|
385 |
+
$screen = convert_to_screen( $screen );
|
386 |
+
|
387 |
+
$page = $screen->id;
|
388 |
+
|
389 |
+
$hidden = get_hidden_meta_boxes( $screen );
|
390 |
+
?>
|
391 |
+
<div id="side-sortables" class="accordion-container">
|
392 |
+
<?php
|
393 |
+
$i = 0;
|
394 |
+
$first_open = false;
|
395 |
+
do {
|
396 |
+
if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[ $page ] ) || ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
|
397 |
+
break;
|
398 |
+
}
|
399 |
+
|
400 |
+
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
|
401 |
+
if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
|
402 |
+
foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
|
403 |
+
if ( false == $box || ! $box['title'] ) {
|
404 |
+
continue;
|
405 |
+
}
|
406 |
+
|
407 |
+
$i++;
|
408 |
+
$hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
|
409 |
+
|
410 |
+
if ( ! $first_open && empty( $hidden_class ) ) {
|
411 |
+
$first_open = true;
|
412 |
+
}
|
413 |
+
|
414 |
+
?>
|
415 |
+
<div class="postbox <?php echo esc_attr( $box['id'] ); ?>">
|
416 |
+
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'formidable' ) ?>"><br/></div>
|
417 |
+
<h3 class='hndle'><span><?php echo esc_html( $box['title'] ); ?></span></h3>
|
418 |
+
<div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
|
419 |
+
<div class="inside">
|
420 |
+
<?php call_user_func( $box['callback'], $object, $box ); ?>
|
421 |
+
</div><!-- .inside -->
|
422 |
+
</div><!-- .accordion-section-content -->
|
423 |
+
</div><!-- .postbox -->
|
424 |
+
<?php
|
425 |
+
}
|
426 |
+
}
|
427 |
+
}
|
428 |
+
} while ( 0 );
|
429 |
+
?>
|
430 |
+
</div><!-- .accordion-container -->
|
431 |
+
<?php
|
432 |
+
return $i;
|
433 |
+
}
|
434 |
+
}
|
classes/controllers/FrmXMLController.php
CHANGED
@@ -1,326 +1,294 @@
|
|
1 |
<?php
|
2 |
-
if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
|
3 |
|
4 |
-
class FrmXMLController{
|
5 |
-
|
6 |
-
add_action('admin_menu', 'FrmXMLController::menu', 41);
|
7 |
-
add_action('wp_ajax_frm_export_xml', 'FrmXMLController::export_xml');
|
8 |
-
}
|
9 |
-
|
10 |
public static function menu() {
|
11 |
-
add_submenu_page('formidable', 'Formidable | Import/Export', 'Import/Export', 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route');
|
12 |
}
|
13 |
-
|
14 |
public static function add_default_templates() {
|
15 |
-
if ( !function_exists( 'libxml_disable_entity_loader' ) ){
|
16 |
// XML import is not enabled on your server
|
17 |
return;
|
18 |
}
|
19 |
-
|
20 |
-
include_once(FrmAppHelper::plugin_path() .'/classes/helpers/FrmXMLHelper.php');
|
21 |
-
|
22 |
$set_err = libxml_use_internal_errors(true);
|
23 |
$loader = libxml_disable_entity_loader( true );
|
24 |
-
|
25 |
$files = apply_filters('frm_default_templates_files', array(FrmAppHelper::plugin_path() .'/classes/views/xml/default-templates.xml'));
|
26 |
-
|
27 |
-
foreach ( (array) $files as $file) {
|
28 |
-
|
29 |
unset($file);
|
30 |
}
|
|
|
31 |
if(is_wp_error($result))
|
32 |
$errors[] = $result->get_error_message();
|
33 |
else if($result)
|
34 |
$message = $result;
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
38 |
libxml_use_internal_errors( $set_err );
|
39 |
libxml_disable_entity_loader( $loader );
|
40 |
}
|
41 |
-
|
42 |
public static function route() {
|
43 |
-
$action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
|
44 |
-
$action = FrmAppHelper::get_param($action);
|
45 |
-
|
46 |
return self::import_xml();
|
47 |
-
|
48 |
return self::export_xml();
|
49 |
} else {
|
50 |
-
if ( apply_filters('frm_xml_route', true, $action) ){
|
51 |
return self::form();
|
52 |
}
|
53 |
}
|
54 |
}
|
55 |
-
|
56 |
-
public static function form($errors = array(), $message = '') {
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
$forms = $frm_form->getAll("status is NULL OR status = '' OR status = 'published'", ' ORDER BY name');
|
62 |
-
unset($frm_form);
|
63 |
-
|
64 |
-
$export_types = apply_filters('frm_xml_export_types',
|
65 |
-
array('forms' => __('Forms', 'formidable'))
|
66 |
);
|
67 |
-
|
68 |
-
$export_format = apply_filters('frm_export_formats', array(
|
69 |
-
'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
|
70 |
-
));
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
75 |
include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php');
|
76 |
}
|
77 |
-
|
78 |
public static function import_xml() {
|
79 |
$errors = array();
|
80 |
$message = '';
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
$errors[] = $
|
85 |
self::form($errors);
|
86 |
return;
|
87 |
}
|
88 |
-
|
89 |
-
if ( !isset($_FILES) || !isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int)$_FILES['frm_import_file']['size'] < 1) {
|
90 |
$errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
|
91 |
self::form($errors);
|
92 |
return;
|
93 |
}
|
94 |
-
|
95 |
$file = $_FILES['frm_import_file']['tmp_name'];
|
96 |
-
|
97 |
-
if ( !is_uploaded_file($file) ) {
|
98 |
unset($file);
|
99 |
$errors[] = __( 'The file does not exist, please try again.', 'formidable' );
|
100 |
self::form($errors);
|
101 |
return;
|
102 |
}
|
103 |
-
|
104 |
//add_filter('upload_mimes', 'FrmXMLController::allow_mime');
|
105 |
-
|
106 |
-
$export_format = apply_filters('frm_export_formats', array(
|
107 |
'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
|
108 |
));
|
109 |
-
|
110 |
$file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
|
111 |
-
if ( $file_type != 'xml' && isset($export_format[$file_type]) ) {
|
112 |
// allow other file types to be imported
|
113 |
do_action('frm_before_import_'. $file_type );
|
114 |
return;
|
115 |
}
|
116 |
unset($file_type);
|
117 |
-
|
118 |
//$media_id = FrmProAppHelper::upload_file('frm_import_file');
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
$t_strings = array(
|
138 |
-
'imported' => __('Imported', 'formidable'),
|
139 |
-
'updated' => __('Updated', 'formidable'),
|
140 |
-
);
|
141 |
-
|
142 |
-
$message = '<ul>';
|
143 |
-
foreach ( $result as $type => $results ) {
|
144 |
-
if ( !isset($t_strings[$type]) ) {
|
145 |
-
// only print imported and updated
|
146 |
-
continue;
|
147 |
-
}
|
148 |
-
|
149 |
-
$s_message = array();
|
150 |
-
foreach ( $results as $k => $m ) {
|
151 |
-
if ( $m ) {
|
152 |
-
$strings = array(
|
153 |
-
'forms' => sprintf(_n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
|
154 |
-
'fields' => sprintf(_n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m),
|
155 |
-
'items' => sprintf(_n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m),
|
156 |
-
'views' => sprintf(_n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m),
|
157 |
-
'posts' => sprintf(_n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m),
|
158 |
-
'terms' => sprintf(_n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m),
|
159 |
-
);
|
160 |
-
|
161 |
-
$s_message[] = isset($strings[$k]) ? $strings[$k] : $t_strings[$type] .' '. $m .' '. ucfirst($k);
|
162 |
-
}
|
163 |
-
unset($k);
|
164 |
-
unset($m);
|
165 |
-
}
|
166 |
-
|
167 |
-
if ( !empty($s_message) ) {
|
168 |
-
$message .= '<li><strong>'. $t_strings[$type] .':</strong> ';
|
169 |
-
$message .= implode(', ', $s_message);
|
170 |
-
$message .= '</li>';
|
171 |
-
}
|
172 |
-
|
173 |
-
}
|
174 |
-
|
175 |
-
if ( $message == '<ul>' ) {
|
176 |
-
$message = '';
|
177 |
-
$errors[] = __('Nothing was imported or updated', 'formidable');
|
178 |
-
} else {
|
179 |
-
$message .= '</ul>';
|
180 |
-
}
|
181 |
-
} else {
|
182 |
-
$message = $result;
|
183 |
-
}
|
184 |
-
}
|
185 |
-
|
186 |
-
unset($file);
|
187 |
-
|
188 |
-
libxml_use_internal_errors( $set_err );
|
189 |
-
libxml_disable_entity_loader( $loader );
|
190 |
-
//}else{
|
191 |
-
// foreach ($media_id->errors as $error)
|
192 |
-
// echo $error[0];
|
193 |
-
//}
|
194 |
-
|
195 |
self::form($errors, $message);
|
196 |
}
|
197 |
-
|
198 |
public static function export_xml() {
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
die();
|
203 |
}
|
204 |
-
|
205 |
-
|
|
|
206 |
$ids = $_POST['frm_export_forms'];
|
207 |
-
} else {
|
208 |
-
$ids = array();
|
209 |
}
|
210 |
-
|
211 |
-
|
|
|
212 |
$type = $_POST['type'];
|
213 |
}
|
214 |
-
|
215 |
$format = isset($_POST['format']) ? $_POST['format'] : 'xml';
|
216 |
-
|
217 |
-
if ( !headers_sent() &&
|
218 |
wp_redirect(admin_url('admin.php?page=formidable-import'));
|
219 |
die();
|
220 |
}
|
221 |
-
|
222 |
if ( $format == 'xml' ) {
|
223 |
self::generate_xml($type, compact('ids'));
|
224 |
} else {
|
225 |
do_action('frm_export_format_'. $format, compact('ids'));
|
226 |
}
|
227 |
-
|
228 |
-
|
229 |
-
}
|
230 |
-
|
231 |
-
public static function export_xml_direct($controller = 'forms', $ids = false) {
|
232 |
-
if ( !current_user_can('frm_edit_forms') ) {
|
233 |
-
global $frm_settings;
|
234 |
-
wp_die($frm_settings->admin_permission);
|
235 |
-
}
|
236 |
-
$is_template = FrmAppHelper::get_param('is_template', false);
|
237 |
-
self::generate_xml($controller, compact('ids', 'is_template'));
|
238 |
-
die();
|
239 |
}
|
240 |
-
|
241 |
public static function generate_xml($type, $args = array() ) {
|
242 |
global $wpdb;
|
243 |
-
|
244 |
-
$type = (array)$type;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
$tables = array(
|
246 |
-
'items'
|
247 |
-
'forms'
|
248 |
-
'
|
|
|
|
|
249 |
);
|
250 |
-
|
251 |
-
$defaults = array('ids' => false);
|
252 |
$args = wp_parse_args( $args, $defaults );
|
253 |
-
|
254 |
$sitename = sanitize_key( get_bloginfo( 'name' ) );
|
255 |
-
|
256 |
-
if ( ! empty($sitename) )
|
|
|
|
|
257 |
$filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
|
258 |
|
259 |
header( 'Content-Description: File Transfer' );
|
260 |
header( 'Content-Disposition: attachment; filename=' . $filename );
|
261 |
header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
|
262 |
-
|
263 |
//make sure ids are numeric
|
264 |
-
if(is_array($args['ids']) && !empty($args['ids']))
|
265 |
-
$args['ids'] =
|
266 |
-
|
|
|
267 |
$records = array();
|
268 |
-
|
269 |
-
|
270 |
-
$where =
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
}
|
296 |
|
297 |
-
|
298 |
-
$where = "WHERE ". $where;
|
299 |
-
|
300 |
-
$records[$tb_type] = $wpdb->get_col( "SELECT $select FROM $table $join $where" );
|
301 |
unset($tb_type);
|
302 |
}
|
303 |
-
|
304 |
-
include_once(FrmAppHelper::plugin_path() .'/classes/helpers/FrmXMLHelper.php');
|
305 |
|
306 |
-
$frm_field = new FrmField();
|
307 |
-
|
308 |
echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
|
309 |
include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php');
|
310 |
}
|
311 |
-
|
312 |
-
function allow_mime($mimes) {
|
313 |
-
if ( !isset($mimes['csv']) ) {
|
314 |
// allow csv files
|
315 |
$mimes['csv'] = 'text/csv';
|
316 |
}
|
317 |
-
|
318 |
-
if ( !isset($mimes['xml']) ) {
|
319 |
// allow xml
|
320 |
$mimes['xml'] = 'text/xml';
|
321 |
}
|
322 |
|
323 |
return $mimes;
|
324 |
}
|
325 |
-
|
326 |
}
|
1 |
<?php
|
|
|
2 |
|
3 |
+
class FrmXMLController {
|
4 |
+
|
|
|
|
|
|
|
|
|
5 |
public static function menu() {
|
6 |
+
add_submenu_page('formidable', 'Formidable | '. __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route');
|
7 |
}
|
8 |
+
|
9 |
public static function add_default_templates() {
|
10 |
+
if ( !function_exists( 'libxml_disable_entity_loader' ) ) {
|
11 |
// XML import is not enabled on your server
|
12 |
return;
|
13 |
}
|
14 |
+
|
|
|
|
|
15 |
$set_err = libxml_use_internal_errors(true);
|
16 |
$loader = libxml_disable_entity_loader( true );
|
17 |
+
|
18 |
$files = apply_filters('frm_default_templates_files', array(FrmAppHelper::plugin_path() .'/classes/views/xml/default-templates.xml'));
|
19 |
+
|
20 |
+
foreach ( (array) $files as $file ) {
|
21 |
+
FrmXMLHelper::import_xml($file);
|
22 |
unset($file);
|
23 |
}
|
24 |
+
/*
|
25 |
if(is_wp_error($result))
|
26 |
$errors[] = $result->get_error_message();
|
27 |
else if($result)
|
28 |
$message = $result;
|
29 |
+
*/
|
30 |
+
|
31 |
+
unset( $files );
|
32 |
+
|
33 |
libxml_use_internal_errors( $set_err );
|
34 |
libxml_disable_entity_loader( $loader );
|
35 |
}
|
36 |
+
|
37 |
public static function route() {
|
38 |
+
$action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
|
39 |
+
$action = FrmAppHelper::get_param( $action );
|
40 |
+
if ( $action == 'import_xml' ) {
|
41 |
return self::import_xml();
|
42 |
+
} else if ( $action == 'export_xml' ) {
|
43 |
return self::export_xml();
|
44 |
} else {
|
45 |
+
if ( apply_filters( 'frm_xml_route', true, $action ) ) {
|
46 |
return self::form();
|
47 |
}
|
48 |
}
|
49 |
}
|
50 |
+
|
51 |
+
public static function form( $errors = array(), $message = '' ) {
|
52 |
+
$forms = FrmForm::getAll( array( 'status' => array( null, '', 'published' ) ), 'name' );
|
53 |
+
|
54 |
+
$export_types = apply_filters( 'frm_xml_export_types',
|
55 |
+
array( 'forms' => __( 'Forms', 'formidable' ) )
|
|
|
|
|
|
|
|
|
|
|
56 |
);
|
57 |
+
|
58 |
+
$export_format = apply_filters( 'frm_export_formats', array(
|
59 |
+
'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ),
|
60 |
+
) );
|
61 |
+
|
62 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
63 |
+
$frmpro_settings = new FrmProSettings();
|
64 |
+
$csv_format = $frmpro_settings->csv_format;
|
65 |
+
} else {
|
66 |
+
$csv_format = 'UTF-8';
|
67 |
+
}
|
68 |
+
|
69 |
include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php');
|
70 |
}
|
71 |
+
|
72 |
public static function import_xml() {
|
73 |
$errors = array();
|
74 |
$message = '';
|
75 |
+
|
76 |
+
$permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce');
|
77 |
+
if ( $permission_error !== false ) {
|
78 |
+
$errors[] = $permission_error;
|
79 |
self::form($errors);
|
80 |
return;
|
81 |
}
|
82 |
+
|
83 |
+
if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) {
|
84 |
$errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
|
85 |
self::form($errors);
|
86 |
return;
|
87 |
}
|
88 |
+
|
89 |
$file = $_FILES['frm_import_file']['tmp_name'];
|
90 |
+
|
91 |
+
if ( ! is_uploaded_file( $file ) ) {
|
92 |
unset($file);
|
93 |
$errors[] = __( 'The file does not exist, please try again.', 'formidable' );
|
94 |
self::form($errors);
|
95 |
return;
|
96 |
}
|
97 |
+
|
98 |
//add_filter('upload_mimes', 'FrmXMLController::allow_mime');
|
99 |
+
|
100 |
+
$export_format = apply_filters('frm_export_formats', array(
|
101 |
'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
|
102 |
));
|
103 |
+
|
104 |
$file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
|
105 |
+
if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) {
|
106 |
// allow other file types to be imported
|
107 |
do_action('frm_before_import_'. $file_type );
|
108 |
return;
|
109 |
}
|
110 |
unset($file_type);
|
111 |
+
|
112 |
//$media_id = FrmProAppHelper::upload_file('frm_import_file');
|
113 |
+
|
114 |
+
if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
|
115 |
+
$errors[] = __( 'XML import is not enabled on your server.', 'formidable' );
|
116 |
+
self::form( $errors );
|
117 |
+
return;
|
118 |
+
}
|
119 |
+
|
120 |
+
$set_err = libxml_use_internal_errors( true );
|
121 |
+
$loader = libxml_disable_entity_loader( true );
|
122 |
+
|
123 |
+
$result = FrmXMLHelper::import_xml( $file );
|
124 |
+
FrmXMLHelper::parse_message( $result, $message, $errors );
|
125 |
+
|
126 |
+
unset( $file );
|
127 |
+
|
128 |
+
libxml_use_internal_errors( $set_err );
|
129 |
+
libxml_disable_entity_loader( $loader );
|
130 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
self::form($errors, $message);
|
132 |
}
|
133 |
+
|
134 |
public static function export_xml() {
|
135 |
+
$error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' );
|
136 |
+
if ( ! empty($error) ) {
|
137 |
+
wp_die( $error );
|
|
|
138 |
}
|
139 |
+
|
140 |
+
$ids = array();
|
141 |
+
if ( isset($_POST['frm_export_forms']) ) {
|
142 |
$ids = $_POST['frm_export_forms'];
|
|
|
|
|
143 |
}
|
144 |
+
|
145 |
+
$type = false;
|
146 |
+
if ( isset($_POST['type']) ) {
|
147 |
$type = $_POST['type'];
|
148 |
}
|
149 |
+
|
150 |
$format = isset($_POST['format']) ? $_POST['format'] : 'xml';
|
151 |
+
|
152 |
+
if ( ! headers_sent() && ! $type ) {
|
153 |
wp_redirect(admin_url('admin.php?page=formidable-import'));
|
154 |
die();
|
155 |
}
|
156 |
+
|
157 |
if ( $format == 'xml' ) {
|
158 |
self::generate_xml($type, compact('ids'));
|
159 |
} else {
|
160 |
do_action('frm_export_format_'. $format, compact('ids'));
|
161 |
}
|
162 |
+
|
163 |
+
wp_die();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
}
|
165 |
+
|
166 |
public static function generate_xml($type, $args = array() ) {
|
167 |
global $wpdb;
|
168 |
+
|
169 |
+
$type = (array) $type;
|
170 |
+
if ( in_array( 'items', $type) && ! in_array( 'forms', $type) ) {
|
171 |
+
// make sure the form is included if there are entries
|
172 |
+
$type[] = 'forms';
|
173 |
+
}
|
174 |
+
|
175 |
+
if ( in_array( 'forms', $type) ) {
|
176 |
+
// include actions with forms
|
177 |
+
$type[] = 'actions';
|
178 |
+
}
|
179 |
+
|
180 |
$tables = array(
|
181 |
+
'items' => $wpdb->prefix .'frm_items',
|
182 |
+
'forms' => $wpdb->prefix .'frm_forms',
|
183 |
+
'posts' => $wpdb->posts,
|
184 |
+
'styles' => $wpdb->posts,
|
185 |
+
'actions' => $wpdb->posts,
|
186 |
);
|
187 |
+
|
188 |
+
$defaults = array( 'ids' => false);
|
189 |
$args = wp_parse_args( $args, $defaults );
|
190 |
+
|
191 |
$sitename = sanitize_key( get_bloginfo( 'name' ) );
|
192 |
+
|
193 |
+
if ( ! empty( $sitename ) ) {
|
194 |
+
$sitename .= '.';
|
195 |
+
}
|
196 |
$filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
|
197 |
|
198 |
header( 'Content-Description: File Transfer' );
|
199 |
header( 'Content-Disposition: attachment; filename=' . $filename );
|
200 |
header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
|
201 |
+
|
202 |
//make sure ids are numeric
|
203 |
+
if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) {
|
204 |
+
$args['ids'] = array_filter( $args['ids'], 'is_numeric' );
|
205 |
+
}
|
206 |
+
|
207 |
$records = array();
|
208 |
+
|
209 |
+
foreach ( $type as $tb_type ) {
|
210 |
+
$where = array();
|
211 |
+
$join = '';
|
212 |
+
$table = $tables[ $tb_type ];
|
213 |
+
|
214 |
+
$select = $table .'.id';
|
215 |
+
$query_vars = array();
|
216 |
+
|
217 |
+
switch ( $tb_type ) {
|
218 |
+
case 'forms':
|
219 |
+
//add forms
|
220 |
+
if ( $args['ids'] ) {
|
221 |
+
$where[] = array( 'or' => 1, $table . '.id' => $args['ids'], $table .'.parent_form_id' => $args['ids'] );
|
222 |
+
} else {
|
223 |
+
$where[ $table . '.status !' ] = 'draft';
|
224 |
+
}
|
225 |
+
break;
|
226 |
+
case 'actions':
|
227 |
+
$select = $table .'.ID';
|
228 |
+
$where['post_type'] = FrmFormActionsController::$action_post_type;
|
229 |
+
if ( ! empty($args['ids']) ) {
|
230 |
+
$where['menu_order'] = $args['ids'];
|
231 |
+
}
|
232 |
+
break;
|
233 |
+
case 'items':
|
234 |
+
//$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
|
235 |
+
if ( $args['ids'] ) {
|
236 |
+
$where[ $table . '.form_id' ] = $args['ids'];
|
237 |
+
}
|
238 |
+
break;
|
239 |
+
case 'styles':
|
240 |
+
// Loop through all exported forms and get their selected style IDs
|
241 |
+
$form_ids = $args['ids'];
|
242 |
+
$style_ids = array();
|
243 |
+
foreach ( $form_ids as $form_id ) {
|
244 |
+
$form_data = FrmForm::getOne( $form_id );
|
245 |
+
// For forms that have not been updated while running 2.0, check if custom_style is set
|
246 |
+
if ( isset( $form_data->options['custom_style'] ) ) {
|
247 |
+
$style_ids[] = $form_data->options['custom_style'];
|
248 |
+
}
|
249 |
+
unset( $form_id, $form_data );
|
250 |
+
}
|
251 |
+
$select = $table .'.ID';
|
252 |
+
$where['post_type'] = 'frm_styles';
|
253 |
+
|
254 |
+
// Only export selected styles
|
255 |
+
if ( ! empty( $style_ids ) ) {
|
256 |
+
$where['ID'] = $style_ids;
|
257 |
+
}
|
258 |
+
break;
|
259 |
+
default:
|
260 |
+
$select = $table .'.ID';
|
261 |
+
$join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
|
262 |
+
$where['pm.meta_key'] = 'frm_form_id';
|
263 |
+
|
264 |
+
if ( empty($args['ids']) ) {
|
265 |
+
$where['pm.meta_value >'] = 1;
|
266 |
+
} else {
|
267 |
+
$where['pm.meta_value'] = $args['ids'];
|
268 |
+
}
|
269 |
+
break;
|
270 |
}
|
271 |
|
272 |
+
$records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select );
|
|
|
|
|
|
|
273 |
unset($tb_type);
|
274 |
}
|
|
|
|
|
275 |
|
|
|
|
|
276 |
echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
|
277 |
include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php');
|
278 |
}
|
279 |
+
|
280 |
+
public static function allow_mime($mimes) {
|
281 |
+
if ( ! isset( $mimes['csv'] ) ) {
|
282 |
// allow csv files
|
283 |
$mimes['csv'] = 'text/csv';
|
284 |
}
|
285 |
+
|
286 |
+
if ( ! isset( $mimes['xml'] ) ) {
|
287 |
// allow xml
|
288 |
$mimes['xml'] = 'text/xml';
|
289 |
}
|
290 |
|
291 |
return $mimes;
|
292 |
}
|
293 |
+
|
294 |
}
|
classes/helpers/FrmAppHelper.php
CHANGED
@@ -1,277 +1,909 @@
|
|
1 |
<?php
|
2 |
-
if(!defined('ABSPATH'))
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
return
|
20 |
}
|
21 |
-
|
22 |
-
public static function
|
|
|
|
|
|
|
|
|
23 |
return dirname(dirname(dirname(__FILE__)));
|
24 |
}
|
25 |
-
|
26 |
-
public static function plugin_url($url=''){
|
27 |
//prevously FRM_URL constant
|
28 |
-
if(empty($url))
|
29 |
-
$url = plugins_url('', '
|
30 |
-
|
|
|
|
|
31 |
$url = str_replace('http://', 'https://', $url);
|
32 |
-
|
|
|
33 |
return $url;
|
34 |
}
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
37 |
$url = self::plugin_url(site_url());
|
38 |
return $url;
|
39 |
}
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
$params = explode('[', $param);
|
44 |
-
$param = $params[0];
|
45 |
}
|
46 |
|
47 |
-
|
48 |
-
$value =
|
49 |
-
if(!isset($_POST[$param])
|
50 |
-
$value = stripslashes_deep(htmlspecialchars_decode(urldecode($_GET[$param])));
|
51 |
-
|
52 |
-
|
|
|
53 |
}
|
54 |
-
|
55 |
-
|
56 |
-
foreach($params as $k => $p){
|
57 |
-
if(
|
58 |
continue;
|
59 |
-
|
|
|
60 |
$p = trim($p, ']');
|
61 |
-
$value =
|
62 |
}
|
63 |
}
|
64 |
|
65 |
return $value;
|
66 |
}
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
public static function is_true($value) {
|
82 |
return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
|
83 |
}
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
foreach ( (array) $scripts as $s ) {
|
87 |
wp_enqueue_script($s);
|
88 |
}
|
89 |
}
|
90 |
-
|
91 |
-
public static function load_styles($styles){
|
|
|
92 |
foreach ( (array) $styles as $s ) {
|
93 |
wp_enqueue_style($s);
|
94 |
}
|
95 |
}
|
96 |
-
|
97 |
-
public static function get_pages(){
|
98 |
-
|
99 |
}
|
100 |
-
|
101 |
-
public static function wp_pages_dropdown($field_name, $page_id, $truncate=false){
|
102 |
-
$pages =
|
103 |
?>
|
104 |
-
<select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-pages-dropdown">
|
105 |
-
<option value=""
|
106 |
-
<?php foreach($pages as $page){ ?>
|
107 |
-
<option value="<?php echo $page->ID; ?>" <?php
|
|
|
|
|
108 |
<?php } ?>
|
109 |
</select>
|
110 |
<?php
|
111 |
}
|
112 |
-
|
113 |
-
public static function
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
?>
|
120 |
-
<select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>"
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
<?php
|
125 |
-
unset($role);
|
126 |
-
unset($details);
|
127 |
-
} ?>
|
128 |
</select>
|
129 |
<?php
|
130 |
}
|
131 |
-
|
132 |
-
public static function
|
133 |
global $frm_vars;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
$cap = array(
|
135 |
-
'frm_view_forms' => __('View Forms and Templates', 'formidable'),
|
136 |
-
'frm_edit_forms' => __('Add/Edit Forms and Templates', 'formidable'),
|
137 |
-
'frm_delete_forms' => __('Delete Forms and Templates', 'formidable'),
|
138 |
-
'frm_change_settings' => __('Access this Settings Page', 'formidable')
|
|
|
|
|
139 |
);
|
140 |
-
|
141 |
-
|
142 |
-
$cap
|
143 |
-
$cap['frm_edit_entries'] = __('Edit Entries from Admin Area', 'formidable');
|
144 |
-
$cap['frm_delete_entries'] = __('Delete Entries from Admin Area', 'formidable');
|
145 |
-
$cap['frm_view_reports'] = __('View Reports', 'formidable');
|
146 |
-
$cap['frm_edit_displays'] = __('Add/Edit Views', 'formidable');
|
147 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
return $cap;
|
149 |
}
|
150 |
-
|
151 |
-
public static function user_has_permission($needed_role){
|
152 |
-
if($needed_role == '-1')
|
153 |
return false;
|
154 |
-
|
155 |
-
|
|
|
|
|
156 |
return true;
|
157 |
-
|
|
|
158 |
$roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
|
159 |
-
foreach ($roles as $role){
|
160 |
-
|
161 |
return true;
|
162 |
-
|
|
|
163 |
break;
|
|
|
164 |
}
|
165 |
return false;
|
166 |
}
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
echo ' checked="checked"';
|
|
|
171 |
}
|
172 |
-
|
173 |
-
public static function check_selected($values, $current){
|
174 |
-
|
175 |
-
// $current = (isset($current['value'])) ? $current['value'] : $current['label'];
|
176 |
-
|
177 |
-
if(is_array($values))
|
178 |
-
$values = array_map(array('FrmAppHelper', 'recursive_trim'), $values);
|
179 |
-
else
|
180 |
-
$values = trim($values);
|
181 |
$current = trim($current);
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
}
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
public static function recursive_trim(&$value) {
|
199 |
-
if (is_array($value))
|
200 |
-
|
201 |
-
else
|
202 |
$value = trim($value);
|
203 |
-
|
|
|
204 |
return $value;
|
205 |
}
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
public static function esc_textarea( $text ) {
|
208 |
$safe_text = str_replace('"', '"', $text);
|
209 |
$safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
|
210 |
return apply_filters( 'esc_textarea', $safe_text, $text );
|
211 |
}
|
212 |
-
|
213 |
-
|
214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
return $val;
|
216 |
}
|
217 |
-
|
218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
global $wp_scripts;
|
220 |
-
if(
|
221 |
return false;
|
222 |
-
|
|
|
223 |
$ver = 0;
|
224 |
-
|
225 |
-
if ( isset($wp_scripts->registered[$handle]) )
|
226 |
-
|
227 |
-
|
228 |
-
|
|
|
|
|
229 |
$ver = $query->ver;
|
|
|
230 |
|
231 |
return $ver;
|
232 |
}
|
233 |
-
|
234 |
-
public static function js_redirect($url){
|
235 |
-
|
236 |
}
|
237 |
-
|
238 |
-
public static function
|
239 |
-
if (
|
240 |
-
|
241 |
-
include $filename;
|
242 |
-
$contents = ob_get_contents();
|
243 |
-
ob_end_clean();
|
244 |
-
return $contents;
|
245 |
}
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
}
|
248 |
-
|
249 |
-
|
|
|
|
|
|
|
|
|
250 |
global $wpdb;
|
251 |
|
252 |
$key = '';
|
253 |
-
|
254 |
-
if (!empty($name)){
|
255 |
$key = sanitize_key($name);
|
256 |
}
|
257 |
-
|
258 |
-
|
259 |
$max_slug_value = pow(36, $num_chars);
|
260 |
$min_slug_value = 37; // we want to have at least 2 characters in the slug
|
261 |
$key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
|
262 |
}
|
263 |
|
264 |
-
if (is_numeric($key)
|
265 |
$key = $key .'a';
|
266 |
-
|
267 |
-
|
268 |
-
$key_check =
|
269 |
-
|
270 |
-
if ($key_check
|
271 |
$suffix = 2;
|
272 |
do {
|
273 |
-
$alt_post_name = substr($key, 0, 200-(strlen($suffix)+1)).
|
274 |
-
|
275 |
$suffix++;
|
276 |
} while ($key_check || is_numeric($key_check));
|
277 |
$key = $alt_post_name;
|
@@ -279,545 +911,808 @@ class FrmAppHelper{
|
|
279 |
return $key;
|
280 |
}
|
281 |
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
$post_values = stripslashes_deep($_POST);
|
289 |
-
|
290 |
-
|
|
|
291 |
|
292 |
-
foreach ( array('name', 'description') as $var ) {
|
293 |
$default_val = isset($record->{$var}) ? $record->{$var} : '';
|
294 |
-
$values[$var] =
|
295 |
unset($var, $default_val);
|
296 |
}
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
foreach ( (array) $fields as $field ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
'
|
324 |
-
'default_value' => $field->default_value,
|
325 |
-
'name' => $field->name,
|
326 |
-
'description' => $field->description,
|
327 |
-
'type' => apply_filters('frm_field_type', $field_type, $field, $new_value),
|
328 |
-
'options' => $field->options,
|
329 |
-
'required' => $field->required,
|
330 |
-
'field_key' => $field->field_key,
|
331 |
-
'field_order' => $field->field_order,
|
332 |
-
'form_id' => $field->form_id
|
333 |
-
);
|
334 |
-
|
335 |
-
/*if(in_array($field_array['type'], array('checkbox', 'radio', 'select')) and !empty($field_array['options'])){
|
336 |
-
foreach((array)$field_array['options'] as $opt_key => $opt){
|
337 |
-
if(!is_array($opt))
|
338 |
-
$field_array['options'][$opt_key] = array('label' => $opt);
|
339 |
-
unset($opt);
|
340 |
-
unset($opt_key);
|
341 |
-
}
|
342 |
-
}*/
|
343 |
-
|
344 |
-
$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
|
345 |
-
|
346 |
-
foreach ($opt_defaults as $opt => $default_opt){
|
347 |
-
$field_array[$opt] = ($post_values && isset($post_values['field_options'][$opt.'_'.$field->id]) ) ? maybe_unserialize($post_values['field_options'][$opt.'_'.$field->id]) : (isset($field->field_options[$opt]) ? $field->field_options[$opt] : $default_opt);
|
348 |
-
if($opt == 'blank' and $field_array[$opt] == ''){
|
349 |
-
$field_array[$opt] = $frm_settings->blank_msg;
|
350 |
-
}else if($opt == 'invalid' and $field_array[$opt] == ''){
|
351 |
-
if($field_type == 'captcha')
|
352 |
-
$field_array[$opt] = $frm_settings->re_msg;
|
353 |
-
else
|
354 |
-
$field_array[$opt] = sprintf(__('%s is invalid', 'formidable'), $field_array['name']);
|
355 |
-
}
|
356 |
-
}
|
357 |
-
|
358 |
-
unset($opt_defaults);
|
359 |
-
|
360 |
-
if ($field_array['custom_html'] == '')
|
361 |
-
$field_array['custom_html'] = FrmFieldsHelper::get_default_html($field_type);
|
362 |
-
|
363 |
-
if ($field_array['size'] == '')
|
364 |
-
$field_array['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
|
365 |
-
|
366 |
-
$field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']);
|
367 |
-
|
368 |
-
if(!isset($field_array['unique']) or !$field_array['unique'])
|
369 |
-
$field_array['unique_msg'] = '';
|
370 |
-
|
371 |
-
foreach((array)$field->field_options as $k => $v){
|
372 |
-
if(!isset($field_array[$k]))
|
373 |
-
$field_array[$k] = $v;
|
374 |
-
unset($k);
|
375 |
-
unset($v);
|
376 |
}
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
}
|
382 |
-
|
383 |
-
$
|
384 |
-
$
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
395 |
}
|
396 |
}
|
397 |
}
|
398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
$form_defaults = FrmFormsHelper::get_default_opts();
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
if($o == 'email_to')
|
409 |
$d = ''; //allow blank email address
|
410 |
-
|
411 |
-
|
412 |
-
unset($d);
|
413 |
}
|
414 |
-
}else{
|
415 |
-
$values[$opt] = ($post_values
|
416 |
-
}
|
417 |
-
}else if($values[$opt] == 'notification'){
|
418 |
-
foreach($values[$opt] as $k => $n){
|
419 |
-
foreach($default as $o => $d){
|
420 |
-
if(!isset($n[$o]))
|
421 |
-
$values[$opt][$k][$o] = ($post_values
|
422 |
-
|
423 |
-
unset($d);
|
424 |
}
|
425 |
-
unset($k);
|
426 |
-
unset($n);
|
427 |
}
|
428 |
}
|
429 |
-
|
430 |
-
unset($opt);
|
431 |
-
unset($defaut);
|
432 |
}
|
433 |
-
|
434 |
-
if (!isset($values['custom_style']))
|
435 |
-
$values['custom_style'] = ($post_values and isset($post_values['options']['custom_style'])) ? $_POST['options']['custom_style'] : ($frm_settings->load_style != 'none');
|
436 |
|
437 |
-
|
438 |
-
|
439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
unset($h);
|
441 |
}
|
442 |
-
|
443 |
-
if ($table == 'entries')
|
444 |
-
$values = FrmEntriesHelper::setup_edit_vars( $values, $record );
|
445 |
-
else if ($table == 'forms')
|
446 |
-
$values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
|
447 |
|
448 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
}
|
450 |
-
|
451 |
-
public static function insert_opt_html($args){
|
452 |
-
extract($args);
|
453 |
-
|
454 |
$class = '';
|
455 |
-
|
456 |
-
if ( in_array( $type, array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
|
457 |
$class .= 'show_frm_not_email_to';
|
458 |
}
|
459 |
?>
|
460 |
<li>
|
461 |
-
<a class="frmids frm_insert_code alignright <?php echo $class ?>" data-code="<?php echo esc_attr($id) ?>"
|
462 |
-
<a class="frmkeys frm_insert_code alignright <?php echo $class ?>" data-code="<?php echo esc_attr($key) ?>"
|
463 |
-
<a class="frm_insert_code <?php echo $class ?>" data-code="<?php echo esc_attr($id) ?>"
|
464 |
</li>
|
465 |
<?php
|
466 |
}
|
467 |
-
|
468 |
-
public static function get_us_states(){
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina',
|
481 |
-
'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah',
|
482 |
-
'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia',
|
483 |
-
'WI' => 'Wisconsin', 'WY' => 'Wyoming'
|
484 |
-
));
|
485 |
-
}
|
486 |
-
|
487 |
-
public static function get_countries(){
|
488 |
-
return apply_filters('frm_countries', array(
|
489 |
-
__('Afghanistan', 'formidable'), __('Albania', 'formidable'), __('Algeria', 'formidable'),
|
490 |
-
__('American Samoa', 'formidable'), __('Andorra', 'formidable'), __('Angola', 'formidable'),
|
491 |
-
__('Anguilla', 'formidable'), __('Antarctica', 'formidable'), __('Antigua and Barbuda', 'formidable'),
|
492 |
-
__('Argentina', 'formidable'), __('Armenia', 'formidable'), __('Aruba', 'formidable'),
|
493 |
-
__('Australia', 'formidable'), __('Austria', 'formidable'), __('Azerbaijan', 'formidable'),
|
494 |
-
__('Bahamas', 'formidable'), __('Bahrain', 'formidable'), __('Bangladesh', 'formidable'),
|
495 |
-
__('Barbados', 'formidable'), __('Belarus', 'formidable'), __('Belgium', 'formidable'),
|
496 |
-
__('Belize', 'formidable'), __('Benin', 'formidable'), __('Bermuda', 'formidable'),
|
497 |
-
__('Bhutan', 'formidable'), __('Bolivia', 'formidable'), __('Bosnia and Herzegovina', 'formidable'),
|
498 |
-
__('Botswana', 'formidable'), __('Brazil', 'formidable'), __('Brunei', 'formidable'),
|
499 |
-
__('Bulgaria', 'formidable'), __('Burkina Faso', 'formidable'), __('Burundi', 'formidable'),
|
500 |
-
__('Cambodia', 'formidable'), __('Cameroon', 'formidable'), __('Canada', 'formidable'),
|
501 |
-
__('Cape Verde', 'formidable'), __('Cayman Islands', 'formidable'), __('Central African Republic', 'formidable'),
|
502 |
-
__('Chad', 'formidable'), __('Chile', 'formidable'), __('China', 'formidable'),
|
503 |
-
__('Colombia', 'formidable'), __('Comoros', 'formidable'), __('Congo', 'formidable'),
|
504 |
-
__('Costa Rica', 'formidable'), __('Côte d\'Ivoire', 'formidable'), __('Croatia', 'formidable'),
|
505 |
-
__('Cuba', 'formidable'), __('Cyprus', 'formidable'), __('Czech Republic', 'formidable'),
|
506 |
-
__('Denmark', 'formidable'), __('Djibouti', 'formidable'), __('Dominica', 'formidable'),
|
507 |
-
__('Dominican Republic', 'formidable'), __('East Timor', 'formidable'), __('Ecuador', 'formidable'),
|
508 |
-
__('Egypt', 'formidable'), __('El Salvador', 'formidable'), __('Equatorial Guinea', 'formidable'),
|
509 |
-
__('Eritrea', 'formidable'), __('Estonia', 'formidable'), __('Ethiopia', 'formidable'),
|
510 |
-
__('Fiji', 'formidable'), __('Finland', 'formidable'), __('France', 'formidable'),
|
511 |
-
__('French Guiana', 'formidable'), __('French Polynesia', 'formidable'), __('Gabon', 'formidable'),
|
512 |
-
__('Gambia', 'formidable'), __('Georgia', 'formidable'), __('Germany', 'formidable'),
|
513 |
-
__('Ghana', 'formidable'), __('Gibraltar', 'formidable'), __('Greece', 'formidable'),
|
514 |
-
__('Greenland', 'formidable'), __('Grenada', 'formidable'), __('Guam', 'formidable'),
|
515 |
-
__('Guatemala', 'formidable'), __('Guinea', 'formidable'), __('Guinea-Bissau', 'formidable'),
|
516 |
-
__('Guyana', 'formidable'), __('Haiti', 'formidable'), __('Honduras', 'formidable'),
|
517 |
-
__('Hong Kong', 'formidable'), __('Hungary', 'formidable'), __('Iceland', 'formidable'),
|
518 |
-
__('India', 'formidable'), __('Indonesia', 'formidable'), __('Iran', 'formidable'),
|
519 |
-
__('Iraq', 'formidable'), __('Ireland', 'formidable'), __('Israel', 'formidable'),
|
520 |
-
__('Italy', 'formidable'), __('Jamaica', 'formidable'), __('Japan', 'formidable'),
|
521 |
-
__('Jordan', 'formidable'), __('Kazakhstan', 'formidable'), __('Kenya', 'formidable'),
|
522 |
-
__('Kiribati', 'formidable'), __('North Korea', 'formidable'), __('South Korea', 'formidable'),
|
523 |
-
__('Kuwait', 'formidable'), __('Kyrgyzstan', 'formidable'), __('Laos', 'formidable'),
|
524 |
-
__('Latvia', 'formidable'), __('Lebanon', 'formidable'), __('Lesotho', 'formidable'),
|
525 |
-
__('Liberia', 'formidable'), __('Libya', 'formidable'), __('Liechtenstein', 'formidable'),
|
526 |
-
__('Lithuania', 'formidable'), __('Luxembourg', 'formidable'), __('Macedonia', 'formidable'),
|
527 |
-
__('Madagascar', 'formidable'), __('Malawi', 'formidable'), __('Malaysia', 'formidable'),
|
528 |
-
__('Maldives', 'formidable'), __('Mali', 'formidable'), __('Malta', 'formidable'),
|
529 |
-
__('Marshall Islands', 'formidable'), __('Mauritania', 'formidable'), __('Mauritius', 'formidable'),
|
530 |
-
__('Mexico', 'formidable'), __('Micronesia', 'formidable'), __('Moldova', 'formidable'),
|
531 |
-
__('Monaco', 'formidable'), __('Mongolia', 'formidable'), __('Montenegro', 'formidable'),
|
532 |
-
__('Montserrat', 'formidable'), __('Morocco', 'formidable'), __('Mozambique', 'formidable'),
|
533 |
-
__('Myanmar', 'formidable'), __('Namibia', 'formidable'), __('Nauru', 'formidable'),
|
534 |
-
__('Nepal', 'formidable'), __('Netherlands', 'formidable'), __('New Zealand', 'formidable'),
|
535 |
-
__('Nicaragua', 'formidable'), __('Niger', 'formidable'), __('Nigeria', 'formidable'),
|
536 |
-
__('Norway', 'formidable'), __('Northern Mariana Islands', 'formidable'), __('Oman', 'formidable'),
|
537 |
-
__('Pakistan', 'formidable'), __('Palau', 'formidable'), __('Palestine', 'formidable'),
|
538 |
-
__('Panama', 'formidable'), __('Papua New Guinea', 'formidable'), __('Paraguay', 'formidable'),
|
539 |
-
__('Peru', 'formidable'), __('Philippines', 'formidable'), __('Poland', 'formidable'),
|
540 |
-
__('Portugal', 'formidable'), __('Puerto Rico', 'formidable'), __('Qatar', 'formidable'),
|
541 |
-
__('Romania', 'formidable'), __('Russia', 'formidable'), __('Rwanda', 'formidable'),
|
542 |
-
__('Saint Kitts and Nevis', 'formidable'), __('Saint Lucia', 'formidable'),
|
543 |
-
__('Saint Vincent and the Grenadines', 'formidable'), __('Samoa', 'formidable'),
|
544 |
-
__('San Marino', 'formidable'), __('Sao Tome and Principe', 'formidable'), __('Saudi Arabia', 'formidable'),
|
545 |
-
__('Senegal', 'formidable'), __('Serbia and Montenegro', 'formidable'), __('Seychelles', 'formidable'),
|
546 |
-
__('Sierra Leone', 'formidable'), __('Singapore', 'formidable'), __('Slovakia', 'formidable'),
|
547 |
-
__('Slovenia', 'formidable'), __('Solomon Islands', 'formidable'), __('Somalia', 'formidable'),
|
548 |
-
__('South Africa', 'formidable'), __('Spain', 'formidable'), __('Sri Lanka', 'formidable'),
|
549 |
-
__('Sudan', 'formidable'), __('Suriname', 'formidable'), __('Swaziland', 'formidable'),
|
550 |
-
__('Sweden', 'formidable'), __('Switzerland', 'formidable'), __('Syria', 'formidable'),
|
551 |
-
__('Taiwan', 'formidable'), __('Tajikistan', 'formidable'), __('Tanzania', 'formidable'),
|
552 |
-
__('Thailand', 'formidable'), __('Togo', 'formidable'), __('Tonga', 'formidable'),
|
553 |
-
__('Trinidad and Tobago', 'formidable'), __('Tunisia', 'formidable'), __('Turkey', 'formidable'),
|
554 |
-
__('Turkmenistan', 'formidable'), __('Tuvalu', 'formidable'), __('Uganda', 'formidable'),
|
555 |
-
__('Ukraine', 'formidable'), __('United Arab Emirates', 'formidable'), __('United Kingdom', 'formidable'),
|
556 |
-
__('United States', 'formidable'), __('Uruguay', 'formidable'), __('Uzbekistan', 'formidable'),
|
557 |
-
__('Vanuatu', 'formidable'), __('Vatican City', 'formidable'), __('Venezuela', 'formidable'),
|
558 |
-
__('Vietnam', 'formidable'), __('Virgin Islands, British', 'formidable'),
|
559 |
-
__('Virgin Islands, U.S.', 'formidable'), __('Yemen', 'formidable'), __('Zambia', 'formidable'),
|
560 |
-
__('Zimbabwe', 'formidable')
|
561 |
-
));
|
562 |
-
}
|
563 |
-
|
564 |
-
public static function truncate($str, $length, $minword = 3, $continue = '...'){
|
565 |
-
if(is_array($str))
|
566 |
return;
|
567 |
-
|
568 |
-
|
569 |
-
$
|
|
|
570 |
$original_len = (function_exists('mb_strlen')) ? mb_strlen($str) : strlen($str);
|
571 |
-
|
572 |
-
|
573 |
return '';
|
574 |
-
}else if($length <= 10){
|
575 |
-
|
576 |
return $sub . (($length < $original_len) ? $continue : '');
|
577 |
}
|
578 |
-
|
579 |
$sub = '';
|
580 |
$len = 0;
|
581 |
|
582 |
$words = (function_exists('mb_split')) ? mb_split(' ', $str) : explode(' ', $str);
|
583 |
-
|
584 |
-
|
585 |
$part = (($sub != '') ? ' ' : '') . $word;
|
586 |
$total_len = (function_exists('mb_strlen')) ? mb_strlen($sub . $part) : strlen($sub. $part);
|
587 |
if ( $total_len > $length && str_word_count($sub) ) {
|
588 |
break;
|
589 |
}
|
590 |
-
|
591 |
$sub .= $part;
|
592 |
$len += (function_exists('mb_strlen')) ? mb_strlen($part) : strlen($part);
|
593 |
-
|
594 |
if ( str_word_count($sub) > $minword && $total_len >= $length ) {
|
595 |
break;
|
596 |
}
|
597 |
-
|
598 |
unset($total_len, $word);
|
599 |
}
|
600 |
-
|
601 |
return $sub . (($len < $original_len) ? $continue : '');
|
602 |
}
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
612 |
public static function esc_like($term) {
|
613 |
global $wpdb;
|
614 |
-
if ( method_exists($wpdb, 'esc_like') ) {
|
|
|
615 |
$term = $wpdb->esc_like( $term );
|
616 |
} else {
|
617 |
$term = like_escape( $term );
|
618 |
}
|
619 |
-
|
620 |
return $term;
|
621 |
}
|
622 |
-
|
623 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
624 |
if ( empty($where) ) {
|
625 |
return '';
|
626 |
}
|
627 |
-
|
628 |
-
|
629 |
-
global $
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
$where = $starts_with . $where;
|
634 |
}
|
635 |
-
|
636 |
return $where;
|
637 |
}
|
638 |
-
|
639 |
// Pagination Methods
|
640 |
-
|
641 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
642 |
}
|
643 |
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
|
|
|
|
649 |
}
|
650 |
-
|
651 |
-
public static function
|
652 |
-
|
653 |
-
|
654 |
-
return $wpdb->get_var($query);
|
655 |
-
}
|
656 |
-
|
657 |
-
public static function get_referer_query($query) {
|
658 |
-
if (strpos($query, "google.")) {
|
659 |
-
//$pattern = '/^.*\/search.*[\?&]q=(.*)$/';
|
660 |
-
$pattern = '/^.*[\?&]q=(.*)$/';
|
661 |
-
} else if (strpos($query, "bing.com")) {
|
662 |
-
$pattern = '/^.*q=(.*)$/';
|
663 |
-
} else if (strpos($query, "yahoo.")) {
|
664 |
-
$pattern = '/^.*[\?&]p=(.*)$/';
|
665 |
-
} else if (strpos($query, "ask.")) {
|
666 |
-
$pattern = '/^.*[\?&]q=(.*)$/';
|
667 |
-
} else {
|
668 |
-
return false;
|
669 |
-
}
|
670 |
-
preg_match($pattern, $query, $matches);
|
671 |
-
$querystr = substr($matches[1], 0, strpos($matches[1], '&'));
|
672 |
-
return urldecode($querystr);
|
673 |
-
}
|
674 |
-
|
675 |
-
public static function get_referer_info(){
|
676 |
-
$referrerinfo = '';
|
677 |
-
$keywords = array();
|
678 |
-
$i = 1;
|
679 |
-
if(isset($_SESSION) and isset($_SESSION['frm_http_referer']) and $_SESSION['frm_http_referer']){
|
680 |
-
foreach ($_SESSION['frm_http_referer'] as $referer) {
|
681 |
-
$referrerinfo .= str_pad("Referer $i: ",20) . $referer. "\r\n";
|
682 |
-
$keywords_used = FrmAppHelper::get_referer_query($referer);
|
683 |
-
if ($keywords_used)
|
684 |
-
$keywords[] = $keywords_used;
|
685 |
-
|
686 |
-
$i++;
|
687 |
-
}
|
688 |
-
|
689 |
-
$referrerinfo .= "\r\n";
|
690 |
-
}else{
|
691 |
-
$referrerinfo = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
|
692 |
-
}
|
693 |
-
|
694 |
-
$i = 1;
|
695 |
-
if(isset($_SESSION) and isset($_SESSION['frm_http_pages']) and $_SESSION['frm_http_pages']){
|
696 |
-
foreach ($_SESSION['frm_http_pages'] as $page) {
|
697 |
-
$referrerinfo .= str_pad("Page visited $i: ",20) . $page. "\r\n";
|
698 |
-
$i++;
|
699 |
-
}
|
700 |
-
|
701 |
-
$referrerinfo .= "\r\n";
|
702 |
-
}
|
703 |
-
|
704 |
-
$i = 1;
|
705 |
-
foreach ($keywords as $keyword) {
|
706 |
-
$referrerinfo .= str_pad("Keyword $i: ",20) . $keyword. "\r\n";
|
707 |
-
$i++;
|
708 |
-
}
|
709 |
-
$referrerinfo .= "\r\n";
|
710 |
-
|
711 |
-
return $referrerinfo;
|
712 |
}
|
713 |
-
|
714 |
-
|
|
|
|
|
|
|
715 |
$vars = array();
|
716 |
-
foreach($json_vars as $jv){
|
717 |
$jv_name = explode('[', $jv['name']);
|
718 |
-
$last = count($jv_name)-1;
|
719 |
-
foreach($jv_name as $p => $n){
|
720 |
$name = trim($n, ']');
|
721 |
-
|
722 |
-
|
723 |
-
if(!$p){
|
724 |
$l1 = $name;
|
725 |
-
if($name == '')
|
726 |
-
$vars[] = $this_val;
|
727 |
-
else if(!isset($vars[$l1]))
|
728 |
-
$vars[$l1] = $this_val;
|
729 |
}
|
730 |
-
|
731 |
-
if($
|
732 |
$l2 = $name;
|
733 |
-
if($name == '')
|
734 |
-
$vars[$l1][] = $this_val;
|
735 |
-
else if(!isset($vars[$l1][$l2]))
|
736 |
-
$vars[$l1][$l2] = $this_val;
|
737 |
}
|
738 |
-
|
739 |
-
if($
|
740 |
$l3 = $name;
|
741 |
-
if($name == '')
|
742 |
-
$vars[$l1][$l2][] = $this_val;
|
743 |
-
else if(!isset($vars[$l1][$l2][$l3]))
|
744 |
-
$vars[$l1][$l2][$l3] = $this_val;
|
745 |
}
|
746 |
-
|
747 |
-
|
748 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
749 |
}
|
750 |
-
|
751 |
-
unset($last);
|
752 |
-
unset($jv);
|
753 |
}
|
754 |
-
|
755 |
return $vars;
|
756 |
}
|
757 |
-
|
758 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
759 |
$new_string = json_decode($string, true);
|
760 |
-
if ( function_exists('json_last_error') ) {
|
|
|
761 |
if ( json_last_error() == JSON_ERROR_NONE ) {
|
762 |
$string = $new_string;
|
763 |
}
|
764 |
-
} else if ( isset($new_string) ) {
|
|
|
765 |
$string = $new_string;
|
766 |
}
|
767 |
return $string;
|
768 |
}
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
/*
|
778 |
-
* @since 1.07.10
|
779 |
-
*
|
780 |
-
* @param string $post_type The name of the post type that may need to be highlighted
|
781 |
-
* @return echo The javascript to open and highlight the Formidable menu
|
782 |
-
*/
|
783 |
public static function maybe_highlight_menu($post_type) {
|
784 |
global $post, $pagenow;
|
785 |
|
786 |
if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
|
787 |
return;
|
788 |
}
|
789 |
-
|
790 |
if ( is_object($post) && $post->post_type != $post_type ) {
|
791 |
return;
|
792 |
}
|
793 |
-
|
794 |
-
|
795 |
-
<script type="text/javascript">
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
810 |
public static function min_version_notice($min_version) {
|
811 |
$frm_version = self::plugin_version();
|
812 |
-
|
813 |
// check if Formidable meets minimum requirements
|
814 |
if ( version_compare($frm_version, $min_version, '>=') ) {
|
815 |
return;
|
816 |
}
|
817 |
-
|
818 |
$wp_list_table = _get_list_table('WP_Plugins_List_Table');
|
819 |
echo '<tr class="plugin-update-tr active"><th colspan="' . $wp_list_table->get_column_count() . '" class="check-column plugin-update colspanchange"><div class="update-message">'.
|
820 |
-
__('You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable') .
|
821 |
'</div></td></tr>';
|
822 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
823 |
}
|
1 |
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
5 |
|
6 |
+
class FrmAppHelper {
|
7 |
+
public static $db_version = 21; //version of the database we are moving to
|
8 |
+
public static $pro_db_version = 27;
|
9 |
|
10 |
+
/**
|
11 |
+
* @since 2.0
|
12 |
+
*/
|
13 |
+
public static $plug_version = '2.0';
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @since 1.07.02
|
17 |
+
*
|
18 |
+
* @param none
|
19 |
+
* @return string The version of this plugin
|
20 |
+
*/
|
21 |
+
public static function plugin_version() {
|
22 |
+
return self::$plug_version;
|
23 |
}
|
24 |
+
|
25 |
+
public static function plugin_folder() {
|
26 |
+
return basename(self::plugin_path());
|
27 |
+
}
|
28 |
+
|
29 |
+
public static function plugin_path() {
|
30 |
return dirname(dirname(dirname(__FILE__)));
|
31 |
}
|
32 |
+
|
33 |
+
public static function plugin_url( $url = '' ) {
|
34 |
//prevously FRM_URL constant
|
35 |
+
if ( empty($url) ) {
|
36 |
+
$url = plugins_url('', self::plugin_folder() .'/formidable.php');
|
37 |
+
}
|
38 |
+
|
39 |
+
if ( is_ssl() && !preg_match('/^https:\/\/.*\..*$/', $url) ) {
|
40 |
$url = str_replace('http://', 'https://', $url);
|
41 |
+
}
|
42 |
+
|
43 |
return $url;
|
44 |
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @return string Site URL
|
48 |
+
*/
|
49 |
+
public static function site_url() {
|
50 |
$url = self::plugin_url(site_url());
|
51 |
return $url;
|
52 |
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Get the name of this site
|
56 |
+
* Used for [sitename] shortcode
|
57 |
+
*
|
58 |
+
* @since 2.0
|
59 |
+
* @return string
|
60 |
+
*/
|
61 |
+
public static function site_name() {
|
62 |
+
return get_option('blogname');
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Get the Formidable settings
|
67 |
+
*
|
68 |
+
* @since 2.0
|
69 |
+
*
|
70 |
+
* @param None
|
71 |
+
* @return FrmSettings $frm_setings
|
72 |
+
*/
|
73 |
+
public static function get_settings() {
|
74 |
+
global $frm_settings;
|
75 |
+
if ( empty($frm_settings) ) {
|
76 |
+
$frm_settings = new FrmSettings();
|
77 |
+
}
|
78 |
+
return $frm_settings;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Show a message in place of pro features
|
83 |
+
*
|
84 |
+
* @since 2.0
|
85 |
+
*/
|
86 |
+
public static function update_message($features, $class = '') {
|
87 |
+
return; // hide the upgrade messages for now
|
88 |
+
if ( ! self::pro_is_installed() ) {
|
89 |
+
include(self::plugin_path() .'/classes/views/shared/update_message.php');
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
public static function pro_is_installed() {
|
94 |
+
return apply_filters('frm_pro_installed', false);
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Check for certain page in Formidable settings
|
99 |
+
*
|
100 |
+
* @since 2.0
|
101 |
+
*
|
102 |
+
* @param string $page The name of the page to check
|
103 |
+
* @return boolean
|
104 |
+
*/
|
105 |
+
public static function is_admin_page($page = 'formidable' ) {
|
106 |
+
global $pagenow;
|
107 |
+
if ( $pagenow ) {
|
108 |
+
return $pagenow == 'admin.php' && $_GET['page'] == $page;
|
109 |
+
}
|
110 |
+
|
111 |
+
return is_admin() && isset($_GET['page']) && $_GET['page'] == $page;
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Check for the form preview page
|
116 |
+
*
|
117 |
+
* @since 2.0
|
118 |
+
*
|
119 |
+
* @param None
|
120 |
+
* @return boolean
|
121 |
+
*/
|
122 |
+
public static function is_preview_page() {
|
123 |
+
global $pagenow;
|
124 |
+
return $pagenow && $pagenow == 'admin-ajax.php' && isset($_GET['action']) && $_GET['action'] == 'frm_forms_preview';
|
125 |
+
}
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Check for ajax except the form preview page
|
129 |
+
*
|
130 |
+
* @since 2.0
|
131 |
+
*
|
132 |
+
* @param None
|
133 |
+
* @return boolean
|
134 |
+
*/
|
135 |
+
public static function doing_ajax() {
|
136 |
+
return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Check if on an admin page
|
141 |
+
*
|
142 |
+
* @since 2.0
|
143 |
+
*
|
144 |
+
* @param None
|
145 |
+
* @return boolean
|
146 |
+
*/
|
147 |
+
public static function is_admin() {
|
148 |
+
return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX );
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Check if value contains blank value or empty array
|
153 |
+
*
|
154 |
+
* @since 2.0
|
155 |
+
* @param $value - value to check
|
156 |
+
* @return boolean
|
157 |
+
*/
|
158 |
+
public static function is_empty_value( $value, $empty = '' ) {
|
159 |
+
return ( is_array( $value ) && empty( $value ) ) || $value == $empty;
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Get any value from the $_SERVER
|
164 |
+
*
|
165 |
+
* @since 2.0
|
166 |
+
* @param string $value
|
167 |
+
* @return string
|
168 |
+
*/
|
169 |
+
public static function get_server_value($value) {
|
170 |
+
return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Check for the IP address in several places
|
175 |
+
* Used by [ip] shortcode
|
176 |
+
*
|
177 |
+
* @return string The IP address of the current user
|
178 |
+
*/
|
179 |
+
public static function get_ip_address() {
|
180 |
+
$ip = '';
|
181 |
+
foreach ( array(
|
182 |
+
'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
|
183 |
+
'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR',
|
184 |
+
) as $key ) {
|
185 |
+
if ( ! isset( $_SERVER[ $key ] ) ) {
|
186 |
+
continue;
|
187 |
+
}
|
188 |
+
|
189 |
+
foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
|
190 |
+
$ip = trim($ip); // just to be safe
|
191 |
+
|
192 |
+
if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
|
193 |
+
return $ip;
|
194 |
+
}
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
return sanitize_text_field( $ip );
|
199 |
+
}
|
200 |
+
|
201 |
+
public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
|
202 |
+
if ( strpos($param, '[') ) {
|
203 |
$params = explode('[', $param);
|
204 |
+
$param = $params[0];
|
205 |
}
|
206 |
|
207 |
+
if ( $src == 'get' ) {
|
208 |
+
$value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
|
209 |
+
if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
|
210 |
+
$value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[ $param ] ) ) );
|
211 |
+
}
|
212 |
+
} else {
|
213 |
+
$value = self::get_post_param( $param, $default, $sanitize );
|
214 |
}
|
215 |
+
|
216 |
+
if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
|
217 |
+
foreach ( $params as $k => $p ) {
|
218 |
+
if ( ! $k || ! is_array($value) ) {
|
219 |
continue;
|
220 |
+
}
|
221 |
+
|
222 |
$p = trim($p, ']');
|
223 |
+
$value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
|
224 |
}
|
225 |
}
|
226 |
|
227 |
return $value;
|
228 |
}
|
229 |
+
|
230 |
+
public static function get_post_param( $param, $default = '', $sanitize = '' ) {
|
231 |
+
$val = $default;
|
232 |
+
if ( isset( $_POST[ $param ] ) ) {
|
233 |
+
$val = stripslashes_deep( maybe_unserialize( $_POST[ $param ] ) );
|
234 |
+
if ( ! empty( $sanitize ) ) {
|
235 |
+
$val = call_user_func( $sanitize, $val );
|
236 |
+
}
|
237 |
+
}
|
238 |
+
return $val;
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* @since 2.0
|
243 |
+
* @param string $action
|
244 |
+
*/
|
245 |
+
public static function simple_get( $action, $sanitize = 'sanitize_text_field' ) {
|
246 |
+
$val = '';
|
247 |
+
if ( $_GET && isset( $_GET[ $action ] ) ) {
|
248 |
+
$val = call_user_func( $sanitize, $_GET[ $action ] );
|
249 |
+
}
|
250 |
+
return $val;
|
251 |
}
|
252 |
+
|
253 |
+
public static function sanitize_request( $sanitize_method, &$values ) {
|
254 |
+
$temp_values = $values;
|
255 |
+
foreach ( $temp_values as $k => $val ) {
|
256 |
+
if ( isset( $sanitize_method[ $k ] ) ) {
|
257 |
+
call_user_func( $sanitize_method[ $k ], $val );
|
258 |
+
}
|
259 |
+
}
|
260 |
+
}
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Sanitize the value, and allow some HTML
|
264 |
+
* @since 2.0
|
265 |
+
*/
|
266 |
+
public static function kses( $value, $allowed = array() ) {
|
267 |
+
$html = array(
|
268 |
+
'a' => array(
|
269 |
+
'href' => array(),
|
270 |
+
'title' => array(),
|
271 |
+
'id' => array(),
|
272 |
+
'class' => array(),
|
273 |
+
),
|
274 |
+
);
|
275 |
+
|
276 |
+
$allowed_html = array();
|
277 |
+
foreach ( $allowed as $a ) {
|
278 |
+
$allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array();
|
279 |
+
}
|
280 |
+
|
281 |
+
return wp_kses( $value, $allowed_html );
|
282 |
+
}
|
283 |
+
|
284 |
+
/**
|
285 |
+
* Used when switching the action for a bulk action
|
286 |
+
* @since 2.0
|
287 |
+
*/
|
288 |
+
public static function remove_get_action() {
|
289 |
+
if ( ! isset($_GET) ) {
|
290 |
+
return;
|
291 |
+
}
|
292 |
+
|
293 |
+
$new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
|
294 |
+
if ( ! empty( $new_action ) ) {
|
295 |
+
$_SERVER['REQUEST_URI'] = str_replace( '&action='. $new_action, '', $_SERVER['REQUEST_URI'] );
|
296 |
+
}
|
297 |
+
}
|
298 |
+
|
299 |
+
/**
|
300 |
+
* Check the WP query for a parameter
|
301 |
+
*
|
302 |
+
* @since 2.0
|
303 |
+
* @return string|array
|
304 |
+
*/
|
305 |
+
public static function get_query_var( $value, $param ) {
|
306 |
+
if ( $value != '' ) {
|
307 |
+
return $value;
|
308 |
+
}
|
309 |
+
|
310 |
+
global $wp_query;
|
311 |
+
if ( isset( $wp_query->query_vars[ $param ] ) ) {
|
312 |
+
$value = $wp_query->query_vars[ $param ];
|
313 |
+
}
|
314 |
+
|
315 |
+
return $value;
|
316 |
+
}
|
317 |
+
|
318 |
+
/**
|
319 |
+
* @param string $type
|
320 |
+
*/
|
321 |
+
public static function trigger_hook_load( $type, $object = null ) {
|
322 |
+
// only load the form hooks once
|
323 |
+
$hooks_loaded = apply_filters('frm_'. $type .'_hooks_loaded', false, $object);
|
324 |
+
if ( ! $hooks_loaded ) {
|
325 |
+
do_action('frm_load_'. $type .'_hooks');
|
326 |
+
}
|
327 |
+
}
|
328 |
+
|
329 |
+
/**
|
330 |
+
* Check cache before fetching values and saving to cache
|
331 |
+
*
|
332 |
+
* @since 2.0
|
333 |
+
*
|
334 |
+
* @param string $cache_key The unique name for this cache
|
335 |
+
* @param string $group The name of the cache group
|
336 |
+
* @param string $query If blank, don't run a db call
|
337 |
+
* @param string $type The wpdb function to use with this query
|
338 |
+
* @return mixed $results The cache or query results
|
339 |
+
*/
|
340 |
+
public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
|
341 |
+
$results = wp_cache_get($cache_key, $group);
|
342 |
+
if ( ! self::is_empty_value( $results, false ) || empty($query) ) {
|
343 |
+
return $results;
|
344 |
+
}
|
345 |
+
|
346 |
+
if ( 'get_posts' == $type ) {
|
347 |
+
$results = get_posts($query);
|
348 |
+
} else {
|
349 |
+
global $wpdb;
|
350 |
+
$results = $wpdb->{$type}($query);
|
351 |
+
}
|
352 |
+
|
353 |
+
wp_cache_set($cache_key, $results, $group, $time);
|
354 |
+
|
355 |
+
return $results;
|
356 |
+
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Data that should be stored for a long time can be stored in a transient.
|
360 |
+
* First check the cache, then check the transient
|
361 |
+
* @since 2.0
|
362 |
+
* @return mixed The cached value or false
|
363 |
+
*/
|
364 |
+
public static function check_cache_and_transient($cache_key) {
|
365 |
+
// check caching layer first
|
366 |
+
$results = self::check_cache( $cache_key );
|
367 |
+
if ( $results ) {
|
368 |
+
return $results;
|
369 |
+
}
|
370 |
+
|
371 |
+
// then check the transient
|
372 |
+
$results = get_transient($cache_key);
|
373 |
+
if ( $results ) {
|
374 |
+
wp_cache_set($cache_key, $results);
|
375 |
+
}
|
376 |
+
|
377 |
+
return $results;
|
378 |
+
}
|
379 |
+
|
380 |
+
/**
|
381 |
+
* @since 2.0
|
382 |
+
* @param string $cache_key
|
383 |
+
*/
|
384 |
+
public static function delete_cache_and_transient($cache_key) {
|
385 |
+
delete_transient($cache_key);
|
386 |
+
wp_cache_delete($cache_key);
|
387 |
+
}
|
388 |
+
|
389 |
+
/**
|
390 |
+
* Delete all caching in a single group
|
391 |
+
*
|
392 |
+
* @since 2.0
|
393 |
+
*
|
394 |
+
* @param string $group The name of the cache group
|
395 |
+
* @return boolean True or False
|
396 |
+
*/
|
397 |
+
public static function cache_delete_group($group) {
|
398 |
+
global $wp_object_cache;
|
399 |
+
|
400 |
+
if ( isset( $wp_object_cache->cache[ $group ] ) ) {
|
401 |
+
foreach ( $wp_object_cache->cache[ $group ] as $k => $v ) {
|
402 |
+
wp_cache_delete($k, $group);
|
403 |
+
}
|
404 |
+
return true;
|
405 |
+
}
|
406 |
+
|
407 |
+
return false;
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Check a value from a shortcode to see if true or false.
|
412 |
+
* True when value is 1, true, 'true', 'yes'
|
413 |
+
*
|
414 |
+
* @since 1.07.10
|
415 |
+
*
|
416 |
+
* @param string $value The value to compare
|
417 |
+
* @return boolean True or False
|
418 |
+
*/
|
419 |
public static function is_true($value) {
|
420 |
return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
|
421 |
}
|
422 |
+
|
423 |
+
/**
|
424 |
+
* Used to filter shortcode in text widgets
|
425 |
+
*/
|
426 |
+
public static function widget_text_filter_callback( $matches ) {
|
427 |
+
return do_shortcode( $matches[0] );
|
428 |
+
}
|
429 |
+
|
430 |
+
public static function load_scripts($scripts) {
|
431 |
+
_deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_script' );
|
432 |
foreach ( (array) $scripts as $s ) {
|
433 |
wp_enqueue_script($s);
|
434 |
}
|
435 |
}
|
436 |
+
|
437 |
+
public static function load_styles($styles) {
|
438 |
+
_deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_style' );
|
439 |
foreach ( (array) $styles as $s ) {
|
440 |
wp_enqueue_style($s);
|
441 |
}
|
442 |
}
|
443 |
+
|
444 |
+
public static function get_pages() {
|
445 |
+
return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => 999, 'orderby' => 'title', 'order' => 'ASC' ) );
|
446 |
}
|
447 |
+
|
448 |
+
public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
|
449 |
+
$pages = self::get_pages();
|
450 |
?>
|
451 |
+
<select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="frm-pages-dropdown">
|
452 |
+
<option value=""> </option>
|
453 |
+
<?php foreach ( $pages as $page ) { ?>
|
454 |
+
<option value="<?php echo esc_attr($page->ID); ?>" <?php
|
455 |
+
echo ( ( ( isset( $_POST[ $field_name ] ) && $_POST[ $field_name ] == $page->ID ) || ( ! isset( $_POST[ $field_name ] ) && $page_id == $page->ID ) ) ? ' selected="selected"' : '' );
|
456 |
+
?>><?php echo esc_html( $truncate ? self::truncate( $page->post_title, $truncate ) : $page->post_title ); ?> </option>
|
457 |
<?php } ?>
|
458 |
</select>
|
459 |
<?php
|
460 |
}
|
461 |
+
|
462 |
+
public static function post_edit_link($post_id) {
|
463 |
+
$post = get_post($post_id);
|
464 |
+
if ( $post ) {
|
465 |
+
return '<a href="'. esc_url(admin_url('post.php') .'?post='. $post_id .'&action=edit') .'">'. self::truncate($post->post_title, 50) .'</a>';
|
466 |
+
}
|
467 |
+
return '';
|
468 |
+
}
|
469 |
+
|
470 |
+
public static function wp_roles_dropdown($field_name, $capability, $multiple = 'single') {
|
471 |
+
$capability = (array) self::get_param($field_name, $capability, 'post');
|
472 |
|
473 |
?>
|
474 |
+
<select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" <?php
|
475 |
+
echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : '';
|
476 |
+
?> class="frm_multiselect">
|
477 |
+
<?php self::roles_options($capability); ?>
|
|
|
|
|
|
|
|
|
478 |
</select>
|
479 |
<?php
|
480 |
}
|
481 |
+
|
482 |
+
public static function roles_options($capability) {
|
483 |
global $frm_vars;
|
484 |
+
if ( isset($frm_vars['editable_roles']) ) {
|
485 |
+
$editable_roles = $frm_vars['editable_roles'];
|
486 |
+
} else {
|
487 |
+
$editable_roles = get_editable_roles();
|
488 |
+
$frm_vars['editable_roles'] = $editable_roles;
|
489 |
+
}
|
490 |
+
|
491 |
+
foreach ( $editable_roles as $role => $details ) {
|
492 |
+
$name = translate_user_role($details['name'] ); ?>
|
493 |
+
<option value="<?php echo esc_attr($role) ?>" <?php echo in_array($role, (array) $capability) ? ' selected="selected"' : ''; ?>><?php echo esc_attr($name) ?> </option>
|
494 |
+
<?php
|
495 |
+
unset($role, $details);
|
496 |
+
}
|
497 |
+
}
|
498 |
+
|
499 |
+
public static function frm_capabilities($type = 'auto') {
|
500 |
$cap = array(
|
501 |
+
'frm_view_forms' => __( 'View Forms and Templates', 'formidable' ),
|
502 |
+
'frm_edit_forms' => __( 'Add/Edit Forms and Templates', 'formidable' ),
|
503 |
+
'frm_delete_forms' => __( 'Delete Forms and Templates', 'formidable' ),
|
504 |
+
'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ),
|
505 |
+
'frm_view_entries' => __( 'View Entries from Admin Area', 'formidable' ),
|
506 |
+
'frm_delete_entries' => __( 'Delete Entries from Admin Area', 'formidable' ),
|
507 |
);
|
508 |
+
|
509 |
+
if ( ! self::pro_is_installed() && 'pro' != $type) {
|
510 |
+
return $cap;
|
|
|
|
|
|
|
|
|
511 |
}
|
512 |
+
|
513 |
+
$cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
|
514 |
+
$cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
|
515 |
+
$cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
|
516 |
+
$cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
|
517 |
+
|
518 |
return $cap;
|
519 |
}
|
520 |
+
|
521 |
+
public static function user_has_permission($needed_role) {
|
522 |
+
if ( $needed_role == '-1' ) {
|
523 |
return false;
|
524 |
+
}
|
525 |
+
|
526 |
+
// $needed_role will be equal to blank if "Logged-in users" is selected
|
527 |
+
if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
|
528 |
return true;
|
529 |
+
}
|
530 |
+
|
531 |
$roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
|
532 |
+
foreach ( $roles as $role ) {
|
533 |
+
if ( current_user_can( $role ) ) {
|
534 |
return true;
|
535 |
+
}
|
536 |
+
if ( $role == $needed_role ) {
|
537 |
break;
|
538 |
+
}
|
539 |
}
|
540 |
return false;
|
541 |
}
|
542 |
+
|
543 |
+
/**
|
544 |
+
* Make sure administrators can see Formidable menu
|
545 |
+
*
|
546 |
+
* @since 2.0
|
547 |
+
*/
|
548 |
+
public static function maybe_add_permissions() {
|
549 |
+
if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) {
|
550 |
+
return;
|
551 |
+
}
|
552 |
+
|
553 |
+
$user_id = get_current_user_id();
|
554 |
+
$user = new WP_User( $user_id );
|
555 |
+
$frm_roles = self::frm_capabilities();
|
556 |
+
foreach ( $frm_roles as $frm_role => $frm_role_description ) {
|
557 |
+
$user->add_cap( $frm_role );
|
558 |
+
unset($frm_role, $frm_role_description);
|
559 |
+
}
|
560 |
+
}
|
561 |
+
|
562 |
+
/**
|
563 |
+
* Check if the user has permision for action.
|
564 |
+
* Return permission message and stop the action if no permission
|
565 |
+
* @since 2.0
|
566 |
+
* @param string $permission
|
567 |
+
*/
|
568 |
+
public static function permission_check($permission, $show_message = 'show') {
|
569 |
+
$permission_error = self::permission_nonce_error($permission);
|
570 |
+
if ( $permission_error !== false ) {
|
571 |
+
if ( 'hide' == $show_message ) {
|
572 |
+
$permission_error = '';
|
573 |
+
}
|
574 |
+
wp_die($permission_error);
|
575 |
+
}
|
576 |
+
}
|
577 |
+
|
578 |
+
/**
|
579 |
+
* Check user permission and nonce
|
580 |
+
* @since 2.0
|
581 |
+
* @param string $permission
|
582 |
+
* @return false|string The permission message or false if allowed
|
583 |
+
*/
|
584 |
+
public static function permission_nonce_error($permission, $nonce_name = '', $nonce = '') {
|
585 |
+
if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
|
586 |
+
$frm_settings = self::get_settings();
|
587 |
+
return $frm_settings->admin_permission;
|
588 |
+
}
|
589 |
+
|
590 |
+
$error = false;
|
591 |
+
if ( empty($nonce_name) ) {
|
592 |
+
return $error;
|
593 |
+
}
|
594 |
+
|
595 |
+
if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
|
596 |
+
$frm_settings = self::get_settings();
|
597 |
+
$error = $frm_settings->admin_permission;
|
598 |
+
}
|
599 |
+
|
600 |
+
return $error;
|
601 |
+
}
|
602 |
+
|
603 |
+
public static function checked( $values, $current ) {
|
604 |
+
if ( self::check_selected( $values, $current ) ) {
|
605 |
echo ' checked="checked"';
|
606 |
+
}
|
607 |
}
|
608 |
+
|
609 |
+
public static function check_selected($values, $current) {
|
610 |
+
self::recursive_trim($values);
|
|
|
|
|
|
|
|
|
|
|
|
|
611 |
$current = trim($current);
|
612 |
+
|
613 |
+
return ( is_array($values) && in_array($current, $values) ) || ( ! is_array($values) && $values == $current );
|
614 |
+
}
|
615 |
+
|
616 |
+
/**
|
617 |
+
* Check if current field option is an "other" option
|
618 |
+
*
|
619 |
+
* @since 2.0
|
620 |
+
*
|
621 |
+
* @param string $opt_key
|
622 |
+
* @return boolean Returns true if current field option is an "Other" option
|
623 |
+
*/
|
624 |
+
public static function is_other_opt( $opt_key ) {
|
625 |
+
return $opt_key && strpos( $opt_key, 'other' ) !== false;
|
626 |
+
}
|
627 |
+
|
628 |
+
/**
|
629 |
+
* Get value that belongs in "Other" text box
|
630 |
+
*
|
631 |
+
* @since 2.0
|
632 |
+
*
|
633 |
+
* @param string $opt_key
|
634 |
+
* @param array $field
|
635 |
+
* @return string $other_val
|
636 |
+
*/
|
637 |
+
public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) {
|
638 |
+
$other_val = '';
|
639 |
+
|
640 |
+
//If option is an "other" option and there is a value set for this field, check if the value belongs in the current "Other" option text field
|
641 |
+
if ( ! self::is_other_opt( $opt_key ) || ! isset( $field['value'] ) || ! $field['value'] ) {
|
642 |
+
return $other_val;
|
643 |
+
}
|
644 |
+
|
645 |
+
// Check posted vals before checking saved values
|
646 |
+
|
647 |
+
// For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
|
648 |
+
if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) {
|
649 |
+
if ( FrmFieldsHelper::is_field_with_multiple_values( $field ) ) {
|
650 |
+
$other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] : '';
|
651 |
+
} else {
|
652 |
+
$other_val = $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ];
|
653 |
+
}
|
654 |
+
return $other_val;
|
655 |
+
|
656 |
+
} else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) {
|
657 |
+
// For normal fields
|
658 |
+
|
659 |
+
if ( FrmFieldsHelper::is_field_with_multiple_values( $field ) ) {
|
660 |
+
$other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] : '';
|
661 |
+
} else {
|
662 |
+
$other_val = $_POST['item_meta']['other'][ $field['id'] ];
|
663 |
+
}
|
664 |
+
return $other_val;
|
665 |
+
}
|
666 |
+
|
667 |
+
// For checkboxes
|
668 |
+
if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) {
|
669 |
+
// Check if there is an "other" val in saved value and make sure the "other" val is not equal to the Other checkbox option
|
670 |
+
if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) {
|
671 |
+
$other_val = $field['value'][ $opt_key ];
|
672 |
+
}
|
673 |
+
} else {
|
674 |
+
/**
|
675 |
+
* For radio buttons and dropdowns
|
676 |
+
* Check if saved value equals any of the options. If not, set it as the other value.
|
677 |
+
*/
|
678 |
+
foreach ( $field['options'] as $opt_key => $opt_val ) {
|
679 |
+
$temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
|
680 |
+
// Multi-select dropdowns - key is not preserved
|
681 |
+
if ( is_array( $field['value'] ) ) {
|
682 |
+
$o_key = array_search( $temp_val, $field['value'] );
|
683 |
+
if ( isset( $field['value'][ $o_key ] ) ) {
|
684 |
+
unset( $field['value'][ $o_key ], $o_key );
|
685 |
+
}
|
686 |
+
} else if ( $temp_val == $field['value'] ) {
|
687 |
+
// For radio and regular dropdowns
|
688 |
+
return '';
|
689 |
+
} else {
|
690 |
+
$other_val = $field['value'];
|
691 |
+
}
|
692 |
+
unset($opt_key, $opt_val, $temp_val);
|
693 |
+
}
|
694 |
+
// For multi-select dropdowns only
|
695 |
+
if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
|
696 |
+
$other_val = reset( $field['value'] );
|
697 |
+
}
|
698 |
+
}
|
699 |
+
return $other_val;
|
700 |
}
|
701 |
+
|
702 |
+
/**
|
703 |
+
* Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
|
704 |
+
* Intended for front-end use
|
705 |
+
*
|
706 |
+
* @since 2.0
|
707 |
+
*
|
708 |
+
* @param array $field
|
709 |
+
* @param boolean $other_opt
|
710 |
+
* @param string $checked
|
711 |
+
* @param array $args should include opt_key and field name
|
712 |
+
* @return string $other_val
|
713 |
+
*/
|
714 |
+
public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) {
|
715 |
+
//Check if this is an "Other" option
|
716 |
+
if ( !self::is_other_opt( $args['opt_key'] ) ) {
|
717 |
+
return;
|
718 |
+
}
|
719 |
+
|
720 |
+
$other_opt = true;
|
721 |
+
$other_args = array();
|
722 |
+
$parent = $pointer = '';
|
723 |
+
|
724 |
+
// Check for parent ID and pointer
|
725 |
+
$temp_array = explode( '[', $args['field_name'] );
|
726 |
+
// Count should only be greater than 3 if inside of a repeating section
|
727 |
+
if ( count( $temp_array ) > 3 ) {
|
728 |
+
$parent = str_replace( ']', '', $temp_array[1] );
|
729 |
+
$pointer = str_replace( ']', '', $temp_array[2]);
|
730 |
+
}
|
731 |
+
unset( $temp_array );
|
732 |
+
|
733 |
+
//Set up name for other field
|
734 |
+
$other_args['name'] = str_replace( '[]', '', $args['field_name'] );
|
735 |
+
$other_args['name'] = preg_replace('/\[' . $field['id'] . '\]$/', '', $other_args['name']);
|
736 |
+
$other_args['name'] = $other_args['name'] . '[other]' . '[' . $field['id'] . ']';
|
737 |
+
//Converts item_meta[field_id] => item_meta[other][field_id] and
|
738 |
+
//item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
|
739 |
+
if ( FrmFieldsHelper::is_field_with_multiple_values( $field ) ) {
|
740 |
+
$other_args['name'] .= '[' . $args['opt_key'] . ']';
|
741 |
+
}
|
742 |
+
|
743 |
+
// Get text for "other" text field
|
744 |
+
$other_args['value'] = self::get_other_val( $args['opt_key'], $field, $parent, $pointer );
|
745 |
+
|
746 |
+
if ( $other_args['value'] ) {
|
747 |
+
$checked = 'checked="checked" ';
|
748 |
+
}
|
749 |
+
|
750 |
+
return $other_args;
|
751 |
+
}
|
752 |
+
|
753 |
public static function recursive_trim(&$value) {
|
754 |
+
if ( is_array($value) ) {
|
755 |
+
$value = array_map( array( 'FrmAppHelper', 'recursive_trim' ), $value);
|
756 |
+
} else {
|
757 |
$value = trim($value);
|
758 |
+
}
|
759 |
+
|
760 |
return $value;
|
761 |
}
|
762 |
+
|
763 |
+
/**
|
764 |
+
* Flatten a multi-dimensional array
|
765 |
+
*/
|
766 |
+
public static function array_flatten( $array ) {
|
767 |
+
$return = array();
|
768 |
+
foreach ( $array as $key => $value ) {
|
769 |
+
if ( is_array($value) ) {
|
770 |
+
$return = array_merge( $return, self::array_flatten($value) );
|
771 |
+
} else {
|
772 |
+
$return[ $key ] = $value;
|
773 |
+
}
|
774 |
+
}
|
775 |
+
return $return;
|
776 |
+
}
|
777 |
+
|
778 |
public static function esc_textarea( $text ) {
|
779 |
$safe_text = str_replace('"', '"', $text);
|
780 |
$safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
|
781 |
return apply_filters( 'esc_textarea', $safe_text, $text );
|
782 |
}
|
783 |
+
|
784 |
+
/**
|
785 |
+
* Add auto paragraphs to text areas
|
786 |
+
* @since 2.0
|
787 |
+
*/
|
788 |
+
public static function use_wpautop($content) {
|
789 |
+
if ( apply_filters('frm_use_wpautop', true) ) {
|
790 |
+
$content = wpautop(str_replace( '<br>', '<br />', $content));
|
791 |
+
}
|
792 |
+
return $content;
|
793 |
+
}
|
794 |
+
|
795 |
+
public static function replace_quotes($val) {
|
796 |
+
//Replace double quotes
|
797 |
+
$val = str_replace( array( '“', '”', '″'), '"', $val);
|
798 |
+
//Replace single quotes
|
799 |
+
$val = str_replace( array( '‘', '’', '′', '′', '’', '‘' ), "'", $val );
|
800 |
return $val;
|
801 |
}
|
802 |
+
|
803 |
+
/**
|
804 |
+
* @since 2.0
|
805 |
+
* @return string The base Google APIS url for the current version of jQuery UI
|
806 |
+
*/
|
807 |
+
public static function jquery_ui_base_url() {
|
808 |
+
$url = 'http'. ( is_ssl() ? 's' : '' ) .'://ajax.googleapis.com/ajax/libs/jqueryui/'. self::script_version('jquery-ui-core');
|
809 |
+
$url = apply_filters('frm_jquery_ui_base_url', $url);
|
810 |
+
return $url;
|
811 |
+
}
|
812 |
+
|
813 |
+
/**
|
814 |
+
* @param string $handle
|
815 |
+
*/
|
816 |
+
public static function script_version($handle) {
|
817 |
global $wp_scripts;
|
818 |
+
if ( ! $wp_scripts ) {
|
819 |
return false;
|
820 |
+
}
|
821 |
+
|
822 |
$ver = 0;
|
823 |
+
|
824 |
+
if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
|
825 |
+
return $ver;
|
826 |
+
}
|
827 |
+
|
828 |
+
$query = $wp_scripts->registered[ $handle ];
|
829 |
+
if ( is_object( $query ) ) {
|
830 |
$ver = $query->ver;
|
831 |
+
}
|
832 |
|
833 |
return $ver;
|
834 |
}
|
835 |
+
|
836 |
+
public static function js_redirect($url) {
|
837 |
+
return '<script type="text/javascript">window.location="' . $url . '"</script>';
|
838 |
}
|
839 |
+
|
840 |
+
public static function get_user_id_param($user_id) {
|
841 |
+
if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) {
|
842 |
+
return $user_id;
|
|
|
|
|
|
|
|
|
843 |
}
|
844 |
+
|
845 |
+
if ( $user_id == 'current' ) {
|
846 |
+
$user_ID = get_current_user_id();
|
847 |
+
$user_id = $user_ID;
|
848 |
+
} else {
|
849 |
+
if ( is_email($user_id) ) {
|
850 |
+
$user = get_user_by('email', $user_id);
|
851 |
+
} else {
|
852 |
+
$user = get_user_by('login', $user_id);
|
853 |
+
}
|
854 |
+
|
855 |
+
if ( $user ) {
|
856 |
+
$user_id = $user->ID;
|
857 |
+
}
|
858 |
+
unset($user);
|
859 |
+
}
|
860 |
+
|
861 |
+
return $user_id;
|
862 |
+
}
|
863 |
+
|
864 |
+
public static function get_file_contents($filename, $atts = array()) {
|
865 |
+
if ( ! is_file($filename) ) {
|
866 |
+
return false;
|
867 |
+
}
|
868 |
+
|
869 |
+
extract($atts);
|
870 |
+
ob_start();
|
871 |
+
include($filename);
|
872 |
+
$contents = ob_get_contents();
|
873 |
+
ob_end_clean();
|
874 |
+
return $contents;
|
875 |
}
|
876 |
+
|
877 |
+
/**
|
878 |
+
* @param string $table_name
|
879 |
+
* @param string $column
|
880 |
+
*/
|
881 |
+
public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 6 ) {
|
882 |
global $wpdb;
|
883 |
|
884 |
$key = '';
|
885 |
+
|
886 |
+
if ( ! empty( $name ) ) {
|
887 |
$key = sanitize_key($name);
|
888 |
}
|
889 |
+
|
890 |
+
if ( empty( $key ) ) {
|
891 |
$max_slug_value = pow(36, $num_chars);
|
892 |
$min_slug_value = 37; // we want to have at least 2 characters in the slug
|
893 |
$key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
|
894 |
}
|
895 |
|
896 |
+
if ( is_numeric($key) || in_array($key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')) ) {
|
897 |
$key = $key .'a';
|
898 |
+
}
|
899 |
+
|
900 |
+
$key_check = FrmDb::get_var( $table_name, array($column => $key, 'ID !' => $id), $column );
|
901 |
+
|
902 |
+
if ( $key_check || is_numeric($key_check) ) {
|
903 |
$suffix = 2;
|
904 |
do {
|
905 |
+
$alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
|
906 |
+
$key_check = FrmDb::get_var( $table_name, array($column => $alt_post_name, 'ID !' => $id), $column );
|
907 |
$suffix++;
|
908 |
} while ($key_check || is_numeric($key_check));
|
909 |
$key = $alt_post_name;
|
911 |
return $key;
|
912 |
}
|
913 |
|
914 |
+
/**
|
915 |
+
* Editing a Form or Entry
|
916 |
+
* @param string $table
|
917 |
+
* @return bool|array
|
918 |
+
*/
|
919 |
+
public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array() ) {
|
920 |
+
if ( ! $record ) {
|
921 |
+
return false;
|
922 |
+
}
|
923 |
+
|
924 |
+
global $frm_vars;
|
925 |
+
|
926 |
+
if ( empty($post_values) ) {
|
927 |
$post_values = stripslashes_deep($_POST);
|
928 |
+
}
|
929 |
+
|
930 |
+
$values = array( 'id' => $record->id, 'fields' => array());
|
931 |
|
932 |
+
foreach ( array( 'name', 'description') as $var ) {
|
933 |
$default_val = isset($record->{$var}) ? $record->{$var} : '';
|
934 |
+
$values[ $var ] = self::get_param( $var, $default_val );
|
935 |
unset($var, $default_val);
|
936 |
}
|
937 |
+
|
938 |
+
$values['description'] = self::use_wpautop($values['description']);
|
939 |
+
$frm_settings = self::get_settings();
|
940 |
+
$is_form_builder = self::is_admin_page('formidable' );
|
941 |
+
|
942 |
foreach ( (array) $fields as $field ) {
|
943 |
+
// Make sure to filter default values (for placeholder text), but not on the form builder page
|
944 |
+
if ( ! $is_form_builder ) {
|
945 |
+
$field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
|
946 |
+
}
|
947 |
+
self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings'));
|
948 |
+
}
|
949 |
|
950 |
+
self::fill_form_opts($record, $table, $post_values, $values);
|
951 |
+
|
952 |
+
if ( $table == 'entries' ) {
|
953 |
+
$values = FrmEntriesHelper::setup_edit_vars( $values, $record );
|
954 |
+
} else if ( $table == 'forms' ) {
|
955 |
+
$values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
|
956 |
+
}
|
957 |
+
|
958 |
+
return $values;
|
959 |
+
}
|
960 |
+
|
961 |
+
private static function fill_field_defaults($field, $record, array &$values, $args) {
|
962 |
+
$post_values = $args['post_values'];
|
963 |
+
|
964 |
+
if ( $args['default'] ) {
|
965 |
+
$meta_value = $field->default_value;
|
966 |
+
} else {
|
967 |
+
if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) {
|
968 |
+
if ( ! isset($field->field_options['custom_field']) ) {
|
969 |
+
$field->field_options['custom_field'] = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
970 |
}
|
971 |
+
$meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field));
|
972 |
+
} else {
|
973 |
+
$meta_value = self::get_meta_value($field->id, $record);
|
974 |
+
}
|
975 |
+
}
|
976 |
+
|
977 |
+
$field_type = isset( $post_values['field_options'][ 'type_'. $field->id ] ) ? $post_values['field_options'][ 'type_'. $field->id ] : $field->type;
|
978 |
+
$new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
|
979 |
+
|
980 |
+
$field_array = array(
|
981 |
+
'id' => $field->id,
|
982 |
+
'value' => $new_value,
|
983 |
+
'default_value' => $field->default_value,
|
984 |
+
'name' => $field->name,
|
985 |
+
'description' => $field->description,
|
986 |
+
'type' => apply_filters('frm_field_type', $field_type, $field, $new_value),
|
987 |
+
'options' => $field->options,
|
988 |
+
'required' => $field->required,
|
989 |
+
'field_key' => $field->field_key,
|
990 |
+
'field_order' => $field->field_order,
|
991 |
+
'form_id' => $field->form_id,
|
992 |
+
);
|
993 |
+
|
994 |
+
$args['field_type'] = $field_type;
|
995 |
+
self::fill_field_opts($field, $field_array, $args);
|
996 |
+
|
997 |
+
$field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']);
|
998 |
+
|
999 |
+
if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) {
|
1000 |
+
$field_array['unique_msg'] = '';
|
1001 |
+
}
|
1002 |
+
|
1003 |
+
$field_array = array_merge( $field->field_options, $field_array );
|
1004 |
+
|
1005 |
+
$values['fields'][ $field->id ] = $field_array;
|
1006 |
+
}
|
1007 |
+
|
1008 |
+
private static function fill_field_opts($field, array &$field_array, $args) {
|
1009 |
+
$post_values = $args['post_values'];
|
1010 |
+
$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
|
1011 |
+
|
1012 |
+
foreach ( $opt_defaults as $opt => $default_opt ) {
|
1013 |
+
$field_array[ $opt ] = ( $post_values && isset( $post_values['field_options'] [ $opt .'_'. $field->id ] ) ) ? maybe_unserialize( $post_values['field_options'][ $opt .'_'. $field->id ] ) : ( isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default_opt );
|
1014 |
+
if ( $opt == 'blank' && $field_array[ $opt ] == '' ) {
|
1015 |
+
$field_array[ $opt ] = $args['frm_settings']->blank_msg;
|
1016 |
+
} else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) {
|
1017 |
+
if ( $args['field_type'] == 'captcha' ) {
|
1018 |
+
$field_array[ $opt ] = $args['frm_settings']->re_msg;
|
1019 |
+
} else {
|
1020 |
+
$field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
|
1021 |
}
|
1022 |
}
|
1023 |
}
|
1024 |
+
|
1025 |
+
if ( $field_array['custom_html'] == '' ) {
|
1026 |
+
$field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']);
|
1027 |
+
}
|
1028 |
+
|
1029 |
+
$field_array['size'] = self::get_field_size($field_array);
|
1030 |
+
}
|
1031 |
+
|
1032 |
+
/**
|
1033 |
+
* @param string $table
|
1034 |
+
*/
|
1035 |
+
private static function fill_form_opts($record, $table, $post_values, array &$values) {
|
1036 |
+
if ( $table == 'entries' ) {
|
1037 |
+
$form = $record->form_id;
|
1038 |
+
FrmFormsHelper::maybe_get_form( $form );
|
1039 |
+
} else {
|
1040 |
+
$form = $record;
|
1041 |
+
}
|
1042 |
+
|
1043 |
+
if ( ! $form ) {
|
1044 |
+
return;
|
1045 |
+
}
|
1046 |
+
|
1047 |
+
$values['form_name'] = isset($record->form_id) ? $form->name : '';
|
1048 |
+
$values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
|
1049 |
+
|
1050 |
+
if ( ! is_array($form->options) ) {
|
1051 |
+
return;
|
1052 |
+
}
|
1053 |
+
|
1054 |
+
foreach ( $form->options as $opt => $value ) {
|
1055 |
+
$values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
|
1056 |
+
}
|
1057 |
+
|
1058 |
+
self::fill_form_defaults($post_values, $values);
|
1059 |
+
}
|
1060 |
+
|
1061 |
+
/**
|
1062 |
+
* Set to POST value or default
|
1063 |
+
*/
|
1064 |
+
private static function fill_form_defaults($post_values, array &$values) {
|
1065 |
$form_defaults = FrmFormsHelper::get_default_opts();
|
1066 |
+
|
1067 |
+
foreach ( $form_defaults as $opt => $default ) {
|
1068 |
+
if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
|
1069 |
+
if ( $opt == 'notification' ) {
|
1070 |
+
$values[ $opt ] = ( $post_values && isset( $post_values[ $opt ] ) ) ? $post_values[ $opt ] : $default;
|
1071 |
+
|
1072 |
+
foreach ( $default as $o => $d ) {
|
1073 |
+
if ( $o == 'email_to' ) {
|
|
|
1074 |
$d = ''; //allow blank email address
|
1075 |
+
}
|
1076 |
+
$values[ $opt ][0][ $o ] = ( $post_values && isset( $post_values[ $opt ][0][ $o ]) ) ? $post_values[ $opt ][0][ $o ] : $d;
|
1077 |
+
unset($o, $d);
|
1078 |
}
|
1079 |
+
} else {
|
1080 |
+
$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
|
1081 |
+
}
|
1082 |
+
} else if ( $values[ $opt ] == 'notification' ) {
|
1083 |
+
foreach ( $values[ $opt ] as $k => $n ) {
|
1084 |
+
foreach ( $default as $o => $d ) {
|
1085 |
+
if ( ! isset( $n[ $o ] ) ) {
|
1086 |
+
$values[ $opt ][ $k ][ $o ] = ( $post_values && isset( $post_values[ $opt ][ $k ][ $o ] ) ) ? $post_values[ $opt ][ $k ][ $o ] : $d;
|
1087 |
+
}
|
1088 |
+
unset($o, $d);
|
1089 |
}
|
1090 |
+
unset($k, $n);
|
|
|
1091 |
}
|
1092 |
}
|
1093 |
+
|
1094 |
+
unset($opt, $defaut);
|
|
|
1095 |
}
|
|
|
|
|
|
|
1096 |
|
1097 |
+
if ( ! isset($values['custom_style']) ) {
|
1098 |
+
$frm_settings = self::get_settings();
|
1099 |
+
$values['custom_style'] = ( $post_values && isset($post_values['options']['custom_style']) ) ? $_POST['options']['custom_style'] : ( $frm_settings->load_style != 'none' );
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
foreach ( array( 'before', 'after', 'submit') as $h ) {
|
1103 |
+
if ( ! isset( $values[ $h .'_html' ] ) ) {
|
1104 |
+
$values[ $h .'_html' ] = ( isset( $post_values['options'][ $h .'_html' ] ) ? $post_values['options'][ $h .'_html' ] : FrmFormsHelper::get_default_html( $h ) );
|
1105 |
+
}
|
1106 |
unset($h);
|
1107 |
}
|
1108 |
+
}
|
|
|
|
|
|
|
|
|
1109 |
|
1110 |
+
/**
|
1111 |
+
* @return string
|
1112 |
+
*/
|
1113 |
+
public static function get_meta_value($field_id, $entry) {
|
1114 |
+
if ( isset($entry->metas) ) {
|
1115 |
+
return isset( $entry->metas[ $field_id ] ) ? $entry->metas[ $field_id ] : false;
|
1116 |
+
} else {
|
1117 |
+
return FrmEntryMeta::get_entry_meta_by_field($entry->id, $field_id);
|
1118 |
+
}
|
1119 |
+
}
|
1120 |
+
|
1121 |
+
/**
|
1122 |
+
* @since 2.0
|
1123 |
+
* @return string
|
1124 |
+
*/
|
1125 |
+
public static function get_field_size($field) {
|
1126 |
+
if ( '' == $field['size'] ) {
|
1127 |
+
global $frm_vars;
|
1128 |
+
$field['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
|
1129 |
+
}
|
1130 |
+
return $field['size'];
|
1131 |
}
|
1132 |
+
|
1133 |
+
public static function insert_opt_html($args) {
|
|
|
|
|
1134 |
$class = '';
|
1135 |
+
if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
|
|
|
1136 |
$class .= 'show_frm_not_email_to';
|
1137 |
}
|
1138 |
?>
|
1139 |
<li>
|
1140 |
+
<a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['id']) ?>" >[<?php echo esc_attr( $args['id'] ) ?>]</a>
|
1141 |
+
<a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['key']) ?>" >[<?php echo esc_attr( self::truncate($args['key'], 10) ) ?>]</a>
|
1142 |
+
<a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr($args['id']) ?>" ><?php echo esc_attr( self::truncate($args['name'], 60) ) ?></a>
|
1143 |
</li>
|
1144 |
<?php
|
1145 |
}
|
1146 |
+
|
1147 |
+
public static function get_us_states() {
|
1148 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmFieldsHelper::get_us_states' );
|
1149 |
+
return FrmFieldsHelper::get_us_states();
|
1150 |
+
}
|
1151 |
+
|
1152 |
+
public static function get_countries() {
|
1153 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmFieldsHelper::get_countries' );
|
1154 |
+
return FrmFieldsHelper::get_countries();
|
1155 |
+
}
|
1156 |
+
|
1157 |
+
public static function truncate($str, $length, $minword = 3, $continue = '...') {
|
1158 |
+
if ( is_array( $str ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1159 |
return;
|
1160 |
+
}
|
1161 |
+
|
1162 |
+
$length = (int) $length;
|
1163 |
+
$str = wp_strip_all_tags( $str );
|
1164 |
$original_len = (function_exists('mb_strlen')) ? mb_strlen($str) : strlen($str);
|
1165 |
+
|
1166 |
+
if ( $length == 0 ) {
|
1167 |
return '';
|
1168 |
+
} else if ( $length <= 10 ) {
|
1169 |
+
$sub = function_exists( 'mb_substr' ) ? mb_substr( $str, 0, $length ) : substr( $str, 0, $length );
|
1170 |
return $sub . (($length < $original_len) ? $continue : '');
|
1171 |
}
|
1172 |
+
|
1173 |
$sub = '';
|
1174 |
$len = 0;
|
1175 |
|
1176 |
$words = (function_exists('mb_split')) ? mb_split(' ', $str) : explode(' ', $str);
|
1177 |
+
|
1178 |
+
foreach ( $words as $word ) {
|
1179 |
$part = (($sub != '') ? ' ' : '') . $word;
|
1180 |
$total_len = (function_exists('mb_strlen')) ? mb_strlen($sub . $part) : strlen($sub. $part);
|
1181 |
if ( $total_len > $length && str_word_count($sub) ) {
|
1182 |
break;
|
1183 |
}
|
1184 |
+
|
1185 |
$sub .= $part;
|
1186 |
$len += (function_exists('mb_strlen')) ? mb_strlen($part) : strlen($part);
|
1187 |
+
|
1188 |
if ( str_word_count($sub) > $minword && $total_len >= $length ) {
|
1189 |
break;
|
1190 |
}
|
1191 |
+
|
1192 |
unset($total_len, $word);
|
1193 |
}
|
1194 |
+
|
1195 |
return $sub . (($len < $original_len) ? $continue : '');
|
1196 |
}
|
1197 |
+
|
1198 |
+
public static function get_formatted_time($date, $date_format = '', $time_format = '' ) {
|
1199 |
+
if ( empty($date) ) {
|
1200 |
+
return $date;
|
1201 |
+
}
|
1202 |
+
|
1203 |
+
if ( empty($date_format) ) {
|
1204 |
+
$date_format = get_option('date_format');
|
1205 |
+
}
|
1206 |
+
|
1207 |
+
if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) {
|
1208 |
+
$frmpro_settings = new FrmProSettings();
|
1209 |
+
$date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
|
1210 |
+
}
|
1211 |
+
|
1212 |
+
$do_time = ( date('H:i:s', strtotime($date)) == '00:00:00' ) ? false : true;
|
1213 |
+
|
1214 |
+
$date = get_date_from_gmt($date);
|
1215 |
+
|
1216 |
+
$formatted = date_i18n($date_format, strtotime($date));
|
1217 |
+
|
1218 |
+
if ( $do_time ) {
|
1219 |
+
|
1220 |
+
if ( empty($time_format) ) {
|
1221 |
+
$time_format = get_option('time_format');
|
1222 |
+
}
|
1223 |
+
|
1224 |
+
$trimmed_format = trim($time_format);
|
1225 |
+
if ( $time_format && ! empty($trimmed_format) ) {
|
1226 |
+
$formatted .= ' '. __( 'at', 'formidable' ) .' '. date_i18n($time_format, strtotime($date));
|
1227 |
+
}
|
1228 |
+
}
|
1229 |
+
|
1230 |
+
return $formatted;
|
1231 |
+
}
|
1232 |
+
|
1233 |
+
/**
|
1234 |
+
* @return string The time ago in words
|
1235 |
+
*/
|
1236 |
+
public static function human_time_diff( $from, $to = '' ) {
|
1237 |
+
if ( empty($to) ) {
|
1238 |
+
$to = time();
|
1239 |
+
}
|
1240 |
+
|
1241 |
+
// Array of time period chunks
|
1242 |
+
$chunks = array(
|
1243 |
+
array( 60 * 60 * 24 * 365, __( 'year', 'formidable' ), __( 'years', 'formidable' ) ),
|
1244 |
+
array( 60 * 60 * 24 * 30, __( 'month', 'formidable' ), __( 'months', 'formidable' ) ),
|
1245 |
+
array( 60 * 60 * 24 * 7, __( 'week', 'formidable' ), __( 'weeks', 'formidable' ) ),
|
1246 |
+
array( 60 * 60 * 24, __( 'day', 'formidable' ), __( 'days', 'formidable' ) ),
|
1247 |
+
array( 60 * 60, __( 'hour', 'formidable' ), __( 'hours', 'formidable' ) ),
|
1248 |
+
array( 60, __( 'minute', 'formidable' ), __( 'minutes', 'formidable' ) ),
|
1249 |
+
array( 1, __( 'second', 'formidable' ), __( 'seconds', 'formidable' ) ),
|
1250 |
+
);
|
1251 |
+
|
1252 |
+
// Difference in seconds
|
1253 |
+
$diff = (int) ($to - $from);
|
1254 |
+
|
1255 |
+
// Something went wrong with date calculation and we ended up with a negative date.
|
1256 |
+
if ( $diff < 1) {
|
1257 |
+
return '0 ' . __( 'seconds', 'formidable' );
|
1258 |
+
}
|
1259 |
+
|
1260 |
+
/**
|
1261 |
+
* We only want to output one chunks of time here, eg:
|
1262 |
+
* x years
|
1263 |
+
* xx months
|
1264 |
+
* so there's only one bit of calculation below:
|
1265 |
+
*/
|
1266 |
+
|
1267 |
+
$count = 0;
|
1268 |
+
|
1269 |
+
//Step one: the first chunk
|
1270 |
+
for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
|
1271 |
+
$seconds = $chunks[ $i ][0];
|
1272 |
+
|
1273 |
+
// Finding the biggest chunk (if the chunk fits, break)
|
1274 |
+
if ( ( $count = floor($diff / $seconds) ) != 0 ) {
|
1275 |
+
break;
|
1276 |
+
}
|
1277 |
+
}
|
1278 |
+
|
1279 |
+
// Set output var
|
1280 |
+
$output = ( 1 == $count ) ? '1 '. $chunks[ $i ][1] : $count . ' ' . $chunks[ $i ][2];
|
1281 |
+
|
1282 |
+
if ( ! (int) trim( $output ) ) {
|
1283 |
+
$output = '0 ' . __( 'seconds', 'formidable' );
|
1284 |
+
}
|
1285 |
+
|
1286 |
+
return $output;
|
1287 |
+
}
|
1288 |
+
|
1289 |
+
/**
|
1290 |
+
* Added for < WP 4.0 compatability
|
1291 |
+
*
|
1292 |
+
* @since 1.07.10
|
1293 |
+
*
|
1294 |
+
* @param string $term The value to escape
|
1295 |
+
* @return string The escaped value
|
1296 |
+
*/
|
1297 |
public static function esc_like($term) {
|
1298 |
global $wpdb;
|
1299 |
+
if ( method_exists($wpdb, 'esc_like') ) {
|
1300 |
+
// WP 4.0
|
1301 |
$term = $wpdb->esc_like( $term );
|
1302 |
} else {
|
1303 |
$term = like_escape( $term );
|
1304 |
}
|
1305 |
+
|
1306 |
return $term;
|
1307 |
}
|
1308 |
+
|
1309 |
+
/**
|
1310 |
+
* @param string $order_query
|
1311 |
+
*/
|
1312 |
+
public static function esc_order($order_query) {
|
1313 |
+
if ( empty($order_query) ) {
|
1314 |
+
return '';
|
1315 |
+
}
|
1316 |
+
|
1317 |
+
// remove ORDER BY before santizing
|
1318 |
+
$order_query = strtolower($order_query);
|
1319 |
+
if ( strpos($order_query, 'order by') !== false ) {
|
1320 |
+
$order_query = str_replace('order by', '', $order_query);
|
1321 |
+
}
|
1322 |
+
|
1323 |
+
$order_query = explode(' ', trim($order_query));
|
1324 |
+
|
1325 |
+
$order_fields = array(
|
1326 |
+
'id', 'form_key', 'name', 'description',
|
1327 |
+
'parent_form_id', 'logged_in', 'is_template',
|
1328 |
+
'default_template', 'status', 'created_at',
|
1329 |
+
);
|
1330 |
+
|
1331 |
+
$order = trim(trim(reset($order_query), ','));
|
1332 |
+
if ( ! in_array($order, $order_fields) ) {
|
1333 |
+
return '';
|
1334 |
+
}
|
1335 |
+
|
1336 |
+
$order_by = '';
|
1337 |
+
if ( count($order_query) > 1 ) {
|
1338 |
+
$order_by = end( $order_query );
|
1339 |
+
self::esc_order_by( $order_by );
|
1340 |
+
}
|
1341 |
+
|
1342 |
+
return ' ORDER BY '. $order . ' '. $order_by;
|
1343 |
+
}
|
1344 |
+
|
1345 |
+
/**
|
1346 |
+
* Make sure this is ordering by either ASC or DESC
|
1347 |
+
*/
|
1348 |
+
public static function esc_order_by( &$order_by ) {
|
1349 |
+
$sort_options = array( 'asc', 'desc' );
|
1350 |
+
if ( ! in_array( strtolower( $order_by ), $sort_options ) ) {
|
1351 |
+
$order_by = 'asc';
|
1352 |
+
}
|
1353 |
+
}
|
1354 |
+
|
1355 |
+
/**
|
1356 |
+
* @param string $limit
|
1357 |
+
*/
|
1358 |
+
public static function esc_limit($limit) {
|
1359 |
+
if ( empty($limit) ) {
|
1360 |
+
return '';
|
1361 |
+
}
|
1362 |
+
|
1363 |
+
$limit = trim(str_replace(' limit', '', strtolower($limit)));
|
1364 |
+
if ( is_numeric($limit) ) {
|
1365 |
+
return ' LIMIT '. $limit;
|
1366 |
+
}
|
1367 |
+
|
1368 |
+
$limit = explode(',', trim($limit));
|
1369 |
+
foreach ( $limit as $k => $l ) {
|
1370 |
+
if ( is_numeric( $l ) ) {
|
1371 |
+
$limit[ $k ] = $l;
|
1372 |
+
}
|
1373 |
+
}
|
1374 |
+
|
1375 |
+
$limit = implode(',', $limit);
|
1376 |
+
return ' LIMIT '. $limit;
|
1377 |
+
}
|
1378 |
+
|
1379 |
+
/**
|
1380 |
+
* Get an array of values ready to go through $wpdb->prepare
|
1381 |
+
* @since 2.0
|
1382 |
+
*/
|
1383 |
+
public static function prepare_array_values( $array, $type = '%s' ) {
|
1384 |
+
$placeholders = array_fill(0, count($array), $type);
|
1385 |
+
return implode(', ', $placeholders);
|
1386 |
+
}
|
1387 |
+
|
1388 |
+
public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
|
1389 |
if ( empty($where) ) {
|
1390 |
return '';
|
1391 |
}
|
1392 |
+
|
1393 |
+
if ( is_array( $where ) ) {
|
1394 |
+
global $wpdb;
|
1395 |
+
FrmDb::get_where_clause_and_values( $where, $starts_with );
|
1396 |
+
$where = $wpdb->prepare( $where['where'], $where['values'] );
|
1397 |
+
} else {
|
1398 |
$where = $starts_with . $where;
|
1399 |
}
|
1400 |
+
|
1401 |
return $where;
|
1402 |
}
|
1403 |
+
|
1404 |
// Pagination Methods
|
1405 |
+
|
1406 |
+
/**
|
1407 |
+
* @param integer $current_p
|
1408 |
+
*/
|
1409 |
+
public static function get_last_record_num( $r_count, $current_p, $p_size ) {
|
1410 |
+
return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
|
1411 |
+
}
|
1412 |
+
|
1413 |
+
/**
|
1414 |
+
* @param integer $current_p
|
1415 |
+
*/
|
1416 |
+
public static function get_first_record_num( $r_count, $current_p, $p_size ) {
|
1417 |
+
if ( $current_p == 1 ) {
|
1418 |
+
return 1;
|
1419 |
+
} else {
|
1420 |
+
return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
|
1421 |
+
}
|
1422 |
}
|
1423 |
|
1424 |
+
/**
|
1425 |
+
* @param string $table_name
|
1426 |
+
*/
|
1427 |
+
public static function &getRecordCount( $where = '', $table_name ) {
|
1428 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_count' );
|
1429 |
+
$count = FrmDb::get_count( $table_name, $where );
|
1430 |
+
return $count;
|
1431 |
}
|
1432 |
+
|
1433 |
+
public static function get_referer_info() {
|
1434 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::get_server_value' );
|
1435 |
+
return self::get_server_value('HTTP_REFERER');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1436 |
}
|
1437 |
+
|
1438 |
+
/**
|
1439 |
+
* @return array
|
1440 |
+
*/
|
1441 |
+
public static function json_to_array( $json_vars ) {
|
1442 |
$vars = array();
|
1443 |
+
foreach ( $json_vars as $jv ) {
|
1444 |
$jv_name = explode('[', $jv['name']);
|
1445 |
+
$last = count($jv_name) - 1;
|
1446 |
+
foreach ( $jv_name as $p => $n ) {
|
1447 |
$name = trim($n, ']');
|
1448 |
+
if ( ! isset($l1) ) {
|
|
|
|
|
1449 |
$l1 = $name;
|
|
|
|
|
|
|
|
|
1450 |
}
|
1451 |
+
|
1452 |
+
if ( ! isset($l2) ) {
|
1453 |
$l2 = $name;
|
|
|
|
|
|
|
|
|
1454 |
}
|
1455 |
+
|
1456 |
+
if ( ! isset($l3) ) {
|
1457 |
$l3 = $name;
|
|
|
|
|
|
|
|
|
1458 |
}
|
1459 |
+
|
1460 |
+
$this_val = ( $p == $last ) ? $jv['value'] : array();
|
1461 |
+
|
1462 |
+
switch ( $p ) {
|
1463 |
+
case 0:
|
1464 |
+
$l1 = $name;
|
1465 |
+
self::add_value_to_array( $name, $l1, $this_val, $vars );
|
1466 |
+
break;
|
1467 |
+
|
1468 |
+
case 1:
|
1469 |
+
$l2 = $name;
|
1470 |
+
self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
|
1471 |
+
break;
|
1472 |
+
|
1473 |
+
case 2:
|
1474 |
+
$l3 = $name;
|
1475 |
+
self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
|
1476 |
+
break;
|
1477 |
+
|
1478 |
+
case 3:
|
1479 |
+
$l4 = $name;
|
1480 |
+
self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
|
1481 |
+
break;
|
1482 |
+
}
|
1483 |
+
|
1484 |
+
unset($this_val, $n);
|
1485 |
}
|
1486 |
+
|
1487 |
+
unset($last, $jv);
|
|
|
1488 |
}
|
1489 |
+
|
1490 |
return $vars;
|
1491 |
}
|
1492 |
+
|
1493 |
+
/**
|
1494 |
+
* @param string $name
|
1495 |
+
* @param string $l1
|
1496 |
+
*/
|
1497 |
+
public static function add_value_to_array( $name, $l1, $val, &$vars ) {
|
1498 |
+
if ( $name == '' ) {
|
1499 |
+
$vars[] = $val;
|
1500 |
+
} else if ( ! isset( $vars[ $l1 ] ) ) {
|
1501 |
+
$vars[ $l1 ] = $val;
|
1502 |
+
}
|
1503 |
+
}
|
1504 |
+
|
1505 |
+
public static function maybe_add_tooltip($name, $class = 'closed', $form_name = '') {
|
1506 |
+
$tooltips = array(
|
1507 |
+
'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ),
|
1508 |
+
'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com. [admin_email] is the address set in WP General Settings.', 'formidable' ),
|
1509 |
+
'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
|
1510 |
+
'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
|
1511 |
+
'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
|
1512 |
+
'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <john@example.com> or john@example.com.', 'formidable' ),
|
1513 |
+
'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
|
1514 |
+
);
|
1515 |
+
|
1516 |
+
if ( ! isset( $tooltips[ $name ] ) ) {
|
1517 |
+
return;
|
1518 |
+
}
|
1519 |
+
|
1520 |
+
if ( 'open' == $class ) {
|
1521 |
+
echo ' frm_help"';
|
1522 |
+
} else {
|
1523 |
+
echo ' class="frm_help"';
|
1524 |
+
}
|
1525 |
+
|
1526 |
+
echo ' title="'. esc_attr( $tooltips[ $name ] );
|
1527 |
+
|
1528 |
+
if ( 'open' != $class ) {
|
1529 |
+
echo '"';
|
1530 |
+
}
|
1531 |
+
}
|
1532 |
+
|
1533 |
+
/**
|
1534 |
+
* Add the current_page class to that page in the form nav
|
1535 |
+
*/
|
1536 |
+
public static function select_current_page( $page, $current_page, $action = array() ) {
|
1537 |
+
if ( $current_page != $page ) {
|
1538 |
+
return;
|
1539 |
+
}
|
1540 |
+
|
1541 |
+
$frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
|
1542 |
+
if ( empty( $action ) || ( ! empty( $frm_action ) && in_array( $frm_action, $action ) ) ) {
|
1543 |
+
echo ' class="current_page"';
|
1544 |
+
}
|
1545 |
+
}
|
1546 |
+
|
1547 |
+
/**
|
1548 |
+
* Prepare and json_encode post content
|
1549 |
+
*
|
1550 |
+
* @since 2.0
|
1551 |
+
*
|
1552 |
+
* @param array $post_content
|
1553 |
+
* @return string $post_content ( json encoded array )
|
1554 |
+
*/
|
1555 |
+
public static function prepare_and_encode( $post_content ) {
|
1556 |
+
|
1557 |
+
//Loop through array to strip slashes and add only the needed ones
|
1558 |
+
foreach ( $post_content as $key => $val ) {
|
1559 |
+
if ( isset( $post_content[ $key ] ) && ! is_array( $val ) ) {
|
1560 |
+
// Strip all slashes so everything is the same, no matter where the value is coming from
|
1561 |
+
$val = stripslashes( $val );
|
1562 |
+
|
1563 |
+
// Add backslashes before double quotes and forward slashes only
|
1564 |
+
$post_content[ $key ] = addcslashes( $val, '"\\/' );
|
1565 |
+
}
|
1566 |
+
unset( $key, $val );
|
1567 |
+
}
|
1568 |
+
|
1569 |
+
// json_encode the array
|
1570 |
+
$post_content = json_encode( $post_content );
|
1571 |
+
|
1572 |
+
// add extra slashes for \r\n since WP strips them
|
1573 |
+
$post_content = str_replace( array( '\\r', '\\n', '\\u'), array( '\\\\r', '\\\\n', '\\\\u'), $post_content );
|
1574 |
+
|
1575 |
+
// allow for "
|
1576 |
+
$post_content = str_replace( '"', '\\"', $post_content );
|
1577 |
+
|
1578 |
+
return $post_content;
|
1579 |
+
}
|
1580 |
+
|
1581 |
+
public static function maybe_json_decode($string) {
|
1582 |
+
if ( is_array($string) ) {
|
1583 |
+
return $string;
|
1584 |
+
}
|
1585 |
+
|
1586 |
$new_string = json_decode($string, true);
|
1587 |
+
if ( function_exists('json_last_error') ) {
|
1588 |
+
// php 5.3+
|
1589 |
if ( json_last_error() == JSON_ERROR_NONE ) {
|
1590 |
$string = $new_string;
|
1591 |
}
|
1592 |
+
} else if ( isset($new_string) ) {
|
1593 |
+
// php < 5.3 fallback
|
1594 |
$string = $new_string;
|
1595 |
}
|
1596 |
return $string;
|
1597 |
}
|
1598 |
+
|
1599 |
+
/**
|
1600 |
+
* @since 1.07.10
|
1601 |
+
*
|
1602 |
+
* @param string $post_type The name of the post type that may need to be highlighted
|
1603 |
+
* @return echo The javascript to open and highlight the Formidable menu
|
1604 |
+
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1605 |
public static function maybe_highlight_menu($post_type) {
|
1606 |
global $post, $pagenow;
|
1607 |
|
1608 |
if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
|
1609 |
return;
|
1610 |
}
|
1611 |
+
|
1612 |
if ( is_object($post) && $post->post_type != $post_type ) {
|
1613 |
return;
|
1614 |
}
|
1615 |
+
|
1616 |
+
self::load_admin_wide_js();
|
1617 |
+
echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
|
1618 |
+
}
|
1619 |
+
|
1620 |
+
/**
|
1621 |
+
* Load the JS file on non-Formidable pages in the admin area
|
1622 |
+
* @since 2.0
|
1623 |
+
*/
|
1624 |
+
public static function load_admin_wide_js( $load = true ) {
|
1625 |
+
$version = FrmAppHelper::plugin_version();
|
1626 |
+
wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery'), $version );
|
1627 |
+
|
1628 |
+
wp_localize_script( 'formidable_admin_global', 'frmGlobal', array(
|
1629 |
+
'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
|
1630 |
+
'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
|
1631 |
+
'url' => FrmAppHelper::plugin_url(),
|
1632 |
+
'loading' => __( 'Loading…' ),
|
1633 |
+
'nonce' => wp_create_nonce( 'frm_ajax' ),
|
1634 |
+
) );
|
1635 |
+
|
1636 |
+
if ( $load ) {
|
1637 |
+
wp_enqueue_script( 'formidable_admin_global' );
|
1638 |
+
}
|
1639 |
+
}
|
1640 |
+
|
1641 |
+
/**
|
1642 |
+
* @since 1.07.10
|
1643 |
+
*
|
1644 |
+
* @param float $min_version The version the add-on requires
|
1645 |
+
* @return echo The message on the plugins listing page
|
1646 |
+
*/
|
1647 |
public static function min_version_notice($min_version) {
|
1648 |
$frm_version = self::plugin_version();
|
1649 |
+
|
1650 |
// check if Formidable meets minimum requirements
|
1651 |
if ( version_compare($frm_version, $min_version, '>=') ) {
|
1652 |
return;
|
1653 |
}
|
1654 |
+
|
1655 |
$wp_list_table = _get_list_table('WP_Plugins_List_Table');
|
1656 |
echo '<tr class="plugin-update-tr active"><th colspan="' . $wp_list_table->get_column_count() . '" class="check-column plugin-update colspanchange"><div class="update-message">'.
|
1657 |
+
__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
|
1658 |
'</div></td></tr>';
|
1659 |
}
|
1660 |
+
|
1661 |
+
public static function locales( $type = 'date' ) {
|
1662 |
+
$locales = array(
|
1663 |
+
'en' => __( 'English', 'formidable' ), '' => __( 'English/Western', 'formidable' ),
|
1664 |
+
'af' => __( 'Afrikaans', 'formidable' ), 'sq' => __( 'Albanian', 'formidable' ),
|
1665 |
+
'ar' => __( 'Arabic', 'formidable' ), 'hy' => __( 'Armenian', 'formidable' ),
|
1666 |
+
'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ),
|
1667 |
+
'bs' => __( 'Bosnian', 'formidable' ), 'bg' => __( 'Bulgarian', 'formidable' ),
|
1668 |
+
'ca' => __( 'Catalan', 'formidable' ), 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
|
1669 |
+
'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
|
1670 |
+
'hr' => __( 'Croatian', 'formidable' ), 'cs' => __( 'Czech', 'formidable' ),
|
1671 |
+
'da' => __( 'Danish', 'formidable' ), 'nl' => __( 'Dutch', 'formidable' ),
|
1672 |
+
'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ),
|
1673 |
+
'et' => __( 'Estonian', 'formidable' ), 'fo' => __( 'Faroese', 'formidable' ),
|
1674 |
+
'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ),
|
1675 |
+
'fi' => __( 'Finnish', 'formidable' ), 'fr' => __( 'French', 'formidable' ),
|
1676 |
+
'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ),
|
1677 |
+
'de' => __( 'German', 'formidable' ), 'de-AT' => __( 'German/Austria', 'formidable' ),
|
1678 |
+
'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ),
|
1679 |
+
'he' => __( 'Hebrew', 'formidable' ), 'iw' => __( 'Hebrew', 'formidable' ),
|
1680 |
+
'hi' => __( 'Hindi', 'formidable' ), 'hu' => __( 'Hungarian', 'formidable' ),
|
1681 |
+
'is' => __( 'Icelandic', 'formidable' ), 'id' => __( 'Indonesian', 'formidable' ),
|
1682 |
+
'it' => __( 'Italian', 'formidable' ), 'ja' => __( 'Japanese', 'formidable' ),
|
1683 |
+
'ko' => __( 'Korean', 'formidable' ), 'lv' => __( 'Latvian', 'formidable' ),
|
1684 |
+
'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ),
|
1685 |
+
'no' => __( 'Norwegian', 'formidable' ), 'pl' => __( 'Polish', 'formidable' ),
|
1686 |
+
'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
|
1687 |
+
'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ),
|
1688 |
+
'ru' => __( 'Russian', 'formidable' ), 'sr' => __( 'Serbian', 'formidable' ),
|
1689 |
+
'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ),
|
1690 |
+
'sl' => __( 'Slovenian', 'formidable' ), 'es' => __( 'Spanish', 'formidable' ),
|
1691 |
+
'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ),
|
1692 |
+
'ta' => __( 'Tamil', 'formidable' ), 'th' => __( 'Thai', 'formidable' ),
|
1693 |
+
'tu' => __( 'Turkish', 'formidable' ), 'tr' => __( 'Turkish', 'formidable' ),
|
1694 |
+
'uk' => __( 'Ukranian', 'formidable' ), 'vi' => __( 'Vietnamese', 'formidable' ),
|
1695 |
+
);
|
1696 |
+
|
1697 |
+
if ( $type == 'captcha' ) {
|
1698 |
+
// remove the languages unavailable for the captcha
|
1699 |
+
$unset = array(
|
1700 |
+
'', 'af', 'sq', 'hy', 'az', 'eu', 'bs',
|
1701 |
+
'zh-HK', 'eo', 'et', 'fo', 'fr-CH',
|
1702 |
+
'he', 'is', 'ms', 'sr-SR', 'ta', 'tu',
|
1703 |
+
);
|
1704 |
+
} else {
|
1705 |
+
// remove the languages unavailable for the datepicker
|
1706 |
+
$unset = array(
|
1707 |
+
'en', 'fil', 'fr-CA', 'de-AT', 'de-AT',
|
1708 |
+
'de-CH', 'iw', 'hi', 'id', 'pt', 'pt-PT',
|
1709 |
+
'es-419', 'tr',
|
1710 |
+
);
|
1711 |
+
}
|
1712 |
+
|
1713 |
+
$locales = array_diff_key($locales, array_flip($unset));
|
1714 |
+
$locales = apply_filters('frm_locales', $locales);
|
1715 |
+
|
1716 |
+
return $locales;
|
1717 |
+
}
|
1718 |
}
|
classes/helpers/FrmEntriesHelper.php
CHANGED
@@ -1,193 +1,659 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
if(class_exists('FrmEntriesHelper'))
|
6 |
-
return;
|
7 |
-
|
8 |
-
class FrmEntriesHelper{
|
9 |
|
10 |
-
public static function setup_new_vars($fields, $form='', $reset=false){
|
11 |
-
global $
|
12 |
$values = array();
|
13 |
-
|
14 |
-
$values[$var] = FrmAppHelper::get_post_param($var, $default);
|
15 |
-
|
|
|
16 |
$values['fields'] = array();
|
17 |
-
if (empty($fields)){
|
18 |
return apply_filters('frm_setup_new_entry', $values);
|
19 |
}
|
20 |
-
|
21 |
foreach ( (array) $fields as $field ) {
|
22 |
-
$field->field_options = maybe_unserialize($field->field_options);
|
23 |
$default = $field->default_value;
|
24 |
$posted_val = false;
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
$new_value = stripslashes_deep($_POST['item_meta'][$field->id]);
|
30 |
$posted_val = true;
|
31 |
} else if ( isset($field->field_options['clear_on_focus']) && $field->field_options['clear_on_focus'] ) {
|
32 |
$new_value = '';
|
33 |
-
} else {
|
34 |
-
$new_value = $default;
|
35 |
}
|
36 |
-
|
37 |
$is_default = ($new_value == $default) ? true : false;
|
38 |
-
|
39 |
//If checkbox, multi-select dropdown, or checkbox data from entries field, set return array to true
|
40 |
-
|
41 |
-
|
42 |
-
} else {
|
43 |
-
$return_array = false;
|
44 |
-
}
|
45 |
-
|
46 |
$field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true, $return_array);
|
47 |
-
|
48 |
-
if ( !is_array($new_value) ) {
|
49 |
if ( $is_default ) {
|
50 |
$new_value = $field->default_value;
|
51 |
-
} else if (
|
52 |
$new_value = apply_filters('frm_filter_default_value', $new_value, $field);
|
53 |
}
|
54 |
-
|
55 |
$new_value = str_replace('"', '"', $new_value);
|
56 |
}
|
57 |
-
|
58 |
-
unset($is_default);
|
59 |
-
unset($posted_val);
|
60 |
-
|
61 |
-
$field_array = array(
|
62 |
-
'id' => $field->id,
|
63 |
-
'value' => $new_value,
|
64 |
-
'default_value' => $field->default_value,
|
65 |
-
'name' => $field->name,
|
66 |
-
'description' => $field->description,
|
67 |
-
'type' => apply_filters('frm_field_type', $field->type, $field, $new_value),
|
68 |
-
'options' => $field->options,
|
69 |
-
'required' => $field->required,
|
70 |
-
'field_key' => $field->field_key,
|
71 |
-
'field_order' => $field->field_order,
|
72 |
-
'form_id' => $field->form_id
|
73 |
-
);
|
74 |
-
|
75 |
-
$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
|
76 |
-
$opt_defaults['required_indicator'] = '';
|
77 |
-
|
78 |
-
foreach ($opt_defaults as $opt => $default_opt){
|
79 |
-
$field_array[$opt] = (isset($field->field_options[$opt]) && $field->field_options[$opt] != '') ? $field->field_options[$opt] : $default_opt;
|
80 |
-
unset($opt);
|
81 |
-
unset($default_opt);
|
82 |
-
}
|
83 |
-
|
84 |
-
unset($opt_defaults);
|
85 |
-
|
86 |
-
if ($field_array['size'] == '')
|
87 |
-
$field_array['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
|
88 |
-
|
89 |
-
|
90 |
-
if ($field_array['custom_html'] == '')
|
91 |
-
$field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type);
|
92 |
-
|
93 |
-
$field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field);
|
94 |
-
|
95 |
-
foreach((array)$field->field_options as $k => $v){
|
96 |
-
if(!isset($field_array[$k]))
|
97 |
-
$field_array[$k] = $v;
|
98 |
-
unset($k);
|
99 |
-
unset($v);
|
100 |
-
}
|
101 |
-
|
102 |
-
$values['fields'][] = $field_array;
|
103 |
-
|
104 |
-
if (!$form or !isset($form->id)){
|
105 |
-
$frm_form = new FrmForm();
|
106 |
-
$form = $frm_form->getOne($field->form_id);
|
107 |
-
}
|
108 |
-
}
|
109 |
|
110 |
-
$
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
}
|
115 |
-
|
116 |
-
if (!isset($values['custom_style']))
|
117 |
-
$values['custom_style'] = ($frm_settings->load_style != 'none');
|
118 |
-
|
119 |
-
if (!isset($values['email_to']))
|
120 |
-
$values['email_to'] = '';
|
121 |
|
122 |
-
|
123 |
-
|
124 |
|
125 |
-
|
126 |
-
$values['success_msg'] = $frm_settings->success_msg;
|
127 |
|
128 |
-
if (!isset($
|
129 |
-
$
|
|
|
|
|
130 |
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
141 |
}
|
142 |
-
|
143 |
-
public static function setup_edit_vars($values, $record){
|
144 |
-
|
145 |
-
$values['item_key'] = isset($_POST['item_key']) ? $_POST['item_key'] : $record->item_key;
|
146 |
$values['form_id'] = $record->form_id;
|
147 |
$values['is_draft'] = $record->is_draft;
|
148 |
return apply_filters('frm_setup_edit_entry_vars', $values, $record);
|
149 |
}
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
public static function replace_default_message($message, $atts) {
|
152 |
-
if ( strpos($message, '[default-message') === false &&
|
153 |
-
strpos($message, '[default_message') === false &&
|
154 |
-
!empty($message) ) {
|
155 |
return $message;
|
156 |
}
|
157 |
-
|
158 |
if ( empty($message) ) {
|
159 |
$message = '[default-message]';
|
160 |
}
|
161 |
-
|
162 |
preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER);
|
163 |
-
|
164 |
foreach ( $shortcodes[0] as $short_key => $tag ) {
|
165 |
-
$add_atts = shortcode_parse_atts( $shortcodes[2][$short_key] );
|
166 |
-
if ( $add_atts ){
|
167 |
$this_atts = array_merge($atts, $add_atts);
|
168 |
} else {
|
169 |
$this_atts = $atts;
|
170 |
}
|
171 |
-
|
172 |
$default = FrmEntriesController::show_entry_shortcode($this_atts);
|
173 |
-
|
174 |
// Add the default message
|
175 |
-
$message = str_replace($shortcodes[0][$short_key], $default, $message);
|
176 |
}
|
177 |
|
178 |
return $message;
|
179 |
}
|
180 |
-
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
_deprecated_function( __FUNCTION__, '1.07.09');
|
185 |
}
|
186 |
-
|
187 |
-
public static function enqueue_scripts($params){
|
188 |
do_action('frm_enqueue_form_scripts', $params);
|
189 |
}
|
190 |
-
|
191 |
// Add submitted values to a string for spam checking
|
192 |
public static function entry_array_to_string($values) {
|
193 |
$content = '';
|
@@ -195,14 +661,78 @@ class FrmEntriesHelper{
|
|
195 |
if ( $content != '' ) {
|
196 |
$content .= "\n\n";
|
197 |
}
|
198 |
-
|
199 |
if ( is_array($val) ) {
|
200 |
$val = implode(',', $val);
|
201 |
}
|
202 |
-
|
203 |
$content .= $val;
|
204 |
}
|
205 |
-
|
206 |
return $content;
|
207 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
}
|
1 |
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
5 |
|
6 |
+
class FrmEntriesHelper {
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
public static function setup_new_vars( $fields, $form = '', $reset = false ) {
|
9 |
+
global $frm_vars;
|
10 |
$values = array();
|
11 |
+
foreach ( array( 'name' => '', 'description' => '', 'item_key' => '' ) as $var => $default ) {
|
12 |
+
$values[ $var ] = FrmAppHelper::get_post_param( $var, $default );
|
13 |
+
}
|
14 |
+
|
15 |
$values['fields'] = array();
|
16 |
+
if ( empty($fields) ) {
|
17 |
return apply_filters('frm_setup_new_entry', $values);
|
18 |
}
|
19 |
+
|
20 |
foreach ( (array) $fields as $field ) {
|
|
|
21 |
$default = $field->default_value;
|
22 |
$posted_val = false;
|
23 |
+
$new_value = $default;
|
24 |
+
|
25 |
+
if ( ! $reset && $_POST && isset( $_POST['item_meta'][ $field->id ] ) && $_POST['item_meta'][ $field->id ] != '' ) {
|
26 |
+
$new_value = stripslashes_deep( $_POST['item_meta'][ $field->id ] );
|
|
|
27 |
$posted_val = true;
|
28 |
} else if ( isset($field->field_options['clear_on_focus']) && $field->field_options['clear_on_focus'] ) {
|
29 |
$new_value = '';
|
|
|
|
|
30 |
}
|
31 |
+
|
32 |
$is_default = ($new_value == $default) ? true : false;
|
33 |
+
|
34 |
//If checkbox, multi-select dropdown, or checkbox data from entries field, set return array to true
|
35 |
+
$return_array = FrmFieldsHelper::is_field_with_multiple_values( $field );
|
36 |
+
|
|
|
|
|
|
|
|
|
37 |
$field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true, $return_array);
|
38 |
+
|
39 |
+
if ( ! is_array( $new_value ) ) {
|
40 |
if ( $is_default ) {
|
41 |
$new_value = $field->default_value;
|
42 |
+
} else if ( ! $posted_val ) {
|
43 |
$new_value = apply_filters('frm_filter_default_value', $new_value, $field);
|
44 |
}
|
45 |
+
|
46 |
$new_value = str_replace('"', '"', $new_value);
|
47 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
+
unset($is_default, $posted_val);
|
50 |
+
|
51 |
+
$field_array = array(
|
52 |
+
'id' => $field->id,
|
53 |
+
'value' => $new_value,
|
54 |
+
'default_value' => $field->default_value,
|
55 |
+
'name' => $field->name,
|
56 |
+
'description' => $field->description,
|
57 |
+
'type' => apply_filters('frm_field_type', $field->type, $field, $new_value),
|
58 |
+
'options' => $field->options,
|
59 |
+
'required' => $field->required,
|
60 |
+
'field_key' => $field->field_key,
|
61 |
+
'field_order' => $field->field_order,
|
62 |
+
'form_id' => $field->form_id,
|
63 |
+
);
|
64 |
+
|
65 |
+
$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
|
66 |
+
$opt_defaults['required_indicator'] = '';
|
67 |
+
|
68 |
+
foreach ( $opt_defaults as $opt => $default_opt ) {
|
69 |
+
$field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt;
|
70 |
+
unset($opt, $default_opt);
|
71 |
+
}
|
72 |
+
|
73 |
+
unset($opt_defaults);
|
74 |
+
|
75 |
+
$field_array['size'] = FrmAppHelper::get_field_size($field_array);
|
76 |
+
|
77 |
+
if ( $field_array['custom_html'] == '' ) {
|
78 |
+
$field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type);
|
79 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
+
$field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field);
|
82 |
+
$field_array = array_merge( $field->field_options, $field_array );
|
83 |
|
84 |
+
$values['fields'][] = $field_array;
|
|
|
85 |
|
86 |
+
if ( ! $form || ! isset($form->id) ) {
|
87 |
+
$form = FrmForm::getOne($field->form_id);
|
88 |
+
}
|
89 |
+
}
|
90 |
|
91 |
+
$form->options = maybe_unserialize($form->options);
|
92 |
+
if ( is_array($form->options) ) {
|
93 |
+
foreach ( $form->options as $opt => $value ) {
|
94 |
+
$values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value );
|
95 |
+
unset($opt, $value);
|
96 |
+
}
|
97 |
+
}
|
98 |
|
99 |
+
$form_defaults = FrmFormsHelper::get_default_opts();
|
100 |
+
|
101 |
+
$frm_settings = FrmAppHelper::get_settings();
|
102 |
+
$form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' );
|
103 |
+
|
104 |
+
$values = array_merge( $form_defaults, $values );
|
105 |
+
|
106 |
+
return apply_filters( 'frm_setup_new_entry', $values );
|
107 |
}
|
108 |
+
|
109 |
+
public static function setup_edit_vars($values, $record) {
|
110 |
+
$values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' );
|
|
|
111 |
$values['form_id'] = $record->form_id;
|
112 |
$values['is_draft'] = $record->is_draft;
|
113 |
return apply_filters('frm_setup_edit_entry_vars', $values, $record);
|
114 |
}
|
115 |
+
|
116 |
+
public static function get_admin_params( $form = null ) {
|
117 |
+
$form_id = $form;
|
118 |
+
if ( $form === null ) {
|
119 |
+
$form_id = self::get_current_form_id();
|
120 |
+
} else if ( $form && is_object($form) ) {
|
121 |
+
$form_id = $form->id;
|
122 |
+
}
|
123 |
+
|
124 |
+
$values = array();
|
125 |
+
foreach ( array(
|
126 |
+
'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form_id,
|
127 |
+
'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '',
|
128 |
+
'keep_post' => '',
|
129 |
+
) as $var => $default ) {
|
130 |
+
$values[ $var ] = FrmAppHelper::get_param( $var, $default );
|
131 |
+
}
|
132 |
+
|
133 |
+
return $values;
|
134 |
+
}
|
135 |
+
|
136 |
+
public static function set_current_form($form_id) {
|
137 |
+
global $frm_vars;
|
138 |
+
|
139 |
+
$query = array();
|
140 |
+
if ( $form_id ) {
|
141 |
+
$query['id'] = $form_id;
|
142 |
+
}
|
143 |
+
|
144 |
+
$frm_vars['current_form'] = FrmForm::get_published_forms( $query, 1 );
|
145 |
+
|
146 |
+
return $frm_vars['current_form'];
|
147 |
+
}
|
148 |
+
|
149 |
+
public static function get_current_form($form_id = 0) {
|
150 |
+
global $frm_vars, $wpdb;
|
151 |
+
|
152 |
+
if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
|
153 |
+
return $frm_vars['current_form'];
|
154 |
+
}
|
155 |
+
|
156 |
+
$form_id = (int) FrmAppHelper::get_param('form', $form_id);
|
157 |
+
return self::set_current_form($form_id);
|
158 |
+
}
|
159 |
+
|
160 |
+
public static function get_current_form_id() {
|
161 |
+
$form = self::get_current_form();
|
162 |
+
$form_id = $form ? $form->id : 0;
|
163 |
+
|
164 |
+
return $form_id;
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* If $entry is numeric, get the entry object
|
169 |
+
* @param int|object $entry by reference
|
170 |
+
*
|
171 |
+
*/
|
172 |
+
public static function maybe_get_entry( &$entry ) {
|
173 |
+
if ( $entry && is_numeric($entry) ) {
|
174 |
+
$entry = FrmEntry::getOne($entry);
|
175 |
+
}
|
176 |
+
}
|
177 |
+
|
178 |
+
public static function fill_entry_values($atts, $f, array &$values) {
|
179 |
+
if ( FrmFieldsHelper::is_no_save_field($f->type) ) {
|
180 |
+
return;
|
181 |
+
}
|
182 |
+
|
183 |
+
if ( $atts['default_email'] ) {
|
184 |
+
$values[ $f->id ] = array( 'label' => '['. $f->id .' show=field_label]', 'val' => '['. $f->id .']' );
|
185 |
+
return;
|
186 |
+
}
|
187 |
+
|
188 |
+
//Remove signature from default-message shortcode
|
189 |
+
if ( $f->type == 'signature' ) {
|
190 |
+
return;
|
191 |
+
}
|
192 |
+
|
193 |
+
if ( $atts['entry'] && ! isset( $atts['entry']->metas[ $f->id ] ) ) {
|
194 |
+
// In case include_blank is set
|
195 |
+
$atts['entry']->metas[ $f->id ] = '';
|
196 |
+
|
197 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
198 |
+
// If field is a post field
|
199 |
+
if ( $atts['entry']->post_id && ( $f->type == 'tag' || (isset($f->field_options['post_field']) && $f->field_options['post_field'])) ) {
|
200 |
+
$p_val = FrmProEntryMetaHelper::get_post_value($atts['entry']->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array(
|
201 |
+
'truncate' => (($f->field_options['post_field'] == 'post_category') ? true : false),
|
202 |
+
'form_id' => $atts['entry']->form_id, 'field' => $f, 'type' => $f->type,
|
203 |
+
'exclude_cat' => (isset($f->field_options['exclude_cat']) ? $f->field_options['exclude_cat'] : 0)
|
204 |
+
));
|
205 |
+
if ( $p_val != '' ) {
|
206 |
+
$atts['entry']->metas[ $f->id ] = $p_val;
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
// If field is in a repeating section
|
211 |
+
if ( $atts['entry']->form_id != $f->form_id ) {
|
212 |
+
// get entry ids linked through repeat field or embeded form
|
213 |
+
$child_entries = FrmProEntry::get_sub_entries($atts['entry']->id, true);
|
214 |
+
$val = FrmProEntryMetaHelper::get_sub_meta_values($child_entries, $f);
|
215 |
+
if ( ! empty( $val ) ) {
|
216 |
+
//Flatten multi-dimensional array for multi-file upload field
|
217 |
+
self::flatten_multi_file_upload( $val, $f );
|
218 |
+
$atts['entry']->metas[ $f->id ] = $val;
|
219 |
+
}
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
// Don't include blank values
|
224 |
+
if ( ! $atts['include_blank'] && FrmAppHelper::is_empty_value( $atts['entry']->metas[ $f->id ] ) ) {
|
225 |
+
return;
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
$val = '';
|
230 |
+
if ( $atts['entry'] ) {
|
231 |
+
$prev_val = maybe_unserialize( $atts['entry']->metas[ $f->id ] );
|
232 |
+
$meta = array( 'item_id' => $atts['id'], 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
|
233 |
+
|
234 |
+
//This filter applies to the default-message shortcode and frm-show-entry shortcode only
|
235 |
+
if ( isset($atts['filter']) && $atts['filter'] == false ) {
|
236 |
+
$val = $prev_val;
|
237 |
+
} else {
|
238 |
+
$val = apply_filters('frm_email_value', $prev_val, (object) $meta, $atts['entry']);
|
239 |
+
}
|
240 |
+
}
|
241 |
+
|
242 |
+
self::textarea_display_value( $val, $f->type, $atts['plain_text'] );
|
243 |
+
|
244 |
+
if ( is_array($val) && $atts['format'] == 'text' ) {
|
245 |
+
$val = implode(', ', $val);
|
246 |
+
}
|
247 |
+
|
248 |
+
if ( $atts['format'] != 'text' ) {
|
249 |
+
$values[ $f->field_key ] = $val;
|
250 |
+
} else {
|
251 |
+
$values[ $f->id ] = array( 'label' => $f->name, 'val' => $val );
|
252 |
+
}
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Flatten multi-dimensional array for multi-file upload fields
|
257 |
+
* @since 2.0
|
258 |
+
*/
|
259 |
+
public static function flatten_multi_file_upload( &$val, $field ) {
|
260 |
+
if ( $field->type == 'file' && isset( $field->field_options['multiple'] ) && $field->field_options['multiple'] ) {
|
261 |
+
$val = FrmAppHelper::array_flatten( $val );
|
262 |
+
}
|
263 |
+
}
|
264 |
+
|
265 |
+
/**
|
266 |
+
* Replace returns with HTML line breaks for display
|
267 |
+
* @since 2.0
|
268 |
+
*/
|
269 |
+
public static function textarea_display_value( &$value, $type, $plain_text ) {
|
270 |
+
if ( $type == 'textarea' && ! $plain_text ) {
|
271 |
+
$value = str_replace( array("\r\n", "\r", "\n"), ' <br/>', $value);
|
272 |
+
}
|
273 |
+
}
|
274 |
+
|
275 |
+
public static function fill_entry_user_info($atts, array &$values) {
|
276 |
+
if ( ! $atts['user_info'] ) {
|
277 |
+
return;
|
278 |
+
}
|
279 |
+
|
280 |
+
if ( isset($atts['entry']->description) ) {
|
281 |
+
$data = maybe_unserialize($atts['entry']->description);
|
282 |
+
} else if ( $atts['default_email'] ) {
|
283 |
+
$atts['entry']->ip = '[ip]';
|
284 |
+
$data = array(
|
285 |
+
'browser' => '[browser]',
|
286 |
+
'referrer' => '[referrer]',
|
287 |
+
);
|
288 |
+
} else {
|
289 |
+
$data = array(
|
290 |
+
'browser' => '',
|
291 |
+
'referrer' => '',
|
292 |
+
);
|
293 |
+
}
|
294 |
+
|
295 |
+
if ( $atts['format'] != 'text' ) {
|
296 |
+
$values['ip'] = $atts['entry']->ip;
|
297 |
+
$values['browser'] = self::get_browser($data['browser']);
|
298 |
+
$values['referrer'] = $data['referrer'];
|
299 |
+
} else {
|
300 |
+
//$content .= "\r\n\r\n" . __( 'User Information', 'formidable' ) ."\r\n";
|
301 |
+
$values['ip'] = array( 'label' => __( 'IP Address', 'formidable' ), 'val' => $atts['entry']->ip);
|
302 |
+
$values['browser'] = array(
|
303 |
+
'label' => __( 'User-Agent (Browser/OS)', 'formidable' ),
|
304 |
+
'val' => self::get_browser($data['browser']),
|
305 |
+
);
|
306 |
+
$values['referrer'] = array( 'label' => __( 'Referrer', 'formidable' ), 'val' => $data['referrer']);
|
307 |
+
}
|
308 |
+
}
|
309 |
+
|
310 |
+
public static function convert_entry_to_content($values, $atts, array &$content) {
|
311 |
+
|
312 |
+
if ( $atts['plain_text'] ) {
|
313 |
+
$bg_color_alt = $row_style = '';
|
314 |
+
} else {
|
315 |
+
$default_settings = apply_filters('frm_show_entry_styles', array(
|
316 |
+
'border_color' => 'dddddd',
|
317 |
+
'bg_color' => 'f7f7f7',
|
318 |
+
'text_color' => '444444',
|
319 |
+
'font_size' => '12px',
|
320 |
+
'border_width' => '1px',
|
321 |
+
'alt_bg_color' => 'ffffff',
|
322 |
+
) );
|
323 |
+
|
324 |
+
// merge defaults, global settings, and shortcode options
|
325 |
+
foreach ( $default_settings as $key => $setting ) {
|
326 |
+
if ( $atts[ $key ] != '' ) {
|
327 |
+
continue;
|
328 |
+
}
|
329 |
+
|
330 |
+
$atts[ $key ] = $setting;
|
331 |
+
unset($key, $setting);
|
332 |
+
}
|
333 |
+
|
334 |
+
unset($default_settings);
|
335 |
+
|
336 |
+
$content[] = '<table cellspacing="0" style="font-size:'. $atts['font_size'] .';line-height:135%; border-bottom:'. $atts['border_width'] .' solid #'. $atts['border_color'] .';"><tbody>'."\r\n";
|
337 |
+
$atts['bg_color'] = ' style="background-color:#'. $atts['bg_color'] .';"';
|
338 |
+
$bg_color_alt = ' style="background-color:#'. $atts['alt_bg_color'] .';"';
|
339 |
+
$row_style = 'style="text-align:'. ( $atts['direction'] == 'rtl' ? 'right' : 'left' ) .';color:#'. $atts['text_color'] .';padding:7px 9px;border-top:'. $atts['border_width'] .' solid #'. $atts['border_color'] .'"';
|
340 |
+
}
|
341 |
+
|
342 |
+
$odd = true;
|
343 |
+
foreach ( $values as $id => $value ) {
|
344 |
+
if ( $atts['plain_text'] ) {
|
345 |
+
if ( 'rtl' == $atts['direction'] ) {
|
346 |
+
$content[] = $value['val'] . ' :'. $value['label'] ."\r\n";
|
347 |
+
} else {
|
348 |
+
$content[] = $value['label'] . ': '. $value['val'] ."\r\n";
|
349 |
+
}
|
350 |
+
continue;
|
351 |
+
}
|
352 |
+
|
353 |
+
if ( $atts['default_email'] && is_numeric($id) ) {
|
354 |
+
$content[] = '[if '. $id .']<tr style="[frm-alt-color]">';
|
355 |
+
} else {
|
356 |
+
$content[] = '<tr'. ( $odd ? $atts['bg_color'] : $bg_color_alt ) .'>';
|
357 |
+
}
|
358 |
+
|
359 |
+
if ( 'rtl' == $atts['direction'] ) {
|
360 |
+
$content[] = '<td '. $row_style .'>'. $value['val'] .'</td><th '. $row_style .'>'. $value['label'] . '</th>';
|
361 |
+
} else {
|
362 |
+
$content[] = '<th '. $row_style .'>'. $value['label'] .'</th><td '. $row_style .'>'. $value['val'] .'</td>';
|
363 |
+
}
|
364 |
+
$content[] = '</tr>'. "\r\n";
|
365 |
+
|
366 |
+
if ( $atts['default_email'] && is_numeric($id) ) {
|
367 |
+
$content[] = '[/if '. $id .']';
|
368 |
+
}
|
369 |
+
$odd = $odd ? false : true;
|
370 |
+
}
|
371 |
+
|
372 |
+
if ( ! $atts['plain_text'] ) {
|
373 |
+
$content[] = '</tbody></table>';
|
374 |
+
}
|
375 |
+
}
|
376 |
+
|
377 |
public static function replace_default_message($message, $atts) {
|
378 |
+
if ( strpos($message, '[default-message') === false &&
|
379 |
+
strpos($message, '[default_message') === false &&
|
380 |
+
! empty( $message ) ) {
|
381 |
return $message;
|
382 |
}
|
383 |
+
|
384 |
if ( empty($message) ) {
|
385 |
$message = '[default-message]';
|
386 |
}
|
387 |
+
|
388 |
preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER);
|
389 |
+
|
390 |
foreach ( $shortcodes[0] as $short_key => $tag ) {
|
391 |
+
$add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] );
|
392 |
+
if ( $add_atts ) {
|
393 |
$this_atts = array_merge($atts, $add_atts);
|
394 |
} else {
|
395 |
$this_atts = $atts;
|
396 |
}
|
397 |
+
|
398 |
$default = FrmEntriesController::show_entry_shortcode($this_atts);
|
399 |
+
|
400 |
// Add the default message
|
401 |
+
$message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
|
402 |
}
|
403 |
|
404 |
return $message;
|
405 |
}
|
|
|
406 |
|
407 |
+
public static function prepare_display_value($entry, $field, $atts) {
|
408 |
+
$field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
|
409 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
410 |
+
FrmProEntriesHelper::get_dfe_values($field, $entry, $field_value);
|
411 |
+
}
|
412 |
+
|
413 |
+
if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) {
|
414 |
+
return self::display_value($field_value, $field, $atts);
|
415 |
+
}
|
416 |
+
|
417 |
+
// this is an embeded form
|
418 |
+
$val = '';
|
419 |
+
|
420 |
+
if ( strpos($atts['embedded_field_id'], 'form') === 0 ) {
|
421 |
+
//this is a repeating section
|
422 |
+
$child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id) );
|
423 |
+
} else {
|
424 |
+
// get all values for this field
|
425 |
+
$child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
|
426 |
+
|
427 |
+
if ( $child_values ) {
|
428 |
+
$child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
|
429 |
+
//$atts['post_id']
|
430 |
+
}
|
431 |
+
}
|
432 |
+
|
433 |
+
$field_value = array();
|
434 |
+
|
435 |
+
if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) {
|
436 |
+
return $val;
|
437 |
+
}
|
438 |
+
|
439 |
+
foreach ( $child_entries as $child_entry ) {
|
440 |
+
$atts['item_id'] = $child_entry->id;
|
441 |
+
$atts['post_id'] = $child_entry->post_id;
|
442 |
+
|
443 |
+
// get the value for this field -- check for post values as well
|
444 |
+
$entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field);
|
445 |
+
|
446 |
+
if ( $entry_val ) {
|
447 |
+
// foreach entry get display_value
|
448 |
+
$field_value[] = self::display_value($entry_val, $field, $atts);
|
449 |
+
}
|
450 |
+
|
451 |
+
unset($child_entry);
|
452 |
+
}
|
453 |
+
|
454 |
+
$val = implode(', ', (array) $field_value );
|
455 |
+
|
456 |
+
return $val;
|
457 |
+
}
|
458 |
+
|
459 |
+
/**
|
460 |
+
* Prepare the saved value for display
|
461 |
+
* @return string
|
462 |
+
*/
|
463 |
+
public static function display_value($value, $field, $atts = array()) {
|
464 |
+
|
465 |
+
$defaults = array(
|
466 |
+
'type' => '', 'html' => false, 'show_filename' => true,
|
467 |
+
'truncate' => false, 'sep' => ', ', 'post_id' => 0,
|
468 |
+
'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0,
|
469 |
+
);
|
470 |
+
|
471 |
+
$atts = wp_parse_args( $atts, $defaults );
|
472 |
+
$atts = apply_filters('frm_display_value_atts', $atts, $field, $value);
|
473 |
+
|
474 |
+
if ( ! isset($field->field_options['post_field']) ) {
|
475 |
+
$field->field_options['post_field'] = '';
|
476 |
+
}
|
477 |
+
|
478 |
+
if ( ! isset($field->field_options['custom_field']) ) {
|
479 |
+
$field->field_options['custom_field'] = '';
|
480 |
+
}
|
481 |
+
|
482 |
+
if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
|
483 |
+
$atts['pre_truncate'] = $atts['truncate'];
|
484 |
+
$atts['truncate'] = true;
|
485 |
+
$atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0;
|
486 |
+
|
487 |
+
$value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts);
|
488 |
+
$atts['truncate'] = $atts['pre_truncate'];
|
489 |
+
}
|
490 |
+
|
491 |
+
if ( $value == '' ) {
|
492 |
+
return $value;
|
493 |
+
}
|
494 |
+
|
495 |
+
$value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts);
|
496 |
+
|
497 |
+
$new_value = '';
|
498 |
+
|
499 |
+
if ( is_array($value) && $atts['type'] != 'file' ) {
|
500 |
+
foreach ( $value as $val ) {
|
501 |
+
if ( is_array($val) ) {
|
502 |
+
//TODO: add options for display (li or ,)
|
503 |
+
$new_value .= implode($atts['sep'], $val);
|
504 |
+
if ( $atts['type'] != 'data' ) {
|
505 |
+
$new_value .= '<br/>';
|
506 |
+
}
|
507 |
+
}
|
508 |
+
unset($val);
|
509 |
+
}
|
510 |
+
}
|
511 |
+
|
512 |
+
if ( ! empty($new_value) ) {
|
513 |
+
$value = $new_value;
|
514 |
+
} else if ( is_array($value) && $atts['type'] != 'file' ) {
|
515 |
+
$value = implode($atts['sep'], $value);
|
516 |
+
}
|
517 |
+
|
518 |
+
if ( $atts['truncate'] && $atts['type'] != 'image' ) {
|
519 |
+
$value = FrmAppHelper::truncate($value, 50);
|
520 |
+
}
|
521 |
|
522 |
+
return apply_filters('frm_display_value', $value, $field, $atts);
|
523 |
+
}
|
524 |
+
|
525 |
+
public static function set_posted_value($field, $value, $args) {
|
526 |
+
// If validating a field with "other" opt, set back to prev value now
|
527 |
+
if ( isset( $args['other'] ) && $args['other'] ) {
|
528 |
+
$value = $args['temp_value'];
|
529 |
+
}
|
530 |
+
if ( empty($args['parent_field_id']) ) {
|
531 |
+
$_POST['item_meta'][ $field->id ] = $value;
|
532 |
+
} else {
|
533 |
+
$_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value;
|
534 |
+
}
|
535 |
+
}
|
536 |
+
|
537 |
+
public static function get_posted_value($field, &$value, $args) {
|
538 |
+
$field_id = is_object( $field ) ? $field->id : $field;
|
539 |
+
|
540 |
+
if ( empty($args['parent_field_id']) ) {
|
541 |
+
$value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : '';
|
542 |
+
} else {
|
543 |
+
$value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : '';
|
544 |
+
}
|
545 |
+
}
|
546 |
+
|
547 |
+
/**
|
548 |
+
* Check if field has an "Other" option and if any other values are posted
|
549 |
+
*
|
550 |
+
* @since 2.0
|
551 |
+
*
|
552 |
+
* @param object $field
|
553 |
+
* @param string|array $value
|
554 |
+
* @param array $args
|
555 |
+
*/
|
556 |
+
public static function maybe_set_other_validation( $field, &$value, &$args ) {
|
557 |
+
$args['other'] = false;
|
558 |
+
if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) {
|
559 |
+
return;
|
560 |
+
}
|
561 |
+
|
562 |
+
// Get other value for fields in repeating section
|
563 |
+
self::set_other_repeating_vals( $field, $value, $args );
|
564 |
+
|
565 |
+
// Check if there are any posted "Other" values
|
566 |
+
if ( isset( $field->field_options['other'] ) && $field->field_options['other'] && isset( $_POST['item_meta']['other'][ $field->id ] ) ) {
|
567 |
+
|
568 |
+
// Save original value
|
569 |
+
$args['temp_value'] = $value;
|
570 |
+
$args['other'] = true;
|
571 |
+
$other_vals = $_POST['item_meta']['other'][ $field->id ];
|
572 |
+
|
573 |
+
// Set the validation value now
|
574 |
+
self::set_other_validation_val( $value, $other_vals, $field, $args );
|
575 |
+
}
|
576 |
+
}
|
577 |
+
|
578 |
+
/**
|
579 |
+
* Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
|
580 |
+
*
|
581 |
+
* @since 2.0
|
582 |
+
*
|
583 |
+
* @param object $field
|
584 |
+
* @param string|array $value
|
585 |
+
* @param array $args
|
586 |
+
*/
|
587 |
+
public static function set_other_repeating_vals( $field, &$value, &$args ) {
|
588 |
+
if ( ! $args['parent_field_id'] ) {
|
589 |
+
return;
|
590 |
+
}
|
591 |
+
|
592 |
+
// Check if there are any other posted "other" values for this field
|
593 |
+
if ( isset( $field->field_options['other'] ) && $field->field_options['other'] && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) {
|
594 |
+
// Save original value
|
595 |
+
$args['temp_value'] = $value;
|
596 |
+
$args['other'] = true;
|
597 |
+
|
598 |
+
$other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ];
|
599 |
+
|
600 |
+
// Set the validation value now
|
601 |
+
self::set_other_validation_val( $value, $other_vals, $field, $args );
|
602 |
+
}
|
603 |
+
}
|
604 |
+
|
605 |
+
/**
|
606 |
+
* Modify value used for validation
|
607 |
+
* This function essentially removes the "Other" radio or checkbox value from the $value being validated.
|
608 |
+
* It also adds any text from the free text fields to the value
|
609 |
+
*
|
610 |
+
* Needs to accommodate for times when other opt is selected, but no other free text is entered
|
611 |
+
*
|
612 |
+
* @since 2.0
|
613 |
+
*
|
614 |
+
* @param string|array $value
|
615 |
+
* @param string|array $other_vals (usually of posted values)
|
616 |
+
* @param object $field
|
617 |
+
* @param array $args
|
618 |
+
*/
|
619 |
+
public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
|
620 |
+
// Checkboxes and multi-select dropdowns
|
621 |
+
if ( is_array( $value ) && $field->type == 'checkbox' ) {
|
622 |
+
// Combine "Other" values with checked values. "Other" values will override checked box values.
|
623 |
+
$value = array_merge( $value, $other_vals );
|
624 |
+
$value = array_filter( $value );
|
625 |
+
if ( count( $value ) == 0 ) {
|
626 |
+
$value = '';
|
627 |
+
}
|
628 |
+
} else {
|
629 |
+
// Radio and dropdowns
|
630 |
+
$other_key = array_filter( array_keys($field->options), 'is_string');
|
631 |
+
$other_key = reset( $other_key );
|
632 |
+
|
633 |
+
// Multi-select dropdown
|
634 |
+
if ( is_array( $value ) ) {
|
635 |
+
$o_key = array_search( $field->options[ $other_key ], $value );
|
636 |
+
if ( $o_key ) {
|
637 |
+
// Modify original value so key is preserved
|
638 |
+
$value[ $other_key ] = $value[ $o_key ];
|
639 |
+
unset( $value[ $o_key ] );
|
640 |
+
$args['temp_value'] = $value;
|
641 |
+
$value[ $other_key ] = reset( $other_vals );
|
642 |
+
}
|
643 |
+
} else if ( $field->options[ $other_key ] == $value ) {
|
644 |
+
$value = $other_vals;
|
645 |
+
}
|
646 |
+
}
|
647 |
+
}
|
648 |
+
|
649 |
+
public static function entries_dropdown() {
|
650 |
_deprecated_function( __FUNCTION__, '1.07.09');
|
651 |
}
|
652 |
+
|
653 |
+
public static function enqueue_scripts($params) {
|
654 |
do_action('frm_enqueue_form_scripts', $params);
|
655 |
}
|
656 |
+
|
657 |
// Add submitted values to a string for spam checking
|
658 |
public static function entry_array_to_string($values) {
|
659 |
$content = '';
|
661 |
if ( $content != '' ) {
|
662 |
$content .= "\n\n";
|
663 |
}
|
664 |
+
|
665 |
if ( is_array($val) ) {
|
666 |
$val = implode(',', $val);
|
667 |
}
|
668 |
+
|
669 |
$content .= $val;
|
670 |
}
|
671 |
+
|
672 |
return $content;
|
673 |
}
|
674 |
+
|
675 |
+
public static function get_browser($u_agent) {
|
676 |
+
$bname = __( 'Unknown', 'formidable' );
|
677 |
+
$platform = __( 'Unknown', 'formidable' );
|
678 |
+
$ub = '';
|
679 |
+
|
680 |
+
//First get the platform?
|
681 |
+
if ( preg_match('/linux/i', $u_agent) ) {
|
682 |
+
$platform = 'Linux';
|
683 |
+
} else if ( preg_match('/macintosh|mac os x/i', $u_agent) ) {
|
684 |
+
$platform = 'Mac';
|
685 |
+
} else if ( preg_match('/windows|win32/i', $u_agent) ) {
|
686 |
+
$platform = 'Windows';
|
687 |
+
}
|
688 |
+
|
689 |
+
$agent_options = array(
|
690 |
+
'Firefox' => 'Mozilla Firefox',
|
691 |
+
'Chrome' => 'Google Chrome',
|
692 |
+
'Safari' => 'Apple Safari',
|
693 |
+
'Opera' => 'Opera',
|
694 |
+
'Netscape' => 'Netscape',
|
695 |
+
);
|
696 |
+
|
697 |
+
// Next get the name of the useragent yes seperately and for good reason
|
698 |
+
if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) {
|
699 |
+
$bname = 'Internet Explorer';
|
700 |
+
$ub = 'MSIE';
|
701 |
+
} else {
|
702 |
+
foreach ( $agent_options as $agent_key => $agent_name ) {
|
703 |
+
if ( strpos( $u_agent, $agent_key ) !== false ) {
|
704 |
+
$bname = $agent_name;
|
705 |
+
$ub = $agent_key;
|
706 |
+
break;
|
707 |
+
}
|
708 |
+
}
|
709 |
+
}
|
710 |
+
|
711 |
+
// finally get the correct version number
|
712 |
+
$known = array( 'Version', $ub, 'other');
|
713 |
+
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
|
714 |
+
preg_match_all($pattern, $u_agent, $matches); // get the matching numbers
|
715 |
+
|
716 |
+
// see how many we have
|
717 |
+
$i = count($matches['browser']);
|
718 |
+
if ( $i != 1 ) {
|
719 |
+
//we will have two since we are not using 'other' argument yet
|
720 |
+
//see if version is before or after the name
|
721 |
+
if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) {
|
722 |
+
$version = $matches['version'][0];
|
723 |
+
} else {
|
724 |
+
$version = $matches['version'][1];
|
725 |
+
}
|
726 |
+
} else {
|
727 |
+
$version = $matches['version'][0];
|
728 |
+
}
|
729 |
+
|
730 |
+
// check if we have a number
|
731 |
+
if ( $version == '') {
|
732 |
+
$version = '?';
|
733 |
+
}
|
734 |
+
|
735 |
+
return $bname .' '. $version .' / '. $platform;
|
736 |
+
}
|
737 |
+
|
738 |
}
|
classes/helpers/FrmEntriesListHelper.php
ADDED
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class FrmEntriesListHelper extends FrmListHelper {
|
4 |
+
|
5 |
+
public function prepare_items() {
|
6 |
+
global $wpdb, $per_page;
|
7 |
+
|
8 |
+
$per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page');
|
9 |
+
|
10 |
+
$form_id = $this->params['form'];
|
11 |
+
if ( ! $form_id ) {
|
12 |
+
$this->items = array();
|
13 |
+
$this->set_pagination_args( array(
|
14 |
+
'total_items' => 0,
|
15 |
+
'per_page' => $per_page,
|
16 |
+
) );
|
17 |
+
return;
|
18 |
+
}
|
19 |
+
|
20 |
+
$default_orderby = 'id';
|
21 |
+
$default_order = 'DESC';
|
22 |
+
|
23 |
+
$s_query = array( 'it.form_id' => $form_id );
|
24 |
+
|
25 |
+
$s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
|
26 |
+
|
27 |
+
if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
|
28 |
+
$fid = isset( $_REQUEST['fid'] ) ? sanitize_text_field( $_REQUEST['fid'] ) : '';
|
29 |
+
$s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid);
|
30 |
+
}
|
31 |
+
|
32 |
+
$orderby = isset( $_REQUEST['orderby'] ) ? sanitize_title( $_REQUEST['orderby'] ) : $default_orderby;
|
33 |
+
if ( strpos($orderby, 'meta') !== false ) {
|
34 |
+
$order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
|
35 |
+
$orderby .= in_array( $order_field_type, array( 'number', 'scale') ) ? ' +0 ' : '';
|
36 |
+
}
|
37 |
+
|
38 |
+
$order = isset( $_REQUEST['order'] ) ? sanitize_title( $_REQUEST['order'] ) : $default_order;
|
39 |
+
$order = ' ORDER BY ' . $orderby . ' ' . $order;
|
40 |
+
|
41 |
+
$page = $this->get_pagenum();
|
42 |
+
$start = (int) isset( $_REQUEST['start'] ) ? absint( $_REQUEST['start'] ) : ( ( $page - 1 ) * $per_page );
|
43 |
+
|
44 |
+
$this->items = FrmEntry::getAll($s_query, $order, ' LIMIT '. $start .','. $per_page, true, false);
|
45 |
+
$total_items = FrmEntry::getRecordCount($s_query);
|
46 |
+
|
47 |
+
$this->set_pagination_args( array(
|
48 |
+
'total_items' => $total_items,
|
49 |
+
'per_page' => $per_page,
|
50 |
+
) );
|
51 |
+
}
|
52 |
+
|
53 |
+
public function no_items() {
|
54 |
+
$s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
|
55 |
+
if ( ! empty($s) ) {
|
56 |
+
_e( 'No Entries Found', 'formidable' );
|
57 |
+
return;
|
58 |
+
}
|
59 |
+
|
60 |
+
$form_id = $form = $this->params['form'];
|
61 |
+
if ( $form_id ) {
|
62 |
+
$form = FrmForm::getOne($form_id);
|
63 |
+
}
|
64 |
+
$colspan = $this->get_column_count();
|
65 |
+
|
66 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/no_entries.php');
|
67 |
+
}
|
68 |
+
|
69 |
+
public function search_box( $text, $input_id ) {
|
70 |
+
if ( ! $this->has_items() && ! isset( $_REQUEST['s'] ) ) {
|
71 |
+
return;
|
72 |
+
}
|
73 |
+
|
74 |
+
if ( isset($this->params['form']) ) {
|
75 |
+
$form = FrmForm::getOne($this->params['form']);
|
76 |
+
} else {
|
77 |
+
$form = FrmForm::get_published_forms( array(), 1 );
|
78 |
+
}
|
79 |
+
|
80 |
+
if ( $form ) {
|
81 |
+
$field_list = FrmField::getAll( array( 'fi.form_id' => $form->id, 'fi.type not' => FrmFieldsHelper::no_save_fields() ), 'field_order');
|
82 |
+
}
|
83 |
+
|
84 |
+
$fid = isset($_REQUEST['fid']) ? esc_attr( stripslashes( $_REQUEST['fid'] ) ) : '';
|
85 |
+
$input_id = $input_id . '-search-input';
|
86 |
+
$search_str = isset($_REQUEST['s']) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '';
|
87 |
+
|
88 |
+
foreach ( array( 'orderby', 'order') as $get_var ) {
|
89 |
+
if ( ! empty( $_REQUEST[ $get_var ] ) ) {
|
90 |
+
echo '<input type="hidden" name="'. esc_attr( $get_var ) .'" value="' . esc_attr( $_REQUEST[ $get_var ] ) . '" />';
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
?>
|
95 |
+
<div class="search-box frm_sidebar">
|
96 |
+
<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ) ?>"><?php echo esc_attr( $text ); ?>:</label>
|
97 |
+
<input type="text" id="<?php echo esc_attr( $input_id ) ?>" name="s" value="<?php echo esc_attr( $search_str ); ?>" />
|
98 |
+
<?php
|
99 |
+
if ( isset( $field_list ) && ! empty( $field_list ) ) { ?>
|
100 |
+
<select name="fid" class="hide-if-js">
|
101 |
+
<option value="">— <?php _e( 'All Fields', 'formidable' ) ?> —</option>
|
102 |
+
<option value="created_at" <?php selected($fid, 'created_at') ?>><?php _e( 'Entry creation date', 'formidable' ) ?></option>
|
103 |
+
<option value="id" <?php selected($fid, 'id') ?>><?php _e( 'Entry ID', 'formidable' ) ?></option>
|
104 |
+
<?php foreach ( $field_list as $f ) { ?>
|
105 |
+
<option value="<?php echo ($f->type == 'user_id') ? 'user_id' : $f->id ?>" <?php selected($fid, $f->id) ?>><?php echo FrmAppHelper::truncate($f->name, 30); ?></option>
|
106 |
+
<?php } ?>
|
107 |
+
</select>
|
108 |
+
|
109 |
+
<div class="button dropdown hide-if-no-js">
|
110 |
+
<a href="#" id="frm-fid-search" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e( 'Search', 'formidable' ) ?> <b class="caret"></b></a>
|
111 |
+
<ul class="frm-dropdown-menu pull-right" id="frm-fid-search-menu" role="menu" aria-labelledby="frm-fid-search">
|
112 |
+
<li><a href="#" id="fid-">— <?php _e( 'All Fields', 'formidable' ) ?> —</a></li>
|
113 |
+
<li><a href="#" id="fid-created_at"><?php _e( 'Entry creation date', 'formidable' ) ?></a></li>
|
114 |
+
<li><a href="#" id="fid-id"><?php _e( 'Entry ID', 'formidable' ) ?></a></li>
|
115 |
+
<?php
|
116 |
+
foreach ( $field_list as $f ) { ?>
|
117 |
+
<li><a href="#" id="fid-<?php echo ($f->type == 'user_id') ? 'user_id' : $f->id ?>"><?php echo FrmAppHelper::truncate($f->name, 30); ?></a></li>
|
118 |
+
<?php
|
119 |
+
unset($f);
|
120 |
+
} ?>
|
121 |
+
</ul>
|
122 |
+
</div>
|
123 |
+
<?php submit_button( $text, 'button hide-if-js', false, false, array( 'id' => 'search-submit') );
|
124 |
+
} else {
|
125 |
+
submit_button( $text, 'button', false, false, array( 'id' => 'search-submit') );
|
126 |
+
if ( ! empty( $search_str ) ) { ?>
|
127 |
+
<a href="<?php echo admin_url('admin.php?page=formidable-entries&frm_action=list&form='.$form->id) ?>"><?php _e( 'Reset', 'formidable' ) ?></a>
|
128 |
+
<?php
|
129 |
+
}
|
130 |
+
} ?>
|
131 |
+
|
132 |
+
</div>
|
133 |
+
<?php
|
134 |
+
}
|
135 |
+
|
136 |
+
public function single_row( $item, $style = '' ) {
|
137 |
+
// Set up the hover actions for this user
|
138 |
+
$actions = array();
|
139 |
+
$view_link = '?page=formidable-entries&frm_action=show&id='. $item->id;
|
140 |
+
|
141 |
+
$this->get_actions( $actions, $item, $view_link );
|
142 |
+
|
143 |
+
$action_links = $this->row_actions( $actions );
|
144 |
+
|
145 |
+
// Set up the checkbox ( because the user is editable, otherwise its empty )
|
146 |
+
$checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
|
147 |
+
|
148 |
+
$r = "<tr id='item-action-{$item->id}'$style>";
|
149 |
+
|
150 |
+
list( $columns, $hidden ) = $this->get_column_info();
|
151 |
+
$action_col = false;
|
152 |
+
|
153 |
+
foreach ( $columns as $column_name => $column_display_name ) {
|
154 |
+
$class = $column_name .' column-'. $column_name;
|
155 |
+
|
156 |
+
if ( in_array( $column_name, $hidden ) ) {
|
157 |
+
$class .= ' frm_hidden';
|
158 |
+
} else if ( ! $action_col && ! in_array($column_name, array( 'cb', 'id', 'form_id', 'post_id')) ) {
|
159 |
+
$action_col = $column_name;
|
160 |
+
}
|
161 |
+
|
162 |
+
$attributes = 'class="'. $class .'"';
|
163 |
+
unset($class);
|
164 |
+
|
165 |
+
$col_name = preg_replace('/^('. $this->params['form'] .'_)/', '', $column_name);
|
166 |
+
|
167 |
+
switch ( $col_name ) {
|
168 |
+
case 'cb':
|
169 |
+
$r .= "<th scope='row' class='check-column'>$checkbox</th>";
|
170 |
+
break;
|
171 |
+
case 'ip':
|
172 |
+
case 'id':
|
173 |
+
case 'item_key':
|
174 |
+
$val = $item->{$col_name};
|
175 |
+
break;
|
176 |
+
case 'name':
|
177 |
+
case 'description':
|
178 |
+
$val = FrmAppHelper::truncate(strip_tags($item->{$col_name}), 100);
|
179 |
+
break;
|
180 |
+
case 'created_at':
|
181 |
+
case 'updated_at':
|
182 |
+
$date = FrmAppHelper::get_formatted_time($item->{$col_name});
|
183 |
+
$val = '<abbr title="' . FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) . '">' . $date . '</abbr>';
|
184 |
+
break;
|
185 |
+
case 'is_draft':
|
186 |
+
$val = empty($item->is_draft) ? __( 'No') : __( 'Yes');
|
187 |
+
break;
|
188 |
+
case 'form_id':
|
189 |
+
$val = FrmFormsHelper::edit_form_link($item->form_id);
|
190 |
+
break;
|
191 |
+
case 'post_id':
|
192 |
+
$val = FrmAppHelper::post_edit_link($item->post_id);
|
193 |
+
break;
|
194 |
+
case 'user_id':
|
195 |
+
$user = get_userdata($item->user_id);
|
196 |
+
$val = $user->user_login;
|
197 |
+
break;
|
198 |
+
default:
|
199 |
+
if ( strpos($col_name, 'frmsep_') === 0 ) {
|
200 |
+
$sep_val = true;
|
201 |
+
$col_name = str_replace('frmsep_', '', $col_name);
|
202 |
+
} else {
|
203 |
+
$sep_val = false;
|
204 |
+
}
|
205 |
+
|
206 |
+
if ( strpos($col_name, '-_-') ) {
|
207 |
+
list($col_name, $embedded_field_id) = explode('-_-', $col_name);
|
208 |
+
}
|
209 |
+
|
210 |
+
$col = FrmField::getOne($col_name);
|
211 |
+
|
212 |
+
$atts = array(
|
213 |
+
'type' => $col->type, 'truncate' => true,
|
214 |
+
'post_id' => $item->post_id, 'entry_id' => $item->id,
|
215 |
+
'embedded_field_id' => 0,
|
216 |
+
);
|
217 |
+
|
218 |
+
if ( $sep_val ) {
|
219 |
+
$atts['saved_value'] = true;
|
220 |
+
}
|
221 |
+
|
222 |
+
if ( isset($embedded_field_id) ) {
|
223 |
+
$atts['embedded_field_id'] = $embedded_field_id;
|
224 |
+
unset($embedded_field_id);
|
225 |
+
}
|
226 |
+
|
227 |
+
$val = FrmEntriesHelper::prepare_display_value($item, $col, $atts);
|
228 |
+
|
229 |
+
break;
|
230 |
+
}
|
231 |
+
|
232 |
+
if ( isset( $val ) ) {
|
233 |
+
$r .= "<td $attributes>";
|
234 |
+
if ( $column_name == $action_col ) {
|
235 |
+
$edit_link = '?page=formidable-entries&frm_action=edit&id='. $item->id;
|
236 |
+
$r .= '<a href="'. (isset($actions['edit']) ? $edit_link : $view_link) .'" class="row-title" >'. $val .'</a> ';
|
237 |
+
$r .= $action_links;
|
238 |
+
} else {
|
239 |
+
$r .= $val;
|
240 |
+
}
|
241 |
+
$r .= '</td>';
|
242 |
+
}
|
243 |
+
unset($val);
|
244 |
+
}
|
245 |
+
$r .= '</tr>';
|
246 |
+
|
247 |
+
return $r;
|
248 |
+
}
|
249 |
+
|
250 |
+
/**
|
251 |
+
* @param string $view_link
|
252 |
+
*/
|
253 |
+
private function get_actions( &$actions, $item, $view_link ) {
|
254 |
+
$actions['view'] = '<a href="' . esc_url( $view_link ) . '">'. __( 'View', 'formidable' ) .'</a>';
|
255 |
+
|
256 |
+
if ( current_user_can('frm_delete_entries') ) {
|
257 |
+
$delete_link = '?page=formidable-entries&frm_action=destroy&id='. $item->id .'&form='. $this->params['form'];
|
258 |
+
$actions['delete'] = '<a href="' . wp_nonce_url( $delete_link ) . '" class="submitdelete" onclick="return confirm(\''. __( 'Are you sure you want to delete that?', 'formidable' ) .'\')">' . __( 'Delete' ) . '</a>';
|
259 |
+
}
|
260 |
+
|
261 |
+
$actions = apply_filters('frm_row_actions', $actions, $item);
|
262 |
+
}
|
263 |
+
|
264 |
+
}
|
classes/helpers/FrmFieldsHelper.php
CHANGED
@@ -1,195 +1,296 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
if(class_exists('FrmFieldsHelper'))
|
6 |
-
return;
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
public static function field_selection(){
|
11 |
$fields = apply_filters('frm_available_fields', array(
|
12 |
-
'text'
|
13 |
-
'textarea'
|
14 |
-
'checkbox'
|
15 |
-
'radio'
|
16 |
-
'select'
|
17 |
-
'
|
|
|
|
|
18 |
));
|
19 |
-
|
20 |
return $fields;
|
21 |
}
|
22 |
-
|
23 |
-
public static function pro_field_selection(){
|
24 |
return apply_filters('frm_pro_available_fields', array(
|
25 |
-
'
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
'
|
30 |
-
'
|
31 |
-
'
|
32 |
-
'
|
33 |
-
'
|
34 |
-
'
|
35 |
-
'
|
36 |
-
'
|
37 |
-
|
38 |
-
'
|
39 |
-
|
40 |
-
'
|
41 |
-
'
|
42 |
-
'
|
43 |
-
'
|
44 |
-
'
|
45 |
-
|
46 |
-
//'
|
47 |
-
//'
|
48 |
-
//'
|
|
|
49 |
));
|
50 |
}
|
51 |
-
|
52 |
-
public static function
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
$values = array();
|
59 |
-
|
60 |
-
foreach ($defaults as $var => $default){
|
61 |
-
if($var == 'field_options'){
|
62 |
$values['field_options'] = array();
|
63 |
-
foreach ($default as $opt_var => $opt_default){
|
64 |
-
$values['field_options'][$opt_var] = $opt_default;
|
65 |
-
unset($opt_var);
|
66 |
-
unset($opt_default);
|
67 |
}
|
68 |
-
}else{
|
69 |
-
$values[$var] = $default;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
80 |
$values['field_options']['max'] = '5';
|
81 |
-
else if ($type == 'captcha')
|
|
|
82 |
$values['invalid'] = $frm_settings->re_msg;
|
83 |
-
|
|
|
|
|
|
|
84 |
$fields = self::field_selection();
|
85 |
$fields = array_merge($fields, self::pro_field_selection());
|
86 |
|
87 |
-
if(isset($fields[$type]))
|
88 |
-
$values['name'] = $fields[$type];
|
|
|
89 |
|
90 |
unset($fields);
|
91 |
-
|
92 |
return $values;
|
93 |
}
|
94 |
-
|
95 |
-
public static function
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
100 |
$default_opts = array(
|
101 |
-
'field_key' => $record->field_key, 'type' => $record->type,
|
102 |
-
'default_value'=> $record->default_value, 'field_order' => $record->field_order,
|
103 |
-
'required' => $record->required
|
104 |
);
|
105 |
-
|
106 |
-
|
107 |
$values = $values + $defaults + $default_opts;
|
108 |
$values['form_name'] = '';
|
109 |
-
|
110 |
-
|
111 |
-
$values[$var] = htmlspecialchars(FrmAppHelper::get_param($var, $default));
|
112 |
-
unset($var);
|
113 |
-
unset($default);
|
114 |
}
|
115 |
-
|
116 |
-
foreach (array('field_key' => $record->field_key, 'type' => $record->type, 'default_value'=> $record->default_value, 'field_order' => $record->field_order, 'required' => $record->required) as $var => $default){
|
117 |
-
$values[$var] = FrmAppHelper::get_param($var, $default);
|
118 |
-
unset($var);
|
119 |
-
unset($default);
|
120 |
}
|
121 |
-
|
122 |
-
$
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
unset($defaults);
|
128 |
-
unset($default_opts);
|
129 |
-
|
130 |
$values['options'] = $record->options;
|
131 |
$values['field_options'] = $record->field_options;
|
132 |
-
|
133 |
$defaults = self::get_default_field_opts($values['type'], $record, true);
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
$defaults['invalid'] = $frm_settings->re_msg;
|
138 |
}
|
139 |
-
|
140 |
-
|
141 |
-
$values[$opt] =
|
142 |
-
unset($opt);
|
143 |
-
unset($default);
|
144 |
}
|
145 |
|
146 |
$values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type);
|
147 |
-
|
148 |
-
return apply_filters('frm_setup_edit_field_vars', $values, array('doing_ajax' => $doing_ajax));
|
149 |
}
|
150 |
-
|
151 |
-
public static function get_default_field_opts($type, $field, $limit=false){
|
152 |
$field_options = array(
|
153 |
-
'size' => '', 'max' => '', 'label' => '', 'blank' => '',
|
154 |
'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0,
|
155 |
'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '',
|
156 |
-
|
157 |
);
|
158 |
-
|
159 |
-
|
160 |
return $field_options;
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
164 |
$form_id = (is_numeric($field)) ? $field : $field->form_id;
|
165 |
-
|
166 |
$key = is_numeric($field) ? FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_fields', 'field_key') : $field->field_key;
|
167 |
-
|
168 |
-
|
|
|
|
|
169 |
return array(
|
170 |
-
'name' => __('Untitled', 'formidable'), 'description' => '',
|
171 |
-
'field_key' => $key, 'type' => $type, 'options'=>'', 'default_value'=>'',
|
172 |
-
'field_order' => $field_count+1, 'required' => false,
|
173 |
'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg,
|
174 |
-
'invalid' => __('This field is invalid', 'formidable'), 'form_id' => $form_id,
|
175 |
-
|
176 |
);
|
177 |
}
|
178 |
-
|
179 |
-
public static function
|
180 |
-
global $
|
181 |
-
|
182 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
return $fields;
|
184 |
}
|
185 |
-
|
186 |
-
|
187 |
-
if (apply_filters('frm_normal_field_type_html', true, $type)){
|
188 |
-
$input = (in_array($type, array('radio', 'checkbox', 'data'))) ? '<div class="frm_opt_container">[input]</div>' : '[input]';
|
189 |
$for = '';
|
190 |
-
if(!in_array($type, array('radio', 'checkbox', 'data', 'scale')))
|
191 |
$for = 'for="field_[key]"';
|
192 |
-
|
|
|
193 |
$default_html = <<<DEFAULT_HTML
|
194 |
<div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]">
|
195 |
<label $for class="frm_primary_label">[field_name]
|
@@ -200,198 +301,341 @@ class FrmFieldsHelper{
|
|
200 |
[if error]<div class="frm_error">[error]</div>[/if error]
|
201 |
</div>
|
202 |
DEFAULT_HTML;
|
203 |
-
}else
|
204 |
-
|
|
|
205 |
|
206 |
return apply_filters('frm_custom_html', $default_html, $type);
|
207 |
}
|
208 |
-
|
209 |
-
public static function replace_shortcodes($html, $field, $errors=array(), $form=false){
|
210 |
$html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form);
|
211 |
-
|
212 |
-
$
|
213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
$field_name .= '[]';
|
215 |
-
|
|
|
216 |
//replace [id]
|
217 |
-
$html = str_replace('[id]', $
|
218 |
-
|
219 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
$html = str_replace('[key]', $field['field_key'], $html);
|
221 |
-
|
222 |
//replace [description] and [required_label] and [error]
|
223 |
$required = ($field['required'] == '0') ? '' : $field['required_indicator'];
|
224 |
-
if(!is_array($errors))
|
225 |
$errors = array();
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
|
|
|
|
233 |
}
|
|
|
|
|
|
|
|
|
|
|
234 |
|
235 |
-
$html = str_replace('['.$code.']', $value, $html);
|
236 |
-
}
|
237 |
-
|
238 |
//replace [required_class]
|
239 |
-
$required_class = ($field['required'] == '0') ? '' : ' frm_required_field';
|
240 |
-
$html = str_replace('[required_class]', $required_class, $html);
|
241 |
-
|
242 |
//replace [label_position]
|
243 |
-
$field['label'] = apply_filters('frm_html_label_position', $field['label'], $field);
|
244 |
-
$field['label'] = ($field['label']
|
245 |
-
|
246 |
-
|
247 |
//replace [field_name]
|
248 |
$html = str_replace('[field_name]', $field['name'], $html);
|
249 |
-
|
250 |
-
//replace [error_class]
|
251 |
-
|
252 |
-
|
253 |
-
//insert custom CSS classes
|
254 |
-
if(!empty($field['classes'])){
|
255 |
-
if(!strpos($html, 'frm_form_field '))
|
256 |
-
$error_class .= ' frm_form_field';
|
257 |
-
$error_class .= ' '. $field['classes'];
|
258 |
-
}
|
259 |
$html = str_replace('[error_class]', $error_class, $html);
|
260 |
-
|
261 |
//replace [entry_key]
|
262 |
-
$entry_key = (
|
263 |
$html = str_replace('[entry_key]', $entry_key, $html);
|
264 |
-
|
265 |
//replace [input]
|
266 |
preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
|
267 |
global $frm_vars;
|
|
|
268 |
|
269 |
-
foreach ($shortcodes[0] as $short_key => $tag){
|
270 |
-
$atts = shortcode_parse_atts( $shortcodes[2][$short_key] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
|
272 |
-
if(!empty($shortcodes[2][$short_key])){
|
273 |
-
$tag = str_replace('[', '',$shortcodes[0][$short_key]);
|
274 |
-
$tag = str_replace(']', '', $tag);
|
275 |
-
$tags = explode(' ', $tag);
|
276 |
-
if(is_array($tags))
|
277 |
-
$tag = $tags[0];
|
278 |
-
}else
|
279 |
-
$tag = $shortcodes[1][$short_key];
|
280 |
-
|
281 |
-
$replace_with = '';
|
282 |
-
|
283 |
-
if($tag == 'input'){
|
284 |
-
if(isset($atts['opt'])) $atts['opt']--;
|
285 |
$field['input_class'] = isset($atts['class']) ? $atts['class'] : '';
|
286 |
-
if(isset($atts['class']))
|
287 |
unset($atts['class']);
|
|
|
|
|
288 |
$field['shortcodes'] = $atts;
|
289 |
ob_start();
|
290 |
include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/input.php');
|
291 |
$replace_with = ob_get_contents();
|
292 |
ob_end_clean();
|
293 |
-
}else if($tag == 'deletelink'
|
294 |
$replace_with = FrmProEntriesController::entry_delete_link($atts);
|
295 |
-
|
296 |
-
|
|
|
297 |
}
|
298 |
-
|
299 |
-
|
300 |
-
$form = (array)$form;
|
301 |
-
|
302 |
//replace [form_key]
|
303 |
$html = str_replace('[form_key]', $form['form_key'], $html);
|
304 |
-
|
305 |
//replace [form_name]
|
306 |
$html = str_replace('[form_name]', $form['name'], $html);
|
307 |
}
|
308 |
$html .= "\n";
|
309 |
-
|
310 |
-
|
311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
// remove [collapse_this] when running the free version
|
313 |
-
if (preg_match('/\[(collapse_this)\]/s', $html))
|
314 |
-
|
315 |
-
|
|
|
316 |
return $html;
|
317 |
}
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
$lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field);
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
|
|
|
|
|
|
|
|
332 |
?>
|
333 |
-
<div id="field_<?php echo $field['field_key'] ?>"></div>
|
334 |
-
<?php
|
335 |
-
|
336 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
}
|
338 |
}
|
339 |
-
|
340 |
-
public static function dropdown_categories($args){
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
$
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
$
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
|
|
|
|
|
|
|
|
|
|
365 |
'hide_empty' => false, 'echo' => 0, 'orderby' => 'name',
|
366 |
);
|
367 |
-
|
368 |
-
$
|
369 |
-
|
370 |
-
if (
|
371 |
-
$post_type = FrmProFormsHelper::post_type($field['form_id']);
|
372 |
-
$
|
373 |
-
if ( ! $
|
374 |
return;
|
375 |
}
|
376 |
-
|
377 |
-
|
378 |
-
|
|
|
379 |
}
|
380 |
}
|
381 |
-
|
382 |
-
$dropdown = wp_dropdown_categories($
|
383 |
-
|
384 |
-
$add_html = FrmFieldsController::input_html($field, false);
|
385 |
-
|
386 |
-
if(
|
387 |
-
$add_html .= FrmProFieldsController::input_html($field, false);
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
|
|
392 |
$skip = true;
|
393 |
-
foreach($field['value'] as $v){
|
394 |
-
|
395 |
$skip = false;
|
396 |
continue;
|
397 |
}
|
@@ -399,78 +643,370 @@ DEFAULT_HTML;
|
|
399 |
unset($v);
|
400 |
}
|
401 |
}
|
402 |
-
|
403 |
return $dropdown;
|
404 |
}
|
405 |
-
|
406 |
public static function get_term_link($tax_id) {
|
407 |
$tax = get_taxonomy($tax_id);
|
408 |
-
if (
|
409 |
return;
|
410 |
}
|
411 |
-
|
412 |
$link = sprintf(
|
413 |
-
__('Please add options from the WordPress "%1$s" page', 'formidable'),
|
414 |
-
'<a href="'. esc_url(admin_url('edit-tags.php?taxonomy='. $tax->name)) .'" target="_blank">'. ( empty($tax->labels->name) ? __('Categories') : $tax->labels->name ) .'</a>'
|
415 |
);
|
416 |
unset($tax);
|
417 |
-
|
418 |
return $link;
|
419 |
}
|
420 |
-
|
421 |
-
public static function
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
);
|
429 |
-
|
430 |
-
$
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
|
|
|
|
439 |
}
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
}
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
$field_types[$input] = $frm_pro_field_selection[$input];
|
451 |
-
else
|
452 |
-
$field_types[$input] = $frm_field_selection[$input];
|
453 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
454 |
}
|
455 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
return $field_types;
|
457 |
}
|
458 |
-
|
459 |
-
|
460 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
461 |
<?php
|
462 |
}
|
463 |
-
|
464 |
-
public static function show_default_blank_js($
|
465 |
-
<a class="frm_bstooltip <?php echo
|
466 |
<?php
|
467 |
}
|
468 |
-
|
469 |
-
public static function switch_field_ids($val){
|
470 |
global $frm_duplicate_ids;
|
471 |
$replace = array();
|
472 |
$replace_with = array();
|
473 |
-
foreach((array)$frm_duplicate_ids as $old => $new){
|
474 |
$replace[] = '[if '. $old .']';
|
475 |
$replace_with[] = '[if '. $new .']';
|
476 |
$replace[] = '[if '. $old .' ';
|
@@ -481,19 +1017,151 @@ DEFAULT_HTML;
|
|
481 |
$replace_with[] = '['. $new .']';
|
482 |
$replace[] = '['. $old .' ';
|
483 |
$replace_with[] = '['. $new .' ';
|
484 |
-
unset($old);
|
485 |
-
unset($new);
|
486 |
}
|
487 |
-
|
488 |
-
|
489 |
-
$val[$k] = str_replace($replace, $replace_with, $v);
|
490 |
-
unset($k);
|
491 |
-
unset($v);
|
492 |
}
|
493 |
-
}else{
|
494 |
$val = str_replace($replace, $replace_with, $val);
|
495 |
}
|
496 |
-
|
497 |
return $val;
|
498 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
}
|
1 |
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
5 |
|
6 |
+
class FrmFieldsHelper {
|
|
|
|
|
|
|
7 |
|
8 |
+
public static function field_selection() {
|
|
|
|
|
9 |
$fields = apply_filters('frm_available_fields', array(
|
10 |
+
'text' => __( 'Single Line Text', 'formidable' ),
|
11 |
+
'textarea' => __( 'Paragraph Text', 'formidable' ),
|
12 |
+
'checkbox' => __( 'Checkboxes', 'formidable' ),
|
13 |
+
'radio' => __( 'Radio Buttons', 'formidable' ),
|
14 |
+
'select' => __( 'Dropdown', 'formidable' ),
|
15 |
+
'email' => __( 'Email Address', 'formidable' ),
|
16 |
+
'url' => __( 'Website/URL', 'formidable' ),
|
17 |
+
'captcha' => __( 'reCAPTCHA', 'formidable' ),
|
18 |
));
|
19 |
+
|
20 |
return $fields;
|
21 |
}
|
22 |
+
|
23 |
+
public static function pro_field_selection() {
|
24 |
return apply_filters('frm_pro_available_fields', array(
|
25 |
+
'end_divider' => array(
|
26 |
+
'name' => __( 'End Section', 'formidable' ),
|
27 |
+
'switch_from' => 'divider',
|
28 |
+
),
|
29 |
+
'divider' => __( 'Section', 'formidable' ),
|
30 |
+
'break' => __( 'Page Break', 'formidable' ),
|
31 |
+
'file' => __( 'File Upload', 'formidable' ),
|
32 |
+
'rte' => __( 'Rich Text', 'formidable' ),
|
33 |
+
'number' => __( 'Number', 'formidable' ),
|
34 |
+
'phone' => __( 'Phone Number', 'formidable' ),
|
35 |
+
'date' => __( 'Date', 'formidable' ),
|
36 |
+
'time' => __( 'Time', 'formidable' ),
|
37 |
+
'image' => __( 'Image URL', 'formidable' ),
|
38 |
+
'scale' => __( 'Scale', 'formidable' ),
|
39 |
+
'data' => __( 'Dynamic Field', 'formidable' ),
|
40 |
+
'form' => __( 'Embed Form', 'formidable' ),
|
41 |
+
'hidden' => __( 'Hidden Field', 'formidable' ),
|
42 |
+
'user_id' => __( 'User ID (hidden)', 'formidable' ),
|
43 |
+
'password' => __( 'Password', 'formidable' ),
|
44 |
+
'html' => __( 'HTML', 'formidable' ),
|
45 |
+
'tag' => __( 'Tags', 'formidable' )
|
46 |
+
//'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
|
47 |
+
//'city_selector' => 'US State/County/City selector',
|
48 |
+
//'full_name' => 'First and Last Name',
|
49 |
+
//'quiz' => 'Question and Answer' // for captcha alternative
|
50 |
));
|
51 |
}
|
52 |
+
|
53 |
+
public static function is_no_save_field($type) {
|
54 |
+
return in_array($type, self::no_save_fields());
|
55 |
+
}
|
56 |
+
|
57 |
+
public static function no_save_fields() {
|
58 |
+
return array( 'divider', 'end_divider', 'captcha', 'break', 'html' );
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Check if this is a multiselect dropdown field
|
63 |
+
*
|
64 |
+
* @since 2.0
|
65 |
+
* @return boolean
|
66 |
+
*/
|
67 |
+
public static function is_multiple_select($field) {
|
68 |
+
if ( is_array($field) ) {
|
69 |
+
return isset($field['multiple']) && $field['multiple'] && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'select') ) );
|
70 |
+
} else {
|
71 |
+
return isset($field->field_options['multiple']) && $field->field_options['multiple'] && ( ( $field->type == 'select' || ( $field->type == 'data' && isset($field->field_options['data_type']) && $field->field_options['data_type'] == 'select') ) );
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Check if this field can hold an array of values
|
77 |
+
*
|
78 |
+
* @since 2.0
|
79 |
+
*
|
80 |
+
* @param array|object $field
|
81 |
+
* @return boolean
|
82 |
+
*/
|
83 |
+
public static function is_field_with_multiple_values( $field ) {
|
84 |
+
if ( ! $field ) {
|
85 |
+
return false;
|
86 |
+
}
|
87 |
+
|
88 |
+
if ( is_array( $field ) ) {
|
89 |
+
// For field array
|
90 |
+
return $field['type'] == 'checkbox' || ( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) || self::is_multiple_select( $field );
|
91 |
+
} else {
|
92 |
+
// For field object
|
93 |
+
return $field->type == 'checkbox' || ( $field->type == 'data' && $field->field_options['data_type'] == 'checkbox' ) || self::is_multiple_select($field);
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* If $field is numeric, get the field object
|
99 |
+
*/
|
100 |
+
public static function maybe_get_field( &$field ) {
|
101 |
+
if ( ! is_object($field) ) {
|
102 |
+
$field = FrmField::getOne($field);
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
public static function setup_new_vars($type = '', $form_id = '') {
|
107 |
+
|
108 |
+
if ( strpos($type, '|') ) {
|
109 |
+
list($type, $setting) = explode('|', $type);
|
110 |
+
}
|
111 |
+
|
112 |
+
$defaults = self::get_default_field_opts($type, $form_id);
|
113 |
+
$defaults['field_options']['custom_html'] = self::get_default_html($type);
|
114 |
|
115 |
$values = array();
|
116 |
+
|
117 |
+
foreach ( $defaults as $var => $default ) {
|
118 |
+
if ( $var == 'field_options' ) {
|
119 |
$values['field_options'] = array();
|
120 |
+
foreach ( $default as $opt_var => $opt_default ) {
|
121 |
+
$values['field_options'][ $opt_var ] = $opt_default;
|
122 |
+
unset($opt_var, $opt_default);
|
|
|
123 |
}
|
124 |
+
} else {
|
125 |
+
$values[ $var ] = $default;
|
126 |
+
}
|
127 |
+
unset($var, $default);
|
128 |
+
}
|
129 |
+
|
130 |
+
if ( isset( $setting ) && ! empty( $setting ) ) {
|
131 |
+
if ( 'data' == $type ) {
|
132 |
+
$values['field_options']['data_type'] = $setting;
|
133 |
+
} else {
|
134 |
+
$values['field_options'][ $setting ] = 1;
|
135 |
}
|
136 |
+
}
|
137 |
+
|
138 |
+
if ( $type == 'radio' || $type == 'checkbox' ) {
|
139 |
+
$values['options'] = serialize( array(
|
140 |
+
__( 'Option 1', 'formidable' ),
|
141 |
+
__( 'Option 2', 'formidable' ),
|
142 |
+
) );
|
143 |
+
} else if ( $type == 'select' ) {
|
144 |
+
$values['options'] = serialize( array(
|
145 |
+
'', __( 'Option 1', 'formidable' ),
|
146 |
+
) );
|
147 |
+
} else if ( $type == 'textarea' ) {
|
148 |
$values['field_options']['max'] = '5';
|
149 |
+
} else if ( $type == 'captcha' ) {
|
150 |
+
$frm_settings = FrmAppHelper::get_settings();
|
151 |
$values['invalid'] = $frm_settings->re_msg;
|
152 |
+
} else if ( 'url' == $type ) {
|
153 |
+
$values['name'] = __( 'Website', 'formidable' );
|
154 |
+
}
|
155 |
+
|
156 |
$fields = self::field_selection();
|
157 |
$fields = array_merge($fields, self::pro_field_selection());
|
158 |
|
159 |
+
if ( isset( $fields[ $type ] ) ) {
|
160 |
+
$values['name'] = is_array( $fields[ $type ] ) ? $fields[ $type ]['name'] : $fields[ $type ];
|
161 |
+
}
|
162 |
|
163 |
unset($fields);
|
164 |
+
|
165 |
return $values;
|
166 |
}
|
167 |
+
|
168 |
+
public static function get_html_id($field, $plus = '') {
|
169 |
+
return apply_filters('frm_field_html_id', 'field_'. $field['field_key'] . $plus, $field);
|
170 |
+
}
|
171 |
+
|
172 |
+
public static function setup_edit_vars( $record, $doing_ajax = false ) {
|
173 |
+
$values = array( 'id' => $record->id, 'form_id' => $record->form_id);
|
174 |
+
$defaults = array( 'name' => $record->name, 'description' => $record->description);
|
175 |
$default_opts = array(
|
176 |
+
'field_key' => $record->field_key, 'type' => $record->type,
|
177 |
+
'default_value'=> $record->default_value, 'field_order' => $record->field_order,
|
178 |
+
'required' => $record->required,
|
179 |
);
|
180 |
+
|
181 |
+
if ( $doing_ajax ) {
|
182 |
$values = $values + $defaults + $default_opts;
|
183 |
$values['form_name'] = '';
|
184 |
+
} else {
|
185 |
+
foreach ( $defaults as $var => $default ) {
|
186 |
+
$values[ $var ] = htmlspecialchars( FrmAppHelper::get_param( $var, $default ) );
|
187 |
+
unset($var, $default);
|
|
|
188 |
}
|
189 |
+
|
190 |
+
foreach ( array( 'field_key' => $record->field_key, 'type' => $record->type, 'default_value' => $record->default_value, 'field_order' => $record->field_order, 'required' => $record->required ) as $var => $default ) {
|
191 |
+
$values[ $var ] = FrmAppHelper::get_param( $var, $default );
|
192 |
+
unset($var, $default);
|
|
|
193 |
}
|
194 |
+
|
195 |
+
$values['form_name'] = ($record->form_id) ? FrmForm::getName( $record->form_id ) : '';
|
196 |
+
}
|
197 |
+
|
198 |
+
unset($defaults, $default_opts);
|
199 |
+
|
|
|
|
|
|
|
200 |
$values['options'] = $record->options;
|
201 |
$values['field_options'] = $record->field_options;
|
202 |
+
|
203 |
$defaults = self::get_default_field_opts($values['type'], $record, true);
|
204 |
+
|
205 |
+
if ( $values['type'] == 'captcha' ) {
|
206 |
+
$frm_settings = FrmAppHelper::get_settings();
|
207 |
$defaults['invalid'] = $frm_settings->re_msg;
|
208 |
}
|
209 |
+
|
210 |
+
foreach ( $defaults as $opt => $default ) {
|
211 |
+
$values[ $opt ] = isset( $record->field_options[ $opt ] ) ? $record->field_options[ $opt ] : $default;
|
212 |
+
unset($opt, $default);
|
|
|
213 |
}
|
214 |
|
215 |
$values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type);
|
216 |
+
|
217 |
+
return apply_filters('frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax));
|
218 |
}
|
219 |
+
|
220 |
+
public static function get_default_field_opts( $type, $field, $limit = false ) {
|
221 |
$field_options = array(
|
222 |
+
'size' => '', 'max' => '', 'label' => '', 'blank' => '',
|
223 |
'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0,
|
224 |
'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '',
|
225 |
+
'custom_html' => '',
|
226 |
);
|
227 |
+
|
228 |
+
if ( $limit ) {
|
229 |
return $field_options;
|
230 |
+
}
|
231 |
+
|
232 |
+
global $wpdb;
|
233 |
+
|
234 |
$form_id = (is_numeric($field)) ? $field : $field->form_id;
|
235 |
+
|
236 |
$key = is_numeric($field) ? FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_fields', 'field_key') : $field->field_key;
|
237 |
+
|
238 |
+
$field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) );
|
239 |
+
|
240 |
+
$frm_settings = FrmAppHelper::get_settings();
|
241 |
return array(
|
242 |
+
'name' => __( 'Untitled', 'formidable' ), 'description' => '',
|
243 |
+
'field_key' => $key, 'type' => $type, 'options'=>'', 'default_value'=>'',
|
244 |
+
'field_order' => $field_count+1, 'required' => false,
|
245 |
'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg,
|
246 |
+
'invalid' => __( 'This field is invalid', 'formidable' ), 'form_id' => $form_id,
|
247 |
+
'field_options' => $field_options,
|
248 |
);
|
249 |
}
|
250 |
+
|
251 |
+
public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
|
252 |
+
global $wpdb;
|
253 |
+
|
254 |
+
$values['field_key'] = FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_fields', 'field_key');
|
255 |
+
$values['form_id'] = $form_id;
|
256 |
+
$values['options'] = maybe_serialize($field->options);
|
257 |
+
$values['default_value'] = maybe_serialize($field->default_value);
|
258 |
+
|
259 |
+
foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) {
|
260 |
+
$values[ $col ] = $field->{$col};
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
/**
|
265 |
+
* @since 2.0
|
266 |
+
*/
|
267 |
+
public static function get_error_msg($field, $error) {
|
268 |
+
$frm_settings = FrmAppHelper::get_settings();
|
269 |
+
$default_settings = $frm_settings->default_options();
|
270 |
+
|
271 |
+
$defaults = array(
|
272 |
+
'unique_msg' => array( 'full' => $default_settings['unique_msg'], 'part' => $field->name.' '. __( 'must be unique', 'formidable' )),
|
273 |
+
'invalid' => array( 'full' => __( 'This field is invalid', 'formidable' ), 'part' => $field->name.' '. __( 'is invalid', 'formidable' ))
|
274 |
+
);
|
275 |
+
|
276 |
+
$msg = ( $field->field_options[ $error ] == $defaults[ $error ]['full'] || empty( $field->field_options[ $error ] ) ) ? $defaults[ $error ]['part'] : $field->field_options[ $error ];
|
277 |
+
return $msg;
|
278 |
+
}
|
279 |
+
|
280 |
+
public static function get_form_fields( $form_id, $error = false ) {
|
281 |
+
$fields = FrmField::get_all_for_form($form_id);
|
282 |
+
$fields = apply_filters('frm_get_paged_fields', $fields, $form_id, $error);
|
283 |
return $fields;
|
284 |
}
|
285 |
+
|
286 |
+
public static function get_default_html( $type = 'text' ) {
|
287 |
+
if (apply_filters('frm_normal_field_type_html', true, $type)) {
|
288 |
+
$input = (in_array($type, array( 'radio', 'checkbox', 'data'))) ? '<div class="frm_opt_container">[input]</div>' : '[input]';
|
289 |
$for = '';
|
290 |
+
if ( ! in_array( $type, array( 'radio', 'checkbox', 'data', 'scale') ) ) {
|
291 |
$for = 'for="field_[key]"';
|
292 |
+
}
|
293 |
+
|
294 |
$default_html = <<<DEFAULT_HTML
|
295 |
<div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]">
|
296 |
<label $for class="frm_primary_label">[field_name]
|
301 |
[if error]<div class="frm_error">[error]</div>[/if error]
|
302 |
</div>
|
303 |
DEFAULT_HTML;
|
304 |
+
} else {
|
305 |
+
$default_html = apply_filters('frm_other_custom_html', '', $type);
|
306 |
+
}
|
307 |
|
308 |
return apply_filters('frm_custom_html', $default_html, $type);
|
309 |
}
|
310 |
+
|
311 |
+
public static function replace_shortcodes($html, $field, $errors = array(), $form = false, $args = array()) {
|
312 |
$html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form);
|
313 |
+
|
314 |
+
$defaults = array(
|
315 |
+
'field_name' => 'item_meta['. $field['id'] .']',
|
316 |
+
'field_id' => $field['id'],
|
317 |
+
'field_plus_id' => '',
|
318 |
+
'section_id' => '',
|
319 |
+
);
|
320 |
+
$args = wp_parse_args($args, $defaults);
|
321 |
+
$field_name = $args['field_name'];
|
322 |
+
$field_id = $args['field_id'];
|
323 |
+
$html_id = self::get_html_id($field, $args['field_plus_id']);
|
324 |
+
|
325 |
+
if ( self::is_multiple_select($field) ) {
|
326 |
$field_name .= '[]';
|
327 |
+
}
|
328 |
+
|
329 |
//replace [id]
|
330 |
+
$html = str_replace('[id]', $field_id, $html);
|
331 |
+
|
332 |
+
// Remove the for attribute for captcha
|
333 |
+
if ( $field['type'] == 'captcha' ) {
|
334 |
+
$html = str_replace(' for="field_[key]"', '', $html);
|
335 |
+
}
|
336 |
+
|
337 |
+
// set the label for
|
338 |
+
$html = str_replace('field_[key]', $html_id, $html);
|
339 |
+
|
340 |
+
//replace [key]
|
341 |
$html = str_replace('[key]', $field['field_key'], $html);
|
342 |
+
|
343 |
//replace [description] and [required_label] and [error]
|
344 |
$required = ($field['required'] == '0') ? '' : $field['required_indicator'];
|
345 |
+
if ( ! is_array( $errors ) ) {
|
346 |
$errors = array();
|
347 |
+
}
|
348 |
+
$error = isset($errors['field'. $field_id]) ? $errors['field'. $field_id] : false;
|
349 |
+
|
350 |
+
//If field type is section heading, add class so a bottom margin can be added to either the h3 or description
|
351 |
+
if ( $field['type'] == 'divider' ) {
|
352 |
+
if ( isset( $field['description'] ) && $field['description'] ) {
|
353 |
+
$html = str_replace( 'frm_description', 'frm_description frm_section_spacing', $html );
|
354 |
+
} else {
|
355 |
+
$html = str_replace('[label_position]', '[label_position] frm_section_spacing', $html);
|
356 |
}
|
357 |
+
}
|
358 |
+
|
359 |
+
foreach ( array( 'description' => $field['description'], 'required_label' => $required, 'error' => $error) as $code => $value) {
|
360 |
+
self::remove_inline_conditions( ( $value && $value != '' ), $code, $value, $html );
|
361 |
+
}
|
362 |
|
|
|
|
|
|
|
363 |
//replace [required_class]
|
364 |
+
$required_class = ($field['required'] == '0') ? '' : ' frm_required_field';
|
365 |
+
$html = str_replace('[required_class]', $required_class, $html);
|
366 |
+
|
367 |
//replace [label_position]
|
368 |
+
$field['label'] = apply_filters('frm_html_label_position', $field['label'], $field, $form);
|
369 |
+
$field['label'] = ( $field['label'] && $field['label'] != '' ) ? $field['label'] : 'top';
|
370 |
+
$html = str_replace( '[label_position]', ( ( in_array( $field['type'], array( 'divider', 'end_divider', 'break' ) ) ) ? $field['label'] : ' frm_primary_label' ), $html );
|
371 |
+
|
372 |
//replace [field_name]
|
373 |
$html = str_replace('[field_name]', $field['name'], $html);
|
374 |
+
|
375 |
+
//replace [error_class]
|
376 |
+
$error_class = isset ( $errors['field'. $field_id] ) ? ' frm_blank_field' : '';
|
377 |
+
self::get_more_field_classes( $error_class, $field, $field_id, $html );
|
|
|
|
|
|
|
|
|
|
|
|
|
378 |
$html = str_replace('[error_class]', $error_class, $html);
|
379 |
+
|
380 |
//replace [entry_key]
|
381 |
+
$entry_key = ( $_GET && isset($_GET['entry']) ) ? $_GET['entry'] : '';
|
382 |
$html = str_replace('[entry_key]', $entry_key, $html);
|
383 |
+
|
384 |
//replace [input]
|
385 |
preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
|
386 |
global $frm_vars;
|
387 |
+
$frm_settings = FrmAppHelper::get_settings();
|
388 |
|
389 |
+
foreach ( $shortcodes[0] as $short_key => $tag ) {
|
390 |
+
$atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] );
|
391 |
+
$tag = self::get_shortcode_tag($shortcodes, $short_key, array( 'conditional' => false, 'conditional_check' => false));
|
392 |
+
|
393 |
+
$replace_with = '';
|
394 |
+
|
395 |
+
if ( $tag == 'input' ) {
|
396 |
+
if ( isset($atts['opt']) ) {
|
397 |
+
$atts['opt']--;
|
398 |
+
}
|
399 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
$field['input_class'] = isset($atts['class']) ? $atts['class'] : '';
|
401 |
+
if ( isset($atts['class']) ) {
|
402 |
unset($atts['class']);
|
403 |
+
}
|
404 |
+
|
405 |
$field['shortcodes'] = $atts;
|
406 |
ob_start();
|
407 |
include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/input.php');
|
408 |
$replace_with = ob_get_contents();
|
409 |
ob_end_clean();
|
410 |
+
} else if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) {
|
411 |
$replace_with = FrmProEntriesController::entry_delete_link($atts);
|
412 |
+
}
|
413 |
+
|
414 |
+
$html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $html );
|
415 |
}
|
416 |
+
|
417 |
+
if ( $form ) {
|
418 |
+
$form = (array) $form;
|
419 |
+
|
420 |
//replace [form_key]
|
421 |
$html = str_replace('[form_key]', $form['form_key'], $html);
|
422 |
+
|
423 |
//replace [form_name]
|
424 |
$html = str_replace('[form_name]', $form['name'], $html);
|
425 |
}
|
426 |
$html .= "\n";
|
427 |
+
|
428 |
+
//Return html if conf_field to prevent loop
|
429 |
+
if ( isset($field['conf_field']) && $field['conf_field'] == 'stop' ) {
|
430 |
+
return $html;
|
431 |
+
}
|
432 |
+
|
433 |
+
//If field is in repeating section
|
434 |
+
if ( $args['section_id'] ) {
|
435 |
+
$html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form, 'field_name' => $field_name, 'field_id' => $field_id, 'field_plus_id' => $args['field_plus_id'], 'section_id' => $args['section_id'] ));
|
436 |
+
} else {
|
437 |
+
$html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form ));
|
438 |
+
}
|
439 |
+
|
440 |
// remove [collapse_this] when running the free version
|
441 |
+
if (preg_match('/\[(collapse_this)\]/s', $html)) {
|
442 |
+
$html = str_replace('[collapse_this]', '', $html);
|
443 |
+
}
|
444 |
+
|
445 |
return $html;
|
446 |
}
|
447 |
+
|
448 |
+
/**
|
449 |
+
* Add more classes to certain fields (like confirmation fields, other fields, repeating fields, etc.)
|
450 |
+
*
|
451 |
+
* @since 2.0
|
452 |
+
* @param $error_class string, pass by reference
|
453 |
+
* @param $field array
|
454 |
+
* @param $field_id int
|
455 |
+
* @param $html string
|
456 |
+
*/
|
457 |
+
private static function get_more_field_classes( &$error_class, $field, $field_id, $html ) {
|
458 |
+
$error_class .= ' frm_'. $field['label'] .'_container';
|
459 |
+
if ( $field['id'] != $field_id ) {
|
460 |
+
// add a class for repeating/embedded fields
|
461 |
+
$error_class .= ' frm_field_'. $field['id'] .'_container';
|
462 |
+
}
|
463 |
+
|
464 |
+
//Add classes to inline confirmation field (if it doesn't already have classes set)
|
465 |
+
if ( isset ( $field['conf_field'] ) && $field['conf_field'] == 'inline' && ! $field['classes'] ) {
|
466 |
+
$error_class .= ' frm_first_half';
|
467 |
+
}
|
468 |
+
|
469 |
+
//Add class if field includes other option
|
470 |
+
if ( isset( $field['other'] ) && true == $field['other'] ) {
|
471 |
+
$error_class .= ' frm_other_container';
|
472 |
+
}
|
473 |
+
|
474 |
+
// If this is a Section
|
475 |
+
if ( $field['type'] == 'divider' ) {
|
476 |
+
|
477 |
+
// If the top margin needs to be removed from a section heading
|
478 |
+
if ( $field['label'] == 'none' ) {
|
479 |
+
$error_class .= ' frm_hide_section';
|
480 |
+
}
|
481 |
+
|
482 |
+
// If this is a repeating section that should be hidden with exclude_fields or fields shortcode, hide it
|
483 |
+
if ( $field['repeat'] ) {
|
484 |
+
global $frm_vars;
|
485 |
+
if ( isset( $frm_vars['show_fields'] ) && ! empty ( $frm_vars['show_fields'] ) && ! in_array( $field['id'], $frm_vars['show_fields'] ) && ! in_array( $field['field_key'], $frm_vars['show_fields'] ) ) {
|
486 |
+
$error_class .= ' frm_hidden';
|
487 |
+
}
|
488 |
+
}
|
489 |
+
}
|
490 |
+
|
491 |
+
//insert custom CSS classes
|
492 |
+
if ( ! empty( $field['classes'] ) ) {
|
493 |
+
if ( ! strpos( $html, 'frm_form_field ') ) {
|
494 |
+
$error_class .= ' frm_form_field';
|
495 |
+
}
|
496 |
+
$error_class .= ' '. $field['classes'];
|
497 |
+
}
|
498 |
+
}
|
499 |
+
|
500 |
+
public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
|
501 |
+
if ( $no_vars ) {
|
502 |
+
$html = str_replace( '[if '. $code.']', '', $html );
|
503 |
+
$html = str_replace( '[/if '. $code.']', '', $html );
|
504 |
+
} else {
|
505 |
+
$html = preg_replace( '/(\[if\s+'. $code .'\])(.*?)(\[\/if\s+'. $code .'\])/mis', '', $html );
|
506 |
+
}
|
507 |
+
|
508 |
+
$html = str_replace( '['. $code .']', $replace_with, $html );
|
509 |
+
}
|
510 |
+
|
511 |
+
public static function get_shortcode_tag($shortcodes, $short_key, $args) {
|
512 |
+
$args = wp_parse_args($args, array( 'conditional' => false, 'conditional_check' => false, 'foreach' => false));
|
513 |
+
if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) {
|
514 |
+
$args['conditional_check'] = true;
|
515 |
+
}
|
516 |
+
|
517 |
+
$prefix = '';
|
518 |
+
if ( $args['conditional_check'] ) {
|
519 |
+
if ( $args['conditional'] ) {
|
520 |
+
$prefix = 'if ';
|
521 |
+
} else if ( $args['foreach'] ) {
|
522 |
+
$prefix = 'foreach ';
|
523 |
+
}
|
524 |
+
}
|
525 |
+
|
526 |
+
$with_tags = $args['conditional_check'] ? 3 : 2;
|
527 |
+
if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) {
|
528 |
+
$tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] );
|
529 |
+
$tag = str_replace(']', '', $tag);
|
530 |
+
$tags = explode(' ', $tag);
|
531 |
+
if ( is_array($tags) ) {
|
532 |
+
$tag = $tags[0];
|
533 |
+
}
|
534 |
+
} else {
|
535 |
+
$tag = $shortcodes[ $with_tags - 1 ][ $short_key ];
|
536 |
+
}
|
537 |
+
|
538 |
+
return $tag;
|
539 |
+
}
|
540 |
+
|
541 |
+
public static function display_recaptcha($field) {
|
542 |
+
$frm_settings = FrmAppHelper::get_settings();
|
543 |
$lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field);
|
544 |
+
|
545 |
+
$api_js_url = 'https://www.google.com/recaptcha/api.js';
|
546 |
+
if ( $lang != 'en' ) {
|
547 |
+
$api_js_url .= '?hl='. $lang;
|
548 |
+
}
|
549 |
+
$api_js_url = apply_filters('frm_recpatcha_js_url', $api_js_url);
|
550 |
+
|
551 |
+
wp_register_script('recaptcha-api', $api_js_url, '', true);
|
552 |
+
wp_enqueue_script('recaptcha-api');
|
553 |
+
|
554 |
?>
|
555 |
+
<div id="field_<?php echo esc_attr( $field['field_key'] ) ?>" class="g-recaptcha" data-sitekey="<?php echo esc_attr( $frm_settings->pubkey ) ?>"></div>
|
556 |
+
<?php
|
557 |
+
}
|
558 |
+
|
559 |
+
public static function show_single_option($field) {
|
560 |
+
$field_name = $field['name'];
|
561 |
+
$html_id = self::get_html_id($field);
|
562 |
+
foreach ( $field['options'] as $opt_key => $opt ) {
|
563 |
+
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
|
564 |
+
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
|
565 |
+
|
566 |
+
// If this is an "Other" option, get the HTML for it
|
567 |
+
if ( FrmAppHelper::is_other_opt( $opt_key ) ) {
|
568 |
+
// Get string for Other text field, if needed
|
569 |
+
$other_val = FrmAppHelper::get_other_val( $opt_key, $field );
|
570 |
+
require(FrmAppHelper::plugin_path() .'/pro/classes/views/frmpro-fields/other-option.php');
|
571 |
+
} else {
|
572 |
+
require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
|
573 |
+
}
|
574 |
}
|
575 |
}
|
576 |
+
|
577 |
+
public static function dropdown_categories($args) {
|
578 |
+
$defaults = array( 'field' => false, 'name' => false, 'show_option_all' => ' ' );
|
579 |
+
$args = wp_parse_args($args, $defaults);
|
580 |
+
|
581 |
+
if ( ! $args['field'] ) {
|
582 |
+
return;
|
583 |
+
}
|
584 |
+
|
585 |
+
if ( ! $args['name'] ) {
|
586 |
+
$args['name'] = 'item_meta['. $args['field']['id'] .']';
|
587 |
+
}
|
588 |
+
|
589 |
+
$id = self::get_html_id($args['field']);
|
590 |
+
$class = $args['field']['type'];
|
591 |
+
|
592 |
+
$exclude = (is_array($args['field']['exclude_cat'])) ? implode(',', $args['field']['exclude_cat']) : $args['field']['exclude_cat'];
|
593 |
+
$exclude = apply_filters('frm_exclude_cats', $exclude, $args['field']);
|
594 |
+
|
595 |
+
if ( is_array($args['field']['value']) ) {
|
596 |
+
if ( ! empty($exclude) ) {
|
597 |
+
$args['field']['value'] = array_diff($args['field']['value'], explode(',', $exclude));
|
598 |
+
}
|
599 |
+
$selected = reset($args['field']['value']);
|
600 |
+
} else {
|
601 |
+
$selected = $args['field']['value'];
|
602 |
+
}
|
603 |
+
|
604 |
+
$tax_atts = array(
|
605 |
+
'show_option_all' => $args['show_option_all'], 'hierarchical' => 1, 'name' => $args['name'],
|
606 |
+
'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected,
|
607 |
'hide_empty' => false, 'echo' => 0, 'orderby' => 'name',
|
608 |
);
|
609 |
+
|
610 |
+
$tax_atts = apply_filters('frm_dropdown_cat', $tax_atts, $args['field']);
|
611 |
+
|
612 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
613 |
+
$post_type = FrmProFormsHelper::post_type($args['field']['form_id']);
|
614 |
+
$tax_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field']);
|
615 |
+
if ( ! $tax_atts['taxonomy'] ) {
|
616 |
return;
|
617 |
}
|
618 |
+
|
619 |
+
// If field type is dropdown (not Dynamic), exclude children when parent is excluded
|
620 |
+
if ( $args['field']['type'] != 'data' && is_taxonomy_hierarchical($tax_atts['taxonomy']) ) {
|
621 |
+
$tax_atts['exclude_tree'] = $exclude;
|
622 |
}
|
623 |
}
|
624 |
+
|
625 |
+
$dropdown = wp_dropdown_categories($tax_atts);
|
626 |
+
|
627 |
+
$add_html = FrmFieldsController::input_html($args['field'], false);
|
628 |
+
|
629 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
630 |
+
$add_html .= FrmProFieldsController::input_html($args['field'], false);
|
631 |
+
}
|
632 |
+
|
633 |
+
$dropdown = str_replace("<select name='". $args['name'] ."' id='$id' class='$class'", "<select name='". $args['name'] ."' id='$id' ". $add_html, $dropdown);
|
634 |
+
|
635 |
+
if ( is_array($args['field']['value']) ) {
|
636 |
$skip = true;
|
637 |
+
foreach ( $args['field']['value'] as $v ) {
|
638 |
+
if ( $skip ) {
|
639 |
$skip = false;
|
640 |
continue;
|
641 |
}
|
643 |
unset($v);
|
644 |
}
|
645 |
}
|
646 |
+
|
647 |
return $dropdown;
|
648 |
}
|
649 |
+
|
650 |
public static function get_term_link($tax_id) {
|
651 |
$tax = get_taxonomy($tax_id);
|
652 |
+
if ( ! $tax ) {
|
653 |
return;
|
654 |
}
|
655 |
+
|
656 |
$link = sprintf(
|
657 |
+
__( 'Please add options from the WordPress "%1$s" page', 'formidable' ),
|
658 |
+
'<a href="'. esc_url( admin_url( 'edit-tags.php?taxonomy='. $tax->name ) ) .'" target="_blank">'. ( empty($tax->labels->name) ? __( 'Categories' ) : $tax->labels->name ) .'</a>'
|
659 |
);
|
660 |
unset($tax);
|
661 |
+
|
662 |
return $link;
|
663 |
}
|
664 |
+
|
665 |
+
public static function value_meets_condition($observed_value, $cond, $hide_opt) {
|
666 |
+
if ( is_array($observed_value) ) {
|
667 |
+
return self::array_value_condition($observed_value, $cond, $hide_opt);
|
668 |
+
}
|
669 |
+
|
670 |
+
$m = false;
|
671 |
+
if ( $cond == '==' ) {
|
672 |
+
$m = $observed_value == $hide_opt;
|
673 |
+
} else if ( $cond == '!=' ) {
|
674 |
+
$m = $observed_value != $hide_opt;
|
675 |
+
} else if ( $cond == '>' ) {
|
676 |
+
$m = $observed_value > $hide_opt;
|
677 |
+
} else if ( $cond == '<' ) {
|
678 |
+
$m = $observed_value < $hide_opt;
|
679 |
+
} else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
|
680 |
+
$m = strpos($observed_value, $hide_opt);
|
681 |
+
if ( $cond == 'not LIKE' ) {
|
682 |
+
$m = ( $m === false ) ? true : false;
|
683 |
+
} else {
|
684 |
+
$m = ( $m === false ) ? false : true;
|
685 |
+
}
|
686 |
+
}
|
687 |
+
return $m;
|
688 |
+
}
|
689 |
+
|
690 |
+
public static function array_value_condition($observed_value, $cond, $hide_opt) {
|
691 |
+
$m = false;
|
692 |
+
if ( $cond == '==' ) {
|
693 |
+
if ( is_array($hide_opt) ) {
|
694 |
+
$m = array_intersect($hide_opt, $observed_value);
|
695 |
+
$m = empty($m) ? false : true;
|
696 |
+
} else {
|
697 |
+
$m = in_array($hide_opt, $observed_value);
|
698 |
+
}
|
699 |
+
} else if ( $cond == '!=' ) {
|
700 |
+
$m = ! in_array($hide_opt, $observed_value);
|
701 |
+
} else if ( $cond == '>' ) {
|
702 |
+
$min = min($observed_value);
|
703 |
+
$m = $min > $hide_opt;
|
704 |
+
} else if ( $cond == '<' ) {
|
705 |
+
$max = max($observed_value);
|
706 |
+
$m = $max < $hide_opt;
|
707 |
+
} else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
|
708 |
+
foreach ( $observed_value as $ob ) {
|
709 |
+
$m = strpos($ob, $hide_opt);
|
710 |
+
if ( $m !== false ) {
|
711 |
+
$m = true;
|
712 |
+
break;
|
713 |
+
}
|
714 |
+
}
|
715 |
+
|
716 |
+
if ( $cond == 'not LIKE' ) {
|
717 |
+
$m = ( $m === false ) ? true : false;
|
718 |
+
}
|
719 |
+
}
|
720 |
+
|
721 |
+
return $m;
|
722 |
+
}
|
723 |
+
|
724 |
+
/**
|
725 |
+
* Replace a few basic shortcodes and field ids
|
726 |
+
* @since 2.0
|
727 |
+
* @return string
|
728 |
+
*/
|
729 |
+
public static function basic_replace_shortcodes($value, $form, $entry) {
|
730 |
+
if ( strpos($value, '[sitename]') !== false ) {
|
731 |
+
$new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
|
732 |
+
$value = str_replace('[sitename]', $new_value, $value);
|
733 |
+
}
|
734 |
+
|
735 |
+
$value = apply_filters('frm_content', $value, $form, $entry);
|
736 |
+
$value = do_shortcode($value);
|
737 |
+
|
738 |
+
return $value;
|
739 |
+
}
|
740 |
+
|
741 |
+
public static function get_shortcodes($content, $form_id) {
|
742 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
743 |
+
return FrmProDisplaysHelper::get_shortcodes($content, $form_id);
|
744 |
+
}
|
745 |
+
|
746 |
+
$fields = FrmField::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type not' => self::no_save_fields() ) );
|
747 |
+
|
748 |
+
$tagregexp = self::allowed_shortcodes($fields);
|
749 |
+
|
750 |
+
preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER);
|
751 |
+
|
752 |
+
return $matches;
|
753 |
+
}
|
754 |
+
|
755 |
+
public static function allowed_shortcodes($fields = array()) {
|
756 |
+
$tagregexp = array(
|
757 |
+
'editlink', 'id', 'key', 'ip',
|
758 |
+
'siteurl', 'sitename', 'admin_email',
|
759 |
+
'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by',
|
760 |
+
);
|
761 |
+
|
762 |
+
foreach ( $fields as $field ) {
|
763 |
+
$tagregexp[] = $field->id;
|
764 |
+
$tagregexp[] = $field->field_key;
|
765 |
+
}
|
766 |
+
|
767 |
+
$tagregexp = implode('|', $tagregexp);
|
768 |
+
return $tagregexp;
|
769 |
+
}
|
770 |
+
|
771 |
+
public static function replace_content_shortcodes($content, $entry, $shortcodes) {
|
772 |
+
$shortcode_values = array(
|
773 |
+
'id' => $entry->id,
|
774 |
+
'key' => $entry->item_key,
|
775 |
+
'ip' => $entry->ip,
|
776 |
);
|
777 |
+
|
778 |
+
foreach ( $shortcodes[0] as $short_key => $tag ) {
|
779 |
+
$atts = shortcode_parse_atts( $shortcodes[3][ $short_key ] );
|
780 |
+
|
781 |
+
if ( ! empty( $shortcodes[3][ $short_key ] ) ) {
|
782 |
+
$tag = str_replace( array( '[', ']' ), '', $shortcodes[0][ $short_key ] );
|
783 |
+
$tags = explode(' ', $tag);
|
784 |
+
if ( is_array($tags) ) {
|
785 |
+
$tag = $tags[0];
|
786 |
+
}
|
787 |
+
} else {
|
788 |
+
$tag = $shortcodes[2][ $short_key ];
|
789 |
}
|
790 |
+
|
791 |
+
switch ( $tag ) {
|
792 |
+
case 'id':
|
793 |
+
case 'key':
|
794 |
+
case 'ip':
|
795 |
+
$replace_with = $shortcode_values[ $tag ];
|
796 |
+
break;
|
797 |
+
|
798 |
+
case 'user_agent':
|
799 |
+
case 'user-agent':
|
800 |
+
$entry->description = maybe_unserialize($entry->description);
|
801 |
+
$replace_with = FrmEntriesHelper::get_browser($entry->description['browser']);
|
802 |
+
break;
|
803 |
+
|
804 |
+
case 'created_at':
|
805 |
+
case 'created-at':
|
806 |
+
case 'updated_at':
|
807 |
+
case 'updated-at':
|
808 |
+
if ( isset($atts['format']) ) {
|
809 |
+
$time_format = ' ';
|
810 |
+
} else {
|
811 |
+
$atts['format'] = get_option('date_format');
|
812 |
+
$time_format = '';
|
813 |
+
}
|
814 |
+
|
815 |
+
$this_tag = str_replace('-', '_', $tag);
|
816 |
+
$replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format);
|
817 |
+
unset($this_tag);
|
818 |
+
break;
|
819 |
+
|
820 |
+
case 'created_by':
|
821 |
+
case 'created-by':
|
822 |
+
case 'updated_by':
|
823 |
+
case 'updated-by':
|
824 |
+
$this_tag = str_replace('-', '_', $tag);
|
825 |
+
$replace_with = self::get_display_value($entry->{$this_tag}, (object) array( 'type' => 'user_id'), $atts);
|
826 |
+
unset($this_tag);
|
827 |
+
break;
|
828 |
+
|
829 |
+
case 'admin_email':
|
830 |
+
case 'siteurl':
|
831 |
+
case 'frmurl':
|
832 |
+
case 'sitename':
|
833 |
+
case 'get':
|
834 |
+
$replace_with = self::dynamic_default_values( $tag, $atts );
|
835 |
+
break;
|
836 |
+
|
837 |
+
default:
|
838 |
+
$field = FrmField::getOne( $tag );
|
839 |
+
if ( ! $field ) {
|
840 |
+
break;
|
841 |
+
}
|
842 |
+
|
843 |
+
$sep = isset($atts['sep']) ? $atts['sep'] : ', ';
|
844 |
+
|
845 |
+
$replace_with = FrmEntryMeta::get_entry_meta_by_field($entry->id, $field->id);
|
846 |
+
|
847 |
+
$atts['entry_id'] = $entry->id;
|
848 |
+
$atts['entry_key'] = $entry->item_key;
|
849 |
+
//$replace_with = apply_filters('frmpro_fields_replace_shortcodes', $replace_with, $tag, $atts, $field);
|
850 |
+
|
851 |
+
if ( is_array($replace_with) ) {
|
852 |
+
$replace_with = implode($sep, $replace_with);
|
853 |
+
}
|
854 |
+
|
855 |
+
if ( isset($atts['show']) && $atts['show'] == 'field_label' ) {
|
856 |
+
$replace_with = $field->name;
|
857 |
+
} else if ( isset($atts['show']) && $atts['show'] == 'description' ) {
|
858 |
+
$replace_with = $field->description;
|
859 |
+
} else if ( empty($replace_with) && $replace_with != '0' ) {
|
860 |
+
$replace_with = '';
|
861 |
+
} else {
|
862 |
+
$replace_with = self::get_display_value($replace_with, $field, $atts);
|
863 |
+
}
|
864 |
+
|
865 |
+
unset($field);
|
866 |
+
break;
|
867 |
}
|
868 |
+
|
869 |
+
if ( isset($replace_with) ) {
|
870 |
+
$content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content );
|
|
|
|
|
|
|
871 |
}
|
872 |
+
|
873 |
+
unset($atts, $conditional, $replace_with);
|
874 |
+
}
|
875 |
+
|
876 |
+
return $content;
|
877 |
+
}
|
878 |
+
|
879 |
+
/**
|
880 |
+
* Get the value to replace a few standard shortcodes
|
881 |
+
*
|
882 |
+
* @since 2.0
|
883 |
+
* @return string
|
884 |
+
*/
|
885 |
+
public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
|
886 |
+
$new_value = '';
|
887 |
+
switch ( $tag ) {
|
888 |
+
case 'admin_email':
|
889 |
+
$new_value = get_option('admin_email');
|
890 |
+
break;
|
891 |
+
case 'siteurl':
|
892 |
+
$new_value = FrmAppHelper::site_url();
|
893 |
+
break;
|
894 |
+
case 'frmurl':
|
895 |
+
$new_value = FrmAppHelper::plugin_url();
|
896 |
+
break;
|
897 |
+
case 'sitename':
|
898 |
+
$new_value = FrmAppHelper::site_name();
|
899 |
+
break;
|
900 |
+
case 'get':
|
901 |
+
$new_value = self::process_get_shortcode( $atts, $return_array );
|
902 |
+
break;
|
903 |
}
|
904 |
+
|
905 |
+
return $new_value;
|
906 |
+
}
|
907 |
+
|
908 |
+
/**
|
909 |
+
* Process the [get] shortcode
|
910 |
+
*
|
911 |
+
* @since 2.0
|
912 |
+
* @return string|array
|
913 |
+
*/
|
914 |
+
public static function process_get_shortcode( $atts, $return_array = false ) {
|
915 |
+
if ( ! isset($atts['param']) ) {
|
916 |
+
return '';
|
917 |
+
}
|
918 |
+
|
919 |
+
if ( strpos($atts['param'], '[') ) {
|
920 |
+
$atts['param'] = str_replace('[', '[', $atts['param']);
|
921 |
+
$atts['param'] = str_replace(']', ']', $atts['param']);
|
922 |
+
}
|
923 |
+
|
924 |
+
$new_value = FrmAppHelper::get_param($atts['param'], '');
|
925 |
+
$new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
|
926 |
+
|
927 |
+
if ( $new_value == '' ) {
|
928 |
+
if ( ! isset($atts['prev_val']) ) {
|
929 |
+
$atts['prev_val'] = '';
|
930 |
+
}
|
931 |
+
|
932 |
+
$new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val'];
|
933 |
+
}
|
934 |
+
|
935 |
+
if ( is_array($new_value) && ! $return_array ) {
|
936 |
+
$new_value = implode(', ', $new_value);
|
937 |
+
}
|
938 |
+
|
939 |
+
return $new_value;
|
940 |
+
}
|
941 |
+
|
942 |
+
public static function get_display_value($replace_with, $field, $atts = array()) {
|
943 |
+
$sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
|
944 |
+
|
945 |
+
$replace_with = apply_filters( 'frm_get_display_value', $replace_with, $field, $atts );
|
946 |
+
|
947 |
+
if ( $field->type == 'textarea' || $field->type == 'rte' ) {
|
948 |
+
$autop = isset($atts['wpautop']) ? $atts['wpautop'] : true;
|
949 |
+
if ( apply_filters('frm_use_wpautop', $autop) ) {
|
950 |
+
if ( is_array($replace_with) ) {
|
951 |
+
$replace_with = implode("\n", $replace_with);
|
952 |
+
}
|
953 |
+
$replace_with = wpautop($replace_with);
|
954 |
+
}
|
955 |
+
unset( $autop );
|
956 |
+
} else if ( is_array( $replace_with ) ) {
|
957 |
+
$replace_with = implode( $sep, $replace_with );
|
958 |
+
}
|
959 |
+
|
960 |
+
return $replace_with;
|
961 |
+
}
|
962 |
+
|
963 |
+
public static function get_field_types($type) {
|
964 |
+
$single_input = array(
|
965 |
+
'text', 'textarea', 'rte', 'number', 'email', 'url',
|
966 |
+
'image', 'file', 'date', 'phone', 'hidden', 'time',
|
967 |
+
'user_id', 'tag', 'password',
|
968 |
+
);
|
969 |
+
$multiple_input = array( 'radio', 'checkbox', 'select', 'scale' );
|
970 |
+
$other_type = array( 'divider', 'html', 'break' );
|
971 |
+
|
972 |
+
$field_selection = array_merge( self::pro_field_selection(), self::field_selection() );
|
973 |
+
|
974 |
+
$field_types = array();
|
975 |
+
if ( in_array($type, $single_input) ) {
|
976 |
+
self::field_types_for_input( $single_input, $field_selection, $field_types );
|
977 |
+
} else if ( in_array($type, $multiple_input) ) {
|
978 |
+
self::field_types_for_input( $multiple_input, $field_selection, $field_types );
|
979 |
+
} else if ( in_array($type, $other_type) ) {
|
980 |
+
self::field_types_for_input( $other_type, $field_selection, $field_types );
|
981 |
+
} else if ( isset( $field_selection[ $type ] ) ) {
|
982 |
+
$field_types[ $type ] = $field_selection[ $type ];
|
983 |
+
}
|
984 |
+
|
985 |
return $field_types;
|
986 |
}
|
987 |
+
|
988 |
+
private static function field_types_for_input( $inputs, $fields, &$field_types ) {
|
989 |
+
foreach ( $inputs as $input ) {
|
990 |
+
$field_types[ $input ] = $fields[ $input ];
|
991 |
+
unset($input);
|
992 |
+
}
|
993 |
+
}
|
994 |
+
|
995 |
+
public static function show_onfocus_js($clear_on_focus){ ?>
|
996 |
+
<a href="javascript:void(0)" class="frm_bstooltip <?php echo ($clear_on_focus) ? '' : 'frm_inactive_icon '; ?>frm_default_val_icons frm_action_icon frm_reload_icon frm_icon_font" title="<?php echo esc_attr($clear_on_focus ? __( 'Clear default value when typing', 'formidable' ) : __( 'Do not clear default value when typing', 'formidable' )); ?>"></a>
|
997 |
<?php
|
998 |
}
|
999 |
+
|
1000 |
+
public static function show_default_blank_js($default_blank){ ?>
|
1001 |
+
<a href="javascript:void(0)" class="frm_bstooltip <?php echo $default_blank ? '' : 'frm_inactive_icon '; ?>frm_default_val_icons frm_action_icon frm_error_icon frm_icon_font" title="<?php echo $default_blank ? esc_attr( 'Default value will NOT pass form validation', 'formidable' ) : esc_attr( 'Default value will pass form validation', 'formidable' ); ?>"></a>
|
1002 |
<?php
|
1003 |
}
|
1004 |
+
|
1005 |
+
public static function switch_field_ids($val) {
|
1006 |
global $frm_duplicate_ids;
|
1007 |
$replace = array();
|
1008 |
$replace_with = array();
|
1009 |
+
foreach ( (array) $frm_duplicate_ids as $old => $new ) {
|
1010 |
$replace[] = '[if '. $old .']';
|
1011 |
$replace_with[] = '[if '. $new .']';
|
1012 |
$replace[] = '[if '. $old .' ';
|
1017 |
$replace_with[] = '['. $new .']';
|
1018 |
$replace[] = '['. $old .' ';
|
1019 |
$replace_with[] = '['. $new .' ';
|
1020 |
+
unset($old, $new);
|
|
|
1021 |
}
|
1022 |
+
if ( is_array( $val ) ) {
|
1023 |
+
foreach ( $val as $k => $v ) {
|
1024 |
+
$val[ $k ] = str_replace( $replace, $replace_with, $v );
|
1025 |
+
unset($k, $v);
|
|
|
1026 |
}
|
1027 |
+
} else {
|
1028 |
$val = str_replace($replace, $replace_with, $val);
|
1029 |
}
|
1030 |
+
|
1031 |
return $val;
|
1032 |
}
|
1033 |
+
|
1034 |
+
public static function get_us_states() {
|
1035 |
+
return apply_filters( 'frm_us_states', array(
|
1036 |
+
'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona',
|
1037 |
+
'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware',
|
1038 |
+
'DC' => 'District of Columbia',
|
1039 |
+
'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho',
|
1040 |
+
'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas',
|
1041 |
+
'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland',
|
1042 |
+
'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi',
|
1043 |
+
'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada',
|
1044 |
+
'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York',
|
1045 |
+
'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma',
|
1046 |
+
'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina',
|
1047 |
+
'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah',
|
1048 |
+
'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia',
|
1049 |
+
'WI' => 'Wisconsin', 'WY' => 'Wyoming',
|
1050 |
+
) );
|
1051 |
+
}
|
1052 |
+
|
1053 |
+
public static function get_countries() {
|
1054 |
+
return apply_filters( 'frm_countries', array(
|
1055 |
+
__( 'Afghanistan', 'formidable' ), __( 'Albania', 'formidable' ), __( 'Algeria', 'formidable' ),
|
1056 |
+
__( 'American Samoa', 'formidable' ), __( 'Andorra', 'formidable' ), __( 'Angola', 'formidable' ),
|
1057 |
+
__( 'Anguilla', 'formidable' ), __( 'Antarctica', 'formidable' ), __( 'Antigua and Barbuda', 'formidable' ),
|
1058 |
+
__( 'Argentina', 'formidable' ), __( 'Armenia', 'formidable' ), __( 'Aruba', 'formidable' ),
|
1059 |
+
__( 'Australia', 'formidable' ), __( 'Austria', 'formidable' ), __( 'Azerbaijan', 'formidable' ),
|
1060 |
+
__( 'Bahamas', 'formidable' ), __( 'Bahrain', 'formidable' ), __( 'Bangladesh', 'formidable' ),
|
1061 |
+
__( 'Barbados', 'formidable' ), __( 'Belarus', 'formidable' ), __( 'Belgium', 'formidable' ),
|
1062 |
+
__( 'Belize', 'formidable' ), __( 'Benin', 'formidable' ), __( 'Bermuda', 'formidable' ),
|
1063 |
+
__( 'Bhutan', 'formidable' ), __( 'Bolivia', 'formidable' ), __( 'Bosnia and Herzegovina', 'formidable' ),
|
1064 |
+
__( 'Botswana', 'formidable' ), __( 'Brazil', 'formidable' ), __( 'Brunei', 'formidable' ),
|
1065 |
+
__( 'Bulgaria', 'formidable' ), __( 'Burkina Faso', 'formidable' ), __( 'Burundi', 'formidable' ),
|
1066 |
+
__( 'Cambodia', 'formidable' ), __( 'Cameroon', 'formidable' ), __( 'Canada', 'formidable' ),
|
1067 |
+
__( 'Cape Verde', 'formidable' ), __( 'Cayman Islands', 'formidable' ), __( 'Central African Republic', 'formidable' ),
|
1068 |
+
__( 'Chad', 'formidable' ), __( 'Chile', 'formidable' ), __( 'China', 'formidable' ),
|
1069 |
+
__( 'Colombia', 'formidable' ), __( 'Comoros', 'formidable' ), __( 'Congo', 'formidable' ),
|
1070 |
+
__( 'Costa Rica', 'formidable' ), __( 'Côte d\'Ivoire', 'formidable' ), __( 'Croatia', 'formidable' ),
|
1071 |
+
__( 'Cuba', 'formidable' ), __( 'Cyprus', 'formidable' ), __( 'Czech Republic', 'formidable' ),
|
1072 |
+
__( 'Denmark', 'formidable' ), __( 'Djibouti', 'formidable' ), __( 'Dominica', 'formidable' ),
|
1073 |
+
__( 'Dominican Republic', 'formidable' ), __( 'East Timor', 'formidable' ), __( 'Ecuador', 'formidable' ),
|
1074 |
+
__( 'Egypt', 'formidable' ), __( 'El Salvador', 'formidable' ), __( 'Equatorial Guinea', 'formidable' ),
|
1075 |
+
__( 'Eritrea', 'formidable' ), __( 'Estonia', 'formidable' ), __( 'Ethiopia', 'formidable' ),
|
1076 |
+
__( 'Fiji', 'formidable' ), __( 'Finland', 'formidable' ), __( 'France', 'formidable' ),
|
1077 |
+
__( 'French Guiana', 'formidable' ), __( 'French Polynesia', 'formidable' ), __( 'Gabon', 'formidable' ),
|
1078 |
+
__( 'Gambia', 'formidable' ), __( 'Georgia', 'formidable' ), __( 'Germany', 'formidable' ),
|
1079 |
+
__( 'Ghana', 'formidable' ), __( 'Gibraltar', 'formidable' ), __( 'Greece', 'formidable' ),
|
1080 |
+
__( 'Greenland', 'formidable' ), __( 'Grenada', 'formidable' ), __( 'Guam', 'formidable' ),
|
1081 |
+
__( 'Guatemala', 'formidable' ), __( 'Guinea', 'formidable' ), __( 'Guinea-Bissau', 'formidable' ),
|
1082 |
+
__( 'Guyana', 'formidable' ), __( 'Haiti', 'formidable' ), __( 'Honduras', 'formidable' ),
|
1083 |
+
__( 'Hong Kong', 'formidable' ), __( 'Hungary', 'formidable' ), __( 'Iceland', 'formidable' ),
|
1084 |
+
__( 'India', 'formidable' ), __( 'Indonesia', 'formidable' ), __( 'Iran', 'formidable' ),
|
1085 |
+
__( 'Iraq', 'formidable' ), __( 'Ireland', 'formidable' ), __( 'Israel', 'formidable' ),
|
1086 |
+
__( 'Italy', 'formidable' ), __( 'Jamaica', 'formidable' ), __( 'Japan', 'formidable' ),
|
1087 |
+
__( 'Jordan', 'formidable' ), __( 'Kazakhstan', 'formidable' ), __( 'Kenya', 'formidable' ),
|
1088 |
+
__( 'Kiribati', 'formidable' ), __( 'North Korea', 'formidable' ), __( 'South Korea', 'formidable' ),
|
1089 |
+
__( 'Kuwait', 'formidable' ), __( 'Kyrgyzstan', 'formidable' ), __( 'Laos', 'formidable' ),
|
1090 |
+
__( 'Latvia', 'formidable' ), __( 'Lebanon', 'formidable' ), __( 'Lesotho', 'formidable' ),
|
1091 |
+
__( 'Liberia', 'formidable' ), __( 'Libya', 'formidable' ), __( 'Liechtenstein', 'formidable' ),
|
1092 |
+
__( 'Lithuania', 'formidable' ), __( 'Luxembourg', 'formidable' ), __( 'Macedonia', 'formidable' ),
|
1093 |
+
__( 'Madagascar', 'formidable' ), __( 'Malawi', 'formidable' ), __( 'Malaysia', 'formidable' ),
|
1094 |
+
__( 'Maldives', 'formidable' ), __( 'Mali', 'formidable' ), __( 'Malta', 'formidable' ),
|
1095 |
+
__( 'Marshall Islands', 'formidable' ), __( 'Mauritania', 'formidable' ), __( 'Mauritius', 'formidable' ),
|
1096 |
+
__( 'Mexico', 'formidable' ), __( 'Micronesia', 'formidable' ), __( 'Moldova', 'formidable' ),
|
1097 |
+
__( 'Monaco', 'formidable' ), __( 'Mongolia', 'formidable' ), __( 'Montenegro', 'formidable' ),
|
1098 |
+
__( 'Montserrat', 'formidable' ), __( 'Morocco', 'formidable' ), __( 'Mozambique', 'formidable' ),
|
1099 |
+
__( 'Myanmar', 'formidable' ), __( 'Namibia', 'formidable' ), __( 'Nauru', 'formidable' ),
|
1100 |
+
__( 'Nepal', 'formidable' ), __( 'Netherlands', 'formidable' ), __( 'New Zealand', 'formidable' ),
|
1101 |
+
__( 'Nicaragua', 'formidable' ), __( 'Niger', 'formidable' ), __( 'Nigeria', 'formidable' ),
|
1102 |
+
__( 'Norway', 'formidable' ), __( 'Northern Mariana Islands', 'formidable' ), __( 'Oman', 'formidable' ),
|
1103 |
+
__( 'Pakistan', 'formidable' ), __( 'Palau', 'formidable' ), __( 'Palestine', 'formidable' ),
|
1104 |
+
__( 'Panama', 'formidable' ), __( 'Papua New Guinea', 'formidable' ), __( 'Paraguay', 'formidable' ),
|
1105 |
+
__( 'Peru', 'formidable' ), __( 'Philippines', 'formidable' ), __( 'Poland', 'formidable' ),
|
1106 |
+
__( 'Portugal', 'formidable' ), __( 'Puerto Rico', 'formidable' ), __( 'Qatar', 'formidable' ),
|
1107 |
+
__( 'Romania', 'formidable' ), __( 'Russia', 'formidable' ), __( 'Rwanda', 'formidable' ),
|
1108 |
+
__( 'Saint Kitts and Nevis', 'formidable' ), __( 'Saint Lucia', 'formidable' ),
|
1109 |
+
__( 'Saint Vincent and the Grenadines', 'formidable' ), __( 'Samoa', 'formidable' ),
|
1110 |
+
__( 'San Marino', 'formidable' ), __( 'Sao Tome and Principe', 'formidable' ), __( 'Saudi Arabia', 'formidable' ),
|
1111 |
+
__( 'Senegal', 'formidable' ), __( 'Serbia and Montenegro', 'formidable' ), __( 'Seychelles', 'formidable' ),
|
1112 |
+
__( 'Sierra Leone', 'formidable' ), __( 'Singapore', 'formidable' ), __( 'Slovakia', 'formidable' ),
|
1113 |
+
__( 'Slovenia', 'formidable' ), __( 'Solomon Islands', 'formidable' ), __( 'Somalia', 'formidable' ),
|
1114 |
+
__( 'South Africa', 'formidable' ), __( 'South Sudan', 'formidable' ),
|
1115 |
+
__( 'Spain', 'formidable' ), __( 'Sri Lanka', 'formidable' ),
|
1116 |
+
__( 'Sudan', 'formidable' ), __( 'Suriname', 'formidable' ), __( 'Swaziland', 'formidable' ),
|
1117 |
+
__( 'Sweden', 'formidable' ), __( 'Switzerland', 'formidable' ), __( 'Syria', 'formidable' ),
|
1118 |
+
__( 'Taiwan', 'formidable' ), __( 'Tajikistan', 'formidable' ), __( 'Tanzania', 'formidable' ),
|
1119 |
+
__( 'Thailand', 'formidable' ), __( 'Togo', 'formidable' ), __( 'Tonga', 'formidable' ),
|
1120 |
+
__( 'Trinidad and Tobago', 'formidable' ), __( 'Tunisia', 'formidable' ), __( 'Turkey', 'formidable' ),
|
1121 |
+
__( 'Turkmenistan', 'formidable' ), __( 'Tuvalu', 'formidable' ), __( 'Uganda', 'formidable' ),
|
1122 |
+
__( 'Ukraine', 'formidable' ), __( 'United Arab Emirates', 'formidable' ), __( 'United Kingdom', 'formidable' ),
|
1123 |
+
__( 'United States', 'formidable' ), __( 'Uruguay', 'formidable' ), __( 'Uzbekistan', 'formidable' ),
|
1124 |
+
__( 'Vanuatu', 'formidable' ), __( 'Vatican City', 'formidable' ), __( 'Venezuela', 'formidable' ),
|
1125 |
+
__( 'Vietnam', 'formidable' ), __( 'Virgin Islands, British', 'formidable' ),
|
1126 |
+
__( 'Virgin Islands, U.S.', 'formidable' ), __( 'Yemen', 'formidable' ), __( 'Zambia', 'formidable' ),
|
1127 |
+
__( 'Zimbabwe', 'formidable' ),
|
1128 |
+
) );
|
1129 |
+
}
|
1130 |
+
|
1131 |
+
public static function get_bulk_prefilled_opts(array &$prepop) {
|
1132 |
+
$prepop[__( 'Countries', 'formidable' )] = FrmFieldsHelper::get_countries();
|
1133 |
+
|
1134 |
+
$states = FrmFieldsHelper::get_us_states();
|
1135 |
+
$state_abv = array_keys($states);
|
1136 |
+
sort($state_abv);
|
1137 |
+
$prepop[__( 'U.S. State Abbreviations', 'formidable' )] = $state_abv;
|
1138 |
+
|
1139 |
+
$states = array_values($states);
|
1140 |
+
sort($states);
|
1141 |
+
$prepop[__( 'U.S. States', 'formidable' )] = $states;
|
1142 |
+
unset($state_abv, $states);
|
1143 |
+
|
1144 |
+
$prepop[__( 'Age', 'formidable' )] = array(
|
1145 |
+
__( 'Under 18', 'formidable' ), __( '18-24', 'formidable' ), __( '25-34', 'formidable' ),
|
1146 |
+
__( '35-44', 'formidable' ), __( '45-54', 'formidable' ), __( '55-64', 'formidable' ),
|
1147 |
+
__( '65 or Above', 'formidable' ), __( 'Prefer Not to Answer', 'formidable' ),
|
1148 |
+
);
|
1149 |
+
|
1150 |
+
$prepop[__( 'Satisfaction', 'formidable' )] = array(
|
1151 |
+
__( 'Very Satisfied', 'formidable' ), __( 'Satisfied', 'formidable' ), __( 'Neutral', 'formidable' ),
|
1152 |
+
__( 'Unsatisfied', 'formidable' ), __( 'Very Unsatisfied', 'formidable' ), __( 'N/A', 'formidable' ),
|
1153 |
+
);
|
1154 |
+
|
1155 |
+
$prepop[__( 'Importance', 'formidable' )] = array(
|
1156 |
+
__( 'Very Important', 'formidable' ), __( 'Important', 'formidable' ), __( 'Neutral', 'formidable' ),
|
1157 |
+
__( 'Somewhat Important', 'formidable' ), __( 'Not at all Important', 'formidable' ), __( 'N/A', 'formidable' ),
|
1158 |
+
);
|
1159 |
+
|
1160 |
+
$prepop[__( 'Agreement', 'formidable' )] = array(
|
1161 |
+
__( 'Strongly Agree', 'formidable' ), __( 'Agree', 'formidable' ), __( 'Neutral', 'formidable' ),
|
1162 |
+
__( 'Disagree', 'formidable' ), __( 'Strongly Disagree', 'formidable' ), __( 'N/A', 'formidable' ),
|
1163 |
+
);
|
1164 |
+
|
1165 |
+
$prepop = apply_filters('frm_bulk_field_choices', $prepop);
|
1166 |
+
}
|
1167 |
}
|
classes/helpers/FrmFormActionsHelper.php
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
5 |
+
|
6 |
+
class FrmFormActionsHelper {
|
7 |
+
|
8 |
+
public static function get_action_for_form($form_id, $type = 'all', $limit = 99) {
|
9 |
+
$action_controls = FrmFormActionsController::get_form_actions( $type );
|
10 |
+
if ( empty($action_controls) ) {
|
11 |
+
// don't continue if there are no available actions
|
12 |
+
return array();
|
13 |
+
}
|
14 |
+
|
15 |
+
if ( 'all' != $type ) {
|
16 |
+
return $action_controls->get_all( $form_id, $limit );
|
17 |
+
}
|
18 |
+
|
19 |
+
$args = array(
|
20 |
+
'post_type' => FrmFormActionsController::$action_post_type,
|
21 |
+
'post_status' => 'publish',
|
22 |
+
'numberposts' => 99,
|
23 |
+
'orderby' => 'title',
|
24 |
+
'order' => 'ASC',
|
25 |
+
);
|
26 |
+
|
27 |
+
if ( $form_id ) {
|
28 |
+
$args['menu_order'] = $form_id;
|
29 |
+
}
|
30 |
+
|
31 |
+
$actions = FrmAppHelper::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
|
32 |
+
|
33 |
+
if ( ! $actions ) {
|
34 |
+
return array();
|
35 |
+
}
|
36 |
+
|
37 |
+
$settings = array();
|
38 |
+
foreach ( $actions as $action ) {
|
39 |
+
if ( ! isset( $action_controls[ $action->post_excerpt ] ) || count( $settings ) >= $limit ) {
|
40 |
+
continue;
|
41 |
+
}
|
42 |
+
|
43 |
+
$action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
|
44 |
+
|
45 |
+
$settings[ $action->ID ] = $action;
|
46 |
+
}
|
47 |
+
|
48 |
+
if ( 1 === $limit ) {
|
49 |
+
$settings = reset($settings);
|
50 |
+
}
|
51 |
+
|
52 |
+
return $settings;
|
53 |
+
}
|
54 |
+
|
55 |
+
public static function action_conditions_met($action, $entry) {
|
56 |
+
$notification = $action->post_content;
|
57 |
+
$stop = false;
|
58 |
+
$met = array();
|
59 |
+
|
60 |
+
if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
|
61 |
+
return $stop;
|
62 |
+
}
|
63 |
+
|
64 |
+
foreach ( $notification['conditions'] as $k => $condition ) {
|
65 |
+
if ( ! is_numeric( $k ) ) {
|
66 |
+
continue;
|
67 |
+
}
|
68 |
+
|
69 |
+
if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
|
70 |
+
continue;
|
71 |
+
}
|
72 |
+
|
73 |
+
if ( is_array($condition['hide_opt']) ) {
|
74 |
+
$condition['hide_opt'] = reset($condition['hide_opt']);
|
75 |
+
}
|
76 |
+
|
77 |
+
$observed_value = isset( $entry->metas[ $condition['hide_field'] ] ) ? $entry->metas[ $condition['hide_field'] ] : '';
|
78 |
+
if ( $condition['hide_opt'] == 'current_user' ) {
|
79 |
+
$condition['hide_opt'] = get_current_user_id();
|
80 |
+
}
|
81 |
+
|
82 |
+
$stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']);
|
83 |
+
|
84 |
+
if ( $notification['conditions']['send_stop'] == 'send' ) {
|
85 |
+
$stop = $stop ? false : true;
|
86 |
+
}
|
87 |
+
|
88 |
+
$met[ $stop ] = $stop;
|
89 |
+
}
|
90 |
+
|
91 |
+
if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
|
92 |
+
$stop = ($notification['conditions']['send_stop'] == 'send') ? true : false;
|
93 |
+
} else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) {
|
94 |
+
$stop = false;
|
95 |
+
}
|
96 |
+
|
97 |
+
return $stop;
|
98 |
+
}
|
99 |
+
|
100 |
+
public static function default_action_opts($class = '') {
|
101 |
+
return array(
|
102 |
+
'classes' => 'frm_icon_font '. $class,
|
103 |
+
'active' => false,
|
104 |
+
'limit' => 0,
|
105 |
+
);
|
106 |
+
}
|
107 |
+
}
|
classes/helpers/FrmFormsHelper.php
CHANGED
@@ -1,296 +1,587 @@
|
|
1 |
<?php
|
2 |
-
if(!defined('ABSPATH'))
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
class FrmFormsHelper{
|
8 |
public static function get_direct_link($key, $form = false ) {
|
9 |
$target_url = esc_url(admin_url('admin-ajax.php') . '?action=frm_forms_preview&form='. $key);
|
10 |
$target_url = apply_filters('frm_direct_link', $target_url, $key, $form);
|
11 |
|
12 |
return $target_url;
|
13 |
}
|
14 |
-
|
15 |
-
public static function
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
?>
|
20 |
-
<select
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
$forms = $frm_form->getAll($where, ' ORDER BY name');
|
36 |
-
?>
|
37 |
-
<select name="<?php echo $field_name; ?>" id="<?php echo $field_id ?>" <?php if ($onchange) echo 'onchange="'. $onchange .'"'; ?>>
|
38 |
-
<?php if ($blank){ ?>
|
39 |
-
<option value=""><?php echo ($blank == 1) ? '' : '- '. $blank .' -'; ?></option>
|
40 |
-
<?php } ?>
|
41 |
-
<?php foreach($forms as $form){ ?>
|
42 |
-
<option value="<?php echo $form->id; ?>" <?php selected($field_value, $form->id); ?>><?php echo FrmAppHelper::truncate($form->name, 33); ?></option>
|
43 |
-
<?php } ?>
|
44 |
</select>
|
45 |
<?php
|
46 |
}
|
47 |
-
|
48 |
-
public static function form_switcher(){
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
$
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
if(isset($_GET['page']) and $_GET['page'] == 'formidable-entries' and isset($_GET['frm_action']) and in_array($_GET['frm_action'], array('edit', 'show', 'destroy_all'))){
|
62 |
$args['frm_action'] = 'list';
|
63 |
$args['form'] = 0;
|
64 |
-
|
65 |
$args['frm_action'] = 'edit';
|
66 |
-
|
67 |
$args['form'] = 0;
|
68 |
$base = admin_url('edit.php?post_type=frm_display');
|
69 |
}
|
70 |
|
71 |
?>
|
72 |
<li class="dropdown last" id="frm_bs_dropdown">
|
73 |
-
<a href="#" id="frm-navbarDrop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e('Switch Form', 'formidable') ?> <b class="caret"></b></a>
|
74 |
-
<ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-navbarDrop">
|
75 |
-
<?php
|
76 |
-
|
|
|
77 |
$args['id'] = $form->id;
|
78 |
-
|
|
|
79 |
$args['form'] = $form->id;
|
|
|
80 |
?>
|
81 |
-
<li><a href="<?php echo isset($base) ? add_query_arg($args, $base) : add_query_arg($args); ?>" tabindex="-1"><?php echo empty($form->name) ? __('(no title)') : FrmAppHelper::truncate($form->name, 33); ?></a></li>
|
82 |
<?php
|
83 |
-
|
84 |
-
|
85 |
</ul>
|
86 |
</li>
|
87 |
<?php
|
88 |
}
|
89 |
-
|
90 |
-
public static function get_sortable_classes($col, $sort_col, $sort_dir){
|
91 |
-
echo ($sort_col == $col) ? 'sorted' : 'sortable';
|
92 |
-
echo ($sort_col == $col
|
93 |
}
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
99 |
$post_values = $values;
|
100 |
-
}else{
|
101 |
$values = array();
|
102 |
$post_values = isset($_POST) ? $_POST : array();
|
103 |
}
|
104 |
-
|
105 |
-
foreach (array('name' => '', 'description' => '') as $var => $default){
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
}
|
109 |
-
|
110 |
-
if(
|
111 |
-
$values['
|
112 |
-
|
113 |
-
foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0) as $var => $default){
|
114 |
-
if(!isset($values[$var]))
|
115 |
-
$values[$var] = FrmAppHelper::get_param($var, $default);
|
116 |
}
|
117 |
-
|
118 |
-
if(!isset($values['form_key']))
|
119 |
-
$values['form_key'] = ($post_values and isset($post_values['form_key'])) ? $post_values['form_key'] : FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_forms', 'form_key');
|
120 |
-
|
121 |
$values = self::fill_default_opts($values, false, $post_values);
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
128 |
return apply_filters('frm_setup_new_form_vars', $values);
|
129 |
}
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
134 |
|
135 |
$values['form_key'] = isset($post_values['form_key']) ? $post_values['form_key'] : $record->form_key;
|
136 |
$values['default_template'] = isset($post_values['default_template']) ? $post_values['default_template'] : $record->default_template;
|
137 |
$values['is_template'] = isset($post_values['is_template']) ? $post_values['is_template'] : $record->is_template;
|
138 |
-
|
|
|
139 |
$values = self::fill_default_opts($values, $record, $post_values);
|
140 |
|
141 |
return apply_filters('frm_setup_edit_form_vars', $values);
|
142 |
}
|
143 |
-
|
144 |
public static function fill_default_opts($values, $record, $post_values) {
|
145 |
-
|
146 |
-
$defaults =
|
147 |
-
|
148 |
if ( is_array($default) ) {
|
149 |
-
if(!isset($values[$var]))
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
156 |
foreach ( $v as $k1 => $v1 ) {
|
157 |
-
|
158 |
-
unset($k1);
|
159 |
-
unset($v1);
|
160 |
}
|
161 |
}
|
162 |
-
|
163 |
-
unset($k);
|
164 |
-
unset($v);
|
165 |
}
|
166 |
-
|
167 |
-
}else{
|
168 |
$values[$var] = ($post_values && isset($post_values['options'][$var])) ? $post_values['options'][$var] : (($record && isset($record->options[$var])) ? $record->options[$var] : $default);
|
169 |
}
|
170 |
-
|
171 |
-
unset($var);
|
172 |
-
unset($default);
|
173 |
}
|
174 |
-
|
175 |
return $values;
|
176 |
}
|
177 |
-
|
178 |
-
public static function get_default_opts(){
|
179 |
-
|
180 |
-
|
181 |
return array(
|
182 |
-
'notification' => array(
|
183 |
-
array(
|
184 |
-
'email_to' => $frm_settings->email_to, 'reply_to' => '', 'reply_to_name' => '',
|
185 |
-
'cust_reply_to' => '', 'cust_reply_to_name' => '',
|
186 |
-
'email_subject' => '', 'email_message' => '[default-message]',
|
187 |
-
'inc_user_info' => 0, 'plain_text' => 0,
|
188 |
-
)
|
189 |
-
),
|
190 |
'submit_value' => $frm_settings->submit_value, 'success_action' => 'message',
|
191 |
'success_msg' => $frm_settings->success_msg, 'show_form' => 0, 'akismet' => '',
|
192 |
-
'no_save' => 0, 'ajax_load' => 0
|
|
|
|
|
|
|
193 |
);
|
194 |
}
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
199 |
$draft_link = self::get_draft_link();
|
200 |
$img = '[frmurl]/images/ajax_loader.gif';
|
201 |
$default_html = <<<SUBMIT_HTML
|
202 |
<div class="frm_submit">
|
203 |
[if back_button]<input type="button" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook] />[/if back_button]
|
204 |
<input type="submit" value="[button_label]" [button_action] />
|
205 |
-
<img class="frm_ajax_loading" src="$img" alt="$sending"
|
206 |
$draft_link
|
207 |
</div>
|
208 |
SUBMIT_HTML;
|
209 |
-
|
210 |
$default_html = <<<BEFORE_HTML
|
211 |
[if form_name]<h3>[form_name]</h3>[/if form_name]
|
212 |
[if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
|
213 |
BEFORE_HTML;
|
214 |
-
|
215 |
$default_html = '';
|
216 |
}
|
217 |
-
|
218 |
return $default_html;
|
219 |
}
|
220 |
-
|
221 |
-
public static function get_draft_link(){
|
222 |
-
$link = '[if save_draft]<a class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
|
223 |
return $link;
|
224 |
}
|
225 |
-
|
226 |
-
public static function get_custom_submit($html, $form, $submit, $form_action, $values){
|
227 |
-
$button =
|
228 |
-
if(strpos($button, '[button_action]')){
|
229 |
-
|
230 |
-
echo $button_parts[0];
|
231 |
-
//echo ' id="frm_submit_"';
|
232 |
-
$classes = apply_filters('frm_submit_button_class', array(), $form);
|
233 |
-
if(!empty($classes))
|
234 |
-
echo ' class="'. implode(' ', $classes) .'"';
|
235 |
-
|
236 |
-
do_action('frm_submit_button_action', $form, $form_action);
|
237 |
-
echo $button_parts[1];
|
238 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
}
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
}
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
}
|
260 |
-
|
|
|
261 |
}
|
262 |
-
|
263 |
//replace [form_key]
|
264 |
$html = str_replace('[form_key]', $form->form_key, $html);
|
265 |
-
|
266 |
//replace [frmurl]
|
267 |
-
$html = str_replace('[frmurl]',
|
268 |
-
|
269 |
-
|
|
|
270 |
$replace_with = apply_filters('frm_submit_button', $title, $form);
|
271 |
$html = str_replace('[button_label]', $replace_with, $html);
|
272 |
}
|
273 |
-
|
274 |
$html = apply_filters('frm_form_replace_shortcodes', $html, $form, $values);
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
|
|
|
|
282 |
return $html;
|
283 |
}
|
284 |
-
|
285 |
-
public static function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
global $frm_vars;
|
287 |
$small_form = new stdClass();
|
288 |
-
foreach ( array('id', 'form_key', 'name' ) as $var ) {
|
289 |
$small_form->{$var} = $form->{$var};
|
290 |
unset($var);
|
291 |
}
|
292 |
-
|
293 |
$frm_vars['forms_loaded'][] = $small_form;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
}
|
295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
}
|
1 |
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
5 |
|
6 |
+
class FrmFormsHelper {
|
7 |
+
/**
|
8 |
+
* If $form is numeric, get the form object
|
9 |
+
* @param object|int $form
|
10 |
+
*/
|
11 |
+
public static function maybe_get_form( &$form ) {
|
12 |
+
if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) {
|
13 |
+
$form = FrmForm::getOne($form);
|
14 |
+
}
|
15 |
+
}
|
16 |
|
|
|
17 |
public static function get_direct_link($key, $form = false ) {
|
18 |
$target_url = esc_url(admin_url('admin-ajax.php') . '?action=frm_forms_preview&form='. $key);
|
19 |
$target_url = apply_filters('frm_direct_link', $target_url, $key, $form);
|
20 |
|
21 |
return $target_url;
|
22 |
}
|
23 |
+
|
24 |
+
public static function forms_dropdown( $field_name, $field_value = '', $args = array() ) {
|
25 |
+
$defaults = array(
|
26 |
+
'blank' => true,
|
27 |
+
'field_id' => false,
|
28 |
+
'onchange' => false,
|
29 |
+
'exclude' => false,
|
30 |
+
'class' => '',
|
31 |
+
);
|
32 |
+
$args = wp_parse_args( $args, $defaults );
|
33 |
+
|
34 |
+
if ( ! $args['field_id'] ) {
|
35 |
+
$args['field_id'] = $field_name;
|
36 |
}
|
37 |
+
|
38 |
+
$query = array();
|
39 |
+
if ( $args['exclude'] ) {
|
40 |
+
$query['id !'] = $args['exclude'];
|
41 |
+
}
|
42 |
+
|
43 |
+
$where = apply_filters('frm_forms_dropdown', $query, $field_name);
|
44 |
+
$forms = FrmForm::get_published_forms( $where );
|
45 |
?>
|
46 |
+
<select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $args['field_id'] ) ?>" <?php
|
47 |
+
if ( $args['onchange'] ) {
|
48 |
+
echo ' onchange="' . esc_attr( $args['onchange'] ) . '"';
|
49 |
+
}
|
50 |
+
if ( ! empty( $args['class'] ) ) {
|
51 |
+
echo ' class="' . esc_attr( $args['class'] ) . '"';
|
52 |
+
} ?>>
|
53 |
+
<?php if ( $args['blank'] ) { ?>
|
54 |
+
<option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option>
|
55 |
+
<?php } ?>
|
56 |
+
<?php foreach ( $forms as $form ) { ?>
|
57 |
+
<option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>><?php
|
58 |
+
echo '' == $form->name ? __( '(no title)', 'formidable' ) : esc_attr( FrmAppHelper::truncate( $form->name, 33 ) );
|
59 |
+
?></option>
|
60 |
+
<?php } ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
</select>
|
62 |
<?php
|
63 |
}
|
64 |
+
|
65 |
+
public static function form_switcher() {
|
66 |
+
$where = apply_filters( 'frm_forms_dropdown', array(), '' );
|
67 |
+
$forms = FrmForm::get_published_forms( $where );
|
68 |
+
|
69 |
+
$args = array( 'id' => 0, 'form' => 0);
|
70 |
+
if ( isset( $_GET['id'] ) && ! isset( $_GET['form'] ) ) {
|
71 |
+
unset( $args['form'] );
|
72 |
+
} else if ( isset( $_GET['form']) && ! isset( $_GET['id'] ) ) {
|
73 |
+
unset( $args['id'] );
|
74 |
+
}
|
75 |
+
|
76 |
+
if ( FrmAppHelper::is_admin_page('formidable-entries') && isset($_GET['frm_action']) && in_array($_GET['frm_action'], array( 'edit', 'show', 'destroy_all')) ) {
|
|
|
|
|
77 |
$args['frm_action'] = 'list';
|
78 |
$args['form'] = 0;
|
79 |
+
} else if ( FrmAppHelper::is_admin_page('formidable' ) && isset( $_GET['frm_action'] ) && in_array( $_GET['frm_action'], array( 'new', 'duplicate' ) ) ) {
|
80 |
$args['frm_action'] = 'edit';
|
81 |
+
} else if ( isset( $_GET['post'] ) ) {
|
82 |
$args['form'] = 0;
|
83 |
$base = admin_url('edit.php?post_type=frm_display');
|
84 |
}
|
85 |
|
86 |
?>
|
87 |
<li class="dropdown last" id="frm_bs_dropdown">
|
88 |
+
<a href="#" id="frm-navbarDrop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e( 'Switch Form', 'formidable' ) ?> <b class="caret"></b></a>
|
89 |
+
<ul class="frm-dropdown-menu frm-on-top" role="menu" aria-labelledby="frm-navbarDrop">
|
90 |
+
<?php
|
91 |
+
foreach ( $forms as $form ) {
|
92 |
+
if ( isset( $args['id'] ) ) {
|
93 |
$args['id'] = $form->id;
|
94 |
+
}
|
95 |
+
if ( isset( $args['form'] ) ) {
|
96 |
$args['form'] = $form->id;
|
97 |
+
}
|
98 |
?>
|
99 |
+
<li><a href="<?php echo isset($base) ? add_query_arg($args, $base) : add_query_arg($args); ?>" tabindex="-1"><?php echo empty($form->name) ? __( '(no title)') : FrmAppHelper::truncate($form->name, 33); ?></a></li>
|
100 |
<?php
|
101 |
+
unset( $form );
|
102 |
+
} ?>
|
103 |
</ul>
|
104 |
</li>
|
105 |
<?php
|
106 |
}
|
107 |
+
|
108 |
+
public static function get_sortable_classes($col, $sort_col, $sort_dir) {
|
109 |
+
echo ($sort_col == $col) ? 'sorted' : 'sortable';
|
110 |
+
echo ($sort_col == $col && $sort_dir == 'desc') ? ' asc' : ' desc';
|
111 |
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Used when a form is created
|
115 |
+
*/
|
116 |
+
public static function setup_new_vars( $values = array() ) {
|
117 |
+
global $wpdb;
|
118 |
+
|
119 |
+
if ( ! empty( $values ) ) {
|
120 |
$post_values = $values;
|
121 |
+
} else {
|
122 |
$values = array();
|
123 |
$post_values = isset($_POST) ? $_POST : array();
|
124 |
}
|
125 |
+
|
126 |
+
foreach ( array( 'name' => '', 'description' => '') as $var => $default) {
|
127 |
+
if ( ! isset( $values[ $var ] ) ) {
|
128 |
+
$values[ $var ] = FrmAppHelper::get_param( $var, $default );
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
$values['description'] = FrmAppHelper::use_wpautop($values['description']);
|
133 |
+
|
134 |
+
foreach ( array( 'form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0, 'status' => 'draft', 'parent_form_id' => 0) as $var => $default) {
|
135 |
+
if ( ! isset( $values[ $var ] ) ) {
|
136 |
+
$values[ $var ] = FrmAppHelper::get_param( $var, $default );
|
137 |
+
}
|
138 |
}
|
139 |
+
|
140 |
+
if ( ! isset( $values['form_key'] ) ) {
|
141 |
+
$values['form_key'] = ($post_values && isset($post_values['form_key'])) ? $post_values['form_key'] : FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_forms', 'form_key');
|
|
|
|
|
|
|
|
|
142 |
}
|
143 |
+
|
|
|
|
|
|
|
144 |
$values = self::fill_default_opts($values, false, $post_values);
|
145 |
+
|
146 |
+
if ( $post_values && isset($post_values['options']['custom_style']) ) {
|
147 |
+
$values['custom_style'] = $post_values['options']['custom_style'];
|
148 |
+
} else {
|
149 |
+
$frm_settings = FrmAppHelper::get_settings();
|
150 |
+
$values['custom_style'] = ( $frm_settings->load_style != 'none' );
|
151 |
+
}
|
152 |
+
|
153 |
return apply_filters('frm_setup_new_form_vars', $values);
|
154 |
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Used when editing a form
|
158 |
+
*/
|
159 |
+
public static function setup_edit_vars( $values, $record, $post_values = array() ) {
|
160 |
+
if ( empty( $post_values ) ) {
|
161 |
+
$post_values = stripslashes_deep( $_POST );
|
162 |
+
}
|
163 |
|
164 |
$values['form_key'] = isset($post_values['form_key']) ? $post_values['form_key'] : $record->form_key;
|
165 |
$values['default_template'] = isset($post_values['default_template']) ? $post_values['default_template'] : $record->default_template;
|
166 |
$values['is_template'] = isset($post_values['is_template']) ? $post_values['is_template'] : $record->is_template;
|
167 |
+
$values['status'] = $record->status;
|
168 |
+
|
169 |
$values = self::fill_default_opts($values, $record, $post_values);
|
170 |
|
171 |
return apply_filters('frm_setup_edit_form_vars', $values);
|
172 |
}
|
173 |
+
|
174 |
public static function fill_default_opts($values, $record, $post_values) {
|
175 |
+
|
176 |
+
$defaults = self::get_default_opts();
|
177 |
+
foreach ( $defaults as $var => $default ) {
|
178 |
if ( is_array($default) ) {
|
179 |
+
if ( ! isset( $values[ $var ] ) ) {
|
180 |
+
$values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array();
|
181 |
+
}
|
182 |
+
|
183 |
+
foreach ( $default as $k => $v ) {
|
184 |
+
$values[ $var ][ $k ] = ( $post_values && isset( $post_values[ $var ][ $k ] ) ) ? $post_values[ $var ][ $k ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ) ? $record->options[ $var ][ $k ] : $v);
|
185 |
+
|
186 |
+
if ( is_array( $v ) ) {
|
187 |
foreach ( $v as $k1 => $v1 ) {
|
188 |
+
$values[ $var ][ $k ][ $k1 ] = ( $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ) ? $post_values[ $var ][ $k ][ $k1 ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 );
|
189 |
+
unset( $k1, $v1 );
|
|
|
190 |
}
|
191 |
}
|
192 |
+
|
193 |
+
unset($k, $v);
|
|
|
194 |
}
|
195 |
+
} else {
|
|
|
196 |
$values[$var] = ($post_values && isset($post_values['options'][$var])) ? $post_values['options'][$var] : (($record && isset($record->options[$var])) ? $record->options[$var] : $default);
|
197 |
}
|
198 |
+
|
199 |
+
unset($var, $default);
|
|
|
200 |
}
|
201 |
+
|
202 |
return $values;
|
203 |
}
|
204 |
+
|
205 |
+
public static function get_default_opts() {
|
206 |
+
$frm_settings = FrmAppHelper::get_settings();
|
207 |
+
|
208 |
return array(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
'submit_value' => $frm_settings->submit_value, 'success_action' => 'message',
|
210 |
'success_msg' => $frm_settings->success_msg, 'show_form' => 0, 'akismet' => '',
|
211 |
+
'no_save' => 0, 'ajax_load' => 0, 'form_class' => '', 'custom_style' => 1,
|
212 |
+
'before_html' => self::get_default_html('before'),
|
213 |
+
'after_html' => '',
|
214 |
+
'submit_html' => self::get_default_html('submit'),
|
215 |
);
|
216 |
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* @param string $loc
|
220 |
+
*/
|
221 |
+
public static function get_default_html($loc) {
|
222 |
+
if ( $loc == 'submit' ) {
|
223 |
+
$sending = __( 'Sending', 'formidable' );
|
224 |
$draft_link = self::get_draft_link();
|
225 |
$img = '[frmurl]/images/ajax_loader.gif';
|
226 |
$default_html = <<<SUBMIT_HTML
|
227 |
<div class="frm_submit">
|
228 |
[if back_button]<input type="button" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook] />[/if back_button]
|
229 |
<input type="submit" value="[button_label]" [button_action] />
|
230 |
+
<img class="frm_ajax_loading" src="$img" alt="$sending"/>
|
231 |
$draft_link
|
232 |
</div>
|
233 |
SUBMIT_HTML;
|
234 |
+
} else if ( $loc == 'before' ) {
|
235 |
$default_html = <<<BEFORE_HTML
|
236 |
[if form_name]<h3>[form_name]</h3>[/if form_name]
|
237 |
[if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
|
238 |
BEFORE_HTML;
|
239 |
+
} else {
|
240 |
$default_html = '';
|
241 |
}
|
242 |
+
|
243 |
return $default_html;
|
244 |
}
|
245 |
+
|
246 |
+
public static function get_draft_link() {
|
247 |
+
$link = '[if save_draft]<a href="javascript:void(0)" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
|
248 |
return $link;
|
249 |
}
|
250 |
+
|
251 |
+
public static function get_custom_submit($html, $form, $submit, $form_action, $values) {
|
252 |
+
$button = self::replace_shortcodes($html, $form, $submit, $form_action, $values);
|
253 |
+
if ( ! strpos($button, '[button_action]') ) {
|
254 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
}
|
256 |
+
|
257 |
+
$button_parts = explode('[button_action]', $button);
|
258 |
+
echo $button_parts[0];
|
259 |
+
//echo ' id="frm_submit_"';
|
260 |
+
|
261 |
+
$classes = apply_filters('frm_submit_button_class', array(), $form);
|
262 |
+
if ( ! empty($classes) ) {
|
263 |
+
echo ' class="'. implode(' ', $classes) .'"';
|
264 |
+
}
|
265 |
+
|
266 |
+
do_action('frm_submit_button_action', $form, $form_action);
|
267 |
+
echo $button_parts[1];
|
268 |
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Automatically add end section fields if they don't exist (2.0 migration)
|
272 |
+
* @since 2.0
|
273 |
+
*
|
274 |
+
* @param boolean $reset_fields
|
275 |
+
*/
|
276 |
+
public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
|
277 |
+
if ( empty( $fields ) ) {
|
278 |
+
return;
|
279 |
+
}
|
280 |
+
|
281 |
+
$end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) );
|
282 |
+
$open = $prev_order = false;
|
283 |
+
$add_order = 0;
|
284 |
+
foreach ( $fields as $field ) {
|
285 |
+
if ( $prev_order === $field->field_order ) {
|
286 |
+
$add_order++;
|
287 |
+
}
|
288 |
+
|
289 |
+
if ( $add_order ) {
|
290 |
+
$reset_fields = true;
|
291 |
+
$field->field_order = $field->field_order + $add_order;
|
292 |
+
FrmField::update( $field->id, array( 'field_order' => $field->field_order ) );
|
293 |
+
}
|
294 |
+
|
295 |
+
switch ( $field->type ) {
|
296 |
+
case 'divider':
|
297 |
+
// create an end section if open
|
298 |
+
self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $field );
|
299 |
+
|
300 |
+
// mark it open for the next end section
|
301 |
+
$open = true;
|
302 |
+
break;
|
303 |
+
case 'break';
|
304 |
+
self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $field );
|
305 |
+
break;
|
306 |
+
case 'end_divider':
|
307 |
+
if ( ! $open ) {
|
308 |
+
// the section isn't open, so this is an extra field that needs to be removed
|
309 |
+
FrmField::destroy( $field->id );
|
310 |
+
$reset_fields = true;
|
311 |
+
}
|
312 |
+
|
313 |
+
// There is already an end section here, so there is no need to create one
|
314 |
+
$open = false;
|
315 |
}
|
316 |
+
$prev_order = $field->field_order;
|
317 |
+
}
|
318 |
+
|
319 |
+
self::maybe_create_end_section($open, $reset_fields, $add_order, $end_section_values, $field );
|
320 |
+
}
|
321 |
+
|
322 |
+
/**
|
323 |
+
* Create end section field if it doesn't exist. This is for migration from < 2.0
|
324 |
+
* Fix any ordering that may be messed up
|
325 |
+
*/
|
326 |
+
public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field ) {
|
327 |
+
if ( ! $open ) {
|
328 |
+
return;
|
329 |
+
}
|
330 |
+
|
331 |
+
$end_section_values['field_order'] = $field->field_order + 1;
|
332 |
+
|
333 |
+
FrmField::create( $end_section_values );
|
334 |
+
|
335 |
+
$add_order += 2;
|
336 |
+
|
337 |
+
// bump the order of current field
|
338 |
+
FrmField::update( $field->id, array( 'field_order' => $field->field_order + $add_order ) );
|
339 |
+
|
340 |
+
$open = false;
|
341 |
+
$reset_fields = true;
|
342 |
+
}
|
343 |
+
|
344 |
+
public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) {
|
345 |
+
foreach ( array( 'form_name' => $title, 'form_description' => $description, 'entry_key' => true) as $code => $show) {
|
346 |
+
if ( $code == 'form_name' ) {
|
347 |
+
$replace_with = $form->name;
|
348 |
+
} else if ( $code == 'form_description' ) {
|
349 |
+
$replace_with = FrmAppHelper::use_wpautop($form->description);
|
350 |
+
} else if ( $code == 'entry_key' && isset($_GET) && isset($_GET['entry']) ) {
|
351 |
+
$replace_with = sanitize_text_field( $_GET['entry'] );
|
352 |
+
} else {
|
353 |
+
$replace_with = '';
|
354 |
}
|
355 |
+
|
356 |
+
FrmFieldsHelper::remove_inline_conditions( ( FrmAppHelper::is_true($show) && $replace_with != '' ), $code, $replace_with, $html );
|
357 |
}
|
358 |
+
|
359 |
//replace [form_key]
|
360 |
$html = str_replace('[form_key]', $form->form_key, $html);
|
361 |
+
|
362 |
//replace [frmurl]
|
363 |
+
$html = str_replace('[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html);
|
364 |
+
|
365 |
+
if ( strpos( $html, '[button_label]' ) ) {
|
366 |
+
add_filter('frm_submit_button', 'FrmFormsHelper::submit_button_label');
|
367 |
$replace_with = apply_filters('frm_submit_button', $title, $form);
|
368 |
$html = str_replace('[button_label]', $replace_with, $html);
|
369 |
}
|
370 |
+
|
371 |
$html = apply_filters('frm_form_replace_shortcodes', $html, $form, $values);
|
372 |
+
|
373 |
+
if ( strpos( $html, '[if back_button]' ) ) {
|
374 |
+
$html = preg_replace( '/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html );
|
375 |
+
}
|
376 |
+
|
377 |
+
if ( strpos( $html, '[if save_draft]' ) ) {
|
378 |
+
$html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html );
|
379 |
+
}
|
380 |
+
|
381 |
return $html;
|
382 |
}
|
383 |
+
|
384 |
+
public static function submit_button_label($submit) {
|
385 |
+
if ( ! $submit || empty($submit) ) {
|
386 |
+
$frm_settings = FrmAppHelper::get_settings();
|
387 |
+
$submit = $frm_settings->submit_value;
|
388 |
+
}
|
389 |
+
|
390 |
+
return $submit;
|
391 |
+
}
|
392 |
+
|
393 |
+
public static function get_form_style_class($form = false) {
|
394 |
+
$style = self::get_form_style($form);
|
395 |
+
$class = ' with_frm_style';
|
396 |
+
|
397 |
+
if ( empty($style) ) {
|
398 |
+
if ( FrmAppHelper::is_admin_page('formidable-entries') ) {
|
399 |
+
return $class;
|
400 |
+
} else {
|
401 |
+
return;
|
402 |
+
}
|
403 |
+
}
|
404 |
+
|
405 |
+
//If submit button needs to be inline or centered
|
406 |
+
if ( is_object($form) ) {
|
407 |
+
$form = $form->options;
|
408 |
+
}
|
409 |
+
|
410 |
+
$submit_align = isset( $form['submit_align'] ) ? $form['submit_align'] : '';
|
411 |
+
|
412 |
+
if ( $submit_align == 'inline' ) {
|
413 |
+
$class .= ' frm_inline_form';
|
414 |
+
} else if ( $submit_align == 'center' ) {
|
415 |
+
$class .= ' frm_center_submit';
|
416 |
+
}
|
417 |
+
|
418 |
+
$class = apply_filters('frm_add_form_style_class', $class, $style);
|
419 |
+
|
420 |
+
return $class;
|
421 |
+
}
|
422 |
+
|
423 |
+
/**
|
424 |
+
* @param string|boolean $form
|
425 |
+
*
|
426 |
+
* @return boolean
|
427 |
+
*/
|
428 |
+
public static function get_form_style( $form ) {
|
429 |
+
$style = 1;
|
430 |
+
if ( empty( $form ) || 'default' == 'form' ) {
|
431 |
+
return $style;
|
432 |
+
} else if ( is_object( $form ) && $form->parent_form_id ) {
|
433 |
+
// get the parent form if this is a child
|
434 |
+
$form = $form->parent_form_id;
|
435 |
+
} else if ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) {
|
436 |
+
$form = $form['parent_form_id'];
|
437 |
+
} else if ( is_array( $form ) && isset( $form['custom_style'] ) ) {
|
438 |
+
$style = $form['custom_style'];
|
439 |
+
}
|
440 |
+
|
441 |
+
if ( $form && is_string( $form ) ) {
|
442 |
+
$form = FrmForm::getOne( $form );
|
443 |
+
}
|
444 |
+
|
445 |
+
$style = ( $form && is_object( $form ) && isset( $form->options['custom_style'] ) ) ? $form->options['custom_style'] : $style;
|
446 |
+
|
447 |
+
return $style;
|
448 |
+
}
|
449 |
+
|
450 |
+
public static function form_loaded($form, $this_load, $global_load) {
|
451 |
global $frm_vars;
|
452 |
$small_form = new stdClass();
|
453 |
+
foreach ( array( 'id', 'form_key', 'name' ) as $var ) {
|
454 |
$small_form->{$var} = $form->{$var};
|
455 |
unset($var);
|
456 |
}
|
457 |
+
|
458 |
$frm_vars['forms_loaded'][] = $small_form;
|
459 |
+
|
460 |
+
if ( $this_load && empty($global_load) ) {
|
461 |
+
$global_load = $frm_vars['load_css'] = true;
|
462 |
+
}
|
463 |
+
|
464 |
+
if ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load ) {
|
465 |
+
echo FrmAppController::footer_js('header');
|
466 |
+
$frm_vars['css_loaded'] = true;
|
467 |
+
}
|
468 |
+
}
|
469 |
+
|
470 |
+
public static function get_scroll_js($form_id) {
|
471 |
+
?><script type="text/javascript">jQuery(document).ready(function(){frmFrontForm.scrollMsg(<?php echo (int) $form_id ?>);})</script><?php
|
472 |
+
}
|
473 |
+
|
474 |
+
public static function edit_form_link($form_id) {
|
475 |
+
if ( is_object($form_id) ) {
|
476 |
+
$form = $form_id;
|
477 |
+
$name = $form->name;
|
478 |
+
$form_id = $form->id;
|
479 |
+
} else {
|
480 |
+
$name = FrmForm::getName($form_id);
|
481 |
+
}
|
482 |
+
|
483 |
+
if ( $form_id ) {
|
484 |
+
$val = '<a href="'. admin_url('admin.php') .'?page=formidable&frm_action=edit&id='. $form_id .'">'. ( '' == $name ? __( '(no title)') : FrmAppHelper::truncate($name, 40) ) .'</a>';
|
485 |
+
} else {
|
486 |
+
$val = '';
|
487 |
+
}
|
488 |
+
|
489 |
+
return $val;
|
490 |
+
}
|
491 |
+
|
492 |
+
public static function delete_trash_link($id, $status, $length = 'long') {
|
493 |
+
$link = '';
|
494 |
+
$labels = array(
|
495 |
+
'restore' => array(
|
496 |
+
'long' => __( 'Restore from Trash', 'formidable' ),
|
497 |
+
'short' => __( 'Restore', 'formidable' ),
|
498 |
+
),
|
499 |
+
'trash' => array(
|
500 |
+
'long' => __( 'Move to Trash', 'formidable' ),
|
501 |
+
'short' => __( 'Trash', 'formidable' ),
|
502 |
+
),
|
503 |
+
'delete' => array(
|
504 |
+
'long' => __( 'Delete Permanently', 'formidable' ),
|
505 |
+
'short' => __( 'Delete', 'formidable' ),
|
506 |
+
),
|
507 |
+
);
|
508 |
+
|
509 |
+
$current_page = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
|
510 |
+
$base_url = '?page=formidable&form_type='. $current_page .'&id='. $id;
|
511 |
+
if ( 'trash' == $status ) {
|
512 |
+
$link = '<a href="'. esc_url(wp_nonce_url( $base_url .'&frm_action=untrash', 'untrash_form_' . $id )) .'" class="submitdelete deletion">'. $labels['restore'][$length] .'</a>';
|
513 |
+
} else if ( current_user_can('frm_delete_forms') ) {
|
514 |
+
if ( EMPTY_TRASH_DAYS ) {
|
515 |
+
$link = '<a href="'. wp_nonce_url( $base_url .'&frm_action=trash', 'trash_form_' . $id ) .'" class="submitdelete deletion">'. $labels['trash'][$length] .'</a>';
|
516 |
+
} else {
|
517 |
+
$link = '<a href="'. wp_nonce_url( $base_url .'&frm_action=destroy', 'destroy_form_' . $id ) .'" class="submitdelete deletion" onclick="return confirm(\''. __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ) .'\')">'. $labels['delete'][$length] .'</a>';
|
518 |
+
}
|
519 |
+
}
|
520 |
+
|
521 |
+
return $link;
|
522 |
+
}
|
523 |
+
|
524 |
+
public static function status_nice_name($status) {
|
525 |
+
$nice_names = array(
|
526 |
+
'draft' => __( 'Draft', 'formidable' ),
|
527 |
+
'trash' => __( 'Trash', 'formidable' ),
|
528 |
+
'publish' => __( 'Published', 'formidable' ),
|
529 |
+
);
|
530 |
+
|
531 |
+
if ( ! in_array($status, array_keys($nice_names)) ) {
|
532 |
+
$status = 'publish';
|
533 |
+
}
|
534 |
+
|
535 |
+
$name = $nice_names[$status];
|
536 |
+
|
537 |
+
return $name;
|
538 |
+
}
|
539 |
+
|
540 |
+
public static function get_params() {
|
541 |
+
$values = array();
|
542 |
+
foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '') as $var => $default ) {
|
543 |
+
$values[$var] = FrmAppHelper::get_param($var, $default);
|
544 |
+
}
|
545 |
+
|
546 |
+
return $values;
|
547 |
}
|
548 |
|
549 |
+
/**
|
550 |
+
* @param string $status
|
551 |
+
*
|
552 |
+
* @return int The number of forms changed
|
553 |
+
*/
|
554 |
+
public static function change_form_status( $status ) {
|
555 |
+
$available_status = array(
|
556 |
+
'untrash' => array(
|
557 |
+
'permission' => 'frm_edit_forms', 'new_status' => 'published',
|
558 |
+
),
|
559 |
+
'trash' => array(
|
560 |
+
'permission' => 'frm_delete_forms', 'new_status' => 'trash',
|
561 |
+
),
|
562 |
+
);
|
563 |
+
|
564 |
+
if ( ! isset($available_status[$status]) ) {
|
565 |
+
return;
|
566 |
+
}
|
567 |
+
|
568 |
+
FrmAppHelper::permission_check($available_status[$status]['permission']);
|
569 |
+
|
570 |
+
$params = self::get_params();
|
571 |
+
|
572 |
+
//check nonce url
|
573 |
+
check_admin_referer($status .'_form_' . $params['id']);
|
574 |
+
|
575 |
+
$count = 0;
|
576 |
+
if ( FrmForm::set_status( $params['id'], $available_status[$status]['new_status'] ) ) {
|
577 |
+
$count++;
|
578 |
+
}
|
579 |
+
|
580 |
+
$available_status['untrash']['message'] = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
|
581 |
+
$available_status['trash']['message'] = sprintf(_n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="'. esc_url(wp_nonce_url( '?page=formidable&frm_action=untrash&form_type='. ( isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '' ) .'&id='. $params['id'], 'untrash_form_' . $params['id'] )) .'">', '</a>' );
|
582 |
+
|
583 |
+
$message = $available_status[$status]['message'];
|
584 |
+
|
585 |
+
FrmFormsController::display_forms_list($params, $message, 1);
|
586 |
+
}
|
587 |
}
|
classes/helpers/FrmFormsListHelper.php
ADDED
@@ -0,0 +1,370 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
5 |
+
|
6 |
+
class FrmFormsListHelper extends FrmListHelper {
|
7 |
+
var $status = '';
|
8 |
+
|
9 |
+
public function __construct( $args ) {
|
10 |
+
$this->status = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
|
11 |
+
|
12 |
+
parent::__construct( $args );
|
13 |
+
}
|
14 |
+
|
15 |
+
public function prepare_items() {
|
16 |
+
global $wpdb, $per_page, $mode;
|
17 |
+
|
18 |
+
$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
|
19 |
+
|
20 |
+
$default_orderby = 'name';
|
21 |
+
$default_order = 'ASC';
|
22 |
+
|
23 |
+
$orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby;
|
24 |
+
$order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : $default_order;
|
25 |
+
|
26 |
+
$page = $this->get_pagenum();
|
27 |
+
$per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
|
28 |
+
|
29 |
+
$start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page);
|
30 |
+
|
31 |
+
$s_query = array();
|
32 |
+
$s_query[] = array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 1 );
|
33 |
+
switch ( $this->status ) {
|
34 |
+
case 'template':
|
35 |
+
$s_query['is_template'] = 1;
|
36 |
+
$s_query['status !'] = 'trash';
|
37 |
+
break;
|
38 |
+
case 'draft':
|
39 |
+
$s_query['is_template'] = 0;
|
40 |
+
$s_query['status'] = 'draft';
|
41 |
+
break;
|
42 |
+
case 'trash':
|
43 |
+
$s_query['status'] = 'trash';
|
44 |
+
break;
|
45 |
+
default:
|
46 |
+
$s_query['is_template'] = 0;
|
47 |
+
$s_query['status !'] = 'trash';
|
48 |
+
break;
|
49 |
+
}
|
50 |
+
|
51 |
+
$s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
|
52 |
+
if ( $s != '' ) {
|
53 |
+
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
|
54 |
+
$search_terms = array_map('trim', $matches[0]);
|
55 |
+
foreach ( (array) $search_terms as $term ) {
|
56 |
+
$s_query[] = array(
|
57 |
+
'or' => true, 'name LIKE' => $term, 'description LIKE' => $term, 'created_at LIKE' => $term,
|
58 |
+
);
|
59 |
+
unset($term);
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
$this->items = FrmForm::getAll($s_query, $orderby .' '. $order, $start .','. $per_page);
|
64 |
+
$total_items = FrmDb::get_count( 'frm_forms', $s_query );
|
65 |
+
|
66 |
+
$this->set_pagination_args( array(
|
67 |
+
'total_items' => $total_items,
|
68 |
+
'per_page' => $per_page,
|
69 |
+
) );
|
70 |
+
}
|
71 |
+
|
72 |
+
public function no_items() {
|
73 |
+
if ( 'template' == $this->status ) {
|
74 |
+
_e( 'No Templates Found.', 'formidable' ) ?>
|
75 |
+
<br/><br/><?php _e( 'To add a new template:', 'formidable' ) ?>
|
76 |
+
<ol><li><?php printf( __( 'Create a new %1$sform%2$s.', 'formidable' ), '<a href="'. esc_url( admin_url( 'admin?page=formidable&frm_action=new' ) ) . '"', '</a>' ) ?></li>
|
77 |
+
<li><?php printf(__( 'After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable' ), '<a href="?page=formidable">', '</a>') ?></li>
|
78 |
+
<li><?php _e( 'Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable' ) ?></li>
|
79 |
+
</ol>
|
80 |
+
<?php } else {
|
81 |
+
_e( 'No Forms Found.', 'formidable' ) ?>
|
82 |
+
<a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=new' ) ) ?>"><?php _e( 'Add New', 'formidable' ); ?></a>
|
83 |
+
<?php }
|
84 |
+
}
|
85 |
+
|
86 |
+
public function get_bulk_actions() {
|
87 |
+
$actions = array();
|
88 |
+
|
89 |
+
if ( in_array($this->status, array( '', 'published')) ) {
|
90 |
+
$actions['bulk_create_template'] = __( 'Create Template', 'formidable' );
|
91 |
+
}
|
92 |
+
|
93 |
+
if ( 'trash' == $this->status ) {
|
94 |
+
if ( current_user_can('frm_edit_forms') ) {
|
95 |
+
$actions['bulk_untrash'] = __( 'Restore', 'formidable' );
|
96 |
+
}
|
97 |
+
|
98 |
+
if ( current_user_can('frm_delete_forms') ) {
|
99 |
+
$actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
|
100 |
+
}
|
101 |
+
} else if ( EMPTY_TRASH_DAYS && current_user_can('frm_delete_forms') ) {
|
102 |
+
$actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
|
103 |
+
} else if ( current_user_can('frm_delete_forms') ) {
|
104 |
+
$actions['bulk_delete'] = __( 'Delete');
|
105 |
+
}
|
106 |
+
|
107 |
+
return $actions;
|
108 |
+
}
|
109 |
+
|
110 |
+
public function extra_tablenav( $which ) {
|
111 |
+
if ( 'top' != $which ) {
|
112 |
+
return;
|
113 |
+
}
|
114 |
+
|
115 |
+
if ( 'trash' == $this->status && current_user_can('frm_delete_forms') ) {
|
116 |
+
?>
|
117 |
+
<div class="alignleft actions frm_visible_overflow">
|
118 |
+
<?php submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); ?>
|
119 |
+
</div>
|
120 |
+
<?php
|
121 |
+
return;
|
122 |
+
}
|
123 |
+
|
124 |
+
if ( 'template' != $this->status ) {
|
125 |
+
return;
|
126 |
+
}
|
127 |
+
|
128 |
+
$where = apply_filters( 'frm_forms_dropdown', array(), '' );
|
129 |
+
$forms = FrmForm::get_published_forms( $where );
|
130 |
+
|
131 |
+
$base = admin_url('admin.php?page=formidable&form_type=template');
|
132 |
+
$args = array(
|
133 |
+
'frm_action' => 'duplicate',
|
134 |
+
'template' => true,
|
135 |
+
);
|
136 |
+
|
137 |
+
?>
|
138 |
+
<div class="alignleft actions frm_visible_overflow">
|
139 |
+
<div class="dropdown frm_tiny_top_margin">
|
140 |
+
<a href="#" id="frm-templateDrop" class="frm-dropdown-toggle button" data-toggle="dropdown"><?php _e( 'Create New Template', 'formidable' ) ?> <b class="caret"></b></a>
|
141 |
+
<ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-templateDrop">
|
142 |
+
<?php
|
143 |
+
if ( empty( $forms ) ) { ?>
|
144 |
+
<li class="frm_dropdown_li"><?php _e( 'You have not created any forms yet. <br/>You must create a form before you can make a template.', 'formidable' ) ?></li>
|
145 |
+
<?php
|
146 |
+
} else {
|
147 |
+
foreach ( $forms as $form ) {
|
148 |
+
$args['id'] = $form->id; ?>
|
149 |
+
<li><a href="<?php echo add_query_arg($args, $base); ?>" tabindex="-1"><?php echo empty($form->name) ? __( '(no title)') : FrmAppHelper::truncate($form->name, 33); ?></a></li>
|
150 |
+
<?php
|
151 |
+
unset($form);
|
152 |
+
}
|
153 |
+
}
|
154 |
+
?>
|
155 |
+
</ul>
|
156 |
+
</div>
|
157 |
+
</div>
|
158 |
+
<?php
|
159 |
+
}
|
160 |
+
|
161 |
+
public function get_views() {
|
162 |
+
|
163 |
+
$statuses = array(
|
164 |
+
'published' => __( 'My Forms', 'formidable' ),
|
165 |
+
'template' => __( 'Templates', 'formidable' ),
|
166 |
+
'draft' => __( 'Drafts', 'formidable' ),
|
167 |
+
'trash' => __( 'Trash', 'formidable' ),
|
168 |
+
);
|
169 |
+
|
170 |
+
$links = array();
|
171 |
+
$counts = FrmForm::get_count();
|
172 |
+
$form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : 'published';
|
173 |
+
|
174 |
+
foreach ( $statuses as $status => $name ) {
|
175 |
+
|
176 |
+
if ( $status == $form_type ) {
|
177 |
+
$class = ' class="current"';
|
178 |
+
} else {
|
179 |
+
$class = '';
|
180 |
+
}
|
181 |
+
|
182 |
+
if ( $counts->{$status} || 'published' == $status ) {
|
183 |
+
$links[$status] = '<a href="?page=formidable&form_type='. $status .'" '. $class .'>'. sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) .'</a>';
|
184 |
+
}
|
185 |
+
|
186 |
+
unset($status, $name);
|
187 |
+
}
|
188 |
+
|
189 |
+
return $links;
|
190 |
+
}
|
191 |
+
|
192 |
+
public function pagination( $which ) {
|
193 |
+
global $mode;
|
194 |
+
|
195 |
+
parent::pagination( $which );
|
196 |
+
|
197 |
+
if ( 'top' == $which ) {
|
198 |
+
$this->view_switcher( $mode );
|
199 |
+
}
|
200 |
+
}
|
201 |
+
|
202 |
+
public function single_row( $item, $style = '' ) {
|
203 |
+
global $frm_vars, $mode;
|
204 |
+
|
205 |
+
// Set up the hover actions for this user
|
206 |
+
$actions = array();
|
207 |
+
$edit_link = '?page=formidable&frm_action=edit&id='. $item->id;
|
208 |
+
$duplicate_link = '?page=formidable&frm_action=duplicate&id='. $item->id;
|
209 |
+
|
210 |
+
$this->get_actions($actions, $item, $edit_link, $duplicate_link);
|
211 |
+
|
212 |
+
$action_links = $this->row_actions( $actions );
|
213 |
+
|
214 |
+
// Set up the checkbox ( because the user is editable, otherwise its empty )
|
215 |
+
$checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-'. $item->id .'" value="'. $item->id .'" />';
|
216 |
+
|
217 |
+
$r = '<tr id="item-action-'. $item->id .'"'. $style .'>';
|
218 |
+
|
219 |
+
list( $columns, $hidden ) = $this->get_column_info();
|
220 |
+
|
221 |
+
$format = 'Y/m/d';
|
222 |
+
if ( 'list' != $mode ) {
|
223 |
+
$format .= ' \<\b\r \/\> g:i:s a';
|
224 |
+
}
|
225 |
+
|
226 |
+
foreach ( $columns as $column_name => $column_display_name ) {
|
227 |
+
$class = $column_name .' column-'. $column_name . ( ('name' == $column_name) ? ' post-title page-title column-title' : '' );
|
228 |
+
|
229 |
+
$style = '';
|
230 |
+
if ( in_array( $column_name, $hidden ) ) {
|
231 |
+
$class .= ' frm_hidden';
|
232 |
+
}
|
233 |
+
|
234 |
+
$class = 'class="' . $class . '"';
|
235 |
+
$attributes = $class . $style;
|
236 |
+
|
237 |
+
switch ( $column_name ) {
|
238 |
+
case 'cb':
|
239 |
+
$r .= '<th scope="row" class="check-column">'. $checkbox .'</th>';
|
240 |
+
break;
|
241 |
+
case 'id':
|
242 |
+
case 'form_key':
|
243 |
+
$val = $item->{$column_name};
|
244 |
+
break;
|
245 |
+
case 'name':
|
246 |
+
$val = $this->get_form_name( $item, $actions, $edit_link );
|
247 |
+
$val .= $action_links;
|
248 |
+
|
249 |
+
break;
|
250 |
+
case 'created_at':
|
251 |
+
$date = date($format, strtotime($item->created_at));
|
252 |
+
$val = '<abbr title="'. date('Y/m/d g:i:s A', strtotime($item->created_at)) .'">'. $date .'</abbr>';
|
253 |
+
break;
|
254 |
+
case 'shortcode':
|
255 |
+
$val = '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable id={$item->id}]") .'" /><br/>';
|
256 |
+
if ( 'excerpt' == $mode ) {
|
257 |
+
$val .= '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable key={$item->form_key}]") .'" />';
|
258 |
+
}
|
259 |
+
break;
|
260 |
+
case 'entries':
|
261 |
+
if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
|
262 |
+
$val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="'. esc_attr('Entries are not being saved', 'formidable' ) .'"></i>';
|
263 |
+
} else {
|
264 |
+
$text = FrmEntry::getRecordCount($item->id);
|
265 |
+
$val = (current_user_can('frm_view_entries')) ? '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable-entries&form='. $item->id ) .'">'. $text .'</a>' : $text;
|
266 |
+
unset($text);
|
267 |
+
}
|
268 |
+
break;
|
269 |
+
case 'type':
|
270 |
+
$val = ( $item->is_template && $item->default_template ) ? __( 'Default', 'formidable' ) : __( 'Custom', 'formidable' );
|
271 |
+
break;
|
272 |
+
}
|
273 |
+
|
274 |
+
if ( isset($val) ) {
|
275 |
+
$r .= "<td $attributes>";
|
276 |
+
$r .= $val;
|
277 |
+
$r .= '</td>';
|
278 |
+
}
|
279 |
+
unset($val);
|
280 |
+
}
|
281 |
+
$r .= '</tr>';
|
282 |
+
|
283 |
+
return $r;
|
284 |
+
}
|
285 |
+
|
286 |
+
/**
|
287 |
+
* @param string $edit_link
|
288 |
+
* @param string $duplicate_link
|
289 |
+
*/
|
290 |
+
private function get_actions( &$actions, $item, $edit_link, $duplicate_link ) {
|
291 |
+
if ( 'trash' == $this->status ) {
|
292 |
+
if ( current_user_can('frm_edit_forms') ) {
|
293 |
+
$actions['restore'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' );
|
294 |
+
}
|
295 |
+
|
296 |
+
if ( current_user_can('frm_delete_forms') ) {
|
297 |
+
$actions['trash'] = '<a href="' . esc_url(wp_nonce_url( '?page=formidable&form_status=trash&frm_action=destroy&id='. $item->id, 'destroy_form_'. $item->id )) .'" class="submitdelete" onclick="return confirm(\''. __( 'Are you sure you want to permanently delete that?', 'formidable' ) .'\')">' . __( 'Delete Permanently' ) . '</a>';
|
298 |
+
}
|
299 |
+
return;
|
300 |
+
}
|
301 |
+
|
302 |
+
if ( current_user_can('frm_edit_forms') ) {
|
303 |
+
if ( ! $item->is_template || ! $item->default_template ) {
|
304 |
+
$actions['frm_edit'] = '<a href="'. esc_url( $edit_link ) . '">'. __( 'Edit') .'</a>';
|
305 |
+
}
|
306 |
+
|
307 |
+
if ( $item->is_template ) {
|
308 |
+
$actions['frm_duplicate'] = '<a href="'. wp_nonce_url( $duplicate_link ) .'">'. __( 'Create Form from Template', 'formidable' ) .'</a>';
|
309 |
+
} else {
|
310 |
+
$actions['frm_settings'] = '<a href="'. esc_url('?page=formidable&frm_action=settings&id='. $item->id ) . '">'. __( 'Settings', 'formidable' ) .'</a>';
|
311 |
+
|
312 |
+
if ( FrmAppHelper::pro_is_installed() ) {
|
313 |
+
$actions['duplicate'] = '<a href="' . wp_nonce_url( $duplicate_link ) . '">'. __( 'Duplicate', 'formidable' ) .'</a>';
|
314 |
+
}
|
315 |
+
}
|
316 |
+
}
|
317 |
+
|
318 |
+
$actions['trash'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' );
|
319 |
+
if ( empty( $actions['trash'] ) ) {
|
320 |
+
// the user doesn't have permission
|
321 |
+
unset( $actions['trash'] );
|
322 |
+
}
|
323 |
+
|
324 |
+
$actions['view'] = '<a href="'. FrmFormsHelper::get_direct_link($item->form_key, $item) .'" target="_blank">'. __( 'Preview') .'</a>';
|
325 |
+
}
|
326 |
+
|
327 |
+
/**
|
328 |
+
* @param string $edit_link
|
329 |
+
*/
|
330 |
+
private function get_form_name( $item, $actions, $edit_link ) {
|
331 |
+
$form_name = $item->name;
|
332 |
+
if ( trim($form_name) == '' ) {
|
333 |
+
$form_name = __( '(no title)');
|
334 |
+
}
|
335 |
+
$form_name = FrmAppHelper::truncate(strip_tags($form_name), 50);
|
336 |
+
|
337 |
+
$val = '<strong>';
|
338 |
+
if ( 'trash' == $this->status ) {
|
339 |
+
$val .= $form_name;
|
340 |
+
} else {
|
341 |
+
$val .= '<a href="'. ( isset($actions['frm_edit']) ? $edit_link : FrmFormsHelper::get_direct_link($item->form_key, $item) ) .'" class="row-title">'. $form_name .'</a> ';
|
342 |
+
}
|
343 |
+
|
344 |
+
$this->add_draft_label( $item, $val );
|
345 |
+
$val .= '</strong>';
|
346 |
+
|
347 |
+
$this->add_form_description( $item, $val );
|
348 |
+
|
349 |
+
return $val;
|
350 |
+
}
|
351 |
+
|
352 |
+
/**
|
353 |
+
* @param string $val
|
354 |
+
*/
|
355 |
+
private function add_draft_label( $item, &$val ) {
|
356 |
+
if ( 'draft' == $item->status && 'draft' != $this->status ) {
|
357 |
+
$val .= ' - <span class="post-state">'. __( 'Draft', 'formidable' ) .'</span>';
|
358 |
+
}
|
359 |
+
}
|
360 |
+
|
361 |
+
/**
|
362 |
+
* @param string $val
|
363 |
+
*/
|
364 |
+
private function add_form_description( $item, &$val ) {
|
365 |
+
global $mode;
|
366 |
+
if ( 'excerpt' == $mode ) {
|
367 |
+
$val .= FrmAppHelper::truncate(strip_tags($item->description), 50);
|
368 |
+
}
|
369 |
+
}
|
370 |
+
}
|
classes/helpers/FrmListHelper.php
CHANGED
@@ -1,228 +1,31 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
if(class_exists('FrmListHelper'))
|
6 |
-
return;
|
7 |
|
8 |
class FrmListHelper extends WP_List_Table {
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
$args = wp_parse_args( $args, array(
|
14 |
-
'ajax' => false,
|
15 |
-
'table_name' => '',
|
16 |
-
'page_name' => '',
|
17 |
'params' => array()
|
18 |
) );
|
19 |
-
|
20 |
-
$this->page_name = $args['page_name'];
|
21 |
$this->params = $args['params'];
|
22 |
-
|
23 |
-
$screen = get_current_screen();
|
24 |
|
25 |
parent::__construct( $args );
|
26 |
}
|
27 |
|
28 |
-
function ajax_user_can() {
|
29 |
return current_user_can( 'administrator' );
|
30 |
}
|
31 |
|
32 |
-
function
|
33 |
-
global $wpdb, $per_page, $frm_settings;
|
34 |
-
$paged = $this->get_pagenum();
|
35 |
-
$default_orderby = 'name';
|
36 |
-
$default_order = 'ASC';
|
37 |
-
|
38 |
-
$orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby;
|
39 |
-
$order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : $default_order;
|
40 |
-
|
41 |
-
$page = $this->get_pagenum();
|
42 |
-
$default_count = empty($this->page_name) ? 20 : 10;
|
43 |
-
$per_page = $this->get_items_per_page( 'formidable_page_formidable'. str_replace('-', '_', $this->page_name) .'_per_page', $default_count);
|
44 |
-
|
45 |
-
$start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page);
|
46 |
-
$s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
|
47 |
-
$fid = isset( $_REQUEST['fid'] ) ? $_REQUEST['fid'] : '';
|
48 |
-
if($s != ''){
|
49 |
-
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
|
50 |
-
$search_terms = array_map('trim', $matches[0]);
|
51 |
-
}
|
52 |
-
|
53 |
-
$s_query = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = ". (int)$this->params['template'];
|
54 |
-
|
55 |
-
if($s != ''){
|
56 |
-
foreach ( (array) $search_terms as $term ) {
|
57 |
-
if ( !empty($s_query) ) {
|
58 |
-
$s_query .= " AND";
|
59 |
-
}
|
60 |
-
|
61 |
-
$term = FrmAppHelper::esc_like($term);
|
62 |
-
|
63 |
-
$s_query .= $wpdb->prepare(" (name like %s OR description like %s OR created_at like %s)", '%'. $term .'%', '%'. $term .'%', '%'. $term .'%');
|
64 |
-
|
65 |
-
unset($term);
|
66 |
-
}
|
67 |
-
}
|
68 |
-
|
69 |
-
$frm_form = new FrmForm();
|
70 |
-
$this->items = $frm_form->getAll($s_query, " ORDER BY $orderby $order", " LIMIT $start, $per_page", true, false);
|
71 |
-
$total_items = FrmAppHelper::getRecordCount($s_query, $this->table_name);
|
72 |
-
|
73 |
-
|
74 |
-
$this->set_pagination_args( array(
|
75 |
-
'total_items' => $total_items,
|
76 |
-
'per_page' => $per_page
|
77 |
-
) );
|
78 |
-
}
|
79 |
-
|
80 |
-
function no_items() {
|
81 |
-
if ($this->params['template']){
|
82 |
-
_e('No Templates Found', 'formidable') ?>.
|
83 |
-
<br/><br/><?php _e('To add a new template','formidable') ?>:
|
84 |
-
<ol><li><?php printf(__('Create a new %1$sform%2$s.', 'formidable'), '<a href="?page=formidable&frm_action=new-selection">', '</a>') ?></li>
|
85 |
-
<li><?php printf(__('After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable'), '<a href="?page=formidable">', '</a>') ?></li>
|
86 |
-
<li><?php _e('Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable') ?></li>
|
87 |
-
</ol>
|
88 |
-
<?php }else{
|
89 |
-
_e('No Forms Found', 'formidable') ?>.
|
90 |
-
<a href="?page=formidable&frm_action=new-selection"><?php _e('Add New', 'formidable'); ?></a>
|
91 |
-
<?php }
|
92 |
-
}
|
93 |
-
|
94 |
-
function get_bulk_actions(){
|
95 |
-
$actions = array();
|
96 |
-
if ( current_user_can('frm_delete_forms') ) {
|
97 |
-
$actions['bulk_delete'] = __('Delete');
|
98 |
-
}
|
99 |
-
|
100 |
-
return $actions;
|
101 |
-
}
|
102 |
-
|
103 |
-
function display_rows() {
|
104 |
$style = '';
|
105 |
foreach ( $this->items as $item ) {
|
106 |
$style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
|
107 |
echo "\n\t", $this->single_row( $item, $style );
|
108 |
}
|
109 |
}
|
110 |
-
|
111 |
-
function single_row( $item, $style='') {
|
112 |
-
global $frm_vars, $frm_entry;
|
113 |
-
$checkbox = '';
|
114 |
-
|
115 |
-
// Set up the hover actions for this user
|
116 |
-
$actions = array();
|
117 |
-
$title = esc_attr(strip_tags($item->name));
|
118 |
-
|
119 |
-
if ( current_user_can('frm_edit_forms') ) {
|
120 |
-
$edit_link = "?page=formidable&frm_action=edit&id={$item->id}";
|
121 |
-
$duplicate_link = "?page=formidable&frm_action=duplicate&id={$item->id}";
|
122 |
-
|
123 |
-
$actions['frm_edit'] = "<a href='" . esc_url( $edit_link ) . "'>". __('Edit') ."</a>";
|
124 |
-
|
125 |
-
if ( $this->params['template'] ) {
|
126 |
-
$actions['frm_duplicate'] = "<a href='" . wp_nonce_url( $duplicate_link ) . "'>". __('Create Form from Template', 'formidable') ."</a>";
|
127 |
-
} else {
|
128 |
-
$actions['frm_settings'] = "<a href='" . wp_nonce_url( "?page=formidable&frm_action=settings&id={$item->id}" ) . "'>". __('Settings', 'formidable') ."</a>";
|
129 |
-
|
130 |
-
if ( $frm_vars['pro_is_installed'] ) {
|
131 |
-
$actions['duplicate'] = '<a href="' . wp_nonce_url( $duplicate_link ) . '">'. __('Duplicate', 'formidable') .'</a>';
|
132 |
-
}
|
133 |
-
}
|
134 |
-
}
|
135 |
-
|
136 |
-
$delete_link = "?page=formidable&frm_action=destroy&id={$item->id}";
|
137 |
-
if(current_user_can('frm_delete_forms'))
|
138 |
-
$actions['trash'] = '<a class="submitdelete" href="' . wp_nonce_url( $delete_link ) .'" onclick="return confirm(\''. __('Are you sure you want to delete that?', 'formidable') .'\')">' . __( 'Delete' ) . '</a>';
|
139 |
-
|
140 |
-
$actions['view'] = '<a href="'. FrmFormsHelper::get_direct_link($item->form_key, $item) .'" target="_blank">'. __('Preview') .'</a>';
|
141 |
-
|
142 |
-
$action_links = $this->row_actions( $actions );
|
143 |
-
|
144 |
-
// Set up the checkbox ( because the user is editable, otherwise its empty )
|
145 |
-
$checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-'. $item->id .'" value="'. $item->id .'" />';
|
146 |
-
|
147 |
-
$r = '<tr id="item-action-'. $item->id .'"'. $style .'>';
|
148 |
-
|
149 |
-
list( $columns, $hidden ) = $this->get_column_info();
|
150 |
-
$action_col = false;
|
151 |
-
|
152 |
-
foreach ( $columns as $column_name => $column_display_name ) {
|
153 |
-
$class = 'class="'. $column_name .' column-'. $column_name .'"';
|
154 |
|
155 |
-
$style = '';
|
156 |
-
if ( in_array( $column_name, $hidden ) )
|
157 |
-
$style = ' style="display:none;"';
|
158 |
-
else if(!$action_col and !in_array($column_name, array('cb', 'id')))
|
159 |
-
$action_col = $column_name;
|
160 |
-
|
161 |
-
$attributes = "$class$style";
|
162 |
-
|
163 |
-
switch ( $column_name ) {
|
164 |
-
case 'cb':
|
165 |
-
$r .= '<th scope="row" class="check-column">'. $checkbox .'</th>';
|
166 |
-
break;
|
167 |
-
case 'id':
|
168 |
-
case 'form_key':
|
169 |
-
$val = $item->{$column_name};
|
170 |
-
break;
|
171 |
-
case 'name':
|
172 |
-
if(trim($item->{$column_name}) == '')
|
173 |
-
$val = __('(no title)');
|
174 |
-
else
|
175 |
-
$val = FrmAppHelper::truncate(strip_tags($item->{$column_name}), 50);
|
176 |
-
break;
|
177 |
-
case 'description':
|
178 |
-
$val = FrmAppHelper::truncate(strip_tags($item->{$column_name}), 50);
|
179 |
-
break;
|
180 |
-
case 'created_at':
|
181 |
-
$format = 'Y/m/d'; //get_option('date_format');
|
182 |
-
$date = date($format, strtotime($item->{$column_name}));
|
183 |
-
$val = "<abbr title='". date($format .' g:i:s A', strtotime($item->{$column_name})) ."'>". $date ."</abbr>";
|
184 |
-
break;
|
185 |
-
case 'shortcode':
|
186 |
-
$val = '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable id={$item->id}]") .'" /><br/>';
|
187 |
-
$val .= '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable key={$item->form_key}]") .'" />';
|
188 |
-
break;
|
189 |
-
case 'entries':
|
190 |
-
$text = $frm_entry->getRecordCount($item->id);
|
191 |
-
//$text = sprintf(_n( '%1$s Entry', '%1$s Entries', $text, 'formidable' ), $text);
|
192 |
-
$val = (current_user_can('frm_view_entries')) ? '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable-entries&form='. $item->id ) .'">'. $text .'</a>' : $text;
|
193 |
-
unset($text);
|
194 |
-
break;
|
195 |
-
case 'link':
|
196 |
-
$links = array();
|
197 |
-
if($frm_vars['pro_is_installed'] and current_user_can('frm_create_entries'))
|
198 |
-
$links[] = '<a href="'. wp_nonce_url( "?page=formidable-entries&frm_action=new&form={$item->id}" ) .'" class="frm_add_entry_icon frm_icon_font frm_bstooltip" title="'. __('Add Entry', 'formidable'). '" data-toggle="tooltip"> </a>';
|
199 |
-
|
200 |
-
if ( current_user_can('frm_edit_forms') ){
|
201 |
-
$links[] = '<a href="' . wp_nonce_url( "?page=formidable&frm_action=duplicate&id={$item->id}&template=1" ) .'" class="frm_icon_font frm_new_template_icon frm_bstooltip" title="'. __('Create template from form', 'formidable') .'" data-toggle="tooltip"> </a>';
|
202 |
-
}
|
203 |
-
|
204 |
-
$val = implode(' ', $links);
|
205 |
-
break;
|
206 |
-
default:
|
207 |
-
$val = $column_name;
|
208 |
-
break;
|
209 |
-
}
|
210 |
-
|
211 |
-
if(isset($val)){
|
212 |
-
$r .= "<td $attributes>";
|
213 |
-
if($column_name == $action_col){
|
214 |
-
$r .= '<a class="row-title" href="'. ( isset($actions['frm_edit']) ? $edit_link : FrmFormsHelper::get_direct_link($item->form_key, $item) ) .'">'. $val .'</a> ';
|
215 |
-
$r .= $action_links;
|
216 |
-
}else{
|
217 |
-
$r .= $val;
|
218 |
-
}
|
219 |
-
$r .= '</td>';
|
220 |
-
}
|
221 |
-
unset($val);
|
222 |
-
}
|
223 |
-
$r .= '</tr>';
|
224 |
-
|
225 |
-
return $r;
|
226 |
-
}
|
227 |
-
|
228 |
}
|
1 |
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
|
|
|
|
5 |
|
6 |
class FrmListHelper extends WP_List_Table {
|
7 |
+
var $params;
|
8 |
+
|
9 |
+
public function __construct( $args ) {
|
|
|
10 |
$args = wp_parse_args( $args, array(
|
|
|
|
|
|
|
11 |
'params' => array()
|
12 |
) );
|
13 |
+
|
|
|
14 |
$this->params = $args['params'];
|
|
|
|
|
15 |
|
16 |
parent::__construct( $args );
|
17 |
}
|
18 |
|
19 |
+
public function ajax_user_can() {
|
20 |
return current_user_can( 'administrator' );
|
21 |
}
|
22 |
|
23 |
+
public function display_rows() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
$style = '';
|
25 |
foreach ( $this->items as $item ) {
|
26 |
$style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
|
27 |
echo "\n\t", $this->single_row( $item, $style );
|
28 |
}
|
29 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
}
|
classes/helpers/FrmStylesHelper.php
ADDED
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class FrmStylesHelper {
|
3 |
+
|
4 |
+
public static function jquery_themes() {
|
5 |
+
$themes = array(
|
6 |
+
'ui-lightness' => 'UI Lightness',
|
7 |
+
'ui-darkness' => 'UI Darkness',
|
8 |
+
'smoothness' => 'Smoothness',
|
9 |
+
'start' => 'Start',
|
10 |
+
'redmond' => 'Redmond',
|
11 |
+
'sunny' => 'Sunny',
|
12 |
+
'overcast' => 'Overcast',
|
13 |
+
'le-frog' => 'Le Frog',
|
14 |
+
'flick' => 'Flick',
|
15 |
+
'pepper-grinder'=> 'Pepper Grinder',
|
16 |
+
'eggplant' => 'Eggplant',
|
17 |
+
'dark-hive' => 'Dark Hive',
|
18 |
+
'cupertino' => 'Cupertino',
|
19 |
+
'south-street' => 'South Street',
|
20 |
+
'blitzer' => 'Blitzer',
|
21 |
+
'humanity' => 'Humanity',
|
22 |
+
'hot-sneaks' => 'Hot Sneaks',
|
23 |
+
'excite-bike' => 'Excite Bike',
|
24 |
+
'vader' => 'Vader',
|
25 |
+
'dot-luv' => 'Dot Luv',
|
26 |
+
'mint-choc' => 'Mint Choc',
|
27 |
+
'black-tie' => 'Black Tie',
|
28 |
+
'trontastic' => 'Trontastic',
|
29 |
+
'swanky-purse' => 'Swanky Purse',
|
30 |
+
);
|
31 |
+
|
32 |
+
$themes = apply_filters('frm_jquery_themes', $themes);
|
33 |
+
return $themes;
|
34 |
+
}
|
35 |
+
|
36 |
+
public static function jquery_css_url($theme_css) {
|
37 |
+
if ( $theme_css == -1 ) {
|
38 |
+
return;
|
39 |
+
}
|
40 |
+
|
41 |
+
if ( ! $theme_css || $theme_css == '' || $theme_css == 'ui-lightness' ) {
|
42 |
+
$css_file = FrmAppHelper::plugin_url() . '/css/ui-lightness/jquery-ui.css';
|
43 |
+
} else if ( preg_match('/^http.?:\/\/.*\..*$/', $theme_css) ) {
|
44 |
+
$css_file = $theme_css;
|
45 |
+
} else {
|
46 |
+
$uploads = self::get_upload_base();
|
47 |
+
$file_path = '/formidable/css/'. $theme_css . '/jquery-ui.css';
|
48 |
+
if ( file_exists($uploads['basedir'] . $file_path) ) {
|
49 |
+
$css_file = $uploads['baseurl'] . $file_path;
|
50 |
+
} else {
|
51 |
+
$css_file = FrmAppHelper::jquery_ui_base_url() .'/themes/'. $theme_css . '/jquery-ui.css';
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
return $css_file;
|
56 |
+
}
|
57 |
+
|
58 |
+
public static function enqueue_jquery_css() {
|
59 |
+
$theme_css = FrmStylesController::get_style_val('theme_css');
|
60 |
+
if ( $theme_css != -1 ) {
|
61 |
+
wp_enqueue_style('jquery-theme', self::jquery_css_url($theme_css), array(), FrmAppHelper::plugin_version());
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
public static function get_upload_base() {
|
66 |
+
$uploads = wp_upload_dir();
|
67 |
+
if ( is_ssl() && ! preg_match('/^https:\/\/.*\..*$/', $uploads['baseurl']) ) {
|
68 |
+
$uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']);
|
69 |
+
}
|
70 |
+
|
71 |
+
return $uploads;
|
72 |
+
}
|
73 |
+
|
74 |
+
public static function style_menu($active = '') {
|
75 |
+
?>
|
76 |
+
<h2 class="nav-tab-wrapper">
|
77 |
+
<a href="<?php echo admin_url('admin.php?page=formidable-styles') ?>" class="nav-tab <?php echo ( '' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Edit Styles', 'formidable' ) ?></a>
|
78 |
+
<a href="<?php echo admin_url('admin.php?page=formidable-styles&frm_action=manage') ?>" class="nav-tab <?php echo ( 'manage' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Manage Form Styles', 'formidable' ) ?></a>
|
79 |
+
<a href="<?php echo admin_url('admin.php?page=formidable-styles&frm_action=custom_css') ?>" class="nav-tab <?php echo ( 'custom_css' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Custom CSS', 'formidable' ) ?></a>
|
80 |
+
</h2>
|
81 |
+
<?php
|
82 |
+
}
|
83 |
+
|
84 |
+
public static function minus_icons() {
|
85 |
+
return array(
|
86 |
+
0 => array( '-' => '62e', '+' => '62f'),
|
87 |
+
1 => array( '-' => '600', '+' => '602'),
|
88 |
+
2 => array( '-' => '604', '+' => '603'),
|
89 |
+
3 => array( '-' => '633', '+' => '632'),
|
90 |
+
4 => array( '-' => '613', '+' => '60f'),
|
91 |
+
);
|
92 |
+
}
|
93 |
+
|
94 |
+
public static function arrow_icons() {
|
95 |
+
$minus_icons = self::minus_icons();
|
96 |
+
|
97 |
+
return array(
|
98 |
+
6 => array( '-' => '62d', '+' => '62a'),
|
99 |
+
0 => array( '-' => '60d', '+' => '609'),
|
100 |
+
1 => array( '-' => '60e', '+' => '60c'),
|
101 |
+
2 => array( '-' => '630', '+' => '631'),
|
102 |
+
3 => array( '-' => '62b', '+' => '628'),
|
103 |
+
4 => array( '-' => '62c', '+' => '629'),
|
104 |
+
5 => array( '-' => '635', '+' => '634'),
|
105 |
+
'p0' => $minus_icons[0],
|
106 |
+
'p1' => $minus_icons[1],
|
107 |
+
'p2' => $minus_icons[2],
|
108 |
+
'p3' => $minus_icons[3],
|
109 |
+
'p4' => $minus_icons[4],
|
110 |
+
);
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* @since 2.0
|
115 |
+
* @return The class for this icon
|
116 |
+
*/
|
117 |
+
public static function icon_key_to_class($key, $icon = '+', $type = 'arrow') {
|
118 |
+
if ( 'arrow' == $type && is_numeric($key) ) {
|
119 |
+
//frm_arrowup6_icon
|
120 |
+
$arrow = array( '-' => 'down', '+' => 'up');
|
121 |
+
$class = 'frm_arrow'. $arrow[$icon];
|
122 |
+
} else {
|
123 |
+
//frm_minus1_icon
|
124 |
+
$key = str_replace('p', '', $key);
|
125 |
+
$plus = array( '-' => 'minus', '+' => 'plus');
|
126 |
+
$class = 'frm_'. $plus[$icon];
|
127 |
+
}
|
128 |
+
|
129 |
+
if ( $key ) {
|
130 |
+
$class .= $key;
|
131 |
+
}
|
132 |
+
$class .= '_icon';
|
133 |
+
|
134 |
+
return $class;
|
135 |
+
}
|
136 |
+
|
137 |
+
public static function bs_icon_select($style, $frm_style, $type = 'arrow') {
|
138 |
+
$function_name = $type . '_icons';
|
139 |
+
$icons = self::$function_name();
|
140 |
+
unset( $function_name );
|
141 |
+
|
142 |
+
$name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
|
143 |
+
?>
|
144 |
+
<select name="<?php echo esc_attr( $frm_style->get_field_name($name) ) ?>" id="frm_<?php echo esc_attr( $name ) ?>" class="frm_icon_font frm_multiselect hide-if-js">
|
145 |
+
<?php foreach ( $icons as $key => $icon ) { ?>
|
146 |
+
<option value="<?php echo esc_attr( $key ) ?>" <?php selected( $style->post_content[$name], $key ) ?>>
|
147 |
+
<?php echo ''. $icon['+'] .'; '. $icon['-'] .';'; ?>
|
148 |
+
</option>
|
149 |
+
<?php } ?>
|
150 |
+
</select>
|
151 |
+
|
152 |
+
<div class="btn-group hide-if-no-js" id="frm_<?php echo esc_attr( $name ) ?>_select">
|
153 |
+
<button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
|
154 |
+
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[$name], '+', $type ) ) ?>"></i>
|
155 |
+
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[$name], '-', $type ) ) ?>"></i>
|
156 |
+
<b class="caret"></b>
|
157 |
+
</button>
|
158 |
+
<ul class="multiselect-container frm-dropdown-menu">
|
159 |
+
<?php foreach ( $icons as $key => $icon ) { ?>
|
160 |
+
<li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : '' ?>>
|
161 |
+
<a href="javascript:void(0);">
|
162 |
+
<label>
|
163 |
+
<input type="radio" value="<?php echo esc_attr( $key ) ?>"/>
|
164 |
+
<span>
|
165 |
+
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '+', $type ) ) ?>"></i>
|
166 |
+
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '-', $type ) ) ?>"></i>
|
167 |
+
</span>
|
168 |
+
</label>
|
169 |
+
</a>
|
170 |
+
</li>
|
171 |
+
<?php } ?>
|
172 |
+
</ul>
|
173 |
+
</div>
|
174 |
+
<?php
|
175 |
+
}
|
176 |
+
|
177 |
+
public static function hex2rgb($hex) {
|
178 |
+
$hex = str_replace('#', '', $hex);
|
179 |
+
|
180 |
+
if ( strlen($hex) == 3 ) {
|
181 |
+
$r = hexdec( substr($hex,0,1).substr($hex,0,1) );
|
182 |
+
$g = hexdec( substr($hex,1,1).substr($hex,1,1) );
|
183 |
+
$b = hexdec( substr($hex,2,1).substr($hex,2,1) );
|
184 |
+
} else {
|
185 |
+
$r = hexdec( substr($hex,0,2) );
|
186 |
+
$g = hexdec( substr($hex,2,2) );
|
187 |
+
$b = hexdec( substr($hex,4,2) );
|
188 |
+
}
|
189 |
+
$rgb = array($r, $g, $b);
|
190 |
+
return implode(',', $rgb); // returns the rgb values separated by commas
|
191 |
+
//return $rgb; // returns an array with the rgb values
|
192 |
+
}
|
193 |
+
}
|
classes/helpers/FrmXMLHelper.php
CHANGED
@@ -1,138 +1,148 @@
|
|
1 |
<?php
|
2 |
-
if ( !defined('ABSPATH') )
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
$defaults = array(
|
23 |
'forms' => 0, 'fields' => 0, 'terms' => 0,
|
|
|
|
|
24 |
);
|
25 |
-
|
26 |
$imported = array(
|
27 |
'imported' => $defaults,
|
28 |
'updated' => $defaults,
|
29 |
'forms' => array(),
|
30 |
);
|
31 |
-
|
32 |
unset($defaults);
|
33 |
-
|
34 |
if ( !defined('WP_IMPORTING') ) {
|
35 |
define('WP_IMPORTING', true);
|
36 |
}
|
37 |
-
|
38 |
if ( !class_exists('DOMDocument') ) {
|
39 |
return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
|
40 |
}
|
41 |
-
|
42 |
$dom = new DOMDocument;
|
43 |
$success = $dom->loadXML( file_get_contents( $file ) );
|
44 |
-
if (
|
45 |
return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
|
46 |
}
|
47 |
-
|
48 |
$xml = simplexml_import_dom( $dom );
|
49 |
unset( $dom );
|
50 |
|
51 |
// halt if loading produces an error
|
52 |
-
if (
|
53 |
return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
|
54 |
}
|
55 |
-
|
56 |
// add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
unset($xml->form);
|
67 |
-
}
|
68 |
-
|
69 |
$return = apply_filters('frm_importing_xml', $imported, $xml );
|
70 |
-
|
71 |
return $return;
|
72 |
}
|
73 |
-
|
74 |
public static function import_xml_terms($terms, $imported) {
|
75 |
foreach ( $terms as $t ) {
|
76 |
if ( term_exists((string) $t->term_slug, (string) $t->term_taxonomy) ) {
|
77 |
continue;
|
78 |
}
|
79 |
-
|
80 |
$term_id = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array(
|
81 |
'slug' => (string) $t->term_slug,
|
82 |
'description' => (string) $t->term_description,
|
83 |
'term_parent' => (string) $t->term_parent,
|
84 |
'slug' => (string) $t->term_slug,
|
85 |
));
|
86 |
-
|
87 |
if ( $term_id ) {
|
88 |
$imported['imported']['terms']++;
|
89 |
}
|
90 |
-
|
91 |
-
unset($term_id);
|
92 |
-
unset($t);
|
93 |
}
|
94 |
-
|
95 |
return $imported;
|
96 |
}
|
97 |
-
|
98 |
public static function import_xml_forms($forms, $imported) {
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
102 |
foreach ( $forms as $item ) {
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
122 |
$edit_query['created_at'] = $form['created_at'];
|
123 |
}
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
128 |
unset($edit_query);
|
129 |
-
|
130 |
-
if ( !empty($this_form) ) {
|
131 |
-
$form_id = $this_form->id;
|
132 |
-
|
133 |
$imported['updated']['forms']++;
|
134 |
-
|
135 |
-
$
|
|
|
|
|
136 |
$old_fields = array();
|
137 |
foreach ( $form_fields as $f ) {
|
138 |
$old_fields[$f->id] = $f;
|
@@ -142,12 +152,27 @@ class FrmXMLHelper{
|
|
142 |
$form_fields = $old_fields;
|
143 |
unset($old_fields);
|
144 |
} else {
|
|
|
145 |
//form does not exist, so create it
|
146 |
-
|
|
|
147 |
$imported['imported']['forms']++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
}
|
149 |
}
|
150 |
-
|
151 |
foreach ( $item->field as $field ) {
|
152 |
$f = array(
|
153 |
'id' => (int) $field->id,
|
@@ -162,25 +187,29 @@ class FrmXMLHelper{
|
|
162 |
'options' => FrmAppHelper::maybe_json_decode( (string) $field->options),
|
163 |
'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options)
|
164 |
);
|
165 |
-
|
166 |
-
if ( is_array($f['default_value']) && in_array($f['type'], array(
|
|
|
|
|
|
|
|
|
167 |
if ( count($f['default_value']) === 1 ) {
|
168 |
$f['default_value'] = '['. reset($f['default_value']) .']';
|
169 |
} else {
|
170 |
$f['default_value'] = reset($f['default_value']);
|
171 |
}
|
172 |
}
|
173 |
-
|
174 |
$f = apply_filters('frm_duplicated_field', $f);
|
175 |
-
|
176 |
-
if ( $this_form ) {
|
177 |
// check for field to edit by field id
|
178 |
if ( isset($form_fields[$f['id']]) ) {
|
179 |
-
|
180 |
$imported['updated']['fields']++;
|
181 |
-
|
182 |
unset($form_fields[$f['id']]);
|
183 |
-
|
184 |
//unset old field key
|
185 |
if ( isset($form_fields[$f['field_key']]) ) {
|
186 |
unset($form_fields[$f['field_key']]);
|
@@ -188,51 +217,358 @@ class FrmXMLHelper{
|
|
188 |
} else if ( isset($form_fields[$f['field_key']]) ) {
|
189 |
// check for field to edit by field key
|
190 |
unset($f['id']);
|
191 |
-
|
192 |
-
|
193 |
$imported['updated']['fields']++;
|
194 |
-
|
195 |
unset($form_fields[$form_fields[$f['field_key']]]); //unset old field id
|
196 |
unset($form_fields[$f['field_key']]); //unset old field key
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
198 |
// if no matching field id or key in this form, create the field
|
199 |
$imported['imported']['fields']++;
|
200 |
}
|
201 |
-
|
|
|
|
|
|
|
|
|
202 |
$imported['imported']['fields']++;
|
203 |
}
|
204 |
-
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
206 |
}
|
207 |
-
|
208 |
-
|
209 |
// Delete any fields attached to this form that were not included in the template
|
210 |
-
if ( isset($form_fields) && !empty($form_fields) ) {
|
211 |
-
|
212 |
if ( is_object($field) ) {
|
213 |
-
|
214 |
}
|
215 |
unset($field);
|
216 |
}
|
217 |
unset($form_fields);
|
218 |
}
|
219 |
-
|
220 |
-
|
221 |
// Update field ids/keys to new ones
|
222 |
-
do_action('frm_after_duplicate_form', $form_id, $form);
|
223 |
-
|
224 |
$imported['forms'][ (int) $item->id] = $form_id;
|
225 |
-
|
226 |
-
|
227 |
-
|
|
|
|
|
228 |
}
|
229 |
-
|
230 |
-
unset($frm_form);
|
231 |
-
unset($frm_field);
|
232 |
-
|
233 |
return $imported;
|
234 |
}
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
public static function cdata( $str ) {
|
237 |
$str = maybe_unserialize($str);
|
238 |
if ( is_array($str) ) {
|
@@ -240,15 +576,367 @@ class FrmXMLHelper{
|
|
240 |
} else if (seems_utf8( $str ) == false ) {
|
241 |
$str = utf8_encode( $str );
|
242 |
}
|
243 |
-
|
244 |
if ( is_numeric($str) ) {
|
245 |
return $str;
|
246 |
}
|
247 |
-
|
248 |
// $str = ent2ncr(esc_html($str));
|
249 |
$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
|
250 |
|
251 |
return $str;
|
252 |
}
|
253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
}
|
1 |
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
5 |
+
|
6 |
+
class FrmXMLHelper {
|
7 |
+
|
8 |
+
public static function get_xml_values( $opt, $padding ) {
|
9 |
+
if ( is_array( $opt ) ) {
|
10 |
+
foreach ( $opt as $ok => $ov ) {
|
11 |
+
echo "\n" . $padding;
|
12 |
+
echo '<' . ( is_numeric( $ok ) ? 'key:' : '' ) . $ok . '>';
|
13 |
+
self::get_xml_values( $ov, $padding .' ' );
|
14 |
+
if ( is_array( $ov ) ) {
|
15 |
+
echo "\n" . $padding;
|
16 |
+
}
|
17 |
+
echo '</' . ( is_numeric( $ok ) ? 'key:' : '' ) . $ok . '>';
|
18 |
+
}
|
19 |
+
} else {
|
20 |
+
echo self::cdata( $opt );
|
21 |
+
}
|
22 |
+
}
|
23 |
+
|
24 |
+
public static function import_xml($file) {
|
25 |
$defaults = array(
|
26 |
'forms' => 0, 'fields' => 0, 'terms' => 0,
|
27 |
+
'posts' => 0, 'views' => 0, 'actions' => 0,
|
28 |
+
'styles' => 0,
|
29 |
);
|
30 |
+
|
31 |
$imported = array(
|
32 |
'imported' => $defaults,
|
33 |
'updated' => $defaults,
|
34 |
'forms' => array(),
|
35 |
);
|
36 |
+
|
37 |
unset($defaults);
|
38 |
+
|
39 |
if ( !defined('WP_IMPORTING') ) {
|
40 |
define('WP_IMPORTING', true);
|
41 |
}
|
42 |
+
|
43 |
if ( !class_exists('DOMDocument') ) {
|
44 |
return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
|
45 |
}
|
46 |
+
|
47 |
$dom = new DOMDocument;
|
48 |
$success = $dom->loadXML( file_get_contents( $file ) );
|
49 |
+
if ( ! $success ) {
|
50 |
return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
|
51 |
}
|
52 |
+
|
53 |
$xml = simplexml_import_dom( $dom );
|
54 |
unset( $dom );
|
55 |
|
56 |
// halt if loading produces an error
|
57 |
+
if ( ! $xml ) {
|
58 |
return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
|
59 |
}
|
60 |
+
|
61 |
// add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
|
62 |
+
foreach ( array( 'term', 'form', 'view' ) as $item_type ) {
|
63 |
+
// grab cats, tags, and terms, or forms or posts
|
64 |
+
if ( isset($xml->{$item_type} ) ) {
|
65 |
+
$function_name = 'import_xml_' . $item_type . 's';
|
66 |
+
$imported = self::$function_name( $xml->{$item_type}, $imported );
|
67 |
+
unset( $function_name, $xml->{$item_type} );
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
|
|
|
|
|
|
71 |
$return = apply_filters('frm_importing_xml', $imported, $xml );
|
72 |
+
|
73 |
return $return;
|
74 |
}
|
75 |
+
|
76 |
public static function import_xml_terms($terms, $imported) {
|
77 |
foreach ( $terms as $t ) {
|
78 |
if ( term_exists((string) $t->term_slug, (string) $t->term_taxonomy) ) {
|
79 |
continue;
|
80 |
}
|
81 |
+
|
82 |
$term_id = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array(
|
83 |
'slug' => (string) $t->term_slug,
|
84 |
'description' => (string) $t->term_description,
|
85 |
'term_parent' => (string) $t->term_parent,
|
86 |
'slug' => (string) $t->term_slug,
|
87 |
));
|
88 |
+
|
89 |
if ( $term_id ) {
|
90 |
$imported['imported']['terms']++;
|
91 |
}
|
92 |
+
|
93 |
+
unset($term_id, $t);
|
|
|
94 |
}
|
95 |
+
|
96 |
return $imported;
|
97 |
}
|
98 |
+
|
99 |
public static function import_xml_forms($forms, $imported) {
|
100 |
+
|
101 |
+
// Keep track of repeating sections that are created
|
102 |
+
$repeat_fields = array();
|
103 |
+
|
104 |
foreach ( $forms as $item ) {
|
105 |
+
$form = array(
|
106 |
+
'id' => (int) $item->id,
|
107 |
+
'form_key' => (string) $item->form_key,
|
108 |
+
'name' => (string) $item->name,
|
109 |
+
'description' => (string) $item->description,
|
110 |
+
'options' => (string) $item->options,
|
111 |
+
'logged_in' => (int) $item->logged_in,
|
112 |
+
'is_template' => (int) $item->is_template,
|
113 |
+
'default_template' => (int) $item->default_template,
|
114 |
+
'editable' => (int) $item->editable,
|
115 |
+
'status' => (string) $item->status,
|
116 |
+
'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0,
|
117 |
+
'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
|
118 |
+
);
|
119 |
+
|
120 |
+
$form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
|
121 |
+
|
122 |
+
// if template, allow to edit if form keys match, otherwise, creation date must also match
|
123 |
+
$edit_query = array( 'form_key' => $form['form_key'], 'is_template' => $form['is_template']);
|
124 |
+
if ( ! $form['is_template'] ) {
|
125 |
$edit_query['created_at'] = $form['created_at'];
|
126 |
}
|
127 |
+
|
128 |
+
if ( ! empty($form['parent_form_id']) && isset($imported['forms'][$form['parent_form_id']]) ) {
|
129 |
+
// replace the old parent id with the new one
|
130 |
+
$form['parent_form_id'] = $imported['forms'][$form['parent_form_id']];
|
131 |
+
}
|
132 |
+
|
133 |
+
$edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
|
134 |
+
|
135 |
+
$this_form = FrmForm::getAll($edit_query, '', 1);
|
136 |
unset($edit_query);
|
137 |
+
|
138 |
+
if ( ! empty( $this_form ) ) {
|
139 |
+
$old_id = $form_id = $this_form->id;
|
140 |
+
FrmForm::update($form_id, $form );
|
141 |
$imported['updated']['forms']++;
|
142 |
+
// Keep track of whether this specific form was updated or not
|
143 |
+
$imported['form_status'][$form_id] = 'updated';
|
144 |
+
|
145 |
+
$form_fields = FrmField::get_all_for_form( $form_id );
|
146 |
$old_fields = array();
|
147 |
foreach ( $form_fields as $f ) {
|
148 |
$old_fields[$f->id] = $f;
|
152 |
$form_fields = $old_fields;
|
153 |
unset($old_fields);
|
154 |
} else {
|
155 |
+
$old_id = false;
|
156 |
//form does not exist, so create it
|
157 |
+
$form_id = FrmForm::create( $form );
|
158 |
+
if ( $form_id ) {
|
159 |
$imported['imported']['forms']++;
|
160 |
+
// Keep track of whether this specific form was updated or not
|
161 |
+
$imported['form_status'][$form_id] = 'imported';
|
162 |
+
|
163 |
+
// Check if any repeating sections form_select need to be updated
|
164 |
+
if ( isset( $repeat_fields[ $form['id'] ] ) ) {
|
165 |
+
// Get section field
|
166 |
+
$section_field = FrmField::getOne( $repeat_fields[ $form['id'] ] );
|
167 |
+
$field_opts = maybe_unserialize( $section_field->field_options );
|
168 |
+
$field_opts['form_select'] = $form_id;
|
169 |
+
|
170 |
+
// update form_select now
|
171 |
+
FrmField::update( $repeat_fields[ $form['id'] ], array( 'field_options' => maybe_serialize( $field_opts ) ) );
|
172 |
+
}
|
173 |
}
|
174 |
}
|
175 |
+
|
176 |
foreach ( $item->field as $field ) {
|
177 |
$f = array(
|
178 |
'id' => (int) $field->id,
|
187 |
'options' => FrmAppHelper::maybe_json_decode( (string) $field->options),
|
188 |
'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options)
|
189 |
);
|
190 |
+
|
191 |
+
if ( is_array($f['default_value']) && in_array($f['type'], array(
|
192 |
+
'text', 'email', 'url', 'textarea',
|
193 |
+
'number','phone', 'date', 'time',
|
194 |
+
'hidden', 'password', 'tag', 'image',
|
195 |
+
)) ) {
|
196 |
if ( count($f['default_value']) === 1 ) {
|
197 |
$f['default_value'] = '['. reset($f['default_value']) .']';
|
198 |
} else {
|
199 |
$f['default_value'] = reset($f['default_value']);
|
200 |
}
|
201 |
}
|
202 |
+
|
203 |
$f = apply_filters('frm_duplicated_field', $f);
|
204 |
+
|
205 |
+
if ( ! empty($this_form) ) {
|
206 |
// check for field to edit by field id
|
207 |
if ( isset($form_fields[$f['id']]) ) {
|
208 |
+
FrmField::update( $f['id'], $f );
|
209 |
$imported['updated']['fields']++;
|
210 |
+
|
211 |
unset($form_fields[$f['id']]);
|
212 |
+
|
213 |
//unset old field key
|
214 |
if ( isset($form_fields[$f['field_key']]) ) {
|
215 |
unset($form_fields[$f['field_key']]);
|
217 |
} else if ( isset($form_fields[$f['field_key']]) ) {
|
218 |
// check for field to edit by field key
|
219 |
unset($f['id']);
|
220 |
+
|
221 |
+
FrmField::update( $form_fields[$f['field_key']], $f );
|
222 |
$imported['updated']['fields']++;
|
223 |
+
|
224 |
unset($form_fields[$form_fields[$f['field_key']]]); //unset old field id
|
225 |
unset($form_fields[$f['field_key']]); //unset old field key
|
226 |
+
} else {
|
227 |
+
$new_id = FrmField::create( $f );
|
228 |
+
if ( $new_id == false ) {
|
229 |
+
continue;
|
230 |
+
}
|
231 |
+
|
232 |
// if no matching field id or key in this form, create the field
|
233 |
$imported['imported']['fields']++;
|
234 |
}
|
235 |
+
} else {
|
236 |
+
$new_id = FrmField::create( $f );
|
237 |
+
if ( $new_id == false ) {
|
238 |
+
continue;
|
239 |
+
}
|
240 |
$imported['imported']['fields']++;
|
241 |
}
|
242 |
+
|
243 |
+
// Check if a repeating section was just created
|
244 |
+
if ( isset( $new_id ) && $f['type'] == 'divider' && isset( $f['field_options']['repeat'] ) && $f['field_options']['repeat'] ) {
|
245 |
+
$repeat_fields[ $f['field_options']['form_select'] ] = $new_id;
|
246 |
+
}
|
247 |
+
|
248 |
+
unset($field, $new_id);
|
249 |
}
|
250 |
+
|
|
|
251 |
// Delete any fields attached to this form that were not included in the template
|
252 |
+
if ( isset( $form_fields ) && ! empty( $form_fields ) ) {
|
253 |
+
foreach ( $form_fields as $field ) {
|
254 |
if ( is_object($field) ) {
|
255 |
+
FrmField::destroy($field->id);
|
256 |
}
|
257 |
unset($field);
|
258 |
}
|
259 |
unset($form_fields);
|
260 |
}
|
261 |
+
|
|
|
262 |
// Update field ids/keys to new ones
|
263 |
+
do_action('frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id));
|
264 |
+
|
265 |
$imported['forms'][ (int) $item->id] = $form_id;
|
266 |
+
|
267 |
+
// Send pre 2.0 form options through function that creates actions
|
268 |
+
self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true );
|
269 |
+
|
270 |
+
unset($form, $item);
|
271 |
}
|
272 |
+
|
|
|
|
|
|
|
273 |
return $imported;
|
274 |
}
|
275 |
+
|
276 |
+
public static function import_xml_views($views, $imported) {
|
277 |
+
$imported['posts'] = array();
|
278 |
+
$form_action_type = FrmFormActionsController::$action_post_type;
|
279 |
+
|
280 |
+
$post_types = array(
|
281 |
+
'frm_display' => 'views',
|
282 |
+
$form_action_type => 'actions',
|
283 |
+
'frm_styles' => 'styles',
|
284 |
+
);
|
285 |
+
|
286 |
+
foreach ( $views as $item ) {
|
287 |
+
$post = array(
|
288 |
+
'post_title' => (string) $item->title,
|
289 |
+
'post_name' => (string) $item->post_name,
|
290 |
+
'post_type' => (string) $item->post_type,
|
291 |
+
'post_password' => (string) $item->post_password,
|
292 |
+
'guid' => (string) $item->guid,
|
293 |
+
'post_status' => (string) $item->status,
|
294 |
+
'post_author' => FrmAppHelper::get_user_id_param( (string) $item->post_author ),
|
295 |
+
'post_id' => (int) $item->post_id,
|
296 |
+
'post_parent' => (int) $item->post_parent,
|
297 |
+
'menu_order' => (int) $item->menu_order,
|
298 |
+
'post_content' => FrmFieldsHelper::switch_field_ids((string) $item->content),
|
299 |
+
'post_excerpt' => FrmFieldsHelper::switch_field_ids((string) $item->excerpt),
|
300 |
+
'is_sticky' => (string) $item->is_sticky,
|
301 |
+
'comment_status' => (string) $item->comment_status,
|
302 |
+
'post_date' => (string) $item->post_date,
|
303 |
+
'post_date_gmt' => (string) $item->post_date_gmt,
|
304 |
+
'ping_status' => (string) $item->ping_status,
|
305 |
+
'postmeta' => array(),
|
306 |
+
'tax_input' => array(),
|
307 |
+
);
|
308 |
+
|
309 |
+
$old_id = $post['post_id'];
|
310 |
+
self::populate_post($post, $item, $imported);
|
311 |
+
|
312 |
+
unset($item);
|
313 |
+
|
314 |
+
if ( $post['post_type'] == $form_action_type ) {
|
315 |
+
$action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
|
316 |
+
$post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
|
317 |
+
unset($action_control);
|
318 |
+
} else if ( $post['post_type'] == 'frm_styles' ) {
|
319 |
+
// Properly encode post content before inserting the post
|
320 |
+
$post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
|
321 |
+
$post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
|
322 |
+
|
323 |
+
// Create/update post now
|
324 |
+
$post_id = wp_insert_post( $post );
|
325 |
+
} else {
|
326 |
+
// Create/update post now
|
327 |
+
$post_id = wp_insert_post( $post );
|
328 |
+
}
|
329 |
+
|
330 |
+
if ( ! is_numeric($post_id) ) {
|
331 |
+
continue;
|
332 |
+
}
|
333 |
+
|
334 |
+
self::update_postmeta($post, $post_id);
|
335 |
+
|
336 |
+
$this_type = 'posts';
|
337 |
+
if ( isset($post_types[$post['post_type']]) ) {
|
338 |
+
$this_type = $post_types[$post['post_type']];
|
339 |
+
}
|
340 |
+
|
341 |
+
if ( isset($post['ID']) && $post_id == $post['ID'] ) {
|
342 |
+
$imported['updated'][ $this_type ]++;
|
343 |
+
} else {
|
344 |
+
$imported['imported'][ $this_type ]++;
|
345 |
+
}
|
346 |
+
|
347 |
+
unset($post);
|
348 |
+
|
349 |
+
$imported['posts'][ (int) $old_id] = $post_id;
|
350 |
+
}
|
351 |
+
|
352 |
+
return $imported;
|
353 |
+
}
|
354 |
+
|
355 |
+
private static function populate_post( &$post, $item, $imported ) {
|
356 |
+
if ( isset($item->attachment_url) ) {
|
357 |
+
$post['attachment_url'] = (string) $item->attachment_url;
|
358 |
+
}
|
359 |
+
|
360 |
+
if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
|
361 |
+
// update to new form id
|
362 |
+
$post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
|
363 |
+
}
|
364 |
+
|
365 |
+
foreach ( $item->postmeta as $meta ) {
|
366 |
+
self::populate_postmeta($post, $meta, $imported);
|
367 |
+
unset($meta);
|
368 |
+
}
|
369 |
+
|
370 |
+
self::populate_taxonomies($post, $item);
|
371 |
+
|
372 |
+
self::maybe_editing_post($post);
|
373 |
+
}
|
374 |
+
|
375 |
+
private static function populate_postmeta( &$post, $meta, $imported ) {
|
376 |
+
global $frm_duplicate_ids;
|
377 |
+
|
378 |
+
$m = array(
|
379 |
+
'key' => (string) $meta->meta_key,
|
380 |
+
'value' => (string) $meta->meta_value,
|
381 |
+
);
|
382 |
+
|
383 |
+
//switch old form and field ids to new ones
|
384 |
+
if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) {
|
385 |
+
$m['value'] = $imported['forms'][ (int) $m['value'] ];
|
386 |
+
} else {
|
387 |
+
$m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
|
388 |
+
|
389 |
+
if ( ! empty($frm_duplicate_ids) ) {
|
390 |
+
|
391 |
+
if ( $m['key'] == 'frm_dyncontent' ) {
|
392 |
+
$m['value'] = FrmFieldsHelper::switch_field_ids($m['value']);
|
393 |
+
} else if ( $m['key'] == 'frm_options' ) {
|
394 |
+
|
395 |
+
foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
|
396 |
+
if ( isset($m['value'][$setting_name]) && is_numeric($m['value'][$setting_name]) && isset($frm_duplicate_ids[$m['value'][$setting_name]]) ) {
|
397 |
+
$m['value'][$setting_name] = $frm_duplicate_ids[$m['value'][$setting_name]];
|
398 |
+
}
|
399 |
+
}
|
400 |
+
|
401 |
+
$check_dup_array = array();
|
402 |
+
if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
|
403 |
+
if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
|
404 |
+
$m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
|
405 |
+
} else if ( is_array( $m['value']['order_by'] ) ) {
|
406 |
+
$check_dup_array[] = 'order_by';
|
407 |
+
}
|
408 |
+
}
|
409 |
+
|
410 |
+
if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
|
411 |
+
$check_dup_array[] = 'where';
|
412 |
+
}
|
413 |
+
|
414 |
+
foreach ( $check_dup_array as $check_k ) {
|
415 |
+
foreach ( (array) $m['value'][$check_k] as $mk => $mv ) {
|
416 |
+
if ( isset($frm_duplicate_ids[$mv]) ) {
|
417 |
+
$m['value'][$check_k][$mk] = $frm_duplicate_ids[$mv];
|
418 |
+
}
|
419 |
+
unset($mk, $mv);
|
420 |
+
}
|
421 |
+
}
|
422 |
+
}
|
423 |
+
}
|
424 |
+
}
|
425 |
+
|
426 |
+
if ( ! is_array($m['value']) ) {
|
427 |
+
$m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
|
428 |
+
}
|
429 |
+
|
430 |
+
$post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
|
431 |
+
}
|
432 |
+
|
433 |
+
/**
|
434 |
+
* Add terms to post
|
435 |
+
* @param array $post by reference
|
436 |
+
* @param object $item The XML object data
|
437 |
+
*/
|
438 |
+
private static function populate_taxonomies( &$post, $item ) {
|
439 |
+
foreach ( $item->category as $c ) {
|
440 |
+
$att = $c->attributes();
|
441 |
+
if ( ! isset( $att['nicename'] ) ) {
|
442 |
+
continue;
|
443 |
+
}
|
444 |
+
|
445 |
+
$taxonomy = (string) $att['domain'];
|
446 |
+
if ( is_taxonomy_hierarchical($taxonomy) ) {
|
447 |
+
$name = (string) $att['nicename'];
|
448 |
+
$h_term = get_term_by('slug', $name, $taxonomy);
|
449 |
+
if ( $h_term ) {
|
450 |
+
$name = $h_term->term_id;
|
451 |
+
}
|
452 |
+
unset($h_term);
|
453 |
+
} else {
|
454 |
+
$name = (string) $c;
|
455 |
+
}
|
456 |
+
|
457 |
+
if ( ! isset($post['tax_input'][$taxonomy]) ) {
|
458 |
+
$post['tax_input'][$taxonomy] = array();
|
459 |
+
}
|
460 |
+
|
461 |
+
$post['tax_input'][$taxonomy][] = $name;
|
462 |
+
unset($name);
|
463 |
+
}
|
464 |
+
}
|
465 |
+
|
466 |
+
/**
|
467 |
+
* Edit post if the key and created time match
|
468 |
+
*/
|
469 |
+
private static function maybe_editing_post( &$post ) {
|
470 |
+
$match_by = array(
|
471 |
+
'post_type' => $post['post_type'],
|
472 |
+
'name' => $post['post_name'],
|
473 |
+
'post_status' => $post['post_status'],
|
474 |
+
'posts_per_page' => 1,
|
475 |
+
);
|
476 |
+
|
477 |
+
if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
|
478 |
+
$match_by['include'] = $post['post_id'];
|
479 |
+
unset($match_by['name']);
|
480 |
+
}
|
481 |
+
|
482 |
+
$editing = get_posts($match_by);
|
483 |
+
|
484 |
+
if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) {
|
485 |
+
// set the id of the post to edit
|
486 |
+
$post['ID'] = current($editing)->ID;
|
487 |
+
}
|
488 |
+
}
|
489 |
+
|
490 |
+
private static function update_postmeta( &$post, $post_id ) {
|
491 |
+
foreach ( $post['postmeta'] as $k => $v ) {
|
492 |
+
if ( '_edit_last' == $k ) {
|
493 |
+
$v = FrmAppHelper::get_user_id_param($v);
|
494 |
+
} else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
|
495 |
+
//change the attachment ID
|
496 |
+
$v = FrmProXMLHelper::get_file_id($v);
|
497 |
+
}
|
498 |
+
|
499 |
+
update_post_meta($post_id, $k, $v);
|
500 |
+
|
501 |
+
unset($k, $v);
|
502 |
+
}
|
503 |
+
}
|
504 |
+
|
505 |
+
/**
|
506 |
+
* @param string $message
|
507 |
+
*/
|
508 |
+
public static function parse_message($result, &$message, &$errors) {
|
509 |
+
if ( is_wp_error($result) ) {
|
510 |
+
$errors[] = $result->get_error_message();
|
511 |
+
} else if ( ! $result ) {
|
512 |
+
return;
|
513 |
+
}
|
514 |
+
|
515 |
+
if ( ! is_array($result) ) {
|
516 |
+
$message = $result;
|
517 |
+
return;
|
518 |
+
}
|
519 |
+
|
520 |
+
$t_strings = array(
|
521 |
+
'imported' => __( 'Imported', 'formidable' ),
|
522 |
+
'updated' => __( 'Updated', 'formidable' ),
|
523 |
+
);
|
524 |
+
|
525 |
+
$message = '<ul>';
|
526 |
+
foreach ( $result as $type => $results ) {
|
527 |
+
if ( ! isset($t_strings[$type]) ) {
|
528 |
+
// only print imported and updated
|
529 |
+
continue;
|
530 |
+
}
|
531 |
+
|
532 |
+
$s_message = array();
|
533 |
+
foreach ( $results as $k => $m ) {
|
534 |
+
self::item_count_message($m, $k, $s_message);
|
535 |
+
unset($k, $m);
|
536 |
+
}
|
537 |
+
|
538 |
+
if ( ! empty($s_message) ) {
|
539 |
+
$message .= '<li><strong>'. $t_strings[$type] .':</strong> ';
|
540 |
+
$message .= implode(', ', $s_message);
|
541 |
+
$message .= '</li>';
|
542 |
+
}
|
543 |
+
}
|
544 |
+
|
545 |
+
if ( $message == '<ul>' ) {
|
546 |
+
$message = '';
|
547 |
+
$errors[] = __( 'Nothing was imported or updated', 'formidable' );
|
548 |
+
} else {
|
549 |
+
$message .= '</ul>';
|
550 |
+
}
|
551 |
+
}
|
552 |
+
|
553 |
+
public static function item_count_message($m, $type, &$s_message) {
|
554 |
+
if ( ! $m ) {
|
555 |
+
return;
|
556 |
+
}
|
557 |
+
|
558 |
+
$strings = array(
|
559 |
+
'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
|
560 |
+
'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ),
|
561 |
+
'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
|
562 |
+
'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
|
563 |
+
'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
|
564 |
+
'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
|
565 |
+
'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
|
566 |
+
'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
|
567 |
+
);
|
568 |
+
|
569 |
+
$s_message[] = isset($strings[$type]) ? $strings[$type] : ' '. $m .' '. ucfirst($type);
|
570 |
+
}
|
571 |
+
|
572 |
public static function cdata( $str ) {
|
573 |
$str = maybe_unserialize($str);
|
574 |
if ( is_array($str) ) {
|
576 |
} else if (seems_utf8( $str ) == false ) {
|
577 |
$str = utf8_encode( $str );
|
578 |
}
|
579 |
+
|
580 |
if ( is_numeric($str) ) {
|
581 |
return $str;
|
582 |
}
|
583 |
+
|
584 |
// $str = ent2ncr(esc_html($str));
|
585 |
$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
|
586 |
|
587 |
return $str;
|
588 |
}
|
589 |
|
590 |
+
public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
|
591 |
+
// Get post type
|
592 |
+
$post_type = FrmFormActionsController::$action_post_type;
|
593 |
+
|
594 |
+
// Set up imported index, if not set up yet
|
595 |
+
if ( ! isset( $imported['imported']['actions'] ) ) {
|
596 |
+
$imported['imported']['actions'] = 0;
|
597 |
+
}
|
598 |
+
|
599 |
+
// Migrate post settings to action
|
600 |
+
self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
|
601 |
+
|
602 |
+
// Migrate email settings to action
|
603 |
+
self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
|
604 |
+
}
|
605 |
+
|
606 |
+
/**
|
607 |
+
* Migrate post settings to form action
|
608 |
+
*
|
609 |
+
* @param string $post_type
|
610 |
+
*/
|
611 |
+
private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
|
612 |
+
if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) {
|
613 |
+
return;
|
614 |
+
}
|
615 |
+
|
616 |
+
$new_action = array(
|
617 |
+
'post_type' => $post_type,
|
618 |
+
'post_excerpt' => 'wppost',
|
619 |
+
'post_title' => __( 'Create Posts', 'formidable' ),
|
620 |
+
'menu_order' => $form_id,
|
621 |
+
'post_status' => 'publish',
|
622 |
+
'post_content' => array(),
|
623 |
+
'post_name' => $form_id .'_wppost_1',
|
624 |
+
);
|
625 |
+
|
626 |
+
$post_settings = array(
|
627 |
+
'post_type', 'post_category', 'post_content',
|
628 |
+
'post_excerpt', 'post_title', 'post_name', 'post_date',
|
629 |
+
'post_status', 'post_custom_fields', 'post_password',
|
630 |
+
);
|
631 |
+
|
632 |
+
foreach ( $post_settings as $post_setting ) {
|
633 |
+
if ( isset( $form_options[$post_setting] ) ) {
|
634 |
+
$new_action['post_content'][$post_setting] = $form_options[$post_setting];
|
635 |
+
}
|
636 |
+
unset($post_setting);
|
637 |
+
}
|
638 |
+
|
639 |
+
$new_action['event'] = array( 'create', 'update');
|
640 |
+
|
641 |
+
if ( $switch ) {
|
642 |
+
// Fields with string or int saved
|
643 |
+
$basic_fields = array( 'post_title', 'post_content', 'post_excerpt', 'post_password', 'post_date', 'post_status' );
|
644 |
+
|
645 |
+
// Fields with arrays saved
|
646 |
+
$array_fields = array( 'post_category', 'post_custom_fields' );
|
647 |
+
|
648 |
+
$new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields );
|
649 |
+
}
|
650 |
+
$new_action['post_content'] = json_encode($new_action['post_content']);
|
651 |
+
|
652 |
+
$exists = get_posts( array(
|
653 |
+
'name' => $new_action['post_name'],
|
654 |
+
'post_type' => $new_action['post_type'],
|
655 |
+
'post_status' => $new_action['post_status'],
|
656 |
+
'numberposts' => 1,
|
657 |
+
) );
|
658 |
+
|
659 |
+
if ( ! $exists ) {
|
660 |
+
// Remove the balanceTags filter in case WordPress is trying to validate the XHTML
|
661 |
+
remove_filter( 'content_save_pre', 'balanceTags', 50 );
|
662 |
+
|
663 |
+
wp_insert_post( $new_action );
|
664 |
+
$imported['imported']['actions']++;
|
665 |
+
}
|
666 |
+
}
|
667 |
+
|
668 |
+
/**
|
669 |
+
* Switch old field IDs for new field IDs in emails and post
|
670 |
+
*
|
671 |
+
* @since 2.0
|
672 |
+
* @param $post_content - string to check for old field IDs
|
673 |
+
* @param $basic_fields - array of fields with string or int saved
|
674 |
+
* @param $array_fields - array of fields with arrays saved
|
675 |
+
* @return $post_content - string with new field IDs
|
676 |
+
*/
|
677 |
+
private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
|
678 |
+
global $frm_duplicate_ids;
|
679 |
+
|
680 |
+
// If there aren't IDs that were switched, end now
|
681 |
+
if ( ! $frm_duplicate_ids ) {
|
682 |
+
return;
|
683 |
+
}
|
684 |
+
|
685 |
+
// Get old IDs
|
686 |
+
$old = array_keys( $frm_duplicate_ids );
|
687 |
+
|
688 |
+
// Get new IDs
|
689 |
+
$new = array_values( $frm_duplicate_ids );
|
690 |
+
|
691 |
+
// Do a str_replace with each item to set the new IDs
|
692 |
+
foreach ( $post_content as $key => $setting ) {
|
693 |
+
if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
|
694 |
+
// Replace old IDs with new IDs
|
695 |
+
$post_content[$key] = str_replace( $old, $new, $setting );
|
696 |
+
} else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
|
697 |
+
foreach ( $setting as $k => $val ) {
|
698 |
+
// Replace old IDs with new IDs
|
699 |
+
$post_content[$key][$k] = str_replace( $old, $new, $val );
|
700 |
+
}
|
701 |
+
}
|
702 |
+
unset( $key, $setting );
|
703 |
+
}
|
704 |
+
return $post_content;
|
705 |
+
}
|
706 |
+
|
707 |
+
private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
|
708 |
+
// No old notifications or autoresponders to carry over
|
709 |
+
if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) ) {
|
710 |
+
return;
|
711 |
+
}
|
712 |
+
|
713 |
+
// Initialize notifications array
|
714 |
+
$notifications = array();
|
715 |
+
|
716 |
+
// Migrate regular notifications
|
717 |
+
self::migrate_notifications_to_action( $form_options, $form_id, $notifications );
|
718 |
+
|
719 |
+
// Migrate autoresponders
|
720 |
+
self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
|
721 |
+
|
722 |
+
if ( empty( $notifications ) ) {
|
723 |
+
return;
|
724 |
+
}
|
725 |
+
|
726 |
+
foreach ( $notifications as $new_notification ) {
|
727 |
+
$new_notification['post_type'] = $post_type;
|
728 |
+
$new_notification['post_excerpt'] = 'email';
|
729 |
+
$new_notification['post_title'] = __( 'Email Notification', 'formidable' );
|
730 |
+
$new_notification['menu_order'] = $form_id;
|
731 |
+
$new_notification['post_status'] = 'publish';
|
732 |
+
|
733 |
+
// Switch field IDs and keys, if needed
|
734 |
+
if ( $switch ) {
|
735 |
+
|
736 |
+
// Switch field IDs in email conditional logic
|
737 |
+
self::switch_email_contition_field_ids( $new_notification['post_content'] );
|
738 |
+
|
739 |
+
// Switch all other field IDs in email
|
740 |
+
$new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
|
741 |
+
}
|
742 |
+
$new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
|
743 |
+
|
744 |
+
$exists = get_posts( array(
|
745 |
+
'name' => $new_notification['post_name'],
|
746 |
+
'post_type' => $new_notification['post_type'],
|
747 |
+
'post_status' => $new_notification['post_status'],
|
748 |
+
'numberposts' => 1,
|
749 |
+
) );
|
750 |
+
|
751 |
+
if ( empty($exists) ) {
|
752 |
+
// Remove the balancTags filter in case WordPress is trying to validate the XHTML
|
753 |
+
remove_filter( 'content_save_pre', 'balanceTags', 50 );
|
754 |
+
|
755 |
+
wp_insert_post( $new_notification );
|
756 |
+
$imported['imported']['actions']++;
|
757 |
+
}
|
758 |
+
unset($new_notification);
|
759 |
+
}
|
760 |
+
}
|
761 |
+
|
762 |
+
private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
|
763 |
+
if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
|
764 |
+
// add old settings into notification array
|
765 |
+
$form_options['notification'] = array(0 => $form_options);
|
766 |
+
} else if ( isset( $form_options['notification']['email_to'] ) ) {
|
767 |
+
// make sure it's in the correct format
|
768 |
+
$form_options['notification'] = array(0 => $form_options['notification']);
|
769 |
+
}
|
770 |
+
|
771 |
+
if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
|
772 |
+
foreach ( $form_options['notification'] as $email_key => $notification ) {
|
773 |
+
|
774 |
+
$atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key );
|
775 |
+
|
776 |
+
// Format the email data
|
777 |
+
self::format_email_data( $atts, $notification );
|
778 |
+
|
779 |
+
if ( isset( $notification['twilio'] ) && $notification['twilio'] ) {
|
780 |
+
do_action( 'frm_create_twilio_action', $atts, $notification );
|
781 |
+
}
|
782 |
+
|
783 |
+
// Setup the new notification
|
784 |
+
$new_notification = array();
|
785 |
+
self::setup_new_notification( $new_notification, $notification, $atts );
|
786 |
+
|
787 |
+
$notifications[] = $new_notification;
|
788 |
+
}
|
789 |
+
}
|
790 |
+
}
|
791 |
+
|
792 |
+
private static function format_email_data( &$atts, $notification ) {
|
793 |
+
// Format email_to
|
794 |
+
self::format_email_to_data( $atts, $notification );
|
795 |
+
|
796 |
+
// Format the reply to email and name
|
797 |
+
$reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' );
|
798 |
+
foreach ( $reply_fields as $f => $val ) {
|
799 |
+
if ( isset( $notification[$f] ) ) {
|
800 |
+
$atts[$f] = $notification[$f];
|
801 |
+
if ( 'custom' == $notification[$f] ) {
|
802 |
+
$atts[$f] = $notification['cust_' . $f];
|
803 |
+
} else if ( is_numeric( $atts[$f] ) && ! empty( $atts[$f] ) ) {
|
804 |
+
$atts[$f] = '['. $atts[$f] .']';
|
805 |
+
}
|
806 |
+
}
|
807 |
+
unset( $f, $val );
|
808 |
+
}
|
809 |
+
|
810 |
+
// Format event
|
811 |
+
$atts['event'] = array( 'create');
|
812 |
+
if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
|
813 |
+
$atts['event'][] = 'update';
|
814 |
+
} else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
|
815 |
+
$atts['event'] = array( 'update');
|
816 |
+
}
|
817 |
+
}
|
818 |
+
|
819 |
+
private static function format_email_to_data( &$atts, $notification ) {
|
820 |
+
if ( isset( $notification['email_to'] ) ) {
|
821 |
+
$atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
|
822 |
+
} else {
|
823 |
+
$atts['email_to'] = array();
|
824 |
+
}
|
825 |
+
|
826 |
+
if ( isset( $notification['also_email_to'] ) ) {
|
827 |
+
$email_fields = (array) $notification['also_email_to'];
|
828 |
+
$atts['email_to'] = array_merge( $email_fields, $atts['email_to'] );
|
829 |
+
unset( $email_fields );
|
830 |
+
}
|
831 |
+
|
832 |
+
foreach ( $atts['email_to'] as $key => $email_field ) {
|
833 |
+
|
834 |
+
if ( is_numeric( $email_field ) ) {
|
835 |
+
$atts['email_to'][$key] = '['. $email_field .']';
|
836 |
+
}
|
837 |
+
|
838 |
+
if ( strpos( $email_field, '|') ) {
|
839 |
+
$email_opt = explode( '|', $email_field );
|
840 |
+
if ( isset( $email_opt[0] ) ) {
|
841 |
+
$atts['email_to'][$key] = '['. $email_opt[0] .' show='. $email_opt[1] .']';
|
842 |
+
}
|
843 |
+
unset( $email_opt );
|
844 |
+
}
|
845 |
+
}
|
846 |
+
$atts['email_to'] = implode(', ', $atts['email_to']);
|
847 |
+
}
|
848 |
+
|
849 |
+
private static function setup_new_notification( &$new_notification, $notification, $atts ) {
|
850 |
+
// Set up new notification
|
851 |
+
$new_notification = array(
|
852 |
+
'post_content' => array(
|
853 |
+
'email_to' => $atts['email_to'],
|
854 |
+
'event' => $atts['event'],
|
855 |
+
),
|
856 |
+
'post_name' => $atts['form_id'] .'_email_'. $atts['email_key'],
|
857 |
+
);
|
858 |
+
|
859 |
+
// Add more fields to the new notification
|
860 |
+
$add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
|
861 |
+
foreach ( $add_fields as $add_field ) {
|
862 |
+
if ( isset ( $notification[$add_field] ) ) {
|
863 |
+
$new_notification['post_content'][$add_field] = $notification[$add_field];
|
864 |
+
} else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
|
865 |
+
$new_notification['post_content'][$add_field] = 0;
|
866 |
+
} else {
|
867 |
+
$new_notification['post_content'][$add_field] = '';
|
868 |
+
}
|
869 |
+
unset( $add_field );
|
870 |
+
}
|
871 |
+
|
872 |
+
// Set reply to
|
873 |
+
$new_notification['post_content']['reply_to'] = $atts['reply_to'];
|
874 |
+
|
875 |
+
// Set from
|
876 |
+
if ( !empty( $atts['reply_to'] ) || !empty( $atts['reply_to_name'] ) ) {
|
877 |
+
$new_notification['post_content']['from'] = ( empty($atts['reply_to_name']) ? '[sitename]' : $atts['reply_to_name'] ) .' <'. ( empty($atts['reply_to']) ? '[admin_email]' : $atts['reply_to'] ) .'>';
|
878 |
+
}
|
879 |
+
}
|
880 |
+
|
881 |
+
/**
|
882 |
+
* Switch field IDs in pre-2.0 email conditional logic
|
883 |
+
*
|
884 |
+
* @param $post_content array, pass by reference
|
885 |
+
*/
|
886 |
+
private static function switch_email_contition_field_ids( &$post_content ){
|
887 |
+
// Switch field IDs in conditional logic
|
888 |
+
if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
|
889 |
+
foreach ( $post_content['conditions'] as $email_key => $val ) {
|
890 |
+
if ( is_numeric( $email_key ) ) {
|
891 |
+
$post_content['conditions'][$email_key] = self::switch_action_field_ids( $val, array( 'hide_field' ) );
|
892 |
+
}
|
893 |
+
unset( $email_key, $val);
|
894 |
+
}
|
895 |
+
}
|
896 |
+
}
|
897 |
+
|
898 |
+
private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
|
899 |
+
if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) {
|
900 |
+
// migrate autoresponder
|
901 |
+
|
902 |
+
$email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
|
903 |
+
if ( strpos($email_field, '|') ) {
|
904 |
+
// data from entries field
|
905 |
+
$email_field = explode('|', $email_field);
|
906 |
+
if ( isset($email_field[1]) ) {
|
907 |
+
$email_field = $email_field[1];
|
908 |
+
}
|
909 |
+
}
|
910 |
+
if ( is_numeric($email_field) && ! empty($email_field) ) {
|
911 |
+
$email_field = '['. $email_field .']';
|
912 |
+
}
|
913 |
+
|
914 |
+
$notification = $form_options;
|
915 |
+
$new_notification2 = array(
|
916 |
+
'post_content' => array(
|
917 |
+
'email_message' => $notification['ar_email_message'],
|
918 |
+
'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '',
|
919 |
+
'email_to' => $email_field,
|
920 |
+
'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0,
|
921 |
+
'inc_user_info' => 0,
|
922 |
+
),
|
923 |
+
'post_name' => $form_id .'_email_'. count( $notifications ),
|
924 |
+
);
|
925 |
+
|
926 |
+
$reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : '';
|
927 |
+
$reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : '';
|
928 |
+
|
929 |
+
if ( ! empty( $reply_to ) ) {
|
930 |
+
$new_notification2['post_content']['reply_to'] = $reply_to;
|
931 |
+
}
|
932 |
+
|
933 |
+
if ( ! empty( $reply_to ) || ! empty( $reply_to_name ) ) {
|
934 |
+
$new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>';
|
935 |
+
}
|
936 |
+
|
937 |
+
$notifications[] = $new_notification2;
|
938 |
+
unset( $new_notification2 );
|
939 |
+
}
|
940 |
+
}
|
941 |
+
|
942 |
}
|
classes/models/FrmDb.php
CHANGED
@@ -1,42 +1,78 @@
|
|
1 |
<?php
|
2 |
-
if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
class FrmDb{
|
8 |
-
|
9 |
-
function __construct(){
|
10 |
global $wpdb;
|
11 |
-
$this->fields = $wpdb->prefix .
|
12 |
-
$this->forms = $wpdb->prefix .
|
13 |
-
$this->entries = $wpdb->prefix .
|
14 |
-
$this->entry_metas = $wpdb->prefix .
|
15 |
}
|
16 |
-
|
17 |
-
function upgrade($old_db_version=false){
|
18 |
global $wpdb;
|
19 |
//$frm_db_version is the version of the database we're moving to
|
20 |
$frm_db_version = FrmAppHelper::$db_version;
|
21 |
-
$old_db_version = (float)$old_db_version;
|
22 |
-
if(
|
23 |
$old_db_version = get_option('frm_db_version');
|
|
|
24 |
|
25 |
-
if ($frm_db_version != $old_db_version){
|
26 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
$charset_collate = '';
|
29 |
-
if( $wpdb->
|
30 |
-
|
31 |
-
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
32 |
-
if( !empty($wpdb->collate) )
|
33 |
-
$charset_collate .= " COLLATE $wpdb->collate";
|
34 |
}
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
/* Create/Upgrade Fields Table */
|
37 |
-
$sql =
|
38 |
id int(11) NOT NULL auto_increment,
|
39 |
-
|
40 |
name text default NULL,
|
41 |
description text default NULL,
|
42 |
type text default NULL,
|
@@ -50,42 +86,37 @@ class FrmDb{
|
|
50 |
PRIMARY KEY (id),
|
51 |
KEY form_id (form_id),
|
52 |
UNIQUE KEY field_key (field_key)
|
53 |
-
|
54 |
|
55 |
-
dbDelta($sql);
|
56 |
-
|
57 |
/* Create/Upgrade Forms Table */
|
58 |
-
$sql =
|
59 |
id int(11) NOT NULL auto_increment,
|
60 |
-
|
61 |
name varchar(255) default NULL,
|
62 |
description text default NULL,
|
63 |
-
parent_form_id int(11) default
|
64 |
logged_in tinyint(1) default NULL,
|
65 |
editable tinyint(1) default NULL,
|
66 |
is_template tinyint(1) default 0,
|
67 |
default_template tinyint(1) default 0,
|
68 |
status varchar(255) default NULL,
|
69 |
-
prli_link_id int(11) default NULL,
|
70 |
options longtext default NULL,
|
71 |
created_at datetime NOT NULL,
|
72 |
PRIMARY KEY (id),
|
73 |
UNIQUE KEY form_key (form_key)
|
74 |
-
|
75 |
-
|
76 |
-
dbDelta($sql);
|
77 |
|
78 |
/* Create/Upgrade Items Table */
|
79 |
-
$sql =
|
80 |
id int(11) NOT NULL auto_increment,
|
81 |
-
|
82 |
name varchar(255) default NULL,
|
83 |
description text default NULL,
|
84 |
ip text default NULL,
|
85 |
form_id int(11) default NULL,
|
86 |
post_id int(11) default NULL,
|
87 |
user_id int(11) default NULL,
|
88 |
-
parent_item_id int(11) default
|
89 |
is_draft tinyint(1) default 0,
|
90 |
updated_by int(11) default NULL,
|
91 |
created_at datetime NOT NULL,
|
@@ -96,12 +127,10 @@ class FrmDb{
|
|
96 |
KEY user_id (user_id),
|
97 |
KEY parent_item_id (parent_item_id),
|
98 |
UNIQUE KEY item_key (item_key)
|
99 |
-
|
100 |
-
|
101 |
-
dbDelta($sql);
|
102 |
|
103 |
/* Create/Upgrade Meta Table */
|
104 |
-
$sql =
|
105 |
id int(11) NOT NULL auto_increment,
|
106 |
meta_value longtext default NULL,
|
107 |
field_id int(11) NOT NULL,
|
@@ -110,219 +139,526 @@ class FrmDb{
|
|
110 |
PRIMARY KEY (id),
|
111 |
KEY field_id (field_id),
|
112 |
KEY item_id (item_id)
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
125 |
}
|
126 |
}
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
133 |
}
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
$new_default_html = FrmFieldsHelper::get_default_html('text');
|
156 |
-
foreach($fields as $field){
|
157 |
-
$field->field_options = maybe_unserialize($field->field_options);
|
158 |
-
if ( !isset($field->field_options['custom_html']) || empty($field->field_options['custom_html']) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
|
159 |
-
$field->field_options['custom_html'] = $new_default_html;
|
160 |
-
$wpdb->update($this->fields, array('field_options' => maybe_serialize($field->field_options)), array( 'id' => $field->id ));
|
161 |
-
}
|
162 |
-
unset($field);
|
163 |
-
}
|
164 |
-
unset($default_html);
|
165 |
-
unset($old_default_html);
|
166 |
-
unset($fields);
|
167 |
}
|
168 |
-
|
169 |
-
|
170 |
-
$
|
171 |
-
$
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
unset($img);
|
182 |
-
|
183 |
-
$new_default_html = FrmFormsHelper::get_default_html('submit');
|
184 |
-
$draft_link = FrmFormsHelper::get_draft_link();
|
185 |
-
foreach($forms as $form){
|
186 |
-
$form->options = maybe_unserialize($form->options);
|
187 |
-
if(!isset($form->options['submit_html']) or empty($form->options['submit_html']))
|
188 |
-
continue;
|
189 |
-
|
190 |
-
if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
|
191 |
-
$form->options['submit_html'] = $new_default_html;
|
192 |
-
$wpdb->update($this->forms, array('options' => serialize($form->options)), array( 'id' => $form->id ));
|
193 |
-
}else if(!strpos($form->options['submit_html'], 'save_draft')){
|
194 |
-
$form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
|
195 |
-
$wpdb->update($this->forms, array('options' => serialize($form->options)), array( 'id' => $form->id ));
|
196 |
}
|
197 |
-
|
|
|
|
|
|
|
198 |
}
|
199 |
-
unset($forms);
|
200 |
}
|
201 |
-
|
202 |
-
|
203 |
|
204 |
-
|
205 |
-
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
}
|
208 |
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
function get_count($table, $args=array()){
|
218 |
-
global $wpdb;
|
219 |
-
extract(FrmDb::get_where_clause_and_values( $args ));
|
220 |
|
221 |
-
$
|
222 |
-
|
223 |
-
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
$values = array();
|
229 |
-
if(is_array($args)){
|
230 |
-
foreach($args as $key => $value){
|
231 |
-
$where .= (!empty($where)) ? ' AND' : ' WHERE';
|
232 |
-
$where .= " {$key}=";
|
233 |
-
$where .= is_numeric($value) ? (strpos($value, ".") !== false ? '%f' : '%d') : '%s';
|
234 |
-
|
235 |
-
$values[] = $value;
|
236 |
-
}
|
237 |
}
|
|
|
238 |
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
240 |
}
|
241 |
-
|
242 |
-
function get_var($table, $args=array(), $field='id', $order_by=''){
|
243 |
-
global $wpdb;
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
|
|
|
248 |
|
249 |
-
|
250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
}
|
252 |
-
|
253 |
-
function get_col($table, $args=array(), $field='id', $order_by=''){
|
254 |
-
global $wpdb;
|
255 |
|
256 |
-
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
259 |
|
260 |
-
|
261 |
-
|
|
|
|
|
|
|
|
|
|
|
262 |
}
|
263 |
|
264 |
-
|
265 |
-
|
|
|
|
|
|
|
|
|
|
|
266 |
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
|
272 |
-
|
273 |
-
|
274 |
-
|
|
|
|
|
|
|
|
|
275 |
}
|
276 |
|
277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
global $wpdb;
|
279 |
|
280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
|
282 |
-
if ( !empty(
|
283 |
-
$order_by =
|
284 |
}
|
285 |
|
286 |
-
if ( !empty($limit
|
287 |
-
$limit =
|
288 |
}
|
289 |
|
290 |
-
$
|
291 |
-
$
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
}
|
294 |
-
|
295 |
-
function uninstall(){
|
296 |
if ( !current_user_can('administrator') ) {
|
297 |
-
|
298 |
wp_die($frm_settings->admin_permission);
|
299 |
}
|
300 |
-
|
301 |
global $wpdb, $wp_roles;
|
302 |
-
|
303 |
-
$wpdb->query('DROP TABLE IF EXISTS '. $this->fields);
|
304 |
-
$wpdb->query('DROP TABLE IF EXISTS '. $this->forms);
|
305 |
-
$wpdb->query('DROP TABLE IF EXISTS '. $this->entries);
|
306 |
-
$wpdb->query('DROP TABLE IF EXISTS '. $this->entry_metas);
|
307 |
-
|
308 |
delete_option('frm_options');
|
309 |
-
delete_option('frm_db_version');
|
310 |
-
|
311 |
//delete roles
|
312 |
$frm_roles = FrmAppHelper::frm_capabilities();
|
313 |
$roles = get_editable_roles();
|
314 |
-
foreach($frm_roles as $frm_role => $frm_role_description){
|
315 |
-
foreach ($roles as $role => $details){
|
316 |
$wp_roles->remove_cap( $role, $frm_role );
|
317 |
-
unset($role);
|
318 |
-
unset($details);
|
319 |
}
|
320 |
-
unset($frm_role);
|
321 |
-
unset($frm_role_description);
|
322 |
}
|
323 |
-
unset($roles);
|
324 |
-
|
325 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
do_action('frm_after_uninstall');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
327 |
}
|
328 |
}
|
1 |
<?php
|
|
|
2 |
|
3 |
+
class FrmDb {
|
4 |
+
var $fields;
|
5 |
+
var $forms;
|
6 |
+
var $entries;
|
7 |
+
var $entry_metas;
|
8 |
+
|
9 |
+
public function __construct() {
|
10 |
+
if ( ! defined('ABSPATH') ) {
|
11 |
+
die('You are not allowed to call this page directly.');
|
12 |
+
}
|
13 |
|
|
|
|
|
|
|
14 |
global $wpdb;
|
15 |
+
$this->fields = $wpdb->prefix . 'frm_fields';
|
16 |
+
$this->forms = $wpdb->prefix . 'frm_forms';
|
17 |
+
$this->entries = $wpdb->prefix . 'frm_items';
|
18 |
+
$this->entry_metas = $wpdb->prefix . 'frm_item_metas';
|
19 |
}
|
20 |
+
|
21 |
+
public function upgrade( $old_db_version = false ) {
|
22 |
global $wpdb;
|
23 |
//$frm_db_version is the version of the database we're moving to
|
24 |
$frm_db_version = FrmAppHelper::$db_version;
|
25 |
+
$old_db_version = (float) $old_db_version;
|
26 |
+
if ( ! $old_db_version ) {
|
27 |
$old_db_version = get_option('frm_db_version');
|
28 |
+
}
|
29 |
|
30 |
+
if ( $frm_db_version != $old_db_version ) {
|
31 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
32 |
+
|
33 |
+
$this->create_tables();
|
34 |
+
$this->migrate_data($frm_db_version, $old_db_version);
|
35 |
+
|
36 |
+
/**** ADD/UPDATE DEFAULT TEMPLATES ****/
|
37 |
+
FrmXMLController::add_default_templates();
|
38 |
+
|
39 |
+
/***** SAVE DB VERSION *****/
|
40 |
+
update_option('frm_db_version', $frm_db_version);
|
41 |
+
}
|
42 |
+
|
43 |
+
do_action('frm_after_install');
|
44 |
+
|
45 |
+
/**** update the styling settings ****/
|
46 |
+
$frm_style = new FrmStyle();
|
47 |
+
$frm_style->update( 'default' );
|
48 |
+
}
|
49 |
+
|
50 |
+
public function collation() {
|
51 |
+
global $wpdb;
|
52 |
+
if ( ! $wpdb->has_cap( 'collation' ) ) {
|
53 |
+
return '';
|
54 |
+
}
|
55 |
+
|
56 |
$charset_collate = '';
|
57 |
+
if ( ! empty($wpdb->charset) ) {
|
58 |
+
$charset_collate = ' DEFAULT CHARACTER SET '. $wpdb->charset;
|
|
|
|
|
|
|
59 |
}
|
60 |
|
61 |
+
if ( ! empty($wpdb->collate) ) {
|
62 |
+
$charset_collate .= ' COLLATE '. $wpdb->collate;
|
63 |
+
}
|
64 |
+
|
65 |
+
return $charset_collate;
|
66 |
+
}
|
67 |
+
|
68 |
+
private function create_tables() {
|
69 |
+
$charset_collate = $this->collation();
|
70 |
+
$sql = array();
|
71 |
+
|
72 |
/* Create/Upgrade Fields Table */
|
73 |
+
$sql[] = 'CREATE TABLE '. $this->fields .' (
|
74 |
id int(11) NOT NULL auto_increment,
|
75 |
+
field_key varchar(100) default NULL,
|
76 |
name text default NULL,
|
77 |
description text default NULL,
|
78 |
type text default NULL,
|
86 |
PRIMARY KEY (id),
|
87 |
KEY form_id (form_id),
|
88 |
UNIQUE KEY field_key (field_key)
|
89 |
+
)';
|
90 |
|
|
|
|
|
91 |
/* Create/Upgrade Forms Table */
|
92 |
+
$sql[] = 'CREATE TABLE '. $this->forms .' (
|
93 |
id int(11) NOT NULL auto_increment,
|
94 |
+
form_key varchar(100) default NULL,
|
95 |
name varchar(255) default NULL,
|
96 |
description text default NULL,
|
97 |
+
parent_form_id int(11) default 0,
|
98 |
logged_in tinyint(1) default NULL,
|
99 |
editable tinyint(1) default NULL,
|
100 |
is_template tinyint(1) default 0,
|
101 |
default_template tinyint(1) default 0,
|
102 |
status varchar(255) default NULL,
|
|
|
103 |
options longtext default NULL,
|
104 |
created_at datetime NOT NULL,
|
105 |
PRIMARY KEY (id),
|
106 |
UNIQUE KEY form_key (form_key)
|
107 |
+
)';
|
|
|
|
|
108 |
|
109 |
/* Create/Upgrade Items Table */
|
110 |
+
$sql[] = 'CREATE TABLE '. $this->entries .' (
|
111 |
id int(11) NOT NULL auto_increment,
|
112 |
+
item_key varchar(100) default NULL,
|
113 |
name varchar(255) default NULL,
|
114 |
description text default NULL,
|
115 |
ip text default NULL,
|
116 |
form_id int(11) default NULL,
|
117 |
post_id int(11) default NULL,
|
118 |
user_id int(11) default NULL,
|
119 |
+
parent_item_id int(11) default 0,
|
120 |
is_draft tinyint(1) default 0,
|
121 |
updated_by int(11) default NULL,
|
122 |
created_at datetime NOT NULL,
|
127 |
KEY user_id (user_id),
|
128 |
KEY parent_item_id (parent_item_id),
|
129 |
UNIQUE KEY item_key (item_key)
|
130 |
+
)';
|
|
|
|
|
131 |
|
132 |
/* Create/Upgrade Meta Table */
|
133 |
+
$sql[] = 'CREATE TABLE '. $this->entry_metas .' (
|
134 |
id int(11) NOT NULL auto_increment,
|
135 |
meta_value longtext default NULL,
|
136 |
field_id int(11) NOT NULL,
|
139 |
PRIMARY KEY (id),
|
140 |
KEY field_id (field_id),
|
141 |
KEY item_id (item_id)
|
142 |
+
)';
|
143 |
+
|
144 |
+
foreach ( $sql as $q ) {
|
145 |
+
dbDelta($q . $charset_collate .';');
|
146 |
+
unset($q);
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* @param integer $frm_db_version
|
152 |
+
*/
|
153 |
+
private function migrate_data($frm_db_version, $old_db_version) {
|
154 |
+
$migrations = array(4, 6, 11, 16, 17);
|
155 |
+
foreach ( $migrations as $migration ) {
|
156 |
+
if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
|
157 |
+
$function_name = 'migrate_to_'. $migration;
|
158 |
+
$this->$function_name();
|
159 |
}
|
160 |
}
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Change array into format $wpdb->prepare can use
|
165 |
+
*/
|
166 |
+
public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
|
167 |
+
if ( empty($args) ) {
|
168 |
+
// add an arg to prevent prepare from failing
|
169 |
+
$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
|
170 |
+
return;
|
171 |
}
|
172 |
+
|
173 |
+
$where = '';
|
174 |
+
$values = array();
|
175 |
+
|
176 |
+
if ( is_array( $args ) ) {
|
177 |
+
$base_where = $starts_with;
|
178 |
+
self::parse_where_from_array( $args, $base_where, $where, $values );
|
179 |
+
}
|
180 |
+
|
181 |
+
$args = compact( 'where', 'values' );
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* @param string $base_where
|
186 |
+
* @param string $where
|
187 |
+
*/
|
188 |
+
public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
|
189 |
+
$condition = ' AND';
|
190 |
+
if ( isset( $args['or'] ) ) {
|
191 |
+
$condition = ' OR';
|
192 |
+
unset( $args['or'] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
}
|
194 |
+
|
195 |
+
foreach ( $args as $key => $value ) {
|
196 |
+
$where .= empty( $where ) ? $base_where : $condition;
|
197 |
+
$array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
|
198 |
+
if ( is_numeric( $key ) || $array_inc_null ) {
|
199 |
+
$where .= ' ( ';
|
200 |
+
$nested_where = '';
|
201 |
+
if ( $array_inc_null ) {
|
202 |
+
foreach ( $value as $val ) {
|
203 |
+
self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
|
204 |
+
}
|
205 |
+
} else {
|
206 |
+
self::parse_where_from_array( $value, '', $nested_where, $values );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
}
|
208 |
+
$where .= $nested_where;
|
209 |
+
$where .= ' ) ';
|
210 |
+
} else {
|
211 |
+
self::interpret_array_to_sql( $key, $value, $where, $values );
|
212 |
}
|
|
|
213 |
}
|
214 |
+
}
|
|
|
215 |
|
216 |
+
/**
|
217 |
+
* @param string $key
|
218 |
+
* @param string $where
|
219 |
+
*/
|
220 |
+
private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
|
221 |
+
if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
|
222 |
+
$k = explode(' ', $key);
|
223 |
+
$where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
|
224 |
+
$values[] = '%Y-%m-%d %H:%i:%s';
|
225 |
+
} else {
|
226 |
+
$where .= ' '. $key;
|
227 |
}
|
228 |
|
229 |
+
$lowercase_key = explode( ' ', strtolower( $key ) );
|
230 |
+
$lowercase_key = end( $lowercase_key );
|
231 |
+
if ( is_array( $value ) ) {
|
232 |
+
// translate array of values to "in"
|
233 |
+
if ( strpos( $lowercase_key, 'like' ) !== false ) {
|
234 |
+
$where = rtrim( $where, $key );
|
235 |
+
$where .= '(';
|
236 |
+
$start = true;
|
237 |
+
foreach ( $value as $v ) {
|
238 |
+
if ( ! $start ) {
|
239 |
+
$where .= ' OR ';
|
240 |
+
}
|
241 |
+
$start = false;
|
242 |
+
$where .= $key . ' %s';
|
243 |
+
$values[] = '%' . FrmAppHelper::esc_like( $v ) . '%';
|
244 |
+
}
|
245 |
+
$where .= ')';
|
246 |
+
} else {
|
247 |
+
$where .= ' in ('. FrmAppHelper::prepare_array_values( $value, '%s' ) .')';
|
248 |
+
$values = array_merge( $values, $value );
|
249 |
+
}
|
250 |
+
} else if ( strpos( $lowercase_key, 'like' ) !== false ) {
|
251 |
+
/**
|
252 |
+
* Allow string to start or end with the value
|
253 |
+
* If the key is like% then skip the first % for starts with
|
254 |
+
* If the key is %like then skip the last % for ends with
|
255 |
+
*/
|
256 |
+
$start = $end = '%';
|
257 |
+
if ( $lowercase_key == 'like%' ) {
|
258 |
+
$start = '';
|
259 |
+
$where = rtrim( $where, '%' );
|
260 |
+
} else if ( $lowercase_key == '%like' ) {
|
261 |
+
$end = '';
|
262 |
+
$where = rtrim( rtrim( $where, '%like' ), '%LIKE' );
|
263 |
+
$where .= 'like';
|
264 |
+
}
|
265 |
|
266 |
+
$where .= ' %s';
|
267 |
+
$values[] = $start . FrmAppHelper::esc_like( $value ) . $end;
|
|
|
|
|
|
|
|
|
268 |
|
269 |
+
} else if ( $value === null ) {
|
270 |
+
$where .= ' IS NULL';
|
271 |
+
} else {
|
272 |
+
// allow a - to prevent = from being added
|
273 |
+
if ( substr( $key, -1 ) == '-' ) {
|
274 |
+
$where = rtrim( $where, '-' );
|
275 |
+
} else {
|
276 |
+
$where .= '=';
|
277 |
+
}
|
278 |
|
279 |
+
$where .= is_numeric( $value ) ? ( strpos( $value, '.' ) !== false ? '%f' : '%d' ) : '%s';
|
280 |
+
$values[] = $value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
}
|
282 |
+
}
|
283 |
|
284 |
+
/**
|
285 |
+
* @param string $table
|
286 |
+
*/
|
287 |
+
public static function get_count( $table, $where = array(), $args = array() ) {
|
288 |
+
$count = self::get_var( $table, $where, 'COUNT(*)', $args );
|
289 |
+
return $count;
|
290 |
}
|
|
|
|
|
|
|
291 |
|
292 |
+
public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
|
293 |
+
$group = '';
|
294 |
+
self::get_group_and_table_name( $table, $group );
|
295 |
+
self::convert_options_to_array( $args, '', $limit );
|
296 |
|
297 |
+
$query = 'SELECT ' . $field . ' FROM ' . $table;
|
298 |
+
if ( is_array( $where ) || empty( $where ) ) {
|
299 |
+
// only separate into array values and query string if is array
|
300 |
+
self::get_where_clause_and_values( $where );
|
301 |
+
global $wpdb;
|
302 |
+
$query = $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] );
|
303 |
+
} else {
|
304 |
+
/**
|
305 |
+
* Allow the $where to be prepared before we recieve it here.
|
306 |
+
* This is a fallback for reverse compatability, but is not recommended
|
307 |
+
*/
|
308 |
+
_deprecated_argument( 'where', '2.0', __( 'Use the query in an array format so it can be properly prepared.', 'formidable' ) );
|
309 |
+
$query .= $where . ' ' . implode( ' ', $args );
|
310 |
+
}
|
311 |
+
|
312 |
+
$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode('_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field .'_'. $type, ' WHERE' ) );
|
313 |
+
$results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_'. $type );
|
314 |
+
return $results;
|
315 |
}
|
|
|
|
|
|
|
316 |
|
317 |
+
/**
|
318 |
+
* @param string $table
|
319 |
+
* @param array $where
|
320 |
+
*/
|
321 |
+
public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
|
322 |
+
return self::get_var( $table, $where, $field, $args, $limit, 'col' );
|
323 |
+
}
|
324 |
|
325 |
+
/**
|
326 |
+
* @since 2.0
|
327 |
+
* @param string $table
|
328 |
+
*/
|
329 |
+
public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
|
330 |
+
$args['limit'] = 1;
|
331 |
+
return self::get_var( $table, $where, $fields, $args, '', 'row' );
|
332 |
}
|
333 |
|
334 |
+
/**
|
335 |
+
* @param string $table
|
336 |
+
*/
|
337 |
+
public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
|
338 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
|
339 |
+
return self::get_var( $table, $args, $fields, array( 'order_by' => $order_by, 'limit' => 1), '', 'row' );
|
340 |
+
}
|
341 |
|
342 |
+
public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
|
343 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' );
|
344 |
+
return self::get_results( $table, $args, $fields, compact('order_by', 'limit') );
|
345 |
+
}
|
346 |
|
347 |
+
/**
|
348 |
+
* Prepare a key/value array before DB call
|
349 |
+
* @since 2.0
|
350 |
+
* @param string $table
|
351 |
+
*/
|
352 |
+
public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
|
353 |
+
return self::get_var( $table, $where, $fields, $args, '', 'results' );
|
354 |
}
|
355 |
|
356 |
+
/**
|
357 |
+
* Check for like, not like, in, not in, =, !=, >, <, <=, >=
|
358 |
+
* Return a value to append to the where array key
|
359 |
+
*
|
360 |
+
* @return string
|
361 |
+
*/
|
362 |
+
public static function append_where_is( $where_is ) {
|
363 |
+
$switch_to = array(
|
364 |
+
'=' => '',
|
365 |
+
'!=' => '!',
|
366 |
+
'<=' => '<',
|
367 |
+
'>=' => '>',
|
368 |
+
'like' => 'like',
|
369 |
+
'not like' => 'not like',
|
370 |
+
'in' => '',
|
371 |
+
'not in' => 'not',
|
372 |
+
'like%' => 'like%',
|
373 |
+
'%like' => '%like',
|
374 |
+
);
|
375 |
+
|
376 |
+
$where_is = strtolower( $where_is );
|
377 |
+
if ( isset( $switch_to[ $where_is ] ) ) {
|
378 |
+
return ' ' . $switch_to[ $where_is ];
|
379 |
+
}
|
380 |
+
|
381 |
+
// > and < need a little more work since we don't want them switched to >= and <=
|
382 |
+
if ( $where_is == '>' || $where_is == '<' ) {
|
383 |
+
return ' ' . $where_is . '-'; // the - indicates that the = should not be added later
|
384 |
+
}
|
385 |
+
|
386 |
+
// fallback to = if the query is none of these
|
387 |
+
return '';
|
388 |
+
}
|
389 |
+
|
390 |
+
/**
|
391 |
+
* Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
|
392 |
+
* Also add the wpdb->prefix to the table if it's missing
|
393 |
+
*
|
394 |
+
* @param string $table
|
395 |
+
* @param string $group
|
396 |
+
*/
|
397 |
+
private static function get_group_and_table_name( &$table, &$group ) {
|
398 |
global $wpdb;
|
399 |
|
400 |
+
$table_parts = explode(' ', $table);
|
401 |
+
$group = reset($table_parts);
|
402 |
+
$group = str_replace( $wpdb->prefix, '', $group );
|
403 |
+
|
404 |
+
if ( $group == $table ) {
|
405 |
+
$table = $wpdb->prefix . $table;
|
406 |
+
}
|
407 |
+
|
408 |
+
// switch to singular group name
|
409 |
+
$group = rtrim( $group, 's' );
|
410 |
+
}
|
411 |
+
|
412 |
+
private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
|
413 |
+
if ( ! is_array($args) ) {
|
414 |
+
$args = array( 'order_by' => $args);
|
415 |
+
}
|
416 |
|
417 |
+
if ( ! empty( $order_by ) ) {
|
418 |
+
$args['order_by'] = $order_by;
|
419 |
}
|
420 |
|
421 |
+
if ( ! empty( $limit ) ) {
|
422 |
+
$args['limit'] = $limit;
|
423 |
}
|
424 |
|
425 |
+
$temp_args = $args;
|
426 |
+
foreach ( $temp_args as $k => $v ) {
|
427 |
+
if ( $v == '' ) {
|
428 |
+
unset($args[$k]);
|
429 |
+
continue;
|
430 |
+
}
|
431 |
+
|
432 |
+
if ( $k == 'limit' ) {
|
433 |
+
$args[$k] = FrmAppHelper::esc_limit( $v );
|
434 |
+
}
|
435 |
+
$db_name = strtoupper( str_replace( '_', ' ', $k ) );
|
436 |
+
if ( strpos( $v, $db_name ) === false ) {
|
437 |
+
$args[$k] = $db_name .' '. $v;
|
438 |
+
}
|
439 |
+
}
|
440 |
}
|
441 |
+
|
442 |
+
public function uninstall() {
|
443 |
if ( !current_user_can('administrator') ) {
|
444 |
+
$frm_settings = FrmAppHelper::get_settings();
|
445 |
wp_die($frm_settings->admin_permission);
|
446 |
}
|
447 |
+
|
448 |
global $wpdb, $wp_roles;
|
449 |
+
|
450 |
+
$wpdb->query( 'DROP TABLE IF EXISTS '. $this->fields );
|
451 |
+
$wpdb->query( 'DROP TABLE IF EXISTS '. $this->forms );
|
452 |
+
$wpdb->query( 'DROP TABLE IF EXISTS '. $this->entries );
|
453 |
+
$wpdb->query( 'DROP TABLE IF EXISTS '. $this->entry_metas );
|
454 |
+
|
455 |
delete_option('frm_options');
|
456 |
+
delete_option('frm_db_version');
|
457 |
+
|
458 |
//delete roles
|
459 |
$frm_roles = FrmAppHelper::frm_capabilities();
|
460 |
$roles = get_editable_roles();
|
461 |
+
foreach ( $frm_roles as $frm_role => $frm_role_description ) {
|
462 |
+
foreach ( $roles as $role => $details ) {
|
463 |
$wp_roles->remove_cap( $role, $frm_role );
|
464 |
+
unset($role, $details);
|
|
|
465 |
}
|
466 |
+
unset($frm_role, $frm_role_description);
|
|
|
467 |
}
|
468 |
+
unset($roles, $frm_roles);
|
469 |
+
|
470 |
+
// delete actions, views, and styles
|
471 |
+
$post_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts .' WHERE post_type in (%s, %s, %s)', FrmFormActionsController::$action_post_type, FrmStylesController::$post_type, 'frm_display' ) );
|
472 |
+
foreach( $post_ids as $post_id ) {
|
473 |
+
// Delete's each post.
|
474 |
+
wp_delete_post( $post_id, true );
|
475 |
+
}
|
476 |
+
unset( $post_ids );
|
477 |
+
|
478 |
do_action('frm_after_uninstall');
|
479 |
+
return true;
|
480 |
+
}
|
481 |
+
|
482 |
+
/**
|
483 |
+
* Change field size from character to pixel -- Multiply by 9
|
484 |
+
*/
|
485 |
+
private function migrate_to_17() {
|
486 |
+
global $wpdb;
|
487 |
+
$pixel_conversion = 9;
|
488 |
+
|
489 |
+
// Get query arguments
|
490 |
+
$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
|
491 |
+
$query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' );
|
492 |
+
|
493 |
+
// Get results
|
494 |
+
$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
|
495 |
+
|
496 |
+
$updated = 0;
|
497 |
+
foreach ( $fields as $f ) {
|
498 |
+
$f->field_options = maybe_unserialize($f->field_options);
|
499 |
+
if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
|
500 |
+
continue;
|
501 |
+
}
|
502 |
+
|
503 |
+
$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
|
504 |
+
$f->field_options['size'] .= 'px';
|
505 |
+
$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
|
506 |
+
if ( $u ) {
|
507 |
+
$updated++;
|
508 |
+
}
|
509 |
+
unset($f);
|
510 |
+
}
|
511 |
+
|
512 |
+
// Change the characters in widgets to pixels
|
513 |
+
$widgets = get_option('widget_frm_show_form');
|
514 |
+
if ( empty($widgets) ) {
|
515 |
+
return;
|
516 |
+
}
|
517 |
+
|
518 |
+
$widgets = maybe_unserialize($widgets);
|
519 |
+
foreach ( $widgets as $k => $widget ) {
|
520 |
+
if ( ! is_array($widget) || ! isset($widget['size']) ) {
|
521 |
+
continue;
|
522 |
+
}
|
523 |
+
$size = round( $pixel_conversion * (int) $widget['size'] );
|
524 |
+
$size .= 'px';
|
525 |
+
$widgets[$k]['size'] = $size;
|
526 |
+
}
|
527 |
+
update_option('widget_frm_show_form', $widgets);
|
528 |
+
}
|
529 |
+
|
530 |
+
/**
|
531 |
+
* Migrate post and email notification settings into actions
|
532 |
+
*/
|
533 |
+
private function migrate_to_16() {
|
534 |
+
global $wpdb;
|
535 |
+
|
536 |
+
$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
|
537 |
+
|
538 |
+
/**
|
539 |
+
* Old email settings format:
|
540 |
+
* email_to: Email or field id
|
541 |
+
* also_email_to: array of fields ids
|
542 |
+
* reply_to: Email, field id, 'custom'
|
543 |
+
* cust_reply_to: string
|
544 |
+
* reply_to_name: field id, 'custom'
|
545 |
+
* cust_reply_to_name: string
|
546 |
+
* plain_text: 0|1
|
547 |
+
* email_message: string or ''
|
548 |
+
* email_subject: string or ''
|
549 |
+
* inc_user_info: 0|1
|
550 |
+
* update_email: 0, 1, 2
|
551 |
+
*
|
552 |
+
* Old autoresponder settings format:
|
553 |
+
* auto_responder: 0|1
|
554 |
+
* ar_email_message: string or ''
|
555 |
+
* ar_email_to: field id
|
556 |
+
* ar_plain_text: 0|1
|
557 |
+
* ar_reply_to_name: string
|
558 |
+
* ar_reply_to: string
|
559 |
+
* ar_email_subject: string
|
560 |
+
* ar_update_email: 0, 1, 2
|
561 |
+
*
|
562 |
+
* New email settings:
|
563 |
+
* post_content: json settings
|
564 |
+
* post_title: form id
|
565 |
+
* post_excerpt: message
|
566 |
+
*
|
567 |
+
*/
|
568 |
+
|
569 |
+
foreach ( $forms as $form ) {
|
570 |
+
if ( $form->is_template && $form->default_template ) {
|
571 |
+
// don't migrate the default templates since the email will be added anyway
|
572 |
+
continue;
|
573 |
+
}
|
574 |
+
|
575 |
+
// Format form options
|
576 |
+
$form_options = maybe_unserialize($form->options);
|
577 |
+
|
578 |
+
// Migrate settings to actions
|
579 |
+
FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
|
580 |
+
}
|
581 |
+
}
|
582 |
+
|
583 |
+
private function migrate_to_11() {
|
584 |
+
global $wpdb;
|
585 |
+
|
586 |
+
$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
|
587 |
+
|
588 |
+
$sending = __( 'Sending', 'formidable' );
|
589 |
+
$img = FrmAppHelper::plugin_url() .'/images/ajax_loader.gif';
|
590 |
+
$old_default_html = <<<DEFAULT_HTML
|
591 |
+
<div class="frm_submit">
|
592 |
+
[if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
|
593 |
+
<input type="submit" value="[button_label]" [button_action] />
|
594 |
+
<img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
|
595 |
+
</div>
|
596 |
+
DEFAULT_HTML;
|
597 |
+
unset($sending, $img);
|
598 |
+
|
599 |
+
$new_default_html = FrmFormsHelper::get_default_html('submit');
|
600 |
+
$draft_link = FrmFormsHelper::get_draft_link();
|
601 |
+
foreach ( $forms as $form ) {
|
602 |
+
$form->options = maybe_unserialize($form->options);
|
603 |
+
if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
|
604 |
+
continue;
|
605 |
+
}
|
606 |
+
|
607 |
+
if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
|
608 |
+
$form->options['submit_html'] = $new_default_html;
|
609 |
+
$wpdb->update($this->forms, array( 'options' => serialize($form->options)), array( 'id' => $form->id ));
|
610 |
+
} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
|
611 |
+
$form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
|
612 |
+
$wpdb->update($this->forms, array( 'options' => serialize($form->options)), array( 'id' => $form->id ));
|
613 |
+
}
|
614 |
+
unset($form);
|
615 |
+
}
|
616 |
+
unset($forms);
|
617 |
+
}
|
618 |
+
|
619 |
+
private function migrate_to_6() {
|
620 |
+
global $wpdb;
|
621 |
+
|
622 |
+
$no_save = array_merge( FrmFieldsHelper::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
|
623 |
+
$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save), 'id, field_options' );
|
624 |
+
|
625 |
+
$default_html = <<<DEFAULT_HTML
|
626 |
+
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
|
627 |
+
<label class="frm_pos_[label_position]">[field_name]
|
628 |
+
<span class="frm_required">[required_label]</span>
|
629 |
+
</label>
|
630 |
+
[input]
|
631 |
+
[if description]<div class="frm_description">[description]</div>[/if description]
|
632 |
+
</div>
|
633 |
+
DEFAULT_HTML;
|
634 |
+
|
635 |
+
$old_default_html = <<<DEFAULT_HTML
|
636 |
+
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
|
637 |
+
<label class="frm_pos_[label_position]">[field_name]
|
638 |
+
<span class="frm_required">[required_label]</span>
|
639 |
+
</label>
|
640 |
+
[input]
|
641 |
+
[if description]<p class="frm_description">[description]</p>[/if description]
|
642 |
+
</div>
|
643 |
+
DEFAULT_HTML;
|
644 |
+
|
645 |
+
$new_default_html = FrmFieldsHelper::get_default_html('text');
|
646 |
+
foreach ( $fields as $field ) {
|
647 |
+
$field->field_options = maybe_unserialize($field->field_options);
|
648 |
+
if ( ! isset( $field->field_options['custom_html'] ) || empty( $field->field_options['custom_html'] ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
|
649 |
+
$field->field_options['custom_html'] = $new_default_html;
|
650 |
+
$wpdb->update($this->fields, array( 'field_options' => maybe_serialize($field->field_options)), array( 'id' => $field->id ));
|
651 |
+
}
|
652 |
+
unset($field);
|
653 |
+
}
|
654 |
+
unset($default_html, $old_default_html, $fields);
|
655 |
+
}
|
656 |
+
|
657 |
+
private function migrate_to_4() {
|
658 |
+
global $wpdb;
|
659 |
+
$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
|
660 |
+
foreach ( $user_ids as $user_id ) {
|
661 |
+
$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value), array( 'id' => $user_id->item_id) );
|
662 |
+
}
|
663 |
}
|
664 |
}
|
classes/models/FrmEntry.php
CHANGED
@@ -1,152 +1,194 @@
|
|
1 |
<?php
|
2 |
-
if(!defined('ABSPATH'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
return;
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
function create( $values ){
|
10 |
-
global $wpdb, $frm_entry_meta;
|
11 |
-
|
12 |
$new_values = array(
|
13 |
'item_key' => FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key'),
|
14 |
'name' => isset($values['name']) ? $values['name'] : $values['item_key'],
|
15 |
-
'ip' =>
|
16 |
'is_draft' => ( ( isset($values['frm_saving_draft']) && $values['frm_saving_draft'] == 1 ) || ( isset($values['is_draft']) && $values['is_draft'] == 1) ) ? 1 : 0,
|
17 |
'form_id' => isset($values['form_id']) ? (int) $values['form_id']: null,
|
18 |
'post_id' => isset($values['post_id']) ? (int) $values['post_id']: null,
|
|
|
19 |
'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
|
20 |
'updated_at' => isset($values['updated_at']) ? $values['updated_at'] : ( isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1) ),
|
21 |
);
|
22 |
-
|
23 |
-
if(is_array($new_values['name']))
|
24 |
$new_values['name'] = reset($new_values['name']);
|
25 |
-
|
26 |
-
|
|
|
27 |
$new_values['description'] = maybe_serialize($values['description']);
|
28 |
-
}else{
|
29 |
-
$referrerinfo = FrmAppHelper::
|
30 |
-
|
31 |
-
$new_values['description'] = serialize(array(
|
32 |
-
|
|
|
|
|
33 |
}
|
34 |
-
|
35 |
//if(isset($values['id']) and is_numeric($values['id']))
|
36 |
// $new_values['id'] = $values['id'];
|
37 |
-
|
38 |
-
if(isset($values['frm_user_id'])
|
39 |
$new_values['user_id'] = $values['frm_user_id'];
|
40 |
-
}else{
|
41 |
$user_ID = get_current_user_id();
|
42 |
$new_values['user_id'] = $user_ID ? $user_ID : 0;
|
43 |
}
|
44 |
-
|
45 |
$new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id'];
|
46 |
-
|
47 |
-
//
|
48 |
-
if(
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
$
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
}
|
85 |
-
|
86 |
-
|
|
|
|
|
87 |
return false;
|
88 |
}
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
if ( isset($values['item_meta']) ) {
|
102 |
-
$frm_entry_meta->update_entry_metas($entry_id, $values['item_meta']);
|
103 |
}
|
104 |
-
|
105 |
-
do_action('frm_after_create_entry', $entry_id, $new_values['form_id']);
|
106 |
-
do_action('frm_after_create_entry_'. $new_values['form_id'], $entry_id);
|
107 |
-
return $entry_id;
|
108 |
-
} else {
|
109 |
-
return false;
|
110 |
}
|
|
|
|
|
111 |
}
|
112 |
-
|
113 |
-
function duplicate( $id ){
|
114 |
-
global $wpdb, $frm_entry, $frm_entry_meta;
|
115 |
|
116 |
-
|
|
|
|
|
|
|
117 |
|
118 |
$new_values = array();
|
119 |
$new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
|
120 |
$new_values['name'] = $values->name;
|
121 |
$new_values['is_draft'] = $values->is_draft;
|
122 |
-
$new_values['user_id'] = $new_values['updated_by'] = (int)$values->user_id;
|
123 |
-
$new_values['form_id'] = $values->form_id ? (int)$values->form_id: null;
|
124 |
$new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
|
125 |
|
126 |
$query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
|
127 |
-
if($query_results){
|
128 |
-
$entry_id = $wpdb->insert_id;
|
129 |
-
|
130 |
-
global $frm_vars;
|
131 |
-
if(!isset($frm_vars['saved_entries']))
|
132 |
-
$frm_vars['saved_entries'] = array();
|
133 |
-
$frm_vars['saved_entries'][] = (int)$entry_id;
|
134 |
-
|
135 |
-
$frm_entry_meta->duplicate_entry_metas($id, $entry_id);
|
136 |
-
|
137 |
-
do_action('frm_after_duplicate_entry', $entry_id, $new_values['form_id']);
|
138 |
-
return $entry_id;
|
139 |
-
}else
|
140 |
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
}
|
142 |
|
143 |
-
function update( $id, $values ){
|
144 |
-
global $wpdb, $
|
145 |
-
if(isset($frm_vars['saved_entries']) && is_array($frm_vars['saved_entries']) && in_array((int)$id, (array)$frm_vars['saved_entries']))
|
146 |
return;
|
|
|
|
|
|
|
147 |
|
148 |
$user_ID = get_current_user_id();
|
149 |
-
|
150 |
$new_values = array(
|
151 |
'name' => isset($values['name']) ? $values['name'] : '',
|
152 |
'form_id' => isset($values['form_id']) ? (int) $values['form_id'] : null,
|
@@ -154,7 +196,7 @@ class FrmEntry{
|
|
154 |
'updated_at' => current_time('mysql', 1),
|
155 |
'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : $user_ID,
|
156 |
);
|
157 |
-
|
158 |
if ( isset($values['post_id']) ) {
|
159 |
$new_values['post_id'] = (int) $values['post_id'];
|
160 |
}
|
@@ -162,289 +204,465 @@ class FrmEntry{
|
|
162 |
if ( isset($values['item_key']) ) {
|
163 |
$new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key', $id);
|
164 |
}
|
165 |
-
|
166 |
-
if(isset($values['
|
|
|
|
|
|
|
|
|
167 |
$new_values['user_id'] = $values['frm_user_id'];
|
|
|
168 |
|
169 |
$new_values = apply_filters('frm_update_entry', $new_values, $id);
|
170 |
$query_results = $wpdb->update( $wpdb->prefix .'frm_items', $new_values, compact('id') );
|
171 |
-
|
|
|
|
|
172 |
wp_cache_delete( $id, 'frm_entry');
|
173 |
-
|
174 |
-
|
|
|
175 |
$frm_vars['saved_entries'] = array();
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
181 |
do_action('frm_after_update_entry', $id, $new_values['form_id']);
|
182 |
do_action('frm_after_update_entry_'. $new_values['form_id'], $id);
|
183 |
return $query_results;
|
184 |
}
|
185 |
|
186 |
-
function &destroy( $id ){
|
187 |
global $wpdb;
|
188 |
-
$id = (int)$id;
|
189 |
-
|
190 |
-
|
191 |
-
if (
|
192 |
$result = false;
|
193 |
return $result;
|
194 |
}
|
195 |
-
|
196 |
do_action('frm_before_destroy_entry', $id, $entry);
|
197 |
-
|
|
|
198 |
wp_cache_delete( $id, 'frm_entry');
|
199 |
-
$wpdb->query('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id
|
200 |
-
$result = $wpdb->query('DELETE FROM ' . $wpdb->prefix .'frm_items WHERE id
|
201 |
return $result;
|
202 |
}
|
203 |
-
|
204 |
-
function &update_form( $id, $value, $form_id ){
|
205 |
global $wpdb;
|
206 |
-
$form_id = isset($value) ? $form_id :
|
207 |
-
$result = $wpdb->update( $wpdb->prefix .'frm_items', array('form_id' => $form_id), array( 'id' => $id ) );
|
208 |
-
|
209 |
wp_cache_delete( $id, 'frm_entry');
|
|
|
210 |
return $result;
|
211 |
}
|
212 |
-
|
213 |
-
function getOne( $id, $meta=false){
|
214 |
global $wpdb;
|
215 |
-
|
216 |
-
$entry = wp_cache_get( $id, 'frm_entry' );
|
217 |
-
if($entry)
|
218 |
-
return stripslashes_deep($entry);
|
219 |
|
220 |
-
$query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
|
221 |
LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
|
222 |
-
|
223 |
-
$query .= $wpdb->prepare( is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s', $id);
|
224 |
-
|
225 |
-
$entry = $wpdb->get_row($query);
|
226 |
-
|
227 |
-
if($meta and $entry){
|
228 |
-
$metas = $wpdb->get_results($wpdb->prepare("SELECT field_id, meta_value, field_key FROM {$wpdb->prefix}frm_item_metas m LEFT JOIN {$wpdb->prefix}frm_fields f ON m.field_id=f.id WHERE item_id=%d and field_id != %d", $entry->id, 0));
|
229 |
-
|
230 |
-
$entry_metas = array();
|
231 |
-
|
232 |
-
foreach($metas as $meta_val){
|
233 |
-
$entry_metas[$meta_val->field_id] = $entry_metas[$meta_val->field_key] = maybe_unserialize($meta_val->meta_value);
|
234 |
-
unset($meta_val);
|
235 |
-
}
|
236 |
-
unset($metas);
|
237 |
|
238 |
-
|
|
|
|
|
239 |
|
240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
}
|
242 |
|
|
|
|
|
|
|
243 |
return stripslashes_deep($entry);
|
244 |
}
|
245 |
-
|
246 |
-
function
|
|
|
|
|
|
|
|
|
247 |
global $wpdb;
|
248 |
-
|
249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
$exists = true;
|
251 |
return $exists;
|
252 |
}
|
253 |
-
|
254 |
-
$where = (is_numeric($id)) ? 'id=%d' : 'item_key=%s';
|
255 |
|
256 |
-
|
257 |
-
|
|
|
|
|
|
|
|
|
|
|
258 |
$exists = ($id && $id > 0) ? true : false;
|
259 |
return $exists;
|
260 |
}
|
261 |
|
262 |
-
function getAll($where
|
263 |
global $wpdb;
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
|
279 |
-
// sort by a requested field
|
280 |
-
$query = str_replace( " FROM {$wpdb->prefix}frm_items ", ", (SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE field_id = {$order_matches[1]} AND item_id = it.id) as meta_{$order_matches[1]} FROM {$wpdb->prefix}frm_items ", $query );
|
281 |
-
}
|
282 |
-
|
283 |
-
$entries = $wpdb->get_results($query, OBJECT_K);
|
284 |
-
unset($query);
|
285 |
-
|
286 |
-
if($meta and $entries){
|
287 |
-
if($limit == '' and !is_array($where) and preg_match('/^it\.form_id=\d+$/', $where)){
|
288 |
-
$meta_where = $wpdb->prepare('fi.form_id=%d', substr($where, 11));
|
289 |
-
}else if($limit == '' and is_array($where) and count($where) == 1 and isset($where['it.form_id'])){
|
290 |
-
$meta_where = $wpdb->prepare('fi.form_id=%d', $where['it.form_id']);
|
291 |
-
}else{
|
292 |
-
$meta_where = "item_id in (". implode(',', array_filter(array_keys($entries), 'is_numeric')) .")";
|
293 |
}
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
unset($query);
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
}
|
|
|
|
|
|
|
|
|
317 |
}
|
318 |
-
|
|
|
|
|
|
|
|
|
|
|
319 |
return stripslashes_deep($entries);
|
320 |
}
|
321 |
|
322 |
// Pagination Methods
|
323 |
-
function getRecordCount($where=''){
|
324 |
global $wpdb;
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
$
|
329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
}
|
331 |
-
|
|
|
332 |
}
|
333 |
|
334 |
-
function getPageCount($p_size, $where=''){
|
335 |
-
if(is_numeric($where))
|
336 |
-
return ceil((int)$where / (int)$p_size);
|
337 |
-
else
|
338 |
-
return ceil((int)
|
|
|
339 |
}
|
340 |
|
341 |
-
function validate( $values, $exclude=false ){
|
342 |
-
global $wpdb
|
343 |
-
|
|
|
344 |
$errors = array();
|
345 |
-
|
346 |
if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
|
347 |
-
$errors['form'] = __('There was a problem with your submission. Please try again.', 'formidable');
|
348 |
return $errors;
|
349 |
}
|
350 |
-
|
351 |
-
if ( is_admin() && is_user_logged_in() && ( ! isset($values['frm_submit_entry_'. $values['form_id']]) || ! wp_verify_nonce($values['frm_submit_entry_'. $values['form_id']], 'frm_submit_entry_nonce') ) ) {
|
352 |
-
$errors['form'] = __('You do not have permission to do that', 'formidable');
|
353 |
}
|
354 |
-
|
355 |
-
if( !isset($values['item_key'])
|
356 |
$_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
|
357 |
}
|
358 |
-
|
359 |
-
$where = apply_filters('frm_posted_field_ids', 'fi.form_id='. (int)$values['form_id']);
|
360 |
-
if($exclude)
|
361 |
-
$where .= " and fi.type not in ('". implode("','", array_filter($exclude, 'esc_sql')) ."')";
|
362 |
-
|
363 |
-
$posted_fields = $frm_field->getAll($where, 'field_order');
|
364 |
-
|
365 |
-
foreach($posted_fields as $posted_field){
|
366 |
-
$posted_field->field_options = maybe_unserialize($posted_field->field_options);
|
367 |
-
$value = '';
|
368 |
-
if (isset($values['item_meta'][$posted_field->id]))
|
369 |
-
$value = $values['item_meta'][$posted_field->id];
|
370 |
-
|
371 |
-
if (isset($posted_field->field_options['default_blank']) and $posted_field->field_options['default_blank'] and $value == $posted_field->default_value)
|
372 |
-
$value = '';
|
373 |
-
|
374 |
-
if(is_array($value) and count($value) === 1)
|
375 |
-
$value = reset($value);
|
376 |
-
|
377 |
-
if($posted_field->type == 'rte' and !is_array($value) and (trim($value) == '<br>'))
|
378 |
-
$value = '';
|
379 |
-
|
380 |
-
if ($posted_field->required == '1' and !is_array($value) and trim($value) == ''){
|
381 |
-
$errors['field'. $posted_field->id] = (!isset($posted_field->field_options['blank']) or $posted_field->field_options['blank'] == '' or $posted_field->field_options['blank'] == 'Untitled cannot be blank') ? $frm_settings->blank_msg : $posted_field->field_options['blank'];
|
382 |
-
}else if ($posted_field->type == 'text' and !isset($_POST['name'])){
|
383 |
-
$_POST['name'] = $value;
|
384 |
-
}
|
385 |
-
|
386 |
-
$_POST['item_meta'][$posted_field->id] = $value;
|
387 |
-
|
388 |
-
if ($posted_field->type == 'captcha' and isset($_POST['recaptcha_challenge_field'])){
|
389 |
-
global $frm_settings;
|
390 |
-
|
391 |
-
if(!function_exists('recaptcha_check_answer'))
|
392 |
-
require(FrmAppHelper::plugin_path().'/classes/recaptchalib.php');
|
393 |
-
|
394 |
-
$response = recaptcha_check_answer($frm_settings->privkey,
|
395 |
-
$_SERVER['REMOTE_ADDR'],
|
396 |
-
$_POST['recaptcha_challenge_field'],
|
397 |
-
$_POST['recaptcha_response_field']);
|
398 |
-
|
399 |
-
if (!$response->is_valid) {
|
400 |
-
// What happens when the CAPTCHA was entered incorrectly
|
401 |
-
$errors['captcha-'. $response->error] = $errors['field'. $posted_field->id] = (!isset($posted_field->field_options['invalid']) or $posted_field->field_options['invalid'] == '') ? $frm_settings->re_msg : $posted_field->field_options['invalid'];
|
402 |
-
}
|
403 |
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
408 |
}
|
409 |
-
|
410 |
-
|
411 |
// check for spam
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
$frm_form = new FrmForm();
|
416 |
-
$form = $frm_form->getOne($values['form_id']);
|
417 |
-
|
418 |
-
if ( isset($form->options['akismet']) && !empty($form->options['akismet']) && ($form->options['akismet'] != 'logged' || !is_user_logged_in()) ) {
|
419 |
-
$errors['spam'] = __('Your entry appears to be spam!', 'formidable');
|
420 |
-
}
|
421 |
-
}
|
422 |
-
|
423 |
-
// check for blacklist keys
|
424 |
-
if ( $this->blacklist_check($values) ) {
|
425 |
-
$errors['spam'] = __('Your entry appears to be spam!', 'formidable');
|
426 |
-
}
|
427 |
-
}
|
428 |
|
429 |
-
|
430 |
-
$errors = apply_filters('frm_validate_entry', $errors, $values);
|
431 |
return $errors;
|
432 |
}
|
433 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
// check the blacklisted words
|
435 |
-
function blacklist_check( $values ) {
|
436 |
if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
|
437 |
return false;
|
438 |
}
|
439 |
-
|
440 |
$mod_keys = trim( get_option( 'blacklist_keys' ) );
|
441 |
|
442 |
if ( empty( $mod_keys ) ) {
|
443 |
return false;
|
444 |
}
|
445 |
-
|
446 |
$content = FrmEntriesHelper::entry_array_to_string($values);
|
447 |
-
|
448 |
if ( empty($content) ) {
|
449 |
return false;
|
450 |
}
|
@@ -465,35 +683,21 @@ class FrmEntry{
|
|
465 |
|
466 |
return false;
|
467 |
}
|
468 |
-
|
469 |
-
|
470 |
-
|
|
|
|
|
|
|
|
|
471 |
$content = FrmEntriesHelper::entry_array_to_string($values);
|
472 |
-
|
473 |
if ( empty($content) ) {
|
474 |
return false;
|
475 |
}
|
476 |
-
|
477 |
$datas = array();
|
478 |
-
|
479 |
-
$datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
|
480 |
-
$datas['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
|
481 |
-
$datas['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
|
482 |
-
$datas['comment_type'] = 'formidable';
|
483 |
-
if ( $permalink = get_permalink() )
|
484 |
-
$datas['permalink'] = $permalink;
|
485 |
-
|
486 |
-
$datas['comment_content'] = $content;
|
487 |
-
|
488 |
-
foreach ( $_SERVER as $key => $value ) {
|
489 |
-
if ( !in_array($key, array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW')) && is_string($value) ) {
|
490 |
-
$datas["$key"] = $value;
|
491 |
-
} else {
|
492 |
-
$datas["$key"] = '';
|
493 |
-
}
|
494 |
-
|
495 |
-
unset($key, $value);
|
496 |
-
}
|
497 |
|
498 |
$query_string = '';
|
499 |
foreach ( $datas as $key => $data ) {
|
@@ -507,8 +711,36 @@ class FrmEntry{
|
|
507 |
global $akismet_api_host, $akismet_api_port;
|
508 |
$response = akismet_http_post( $query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
|
509 |
}
|
510 |
-
|
511 |
-
return ( is_array($response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
512 |
}
|
513 |
-
|
514 |
}
|
1 |
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
5 |
+
|
6 |
+
class FrmEntry {
|
7 |
+
|
8 |
+
public static function create( $values ) {
|
9 |
+
global $wpdb;
|
10 |
|
11 |
+
self::sanitize_entry_post( $values );
|
|
|
12 |
|
13 |
+
$values = apply_filters('frm_pre_create_entry', $values);
|
14 |
+
|
15 |
+
if ( ! isset( $values['item_key'] ) ) {
|
16 |
+
$values['item_key'] = '';
|
17 |
+
}
|
18 |
|
|
|
|
|
|
|
19 |
$new_values = array(
|
20 |
'item_key' => FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key'),
|
21 |
'name' => isset($values['name']) ? $values['name'] : $values['item_key'],
|
22 |
+
'ip' => FrmAppHelper::get_ip_address(),
|
23 |
'is_draft' => ( ( isset($values['frm_saving_draft']) && $values['frm_saving_draft'] == 1 ) || ( isset($values['is_draft']) && $values['is_draft'] == 1) ) ? 1 : 0,
|
24 |
'form_id' => isset($values['form_id']) ? (int) $values['form_id']: null,
|
25 |
'post_id' => isset($values['post_id']) ? (int) $values['post_id']: null,
|
26 |
+
'parent_item_id' => isset($values['parent_item_id']) ? (int) $values['parent_item_id']: null,
|
27 |
'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
|
28 |
'updated_at' => isset($values['updated_at']) ? $values['updated_at'] : ( isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1) ),
|
29 |
);
|
30 |
+
|
31 |
+
if ( is_array($new_values['name']) ) {
|
32 |
$new_values['name'] = reset($new_values['name']);
|
33 |
+
}
|
34 |
+
|
35 |
+
if ( isset($values['description']) && ! empty($values['description']) ) {
|
36 |
$new_values['description'] = maybe_serialize($values['description']);
|
37 |
+
} else {
|
38 |
+
$referrerinfo = FrmAppHelper::get_server_value('HTTP_REFERER');
|
39 |
+
|
40 |
+
$new_values['description'] = serialize( array(
|
41 |
+
'browser' => FrmAppHelper::get_server_value('HTTP_USER_AGENT'),
|
42 |
+
'referrer' => $referrerinfo,
|
43 |
+
) );
|
44 |
}
|
45 |
+
|
46 |
//if(isset($values['id']) and is_numeric($values['id']))
|
47 |
// $new_values['id'] = $values['id'];
|
48 |
+
|
49 |
+
if ( isset($values['frm_user_id']) && ( is_numeric($values['frm_user_id']) || FrmAppHelper::is_admin() ) ) {
|
50 |
$new_values['user_id'] = $values['frm_user_id'];
|
51 |
+
} else {
|
52 |
$user_ID = get_current_user_id();
|
53 |
$new_values['user_id'] = $user_ID ? $user_ID : 0;
|
54 |
}
|
55 |
+
|
56 |
$new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id'];
|
57 |
+
|
58 |
+
// don't create duplicate entry
|
59 |
+
if ( self::is_duplicate($new_values, $values) ) {
|
60 |
+
return false;
|
61 |
+
}
|
62 |
+
|
63 |
+
$query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
|
64 |
+
|
65 |
+
if ( ! $query_results ) {
|
66 |
+
return false;
|
67 |
+
}
|
68 |
+
|
69 |
+
$entry_id = $wpdb->insert_id;
|
70 |
+
|
71 |
+
global $frm_vars;
|
72 |
+
if ( ! isset($frm_vars['saved_entries']) ) {
|
73 |
+
$frm_vars['saved_entries'] = array();
|
74 |
+
}
|
75 |
+
$frm_vars['saved_entries'][] = (int) $entry_id;
|
76 |
+
|
77 |
+
if ( isset($values['item_meta']) ) {
|
78 |
+
FrmEntryMeta::update_entry_metas($entry_id, $values['item_meta']);
|
79 |
+
}
|
80 |
+
|
81 |
+
// this is a child entry
|
82 |
+
$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
|
83 |
+
|
84 |
+
do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) );
|
85 |
+
do_action( 'frm_after_create_entry_'. $new_values['form_id'], $entry_id , compact( 'is_child' ) );
|
86 |
+
|
87 |
+
return $entry_id;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* check for duplicate entries created in the last minute
|
92 |
+
* @return boolean
|
93 |
+
*/
|
94 |
+
public static function is_duplicate($new_values, $values) {
|
95 |
+
if ( defined('WP_IMPORTING') ) {
|
96 |
+
return false;
|
97 |
+
}
|
98 |
+
|
99 |
+
$check_val = $new_values;
|
100 |
+
$check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - 60 ) );
|
101 |
+
|
102 |
+
unset($check_val['created_at'], $check_val['updated_at']);
|
103 |
+
unset($check_val['is_draft'], $check_val['id'], $check_val['item_key']);
|
104 |
+
|
105 |
+
if ( $new_values['item_key'] == $new_values['name'] ) {
|
106 |
+
unset($check_val['name']);
|
107 |
+
}
|
108 |
+
|
109 |
+
global $wpdb;
|
110 |
+
|
111 |
+
$entry_exists = FrmDb::get_col( $wpdb->prefix .'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC') );
|
112 |
+
|
113 |
+
if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
|
114 |
+
return false;
|
115 |
+
}
|
116 |
+
|
117 |
+
$is_duplicate = false;
|
118 |
+
foreach ( $entry_exists as $entry_exist ) {
|
119 |
+
$is_duplicate = true;
|
120 |
+
|
121 |
+
//add more checks here to make sure it's a duplicate
|
122 |
+
$metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
|
123 |
+
$field_metas = array();
|
124 |
+
foreach ( $metas as $meta ) {
|
125 |
+
$field_metas[$meta->field_id] = $meta->meta_value;
|
126 |
}
|
127 |
+
|
128 |
+
// If prev entry is empty and current entry is not, they are not duplicates
|
129 |
+
$filtered_vals = array_filter( $values['item_meta'] );
|
130 |
+
if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
|
131 |
return false;
|
132 |
}
|
133 |
+
|
134 |
+
$diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
|
135 |
+
foreach ( $diff as $field_id => $meta_value ) {
|
136 |
+
if ( ! empty($meta_value) ) {
|
137 |
+
$is_duplicate = false;
|
138 |
+
continue;
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
if ( $is_duplicate ) {
|
143 |
+
return $is_duplicate;
|
|
|
|
|
|
|
144 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
}
|
146 |
+
|
147 |
+
return $is_duplicate;
|
148 |
}
|
|
|
|
|
|
|
149 |
|
150 |
+
public static function duplicate( $id ) {
|
151 |
+
global $wpdb;
|
152 |
+
|
153 |
+
$values = self::getOne( $id );
|
154 |
|
155 |
$new_values = array();
|
156 |
$new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
|
157 |
$new_values['name'] = $values->name;
|
158 |
$new_values['is_draft'] = $values->is_draft;
|
159 |
+
$new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
|
160 |
+
$new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
|
161 |
$new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
|
162 |
|
163 |
$query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
|
164 |
+
if ( ! $query_results ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
return false;
|
166 |
+
}
|
167 |
+
|
168 |
+
$entry_id = $wpdb->insert_id;
|
169 |
+
|
170 |
+
global $frm_vars;
|
171 |
+
if ( ! isset($frm_vars['saved_entries']) ) {
|
172 |
+
$frm_vars['saved_entries'] = array();
|
173 |
+
}
|
174 |
+
$frm_vars['saved_entries'][] = (int) $entry_id;
|
175 |
+
|
176 |
+
FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
|
177 |
+
|
178 |
+
do_action('frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id));
|
179 |
+
return $entry_id;
|
180 |
}
|
181 |
|
182 |
+
public static function update( $id, $values ) {
|
183 |
+
global $wpdb, $frm_vars;
|
184 |
+
if ( isset($frm_vars['saved_entries']) && is_array($frm_vars['saved_entries']) && in_array( (int) $id, (array) $frm_vars['saved_entries'] ) ) {
|
185 |
return;
|
186 |
+
}
|
187 |
+
|
188 |
+
$values = apply_filters('frm_pre_update_entry', $values, $id);
|
189 |
|
190 |
$user_ID = get_current_user_id();
|
191 |
+
|
192 |
$new_values = array(
|
193 |
'name' => isset($values['name']) ? $values['name'] : '',
|
194 |
'form_id' => isset($values['form_id']) ? (int) $values['form_id'] : null,
|
196 |
'updated_at' => current_time('mysql', 1),
|
197 |
'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : $user_ID,
|
198 |
);
|
199 |
+
|
200 |
if ( isset($values['post_id']) ) {
|
201 |
$new_values['post_id'] = (int) $values['post_id'];
|
202 |
}
|
204 |
if ( isset($values['item_key']) ) {
|
205 |
$new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key', $id);
|
206 |
}
|
207 |
+
|
208 |
+
if ( isset($values['parent_item_id']) ) {
|
209 |
+
$new_values['parent_item_id'] = (int) $values['parent_item_id'];
|
210 |
+
}
|
211 |
+
|
212 |
+
if ( isset($values['frm_user_id']) && is_numeric($values['frm_user_id']) ) {
|
213 |
$new_values['user_id'] = $values['frm_user_id'];
|
214 |
+
}
|
215 |
|
216 |
$new_values = apply_filters('frm_update_entry', $new_values, $id);
|
217 |
$query_results = $wpdb->update( $wpdb->prefix .'frm_items', $new_values, compact('id') );
|
218 |
+
|
219 |
+
if ( $query_results ) {
|
220 |
+
wp_cache_delete( $id .'_nometa', 'frm_entry');
|
221 |
wp_cache_delete( $id, 'frm_entry');
|
222 |
+
}
|
223 |
+
|
224 |
+
if ( ! isset( $frm_vars['saved_entries'] ) ) {
|
225 |
$frm_vars['saved_entries'] = array();
|
226 |
+
}
|
227 |
+
|
228 |
+
$frm_vars['saved_entries'][] = (int) $id;
|
229 |
+
|
230 |
+
if ( isset($values['item_meta']) ) {
|
231 |
+
FrmEntryMeta::update_entry_metas($id, $values['item_meta']);
|
232 |
+
}
|
233 |
do_action('frm_after_update_entry', $id, $new_values['form_id']);
|
234 |
do_action('frm_after_update_entry_'. $new_values['form_id'], $id);
|
235 |
return $query_results;
|
236 |
}
|
237 |
|
238 |
+
public static function &destroy( $id ){
|
239 |
global $wpdb;
|
240 |
+
$id = (int) $id;
|
241 |
+
|
242 |
+
$entry = self::getOne( $id );
|
243 |
+
if ( ! $entry ) {
|
244 |
$result = false;
|
245 |
return $result;
|
246 |
}
|
247 |
+
|
248 |
do_action('frm_before_destroy_entry', $id, $entry);
|
249 |
+
|
250 |
+
wp_cache_delete( $id .'_nometa', 'frm_entry');
|
251 |
wp_cache_delete( $id, 'frm_entry');
|
252 |
+
$wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id=%d', $id) );
|
253 |
+
$result = $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_items WHERE id=%d', $id) );
|
254 |
return $result;
|
255 |
}
|
256 |
+
|
257 |
+
public static function &update_form( $id, $value, $form_id ){
|
258 |
global $wpdb;
|
259 |
+
$form_id = isset($value) ? $form_id : null;
|
260 |
+
$result = $wpdb->update( $wpdb->prefix .'frm_items', array( 'form_id' => $form_id), array( 'id' => $id ) );
|
261 |
+
if ( $result ) {
|
262 |
wp_cache_delete( $id, 'frm_entry');
|
263 |
+
}
|
264 |
return $result;
|
265 |
}
|
266 |
+
|
267 |
+
public static function getOne( $id, $meta = false) {
|
268 |
global $wpdb;
|
|
|
|
|
|
|
|
|
269 |
|
270 |
+
$query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
|
271 |
LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
|
273 |
+
$query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
|
274 |
+
$query_args = array( $id );
|
275 |
+
$query = $wpdb->prepare( $query, $query_args );
|
276 |
|
277 |
+
if ( ! $meta ) {
|
278 |
+
$entry = FrmAppHelper::check_cache( $id .'_nometa', 'frm_entry', $query, 'get_row' );
|
279 |
+
return stripslashes_deep($entry);
|
280 |
+
}
|
281 |
+
|
282 |
+
$entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
|
283 |
+
if ( $entry !== false ) {
|
284 |
+
return stripslashes_deep($entry);
|
285 |
}
|
286 |
|
287 |
+
$entry = $wpdb->get_row( $query );
|
288 |
+
$entry = self::get_meta($entry);
|
289 |
+
|
290 |
return stripslashes_deep($entry);
|
291 |
}
|
292 |
+
|
293 |
+
public static function get_meta($entry) {
|
294 |
+
if ( ! $entry ) {
|
295 |
+
return $entry;
|
296 |
+
}
|
297 |
+
|
298 |
global $wpdb;
|
299 |
+
$metas = FrmDb::get_results( $wpdb->prefix .'frm_item_metas m LEFT JOIN '. $wpdb->prefix .'frm_fields f ON m.field_id=f.id', array( 'item_id' => $entry->id, 'field_id !' => 0), 'field_id, meta_value, field_key, item_id' );
|
300 |
+
|
301 |
+
$entry->metas = array();
|
302 |
+
|
303 |
+
foreach ( $metas as $meta_val ) {
|
304 |
+
if ( $meta_val->item_id == $entry->id ) {
|
305 |
+
$entry->metas[$meta_val->field_id] = maybe_unserialize($meta_val->meta_value);
|
306 |
+
continue;
|
307 |
+
}
|
308 |
+
|
309 |
+
// include sub entries in an array
|
310 |
+
if ( ! isset( $entry_metas[$meta_val->field_id]) ) {
|
311 |
+
$entry->metas[$meta_val->field_id] = array();
|
312 |
+
}
|
313 |
+
|
314 |
+
$entry->metas[$meta_val->field_id][] = maybe_unserialize($meta_val->meta_value);
|
315 |
+
|
316 |
+
unset($meta_val);
|
317 |
+
}
|
318 |
+
unset($metas);
|
319 |
+
|
320 |
+
wp_cache_set( $entry->id, $entry, 'frm_entry');
|
321 |
+
|
322 |
+
return $entry;
|
323 |
+
}
|
324 |
+
|
325 |
+
/**
|
326 |
+
* @param string $id
|
327 |
+
*/
|
328 |
+
public static function &exists( $id ){
|
329 |
+
global $wpdb;
|
330 |
+
|
331 |
+
if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
|
332 |
$exists = true;
|
333 |
return $exists;
|
334 |
}
|
|
|
|
|
335 |
|
336 |
+
if ( is_numeric($id) ) {
|
337 |
+
$where = array( 'id' => $id );
|
338 |
+
} else {
|
339 |
+
$where = array( 'item_key' => $id );
|
340 |
+
}
|
341 |
+
$id = FrmDb::get_var( $wpdb->prefix .'frm_items', $where );
|
342 |
+
|
343 |
$exists = ($id && $id > 0) ? true : false;
|
344 |
return $exists;
|
345 |
}
|
346 |
|
347 |
+
public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
|
348 |
global $wpdb;
|
349 |
+
|
350 |
+
$limit = FrmAppHelper::esc_limit($limit);
|
351 |
+
|
352 |
+
$cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
|
353 |
+
$entries = wp_cache_get($cache_key, 'frm_entry');
|
354 |
+
|
355 |
+
if ( false === $entries ) {
|
356 |
+
$fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
|
357 |
+
$table = $wpdb->prefix .'frm_items it ';
|
358 |
+
|
359 |
+
if ( $inc_form ) {
|
360 |
+
$fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
|
361 |
+
$table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
}
|
363 |
+
|
364 |
+
if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
|
365 |
+
// sort by a requested field
|
366 |
+
$field_id = (int) $order_matches[1];
|
367 |
+
$fields .= ', (SELECT meta_value FROM '. $wpdb->prefix .'frm_item_metas WHERE field_id = '. $field_id .' AND item_id = it.id) as meta_'. $field_id;
|
368 |
+
unset( $order_matches, $field_id );
|
369 |
+
}
|
370 |
+
|
371 |
+
// prepare the query
|
372 |
+
$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
|
373 |
+
|
374 |
+
$entries = $wpdb->get_results($query, OBJECT_K);
|
375 |
unset($query);
|
376 |
+
|
377 |
+
wp_cache_set($cache_key, $entries, 'frm_entry', 300);
|
378 |
+
}
|
379 |
+
|
380 |
+
if ( ! $meta || ! $entries ) {
|
381 |
+
return stripslashes_deep($entries);
|
382 |
+
}
|
383 |
+
unset($meta);
|
384 |
+
|
385 |
+
if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
|
386 |
+
$where = array( 'it.form_id' => substr($where, 11));
|
387 |
+
}
|
388 |
+
|
389 |
+
$meta_where = array( 'field_id !' => 0 );
|
390 |
+
if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
|
391 |
+
$meta_where['fi.form_id'] = $where['it.form_id'];
|
392 |
+
} else {
|
393 |
+
$meta_where['item_id'] = array_keys( $entries );
|
394 |
+
}
|
395 |
+
|
396 |
+
$metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
|
397 |
+
|
398 |
+
unset( $meta_where );
|
399 |
+
|
400 |
+
if ( ! $metas ) {
|
401 |
+
return stripslashes_deep($entries);
|
402 |
+
}
|
403 |
+
|
404 |
+
foreach ( $metas as $m_key => $meta_val ) {
|
405 |
+
if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
|
406 |
+
continue;
|
407 |
+
}
|
408 |
+
|
409 |
+
if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
|
410 |
+
$entries[$meta_val->item_id]->metas = array();
|
411 |
}
|
412 |
+
|
413 |
+
$entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize($meta_val->meta_value);
|
414 |
+
|
415 |
+
unset($m_key, $meta_val);
|
416 |
}
|
417 |
+
|
418 |
+
foreach ( $entries as $entry ) {
|
419 |
+
wp_cache_set( $entry->id, $entry, 'frm_entry');
|
420 |
+
unset($entry);
|
421 |
+
}
|
422 |
+
|
423 |
return stripslashes_deep($entries);
|
424 |
}
|
425 |
|
426 |
// Pagination Methods
|
427 |
+
public static function getRecordCount( $where = '' ) {
|
428 |
global $wpdb;
|
429 |
+
$table_join = $wpdb->prefix .'frm_items it LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON it.form_id=fr.id';
|
430 |
+
|
431 |
+
if ( is_numeric($where) ) {
|
432 |
+
$table_join = 'frm_items';
|
433 |
+
$where = array( 'form_id' => $where );
|
434 |
+
}
|
435 |
+
|
436 |
+
if ( is_array( $where ) ) {
|
437 |
+
$count = FrmDb::get_count( $table_join, $where );
|
438 |
+
} else {
|
439 |
+
global $wpdb;
|
440 |
+
$cache_key = 'count_'. maybe_serialize($where);
|
441 |
+
$query = 'SELECT COUNT(*) FROM '. $table_join . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
|
442 |
+
$count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
|
443 |
}
|
444 |
+
|
445 |
+
return $count;
|
446 |
}
|
447 |
|
448 |
+
public static function getPageCount( $p_size, $where = '' ) {
|
449 |
+
if ( is_numeric($where) ) {
|
450 |
+
return ceil( (int) $where / (int) $p_size );
|
451 |
+
} else {
|
452 |
+
return ceil( (int) self::getRecordCount($where) / (int) $p_size );
|
453 |
+
}
|
454 |
}
|
455 |
|
456 |
+
public static function validate( $values, $exclude = false ) {
|
457 |
+
global $wpdb;
|
458 |
+
|
459 |
+
self::sanitize_entry_post( $values );
|
460 |
$errors = array();
|
461 |
+
|
462 |
if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
|
463 |
+
$errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );
|
464 |
return $errors;
|
465 |
}
|
466 |
+
|
467 |
+
if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values['frm_submit_entry_'. $values['form_id'] ] ) || ! wp_verify_nonce($values['frm_submit_entry_'. $values['form_id']], 'frm_submit_entry_nonce') ) ) {
|
468 |
+
$errors['form'] = __( 'You do not have permission to do that', 'formidable' );
|
469 |
}
|
470 |
+
|
471 |
+
if ( ! isset($values['item_key']) || $values['item_key'] == '' ) {
|
472 |
$_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
|
473 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
|
475 |
+
$where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) );
|
476 |
+
// Don't get subfields
|
477 |
+
$where['fr.parent_form_id'] = array( null, 0 );
|
478 |
+
// Don't get excluded fields (like file upload fields in the ajax validation)
|
479 |
+
if ( ! empty( $exclude ) ) {
|
480 |
+
$where['fi.type not'] = $exclude;
|
481 |
+
}
|
482 |
+
|
483 |
+
$posted_fields = FrmField::getAll($where, 'field_order');
|
484 |
+
|
485 |
+
// Pass exclude value to validate_field function so it can be used for repeating sections
|
486 |
+
$args = array( 'exclude' => $exclude );
|
487 |
+
|
488 |
+
foreach ( $posted_fields as $posted_field ) {
|
489 |
+
self::validate_field($posted_field, $errors, $values, $args);
|
490 |
+
unset($posted_field);
|
491 |
}
|
492 |
+
|
|
|
493 |
// check for spam
|
494 |
+
self::spam_check($exclude, $values, $errors);
|
495 |
+
|
496 |
+
$errors = apply_filters('frm_validate_entry', $errors, $values, compact('exclude'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
|
|
|
|
|
498 |
return $errors;
|
499 |
}
|
500 |
+
|
501 |
+
/**
|
502 |
+
* Sanitize the POST values before we use them
|
503 |
+
*
|
504 |
+
* @since 2.0
|
505 |
+
* @param array $values The POST values by reference
|
506 |
+
*/
|
507 |
+
public static function sanitize_entry_post( &$values ) {
|
508 |
+
$sanitize_method = array(
|
509 |
+
'form_id' => 'absint',
|
510 |
+
'frm_action' => 'sanitize_title',
|
511 |
+
'form_key' => 'sanitize_title',
|
512 |
+
'item_key' => 'sanitize_title',
|
513 |
+
'name' => 'sanitize_text_field',
|
514 |
+
'frm_saving_draft' => 'absint',
|
515 |
+
'is_draft' => 'absint',
|
516 |
+
'post_id' => 'absint',
|
517 |
+
'parent_item_id' => 'absint',
|
518 |
+
'created_at' => 'sanitize_title',
|
519 |
+
'updated_at' => 'sanitize_title',
|
520 |
+
);
|
521 |
+
|
522 |
+
FrmAppHelper::sanitize_request( $sanitize_method, $values );
|
523 |
+
}
|
524 |
+
|
525 |
+
public static function validate_field($posted_field, &$errors, $values, $args = array()) {
|
526 |
+
$defaults = array(
|
527 |
+
'id' => $posted_field->id,
|
528 |
+
'parent_field_id' => '', // the id of the repeat or embed form
|
529 |
+
'key_pointer' => '', // the pointer in the posted array
|
530 |
+
'exclude' => array(), // exclude these field types from validation
|
531 |
+
);
|
532 |
+
$args = wp_parse_args( $args, $defaults );
|
533 |
+
|
534 |
+
if ( empty($args['parent_field_id']) ) {
|
535 |
+
$value = isset($values['item_meta'][$args['id']]) ? $values['item_meta'][$args['id']] : '';
|
536 |
+
} else {
|
537 |
+
// value is from a nested form
|
538 |
+
$value = $values;
|
539 |
+
}
|
540 |
+
|
541 |
+
// Check for values in "Other" fields
|
542 |
+
FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args );
|
543 |
+
|
544 |
+
if ( isset($posted_field->field_options['default_blank']) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) {
|
545 |
+
$value = '';
|
546 |
+
}
|
547 |
+
|
548 |
+
// Check for an array with only one value
|
549 |
+
// Don't reset values in "Other" fields because array keys need to be preserved
|
550 |
+
if ( is_array($value) && count( $value ) == 1 && $args['other'] !== true ) {
|
551 |
+
$value = reset($value);
|
552 |
+
}
|
553 |
+
|
554 |
+
if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) {
|
555 |
+
$frm_settings = FrmAppHelper::get_settings();
|
556 |
+
$errors['field'. $args['id']] = ( ! isset( $posted_field->field_options['blank'] ) || $posted_field->field_options['blank'] == '') ? $frm_settings->blank_msg : $posted_field->field_options['blank'];
|
557 |
+
} else if ( $posted_field->type == 'text' && ! isset( $_POST['name'] ) ) {
|
558 |
+
$_POST['name'] = $value;
|
559 |
+
}
|
560 |
+
|
561 |
+
self::validate_url_field($errors, $posted_field, $value, $args);
|
562 |
+
self::validate_email_field($errors, $posted_field, $value, $args);
|
563 |
+
|
564 |
+
FrmEntriesHelper::set_posted_value($posted_field, $value, $args);
|
565 |
+
|
566 |
+
self::validate_recaptcha($errors, $posted_field, $args);
|
567 |
+
|
568 |
+
$errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args);
|
569 |
+
}
|
570 |
+
|
571 |
+
public static function validate_url_field(&$errors, $field, &$value, $args) {
|
572 |
+
if ( $value == '' || ! in_array($field->type, array( 'website', 'url', 'image')) ) {
|
573 |
+
return;
|
574 |
+
}
|
575 |
+
|
576 |
+
if ( trim($value) == 'http://' ) {
|
577 |
+
$value = '';
|
578 |
+
} else {
|
579 |
+
$value = esc_url_raw( $value );
|
580 |
+
$value = preg_match('/^(https?|ftps?|mailto|news|feed|telnet):/is', $value) ? $value : 'http://'. $value;
|
581 |
+
}
|
582 |
+
|
583 |
+
//validate the url format
|
584 |
+
if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) {
|
585 |
+
$errors['field'. $args['id']] = FrmFieldsHelper::get_error_msg($field, 'invalid');
|
586 |
+
}
|
587 |
+
}
|
588 |
+
|
589 |
+
public static function validate_email_field(&$errors, $field, $value, $args) {
|
590 |
+
if ( $value == '' || $field->type != 'email' ) {
|
591 |
+
return;
|
592 |
+
}
|
593 |
+
|
594 |
+
//validate the email format
|
595 |
+
if ( ! is_email($value) ) {
|
596 |
+
$errors['field'. $args['id']] = FrmFieldsHelper::get_error_msg($field, 'invalid');
|
597 |
+
}
|
598 |
+
}
|
599 |
+
|
600 |
+
public static function validate_recaptcha(&$errors, $field, $args) {
|
601 |
+
if ( $field->type != 'captcha' || FrmAppHelper::is_admin() ) {
|
602 |
+
return;
|
603 |
+
}
|
604 |
+
|
605 |
+
if ( ! isset($_POST['g-recaptcha-response']) ) {
|
606 |
+
// If captcha is missing, check if it was already verified
|
607 |
+
if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) {
|
608 |
+
// There was no captcha submitted
|
609 |
+
$errors['field'. $args['id']] = __( 'The captcha is missing from this form', 'formidable' );
|
610 |
+
}
|
611 |
+
return;
|
612 |
+
}
|
613 |
+
|
614 |
+
$frm_settings = FrmAppHelper::get_settings();
|
615 |
+
|
616 |
+
$resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify?secret='. $frm_settings->privkey .'&response='. $_POST['g-recaptcha-response'] .'&remoteip='. FrmAppHelper::get_ip_address() );
|
617 |
+
$response = json_decode(wp_remote_retrieve_body( $resp ), true);
|
618 |
+
|
619 |
+
if ( ! $response['success'] ) {
|
620 |
+
// What happens when the CAPTCHA was entered incorrectly
|
621 |
+
$errors['field'. $args['id']] = ( ! isset($field->field_options['invalid']) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid'];
|
622 |
+
}
|
623 |
+
}
|
624 |
+
|
625 |
+
/**
|
626 |
+
* check for spam
|
627 |
+
* @param boolean $exclude
|
628 |
+
* @param array $values
|
629 |
+
* @param array $errors by reference
|
630 |
+
*/
|
631 |
+
public static function spam_check($exclude, $values, &$errors) {
|
632 |
+
if ( ! empty($exclude) || ! isset($values['item_meta']) || empty($values['item_meta']) || ! empty($errors) ) {
|
633 |
+
// only check spam if there are no other errors
|
634 |
+
return;
|
635 |
+
}
|
636 |
+
|
637 |
+
global $wpcom_api_key;
|
638 |
+
if ( ( function_exists( 'akismet_http_post' ) || is_callable('Akismet::http_post') ) && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet($values) ) {
|
639 |
+
$form = FrmForm::getOne($values['form_id']);
|
640 |
+
|
641 |
+
if ( isset($form->options['akismet']) && ! empty($form->options['akismet']) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ) {
|
642 |
+
$errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
|
643 |
+
}
|
644 |
+
}
|
645 |
+
|
646 |
+
// check for blacklist keys
|
647 |
+
if ( self::blacklist_check($values) ) {
|
648 |
+
$errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
|
649 |
+
}
|
650 |
+
}
|
651 |
+
|
652 |
// check the blacklisted words
|
653 |
+
public static function blacklist_check( $values ) {
|
654 |
if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
|
655 |
return false;
|
656 |
}
|
657 |
+
|
658 |
$mod_keys = trim( get_option( 'blacklist_keys' ) );
|
659 |
|
660 |
if ( empty( $mod_keys ) ) {
|
661 |
return false;
|
662 |
}
|
663 |
+
|
664 |
$content = FrmEntriesHelper::entry_array_to_string($values);
|
665 |
+
|
666 |
if ( empty($content) ) {
|
667 |
return false;
|
668 |
}
|
683 |
|
684 |
return false;
|
685 |
}
|
686 |
+
|
687 |
+
/**
|
688 |
+
* Check entries for spam
|
689 |
+
*
|
690 |
+
* @return boolean true if is spam
|
691 |
+
*/
|
692 |
+
public static function akismet($values) {
|
693 |
$content = FrmEntriesHelper::entry_array_to_string($values);
|
694 |
+
|
695 |
if ( empty($content) ) {
|
696 |
return false;
|
697 |
}
|
698 |
+
|
699 |
$datas = array();
|
700 |
+
self::parse_akismet_array($datas, $content);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
701 |
|
702 |
$query_string = '';
|
703 |
foreach ( $datas as $key => $data ) {
|
711 |
global $akismet_api_host, $akismet_api_port;
|
712 |
$response = akismet_http_post( $query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
|
713 |
}
|
714 |
+
|
715 |
+
return ( is_array($response) && $response[1] == 'true' ) ? true : false;
|
716 |
+
}
|
717 |
+
|
718 |
+
/**
|
719 |
+
* Called by FrmEntry::akismet
|
720 |
+
* @since 2.0
|
721 |
+
*
|
722 |
+
* @param string $content
|
723 |
+
*/
|
724 |
+
private static function parse_akismet_array( &$datas, $content ) {
|
725 |
+
$datas['blog'] = FrmAppHelper::site_url();
|
726 |
+
$datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() );
|
727 |
+
$datas['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
|
728 |
+
$datas['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
|
729 |
+
$datas['comment_type'] = 'formidable';
|
730 |
+
$datas['comment_content'] = $content;
|
731 |
+
|
732 |
+
if ( $permalink = get_permalink() ) {
|
733 |
+
$datas['permalink'] = $permalink;
|
734 |
+
}
|
735 |
+
|
736 |
+
foreach ( $_SERVER as $key => $value ) {
|
737 |
+
if ( ! in_array($key, array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW')) && is_string($value) ) {
|
738 |
+
$datas[$key] = $value;
|
739 |
+
} else {
|
740 |
+
$datas[$key] = '';
|
741 |
+
}
|
742 |
+
|
743 |
+
unset($key, $value);
|
744 |
+
}
|
745 |
}
|
|
|
746 |
}
|
classes/models/FrmEntryMeta.php
CHANGED
@@ -1,275 +1,353 @@
|
|
1 |
<?php
|
2 |
-
if(!defined('ABSPATH'))
|
3 |
-
|
4 |
-
|
5 |
-
return;
|
6 |
|
7 |
-
class FrmEntryMeta{
|
8 |
|
9 |
-
|
|
|
|
|
|
|
10 |
global $wpdb;
|
11 |
-
|
12 |
-
if ( (is_array($meta_value) && empty($meta_value) ) || ( !is_array($meta_value) && trim($meta_value) == '' ) ) {
|
13 |
// don't save blank fields
|
14 |
return;
|
15 |
}
|
16 |
-
|
17 |
$new_values = array(
|
18 |
'meta_value' => is_array($meta_value) ? serialize(array_filter($meta_value)) : trim($meta_value),
|
19 |
'item_id' => $entry_id,
|
20 |
'field_id' => $field_id,
|
21 |
'created_at' => current_time('mysql', 1),
|
22 |
);
|
23 |
-
|
24 |
$new_values = apply_filters('frm_add_entry_meta', $new_values);
|
25 |
|
26 |
$query_results = $wpdb->insert( $wpdb->prefix .'frm_item_metas', $new_values );
|
27 |
-
|
28 |
$id = $query_results ? $wpdb->insert_id : 0;
|
29 |
-
|
30 |
return $id;
|
31 |
}
|
32 |
|
33 |
-
|
|
|
|
|
|
|
34 |
if ( ! $field_id ) {
|
35 |
return false;
|
36 |
}
|
37 |
-
|
38 |
global $wpdb;
|
39 |
-
|
40 |
$values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
|
41 |
$values['meta_value'] = $meta_value;
|
42 |
$values = apply_filters('frm_update_entry_meta', $values);
|
43 |
-
if ( is_array($meta_value) ) {
|
44 |
-
$meta_value = array_filter($meta_value);
|
45 |
}
|
46 |
$meta_value = maybe_serialize($values['meta_value']);
|
47 |
-
|
|
|
|
|
48 |
return $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
|
49 |
}
|
50 |
-
|
51 |
-
function update_entry_metas($entry_id, $values){
|
52 |
-
global $
|
53 |
-
|
54 |
-
$prev_values =
|
55 |
-
|
56 |
foreach ( $values as $field_id => $meta_value ) {
|
57 |
-
|
|
|
|
|
58 |
if ( $prev_values && in_array($field_id, $prev_values) ) {
|
59 |
-
if ( (is_array($meta_value) && empty($meta_value) ) || ( !is_array($meta_value) && trim($meta_value) == '' ) ) {
|
60 |
// remove blank fields
|
61 |
unset($values[$field_id]);
|
62 |
} else {
|
63 |
// if value exists, then update it
|
64 |
-
|
65 |
}
|
66 |
} else {
|
67 |
// if value does not exist, then create it
|
68 |
-
|
69 |
}
|
70 |
-
|
71 |
}
|
72 |
-
|
73 |
if ( empty($prev_values) ) {
|
74 |
return;
|
75 |
}
|
76 |
-
|
77 |
$prev_values = array_diff($prev_values, array_keys($values));
|
78 |
-
|
79 |
if ( empty($prev_values) ) {
|
80 |
return;
|
81 |
}
|
82 |
-
|
|
|
|
|
|
|
|
|
83 |
// Delete any leftovers
|
84 |
-
$wpdb->query($wpdb->prepare(
|
85 |
}
|
86 |
-
|
87 |
-
function duplicate_entry_metas($old_id, $new_id){
|
88 |
-
$metas =
|
89 |
foreach ( $metas as $meta ) {
|
90 |
-
|
91 |
unset($meta);
|
92 |
}
|
93 |
}
|
94 |
|
95 |
-
function delete_entry_meta($entry_id, $field_id){
|
96 |
global $wpdb;
|
97 |
return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
|
98 |
}
|
99 |
-
|
100 |
-
function
|
101 |
-
_deprecated_function( __FUNCTION__, '1.07.05', '$frm_entry_meta->delete_entry_meta()' );
|
102 |
-
}
|
103 |
-
|
104 |
-
function get_entry_meta_by_field($entry_id, $field_id, $return_var=true){
|
105 |
global $wpdb;
|
106 |
-
|
107 |
-
$entry_id = (int)$entry_id;
|
108 |
-
|
109 |
-
$cached =
|
110 |
-
if($cached
|
111 |
$result = $cached->metas[$field_id];
|
112 |
return stripslashes_deep($result);
|
113 |
}
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
127 |
}
|
128 |
-
$
|
129 |
-
|
130 |
-
$result = $wpdb->get_col($query, 0);
|
131 |
}
|
132 |
-
|
|
|
133 |
return $result;
|
134 |
}
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
global $wpdb;
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
}
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
$var = $wpdb->get_var("{$query} LIMIT 1");
|
149 |
-
if($var)
|
150 |
-
$var = stripslashes_deep(maybe_unserialize($var));
|
151 |
-
}else{
|
152 |
-
$var = $wpdb->get_col($query, 0);
|
153 |
}
|
154 |
-
return $var;
|
155 |
-
}
|
156 |
|
157 |
-
|
158 |
-
global $wpdb;
|
159 |
-
return $wpdb->get_col($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d", $entry_id));
|
160 |
}
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
|
|
163 |
global $wpdb;
|
164 |
-
|
165 |
-
$
|
166 |
-
|
167 |
-
|
168 |
-
$
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
if(
|
173 |
-
$query
|
174 |
-
|
175 |
-
|
176 |
-
if(!$is_draft)
|
177 |
-
$query .= " AND e.is_draft=0";
|
178 |
-
|
179 |
-
if($value)
|
180 |
-
$query .= " AND meta_value='$value'";
|
181 |
-
$query .= "{$order}{$limit}";
|
182 |
-
|
183 |
-
$values = $wpdb->get_col($query);
|
184 |
-
if($stripslashes){
|
185 |
-
foreach($values as $k => $v){
|
186 |
-
$values[$k] = maybe_unserialize($v);
|
187 |
-
unset($k);
|
188 |
-
unset($v);
|
189 |
-
}
|
190 |
-
$values = stripslashes_deep($values);
|
191 |
}
|
192 |
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
}
|
195 |
-
|
196 |
-
function get_entry_meta_info($entry_id){
|
197 |
-
|
198 |
-
return $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d", $entry_id));
|
199 |
}
|
200 |
-
|
201 |
-
|
202 |
-
global $wpdb
|
203 |
-
$query =
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
$
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
|
|
|
|
216 |
}
|
217 |
-
|
218 |
-
return $results;
|
219 |
}
|
220 |
-
|
221 |
-
function getEntryIds($where =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
global $wpdb;
|
223 |
-
$query =
|
224 |
-
$query
|
225 |
-
$query
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
if (
|
230 |
$where['e.is_draft'] = 0;
|
231 |
-
} else {
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
$where .= ' GROUP BY '. $parts[1];
|
238 |
-
} else {
|
239 |
-
$where .= ' AND e.is_draft=0';
|
240 |
-
}
|
241 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
}
|
243 |
|
244 |
-
|
245 |
-
if (
|
246 |
-
|
247 |
-
else
|
248 |
-
|
|
|
|
|
|
|
|
|
|
|
249 |
|
250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
}
|
252 |
-
|
253 |
-
function search_entry_metas($search, $field_id='', $operator){
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
global $wpdb;
|
255 |
-
if (is_array($search)){
|
256 |
$where = '';
|
257 |
-
|
258 |
-
if ($field
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
}
|
265 |
-
$where .=
|
266 |
$query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas". FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
|
267 |
-
}else{
|
268 |
-
|
269 |
-
$search =
|
|
|
270 |
$query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
|
271 |
}
|
272 |
-
|
|
|
|
|
|
|
|
|
273 |
}
|
274 |
|
275 |
}
|
1 |
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
|
|
5 |
|
6 |
+
class FrmEntryMeta {
|
7 |
|
8 |
+
/**
|
9 |
+
* @param string $meta_key
|
10 |
+
*/
|
11 |
+
public static function add_entry_meta($entry_id, $field_id, $meta_key = null, $meta_value) {
|
12 |
global $wpdb;
|
13 |
+
|
14 |
+
if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) {
|
15 |
// don't save blank fields
|
16 |
return;
|
17 |
}
|
18 |
+
|
19 |
$new_values = array(
|
20 |
'meta_value' => is_array($meta_value) ? serialize(array_filter($meta_value)) : trim($meta_value),
|
21 |
'item_id' => $entry_id,
|
22 |
'field_id' => $field_id,
|
23 |
'created_at' => current_time('mysql', 1),
|
24 |
);
|
25 |
+
|
26 |
$new_values = apply_filters('frm_add_entry_meta', $new_values);
|
27 |
|
28 |
$query_results = $wpdb->insert( $wpdb->prefix .'frm_item_metas', $new_values );
|
29 |
+
|
30 |
$id = $query_results ? $wpdb->insert_id : 0;
|
31 |
+
|
32 |
return $id;
|
33 |
}
|
34 |
|
35 |
+
/**
|
36 |
+
* @param string $meta_key
|
37 |
+
*/
|
38 |
+
public static function update_entry_meta($entry_id, $field_id, $meta_key = null, $meta_value) {
|
39 |
if ( ! $field_id ) {
|
40 |
return false;
|
41 |
}
|
42 |
+
|
43 |
global $wpdb;
|
44 |
+
|
45 |
$values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
|
46 |
$values['meta_value'] = $meta_value;
|
47 |
$values = apply_filters('frm_update_entry_meta', $values);
|
48 |
+
if ( is_array($values['meta_value']) ) {
|
49 |
+
$values['meta_value'] = array_filter($values['meta_value']);
|
50 |
}
|
51 |
$meta_value = maybe_serialize($values['meta_value']);
|
52 |
+
|
53 |
+
wp_cache_delete( $entry_id, 'frm_entry');
|
54 |
+
|
55 |
return $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
|
56 |
}
|
57 |
+
|
58 |
+
public static function update_entry_metas($entry_id, $values) {
|
59 |
+
global $wpdb;
|
60 |
+
|
61 |
+
$prev_values = FrmDb::get_col( $wpdb->prefix .'frm_item_metas', array( 'item_id' => $entry_id, 'field_id !' => 0), 'field_id' );
|
62 |
+
|
63 |
foreach ( $values as $field_id => $meta_value ) {
|
64 |
+
// set the value for the file upload field and add new tags (in Pro version)
|
65 |
+
$values = apply_filters( 'frm_prepare_data_before_db', $values, $field_id, $entry_id );
|
66 |
+
|
67 |
if ( $prev_values && in_array($field_id, $prev_values) ) {
|
68 |
+
if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) {
|
69 |
// remove blank fields
|
70 |
unset($values[$field_id]);
|
71 |
} else {
|
72 |
// if value exists, then update it
|
73 |
+
self::update_entry_meta($entry_id, $field_id, '', $values[$field_id]);
|
74 |
}
|
75 |
} else {
|
76 |
// if value does not exist, then create it
|
77 |
+
self::add_entry_meta($entry_id, $field_id, '', $values[$field_id]);
|
78 |
}
|
|
|
79 |
}
|
80 |
+
|
81 |
if ( empty($prev_values) ) {
|
82 |
return;
|
83 |
}
|
84 |
+
|
85 |
$prev_values = array_diff($prev_values, array_keys($values));
|
86 |
+
|
87 |
if ( empty($prev_values) ) {
|
88 |
return;
|
89 |
}
|
90 |
+
|
91 |
+
// prepare the query
|
92 |
+
$where = array( 'item_id' => $entry_id, 'field_id' => $prev_values );
|
93 |
+
FrmDb::get_where_clause_and_values( $where );
|
94 |
+
|
95 |
// Delete any leftovers
|
96 |
+
$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) );
|
97 |
}
|
98 |
+
|
99 |
+
public static function duplicate_entry_metas($old_id, $new_id) {
|
100 |
+
$metas = self::get_entry_meta_info($old_id);
|
101 |
foreach ( $metas as $meta ) {
|
102 |
+
self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
|
103 |
unset($meta);
|
104 |
}
|
105 |
}
|
106 |
|
107 |
+
public static function delete_entry_meta($entry_id, $field_id) {
|
108 |
global $wpdb;
|
109 |
return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
|
110 |
}
|
111 |
+
|
112 |
+
public static function get_entry_meta_by_field($entry_id, $field_id) {
|
|
|
|
|
|
|
|
|
113 |
global $wpdb;
|
114 |
+
|
115 |
+
$entry_id = (int) $entry_id;
|
116 |
+
|
117 |
+
$cached = FrmAppHelper::check_cache( $entry_id, 'frm_entry' );
|
118 |
+
if ( $cached && isset($cached->metas) && isset($cached->metas[$field_id]) ) {
|
119 |
$result = $cached->metas[$field_id];
|
120 |
return stripslashes_deep($result);
|
121 |
}
|
122 |
+
|
123 |
+
$get_table = $wpdb->prefix .'frm_item_metas';
|
124 |
+
$query = array( 'item_id' => $entry_id );
|
125 |
+
if ( is_numeric($field_id) ) {
|
126 |
+
$query['field_id'] = $field_id;
|
127 |
+
} else {
|
128 |
+
$get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
|
129 |
+
$query['fi.field_key'] = $field_id;
|
130 |
+
}
|
131 |
+
|
132 |
+
$result = FrmDb::get_var( $get_table, $query, 'meta_value' );
|
133 |
+
$result = maybe_unserialize($result);
|
134 |
+
|
135 |
+
if ( $cached ) {
|
136 |
+
if ( ! isset( $cached->metas ) ) {
|
137 |
+
$cached->metas = array();
|
138 |
}
|
139 |
+
$cached->metas[$field_id] = $result;
|
140 |
+
wp_cache_set($entry_id, $cached, 'frm_entry');
|
|
|
141 |
}
|
142 |
+
$result = stripslashes_deep($result);
|
143 |
+
|
144 |
return $result;
|
145 |
}
|
146 |
+
|
147 |
+
public static function get_entry_meta( $entry_id, $field_id, $return_var = true ) {
|
148 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmEntryMeta::get_entry_meta_by_field' );
|
149 |
+
return self::get_entry_meta_by_field( $entry_id, $field_id );
|
150 |
+
}
|
151 |
+
|
152 |
+
public static function get_entry_metas($entry_id) {
|
153 |
+
_deprecated_function( __FUNCTION__, '1.07.10');
|
154 |
+
|
155 |
global $wpdb;
|
156 |
+
return FrmDb::get_col( $wpdb->prefix .'frm_item_metas', array( 'item_id' => $entry_id), 'meta_value' );
|
157 |
+
}
|
158 |
+
|
159 |
+
public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
|
160 |
+
$defaults = array( 'value' => false, 'unique' => false, 'stripslashes' => true, 'is_draft' => false);
|
161 |
+
$args = wp_parse_args( $args, $defaults );
|
162 |
+
|
163 |
+
$query = array();
|
164 |
+
self::meta_field_query($field_id, $order, $limit, $args, $query);
|
165 |
+
$query = implode(' ', $query);
|
166 |
+
|
167 |
+
$cache_key = 'entry_metas_for_field_'. $field_id . $order . $limit . maybe_serialize($args);
|
168 |
+
$values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col');
|
169 |
+
|
170 |
+
if ( ! $args['stripslashes'] ) {
|
171 |
+
return $values;
|
172 |
}
|
173 |
+
|
174 |
+
foreach ( $values as $k => $v ) {
|
175 |
+
$values[$k] = maybe_unserialize($v);
|
176 |
+
unset($k, $v);
|
|
|
|
|
|
|
|
|
|
|
177 |
}
|
|
|
|
|
178 |
|
179 |
+
return stripslashes_deep($values);
|
|
|
|
|
180 |
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* @param string $order
|
184 |
+
* @param string $limit
|
185 |
+
*/
|
186 |
+
private static function meta_field_query($field_id, $order, $limit, $args, array &$query) {
|
187 |
global $wpdb;
|
188 |
+
$query[] = 'SELECT';
|
189 |
+
$query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
|
190 |
+
$query[] = 'FROM '. $wpdb->prefix .'frm_item_metas em ';
|
191 |
+
|
192 |
+
if ( ! $args['is_draft'] ) {
|
193 |
+
$query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=em.item_id)';
|
194 |
+
}
|
195 |
+
|
196 |
+
if ( is_numeric($field_id) ) {
|
197 |
+
$query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
|
198 |
+
} else {
|
199 |
+
$query[] = $wpdb->prepare('LEFT JOIN '. $wpdb->prefix .'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
}
|
201 |
|
202 |
+
if ( ! $args['is_draft'] ) {
|
203 |
+
$query[] = 'AND e.is_draft=0';
|
204 |
+
}
|
205 |
+
|
206 |
+
if ( $args['value'] ) {
|
207 |
+
$query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
|
208 |
+
}
|
209 |
+
$query[] = $order . $limit;
|
210 |
}
|
211 |
+
|
212 |
+
public static function get_entry_meta_info($entry_id) {
|
213 |
+
return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id) );
|
|
|
214 |
}
|
215 |
+
|
216 |
+
public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) {
|
217 |
+
global $wpdb;
|
218 |
+
$query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
|
219 |
+
fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
|
220 |
+
FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id' .
|
221 |
+
FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
|
222 |
+
|
223 |
+
$cache_key = 'all_'. maybe_serialize($where) . $order_by . $limit;
|
224 |
+
$results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
|
225 |
+
|
226 |
+
if ( ! $results || ! $stripslashes ) {
|
227 |
+
return $results;
|
228 |
+
}
|
229 |
+
|
230 |
+
foreach ( $results as $k => $result ) {
|
231 |
+
$results[$k]->meta_value = stripslashes_deep(maybe_unserialize($result->meta_value));
|
232 |
+
unset($k, $result);
|
233 |
}
|
234 |
+
|
235 |
+
return $results;
|
236 |
}
|
237 |
+
|
238 |
+
public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
|
239 |
+
$defaults = array(
|
240 |
+
'is_draft' => false, 'user_id' => '',
|
241 |
+
'group_by' => '',
|
242 |
+
);
|
243 |
+
$args = wp_parse_args($args, $defaults);
|
244 |
+
|
245 |
+
$query = array();
|
246 |
+
self::get_ids_query($where, $order_by, $limit, $unique, $args, $query);
|
247 |
+
$query = implode(' ', $query);
|
248 |
+
|
249 |
+
$cache_key = 'ids_'. maybe_serialize($where) . $order_by . 'l'. $limit . 'u'. $unique . maybe_serialize($args);
|
250 |
+
$results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
|
251 |
+
|
252 |
+
return $results;
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* @param string $where
|
257 |
+
* @param string $order_by
|
258 |
+
* @param string $limit
|
259 |
+
* @param boolean $unique
|
260 |
+
*/
|
261 |
+
private static function get_ids_query($where, $order_by, $limit, $unique, $args, array &$query) {
|
262 |
global $wpdb;
|
263 |
+
$query[] = 'SELECT';
|
264 |
+
$query[] = $unique ? 'DISTINCT(it.item_id)' : 'it.item_id';
|
265 |
+
$query[] = 'FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id';
|
266 |
+
|
267 |
+
$query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=it.item_id)';
|
268 |
+
if ( is_array($where) ) {
|
269 |
+
if ( ! $args['is_draft'] ) {
|
270 |
$where['e.is_draft'] = 0;
|
271 |
+
} else if ( $args['is_draft'] == 1 ) {
|
272 |
+
$where['e.is_draft'] = 1;
|
273 |
+
}
|
274 |
+
|
275 |
+
if ( ! empty($args['user_id']) ) {
|
276 |
+
$where['e.user_id'] = $args['user_id'];
|
|
|
|
|
|
|
|
|
277 |
}
|
278 |
+
$query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
|
279 |
+
|
280 |
+
if ( $args['group_by'] ) {
|
281 |
+
$query[] = ' GROUP BY '. sanitize_text_field( $args['group_by'] );
|
282 |
+
}
|
283 |
+
return;
|
284 |
}
|
285 |
|
286 |
+
$draft_where = $user_where = '';
|
287 |
+
if ( ! $args['is_draft'] ) {
|
288 |
+
$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 0 );
|
289 |
+
} else if ( $args['is_draft'] == 1 ) {
|
290 |
+
$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
|
291 |
+
}
|
292 |
+
|
293 |
+
if ( ! empty($args['user_id']) ) {
|
294 |
+
$user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
|
295 |
+
}
|
296 |
|
297 |
+
if ( strpos($where, ' GROUP BY ') ) {
|
298 |
+
// don't inject WHERE filtering after GROUP BY
|
299 |
+
$parts = explode(' GROUP BY ', $where);
|
300 |
+
$where = $parts[0];
|
301 |
+
$where .= $draft_where . $user_where;
|
302 |
+
$where .= ' GROUP BY '. $parts[1];
|
303 |
+
} else {
|
304 |
+
$where .= $draft_where . $user_where;
|
305 |
+
}
|
306 |
+
|
307 |
+
// The query has already been prepared
|
308 |
+
$query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
|
309 |
}
|
310 |
+
|
311 |
+
public static function search_entry_metas( $search, $field_id = '', $operator ) {
|
312 |
+
$cache_key = 'search_'. maybe_serialize($search) . $field_id . $operator;
|
313 |
+
$results = wp_cache_get($cache_key, 'frm_entry');
|
314 |
+
if ( false !== $results ) {
|
315 |
+
return $results;
|
316 |
+
}
|
317 |
+
|
318 |
global $wpdb;
|
319 |
+
if (is_array($search)) {
|
320 |
$where = '';
|
321 |
+
foreach ( $search as $field => $value ) {
|
322 |
+
if ( $value <= 0 || ! in_array($field, array( 'year', 'month', 'day')) ) {
|
323 |
+
continue;
|
324 |
+
}
|
325 |
+
|
326 |
+
switch ( $field ) {
|
327 |
+
case 'year':
|
328 |
+
$value = '%'. $value;
|
329 |
+
break;
|
330 |
+
case 'month':
|
331 |
+
$value .= '%';
|
332 |
+
break;
|
333 |
+
case 'day':
|
334 |
+
$value = '%'. $value .'%';
|
335 |
+
}
|
336 |
+
$where .= $wpdb->prepare(' meta_value '. $operator .' %s and', $value);
|
337 |
}
|
338 |
+
$where .= $wpdb->prepare(' field_id=%d', $field_id);
|
339 |
$query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas". FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
|
340 |
+
} else {
|
341 |
+
if ( $operator == 'LIKE' ) {
|
342 |
+
$search = '%' . $search . '%';
|
343 |
+
}
|
344 |
$query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
|
345 |
}
|
346 |
+
|
347 |
+
$results = $wpdb->get_col($query, 0);
|
348 |
+
wp_cache_set($cache_key, $results, 'frm_entry', 300);
|
349 |
+
|
350 |
+
return $results;
|
351 |
}
|
352 |
|
353 |
}
|
classes/models/FrmField.php
CHANGED
@@ -1,257 +1,441 @@
|
|
1 |
<?php
|
2 |
-
if(!defined('ABSPATH'))
|
3 |
-
|
4 |
-
|
5 |
-
return;
|
6 |
|
7 |
class FrmField{
|
|
|
8 |
|
9 |
-
function create( $values, $return=true ){
|
10 |
-
global $wpdb;
|
11 |
|
12 |
$new_values = array();
|
13 |
$key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
|
14 |
$new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key');
|
15 |
|
16 |
-
foreach ( array('name', 'description', 'type', 'default_value') as $col ) {
|
17 |
$new_values[$col] = $values[$col];
|
18 |
}
|
19 |
-
|
20 |
$new_values['options'] = $values['options'];
|
21 |
|
22 |
-
$new_values['field_order'] = isset($values['field_order']) ? (int)$values['field_order'] :
|
23 |
-
$new_values['required'] = isset($values['required']) ? (int)$values['required'] : 0;
|
24 |
-
$new_values['form_id'] = isset($values['form_id']) ? (int)$values['form_id'] :
|
25 |
$new_values['field_options'] = $values['field_options'];
|
26 |
$new_values['created_at'] = current_time('mysql', 1);
|
27 |
-
|
28 |
-
|
29 |
$frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
|
30 |
$new_values = apply_filters('frm_duplicated_field', $new_values);
|
31 |
}
|
32 |
-
|
33 |
-
|
34 |
-
if(is_array($v))
|
35 |
-
|
36 |
-
|
37 |
-
unset($v);
|
38 |
}
|
39 |
-
|
40 |
//if(isset($values['id']) and is_numeric($values['id']))
|
41 |
// $new_values['id'] = $values['id'];
|
42 |
-
|
43 |
$query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
}
|
56 |
|
57 |
-
function duplicate($old_form_id, $form_id, $copy_keys=false, $blog_id=false){
|
58 |
-
global $frm_duplicate_ids
|
59 |
-
$fields =
|
60 |
-
foreach ((array)$fields as $field){
|
61 |
-
$values = array();
|
62 |
$new_key = ($copy_keys) ? $field->field_key : '';
|
63 |
-
if($copy_keys
|
64 |
$new_key = rtrim($new_key, 2);
|
65 |
-
|
66 |
-
|
67 |
-
$values
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
$values = apply_filters('frm_duplicated_field', $values);
|
71 |
-
$new_id =
|
72 |
-
$frm_duplicate_ids[$field->id] = $new_id;
|
73 |
-
$frm_duplicate_ids[$field->field_key] = $new_id;
|
74 |
unset($field);
|
75 |
}
|
76 |
}
|
77 |
|
78 |
-
function update( $id, $values ){
|
79 |
global $wpdb;
|
80 |
-
|
81 |
-
|
|
|
|
|
82 |
$values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id);
|
|
|
83 |
|
84 |
if ( isset($values['required']) ) {
|
85 |
$values['required'] = (int) $values['required'];
|
86 |
}
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
$values['options'] = serialize($values['options']);
|
96 |
-
|
97 |
$query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
104 |
$form_id = $field->form_id;
|
|
|
105 |
unset($field);
|
106 |
}
|
107 |
unset($values);
|
108 |
-
|
109 |
-
|
110 |
wp_cache_delete( $id, 'frm_field' );
|
111 |
-
|
|
|
|
|
112 |
}
|
113 |
-
|
114 |
return $query_results;
|
115 |
}
|
116 |
|
117 |
-
function destroy( $id ){
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
}
|
134 |
|
135 |
-
function getOne( $id ){
|
|
|
|
|
|
|
|
|
136 |
global $wpdb;
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
wp_cache_set( $results->field_key, $results, 'frm_field' );
|
146 |
-
}
|
147 |
}
|
148 |
-
|
149 |
-
if($
|
150 |
-
$results->
|
151 |
-
|
152 |
-
|
153 |
-
$results->options = maybe_unserialize($results->options);
|
154 |
-
$results->default_value = maybe_unserialize($results->default_value);
|
155 |
}
|
156 |
-
|
|
|
|
|
157 |
return stripslashes_deep($results);
|
158 |
}
|
159 |
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
global $wpdb;
|
162 |
-
|
163 |
-
if ($blog_id
|
164 |
global $wpmuBaseTablePrefix;
|
165 |
-
if($wpmuBaseTablePrefix)
|
166 |
-
$prefix =
|
167 |
-
else
|
168 |
$prefix = $wpdb->get_blog_prefix( $blog_id );
|
169 |
-
|
170 |
-
|
171 |
-
$
|
|
|
172 |
}else{
|
173 |
$table_name = $wpdb->prefix .'frm_fields';
|
174 |
$form_table_name = $wpdb->prefix .'frm_forms';
|
175 |
}
|
176 |
-
|
177 |
-
if(!empty($order_by) and !preg_match("/ORDER BY/", $order_by))
|
178 |
-
$order_by = " ORDER BY {$order_by}";
|
179 |
|
180 |
-
|
181 |
-
$
|
182 |
-
|
|
|
|
|
|
|
183 |
$query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
|
184 |
-
$
|
185 |
-
|
186 |
-
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
-
$
|
190 |
-
$query = $wpdb->prepare($query, $values);
|
191 |
}else{
|
|
|
192 |
$query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
|
|
|
|
|
|
|
193 |
}
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
$ak = is_array($old_where) ? array_keys($old_where) : $old_where;
|
199 |
-
if($order_by == ' ORDER BY field_order' and empty($limit) and empty($blog_id) and is_array($old_where) and count($old_where) == 1 and reset($ak) == 'fi.form_id'){
|
200 |
-
$save_cache = true;
|
201 |
-
$results = get_transient('frm_all_form_fields_'. reset($old_where));
|
202 |
-
if($results and (is_array($results) or is_object($results)))
|
203 |
-
$cached = true;
|
204 |
-
}
|
205 |
-
unset($ak);
|
206 |
-
if(!isset($cached))
|
207 |
-
$results = $wpdb->get_results($query);
|
208 |
}
|
209 |
-
|
210 |
-
if(
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
$results[$r_key]->options = maybe_unserialize($result->options);
|
219 |
-
$results[$r_key]->default_value = maybe_unserialize($result->default_value);
|
220 |
-
$form_id = $result->form_id;
|
221 |
-
|
222 |
-
unset($r_key, $result);
|
223 |
}
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
$results->field_options = maybe_unserialize($results->field_options);
|
231 |
-
if(isset($results->field_options['format']) and !empty($results->field_options['format']))
|
232 |
-
$results->field_options['format'] = addslashes($results->field_options['format']);
|
233 |
-
$results->options = maybe_unserialize($results->options);
|
234 |
-
$results->default_value = maybe_unserialize($results->default_value);
|
235 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
}
|
237 |
-
|
|
|
|
|
238 |
return stripslashes_deep($results);
|
239 |
}
|
240 |
|
241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
global $wpdb;
|
243 |
-
|
244 |
-
if ( !empty($order_by) && !preg_match("/ORDER BY/", $order_by) ){
|
245 |
$order_by = ' ORDER BY '. $order_by;
|
246 |
}
|
247 |
-
|
248 |
-
$query =
|
249 |
-
|
250 |
FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
|
|
255 |
return $results;
|
256 |
}
|
|
|
257 |
}
|
1 |
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
|
|
5 |
|
6 |
class FrmField{
|
7 |
+
static $use_cache = true;
|
8 |
|
9 |
+
public static function create( $values, $return = true ) {
|
10 |
+
global $wpdb, $frm_duplicate_ids;
|
11 |
|
12 |
$new_values = array();
|
13 |
$key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
|
14 |
$new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key');
|
15 |
|
16 |
+
foreach ( array( 'name', 'description', 'type', 'default_value') as $col ) {
|
17 |
$new_values[$col] = $values[$col];
|
18 |
}
|
19 |
+
|
20 |
$new_values['options'] = $values['options'];
|
21 |
|
22 |
+
$new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
|
23 |
+
$new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
|
24 |
+
$new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
|
25 |
$new_values['field_options'] = $values['field_options'];
|
26 |
$new_values['created_at'] = current_time('mysql', 1);
|
27 |
+
|
28 |
+
if ( isset( $values['id'] ) ) {
|
29 |
$frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
|
30 |
$new_values = apply_filters('frm_duplicated_field', $new_values);
|
31 |
}
|
32 |
+
|
33 |
+
foreach ( $new_values as $k => $v ) {
|
34 |
+
if ( is_array( $v ) ) {
|
35 |
+
$new_values[ $k ] = serialize( $v );
|
36 |
+
}
|
37 |
+
unset( $k, $v );
|
38 |
}
|
39 |
+
|
40 |
//if(isset($values['id']) and is_numeric($values['id']))
|
41 |
// $new_values['id'] = $values['id'];
|
42 |
+
|
43 |
$query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
|
44 |
+
if ( $query_results ) {
|
45 |
+
self::delete_form_transient( $new_values['form_id'] );
|
46 |
+
$new_id = $wpdb->insert_id;
|
47 |
+
}
|
48 |
+
|
49 |
+
if ( ! $return ) {
|
50 |
+
return;
|
51 |
+
}
|
52 |
+
|
53 |
+
if ( $query_results ) {
|
54 |
+
if ( isset( $values['id'] ) ) {
|
55 |
+
$frm_duplicate_ids[ $values['id'] ] = $new_id;
|
56 |
+
}
|
57 |
+
return $new_id;
|
58 |
+
} else {
|
59 |
+
return false;
|
60 |
+
}
|
61 |
}
|
62 |
|
63 |
+
public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
|
64 |
+
global $frm_duplicate_ids;
|
65 |
+
$fields = self::getAll( array( 'fi.form_id' => $old_form_id), 'field_order', '', $blog_id);
|
66 |
+
foreach ( (array) $fields as $field ) {
|
|
|
67 |
$new_key = ($copy_keys) ? $field->field_key : '';
|
68 |
+
if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
|
69 |
$new_key = rtrim($new_key, 2);
|
70 |
+
}
|
71 |
+
|
72 |
+
$values = array();
|
73 |
+
FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
|
74 |
+
|
75 |
+
// If this is a repeating section, create new form
|
76 |
+
if ( $field->type == 'divider' && isset( $field->field_options['repeat'] ) && $field->field_options['repeat'] ) {
|
77 |
+
// create the repeatable form
|
78 |
+
$repeat_form_values = FrmFormsHelper::setup_new_vars( array( 'parent_form_id' => $form_id ) );
|
79 |
+
$new_repeat_form_id = FrmForm::create( $repeat_form_values );
|
80 |
+
|
81 |
+
// Save old form_select
|
82 |
+
$old_repeat_form_id = $field->field_options['form_select'];
|
83 |
+
|
84 |
+
// Update form_select for repeating field
|
85 |
+
$values['field_options']['form_select'] = $new_repeat_form_id;
|
86 |
+
}
|
87 |
+
|
88 |
+
// If this is a field inside of a repeating section, associate it with the correct form
|
89 |
+
if ( $field->form_id != $old_form_id && isset( $old_repeat_form_id ) && isset( $new_repeat_form_id ) && $field->form_id == $old_repeat_form_id ) {
|
90 |
+
$values['form_id'] = $new_repeat_form_id;
|
91 |
+
}
|
92 |
+
|
93 |
$values = apply_filters('frm_duplicated_field', $values);
|
94 |
+
$new_id = self::create($values);
|
95 |
+
$frm_duplicate_ids[ $field->id ] = $new_id;
|
96 |
+
$frm_duplicate_ids[ $field->field_key ] = $new_id;
|
97 |
unset($field);
|
98 |
}
|
99 |
}
|
100 |
|
101 |
+
public static function update( $id, $values ){
|
102 |
global $wpdb;
|
103 |
+
|
104 |
+
$id = absint( $id );
|
105 |
+
|
106 |
+
if ( isset( $values['field_key'] ) ) {
|
107 |
$values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id);
|
108 |
+
}
|
109 |
|
110 |
if ( isset($values['required']) ) {
|
111 |
$values['required'] = (int) $values['required'];
|
112 |
}
|
113 |
+
|
114 |
+
// serialize array values
|
115 |
+
foreach ( array( 'default_value', 'field_options', 'options') as $opt ) {
|
116 |
+
if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) {
|
117 |
+
$values[ $opt ] = serialize( $values[ $opt ] );
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
|
|
|
|
121 |
$query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
|
122 |
+
|
123 |
+
$form_id = 0;
|
124 |
+
if ( isset( $values['form_id'] ) ) {
|
125 |
+
$form_id = absint( $values['form_id'] );
|
126 |
+
} else {
|
127 |
+
$field = self::getOne($id);
|
128 |
+
if ( $field ) {
|
129 |
$form_id = $field->form_id;
|
130 |
+
}
|
131 |
unset($field);
|
132 |
}
|
133 |
unset($values);
|
134 |
+
|
135 |
+
if ( $query_results ) {
|
136 |
wp_cache_delete( $id, 'frm_field' );
|
137 |
+
if ( $form_id ) {
|
138 |
+
self::delete_form_transient($form_id);
|
139 |
+
}
|
140 |
}
|
141 |
+
|
142 |
return $query_results;
|
143 |
}
|
144 |
|
145 |
+
public static function destroy( $id ) {
|
146 |
+
global $wpdb;
|
147 |
+
|
148 |
+
do_action( 'frm_before_destroy_field', $id );
|
149 |
+
|
150 |
+
wp_cache_delete( $id, 'frm_field' );
|
151 |
+
$field = self::getOne( $id );
|
152 |
+
if ( ! $field ) {
|
153 |
+
return false;
|
154 |
+
}
|
155 |
+
|
156 |
+
self::delete_form_transient( $field->form_id );
|
157 |
+
|
158 |
+
$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
|
159 |
+
return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
|
160 |
+
}
|
161 |
+
|
162 |
+
public static function delete_form_transient($form_id) {
|
163 |
+
$form_id = absint( $form_id );
|
164 |
+
delete_transient( 'frm_form_fields_'. $form_id .'exclude' );
|
165 |
+
delete_transient( 'frm_form_fields_'. $form_id .'include' );
|
166 |
+
|
167 |
+
$cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb';
|
168 |
+
wp_cache_delete($cache_key, 'frm_field');
|
169 |
+
|
170 |
+
// this cache key is autogenerated in FrmDb::get_var
|
171 |
+
wp_cache_delete( '(__fi.form_id=%d_OR_fr.parent_form_id=%d_)__' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' );
|
172 |
+
|
173 |
+
$form = FrmForm::getOne($form_id);
|
174 |
+
if ( $form && $form->parent_form_id ) {
|
175 |
+
self::delete_form_transient( $form->parent_form_id );
|
176 |
+
}
|
177 |
}
|
178 |
|
179 |
+
public static function getOne( $id ){
|
180 |
+
if ( empty( $id ) ) {
|
181 |
+
return;
|
182 |
+
}
|
183 |
+
|
184 |
global $wpdb;
|
185 |
+
|
186 |
+
$where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
|
187 |
+
$query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id);
|
188 |
+
|
189 |
+
$results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
|
190 |
+
|
191 |
+
if ( empty($results) ) {
|
192 |
+
return $results;
|
|
|
|
|
193 |
}
|
194 |
+
|
195 |
+
if ( is_numeric($id) ) {
|
196 |
+
wp_cache_set( $results->field_key, $results, 'frm_field' );
|
197 |
+
} else if ( $results ) {
|
198 |
+
wp_cache_set( $results->id, $results, 'frm_field' );
|
|
|
|
|
199 |
}
|
200 |
+
|
201 |
+
self::prepare_options( $results );
|
202 |
+
|
203 |
return stripslashes_deep($results);
|
204 |
}
|
205 |
|
206 |
+
/**
|
207 |
+
* Get the field type by key or id
|
208 |
+
* @param int|string The field id or key
|
209 |
+
*/
|
210 |
+
public static function &get_type( $id ) {
|
211 |
+
$field = FrmAppHelper::check_cache( $id, 'frm_field' );
|
212 |
+
if ( $field ) {
|
213 |
+
$type = $field->type;
|
214 |
+
} else {
|
215 |
+
$type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), 'type' );
|
216 |
+
}
|
217 |
+
|
218 |
+
return $type;
|
219 |
+
}
|
220 |
+
|
221 |
+
public static function get_all_types_in_form($form_id, $type, $limit = '', $inc_sub = 'exclude') {
|
222 |
+
if ( ! $form_id ) {
|
223 |
+
return array();
|
224 |
+
}
|
225 |
+
|
226 |
+
$results = get_transient( 'frm_form_fields_' . $form_id . $inc_sub );
|
227 |
+
if ( $results !== false ) {
|
228 |
+
$fields = array();
|
229 |
+
$count = 0;
|
230 |
+
foreach ( $results as $result ) {
|
231 |
+
if ( $type != $result->type ) {
|
232 |
+
continue;
|
233 |
+
}
|
234 |
+
|
235 |
+
$fields[$result->id] = $result;
|
236 |
+
$count++;
|
237 |
+
if ( $limit == 1 ) {
|
238 |
+
$fields = $result;
|
239 |
+
break;
|
240 |
+
}
|
241 |
+
|
242 |
+
if ( ! empty($limit) && $count >= $limit ) {
|
243 |
+
break;
|
244 |
+
}
|
245 |
+
|
246 |
+
unset($result);
|
247 |
+
}
|
248 |
+
return stripslashes_deep($fields);
|
249 |
+
}
|
250 |
+
|
251 |
+
self::$use_cache = false;
|
252 |
+
$results = self::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type), 'field_order', $limit);
|
253 |
+
self::$use_cache = true;
|
254 |
+
self::include_sub_fields($results, $inc_sub, $type);
|
255 |
+
|
256 |
+
return $results;
|
257 |
+
}
|
258 |
+
|
259 |
+
public static function get_all_for_form( $form_id, $limit = '', $inc_sub = 'exclude' ) {
|
260 |
+
if ( ! (int) $form_id ) {
|
261 |
+
return array();
|
262 |
+
}
|
263 |
+
|
264 |
+
$results = get_transient( 'frm_form_fields_' . $form_id . $inc_sub );
|
265 |
+
if ( $results !== false ) {
|
266 |
+
if ( empty($limit) ) {
|
267 |
+
return stripslashes_deep($results);
|
268 |
+
}
|
269 |
+
|
270 |
+
$fields = array();
|
271 |
+
$count = 0;
|
272 |
+
foreach ( $results as $result ) {
|
273 |
+
$fields[$result->id] = $result;
|
274 |
+
if ( ! empty($limit) && $count >= $limit ) {
|
275 |
+
break;
|
276 |
+
}
|
277 |
+
}
|
278 |
+
|
279 |
+
return stripslashes_deep($fields);
|
280 |
+
}
|
281 |
+
|
282 |
+
self::$use_cache = false;
|
283 |
+
|
284 |
+
// get the fields, but make sure to not get the subfields if set to exclude
|
285 |
+
$results = self::getAll( array( 'fi.form_id' => absint( $form_id ) ), 'field_order', $limit );
|
286 |
+
self::$use_cache = true;
|
287 |
+
|
288 |
+
self::include_sub_fields( $results, $inc_sub, 'all' );
|
289 |
+
|
290 |
+
if ( empty($limit) ) {
|
291 |
+
set_transient( 'frm_form_fields_' . $form_id . $inc_sub, $results, 60 * 60 * 6 );
|
292 |
+
}
|
293 |
+
|
294 |
+
return $results;
|
295 |
+
}
|
296 |
+
|
297 |
+
public static function include_sub_fields(&$results, $inc_sub, $type = 'all') {
|
298 |
+
if ( 'include' != $inc_sub ) {
|
299 |
+
return;
|
300 |
+
}
|
301 |
+
|
302 |
+
$form_fields = $results;
|
303 |
+
foreach ( $form_fields as $k => $field ) {
|
304 |
+
if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
|
305 |
+
continue;
|
306 |
+
}
|
307 |
+
|
308 |
+
if ( $type == 'all' ) {
|
309 |
+
$sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
|
310 |
+
} else {
|
311 |
+
$sub_fields = self::get_all_types_in_form($field->form_id, $type);
|
312 |
+
}
|
313 |
+
|
314 |
+
if ( ! empty($sub_fields) ) {
|
315 |
+
array_splice($results, $k, 1, $sub_fields);
|
316 |
+
}
|
317 |
+
unset($field, $sub_fields);
|
318 |
+
}
|
319 |
+
}
|
320 |
+
|
321 |
+
public static function getAll($where = array(), $order_by = '', $limit = '', $blog_id = false) {
|
322 |
+
$cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id;
|
323 |
+
if ( self::$use_cache ) {
|
324 |
+
// make sure old cache doesn't get saved as a transient
|
325 |
+
$results = wp_cache_get($cache_key, 'frm_field');
|
326 |
+
if ( false !== $results ) {
|
327 |
+
return stripslashes_deep($results);
|
328 |
+
}
|
329 |
+
}
|
330 |
+
|
331 |
global $wpdb;
|
332 |
+
|
333 |
+
if ( $blog_id && is_multisite() ) {
|
334 |
global $wpmuBaseTablePrefix;
|
335 |
+
if ( $wpmuBaseTablePrefix ) {
|
336 |
+
$prefix = $wpmuBaseTablePrefix . $blog_id .'_';
|
337 |
+
} else {
|
338 |
$prefix = $wpdb->get_blog_prefix( $blog_id );
|
339 |
+
}
|
340 |
+
|
341 |
+
$table_name = $prefix .'frm_fields';
|
342 |
+
$form_table_name = $prefix .'frm_forms';
|
343 |
}else{
|
344 |
$table_name = $wpdb->prefix .'frm_fields';
|
345 |
$form_table_name = $wpdb->prefix .'frm_forms';
|
346 |
}
|
|
|
|
|
|
|
347 |
|
348 |
+
if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
|
349 |
+
$order_by = ' ORDER BY '. $order_by;
|
350 |
+
}
|
351 |
+
|
352 |
+
$limit = FrmAppHelper::esc_limit($limit);
|
353 |
+
|
354 |
$query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
|
355 |
+
$query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
|
356 |
+
|
357 |
+
if ( is_array($where) ) {
|
358 |
+
if ( isset( $where['fi.form_id'] ) && count( $where ) == 1 ) {
|
359 |
+
// add sub fields to query
|
360 |
+
$form_id = $where['fi.form_id'];
|
361 |
+
$where[] = array( 'or' => 1, 'fi.form_id' => $form_id, 'fr.parent_form_id' => $form_id );
|
362 |
+
unset( $where['fi.form_id'] );
|
363 |
+
}
|
364 |
|
365 |
+
$results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
|
|
|
366 |
}else{
|
367 |
+
// if the query is not an array, then it has already been prepared
|
368 |
$query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
|
369 |
+
|
370 |
+
$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
|
371 |
+
$results = $wpdb->$function_name( $query );
|
372 |
}
|
373 |
+
unset( $where );
|
374 |
+
|
375 |
+
if ( ! $results ) {
|
376 |
+
stripslashes_deep($results);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
}
|
378 |
+
|
379 |
+
if ( is_array($results) ) {
|
380 |
+
foreach ( $results as $r_key => $result ) {
|
381 |
+
wp_cache_set($result->id, $result, 'frm_field');
|
382 |
+
wp_cache_set($result->field_key, $result, 'frm_field');
|
383 |
+
|
384 |
+
$results[$r_key]->field_options = maybe_unserialize($result->field_options);
|
385 |
+
if ( isset( $results[ $r_key ]->field_options['format'] ) && ! empty( $results[ $r_key ]->field_options['format'] ) ) {
|
386 |
+
$results[ $r_key ]->field_options['format'] = addslashes( $results[ $r_key ]->field_options['format'] );
|
|
|
|
|
|
|
|
|
|
|
387 |
}
|
388 |
+
|
389 |
+
$results[ $r_key ]->options = maybe_unserialize( $result->options );
|
390 |
+
$results[ $r_key ]->default_value = maybe_unserialize( $result->default_value );
|
391 |
+
$form_id = $result->form_id;
|
392 |
+
|
393 |
+
unset($r_key, $result);
|
|
|
|
|
|
|
|
|
|
|
394 |
}
|
395 |
+
|
396 |
+
unset($form_id);
|
397 |
+
} else if ( $results ) {
|
398 |
+
wp_cache_set($results->id, $results, 'frm_field');
|
399 |
+
wp_cache_set($results->field_key, $results, 'frm_field');
|
400 |
+
|
401 |
+
self::prepare_options( $results );
|
402 |
}
|
403 |
+
|
404 |
+
wp_cache_set($cache_key, $results, 'frm_field', 300);
|
405 |
+
|
406 |
return stripslashes_deep($results);
|
407 |
}
|
408 |
|
409 |
+
/**
|
410 |
+
* Unserialize all the serialized field data
|
411 |
+
* @since 2.0
|
412 |
+
*/
|
413 |
+
private static function prepare_options( &$results ) {
|
414 |
+
$results->field_options = maybe_unserialize( $results->field_options );
|
415 |
+
if ( isset( $results->field_options['format'] ) && ! empty( $results->field_options['format'] ) ) {
|
416 |
+
$results->field_options['format'] = addslashes( $results->field_options['format'] );
|
417 |
+
}
|
418 |
+
|
419 |
+
$results->options = maybe_unserialize($results->options);
|
420 |
+
$results->default_value = maybe_unserialize($results->default_value);
|
421 |
+
}
|
422 |
+
|
423 |
+
public static function getIds($where = '', $order_by = '', $limit = ''){
|
424 |
+
_deprecated_function( __FUNCTION__, '2.0' );
|
425 |
global $wpdb;
|
426 |
+
if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
|
|
|
427 |
$order_by = ' ORDER BY '. $order_by;
|
428 |
}
|
429 |
+
|
430 |
+
$query = 'SELECT fi.id FROM '. $wpdb->prefix .'frm_fields fi ' .
|
431 |
+
'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' .
|
432 |
FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
|
433 |
+
|
434 |
+
$method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
|
435 |
+
$cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit;
|
436 |
+
$results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
|
437 |
+
|
438 |
return $results;
|
439 |
}
|
440 |
+
|
441 |
}
|
classes/models/FrmForm.php
CHANGED
@@ -1,32 +1,35 @@
|
|
1 |
<?php
|
2 |
-
if(!defined('ABSPATH'))
|
3 |
-
|
4 |
-
|
5 |
-
return;
|
6 |
|
7 |
class FrmForm{
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
$new_values = array(
|
13 |
'form_key' => FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key'),
|
14 |
'name' => $values['name'],
|
15 |
'description' => $values['description'],
|
16 |
'status' => isset($values['status']) ? $values['status'] : 'draft',
|
|
|
17 |
'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0,
|
|
|
18 |
'editable' => isset($values['editable']) ? (int) $values['editable'] : 0,
|
19 |
'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
|
20 |
'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
|
21 |
);
|
22 |
-
|
23 |
$options = array();
|
24 |
|
25 |
$defaults = FrmFormsHelper::get_default_opts();
|
26 |
-
|
27 |
-
|
28 |
-
unset($var);
|
29 |
-
unset($default);
|
30 |
}
|
31 |
|
32 |
$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
|
@@ -39,27 +42,30 @@ class FrmForm{
|
|
39 |
//if(isset($values['id']) && is_numeric($values['id']))
|
40 |
// $new_values['id'] = $values['id'];
|
41 |
|
42 |
-
$
|
43 |
|
44 |
-
|
|
|
45 |
}
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
48 |
global $wpdb;
|
49 |
|
50 |
-
$
|
51 |
-
|
52 |
-
if ( !$values ) {
|
53 |
return false;
|
54 |
}
|
55 |
-
|
56 |
$new_key = $copy_keys ? $values->form_key : '';
|
57 |
-
|
58 |
$new_values = array(
|
59 |
'form_key' => FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_forms', 'form_key'),
|
60 |
'name' => $values->name,
|
61 |
'description' => $values->description,
|
62 |
-
'status' => $template ? '' : 'draft',
|
63 |
'logged_in' => $values->logged_in ? $values->logged_in : 0,
|
64 |
'editable' => $values->editable ? $values->editable : 0,
|
65 |
'created_at' => current_time('mysql', 1),
|
@@ -81,37 +87,39 @@ class FrmForm{
|
|
81 |
}
|
82 |
|
83 |
$query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
|
84 |
-
|
85 |
if ( $query_results ) {
|
86 |
-
global $frm_field;
|
87 |
$form_id = $wpdb->insert_id;
|
88 |
-
|
89 |
-
|
90 |
// update form settings after fields are created
|
91 |
-
do_action('frm_after_duplicate_form', $form_id, $new_values);
|
92 |
return $form_id;
|
93 |
-
} else {
|
94 |
-
return false;
|
95 |
}
|
|
|
|
|
96 |
}
|
97 |
-
|
98 |
-
function after_duplicate($form_id, $values) {
|
99 |
$new_opts = $values['options'] = maybe_unserialize($values['options']);
|
100 |
-
|
101 |
if ( isset($new_opts['success_msg']) ) {
|
102 |
$new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
|
103 |
}
|
104 |
-
|
105 |
$new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
|
106 |
-
|
107 |
if ( $new_opts != $values['options'] ) {
|
108 |
global $wpdb;
|
109 |
-
$wpdb->update($wpdb->prefix .'frm_forms', array('options' => maybe_serialize($new_opts)), array('id' => $form_id));
|
110 |
}
|
111 |
}
|
112 |
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
115 |
|
116 |
if ( $create_link || isset($values['options']) || isset($values['item_meta']) || isset($values['field_options']) ) {
|
117 |
$values['status'] = 'published';
|
@@ -121,30 +129,9 @@ class FrmForm{
|
|
121 |
$values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
|
122 |
}
|
123 |
|
124 |
-
$form_fields = array( 'form_key', 'name', 'description', 'status'
|
125 |
|
126 |
-
$new_values = array();
|
127 |
-
|
128 |
-
if (isset($values['options'])){
|
129 |
-
$options = array();
|
130 |
-
|
131 |
-
$defaults = FrmFormsHelper::get_default_opts();
|
132 |
-
foreach ($defaults as $var => $default) {
|
133 |
-
if ( $var == 'notification' && !defined('WP_IMPORTING')) {
|
134 |
-
$options[$var] = isset($values[$var]) ? $values[$var] : $default;
|
135 |
-
} else {
|
136 |
-
$options[$var] = isset($values['options'][$var]) ? $values['options'][$var] : $default;
|
137 |
-
}
|
138 |
-
}
|
139 |
-
|
140 |
-
$options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
|
141 |
-
$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
|
142 |
-
$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
|
143 |
-
$options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
|
144 |
-
|
145 |
-
$options = apply_filters('frm_form_options_before_update', $options, $values);
|
146 |
-
$new_values['options'] = serialize($options);
|
147 |
-
}
|
148 |
|
149 |
foreach ( $values as $value_key => $value ) {
|
150 |
if ( in_array($value_key, $form_fields) ) {
|
@@ -152,7 +139,11 @@ class FrmForm{
|
|
152 |
}
|
153 |
}
|
154 |
|
155 |
-
if ( !empty($
|
|
|
|
|
|
|
|
|
156 |
$query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
|
157 |
if ( $query_results ) {
|
158 |
wp_cache_delete( $id, 'frm_form');
|
@@ -160,120 +151,283 @@ class FrmForm{
|
|
160 |
} else {
|
161 |
$query_results = true;
|
162 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
-
$
|
165 |
-
|
166 |
-
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
}
|
169 |
-
$
|
|
|
|
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
|
|
|
|
|
|
|
|
|
|
175 |
}
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
if (
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
}else if($field->type == 'hidden' || $field->type == 'user_id'){
|
189 |
-
$prev_opts = $field_options;
|
190 |
-
$field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values);
|
191 |
-
if($prev_opts != $field_options)
|
192 |
-
$frm_field->update($field_id, array('field_options' => $field_options));
|
193 |
-
unset($prev_opts);
|
194 |
}
|
|
|
195 |
}
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
}
|
202 |
|
203 |
-
|
204 |
-
|
|
|
|
|
205 |
|
206 |
-
|
207 |
-
|
208 |
-
$field_key = (isset($values['field_options']['field_key_'.$field_id])) ? $values['field_options']['field_key_'.$field_id] : $field->field_key;
|
209 |
-
$required = (isset($values['field_options']['required_'.$field_id])) ? $values['field_options']['required_'.$field_id] : false;
|
210 |
-
$field_type = (isset($values['field_options']['type_'.$field_id])) ? $values['field_options']['type_'.$field_id] : $field->type;
|
211 |
-
$field_description = (isset($values['field_options']['description_'.$field_id])) ? $values['field_options']['description_'.$field_id] : $field->description;
|
212 |
|
213 |
-
|
214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
}
|
216 |
}
|
217 |
-
|
218 |
-
do_action('frm_update_form', $id, $values);
|
219 |
-
do_action('frm_update_form_'. $id, $values);
|
220 |
|
221 |
return $query_results;
|
222 |
}
|
223 |
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
-
$form =
|
228 |
-
if (
|
229 |
return false;
|
230 |
}
|
231 |
|
232 |
-
|
233 |
-
$
|
234 |
-
|
235 |
-
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
// Disconnect the fields from this form
|
239 |
-
$
|
240 |
|
241 |
-
$query_results = $wpdb->query($wpdb->prepare(
|
242 |
if ( $query_results ) {
|
|
|
|
|
|
|
|
|
243 |
do_action('frm_destroy_form', $id);
|
244 |
do_action('frm_destroy_form_'. $id);
|
245 |
}
|
|
|
246 |
return $query_results;
|
247 |
}
|
248 |
-
|
249 |
-
|
|
|
|
|
|
|
250 |
global $wpdb;
|
251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
if ( $cache ) {
|
253 |
-
return
|
254 |
-
}
|
255 |
-
|
256 |
-
$
|
257 |
-
|
258 |
-
|
259 |
-
$r = $wpdb->get_var($query);
|
260 |
-
return stripslashes($r);
|
261 |
}
|
262 |
-
|
263 |
-
|
|
|
|
|
|
|
264 |
global $wpdb;
|
265 |
-
$query = $wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_forms WHERE form_key=%s LIMIT 1", $key);
|
266 |
-
return $wpdb->get_var($query);
|
267 |
-
}
|
268 |
|
269 |
-
function getOne( $id, $blog_id=false ){
|
270 |
-
global $wpdb, $frmdb;
|
271 |
-
|
272 |
if ( $blog_id && is_multisite() ) {
|
273 |
global $wpmuBaseTablePrefix;
|
274 |
-
$prefix = $wpmuBaseTablePrefix ?
|
275 |
-
|
276 |
-
$table_name =
|
277 |
} else {
|
278 |
$table_name = $wpdb->prefix .'frm_forms';
|
279 |
$cache = wp_cache_get($id, 'frm_form');
|
@@ -281,15 +435,18 @@ class FrmForm{
|
|
281 |
if ( isset($cache->options) ) {
|
282 |
$cache->options = maybe_unserialize($cache->options);
|
283 |
}
|
284 |
-
|
285 |
return stripslashes_deep($cache);
|
286 |
}
|
287 |
}
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
|
|
|
|
|
|
293 |
if ( isset($results->options) ) {
|
294 |
wp_cache_set($results->id, $results, 'frm_form');
|
295 |
$results->options = maybe_unserialize($results->options);
|
@@ -297,52 +454,111 @@ class FrmForm{
|
|
297 |
return stripslashes_deep($results);
|
298 |
}
|
299 |
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
|
|
|
|
|
|
|
|
|
|
312 |
$results = $wpdb->get_row($query);
|
313 |
-
|
314 |
-
|
|
|
315 |
wp_cache_set($results->id, $results, 'frm_form');
|
316 |
$results->options = maybe_unserialize($results->options);
|
317 |
}
|
318 |
}else{
|
319 |
-
if ( is_array($where) && !empty($where) ) {
|
320 |
-
$results =
|
321 |
} else {
|
322 |
$results = $wpdb->get_results($query);
|
323 |
}
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
}
|
331 |
}
|
332 |
-
|
333 |
return stripslashes_deep($results);
|
334 |
}
|
335 |
|
336 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
$errors = array();
|
338 |
|
339 |
-
/*if( $values['form_key'] == null || $values['form_key'] == '' ){
|
340 |
-
if( $values['name'] == null || $values['name'] == '' )
|
341 |
-
$errors[] = "Key can't be blank";
|
342 |
-
else
|
343 |
-
$_POST['form_key'] = $values['name'];
|
344 |
-
}*/
|
345 |
-
|
346 |
return apply_filters('frm_validate_form', $errors, $values);
|
347 |
}
|
348 |
|
1 |
<?php
|
2 |
+
if ( ! defined('ABSPATH') ) {
|
3 |
+
die('You are not allowed to call this page directly.');
|
4 |
+
}
|
|
|
5 |
|
6 |
class FrmForm{
|
7 |
|
8 |
+
/**
|
9 |
+
* @return int|boolean id on success or false on failure
|
10 |
+
*/
|
11 |
+
public static function create( $values ) {
|
12 |
+
global $wpdb;
|
13 |
|
14 |
$new_values = array(
|
15 |
'form_key' => FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key'),
|
16 |
'name' => $values['name'],
|
17 |
'description' => $values['description'],
|
18 |
'status' => isset($values['status']) ? $values['status'] : 'draft',
|
19 |
+
'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0,
|
20 |
'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0,
|
21 |
+
'parent_form_id'=> isset($values['parent_form_id']) ? (int) $values['parent_form_id'] : 0,
|
22 |
'editable' => isset($values['editable']) ? (int) $values['editable'] : 0,
|
23 |
'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
|
24 |
'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
|
25 |
);
|
26 |
+
|
27 |
$options = array();
|
28 |
|
29 |
$defaults = FrmFormsHelper::get_default_opts();
|
30 |
+
foreach ( $defaults as $var => $default ) {
|
31 |
+
$options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default;
|
32 |
+
unset( $var, $default );
|
|
|
33 |
}
|
34 |
|
35 |
$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
|
42 |
//if(isset($values['id']) && is_numeric($values['id']))
|
43 |
// $new_values['id'] = $values['id'];
|
44 |
|
45 |
+
$wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
|
46 |
|
47 |
+
$id = $wpdb->insert_id;
|
48 |
+
return $id;
|
49 |
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @return int|boolean ID on success or false on failure
|
53 |
+
*/
|
54 |
+
public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
|
55 |
global $wpdb;
|
56 |
|
57 |
+
$values = self::getOne( $id, $blog_id );
|
58 |
+
if ( ! $values ) {
|
|
|
59 |
return false;
|
60 |
}
|
61 |
+
|
62 |
$new_key = $copy_keys ? $values->form_key : '';
|
63 |
+
|
64 |
$new_values = array(
|
65 |
'form_key' => FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_forms', 'form_key'),
|
66 |
'name' => $values->name,
|
67 |
'description' => $values->description,
|
68 |
+
'status' => $template ? 'published' : 'draft',
|
69 |
'logged_in' => $values->logged_in ? $values->logged_in : 0,
|
70 |
'editable' => $values->editable ? $values->editable : 0,
|
71 |
'created_at' => current_time('mysql', 1),
|
87 |
}
|
88 |
|
89 |
$query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
|
90 |
+
|
91 |
if ( $query_results ) {
|
|
|
92 |
$form_id = $wpdb->insert_id;
|
93 |
+
FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
|
94 |
+
|
95 |
// update form settings after fields are created
|
96 |
+
do_action('frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id));
|
97 |
return $form_id;
|
|
|
|
|
98 |
}
|
99 |
+
|
100 |
+
return false;
|
101 |
}
|
102 |
+
|
103 |
+
public static function after_duplicate($form_id, $values) {
|
104 |
$new_opts = $values['options'] = maybe_unserialize($values['options']);
|
105 |
+
|
106 |
if ( isset($new_opts['success_msg']) ) {
|
107 |
$new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
|
108 |
}
|
109 |
+
|
110 |
$new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
|
111 |
+
|
112 |
if ( $new_opts != $values['options'] ) {
|
113 |
global $wpdb;
|
114 |
+
$wpdb->update($wpdb->prefix .'frm_forms', array( 'options' => maybe_serialize($new_opts)), array( 'id' => $form_id));
|
115 |
}
|
116 |
}
|
117 |
|
118 |
+
/**
|
119 |
+
* @return int|boolean
|
120 |
+
*/
|
121 |
+
public static function update( $id, $values, $create_link = false ) {
|
122 |
+
global $wpdb;
|
123 |
|
124 |
if ( $create_link || isset($values['options']) || isset($values['item_meta']) || isset($values['field_options']) ) {
|
125 |
$values['status'] = 'published';
|
129 |
$values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
|
130 |
}
|
131 |
|
132 |
+
$form_fields = array( 'form_key', 'name', 'description', 'status' );
|
133 |
|
134 |
+
$new_values = self::set_update_options( array(), $values);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
foreach ( $values as $value_key => $value ) {
|
137 |
if ( in_array($value_key, $form_fields) ) {
|
139 |
}
|
140 |
}
|
141 |
|
142 |
+
if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
|
143 |
+
$new_values['status'] = $values['new_status'];
|
144 |
+
}
|
145 |
+
|
146 |
+
if ( ! empty( $new_values ) ) {
|
147 |
$query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
|
148 |
if ( $query_results ) {
|
149 |
wp_cache_delete( $id, 'frm_form');
|
151 |
} else {
|
152 |
$query_results = true;
|
153 |
}
|
154 |
+
unset($new_values);
|
155 |
+
|
156 |
+
$values = self::update_fields($id, $values);
|
157 |
+
|
158 |
+
do_action('frm_update_form', $id, $values);
|
159 |
+
do_action('frm_update_form_'. $id, $values);
|
160 |
+
|
161 |
+
return $query_results;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* @return array
|
166 |
+
*/
|
167 |
+
public static function set_update_options($new_values, $values) {
|
168 |
+
if ( ! isset($values['options']) ) {
|
169 |
+
return $new_values;
|
170 |
+
}
|
171 |
|
172 |
+
$options = array();
|
173 |
+
|
174 |
+
$defaults = FrmFormsHelper::get_default_opts();
|
175 |
+
foreach ( $defaults as $var => $default ) {
|
176 |
+
$options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default;
|
177 |
+
}
|
178 |
+
|
179 |
+
$options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
|
180 |
+
$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
|
181 |
+
$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
|
182 |
+
$options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
|
183 |
+
|
184 |
+
$options = apply_filters('frm_form_options_before_update', $options, $values);
|
185 |
+
$new_values['options'] = serialize($options);
|
186 |
+
|
187 |
+
return $new_values;
|
188 |
+
}
|
189 |
+
|
190 |
+
|
191 |
+
/**
|
192 |
+
* @return array
|
193 |
+
*/
|
194 |
+
public static function update_fields($id, $values) {
|
195 |
+
|
196 |
+
if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
|
197 |
+
return $values;
|
198 |
+
}
|
199 |
+
|
200 |
+
$all_fields = FrmField::get_all_for_form($id);
|
201 |
+
if ( empty($all_fields) ) {
|
202 |
+
return $values;
|
203 |
+
}
|
204 |
+
|
205 |
+
if ( ! isset($values['item_meta']) ) {
|
206 |
+
$values['item_meta'] = array();
|
207 |
+
}
|
208 |
+
|
209 |
+
$field_array = array();
|
210 |
+
$existing_keys = array_keys($values['item_meta']);
|
211 |
+
foreach ( $all_fields as $fid ) {
|
212 |
+
if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
|
213 |
+
$values['item_meta'][$fid->id] = '';
|
214 |
}
|
215 |
+
$field_array[$fid->id] = $fid;
|
216 |
+
}
|
217 |
+
unset($all_fields);
|
218 |
|
219 |
+
foreach ( $values['item_meta'] as $field_id => $default_value ) {
|
220 |
+
if ( isset($field_array[$field_id]) ) {
|
221 |
+
$field = $field_array[$field_id];
|
222 |
+
} else {
|
223 |
+
$field = FrmField::getOne($field_id);
|
224 |
+
}
|
225 |
+
|
226 |
+
if ( ! $field ) {
|
227 |
+
continue;
|
228 |
}
|
229 |
+
|
230 |
+
if ( isset($values['options']) || isset($values['field_options']['custom_html_'. $field_id]) ) {
|
231 |
+
//updating the settings page
|
232 |
+
if ( isset($values['field_options']['custom_html_'. $field_id]) ) {
|
233 |
+
$field->field_options['custom_html'] = isset($values['field_options']['custom_html_'.$field_id]) ? $values['field_options']['custom_html_'.$field_id] : ( isset($field->field_options['custom_html']) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html($field->type));
|
234 |
+
$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
|
235 |
+
FrmField::update($field_id, array( 'field_options' => $field->field_options));
|
236 |
+
} else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
|
237 |
+
$prev_opts = $field->field_options;
|
238 |
+
$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
|
239 |
+
if ( $prev_opts != $field->field_options ) {
|
240 |
+
FrmField::update($field_id, array( 'field_options' => $field->field_options));
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
}
|
242 |
+
unset($prev_opts);
|
243 |
}
|
244 |
+
}
|
245 |
+
|
246 |
+
if ( ( isset($values['options']) || isset($values['field_options']['custom_html_'. $field_id]) ) && ! defined('WP_IMPORTING') ) {
|
247 |
+
continue;
|
248 |
+
}
|
|
|
249 |
|
250 |
+
//updating the form
|
251 |
+
foreach ( array( 'size', 'max', 'label', 'invalid', 'blank', 'classes') as $opt ) {
|
252 |
+
$field->field_options[$opt] = isset($values['field_options'][$opt .'_'. $field_id]) ? trim($values['field_options'][$opt .'_'. $field_id]) : '';
|
253 |
+
}
|
254 |
|
255 |
+
$field->field_options['required_indicator'] = isset($values['field_options']['required_indicator_'. $field_id]) ? trim($values['field_options']['required_indicator_'. $field_id]) : '*';
|
256 |
+
$field->field_options['separate_value'] = isset($values['field_options']['separate_value_'. $field_id]) ? trim($values['field_options']['separate_value_'. $field_id]) : 0;
|
|
|
|
|
|
|
|
|
257 |
|
258 |
+
$field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
|
259 |
+
$default_value = maybe_serialize($values['item_meta'][$field_id]);
|
260 |
+
$field_key = isset($values['field_options']['field_key_'. $field_id]) ? $values['field_options']['field_key_'. $field_id] : $field->field_key;
|
261 |
+
$required = isset($values['field_options']['required_'. $field_id]) ? $values['field_options']['required_'. $field_id] : false;
|
262 |
+
$field_type = isset($values['field_options']['type_'. $field_id]) ? $values['field_options']['type_'. $field_id] : $field->type;
|
263 |
+
$field_description = isset($values['field_options']['description_'. $field_id]) ? $values['field_options']['description_'. $field_id] : $field->description;
|
264 |
+
|
265 |
+
FrmField::update($field_id, array(
|
266 |
+
'field_key' => $field_key, 'type' => $field_type,
|
267 |
+
'default_value' => $default_value, 'field_options' => $field->field_options,
|
268 |
+
'description' => $field_description, 'required' => $required,
|
269 |
+
) );
|
270 |
+
|
271 |
+
FrmField::delete_form_transient($field->form_id);
|
272 |
+
}
|
273 |
+
|
274 |
+
return $values;
|
275 |
+
}
|
276 |
+
|
277 |
+
/**
|
278 |
+
* @param string $status
|
279 |
+
* @return int|boolean
|
280 |
+
*/
|
281 |
+
public static function set_status($id, $status) {
|
282 |
+
if ( 'trash' == $status ) {
|
283 |
+
return self::trash($id);
|
284 |
+
}
|
285 |
+
|
286 |
+
$statuses = array( 'published', 'draft', 'trash');
|
287 |
+
if ( ! in_array( $status, $statuses ) ) {
|
288 |
+
return false;
|
289 |
+
}
|
290 |
+
|
291 |
+
global $wpdb;
|
292 |
+
|
293 |
+
if ( is_array($id) ) {
|
294 |
+
$where = array( 'id' => $id );
|
295 |
+
FrmDb::get_where_clause_and_values( $where );
|
296 |
+
array_unshift( $where['values'], $status );
|
297 |
+
|
298 |
+
$query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) );
|
299 |
+
} else {
|
300 |
+
$query_results = $wpdb->update( $wpdb->prefix .'frm_forms', array( 'status' => $status), array( 'id' => $id));
|
301 |
+
}
|
302 |
+
|
303 |
+
if ( $query_results ) {
|
304 |
+
foreach ( (array) $id as $i ) {
|
305 |
+
wp_cache_delete( $i, 'frm_form');
|
306 |
}
|
307 |
}
|
|
|
|
|
|
|
308 |
|
309 |
return $query_results;
|
310 |
}
|
311 |
|
312 |
+
/**
|
313 |
+
* @return int|boolean
|
314 |
+
*/
|
315 |
+
public static function trash($id) {
|
316 |
+
if ( ! EMPTY_TRASH_DAYS ) {
|
317 |
+
return self::destroy( $id );
|
318 |
+
}
|
319 |
|
320 |
+
$form = self::getOne($id);
|
321 |
+
if ( ! $form ) {
|
322 |
return false;
|
323 |
}
|
324 |
|
325 |
+
$options = $form->options;
|
326 |
+
$options['trash_time'] = time();
|
327 |
+
|
328 |
+
global $wpdb;
|
329 |
+
$query_results = $wpdb->update(
|
330 |
+
$wpdb->prefix .'frm_forms',
|
331 |
+
array( 'status' => 'trash', 'options' => serialize($options)),
|
332 |
+
array( 'id' => $id)
|
333 |
+
);
|
334 |
+
|
335 |
+
if ( $query_results ) {
|
336 |
+
wp_cache_delete( $id, 'frm_form');
|
337 |
}
|
338 |
+
|
339 |
+
return $query_results;
|
340 |
+
}
|
341 |
+
|
342 |
+
/**
|
343 |
+
* @return int|boolean
|
344 |
+
*/
|
345 |
+
public static function destroy( $id ){
|
346 |
+
global $wpdb;
|
347 |
+
|
348 |
+
$form = self::getOne($id);
|
349 |
+
if ( ! $form ) {
|
350 |
+
return false;
|
351 |
+
}
|
352 |
+
|
353 |
+
// Disconnect the entries from this form
|
354 |
+
$entries = FrmDb::get_col( $wpdb->prefix .'frm_items', array( 'form_id' => $id) );
|
355 |
+
foreach ( $entries as $entry_id ) {
|
356 |
+
FrmEntry::destroy($entry_id);
|
357 |
+
unset($entry_id);
|
358 |
+
}
|
359 |
+
|
360 |
// Disconnect the fields from this form
|
361 |
+
$wpdb->query($wpdb->prepare('DELETE fi FROM '. $wpdb->prefix .'frm_fields AS fi LEFT JOIN '. $wpdb->prefix .'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id));
|
362 |
|
363 |
+
$query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
|
364 |
if ( $query_results ) {
|
365 |
+
// Delete all form actions linked to this form
|
366 |
+
$action_control = FrmFormActionsController::get_form_actions( 'email' );
|
367 |
+
$action_control->destroy($id, 'all');
|
368 |
+
|
369 |
do_action('frm_destroy_form', $id);
|
370 |
do_action('frm_destroy_form_'. $id);
|
371 |
}
|
372 |
+
|
373 |
return $query_results;
|
374 |
}
|
375 |
+
|
376 |
+
/**
|
377 |
+
* @return string form name
|
378 |
+
*/
|
379 |
+
public static function &getName( $id ) {
|
380 |
global $wpdb;
|
381 |
+
|
382 |
+
$form = FrmAppHelper::check_cache($id, 'frm_form');
|
383 |
+
if ( $form ) {
|
384 |
+
$r = stripslashes($form->name);
|
385 |
+
return $r;
|
386 |
+
}
|
387 |
+
|
388 |
+
$query_key = is_numeric( $id ) ? 'id' : 'form_key';
|
389 |
+
$r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
|
390 |
+
$r = stripslashes($r);
|
391 |
+
|
392 |
+
return $r;
|
393 |
+
}
|
394 |
+
|
395 |
+
/**
|
396 |
+
* @param string $key
|
397 |
+
* @return int form id
|
398 |
+
*/
|
399 |
+
public static function &getIdByKey( $key ){
|
400 |
+
$id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
|
401 |
+
return $id;
|
402 |
+
}
|
403 |
+
|
404 |
+
/**
|
405 |
+
* @param int $id
|
406 |
+
* @return string form key
|
407 |
+
*/
|
408 |
+
public static function &getKeyById($id){
|
409 |
+
$id = (int) $id;
|
410 |
+
$cache = FrmAppHelper::check_cache($id, 'frm_form');
|
411 |
if ( $cache ) {
|
412 |
+
return $cache->form_key;
|
413 |
+
}
|
414 |
+
|
415 |
+
$key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
|
416 |
+
|
417 |
+
return $key;
|
|
|
|
|
418 |
}
|
419 |
+
|
420 |
+
/**
|
421 |
+
* @return object form
|
422 |
+
*/
|
423 |
+
public static function getOne( $id, $blog_id = false ) {
|
424 |
global $wpdb;
|
|
|
|
|
|
|
425 |
|
|
|
|
|
|
|
426 |
if ( $blog_id && is_multisite() ) {
|
427 |
global $wpmuBaseTablePrefix;
|
428 |
+
$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id );
|
429 |
+
|
430 |
+
$table_name = $prefix .'frm_forms';
|
431 |
} else {
|
432 |
$table_name = $wpdb->prefix .'frm_forms';
|
433 |
$cache = wp_cache_get($id, 'frm_form');
|
435 |
if ( isset($cache->options) ) {
|
436 |
$cache->options = maybe_unserialize($cache->options);
|
437 |
}
|
438 |
+
|
439 |
return stripslashes_deep($cache);
|
440 |
}
|
441 |
}
|
442 |
+
|
443 |
+
if ( is_numeric($id) ) {
|
444 |
+
$where = array( 'id' => $id );
|
445 |
+
} else {
|
446 |
+
$where = array( 'form_key' => $id );
|
447 |
+
}
|
448 |
+
$results = FrmDb::get_row( $table_name, $where );
|
449 |
+
|
450 |
if ( isset($results->options) ) {
|
451 |
wp_cache_set($results->id, $results, 'frm_form');
|
452 |
$results->options = maybe_unserialize($results->options);
|
454 |
return stripslashes_deep($results);
|
455 |
}
|
456 |
|
457 |
+
/**
|
458 |
+
* @return array of objects
|
459 |
+
*/
|
460 |
+
public static function getAll( $where = array(), $order_by = '', $limit = '' ){
|
461 |
+
global $wpdb;
|
462 |
+
|
463 |
+
if ( is_numeric($limit) ) {
|
464 |
+
$limit = ' LIMIT '. $limit;
|
465 |
+
}
|
466 |
+
|
467 |
+
$query = 'SELECT * FROM ' . $wpdb->prefix .'frm_forms' . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . FrmAppHelper::esc_order($order_by) . FrmAppHelper::esc_limit($limit);
|
468 |
+
|
469 |
+
if ( $limit == ' LIMIT 1' || $limit == 1 ) {
|
470 |
+
if ( is_array($where) && ! empty($where) ) {
|
471 |
+
$results = FrmDb::get_row($wpdb->prefix .'frm_forms', $where, '*', array( 'order_by' => $order_by) );
|
472 |
+
} else {
|
473 |
+
// the query has already been prepared if this is not an array
|
474 |
$results = $wpdb->get_row($query);
|
475 |
+
}
|
476 |
+
|
477 |
+
if ( $results ) {
|
478 |
wp_cache_set($results->id, $results, 'frm_form');
|
479 |
$results->options = maybe_unserialize($results->options);
|
480 |
}
|
481 |
}else{
|
482 |
+
if ( is_array($where) && ! empty($where) ) {
|
483 |
+
$results = FrmDb::get_results( $wpdb->prefix .'frm_forms', $where, '*', compact('order_by', 'limit') );
|
484 |
} else {
|
485 |
$results = $wpdb->get_results($query);
|
486 |
}
|
487 |
+
|
488 |
+
if ( $results ) {
|
489 |
+
foreach ( $results as $result ) {
|
490 |
+
wp_cache_set( $result->id, $result, 'frm_form' );
|
491 |
+
$result->options = maybe_unserialize( $result->options );
|
492 |
+
}
|
493 |
}
|
494 |
}
|
495 |
+
|
496 |
return stripslashes_deep($results);
|
497 |
}
|
498 |
|
499 |
+
/**
|
500 |
+
* Get all published forms
|
501 |
+
* @since 2.0
|
502 |
+
*/
|
503 |
+
public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
|
504 |
+
$query['is_template'] = 0;
|
505 |
+
$query['status'] = array( null, '', 'published' );
|
506 |
+
if ( $inc_children == 'exclude' ) {
|
507 |
+
$query['parent_form_id'] = array( null, 0 );
|
508 |
+
}
|
509 |
+
|
510 |
+
$forms = self::getAll( $query, 'name', $limit );
|
511 |
+
return $forms;
|
512 |
+
}
|
513 |
+
|
514 |
+
/**
|
515 |
+
* @return int count of forms
|
516 |
+
*/
|
517 |
+
public static function &get_count( ) {
|
518 |
+
global $wpdb;
|
519 |
+
|
520 |
+
$cache_key = 'frm_form_counts';
|
521 |
+
|
522 |
+
$counts = wp_cache_get( $cache_key, 'counts' );
|
523 |
+
if ( false !== $counts ) {
|
524 |
+
return $counts;
|
525 |
+
}
|
526 |
+
|
527 |
+
$results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
|
528 |
+
|
529 |
+
$statuses = array( 'published', 'draft', 'template', 'trash');
|
530 |
+
$counts = array_fill_keys( $statuses, 0 );
|
531 |
+
|
532 |
+
foreach ( $results as $row ) {
|
533 |
+
if ( 'trash' != $row->status ) {
|
534 |
+
if ( $row->is_template ) {
|
535 |
+
$counts['template']++;
|
536 |
+
} else {
|
537 |
+
$counts['published']++;
|
538 |
+
}
|
539 |
+
} else {
|
540 |
+
$counts['trash']++;
|
541 |
+
}
|
542 |
+
|
543 |
+
if ( 'draft' == $row->status ) {
|
544 |
+
$counts['draft']++;
|
545 |
+
}
|
546 |
+
|
547 |
+
unset($row);
|
548 |
+
}
|
549 |
+
|
550 |
+
$counts = (object) $counts;
|
551 |
+
wp_cache_set( $cache_key, $counts, 'counts' );
|
552 |
+
|
553 |
+
return $counts;
|
554 |
+
}
|
555 |
+
|
556 |
+
/**
|
557 |
+
* @return array of errors
|
558 |
+
*/
|
559 |
+
public static function validate( $values ){
|
560 |
$errors = array();
|
561 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
562 |
return apply_filters('frm_validate_form', $errors, $values);
|
563 |
}
|
564 |
|
classes/models/FrmFormAction.php
ADDED
@@ -0,0 +1,529 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class FrmFormAction {
|
4 |
+
|
5 |
+
public $id_base; // Root id for all actions of this type.
|
6 |
+
public $name; // Name for this action type.
|
7 |
+
public $option_name;
|
8 |
+
public $action_options; // Option array passed to wp_register_sidebar_widget()
|
9 |
+
public $control_options; // Option array passed to wp_register_widget_control()
|
10 |
+
|
11 |
+
public $form_id; // The ID of the form to evaluate
|
12 |
+
public $number = false; // Unique ID number of the current instance.
|
13 |
+
public $id = ''; // Unique ID string of the current instance (id_base-number)
|
14 |
+
public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.
|
15 |
+
|
16 |
+
// Member functions that you must over-ride.
|
17 |
+
|
18 |
+
/** Update a particular instance.
|
19 |
+
*
|
20 |
+
* This function should check that $new_instance is set correctly.
|
21 |
+
* The newly calculated value of $instance should be returned.
|
22 |
+
* If "false" is returned, the instance won't be saved/updated.
|
23 |
+
*
|
24 |
+
* @param array $new_instance New settings for this instance as input by the user via form()
|
25 |
+
* @param array $old_instance Old settings for this instance
|
26 |
+
* @return array Settings to save or bool false to cancel saving
|
27 |
+
*/
|
28 |
+
public function update($new_instance, $old_instance) {
|
29 |
+
return $new_instance;
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Echo the settings update form
|
34 |
+
*
|
35 |
+
* @param array $instance Current settings
|
36 |
+
*/
|
37 |
+
public function form($instance, $args = array()) {
|
38 |
+
echo '<p class="no-options-widget">' . __( 'There are no options for this action.', 'formidable' ) . '</p>';
|
39 |
+
return 'noform';
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @return array of the default options
|
44 |
+
*/
|
45 |
+
public function get_defaults() {
|
46 |
+
return array();
|
47 |
+
}
|
48 |
+
|
49 |
+
public function get_switch_fields() {
|
50 |
+
return array();
|
51 |
+
}
|
52 |
+
|
53 |
+
public function migrate_values($action, $form) {
|
54 |
+
return $action;
|
55 |
+
}
|
56 |
+
|
57 |
+
// Functions you'll need to call.
|
58 |
+
|
59 |
+
/**
|
60 |
+
* PHP5 constructor
|
61 |
+
*
|
62 |
+
* @param string $id_base Optional Base ID for the widget, lower case,
|
63 |
+
* if left empty a portion of the widget's class name will be used. Has to be unique.
|
64 |
+
* @param string $name Name for the widget displayed on the configuration page.
|
65 |
+
* @param array $action_options Optional Passed to wp_register_sidebar_widget()
|
66 |
+
* - description: shown on the configuration page
|
67 |
+
* - classname
|
68 |
+
* @param array $control_options Optional Passed to wp_register_widget_control()
|
69 |
+
* - width: required if more than 250px
|
70 |
+
* - height: currently not used but may be needed in the future
|
71 |
+
*/
|
72 |
+
public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
|
73 |
+
if ( ! defined('ABSPATH') ) {
|
74 |
+
die('You are not allowed to call this page directly.');
|
75 |
+
}
|
76 |
+
|
77 |
+
$this->id_base = strtolower($id_base);
|
78 |
+
$this->name = $name;
|
79 |
+
$this->option_name = 'frm_' . $this->id_base .'_action';
|
80 |
+
|
81 |
+
$default_options = array(
|
82 |
+
'classes' => '',
|
83 |
+
'active' => true,
|
84 |
+
'event' => array( 'create'),
|
85 |
+
'limit' => 1,
|
86 |
+
'force_event' => false,
|
87 |
+
'priority' => 20,
|
88 |
+
'ajax_load' => true,
|
89 |
+
'tooltip' => $name,
|
90 |
+
);
|
91 |
+
|
92 |
+
$this->action_options = wp_parse_args( $action_options, $default_options );
|
93 |
+
$this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base) );
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* @param string $id_base
|
98 |
+
*/
|
99 |
+
public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) {
|
100 |
+
FrmFormAction::__construct( $id_base, $name, $action_options, $control_options );
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Constructs name attributes for use in form() fields
|
105 |
+
*
|
106 |
+
* This function should be used in form() methods to create name attributes for fields to be saved by update()
|
107 |
+
*
|
108 |
+
* @param string $field_name Field name
|
109 |
+
* @return string Name attribute for $field_name
|
110 |
+
*/
|
111 |
+
public function get_field_name($field_name, $post_field = 'post_content') {
|
112 |
+
return $this->option_name . '[' . $this->number . ']'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']';
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Constructs id attributes for use in form() fields
|
117 |
+
*
|
118 |
+
* This function should be used in form() methods to create id attributes for fields to be saved by update()
|
119 |
+
*
|
120 |
+
* @param string $field_name Field name
|
121 |
+
* @return string ID attribute for $field_name
|
122 |
+
*/
|
123 |
+
public function get_field_id($field_name) {
|
124 |
+
return $field_name .'_'. $this->number;
|
125 |
+
}
|
126 |
+
|
127 |
+
// Private Function. Don't worry about this.
|
128 |
+
|
129 |
+
public function _set($number) {
|
130 |
+
$this->number = $number;
|
131 |
+
$this->id = $this->id_base . '-' . $number;
|
132 |
+
}
|
133 |
+
|
134 |
+
public function prepare_new($form_id = false) {
|
135 |
+
if ( $form_id ) {
|
136 |
+
$this->form_id = $form_id;
|
137 |
+
}
|
138 |
+
|
139 |
+
$post_content = array();
|
140 |
+
$default_values = $this->get_global_defaults();
|
141 |
+
|
142 |
+
// fill default values
|
143 |
+
$post_content = wp_parse_args( $post_content, $default_values);
|
144 |
+
|
145 |
+
if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
|
146 |
+
$post_content['event'] = array( reset($this->action_options['event']) );
|
147 |
+
}
|
148 |
+
|
149 |
+
$form_action = array(
|
150 |
+
'post_title' => $this->name,
|
151 |
+
'post_content' => $post_content,
|
152 |
+
'post_excerpt' => $this->id_base,
|
153 |
+
'ID' => '',
|
154 |
+
'post_status' => 'publish',
|
155 |
+
'post_type' => FrmFormActionsController::$action_post_type,
|
156 |
+
'post_name' => $this->form_id .'_'. $this->id_base .'_'. $this->number,
|
157 |
+
'menu_order' => $this->form_id,
|
158 |
+
);
|
159 |
+
unset($post_content);
|
160 |
+
|
161 |
+
return (object) $form_action;
|
162 |
+
}
|
163 |
+
|
164 |
+
public function create($form_id) {
|
165 |
+
$this->form_id = $form_id;
|
166 |
+
|
167 |
+
$action = $this->prepare_new();
|
168 |
+
|
169 |
+
return $this->save_settings($action);
|
170 |
+
}
|
171 |
+
|
172 |
+
public function duplicate_form_actions($form_id, $old_id) {
|
173 |
+
if ( $form_id == $old_id ) {
|
174 |
+
// don't duplicate the actions if this is a template getting updated
|
175 |
+
return;
|
176 |
+
}
|
177 |
+
|
178 |
+
$this->form_id = $old_id;
|
179 |
+
$actions = $this->get_all();
|
180 |
+
|
181 |
+
$this->form_id = $form_id;
|
182 |
+
foreach ( $actions as $action ) {
|
183 |
+
$this->duplicate_one($action, $form_id);
|
184 |
+
unset($action);
|
185 |
+
}
|
186 |
+
}
|
187 |
+
|
188 |
+
/* Check if imported action should be created or updated
|
189 |
+
*
|
190 |
+
* Since 2.0
|
191 |
+
*
|
192 |
+
* @param array $action
|
193 |
+
* @return integer $post_id
|
194 |
+
*/
|
195 |
+
public function maybe_create_action( $action, $forms ) {
|
196 |
+
if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[$action['menu_order']] == 'updated' ) {
|
197 |
+
// Update action only
|
198 |
+
$action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
|
199 |
+
$post_id = $this->save_settings( $action );
|
200 |
+
} else {
|
201 |
+
// Create action
|
202 |
+
$action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
|
203 |
+
$post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
|
204 |
+
}
|
205 |
+
return $post_id;
|
206 |
+
}
|
207 |
+
|
208 |
+
public function duplicate_one($action, $form_id) {
|
209 |
+
global $frm_duplicate_ids;
|
210 |
+
|
211 |
+
$action->menu_order = $form_id;
|
212 |
+
$switch = $this->get_global_switch_fields();
|
213 |
+
foreach ( $action->post_content as $key => $val ) {
|
214 |
+
if ( is_numeric($val) && isset($frm_duplicate_ids[$val]) ) {
|
215 |
+
$action->post_content[$key] = $frm_duplicate_ids[$val];
|
216 |
+
} else if ( ! is_array( $val ) ) {
|
217 |
+
$action->post_content[$key] = FrmFieldsHelper::switch_field_ids($val);
|
218 |
+
} else if ( isset($switch[$key]) && is_array($switch[$key]) ) {
|
219 |
+
// loop through each value if empty
|
220 |
+
if ( empty($switch[$key]) ) {
|
221 |
+
$switch[$key] = array_keys($val);
|
222 |
+
}
|
223 |
+
|
224 |
+
foreach ( $switch[$key] as $subkey ) {
|
225 |
+
$action->post_content[$key] = $this->duplicate_array_walk($action->post_content[$key], $subkey, $val);
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
unset($key, $val);
|
230 |
+
}
|
231 |
+
unset($action->ID);
|
232 |
+
|
233 |
+
return $this->save_settings($action);
|
234 |
+
}
|
235 |
+
|
236 |
+
private function duplicate_array_walk($action, $subkey, $val) {
|
237 |
+
global $frm_duplicate_ids;
|
238 |
+
|
239 |
+
if ( is_array($subkey) ) {
|
240 |
+
foreach ( $subkey as $subkey2 ) {
|
241 |
+
foreach ( (array) $val as $ck => $cv ) {
|
242 |
+
if ( is_array($cv) ) {
|
243 |
+
$action[$ck] = $this->duplicate_array_walk($action[$ck], $subkey2, $cv);
|
244 |
+
} else if ( isset($cv[$subkey]) && is_numeric($cv[$subkey]) && isset($frm_duplicate_ids[$cv[$subkey]]) ) {
|
245 |
+
$action[$ck][$subkey] = $frm_duplicate_ids[$cv[$subkey]];
|
246 |
+
}
|
247 |
+
}
|
248 |
+
}
|
249 |
+
} else {
|
250 |
+
foreach ( (array) $val as $ck => $cv ) {
|
251 |
+
if ( is_array($cv) ) {
|
252 |
+
$action[$ck] = $this->duplicate_array_walk($action[$ck], $subkey, $cv);
|
253 |
+
} else if ( $ck == $subkey && isset($frm_duplicate_ids[$cv]) ) {
|
254 |
+
$action[$ck] = $frm_duplicate_ids[$cv];
|
255 |
+
}
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
return $action;
|
260 |
+
}
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Deal with changed settings.
|
264 |
+
*
|
265 |
+
* Do NOT over-ride this function
|
266 |
+
*
|
267 |
+
*/
|
268 |
+
public function update_callback( $form_id ) {
|
269 |
+
$this->form_id = $form_id;
|
270 |
+
|
271 |
+
$all_instances = $this->get_settings();
|
272 |
+
|
273 |
+
// We need to update the data
|
274 |
+
if ( $this->updated ) {
|
275 |
+
return;
|
276 |
+
}
|
277 |
+
|
278 |
+
if ( isset($_POST[$this->option_name]) && is_array($_POST[$this->option_name]) ) {
|
279 |
+
$settings = $_POST[$this->option_name];
|
280 |
+
} else {
|
281 |
+
return;
|
282 |
+
}
|
283 |
+
|
284 |
+
$action_ids = array();
|
285 |
+
|
286 |
+
foreach ( $settings as $number => $new_instance ) {
|
287 |
+
$this->_set($number);
|
288 |
+
|
289 |
+
if ( ! isset($new_instance['post_title']) ) {
|
290 |
+
// settings were never opened, so don't update
|
291 |
+
$action_ids[] = $new_instance['ID'];
|
292 |
+
$this->updated = true;
|
293 |
+
continue;
|
294 |
+
}
|
295 |
+
|
296 |
+
$old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
|
297 |
+
|
298 |
+
$new_instance['post_type'] = FrmFormActionsController::$action_post_type;
|
299 |
+
$new_instance['post_name'] = $this->form_id .'_'. $this->id_base .'_'. $this->number;
|
300 |
+
$new_instance['menu_order'] = $this->form_id;
|
301 |
+
$new_instance['post_status'] = 'publish';
|
302 |
+
$new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
|
303 |
+
|
304 |
+
$instance = $this->update( $new_instance, $old_instance );
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Filter an action's settings before saving.
|
308 |
+
*
|
309 |
+
* Returning false will effectively short-circuit the widget's ability
|
310 |
+
* to update settings.
|
311 |
+
*
|
312 |
+
* @since 2.0
|
313 |
+
*
|
314 |
+
* @param array $instance The current widget instance's settings.
|
315 |
+
* @param array $new_instance Array of new widget settings.
|
316 |
+
* @param array $old_instance Array of old widget settings.
|
317 |
+
* @param WP_Widget $this The current widget instance.
|
318 |
+
*/
|
319 |
+
$instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
|
320 |
+
|
321 |
+
$instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this);
|
322 |
+
$instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this);
|
323 |
+
|
324 |
+
if ( false !== $instance ) {
|
325 |
+
$all_instances[$number] = $instance;
|
326 |
+
}
|
327 |
+
|
328 |
+
$action_ids[] = $this->save_settings($instance);
|
329 |
+
|
330 |
+
$this->updated = true;
|
331 |
+
}
|
332 |
+
|
333 |
+
return $action_ids;
|
334 |
+
}
|
335 |
+
|
336 |
+
public function save_settings($settings) {
|
337 |
+
$settings = (array) $settings;
|
338 |
+
|
339 |
+
$settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
|
340 |
+
|
341 |
+
if ( empty($settings['ID']) ) {
|
342 |
+
unset($settings['ID']);
|
343 |
+
}
|
344 |
+
|
345 |
+
// delete all styling caches
|
346 |
+
FrmAppHelper::cache_delete_group('frm_actions');
|
347 |
+
|
348 |
+
// Remove the balanceTags filter in case WordPress is trying to validate the XHTML
|
349 |
+
remove_filter( 'content_save_pre', 'balanceTags', 50 );
|
350 |
+
|
351 |
+
return wp_insert_post($settings);
|
352 |
+
}
|
353 |
+
|
354 |
+
public function get_single_action( $id ) {
|
355 |
+
$action = get_post($id);
|
356 |
+
$action = $this->prepare_action($action);
|
357 |
+
$this->_set($id);
|
358 |
+
return $action;
|
359 |
+
}
|
360 |
+
|
361 |
+
public function get_one( $form_id ) {
|
362 |
+
return $this->get_all($form_id, 1);
|
363 |
+
}
|
364 |
+
|
365 |
+
public function get_all( $form_id = false, $limit = 99 ) {
|
366 |
+
if ( $form_id ) {
|
367 |
+
$this->form_id = $form_id;
|
368 |
+
}
|
369 |
+
|
370 |
+
$type = $this->id_base;
|
371 |
+
|
372 |
+
global $frm_vars;
|
373 |
+
$frm_vars['action_type'] = $type;
|
374 |
+
|
375 |
+
add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
|
376 |
+
$query = array(
|
377 |
+
'post_type' => FrmFormActionsController::$action_post_type,
|
378 |
+
'post_status' => 'any',
|
379 |
+
'numberposts' => 99,
|
380 |
+
'order' => 'ASC',
|
381 |
+
'suppress_filters' => false,
|
382 |
+
);
|
383 |
+
|
384 |
+
if ( $form_id != 'all' ) {
|
385 |
+
// allow actions for all forms
|
386 |
+
$query['menu_order'] = $this->form_id;
|
387 |
+
}
|
388 |
+
|
389 |
+
$actions = get_posts( $query );
|
390 |
+
unset($query);
|
391 |
+
|
392 |
+
remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
|
393 |
+
|
394 |
+
if ( empty($actions) ) {
|
395 |
+
return array();
|
396 |
+
}
|
397 |
+
|
398 |
+
$settings = array();
|
399 |
+
foreach ( $actions as $action ) {
|
400 |
+
if ( count($settings) >= $limit ) {
|
401 |
+
continue;
|
402 |
+
}
|
403 |
+
|
404 |
+
$action = $this->prepare_action($action);
|
405 |
+
|
406 |
+
$settings[$action->ID] = $action;
|
407 |
+
}
|
408 |
+
|
409 |
+
if ( 1 === $limit ) {
|
410 |
+
$settings = reset($settings);
|
411 |
+
}
|
412 |
+
|
413 |
+
return $settings;
|
414 |
+
}
|
415 |
+
|
416 |
+
public function prepare_action($action) {
|
417 |
+
$action->post_content = FrmAppHelper::maybe_json_decode($action->post_content);
|
418 |
+
|
419 |
+
$default_values = $this->get_global_defaults();
|
420 |
+
|
421 |
+
// fill default values
|
422 |
+
$action->post_content = wp_parse_args( $action->post_content, $default_values);
|
423 |
+
|
424 |
+
foreach ( $default_values as $k => $vals ) {
|
425 |
+
if ( is_array($vals) && ! empty($vals) ) {
|
426 |
+
if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty($action->post_content[$k]) ) {
|
427 |
+
continue;
|
428 |
+
}
|
429 |
+
$action->post_content[$k] = wp_parse_args($action->post_content[$k], $vals);
|
430 |
+
}
|
431 |
+
}
|
432 |
+
|
433 |
+
if ( ! is_array($action->post_content['event']) ) {
|
434 |
+
$action->post_content['event'] = explode(',', $action->post_content['event']);
|
435 |
+
}
|
436 |
+
|
437 |
+
return $action;
|
438 |
+
}
|
439 |
+
|
440 |
+
public function destroy($form_id = false, $type = 'default') {
|
441 |
+
global $wpdb;
|
442 |
+
|
443 |
+
$this->form_id = $form_id;
|
444 |
+
|
445 |
+
$query = array( 'post_type' => FrmFormActionsController::$action_post_type );
|
446 |
+
if ( $form_id ) {
|
447 |
+
$query['menu_order'] = $form_id;
|
448 |
+
}
|
449 |
+
if ( 'all' != $type ) {
|
450 |
+
$query['post_excerpt'] = $this->id_base;
|
451 |
+
}
|
452 |
+
|
453 |
+
$post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
|
454 |
+
|
455 |
+
foreach ( $post_ids as $id ) {
|
456 |
+
wp_delete_post($id);
|
457 |
+
}
|
458 |
+
}
|
459 |
+
|
460 |
+
public function get_settings() {
|
461 |
+
return FrmFormActionsHelper::get_action_for_form($this->form_id, $this->id_base);
|
462 |
+
}
|
463 |
+
|
464 |
+
public function get_global_defaults() {
|
465 |
+
$defaults = $this->get_defaults();
|
466 |
+
|
467 |
+
if ( ! isset($defaults['event']) ) {
|
468 |
+
$defaults['event'] = array( 'create');
|
469 |
+
}
|
470 |
+
|
471 |
+
if ( ! isset($defaults['conditions']) ) {
|
472 |
+
$defaults['conditions'] = array(
|
473 |
+
'send_stop' => '',
|
474 |
+
'any_all' => '',
|
475 |
+
);
|
476 |
+
}
|
477 |
+
|
478 |
+
return $defaults;
|
479 |
+
}
|
480 |
+
|
481 |
+
public function get_global_switch_fields() {
|
482 |
+
$switch = $this->get_switch_fields();
|
483 |
+
$switch['conditions'] = array( 'hide_field');
|
484 |
+
return $switch;
|
485 |
+
}
|
486 |
+
|
487 |
+
/**
|
488 |
+
* Migrate settings from form->options into new action.
|
489 |
+
*/
|
490 |
+
public function migrate_to_2($form, $update = 'update') {
|
491 |
+
$action = $this->prepare_new($form->id);
|
492 |
+
$form->options = maybe_unserialize($form->options);
|
493 |
+
|
494 |
+
// fill with existing options
|
495 |
+
foreach ( $action->post_content as $name => $val ) {
|
496 |
+
if ( isset($form->options[$name]) ) {
|
497 |
+
$action->post_content[$name] = $form->options[$name];
|
498 |
+
unset($form->options[$name]);
|
499 |
+
}
|
500 |
+
}
|
501 |
+
|
502 |
+
$action = $this->migrate_values($action, $form);
|
503 |
+
|
504 |
+
// check if action already exists
|
505 |
+
$post_id = get_posts( array(
|
506 |
+
'name' => $action->post_name,
|
507 |
+
'post_type' => FrmFormActionsController::$action_post_type,
|
508 |
+
'post_status' => $action->post_status,
|
509 |
+
'numberposts' => 1,
|
510 |
+
) );
|
511 |
+
|
512 |
+
if ( empty($post_id) ) {
|
513 |
+
// create action now
|
514 |
+
$post_id = $this->save_settings($action);
|
515 |
+
}
|
516 |
+
|
517 |
+
if ( $post_id && 'update' == $update ) {
|
518 |
+
global $wpdb;
|
519 |
+
$form->options = maybe_serialize($form->options);
|
520 |
+
|
521 |
+
// update form options
|
522 |
+
$wpdb->update($wpdb->prefix .'frm_forms', array( 'options' => $form->options), array( 'id' => $form->id));
|
523 |
+
wp_cache_delete( $form->id, 'frm_form');
|
524 |
+
}
|
525 |
+
|
526 |
+
return $post_id;
|
527 |
+
}
|
528 |
+
|
529 |
+
}
|
classes/models/FrmNotification.php
CHANGED
@@ -1,115 +1,367 @@
|
|
1 |
<?php
|
2 |
-
if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
|
3 |
|
4 |
class FrmNotification{
|
5 |
-
function __construct(){
|
6 |
-
|
|
|
|
|
|
|
7 |
}
|
8 |
-
|
9 |
-
function
|
10 |
-
if (
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
$
|
15 |
-
|
16 |
-
$
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
if
|
40 |
-
$
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
$
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
$mail_body = FrmEntriesHelper::replace_default_message($mail_body, array(
|
60 |
'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text,
|
61 |
'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false),
|
62 |
) );
|
63 |
-
|
64 |
-
//
|
65 |
-
|
66 |
-
|
67 |
-
$
|
68 |
-
$
|
|
|
|
|
69 |
}
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
74 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
}
|
76 |
-
|
77 |
-
function
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
$header = array();
|
88 |
-
$header[] = 'From:
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
$header[] = 'Content-Type: '. $content_type .'; charset="'. $charset . '"';
|
91 |
-
$subject
|
92 |
-
|
93 |
-
$message = do_shortcode($message);
|
94 |
-
|
95 |
-
if($plain_text)
|
|
|
96 |
$message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES );
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
$header = apply_filters('frm_email_header', $header,
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
102 |
}
|
103 |
-
|
104 |
remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' );
|
105 |
remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter');
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
110 |
}
|
111 |
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
}
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
}
|
1 |
<?php
|
|
|
2 |
|
3 |
class FrmNotification{
|
4 |
+
public function __construct(){
|
5 |
+
if ( ! defined('ABSPATH') ) {
|
6 |
+
die('You are not allowed to call this page directly.');
|
7 |
+
}
|
8 |
+
add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3);
|
9 |
}
|
10 |
+
|
11 |
+
public static function trigger_email($action, $entry, $form) {
|
12 |
+
if ( defined('WP_IMPORTING') ) {
|
13 |
+
return;
|
14 |
+
}
|
15 |
+
|
16 |
+
global $wpdb;
|
17 |
+
|
18 |
+
$notification = $action->post_content;
|
19 |
+
$email_key = $action->ID;
|
20 |
+
|
21 |
+
// Set the subject
|
22 |
+
if ( empty($notification['email_subject']) ) {
|
23 |
+
$notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]');
|
24 |
+
}
|
25 |
+
|
26 |
+
$plain_text = $notification['plain_text'] ? true : false;
|
27 |
+
|
28 |
+
//Filter these fields
|
29 |
+
$filter_fields = array(
|
30 |
+
'email_to', 'cc', 'bcc',
|
31 |
+
'reply_to', 'from',
|
32 |
+
'email_subject', 'email_message',
|
33 |
+
);
|
34 |
+
|
35 |
+
add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false'));
|
36 |
+
|
37 |
+
//Get all values in entry in order to get User ID field ID
|
38 |
+
$values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' );
|
39 |
+
$user_id_field = $user_id_key = '';
|
40 |
+
foreach ( $values as $value ) {
|
41 |
+
if ( $value->field_type == 'user_id' ) {
|
42 |
+
$user_id_field = $value->field_id;
|
43 |
+
$user_id_key = $value->field_key;
|
44 |
+
break;
|
45 |
+
}
|
46 |
+
unset($value);
|
47 |
+
}
|
48 |
+
|
49 |
+
//Filter and prepare the email fields
|
50 |
+
foreach ( $filter_fields as $f ) {
|
51 |
+
//Don't allow empty From
|
52 |
+
if ( $f == 'from' && empty($notification[$f]) ) {
|
53 |
+
$notification[$f] = '[admin_email]';
|
54 |
+
} else if ( in_array($f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from')) ) {
|
55 |
+
//Remove brackets
|
56 |
+
//Add a space in case there isn't one
|
57 |
+
$notification[$f] = str_replace('<', ' ', $notification[$f]);
|
58 |
+
$notification[$f] = str_replace( array( '"', '>'), '', $notification[$f]);
|
59 |
+
|
60 |
+
//Switch userID shortcode to email address
|
61 |
+
if ( strpos($notification[$f], '[' . $user_id_field . ']' ) !== false || strpos($notification[$f], '[' . $user_id_key . ']' ) !== false ) {
|
62 |
+
$user_data = get_userdata($entry->metas[$user_id_field]);
|
63 |
+
$user_email = $user_data->user_email;
|
64 |
+
$notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] );
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
$notification[$f] = FrmFieldsHelper::basic_replace_shortcodes($notification[$f], $form, $entry);
|
69 |
+
}
|
70 |
+
|
71 |
+
//Put recipients, cc, and bcc into an array if they aren't empty
|
72 |
+
$to_emails = ( ! empty( $notification['email_to'] ) ? preg_split( '/(,|;)/', $notification['email_to'] ) : '' );
|
73 |
+
$cc = ( ! empty( $notification['cc'] ) ? preg_split( '/(,|;)/', $notification['cc'] ) : '' );
|
74 |
+
$bcc = ( ! empty( $notification['bcc'] ) ? preg_split( '/(,|;)/', $notification['bcc'] ) : '' );
|
75 |
+
|
76 |
+
$to_emails = apply_filters('frm_to_email', $to_emails, array(), $form->id, compact('email_key', 'entry', 'form'));
|
77 |
+
|
78 |
+
// Stop now if there aren't any recipients
|
79 |
+
if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) {
|
80 |
+
return;
|
81 |
+
}
|
82 |
+
|
83 |
+
$to_emails = array_unique( (array) $to_emails );
|
84 |
+
|
85 |
+
$prev_mail_body = $mail_body = $notification['email_message'];
|
86 |
$mail_body = FrmEntriesHelper::replace_default_message($mail_body, array(
|
87 |
'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text,
|
88 |
'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false),
|
89 |
) );
|
90 |
+
|
91 |
+
// Add the user info if it isn't already included
|
92 |
+
if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) {
|
93 |
+
$data = maybe_unserialize($entry->description);
|
94 |
+
$mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) ."\r\n";
|
95 |
+
$mail_body .= __( 'IP Address', 'formidable' ) . ': '. $entry->ip ."\r\n";
|
96 |
+
$mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': '. FrmEntriesHelper::get_browser($data['browser']) ."\r\n";
|
97 |
+
$mail_body .= __( 'Referrer', 'formidable' ) . ': '. $data['referrer']."\r\n";
|
98 |
}
|
99 |
+
unset($prev_mail_body);
|
100 |
+
|
101 |
+
// Add attachments
|
102 |
+
$attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') );
|
103 |
+
|
104 |
+
if ( ! empty($notification['email_subject']) ) {
|
105 |
+
$notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key'));
|
106 |
}
|
107 |
+
|
108 |
+
// check for a phone number
|
109 |
+
foreach ( (array) $to_emails as $email_key => $e ) {
|
110 |
+
$e = trim($e);
|
111 |
+
if ( $e != '[admin_email]' && ! is_email($e) ) {
|
112 |
+
$e = explode(' ', $e);
|
113 |
+
|
114 |
+
//If to_email has name <test@mail.com> format
|
115 |
+
if ( is_email(end($e)) ) {
|
116 |
+
continue;
|
117 |
+
}
|
118 |
+
|
119 |
+
do_action('frm_send_to_not_email', array(
|
120 |
+
'e' => $e,
|
121 |
+
'subject' => $notification['email_subject'],
|
122 |
+
'mail_body' => $mail_body,
|
123 |
+
'reply_to' => $notification['reply_to'],
|
124 |
+
'from' => $notification['from'],
|
125 |
+
'plain_text' => $plain_text,
|
126 |
+
'attachments' => $attachments,
|
127 |
+
'form' => $form,
|
128 |
+
'email_key' => $email_key,
|
129 |
+
) );
|
130 |
+
|
131 |
+
unset($to_emails[$email_key]);
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
// Send the email now
|
136 |
+
$sent_to = self::send_email( array(
|
137 |
+
'to_email' => $to_emails,
|
138 |
+
'subject' => $notification['email_subject'],
|
139 |
+
'message' => $mail_body,
|
140 |
+
'from' => $notification['from'],
|
141 |
+
'plain_text' => $plain_text,
|
142 |
+
'reply_to' => $notification['reply_to'],
|
143 |
+
'attachments' => $attachments,
|
144 |
+
'cc' => $cc,
|
145 |
+
'bcc' => $bcc,
|
146 |
+
) );
|
147 |
+
|
148 |
+
return $sent_to;
|
149 |
}
|
150 |
+
|
151 |
+
public function entry_created($entry_id, $form_id) {
|
152 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmFormActionsController::trigger_actions("create", '. $form_id .', '. $entry_id .', "email")');
|
153 |
+
FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email');
|
154 |
+
}
|
155 |
+
|
156 |
+
public function send_notification_email($to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '') {
|
157 |
+
_deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' );
|
158 |
+
|
159 |
+
return self::send_email(compact(
|
160 |
+
'to_email', 'subject', 'message',
|
161 |
+
'from', 'from_name', 'plain_text',
|
162 |
+
'attachments', 'reply_to'
|
163 |
+
));
|
164 |
+
}
|
165 |
+
|
166 |
+
/**
|
167 |
+
* Put To, BCC, CC, Reply To, and From fields in Name <test@mail.com> format
|
168 |
+
* Formats that should work: Name, "Name", test@mail.com, <test@mail.com>, Name <test@mail.com>,
|
169 |
+
* "Name" <test@mail.com>, Name test@mail.com, "Name" test@mail.com, Name<test@mail.com>, "Name"<test@mail.com>
|
170 |
+
* "First Last" <test@mail.com>
|
171 |
+
*
|
172 |
+
* Things that won't work: First Last (with no email entered)
|
173 |
+
* @since 2.0
|
174 |
+
* @param array $atts array of email fields, pass by reference
|
175 |
+
* @param $admin_email
|
176 |
+
*/
|
177 |
+
private static function format_email_fields( &$atts, $admin_email ) {
|
178 |
+
|
179 |
+
// If from is empty or is set to admin_email, set it now
|
180 |
+
$atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from'];
|
181 |
+
|
182 |
+
// Filter values in these fields
|
183 |
+
$filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' );
|
184 |
+
|
185 |
+
foreach ( $filter_fields as $f ) {
|
186 |
+
// If empty, just skip it
|
187 |
+
if ( empty($atts[$f]) ) {
|
188 |
+
continue;
|
189 |
+
}
|
190 |
+
|
191 |
+
// to_email, cc, and bcc can be an array
|
192 |
+
if ( is_array($atts[$f]) ) {
|
193 |
+
foreach ( $atts[$f] as $key => $val ) {
|
194 |
+
self::format_single_field( $atts, $f, $val, $key );
|
195 |
+
unset( $key, $val );
|
196 |
+
}
|
197 |
+
unset($f);
|
198 |
+
continue;
|
199 |
+
}
|
200 |
+
|
201 |
+
self::format_single_field( $atts, $f, $atts[$f] );
|
202 |
+
}
|
203 |
+
|
204 |
+
// If reply-to isn't set, make it match the from settings
|
205 |
+
if ( empty( $atts['reply_to'] ) ) {
|
206 |
+
$atts['reply_to'] = $atts['from'];
|
207 |
+
}
|
208 |
+
|
209 |
+
if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) {
|
210 |
+
$atts['to_email'] = $admin_email;
|
211 |
+
}
|
212 |
+
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Format individual email fields
|
216 |
+
*
|
217 |
+
* @since 2.0
|
218 |
+
* @param array $atts pass by reference
|
219 |
+
* @param string $f (to, from, reply_to, etc)
|
220 |
+
* @param string $val value saved in field
|
221 |
+
* @param int $key if in array, this will be set
|
222 |
+
*/
|
223 |
+
private static function format_single_field( &$atts, $f, $val, $key = false ) {
|
224 |
+
$val = trim($val);
|
225 |
+
|
226 |
+
// If just a plain email is used
|
227 |
+
if ( is_email($val) ) {
|
228 |
+
// add sender's name if not included in $from
|
229 |
+
if ( $f == 'from' ) {
|
230 |
+
$part_2 = $atts[$f];
|
231 |
+
$part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
|
232 |
+
} else {
|
233 |
+
return;
|
234 |
+
}
|
235 |
+
} else {
|
236 |
+
$parts = explode(' ', $val);
|
237 |
+
$part_2 = end($parts);
|
238 |
+
|
239 |
+
// If inputted correcly, $part_2 should be an email
|
240 |
+
if ( is_email( $part_2 ) ) {
|
241 |
+
$part_1 = trim( str_replace( $part_2, '', $val ) );
|
242 |
+
} else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) {
|
243 |
+
// In case someone just puts a name in the From or Reply To field
|
244 |
+
$part_1 = $part_2;
|
245 |
+
$part_2 = get_option('admin_email');
|
246 |
+
} else {
|
247 |
+
// In case someone just puts a name in any other email field
|
248 |
+
if ( false !== $key ) {
|
249 |
+
unset( $atts[$f][$key] );
|
250 |
+
return;
|
251 |
+
}
|
252 |
+
$atts[$f] = '';
|
253 |
+
return;
|
254 |
+
}
|
255 |
+
}
|
256 |
+
|
257 |
+
// Set up formatted value
|
258 |
+
$final_val = '"'. str_replace( '"', '', $part_1 ) . '" <'. $part_2 .'>';
|
259 |
+
|
260 |
+
// If value is an array
|
261 |
+
if ( false !== $key ) {
|
262 |
+
$atts[$f][$key] = $final_val;
|
263 |
+
return;
|
264 |
+
}
|
265 |
+
$atts[$f] = $final_val;
|
266 |
+
}
|
267 |
+
|
268 |
+
public static function send_email($atts) {
|
269 |
+
$admin_email = get_option('admin_email');
|
270 |
+
$defaults = array(
|
271 |
+
'to_email' => $admin_email,
|
272 |
+
'subject' => '',
|
273 |
+
'message' => '',
|
274 |
+
'from' => $admin_email,
|
275 |
+
'from_name' => '',
|
276 |
+
'cc' => '',
|
277 |
+
'bcc' => '',
|
278 |
+
'plain_text' => true,
|
279 |
+
'reply_to' => $admin_email,
|
280 |
+
'attachments' => array(),
|
281 |
+
);
|
282 |
+
$atts = wp_parse_args($atts, $defaults);
|
283 |
+
|
284 |
+
// Put To, BCC, CC, Reply To, and From fields in the correct format
|
285 |
+
self::format_email_fields( $atts, $admin_email );
|
286 |
+
|
287 |
+
$recipient = $atts['to_email']; //recipient
|
288 |
$header = array();
|
289 |
+
$header[] = 'From: ' . $atts['from'];
|
290 |
+
|
291 |
+
//Allow for cc and bcc arrays
|
292 |
+
$array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc']);
|
293 |
+
foreach ( $array_fields as $key => $a_field ) {
|
294 |
+
if ( empty($a_field) ) {
|
295 |
+
continue;
|
296 |
+
}
|
297 |
+
if ( is_array($a_field ) ) {
|
298 |
+
foreach ( $a_field as $email ) {
|
299 |
+
$header[] = $key . ': ' . $email;
|
300 |
+
}
|
301 |
+
} else {
|
302 |
+
$header[] = $key . ': ' . $a_field;
|
303 |
+
}
|
304 |
+
unset($key, $a_field);
|
305 |
+
}
|
306 |
+
|
307 |
+
$content_type = $atts['plain_text'] ? 'text/plain' : 'text/html';
|
308 |
+
$charset = get_option('blog_charset');
|
309 |
+
|
310 |
+
$header[] = 'Reply-To: '. $atts['reply_to'];
|
311 |
$header[] = 'Content-Type: '. $content_type .'; charset="'. $charset . '"';
|
312 |
+
$atts['subject'] = wp_specialchars_decode(strip_tags(stripslashes($atts['subject'])), ENT_QUOTES );
|
313 |
+
|
314 |
+
$message = do_shortcode($atts['message']);
|
315 |
+
|
316 |
+
if ( $atts['plain_text'] ) {
|
317 |
+
//$message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars
|
318 |
$message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES );
|
319 |
+
} else {
|
320 |
+
// remove line breaks in HTML emails to prevent conflicts with Mandrill
|
321 |
+
add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' );
|
322 |
+
}
|
323 |
|
324 |
+
$header = apply_filters('frm_email_header', $header, array(
|
325 |
+
'to_email' => $atts['to_email'], 'subject' => $atts['subject'],
|
326 |
+
) );
|
327 |
+
|
328 |
+
if ( apply_filters('frm_encode_subject', 1, $atts['subject'] ) ) {
|
329 |
+
$atts['subject'] = '=?'. $charset .'?B?'. base64_encode($atts['subject']) .'?=';
|
330 |
}
|
331 |
+
|
332 |
remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' );
|
333 |
remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter');
|
334 |
+
|
335 |
+
$sent = wp_mail($recipient, $atts['subject'], $message, $header, $atts['attachments']);
|
336 |
+
if ( ! $sent ) {
|
337 |
+
$header = 'From: '. $atts['from'] ."\r\n";
|
338 |
+
$recipient = implode(',', (array) $recipient);
|
339 |
+
$sent = mail($recipient, $atts['subject'], $message, $header);
|
340 |
}
|
341 |
|
342 |
+
// remove the filter now so other emails can still use it
|
343 |
+
remove_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' );
|
344 |
+
|
345 |
+
do_action('frm_notification', $recipient, $atts['subject'], $message);
|
346 |
+
|
347 |
+
if ( $sent ) {
|
348 |
+
$sent_to = array_merge( (array)$atts['to_email'], (array) $atts['cc'], (array) $atts['bcc']);
|
349 |
+
$sent_to = array_filter( $sent_to );
|
350 |
+
if ( apply_filters('frm_echo_emails', false) ) {
|
351 |
+
$temp = str_replace('<', '<', $sent_to);
|
352 |
+
echo implode(', ', (array) $temp);
|
353 |
+
}
|
354 |
+
return $sent_to;
|
355 |
+
}
|
356 |
}
|
357 |
|
358 |
+
/**
|
359 |
+
* This function should only be fired when Mandrill is sending an HTML email
|
360 |
+
* This will make sure Mandrill doesn't mess with our HTML emails
|
361 |
+
*
|
362 |
+
* @since 2.0
|
363 |
+
*/
|
364 |
+
public static function remove_mandrill_br() {
|
365 |
+
return false;
|
366 |
+
}
|
367 |
}
|
classes/models/FrmSettings.php
CHANGED
@@ -1,158 +1,250 @@
|
|
1 |
<?php
|
2 |
-
if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
|
3 |
-
|
4 |
-
if(class_exists('FrmSettings'))
|
5 |
-
return;
|
6 |
|
7 |
class FrmSettings{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
function __construct(){
|
10 |
$this->set_default_options();
|
11 |
}
|
12 |
-
|
13 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
return array(
|
15 |
'menu' => 'Formidable',
|
16 |
'mu_menu' => 0,
|
17 |
'preview_page_id' => 0,
|
18 |
'lock_keys' => false,
|
19 |
-
'track' => false,
|
20 |
'use_html' => true,
|
21 |
'jquery_css' => false,
|
22 |
'accordion_js' => false,
|
23 |
-
|
24 |
-
'success_msg' => __('Your responses were successfully submitted. Thank you!', 'formidable'),
|
25 |
-
'blank_msg' => __('This field cannot be blank.', 'formidable'),
|
26 |
-
'unique_msg' => __('This value must be unique.', 'formidable'),
|
27 |
-
'invalid_msg' => __('There was a problem with your submission. Errors are marked below.', 'formidable'),
|
28 |
-
'failed_msg' => __('We\'re sorry. It looks like you\'ve already submitted that.', 'formidable'),
|
29 |
-
'submit_value' => __('Submit', 'formidable'),
|
30 |
-
'login_msg' => __('You do not have permission to view this form.', 'formidable'),
|
31 |
-
'admin_permission' => __('You do not have permission to do that', 'formidable'),
|
32 |
-
|
33 |
'email_to' => '[admin_email]',
|
34 |
);
|
35 |
}
|
36 |
|
37 |
-
function set_default_options(){
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
}
|
43 |
-
|
44 |
-
if(!isset($this->privkey))
|
45 |
-
$this->privkey = (isset($recaptcha_opt) and isset($recaptcha_opt['privkey'])) ? $recaptcha_opt['privkey'] : '';
|
46 |
-
|
47 |
-
if(!isset($this->re_theme))
|
48 |
-
$this->re_theme = (isset($recaptcha_opt) and isset($recaptcha_opt['re_theme'])) ? $recaptcha_opt['re_theme'] : 'red';
|
49 |
-
|
50 |
-
if(!isset($this->re_lang))
|
51 |
-
$this->re_lang = (isset($recaptcha_opt) and isset($recaptcha_opt['re_lang'])) ? $recaptcha_opt['re_lang'] : 'en';
|
52 |
-
|
53 |
-
if(!isset($this->re_msg) or empty($this->re_msg))
|
54 |
-
$this->re_msg = __('The reCAPTCHA was not entered correctly', 'formidable');
|
55 |
-
|
56 |
-
if(!isset($this->load_style)){
|
57 |
-
if(!isset($this->custom_style))
|
58 |
$this->custom_style = true;
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
$this->load_style = ($this->custom_stylesheet) ? 'none' : 'all';
|
63 |
-
}
|
64 |
-
|
65 |
-
$settings = $this->default_options();
|
66 |
-
|
67 |
-
foreach($settings as $setting => $default){
|
68 |
-
if(!isset($this->{$setting}))
|
69 |
-
$this->{$setting} = $default;
|
70 |
-
unset($setting);
|
71 |
-
unset($default);
|
72 |
}
|
73 |
-
|
74 |
-
|
|
|
|
|
75 |
$mu_menu = get_site_option('frm_admin_menu_name');
|
76 |
-
if($mu_menu
|
77 |
$this->menu = $mu_menu;
|
78 |
$this->mu_menu = 1;
|
79 |
}
|
80 |
}
|
81 |
-
|
82 |
$frm_roles = FrmAppHelper::frm_capabilities('pro');
|
83 |
-
foreach($frm_roles as $frm_role => $frm_role_description){
|
84 |
-
if(!isset($this->$frm_role))
|
85 |
$this->$frm_role = 'administrator';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
}
|
87 |
}
|
88 |
|
89 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
$errors = apply_filters( 'frm_validate_settings', $errors, $params );
|
91 |
return $errors;
|
92 |
}
|
93 |
|
94 |
-
function update($params){
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
if ( $this->mu_menu ) {
|
99 |
update_site_option('frm_admin_menu_name', $this->menu);
|
100 |
} else if ( current_user_can('administrator') ) {
|
101 |
update_site_option('frm_admin_menu_name', false);
|
102 |
}
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
$this->pubkey = trim($params['frm_pubkey']);
|
105 |
$this->privkey = $params['frm_privkey'];
|
106 |
-
$this->re_theme = $params['frm_re_theme'];
|
107 |
$this->re_lang = $params['frm_re_lang'];
|
108 |
-
|
109 |
-
$settings = $this->default_options();
|
110 |
-
|
111 |
-
foreach($settings as $setting => $default){
|
112 |
-
if(isset($params['frm_'. $setting]))
|
113 |
-
$this->{$setting} = $params['frm_'. $setting];
|
114 |
-
|
115 |
-
unset($setting);
|
116 |
-
unset($default);
|
117 |
-
}
|
118 |
-
|
119 |
$this->load_style = $params['frm_load_style'];
|
120 |
-
$this->preview_page_id = (int)$params['frm-preview-page-id'];
|
121 |
$this->lock_keys = isset($params['frm_lock_keys']) ? $params['frm_lock_keys'] : 0;
|
122 |
-
|
123 |
-
|
124 |
$this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
|
125 |
//$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0;
|
126 |
-
//$this->custom_stylesheet = isset($params['frm_custom_stylesheet']) ? $params['frm_custom_stylesheet'] : 0;
|
127 |
$this->jquery_css = isset($params['frm_jquery_css']) ? $params['frm_jquery_css'] : 0;
|
128 |
$this->accordion_js = isset($params['frm_accordion_js']) ? $params['frm_accordion_js'] : 0;
|
129 |
-
|
|
|
|
|
130 |
//update roles
|
|
|
|
|
131 |
$frm_roles = FrmAppHelper::frm_capabilities();
|
132 |
$roles = get_editable_roles();
|
133 |
-
foreach($frm_roles as $frm_role => $frm_role_description){
|
134 |
-
$this->$frm_role = isset($params[$frm_role]) ? $params[$frm_role] : 'administrator';
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
$wp_roles->remove_cap( $role, $frm_role );
|
141 |
-
|
|
|
|
|
142 |
}
|
143 |
-
|
144 |
-
do_action( 'frm_update_settings', $params );
|
145 |
}
|
146 |
|
147 |
-
function store(){
|
148 |
// Save the posted value in the database
|
149 |
|
150 |
update_option('frm_options', $this);
|
151 |
-
|
152 |
delete_transient('frm_options');
|
153 |
set_transient('frm_options', $this);
|
154 |
|
155 |
do_action( 'frm_store_settings' );
|
156 |
}
|
157 |
-
|
158 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
|
3 |
class FrmSettings{
|
4 |
+
public $option_name = 'frm_options';
|
5 |
+
public $menu;
|
6 |
+
public $mu_menu;
|
7 |
+
public $preview_page_id;
|
8 |
+
public $lock_keys;
|
9 |
+
public $use_html;
|
10 |
+
public $jquery_css;
|
11 |
+
public $accordion_js;
|
12 |
+
|
13 |
+
public $success_msg;
|
14 |
+
public $blank_msg;
|
15 |
+
public $unique_msg;
|
16 |
+
public $invalid_msg;
|
17 |
+
public $failed_msg;
|
18 |
+
public $submit_value;
|
19 |
+
public $login_msg;
|
20 |
+
public $admin_permission;
|
21 |
+
|
22 |
+
public $email_to;
|
23 |
+
public $load_style;
|
24 |
+
public $custom_style;
|
25 |
+
|
26 |
+
public $pubkey;
|
27 |
+
public $privkey;
|
28 |
+
public $re_lang;
|
29 |
+
public $re_msg;
|
30 |
+
|
31 |
+
public function __construct() {
|
32 |
+
if ( ! defined('ABSPATH') ) {
|
33 |
+
die('You are not allowed to call this page directly.');
|
34 |
+
}
|
35 |
+
|
36 |
+
$settings = get_transient($this->option_name);
|
37 |
+
|
38 |
+
if ( ! is_object($settings) ) {
|
39 |
+
$settings = $this->translate_settings($settings);
|
40 |
+
}
|
41 |
+
|
42 |
+
foreach ( $settings as $setting_name => $setting ) {
|
43 |
+
$this->{$setting_name} = $setting;
|
44 |
+
unset($setting_name, $setting);
|
45 |
+
}
|
46 |
|
|
|
47 |
$this->set_default_options();
|
48 |
}
|
49 |
+
|
50 |
+
private function translate_settings($settings) {
|
51 |
+
if ( $settings ) { //workaround for W3 total cache conflict
|
52 |
+
return unserialize(serialize($settings));
|
53 |
+
}
|
54 |
+
|
55 |
+
$settings = get_option($this->option_name);
|
56 |
+
if ( is_object($settings) ) {
|
57 |
+
set_transient($this->option_name, $settings);
|
58 |
+
return $settings;
|
59 |
+
}
|
60 |
+
|
61 |
+
// If unserializing didn't work
|
62 |
+
if ( $settings ) { //workaround for W3 total cache conflict
|
63 |
+
$settings = unserialize(serialize($settings));
|
64 |
+
} else {
|
65 |
+
$settings = $this;
|
66 |
+
}
|
67 |
+
|
68 |
+
update_option($this->option_name, $settings);
|
69 |
+
set_transient($this->option_name, $settings);
|
70 |
+
|
71 |
+
return $settings;
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* @return array
|
76 |
+
*/
|
77 |
+
public function default_options(){
|
78 |
return array(
|
79 |
'menu' => 'Formidable',
|
80 |
'mu_menu' => 0,
|
81 |
'preview_page_id' => 0,
|
82 |
'lock_keys' => false,
|
|
|
83 |
'use_html' => true,
|
84 |
'jquery_css' => false,
|
85 |
'accordion_js' => false,
|
86 |
+
|
87 |
+
'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
|
88 |
+
'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
|
89 |
+
'unique_msg' => __( 'This value must be unique.', 'formidable' ),
|
90 |
+
'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
|
91 |
+
'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
|
92 |
+
'submit_value' => __( 'Submit', 'formidable' ),
|
93 |
+
'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
|
94 |
+
'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
|
95 |
+
|
96 |
'email_to' => '[admin_email]',
|
97 |
);
|
98 |
}
|
99 |
|
100 |
+
private function set_default_options(){
|
101 |
+
$this->fill_recaptcha_settings();
|
102 |
+
|
103 |
+
if ( ! isset($this->load_style) ) {
|
104 |
+
if ( ! isset($this->custom_style) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
$this->custom_style = true;
|
106 |
+
}
|
107 |
+
|
108 |
+
$this->load_style = 'all';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
+
|
111 |
+
$this->fill_with_defaults();
|
112 |
+
|
113 |
+
if ( is_multisite() && is_admin() ) {
|
114 |
$mu_menu = get_site_option('frm_admin_menu_name');
|
115 |
+
if ( $mu_menu && ! empty($mu_menu) ) {
|
116 |
$this->menu = $mu_menu;
|
117 |
$this->mu_menu = 1;
|
118 |
}
|
119 |
}
|
120 |
+
|
121 |
$frm_roles = FrmAppHelper::frm_capabilities('pro');
|
122 |
+
foreach ( $frm_roles as $frm_role => $frm_role_description ) {
|
123 |
+
if ( ! isset($this->$frm_role) ) {
|
124 |
$this->$frm_role = 'administrator';
|
125 |
+
}
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
public function fill_with_defaults($params = array()) {
|
130 |
+
$settings = $this->default_options();
|
131 |
+
|
132 |
+
foreach ( $settings as $setting => $default ) {
|
133 |
+
if ( isset($params['frm_'. $setting]) ) {
|
134 |
+
$this->{$setting} = $params['frm_'. $setting];
|
135 |
+
} else if ( ! isset($this->{$setting}) ) {
|
136 |
+
$this->{$setting} = $default;
|
137 |
+
}
|
138 |
+
unset($setting, $default);
|
139 |
}
|
140 |
}
|
141 |
|
142 |
+
private function fill_recaptcha_settings() {
|
143 |
+
$privkey = '';
|
144 |
+
$re_lang = 'en';
|
145 |
+
|
146 |
+
if ( ! isset($this->pubkey) ) {
|
147 |
+
// get the options from the database
|
148 |
+
$recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha');
|
149 |
+
$this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : '';
|
150 |
+
$privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey;
|
151 |
+
$re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang;
|
152 |
+
}
|
153 |
+
|
154 |
+
if ( ! isset($this->re_msg) || empty($this->re_msg) ) {
|
155 |
+
$this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
|
156 |
+
}
|
157 |
+
|
158 |
+
if ( ! isset($this->privkey) ) {
|
159 |
+
$this->privkey = $privkey;
|
160 |
+
}
|
161 |
+
|
162 |
+
if ( ! isset($this->re_lang) ) {
|
163 |
+
$this->re_lang = $re_lang;
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
public function validate( $params, $errors ) {
|
168 |
$errors = apply_filters( 'frm_validate_settings', $errors, $params );
|
169 |
return $errors;
|
170 |
}
|
171 |
|
172 |
+
public function update($params){
|
173 |
+
$this->fill_with_defaults($params);
|
174 |
+
$this->update_settings($params);
|
175 |
+
|
176 |
if ( $this->mu_menu ) {
|
177 |
update_site_option('frm_admin_menu_name', $this->menu);
|
178 |
} else if ( current_user_can('administrator') ) {
|
179 |
update_site_option('frm_admin_menu_name', false);
|
180 |
}
|
181 |
+
|
182 |
+
$this->update_roles($params);
|
183 |
+
|
184 |
+
do_action( 'frm_update_settings', $params );
|
185 |
+
}
|
186 |
+
|
187 |
+
private function update_settings($params) {
|
188 |
+
$this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0;
|
189 |
+
|
190 |
$this->pubkey = trim($params['frm_pubkey']);
|
191 |
$this->privkey = $params['frm_privkey'];
|
|
|
192 |
$this->re_lang = $params['frm_re_lang'];
|
193 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
$this->load_style = $params['frm_load_style'];
|
195 |
+
$this->preview_page_id = (int) $params['frm-preview-page-id'];
|
196 |
$this->lock_keys = isset($params['frm_lock_keys']) ? $params['frm_lock_keys'] : 0;
|
197 |
+
|
|
|
198 |
$this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
|
199 |
//$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0;
|
|
|
200 |
$this->jquery_css = isset($params['frm_jquery_css']) ? $params['frm_jquery_css'] : 0;
|
201 |
$this->accordion_js = isset($params['frm_accordion_js']) ? $params['frm_accordion_js'] : 0;
|
202 |
+
}
|
203 |
+
|
204 |
+
private function update_roles($params) {
|
205 |
//update roles
|
206 |
+
global $wp_roles;
|
207 |
+
|
208 |
$frm_roles = FrmAppHelper::frm_capabilities();
|
209 |
$roles = get_editable_roles();
|
210 |
+
foreach ( $frm_roles as $frm_role => $frm_role_description ) {
|
211 |
+
$this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
|
212 |
+
|
213 |
+
if ( count($this->$frm_role) === 1 ) {
|
214 |
+
$set_role = reset($this->$frm_role);
|
215 |
+
switch ( $set_role ) {
|
216 |
+
case 'subscriber':
|
217 |
+
array_push($this->$frm_role, 'contributor');
|
218 |
+
case 'contributor':
|
219 |
+
array_push($this->$frm_role, 'author');
|
220 |
+
case 'author':
|
221 |
+
array_push($this->$frm_role, 'editor');
|
222 |
+
case 'editor':
|
223 |
+
array_push($this->$frm_role, 'administrator');
|
224 |
+
}
|
225 |
+
unset($set_role);
|
226 |
+
}
|
227 |
+
|
228 |
+
foreach ( $roles as $role => $details ) {
|
229 |
+
if ( in_array($role, $this->$frm_role) ) {
|
230 |
+
$wp_roles->add_cap( $role, $frm_role );
|
231 |
+
} else {
|
232 |
$wp_roles->remove_cap( $role, $frm_role );
|
233 |
+
}
|
234 |
+
unset($role, $details);
|
235 |
+
}
|
236 |
}
|
|
|
|
|
237 |
}
|
238 |
|
239 |
+
public function store(){
|
240 |
// Save the posted value in the database
|
241 |
|
242 |
update_option('frm_options', $this);
|
243 |
+
|
244 |
delete_transient('frm_options');
|
245 |
set_transient('frm_options', $this);
|
246 |
|
247 |
do_action( 'frm_store_settings' );
|
248 |
}
|
249 |
+
|
250 |
}
|
classes/models/FrmStyle.php
ADDED
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class FrmStyle{
|
3 |
+
public $number = false; // Unique ID number of the current instance.
|
4 |
+
public $id = 0; // the id of the post
|
5 |
+
|
6 |
+
/**
|
7 |
+
* @param int|string $id The id of the stylsheet or 'default'
|
8 |
+
*/
|
9 |
+
public function __construct( $id = 0 ) {
|
10 |
+
$this->id = $id;
|
11 |
+
}
|
12 |
+
|
13 |
+
public function get_new() {
|
14 |
+
$this->id = 0;
|
15 |
+
|
16 |
+
$max_slug_value = pow(36, 6);
|
17 |
+
$min_slug_value = 37; // we want to have at least 2 characters in the slug
|
18 |
+
$key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
|
19 |
+
|
20 |
+
$style = array(
|
21 |
+
'post_type' => FrmStylesController::$post_type,
|
22 |
+
'ID' => '',
|
23 |
+
'post_title' => __( 'New Style', 'formidable' ),
|
24 |
+
'post_name' => $key,
|
25 |
+
'post_content' => $this->get_defaults(),
|
26 |
+
'menu_order' => '',
|
27 |
+
'post_status' => 'publish',
|
28 |
+
);
|
29 |
+
|
30 |
+
return (object) $style;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function save($settings) {
|
34 |
+
$settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
|
35 |
+
|
36 |
+
if ( empty($settings['ID']) ) {
|
37 |
+
unset($settings['ID']);
|
38 |
+
}
|
39 |
+
|
40 |
+
// delete all styling caches
|
41 |
+
FrmAppHelper::cache_delete_group('frm_styles');
|
42 |
+
|
43 |
+
return wp_insert_post($settings);
|
44 |
+
}
|
45 |
+
|
46 |
+
public function duplicate($id) {
|
47 |
+
// duplicating is a pro feature
|
48 |
+
}
|
49 |
+
|
50 |
+
public function update( $id = 'default' ) {
|
51 |
+
$all_instances = $this->get_all();
|
52 |
+
|
53 |
+
if ( empty($id) ) {
|
54 |
+
$new_style = (array) $this->get_new();
|
55 |
+
$all_instances[] = $new_style;
|
56 |
+
}
|
57 |
+
|
58 |
+
$action_ids = array();
|
59 |
+
|
60 |
+
foreach ( $all_instances as $number => $new_instance ) {
|
61 |
+
$new_instance = stripslashes_deep( (array) $new_instance);
|
62 |
+
$this->id = $new_instance['ID'];
|
63 |
+
if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) {
|
64 |
+
$all_instances[$number] = $new_instance;
|
65 |
+
|
66 |
+
if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) {
|
67 |
+
// this style was set to default, so remove default setting on previous default style
|
68 |
+
$new_instance['menu_order'] = 0;
|
69 |
+
$action_ids[] = $this->save($new_instance);
|
70 |
+
}
|
71 |
+
|
72 |
+
// don't continue if not saving this style
|
73 |
+
continue;
|
74 |
+
}
|
75 |
+
|
76 |
+
$new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] );
|
77 |
+
$new_instance['post_content'] = $_POST['frm_style_setting']['post_content'];
|
78 |
+
$new_instance['post_type'] = FrmStylesController::$post_type;
|
79 |
+
$new_instance['post_status'] = 'publish';
|
80 |
+
$new_instance['menu_order'] = isset($_POST['frm_style_setting']['menu_order']) ? (int) $_POST['frm_style_setting']['menu_order'] : 0;
|
81 |
+
|
82 |
+
if ( empty($id) ) {
|
83 |
+
$new_instance['post_name'] = $new_instance['post_title'];
|
84 |
+
}
|
85 |
+
|
86 |
+
$default_settings = $this->get_defaults();
|
87 |
+
|
88 |
+
foreach ( $default_settings as $setting => $default ) {
|
89 |
+
if ( strpos($setting, 'color') !== false || in_array($setting, array( 'error_bg', 'error_border', 'error_text')) ) {
|
90 |
+
//if is a color
|
91 |
+
$new_instance['post_content'][$setting] = str_replace('#', '', $new_instance['post_content'][$setting]);
|
92 |
+
} else if ( in_array($setting, array( 'submit_style', 'important_style', 'auto_width')) && ! isset($new_instance['post_content'][$setting]) ) {
|
93 |
+
$new_instance['post_content'][$setting] = 0;
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
$all_instances[$number] = $new_instance;
|
98 |
+
|
99 |
+
$action_ids[] = $this->save($new_instance);
|
100 |
+
|
101 |
+
}
|
102 |
+
|
103 |
+
$this->save_settings($all_instances);
|
104 |
+
|
105 |
+
return $action_ids;
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Create static css file
|
110 |
+
*/
|
111 |
+
public function save_settings($styles) {
|
112 |
+
$filename = FrmAppHelper::plugin_path() .'/css/custom_theme.css.php';
|
113 |
+
|
114 |
+
if ( ! is_file($filename) ) {
|
115 |
+
return;
|
116 |
+
}
|
117 |
+
|
118 |
+
$defaults = $this->get_defaults();
|
119 |
+
$uploads = wp_upload_dir();
|
120 |
+
$target_path = $uploads['basedir'] .'/formidable';
|
121 |
+
$needed_dirs = array( $target_path, $target_path .'/css' );
|
122 |
+
$dirs_exist = true;
|
123 |
+
|
124 |
+
$saving = true;
|
125 |
+
$css = '/* '. __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) .' */'. "\n";
|
126 |
+
|
127 |
+
ob_start();
|
128 |
+
$frm_style = $this;
|
129 |
+
include($filename);
|
130 |
+
$css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
|
131 |
+
ob_end_clean();
|
132 |
+
|
133 |
+
$access_type = get_filesystem_method();
|
134 |
+
if ( $access_type === 'direct' ) {
|
135 |
+
$creds = request_filesystem_credentials( site_url() .'/wp-admin/', '', false, false, array() );
|
136 |
+
|
137 |
+
// initialize the API
|
138 |
+
if ( ! WP_Filesystem($creds) ) {
|
139 |
+
// any problems and we exit
|
140 |
+
$dirs_exist = false;
|
141 |
+
}
|
142 |
+
|
143 |
+
global $wp_filesystem;
|
144 |
+
|
145 |
+
if ( $dirs_exist ) {
|
146 |
+
$chmod_dir = defined('FS_CHMOD_DIR') ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 );
|
147 |
+
$chmod_file = defined('FS_CHMOD_FILE') ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 );
|
148 |
+
|
149 |
+
// Create the directories if need be:
|
150 |
+
foreach ( $needed_dirs as $_dir ) {
|
151 |
+
// Only check to see if the Dir exists upon creation failure. Less I/O this way.
|
152 |
+
if ( ! $wp_filesystem->mkdir( $_dir, $chmod_dir ) && ! $wp_filesystem->is_dir( $_dir ) ) {
|
153 |
+
$dirs_exist = false;
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
$index_path = $target_path .'/index.php';
|
158 |
+
$wp_filesystem->put_contents( $index_path, "<?php\n// Silence is golden.\n?>", $chmod_file );
|
159 |
+
|
160 |
+
// only write the file if the folders exist
|
161 |
+
if ( $dirs_exist ) {
|
162 |
+
$css_file = $target_path .'/css/formidablepro.css';
|
163 |
+
$wp_filesystem->put_contents( $css_file, $css, $chmod_file );
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
update_option('frmpro_css', $css);
|
169 |
+
|
170 |
+
delete_transient('frmpro_css');
|
171 |
+
set_transient('frmpro_css', $css);
|
172 |
+
}
|
173 |
+
|
174 |
+
public function destroy($id) {
|
175 |
+
return wp_delete_post($id);
|
176 |
+
}
|
177 |
+
|
178 |
+
public function get_one() {
|
179 |
+
if ( 'default' == $this->id ) {
|
180 |
+
$style = $this->get_default_style();
|
181 |
+
if ( $style ) {
|
182 |
+
$this->id = $style->ID;
|
183 |
+
} else {
|
184 |
+
$this->id = 0;
|
185 |
+
}
|
186 |
+
return $style;
|
187 |
+
}
|
188 |
+
|
189 |
+
$style = get_post($this->id);
|
190 |
+
|
191 |
+
if ( ! $style ) {
|
192 |
+
return $style;
|
193 |
+
}
|
194 |
+
|
195 |
+
$style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
|
196 |
+
|
197 |
+
$default_values = $this->get_defaults();
|
198 |
+
|
199 |
+
// fill default values
|
200 |
+
$style->post_content = $this->override_defaults($style->post_content);
|
201 |
+
$style->post_content = wp_parse_args( $style->post_content, $default_values);
|
202 |
+
|
203 |
+
return $style;
|
204 |
+
}
|
205 |
+
|
206 |
+
public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
|
207 |
+
$post_atts = array(
|
208 |
+
'post_type' => FrmStylesController::$post_type,
|
209 |
+
'post_status' => 'publish',
|
210 |
+
'numberposts' => $limit,
|
211 |
+
'orderby' => $orderby,
|
212 |
+
'order' => $order,
|
213 |
+
);
|
214 |
+
|
215 |
+
$temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts');
|
216 |
+
|
217 |
+
if ( empty($temp_styles) ) {
|
218 |
+
global $wpdb;
|
219 |
+
// make sure there wasn't a conflict with the query
|
220 |
+
$query = $wpdb->prepare('SELECT * FROM '. $wpdb->posts .' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish');
|
221 |
+
$temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results');
|
222 |
+
|
223 |
+
if ( empty($temp_styles) ) {
|
224 |
+
// create a new style if there are none
|
225 |
+
$new = $this->get_new();
|
226 |
+
$new->post_title = $new->post_name = __( 'Formidable Style', 'formidable' );
|
227 |
+
$new->menu_order = 1;
|
228 |
+
$new = $this->save( (array) $new);
|
229 |
+
$this->update('default');
|
230 |
+
|
231 |
+
$post_atts['include'] = $new;
|
232 |
+
|
233 |
+
$temp_styles = get_posts( $post_atts );
|
234 |
+
}
|
235 |
+
}
|
236 |
+
|
237 |
+
$default_values = $this->get_defaults();
|
238 |
+
$default_style = false;
|
239 |
+
|
240 |
+
$styles = array();
|
241 |
+
foreach ( $temp_styles as $style ) {
|
242 |
+
$this->id = $style->ID;
|
243 |
+
if ( $style->menu_order ) {
|
244 |
+
if ( $default_style ) {
|
245 |
+
// only return one default
|
246 |
+
$style->menu_order = 0;
|
247 |
+
} else {
|
248 |
+
// check for a default style
|
249 |
+
$default_style = $style->ID;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
$style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
|
254 |
+
|
255 |
+
// fill default values
|
256 |
+
$style->post_content = $this->override_defaults($style->post_content);
|
257 |
+
$style->post_content = wp_parse_args( $style->post_content, $default_values);
|
258 |
+
|
259 |
+
$styles[$style->ID] = $style;
|
260 |
+
}
|
261 |
+
|
262 |
+
if ( ! $default_style ) {
|
263 |
+
$default_style = reset($styles);
|
264 |
+
$styles[$default_style->ID]->menu_order = 1;
|
265 |
+
}
|
266 |
+
|
267 |
+
return $styles;
|
268 |
+
}
|
269 |
+
|
270 |
+
public function get_default_style($styles = null) {
|
271 |
+
if ( ! isset($styles) ) {
|
272 |
+
$styles = $this->get_all( 'menu_order', 'DESC', 1 );
|
273 |
+
}
|
274 |
+
|
275 |
+
foreach ( $styles as $style ) {
|
276 |
+
if ( $style->menu_order ) {
|
277 |
+
return $style;
|
278 |
+
}
|
279 |
+
}
|
280 |
+
}
|
281 |
+
|
282 |
+
public function override_defaults($settings) {
|
283 |
+
if ( ! is_array($settings) ) {
|
284 |
+
return $settings;
|
285 |
+
}
|
286 |
+
|
287 |
+
$settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height'];
|
288 |
+
|
289 |
+
if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
|
290 |
+
$settings['form_desc_size'] = $settings['description_font_size'];
|
291 |
+
$settings['form_desc_color'] = $settings['description_color'];
|
292 |
+
$settings['title_color'] = $settings['label_color'];
|
293 |
+
}
|
294 |
+
|
295 |
+
if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
|
296 |
+
$settings['section_color'] = $settings['label_color'];
|
297 |
+
$settings['section_border_color'] = $settings['border_color'];
|
298 |
+
}
|
299 |
+
|
300 |
+
if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
|
301 |
+
$settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
|
302 |
+
$settings['submit_hover_color'] = $settings['submit_text_color'];
|
303 |
+
$settings['submit_hover_border_color'] = $settings['submit_border_color'];
|
304 |
+
|
305 |
+
$settings['submit_active_bg_color'] = $settings['submit_bg_color'];
|
306 |
+
$settings['submit_active_color'] = $settings['submit_text_color'];
|
307 |
+
$settings['submit_active_border_color'] = $settings['submit_border_color'];
|
308 |
+
}
|
309 |
+
|
310 |
+
return $settings;
|
311 |
+
}
|
312 |
+
|
313 |
+
public function get_defaults(){
|
314 |
+
return array(
|
315 |
+
'theme_css' => 'ui-lightness',
|
316 |
+
'theme_name' => 'UI Lightness',
|
317 |
+
|
318 |
+
'form_width' => '100%',
|
319 |
+
'form_align' => 'left',
|
320 |
+
'direction' => is_rtl() ? 'rtl' : 'ltr',
|
321 |
+
'fieldset' => '0px',
|
322 |
+
'fieldset_color' => '000000',
|
323 |
+
'fieldset_padding' => '0 0 15px 0',
|
324 |
+
'fieldset_bg_color' => '',
|
325 |
+
|
326 |
+
'title_size' => '20px',
|
327 |
+
'title_color' => '444444',
|
328 |
+
'form_desc_size' => '14px',
|
329 |
+
'form_desc_color' => '666666',
|
330 |
+
|
331 |
+
'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif',
|
332 |
+
'font_size' => '14px',
|
333 |
+
'label_color' => '444444',
|
334 |
+
'weight' => 'bold',
|
335 |
+
'position' => 'none',
|
336 |
+
'align' => 'left',
|
337 |
+
'width' => '150px',
|
338 |
+
'required_color' => 'B94A48',
|
339 |
+
'required_weight' => 'bold',
|
340 |
+
'label_padding' => '0 0 3px 0',
|
341 |
+
|
342 |
+
'description_font_size' => '12px',
|
343 |
+
'description_color' => '666666',
|
344 |
+
'description_weight' => 'normal',
|
345 |
+
'description_style' => 'normal',
|
346 |
+
'description_align' => 'left',
|
347 |
+
|
348 |
+
'field_font_size' => '14px',
|
349 |
+
'field_height' => '32px',
|
350 |
+
'line_height' => 'normal',
|
351 |
+
'field_width' => '100%',
|
352 |
+
'auto_width' => false,
|
353 |
+
'field_pad' => '6px 10px',
|
354 |
+
'field_margin' => '20px',
|
355 |
+
'text_color' => '555555',
|
356 |
+
//'border_color_hv' => 'cccccc',
|
357 |
+
'border_color' => 'cccccc',
|
358 |
+
'field_border_width' => '1px',
|
359 |
+
'field_border_style' => 'solid',
|
360 |
+
|
361 |
+
'bg_color' => 'ffffff',
|
362 |
+
//'bg_color_hv' => 'ffffff',
|
363 |
+
'bg_color_active' => 'ffffff',
|
364 |
+
'border_color_active'=> '66afe9',
|
365 |
+
'text_color_error' => '444444',
|
366 |
+
'bg_color_error' => 'ffffff',
|
367 |
+
'border_color_error'=> 'B94A48',
|
368 |
+
'border_width_error'=> '1px',
|
369 |
+
'border_style_error'=> 'solid',
|
370 |
+
'bg_color_disabled' => 'ffffff',
|
371 |
+
'border_color_disabled' => 'E5E5E5',
|
372 |
+
'text_color_disabled' => 'A1A1A1',
|
373 |
+
|
374 |
+
'radio_align' => 'block',
|
375 |
+
'check_align' => 'block',
|
376 |
+
'check_font_size' => '13px',
|
377 |
+
'check_label_color' => '444444',
|
378 |
+
'check_weight' => 'normal',
|
379 |
+
|
380 |
+
'section_font_size' => '18px',
|
381 |
+
'section_color' => '444444',
|
382 |
+
'section_weight' => 'bold',
|
383 |
+
'section_pad' => '15px 0 3px 0',
|
384 |
+
'section_mar_top' => '15px',
|
385 |
+
'section_mar_bottom'=> '12px',
|
386 |
+
'section_bg_color' => '',
|
387 |
+
'section_border_color' => 'e8e8e8',
|
388 |
+
'section_border_width' => '2px',
|
389 |
+
'section_border_style' => 'solid',
|
390 |
+
'section_border_loc' => '-top',
|
391 |
+
'collapse_icon' => '6',
|
392 |
+
'collapse_pos' => 'after',
|
393 |
+
'repeat_icon' => '1',
|
394 |
+
|
395 |
+
'submit_style' => false,
|
396 |
+
'submit_font_size' => '14px',
|
397 |
+
'submit_width' => 'auto',
|
398 |
+
'submit_height' => 'auto',
|
399 |
+
'submit_bg_color' => 'ffffff',
|
400 |
+
'submit_border_color' => 'cccccc',
|
401 |
+
'submit_border_width' => '1px',
|
402 |
+
'submit_text_color' => '444444',
|
403 |
+
'submit_weight' => 'normal',
|
404 |
+
'submit_border_radius' => '4px',
|
405 |
+
'submit_bg_img' => '',
|
406 |
+
'submit_margin' => '10px',
|
407 |
+
'submit_padding' => '6px 11px',
|
408 |
+
'submit_shadow_color' => 'eeeeee',
|
409 |
+
'submit_hover_bg_color' => 'efefef',
|
410 |
+
'submit_hover_color' => '444444',
|
411 |
+
'submit_hover_border_color' => 'cccccc',
|
412 |
+
'submit_active_bg_color' => 'efefef',
|
413 |
+
'submit_active_color' => '444444',
|
414 |
+
'submit_active_border_color' => 'cccccc',
|
415 |
+
|
416 |
+
'border_radius' => '4px',
|
417 |
+
'error_bg' => 'F2DEDE',
|
418 |
+
'error_border' => 'EBCCD1',
|
419 |
+
'error_text' => 'B94A48',
|
420 |
+
'error_font_size' => '14px',
|
421 |
+
|
422 |
+
'success_bg_color' => 'DFF0D8',
|
423 |
+
'success_border_color' => 'D6E9C6',
|
424 |
+
'success_text_color' => '468847',
|
425 |
+
'success_font_size' => '14px',
|
426 |
+
|
427 |
+
'important_style' => false,
|
428 |
+
|
429 |
+
'custom_css' => '',
|
430 |
+
);
|
431 |
+
}
|
432 |
+
|
433 |
+
public function get_field_name($field_name, $post_field = 'post_content') {
|
434 |
+
return 'frm_style_setting'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']';
|
435 |
+
}
|
436 |
+
|
437 |
+
}
|
classes/recaptchalib.php
DELETED
@@ -1,274 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
* This is a PHP library that handles calling reCAPTCHA.
|
4 |
-
* - Documentation and latest version
|
5 |
-
* http://recaptcha.net/plugins/php/
|
6 |
-
* - Get a reCAPTCHA API Key
|
7 |
-
* https://www.google.com/recaptcha/admin/create
|
8 |
-
* - Discussion group
|
9 |
-
* http://groups.google.com/group/recaptcha
|
10 |
-
*
|
11 |
-
* Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
|
12 |
-
* AUTHORS:
|
13 |
-
* Mike Crawford
|
14 |
-
* Ben Maurer
|
15 |
-
*
|
16 |
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
17 |
-
* of this software and associated documentation files (the "Software"), to deal
|
18 |
-
* in the Software without restriction, including without limitation the rights
|
19 |
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
20 |
-
* copies of the Software, and to permit persons to whom the Software is
|
21 |
-
* furnished to do so, subject to the following conditions:
|
22 |
-
*
|
23 |
-
* The above copyright notice and this permission notice shall be included in
|
24 |
-
* all copies or substantial portions of the Software.
|
25 |
-
*
|
26 |
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
27 |
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
28 |
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
29 |
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
30 |
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
31 |
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
32 |
-
* THE SOFTWARE.
|
33 |
-
*/
|
34 |
-
|
35 |
-
/**
|
36 |
-
* The reCAPTCHA server URL's
|
37 |
-
*/
|
38 |
-
define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
|
39 |
-
define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
|
40 |
-
define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Encodes the given data into a query string format
|
44 |
-
* @param $data - array of string elements to be encoded
|
45 |
-
* @return string - encoded request
|
46 |
-
*/
|
47 |
-
function _recaptcha_qsencode ($data) {
|
48 |
-
$req = "";
|
49 |
-
foreach ( $data as $key => $value )
|
50 |
-
$req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
|
51 |
-
|
52 |
-
// Cut the last '&'
|
53 |
-
$req=substr($req,0,strlen($req)-1);
|
54 |
-
return $req;
|
55 |
-
}
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Submits an HTTP POST to a reCAPTCHA server
|
61 |
-
* @param string $host
|
62 |
-
* @param string $path
|
63 |
-
* @param array $data
|
64 |
-
* @param int port
|
65 |
-
* @return array response
|
66 |
-
*/
|
67 |
-
function _recaptcha_http_post($host, $path, $data, $port = 80) {
|
68 |
-
|
69 |
-
$req = _recaptcha_qsencode ($data);
|
70 |
-
|
71 |
-
$http_request = "POST $path HTTP/1.0\r\n";
|
72 |
-
$http_request .= "Host: $host\r\n";
|
73 |
-
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
|
74 |
-
$http_request .= "Content-Length: " . strlen($req) . "\r\n";
|
75 |
-
$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
|
76 |
-
$http_request .= "\r\n";
|
77 |
-
$http_request .= $req;
|
78 |
-
|
79 |
-
$response = '';
|
80 |
-
if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
|
81 |
-
die ('Could not open socket');
|
82 |
-
}
|
83 |
-
|
84 |
-
fwrite($fs, $http_request);
|
85 |
-
|
86 |
-
while ( !feof($fs) )
|
87 |
-
$response .= fgets($fs, 1160); // One TCP-IP packet
|
88 |
-
fclose($fs);
|
89 |
-
$response = explode("\r\n\r\n", $response, 2);
|
90 |
-
|
91 |
-
return $response;
|
92 |
-
}
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Gets the challenge HTML (javascript and non-javascript version).
|
98 |
-
* This is called from the browser, and the resulting reCAPTCHA HTML widget
|
99 |
-
* is embedded within the HTML form it was called from.
|
100 |
-
* @param string $pubkey A public key for reCAPTCHA
|
101 |
-
* @param string $error The error given by reCAPTCHA (optional, default is null)
|
102 |
-
* @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
|
103 |
-
|
104 |
-
* @return string - The HTML to be embedded in the user's form.
|
105 |
-
*/
|
106 |
-
function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
|
107 |
-
{
|
108 |
-
if ($pubkey == null || $pubkey == '') {
|
109 |
-
die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
|
110 |
-
}
|
111 |
-
|
112 |
-
if ($use_ssl) {
|
113 |
-
$server = RECAPTCHA_API_SECURE_SERVER;
|
114 |
-
} else {
|
115 |
-
$server = RECAPTCHA_API_SERVER;
|
116 |
-
}
|
117 |
-
|
118 |
-
$errorpart = "";
|
119 |
-
if ($error) {
|
120 |
-
$errorpart = "&error=" . $error;
|
121 |
-
}
|
122 |
-
return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
|
123 |
-
|
124 |
-
<noscript>
|
125 |
-
<iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
|
126 |
-
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
|
127 |
-
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
|
128 |
-
</noscript>';
|
129 |
-
}
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
/**
|
135 |
-
* A ReCaptchaResponse is returned from recaptcha_check_answer()
|
136 |
-
*/
|
137 |
-
class ReCaptchaResponse {
|
138 |
-
var $is_valid;
|
139 |
-
var $error;
|
140 |
-
}
|
141 |
-
|
142 |
-
|
143 |
-
/**
|
144 |
-
* Calls an HTTP POST function to verify if the user's guess was correct
|
145 |
-
* @param string $privkey
|
146 |
-
* @param string $remoteip
|
147 |
-
* @param string $challenge
|
148 |
-
* @param string $response
|
149 |
-
* @param array $extra_params an array of extra variables to post to the server
|
150 |
-
* @return ReCaptchaResponse
|
151 |
-
*/
|
152 |
-
function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
|
153 |
-
{
|
154 |
-
if ($privkey == null || $privkey == '') {
|
155 |
-
die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
|
156 |
-
}
|
157 |
-
|
158 |
-
if ($remoteip == null || $remoteip == '') {
|
159 |
-
die ("For security reasons, you must pass the remote ip to reCAPTCHA");
|
160 |
-
}
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
//discard spam submissions
|
165 |
-
if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
|
166 |
-
$recaptcha_response = new ReCaptchaResponse();
|
167 |
-
$recaptcha_response->is_valid = false;
|
168 |
-
$recaptcha_response->error = 'incorrect-captcha-sol';
|
169 |
-
return $recaptcha_response;
|
170 |
-
}
|
171 |
-
|
172 |
-
$response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
|
173 |
-
array (
|
174 |
-
'privatekey' => $privkey,
|
175 |
-
'remoteip' => $remoteip,
|
176 |
-
'challenge' => $challenge,
|
177 |
-
'response' => $response
|
178 |
-
) + $extra_params
|
179 |
-
);
|
180 |
-
|
181 |
-
$answers = explode ("\n", $response [1]);
|
182 |
-
$recaptcha_response = new ReCaptchaResponse();
|
183 |
-
|
184 |
-
if (trim ($answers [0]) == 'true') {
|
185 |
-
$recaptcha_response->is_valid = true;
|
186 |
-
}
|
187 |
-
else {
|
188 |
-
$recaptcha_response->is_valid = false;
|
189 |
-
$recaptcha_response->error = $answers [1];
|
190 |
-
}
|
191 |
-
return $recaptcha_response;
|
192 |
-
|
193 |
-
}
|
194 |
-
|
195 |
-
/**
|
196 |
-
* gets a URL where the user can sign up for reCAPTCHA. If your application
|
197 |
-
* has a configuration page where you enter a key, you should provide a link
|
198 |
-
* using this function.
|
199 |
-
* @param string $domain The domain where the page is hosted
|
200 |
-
* @param string $appname The name of your application
|
201 |
-
*/
|
202 |
-
function recaptcha_get_signup_url ($domain = null, $appname = null) {
|
203 |
-
return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
|
204 |
-
}
|
205 |
-
|
206 |
-
function _recaptcha_aes_pad($val) {
|
207 |
-
$block_size = 16;
|
208 |
-
$numpad = $block_size - (strlen ($val) % $block_size);
|
209 |
-
return str_pad($val, strlen ($val) + $numpad, chr($numpad));
|
210 |
-
}
|
211 |
-
|
212 |
-
/* Mailhide related code */
|
213 |
-
|
214 |
-
function _recaptcha_aes_encrypt($val,$ky) {
|
215 |
-
if (! function_exists ("mcrypt_encrypt")) {
|
216 |
-
die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
|
217 |
-
}
|
218 |
-
$mode=MCRYPT_MODE_CBC;
|
219 |
-
$enc=MCRYPT_RIJNDAEL_128;
|
220 |
-
$val=_recaptcha_aes_pad($val);
|
221 |
-
return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
|
222 |
-
}
|
223 |
-
|
224 |
-
|
225 |
-
function _recaptcha_mailhide_urlbase64 ($x) {
|
226 |
-
return strtr(base64_encode ($x), '+/', '-_');
|
227 |
-
}
|
228 |
-
|
229 |
-
/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
|
230 |
-
function recaptcha_mailhide_url($pubkey, $privkey, $email) {
|
231 |
-
if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
|
232 |
-
die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
|
233 |
-
"you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
|
234 |
-
}
|
235 |
-
|
236 |
-
|
237 |
-
$ky = pack('H*', $privkey);
|
238 |
-
$cryptmail = _recaptcha_aes_encrypt ($email, $ky);
|
239 |
-
|
240 |
-
return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
|
241 |
-
}
|
242 |
-
|
243 |
-
/**
|
244 |
-
* gets the parts of the email to expose to the user.
|
245 |
-
* eg, given johndoe@example,com return ["john", "example.com"].
|
246 |
-
* the email is then displayed as john...@example.com
|
247 |
-
*/
|
248 |
-
function _recaptcha_mailhide_email_parts ($email) {
|
249 |
-
$arr = preg_split("/@/", $email );
|
250 |
-
|
251 |
-
if (strlen ($arr[0]) <= 4) {
|
252 |
-
$arr[0] = substr ($arr[0], 0, 1);
|
253 |
-
} else if (strlen ($arr[0]) <= 6) {
|
254 |
-
$arr[0] = substr ($arr[0], 0, 3);
|
255 |
-
} else {
|
256 |
-
$arr[0] = substr ($arr[0], 0, 4);
|
257 |
-
}
|
258 |
-
return $arr;
|
259 |
-
}
|
260 |
-
|
261 |
-
/**
|
262 |
-
* Gets html to display an email address given a public an private key.
|
263 |
-
* to get a key, go to:
|
264 |
-
*
|
265 |
-
* http://www.google.com/recaptcha/mailhide/apikey
|
266 |
-
*/
|
267 |
-
function recaptcha_mailhide_html($pubkey, $privkey, $email) {
|
268 |
-
$emailparts = _recaptcha_mailhide_email_parts ($email);
|
269 |
-
$url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
|
270 |
-
|
271 |
-
return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
|
272 |
-
"' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
|
273 |
-
|
274 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/views/frm-entries/_sidebar-shared-pub.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! isset( $entry) ) {
|
3 |
+
$entry = $record;
|
4 |
+
} ?>
|
5 |
+
|
6 |
+
<div class="misc-pub-section curtime misc-pub-curtime">
|
7 |
+
<span id="timestamp">
|
8 |
+
<?php
|
9 |
+
$datef = __( 'M j, Y @ G:i' );
|
10 |
+
printf(__( 'Published on: <b>%1$s</b>'), date_i18n( $datef, strtotime( $entry->created_at ) )); ?>
|
11 |
+
</span>
|
12 |
+
</div>
|
13 |
+
<?php if ( $entry->updated_at && $entry->updated_at != $entry->created_at ) { ?>
|
14 |
+
<div class="misc-pub-section curtime misc-pub-curtime">
|
15 |
+
<span id="timestamp">
|
16 |
+
<?php printf(__( 'Updated on: <b>%1$s</b>', 'formidable' ), date_i18n( $datef, strtotime( $entry->updated_at ) )); ?>
|
17 |
+
</span>
|
18 |
+
</div>
|
19 |
+
<?php } ?>
|
20 |
+
|
21 |
+
<?php do_action('frm_entry_shared_sidebar', $entry); ?>
|
classes/views/frm-entries/direct.php
CHANGED
@@ -1,17 +1,13 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html <?php language_attributes(); ?>>
|
3 |
<head>
|
4 |
-
<
|
5 |
-
<
|
6 |
-
|
7 |
-
|
8 |
-
<style type="text/css">.frm_forms.with_frm_style{max-width:750px;}</style>
|
9 |
-
<?php } ?>
|
10 |
</head>
|
11 |
-
<body>
|
12 |
-
|
13 |
-
<?php
|
14 |
-
</div>
|
15 |
-
<?php wp_footer(); ?>
|
16 |
</body>
|
17 |
</html>
|
1 |
<!DOCTYPE html>
|
2 |
<html <?php language_attributes(); ?>>
|
3 |
<head>
|
4 |
+
<title><?php bloginfo( 'name' ); ?> | <?php echo esc_html( $form->name ) ?></title>
|
5 |
+
<meta charset="<?php bloginfo( 'charset' ); ?>" />
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
7 |
+
<?php wp_head(); ?>
|
|
|
|
|
8 |
</head>
|
9 |
+
<body class="frm_preview_page">
|
10 |
+
<?php echo FrmFormsController::show_form( $form->id, '', true, true ); ?>
|
11 |
+
<?php wp_footer(); ?>
|
|
|
|
|
12 |
</body>
|
13 |
</html>
|
classes/views/frm-entries/errors.php
CHANGED
@@ -1,35 +1,39 @@
|
|
1 |
-
<?php
|
2 |
-
if (isset($
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
}
|
9 |
-
}
|
10 |
|
11 |
-
if( isset($errors) && is_array($errors) && !empty($errors) ){
|
12 |
-
global $frm_settings;
|
13 |
|
14 |
-
if ( isset($form) && is_object($form) ) {
|
15 |
-
|
16 |
-
|
17 |
-
<div class="frm_error_style">
|
18 |
<?php
|
19 |
$img = '';
|
20 |
-
if(!is_admin()
|
21 |
$img = apply_filters('frm_error_icon', $img);
|
22 |
-
if($img
|
23 |
-
?><img src="<?php echo $img ?>" alt="" />
|
24 |
-
<?php
|
25 |
}
|
26 |
-
}
|
27 |
-
|
28 |
-
|
|
|
29 |
$show_img = false;
|
30 |
-
|
31 |
-
if($show_img
|
32 |
-
?><img src="<?php echo $img ?>" alt="" /><?php
|
33 |
}else{
|
34 |
$show_img = true;
|
35 |
}
|
@@ -39,13 +43,14 @@ if(empty($frm_settings->invalid_msg)){
|
|
39 |
echo $frm_settings->invalid_msg;
|
40 |
|
41 |
$show_img = true;
|
42 |
-
|
43 |
-
if(!is_numeric($err_key)
|
44 |
continue;
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
}else{
|
50 |
$show_img = true;
|
51 |
}
|
@@ -53,4 +58,10 @@ if(empty($frm_settings->invalid_msg)){
|
|
53 |
}
|
54 |
} ?>
|
55 |
</div>
|
56 |
-
<?php
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( isset($include_extra_container) ) { ?>
|
3 |
+
<div class="<?php echo esc_attr( $include_extra_container ) ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container">
|
4 |
+
<?php
|
5 |
+
}
|
6 |
+
if (isset($message) && $message != ''){
|
7 |
+
if ( FrmAppHelper::is_admin() ) {
|
8 |
+
?><div id="message" class="frm_message updated frm_msg_padding"><?php echo $message ?></div><?php
|
9 |
+
}else{
|
10 |
+
FrmFormsHelper::get_scroll_js($form->id);
|
11 |
+
echo $message;
|
12 |
}
|
13 |
+
}
|
14 |
|
15 |
+
if ( isset($errors) && is_array( $errors ) && ! empty( $errors ) ) {
|
|
|
16 |
|
17 |
+
if ( isset( $form ) && is_object( $form ) ) {
|
18 |
+
FrmFormsHelper::get_scroll_js( $form->id );
|
19 |
+
} ?>
|
20 |
+
<div class="frm_error_style">
|
21 |
<?php
|
22 |
$img = '';
|
23 |
+
if ( ! FrmAppHelper::is_admin() ) {
|
24 |
$img = apply_filters('frm_error_icon', $img);
|
25 |
+
if ( $img && ! empty($img) ) {
|
26 |
+
?><img src="<?php echo esc_attr( $img ) ?>" alt="" />
|
27 |
+
<?php
|
28 |
}
|
29 |
+
}
|
30 |
+
|
31 |
+
$frm_settings = FrmAppHelper::get_settings();
|
32 |
+
if ( empty( $frm_settings->invalid_msg ) ) {
|
33 |
$show_img = false;
|
34 |
+
foreach ( $errors as $error ) {
|
35 |
+
if ( $show_img && ! empty($img) ) {
|
36 |
+
?><img src="<?php echo esc_attr( $img ) ?>" alt="" /><?php
|
37 |
}else{
|
38 |
$show_img = true;
|
39 |
}
|
43 |
echo $frm_settings->invalid_msg;
|
44 |
|
45 |
$show_img = true;
|
46 |
+
foreach ( $errors as $err_key => $error ) {
|
47 |
+
if ( ! is_numeric($err_key) && ( $err_key == 'cptch_number' || strpos($err_key, 'field') === 0 ) ) {
|
48 |
continue;
|
49 |
+
}
|
50 |
+
|
51 |
+
echo '<br/>';
|
52 |
+
if ( $show_img && ! empty($img) ) {
|
53 |
+
?><img src="<?php echo esc_attr( $img ) ?>" alt="" /><?php
|
54 |
}else{
|
55 |
$show_img = true;
|
56 |
}
|
58 |
}
|
59 |
} ?>
|
60 |
</div>
|
61 |
+
<?php
|
62 |
+
}
|
63 |
+
|
64 |
+
if ( isset($include_extra_container) ) { ?>
|
65 |
+
</div>
|
66 |
+
<?php
|
67 |
+
}
|
classes/views/frm-entries/form.php
CHANGED
@@ -1,17 +1,11 @@
|
|
1 |
-
<?php
|
2 |
-
global $frm_vars
|
3 |
-
FrmFormsHelper::form_loaded($form);
|
4 |
-
if($values['custom_style']) $frm_vars['load_css'] = true;
|
5 |
-
|
6 |
-
if((!isset($frm_vars['css_loaded']) || !$frm_vars['css_loaded']) && $frm_vars['load_css']){
|
7 |
-
echo FrmAppController::footer_js('header');
|
8 |
-
$frm_vars['css_loaded'] = true;
|
9 |
-
}
|
10 |
|
11 |
echo FrmFormsHelper::replace_shortcodes($values['before_html'], $form, $title, $description); ?>
|
12 |
<div class="frm_form_fields <?php echo apply_filters('frm_form_fields_class', '', $values); ?>">
|
13 |
<fieldset>
|
14 |
-
<
|
15 |
<input type="hidden" name="frm_action" value="<?php echo esc_attr($form_action) ?>" />
|
16 |
<input type="hidden" name="form_id" value="<?php echo esc_attr($form->id) ?>" />
|
17 |
<input type="hidden" name="form_key" value="<?php echo esc_attr($form->form_key) ?>" />
|
@@ -23,21 +17,22 @@ echo FrmFormsHelper::replace_shortcodes($values['before_html'], $form, $title, $
|
|
23 |
<input type="hidden" name="plugin" value="<?php echo esc_attr($plugin); ?>" />
|
24 |
<?php }
|
25 |
|
26 |
-
if($values['fields']){
|
27 |
-
foreach($values['fields'] as $field){
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
}
|
36 |
}
|
37 |
|
38 |
-
|
|
|
39 |
<div class="frm_form_field form-field">
|
40 |
-
<label class="frm_primary_label"><?php _e('Entry Key', 'formidable') ?></label>
|
41 |
<input type="text" name="item_key" value="<?php echo esc_attr($values['item_key']) ?>" />
|
42 |
</div>
|
43 |
<?php }else{ ?>
|
@@ -47,22 +42,24 @@ if ((is_admin() and !defined('DOING_AJAX')) and !$frm_settings->lock_keys){ ?>
|
|
47 |
do_action('frm_entry_form', $form, $form_action, $errors);
|
48 |
|
49 |
global $frm_vars;
|
50 |
-
if(isset($frm_vars['div'])
|
51 |
echo "</div>\n";
|
52 |
-
$frm_vars['div']
|
53 |
-
}
|
54 |
-
|
55 |
-
|
56 |
-
</div>
|
57 |
-
<?php echo FrmFormsHelper::replace_shortcodes($values['after_html'], $form);
|
58 |
|
59 |
-
|
60 |
-
if(
|
61 |
<script type="text/javascript">
|
62 |
<?php do_action('frm_entries_footer_scripts', $values['fields'], $form); ?>
|
63 |
-
</script><?php
|
|
|
64 |
|
65 |
-
if (
|
66 |
unset($values['fields']);
|
67 |
FrmFormsHelper::get_custom_submit($values['submit_html'], $form, $submit, $form_action, $values);
|
68 |
}
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
global $frm_vars;
|
3 |
+
FrmFormsHelper::form_loaded($form, $values['custom_style'], $frm_vars['load_css']);
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
echo FrmFormsHelper::replace_shortcodes($values['before_html'], $form, $title, $description); ?>
|
6 |
<div class="frm_form_fields <?php echo apply_filters('frm_form_fields_class', '', $values); ?>">
|
7 |
<fieldset>
|
8 |
+
<legend class="frm_hidden"><?php echo wp_kses($form->name, array()); ?></legend>
|
9 |
<input type="hidden" name="frm_action" value="<?php echo esc_attr($form_action) ?>" />
|
10 |
<input type="hidden" name="form_id" value="<?php echo esc_attr($form->id) ?>" />
|
11 |
<input type="hidden" name="form_key" value="<?php echo esc_attr($form->form_key) ?>" />
|
17 |
<input type="hidden" name="plugin" value="<?php echo esc_attr($plugin); ?>" />
|
18 |
<?php }
|
19 |
|
20 |
+
if ( $values['fields'] ) {
|
21 |
+
foreach ( $values['fields'] as $field ) {
|
22 |
+
if ( apply_filters( 'frm_show_normal_field_type', true, $field['type'] ) ) {
|
23 |
+
echo FrmFieldsHelper::replace_shortcodes( $field['custom_html'], $field, $errors, $form );
|
24 |
+
} else {
|
25 |
+
do_action( 'frm_show_other_field_type', $field, $form, array( 'action' => $form_action ) );
|
26 |
+
}
|
27 |
+
|
28 |
+
do_action('frm_get_field_scripts', $field, $form);
|
29 |
+
}
|
30 |
}
|
31 |
|
32 |
+
$frm_settings = FrmAppHelper::get_settings();
|
33 |
+
if ( FrmAppHelper::is_admin() && ! $frm_settings->lock_keys ) { ?>
|
34 |
<div class="frm_form_field form-field">
|
35 |
+
<label class="frm_primary_label"><?php _e( 'Entry Key', 'formidable' ) ?></label>
|
36 |
<input type="text" name="item_key" value="<?php echo esc_attr($values['item_key']) ?>" />
|
37 |
</div>
|
38 |
<?php }else{ ?>
|
42 |
do_action('frm_entry_form', $form, $form_action, $errors);
|
43 |
|
44 |
global $frm_vars;
|
45 |
+
if ( isset($frm_vars['div']) && $frm_vars['div'] ) {
|
46 |
echo "</div>\n";
|
47 |
+
unset($frm_vars['div']);
|
48 |
+
}
|
49 |
+
|
50 |
+
echo FrmFormsHelper::replace_shortcodes($values['after_html'], $form);
|
|
|
|
|
51 |
|
52 |
+
|
53 |
+
if ( has_action('frm_entries_footer_scripts') ) { ?>
|
54 |
<script type="text/javascript">
|
55 |
<?php do_action('frm_entries_footer_scripts', $values['fields'], $form); ?>
|
56 |
+
</script><?php
|
57 |
+
}
|
58 |
|
59 |
+
if ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() ) {
|
60 |
unset($values['fields']);
|
61 |
FrmFormsHelper::get_custom_submit($values['submit_html'], $form, $submit, $form_action, $values);
|
62 |
}
|
63 |
+
?>
|
64 |
+
</fieldset>
|
65 |
+
</div>
|
classes/views/frm-entries/frm-entry.php
DELETED
@@ -1,52 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST ) {
|
4 |
-
|
5 |
-
if ( !empty($errors) ) {
|
6 |
-
$values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
|
7 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
|
8 |
-
return;
|
9 |
-
}
|
10 |
-
|
11 |
-
do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description);
|
12 |
-
if ( !apply_filters('frm_continue_to_create', true, $form->id) ) {
|
13 |
-
return;
|
14 |
-
}
|
15 |
-
|
16 |
-
$values = FrmEntriesHelper::setup_new_vars($fields, $form, true);
|
17 |
-
$created = (isset($frm_vars['created_entries']) && isset($frm_vars['created_entries'][$form->id])) ? $frm_vars['created_entries'][$form->id]['entry_id'] : 0;
|
18 |
-
$conf_method = apply_filters('frm_success_filter', 'message', $form, $form->options, 'create');
|
19 |
-
|
20 |
-
if ( !$created || !is_numeric($created) || $conf_method == 'message' ) {
|
21 |
-
$saved_message = apply_filters('frm_content', $saved_message, $form, $created);
|
22 |
-
$message = ($created && is_numeric($created)) ? '<div class="frm_message" id="message">'. wpautop(do_shortcode($saved_message)) .'</div>' : '<div class="frm_error_style">'. $frm_settings->failed_msg .'</div>';
|
23 |
-
|
24 |
-
if ( !isset($form->options['show_form']) || $form->options['show_form'] ) {
|
25 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
|
26 |
-
} else {
|
27 |
-
global $frm_vars;
|
28 |
-
FrmFormsHelper::form_loaded($form);
|
29 |
-
if ( $values['custom_style'] ) {
|
30 |
-
$frm_vars['load_css'] = true;
|
31 |
-
}
|
32 |
-
|
33 |
-
if ( (!isset($frm_vars['css_loaded']) || !$frm_vars['css_loaded']) && $frm_vars['load_css'] ) {
|
34 |
-
echo FrmAppController::footer_js('header');
|
35 |
-
$frm_vars['css_loaded'] = true;
|
36 |
-
}
|
37 |
-
?>
|
38 |
-
<div class="frm_forms<?php echo ($values['custom_style']) ? ' with_frm_style' : ''; ?>" id="frm_form_<?php echo $form->id ?>_container"><?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php') ?></div>
|
39 |
-
<?php
|
40 |
-
}
|
41 |
-
} else {
|
42 |
-
do_action('frm_success_action', $conf_method, $form, $form->options, $created);
|
43 |
-
}
|
44 |
-
|
45 |
-
do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
|
46 |
-
}else{
|
47 |
-
do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
|
48 |
-
if (apply_filters('frm_continue_to_new', true, $form->id, $params['action'])){
|
49 |
-
$values = FrmEntriesHelper::setup_new_vars($fields, $form);
|
50 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
|
51 |
-
}
|
52 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/views/frm-entries/list.php
CHANGED
@@ -1,31 +1,34 @@
|
|
1 |
<div id="form_entries_page" class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
-
<h2
|
4 |
-
|
5 |
-
|
6 |
-
</h2>
|
7 |
|
8 |
-
<?php
|
9 |
-
|
10 |
-
<?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
|
11 |
-
<?php FrmAppController::update_message('view, search, export, and bulk delete your saved entries'); ?>
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
</div>
|
|
|
|
|
|
|
31 |
|
|
|
|
|
|
|
|
1 |
<div id="form_entries_page" class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
+
<h2><?php _e( 'Entries', 'formidable' ); ?>
|
4 |
+
<?php do_action('frm_entry_inside_h2', $form); ?>
|
5 |
+
</h2>
|
|
|
6 |
|
7 |
+
<?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
|
|
|
|
|
|
|
8 |
|
9 |
+
<form id="posts-filter" method="get">
|
10 |
+
<div id="poststuff">
|
11 |
+
<div id="post-body" class="metabox-holder columns-2">
|
12 |
+
<div id="post-body-content">
|
13 |
+
<?php FrmAppController::get_form_nav($form, true, 'hide'); ?>
|
14 |
+
</div>
|
15 |
+
<div id="postbox-container-1" class="postbox-container">
|
16 |
+
<input type="hidden" name="page" value="formidable-entries" />
|
17 |
+
<input type="hidden" name="form" value="<?php echo ($form) ? $form->id : ''; ?>" />
|
18 |
+
<input type="hidden" name="frm_action" value="list" />
|
19 |
+
<?php $wp_list_table->search_box( __( 'Search', 'formidable' ), 'entry' ); ?>
|
20 |
+
</div>
|
21 |
+
<div class="clear"></div>
|
22 |
+
</div>
|
23 |
+
<?php if ( $form ) { ?>
|
24 |
+
<div id="titlediv">
|
25 |
+
<input id="title" type="text" value="<?php echo esc_attr($form->name == '' ? __( '(no title)') : $form->name) ?>" readonly="readonly" disabled="disabled" />
|
26 |
+
</div>
|
27 |
+
<?php } ?>
|
28 |
+
|
29 |
+
<?php $wp_list_table->display(); ?>
|
30 |
|
31 |
+
</div>
|
32 |
+
</form>
|
33 |
+
|
34 |
+
</div>
|
classes/views/frm-entries/new.php
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
<?php
|
2 |
-
if(empty($values)
|
3 |
-
<div class="frm_forms
|
4 |
-
<div class="frm_error_style"><strong><?php _e('Oops!', 'formidable') ?></strong> <?php printf(__('You did not add any fields to your form. %1$sGo back%2$s and add some.', 'formidable'), '<a href="'. admin_url('?page=formidable&frm_action=edit&id='. $form->id) .'">', '</a>') ?>
|
5 |
</div>
|
6 |
-
</div>
|
7 |
<?php
|
8 |
return;
|
9 |
} ?>
|
10 |
-
<div class="frm_forms<?php echo ($values
|
11 |
-
<form enctype="<?php echo apply_filters('frm_form_enctype', 'multipart/form-data', $form) ?>" method="post" class="frm-show-form <?php do_action('frm_form_classes', $form) ?>" id="form_<?php echo $form->form_key ?>" <?php echo
|
12 |
-
<?php
|
13 |
include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
|
14 |
$form_action = 'create';
|
15 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/form.php');
|
16 |
?>
|
17 |
</form>
|
18 |
</div>
|
1 |
<?php
|
2 |
+
if ( empty($values) || ! isset($values['fields']) || empty($values['fields']) ) { ?>
|
3 |
+
<div class="frm_forms <?php echo FrmFormsHelper::get_form_style_class($form); ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container">
|
4 |
+
<div class="frm_error_style"><strong><?php _e( 'Oops!', 'formidable' ) ?></strong> <?php printf( __( 'You did not add any fields to your form. %1$sGo back%2$s and add some.', 'formidable' ), '<a href="'. admin_url('?page=formidable&frm_action=edit&id='. $form->id) .'">', '</a>' ) ?>
|
5 |
</div>
|
6 |
+
</div>
|
7 |
<?php
|
8 |
return;
|
9 |
} ?>
|
10 |
+
<div class="frm_forms <?php echo FrmFormsHelper::get_form_style_class($values); ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container">
|
11 |
+
<form enctype="<?php echo apply_filters('frm_form_enctype', 'multipart/form-data', $form) ?>" method="post" class="frm-show-form <?php do_action('frm_form_classes', $form) ?>" id="form_<?php echo esc_attr( $form->form_key ) ?>" <?php echo $frm_settings->use_html ? '' : 'action=""'; ?>>
|
12 |
+
<?php
|
13 |
include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
|
14 |
$form_action = 'create';
|
15 |
+
require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/form.php');
|
16 |
?>
|
17 |
</form>
|
18 |
</div>
|
classes/views/frm-entries/no_entries.php
CHANGED
@@ -1,48 +1,18 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
$
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
if(
|
8 |
-
<h3><?php _e('This form is not set to save any entries.', 'formidable') ?></h3>
|
9 |
-
<p>If you would like entries in this form to be saved, go to the <a href="<?php echo esc_url(admin_url('admin.php?page=formidable') . '&frm_action=settings&id='. $form->id) ?>">form Settings</a> page and uncheck the "Do not store any entries submitted from this form" box.</p>
|
10 |
-
<?php
|
11 |
-
}else{
|
12 |
?>
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
<li><?php _e('Select your form from the dropdown and check the boxes to show the title and description if desired.', 'formidable') ?></li>
|
24 |
-
<li><?php _e('Click the "Insert Form" button.', 'formidable') ?></li>
|
25 |
-
</ol>
|
26 |
-
</td></tr>
|
27 |
-
<tr><td colspan="<?php echo $colspan ?>">
|
28 |
-
<h3><?php _e('Option 2: Add a Widget', 'formidable') ?></h3>
|
29 |
-
<ol class="alignleft" style="margin-right:30px;">
|
30 |
-
<li><?php _e('Drag a "Formidable Form" widget into your sidebar.', 'formidable') ?></li>
|
31 |
-
<li><?php _e('Select a form from the "Form" drop-down.', 'formidable') ?></li>
|
32 |
-
<li><?php _e('Click the "Save" button', 'formidable') ?></li>
|
33 |
-
</ol>
|
34 |
-
<img src="<?php echo FrmAppHelper::plugin_url() ?>/screenshot-6.png" alt="<?php esc_attr_e('Formidable Form Widget', 'formidable') ?>" title="<?php esc_attr_e('Formidable Form Widget', 'formidable') ?>" height="261" width="252" />
|
35 |
-
</td></tr>
|
36 |
-
<tr class="alternate"><td colspan="<?php echo $colspan ?>">
|
37 |
-
<h3><?php _e('Option 3: Insert the shortcode or PHP', 'formidable') ?></h3>
|
38 |
-
<p><?php _e('Insert the following shortcode in your page, post, or text widget. This will be replaced with your form:', 'formidable') ?><br/>
|
39 |
-
<input type="text" readonly="true" class="frm_select_box frm_no_items" value="[formidable id=<?php echo $form->id; ?>]" />
|
40 |
-
</p>
|
41 |
-
<p><?php _e('Show the form with the title and description:', 'formidable') ?><br/>
|
42 |
-
<input type="text" readonly="true" class="frm_select_box frm_no_items" value="[formidable id=<?php echo $form->id; ?> title=true description=true]" />
|
43 |
-
</p>
|
44 |
-
|
45 |
-
<p><?php _e('Insert into a theme template file:', 'formidable') ?><br/>
|
46 |
-
<input type="text" readonly="true" class="frm_select_box frm_no_items" value="echo FrmFormsController::show_form(<?php echo $form->id; ?>, $key='', $title=true, $description=true);" />
|
47 |
-
</p>
|
48 |
-
<?php } ?>
|
1 |
+
<div class="frmcenter frm_no_entries_form">
|
2 |
+
<?php
|
3 |
+
if ( $form && isset($form->options['no_save']) && $form->options['no_save'] ) { ?>
|
4 |
+
<h3><?php _e( 'This form is not set to save any entries.', 'formidable' ) ?></h3>
|
5 |
+
<p>If you would like entries in this form to be saved, go to the <a href="<?php echo esc_url(admin_url('admin.php?page=formidable') . '&frm_action=settings&id='. $form->id) ?>">form Settings</a> page and uncheck the "Do not store any entries submitted from this form" box.</p>
|
6 |
+
<?php
|
7 |
+
} else if ( $form ) {
|
|
|
|
|
|
|
|
|
8 |
?>
|
9 |
+
<div class="frm_no_entries_header"><?php printf(__( 'No Entries for form: %s', 'formidable' ), $form->name); ?></div>
|
10 |
+
<p class="frm_no_entries_text"><?php printf( __( 'For instructions on publishing your form see %1$sthis page%2$s <br/> or click "%3$sAdd New%4$s" above to add an entry from here (Requires License)', 'formidable' ), '<a href="https://formidablepro.com/knowledgebase/publish-your-forms/" target="_blank">', '</a>', '<a href="'. admin_url('admin.php?page=formidable-entries&frm_action=new&form='. $form->id) .'">', '</a>'); ?></p>
|
11 |
+
<?php
|
12 |
+
} else {
|
13 |
+
?>
|
14 |
+
<div class="frm_no_entries_header"><?php _e( 'You have not created any forms yet.', 'formidable' ); ?></div>
|
15 |
+
<p class="frm_no_entries_text"><?php printf( __( 'To view entries, you must first %1$sbuild a form%2$s', 'formidable' ), '<a href="'. esc_url( admin_url( 'admin.php?page=formidable&frm_action=new' ) ) . '">', '</a>' ); ?></p>
|
16 |
+
<?php
|
17 |
+
} ?>
|
18 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/views/frm-entries/show.php
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="form_show_entry_page" class="wrap">
|
2 |
+
<div class="frmicon icon32"><br/></div>
|
3 |
+
<h2><?php _e( 'View Entry', 'formidable' ) ?>
|
4 |
+
<?php do_action('frm_entry_inside_h2', $entry->form_id); ?>
|
5 |
+
</h2>
|
6 |
+
|
7 |
+
<div class="frm_forms">
|
8 |
+
|
9 |
+
<div id="poststuff">
|
10 |
+
<div id="post-body" class="metabox-holder columns-2">
|
11 |
+
<div id="post-body-content">
|
12 |
+
<?php FrmAppController::get_form_nav($entry->form_id, true); ?>
|
13 |
+
<div class="postbox">
|
14 |
+
<h3 class="hndle"><span><?php _e( 'Entry', 'formidable' ) ?></span></h3>
|
15 |
+
<div class="inside">
|
16 |
+
<table class="form-table"><tbody>
|
17 |
+
<?php
|
18 |
+
$first_h3 = 'frm_first_h3';
|
19 |
+
foreach ( $fields as $field ) {
|
20 |
+
if ( in_array( $field->type, array( 'captcha', 'html', 'end_divider', 'form' ) ) ) {
|
21 |
+
continue;
|
22 |
+
}
|
23 |
+
|
24 |
+
if ( in_array($field->type, array( 'break', 'divider' ) ) ) {
|
25 |
+
?>
|
26 |
+
</tbody></table>
|
27 |
+
<br/><h3 class="<?php echo esc_attr( $first_h3 ) ?>"><?php echo esc_html( $field->name ) ?></h3>
|
28 |
+
<table class="form-table"><tbody>
|
29 |
+
<?php
|
30 |
+
$first_h3 = '';
|
31 |
+
} else {
|
32 |
+
?>
|
33 |
+
<tr>
|
34 |
+
<th scope="row"><?php echo esc_html( $field->name ) ?>:</th>
|
35 |
+
<td>
|
36 |
+
<?php
|
37 |
+
$embedded_field_id = ( $entry->form_id != $field->form_id ) ? 'form' . $field->form_id : 0;
|
38 |
+
$atts = array(
|
39 |
+
'type' => $field->type, 'post_id' => $entry->post_id,
|
40 |
+
'show_filename' => true, 'show_icon' => true, 'entry_id' => $entry->id,
|
41 |
+
'embedded_field_id' => $embedded_field_id,
|
42 |
+
);
|
43 |
+
echo $display_value = FrmEntriesHelper::prepare_display_value($entry, $field, $atts);
|
44 |
+
|
45 |
+
if ( is_email($display_value) && ! in_array($display_value, $to_emails) ) {
|
46 |
+
$to_emails[] = $display_value;
|
47 |
+
}
|
48 |
+
?>
|
49 |
+
</td>
|
50 |
+
</tr>
|
51 |
+
<?php }
|
52 |
+
}
|
53 |
+
|
54 |
+
?>
|
55 |
+
|
56 |
+
<?php if ( $entry->parent_item_id ) { ?>
|
57 |
+
<tr><th><?php _e( 'Parent Entry ID', 'formidable' ) ?>:</th>
|
58 |
+
<td><?php echo (int) $entry->parent_item_id ?>
|
59 |
+
</td></tr>
|
60 |
+
<?php } ?>
|
61 |
+
</tbody></table>
|
62 |
+
<?php do_action('frm_show_entry', $entry); ?>
|
63 |
+
</div>
|
64 |
+
</div>
|
65 |
+
|
66 |
+
<?php do_action('frm_after_show_entry', $entry); ?>
|
67 |
+
|
68 |
+
</div>
|
69 |
+
<?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/sidebar-show.php'); ?>
|
70 |
+
</div>
|
71 |
+
</div>
|
72 |
+
</div>
|
73 |
+
</div>
|
74 |
+
<br/>
|
classes/views/frm-entries/sidebar-shared.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
<div class="postbox frm_with_icons" >
|
3 |
+
<h3 class="hndle"><span><?php _e( 'Entry Details', 'formidable' ) ?></span></h3>
|
4 |
+
<div class="inside">
|
5 |
+
<?php if ( $entry->post_id ) { ?>
|
6 |
+
<div class="misc-pub-section">
|
7 |
+
<span class="dashicons dashicons-admin-post wp-media-buttons-icon"></span>
|
8 |
+
<?php _e( 'Post', 'formidable' ) ?>:
|
9 |
+
<b><?php echo get_the_title($entry->post_id) ?></b>
|
10 |
+
<span><a href="<?php echo esc_url( admin_url('post.php?post='. $entry->post_id .'&action=edit') ) ?>"><?php _e( 'Edit', 'formidable' ) ?></a>
|
11 |
+
<a href="<?php echo esc_url( get_permalink( $entry->post_id ) ) ?>"><?php _e( 'View', 'formidable' ) ?></a></span>
|
12 |
+
</div>
|
13 |
+
<?php } ?>
|
14 |
+
|
15 |
+
<div class="misc-pub-section">
|
16 |
+
<span class="dashicons dashicons-id wp-media-buttons-icon"></span>
|
17 |
+
<?php _e( 'Entry ID', 'formidable' ) ?>: <b><?php echo (int) $entry->id ?></b>
|
18 |
+
</div>
|
19 |
+
|
20 |
+
<div class="misc-pub-section">
|
21 |
+
<span class="dashicons dashicons-post-status wp-media-buttons-icon"></span>
|
22 |
+
<?php _e( 'Entry Key', 'formidable' ) ?>:
|
23 |
+
<b><?php echo $entry->item_key ?></b>
|
24 |
+
</div>
|
25 |
+
|
26 |
+
<?php if ( FrmAppHelper::pro_is_installed() ) { ?>
|
27 |
+
<?php if ( $entry->user_id ) { ?>
|
28 |
+
<div class="misc-pub-section">
|
29 |
+
<span class="dashicons dashicons-admin-users wp-media-buttons-icon"></span>
|
30 |
+
<?php printf(__( 'Created by: %1$s', 'formidable' ), FrmProFieldsHelper::get_display_name($entry->user_id, 'display_name', array( 'link' => true))); ?>
|
31 |
+
</div>
|
32 |
+
<?php } ?>
|
33 |
+
|
34 |
+
<?php if ( $entry->updated_by && $entry->updated_by != $entry->user_id ) { ?>
|
35 |
+
<div class="misc-pub-section">
|
36 |
+
<span class="dashicons dashicons-admin-users wp-media-buttons-icon"></span>
|
37 |
+
<?php printf(__( 'Updated by: %1$s', 'formidable' ), FrmProFieldsHelper::get_display_name($entry->updated_by, 'display_name', array( 'link' => true)) ); ?>
|
38 |
+
</div>
|
39 |
+
<?php } ?>
|
40 |
+
<?php } ?>
|
41 |
+
|
42 |
+
</div>
|
43 |
+
</div>
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
<div class="postbox">
|
48 |
+
<h3 class="hndle"><span><?php _e( 'User Information', 'formidable' ) ?></span></h3>
|
49 |
+
<div class="inside">
|
50 |
+
<div class="misc-pub-section">
|
51 |
+
<?php _e( 'IP Address', 'formidable' ) ?>:
|
52 |
+
<b><?php echo $entry->ip; ?></b>
|
53 |
+
</div>
|
54 |
+
|
55 |
+
<?php if ( isset($data['browser']) ) { ?>
|
56 |
+
<div class="misc-pub-section">
|
57 |
+
<b><?php _e( 'Browser/OS', 'formidable' ) ?></b>:<br/>
|
58 |
+
<?php echo FrmEntriesHelper::get_browser($data['browser']); ?>
|
59 |
+
</div>
|
60 |
+
<?php } ?>
|
61 |
+
|
62 |
+
<?php if ( isset($data['referrer']) ) { ?>
|
63 |
+
<div class="misc-pub-section">
|
64 |
+
<b><?php _e( 'Referrer', 'formidable' ) ?></b>:<br/>
|
65 |
+
<?php echo str_replace("\r\n", '<br/>', $data['referrer']); ?>
|
66 |
+
</div>
|
67 |
+
<?php } ?>
|
68 |
+
|
69 |
+
<?php
|
70 |
+
foreach ( (array) $data as $k => $d ) {
|
71 |
+
if ( in_array($k, array( 'browser', 'referrer')) ) {
|
72 |
+
continue;
|
73 |
+
}
|
74 |
+
?>
|
75 |
+
<div class="misc-pub-section">
|
76 |
+
<b><?php echo ucfirst(str_replace('-', ' ', $k)); ?></b>:
|
77 |
+
<?php echo implode(', ', (array) $d); ?>
|
78 |
+
</div>
|
79 |
+
<?php
|
80 |
+
unset($k, $d);
|
81 |
+
}
|
82 |
+
?>
|
83 |
+
</div>
|
84 |
+
</div>
|
classes/views/frm-entries/sidebar-show.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="postbox-container-1" class="postbox-container">
|
2 |
+
<div id="submitdiv" class="postbox">
|
3 |
+
<h3 class="hndle"><span><?php _e( 'Entry Actions', 'formidable' ) ?></span></h3>
|
4 |
+
<div class="inside">
|
5 |
+
<div class="submitbox">
|
6 |
+
<div id="minor-publishing" class="frm_remove_border">
|
7 |
+
<div class="misc-pub-section">
|
8 |
+
<?php do_action('frm_show_entry_publish_box', $entry); ?>
|
9 |
+
<div class="clear"></div>
|
10 |
+
</div>
|
11 |
+
<div id="misc-publishing-actions">
|
12 |
+
<?php include(dirname(__FILE__) .'/_sidebar-shared-pub.php'); ?>
|
13 |
+
<div class="misc-pub-section">
|
14 |
+
<span class="dashicons dashicons-format-aside wp-media-buttons-icon"></span>
|
15 |
+
<a href="#" onclick="window.print();return false;"><?php _e( 'Print', 'formidable' ) ?></a>
|
16 |
+
</div>
|
17 |
+
</div>
|
18 |
+
</div>
|
19 |
+
<div id="major-publishing-actions">
|
20 |
+
<?php if ( current_user_can('frm_delete_entries') ) { ?>
|
21 |
+
<div id="delete-action">
|
22 |
+
<a href="<?php echo esc_url( admin_url('admin.php?page=formidable-entries&frm_action=destroy&id='. $id .'&form='. $entry->form_id) ) ?>" class="submitdelete deletion" onclick="return confirm('<?php _e( 'Are you sure you want to delete that entry?', 'formidable' ) ?>');" title="<?php esc_attr_e( 'Delete' ) ?>"><?php _e( 'Delete' ) ?></a>
|
23 |
+
<?php if ( ! empty($entry->post_id) ) { ?>
|
24 |
+
<a href="<?php echo esc_url( admin_url('admin.php?page=formidable-entries&frm_action=destroy&id='. $id .'&form='. $entry->form_id .'&keep_post=1') ) ?>" class="submitdelete deletion frm_delete_wo_post" onclick="return confirm('<?php esc_attr_e( 'Are you sure you want to delete this entry?', 'formidable' ) ?>);" title="<?php esc_attr_e( 'Delete entry but leave the post', 'formidable' ) ?>"><?php _e( 'Delete without Post', 'formidable' ) ?></a>
|
25 |
+
<?php } ?>
|
26 |
+
</div>
|
27 |
+
<?php } ?>
|
28 |
+
|
29 |
+
<?php do_action('frm_entry_major_pub', $entry); ?>
|
30 |
+
<div class="clear"></div>
|
31 |
+
</div>
|
32 |
+
</div>
|
33 |
+
</div>
|
34 |
+
</div>
|
35 |
+
<?php do_action('frm_show_entry_sidebar', $entry);
|
36 |
+
FrmEntriesController::entry_sidebar($entry);
|
37 |
+
?>
|
38 |
+
</div>
|
classes/views/frm-fields/import_choices.php
CHANGED
@@ -3,82 +3,54 @@
|
|
3 |
<head>
|
4 |
<meta charset="<?php bloginfo( 'charset' ); ?>" />
|
5 |
<title><?php bloginfo('name'); ?></title>
|
6 |
-
<?php
|
7 |
wp_admin_css( 'global' );
|
8 |
wp_admin_css();
|
9 |
wp_admin_css( 'colors' );
|
10 |
wp_admin_css( 'ie' );
|
11 |
-
|
12 |
wp_admin_css( 'ms' );
|
13 |
-
|
14 |
|
15 |
do_action('admin_print_styles');
|
16 |
do_action('admin_print_scripts');
|
17 |
-
|
18 |
-
?>
|
19 |
-
<style type="text/css">
|
20 |
-
#wpadminbar{display:none;}
|
21 |
-
.prepop{
|
22 |
-
float:left;
|
23 |
-
width:235px;
|
24 |
-
list-style:none;
|
25 |
-
overflow:auto;
|
26 |
-
border-right: 2px solid #DEDEDE;
|
27 |
-
padding-right:10px;
|
28 |
-
margin:0;
|
29 |
-
}
|
30 |
-
.prepop li{
|
31 |
-
margin: 0 0 3px;
|
32 |
-
}
|
33 |
|
34 |
-
|
35 |
-
background:#F5F5F5;
|
36 |
-
border:1px solid #EEEEEE;
|
37 |
-
border-color:#EEEEEE #DEDEDE #DEDEDE #EEEEEE;
|
38 |
-
display: block;
|
39 |
-
font-weight: bold;
|
40 |
-
height: 30px;
|
41 |
-
line-height: 30px;
|
42 |
-
margin: 0 10px 0 0;
|
43 |
-
text-align: center;
|
44 |
-
text-decoration: none;
|
45 |
-
cursor:pointer;
|
46 |
-
}
|
47 |
-
</style>
|
48 |
</head>
|
49 |
-
<body class="wp-admin no-js wp-core-ui <?php echo apply_filters( 'admin_body_class', '' ) . " $admin_body_class"; ?>"
|
50 |
-
<div
|
51 |
-
<p class="howto"><?php _e('Edit or add field options (one per line)', 'formidable') ?></p>
|
52 |
-
<ul class="
|
53 |
-
|
54 |
-
<li><a onclick='frmPrePop(<?php echo str_replace("'", '‘', json_encode($pop)) ?>); return false;'><?php echo $label ?></a></li>
|
55 |
<?php } ?>
|
56 |
</ul>
|
57 |
-
<textarea name="frm_bulk_options" id="frm_bulk_options"
|
58 |
-
<?php
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
if(
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
} ?>
|
70 |
</textarea>
|
71 |
|
72 |
<p class="submit clear">
|
73 |
-
<input type="button" onclick="
|
74 |
</p>
|
75 |
</div>
|
76 |
|
77 |
-
<script type="text/javascript">
|
78 |
-
function frmPrePop(opts){
|
79 |
-
jQuery('#frm_bulk_options').val(opts.join("\n"));
|
80 |
-
return false;
|
81 |
-
}
|
82 |
-
</script>
|
83 |
</body>
|
84 |
</html>
|
3 |
<head>
|
4 |
<meta charset="<?php bloginfo( 'charset' ); ?>" />
|
5 |
<title><?php bloginfo('name'); ?></title>
|
6 |
+
<?php
|
7 |
wp_admin_css( 'global' );
|
8 |
wp_admin_css();
|
9 |
wp_admin_css( 'colors' );
|
10 |
wp_admin_css( 'ie' );
|
11 |
+
if ( is_multisite() ) {
|
12 |
wp_admin_css( 'ms' );
|
13 |
+
}
|
14 |
|
15 |
do_action('admin_print_styles');
|
16 |
do_action('admin_print_scripts');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</head>
|
20 |
+
<body class="wp-admin no-js wp-core-ui frm_field_opts_popup <?php echo apply_filters( 'admin_body_class', '' ) . " $admin_body_class"; ?>">
|
21 |
+
<div class="frm_med_padding">
|
22 |
+
<p class="howto"><?php _e( 'Edit or add field options (one per line)', 'formidable' ) ?></p>
|
23 |
+
<ul class="frm_prepop">
|
24 |
+
<?php foreach ( $prepop as $label => $pop ) { ?>
|
25 |
+
<li><a href="javascript:void(0)" onclick='frmPrePop(<?php echo str_replace("'", '‘', json_encode($pop)) ?>); return false;'><?php echo esc_html( $label ) ?></a></li>
|
26 |
<?php } ?>
|
27 |
</ul>
|
28 |
+
<textarea name="frm_bulk_options" id="frm_bulk_options">
|
29 |
+
<?php
|
30 |
+
$other_array = array();
|
31 |
+
foreach ( $field->options as $fkey => $fopt ) {
|
32 |
+
//If it is an other option, don't include it
|
33 |
+
if ( $fkey && strpos( $fkey, 'other') !== false ) {
|
34 |
+
continue;
|
35 |
+
}
|
36 |
+
if ( is_array( $fopt ) ) {
|
37 |
+
$label = (isset($fopt['label'])) ? $fopt['label'] : reset($fopt);
|
38 |
+
$value = (isset($fopt['value'])) ? $fopt['value'] : $label;
|
39 |
+
if ( $label != $value && isset($field->field_options['separate_value']) && $field->field_options['separate_value'] ) {
|
40 |
+
echo "$label|$value\n";
|
41 |
+
} else{
|
42 |
+
echo $label ."\n";
|
43 |
+
}
|
44 |
+
}else{
|
45 |
+
echo $fopt ."\n";
|
46 |
+
}
|
47 |
} ?>
|
48 |
</textarea>
|
49 |
|
50 |
<p class="submit clear">
|
51 |
+
<input type="button" onclick="frmUpdateBulkOpts(<?php echo (int) $field->id ?>)" class="button-primary" value="<?php esc_attr_e( 'Update Field Choices', 'formidable' ) ?>" />
|
52 |
</p>
|
53 |
</div>
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
</body>
|
56 |
</html>
|
classes/views/frm-fields/input.php
CHANGED
@@ -1,105 +1,154 @@
|
|
1 |
-
<?php if ($field['type']
|
2 |
-
<input type="text" id="
|
3 |
<?php }else if ($field['type'] == 'textarea'){ ?>
|
4 |
-
<textarea name="<?php echo $field_name ?>" id="
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
}else if ($field['type'] == 'radio'){
|
8 |
if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
|
9 |
-
do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
|
10 |
} else if ( is_array($field['options']) ) {
|
11 |
foreach ( $field['options'] as $opt_key => $opt ) {
|
12 |
-
if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key)
|
13 |
continue;
|
14 |
}
|
15 |
-
|
16 |
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
|
17 |
-
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
|
18 |
-
|
19 |
-
<div class="<?php echo apply_filters('frm_radio_class', 'frm_radio', $field, $field_val)?>"><?php
|
20 |
|
21 |
-
|
22 |
-
?><label for="
|
23 |
}
|
24 |
-
|
25 |
-
?><input type="radio" name="<?php echo $field_name ?>" id="field_<?php echo $field['id'] ?>-<?php echo $opt_key ?>" value="<?php echo esc_attr($field_val) ?>" <?php echo (FrmAppHelper::check_selected($field['value'], $field_val)) ? 'checked="checked"' : ''; ?> <?php do_action('frm_field_input_html', $field) ?>/><?php
|
26 |
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
echo ' '. $opt .'</label>';
|
29 |
-
}
|
|
|
|
|
|
|
|
|
|
|
30 |
?></div>
|
31 |
<?php
|
32 |
}
|
33 |
}
|
34 |
-
|
35 |
-
|
36 |
-
if(isset($field['post_field'])
|
37 |
-
echo FrmFieldsHelper::dropdown_categories(array('name' => $field_name, 'field' => $field) );
|
38 |
-
}else{
|
39 |
-
if ( isset($field['read_only']) && $field['read_only'] && (!isset($frm_vars['readonly']) || $frm_vars['readonly'] != 'disabled') &&
|
40 |
-
|
|
|
41 |
<select disabled="disabled" <?php do_action('frm_field_input_html', $field) ?>>
|
42 |
-
<?php }else{ ?>
|
43 |
-
<select name="<?php echo $field_name ?>" id="
|
44 |
-
<?php }
|
45 |
-
foreach ($field['options'] as $opt_key => $opt){
|
46 |
-
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
|
47 |
-
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); ?>
|
48 |
-
<option value="<?php echo esc_attr($field_val) ?>" <?php
|
49 |
-
if (FrmAppHelper::check_selected($field['value'], $field_val)) echo ' selected="selected"'; ?>><?php echo ($opt == '') ? ' ' : $opt; ?></option>
|
50 |
-
<?php } ?>
|
51 |
-
</select>
|
52 |
-
<?php }
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
}else if ($field['type'] == 'checkbox'){
|
55 |
$checked_values = $field['value'];
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
} else if ( $field['options'] ) {
|
60 |
foreach ( $field['options'] as $opt_key => $opt ) {
|
61 |
if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) {
|
62 |
continue;
|
63 |
}
|
64 |
-
|
65 |
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
|
66 |
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
|
67 |
$checked = FrmAppHelper::check_selected($checked_values, $field_val) ? ' checked="checked"' : '';
|
68 |
-
|
|
|
|
|
|
|
|
|
69 |
?>
|
70 |
-
<div class="<?php echo apply_filters('frm_checkbox_class', 'frm_checkbox', $field, $field_val) ?>" id="frm_checkbox_<?php echo $field['id']?>-<?php echo $opt_key ?>"><?php
|
71 |
|
72 |
-
if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
|
73 |
-
?><label for="
|
74 |
}
|
75 |
-
|
76 |
-
?><input type="checkbox" name="<?php echo $field_name ?>[]" id="
|
77 |
-
|
78 |
-
if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
|
79 |
echo ' '. $opt .'</label>';
|
80 |
}
|
81 |
-
|
82 |
-
?></div>
|
83 |
-
<?php
|
84 |
-
}
|
85 |
-
}
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
$error_msg = null;
|
90 |
-
|
91 |
-
if ( !empty($errors) ) {
|
92 |
-
foreach ( $errors as $error_key => $error ) {
|
93 |
-
if ( strpos($error_key, 'captcha-') === 0 ) {
|
94 |
-
$error_msg = preg_replace('/^captcha-/', '', $error_key);
|
95 |
}
|
96 |
-
|
|
|
|
|
|
|
|
|
97 |
}
|
98 |
}
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
102 |
}
|
103 |
} else {
|
104 |
-
do_action('frm_form_fields', $field, $field_name);
|
105 |
}
|
1 |
+
<?php if ( in_array($field['type'], array( 'email', 'url', 'text')) ) { ?>
|
2 |
+
<input type="<?php echo ( $frm_settings->use_html || $field['type'] == 'password' ) ? $field['type'] : 'text'; ?>" id="<?php echo esc_attr( $html_id ) ?>" name="<?php echo esc_attr( $field_name ) ?>" value="<?php echo esc_attr( $field['value'] ) ?>" <?php do_action('frm_field_input_html', $field) ?>/>
|
3 |
<?php }else if ($field['type'] == 'textarea'){ ?>
|
4 |
+
<textarea name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" <?php
|
5 |
+
if ( $field['max'] ) {
|
6 |
+
echo 'rows="'. esc_attr( $field['max'] ) .'" ';
|
7 |
+
}
|
8 |
+
do_action('frm_field_input_html', $field);
|
9 |
+
?>><?php echo FrmAppHelper::esc_textarea($field['value']) ?></textarea>
|
10 |
+
<?php
|
11 |
+
|
12 |
+
} else if ( $field['type'] == 'radio' ) {
|
13 |
+
$read_only = false;
|
14 |
+
if ( isset($field['read_only']) && $field['read_only'] && ( ! isset($frm_vars['readonly']) || $frm_vars['readonly'] != 'disabled') && ! FrmAppHelper::is_admin() ) {
|
15 |
+
$read_only = true; ?>
|
16 |
+
<input type="hidden" value="<?php echo esc_attr( $field['value'] ) ?>" name="<?php echo esc_attr( $field_name ) ?>" />
|
17 |
+
<?php
|
18 |
+
}
|
19 |
|
|
|
20 |
if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
|
21 |
+
do_action('frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
|
22 |
} else if ( is_array($field['options']) ) {
|
23 |
foreach ( $field['options'] as $opt_key => $opt ) {
|
24 |
+
if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key)) {
|
25 |
continue;
|
26 |
}
|
27 |
+
|
28 |
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
|
29 |
+
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); ?>
|
30 |
+
<div class="<?php echo apply_filters('frm_radio_class', 'frm_radio', $field, $field_val)?>"><?php
|
|
|
31 |
|
32 |
+
if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) {
|
33 |
+
?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php
|
34 |
}
|
35 |
+
$checked = FrmAppHelper::check_selected($field['value'], $field_val) ? 'checked="checked" ' : ' ';
|
|
|
36 |
|
37 |
+
$other_opt = false;
|
38 |
+
$other_args = FrmAppHelper::prepare_other_input( $field, $other_opt, $checked, array( 'field_name' => $field_name, 'opt_key' => $opt_key ) );
|
39 |
+
?>
|
40 |
+
<input type="radio" name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php
|
41 |
+
echo $checked;
|
42 |
+
do_action('frm_field_input_html', $field);
|
43 |
+
?>/><?php
|
44 |
+
|
45 |
+
if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) {
|
46 |
echo ' '. $opt .'</label>';
|
47 |
+
}
|
48 |
+
|
49 |
+
if ( $other_opt ) { ?>
|
50 |
+
<input type="text" <?php echo ( $read_only ? ' readonly="readonly" disabled="disabled"' : '' ); ?> class="frm_other_input <?php echo ( $checked != ' ' ? '' : ' frm_pos_none' ); ?>" name="<?php echo esc_attr( $other_args['name'] ) ?>" value="<?php echo esc_attr( $other_args['value'] ); ?>"><?php
|
51 |
+
}
|
52 |
+
unset( $other_opt, $other_args );
|
53 |
?></div>
|
54 |
<?php
|
55 |
}
|
56 |
}
|
57 |
+
}else if ($field['type'] == 'select'){
|
58 |
+
$read_only = false;
|
59 |
+
if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
|
60 |
+
echo FrmFieldsHelper::dropdown_categories( array( 'name' => $field_name, 'field' => $field) );
|
61 |
+
}else{
|
62 |
+
if ( isset( $field['read_only'] ) && $field['read_only'] && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) && ! FrmAppHelper::is_admin() ) {
|
63 |
+
$read_only = true; ?>
|
64 |
+
<input type="hidden" value="<?php echo esc_attr($field['value']) ?>" name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" />
|
65 |
<select disabled="disabled" <?php do_action('frm_field_input_html', $field) ?>>
|
66 |
+
<?php }else{ ?>
|
67 |
+
<select name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" <?php do_action('frm_field_input_html', $field) ?>>
|
68 |
+
<?php }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
$other_opt = $other_checked = false;
|
71 |
+
foreach ( $field['options'] as $opt_key => $opt ) {
|
72 |
+
$field_val = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field );
|
73 |
+
$opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field );
|
74 |
+
$selected = FrmAppHelper::check_selected( $field['value'], $field_val );
|
75 |
+
if ( $other_opt === false ) {
|
76 |
+
$other_args = FrmAppHelper::prepare_other_input( $field, $other_opt, $selected, array( 'field_name' => $field_name, 'opt_key' => $opt_key ) );
|
77 |
+
if ( FrmAppHelper::is_other_opt( $opt_key ) && $selected ) {
|
78 |
+
$other_checked = true;
|
79 |
+
}
|
80 |
+
}
|
81 |
+
?>
|
82 |
+
<option value="<?php echo esc_attr($field_val) ?>" <?php echo $selected ? ' selected="selected"' : ''; ?><?php echo ( FrmAppHelper::is_other_opt( $opt_key ) ) ? ' class="frm_other_trigger"' : '';?>><?php echo ($opt == '') ? ' ' : $opt; ?></option>
|
83 |
+
<?php
|
84 |
+
} ?>
|
85 |
+
</select>
|
86 |
+
<?php
|
87 |
+
if ( $other_opt ) { ?>
|
88 |
+
<input type="text" <?php echo ( $read_only ? 'readonly="readonly" disabled="disabled"' : '' );?> class="frm_other_input<?php echo ( $other_checked ? '' : ' frm_pos_none' ); echo ( $field['multiple'] ? ' frm_other_full' : '' ); ?>" name="<?php echo esc_attr( $other_args['name'] ) ?>" value="<?php echo esc_attr($other_args['value']);?>"><?php
|
89 |
+
}
|
90 |
+
}
|
91 |
}else if ($field['type'] == 'checkbox'){
|
92 |
$checked_values = $field['value'];
|
93 |
+
$read_only = false;
|
94 |
+
|
95 |
+
if ( isset($field['read_only']) && $field['read_only'] && ( ! isset($frm_vars['readonly']) || $frm_vars['readonly'] != 'disabled') && ! FrmAppHelper::is_admin() ) {
|
96 |
+
$read_only = true;
|
97 |
+
if ( $checked_values ) {
|
98 |
+
foreach ( (array) $checked_values as $checked_value ) { ?>
|
99 |
+
<input type="hidden" value="<?php echo esc_attr( $checked_value ) ?>" name="<?php echo esc_attr( $field_name ) ?>[]" />
|
100 |
+
<?php
|
101 |
+
}
|
102 |
+
} else { ?>
|
103 |
+
<input type="hidden" value="<?php echo esc_attr( $checked_values ) ?>" name="<?php echo esc_attr( $field_name ) ?>[]" />
|
104 |
+
<?php
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
|
109 |
+
do_action('frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
|
110 |
} else if ( $field['options'] ) {
|
111 |
foreach ( $field['options'] as $opt_key => $opt ) {
|
112 |
if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) {
|
113 |
continue;
|
114 |
}
|
115 |
+
|
116 |
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
|
117 |
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
|
118 |
$checked = FrmAppHelper::check_selected($checked_values, $field_val) ? ' checked="checked"' : '';
|
119 |
+
|
120 |
+
// Check if other opt, and get values for other field if needed
|
121 |
+
$other_opt = false;
|
122 |
+
$other_args = FrmAppHelper::prepare_other_input( $field, $other_opt, $checked, array( 'field_name' => $field_name, 'opt_key' => $opt_key ) );
|
123 |
+
|
124 |
?>
|
125 |
+
<div class="<?php echo esc_attr( apply_filters( 'frm_checkbox_class', 'frm_checkbox', $field, $field_val ) ) ?>" id="frm_checkbox_<?php echo esc_attr( $field['id'] ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php
|
126 |
|
127 |
+
if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) {
|
128 |
+
?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php
|
129 |
}
|
130 |
+
|
131 |
+
?><input type="checkbox" name="<?php echo esc_attr( $field_name ) ?>[<?php echo ( $other_opt ? esc_attr( $opt_key ) : '' ) ?>]" id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php echo $checked ?> <?php do_action('frm_field_input_html', $field) ?> /><?php
|
132 |
+
|
133 |
+
if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) {
|
134 |
echo ' '. $opt .'</label>';
|
135 |
}
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
+
if ( $other_opt ) { ?>
|
138 |
+
<input type="text" <?php echo ( $read_only ? ' readonly="readonly" disabled="disabled"' : '' );?> class="frm_other_input <?php echo ( $checked ? '' : 'frm_pos_none' ); ?>" name="<?php echo esc_attr( $other_args['name'] ) ?>" value="<?php echo esc_attr( $other_args['value'] );?>"><?php
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
}
|
140 |
+
|
141 |
+
unset( $other_opt, $other_args, $checked );
|
142 |
+
|
143 |
+
?></div>
|
144 |
+
<?php
|
145 |
}
|
146 |
}
|
147 |
+
} else if ( $field['type'] == 'captcha' && ! FrmAppHelper::is_admin() ) {
|
148 |
+
$frm_settings = FrmAppHelper::get_settings();
|
149 |
+
if ( ! empty($frm_settings->pubkey) ) {
|
150 |
+
FrmFieldsHelper::display_recaptcha($field);
|
151 |
}
|
152 |
} else {
|
153 |
+
do_action('frm_form_fields', $field, $field_name, compact('errors', 'html_id'));
|
154 |
}
|
classes/views/frm-fields/radio.php
CHANGED
@@ -1,12 +1,22 @@
|
|
1 |
<?php
|
2 |
-
if (is_array($field['options'])){
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
}
|
12 |
-
?>
|
1 |
<?php
|
2 |
+
if ( ! is_array($field['options']) ) {
|
3 |
+
return;
|
4 |
+
}
|
5 |
+
|
6 |
+
foreach ( $field['options'] as $opt_key => $opt ) {
|
7 |
+
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
|
8 |
+
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
|
9 |
+
|
10 |
+
// Get string for Other text field, if needed
|
11 |
+
$other_val = FrmAppHelper::get_other_val( $opt_key, $field );
|
12 |
+
|
13 |
+
$checked = ( $other_val || isset($field['value']) && (( ! is_array($field['value']) && $field['value'] == $field_val ) || (is_array($field['value']) && in_array($field_val, $field['value']) ) ) ) ? ' checked="checked"':'';
|
14 |
+
|
15 |
+
if ( FrmAppHelper::is_other_opt( $opt_key ) ) {
|
16 |
+
include(FrmAppHelper::plugin_path() .'/pro/classes/views/frmpro-fields/other-option.php');
|
17 |
+
} else {
|
18 |
include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
|
19 |
+
}
|
20 |
+
|
21 |
+
unset($checked, $other_val);
|
22 |
}
|
|
classes/views/frm-fields/show-build.php
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if ( in_array($display['type'], array( 'text', 'website', 'email', 'url') ) ) { ?>
|
2 |
+
<input type="text" name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" value="<?php echo esc_attr( $field['default_value'] ); ?>" <?php echo ( isset($field['size']) && $field['size'] ) ? esc_attr( 'style="width:'. $field['size'] . ( is_numeric($field['size']) ? 'px' : '') .';"' ) : ''; ?> class="dyn_default_value" />
|
3 |
+
<?php }else if ($field['type'] == 'textarea'){ ?>
|
4 |
+
<textarea name="<?php echo esc_attr( $field_name ) ?>" <?php
|
5 |
+
echo ( isset($field['size']) && $field['size'] ) ? esc_attr( 'style="width:'. $field['size'] . ( is_numeric($field['size']) ? 'px' : '') .';"' ) : '';
|
6 |
+
?> rows="<?php echo esc_attr( $field['max'] ); ?>" id="<?php echo esc_attr( $html_id ) ?>" class="dyn_default_value"><?php echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value'])); ?></textarea>
|
7 |
+
|
8 |
+
<?php
|
9 |
+
|
10 |
+
} else if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
|
11 |
+
$field['default_value'] = maybe_unserialize($field['default_value']);
|
12 |
+
if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
|
13 |
+
do_action('frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
|
14 |
+
} else {
|
15 |
+
do_action('frm_add_multiple_opts_labels', $field); ?>
|
16 |
+
<ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts clear<?php echo (count($field['options']) > 10) ? ' frm_field_opts_list' : ''; ?>">
|
17 |
+
<?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php'); ?>
|
18 |
+
</ul>
|
19 |
+
<?php
|
20 |
+
}
|
21 |
+
} else if ( $field['type'] == 'select' ) {
|
22 |
+
if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
|
23 |
+
echo FrmFieldsHelper::dropdown_categories( array( 'name' => $field_name, 'field' => $field) );
|
24 |
+
} else { ?>
|
25 |
+
<select name="<?php echo esc_attr( $field_name ) . ( ( isset($field['multiple']) && $field['multiple']) ? '[]' : '' ); ?>" <?php
|
26 |
+
echo ( isset($field['size']) && $field['size'] ) ? 'class="auto_width"' : '';
|
27 |
+
echo ( isset($field['multiple']) && $field['multiple'] ) ? ' multiple="multiple"' : ''; ?> >
|
28 |
+
<?php foreach ( $field['options'] as $opt_key => $opt ) {
|
29 |
+
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
|
30 |
+
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
|
31 |
+
$selected = ($field['default_value'] == $field_val || FrmAppHelper::get_other_val( $opt_key, $field ) )?(' selected="selected"'):(''); ?>
|
32 |
+
<option value="<?php echo esc_attr( $field_val ) ?>"<?php echo $selected ?>><?php echo esc_html( $opt ) ?> </option>
|
33 |
+
<?php } ?>
|
34 |
+
</select>
|
35 |
+
<?php }
|
36 |
+
|
37 |
+
if ( $display['default_blank'] ) { ?>
|
38 |
+
<span id="frm_clear_on_focus_<?php echo esc_attr( $field['id'] ) ?>" class="frm_clear_on_focus frm-show-click">
|
39 |
+
<?php FrmFieldsHelper::show_default_blank_js($field['default_blank']); ?>
|
40 |
+
</span>
|
41 |
+
<?php } ?>
|
42 |
+
<div class="clear"></div>
|
43 |
+
<div class="frm-show-click frm_small_top_margin">
|
44 |
+
<?php
|
45 |
+
|
46 |
+
if ( ! isset($field['post_field']) || ! in_array($field['post_field'], array( 'post_status', 'post_category')) ) { ?>
|
47 |
+
<?php do_action('frm_add_multiple_opts_labels', $field); ?>
|
48 |
+
<ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts<?php echo ( count($field['options']) > 10 ) ? ' frm_field_opts_list' : ''; ?>">
|
49 |
+
<?php FrmFieldsHelper::show_single_option($field); ?>
|
50 |
+
</ul>
|
51 |
+
<?php
|
52 |
+
} ?>
|
53 |
+
</div>
|
54 |
+
<?php
|
55 |
+
} else if ($field['type'] == 'captcha' ) {
|
56 |
+
?>
|
57 |
+
<?php if ( empty($frm_settings->pubkey) ) { ?>
|
58 |
+
<div class="howto frm_no_captcha_text"><?php printf(__( 'Your captcha will not appear on your form until you %1$sset up%2$s the Site and Private Keys', 'formidable' ), '<a href="?page=formidable-settings">', '</a>') ?></div>
|
59 |
+
<?php } ?>
|
60 |
+
<input type="hidden" name="<?php echo esc_attr( $field_name ) ?>" value="1" />
|
61 |
+
<?php
|
62 |
+
} else {
|
63 |
+
do_action( 'frm_display_added_fields', $field );
|
64 |
+
}
|
classes/views/frm-fields/show.php
CHANGED
@@ -1 +1,4 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
_deprecated_file( basename(__FILE__), '1.07.11', 'FrmFieldsHelper::replace_shortcodes' );
|
3 |
+
|
4 |
+
echo FrmFieldsHelper::replace_shortcodes($field['custom_html'], $field, $errors, $form);
|
classes/views/frm-fields/single-option.php
CHANGED
@@ -1,16 +1,12 @@
|
|
1 |
-
<
|
2 |
-
<a href="javascript:void(0)" class="frm_single_visible_hover frm_icon_font frm_delete_icon"> </a>
|
3 |
-
<?php if ($field['type'] != 'select'){ ?>
|
4 |
-
<input type="<?php echo $field['type'] ?>" name="<?php echo $field_name ?><?php echo ($field['type'] == 'checkbox')?'[]':''; ?>" value="<?php echo esc_attr($field_val) ?>"<?php echo isset($checked)? $checked : ''; ?>/>
|
5 |
-
<?php } ?>
|
6 |
-
<label class="frm_ipe_field_option field_<?php echo $field['id']?>_option <?php echo $field['separate_value'] ? 'frm_with_key' : ''; ?>" id="
|
7 |
-
<span class="frm_option_key field_<?php echo $field['id']?>_option_key
|
8 |
-
<label class="frm-show-click frm_ipe_field_option_key" id="field_key_<?php echo $field['id']?>-<?php echo $opt_key ?>"><?php echo ($field_val == '') ? __('(Blank)', 'formidable') : $field_val ?></label>
|
9 |
-
</span>
|
10 |
-
</
|
11 |
-
<div class="clear"></div>
|
12 |
<?php
|
13 |
-
unset($field_val);
|
14 |
-
unset($opt);
|
15 |
-
unset($opt_key);
|
16 |
-
?>
|
1 |
+
<li id="frm_delete_field_<?php echo esc_attr( $field['id'] ); ?>-<?php echo esc_attr( $opt_key ) ?>_container" class="frm_single_option">
|
2 |
+
<a href="javascript:void(0)" class="frm_single_visible_hover frm_icon_font frm_delete_icon" data-fid="<?php echo esc_attr( $field['id'] ); ?>"> </a>
|
3 |
+
<?php if ( $field['type'] != 'select' ) { ?>
|
4 |
+
<input type="<?php echo esc_attr( $field['type'] ) ?>" name="<?php echo esc_attr( $field_name ) ?><?php echo ( $field['type'] == 'checkbox' ) ? '[]' : ''; ?>" value="<?php echo esc_attr($field_val) ?>"<?php echo isset( $checked ) ? $checked : ''; ?>/>
|
5 |
+
<?php } ?>
|
6 |
+
<label class="frm_ipe_field_option field_<?php echo esc_attr( $field['id'] ) ?>_option <?php echo $field['separate_value'] ? 'frm_with_key' : ''; ?>" id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php echo ($opt == '') ? __( '(Blank)', 'formidable' ) : $opt ?></label>
|
7 |
+
<span class="frm_option_key field_<?php echo esc_attr( $field['id'] ) ?>_option_key<?php echo $field['separate_value'] ? '' : ' frm_hidden'; ?>">
|
8 |
+
<label class="frm-show-click frm_ipe_field_option_key" id="field_key_<?php echo esc_attr( $field['id'] ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php echo ( $field_val == '' ) ? __( '(Blank)', 'formidable' ) : $field_val ?></label>
|
9 |
+
</span>
|
10 |
+
</li>
|
|
|
11 |
<?php
|
12 |
+
unset($field_val, $opt, $opt_key);
|
|
|
|
|
|
classes/views/frm-form-actions/_action_inside.php
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('post_excerpt', '') ) ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" />
|
2 |
+
<input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('ID', '') ) ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" />
|
3 |
+
|
4 |
+
<table class="form-table">
|
5 |
+
<tr>
|
6 |
+
<th>
|
7 |
+
<label <?php FrmAppHelper::maybe_add_tooltip('action_title') ?>><?php _e( 'Label', 'formidable' ) ?></label>
|
8 |
+
</th>
|
9 |
+
<td><input type="text" name="<?php echo esc_attr( $action_control->get_field_name('post_title', '') ) ?>" value="<?php echo esc_attr($form_action->post_title); ?>" class="large-text <?php FrmAppHelper::maybe_add_tooltip('action_title', 'open') ?>" id="<?php echo esc_attr( $action_control->get_field_id('action_post_title') ) ?>" />
|
10 |
+
</td>
|
11 |
+
</tr>
|
12 |
+
</table>
|
13 |
+
<?php $action_control->form($form_action, compact('form', 'action_key', 'values')); ?>
|
14 |
+
|
15 |
+
<table class="form-table frm-no-margin">
|
16 |
+
<tr><td>
|
17 |
+
<?php
|
18 |
+
if ( ! isset( $action_control->action_options['event'] ) ) {
|
19 |
+
$events = 'create';
|
20 |
+
}
|
21 |
+
|
22 |
+
if ( ! is_array( $action_control->action_options['event'] ) ) {
|
23 |
+
$action_control->action_options['event'] = explode( ',', $action_control->action_options['event'] );
|
24 |
+
}
|
25 |
+
|
26 |
+
if ( count( $action_control->action_options['event'] ) == 1 || $action_control->action_options['force_event'] ) {
|
27 |
+
foreach ( $action_control->action_options['event'] as $e ) { ?>
|
28 |
+
<input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('event') ) ?>[]" value="<?php echo esc_attr( $e ) ?>" />
|
29 |
+
<?php
|
30 |
+
}
|
31 |
+
} else {
|
32 |
+
?>
|
33 |
+
<p><label><?php _e( 'Trigger this action after', 'formidable' ) ?></label>
|
34 |
+
<?php
|
35 |
+
$event_labels = array(
|
36 |
+
'create' => __( 'Create', 'formidable' ),
|
37 |
+
'update' => __( 'Update', 'formidable' ),
|
38 |
+
'delete' => __( 'Delete', 'formidable' ),
|
39 |
+
);
|
40 |
+
|
41 |
+
foreach ( $action_control->action_options['event'] as $event ) { ?>
|
42 |
+
<label for="frm_action_event_<?php echo esc_attr( $event ) ?>" class="frm_action_events">
|
43 |
+
<input type="checkbox" name="<?php echo esc_attr( $action_control->get_field_name('event') ) ?>[]" value="<?php echo esc_attr( $event ) ?>" id="<?php echo esc_attr( $action_control->get_field_id('frm_action_event_'. $event) ) ?>" <?php FrmAppHelper::checked($form_action->post_content['event'], $event) ?> />
|
44 |
+
<?php echo isset( $event_labels[ $event ] ) ? $event_labels[ $event ] : $event; ?>
|
45 |
+
</label>
|
46 |
+
<?php
|
47 |
+
}
|
48 |
+
?> </p>
|
49 |
+
<?php
|
50 |
+
}
|
51 |
+
|
52 |
+
do_action( 'frm_additional_action_settings', $form_action, compact( 'form', 'action_control', 'action_key', 'values' ) );
|
53 |
+
|
54 |
+
?>
|
55 |
+
<span class="alignright frm_action_id <?php echo empty( $form_action->ID ) ? 'frm_hidden' : ''; ?>"><?php printf( __( 'Action ID: %1$s', 'formidable' ), $form_action->ID); ?></span>
|
56 |
+
</td></tr>
|
57 |
+
</table>
|
classes/views/frm-form-actions/_email_settings.php
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<table class="form-table frm-no-margin">
|
2 |
+
<tr>
|
3 |
+
<th><label <?php FrmAppHelper::maybe_add_tooltip('email_to') ?>><?php _e( 'To', 'formidable' ) ?></label>
|
4 |
+
</th>
|
5 |
+
<td><input type="text" name="<?php echo esc_attr( $this->get_field_name('email_to') ) ?>" value="<?php echo esc_attr( $form_action->post_content['email_to'] ); ?>" class="frm_not_email_to frm_email_blur large-text <?php FrmAppHelper::maybe_add_tooltip('email_to', 'open') ?>" id="<?php echo esc_attr( $this->get_field_id('email_to') ) ?>" />
|
6 |
+
</td>
|
7 |
+
<td class="frm_bcc_cc_container">
|
8 |
+
<a href="javascript:void(0)" class="button frm_email_buttons frm_bcc_button <?php
|
9 |
+
echo ( ! empty($form_action->post_content['bcc']) ? 'frm_hidden' : '' );
|
10 |
+
?>" data-emailrow="bcc"><?php _e( 'BCC', 'formidable' ) ?></a>
|
11 |
+
<a href="javascript:void(0)" class="button frm_email_buttons frm_cc_button <?php
|
12 |
+
echo ( ! empty($form_action->post_content['cc']) ? 'frm_hidden' : '' );
|
13 |
+
?>" data-emailrow="cc"><?php _e( 'CC', 'formidable' ) ?></a>
|
14 |
+
</td>
|
15 |
+
</tr>
|
16 |
+
<tr id="frm_cc_row" class="<?php echo ( empty($form_action->post_content['cc']) ? 'frm_hidden' : '' )?>" >
|
17 |
+
<th><label <?php FrmAppHelper::maybe_add_tooltip('cc') ?>><?php _e( 'CC', 'formidable' ) ?></label>
|
18 |
+
</th>
|
19 |
+
<td class="frm_right_addon">
|
20 |
+
<input type="text" name="<?php echo esc_attr( $this->get_field_name('cc') ) ?>" value="<?php echo esc_attr( $form_action->post_content['cc'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip('cc', 'open') ?>" id="<?php echo esc_attr( $this->get_field_id('cc') ) ?>" />
|
21 |
+
<a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="cc"></a>
|
22 |
+
</td>
|
23 |
+
<td></td>
|
24 |
+
</tr>
|
25 |
+
<tr id="frm_bcc_row" class="<?php echo ( empty($form_action->post_content['bcc']) ? 'frm_hidden' : '' )?>" >
|
26 |
+
<th><label <?php FrmAppHelper::maybe_add_tooltip('bcc') ?>><?php _e( 'BCC', 'formidable' ) ?></label>
|
27 |
+
</th>
|
28 |
+
<td class="frm_right_addon">
|
29 |
+
<input type="text" name="<?php echo esc_attr( $this->get_field_name('bcc') ) ?>" value="<?php echo esc_attr( $form_action->post_content['bcc'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip('bcc', 'open') ?>" id="<?php echo esc_attr( $this->get_field_id('bcc') ) ?>" />
|
30 |
+
<a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="bcc"></a>
|
31 |
+
</td>
|
32 |
+
<td></td>
|
33 |
+
</tr>
|
34 |
+
<tr id="frm_reply_to_row" class="<?php echo ( empty($form_action->post_content['reply_to']) ? 'frm_hidden' : '' )?>">
|
35 |
+
<th><label <?php FrmAppHelper::maybe_add_tooltip('reply_to') ?>><?php _e( 'Reply to', 'formidable' ) ?></label>
|
36 |
+
</th>
|
37 |
+
<td class="frm_right_addon">
|
38 |
+
<input type="text" name="<?php echo esc_attr( $this->get_field_name('reply_to') ) ?>" value="<?php echo esc_attr( $form_action->post_content['reply_to'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip('reply_to', 'open') ?>" id="<?php echo esc_attr( $this->get_field_id('reply_to') ) ?>" />
|
39 |
+
<a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="reply_to"></a>
|
40 |
+
</td>
|
41 |
+
<td></td>
|
42 |
+
</tr>
|
43 |
+
<tr>
|
44 |
+
<th><label <?php FrmAppHelper::maybe_add_tooltip('from') ?>><?php _e( 'From', 'formidable' ) ?></label></th>
|
45 |
+
<td><input type="text" name="<?php echo esc_attr( $this->get_field_name('from') ) ?>" value="<?php echo esc_attr( $form_action->post_content['from'] ); ?>" class="frm_not_email_to frm_email_blur large-text <?php FrmAppHelper::maybe_add_tooltip('from', 'open') ?>" id="<?php echo esc_attr( $this->get_field_id('from') ) ?>" />
|
46 |
+
</td>
|
47 |
+
<td><a href="javascript:void(0)" class="button frm_email_buttons frm_reply_to_button <?php echo ( ! empty( $form_action->post_content['reply_to'] ) ? 'frm_hidden' : '' ) ?>" data-emailrow="reply_to"><?php _e( 'Reply To', 'formidable' ) ?></a></td>
|
48 |
+
</tr>
|
49 |
+
<tr>
|
50 |
+
<td colspan="3" class="frm_no_top_padding">
|
51 |
+
<p><label <?php FrmAppHelper::maybe_add_tooltip('email_subject', '', $form->name) ?>><?php _e( 'Subject', 'formidable' ) ?></label><br/>
|
52 |
+
<input type="text" name="<?php echo esc_attr( $this->get_field_name('email_subject') ) ?>" class="frm_not_email_subject large-text <?php FrmAppHelper::maybe_add_tooltip('email_subject', 'open', $form->name) ?>" id="<?php echo esc_attr( $this->get_field_id('email_subject') ) ?>" size="55" value="<?php echo esc_attr( $form_action->post_content['email_subject'] ); ?>" /></p>
|
53 |
+
|
54 |
+
<p><label><?php _e( 'Message', 'formidable' ) ?> </label><br/>
|
55 |
+
<textarea name="<?php echo esc_attr( $this->get_field_name('email_message') ) ?>" class="frm_not_email_message large-text" id="<?php echo esc_attr( $this->get_field_id('email_message') ) ?>" cols="50" rows="5"><?php echo FrmAppHelper::esc_textarea($form_action->post_content['email_message']) ?></textarea></p>
|
56 |
+
|
57 |
+
<h4><?php _e( 'Options', 'formidable' ) ?> </h4>
|
58 |
+
<label for="<?php echo esc_attr( $this->get_field_id('inc_user_info') ) ?>"><input type="checkbox" name="<?php echo esc_attr( $this->get_field_name('inc_user_info') ) ?>" class="frm_not_inc_user_info" id="<?php echo esc_attr( $this->get_field_id('inc_user_info') ) ?>" value="1" <?php checked( $form_action->post_content['inc_user_info'], 1 ); ?> /> <?php _e( 'Append IP Address, Browser, and Referring URL to message', 'formidable' ) ?></label>
|
59 |
+
|
60 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id('plain_text') ) ?>"><input type="checkbox" name="<?php echo esc_attr( $this->get_field_name('plain_text') ) ?>" id="<?php echo esc_attr( $this->get_field_id('plain_text') ) ?>" value="1" <?php checked( $form_action->post_content['plain_text'], 1 ); ?> /> <?php _e( 'Send Emails in Plain Text', 'formidable' ) ?></label></p>
|
61 |
+
<?php FrmAppHelper::update_message('conditionally send email notifications'); ?>
|
62 |
+
</td>
|
63 |
+
</tr>
|
64 |
+
</table>
|
classes/views/frm-form-actions/default_actions.php
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// add post action
|
3 |
+
class FrmDefPostAction extends FrmFormAction {
|
4 |
+
public function __construct() {
|
5 |
+
$action_ops = FrmFormActionsHelper::default_action_opts();
|
6 |
+
$action_ops['classes'] = 'ab-icon frm_dashicon_font dashicons-before';
|
7 |
+
|
8 |
+
$this->FrmFormAction('wppost', __( 'Create Post', 'formidable' ), $action_ops);
|
9 |
+
}
|
10 |
+
}
|
11 |
+
|
12 |
+
|
13 |
+
// add register action
|
14 |
+
class FrmDefRegAction extends FrmFormAction {
|
15 |
+
public function __construct() {
|
16 |
+
$action_ops = FrmFormActionsHelper::default_action_opts('frm_register_icon');
|
17 |
+
|
18 |
+
$this->FrmFormAction('register', __( 'Register User', 'formidable' ), $action_ops);
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
// add paypal action
|
23 |
+
class FrmDefPayPalAction extends FrmFormAction {
|
24 |
+
public function __construct() {
|
25 |
+
$action_ops = FrmFormActionsHelper::default_action_opts('frm_paypal_icon');
|
26 |
+
|
27 |
+
$this->FrmFormAction('paypal', __( 'Collect Payment', 'formidable' ), $action_ops);
|
28 |
+
}
|
29 |
+
}
|
30 |
+
|
31 |
+
// add aweber action
|
32 |
+
class FrmDefAweberAction extends FrmFormAction {
|
33 |
+
public function __construct() {
|
34 |
+
$action_ops = FrmFormActionsHelper::default_action_opts('frm_aweber_icon');
|
35 |
+
|
36 |
+
$this->FrmFormAction('aweber', __( 'Aweber', 'formidable' ), $action_ops);
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
// add mailchimp action
|
41 |
+
class FrmDefMlcmpAction extends FrmFormAction {
|
42 |
+
public function __construct() {
|
43 |
+
$action_ops = FrmFormActionsHelper::default_action_opts('frm_mailchimp_icon');
|
44 |
+
|
45 |
+
$this->FrmFormAction('mailchimp', __( 'MailChimp', 'formidable' ), $action_ops);
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
// add twilio action
|
50 |
+
class FrmDefTwilioAction extends FrmFormAction {
|
51 |
+
public function __construct() {
|
52 |
+
$action_ops = FrmFormActionsHelper::default_action_opts('frm_sms_icon');
|
53 |
+
|
54 |
+
$this->FrmFormAction('twilio', __( 'Twilio', 'formidable' ), $action_ops);
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
// add highrise action
|
59 |
+
class FrmDefHrsAction extends FrmFormAction {
|
60 |
+
public function __construct() {
|
61 |
+
$action_ops = FrmFormActionsHelper::default_action_opts('frm_highrise_icon');
|
62 |
+
|
63 |
+
$this->FrmFormAction('highrise', __( 'Highrise', 'formidable' ), $action_ops);
|
64 |
+
}
|
65 |
+
}
|
classes/views/frm-form-actions/email_action.php
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class FrmEmailAction extends FrmFormAction {
|
4 |
+
|
5 |
+
public function __construct() {
|
6 |
+
$action_ops = array(
|
7 |
+
'classes' => 'frm_email_icon frm_icon_font',
|
8 |
+
'active' => true,
|
9 |
+
'event' => array( 'create'),
|
10 |
+
'limit' => 99,
|
11 |
+
'priority' => 10,
|
12 |
+
'ajax_load' => false,
|
13 |
+
);
|
14 |
+
$action_ops = apply_filters('frm_email_control_settings', $action_ops);
|
15 |
+
|
16 |
+
$this->FrmFormAction('email', __( 'Email Notification', 'formidable' ), $action_ops);
|
17 |
+
}
|
18 |
+
|
19 |
+
public function form( $form_action, $args = array() ) {
|
20 |
+
extract($args);
|
21 |
+
|
22 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/_email_settings.php');
|
23 |
+
}
|
24 |
+
|
25 |
+
public function get_defaults() {
|
26 |
+
return array(
|
27 |
+
'email_to' => '[admin_email]',
|
28 |
+
'cc' => '',
|
29 |
+
'bcc' => '',
|
30 |
+
'from' => '[sitename] <[admin_email]>',
|
31 |
+
'reply_to' => '',
|
32 |
+
'email_subject' => '',
|
33 |
+
'email_message' => '[default-message]',
|
34 |
+
'inc_user_info' => 0,
|
35 |
+
'plain_text' => 0,
|
36 |
+
'event' => array( 'create'),
|
37 |
+
);
|
38 |
+
}
|
39 |
+
|
40 |
+
}
|
classes/views/frm-form-actions/form_action.php
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings';
|
3 |
+
|
4 |
+
$form_action = apply_filters('frm_form_action_settings', $form_action, $form_action->post_excerpt);
|
5 |
+
$form_action = apply_filters('frm_form_'. $form_action->post_excerpt .'_action_settings', $form_action);
|
6 |
+
|
7 |
+
?>
|
8 |
+
<div id="frm_form_action_<?php echo esc_attr( $action_key ) ?>" class="widget frm_form_action_settings frm_single_<?php echo esc_attr( $form_action->post_excerpt ) ?>_settings" data-actionkey="<?php echo esc_attr( $action_key ) ?>">
|
9 |
+
<div class="widget-top">
|
10 |
+
<div class="widget-title-action">
|
11 |
+
<a href="javascript:void(0)" class="widget-action hide-if-no-js"></a>
|
12 |
+
</div>
|
13 |
+
<div class="widget-title">
|
14 |
+
<h3><span class="frm_form_action_icon <?php echo esc_attr( $action_control->action_options['classes'] ) ?>"></span>
|
15 |
+
<?php echo esc_html( $form_action->post_title ); ?>
|
16 |
+
</h3>
|
17 |
+
<span class="frm_email_icons alignright">
|
18 |
+
<a href="javascript:void(0)" data-removeid="frm_form_action_<?php echo esc_attr( $action_key ) ?>" class="frm_icon_font frm_delete_icon frm_remove_form_action"> </a>
|
19 |
+
</span>
|
20 |
+
</div>
|
21 |
+
</div>
|
22 |
+
<div class="widget-inside frm_hidden">
|
23 |
+
<?php
|
24 |
+
if ( defined('DOING_AJAX') || ! $action_control->action_options['ajax_load'] ) {
|
25 |
+
// only load settings if they are just added or are open
|
26 |
+
include(dirname(__FILE__) .'/_action_inside.php');
|
27 |
+
} else {
|
28 |
+
// include hidden settings so action won't get lost on update ?>
|
29 |
+
<input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('post_excerpt', '') ) ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" />
|
30 |
+
<input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('ID', '') ) ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" />
|
31 |
+
<?php
|
32 |
+
} ?>
|
33 |
+
</div>
|
34 |
+
<style type="text/css">
|
35 |
+
.frm_no_actions{
|
36 |
+
opacity:0;
|
37 |
+
*visibility:hidden;
|
38 |
+
}
|
39 |
+
</style>
|
40 |
+
</div>
|
classes/views/frm-forms/_publish_box.php
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="submitdiv" class="postbox">
|
2 |
+
<div class="inside">
|
3 |
+
<div class="submitbox" id="submitpost">
|
4 |
+
|
5 |
+
<div id="minor-publishing">
|
6 |
+
<div id="minor-publishing-actions">
|
7 |
+
<?php if ( 'draft' == $values['status'] ) { ?>
|
8 |
+
<div id="save-action">
|
9 |
+
<input type="button" value="<?php esc_html_e( 'Save Draft', 'formidable' ); ?>" class="frm_submit_form frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-secondary button-large" id="save-post" />
|
10 |
+
<span class="spinner"></span>
|
11 |
+
</div>
|
12 |
+
<?php } ?>
|
13 |
+
<div id="preview-action">
|
14 |
+
<?php
|
15 |
+
if ( ! isset($hide_preview) || ! $hide_preview ) {
|
16 |
+
|
17 |
+
if ( isset($values['form_key']) ) {
|
18 |
+
$frm_settings = FrmAppHelper::get_settings();
|
19 |
+
if ( empty($frm_settings->preview_page_id) ) { ?>
|
20 |
+
<a href="<?php echo esc_url( FrmFormsHelper::get_direct_link($values['form_key']) ); ?>" class="preview button" target="wp-frm-preview-<?php echo esc_attr( $id ) ?>"><?php _e( 'Preview', 'formidable' ) ?></a>
|
21 |
+
<?php
|
22 |
+
} else {
|
23 |
+
?>
|
24 |
+
<div class="preview dropdown">
|
25 |
+
<a href="#" id="frm-previewDrop" class="frm-dropdown-toggle button" data-toggle="dropdown"><?php _e( 'Preview', 'formidable' ) ?> <b class="caret"></b></a>
|
26 |
+
|
27 |
+
<ul class="frm-dropdown-menu pull-right" role="menu" aria-labelledby="frm-previewDrop">
|
28 |
+
<li><a href="<?php echo esc_url( FrmFormsHelper::get_direct_link($values['form_key']) ); ?>" target="_blank"><?php _e( 'On Blank Page', 'formidable' ) ?></a></li>
|
29 |
+
<li><a href="<?php echo esc_url( add_query_arg('form', $values['form_key'], get_permalink( $frm_settings->preview_page_id )) ) ?>" target="_blank"><?php _e( 'In Theme', 'formidable' ) ?></a></li>
|
30 |
+
</ul>
|
31 |
+
</div>
|
32 |
+
<?php }
|
33 |
+
}
|
34 |
+
} ?>
|
35 |
+
</div>
|
36 |
+
<?php if ( 'draft' == $values['status'] ) { ?>
|
37 |
+
<div class="clear"></div>
|
38 |
+
<?php } ?>
|
39 |
+
</div><!-- #minor-publishing-actions -->
|
40 |
+
|
41 |
+
<div id="misc-publishing-actions">
|
42 |
+
<div class="misc-pub-section">
|
43 |
+
|
44 |
+
<?php if ( $values['is_template'] ) { ?>
|
45 |
+
<br/>
|
46 |
+
<?php } else { ?>
|
47 |
+
<span id="frm_shortcode"><span class="frm-buttons-icon wp-media-buttons-icon"></span> <?php _e( 'Form', 'formidable' ) ?> <strong><?php _e( 'Shortcodes', 'formidable' ) ?></strong></span>
|
48 |
+
<a href="#edit_frm_shortcode" class="edit-frm_shortcode hide-if-no-js" tabindex='4'><?php _e( 'Show', 'formidable' ) ?></a>
|
49 |
+
<div id="frm_shortcodediv" class="hide-if-js">
|
50 |
+
<p class="howto"><?php _e( 'Insert on a page, post, or text widget', 'formidable' ) ?>:</p>
|
51 |
+
<p><input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo esc_attr( $id ); ?>]" />
|
52 |
+
<input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo esc_attr( $id ); ?> title=true description=true]" />
|
53 |
+
</p>
|
54 |
+
|
55 |
+
<p class="howto"><?php _e( 'Insert in a template', 'formidable' ) ?>:</p>
|
56 |
+
<p><input type="text" readonly="true" class="frm_select_box frm_insert_in_template" value="<?php echo FrmFormsController::get_form_shortcode( array( 'id' => $id, 'title' => false, 'description' => false)); ?>" /></p>
|
57 |
+
|
58 |
+
<p><a href="#edit_frm_shortcode" class="cancel-frm_shortcode hide-if-no-js"><?php _e( 'Hide', 'formidable' ); ?></a></p>
|
59 |
+
</div>
|
60 |
+
<?php } ?>
|
61 |
+
</div>
|
62 |
+
|
63 |
+
|
64 |
+
<div class="misc-pub-section misc-pub-post-status"><label for="post_status"><?php _e( 'Status', 'formidable' ) ?>:</label>
|
65 |
+
<span id="form-status-display"><?php echo FrmFormsHelper::status_nice_name($values['status']); ?></span>
|
66 |
+
<?php if ( 'draft' != $values['status'] && ( ! isset($_GET['frm_action']) || 'settings' != $_GET['frm_action'] ) ) { ?>
|
67 |
+
<a href="#post_status" class="edit-form-status hide-if-no-js" data-slidedown="form-status-select"><span aria-hidden="true"><?php _e( 'Edit') ?></span> <span class="screen-reader-text"><?php _e( 'Edit status') ?></span></a>
|
68 |
+
|
69 |
+
<div id="form-status-select" class="frm_hidden">
|
70 |
+
<select name="frm_change_status" id="form_change_status">
|
71 |
+
<option value="published" <?php selected($values['status'], 'published') ?>><?php _e( 'Published' ) ?></option>
|
72 |
+
<option value="draft" <?php selected($values['status'], 'draft') ?>><?php _e( 'Draft' ) ?></option>
|
73 |
+
</select>
|
74 |
+
<a href="#post_status" class="save-form-status hide-if-no-js button"><?php _e( 'OK') ?></a>
|
75 |
+
<a href="#post_status" class="cancel-form-status hide-if-no-js button-cancel" data-slideup="form-status-select"><?php _e( 'Cancel') ?></a>
|
76 |
+
</div>
|
77 |
+
<?php } ?>
|
78 |
+
</div><!-- .misc-pub-section -->
|
79 |
+
|
80 |
+
<?php if ( has_action('frm_settings_buttons') ) { ?>
|
81 |
+
<div class="misc-pub-section">
|
82 |
+
<?php do_action('frm_settings_buttons', $values); ?>
|
83 |
+
<div class="clear"></div>
|
84 |
+
</div>
|
85 |
+
<?php } ?>
|
86 |
+
|
87 |
+
</div><!-- #misc-publishing-actions -->
|
88 |
+
<div class="clear"></div>
|
89 |
+
</div><!-- #minor-publishing -->
|
90 |
+
|
91 |
+
<div id="major-publishing-actions">
|
92 |
+
<div id="delete-action">
|
93 |
+
<?php echo FrmFormsHelper::delete_trash_link($id, $values['status']); ?>
|
94 |
+
</div>
|
95 |
+
|
96 |
+
<div id="publishing-action">
|
97 |
+
<span class="spinner"></span>
|
98 |
+
<?php if ( isset($_GET['frm_action']) && 'settings' == $_GET['frm_action'] ) { ?>
|
99 |
+
<input type="button" value="<?php esc_attr_e( 'Update', 'formidable' ); ?>" class="frm_submit_form frm_submit_settings_btn button-primary button-large" id="frm_submit_side_top" />
|
100 |
+
<?php } else { ?>
|
101 |
+
<input type="button" value="<?php echo isset($button) ? esc_attr($button) : __( 'Update', 'formidable' ); ?>" class="frm_submit_form frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-primary button-large" id="frm_submit_side_top" />
|
102 |
+
<?php } ?>
|
103 |
+
</div>
|
104 |
+
|
105 |
+
<div class="clear"></div>
|
106 |
+
</div><!-- #major-publishing-actions -->
|
107 |
+
|
108 |
+
</div><!-- .submitbox -->
|
109 |
+
</div><!-- .inside -->
|
110 |
+
</div><!-- .submitdiv -->
|
classes/views/frm-forms/add_field.php
CHANGED
@@ -1,303 +1,322 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
<span class="frm_hidden_fdata frm_hidden"><?php echo htmlspecialchars(json_encode($field)) ?></span>
|
6 |
</li>
|
7 |
<?php
|
8 |
return;
|
9 |
}
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
$
|
|
|
18 |
}
|
19 |
}
|
20 |
|
21 |
-
|
22 |
-
global $frm_vars;
|
23 |
-
|
24 |
-
$disabled_fields = ($frm_vars['pro_is_installed']) ? array() : $frm_pro_field_selection;
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
)
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
<a href="javascript:
|
|
|
|
|
40 |
<input type="hidden" name="frm_fields_submitted[]" value="<?php echo esc_attr($field['id']) ?>" />
|
41 |
<?php do_action('frm_extra_field_actions', $field['id']); ?>
|
42 |
-
<?php if ($display['required']){ ?>
|
43 |
-
<span id="require_field_<?php echo $field['id']; ?>">
|
44 |
-
<a class="frm_req_field frm_action_icon frm_required_icon frm_icon_font alignleft frm_required<?php echo (int)$field['required'] ?>" id="req_field_<?php echo $field['id']; ?>" title="Click to Mark as <?php echo ($field['required'] == '0') ? '' : 'not '; ?>Required"></a>
|
45 |
</span>
|
46 |
-
<?php }
|
47 |
-
|
48 |
-
|
49 |
-
<div class="frm_form_fields" data-ftype="<?php echo $display['type'] ?>">
|
50 |
-
<?php if ($display['type'] == 'text'){ ?>
|
51 |
-
<input type="text" name="<?php echo $field_name ?>" id="field_<?php echo $field['field_key'] ?>" value="<?php echo esc_attr($field['default_value']); ?>" <?php echo (isset($field['size']) && $field['size']) ? 'style="width:auto" size="'. $field['size'] .'"' : ''; ?> class="dyn_default_value" />
|
52 |
-
<?php }else if ($field['type'] == 'textarea'){ ?>
|
53 |
-
<textarea name="<?php echo $field_name ?>"<?php if ($field['size']) echo ' style="width:auto" cols="'. $field['size'] .'"' ?> rows="<?php echo $field['max']; ?>" id="field_<?php echo $field['field_key'] ?>" class="dyn_default_value"><?php echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value'])); ?></textarea>
|
54 |
-
|
55 |
-
<?php
|
56 |
-
|
57 |
-
}else if ($field['type'] == 'radio' or $field['type'] == 'checkbox'){
|
58 |
-
$field['default_value'] = maybe_unserialize($field['default_value']);
|
59 |
-
if(isset($field['post_field']) and $field['post_field'] == 'post_category'){
|
60 |
-
do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
|
61 |
-
}else{ ?>
|
62 |
-
<div id="frm_field_<?php echo $field['id'] ?>_opts" class="clear<?php echo (count($field['options']) > 10) ? ' frm_field_opts_list' : ''; ?>">
|
63 |
-
<?php do_action('frm_add_multiple_opts_labels', $field); ?>
|
64 |
-
<?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php'); ?>
|
65 |
-
</div>
|
66 |
-
<?php
|
67 |
-
}
|
68 |
?>
|
|
|
69 |
|
70 |
-
|
|
|
|
|
71 |
<?php
|
|
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
76 |
?>
|
77 |
-
|
78 |
-
<a href="javascript:frm_add_field_option(<?php echo $field['id']; ?>)" class="frm_orange frm_add_opt">+ <?php _e('Add an Option', 'formidable') ?></a>
|
79 |
-
|
80 |
-
<?php _e('or', 'formidable'); ?>
|
81 |
-
<a title="<?php echo FrmAppHelper::truncate(esc_attr(strip_tags(str_replace('"', '"', $field['name']))), 20) . ' '. __('Field Choices', 'formidable'); ?>" href="<?php echo esc_url(admin_url('admin-ajax.php') .'?action=frm_import_choices&field_id='. $field['id'] .'&TB_iframe=1') ?>" class="thickbox frm_orange"><?php _e('Bulk Edit Field Choices', 'formidable') ?></a>
|
82 |
-
</div>
|
83 |
<?php
|
84 |
-
|
|
|
|
|
85 |
?>
|
86 |
-
|
|
|
87 |
<?php
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
<?php
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
<?php } ?>
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
112 |
if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
|
113 |
echo '<p class="howto">'. FrmFieldsHelper::get_term_link($field['taxonomy']) .'</p>';
|
114 |
-
} else if ( !isset($field['post_field']) || $field['post_field']
|
115 |
-
<div id="frm_field_<?php echo $field['id'] ?>_opts"<?php echo (count($field['options']) > 10) ? ' class="frm_field_opts_list"' : ''; ?>>
|
116 |
-
<?php do_action('frm_add_multiple_opts_labels', $field); ?>
|
117 |
-
<?php
|
118 |
-
|
119 |
-
foreach ( $field['options'] as $opt_key => $opt ) {
|
120 |
-
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
|
121 |
-
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
|
122 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
|
123 |
-
}
|
124 |
-
?>
|
125 |
-
</div>
|
126 |
-
<div id="frm_add_field_<?php echo $field['id']; ?>">
|
127 |
-
<a href="javascript:frm_add_field_option(<?php echo $field['id']; ?>)" class="frm_orange frm_add_opt">+ <?php _e('Add an Option', 'formidable') ?></a>
|
128 |
-
|
129 |
-
<?php if (!isset($field['post_field']) or $field['post_field'] != 'post_category'){ ?>
|
130 |
-
<?php _e('or', 'formidable'); ?>
|
131 |
-
<a title="<?php echo FrmAppHelper::truncate(esc_attr(strip_tags(str_replace('"', '"', $field['name']))), 20) . ' '. __('Field Choices', 'formidable'); ?>" href="<?php echo esc_url(admin_url('admin-ajax.php') .'?action=frm_import_choices&field_id='. $field['id'] .'&TB_iframe=1') ?>" class="thickbox frm_orange"><?php _e('Bulk Edit Field Choices', 'formidable') ?></a>
|
132 |
-
<?php } ?>
|
133 |
-
</div>
|
134 |
-
<?php
|
135 |
-
} ?>
|
136 |
-
</div>
|
137 |
-
<?php
|
138 |
-
}else if ($field['type'] == 'captcha'){
|
139 |
?>
|
140 |
-
|
141 |
-
|
142 |
-
<div class="clear"></div>
|
143 |
-
<?php if (empty($frm_settings->pubkey)){ ?>
|
144 |
-
<div class="howto" style="font-weight:bold;color:red;"><?php printf(__('Your captcha will not appear on your form until you %1$sset up%2$s the Public and Private Keys', 'formidable'), '<a href="?page=formidable-settings">', '</a>') ?></div>
|
145 |
-
<?php } ?>
|
146 |
-
<input type="hidden" name="<?php echo $field_name ?>" value="1"/>
|
147 |
-
<?php
|
148 |
-
}else{
|
149 |
-
do_action('frm_display_added_fields',$field);
|
150 |
-
}
|
151 |
|
152 |
-
|
153 |
-
|
154 |
-
<?php
|
155 |
-
|
156 |
-
|
|
|
157 |
|
158 |
-
|
159 |
-
?>
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
do_action('frm_extra_field_display_options', $field);
|
164 |
-
}
|
165 |
-
?>
|
166 |
-
<div class="clear"></div>
|
167 |
-
</div>
|
168 |
<?php
|
169 |
-
|
170 |
-
|
|
|
171 |
<?php
|
172 |
}
|
173 |
|
|
|
|
|
174 |
if ($display['options']){ ?>
|
175 |
<div class="widget">
|
176 |
<div class="widget-top">
|
177 |
-
<div class="widget-title-action"><a class="widget-action"></a></div>
|
178 |
-
<div class="widget-title"><h4><?php _e('Field Options', 'formidable') ?> (ID <?php echo $field['id'] ?>)</h4></div>
|
179 |
</div>
|
180 |
<div class="widget-inside">
|
181 |
-
<table class="form-table
|
182 |
<?php $field_types = FrmFieldsHelper::get_field_types($field['type']); ?>
|
183 |
-
<tr><td
|
184 |
<td>
|
185 |
-
|
186 |
-
<?php _e('Field Key:', 'formidable') ?>
|
187 |
-
<div class="<?php echo ($frm_settings->lock_keys) ? 'frm_field_key' : 'frm_ipe_field_key" title="'. __('Click to edit.', 'formidable'); ?>" ><?php echo $field['field_key']; ?></div>
|
188 |
-
<?php if(
|
189 |
-
<input type="hidden" name="field_options[field_key_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['field_key']); ?>" />
|
190 |
<?php } ?>
|
191 |
</div>
|
192 |
-
|
193 |
-
<?php if (
|
194 |
-
<select name="field_options[type_<?php echo $field['id'] ?>]">
|
195 |
-
<?php foreach ($field_types as $fkey => $ftype){ ?>
|
196 |
-
<option value="<?php echo $fkey ?>" <?php echo ($fkey == $field['type']) ? ' selected="selected"' : ''; ?> <?php echo array_key_exists($fkey, $disabled_fields ) ? 'disabled="disabled"' : ''; ?>><?php echo $ftype ?></option>
|
197 |
<?php
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
|
|
212 |
$field['unique'] = false;
|
|
|
213 |
?>
|
214 |
-
<label for="frm_uniq_field_<?php echo $field['id'] ?>" class="frm_inline_label frm_help" title="<?php
|
215 |
-
<?php
|
216 |
-
|
217 |
-
|
|
|
|
|
218 |
$field['read_only'] = false;
|
|
|
219 |
?>
|
220 |
-
<label for="frm_read_only_field_<?php echo $field['id'] ?>" class="frm_inline_label frm_help" title="<?php
|
221 |
-
<?php }
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
|
|
|
|
|
|
|
|
227 |
</div>
|
228 |
<?php } ?>
|
229 |
</td>
|
230 |
</tr>
|
231 |
-
|
232 |
-
<?php
|
233 |
-
|
234 |
-
|
|
|
|
|
|
|
235 |
</td>
|
236 |
-
<td><input type="text" name="field_options[classes_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['classes']) ?>" id="frm_classes_<?php echo $field['id'] ?>" class="frm_classes frm_long_input" />
|
237 |
-
</td>
|
238 |
</tr>
|
239 |
-
<?php
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
<option value="
|
246 |
-
<option value="
|
247 |
-
<option value="
|
248 |
-
<option value="
|
249 |
-
<option value="
|
|
|
|
|
250 |
</select>
|
251 |
-
</td>
|
252 |
</tr>
|
253 |
<?php } ?>
|
254 |
<?php if ($display['size']){ ?>
|
255 |
-
<tr><td
|
256 |
<td>
|
257 |
-
<?php
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
<input type="text" name="field_options[
|
265 |
-
|
|
|
|
|
|
|
266 |
</td>
|
267 |
</tr>
|
268 |
<?php } ?>
|
269 |
-
<?php do_action('frm_field_options_form', $field, $display, $values);
|
270 |
-
|
271 |
-
|
272 |
-
<tr class="frm_validation_msg <?php echo ($display['invalid'] || $field['required'] || (isset($field['unique']) && $field['unique'])) ? '' : 'frm_hidden'; ?>"><td
|
273 |
-
<
|
274 |
-
|
275 |
-
|
276 |
-
|
|
|
|
|
|
|
|
|
277 |
</p>
|
278 |
-
<?php
|
279 |
-
|
280 |
-
|
281 |
-
|
|
|
|
|
282 |
</p>
|
283 |
-
<?php
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
|
|
288 |
</p>
|
289 |
-
<?php
|
290 |
-
|
291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
</td>
|
293 |
</tr>
|
294 |
<?php } ?>
|
295 |
-
|
296 |
</table>
|
297 |
</div>
|
298 |
</div>
|
299 |
-
<?php }
|
300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
</li>
|
302 |
-
<?php
|
303 |
-
|
|
|
|
1 |
<?php
|
2 |
+
|
3 |
+
$display = apply_filters('frm_display_field_options', array(
|
4 |
+
'type' => $field['type'], 'field_data' => $field,
|
5 |
+
'required' => true, 'unique' => false, 'read_only' => false,
|
6 |
+
'description' => true, 'options' => true, 'label_position' => true,
|
7 |
+
'invalid' => false, 'size' => false, 'clear_on_focus' => false,
|
8 |
+
'default_blank' => true, 'css' => true, 'conf_field' => false,
|
9 |
+
));
|
10 |
+
|
11 |
+
$li_classes = 'form-field edit_form_item frm_field_box frm_top_container frm_not_divider edit_field_type_'. $display['type'];
|
12 |
+
$li_classes = apply_filters('frm_build_field_class', $li_classes, $field );
|
13 |
+
|
14 |
+
if ( isset($values) && isset($values['ajax_load']) && $values['ajax_load'] && isset($count) && $count > 10 && ! in_array($field['type'], array( 'divider', 'end_divider')) ) {
|
15 |
+
?>
|
16 |
+
<li id="frm_field_id_<?php echo esc_attr( $field['id'] ); ?>" class="<?php echo esc_attr( $li_classes ) ?> frm_field_loading" data-fid="<?php echo esc_attr( $field['id'] ) ?>" data-formid="<?php echo esc_attr( 'divider' == $field['type'] ? $field['form_select'] : $field['form_id'] ); ?>" data-ftype="<?php echo esc_attr( $display['type'] ) ?>">
|
17 |
+
<img src="<?php echo FrmAppHelper::plugin_url() ?>/images/ajax_loader.gif" alt="<?php esc_attr_e( 'Loading', 'formidable' ) ?>" />
|
18 |
<span class="frm_hidden_fdata frm_hidden"><?php echo htmlspecialchars(json_encode($field)) ?></span>
|
19 |
</li>
|
20 |
<?php
|
21 |
return;
|
22 |
}
|
23 |
|
24 |
+
$frm_settings = FrmAppHelper::get_settings();
|
25 |
+
|
26 |
+
if ( ! isset( $frm_all_field_selection ) ) {
|
27 |
+
if ( isset($frm_field_selection) && isset($pro_field_selection) ) {
|
28 |
+
$frm_all_field_selection = array_merge($frm_field_selection, $pro_field_selection);
|
29 |
+
} else {
|
30 |
+
$pro_field_selection = FrmFieldsHelper::pro_field_selection();
|
31 |
+
$frm_all_field_selection = array_merge(FrmFieldsHelper::field_selection(), $pro_field_selection);
|
32 |
}
|
33 |
}
|
34 |
|
35 |
+
$disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
|
|
|
|
|
|
|
36 |
|
37 |
+
|
38 |
+
if ( ! isset( $ajax ) ) {
|
39 |
+
$li_classes .= ' ui-state-default widgets-holder-wrap'; ?>
|
40 |
+
<li id="frm_field_id_<?php echo esc_attr( $field['id'] ); ?>" class="<?php echo esc_attr( $li_classes ) ?>" data-fid="<?php echo esc_attr( $field['id'] ) ?>" data-formid="<?php echo ( 'divider' == $field['type'] ) ? esc_attr( $field['form_select'] ) : esc_attr( $field['form_id'] ); ?>">
|
41 |
+
<?php
|
42 |
+
}
|
43 |
+
|
44 |
+
if ( $field['type'] == 'divider' ) { ?>
|
45 |
+
<div class="divider_section_only">
|
46 |
+
<?php
|
47 |
+
}
|
48 |
+
?>
|
49 |
+
|
50 |
+
<a href="javascript:void(0);" class="frm_bstooltip alignright frm-show-hover frm-move frm-hover-icon frm_icon_font frm_move_icon" title="<?php esc_attr_e( 'Move Field', 'formidable' ) ?>"> </a>
|
51 |
+
<a href="#" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_delete_icon frm_delete_field" title="<?php esc_attr_e( 'Delete Field', 'formidable' ) ?>"> </a>
|
52 |
+
<a href="#" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_duplicate_icon" title="<?php ( $field['type'] == 'divider' ) ? esc_attr_e( 'Duplicate Section', 'formidable' ) : esc_attr_e( 'Duplicate Field', 'formidable' ) ?>"> </a>
|
53 |
<input type="hidden" name="frm_fields_submitted[]" value="<?php echo esc_attr($field['id']) ?>" />
|
54 |
<?php do_action('frm_extra_field_actions', $field['id']); ?>
|
55 |
+
<?php if ( $display['required'] ) { ?>
|
56 |
+
<span id="require_field_<?php echo esc_attr( $field['id'] ); ?>">
|
57 |
+
<a href="javascript:void(0);" class="frm_req_field frm_action_icon frm_required_icon frm_icon_font alignleft frm_required<?php echo (int) $field['required'] ?>" id="req_field_<?php echo esc_attr( $field['id'] ); ?>" title="Click to Mark as <?php echo ($field['required'] == '0') ? '' : 'not '; ?>Required"></a>
|
58 |
</span>
|
59 |
+
<?php }
|
60 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
?>
|
62 |
+
<label class="<?php echo ( $field['type'] == 'end_divider' ) ? '' : 'frm_ipe_field_label'; ?> frm_primary_label <?php echo ($field['type'] == 'break') ? 'button': ''; ?>" id="field_label_<?php echo esc_attr( $field['id'] ); ?>"><?php echo ($field['name'] == '') ? __( '(no label)') : force_balance_tags($field['name']); ?></label>
|
63 |
|
64 |
+
|
65 |
+
<div id="field_<?php echo esc_attr( $field['id'] ) ?>_inner_container" class="frm_inner_field_container">
|
66 |
+
<div class="frm_form_fields" data-ftype="<?php echo esc_attr( $display['type'] ) ?>">
|
67 |
<?php
|
68 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/show-build.php');
|
69 |
|
70 |
+
if ($display['clear_on_focus']){ ?>
|
71 |
+
<span id="frm_clear_on_focus_<?php echo esc_attr( $field['id'] ) ?>" class="frm-show-click"><?php
|
72 |
+
|
73 |
+
if ( $display['default_blank'] ) {
|
74 |
+
FrmFieldsHelper::show_default_blank_js($field['default_blank']);
|
75 |
+
}
|
76 |
+
|
77 |
+
FrmFieldsHelper::show_onfocus_js($field['clear_on_focus']);
|
78 |
?>
|
79 |
+
</span>
|
|
|
|
|
|
|
|
|
|
|
80 |
<?php
|
81 |
+
|
82 |
+
do_action('frm_extra_field_display_options', $field);
|
83 |
+
}
|
84 |
?>
|
85 |
+
<div class="clear"></div>
|
86 |
+
</div>
|
87 |
<?php
|
88 |
+
if ($display['description']){ ?>
|
89 |
+
<div class="frm_ipe_field_desc description <?php echo ($field['description'] == '') ? 'frm-show-click' : '' ?>" id="field_description_<?php echo esc_attr( $field['id'] ); ?>"><?php echo ($field['description'] == '') ? __( '(Click to add description)', 'formidable' ) : force_balance_tags( $field['description'] ); ?></div>
|
90 |
+
<input type="hidden" name="field_options[description_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['description'] ); ?>" />
|
91 |
+
|
92 |
+
<?php } ?>
|
93 |
+
</div> <?php //End field_x_inner_container div
|
94 |
+
|
95 |
+
if ( $display['conf_field'] ) { ?>
|
96 |
+
<div id="frm_conf_field_<?php echo esc_attr( $field['id'] ) ?>_container" class="frm_conf_field_container frm_form_fields frm_conf_details<?php echo esc_attr( $field['id'] . ( $field['conf_field'] ? '' : ' frm_hidden' ) ); ?>">
|
97 |
+
<div id="frm_conf_field_<?php echo esc_attr( $field['id'] ) ?>_inner_container" class="frm_inner_conf_container">
|
98 |
+
<input type="text" id="conf_field_<?php echo esc_attr( $field['field_key'] ) ?>" name="field_options[conf_input_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['conf_input'] ); ?>" <?php do_action('frm_field_input_html', $field) ?> />
|
99 |
+
<div class="frm_ipe_field_conf_desc description <?php echo ($field['conf_desc'] == '') ? 'frm-show-click' : '' ?>"><?php echo ($field['conf_desc'] == '') ? __( '(Click to add description)', 'formidable' ) : force_balance_tags($field['conf_desc']); ?></div>
|
100 |
+
<input type="hidden" name="field_options[conf_desc_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['conf_desc'] ); ?>" />
|
101 |
+
</div>
|
102 |
+
<?php if ($display['clear_on_focus']){ ?>
|
103 |
+
<div class="alignleft">
|
104 |
+
<span id="frm_clear_on_focus_<?php echo esc_attr( $field['id'] ) ?>" class="frm-show-click">
|
105 |
+
<?php
|
106 |
+
if ( $display['default_blank'] ) {
|
107 |
+
FrmFieldsHelper::show_default_blank_js($field['default_blank']);
|
108 |
+
}
|
109 |
+
|
110 |
+
FrmFieldsHelper::show_onfocus_js($field['clear_on_focus']);
|
111 |
+
?>
|
112 |
+
</span>
|
113 |
+
</div>
|
114 |
<?php } ?>
|
115 |
+
</div>
|
116 |
+
<div class="clear"></div>
|
117 |
+
<?php }
|
118 |
+
|
119 |
+
if ( in_array($field['type'], array( 'select', 'radio', 'checkbox')) ) { ?>
|
120 |
+
<div class="frm-show-click frm_small_top_margin"><?php
|
121 |
+
|
122 |
if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
|
123 |
echo '<p class="howto">'. FrmFieldsHelper::get_term_link($field['taxonomy']) .'</p>';
|
124 |
+
} else if ( ! isset( $field['post_field'] ) || ! in_array( $field['post_field'], array( 'post_category', 'post_status') ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
?>
|
126 |
+
<div id="frm_add_field_<?php echo esc_attr( $field['id'] ); ?>">
|
127 |
+
<a href="javascript:void(0);" data-opttype="single" class="button frm_cb_button frm_add_opt"><?php _e( 'Add Option', 'formidable' ) ?></a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
+
<?php
|
130 |
+
if ( FrmAppHelper::pro_is_installed() ) { ?>
|
131 |
+
<a href="javascript:void(0);" id="other_button_<?php echo esc_attr( $field['id'] ); ?>" data-opttype="other" data-ftype="<?php echo esc_attr( $field['type'] ) ?>" class="button frm_cb_button frm_add_opt<?php echo ( in_array( $field['type'], array( 'radio', 'select') ) && $field['other'] == true ? ' frm_hidden' : '' ); ?>"><?php _e( 'Add "Other"', 'formidable' ) ?></a>
|
132 |
+
<input type="hidden" value="<?php echo esc_attr( $field['other'] ); ?>" id="other_input_<?php echo esc_attr( $field['id'] ); ?>" name="field_options[other_<?php echo esc_attr( $field['id'] ); ?>]">
|
133 |
+
<?php
|
134 |
+
}
|
135 |
|
136 |
+
if ( ! isset($field['post_field']) || $field['post_field'] != 'post_category' ) { ?>
|
137 |
+
<a href="<?php echo esc_url(admin_url('admin-ajax.php') .'?action=frm_import_choices&field_id='. $field['id'] .'&TB_iframe=1') ?>" title="<?php echo FrmAppHelper::truncate(esc_attr(strip_tags(str_replace('"', '"', $field['name']))), 20) . ' '. __( 'Field Choices', 'formidable' ); ?>" class="thickbox frm_orange"><?php _e( 'Bulk Edit Options', 'formidable' ) ?></a>
|
138 |
+
<?php } ?>
|
139 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
<?php
|
141 |
+
}
|
142 |
+
?>
|
143 |
+
</div>
|
144 |
<?php
|
145 |
}
|
146 |
|
147 |
+
do_action('frm_before_field_options', $field);
|
148 |
+
|
149 |
if ($display['options']){ ?>
|
150 |
<div class="widget">
|
151 |
<div class="widget-top">
|
152 |
+
<div class="widget-title-action"><a href="javascript:void(0);" class="widget-action"></a></div>
|
153 |
+
<div class="widget-title"><h4><?php _e( 'Field Options', 'formidable' ) ?> (ID <?php echo (int) $field['id'] ?>)</h4></div>
|
154 |
</div>
|
155 |
<div class="widget-inside">
|
156 |
+
<table class="form-table frm_clear_none">
|
157 |
<?php $field_types = FrmFieldsHelper::get_field_types($field['type']); ?>
|
158 |
+
<tr><td class="frm_150_width"><label><?php _e( 'Field Type', 'formidable' ) ?></label></td>
|
159 |
<td>
|
160 |
+
<div class="hide-if-no-js edit-slug-box frm_help" title="<?php esc_attr_e( 'The field key can be used as an alternative to the field ID in many cases.', 'formidable' ) ?>">
|
161 |
+
<?php _e( 'Field Key:', 'formidable' ) ?>
|
162 |
+
<div class="<?php echo ($frm_settings->lock_keys) ? 'frm_field_key' : 'frm_ipe_field_key" title="'. __( 'Click to edit.', 'formidable' ); ?>" ><?php echo esc_html( $field['field_key'] ); ?></div>
|
163 |
+
<?php if ( ! $frm_settings->lock_keys ) { ?>
|
164 |
+
<input type="hidden" name="field_options[field_key_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['field_key'] ); ?>" />
|
165 |
<?php } ?>
|
166 |
</div>
|
167 |
+
|
168 |
+
<select <?php if ( count($field_types) == 1 ) { ?>disabled="disabled"<?php } else { ?>name="field_options[type_<?php echo esc_attr( $field['id'] ) ?>]"<?php } ?>>
|
|
|
|
|
|
|
169 |
<?php
|
170 |
+
foreach ( $field_types as $fkey => $ftype ) { ?>
|
171 |
+
<option value="<?php echo esc_attr( $fkey ) ?>" <?php echo ( $fkey == $field['type'] ) ? ' selected="selected"' : ''; ?> <?php echo array_key_exists($fkey, $disabled_fields ) ? 'disabled="disabled"' : ''; ?>><?php echo is_array($ftype) ? $ftype['name'] : $ftype ?> </option>
|
172 |
+
<?php
|
173 |
+
unset( $fkey, $ftype );
|
174 |
+
} ?>
|
175 |
+
</select>
|
176 |
+
|
177 |
+
<?php
|
178 |
+
if ( $display['required'] ) { ?>
|
179 |
+
<label for="frm_req_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_inline_label"><input type="checkbox" id="frm_req_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_req_field" name="field_options[required_<?php echo esc_attr( $field['id'] ) ?>]" value="1" <?php echo $field['required'] ? 'checked="checked"': ''; ?> /> <?php _e( 'Required', 'formidable' ) ?></label>
|
180 |
+
<?php
|
181 |
+
}
|
182 |
+
|
183 |
+
if ( $display['unique'] ) {
|
184 |
+
if ( ! isset( $field['unique'] ) ) {
|
185 |
$field['unique'] = false;
|
186 |
+
}
|
187 |
?>
|
188 |
+
<label for="frm_uniq_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_inline_label frm_help" title="<?php esc_attr_e( 'Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\' then no one else will be allowed to enter the same name.', 'formidable' ) ?>"><input type="checkbox" name="field_options[unique_<?php echo esc_attr( $field['id'] ) ?>]" id="frm_uniq_field_<?php echo esc_attr( $field['id'] ) ?>" value="1" <?php checked( $field['unique'], 1 ); ?> class="frm_mark_unique" /> <?php _e( 'Unique', 'formidable' ) ?></label>
|
189 |
+
<?php
|
190 |
+
}
|
191 |
+
|
192 |
+
if ( $display['read_only'] ) {
|
193 |
+
if ( ! isset( $field['read_only'] ) ) {
|
194 |
$field['read_only'] = false;
|
195 |
+
}
|
196 |
?>
|
197 |
+
<label for="frm_read_only_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_inline_label frm_help" title="<?php esc_attr_e( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ) ?>" ><input type="checkbox" id="frm_read_only_field_<?php echo esc_attr( $field['id'] ) ?>" name="field_options[read_only_<?php echo esc_attr( $field['id'] ) ?>]" value="1" <?php echo $field['read_only'] ? ' checked="checked"' : ''; ?>/> <?php _e( 'Read Only', 'formidable' ) ?></label>
|
198 |
+
<?php }
|
199 |
+
|
200 |
+
do_action('frm_field_options_form_top', $field, $display, $values);
|
201 |
+
|
202 |
+
?>
|
203 |
+
<?php
|
204 |
+
if ( $display['required'] ) { ?>
|
205 |
+
<div class="frm_required_details<?php echo esc_attr( $field['id'] . ( $field['required'] ? '' : ' frm_hidden' ) ); ?>">
|
206 |
+
<span class="howto"><?php _e( 'Indicate required field with', 'formidable' ) ?></span>
|
207 |
+
<input type="text" name="field_options[required_indicator_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['required_indicator'] ); ?>" />
|
208 |
</div>
|
209 |
<?php } ?>
|
210 |
</td>
|
211 |
</tr>
|
212 |
+
|
213 |
+
<?php
|
214 |
+
if ( $display['css'] ) { ?>
|
215 |
+
<tr><td><label><?php _e( 'CSS layout classes', 'formidable' ) ?></label>
|
216 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Add a CSS class to the field container. Use our predefined classes to align multiple fields in single row.', 'formidable' ) ?>" ></span>
|
217 |
+
</td>
|
218 |
+
<td><input type="text" name="field_options[classes_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['classes'] ) ?>" id="frm_classes_<?php echo esc_attr( $field['id'] ) ?>" class="frm_classes frm_long_input" />
|
219 |
</td>
|
|
|
|
|
220 |
</tr>
|
221 |
+
<?php
|
222 |
+
}
|
223 |
+
|
224 |
+
if ( $display['label_position'] ) { ?>
|
225 |
+
<tr><td class="frm_150_width"><label><?php _e( 'Label Position', 'formidable' ) ?></label></td>
|
226 |
+
<td><select name="field_options[label_<?php echo esc_attr( $field['id'] ) ?>]">
|
227 |
+
<option value=""<?php selected($field['label'], ''); ?>><?php _e( 'Default', 'formidable' ) ?></option>
|
228 |
+
<option value="top"<?php selected($field['label'], 'top'); ?>><?php _e( 'Top', 'formidable' ) ?></option>
|
229 |
+
<option value="left"<?php selected($field['label'], 'left'); ?>><?php _e( 'Left', 'formidable' ) ?></option>
|
230 |
+
<option value="right"<?php selected($field['label'], 'right'); ?>><?php _e( 'Right', 'formidable' ) ?></option>
|
231 |
+
<option value="inline"<?php selected($field['label'], 'inline'); ?>><?php _e( 'Inline (left without a set width)', 'formidable' ) ?></option>
|
232 |
+
<option value="none"<?php selected($field['label'], 'none'); ?>><?php _e( 'None', 'formidable' ) ?></option>
|
233 |
+
<option value="hidden"<?php selected($field['label'], 'hidden'); ?>><?php _e( 'Hidden (but leave the space)', 'formidable' ) ?></option>
|
234 |
</select>
|
235 |
+
</td>
|
236 |
</tr>
|
237 |
<?php } ?>
|
238 |
<?php if ($display['size']){ ?>
|
239 |
+
<tr><td class="frm_150_width"><label><?php _e( 'Field Size', 'formidable' ) ?></label></td>
|
240 |
<td>
|
241 |
+
<?php
|
242 |
+
if ( in_array( $field['type'], array( 'select', 'time', 'data' ) ) ) {
|
243 |
+
if ( ! isset( $values['custom_style'] ) || $values['custom_style'] ) { ?>
|
244 |
+
<label for="size_<?php echo esc_attr( $field['id'] ) ?>"><input type="checkbox" name="field_options[size_<?php echo esc_attr( $field['id'] ) ?>]" id="size_<?php echo esc_attr( $field['id'] ) ?>" value="1" <?php echo ( isset($field['size']) && $field['size'] ) ? 'checked="checked"' : ''; ?> /> <?php _e( 'automatic width', 'formidable' ) ?></label>
|
245 |
+
<?php
|
246 |
+
}
|
247 |
+
} else { ?>
|
248 |
+
<input type="text" name="field_options[size_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['size'] ); ?>" size="5" /> <span class="howto"><?php _e( 'pixels wide', 'formidable' ) ?></span>
|
249 |
+
|
250 |
+
<input type="text" name="field_options[max_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['max'] ); ?>" size="5" /> <span class="howto"><?php echo ( $field['type'] == 'textarea' || $field['type'] == 'rte' ) ? __( 'rows high', 'formidable' ) : __( 'characters maximum', 'formidable' ) ?></span>
|
251 |
+
<?php
|
252 |
+
} ?>
|
253 |
</td>
|
254 |
</tr>
|
255 |
<?php } ?>
|
256 |
+
<?php do_action('frm_field_options_form', $field, $display, $values);
|
257 |
+
|
258 |
+
if ( $display['required'] || $display['invalid'] || $display['unique'] || $display['conf_field'] ) { ?>
|
259 |
+
<tr class="frm_validation_msg <?php echo ($display['invalid'] || $field['required'] || (isset($field['unique']) && $field['unique']) || ( isset($field['conf_field']) && $field['conf_field'] ) ) ? '' : 'frm_hidden'; ?>"><td colspan="2">
|
260 |
+
<div class="menu-settings">
|
261 |
+
<h3 class="frm_no_bg"><?php _e( 'Validation', 'formidable' ) ?></h3>
|
262 |
+
|
263 |
+
<div class="frm_validation_box">
|
264 |
+
<?php
|
265 |
+
if ( $display['required'] ) { ?>
|
266 |
+
<p class="frm_required_details<?php echo esc_attr( $field['id'] . ( $field['required'] ? '' : ' frm_hidden' ) ); ?>"><label><?php _e( 'Required', 'formidable' ) ?></label>
|
267 |
+
<input type="text" name="field_options[blank_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['blank'] ); ?>" />
|
268 |
</p>
|
269 |
+
<?php
|
270 |
+
}
|
271 |
+
|
272 |
+
if ( $display['invalid'] ) { ?>
|
273 |
+
<p><label><?php _e( 'Invalid Format', 'formidable' ) ?></label>
|
274 |
+
<input type="text" name="field_options[invalid_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['invalid'] ); ?>" />
|
275 |
</p>
|
276 |
+
<?php
|
277 |
+
}
|
278 |
+
|
279 |
+
if ( $display['unique'] ) { ?>
|
280 |
+
<p class="frm_unique_details<?php echo esc_attr( $field['id'] . ( $field['unique'] ? '' : ' frm_hidden' ) ); ?>">
|
281 |
+
<label><?php _e( 'Unique', 'formidable' ) ?></label>
|
282 |
+
<input type="text" name="field_options[unique_msg_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['unique_msg'] ); ?>" />
|
283 |
</p>
|
284 |
+
<?php
|
285 |
+
}
|
286 |
+
|
287 |
+
if ( $display['conf_field'] ) { ?>
|
288 |
+
<p class="frm_conf_details<?php echo esc_attr( $field['id'] . ( $field['conf_field'] ? '' : ' frm_hidden' ) ); ?>">
|
289 |
+
<label><?php _e( 'Confirmation', 'formidable' ) ?></label>
|
290 |
+
<input type="text" name="field_options[conf_msg_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['conf_msg'] ); ?>" />
|
291 |
+
</p>
|
292 |
+
<?php
|
293 |
+
} ?>
|
294 |
+
</div>
|
295 |
+
</div>
|
296 |
</td>
|
297 |
</tr>
|
298 |
<?php } ?>
|
299 |
+
|
300 |
</table>
|
301 |
</div>
|
302 |
</div>
|
303 |
+
<?php }
|
304 |
+
|
305 |
+
if ( $field['type'] == 'divider' ) { ?>
|
306 |
+
</div>
|
307 |
+
<div class="frm_no_section_fields">
|
308 |
+
<p class="howto"><?php _e( 'Drag fields from your form or the sidebar into this section', 'formidable' ) ?></p>
|
309 |
+
</div>
|
310 |
+
<ul class="start_divider frm_sorting">
|
311 |
+
<?php
|
312 |
+
} else if ( $field['type'] == 'end_divider' ) { ?>
|
313 |
+
</ul>
|
314 |
+
<?php
|
315 |
+
}
|
316 |
+
|
317 |
+
if ( ! isset( $ajax ) ) { ?>
|
318 |
</li>
|
319 |
+
<?php
|
320 |
+
}
|
321 |
+
|
322 |
+
unset($display);
|
classes/views/frm-forms/add_field_links.php
CHANGED
@@ -1,125 +1,171 @@
|
|
1 |
-
<div id="postbox-container-1" class="
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
if (!empty($frm_settings->preview_page_id)){ ?>
|
12 |
-
<?php _e('or', 'formidable') ?>
|
13 |
-
<a href="<?php echo add_query_arg('form', $values['form_key'], get_permalink($frm_settings->preview_page_id)) ?>" target="_blank"><?php _e('Preview in Current Theme', 'formidable') ?></a>
|
14 |
-
<?php } ?>
|
15 |
-
</p>
|
16 |
-
<?php }
|
17 |
-
} ?>
|
18 |
<div id="frm_position_ele"></div>
|
19 |
-
|
|
|
20 |
<div class="postbox frm_field_list">
|
21 |
<div class="inside">
|
22 |
<div id="taxonomy-linkcategory" class="categorydiv">
|
23 |
<ul id="category-tabs" class="category-tabs frm-category-tabs">
|
24 |
<li class="tabs" ><a href="#frm-insert-fields" id="frm_insert_fields_tab"><?php _e( 'Fields', 'formidable' ); ?></a></li>
|
25 |
-
<li class="hide-if-no-js"><a href="#frm-layout-classes" id="frm_layout_classes_tab"><?php _e( 'Layout', 'formidable' ); ?></a></li>
|
26 |
-
|
27 |
</ul>
|
28 |
|
29 |
-
<div id="frm-insert-fields" class="tabs-panel"
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
<li class="frmbutton button <?php echo $col_class
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
} ?>
|
49 |
-
|
50 |
-
|
51 |
</div>
|
52 |
<?php do_action('frm_extra_form_instructions'); ?>
|
53 |
-
|
54 |
-
<div id="frm-layout-classes" class="tabs-panel"
|
55 |
-
<p class="howto"><?php _e('Add classes in the "CSS layout classes" field option', 'formidable') ?></p>
|
56 |
<ul class="frm_code_list">
|
57 |
<?php $classes = array(
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
'
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
'
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
);
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
</a>
|
101 |
</li>
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
?>
|
108 |
</ul>
|
109 |
</div>
|
110 |
-
|
111 |
-
<?php
|
112 |
-
$action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
|
113 |
-
$action = FrmAppHelper::get_param($action);
|
114 |
-
$button = ($action == 'new' or $action == 'duplicate') ? __('Create', 'formidable') : __('Update', 'formidable');
|
115 |
-
?>
|
116 |
-
<form method="post" id="frm_js_build_form">
|
117 |
-
<input type="hidden" id="frm_compact_fields" name="frm_compact_fields" value="" />
|
118 |
-
<p><input type="button" onclick="frmSubmit<?php echo (isset($values['ajax_load']) and $values['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php echo esc_attr($button) ?>" class="frm_submit_form button-primary" id="frm_submit_side" />
|
119 |
-
<span class="frm-loading-img"></span>
|
120 |
-
</p>
|
121 |
-
</form>
|
122 |
</div>
|
123 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
</div>
|
125 |
-
</div>
|
1 |
+
<div id="postbox-container-1" class="postbox-container">
|
2 |
+
|
3 |
+
<?php
|
4 |
+
$action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
|
5 |
+
$action = sanitize_title( FrmAppHelper::get_param( $action ) );
|
6 |
+
$button = ( $action == 'new' || $action == 'duplicate' ) ? __( 'Create', 'formidable' ) : __( 'Update', 'formidable' );
|
7 |
+
|
8 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/_publish_box.php');
|
9 |
+
?>
|
10 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
<div id="frm_position_ele"></div>
|
12 |
+
|
13 |
+
|
14 |
<div class="postbox frm_field_list">
|
15 |
<div class="inside">
|
16 |
<div id="taxonomy-linkcategory" class="categorydiv">
|
17 |
<ul id="category-tabs" class="category-tabs frm-category-tabs">
|
18 |
<li class="tabs" ><a href="#frm-insert-fields" id="frm_insert_fields_tab"><?php _e( 'Fields', 'formidable' ); ?></a></li>
|
19 |
+
<li class="hide-if-no-js"><a href="#frm-layout-classes" id="frm_layout_classes_tab" class="frm_help" title="<?php esc_attr_e( 'Open the Field Options and click on the CSS Layout Classes option to enable this tab') ?>"><?php _e( 'Layout', 'formidable' ); ?></a></li>
|
20 |
+
<?php do_action('frm_extra_form_instruction_tabs'); ?>
|
21 |
</ul>
|
22 |
|
23 |
+
<div id="frm-insert-fields" class="tabs-panel">
|
24 |
+
<ul class="field_type_list">
|
25 |
+
<?php
|
26 |
+
$col_class = 'frm_col_one';
|
27 |
+
foreach ( $frm_field_selection as $field_key => $field_type ) { ?>
|
28 |
+
<li class="frmbutton button <?php echo esc_attr( $col_class .' frm_t'. $field_key ) ?>" id="<?php echo esc_attr( $field_key ) ?>"><a href="#" class="frm_add_field"><?php echo esc_html( $field_type ) ?></a></li>
|
29 |
+
<?php
|
30 |
+
$col_class = empty( $col_class ) ? 'frm_col_one' : '';
|
31 |
+
unset( $field_key, $field_type );
|
32 |
+
} ?>
|
33 |
+
</ul>
|
34 |
+
<div class="clear"></div>
|
35 |
+
<hr/>
|
36 |
+
<ul<?php echo apply_filters('frm_drag_field_class', '') ?> style="margin-top:2px;">
|
37 |
+
<?php
|
38 |
+
$col_class = 'frm_col_one';
|
39 |
+
$no_allow_class = apply_filters( 'frm_noallow_class', 'frm_noallow' );
|
40 |
+
foreach ( FrmFieldsHelper::pro_field_selection() as $field_key => $field_type ) {
|
41 |
+
|
42 |
+
if ( is_array( $field_type ) ) {
|
43 |
+
$field_label = $field_type['name'];
|
44 |
+
|
45 |
+
if ( isset( $field_type['switch_from'] ) ) { ?>
|
46 |
+
<li class="frmbutton button <?php echo esc_attr( $col_class .' '. $no_allow_class .' frm_t'. $field_key ) ?>" id="<?php echo esc_attr( $field_key ) ?>" data-switchto="<?php echo esc_attr( $field_type['switch_from'] ) ?>" style="display:none !important;"><?php echo apply_filters( 'frmpro_field_links', $field_label, $id, $field_key ) ?></li>
|
47 |
+
<?php
|
48 |
+
continue;
|
49 |
+
}
|
50 |
+
|
51 |
+
?>
|
52 |
+
<li class="frmbutton button <?php echo esc_attr( $col_class .' '. $no_allow_class .' frm_t'. $field_key ) ?> dropdown" id="<?php echo esc_attr( $field_key ) ?>" <?php echo ( isset( $field_type['switch_to'] ) ) ? 'data-switchto="'. esc_attr( $field_type['switch_to'] ) .'"' : ''; ?>>
|
53 |
+
<a href="#" id="frm-<?php echo esc_attr( $field_key ) ?>Drop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php echo esc_html( $field_label ) ?> <b class="caret"></b></a>
|
54 |
+
|
55 |
+
<ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-<?php echo esc_attr( $field_key ) ?>Drop">
|
56 |
+
<?php
|
57 |
+
foreach ( $field_type['types'] as $k => $type ) { ?>
|
58 |
+
<li class="frm_t<?php echo esc_attr( $field_key ) ?>" id="<?php echo esc_attr( $field_key ) ?>|<?php echo esc_attr( $k ) ?>"><?php echo apply_filters( 'frmpro_field_links', $type, $id, $field_key .'|'. $k ) ?></li>
|
59 |
+
<?php
|
60 |
+
unset( $k, $type );
|
61 |
+
} ?>
|
62 |
+
</ul>
|
63 |
+
</li>
|
64 |
+
<?php
|
65 |
+
} else {
|
66 |
+
$field_label = $field_type;
|
67 |
+
?>
|
68 |
+
<li class="frmbutton button <?php echo esc_attr( $col_class .' '. $no_allow_class .' frm_t'. $field_key ) ?>" id="<?php echo esc_attr( $field_key ) ?>"><?php echo apply_filters( 'frmpro_field_links', $field_label, $id, $field_key ) ?></li>
|
69 |
+
<?php
|
70 |
+
}
|
71 |
+
|
72 |
+
$col_class = empty($col_class) ? 'frm_col_one' : '';
|
73 |
+
unset($field_key, $field_type, $field_label);
|
74 |
} ?>
|
75 |
+
</ul>
|
76 |
+
<div class="clear"></div>
|
77 |
</div>
|
78 |
<?php do_action('frm_extra_form_instructions'); ?>
|
79 |
+
|
80 |
+
<div id="frm-layout-classes" class="tabs-panel">
|
81 |
+
<p class="howto"><?php _e( 'Add classes in the "CSS layout classes" field option', 'formidable' ) ?></p>
|
82 |
<ul class="frm_code_list">
|
83 |
<?php $classes = array(
|
84 |
+
'frm_first' => array(
|
85 |
+
'label' => __( 'First', 'formidable' ),
|
86 |
+
'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm_third', 'formidable' ),
|
87 |
+
),
|
88 |
+
'frm_last' => array(
|
89 |
+
'label' => __( 'Last', 'formidable' ),
|
90 |
+
'title' => __( 'Add this to the last field in each row along with a width. ie frm_last frm_third', 'formidable' ),
|
91 |
+
),
|
92 |
+
'frm_half' => __( '1/2', 'formidable' ),
|
93 |
+
'frm_third' => __( '1/3', 'formidable' ),
|
94 |
+
'frm_two_thirds' => __( '2/3', 'formidable' ),
|
95 |
+
'frm_fourth' => __( '1/4', 'formidable' ),
|
96 |
+
'frm_fifth' => __( '1/5', 'formidable' ),
|
97 |
+
'frm_sixth' => __( '1/6', 'formidable' ),
|
98 |
+
'frm_seventh' => __( '1/7', 'formidable' ),
|
99 |
+
'frm_eigth' => __( '1/8', 'formidable' ),
|
100 |
+
'frm_inline' => array(
|
101 |
+
'label' => __( 'Inline', 'formidable' ),
|
102 |
+
'title' => __( 'Align fields in a row without a specific width.', 'formidable' )
|
103 |
+
),
|
104 |
+
|
105 |
+
'frm_full' => array(
|
106 |
+
'label' => __( '100% width', 'formidable' ),
|
107 |
+
'title' => __( 'Force the field to fill the full space with 100% width.', 'formidable' )
|
108 |
+
),
|
109 |
+
'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
|
110 |
+
'frm_grid' => __( 'Even Grid Row', 'formidable' ),
|
111 |
+
'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
|
112 |
+
'frm_two_col' => array( 'label' => __( '2 Col Options', 'formidable' ), 'title' => __( 'Put your radio button or checkbox options into two columns.', 'formidable' )),
|
113 |
+
'frm_three_col' => array( 'label' => __( '3 Col Options', 'formidable' ), 'title' => __( 'Put your radio button or checkbox options into three columns.', 'formidable' )),
|
114 |
+
'frm_four_col' => array( 'label' => __( '4 Col Options', 'formidable' ), 'title' => __( 'Put your radio button or checkbox options into four columns.', 'formidable' )),
|
115 |
+
'frm_total' => array( 'label' => __( 'Total', 'formidable' ), 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' )),
|
116 |
+
'frm_scroll_box' => array( 'label' => __( 'Scroll Box', 'formidable' ), 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options.', 'formidable' ))
|
117 |
);
|
118 |
+
|
119 |
+
$classes = apply_filters( 'frm_layout_classes', $classes );
|
120 |
+
$col = 'one';
|
121 |
+
foreach ( $classes as $c => $d ) {
|
122 |
+
$title = ( ! empty( $d ) && is_array( $d ) && isset( $d['title'] ) ) ? $d['title'] : '';
|
123 |
+
?>
|
124 |
+
<li class="frm_col_<?php echo esc_attr( $col ) ?>">
|
125 |
+
<a href="javascript:void(0);" class="frmbutton frm_insert_code button show_frm_classes<?php
|
126 |
+
if ( ! empty( $title ) ) {
|
127 |
+
echo ' frm_help';
|
128 |
+
} ?>" data-code="<?php echo esc_attr($c) ?>" <?php
|
129 |
+
if ( ! empty( $title ) ) {
|
130 |
+
?>title="<?php echo esc_attr($title); ?>"<?php
|
131 |
+
} ?>>
|
132 |
+
<?php
|
133 |
+
if ( empty( $d ) ) {
|
134 |
+
echo $c;
|
135 |
+
} else if ( ! is_array( $d ) ) {
|
136 |
+
echo $d;
|
137 |
+
} else if ( isset( $d['label'] ) ) {
|
138 |
+
echo $d['label'];
|
139 |
+
}
|
140 |
+
?>
|
141 |
</a>
|
142 |
</li>
|
143 |
+
<?php
|
144 |
+
$col = ( $col == 'one' ) ? 'two' : 'one';
|
145 |
+
unset( $c, $d );
|
146 |
+
}
|
147 |
+
?>
|
|
|
148 |
</ul>
|
149 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
</div>
|
151 |
</div>
|
152 |
+
|
153 |
+
<div class="submitbox" id="major-publishing-actions">
|
154 |
+
<div id="delete-action">
|
155 |
+
<?php echo FrmFormsHelper::delete_trash_link($id, $values['status']); ?>
|
156 |
+
</div>
|
157 |
+
|
158 |
+
<div id="publishing-action">
|
159 |
+
<form method="post" id="frm_js_build_form">
|
160 |
+
<span class="spinner"></span>
|
161 |
+
<input type="hidden" id="frm_compact_fields" name="frm_compact_fields" value="" />
|
162 |
+
<input type="button" value="<?php echo esc_attr($button) ?>" class="frm_submit_form frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-primary button-large" id="frm_submit_side" />
|
163 |
+
</form>
|
164 |
+
</div>
|
165 |
+
<div class="clear"></div>
|
166 |
+
</div><!-- #major-publishing-actions -->
|
167 |
+
|
168 |
+
|
169 |
+
|
170 |
</div>
|
171 |
+
</div>
|
classes/views/frm-forms/default-templates.php
DELETED
@@ -1,47 +0,0 @@
|
|
1 |
-
<?php FrmFormsHelper::get_template_dropdown($all_templates); ?>
|
2 |
-
|
3 |
-
<h3><?php _e('Default Templates', 'formidable') ?></h3>
|
4 |
-
<table class="widefat post fixed" id="posts-filter" cellspacing="0">
|
5 |
-
<thead>
|
6 |
-
<tr>
|
7 |
-
<th class="manage-column" width="30%"><?php _e('Name') ?></th>
|
8 |
-
<th class="manage-column"><?php _e('Description') ?></th>
|
9 |
-
</tr>
|
10 |
-
</thead>
|
11 |
-
<?php if(empty($default_templates)){ ?>
|
12 |
-
<tr><td colspan="2"><?php _e('No Templates Found', 'formidable') ?></td></tr>
|
13 |
-
<?php
|
14 |
-
}else{
|
15 |
-
$alternate = false;
|
16 |
-
foreach($default_templates as $form){
|
17 |
-
$alternate = (!$alternate) ? 'alternate' : false;
|
18 |
-
?>
|
19 |
-
<tr class="<?php echo $alternate ?>">
|
20 |
-
<td class="post-title">
|
21 |
-
<a class="row-title" href="<?php echo $url = FrmFormsHelper::get_direct_link($form->form_key, $form); ?>" title="<?php _e('View', 'formidable')?> <?php echo esc_attr($form->name) ?>" target="blank"><?php echo $form->name; ?></a><br/>
|
22 |
-
<div class="row-actions">
|
23 |
-
<?php if(current_user_can('frm_edit_forms')){ ?>
|
24 |
-
<span><a href="?page=formidable&frm_action=duplicate&id=<?php echo $form->id; ?>"><?php _e('Create Form from Template', 'formidable') ?></a></span> |
|
25 |
-
<?php } ?>
|
26 |
-
<?php global $frm_settings;
|
27 |
-
if ($frm_settings->preview_page_id > 0)
|
28 |
-
$url = add_query_arg('form', $form->form_key, get_permalink($frm_settings->preview_page_id));
|
29 |
-
?>
|
30 |
-
<span><a href="<?php echo $url ?>" target="blank"><?php _e('View', 'formidable') ?></a></span>
|
31 |
-
</div>
|
32 |
-
</td>
|
33 |
-
<td><?php echo $form->description ?></td>
|
34 |
-
</tr>
|
35 |
-
<?php
|
36 |
-
}
|
37 |
-
}
|
38 |
-
?>
|
39 |
-
<tfoot>
|
40 |
-
<tr>
|
41 |
-
<th class="manage-column"><?php _e('Name') ?></th>
|
42 |
-
<th class="manage-column"><?php _e('Description') ?></th>
|
43 |
-
</tr>
|
44 |
-
</tfoot>
|
45 |
-
</table>
|
46 |
-
|
47 |
-
<br/><br/><h3><?php _e('Custom Templates', 'formidable') ?></h3>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/views/frm-forms/edit.php
CHANGED
@@ -1,53 +1,48 @@
|
|
1 |
<div class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
-
<h2><?php echo ( $form->is_template ? __('Templates', 'formidable') : __('Build', 'formidable')); ?>
|
4 |
-
<a href="?page=formidable&frm_action=new
|
5 |
</h2>
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
<div id="poststuff" class="metabox-holder has-right-sidebar">
|
14 |
-
<?php
|
15 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
|
16 |
-
}else{ ?>
|
17 |
-
<div id="poststuff">
|
18 |
-
<?php } ?>
|
19 |
|
20 |
<div id="post-body" class="metabox-holder columns-2">
|
21 |
<div id="post-body-content">
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
<span class="frm-loading-img"></span>
|
29 |
</p>
|
30 |
-
|
31 |
<form method="post" id="frm_build_form">
|
32 |
<input type="hidden" name="frm_action" value="update" />
|
33 |
<input type="hidden" name="action" value="update" />
|
34 |
-
<input type="hidden" name="id" value="<?php echo $id; ?>" />
|
35 |
|
36 |
<?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
|
37 |
|
38 |
-
<p>
|
39 |
-
|
40 |
-
<?php _e('or', 'formidable') ?>
|
41 |
-
<a class="button-secondary cancel" href="?page=formidable<?php echo $form->is_template ? '-templates' : ''; ?>"><?php _e('Cancel', 'formidable') ?></a>
|
42 |
<span class="frm-loading-img"></span>
|
43 |
</p>
|
44 |
</form>
|
45 |
</div>
|
46 |
</div>
|
47 |
-
<?php
|
48 |
-
if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
|
49 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
|
50 |
-
?>
|
51 |
</div>
|
52 |
</div>
|
53 |
</div>
|
1 |
<div class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
+
<h2><?php echo ( $form->is_template ? __( 'Templates', 'formidable' ) : __( 'Build', 'formidable' )); ?>
|
4 |
+
<a href="?page=formidable&frm_action=new" class="add-new-h2"><?php _e( 'Add New', 'formidable' ); ?></a>
|
5 |
</h2>
|
6 |
+
|
7 |
+
<?php
|
8 |
+
// Add form messages
|
9 |
+
require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' );
|
10 |
+
?>
|
11 |
+
|
12 |
+
<div id="poststuff">
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
<div id="post-body" class="metabox-holder columns-2">
|
15 |
<div id="post-body-content">
|
16 |
+
<?php
|
17 |
+
|
18 |
+
// Add form nav
|
19 |
+
if ( ! $values['is_template'] ) {
|
20 |
+
FrmAppController::get_form_nav( $id, true, 'hide' );
|
21 |
+
}
|
22 |
+
|
23 |
+
?>
|
24 |
+
<div class="frm_form_builder<?php echo FrmFormsHelper::get_form_style_class($form); ?>">
|
25 |
+
|
26 |
+
<p class="frm_hidden frm-no-margin">
|
27 |
+
<input type="button" value="<?php esc_attr_e( 'Update', 'formidable' ) ?>" class="frm_submit_<?php echo ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_'; ?>ajax button-primary" />
|
28 |
<span class="frm-loading-img"></span>
|
29 |
</p>
|
30 |
+
|
31 |
<form method="post" id="frm_build_form">
|
32 |
<input type="hidden" name="frm_action" value="update" />
|
33 |
<input type="hidden" name="action" value="update" />
|
34 |
+
<input type="hidden" name="id" id="form_id" value="<?php echo (int) $id; ?>" />
|
35 |
|
36 |
<?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
|
37 |
|
38 |
+
<p>
|
39 |
+
<input type="button" value="<?php esc_attr_e( 'Update', 'formidable' ) ?>" class="frm_submit_<?php echo ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_'; ?>ajax button-primary" />
|
|
|
|
|
40 |
<span class="frm-loading-img"></span>
|
41 |
</p>
|
42 |
</form>
|
43 |
</div>
|
44 |
</div>
|
45 |
+
<?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php'); ?>
|
|
|
|
|
|
|
46 |
</div>
|
47 |
</div>
|
48 |
</div>
|
classes/views/frm-forms/form.php
CHANGED
@@ -1,33 +1,61 @@
|
|
1 |
<?php wp_nonce_field('frm_save_form_nonce', 'frm_save_form'); ?>
|
|
|
|
|
2 |
|
3 |
<div id="frm_form_editor_container">
|
4 |
<div id="titlediv">
|
5 |
-
<input type="text" name="name" value="<?php echo esc_attr($form->name); ?>" id="title" placeholder="<?php esc_attr_e('Enter title here') ?>" />
|
6 |
<div id="edit-slug-box" class="hide-if-no-js">
|
7 |
-
<div
|
8 |
-
<strong><?php _e('Form Key:', 'formidable') ?></strong>
|
9 |
-
|
10 |
</div>
|
11 |
-
<div class="frm_ipe_form_desc alignleft"
|
12 |
-
<div
|
13 |
</div>
|
14 |
</div>
|
15 |
|
16 |
<div <?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'class="postbox"' : ''; ?>>
|
17 |
-
<div class="frm_no_fields <?php echo ( isset($values['fields']) && ! empty($values['fields']) ) ? 'frm_hidden' : ''; ?>">
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
</div>
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
<?php
|
26 |
if ( isset($values['fields']) && ! empty($values['fields']) ) {
|
27 |
$count = 0;
|
28 |
foreach ( $values['fields'] as $field ) {
|
29 |
$count++;
|
30 |
$field_name = 'item_meta['. $field['id'] .']';
|
|
|
31 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
|
32 |
unset($field, $field_name);
|
33 |
}
|
1 |
<?php wp_nonce_field('frm_save_form_nonce', 'frm_save_form'); ?>
|
2 |
+
<input type="hidden" name="status" value="<?php echo esc_attr( $values['status'] ); ?>" />
|
3 |
+
<input type="hidden" name="new_status" value="" />
|
4 |
|
5 |
<div id="frm_form_editor_container">
|
6 |
<div id="titlediv">
|
7 |
+
<input type="text" name="name" value="<?php echo esc_attr($form->name); ?>" id="title" placeholder="<?php esc_attr_e( 'Enter title here') ?>" />
|
8 |
<div id="edit-slug-box" class="hide-if-no-js">
|
9 |
+
<div id="frm_form_key_box" class="alignright">
|
10 |
+
<strong><?php _e( 'Form Key:', 'formidable' ) ?></strong>
|
11 |
+
<div id="editable-post-name" class="frm_ipe_form_key" title="<?php esc_attr_e( 'Click to edit.', 'formidable' ) ?>"><?php echo esc_html( $form->form_key ); ?></div>
|
12 |
</div>
|
13 |
+
<div id="frm_form_desc" class="frm_ipe_form_desc alignleft"><?php echo ($form->description == '') ? __( '(Click to add description)', 'formidable' ) : force_balance_tags($form->description); ?></div>
|
14 |
+
<div class="frm_clear"></div>
|
15 |
</div>
|
16 |
</div>
|
17 |
|
18 |
<div <?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'class="postbox"' : ''; ?>>
|
19 |
+
<div class="frm_no_fields <?php echo ( isset($values['fields']) && ! empty($values['fields']) ) ? 'frm_hidden' : ''; ?>">
|
20 |
+
<div class="alignleft sketch1">
|
21 |
+
<img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow1.png'; ?>" alt="" />
|
22 |
+
</div>
|
23 |
+
<div class="alignleft sketch1_text">
|
24 |
+
<?php _e( '1. Name your form', 'formidable' ) ?>
|
25 |
+
</div>
|
26 |
+
|
27 |
+
<div class="alignright sketch2">
|
28 |
+
<?php _e( '2. Click or drag a field to<br/>add it to your form', 'formidable' ) ?>
|
29 |
+
<div class="clear"></div>
|
30 |
+
<img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow2.png'; ?>" alt="" />
|
31 |
+
</div>
|
32 |
+
<div class="clear"></div>
|
33 |
+
|
34 |
+
<div class="frm_drag_inst"><?php _e( 'Add Fields Here', 'formidable' ) ?></div>
|
35 |
+
<p id="frm_create_template_form">
|
36 |
+
<?php _e( 'Or load fields from a template', 'formidable' ); ?>
|
37 |
+
<select id="frm_create_template_dropdown">
|
38 |
+
<?php foreach ( $all_templates as $temp ) { ?>
|
39 |
+
<option value="<?php echo esc_attr( $temp->id ) ?>"><?php echo FrmAppHelper::truncate( $temp->name, 40 ) ?></option>
|
40 |
+
<?php } ?>
|
41 |
+
</select>
|
42 |
+
<input type="button" id="frm_create_template_button" class="button-secondary" value="<?php esc_attr_e( 'Load Template', 'formidable' ) ?>" />
|
43 |
+
</p>
|
44 |
+
|
45 |
+
<div class="alignleft sketch3">
|
46 |
+
<div class="alignright"><?php _e( '3. Save your form', 'formidable' ) ?></div>
|
47 |
+
<img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow3.png'; ?>" alt="" />
|
48 |
+
</div>
|
49 |
+
<div class="clear"></div>
|
50 |
+
</div>
|
51 |
+
<ul id="new_fields" class="frm_sorting <?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'inside' : ''; ?>">
|
52 |
<?php
|
53 |
if ( isset($values['fields']) && ! empty($values['fields']) ) {
|
54 |
$count = 0;
|
55 |
foreach ( $values['fields'] as $field ) {
|
56 |
$count++;
|
57 |
$field_name = 'item_meta['. $field['id'] .']';
|
58 |
+
$html_id = FrmFieldsHelper::get_html_id($field);
|
59 |
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
|
60 |
unset($field, $field_name);
|
61 |
}
|
classes/views/frm-forms/insert_form_popup.php
CHANGED
@@ -1,70 +1,50 @@
|
|
1 |
-
<script type="text/javascript">
|
2 |
-
function frm_insert_form(){
|
3 |
-
var form_id=jQuery("#frm_add_form_id").val();
|
4 |
-
if(form_id==""){alert("<?php _e('Please select a form', 'formidable') ?>");return;}
|
5 |
-
var title_qs=jQuery("#frm_display_title").is(":checked") ? " title=true" : "";
|
6 |
-
var description_qs=jQuery("#frm_display_description").is(":checked") ? " description=true" : "";
|
7 |
-
var win = window.dialogArguments || opener || parent || top;
|
8 |
-
win.send_to_editor("[formidable id="+form_id+title_qs+description_qs+"]");
|
9 |
-
}
|
10 |
-
|
11 |
-
function frm_insert_display(){
|
12 |
-
var display_id = jQuery("#frm_add_display_id").val();
|
13 |
-
if(display_id==""){alert("<?php _e('Please select a view', 'formidable') ?>");return;}
|
14 |
-
var filter_qs=jQuery("#frm_filter_content").is(":checked") ? " filter=1" : "";
|
15 |
-
var win = window.dialogArguments || opener || parent || top;
|
16 |
-
win.send_to_editor("[display-frm-data id="+display_id+filter_qs+"]");
|
17 |
-
}
|
18 |
-
|
19 |
-
function frm_insert_search(){
|
20 |
-
var win = window.dialogArguments || opener || parent || top;
|
21 |
-
win.send_to_editor("[frm-search]");
|
22 |
-
}
|
23 |
-
</script>
|
24 |
-
<style type="text/css">
|
25 |
-
#frm_popup_content h3{
|
26 |
-
color:#5A5A5A;
|
27 |
-
font-family:Georgia,"Times New Roman",Times,serif;
|
28 |
-
font-weight:normal;
|
29 |
-
font-size:1.6em;
|
30 |
-
}
|
31 |
-
.frm_box_line{border-bottom:1px solid #DFDFDF;display:block;margin:20px 0;}
|
32 |
-
</style>
|
33 |
|
34 |
-
<div id="frm_insert_form"
|
35 |
-
<div
|
36 |
-
<
|
37 |
-
|
38 |
-
<p><?php FrmFormsHelper::forms_dropdown( 'frm_add_form_id' )?></p>
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
<option value=""></option>
|
53 |
-
<?php foreach ($displays as $display){ ?>
|
54 |
-
<option value="<?php echo $display->ID ?>"><?php echo $display->post_title ?></option>
|
55 |
<?php } ?>
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
<
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
</div>
|
70 |
-
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
+
<div id="frm_insert_form" class="frm_hidden">
|
3 |
+
<div id="frm_popup_content">
|
4 |
+
<div class="media-modal wp-core-ui">
|
5 |
+
<a href="#" class="media-modal-close"><span class="media-modal-icon"><span class="screen-reader-text"><?php _e( 'Close panel', 'formidable' ) ?></span></span></a>
|
|
|
6 |
|
7 |
+
<div class="media-modal-content">
|
8 |
+
<div class="media-frame mode-select wp-core-ui hide-router">
|
9 |
+
|
10 |
+
<div id="frm_insert_form_content">
|
11 |
+
|
12 |
+
<div class="media-frame-menu">
|
13 |
+
<div class="media-menu">
|
14 |
+
<?php foreach ( $shortcodes as $shortcode => $labels ) { ?>
|
15 |
+
<a href="#" class="media-menu-item frm_switch_sc" id="sc-link-<?php echo esc_attr( $shortcode ) ?>">
|
16 |
+
<?php echo esc_html( $labels['name'] ) ?>
|
17 |
+
<span class="howto"><?php echo esc_html( $labels['label'] ) ?></span>
|
18 |
+
</a>
|
|
|
|
|
|
|
19 |
<?php } ?>
|
20 |
+
<div class="clear"></div>
|
21 |
+
</div>
|
22 |
+
</div>
|
23 |
+
|
24 |
+
<div class="media-frame-title"><h1><?php _e( 'Insert a Form', 'formidable' ) ?> <span class="spinner"></span><span class="dashicons dashicons-arrow-down"></span></h1></div>
|
25 |
+
|
26 |
+
<div class="media-frame-content">
|
27 |
+
<div class="attachments-browser">
|
28 |
+
<div id="frm_shortcode_options" class="media-embed">
|
29 |
+
|
30 |
+
</div>
|
31 |
+
</div>
|
32 |
+
</div>
|
33 |
+
|
34 |
+
<div class="media-frame-toolbar">
|
35 |
+
<div class="media-toolbar">
|
36 |
+
<div class="media-toolbar-secondary">
|
37 |
+
<input type="text" value="" id="frm_complete_shortcode" />
|
38 |
+
</div>
|
39 |
+
<div class="media-toolbar-primary search-form">
|
40 |
+
<a href="javascript:void(0);" class="button-primary button button-large media-button-group" id="frm_insert_shortcode"><?php _e( 'Insert into Post', 'formidable' ) ?></a>
|
41 |
+
</div>
|
42 |
+
</div>
|
43 |
+
</div>
|
44 |
+
</div>
|
45 |
+
</div>
|
46 |
+
|
47 |
+
</div>
|
48 |
+
</div>
|
49 |
</div>
|
50 |
+
</div>
|
classes/views/frm-forms/list.php
CHANGED
@@ -1,21 +1,28 @@
|
|
1 |
<div class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
7 |
</h2>
|
8 |
-
|
9 |
-
<?php
|
|
|
|
|
|
|
10 |
|
11 |
<form id="posts-filter" method="get">
|
12 |
-
<input type="hidden" name="page" value="<?php echo $_GET['page'] ?>" />
|
13 |
<input type="hidden" name="frm_action" value="list" />
|
14 |
-
<?php
|
15 |
|
16 |
-
|
|
|
17 |
|
18 |
-
|
19 |
</form>
|
20 |
|
21 |
-
</div>
|
1 |
<div class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
+
<h2 id="frm_form_page_header">
|
4 |
+
<?php
|
5 |
+
echo $params['template'] ? __( 'Templates', 'formidable' ) : __( 'Forms', 'formidable' );
|
6 |
+
if ( ! $params['template'] && current_user_can( 'frm_edit_forms' ) ) { ?>
|
7 |
+
<a href="?page=formidable&frm_action=new" class="add-new-h2"><?php _e( 'Add New', 'formidable' ); ?></a>
|
8 |
+
<?php
|
9 |
+
} ?>
|
10 |
</h2>
|
11 |
+
|
12 |
+
<?php
|
13 |
+
require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' );
|
14 |
+
$wp_list_table->views();
|
15 |
+
?>
|
16 |
|
17 |
<form id="posts-filter" method="get">
|
18 |
+
<input type="hidden" name="page" value="<?php echo esc_attr( $_GET['page'] ) ?>" />
|
19 |
<input type="hidden" name="frm_action" value="list" />
|
20 |
+
<?php
|
21 |
|
22 |
+
$wp_list_table->search_box( __( 'Search', 'formidable' ), 'entry' );
|
23 |
+
$wp_list_table->display();
|
24 |
|
25 |
+
?>
|
26 |
</form>
|
27 |
|
28 |
+
</div>
|
classes/views/frm-forms/mb_html_tab.php
CHANGED
@@ -1,54 +1,53 @@
|
|
1 |
-
<div id="frm-html-tags" class="tabs-panel"
|
2 |
<ul class="frm_code_list">
|
3 |
<?php
|
4 |
$col = 'one';
|
5 |
$entry_shortcodes = array(
|
6 |
-
'id' => __('Field ID', 'formidable'),
|
7 |
-
'key' => __('Field Key', 'formidable'),
|
8 |
-
'field_name' => __('Field Name', 'formidable'),
|
9 |
-
'description' => __('Field Description', 'formidable'),
|
10 |
-
'label_position' => __('Label Position', 'formidable'),
|
11 |
-
'required_label' => __('Required Label', 'formidable'),
|
12 |
-
'input' => __('Input Field', 'formidable'),
|
13 |
-
'input opt=1' => array('label' => __('Single Option', 'formidable'), 'title' => __('Show a single radio or checkbox option by replacing
|
14 |
-
'input label=0' => __('Hide Option Label', 'formidable'),
|
15 |
-
'required_class' => array('label' => __('Required Class', 'formidable'), 'title' => __('Add class name if field is required', 'formidable')),
|
16 |
-
'error_class' => array('label' => __('Error Class', 'formidable'), 'title' => __('Add class name if field has an error on form submit', 'formidable'))
|
17 |
);
|
18 |
|
19 |
-
|
20 |
?>
|
21 |
-
<li class="frm_col_<?php echo $col ?>">
|
22 |
-
<a class="show_field_custom_html frmbutton button frm_insert_code <?php echo is_array($sname) ? 'frm_help' : ''; ?>" data-code="<?php echo esc_attr($skey) ?>"
|
23 |
</li>
|
24 |
<?php
|
25 |
$col = ($col == 'one') ? 'two' : 'one';
|
26 |
-
unset($skey);
|
27 |
-
unset($sname);
|
28 |
}
|
29 |
?>
|
30 |
</ul>
|
31 |
-
|
32 |
<ul class="frm_code_list clear">
|
33 |
-
<?php
|
34 |
$col = 'one';
|
35 |
-
|
36 |
-
'form_name' => __('Form Name', 'formidable'), 'form_description' => __('Form Description', 'formidable'),
|
37 |
-
'form_key' => __('Form Key', 'formidable'), 'deletelink' => __('Delete Entry Link', 'formidable')) as $skey => $sname){ ?>
|
38 |
-
<li class="frm_col_<?php echo $col ?>">
|
39 |
-
<a class="show_before_html show_after_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>"
|
40 |
</li>
|
41 |
<?php
|
42 |
-
$col = ($col == 'one') ? 'two' : 'one';
|
43 |
}
|
44 |
-
|
45 |
-
foreach(array(
|
46 |
-
'button_label' => __('Button Label', 'formidable'), 'button_action' => __('Button Hook', 'formidable')) as $skey => $sname){ ?>
|
47 |
-
<li class="frm_col_<?php echo $col ?>">
|
48 |
-
<a class="show_submit_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>"
|
49 |
</li>
|
50 |
<?php
|
51 |
-
$col = ($col == 'one') ? 'two' : 'one';
|
52 |
} ?>
|
53 |
</ul>
|
54 |
</div>
|
1 |
+
<div id="frm-html-tags" class="tabs-panel">
|
2 |
<ul class="frm_code_list">
|
3 |
<?php
|
4 |
$col = 'one';
|
5 |
$entry_shortcodes = array(
|
6 |
+
'id' => __( 'Field ID', 'formidable' ),
|
7 |
+
'key' => __( 'Field Key', 'formidable' ),
|
8 |
+
'field_name' => __( 'Field Name', 'formidable' ),
|
9 |
+
'description' => __( 'Field Description', 'formidable' ),
|
10 |
+
'label_position' => __( 'Label Position', 'formidable' ),
|
11 |
+
'required_label' => __( 'Required Label', 'formidable' ),
|
12 |
+
'input' => __( 'Input Field', 'formidable' ),
|
13 |
+
'input opt=1' => array( 'label' => __( 'Single Option', 'formidable' ), 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' )),
|
14 |
+
'input label=0' => __( 'Hide Option Label', 'formidable' ),
|
15 |
+
'required_class' => array( 'label' => __( 'Required Class', 'formidable' ), 'title' => __( 'Add class name if field is required', 'formidable' )),
|
16 |
+
'error_class' => array( 'label' => __( 'Error Class', 'formidable' ), 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ))
|
17 |
);
|
18 |
|
19 |
+
foreach ( $entry_shortcodes as $skey => $sname ) {
|
20 |
?>
|
21 |
+
<li class="frm_col_<?php echo esc_attr( $col ) ?>">
|
22 |
+
<a href="javascript:void(0)" class="show_field_custom_html frmbutton button frm_insert_code <?php echo is_array($sname) ? 'frm_help' : ''; ?>" data-code="<?php echo esc_attr($skey) ?>" <?php echo is_array($sname) ? 'title="'. $sname['title'] .'"' : ''; ?>><?php echo is_array($sname) ? $sname['label'] : $sname; ?></a>
|
23 |
</li>
|
24 |
<?php
|
25 |
$col = ($col == 'one') ? 'two' : 'one';
|
26 |
+
unset($skey, $sname);
|
|
|
27 |
}
|
28 |
?>
|
29 |
</ul>
|
30 |
+
|
31 |
<ul class="frm_code_list clear">
|
32 |
+
<?php
|
33 |
$col = 'one';
|
34 |
+
foreach ( array(
|
35 |
+
'form_name' => __( 'Form Name', 'formidable' ), 'form_description' => __( 'Form Description', 'formidable' ),
|
36 |
+
'form_key' => __( 'Form Key', 'formidable' ), 'deletelink' => __( 'Delete Entry Link', 'formidable' ) ) as $skey => $sname ) { ?>
|
37 |
+
<li class="frm_col_<?php echo esc_attr( $col ) ?>">
|
38 |
+
<a href="javascript:void(0)" class="show_before_html show_after_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>"><?php echo $sname; ?></a>
|
39 |
</li>
|
40 |
<?php
|
41 |
+
$col = ($col == 'one') ? 'two' : 'one';
|
42 |
}
|
43 |
+
|
44 |
+
foreach ( array(
|
45 |
+
'button_label' => __( 'Button Label', 'formidable' ), 'button_action' => __( 'Button Hook', 'formidable' ) ) as $skey => $sname ) { ?>
|
46 |
+
<li class="frm_col_<?php echo esc_attr( $col ) ?>">
|
47 |
+
<a href="javascript:void(0)" class="show_submit_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>"><?php echo $sname; ?></a>
|
48 |
</li>
|
49 |
<?php
|
50 |
+
$col = ($col == 'one') ? 'two' : 'one';
|
51 |
} ?>
|
52 |
</ul>
|
53 |
</div>
|
classes/views/frm-forms/mb_insert_fields.php
CHANGED
@@ -1,23 +1,7 @@
|
|
1 |
<div id="frm_adv_info" class="postbox">
|
2 |
-
|
|
|
3 |
<div class="inside">
|
4 |
-
<?php
|
5 |
-
|
6 |
-
}else{ ?>
|
7 |
-
<div id="taxonomy-linkcategory" class="categorydiv">
|
8 |
-
<ul id="category-tabs" class="category-tabs frm-category-tabs">
|
9 |
-
<li class="tabs" ><a href="#frm-insert-fields-box" id="frm_insert_fields_tab" ><?php _e( 'Insert Fields', 'formidable' ); ?></a></li>
|
10 |
-
<li class="hide-if-no-js"><a href="#frm-html-tags" id="frm_html_tags_tab" ><?php _e( 'HTML Tags', 'formidable' ); ?></a></li>
|
11 |
-
</ul>
|
12 |
-
<div id="frm-insert-fields-box" class="tabs-panel" style="max-height:none;padding-right:0;">
|
13 |
-
<br/><br/>
|
14 |
-
<?php FrmAppController::update_message('insert field values into your messages'); ?>
|
15 |
-
</div>
|
16 |
-
<?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/mb_html_tab.php'); ?>
|
17 |
-
</div>
|
18 |
-
<?php
|
19 |
-
} ?>
|
20 |
-
|
21 |
-
|
22 |
-
</div>
|
23 |
</div>
|
1 |
<div id="frm_adv_info" class="postbox">
|
2 |
+
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'formidable' ) ?>"><br/></div>
|
3 |
+
<h3 class="hndle"><span><?php _e( 'Customization', 'formidable' ) ?></span></h3>
|
4 |
<div class="inside">
|
5 |
+
<?php FrmFormsController::mb_tags_box($id); ?>
|
6 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
</div>
|
classes/views/frm-forms/new-field-js.php
CHANGED
@@ -1 +1 @@
|
|
1 |
-
<?php _deprecated_file( basename(__FILE__), '1.07.10', null, __( 'This file no longer needs to be included.' ) );
|
1 |
+
<?php _deprecated_file( basename(__FILE__), '1.07.10', null, __( 'This file no longer needs to be included.' ) );
|
classes/views/frm-forms/new-selection.php
DELETED
@@ -1,56 +0,0 @@
|
|
1 |
-
<div class="wrap">
|
2 |
-
<div class="frmicon icon32"><br/></div>
|
3 |
-
<h2><?php _e('Build New Form', 'formidable') ?></h2>
|
4 |
-
|
5 |
-
<div class="clear"></div>
|
6 |
-
<div id="menu-management" class="nav-menus-php frm-menu-boxes">
|
7 |
-
<div class="menu-edit">
|
8 |
-
<div id="nav-menu-header"><div class="major-publishing-actions" style="padding:8px 0;">
|
9 |
-
<div style="font-size:15px;background:transparent;" class="search"><?php _e('Pre-Built Form', 'formidable') ?></div>
|
10 |
-
</div></div>
|
11 |
-
|
12 |
-
<form method="get">
|
13 |
-
<div id="post-body">
|
14 |
-
<p><?php _e('Select a template to generate your form.', 'formidable'); ?></p>
|
15 |
-
<input type="hidden" name="frm_action" value="duplicate" />
|
16 |
-
<input type="hidden" name="page" value="formidable" />
|
17 |
-
<select name="id">
|
18 |
-
<?php foreach ($all_templates as $temp){ ?>
|
19 |
-
<option value="<?php echo $temp->id ?>"><?php echo FrmAppHelper::truncate($temp->name, 40) ?></option>
|
20 |
-
<?php } ?>
|
21 |
-
</select><br/>
|
22 |
-
</div>
|
23 |
-
<div id="nav-menu-footer">
|
24 |
-
<div class="major-publishing-actions"><input type="submit" class="button-primary" value="<?php _e('Create', 'formidable') ?>" /></div>
|
25 |
-
|
26 |
-
<div class="clear"></div>
|
27 |
-
</div>
|
28 |
-
</form>
|
29 |
-
</div>
|
30 |
-
</div>
|
31 |
-
|
32 |
-
<div id="menu-management" class="nav-menus-php frm-menu-boxes">
|
33 |
-
<div class="menu-edit">
|
34 |
-
<div id="nav-menu-header"><div class="major-publishing-actions" style="padding:8px 0;">
|
35 |
-
<div style="font-size:15px;background:transparent;" class="search"><?php _e('Blank Form', 'formidable') ?></div>
|
36 |
-
</div></div>
|
37 |
-
|
38 |
-
<form method="get">
|
39 |
-
<div id="post-body">
|
40 |
-
<p style="padding-bottom:26px;"><?php _e('Start with a blank form and build anything.', 'formidable'); ?></p>
|
41 |
-
<input type="hidden" name="frm_action" value="new" />
|
42 |
-
<input type="hidden" name="page" value="formidable" />
|
43 |
-
</div>
|
44 |
-
<div id="nav-menu-footer">
|
45 |
-
<div class="major-publishing-actions"><input type="submit" class="button-primary" value="<?php _e('Create', 'formidable') ?>" /></div>
|
46 |
-
|
47 |
-
<div class="clear"></div>
|
48 |
-
</div>
|
49 |
-
</form>
|
50 |
-
</div>
|
51 |
-
|
52 |
-
<div class="clear"></div>
|
53 |
-
</div>
|
54 |
-
|
55 |
-
<div class="clear"></div>
|
56 |
-
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/views/frm-forms/new.php
CHANGED
@@ -1,53 +1,38 @@
|
|
1 |
<div class="wrap">
|
2 |
-
<div class="frmicon icon32"><br/></div>
|
3 |
-
<h2><?php _e('Build New Form', 'formidable') ?>
|
4 |
-
<a href="?page=formidable-new" class="add-new-h2
|
5 |
</h2>
|
6 |
-
<?php
|
7 |
-
if ( !$form->is_template ) {
|
8 |
-
FrmAppController::get_form_nav($id, true);
|
9 |
-
}
|
10 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
|
11 |
-
|
12 |
-
if(version_compare( $GLOBALS['wp_version'], '3.3.3', '<')){ ?>
|
13 |
-
<div id="poststuff" class="metabox-holder has-right-sidebar">
|
14 |
-
<?php
|
15 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
|
16 |
-
}else{ ?>
|
17 |
-
<div id="poststuff">
|
18 |
-
<?php } ?>
|
19 |
|
|
|
20 |
<div id="post-body" class="metabox-holder columns-2">
|
21 |
<div id="post-body-content">
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
31 |
<form method="post" id="frm_build_form">
|
32 |
<input type="hidden" name="frm_action" value="create" />
|
33 |
<input type="hidden" name="action" value="create" />
|
34 |
-
<input type="hidden" name="id" value="<?php echo $id; ?>" />
|
35 |
|
36 |
<?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
|
37 |
|
38 |
<p>
|
39 |
-
|
40 |
-
<?php _e('or', 'formidable') ?>
|
41 |
-
<a class="button-secondary cancel" href="?page=formidable&frm_action=destroy&id=<?php echo $id; ?>"><?php _e('Cancel', 'formidable') ?></a>
|
42 |
<span class="frm-loading-img"></span>
|
43 |
</p>
|
44 |
</form>
|
|
|
|
|
45 |
</div>
|
46 |
-
|
47 |
-
<?php
|
48 |
-
if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
|
49 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
|
50 |
-
?>
|
51 |
</div>
|
52 |
</div>
|
53 |
-
</div>
|
1 |
<div class="wrap">
|
2 |
+
<div class="frmicon icon32"><br/></div>
|
3 |
+
<h2><?php _e( 'Build New Form', 'formidable' ) ?>
|
4 |
+
<a href="?page=formidable-new" class="add-new-h2 frm_invisible"><?php _e( 'Add New', 'formidable' ); ?></a>
|
5 |
</h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
<div id="poststuff">
|
8 |
<div id="post-body" class="metabox-holder columns-2">
|
9 |
<div id="post-body-content">
|
10 |
+
<?php
|
11 |
+
if ( ! $values['is_template'] ) {
|
12 |
+
FrmAppController::get_form_nav($id, true, 'hide');
|
13 |
+
}
|
14 |
+
require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
|
15 |
+
|
16 |
+
?>
|
17 |
+
|
18 |
+
<div class="frm_form_builder<?php echo FrmFormsHelper::get_form_style_class($form); ?>">
|
19 |
+
|
20 |
<form method="post" id="frm_build_form">
|
21 |
<input type="hidden" name="frm_action" value="create" />
|
22 |
<input type="hidden" name="action" value="create" />
|
23 |
+
<input type="hidden" name="id" id="form_id" value="<?php echo (int) $id; ?>" />
|
24 |
|
25 |
<?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
|
26 |
|
27 |
<p>
|
28 |
+
<input type="button" value="<?php esc_attr_e( 'Create', 'formidable' ) ?>" class="frm_submit_<?php echo ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_'; ?>ajax button-primary" />
|
|
|
|
|
29 |
<span class="frm-loading-img"></span>
|
30 |
</p>
|
31 |
</form>
|
32 |
+
|
33 |
+
</div>
|
34 |
</div>
|
35 |
+
<?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php'); ?>
|
|
|
|
|
|
|
|
|
36 |
</div>
|
37 |
</div>
|
38 |
+
</div>
|
classes/views/frm-forms/notification.php
DELETED
@@ -1,94 +0,0 @@
|
|
1 |
-
<?php $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings'; ?>
|
2 |
-
<div id="frm_notification_<?php echo $email_key ?>" class="tabs-panel notification_settings <?php if(!$first_email) echo 'panel_secondary' ?>" style="display:<?php echo ($a == 'notification_settings') ? 'block' : 'none'; ?>;">
|
3 |
-
<table class="form-table <?php if(!$first_email) echo 'menu-settings'; ?>">
|
4 |
-
<tr>
|
5 |
-
<td><label><?php _e('From/Reply to', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Usually the name and email of the person filling out the form. Select from Text, Email, User ID, or hidden fields for the name. <br/>Defaults to your site name and admin email found on the WordPress General Settings page.', 'formidable') ?>"></span>
|
6 |
-
</td>
|
7 |
-
<td class="frm_email_reply_container">
|
8 |
-
<div class="alignright frm_email_actions feature-filter">
|
9 |
-
<?php echo $email_key; ?>
|
10 |
-
<?php if ( $email_key !== 0 ) { ?>
|
11 |
-
<span class="frm_email_icons">
|
12 |
-
<a data-removeid="frm_notification_<?php echo $email_key ?>" class="frm_icon_font frm_delete_icon frm_remove_email"> </a>
|
13 |
-
</span>
|
14 |
-
<?php } ?>
|
15 |
-
</div>
|
16 |
-
<span class="howto"><?php _e('Name') ?></span>
|
17 |
-
|
18 |
-
<select name="notification[<?php echo $email_key ?>][reply_to_name]" id="reply_to_name_<?php echo $email_key ?>" onchange="frmCheckCustomEmail(this.value,'reply_to_name',<?php echo $email_key ?>)">
|
19 |
-
<option value=""><?php echo FrmAppHelper::truncate(get_option('blogname'), 80); ?></option>
|
20 |
-
<option value="custom" <?php selected($notification['reply_to_name'], 'custom'); ?>><?php _e('Custom Name', 'formidable') ?></option>
|
21 |
-
<?php
|
22 |
-
if(!empty($values['fields'])){ ?>
|
23 |
-
<optgroup label="<?php _e('Fields', 'formidable') ?>">
|
24 |
-
<?php
|
25 |
-
$field_select = array('text', 'email', 'user_id', 'hidden', 'select', 'radio');
|
26 |
-
foreach($values['fields'] as $val_key => $fo){
|
27 |
-
if(in_array($fo['type'], $field_select)){ ?>
|
28 |
-
<option value="<?php echo $fo['id'] ?>" <?php selected($notification['reply_to_name'], $fo['id']); ?>><?php echo FrmAppHelper::truncate($fo['name'], 40) ?></option>
|
29 |
-
<?php }else if($fo['type'] == 'data' and isset($fo['data_type']) and $fo['data_type'] != 'data'){
|
30 |
-
if(isset($values['fields'][$val_key]['linked'])){
|
31 |
-
foreach($values['fields'][$val_key]['linked'] as $linked_field){
|
32 |
-
if(!in_array($linked_field->type, $field_select)) continue; ?>
|
33 |
-
<option value="<?php echo $fo['id'] ?>|<?php echo $linked_field->id ?>" <?php selected($notification['reply_to_name'], $fo['id'] .'|'. $linked_field->id); ?>><?php echo $fo['name'] .': '. FrmAppHelper::truncate($linked_field->name, 40) ?></option>
|
34 |
-
<?php }
|
35 |
-
}
|
36 |
-
}
|
37 |
-
}
|
38 |
-
} ?>
|
39 |
-
</select>
|
40 |
-
|
41 |
-
<span class="howto" ><?php _e('Email', 'formidable') ?></span>
|
42 |
-
<select name="notification[<?php echo $email_key ?>][reply_to]" id="reply_to_<?php echo $email_key ?>" onchange="frmCheckCustomEmail(this.value,'reply_to',<?php echo $email_key ?>)">
|
43 |
-
<option value=""><?php echo get_option('admin_email') ?></option>
|
44 |
-
<option value="custom" <?php selected($notification['reply_to'], 'custom'); ?>><?php _e('Custom Address', 'formidable') ?></option>
|
45 |
-
<?php
|
46 |
-
if(!empty($values['fields'])){ ?>
|
47 |
-
<optgroup label="<?php _e('Fields', 'formidable') ?>">
|
48 |
-
<?php
|
49 |
-
foreach($values['fields'] as $val_key => $fo){
|
50 |
-
if(in_array($fo['type'], $field_select)){ ?>
|
51 |
-
<option value="<?php echo $fo['id'] ?>" <?php selected($notification['reply_to'], $fo['id']); ?>><?php echo FrmAppHelper::truncate($fo['name'], 40) ?></option>
|
52 |
-
<?php }else if($fo['type'] == 'data' and isset($fo['data_type']) and $fo['data_type'] != 'data'){
|
53 |
-
if(isset($values['fields'][$val_key]['linked'])){ ?>
|
54 |
-
<?php foreach($values['fields'][$val_key]['linked'] as $linked_field){
|
55 |
-
if(!in_array($linked_field->type, $field_select)) continue; ?>
|
56 |
-
<option value="<?php echo $fo['id'] ?>|<?php echo $linked_field->id ?>" <?php selected($notification['reply_to'], $fo['id'] .'|'. $linked_field->id); ?>><?php echo $fo['name'] .': '. FrmAppHelper::truncate($linked_field->name, 40) ?></option>
|
57 |
-
<?php }
|
58 |
-
}
|
59 |
-
}
|
60 |
-
}
|
61 |
-
} ?>
|
62 |
-
</select>
|
63 |
-
|
64 |
-
<div id="frm_cust_reply_container_<?php echo $email_key ?>" <?php echo ($notification['reply_to_name'] == 'custom' or $notification['reply_to'] == 'custom') ? '' : 'style="display:none"'; ?>>
|
65 |
-
<span class="howto" style="visibility:hidden;"><?php _e('Name') ?></span>
|
66 |
-
<input type="text" name="notification[<?php echo $email_key ?>][cust_reply_to_name]" value="<?php echo esc_attr($notification['cust_reply_to_name']) ?>" id="cust_reply_to_name_<?php echo $email_key ?>" title="<?php _e('Name') ?>" <?php echo ($notification['reply_to_name'] == 'custom') ? '' : 'style="visibility:hidden;"'; ?> />
|
67 |
-
<span class="howto" style="visibility:hidden;"><?php _e('Email', 'formidable') ?></span>
|
68 |
-
<input type="text" name="notification[<?php echo $email_key ?>][cust_reply_to]" value="<?php echo esc_attr($notification['cust_reply_to']) ?>" id="cust_reply_to_<?php echo $email_key ?>" title="<?php _e('Email Address', 'formidable') ?>" <?php echo ($notification['reply_to'] == 'custom') ? '' : 'style="visibility:hidden;"'; ?> />
|
69 |
-
</div>
|
70 |
-
</td>
|
71 |
-
</tr>
|
72 |
-
|
73 |
-
<tr>
|
74 |
-
<td colspan="2"><label><?php _e('Email Recipients', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e('To send to multiple addresses, separate each address with a comma. You can use [admin_email] to dynamically use the address on your WordPress General Settings page. <br/>PRO only: Leave blank if you do not want email notifications for this form.', 'formidable') ?>"></span>
|
75 |
-
<input type="text" name="notification[<?php echo $email_key ?>][email_to]" value="<?php echo esc_attr($notification['email_to']); ?>" class="frm_not_email_to frm_long_input" id="email_to_<?php echo $email_key ?>" />
|
76 |
-
|
77 |
-
<p><label><?php _e('Subject', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php echo esc_attr(sprintf(__('If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable'), $form->name, get_option('blogname'))); ?>"></span><br/>
|
78 |
-
<input type="text" name="notification[<?php echo $email_key ?>][email_subject]" class="frm_not_email_subject frm_long_input" id="email_subject_<?php echo $email_key ?>" size="55" value="<?php echo esc_attr($notification['email_subject']); ?>" /></p>
|
79 |
-
|
80 |
-
<p><label><?php _e('Message', 'formidable') ?> </label><br/>
|
81 |
-
<textarea name="notification[<?php echo $email_key ?>][email_message]" class="frm_not_email_message frm_long_input" id="email_message_<?php echo $email_key ?>" cols="50" rows="5"><?php echo FrmAppHelper::esc_textarea($notification['email_message']) ?></textarea></p>
|
82 |
-
|
83 |
-
<h4><?php _e('Options', 'formidable') ?> </h4>
|
84 |
-
<label for="inc_user_info_<?php echo $email_key ?>"><input type="checkbox" name="notification[<?php echo $email_key ?>][inc_user_info]" class="frm_not_inc_user_info" id="inc_user_info_<?php echo $email_key ?>" value="1" <?php checked($notification['inc_user_info'], 1); ?> /> <?php _e('Append IP Address, Browser, and Referring URL to message', 'formidable') ?></label>
|
85 |
-
|
86 |
-
<p><label for="plain_text_<?php echo $email_key ?>"><input type="checkbox" name="notification[<?php echo $email_key ?>][plain_text]" id="plain_text_<?php echo $email_key ?>" value="1" <?php checked($notification['plain_text'], 1); ?> /> <?php _e('Send Emails in Plain Text', 'formidable') ?></label></p>
|
87 |
-
<?php
|
88 |
-
if(!$frm_vars['pro_is_installed'])
|
89 |
-
FrmAppController::update_message('send autoresponders or conditionally send email notifications');
|
90 |
-
|
91 |
-
do_action('frm_additional_form_notification_options', $values, compact('notification', 'email_key')); ?>
|
92 |
-
</td></tr>
|
93 |
-
</table>
|
94 |
-
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/views/frm-forms/settings.php
CHANGED
@@ -1,194 +1,254 @@
|
|
1 |
<div id="form_settings_page" class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
-
<h2><?php _e('Settings', 'formidable') ?>
|
4 |
-
<a href="#" class="add-new-h2
|
5 |
</h2>
|
6 |
-
|
|
|
|
|
7 |
require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
|
8 |
-
|
9 |
-
|
10 |
-
<div id="poststuff" class="metabox-holder has-right-sidebar">
|
11 |
-
<?php
|
12 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/sidebar-settings.php');
|
13 |
-
}else{ ?>
|
14 |
<div id="poststuff">
|
15 |
-
<?php } ?>
|
16 |
-
|
17 |
<div id="post-body" class="metabox-holder columns-2">
|
18 |
<div id="post-body-content">
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
<input type="submit" value="<?php _e('Update', 'formidable') ?>" class="button-primary" />
|
23 |
-
<?php _e('or', 'formidable') ?>
|
24 |
-
<a class="button-secondary cancel" href="<?php echo esc_url(admin_url('admin.php?page=formidable') . '&frm_action=edit&id='. $id) ?>"><?php _e('Cancel', 'formidable') ?></a>
|
25 |
-
<?php do_action('frm_settings_buttons', $values); ?>
|
26 |
-
</p>
|
27 |
-
|
28 |
-
<div class="clear"></div>
|
29 |
|
30 |
-
|
|
|
31 |
<input type="hidden" name="frm_action" value="update_settings" />
|
32 |
-
|
33 |
-
<div id="post-body">
|
34 |
<div class="meta-box-sortables">
|
35 |
<div class="categorydiv postbox">
|
36 |
-
<h3 class="hndle"><span><?php echo
|
37 |
<div class="inside frm-help-tabs">
|
38 |
<div id="contextual-help-back"></div>
|
39 |
<div id="contextual-help-columns">
|
40 |
<div class="contextual-help-tabs">
|
41 |
<ul class="frm-category-tabs frm-form-setting-tabs">
|
42 |
<?php $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings'; ?>
|
43 |
-
<li <?php echo ($a == 'advanced_settings') ? 'class="tabs active"' : '' ?>><a href="#advanced_settings"><?php _e('General', 'formidable') ?></a></li>
|
44 |
-
<li <?php echo ($a == '
|
45 |
-
<li <?php echo ($a == 'html_settings') ? 'class="tabs active"' : '' ?>><a href="#html_settings"><?php _e('Customize HTML', 'formidable') ?></a></li>
|
46 |
-
|
47 |
-
|
48 |
-
<li <?php echo ($a == $sec_name .'_settings') ? 'class="tabs active"' : '' ?>><a href="#<?php echo $sec_name ?>_settings"><?php echo ucfirst($sec_name) ?></a></li>
|
49 |
<?php } ?>
|
50 |
</ul>
|
51 |
</div>
|
52 |
-
<div
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
<
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
85 |
<?php FrmAppHelper::wp_pages_dropdown( 'options[success_page_id]', $values['success_page_id'] ) ?>
|
86 |
-
</
|
87 |
<?php } ?>
|
88 |
</td>
|
89 |
</tr>
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
100 |
<select name="options[akismet]">
|
101 |
-
<option value=""><?php _e('no one', 'formidable') ?></option>
|
102 |
-
<option value="1" <?php selected($values['akismet'], 1)?>><?php _e('everyone', 'formidable') ?></option>
|
103 |
-
<option value="logged" <?php selected($values['akismet'], 'logged')?>><?php _e('visitors who are not logged in', 'formidable') ?></option>
|
104 |
</select>
|
105 |
</td>
|
106 |
</tr>
|
107 |
<?php } ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
</table>
|
109 |
</div>
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
</div>
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
129 |
<textarea name="options[before_html]" rows="4" id="before_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['before_html']) ?></textarea></p>
|
130 |
|
131 |
<div id="add_html_fields">
|
132 |
-
<?php
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
<p><label
|
137 |
-
<textarea name="field_options[custom_html_<?php echo $field['id'] ?>]" rows="7" id="custom_html_<?php echo $field['id'] ?>" class="field_custom_html frm_long_input"><?php echo FrmAppHelper::esc_textarea($field['custom_html']) ?></textarea></p>
|
138 |
<?php }
|
139 |
unset($field);
|
140 |
}
|
141 |
} ?>
|
142 |
</div>
|
143 |
|
144 |
-
<p><label
|
145 |
-
<textarea name="options[after_html]" rows="3" id="after_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['after_html']) ?></textarea></p>
|
146 |
-
|
147 |
-
<p><label
|
148 |
<textarea name="options[submit_html]" rows="3" id="submit_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['submit_html']) ?></textarea></p>
|
149 |
</div>
|
150 |
</div>
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
<?php foreach($sections as $sec_name => $section){ ?>
|
160 |
-
<div id="<?php echo $sec_name ?>_settings" class="tabs-panel" style="display:<?php echo ($a == $sec_name .'_settings') ? 'block' : 'none'; ?>;"><?php
|
161 |
-
if(isset($section['class'])){
|
162 |
-
call_user_func(array($section['class'], $section['function']), $values);
|
163 |
-
}else{
|
164 |
-
call_user_func((isset($section['function']) ? $section['function'] : $section), $values);
|
165 |
} ?>
|
166 |
</div>
|
167 |
<?php } ?>
|
168 |
-
|
169 |
<?php do_action('frm_add_form_option_section', $values); ?>
|
170 |
<div class="clear"></div>
|
171 |
</div>
|
172 |
</div>
|
173 |
-
</div>
|
174 |
-
</div>
|
175 |
</div>
|
176 |
|
177 |
</div>
|
178 |
|
179 |
-
<p>
|
180 |
-
<input type="submit" value="<?php
|
181 |
-
<?php _e('or', 'formidable') ?>
|
182 |
-
<a class="button-secondary cancel" href="<?php echo admin_url('admin.php?page=formidable') ?>&frm_action=edit&id=<?php echo $id ?>"><?php _e('Cancel', 'formidable') ?></a>
|
183 |
</p>
|
184 |
</form>
|
185 |
|
186 |
|
187 |
</div>
|
188 |
-
<?php
|
189 |
-
if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
|
190 |
-
require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/sidebar-settings.php');
|
191 |
-
?>
|
192 |
</div>
|
193 |
</div>
|
194 |
</div>
|
1 |
<div id="form_settings_page" class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
+
<h2><?php _e( 'Settings', 'formidable' ) ?>
|
4 |
+
<a href="#" class="add-new-h2 frm_invisible"></a>
|
5 |
</h2>
|
6 |
+
|
7 |
+
<?php
|
8 |
+
// Add form messages
|
9 |
require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
|
10 |
+
?>
|
11 |
+
|
|
|
|
|
|
|
|
|
12 |
<div id="poststuff">
|
|
|
|
|
13 |
<div id="post-body" class="metabox-holder columns-2">
|
14 |
<div id="post-body-content">
|
15 |
+
<?php
|
16 |
+
FrmAppController::get_form_nav($id, true);
|
17 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
<form method="post" class="frm_form_settings">
|
20 |
+
<input type="hidden" name="id" id="form_id" value="<?php echo (int) $id; ?>" />
|
21 |
<input type="hidden" name="frm_action" value="update_settings" />
|
22 |
+
|
|
|
23 |
<div class="meta-box-sortables">
|
24 |
<div class="categorydiv postbox">
|
25 |
+
<h3 class="hndle"><span><?php echo __( 'Form Settings', 'formidable' ) ?></span></h3>
|
26 |
<div class="inside frm-help-tabs">
|
27 |
<div id="contextual-help-back"></div>
|
28 |
<div id="contextual-help-columns">
|
29 |
<div class="contextual-help-tabs">
|
30 |
<ul class="frm-category-tabs frm-form-setting-tabs">
|
31 |
<?php $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings'; ?>
|
32 |
+
<li <?php echo ($a == 'advanced_settings') ? 'class="tabs active"' : '' ?>><a href="#advanced_settings"><?php _e( 'General', 'formidable' ) ?></a></li>
|
33 |
+
<li <?php echo ($a == 'email_settings') ? 'class="tabs active"' : '' ?>><a href="#email_settings"><?php _e( 'Form Actions', 'formidable' ); ?></a></li>
|
34 |
+
<li <?php echo ($a == 'html_settings') ? 'class="tabs active"' : '' ?>><a href="#html_settings"><?php _e( 'Customize HTML', 'formidable' ) ?></a></li>
|
35 |
+
<?php foreach ( $sections as $sec_name => $section ) { ?>
|
36 |
+
<li <?php echo ($a == $sec_name .'_settings') ? 'class="tabs active"' : '' ?>><a href="#<?php echo esc_attr( $sec_name ) ?>_settings"><?php echo ucfirst($sec_name) ?></a></li>
|
|
|
37 |
<?php } ?>
|
38 |
</ul>
|
39 |
</div>
|
40 |
+
<div class="advanced_settings tabs-panel <?php echo ($a == 'advanced_settings') ? 'frm_block' : 'frm_hidden' ?>">
|
41 |
+
<h3 class="frm_first_h3"><?php _e( 'On Submit', 'formidable' ); ?>
|
42 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Choose what will happen after the user submits this form.', 'formidable' );
|
43 |
+
if ( ! FrmAppHelper::pro_is_installed() ) {
|
44 |
+
esc_attr_e( ' Upgrade to Formidable Forms to get access to all options in the dropdown.', 'formidable' );
|
45 |
+
} ?>" ></span>
|
46 |
+
</h3>
|
47 |
|
48 |
+
<!--On Submit Section-->
|
49 |
+
<table class="form-table">
|
50 |
+
<tr>
|
51 |
+
<td class="frm_175_width">
|
52 |
+
<select name="options[success_action]" id="success_action">
|
53 |
+
<option value="message" <?php selected($values['success_action'], 'message') ?>><?php _e( 'Show Message', 'formidable' )?></option>
|
54 |
+
<?php if ( FrmAppHelper::pro_is_installed() ) { ?>
|
55 |
+
<option value="redirect" <?php selected($values['success_action'], 'redirect');
|
56 |
+
?>><?php _e( 'Redirect to URL', 'formidable' ) ?></option>
|
57 |
+
<option value="page" <?php selected($values['success_action'], 'page');
|
58 |
+
?>><?php _e( 'Show Page Content', 'formidable' )?></option>
|
59 |
+
<?php } else { ?>
|
60 |
+
<option value="redirect" disabled="disabled" <?php selected($values['success_action'], 'redirect');
|
61 |
+
?>><?php _e( 'Redirect to URL', 'formidable' ); echo ' '. __( '(Pro feature)', 'formidable' ); ?></option>
|
62 |
+
<option value="page" disabled="disabled" <?php selected($values['success_action'], 'page');
|
63 |
+
?>><?php _e( 'Show Page Content', 'formidable' ); echo ' '. __( '(Pro feature)', 'formidable' ); ?></option>
|
64 |
+
<?php } ?>
|
65 |
+
</select>
|
66 |
+
</td>
|
67 |
+
<td>
|
68 |
+
<span class="success_action_redirect_box success_action_box<?php echo ($values['success_action'] == 'redirect') ? '' : ' frm_hidden'; ?>">
|
69 |
+
<input type="text" name="options[success_url]" id="success_url" value="<?php
|
70 |
+
if ( isset( $values['success_url'] ) ) {
|
71 |
+
echo esc_attr( $values['success_url'] );
|
72 |
+
} ?>" placeholder="http://example.com" />
|
73 |
+
</span>
|
74 |
+
|
75 |
+
<?php if ( FrmAppHelper::pro_is_installed() ){ ?>
|
76 |
+
<span class="success_action_page_box success_action_box<?php echo ($values['success_action'] == 'page') ? '' : ' frm_hidden'; ?>">
|
77 |
+
<label><?php _e( 'Use Content from Page', 'formidable' ) ?></label>
|
78 |
<?php FrmAppHelper::wp_pages_dropdown( 'options[success_page_id]', $values['success_page_id'] ) ?>
|
79 |
+
</span>
|
80 |
<?php } ?>
|
81 |
</td>
|
82 |
</tr>
|
83 |
+
<tr class="frm_show_form_opt success_action_message_box success_action_box<?php echo ($values['success_action'] == 'message') ? '' : ' frm_hidden'; ?>">
|
84 |
+
<td colspan="2">
|
85 |
+
<label for="show_form"><input type="checkbox" name="options[show_form]" id="show_form" value="1" <?php checked($values['show_form'], 1) ?> /> <?php _e( 'Show the form with the confirmation message', 'formidable' )?></label>
|
86 |
+
</td>
|
87 |
+
</tr>
|
88 |
+
<tr>
|
89 |
+
<td colspan="2"><label for="no_save"><input type="checkbox" name="options[no_save]" id="no_save" value="1" <?php checked($values['no_save'], 1); ?> /> <?php _e( 'Do not store entries submitted from this form', 'formidable' ) ?></label>
|
90 |
+
</td>
|
91 |
+
</tr>
|
92 |
+
<?php if ( function_exists( 'akismet_http_post') ) { ?>
|
93 |
+
<tr>
|
94 |
+
<td colspan="2"><?php _e( 'Use Akismet to check entries for spam for', 'formidable' ) ?>
|
95 |
<select name="options[akismet]">
|
96 |
+
<option value=""><?php _e( 'no one', 'formidable' ) ?></option>
|
97 |
+
<option value="1" <?php selected($values['akismet'], 1)?>><?php _e( 'everyone', 'formidable' ) ?></option>
|
98 |
+
<option value="logged" <?php selected($values['akismet'], 'logged')?>><?php _e( 'visitors who are not logged in', 'formidable' ) ?></option>
|
99 |
</select>
|
100 |
</td>
|
101 |
</tr>
|
102 |
<?php } ?>
|
103 |
+
<?php do_action('frm_additional_form_options', $values); ?>
|
104 |
+
</table>
|
105 |
+
|
106 |
+
<!--AJAX Section-->
|
107 |
+
<h3><?php _e( 'AJAX', 'formidable' ) ?>
|
108 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Make stuff happen in the background without a page refresh', 'formidable' ) ?>" ></span>
|
109 |
+
</h3>
|
110 |
+
<table class="form-table">
|
111 |
+
<tr>
|
112 |
+
<td>
|
113 |
+
<label for="ajax_load">
|
114 |
+
<input type="checkbox" name="options[ajax_load]" id="ajax_load" value="1"<?php echo ( $values['ajax_load'] ) ? ' checked="checked"' : ''; ?> /> <?php _e( 'Load and save form builder page with AJAX', 'formidable' ) ?>
|
115 |
+
</label>
|
116 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Recommended for long forms.', 'formidable' ) ?>" ></span>
|
117 |
+
</td>
|
118 |
+
</tr>
|
119 |
+
<?php do_action('frm_add_form_ajax_options', $values); ?>
|
120 |
+
</table>
|
121 |
+
|
122 |
+
<!--Permissions Section-->
|
123 |
+
<table class="form-table">
|
124 |
+
<?php do_action('frm_add_form_perm_options', $values); ?>
|
125 |
+
</table>
|
126 |
+
|
127 |
+
<!--Styling & Buttons Section-->
|
128 |
+
<h3><?php _e( 'Styling & Buttons', 'formidable' ) ?>
|
129 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Select a style for this form and set the text for your buttons.', 'formidable' ) ?>" ></span>
|
130 |
+
</h3>
|
131 |
+
<table class="form-table">
|
132 |
+
<tr>
|
133 |
+
<td class="frm_left_label"><label for="custom_style"><?php _e( 'Style Template', 'formidable' ) ?></label></td>
|
134 |
+
<td><select name="options[custom_style]" id="custom_style">
|
135 |
+
<option value="1" <?php selected($values['custom_style'], 1) ?>><?php _e( 'Always use default', 'formidable' )?></option>
|
136 |
+
<?php foreach ( $styles as $s ) { ?>
|
137 |
+
<option value="<?php echo esc_attr( $s->ID ) ?>" <?php selected( $s->ID, $values['custom_style'] ) ?>><?php echo esc_html( $s->post_title . ( empty( $s->menu_order ) ? '' : ' ('. __( 'default', 'formidable' ) .')' ) ) ?></option>
|
138 |
+
<?php } ?>
|
139 |
+
<option value="0" <?php selected($values['custom_style'], 0); selected($values['custom_style'], '') ?>><?php _e( 'Do not use Formidable styling', 'formidable' )?></option>
|
140 |
+
</select></td>
|
141 |
+
</tr>
|
142 |
+
<tr>
|
143 |
+
<td><label><?php _e( 'Submit Button Text', 'formidable' ) ?></label></td>
|
144 |
+
<td><input type="text" name="options[submit_value]" value="<?php echo esc_attr($values['submit_value']); ?>" /></td>
|
145 |
+
</tr>
|
146 |
+
<?php do_action( 'frm_add_form_button_options', $values ); ?>
|
147 |
+
</table>
|
148 |
+
|
149 |
+
<!--Message Section-->
|
150 |
+
<h3 id="frm_messages_header" class="<?php echo ( ( isset( $values['edit_action'] ) && $values['edit_action'] == 'message' && isset( $values['editable'] ) && $values['editable'] == 1 ) || $values['success_action'] == 'message' || $values['save_draft'] == 1 ) ? '' : 'frm_hidden'; ?>"><?php _e( 'Messages', 'formidable' ); ?>
|
151 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Set up your confirmation messages.', 'formidable' ) ?>" ></span>
|
152 |
+
</h3>
|
153 |
+
<table class="form-table">
|
154 |
+
<tr class="success_action_message_box success_action_box<?php echo ($values['success_action'] == 'message') ? '' : ' frm_hidden'; ?>">
|
155 |
+
<td>
|
156 |
+
<div><?php _e( 'On Submit', 'formidable' ) ?></div>
|
157 |
+
<textarea id="success_msg" name="options[success_msg]" cols="50" rows="2" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['success_msg']); ?></textarea>
|
158 |
+
</td>
|
159 |
+
</tr>
|
160 |
+
<?php do_action('frm_add_form_msg_options', $values); ?>
|
161 |
</table>
|
162 |
</div>
|
163 |
|
164 |
+
|
165 |
+
<div id="frm_notification_settings" class="frm_email_settings email_settings tabs-panel widgets-holder-wrap <?php echo ($a == 'email_settings') ? ' frm_block' : ' frm_hidden'; ?>">
|
166 |
+
<div id="frm_email_addon_menu" class="manage-menus">
|
167 |
+
<h3><?php _e( 'Add New Action', 'formidable' ) ?></h3>
|
168 |
+
<ul class="frm_actions_list">
|
169 |
+
<?php
|
170 |
+
|
171 |
+
//For each add-on, add an li, class, and javascript function. If active, add an additional class.
|
172 |
+
foreach ( $action_controls as $action_control ) {
|
173 |
+
?>
|
174 |
+
<li><a href="javascript:void(0)" class="frm_<?php echo esc_attr( $action_control->id_base ) ?>_action frm_bstooltip <?php
|
175 |
+
echo ( isset($action_control->action_options['active']) && $action_control->action_options['active']) ? 'frm_active_action ' : 'frm_inactive_action ';
|
176 |
+
echo esc_attr( $action_control->action_options['classes'] );
|
177 |
+
?>" title="<?php echo esc_attr($action_control->action_options['tooltip']) ?>" data-limit="<?php echo isset($action_control->action_options['limit']) ? esc_attr( $action_control->action_options['limit'] ) : '99' ?>" data-actiontype="<?php echo esc_attr($action_control->id_base) ?>"></a></li>
|
178 |
+
<?php
|
179 |
+
unset($actions_icon);
|
180 |
+
}
|
181 |
+
?>
|
182 |
+
</ul>
|
183 |
+
</div>
|
184 |
+
<div class="frm_no_actions">
|
185 |
+
<div class="inner_actions">
|
186 |
+
<img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow1.png'; ?>" alt=""/>
|
187 |
+
<div class="clear"></div>
|
188 |
+
<?php _e( 'Click an action to add it to this form', 'formidable' ) ?>
|
189 |
+
</div>
|
190 |
+
</div>
|
191 |
+
<?php FrmFormActionsController::list_actions($form, $values); ?>
|
192 |
</div>
|
193 |
+
|
194 |
+
<div id="html_settings" class="tabs-panel <?php echo ($a == 'html_settings') ? ' frm_block' : ' frm_hidden'; ?>">
|
195 |
+
|
196 |
+
<div class="frm_field_html_box frm_top_container">
|
197 |
+
<p><label><?php _e( 'Form Classes', 'formidable' ) ?></label>
|
198 |
+
<input type="text" name="options[form_class]" value="<?php echo esc_attr($values['form_class']) ?>" />
|
199 |
+
</p>
|
200 |
+
<div class="clear"></div>
|
201 |
+
|
202 |
+
<p><label><?php _e( 'Before Fields', 'formidable' ) ?></label>
|
203 |
<textarea name="options[before_html]" rows="4" id="before_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['before_html']) ?></textarea></p>
|
204 |
|
205 |
<div id="add_html_fields">
|
206 |
+
<?php
|
207 |
+
if ( isset( $values['fields'] ) ) {
|
208 |
+
foreach ( $values['fields'] as $field ) {
|
209 |
+
if ( apply_filters( 'frm_show_custom_html', true, $field['type'] ) ) { ?>
|
210 |
+
<p><label><?php echo esc_html( $field['name'] ) ?></label>
|
211 |
+
<textarea name="field_options[custom_html_<?php echo esc_attr( $field['id'] ) ?>]" rows="7" id="custom_html_<?php echo esc_attr( $field['id'] ) ?>" class="field_custom_html frm_long_input"><?php echo FrmAppHelper::esc_textarea($field['custom_html']) ?></textarea></p>
|
212 |
<?php }
|
213 |
unset($field);
|
214 |
}
|
215 |
} ?>
|
216 |
</div>
|
217 |
|
218 |
+
<p><label><?php _e( 'After Fields', 'formidable' ) ?></label>
|
219 |
+
<textarea name="options[after_html]" rows="3" id="after_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['after_html']) ?></textarea></p>
|
220 |
+
|
221 |
+
<p><label><?php _e( 'Submit Button', 'formidable' ) ?></label>
|
222 |
<textarea name="options[submit_html]" rows="3" id="submit_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['submit_html']) ?></textarea></p>
|
223 |
</div>
|
224 |
</div>
|
225 |
+
|
226 |
+
<?php foreach ( $sections as $sec_name => $section ) { ?>
|
227 |
+
<div id="<?php echo esc_attr( $sec_name ) ?>_settings" class="tabs-panel <?php echo ($a == $sec_name .'_settings') ? ' frm_block' : ' frm_hidden'; ?>"><?php
|
228 |
+
if ( isset( $section['class'] ) ) {
|
229 |
+
call_user_func( array($section['class'], $section['function']), $values);
|
230 |
+
} else {
|
231 |
+
call_user_func((isset($section['function']) ? $section['function'] : $section), $values);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
} ?>
|
233 |
</div>
|
234 |
<?php } ?>
|
235 |
+
|
236 |
<?php do_action('frm_add_form_option_section', $values); ?>
|
237 |
<div class="clear"></div>
|
238 |
</div>
|
239 |
</div>
|
|
|
|
|
240 |
</div>
|
241 |
|
242 |
</div>
|
243 |
|
244 |
+
<p>
|
245 |
+
<input type="submit" value="<?php esc_attr_e( 'Update', 'formidable' ) ?>" class="button-primary" />
|
|
|
|
|
246 |
</p>
|
247 |
</form>
|
248 |
|
249 |
|
250 |
</div>
|
251 |
+
<?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/sidebar-settings.php'); ?>
|
|
|
|
|
|
|
252 |
</div>
|
253 |
</div>
|
254 |
</div>
|
classes/views/frm-forms/shortcode_opts.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! empty($form_id) ) {
|
3 |
+
?>
|
4 |
+
<h4 class="frm_left_label"><?php _e( 'Select a form:', 'formidable' ) ?></h4>
|
5 |
+
<?php FrmFormsHelper::forms_dropdown( 'frmsc_'. $shortcode .'_'. $form_id ); ?>
|
6 |
+
<div class="frm_box_line"></div>
|
7 |
+
<?php
|
8 |
+
}
|
9 |
+
|
10 |
+
if ( ! empty($opts) ) { ?>
|
11 |
+
<h4><?php _e( 'Options', 'formidable' ) ?></h4>
|
12 |
+
<ul>
|
13 |
+
<?php
|
14 |
+
foreach ( $opts as $opt => $val ) {
|
15 |
+
if ( isset( $val['type'] ) && 'text' == $val['type'] ) { ?>
|
16 |
+
<li><label class="setting" for="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>">
|
17 |
+
<span><?php echo esc_html( $val['label'] ) ?></span>
|
18 |
+
<input type="text" id="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>" value="<?php echo esc_attr( $val['val'] ) ?>" />
|
19 |
+
</label>
|
20 |
+
</li>
|
21 |
+
<?php
|
22 |
+
} else if ( isset( $val['type'] ) && 'select' == $val['type'] ) { ?>
|
23 |
+
<li><label class="setting" for="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>">
|
24 |
+
<span><?php echo esc_html( $val['label'] ) ?></span>
|
25 |
+
<select id="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>">
|
26 |
+
<?php foreach ( $val['opts'] as $select_opt => $select_label ) { ?>
|
27 |
+
<option value="<?php echo esc_attr( $select_opt ) ?>"><?php echo esc_html( $select_label ) ?></option>
|
28 |
+
<?php } ?>
|
29 |
+
</select>
|
30 |
+
</label>
|
31 |
+
</li>
|
32 |
+
<?php
|
33 |
+
} else { ?>
|
34 |
+
<li><label class="setting" for="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>"><input type="checkbox" id="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>" value="<?php echo esc_attr( $val['val'] ) ?>" /> <?php echo esc_html( $val['label'] ) ?></label></li>
|
35 |
+
<?php
|
36 |
+
}
|
37 |
+
}
|
38 |
+
?>
|
39 |
+
</ul>
|
40 |
+
<?php
|
41 |
+
}
|
classes/views/frm-forms/sidebar-settings.php
CHANGED
@@ -1,33 +1,11 @@
|
|
1 |
-
<div id="postbox-container-1" class="
|
2 |
-
<?php if(!isset($hide_preview) or !$hide_preview){
|
3 |
-
if (!$values['is_template']){ ?>
|
4 |
-
<p class="howto" style="margin-top:0;"><?php _e('Add to a post, page or text widget', 'formidable') ?>
|
5 |
-
<a href="http://formidablepro.com/knowledgebase/publish-your-forms/" target="_blank" class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Key and id are generally synonymous. For more information on using this shortcode, click now.', 'formidable') ?>" ></a>
|
6 |
-
<a href="javascript:void(0)" data-toggle=".frm_ext_sc"><?php _e('Show more', 'formidable') ?></a>
|
7 |
-
<input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo $id; ?>]" />
|
8 |
-
<span class="frm_ext_sc">
|
9 |
-
<input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo $id; ?> title=true description=true]" />
|
10 |
-
<input type="text" readonly="true" class="frm_select_box" value="[formidable key=<?php echo $values['form_key']; ?>]" /><br/>
|
11 |
-
|
12 |
-
<?php _e('Insert in a template', 'formidable') ?>
|
13 |
-
<input type="text" readonly="true" class="frm_select_box" value="<?php echo FrmFormsController::get_form_shortcode(array('id' => <?php echo $id; ?>, 'title' => false, 'description' => false)); ?>" /><br/>
|
14 |
-
|
15 |
-
<?php _e('Direct Link', 'formidable') ?>
|
16 |
-
<input type="text" readonly="true" class="frm_select_box" value="<?php echo esc_attr(FrmFormsHelper::get_direct_link($values['form_key'])) ?>" />
|
17 |
-
</span>
|
18 |
-
</p>
|
19 |
-
</tr>
|
20 |
-
<?php } ?>
|
21 |
-
|
22 |
-
<p class="frm_orange"><a href="<?php echo FrmFormsHelper::get_direct_link($values['form_key']); ?>" target="_blank"><?php _e('Preview Form', 'formidable') ?></a>
|
23 |
-
<?php global $frm_settings;
|
24 |
-
if ($frm_settings->preview_page_id > 0){ ?>
|
25 |
-
<?php _e('or', 'formidable') ?>
|
26 |
-
<a href="<?php echo add_query_arg('form', $values['form_key'], get_permalink($frm_settings->preview_page_id)) ?>" target="_blank"><?php _e('Preview in Current Theme', 'formidable') ?></a>
|
27 |
-
<?php } ?>
|
28 |
-
</p>
|
29 |
<?php
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
33 |
</div>
|
1 |
+
<div id="postbox-container-1" class="postbox-container">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
<?php
|
3 |
+
|
4 |
+
if ( ! isset($hide_preview) || ! $hide_preview ) {
|
5 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/_publish_box.php');
|
6 |
+
}
|
7 |
+
|
8 |
+
include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/mb_insert_fields.php');
|
9 |
+
|
10 |
+
?>
|
11 |
</div>
|
classes/views/frm-settings/form.php
CHANGED
@@ -1,164 +1,173 @@
|
|
1 |
<div id="form_global_settings" class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
-
<h2><?php _e('Global Settings', 'formidable'); ?></h2>
|
4 |
|
5 |
<?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
|
6 |
-
|
7 |
<div id="poststuff" class="metabox-holder">
|
8 |
<div id="post-body">
|
9 |
<div class="meta-box-sortables">
|
10 |
<div class="categorydiv postbox">
|
11 |
-
<h3 class="hndle"><span><?php _e('Global Settings', 'formidable') ?></span></h3>
|
12 |
<div class="inside frm-help-tabs">
|
13 |
<div id="contextual-help-back"></div>
|
14 |
<div id="contextual-help-columns">
|
15 |
<div class="contextual-help-tabs">
|
16 |
<ul class="frm-category-tabs">
|
17 |
<?php $a = isset($_GET['t']) ? $_GET['t'] : 'general_settings'; ?>
|
18 |
-
<li <?php echo ($a == 'general_settings') ? 'class="tabs active"' : '' ?>><a href="#general_settings"
|
19 |
-
|
20 |
-
<li <?php echo ($a == $sec_name .'_settings') ? 'class="tabs active"' : '' ?>><a href="#<?php echo $sec_name ?>_settings"><?php echo isset($section['name']) ? $section['name'] : ucfirst($sec_name) ?></a></li>
|
21 |
<?php } ?>
|
22 |
</ul>
|
23 |
</div>
|
24 |
|
25 |
<?php do_action('frm_before_settings'); ?>
|
26 |
-
|
27 |
<form name="frm_settings_form" method="post" class="frm_settings_form" action="?page=formidable-settings<?php echo (isset($_GET['t'])) ? '&t='. $_GET['t'] : ''; ?>">
|
28 |
<input type="hidden" name="frm_action" value="process-form" />
|
29 |
<input type="hidden" name="action" value="process-form" />
|
30 |
<?php wp_nonce_field('process_form_nonce', 'process_form'); ?>
|
31 |
-
|
32 |
-
<div class="general_settings tabs-panel
|
33 |
-
<p class="submit"
|
34 |
-
|
35 |
</p>
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
<
|
40 |
-
|
41 |
-
<p><?php _e('Load Formidable styling', 'formidable') ?>
|
42 |
<select id="frm_load_style" name="frm_load_style">
|
43 |
-
<option value="all" <?php selected($frm_settings->load_style, 'all') ?>><?php _e('on every page of your site', 'formidable') ?></option>
|
44 |
-
<option value="dynamic" <?php selected($frm_settings->load_style, 'dynamic') ?>><?php _e('only on applicable pages', 'formidable') ?></option>
|
45 |
-
<option value="none" <?php selected($frm_settings->load_style, 'none') ?>><?php _e('Don\'t use Formidable styling on any page', 'formidable') ?></option>
|
46 |
</select>
|
47 |
</p>
|
48 |
-
|
49 |
-
<p><label for="frm_use_html"><input type="checkbox" id="frm_use_html" name="frm_use_html" value="1" <?php checked($frm_settings->use_html, 1) ?> > <?php _e('Use HTML5 in forms', 'formidable') ?></label>
|
50 |
</p>
|
51 |
-
|
52 |
<?php do_action('frm_style_general_settings', $frm_settings); ?>
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
<
|
58 |
-
|
59 |
-
<
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
70 |
<input type="text" name="frm_pubkey" id="frm_pubkey" size="42" value="<?php echo esc_attr($frm_settings->pubkey) ?>" /></p>
|
71 |
-
|
72 |
-
|
73 |
-
<p><label class="frm_left_label"><?php _e('Private Key', 'formidable') ?></label>
|
74 |
<input type="text" name="frm_privkey" id="frm_privkey" size="42" value="<?php echo esc_attr($frm_settings->privkey) ?>" /></p>
|
75 |
|
76 |
-
<p><label class="frm_left_label"><?php _e('reCAPTCHA
|
77 |
-
<select name="frm_re_theme" id="frm_re_theme">
|
78 |
-
<?php foreach($recaptcha_themes as $theme_value => $theme_name){ ?>
|
79 |
-
<option value="<?php echo esc_attr($theme_value) ?>" <?php selected($frm_settings->re_theme, $theme_value) ?>><?php echo $theme_name ?></option>
|
80 |
-
<?php }
|
81 |
-
unset($recaptcha_themes, $theme_value, $theme_name);
|
82 |
-
?>
|
83 |
-
</select></p>
|
84 |
-
|
85 |
-
<p><label class="frm_left_label"><?php _e('reCAPTCHA Language', 'formidable') ?></label>
|
86 |
<select name="frm_re_lang" id="frm_re_lang">
|
87 |
-
<?php foreach
|
88 |
-
<option value="<?php echo esc_attr($lang) ?>" <?php selected($frm_settings->re_lang, $lang) ?>><?php echo $lang_name ?></option>
|
89 |
<?php } ?>
|
90 |
</select></p>
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
<?php
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
<?php do_action('frm_settings_form', $frm_settings); ?>
|
121 |
-
|
122 |
-
<?php if(
|
123 |
<div class="clear"></div>
|
124 |
-
<
|
125 |
-
<h3 class="frm_no_bg"><?php _e('Miscellaneous', 'formidable') ?></h3>
|
126 |
-
</div>
|
127 |
<?php } ?>
|
128 |
-
<p><label class="frm_left_label"><?php _e('Admin menu label', 'formidable'); ?></label>
|
129 |
<input type="text" name="frm_menu" id="frm_menu" value="<?php echo esc_attr($frm_settings->menu) ?>" />
|
130 |
-
<?php if (is_multisite()
|
131 |
-
<label for="frm_mu_menu"><input type="checkbox" name="frm_mu_menu" id="frm_mu_menu" value="1" <?php checked($frm_settings->mu_menu, 1) ?> /> <?php _e('Use this menu name site-wide', 'formidable'); ?></label>
|
132 |
<?php } ?>
|
133 |
</p>
|
134 |
-
|
135 |
-
<p><label class="frm_left_label"><?php _e('Preview Page', 'formidable'); ?></label>
|
136 |
<?php FrmAppHelper::wp_pages_dropdown('frm-preview-page-id', $frm_settings->preview_page_id ) ?>
|
137 |
</p>
|
138 |
-
|
139 |
-
<p><label class="frm_left_label"><?php _e('Tracking', 'formidable'); ?></label>
|
140 |
-
<label for="frm_track"><input type="checkbox" id="frm_track" name="frm_track" value="1" <?php checked($frm_settings->track, 1) ?>> <?php _e('Track referrer information and pages visited', 'formidable') ?></label>
|
141 |
-
</p>
|
142 |
</div>
|
143 |
-
|
144 |
-
<?php
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
152 |
} ?>
|
153 |
</div>
|
154 |
-
<?php
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
158 |
<span class="spinner frm_spinner"></span>
|
159 |
</p>
|
160 |
<p class="submit">
|
161 |
-
|
162 |
</p>
|
163 |
|
164 |
</form>
|
1 |
<div id="form_global_settings" class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
+
<h2><?php _e( 'Global Settings', 'formidable' ); ?></h2>
|
4 |
|
5 |
<?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
|
6 |
+
|
7 |
<div id="poststuff" class="metabox-holder">
|
8 |
<div id="post-body">
|
9 |
<div class="meta-box-sortables">
|
10 |
<div class="categorydiv postbox">
|
11 |
+
<h3 class="hndle"><span><?php _e( 'Global Settings', 'formidable' ) ?></span></h3>
|
12 |
<div class="inside frm-help-tabs">
|
13 |
<div id="contextual-help-back"></div>
|
14 |
<div id="contextual-help-columns">
|
15 |
<div class="contextual-help-tabs">
|
16 |
<ul class="frm-category-tabs">
|
17 |
<?php $a = isset($_GET['t']) ? $_GET['t'] : 'general_settings'; ?>
|
18 |
+
<li <?php echo ($a == 'general_settings') ? 'class="tabs active"' : '' ?>><a href="#general_settings" class="frm_cursor_pointer"><?php _e( 'General', 'formidable' ) ?></a></li>
|
19 |
+
<?php foreach ( $sections as $sec_name => $section ) { ?>
|
20 |
+
<li <?php echo ($a == $sec_name .'_settings') ? 'class="tabs active"' : '' ?>><a href="#<?php echo esc_attr( $sec_name ) ?>_settings"><?php echo isset($section['name']) ? $section['name'] : ucfirst($sec_name) ?></a></li>
|
21 |
<?php } ?>
|
22 |
</ul>
|
23 |
</div>
|
24 |
|
25 |
<?php do_action('frm_before_settings'); ?>
|
26 |
+
|
27 |
<form name="frm_settings_form" method="post" class="frm_settings_form" action="?page=formidable-settings<?php echo (isset($_GET['t'])) ? '&t='. $_GET['t'] : ''; ?>">
|
28 |
<input type="hidden" name="frm_action" value="process-form" />
|
29 |
<input type="hidden" name="action" value="process-form" />
|
30 |
<?php wp_nonce_field('process_form_nonce', 'process_form'); ?>
|
31 |
+
|
32 |
+
<div class="general_settings tabs-panel <?php echo ($a == 'general_settings') ? 'frm_block' : 'frm_hidden'; ?>">
|
33 |
+
<p class="submit">
|
34 |
+
<input class="button-primary" type="submit" value="<?php esc_attr_e( 'Update Options', 'formidable' ) ?>" />
|
35 |
</p>
|
36 |
+
|
37 |
+
<h3><?php _e( 'Styling & Scripts', 'formidable' ); ?></h3>
|
38 |
+
|
39 |
+
<p><label class="frm_left_label"><?php _e( 'Load Formidable styling', 'formidable' ) ?></label>
|
|
|
|
|
40 |
<select id="frm_load_style" name="frm_load_style">
|
41 |
+
<option value="all" <?php selected($frm_settings->load_style, 'all') ?>><?php _e( 'on every page of your site', 'formidable' ) ?></option>
|
42 |
+
<option value="dynamic" <?php selected($frm_settings->load_style, 'dynamic') ?>><?php _e( 'only on applicable pages', 'formidable' ) ?></option>
|
43 |
+
<option value="none" <?php selected($frm_settings->load_style, 'none') ?>><?php _e( 'Don\'t use Formidable styling on any page', 'formidable' ) ?></option>
|
44 |
</select>
|
45 |
</p>
|
46 |
+
|
47 |
+
<p><label for="frm_use_html"><input type="checkbox" id="frm_use_html" name="frm_use_html" value="1" <?php checked($frm_settings->use_html, 1) ?> > <?php _e( 'Use HTML5 in forms', 'formidable' ) ?></label>
|
48 |
</p>
|
49 |
+
|
50 |
<?php do_action('frm_style_general_settings', $frm_settings); ?>
|
51 |
+
|
52 |
+
<h3><?php _e( 'User Permissions', 'formidable' ); ?>
|
53 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Select users that are allowed access to Formidable. Without access to View Forms, users will be unable to see the Formidable menu.', 'formidable' ) ?>"></span>
|
54 |
+
</h3>
|
55 |
+
<table class="form-table">
|
56 |
+
<?php foreach ( $frm_roles as $frm_role => $frm_role_description ) { ?>
|
57 |
+
<tr>
|
58 |
+
<td class="frm_left_label"><label><?php echo esc_html( $frm_role_description ) ?></label></td>
|
59 |
+
<td><?php FrmAppHelper::wp_roles_dropdown( $frm_role, $frm_settings->$frm_role, 'multiple' ) ?></td>
|
60 |
+
</tr>
|
61 |
+
<?php } ?>
|
62 |
+
</table>
|
63 |
+
|
64 |
+
<h3><?php _e( 'reCAPTCHA', 'formidable' ); ?>
|
65 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'reCAPTCHA is a free, accessible CAPTCHA service that helps to digitize books while blocking spam on your blog. reCAPTCHA asks commenters to retype two words scanned from a book to prove that they are a human. This verifies that they are not a spambot.', 'formidable' ) ?>" ></span>
|
66 |
+
</h3>
|
67 |
+
|
68 |
+
<p class="howto">reCAPTCHA requires an API key, consisting of a "site" and a "private" key. You can sign up for a <a href="https://www.google.com/recaptcha/" target="_blank">free reCAPTCHA key</a>.</p>
|
69 |
+
|
70 |
+
<p><label class="frm_left_label"><?php _e( 'Site Key', 'formidable' ) ?></label>
|
71 |
<input type="text" name="frm_pubkey" id="frm_pubkey" size="42" value="<?php echo esc_attr($frm_settings->pubkey) ?>" /></p>
|
72 |
+
|
73 |
+
<p><label class="frm_left_label"><?php _e( 'Private Key', 'formidable' ) ?></label>
|
|
|
74 |
<input type="text" name="frm_privkey" id="frm_privkey" size="42" value="<?php echo esc_attr($frm_settings->privkey) ?>" /></p>
|
75 |
|
76 |
+
<p><label class="frm_left_label"><?php _e( 'reCAPTCHA Language', 'formidable' ) ?></label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
<select name="frm_re_lang" id="frm_re_lang">
|
78 |
+
<?php foreach ( $captcha_lang as $lang => $lang_name ) { ?>
|
79 |
+
<option value="<?php echo esc_attr($lang) ?>" <?php selected($frm_settings->re_lang, $lang) ?>><?php echo esc_html( $lang_name ) ?></option>
|
80 |
<?php } ?>
|
81 |
</select></p>
|
82 |
+
|
83 |
+
<h3><?php _e( 'Default Messages', 'formidable' ); ?>
|
84 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'You can override the success message and submit button settings on individual forms.', 'formidable' ) ?>"></span>
|
85 |
+
</h3>
|
86 |
+
|
87 |
+
<p>
|
88 |
+
<label class="frm_left_label"><?php _e( 'Failed/Duplicate Entry', 'formidable' ); ?>
|
89 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'The message seen when a form is submitted and passes validation, but something goes wrong.', 'formidable' ) ?>" ></span>
|
90 |
+
</label>
|
91 |
+
<input type="text" id="frm_failed_msg" name="frm_failed_msg" class="frm_with_left_label" value="<?php echo esc_attr( $frm_settings->failed_msg ) ?>" />
|
92 |
+
</p>
|
93 |
+
|
94 |
+
<p>
|
95 |
+
<label class="frm_left_label"><?php _e( 'Blank Field', 'formidable' ); ?>
|
96 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'The message seen when a required field is left blank.', 'formidable' ) ?>" ></span>
|
97 |
+
</label>
|
98 |
+
<input type="text" id="frm_blank_msg" name="frm_blank_msg" class="frm_with_left_label" value="<?php echo esc_attr( $frm_settings->blank_msg ) ?>" />
|
99 |
+
</p>
|
100 |
+
|
101 |
+
<p>
|
102 |
+
<label class="frm_left_label"><?php _e( 'Incorrect Field', 'formidable' ); ?>
|
103 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'The message seen when a field response is either incorrect or missing.', 'formidable' ) ?>" ></span>
|
104 |
+
</label>
|
105 |
+
<input type="text" id="frm_invalid_msg" name="frm_invalid_msg" class="frm_with_left_label" value="<?php echo esc_attr( $frm_settings->invalid_msg ) ?>" />
|
106 |
+
</p>
|
107 |
+
|
108 |
+
<?php if ( FrmAppHelper::pro_is_installed() ) { ?>
|
109 |
+
<p>
|
110 |
+
<label class="frm_left_label"><?php _e( 'Unique Value', 'formidable' ); ?>
|
111 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'The message seen when a user selects a value in a unique field that has already been used.', 'formidable' ) ?>" ></span>
|
112 |
+
</label>
|
113 |
+
<input type="text" id="frm_unique_msg" name="frm_unique_msg" class="frm_with_left_label" value="<?php echo esc_attr( $frm_settings->unique_msg ) ?>" />
|
114 |
+
</p>
|
115 |
+
<?php } else { ?>
|
116 |
+
<input type="hidden" id="frm_unique_msg" name="frm_unique_msg" value="<?php echo esc_attr( $frm_settings->unique_msg ) ?>" />
|
117 |
+
<input type="hidden" id="frm_login_msg" name="frm_login_msg" class="frm_with_left_label" value="<?php echo esc_attr( $frm_settings->login_msg ) ?>" />
|
118 |
+
<?php } ?>
|
119 |
+
|
120 |
+
<p>
|
121 |
+
<label class="frm_left_label"><?php _e( 'Success Message', 'formidable' ); ?>
|
122 |
+
<span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'The default message seen after a form is submitted.', 'formidable' ) ?>" ></span>
|
123 |
+
</label>
|
124 |
+
<input type="text" id="frm_success_msg" name="frm_success_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->success_msg) ?>" />
|
125 |
+
</p>
|
126 |
+
|
127 |
+
<p>
|
128 |
+
<label class="frm_left_label"><?php _e( 'Default Submit Button', 'formidable' ); ?></label>
|
129 |
+
<input type="text" value="<?php echo esc_attr( $frm_settings->submit_value ) ?>" id="frm_submit_value" name="frm_submit_value" class="frm_with_left_label" />
|
130 |
+
</p>
|
131 |
+
|
132 |
<?php do_action('frm_settings_form', $frm_settings); ?>
|
133 |
+
|
134 |
+
<?php if ( ! FrmAppHelper::pro_is_installed() ) { ?>
|
135 |
<div class="clear"></div>
|
136 |
+
<h3><?php _e( 'Miscellaneous', 'formidable' ) ?></h3>
|
|
|
|
|
137 |
<?php } ?>
|
138 |
+
<p><label class="frm_left_label"><?php _e( 'Admin menu label', 'formidable' ); ?></label>
|
139 |
<input type="text" name="frm_menu" id="frm_menu" value="<?php echo esc_attr($frm_settings->menu) ?>" />
|
140 |
+
<?php if ( is_multisite() && is_super_admin() ) { ?>
|
141 |
+
<label for="frm_mu_menu"><input type="checkbox" name="frm_mu_menu" id="frm_mu_menu" value="1" <?php checked($frm_settings->mu_menu, 1) ?> /> <?php _e( 'Use this menu name site-wide', 'formidable' ); ?></label>
|
142 |
<?php } ?>
|
143 |
</p>
|
144 |
+
|
145 |
+
<p><label class="frm_left_label"><?php _e( 'Preview Page', 'formidable' ); ?></label>
|
146 |
<?php FrmAppHelper::wp_pages_dropdown('frm-preview-page-id', $frm_settings->preview_page_id ) ?>
|
147 |
</p>
|
148 |
+
|
|
|
|
|
|
|
149 |
</div>
|
150 |
+
|
151 |
+
<?php
|
152 |
+
foreach ( $sections as $sec_name => $section ) {
|
153 |
+
if ( $a == $sec_name .'_settings' ) { ?>
|
154 |
+
<style type="text/css">.<?php echo esc_attr( $sec_name ) ?>_settings{display:block;}</style><?php }?>
|
155 |
+
<div id="<?php echo esc_attr( $sec_name ) ?>_settings" class="<?php echo esc_attr( $sec_name ) ?>_settings tabs-panel <?php echo ( $a == $sec_name .'_settings' ) ? 'frm_block' : 'frm_hidden'; ?>"><?php
|
156 |
+
if ( isset( $section['class'] ) ) {
|
157 |
+
call_user_func( array($section['class'], $section['function']));
|
158 |
+
} else {
|
159 |
+
call_user_func((isset($section['function']) ? $section['function'] : $section));
|
160 |
} ?>
|
161 |
</div>
|
162 |
+
<?php
|
163 |
+
} ?>
|
164 |
+
|
165 |
+
<p class="alignright frm_uninstall">
|
166 |
+
<a href="javascript:void(0)" id="frm_uninstall_now"><?php _e( 'Uninstall Formidable', 'formidable' ) ?></a>
|
167 |
<span class="spinner frm_spinner"></span>
|
168 |
</p>
|
169 |
<p class="submit">
|
170 |
+
<input class="button-primary" type="submit" value="<?php esc_attr_e( 'Update Options', 'formidable' ) ?>" />
|
171 |
</p>
|
172 |
|
173 |
</form>
|
classes/views/frm-settings/license_box.php
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
<div class="general_settings metabox-holder tabs-panel
|
2 |
-
<?php if (!is_multisite()
|
3 |
<div class="postbox">
|
4 |
<div class="inside">
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
<p>Already signed up? <a href="http://formidablepro.com/knowledgebase/manually-install-formidable-pro/" target="_blank"><?php _e('Click here', 'formidable') ?></a> to get installation instructions and download the pro version.</p>
|
9 |
</div>
|
10 |
</div>
|
11 |
<?php } ?>
|
1 |
+
<div class="general_settings metabox-holder tabs-panel frm_license_box <?php echo ($a == 'general_settings') ? 'frm_block' : 'frm_hidden'; ?>">
|
2 |
+
<?php if ( ! is_multisite() || is_super_admin() ) { ?>
|
3 |
<div class="postbox">
|
4 |
<div class="inside">
|
5 |
+
<p class="alignright"><?php printf( __( '%1$sClick here%2$s to get it now', 'formidable' ), '<a href="http://formidablepro.com">', '</a>' ) ?> »</p>
|
6 |
+
<p><?php _e( 'Ready to take your forms to the next level?<br/>Formidable Forms will help you create views, manage data, and get reports.', 'formidable' ) ?></p>
|
7 |
+
|
8 |
+
<p>Already signed up? <a href="http://formidablepro.com/knowledgebase/manually-install-formidable-pro/" target="_blank"><?php _e( 'Click here', 'formidable' ) ?></a> to get installation instructions and download the pro version.</p>
|
9 |
</div>
|
10 |
</div>
|
11 |
<?php } ?>
|
classes/views/frm-settings/styling_tab.php
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
<div class="frm_update_msg">
|
2 |
-
This plugin version does not give you access to the visual form styler.<br/>
|
3 |
-
<a href="http://formidablepro.com/pricing/" target="_blank">Compare</a> our plans to find a solution that's right for you.
|
4 |
-
</div>
|
|
|
|
|
|
|
|
classes/views/frm-statistics/list.php
CHANGED
@@ -1,17 +1,19 @@
|
|
1 |
<div id="form_reports_page" class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
<h2>
|
4 |
-
<?php _e('Reports', 'formidable') ?>
|
5 |
-
<a href="#" class="add-new-h2
|
6 |
</h2>
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
?>
|
14 |
|
15 |
-
|
|
|
|
|
|
|
16 |
|
17 |
</div>
|
1 |
<div id="form_reports_page" class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
<h2>
|
4 |
+
<?php _e( 'Reports', 'formidable' ) ?>
|
5 |
+
<a href="#" class="add-new-h2 frm_invisible"><?php _e( 'Add New', 'formidable' ); ?></a>
|
6 |
</h2>
|
7 |
|
8 |
+
<?php
|
9 |
+
if ( $form ) {
|
10 |
+
FrmAppController::get_form_nav( $form, true );
|
11 |
+
}
|
12 |
+
require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' );
|
|
|
13 |
|
14 |
+
FrmAppHelper::update_message( __( 'view reports and statistics on your saved entries', 'formidable' ) );
|
15 |
+
?>
|
16 |
+
|
17 |
+
<img class="frm_no_reports" src="http://fp.strategy11.com/wp-content/themes/formidablepro/images/reports1.png" alt="Reports"/>
|
18 |
|
19 |
</div>
|
classes/views/frm-statistics/list_displays.php
CHANGED
@@ -1,16 +1,18 @@
|
|
1 |
<div id="form_views_page" class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
<h2>
|
4 |
-
<?php _e('Views', 'formidable'); ?>
|
5 |
-
<a href="#" class="add-new-h2
|
6 |
</h2>
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
1 |
<div id="form_views_page" class="wrap">
|
2 |
<div class="frmicon icon32"><br/></div>
|
3 |
<h2>
|
4 |
+
<?php _e( 'Views', 'formidable' ); ?>
|
5 |
+
<a href="#" class="add-new-h2 frm_invisible"><?php _e( 'Add New', 'formidable' ); ?></a>
|
6 |
</h2>
|
7 |
|
8 |
+
<?php
|
9 |
+
if ( $form ) {
|
10 |
+
FrmAppController::get_form_nav( $form );
|
11 |
+
}
|
12 |
+
require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' );
|
13 |
+
FrmAppHelper::update_me
|