| @@ -1,708 +1,440 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 2 | +/** | |
| 3 | + * @package Formidable | |
| 4 | + */ | |
| 5 | + | |
| 6 | +if(!defined('ABSPATH')) die('You are not allowed to call this page directly.'); | |
| 5 | 7 | |
| 6 | -class FrmEntriesController { | |
| 8 | +if(class_exists('FrmEntriesController')) | |
| 9 | + return; | |
| 7 | 10 | |
| 8 | - public static function menu() { | |
| 9 | - FrmAppHelper::force_capability( 'frm_view_entries' ); | |
| 11 | +class FrmEntriesController{ | |
| 12 | + | |
| 13 | + public static function load_hooks(){ | |
| 14 | + add_action('admin_menu', 'FrmEntriesController::menu', 11); | |
| 15 | + add_action('wp', 'FrmEntriesController::process_entry', 10, 0); | |
| 16 | + add_action('frm_wp', 'FrmEntriesController::process_entry', 10, 0); | |
| 17 | + add_filter('frm_redirect_url', 'FrmEntriesController::delete_entry_before_redirect', 50, 3); | |
| 18 | + add_action('frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100); | |
| 19 | + add_filter('frm_email_value', 'FrmEntriesController::filter_email_value', 10, 3); | |
| 20 | + } | |
| 21 | + | |
| 22 | + public static function menu(){ | |
| 23 | + global $frm_vars; | |
| 24 | + if(!$frm_vars['pro_is_installed']){ | |
| 25 | + add_submenu_page('formidable', 'Formidable |'. __('Entries', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Entries', 'formidable') .'</span>', 'administrator', 'formidable-entries', 'FrmEntriesController::list_entries'); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + | |
| 29 | + public static function list_entries(){ | |
| 30 | + global $frm_entry; | |
| 31 | + $frm_form = new FrmForm(); | |
| 32 | + $form_select = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name'); | |
| 33 | + $form_id = FrmAppHelper::get_param('form', false); | |
| 34 | + if($form_id) | |
| 35 | + $form = $frm_form->getOne($form_id); | |
| 36 | + else | |
| 37 | + $form = (isset($form_select[0])) ? $form_select[0] : 0; | |
| 38 | + | |
| 39 | + if($form) | |
| 40 | + $entry_count = $frm_entry->getRecordCount($form->id); | |
| 41 | + | |
| 42 | + include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php'); | |
| 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 | + if((is_admin() and !defined('DOING_AJAX')) or !isset($_POST) or !isset($_POST['form_id']) or !is_numeric($_POST['form_id']) or !isset($_POST['item_key'])) | |
| 57 | + return; | |
| 10 | 58 | |
| 11 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); | |
| 59 | + global $frm_entry, $frm_vars; | |
| 60 | + | |
| 61 | + $frm_form = new FrmForm(); | |
| 62 | + $form = $frm_form->getOne($_POST['form_id']); | |
| 63 | + if(!$form) | |
| 64 | + return; | |
| 65 | + | |
| 66 | + $params = FrmEntriesController::get_params($form); | |
| 67 | + | |
| 68 | + if(!isset($frm_vars['form_params'])) | |
| 69 | + $frm_vars['form_params'] = array(); | |
| 70 | + $frm_vars['form_params'][$form->id] = $params; | |
| 71 | + | |
| 72 | + if(isset($frm_vars['created_entries'][$_POST['form_id']])) | |
| 73 | + return; | |
| 74 | + | |
| 75 | + if($errors == '') | |
| 76 | + $errors = $frm_entry->validate($_POST); | |
| 77 | + $frm_vars['created_entries'][$_POST['form_id']] = array('errors' => $errors); | |
| 78 | + | |
| 79 | + if( empty($errors) ){ | |
| 80 | + $_POST['frm_skip_cookie'] = 1; | |
| 81 | + if($params['action'] == 'create'){ | |
| 82 | + if (apply_filters('frm_continue_to_create', true, $_POST['form_id']) and !isset($frm_vars['created_entries'][$_POST['form_id']]['entry_id'])) | |
| 83 | + $frm_vars['created_entries'][$_POST['form_id']]['entry_id'] = $frm_entry->create( $_POST ); | |
| 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(!$form) | |
| 103 | + return; | |
| 104 | + | |
| 105 | + $form->options = maybe_unserialize($form->options); | |
| 106 | + if(isset($form->options['no_save']) and $form->options['no_save']){ | |
| 107 | + global $frm_entry; | |
| 108 | + $frm_entry->destroy( $entry_id ); | |
| 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 | + extract($atts); | |
| 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); | |
| 12 | 219 | |
| 13 | - $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) ? FrmProAppHelper::views_is_installed() : FrmAppHelper::pro_is_installed(); | |
| 14 | - if ( ! $views_installed ) { | |
| 15 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Views', 'formidable' ), __( 'Views', 'formidable' ), 'frm_view_entries', 'formidable-views', 'FrmFormsController::no_views' ); | |
| 16 | - } | |
| 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 | + } | |
| 17 | 224 | |
| 18 | - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) { | |
| 19 | - self::load_manage_entries_hooks(); | |
| 20 | - } | |
| 21 | - } | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * @since 2.05.07 | |
| 25 | - */ | |
| 26 | - private static function load_manage_entries_hooks() { | |
| 27 | - if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) { | |
| 28 | - $menu_name = FrmAppHelper::get_menu_name(); | |
| 29 | - $base = self::base_column_key( $menu_name ); | |
| 30 | - | |
| 31 | - add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' ); | |
| 32 | - add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' ); | |
| 33 | - add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' ); | |
| 34 | - } else { | |
| 35 | - add_filter( 'screen_options_show_screen', __CLASS__ . '::remove_screen_options', 10, 2 ); | |
| 36 | - } | |
| 37 | - } | |
| 38 | - | |
| 39 | - /* Display in Back End */ | |
| 40 | - public static function route() { | |
| 41 | - $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' ); | |
| 42 | - FrmAppHelper::include_svg(); | |
| 43 | - | |
| 44 | - switch ( $action ) { | |
| 45 | - case 'show': | |
| 46 | - case 'destroy': | |
| 47 | - return self::$action(); | |
| 48 | - | |
| 49 | - default: | |
| 50 | - do_action( 'frm_entry_action_route', $action ); | |
| 51 | - if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) { | |
| 52 | - return; | |
| 225 | + if ( $f->type == 'textarea' and !$plain_text ) { | |
| 226 | + $val = str_replace(array("\r\n", "\r", "\n"), ' <br/>', $val); | |
| 227 | + } | |
| 228 | + | |
| 229 | + //Remove signature from default-message shortcode | |
| 230 | + if ( $f->type == 'signature' && !$default_email ) { | |
| 231 | + continue; | |
| 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]"; | |
| 53 | 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 | + if ( $format != 'text' ) { | |
| 284 | + $content['ip'] = $entry->ip; | |
| 285 | + $content['browser'] = $data['browser']; | |
| 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 | + } | |
| 54 | 330 | |
| 55 | - return self::display_list(); | |
| 56 | - } | |
| 57 | - } | |
| 331 | + if ( ! $plain_text ) { | |
| 332 | + $content .= '</tbody></table>'; | |
| 333 | + } | |
| 334 | + | |
| 335 | + if ( $format == 'json' ) { | |
| 336 | + $content = json_encode($content); | |
| 337 | + } | |
| 338 | + | |
| 339 | + return $content; | |
| 340 | + } | |
| 341 | + | |
| 342 | + public static function &filter_email_value($value, $meta, $entry, $atts=array()){ | |
| 343 | + $frm_field = new FrmField(); | |
| 344 | + $field = $frm_field->getOne($meta->field_id); | |
| 345 | + if(!$field) | |
| 346 | + return $value; | |
| 347 | + | |
| 348 | + $value = self::filter_display_value($value, $field, $atts); | |
| 349 | + return $value; | |
| 350 | + } | |
| 351 | + | |
| 352 | + public static function &filter_display_value($value, $field, $atts=array()){ | |
| 353 | + $field->field_options = maybe_unserialize($field->field_options); | |
| 354 | + | |
| 355 | + $saved_value = (isset($atts['saved_value']) and $atts['saved_value']) ? true : false; | |
| 356 | + if(!in_array($field->type, array('radio', 'checkbox', 'radio', 'select')) or !isset($field->field_options['separate_value']) or !$field->field_options['separate_value'] or $saved_value) | |
| 357 | + return $value; | |
| 358 | + | |
| 359 | + $field->options = maybe_unserialize($field->options); | |
| 360 | + $f_values = array(); | |
| 361 | + $f_labels = array(); | |
| 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 | + unset($opt_key); | |
| 373 | + unset($opt); | |
| 374 | + } | |
| 58 | 375 | |
| 59 | - /** | |
| 60 | - * Prevent the "screen options" tab from showing when | |
| 61 | - * editing or creating an entry | |
| 62 | - * | |
| 63 | - * @since 3.0 | |
| 64 | - */ | |
| 65 | - public static function remove_screen_options( $show_screen, $screen ) { | |
| 66 | - $menu_name = sanitize_title( FrmAppHelper::get_menu_name() ); | |
| 67 | - if ( $screen->id == $menu_name . '_page_formidable-entries' ) { | |
| 68 | - $show_screen = false; | |
| 69 | - } | |
| 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 | + public static function get_params($form=null){ | |
| 394 | + global $frm_vars; | |
| 395 | + | |
| 396 | + $frm_form = new FrmForm(); | |
| 397 | + if(!$form) | |
| 398 | + $form = $frm_form->getAll(array(), 'name', 1); | |
| 399 | + else if(!is_object($form)) | |
| 400 | + $form = $frm_form->getOne($form); | |
| 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'); | |
| 70 | 416 | |
| 71 | - return $show_screen; | |
| 72 | - } | |
| 417 | + if ($form->id == $values['posted_form_id']){ //if there are two forms on the same page, make sure not to submit both | |
| 418 | + foreach ($default_values as $var => $default){ | |
| 419 | + if($var == 'action') | |
| 420 | + $values[$var] = FrmAppHelper::get_param($action_var, $default); | |
| 421 | + else | |
| 422 | + $values[$var] = FrmAppHelper::get_param($var, $default); | |
| 423 | + unset($var); | |
| 424 | + unset($default); | |
| 425 | + } | |
| 426 | + }else{ | |
| 427 | + foreach ($default_values as $var => $default){ | |
| 428 | + $values[$var] = $default; | |
| 429 | + unset($var); | |
| 430 | + unset($default); | |
| 431 | + } | |
| 432 | + } | |
| 73 | 433 | |
| 74 | - public static function manage_columns( $columns ) { | |
| 75 | - global $frm_vars; | |
| 76 | - $form_id = FrmForm::get_current_form_id(); | |
| 434 | + if(in_array($values['action'], array('create', 'update')) and (!isset($_POST) or (!isset($_POST['action']) and !isset($_POST['frm_action'])))) | |
| 435 | + $values['action'] = 'new'; | |
| 77 | 436 | |
| 78 | - $columns[ $form_id . '_id' ] = 'ID'; | |
| 79 | - $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' ); | |
| 80 | - | |
| 81 | - if ( $form_id ) { | |
| 82 | - self::get_columns_for_form( $form_id, $columns ); | |
| 83 | - } else { | |
| 84 | - $columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' ); | |
| 85 | - $columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' ); | |
| 86 | - $columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' ); | |
| 87 | - } | |
| 88 | - | |
| 89 | - $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' ); | |
| 90 | - $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' ); | |
| 91 | - self::maybe_add_ip_col( $form_id, $columns ); | |
| 92 | - | |
| 93 | - $frm_vars['cols'] = $columns; | |
| 94 | - | |
| 95 | - $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); | |
| 96 | - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) { | |
| 97 | - add_screen_option( | |
| 98 | - 'per_page', | |
| 99 | - array( | |
| 100 | - 'label' => __( 'Entries', 'formidable' ), | |
| 101 | - 'default' => 20, | |
| 102 | - 'option' => 'formidable_page_formidable_entries_per_page', | |
| 103 | - ) | |
| 104 | - ); | |
| 105 | - } | |
| 106 | - | |
| 107 | - return $columns; | |
| 108 | - } | |
| 109 | - | |
| 110 | - private static function get_columns_for_form( $form_id, &$columns ) { | |
| 111 | - $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' ); | |
| 112 | - | |
| 113 | - /** | |
| 114 | - * Allows changing fields in the Entries list table heading. | |
| 115 | - * | |
| 116 | - * @since 5.0.04 | |
| 117 | - * | |
| 118 | - * @param array $fields Array of fields. | |
| 119 | - * @param array $args The arguments. Contains `form_id`. | |
| 120 | - */ | |
| 121 | - $form_cols = apply_filters( 'frm_fields_in_entries_list_table', $form_cols, compact( 'form_id' ) ); | |
| 122 | - | |
| 123 | - foreach ( $form_cols as $form_col ) { | |
| 124 | - if ( FrmField::is_no_save_field( $form_col->type ) ) { | |
| 125 | - continue; | |
| 126 | - } | |
| 127 | - | |
| 128 | - $has_child_fields = $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ); | |
| 129 | - if ( $has_child_fields ) { | |
| 130 | - self::add_subform_cols( $form_col, $form_id, $columns ); | |
| 131 | - } else { | |
| 132 | - self::add_field_cols( $form_col, $form_id, $columns ); | |
| 133 | - } | |
| 134 | - } | |
| 135 | - } | |
| 136 | - | |
| 137 | - /** | |
| 138 | - * @since 3.01 | |
| 139 | - */ | |
| 140 | - private static function add_subform_cols( $field, $form_id, &$columns ) { | |
| 141 | - $sub_form_cols = FrmField::get_all_for_form( $field->field_options['form_select'] ); | |
| 142 | - if ( empty( $sub_form_cols ) ) { | |
| 143 | - return; | |
| 144 | - } | |
| 145 | - | |
| 146 | - foreach ( $sub_form_cols as $k => $sub_form_col ) { | |
| 147 | - if ( FrmField::is_no_save_field( $sub_form_col->type ) ) { | |
| 148 | - unset( $sub_form_cols[ $k ] ); | |
| 149 | - continue; | |
| 150 | - } | |
| 151 | - $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $field->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); | |
| 152 | - unset( $sub_form_col ); | |
| 153 | - } | |
| 154 | - } | |
| 155 | - | |
| 156 | - /** | |
| 157 | - * @since 3.01 | |
| 158 | - */ | |
| 159 | - private static function add_field_cols( $field, $form_id, &$columns ) { | |
| 160 | - $col_id = $field->field_key; | |
| 161 | - if ( $field->form_id != $form_id ) { | |
| 162 | - $col_id .= '-_-form' . $field->form_id; | |
| 163 | - } | |
| 164 | - | |
| 165 | - $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' ); | |
| 166 | - $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] == 'post_status'; | |
| 167 | - if ( $has_separate_value && ! $is_post_status ) { | |
| 168 | - $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 ); | |
| 169 | - } | |
| 170 | - | |
| 171 | - $columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 ); | |
| 172 | - } | |
| 173 | - | |
| 174 | - private static function maybe_add_ip_col( $form_id, &$columns ) { | |
| 175 | - if ( FrmAppHelper::ips_saved() ) { | |
| 176 | - $columns[ $form_id . '_ip' ] = 'IP'; | |
| 177 | - } | |
| 178 | - } | |
| 179 | - | |
| 180 | - public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) { | |
| 181 | - $this_page_name = self::hidden_column_key(); | |
| 182 | - if ( $meta_key != $this_page_name || $meta_value == $prev_value ) { | |
| 183 | - return $check; | |
| 184 | - } | |
| 185 | - | |
| 186 | - if ( empty( $prev_value ) ) { | |
| 187 | - $prev_value = get_metadata( 'user', $object_id, $meta_key, true ); | |
| 188 | - } | |
| 189 | - | |
| 190 | - global $frm_vars; | |
| 191 | - //add a check so we don't create a loop | |
| 192 | - $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; | |
| 193 | - | |
| 194 | - return $check; | |
| 195 | - } | |
| 196 | - | |
| 197 | - /** | |
| 198 | - * Add hidden columns back from other forms | |
| 199 | - */ | |
| 200 | - public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) { | |
| 201 | - $this_page_name = self::hidden_column_key(); | |
| 202 | - if ( $meta_key != $this_page_name ) { | |
| 203 | - return; | |
| 204 | - } | |
| 205 | - | |
| 206 | - global $frm_vars; | |
| 207 | - if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) { | |
| 208 | - return; // Don't continue if there's no previous value. | |
| 209 | - } | |
| 210 | - | |
| 211 | - foreach ( $meta_value as $mk => $mv ) { | |
| 212 | - // Remove blank values. | |
| 213 | - if ( empty( $mv ) ) { | |
| 214 | - unset( $meta_value[ $mk ] ); | |
| 215 | - } | |
| 216 | - } | |
| 217 | - | |
| 218 | - $cur_form_prefix = reset( $meta_value ); | |
| 219 | - $cur_form_prefix = explode( '_', $cur_form_prefix ); | |
| 220 | - $cur_form_prefix = $cur_form_prefix[0]; | |
| 221 | - $save = false; | |
| 222 | - | |
| 223 | - foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) { | |
| 224 | - if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) { | |
| 225 | - // Don't add blank cols or process included cols. | |
| 226 | - continue; | |
| 227 | - } | |
| 228 | - | |
| 229 | - $form_prefix = explode( '_', $prev_hidden ); | |
| 230 | - $form_prefix = $form_prefix[0]; | |
| 231 | - if ( $form_prefix == $cur_form_prefix ) { | |
| 232 | - // Don't add back columns that are meant to be hidden. | |
| 233 | - continue; | |
| 234 | - } | |
| 235 | - | |
| 236 | - $meta_value[] = $prev_hidden; | |
| 237 | - $save = true; | |
| 238 | - unset( $form_prefix ); | |
| 239 | - } | |
| 240 | - | |
| 241 | - if ( $save ) { | |
| 242 | - $user_id = get_current_user_id(); | |
| 243 | - update_user_option( $user_id, $this_page_name, $meta_value, true ); | |
| 244 | - } | |
| 245 | - } | |
| 246 | - | |
| 247 | - /** | |
| 248 | - * @since 2.05.07 | |
| 249 | - */ | |
| 250 | - private static function hidden_column_key( $menu_name = '' ) { | |
| 251 | - $base = self::base_column_key( $menu_name ); | |
| 252 | - | |
| 253 | - return 'manage' . $base . 'columnshidden'; | |
| 254 | - } | |
| 255 | - | |
| 256 | - /** | |
| 257 | - * @since 2.05.07 | |
| 258 | - */ | |
| 259 | - private static function base_column_key( $menu_name = '' ) { | |
| 260 | - if ( empty( $menu_name ) ) { | |
| 261 | - $menu_name = FrmAppHelper::get_menu_name(); | |
| 262 | - } | |
| 263 | - | |
| 264 | - return sanitize_title( $menu_name ) . '_page_formidable-entries'; | |
| 265 | - } | |
| 266 | - | |
| 267 | - public static function save_per_page( $save, $option, $value ) { | |
| 268 | - if ( $option == 'formidable_page_formidable_entries_per_page' ) { | |
| 269 | - $save = (int) $value; | |
| 270 | - } | |
| 271 | - | |
| 272 | - return $save; | |
| 273 | - } | |
| 274 | - | |
| 275 | - public static function sortable_columns() { | |
| 276 | - $form_id = FrmForm::get_current_form_id(); | |
| 277 | - $fields = FrmField::get_all_for_form( $form_id ); | |
| 278 | - | |
| 279 | - $columns = array( | |
| 280 | - $form_id . '_id' => 'id', | |
| 281 | - $form_id . '_created_at' => 'created_at', | |
| 282 | - $form_id . '_updated_at' => 'updated_at', | |
| 283 | - $form_id . '_ip' => 'ip', | |
| 284 | - $form_id . '_item_key' => 'item_key', | |
| 285 | - $form_id . '_is_draft' => 'is_draft', | |
| 286 | - ); | |
| 287 | - | |
| 288 | - foreach ( $fields as $field ) { | |
| 289 | - if ( self::field_supports_sorting( $field ) ) { | |
| 290 | - $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id; | |
| 291 | - } | |
| 292 | - } | |
| 293 | - | |
| 294 | - return $columns; | |
| 295 | - } | |
| 296 | - | |
| 297 | - /** | |
| 298 | - * Can't sort on checkboxes because they are sorted serialized. | |
| 299 | - * Some post content can be sorted but not everything. | |
| 300 | - * | |
| 301 | - * @param stdClass $field | |
| 302 | - * @return bool | |
| 303 | - */ | |
| 304 | - private static function field_supports_sorting( $field ) { | |
| 305 | - $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] ); | |
| 306 | - return apply_filters( 'frm_field_column_is_sortable', $is_sortable, $field ); | |
| 307 | - } | |
| 308 | - | |
| 309 | - /** | |
| 310 | - * @param mixed $result Option value from database for hidden columns in entries table. | |
| 311 | - * @return array | |
| 312 | - */ | |
| 313 | - public static function hidden_columns( $result ) { | |
| 314 | - if ( ! is_array( $result ) ) { | |
| 315 | - // Force an unexpected value to be an array. | |
| 316 | - // Since $result is a filtered option and gets saved to the database, it's possible it could be a string. | |
| 317 | - // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error. | |
| 318 | - $result = array(); | |
| 319 | - } | |
| 320 | - | |
| 321 | - $form_id = FrmForm::get_current_form_id(); | |
| 322 | - | |
| 323 | - $hidden = self::user_hidden_columns_for_form( $form_id, $result ); | |
| 324 | - | |
| 325 | - global $frm_vars; | |
| 326 | - $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0; | |
| 327 | - | |
| 328 | - if ( ! empty( $hidden ) ) { | |
| 329 | - $result = $hidden; | |
| 330 | - $i = $i - count( $result ); | |
| 331 | - $max_columns = 11; | |
| 332 | - } else { | |
| 333 | - $max_columns = 8; | |
| 334 | - } | |
| 335 | - | |
| 336 | - if ( $i <= $max_columns ) { | |
| 337 | - return $result; | |
| 338 | - } | |
| 339 | - | |
| 340 | - self::remove_excess_cols( compact( 'i', 'max_columns', 'form_id' ), $result ); | |
| 341 | - | |
| 342 | - return $result; | |
| 343 | - } | |
| 344 | - | |
| 345 | - /** | |
| 346 | - * @since 2.05.07 | |
| 347 | - */ | |
| 348 | - private static function user_hidden_columns_for_form( $form_id, $result ) { | |
| 349 | - $hidden = array(); | |
| 350 | - foreach ( (array) $result as $r ) { | |
| 351 | - if ( ! empty( $r ) ) { | |
| 352 | - list( $form_prefix, $field_key ) = explode( '_', $r ); | |
| 353 | - | |
| 354 | - if ( (int) $form_prefix == (int) $form_id ) { | |
| 355 | - $hidden[] = $r; | |
| 356 | - } | |
| 357 | - | |
| 358 | - unset( $form_prefix ); | |
| 359 | - } | |
| 360 | - } | |
| 361 | - | |
| 362 | - return $hidden; | |
| 363 | - } | |
| 364 | - | |
| 365 | - /** | |
| 366 | - * Remove some columns by default when there are too many | |
| 367 | - * | |
| 368 | - * @since 2.05.07 | |
| 369 | - */ | |
| 370 | - private static function remove_excess_cols( $atts, &$result ) { | |
| 371 | - global $frm_vars; | |
| 372 | - | |
| 373 | - $remove_first = array( | |
| 374 | - $atts['form_id'] . '_item_key' => '', | |
| 375 | - $atts['form_id'] . '_id' => '', | |
| 376 | - ); | |
| 377 | - $cols = $remove_first + array_reverse( $frm_vars['cols'], true ); | |
| 378 | - | |
| 379 | - $i = $atts['i']; | |
| 380 | - | |
| 381 | - foreach ( $cols as $col_key => $col ) { | |
| 382 | - if ( $i <= $atts['max_columns'] ) { | |
| 383 | - break; | |
| 384 | - } | |
| 385 | - | |
| 386 | - if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) { | |
| 387 | - $result[] = $col_key; | |
| 388 | - $i--; | |
| 389 | - } | |
| 390 | - | |
| 391 | - unset( $col_key, $col ); | |
| 392 | - } | |
| 393 | - } | |
| 394 | - | |
| 395 | - public static function display_list( $message = '', $errors = array() ) { | |
| 396 | - global $wpdb, $frm_vars; | |
| 397 | - | |
| 398 | - $form = FrmForm::maybe_get_current_form(); | |
| 399 | - $params = FrmForm::get_admin_params( $form ); | |
| 400 | - | |
| 401 | - if ( $form ) { | |
| 402 | - $params['form'] = $form->id; | |
| 403 | - $frm_vars['current_form'] = $form; | |
| 404 | - | |
| 405 | - self::get_delete_form_time( $form, $errors ); | |
| 406 | - } | |
| 407 | - | |
| 408 | - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' ); | |
| 409 | - | |
| 410 | - $wp_list_table = new $table_class( array( 'params' => $params ) ); | |
| 411 | - | |
| 412 | - $pagenum = $wp_list_table->get_pagenum(); | |
| 413 | - | |
| 414 | - $wp_list_table->prepare_items(); | |
| 415 | - | |
| 416 | - $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); | |
| 417 | - if ( $pagenum > $total_pages && $total_pages > 0 ) { | |
| 418 | - $url = add_query_arg( 'paged', $total_pages ); | |
| 419 | - if ( headers_sent() ) { | |
| 420 | - FrmAppHelper::js_redirect( $url, true ); | |
| 421 | - } else { | |
| 422 | - wp_redirect( esc_url_raw( $url ) ); | |
| 423 | - } | |
| 424 | - die(); | |
| 425 | - } | |
| 426 | - | |
| 427 | - if ( empty( $message ) && isset( $_GET['import-message'] ) ) { | |
| 428 | - $message = __( 'Your import is complete', 'formidable' ); | |
| 429 | - } | |
| 430 | - | |
| 431 | - require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php'; | |
| 432 | - } | |
| 433 | - | |
| 434 | - private static function get_delete_form_time( $form, &$errors ) { | |
| 435 | - if ( 'trash' == $form->status ) { | |
| 436 | - $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); | |
| 437 | - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) ); | |
| 438 | - | |
| 439 | - /* translators: %1$s: Time string */ | |
| 440 | - $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 ); | |
| 441 | - } | |
| 442 | - } | |
| 443 | - | |
| 444 | - /* Back End CRUD */ | |
| 445 | - public static function show( $id = 0 ) { | |
| 446 | - FrmAppHelper::permission_check( 'frm_view_entries' ); | |
| 447 | - | |
| 448 | - if ( ! $id ) { | |
| 449 | - $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); | |
| 450 | - | |
| 451 | - if ( ! $id ) { | |
| 452 | - $id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' ); | |
| 453 | - } | |
| 454 | - } | |
| 455 | - | |
| 456 | - $entry = FrmEntry::getOne( $id, true ); | |
| 457 | - if ( ! $entry ) { | |
| 458 | - echo '<div id="form_show_entry_page" class="wrap">' . | |
| 459 | - esc_html__( 'You are trying to view an entry that does not exist.', 'formidable' ) . | |
| 460 | - '</div>'; | |
| 461 | - | |
| 462 | - return; | |
| 463 | - } | |
| 464 | - | |
| 465 | - $data = $entry->description; | |
| 466 | - if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { | |
| 467 | - $data = array( 'referrer' => $data ); | |
| 468 | - } | |
| 469 | - | |
| 470 | - $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' ); | |
| 471 | - $form = FrmForm::getOne( $entry->form_id ); | |
| 472 | - | |
| 473 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' ); | |
| 474 | - } | |
| 475 | - | |
| 476 | - /** | |
| 477 | - * Destroy an entry from the admin page. | |
| 478 | - * This is triggered from the entries list from the "Delete" row action, and also from the "Delete Entry" trigger in the view/edit entry sidebar. | |
| 479 | - * | |
| 480 | - * @return void | |
| 481 | - */ | |
| 482 | - public static function destroy() { | |
| 483 | - $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 ); | |
| 484 | - if ( false !== $permission_error ) { | |
| 485 | - wp_die( esc_html( $permission_error ) ); | |
| 486 | - } | |
| 487 | - | |
| 488 | - $params = FrmForm::get_admin_params(); | |
| 489 | - | |
| 490 | - if ( isset( $params['keep_post'] ) && $params['keep_post'] ) { | |
| 491 | - self::unlink_post( $params['id'] ); | |
| 492 | - } | |
| 493 | - | |
| 494 | - $message = ''; | |
| 495 | - if ( FrmEntry::destroy( $params['id'] ) ) { | |
| 496 | - $message = __( 'Entry was successfully deleted', 'formidable' ); | |
| 497 | - } | |
| 498 | - | |
| 499 | - self::display_list( $message ); | |
| 500 | - } | |
| 501 | - | |
| 502 | - /** | |
| 503 | - * @deprecated 4.02.04 - Moved to Pro since it was unused in Lite. | |
| 504 | - */ | |
| 505 | - public static function destroy_all() { | |
| 506 | - _deprecated_function( __METHOD__, '4.02.04', 'FrmProEntriesController::destroy_all' ); | |
| 507 | - if ( is_callable( 'FrmProEntriesController::destroy_all' ) ) { | |
| 508 | - FrmProEntriesController::destroy_all(); | |
| 509 | - } | |
| 510 | - } | |
| 511 | - | |
| 512 | - public static function process_entry( $errors = '', $ajax = false ) { | |
| 513 | - $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); | |
| 514 | - if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 515 | - return; | |
| 516 | - } | |
| 517 | - | |
| 518 | - global $frm_vars; | |
| 519 | - | |
| 520 | - $form = FrmForm::getOne( $form_id ); | |
| 521 | - if ( ! $form ) { | |
| 522 | - return; | |
| 523 | - } | |
| 524 | - | |
| 525 | - $params = FrmForm::get_params( $form ); | |
| 526 | - | |
| 527 | - if ( ! isset( $frm_vars['form_params'] ) ) { | |
| 528 | - $frm_vars['form_params'] = array(); | |
| 529 | - } | |
| 530 | - $frm_vars['form_params'][ $form->id ] = $params; | |
| 531 | - | |
| 532 | - if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) { | |
| 533 | - return; | |
| 534 | - } | |
| 535 | - | |
| 536 | - if ( $errors == '' && ! $ajax ) { | |
| 537 | - $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 538 | - } | |
| 539 | - | |
| 540 | - /** | |
| 541 | - * Use this filter to add trigger actions and add errors after | |
| 542 | - * all other errors have been processed | |
| 543 | - * | |
| 544 | - * @since 2.0.6 | |
| 545 | - */ | |
| 546 | - $errors = apply_filters( 'frm_entries_before_create', $errors, $form ); | |
| 547 | - | |
| 548 | - $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors ); | |
| 549 | - | |
| 550 | - if ( empty( $errors ) ) { | |
| 551 | - $_POST['frm_skip_cookie'] = 1; | |
| 552 | - $do_success = false; | |
| 553 | - if ( $params['action'] === 'create' ) { | |
| 554 | - if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { | |
| 555 | - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 556 | - | |
| 557 | - $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id']; | |
| 558 | - $do_success = true; | |
| 559 | - } | |
| 560 | - } | |
| 561 | - | |
| 562 | - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); | |
| 563 | - if ( $do_success ) { | |
| 564 | - FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) ); | |
| 565 | - } | |
| 566 | - unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 567 | - } | |
| 568 | - } | |
| 569 | - | |
| 570 | - /** | |
| 571 | - * Escape url entities before redirect | |
| 572 | - * | |
| 573 | - * @since 3.0 | |
| 574 | - * | |
| 575 | - * @param string $url | |
| 576 | - * | |
| 577 | - * @return string | |
| 578 | - */ | |
| 579 | - public static function prepare_redirect_url( $url ) { | |
| 580 | - return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url ); | |
| 581 | - } | |
| 582 | - | |
| 583 | - public static function delete_entry_before_redirect( $url, $form, $atts ) { | |
| 584 | - self::_delete_entry( $atts['id'], $form ); | |
| 585 | - | |
| 586 | - return $url; | |
| 587 | - } | |
| 588 | - | |
| 589 | - /** | |
| 590 | - * Delete entry if not redirected. | |
| 591 | - * | |
| 592 | - * @param array $atts | |
| 593 | - */ | |
| 594 | - public static function delete_entry_after_save( $atts ) { | |
| 595 | - self::_delete_entry( $atts['entry_id'], $atts['form'] ); | |
| 596 | - } | |
| 597 | - | |
| 598 | - private static function _delete_entry( $entry_id, $form ) { | |
| 599 | - if ( ! $form ) { | |
| 600 | - return; | |
| 601 | - } | |
| 602 | - | |
| 603 | - FrmAppHelper::unserialize_or_decode( $form->options ); | |
| 604 | - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { | |
| 605 | - self::unlink_post( $entry_id ); | |
| 606 | - FrmEntry::destroy( $entry_id ); | |
| 607 | - } | |
| 608 | - } | |
| 609 | - | |
| 610 | - /** | |
| 611 | - * Unlink entry from post | |
| 612 | - */ | |
| 613 | - private static function unlink_post( $entry_id ) { | |
| 614 | - global $wpdb; | |
| 615 | - $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $entry_id ) ); | |
| 616 | - FrmEntry::clear_cache(); | |
| 617 | - } | |
| 618 | - | |
| 619 | - /** | |
| 620 | - * @param $atts | |
| 621 | - * | |
| 622 | - * @return array|string | |
| 623 | - */ | |
| 624 | - public static function show_entry_shortcode( $atts ) { | |
| 625 | - $defaults = array( | |
| 626 | - 'id' => false, | |
| 627 | - 'entry' => false, | |
| 628 | - 'fields' => false, | |
| 629 | - 'plain_text' => false, | |
| 630 | - 'user_info' => false, | |
| 631 | - 'include_blank' => false, | |
| 632 | - 'default_email' => false, | |
| 633 | - 'form_id' => false, | |
| 634 | - 'format' => 'text', | |
| 635 | - 'array_key' => 'key', | |
| 636 | - 'direction' => 'ltr', | |
| 637 | - 'font_size' => '', | |
| 638 | - 'text_color' => '', | |
| 639 | - 'border_width' => '', | |
| 640 | - 'border_color' => '', | |
| 641 | - 'bg_color' => '', | |
| 642 | - 'alt_bg_color' => '', | |
| 643 | - 'class' => '', | |
| 644 | - 'clickable' => false, | |
| 645 | - 'exclude_fields' => '', | |
| 646 | - 'include_fields' => '', | |
| 647 | - 'include_extras' => '', | |
| 648 | - 'inline_style' => 1, | |
| 649 | - 'child_array' => false, // return embedded fields as nested array | |
| 650 | - 'line_breaks' => true, | |
| 651 | - 'array_separator' => ', ', | |
| 652 | - ); | |
| 653 | - $defaults = apply_filters( 'frm_show_entry_defaults', $defaults ); | |
| 654 | - | |
| 655 | - $atts = shortcode_atts( $defaults, $atts ); | |
| 656 | - | |
| 657 | - if ( $atts['default_email'] ) { | |
| 658 | - $shortcode_atts = array( | |
| 659 | - 'format' => $atts['format'], | |
| 660 | - 'plain_text' => $atts['plain_text'], | |
| 661 | - ); | |
| 662 | - | |
| 663 | - $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts ); | |
| 664 | - $formatted_entry = $entry_formatter->content(); | |
| 665 | - | |
| 666 | - } else { | |
| 667 | - | |
| 668 | - $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts ); | |
| 669 | - $formatted_entry = $entry_formatter->get_formatted_entry_values(); | |
| 670 | - | |
| 671 | - } | |
| 672 | - | |
| 673 | - return $formatted_entry; | |
| 674 | - } | |
| 675 | - | |
| 676 | - public static function entry_sidebar( $entry = false ) { | |
| 677 | - $data = array(); | |
| 678 | - $id = 0; | |
| 679 | - | |
| 680 | - $date_format = get_option( 'date_format' ); | |
| 681 | - $time_format = get_option( 'time_format' ); | |
| 682 | - | |
| 683 | - if ( $entry ) { | |
| 684 | - $id = $entry->id; | |
| 685 | - $data = $entry->description; | |
| 686 | - if ( isset( $data['browser'] ) ) { | |
| 687 | - $browser = FrmEntriesHelper::get_browser( $data['browser'] ); | |
| 688 | - } | |
| 689 | - /** | |
| 690 | - * Add or remove information in the entry sidebar. | |
| 691 | - * | |
| 692 | - * @since 5.5.2 | |
| 693 | - * @param array $data | |
| 694 | - */ | |
| 695 | - $data = apply_filters( 'frm_sidebar_data', $data, compact( 'entry' ) ); | |
| 696 | - } | |
| 697 | - | |
| 698 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' ); | |
| 699 | - } | |
| 700 | - | |
| 701 | - /** | |
| 702 | - * @deprecated 4.0 | |
| 703 | - */ | |
| 704 | - public static function contextual_help( $help, $screen_id, $screen ) { | |
| 705 | - _deprecated_function( __METHOD__, '4.0' ); | |
| 706 | - return $help; | |
| 707 | - } | |
| 437 | + return $values; | |
| 438 | + } | |
| 439 | + | |
| 708 | 440 | } |