PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 1.07.11
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v1.07.11
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / helpers / FrmFormsHelper.php

FrmFormsHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 1.07.11, at classes/helpers/FrmFormsHelper.php

297 lines 13.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
4 if(class_exists('FrmFormsHelper'))
5 return;
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 get_template_dropdown($templates) {
16 if ( ! current_user_can('frm_edit_forms') ) {
17 return;
18 }
19 ?>
20 <select id="select_form" name="select_form" onChange="frmAddNewForm(this.value,'duplicate')">
21 <option value="">&mdash; <?php _e('Create Form from Template', 'formidable') ?> &mdash;</option>
22 <?php foreach ($templates as $temp){ ?>
23 <option value="<?php echo $temp->id ?>"><?php echo FrmAppHelper::truncate($temp->name, 40) ?></option>
24 <?php }?>
25 </select>
26 <?php
27 }
28
29 public static function forms_dropdown( $field_name, $field_value='', $blank=true, $field_id=false, $onchange=false ){
30 if (!$field_id)
31 $field_id = $field_name;
32
33 $where = apply_filters('frm_forms_dropdown', "is_template=0 AND (status is NULL OR status = '' OR status = 'published')", $field_name);
34 $frm_form = new FrmForm();
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 $where = apply_filters('frm_forms_dropdown', "is_template=0 AND (status is NULL OR status = '' OR status = 'published')", '');
50
51 $frm_form = new FrmForm();
52 $forms = $frm_form->getAll($where, ' ORDER BY name');
53 unset($frm_form);
54
55 $args = array('id' => 0, 'form' => 0);
56 if(isset($_GET['id']) and !isset($_GET['form']))
57 unset($args['form']);
58 else if(isset($_GET['form']) and !isset($_GET['id']))
59 unset($args['id']);
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 }else if(isset($_GET['page']) and $_GET['page'] == 'formidable' and isset($_GET['frm_action']) and $_GET['frm_action'] == 'new'){
65 $args['frm_action'] = 'edit';
66 }else if(isset($_GET['post'])){
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 foreach($forms as $form){
76 if(isset($args['id']))
77 $args['id'] = $form->id;
78 if(isset($args['form']))
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 unset($form);
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 and $sort_dir == 'desc') ? ' asc' : ' desc';
93 }
94
95 public static function setup_new_vars($values=array()){
96 global $wpdb, $frmdb, $frm_settings;
97
98 if(!empty($values)){
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 if(!isset($values[$var]))
107 $values[$var] = FrmAppHelper::get_param($var, $default);
108 }
109
110 if(apply_filters('frm_use_wpautop', true))
111 $values['description'] = wpautop(str_replace( '<br>', '<br />', $values['description']));
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 $values['custom_style'] = ($post_values and isset($post_values['options']['custom_style'])) ? $post_values['options']['custom_style'] : ($frm_settings->load_style != 'none');
124 $values['before_html'] = FrmFormsHelper::get_default_html('before');
125 $values['after_html'] = FrmFormsHelper::get_default_html('after');
126 $values['submit_html'] = FrmFormsHelper::get_default_html('submit');
127
128 return apply_filters('frm_setup_new_form_vars', $values);
129 }
130
131 public static function setup_edit_vars($values, $record, $post_values=array()){
132 if(empty($post_values))
133 $post_values = stripslashes_deep($_POST);
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 = FrmFormsHelper::get_default_opts();
147 foreach ($defaults as $var => $default){
148 if ( is_array($default) ) {
149 if(!isset($values[$var]))
150 $values[$var] = ($record && isset($record->options[$var])) ? $record->options[$var] : array();
151
152 foreach($default as $k => $v){
153 $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);
154
155 if ( is_array($v) ) {
156 foreach ( $v as $k1 => $v1 ) {
157 $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);
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 global $frm_settings;
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 public static function get_default_html($loc){
197 if($loc == 'submit'){
198 $sending = __('Sending', 'formidable');
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" style="visibility:hidden;" />
206 $draft_link
207 </div>
208 SUBMIT_HTML;
209 }else if ($loc == 'before'){
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 }else{
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 = FrmFormsHelper::replace_shortcodes($html, $form, $submit, $form_action, $values);
228 if(strpos($button, '[button_action]')){
229 $button_parts = explode('[button_action]', $button);
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 public static function replace_shortcodes($html, $form, $title=false, $description=false, $values=array()){
242 foreach (array('form_name' => $title, 'form_description' => $description, 'entry_key' => true) as $code => $show){
243 if ($code == 'form_name'){
244 $replace_with = $form->name;
245 }else if ($code == 'form_description'){
246 if(apply_filters('frm_use_wpautop', true))
247 $replace_with = wpautop(str_replace( '<br>', '<br />', $form->description));
248 else
249 $replace_with = $form->description;
250 }else if($code == 'entry_key' and isset($_GET) and isset($_GET['entry'])){
251 $replace_with = $_GET['entry'];
252 }
253
254 if ( FrmAppHelper::is_true($show) && $replace_with != '' ) {
255 $html = str_replace('[if '.$code.']', '', $html);
256 $html = str_replace('[/if '.$code.']', '', $html);
257 }else{
258 $html = preg_replace('/(\[if\s+'.$code.'\])(.*?)(\[\/if\s+'.$code.'\])/mis', '', $html);
259 }
260 $html = str_replace('['.$code.']', $replace_with, $html);
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]', FrmAppHelper::plugin_url(), $html);
268
269 if(strpos($html, '[button_label]')){
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 if(strpos($html, '[if back_button]'))
277 $html = preg_replace('/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html);
278
279 if(strpos($html, '[if save_draft]'))
280 $html = preg_replace('/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html);
281
282 return $html;
283 }
284
285 public static function form_loaded($form) {
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 }
297