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; }
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; }
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; }
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); }
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); }
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; }
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)); }