public static function do_shortcode_editlink(&$content, $atts, $shortcodes, $short_key, $args) { global $post; $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'] = isset($args['foreach_loop']) ? $args['entry']->parent_item_id : $args['entry']->id; $edit_atts['page_id'] = $page_id; $replace_with = FrmProEntriesController::entry_edit_link($edit_atts); } else { if ($args['entry']->post_id) { $replace_with = get_edit_post_link($args['entry']->post_id); } else { if (current_user_can('frm_edit_entries')) { $replace_with = admin_url('admin.php?page=formidable-entries&frm_action=edit&id=' . $args['entry']->id); } } if (!empty($replace_with)) { $replace_with = '<a href="' . esc_url($replace_with) . '" class="frm_edit_link ' . esc_attr($class) . '">' . $link_text . '</a>'; } } $content = str_replace($shortcodes[0][$short_key], $replace_with, $content); }
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; }
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; }