コード例 #1
0
 function prepare_items()
 {
     global $frmdb, $wpdb, $per_page, $frm_settings;
     $paged = $this->get_pagenum();
     $default_orderby = 'name';
     $default_order = 'ASC';
     if ($this->plural == 'entries') {
         $default_orderby = 'id';
         $default_order = 'DESC';
     }
     $orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : $default_orderby;
     $order = isset($_REQUEST['order']) ? $_REQUEST['order'] : $default_order;
     $page = $this->get_pagenum();
     $per_page = $this->get_items_per_page('formidable_page_formidable_' . str_replace('-', '_', $this->page_name) . '_per_page');
     $start = isset($_REQUEST['start']) ? $_REQUEST['start'] : ($page - 1) * $per_page;
     $s = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : '';
     $fid = isset($_REQUEST['fid']) ? $_REQUEST['fid'] : '';
     if ($s != '') {
         preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
         $search_terms = array_map('trim', $matches[0]);
     }
     $s_query = '';
     if ($this->plural == 'entries') {
         global $frm_entry;
         $form_id = $this->params['form'];
         $s_query = 'it.form_id=' . (int) $form_id;
         if ($s != '') {
             $s_query = FrmProEntriesController::get_search_str($s_query, $s, $form_id, $fid);
         }
         $this->items = $frm_entry->getAll($s_query, " ORDER BY {$orderby} {$order}", " LIMIT {$start}, {$per_page}", true, false);
         $total_items = $frm_entry->getRecordCount($s_query);
     }
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page));
 }
コード例 #2
0
 function allow_submit_with_cookie($entry_id)
 {
     $form = $this->form;
     FrmProEntriesController::set_cookie($entry_id, $form->id);
     $this->assertTrue(isset($_COOKIE['frm_form' . $form->id . '_' . COOKIEHASH]), 'The cookie was not created');
     $this->assertFalse(FrmProFormsHelper::user_can_submit_form($form));
 }
コード例 #3
0
 public static function export_csv($atts)
 {
     $form_ids = $atts['ids'];
     if (empty($form_ids)) {
         wp_die(__('Please select a form', 'formidable'));
     }
     FrmProEntriesController::csv(reset($form_ids));
 }
コード例 #4
0
ファイル: FrmProEntry.php プロジェクト: swc-dng/swcsandbox
 public static function validate($params, $fields, $form, $title, $description)
 {
     global $frm_vars;
     $frm_settings = FrmAppHelper::get_settings();
     if (($_POST && isset($_POST['frm_page_order_' . $form->id]) || FrmProFormsHelper::going_to_prev($form->id)) && !FrmProFormsHelper::saving_draft()) {
         $errors = '';
         $fields = FrmFieldsHelper::get_form_fields($form->id);
         $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
         $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
         require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
         add_filter('frm_continue_to_create', '__return_false');
     } else {
         if ($form->editable && isset($form->options['single_entry']) && $form->options['single_entry'] && $form->options['single_entry_type'] == 'user') {
             $user_ID = get_current_user_id();
             if ($user_ID) {
                 $entry = FrmEntry::getAll(array('it.user_id' => $user_ID, 'it.form_id' => $form->id), '', 1, true);
                 if ($entry) {
                     $entry = reset($entry);
                 }
             } else {
                 $entry = false;
             }
             if ($entry && !empty($entry) && (!isset($frm_vars['created_entries'][$form->id]) || !isset($frm_vars['created_entries'][$form->id]['entry_id']) || $entry->id != $frm_vars['created_entries'][$form->id]['entry_id'])) {
                 FrmProEntriesController::show_responses($entry, $fields, $form, $title, $description);
             } else {
                 $record = $frm_vars['created_entries'][$form->id]['entry_id'];
                 $saved_message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
                 if (FrmProFormsHelper::saving_draft()) {
                     $saved_message = isset($form->options['draft_msg']) ? $form->options['draft_msg'] : __('Your draft has been saved.', 'formidable');
                 }
                 $saved_message = apply_filters('frm_content', $saved_message, $form, $record ? $record : false);
                 $message = wpautop(do_shortcode($record ? $saved_message : $frm_settings->failed_msg));
                 $message = '<div class="frm_message" id="message">' . $message . '</div>';
                 FrmProEntriesController::show_responses($record, $fields, $form, $title, $description, $message);
             }
             add_filter('frm_continue_to_create', '__return_false');
         } else {
             if (FrmProFormsHelper::saving_draft()) {
                 $record = isset($frm_vars['created_entries']) && isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['entry_id'] : 0;
                 if (!$record) {
                     return;
                 }
                 $saved_message = '';
                 FrmProFormsHelper::save_draft_msg($saved_message, $form, $record);
                 $message = FrmFormsHelper::get_success_message(array('message' => $saved_message, 'form' => $form, 'entry_id' => $record, 'class' => 'frm_message'));
                 FrmProEntriesController::show_responses($record, $fields, $form, $title, $description, $message);
                 add_filter('frm_continue_to_create', '__return_false');
             }
         }
     }
 }
コード例 #5
0
ファイル: FrmFormsHelper.php プロジェクト: moscarar/cityhow
 function replace_shortcodes($html, $form, $title = false, $description = false)
 {
     foreach (array('form_name' => $title, 'form_description' => $description, 'entry_key' => true) as $code => $show) {
         if ($code == 'form_name') {
             $replace_with = stripslashes($form->name);
         } else {
             if ($code == 'form_description') {
                 if (apply_filters('frm_use_wpautop', true)) {
                     $replace_with = wpautop(stripslashes($form->description));
                 } else {
                     $replace_with = stripslashes($form->description);
                 }
             } else {
                 if ($code == 'entry_key' and isset($_GET) and isset($_GET['entry'])) {
                     $replace_with = $_GET['entry'];
                 }
             }
         }
         if (($show == true || $show == 'true') && $replace_with != '') {
             $html = str_replace('[if ' . $code . ']', '', $html);
             $html = str_replace('[/if ' . $code . ']', '', $html);
         } else {
             $html = preg_replace('/(\\[if\\s+' . $code . '\\])(.*?)(\\[\\/if\\s+' . $code . '\\])/mis', '', $html);
         }
         $html = str_replace('[' . $code . ']', $replace_with, $html);
     }
     //replace [form_key]
     $html = str_replace('[form_key]', $form->form_key, $html);
     if (class_exists('FrmProEntriesController')) {
         $html = str_replace('[deletelink]', FrmProEntriesController::entry_delete_link(array()), $html);
     }
     return apply_filters('frm_form_replace_shortcodes', stripslashes($html), $form);
 }
コード例 #6
0
 public static function do_shortcode_deletelink(&$content, $atts, $shortcodes, $short_key, $args)
 {
     global $post;
     $page_id = isset($atts['page_id']) ? $atts['page_id'] : ($post ? $post->ID : 0);
     if (!isset($atts['label'])) {
         $atts['label'] = false;
     }
     $delete_atts = $atts;
     $delete_atts['id'] = $args['entry']->id;
     $delete_atts['page_id'] = $page_id;
     $replace_with = FrmProEntriesController::entry_delete_link($delete_atts);
     $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
 }
コード例 #7
0
 public static function replace_shortcodes($content, $entry, $shortcodes, $display = false, $show = 'one', $odd = '', $args = array())
 {
     global $frm_field, $frm_entry_meta, $post, $frmpro_settings;
     if ($display) {
         $param_value = $display->frm_type == 'id' ? $entry->id : $entry->item_key;
         if ($entry->post_id) {
             $detail_link = get_permalink($entry->post_id);
         } else {
             $param = isset($display->frm_param) && !empty($display->frm_param) ? $display->frm_param : 'entry';
             if ($post) {
                 $detail_link = add_query_arg($param, $param_value, get_permalink($post->ID));
             } else {
                 $detail_link = add_query_arg($param, $param_value);
             }
             //if( FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks )
             //    $detail_link = get_permalink($post->ID) .$param_value .'/';
         }
     }
     foreach ($shortcodes[0] as $short_key => $tag) {
         $conditional = preg_match('/^\\[if/s', $shortcodes[0][$short_key]) ? true : false;
         $atts = shortcode_parse_atts($shortcodes[3][$short_key]);
         if (!empty($shortcodes[3][$short_key])) {
             $tag = str_replace($conditional ? '[if ' : '[', '', $shortcodes[0][$short_key]);
             $tag = str_replace(']', '', $tag);
             $tags = explode(' ', $tag);
             if (is_array($tags)) {
                 $tag = $tags[0];
             }
         } else {
             $tag = $shortcodes[2][$short_key];
         }
         switch ($tag) {
             case 'entry_count':
                 $content = str_replace($shortcodes[0][$short_key], isset($args['record_count']) ? $args['record_count'] : '', $content);
                 break;
             case 'detaillink':
                 if ($display and $detail_link) {
                     $content = str_replace($shortcodes[0][$short_key], $detail_link, $content);
                 }
                 break;
             case 'id':
                 $content = str_replace($shortcodes[0][$short_key], $entry->id, $content);
                 break;
             case 'post-id':
             case 'post_id':
                 $content = str_replace($shortcodes[0][$short_key], $entry->post_id, $content);
                 break;
             case 'key':
                 $content = str_replace($shortcodes[0][$short_key], $entry->item_key, $content);
                 break;
             case 'ip':
                 $content = str_replace($shortcodes[0][$short_key], $entry->ip, $content);
                 break;
             case 'user_agent':
             case 'user-agent':
                 $entry->description = maybe_unserialize($entry->description);
                 $content = str_replace($shortcodes[0][$short_key], $entry->description['browser'], $content);
                 break;
             case 'created_at':
             case 'created-at':
             case 'updated_at':
             case 'updated-at':
                 if (!isset($atts['format'])) {
                     $atts['format'] = get_option('date_format');
                     $time_format = false;
                 } else {
                     $time_format = ' ';
                 }
                 $this_tag = str_replace('-', '_', $tag);
                 if ($conditional) {
                     $atts['short_key'] = $shortcodes[0][$short_key];
                     $content = self::check_conditional_shortcode($content, $entry->{$this_tag}, $atts, $tag);
                 } else {
                     if (isset($atts['time_ago'])) {
                         $date = FrmProAppHelper::human_time_diff(strtotime($entry->{$this_tag}));
                     } else {
                         $date = FrmProAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format);
                     }
                     $content = str_replace($shortcodes[0][$short_key], $date, $content);
                 }
                 unset($this_tag);
                 break;
             case 'created_by':
             case 'created-by':
             case 'updated_by':
             case 'updated-by':
                 $this_tag = str_replace('-', '_', $tag);
                 $replace_with = self::get_display_value($entry->{$this_tag}, (object) array('type' => 'user_id'), $atts);
                 if ($conditional) {
                     $atts['short_key'] = $shortcodes[0][$short_key];
                     $content = self::check_conditional_shortcode($content, $entry->{$this_tag}, $atts, $tag);
                 } else {
                     $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
                 }
                 unset($this_tag);
                 unset($replace_with);
                 break;
             case 'evenodd':
                 $content = str_replace($shortcodes[0][$short_key], $odd, $content);
                 break;
             case 'siteurl':
                 $content = str_replace($shortcodes[0][$short_key], FrmAppHelper::site_url(), $content);
                 break;
             case 'frmurl':
                 $content = str_replace($shortcodes[0][$short_key], FrmAppHelper::plugin_url(), $content);
                 break;
             case 'sitename':
                 $content = str_replace($shortcodes[0][$short_key], get_option('blogname'), $content);
                 break;
             case 'get':
                 if (isset($atts['param'])) {
                     $param = $atts['param'];
                     $replace_with = FrmAppHelper::get_param($param);
                     if (is_array($replace_with)) {
                         $replace_with = implode(', ', $replace_with);
                     }
                     $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
                     unset($param);
                     unset($replace_with);
                 }
                 break;
             default:
                 if ($tag == 'deletelink') {
                     $page_id = isset($atts['page_id']) ? $atts['page_id'] : ($post ? $post->ID : 0);
                     if (!isset($atts['label'])) {
                         $atts['label'] = false;
                     }
                     $delete_atts = $atts;
                     $delete_atts['id'] = $entry->id;
                     $delete_atts['page_id'] = $page_id;
                     $replace_with = FrmProEntriesController::entry_delete_link($delete_atts);
                     unset($delete_atts);
                     $field = false;
                 } else {
                     if ($tag == 'editlink') {
                         $replace_with = '';
                         $link_text = isset($atts['label']) ? $atts['label'] : false;
                         if (!$link_text) {
                             $link_text = isset($atts['link_text']) ? $atts['link_text'] : __('Edit');
                         }
                         $class = isset($atts['class']) ? $atts['class'] : '';
                         $page_id = isset($atts['page_id']) ? $atts['page_id'] : ($post ? $post->ID : 0);
                         if (isset($atts['location']) && $atts['location'] == 'front' || isset($atts['prefix']) && !empty($atts['prefix']) || isset($atts['page_id']) && !empty($atts['page_id'])) {
                             $edit_atts = $atts;
                             $edit_atts['id'] = $entry->id;
                             $delete_atts['page_id'] = $page_id;
                             $replace_with = FrmProEntriesController::entry_edit_link($edit_atts);
                         } else {
                             if ($entry->post_id) {
                                 $replace_with = get_edit_post_link($entry->post_id);
                             } else {
                                 if (current_user_can('frm_edit_entries')) {
                                     $replace_with = esc_url(admin_url('admin.php?page=formidable-entries&frm_action=edit&id=' . $entry->id));
                                 }
                             }
                             if (!empty($replace_with)) {
                                 $replace_with = '<a href="' . $replace_with . '" class="frm_edit_link ' . $class . '">' . $link_text . '</a>';
                             }
                         }
                         unset($class);
                     } else {
                         $field = $frm_field->getOne($tag);
                     }
                 }
                 $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
                 if (!isset($field)) {
                     $field = false;
                 }
                 if ($field) {
                     $replace_with = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, $atts);
                     $atts['entry_id'] = $entry->id;
                     $atts['entry_key'] = $entry->item_key;
                     $atts['post_id'] = $entry->post_id;
                     $replace_with = apply_filters('frmpro_fields_replace_shortcodes', $replace_with, $tag, $atts, $field);
                 }
                 if ($field and $field->type == 'file') {
                     //size options are thumbnail, medium, large, or full, label
                     $size = isset($atts['size']) ? $atts['size'] : (isset($atts['show']) ? $atts['show'] : 'thumbnail');
                     $inc_html = (isset($atts['html']) and $atts['html']) ? true : false;
                     $inc_links = (isset($atts['links']) and $atts['links']) ? true : false;
                     $sep = isset($atts['sep']) ? $atts['sep'] : ' ';
                     $show_filename = (isset($atts['show_filename']) and $atts['show_filename']) ? true : false;
                     if ($size != 'id' && !empty($replace_with)) {
                         $replace_with = FrmProFieldsHelper::get_media_from_id($replace_with, $size, array('html' => $inc_html, 'links' => $inc_links, 'show_filename' => $show_filename));
                     } else {
                         if (is_array($replace_with)) {
                             $replace_with = array_filter($replace_with);
                         }
                     }
                     unset($size);
                 }
                 if (isset($replace_with) and is_array($replace_with)) {
                     $replace_with = implode($sep, $replace_with);
                 }
                 if ($conditional) {
                     if (!isset($replace_with)) {
                         $replace_with = '';
                     }
                     $replace_with = apply_filters('frm_conditional_value', $replace_with, $atts, $field, $tag);
                     $start_pos = strpos($content, $shortcodes[0][$short_key]);
                     if ($start_pos !== false) {
                         $start_pos_len = strlen($shortcodes[0][$short_key]);
                         $end_pos = strpos($content, '[/if ' . $tag . ']', $start_pos);
                         $end_pos_len = strlen('[/if ' . $tag . ']');
                         if ($end_pos !== false) {
                             if (empty($replace_with)) {
                                 $total_len = $end_pos + $end_pos_len - $start_pos;
                                 $content = substr_replace($content, '', $start_pos, $total_len);
                             } else {
                                 $content = substr_replace($content, '', $end_pos, $end_pos_len);
                                 $content = substr_replace($content, '', $start_pos, $start_pos_len);
                             }
                         }
                     }
                 } else {
                     if ($field) {
                         if (isset($atts['show']) and $atts['show'] == 'field_label') {
                             $replace_with = $field->name;
                         } else {
                             if (isset($atts['show']) and $atts['show'] == 'description') {
                                 $replace_with = $field->description;
                             } else {
                                 if (empty($replace_with) and $replace_with != '0') {
                                     $replace_with = '';
                                     if ($field->type == 'number') {
                                         $replace_with = '0';
                                     }
                                 } else {
                                     $replace_with = FrmProFieldsHelper::get_display_value($replace_with, $field, $atts);
                                 }
                             }
                         }
                     }
                     if (isset($atts['sanitize'])) {
                         $replace_with = sanitize_title_with_dashes($replace_with);
                     }
                     if (isset($atts['sanitize_url'])) {
                         if (seems_utf8($replace_with)) {
                             $replace_with = utf8_uri_encode($replace_with, 200);
                         }
                         $replace_with = urlencode(htmlentities($replace_with));
                     }
                     if (isset($atts['truncate'])) {
                         if (isset($atts['more_text'])) {
                             $more_link_text = $atts['more_text'];
                         } else {
                             $more_link_text = isset($atts['more_link_text']) ? $atts['more_link_text'] : '. . .';
                         }
                         if ($display and $display->frm_show_count == 'dynamic') {
                             $more_link_text = ' <a href="' . $detail_link . '">' . $more_link_text . '</a>';
                             $replace_with = FrmAppHelper::truncate($replace_with, (int) $atts['truncate'], 3, $more_link_text);
                         } else {
                             $replace_with = wp_specialchars_decode(strip_tags($replace_with), ENT_QUOTES);
                             $part_one = substr($replace_with, 0, (int) $atts['truncate']);
                             $part_two = substr($replace_with, (int) $atts['truncate']);
                             if (!empty($part_two)) {
                                 $replace_with = $part_one . '<a href="#" onclick="jQuery(this).next().css(\'display\', \'inline\');jQuery(this).css(\'display\', \'none\');return false;" class="frm_text_exposed_show"> ' . $more_link_text . '</a><span style="display:none;">' . $part_two . '</span>';
                             }
                         }
                     }
                     if (isset($atts['clickable'])) {
                         $replace_with = make_clickable($replace_with);
                     }
                     if (!isset($replace_with)) {
                         $replace_with = '';
                     }
                     $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
                 }
                 unset($replace_with);
                 if (isset($field)) {
                     unset($field);
                 }
         }
         unset($atts);
         unset($conditional);
     }
     return $content;
 }
コード例 #8
0
ファイル: FrmProEntry.php プロジェクト: amit0773/manaslake
 public function check_draft_status($values, $id)
 {
     _deprecated_function(__FUNCTION__, '1.07.05', 'FrmProEntriesController::check_draft_status');
     return FrmProEntriesController::check_draft_status($values, $id);
 }
コード例 #9
0
 public static function preview()
 {
     do_action('frm_wp');
     global $frm_settings, $frm_vars;
     $frm_vars['preview'] = true;
     $frm_form = new FrmForm();
     if (!defined('ABSPATH') && !defined('XMLRPC_REQUEST')) {
         global $wp;
         $root = dirname(dirname(dirname(dirname(__FILE__))));
         include_once $root . '/wp-config.php';
         $wp->init();
         $wp->register_globals();
     }
     if ($frm_vars['pro_is_installed']) {
         FrmProEntriesController::register_scripts();
     }
     header("Content-Type: text/html; charset=" . get_option('blog_charset'));
     $plugin = FrmAppHelper::get_param('plugin');
     $controller = FrmAppHelper::get_param('controller');
     $key = isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : '');
     $form = $frm_form->getAll(array('form_key' => $key), '', 1);
     if (!$form) {
         $form = $frm_form->getAll('', '', 1);
     }
     require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php';
     die;
 }
コード例 #10
0
 /**
  * Get displayed values for separate values, data from entries, and other option.
  * Capitalizes first letter of each option
  *
  * @since 2.0
  *
  * @param array $temp_values
  * @param object $field
  */
 public static function get_displayed_values(&$temp_values, $field)
 {
     $temp_array = array();
     // If data from entries field
     if ($field->type == 'data') {
         // Get DFE text
         foreach ($temp_values as $entry_id => $total) {
             $linked_field = $field->field_options['form_select'];
             $text_val = FrmProEntriesController::get_field_value_shortcode(array('field_id' => $linked_field, 'entry_id' => $entry_id));
             $temp_array[$text_val] = $total;
             unset($entry_id, $total, $linked_field, $text_val);
         }
     } else {
         $other_label = false;
         foreach ($field->options as $opt_key => $opt) {
             if (!$opt) {
                 continue;
             }
             // If field option is "other" option
             if (FrmFieldsHelper::is_other_opt($opt_key)) {
                 // For radio button field, combine all extra counts/totals into one "Other" count/total
                 if ($field->type == 'radio' || $field->type == 'select') {
                     $other_label = strtolower($opt);
                     continue;
                     // For checkbox fields, set value and label
                 } else {
                     $opt_value = strtolower($opt_key);
                     $opt_label = strtolower($opt);
                 }
                 // If using separate values
             } else {
                 if (is_array($opt)) {
                     $opt_label = strtolower($opt['label']);
                     $opt_value = strtolower($opt['value']);
                     if (!$opt_value || !$opt_label) {
                         continue;
                     }
                 } else {
                     $opt_label = $opt_value = strtolower($opt);
                 }
             }
             // Set displayed value total in new array, unset original value in old array
             if (isset($temp_values[$opt_value])) {
                 $temp_array[$opt_label] = $temp_values[$opt_value];
                 unset($temp_values[$opt_value]);
             }
             unset($opt_key, $opt, $opt_label, $opt_value);
         }
         // Applies to radio buttons only (with other option)
         // Combines all extra counts/totals into one "Other" count/total
         if ($other_label) {
             $temp_array[$other_label] = array_sum($temp_values);
         }
     }
     // Copy new array
     $temp_values = $temp_array;
 }
コード例 #11
0
 public static function get_display_data($display, $content = '', $entry_id = false, $extra_atts = array())
 {
     global $frmpro_display, $frm_entry, $frmpro_settings, $frm_entry_meta, $frm_vars, $post;
     $frm_vars['forms_loaded'][] = true;
     if (!isset($display->frm_form_id)) {
         $display = FrmProDisplaysHelper::setup_edit_vars($display, false);
     }
     if (!isset($display->frm_form_id) or empty($display->frm_form_id)) {
         return $content;
     }
     // check if entry needs to be deleted before loading entries
     if (FrmAppHelper::get_param('frm_action') == 'destroy' && isset($_GET['entry'])) {
         $deleted = FrmProEntriesController::ajax_destroy($display->frm_form_id, false, false);
         if (!empty($deleted)) {
             $message = '<div class="with_frm_style"><div class="frm_message">' . $deleted . '</div></div>';
         }
         unset($_GET['entry']);
     }
     //for backwards compatability
     $display->id = $display->frm_old_id;
     $display->display_key = $display->post_name;
     $defaults = array('filter' => false, 'user_id' => '', 'limit' => '', 'page_size' => '', 'order_by' => '', 'order' => '', 'drafts' => false, 'auto_id' => '');
     extract(wp_parse_args($extra_atts, $defaults));
     //if (FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks )
     //    self::parse_pretty_entry_url();
     if ($display->frm_show_count == 'one' and is_numeric($display->frm_entry_id) and $display->frm_entry_id > 0 and !$entry_id) {
         $entry_id = $display->frm_entry_id;
     }
     $entry = false;
     $show = 'all';
     global $wpdb, $frmpro_entry;
     $where = $wpdb->prepare('it.form_id=%d', $display->frm_form_id);
     if (in_array($display->frm_show_count, array('dynamic', 'calendar', 'one'))) {
         $one_param = isset($_GET['entry']) ? $_GET['entry'] : $auto_id;
         $get_param = isset($_GET[$display->frm_param]) ? $_GET[$display->frm_param] : ($display->frm_show_count == 'one' ? $one_param : $auto_id);
         unset($one_param);
         if ($get_param) {
             if (($display->frm_type == 'id' or $display->frm_show_count == 'one') and is_numeric($get_param)) {
                 $where .= $wpdb->prepare(' AND it.id=%d', $get_param);
             } else {
                 $where .= $wpdb->prepare(' AND it.item_key=%s', $get_param);
             }
             $entry = $frm_entry->getAll($where, '', 1, 0);
             if ($entry) {
                 $entry = reset($entry);
             }
             if ($entry and $entry->post_id) {
                 //redirect to single post page if this entry is a post
                 if (in_the_loop() and $display->frm_show_count != 'one' and !is_single($entry->post_id) and $post->ID != $entry->post_id) {
                     $this_post = get_post($entry->post_id);
                     if (in_array($this_post->post_status, array('publish', 'private'))) {
                         die(FrmAppHelper::js_redirect(get_permalink($entry->post_id)));
                     }
                 }
             }
         }
         unset($get_param);
     }
     if ($entry and in_array($display->frm_show_count, array('dynamic', 'calendar'))) {
         $new_content = $display->frm_dyncontent;
         $show = 'one';
     } else {
         $new_content = $display->post_content;
     }
     $show = $display->frm_show_count == 'one' ? 'one' : $show;
     $shortcodes = FrmProDisplaysHelper::get_shortcodes($new_content, $display->frm_form_id);
     //don't let page size and limit override single entry displays
     if ($display->frm_show_count == 'one') {
         $display->frm_page_size = $display->frm_limit = '';
     }
     //don't keep current content if post type is frm_display
     if ($post and $post->post_type == 'frm_display') {
         $display->frm_insert_loc = '';
     }
     $pagination = '';
     $is_draft = !empty($drafts) ? 1 : 0;
     $form_query = $wpdb->prepare("SELECT id, post_id FROM {$wpdb->prefix}frm_items WHERE form_id=%d and post_id>%d", $display->frm_form_id, 1);
     if ($drafts != 'both') {
         $form_query .= $wpdb->prepare(' AND is_draft=%d', $is_draft);
     }
     if ($entry and $entry->form_id == $display->frm_form_id) {
         $form_query .= $wpdb->prepare(' AND id=%d', $entry->id);
         $form_posts = $wpdb->get_results($form_query);
         $entry_ids = array($entry->id);
     } else {
         $form_posts = $wpdb->get_results($form_query);
         //Only get $entry_ids if filters are set or if frm_search parameter is set
         if (isset($display->frm_where) && !empty($display->frm_where) && (!$entry || !$post || empty($auto_id)) || isset($_GET['frm_search'])) {
             $entry_query = $wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $display->frm_form_id);
             if ($drafts != 'both') {
                 $entry_query .= $wpdb->prepare(" AND is_draft=%d", $is_draft);
             }
             $entry_ids = $wpdb->get_col($entry_query);
             unset($entry_query);
         }
     }
     unset($form_query);
     $empty_msg = (isset($display->frm_empty_msg) and !empty($display->frm_empty_msg)) ? '<div class="frm_no_entries">' . FrmProFieldsHelper::get_default_value($display->frm_empty_msg, false, true, true) . '</div>' : '';
     if (isset($message)) {
         // if an entry was deleted above, show a message
         $empty_msg = $message . $empty_msg;
     }
     $after_where = false;
     if ($user_id and !empty($user_id)) {
         $user_id = FrmProAppHelper::get_user_id_param($user_id);
         $uid_used = false;
     }
     if (isset($display->frm_where) && !empty($display->frm_where) && (!$entry || !$post || empty($auto_id))) {
         $display->frm_where = apply_filters('frm_custom_where_opt', $display->frm_where, array('display' => $display, 'entry' => $entry));
         $continue = false;
         foreach ($display->frm_where as $where_key => $where_opt) {
             $where_val = isset($display->frm_where_val[$where_key]) ? $display->frm_where_val[$where_key] : '';
             if (preg_match("/\\[(get|get-(.?))\\b(.*?)(?:(\\/))?\\]/s", $where_val)) {
                 $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
                 //if this param doesn't exist, then don't include it
                 if ($where_val == '') {
                     if (!$after_where) {
                         $continue = true;
                     }
                     continue;
                 }
             } else {
                 $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
             }
             $continue = false;
             if ($where_val == 'current_user') {
                 if ($user_id and is_numeric($user_id)) {
                     $where_val = $user_id;
                     $uid_used = true;
                 } else {
                     $where_val = get_current_user_id();
                 }
             }
             $where_val = do_shortcode($where_val);
             if (in_array($where_opt, array('id', 'item_key', 'post_id')) && !is_array($where_val) && strpos($where_val, ',')) {
                 $where_val = explode(',', $where_val);
             }
             if (is_array($where_val) and !empty($where_val)) {
                 $new_where = '(';
                 if (strpos($display->frm_where_is[$where_key], 'LIKE') !== false) {
                     foreach ($where_val as $w) {
                         if ($new_where != '(') {
                             $new_where .= ',';
                         }
                         $new_where .= $wpdb->prepare('%s', '%' . FrmAppHelper::esc_like($w) . '%');
                         unset($w);
                     }
                 } else {
                     foreach ($where_val as $w) {
                         if ($new_where != '(') {
                             $new_where .= ',';
                         }
                         $new_where .= $wpdb->prepare('%s', $w);
                         unset($w);
                     }
                 }
                 $new_where .= ')';
                 $where_val = $new_where;
                 unset($new_where);
                 if (strpos($display->frm_where_is[$where_key], '!') === false && strpos($display->frm_where_is[$where_key], 'not') === false) {
                     $display->frm_where_is[$where_key] = ' in ';
                 } else {
                     $display->frm_where_is[$where_key] = ' not in ';
                 }
             }
             if (is_numeric($where_opt)) {
                 $filter_opts = apply_filters('frm_display_filter_opt', array('where_opt' => $where_opt, 'where_is' => $display->frm_where_is[$where_key], 'where_val' => $where_val, 'form_id' => $display->frm_form_id, 'form_posts' => $form_posts, 'after_where' => $after_where, 'display' => $display, 'drafts' => $is_draft));
                 $entry_ids = FrmProAppHelper::filter_where($entry_ids, $filter_opts);
                 unset($filter_opts);
                 $after_where = true;
                 $continue = false;
                 if (empty($entry_ids)) {
                     break;
                 }
             } else {
                 if ($where_opt == 'created_at' or $where_opt == 'updated_at') {
                     if ($where_val == 'NOW') {
                         $where_val = current_time('mysql', 1);
                     }
                     if (strpos($display->frm_where_is[$where_key], 'LIKE') === false) {
                         $where_val = date('Y-m-d H:i:s', strtotime($where_val));
                     }
                     $where .= $wpdb->prepare(" and it.{$where_opt} " . $display->frm_where_is[$where_key] . "%s", '');
                     if (strpos($display->frm_where_is[$where_key], 'in')) {
                         $where .= " {$where_val}";
                     } else {
                         if (strpos($display->frm_where_is[$where_key], 'LIKE') !== false) {
                             $where .= $wpdb->prepare(" %s", '%' . FrmAppHelper::esc_like($where_val) . '%');
                         } else {
                             $where .= $wpdb->prepare(" %s", $where_val);
                         }
                     }
                     $continue = true;
                 } else {
                     if (in_array($where_opt, array('id', 'item_key', 'post_id'))) {
                         $where .= " and it.{$where_opt} " . $display->frm_where_is[$where_key];
                         if (strpos($display->frm_where_is[$where_key], 'in')) {
                             $where .= " {$where_val}";
                         } else {
                             $where .= $wpdb->prepare(" %s", $where_val);
                         }
                         $continue = true;
                     }
                 }
             }
         }
         if (!$continue and empty($entry_ids)) {
             if ($display->frm_insert_loc == 'after') {
                 $content .= $empty_msg;
             } else {
                 if ($display->frm_insert_loc == 'before') {
                     $content = $empty_msg . $content;
                 } else {
                     if ($filter) {
                         $empty_msg = apply_filters('the_content', $empty_msg);
                     }
                     if ($post->post_type == 'frm_display' and in_the_loop()) {
                         $content = '';
                     }
                     $content .= $empty_msg;
                 }
             }
             return $content;
         }
     }
     if ($user_id && is_numeric($user_id) && !$uid_used) {
         $where .= $wpdb->prepare(" AND it.user_id=%d", $user_id);
     }
     $s = FrmAppHelper::get_param('frm_search', false);
     if ($s) {
         $new_ids = FrmProEntriesHelper::get_search_ids($s, $display->frm_form_id);
         if ($after_where and isset($entry_ids) and !empty($entry_ids)) {
             $entry_ids = array_intersect($new_ids, $entry_ids);
         } else {
             $entry_ids = $new_ids;
         }
         if (empty($entry_ids)) {
             if ($post->post_type == 'frm_display' and in_the_loop()) {
                 $content = '';
             }
             return $content . ' ' . $empty_msg;
         }
     }
     if (isset($entry_ids) && !empty($entry_ids)) {
         $where .= ' and it.id in (' . implode(',', array_filter($entry_ids, 'is_numeric')) . ')';
     }
     if ($entry_id) {
         $entry_id_array = explode(',', $entry_id);
         //Get IDs (if there are any)
         $numeric_entry_ids = array_filter($entry_id_array, 'is_numeric');
         //If there are entry keys, use esc_sql
         if (empty($numeric_entry_ids)) {
             $entry_id_array = array_filter($entry_id_array, 'esc_sql');
         }
         $where .= !empty($numeric_entry_ids) ? " and it.id in ('" . implode("','", $numeric_entry_ids) . "')" : " and it.item_key in ('" . implode("','", $entry_id_array) . "')";
     }
     if ($drafts != 'both') {
         $where .= $wpdb->prepare(' AND is_draft=%d', $is_draft);
     }
     unset($is_draft);
     if ($show == 'one') {
         $limit = ' LIMIT 1';
     } else {
         if (isset($_GET['frm_cat']) and isset($_GET['frm_cat_id'])) {
             //Get fields with specified field value 'frm_cat' = field key/id, 'frm_cat_id' = order position of selected option
             global $frm_field;
             if ($cat_field = $frm_field->getOne($_GET['frm_cat'])) {
                 $categories = maybe_unserialize($cat_field->options);
                 if (isset($categories[$_GET['frm_cat_id']])) {
                     $cat_entry_ids = $frm_entry_meta->getEntryIds(array('meta_value' => $categories[$_GET['frm_cat_id']], 'fi.field_key' => $_GET['frm_cat']));
                     if ($cat_entry_ids) {
                         $where .= " and it.id in (" . implode(',', $cat_entry_ids) . ")";
                     } else {
                         $where .= " and it.id=0";
                     }
                 }
             }
         }
     }
     if (!empty($limit) and is_numeric($limit)) {
         $display->frm_limit = (int) $limit;
     }
     if (is_numeric($display->frm_limit)) {
         $num_limit = (int) $display->frm_limit;
         $limit = ' LIMIT ' . $display->frm_limit;
     }
     if (!empty($order_by)) {
         $display->frm_order_by = explode(',', $order_by);
         $order_by = '';
     }
     if (!empty($order)) {
         $display->frm_order = explode(',', $order);
     }
     unset($order);
     if (!empty($page_size) && is_numeric($page_size)) {
         $display->frm_page_size = (int) $page_size;
     }
     // if limit is lower than page size, ignore the page size
     if (isset($num_limit) && $display->frm_page_size > $num_limit) {
         $display->frm_page_size = '';
     }
     if (isset($display->frm_page_size) and is_numeric($display->frm_page_size)) {
         $page_param = ($_GET and isset($_GET['frm-page-' . $display->ID])) ? 'frm-page-' . $display->ID : 'frm-page';
         $current_page = (int) FrmAppHelper::get_param($page_param, 1);
         $record_where = $where == $wpdb->prepare('it.form_id=%d', $display->frm_form_id) ? $display->frm_form_id : $where;
         $record_count = $frm_entry->getRecordCount($record_where);
         if (isset($num_limit) and $record_count > (int) $num_limit) {
             $record_count = (int) $num_limit;
         }
         $page_count = $frm_entry->getPageCount($display->frm_page_size, $record_count);
         //Get a page of entries
         $entries = $frmpro_entry->get_view_page($current_page, $display->frm_page_size, $where, array('order_by_array' => $display->frm_order_by, 'order_array' => $display->frm_order, 'posts' => $form_posts));
         $page_last_record = FrmAppHelper::getLastRecordNum($record_count, $current_page, $display->frm_page_size);
         $page_first_record = FrmAppHelper::getFirstRecordNum($record_count, $current_page, $display->frm_page_size);
         if ($page_count > 1) {
             $page_param = 'frm-page-' . $display->ID;
             $pagination = FrmProDisplaysController::get_pagination_file(FrmAppHelper::plugin_path() . '/pro/classes/views/displays/pagination.php', compact('current_page', 'record_count', 'page_count', 'page_last_record', 'page_first_record', 'page_param'));
         }
     } else {
         //Get all entries
         $entries = $frmpro_entry->get_view_results($where, array('order_by_array' => $display->frm_order_by, 'order_array' => $display->frm_order, 'limit' => $limit, 'posts' => $form_posts));
     }
     $total_count = count($entries);
     $sc_atts = array();
     if (isset($record_count)) {
         $sc_atts['record_count'] = $record_count;
     } else {
         $sc_atts['record_count'] = $total_count;
     }
     $display_content = '';
     if (isset($message)) {
         // if an entry was deleted above, show a message
         $display_content .= $message;
     }
     if ($show == 'all') {
         $display_content .= isset($display->frm_before_content) ? $display->frm_before_content : '';
     }
     if (!isset($entry_ids) || empty($entry_ids)) {
         $entry_ids = array_keys($entries);
     }
     $display_content = apply_filters('frm_before_display_content', $display_content, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids));
     $filtered_content = apply_filters('frm_display_entries_content', $new_content, $entries, $shortcodes, $display, $show, $sc_atts);
     if ($filtered_content != $new_content) {
         $display_content .= $filtered_content;
     } else {
         $odd = 'odd';
         $count = 0;
         if (!empty($entries)) {
             foreach ($entries as $entry) {
                 $count++;
                 //TODO: use the count with conditionals
                 $display_content .= apply_filters('frm_display_entry_content', $new_content, $entry, $shortcodes, $display, $show, $odd, array('count' => $count, 'total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'pagination' => $pagination, 'entry_ids' => $entry_ids));
                 $odd = $odd == 'odd' ? 'even' : 'odd';
                 unset($entry);
             }
             unset($count);
         } else {
             if ($post->post_type == 'frm_display' and in_the_loop()) {
                 $display_content = '';
             }
             if (!isset($message) || FrmAppHelper::get_param('frm_action') != 'destroy') {
                 $display_content .= $empty_msg;
             }
         }
     }
     if (isset($message)) {
         unset($message);
     }
     if ($show == 'all') {
         $display_content .= isset($display->frm_after_content) ? apply_filters('frm_after_content', $display->frm_after_content, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids)) : '';
     }
     if (!isset($sc_atts)) {
         $sc_atts = array('record_count' => 0);
     }
     if (!isset($total_count)) {
         $total_count = 0;
     }
     $display_content .= apply_filters('frm_after_display_content', $pagination, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids));
     unset($sc_atts);
     $display_content = FrmProFieldsHelper::get_default_value($display_content, false, true, true);
     if ($display->frm_insert_loc == 'after') {
         $content .= $display_content;
     } else {
         if ($display->frm_insert_loc == 'before') {
             $content = $display_content . $content;
         } else {
             if ($filter) {
                 $display_content = apply_filters('the_content', $display_content);
             }
             $content = $display_content;
         }
     }
     return $content;
 }
コード例 #12
0
 function preview()
 {
     global $frm_form, $frm_settings, $frmpro_is_installed;
     if (!defined('ABSPATH') && !defined('XMLRPC_REQUEST')) {
         global $wp;
         $root = dirname(dirname(dirname(dirname(__FILE__))));
         include_once $root . '/wp-config.php';
         $wp->init();
         $wp->register_globals();
     }
     if ($frmpro_is_installed) {
         FrmProEntriesController::register_scripts();
     }
     header("Content-Type: text/html; charset=utf-8");
     $plugin = FrmAppHelper::get_param('plugin');
     $controller = FrmAppHelper::get_param('controller');
     $key = isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : '');
     $form = $frm_form->getAll(array('form_key' => $key), '', 1);
     if (!$form) {
         $form = $frm_form->getAll(array(), '', 1);
     }
     require FRM_VIEWS_PATH . '/frm-entries/direct.php';
 }
コード例 #13
0
 /**
  * @covers FrmProEntriesController::get_field_value_shortcode
  * TODO: Test with post fields, IP, and user_id parameters
  */
 function test_get_field_value_shortcode()
 {
     $tests = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
     $field_id = $this->factory->field->get_id_by_key('493ito');
     $entry_id = $this->factory->entry->get_id_by_key('jamie_entry_key');
     foreach ($tests as $test) {
         $sc_atts = self::_setup_frm_field_value_sc_atts($test, $field_id, $entry_id);
         $sc_atts_list = self::_get_sc_atts_list($sc_atts);
         $expected_result = self::_get_expected_frm_field_value($test);
         $value = FrmProEntriesController::get_field_value_shortcode($sc_atts);
         $this->assertEquals($expected_result, $value, 'The frm-field-value shortcode is not retrieving the correct value with the following parameters: ' . $sc_atts_list);
     }
 }
コード例 #14
0
ファイル: formidable-pro.php プロジェクト: amit0773/manaslake
require $frm_path . '/pro/classes/models/FrmProField.php';
require $frm_path . '/pro/classes/models/FrmProForm.php';
require $frm_path . '/pro/classes/models/FrmProNotification.php';
global $frmpro_display;
$frmpro_display = new FrmProDisplay();
$obj = new FrmProNotification();
// Instansiate Controllers
require $frm_path . '/pro/classes/controllers/FrmProAppController.php';
require $frm_path . '/pro/classes/controllers/FrmProDisplaysController.php';
require $frm_path . '/pro/classes/controllers/FrmProEntriesController.php';
require $frm_path . '/pro/classes/controllers/FrmProFieldsController.php';
require $frm_path . '/pro/classes/controllers/FrmProFormsController.php';
require $frm_path . '/pro/classes/controllers/FrmProStatisticsController.php';
FrmProAppController::load_hooks();
FrmProDisplaysController::load_hooks();
FrmProEntriesController::load_hooks();
FrmProFieldsController::load_hooks();
FrmProFormsController::load_hooks();
FrmProStatisticsController::load_hooks();
FrmProSettingsController::load_hooks();
if (is_admin()) {
    require $frm_path . '/pro/classes/controllers/FrmProXMLController.php';
    FrmProXMLController::load_hooks();
}
if (is_multisite()) {
    //Models
    require $frm_path . '/pro/classes/models/FrmProCopy.php';
    $obj = new FrmProCopy();
    //Add options to copy forms and displays
    require $frm_path . '/pro/classes/controllers/FrmProCopiesController.php';
    FrmProCopiesController::load_hooks();
コード例 #15
0
ファイル: FrmProEntry.php プロジェクト: moscarar/cityhow
    function set_cookie($entry_id, $form_id)
    {
        //if form options['single] or isset($_POST['frm_single_submit']){
        if (defined('WP_IMPORTING') or defined('DOING_AJAX')) {
            return;
        }
        if (isset($_POST) and isset($_POST['frm_skip_cookie'])) {
            if (!headers_sent()) {
                FrmProEntriesController::set_cookie($entry_id, $form_id);
            }
            return;
        }
        ?>
<script type="text/javascript">
jQuery(document).ready(function($){
jQuery.ajax({type:"POST",url:"<?php 
        echo FRM_SCRIPT_URL;
        ?>
",
data:"controller=entries&frm_action=ajax_set_cookie&entry_id=<?php 
        echo $entry_id;
        ?>
&form_id=<?php 
        echo $form_id;
        ?>
"
});
});    
</script>
<?php 
        //}
    }
コード例 #16
0
 function replace_shortcodes($content, $entry, $shortcodes, $display = false, $show = 'one', $odd = '')
 {
     global $frm_field, $frm_entry_meta, $post, $frmpro_settings;
     if ($display) {
         $param_value = $display->type == 'id' ? $entry->id : $entry->item_key;
         if ($entry->post_id) {
             $detail_link = get_permalink($entry->post_id);
         } else {
             $param = isset($display->param) && !empty($display->param) ? $display->param : 'entry';
             if ($post) {
                 $detail_link = add_query_arg($param, $param_value, get_permalink($post->ID));
             } else {
                 $detail_link = add_query_arg($param, $param_value);
             }
             //if( FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks )
             //    $detail_link = get_permalink($post->ID) .$param_value .'/';
         }
     }
     foreach ($shortcodes[0] as $short_key => $tag) {
         $conditional = preg_match('/^\\[if/s', $shortcodes[0][$short_key]) ? true : false;
         $atts = shortcode_parse_atts($shortcodes[3][$short_key]);
         if (!empty($shortcodes[3][$short_key])) {
             if ($conditional) {
                 $tag = str_replace('[if ', '', $shortcodes[0][$short_key]);
             } else {
                 $tag = str_replace('[', '', $shortcodes[0][$short_key]);
             }
             $tag = str_replace(']', '', $tag);
             $tags = explode(' ', $tag);
             if (is_array($tags)) {
                 $tag = $tags[0];
             }
         } else {
             $tag = $shortcodes[2][$short_key];
         }
         switch ($tag) {
             case 'detaillink':
                 if ($display and $detail_link) {
                     $content = str_replace($shortcodes[0][$short_key], $detail_link, $content);
                 }
                 break;
             case 'id':
                 $content = str_replace($shortcodes[0][$short_key], $entry->id, $content);
                 break;
             case 'post-id':
             case 'post_id':
                 $content = str_replace($shortcodes[0][$short_key], $entry->post_id, $content);
                 break;
             case 'key':
                 $content = str_replace($shortcodes[0][$short_key], $entry->item_key, $content);
                 break;
             case 'ip':
                 $content = str_replace($shortcodes[0][$short_key], $entry->ip, $content);
                 break;
             case 'user_agent':
             case 'user-agent':
                 $entry->description = maybe_unserialize($entry->description);
                 $content = str_replace($shortcodes[0][$short_key], $entry->description['browser'], $content);
                 break;
             case 'created-at':
             case 'updated-at':
                 if (!isset($atts['format'])) {
                     $atts['format'] = get_option('date_format');
                     $time_format = false;
                 } else {
                     $time_format = ' ';
                 }
                 $this_tag = str_replace('-', '_', $tag);
                 if ($conditional) {
                     $replace_with = apply_filters('frm_conditional_value', $entry->{$this_tag}, $atts, false, $tag);
                     if ($atts) {
                         $content = str_replace($shortcodes[0][$short_key], '[if ' . $tag . ']', $content);
                     }
                     if (empty($replace_with)) {
                         $content = preg_replace('/(\\[if\\s+' . $tag . '\\])(.*?)(\\[\\/if\\s+' . $tag . '\\])/mis', '', $content);
                     } else {
                         $content = preg_replace('/(\\[if\\s+' . $tag . '\\])/', '', $content, 1);
                         $content = preg_replace('/(\\[\\/if\\s+' . $tag . '\\])/', '', $content, 1);
                     }
                 } else {
                     if (isset($atts['time_ago'])) {
                         $date = FrmProAppHelper::human_time_diff(strtotime($entry->{$this_tag}));
                     } else {
                         $date = FrmProAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format);
                     }
                     $content = str_replace($shortcodes[0][$short_key], $date, $content);
                 }
                 unset($this_tag);
                 break;
             case 'evenodd':
                 $content = str_replace($shortcodes[0][$short_key], $odd, $content);
                 break;
             case 'siteurl':
                 global $frm_siteurl;
                 $content = str_replace($shortcodes[0][$short_key], $frm_siteurl, $content);
                 break;
             case 'sitename':
                 $content = str_replace($shortcodes[0][$short_key], get_option('blogname'), $content);
                 break;
             case 'get':
                 if (isset($atts['param'])) {
                     $param = $atts['param'];
                     $replace_with = FrmAppHelper::get_param($param);
                     if (is_array($replace_with)) {
                         $replace_with = implode(', ', $replace_with);
                     }
                     $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
                     unset($param);
                     unset($replace_with);
                 }
                 break;
             default:
                 if ($tag == 'deletelink') {
                     $page_id = isset($atts['page_id']) ? $atts['page_id'] : $post->ID;
                     $can_delete = FrmProEntriesHelper::allow_delete($entry);
                     if ($can_delete) {
                         if (isset($atts['label'])) {
                             $delete_atts = $atts;
                             $delete_atts['id'] = $entry->id;
                             $delete_atts['page_id'] = $page_id;
                             $replace_with = FrmProEntriesController::entry_delete_link($delete_atts);
                             unset($delete_atts);
                         } else {
                             $replace_with = add_query_arg(array('frm_action' => 'destroy', 'entry' => $entry->id), get_permalink($page_id));
                         }
                     } else {
                         $replace_with = '';
                     }
                     $field = false;
                 } else {
                     if ($tag == 'editlink') {
                         $replace_with = '';
                         $link_text = isset($atts['label']) ? $atts['label'] : false;
                         if (!$link_text) {
                             $link_text = isset($atts['link_text']) ? $atts['link_text'] : __('Edit', 'formidable');
                         }
                         $class = isset($atts['class']) ? $atts['class'] : '';
                         $page_id = isset($atts['page_id']) ? $atts['page_id'] : $post->ID;
                         if (isset($atts['location']) and $atts['location'] == 'front') {
                             $edit_atts = $atts;
                             $edit_atts['id'] = $entry->id;
                             $delete_atts['page_id'] = $page_id;
                             $replace_with = FrmProEntriesController::entry_edit_link($edit_atts);
                         } else {
                             if ($entry->post_id) {
                                 $replace_with = get_edit_post_link($entry->post_id);
                             } else {
                                 global $frm_siteurl;
                                 if (current_user_can('frm_edit_entries')) {
                                     $replace_with = esc_url($frm_siteurl . '/wp-admin/admin.php?page=formidable-entries&frm_action=edit&id=' . $entry->id);
                                 }
                             }
                             if (!empty($replace_with)) {
                                 $replace_with = '<a href="' . $replace_with . '" class="frm_edit_link ' . $class . '">' . $link_text . '</a>';
                             }
                         }
                         unset($class);
                     } else {
                         $field = $frm_field->getOne($tag);
                     }
                 }
                 $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
                 if (!isset($field)) {
                     $field = false;
                 }
                 if ($field) {
                     $field->field_options = maybe_unserialize($field->field_options);
                     $replace_with = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, $atts);
                     $replace_with = maybe_unserialize($replace_with);
                     $atts['entry_id'] = $entry->id;
                     $atts['entry_key'] = $entry->item_key;
                     $atts['post_id'] = $entry->post_id;
                     $replace_with = apply_filters('frmpro_fields_replace_shortcodes', $replace_with, $tag, $atts, $field);
                 }
                 if (isset($replace_with) and is_array($replace_with)) {
                     $replace_with = implode($sep, $replace_with);
                 }
                 if ($field and $field->type == 'file') {
                     //size options are thumbnail, medium, large, or full
                     $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
                     if ($size != 'id') {
                         $replace_with = FrmProFieldsHelper::get_media_from_id($replace_with, $size);
                     }
                 }
                 if ($conditional) {
                     $replace_with = apply_filters('frm_conditional_value', $replace_with, $atts, $field, $tag);
                     if ($atts) {
                         $content = str_replace($shortcodes[0][$short_key], '[if ' . $tag . ']', $content);
                     }
                     if (empty($replace_with)) {
                         $content = preg_replace('/(\\[if\\s+' . $tag . '\\])(.*?)(\\[\\/if\\s+' . $tag . '\\])/mis', '', $content);
                     } else {
                         $content = preg_replace('/(\\[if\\s+' . $tag . '\\])/', '', $content, 1);
                         $content = preg_replace('/(\\[\\/if\\s+' . $tag . '\\])/', '', $content, 1);
                     }
                 } else {
                     if ($field) {
                         if (isset($atts['show']) and $atts['show'] == 'field_label') {
                             $replace_with = stripslashes($field->name);
                         } else {
                             if (empty($replace_with) and $replace_with != '0') {
                                 $replace_with = '';
                                 if ($field->type == 'number') {
                                     $replace_with = '0';
                                 }
                             } else {
                                 $replace_with = FrmProFieldsHelper::get_display_value($replace_with, $field, $atts);
                             }
                         }
                     }
                     if (isset($atts['sanitize'])) {
                         $replace_with = sanitize_title_with_dashes($replace_with);
                     }
                     if (isset($atts['sanitize_url'])) {
                         $replace_with = urlencode(htmlentities($replace_with));
                     }
                     if (isset($atts['truncate'])) {
                         if (isset($atts['more_text'])) {
                             $more_link_text = $atts['more_text'];
                         } else {
                             $more_link_text = isset($atts['more_link_text']) ? $atts['more_link_text'] : '. . .';
                         }
                         if ($display and $show == 'all') {
                             $more_link_text = ' <a href="' . $detail_link . '">' . $more_link_text . '</a>';
                             $replace_with = FrmAppHelper::truncate($replace_with, (int) $atts['truncate'], 3, $more_link_text);
                         } else {
                             $replace_with = wp_specialchars_decode(strip_tags($replace_with), ENT_QUOTES);
                             $part_one = substr($replace_with, 0, (int) $atts['truncate']);
                             $part_two = substr($replace_with, (int) $atts['truncate']);
                             $replace_with = $part_one . '<a onclick="jQuery(this).next().css(\'display\', \'inline\');jQuery(this).css(\'display\', \'none\')" class="frm_text_exposed_show"> ' . $more_link_text . '</a><span style="display:none;">' . $part_two . '</span>';
                         }
                     }
                     if (isset($atts['clickable'])) {
                         $replace_with = make_clickable($replace_with);
                     }
                     if (!isset($replace_with)) {
                         $replace_with = '';
                     }
                     $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
                 }
                 unset($replace_with);
                 if (isset($field)) {
                     unset($field);
                 }
         }
         unset($atts);
         unset($conditional);
     }
     return $content;
 }
コード例 #17
0
 public static function replace_shortcodes($html, $form, $values = array())
 {
     preg_match_all("/\\[(if )?(deletelink|back_label|back_hook|back_button|draft_label|save_draft|draft_hook)\\b(.*?)(?:(\\/))?\\](?:(.+?)\\[\\/\\])?/s", $html, $shortcodes, PREG_PATTERN_ORDER);
     if (empty($shortcodes[0])) {
         return $html;
     }
     foreach ($shortcodes[0] as $short_key => $tag) {
         $replace_with = '';
         $atts = shortcode_parse_atts($shortcodes[3][$short_key]);
         switch ($shortcodes[2][$short_key]) {
             case 'deletelink':
                 $replace_with = FrmProEntriesController::entry_delete_link($atts);
                 break;
             case 'back_label':
                 $replace_with = isset($form->options['prev_value']) ? $form->options['prev_value'] : __('Previous', 'formidable');
                 break;
             case 'back_hook':
                 $replace_with = apply_filters('frm_back_button_action', '', $form);
                 break;
             case 'back_button':
                 global $frm_vars;
                 if (!$frm_vars['prev_page'] || !is_array($frm_vars['prev_page']) || !isset($frm_vars['prev_page'][$form->id]) || empty($frm_vars['prev_page'][$form->id])) {
                     unset($replace_with);
                 } else {
                     $classes = apply_filters('frm_back_button_class', array(), $form);
                     if (!empty($classes)) {
                         $html = str_replace('class="frm_prev_page', 'class="frm_prev_page ' . implode(' ', $classes), $html);
                     }
                     $html = str_replace('[/if back_button]', '', $html);
                 }
                 break;
             case 'draft_label':
                 $replace_with = __('Save Draft', 'formidable');
                 break;
             case 'save_draft':
                 if (!is_user_logged_in() || !isset($form->options['save_draft']) || $form->options['save_draft'] != 1 || isset($values['is_draft']) && !$values['is_draft']) {
                     //remove button if user is not logged in, drafts are not allowed, or editing an entry that is not a draft
                     unset($replace_with);
                 } else {
                     $html = str_replace('[/if save_draft]', '', $html);
                 }
                 break;
             case 'draft_hook':
                 $replace_with = apply_filters('frm_draft_button_action', '', $form);
                 break;
         }
         if (isset($replace_with)) {
             $html = str_replace($shortcodes[0][$short_key], $replace_with, $html);
         }
         unset($short_key, $tag, $replace_with);
     }
     return $html;
 }
コード例 #18
0
 public static function get_email_html()
 {
     echo FrmProEntriesController::show_entry_shortcode(array('form_id' => $_POST['form_id'], 'default_email' => true, 'plain_text' => $_POST['plain_text']));
     die;
 }
コード例 #19
0
 public static function replace_shortcodes($html, $field, $errors = array(), $form = false, $args = array())
 {
     $html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form);
     $defaults = array('field_name' => 'item_meta[' . $field['id'] . ']', 'field_id' => $field['id'], 'field_plus_id' => '', 'section_id' => '');
     $args = wp_parse_args($args, $defaults);
     $field_name = $args['field_name'];
     $field_id = $args['field_id'];
     $html_id = self::get_html_id($field, $args['field_plus_id']);
     if (FrmField::is_multiple_select($field)) {
         $field_name .= '[]';
     }
     //replace [id]
     $html = str_replace('[id]', $field_id, $html);
     // Remove the for attribute for captcha
     if ($field['type'] == 'captcha') {
         $html = str_replace(' for="field_[key]"', '', $html);
     }
     // set the label for
     $html = str_replace('field_[key]', $html_id, $html);
     //replace [key]
     $html = str_replace('[key]', $field['field_key'], $html);
     //replace [description] and [required_label] and [error]
     $required = FrmField::is_required($field) ? $field['required_indicator'] : '';
     if (!is_array($errors)) {
         $errors = array();
     }
     $error = isset($errors['field' . $field_id]) ? $errors['field' . $field_id] : false;
     //If field type is section heading, add class so a bottom margin can be added to either the h3 or description
     if ($field['type'] == 'divider') {
         if (FrmField::is_option_true($field, 'description')) {
             $html = str_replace('frm_description', 'frm_description frm_section_spacing', $html);
         } else {
             $html = str_replace('[label_position]', '[label_position] frm_section_spacing', $html);
         }
     }
     foreach (array('description' => $field['description'], 'required_label' => $required, 'error' => $error) as $code => $value) {
         self::remove_inline_conditions($value && $value != '', $code, $value, $html);
     }
     //replace [required_class]
     $required_class = FrmField::is_required($field) ? ' frm_required_field' : '';
     $html = str_replace('[required_class]', $required_class, $html);
     //replace [label_position]
     $field['label'] = apply_filters('frm_html_label_position', $field['label'], $field, $form);
     $field['label'] = $field['label'] && $field['label'] != '' ? $field['label'] : 'top';
     $html = str_replace('[label_position]', in_array($field['type'], array('divider', 'end_divider', 'break')) ? $field['label'] : ' frm_primary_label', $html);
     //replace [field_name]
     $html = str_replace('[field_name]', $field['name'], $html);
     //replace [error_class]
     $error_class = isset($errors['field' . $field_id]) ? ' frm_blank_field' : '';
     self::get_more_field_classes($error_class, $field, $field_id, $html);
     if ($field['type'] == 'html' && strpos($html, '[error_class]') === false) {
         // there is no error_class shortcode to use for addign fields
         $html = str_replace('class="frm_form_field', 'class="frm_form_field ' . $error_class, $html);
     }
     $html = str_replace('[error_class]', $error_class, $html);
     //replace [entry_key]
     $entry_key = FrmAppHelper::simple_get('entry', 'sanitize_title');
     $html = str_replace('[entry_key]', $entry_key, $html);
     //replace [input]
     preg_match_all("/\\[(input|deletelink)\\b(.*?)(?:(\\/))?\\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
     global $frm_vars;
     $frm_settings = FrmAppHelper::get_settings();
     foreach ($shortcodes[0] as $short_key => $tag) {
         $atts = shortcode_parse_atts($shortcodes[2][$short_key]);
         $tag = self::get_shortcode_tag($shortcodes, $short_key, array('conditional' => false, 'conditional_check' => false));
         $replace_with = '';
         if ($tag == 'input') {
             if (isset($atts['opt'])) {
                 $atts['opt']--;
             }
             $field['input_class'] = isset($atts['class']) ? $atts['class'] : '';
             if (isset($atts['class'])) {
                 unset($atts['class']);
             }
             $field['shortcodes'] = $atts;
             ob_start();
             include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/input.php';
             $replace_with = ob_get_contents();
             ob_end_clean();
         } else {
             if ($tag == 'deletelink' && FrmAppHelper::pro_is_installed()) {
                 $replace_with = FrmProEntriesController::entry_delete_link($atts);
             }
         }
         $html = str_replace($shortcodes[0][$short_key], $replace_with, $html);
     }
     if ($form) {
         $form = (array) $form;
         //replace [form_key]
         $html = str_replace('[form_key]', $form['form_key'], $html);
         //replace [form_name]
         $html = str_replace('[form_name]', $form['name'], $html);
     }
     $html .= "\n";
     //Return html if conf_field to prevent loop
     if (isset($field['conf_field']) && $field['conf_field'] == 'stop') {
         return $html;
     }
     //If field is in repeating section
     if ($args['section_id']) {
         $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']));
     } else {
         $html = apply_filters('frm_replace_shortcodes', $html, $field, array('errors' => $errors, 'form' => $form));
     }
     self::remove_collapse_shortcode($html);
     if (apply_filters('frm_do_html_shortcodes', true)) {
         $html = do_shortcode($html);
     }
     return $html;
 }
コード例 #20
0
 function replace_shortcodes($html, $field, $errors = array(), $form = false)
 {
     $html = stripslashes($html);
     $html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form);
     $field_name = "item_meta[" . $field['id'] . "]";
     //replace [id]
     $html = str_replace('[id]', $field['id'], $html);
     //replace [key]
     $html = str_replace('[key]', $field['field_key'], $html);
     //replace [description] and [required_label] and [error]
     $required = $field['required'] == '0' ? '' : $field['required_indicator'];
     $error = isset($errors['field' . $field['id']]) ? stripslashes($errors['field' . $field['id']]) : false;
     foreach (array('description' => $field['description'], 'required_label' => $required, 'error' => $error) as $code => $value) {
         if (!$value or $value == '') {
             $html = preg_replace('/(\\[if\\s+' . $code . '\\])(.*?)(\\[\\/if\\s+' . $code . '\\])/mis', '', $html);
         } else {
             $html = str_replace('[if ' . $code . ']', '', $html);
             $html = str_replace('[/if ' . $code . ']', '', $html);
         }
         $html = str_replace('[' . $code . ']', $value, $html);
     }
     //replace [required_class]
     $required_class = $field['required'] == '0' ? '' : ' frm_required_field';
     $html = str_replace('[required_class]', $required_class, $html);
     //replace [label_position]
     $field['label'] = apply_filters('frm_html_label_position', $field['label'], $field);
     $field['label'] = ($field['label'] and $field['label'] != '') ? $field['label'] : 'top';
     $html = str_replace('[label_position]', $field['type'] == 'divider' ? $field['label'] : ' frm_primary_label', $html);
     //replace [field_name]
     $html = str_replace('[field_name]', $field['name'], $html);
     //replace [error_class]
     $error_class = isset($errors['field' . $field['id']]) ? ' frm_blank_field' : '';
     $error_class .= ' frm_' . $field['label'] . '_container';
     //insert custom CSS classes
     if (!empty($field['classes'])) {
         if (!strpos($html, 'frm_form_field ')) {
             $error_class .= ' frm_form_field';
         }
         $error_class .= ' ' . $field['classes'];
     }
     $html = str_replace('[error_class]', $error_class, $html);
     //replace [entry_key]
     $entry_key = (isset($_GET) and isset($_GET['entry'])) ? $_GET['entry'] : '';
     $html = str_replace('[entry_key]', $entry_key, $html);
     //replace [input]
     preg_match_all("/\\[(input|deletelink)\\b(.*?)(?:(\\/))?\\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
     foreach ($shortcodes[0] as $short_key => $tag) {
         $atts = shortcode_parse_atts($shortcodes[2][$short_key]);
         if (!empty($shortcodes[2][$short_key])) {
             $tag = str_replace('[', '', $shortcodes[0][$short_key]);
             $tag = str_replace(']', '', $tag);
             $tags = explode(' ', $tag);
             if (is_array($tags)) {
                 $tag = $tags[0];
             }
         } else {
             $tag = $shortcodes[1][$short_key];
         }
         $replace_with = '';
         if ($tag == 'input') {
             if (isset($atts['opt'])) {
                 $atts['opt']--;
             }
             $field['input_class'] = isset($atts['class']) ? $atts['class'] : '';
             ob_start();
             include FRM_VIEWS_PATH . '/frm-fields/input.php';
             $replace_with = ob_get_contents();
             ob_end_clean();
         } else {
             if ($tag == 'deletelink' and class_exists('FrmProEntriesController')) {
                 $replace_with = FrmProEntriesController::entry_delete_link($atts);
             }
         }
         $html = str_replace($shortcodes[0][$short_key], $replace_with, $html);
     }
     if ($form) {
         $form = (array) $form;
         //replace [form_key]
         $html = str_replace('[form_key]', $form['form_key'], $html);
         //replace [form_name]
         $html = str_replace('[form_name]', $form['name'], $html);
     }
     $html .= "\n";
     return apply_filters('frm_replace_shortcodes', $html, $field, array('errors' => $errors, 'form' => $form));
 }
コード例 #21
0
 function entry_delete_link($atts)
 {
     global $frm_editing_entry, $post, $frm_forms_loaded;
     extract(shortcode_atts(array('id' => $frm_editing_entry, 'label' => 'Delete', 'confirm' => __('Are you sure you want to delete that entry?', 'formidable'), 'class' => '', 'page_id' => $post ? $post->ID : 0, 'html_id' => false, 'prefix' => ''), $atts));
     $frm_forms_loaded[] = true;
     $link = '';
     $entry_id = ($id and is_numeric($id)) ? $id : (is_admin() ? FrmAppHelper::get_param('id', false) : FrmAppHelper::get_param('entry', false));
     if ($entry_id and !empty($entry_id)) {
         if (empty($prefix)) {
             $action = FrmAppHelper::get_param('frm_action');
             if ($action == 'destroy') {
                 $entry_key = FrmAppHelper::get_param('entry');
                 if (is_numeric($entry_key) and $entry_key == $entry_id) {
                     $link = FrmProEntriesController::ajax_destroy(false, false, false);
                     if (!empty($link)) {
                         $new_link = '<div class="frm_message">' . $link . '</div>';
                         if ($link == __('Your entry was successfully deleted', 'formidable')) {
                             return $new_link;
                         } else {
                             $link = $new_link;
                         }
                         unset($new_link);
                     }
                 }
             }
             $link .= "<a href='" . add_query_arg(array('frm_action' => 'destroy', 'entry' => $entry_id), get_permalink($page_id)) . "' class='{$class}' onclick='return confirm(\"" . $confirm . "\")'>{$label}</a>\n";
         } else {
             if (!$html_id) {
                 $html_id = "frm_delete_{$entry_id}";
             }
             $link = "<a href='javascript:frmDeleteEntry({$entry_id},\"" . FRM_SCRIPT_URL . "\",\"{$prefix}\")' class='frm_delete_link {$class}' id='{$html_id}' onclick='return confirm(\"" . $confirm . "\")'>{$label}</a>\n";
         }
     }
     return $link;
 }
コード例 #22
0
 public static function ajax_create()
 {
     global $frm_entry;
     $frm_form = new FrmForm();
     $form = $frm_form->getOne($_POST['form_id']);
     if (!$form) {
         echo false;
         die;
     }
     $no_ajax_fields = array('file');
     $errors = $frm_entry->validate($_POST, $no_ajax_fields);
     if (empty($errors)) {
         global $wpdb;
         $where = $wpdb->prepare("form_id=%d", $form->id);
         if (isset($_POST['frm_page_order_' . $form->id])) {
             $where .= $wpdb->prepare(" AND field_order < %d", $_POST['frm_page_order_' . $form->id]);
         }
         $ajax = isset($form->options['ajax_submit']) ? $form->options['ajax_submit'] : 0;
         //ajax submit if no file, rte, captcha
         if ($ajax) {
             $no_ajax = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}frm_fields WHERE type in ('" . implode("','", $no_ajax_fields) . "') AND {$where} LIMIT 1");
             if ($no_ajax) {
                 $ajax = false;
             }
         }
         if ($ajax) {
             global $frm_vars;
             $frm_vars['ajax'] = true;
             $frm_vars['css_loaded'] = true;
             if (!isset($_POST['frm_page_order_' . $form->id]) && !FrmProFormsHelper::going_to_prev($form->id) || FrmProFormsHelper::saving_draft($form->id)) {
                 $processed = true;
                 FrmEntriesController::process_entry($errors, true);
             }
             echo FrmFormsController::show_form($form->id);
             // trigger the footer scripts if there is a form to show
             if ($errors || !isset($form->options['show_form']) || $form->options['show_form'] || !isset($processed)) {
                 self::register_scripts();
                 FrmProEntriesController::enqueue_footer_js();
                 wp_deregister_script('formidable');
                 global $wp_scripts, $wp_styles;
                 foreach (array('jquery', 'jquery-ui-core', 'jquery-migrate', 'thickbox') as $s) {
                     if (isset($wp_scripts->registered[$s])) {
                         $wp_scripts->done[] = $s;
                     }
                     unset($s);
                 }
                 $keep_styles = apply_filters('frm_ajax_load_styles', array('dashicons', 'jquery-theme'));
                 foreach ($wp_styles->registered as $s => $info) {
                     if (!is_array($keep_styles) || !in_array($s, $keep_styles)) {
                         $wp_styles->done[] = $s;
                     }
                     unset($s);
                 }
                 wp_print_footer_scripts();
                 FrmProEntriesController::footer_js();
             }
         } else {
             echo false;
         }
     } else {
         $errors = str_replace('"', '&quot;', $errors);
         $obj = array();
         foreach ($errors as $field => $error) {
             $field_id = str_replace('field', '', $field);
             $obj[$field_id] = $error;
         }
         echo json_encode($obj);
     }
     die;
 }