function entry_link_shortcode($atts)
 {
     global $user_ID, $frm_entry, $frm_entry_meta, $post;
     extract(shortcode_atts(array('id' => false, 'field_key' => 'created_at', 'type' => 'list', 'logged_in' => true, 'edit' => true, 'class' => '', 'link_type' => 'page', 'blank_label' => '', 'param_name' => 'entry', 'param_value' => 'key', 'page_id' => false, 'show_delete' => false), $atts));
     if (!$id or $logged_in && !$user_ID) {
         return;
     }
     $id = (int) $id;
     if ($show_delete === 1) {
         $show_delete = __('Delete', 'formidable');
     }
     $s = FrmAppHelper::get_param('frm_search', false);
     if ($s) {
         $entry_ids = FrmProEntriesHelper::get_search_ids($s, $id);
     } else {
         $entry_ids = $frm_entry_meta->getEntryIds("fi.form_id='{$id}'");
     }
     if ($entry_ids) {
         $id_list = implode(',', $entry_ids);
         $order = $type == 'collapse' ? ' ORDER BY it.created_at DESC' : '';
         $where = "it.id in ({$id_list})";
         if ($logged_in) {
             $where .= " and it.form_id='" . $id . "' and it.user_id='" . (int) $user_ID . "'";
         }
         $entries = $frm_entry->getAll($where, $order, '', true);
     }
     if (!empty($entries)) {
         if ($type == 'list') {
             $content = "<ul class='frm_entry_ul {$class}'>\n";
         } else {
             if ($type == 'collapse') {
                 $content = '<div class="frm_collapse">';
                 $year = $month = '';
                 $prev_year = $prev_month = false;
             } else {
                 $content = "<select id='frm_select_form_{$id}' name='frm_select_form_{$id}' class='{$class}' onchange='location=this.options[this.selectedIndex].value;'>\n <option value='" . get_permalink($post->ID) . "'>{$blank_label}</option>\n";
             }
         }
         global $frm_field;
         if ($field_key != 'created_at') {
             $field = $frm_field->getOne($field_key);
         }
         foreach ($entries as $entry) {
             $action = (isset($_GET) and isset($_GET['frm_action'])) ? 'frm_action' : 'action';
             if (isset($_GET) and isset($_GET[$action]) and $_GET[$action] == 'destroy') {
                 if (isset($_GET['entry']) and ($_GET['entry'] == $entry->item_key or $_GET['entry'] == $entry->id)) {
                     continue;
                 }
             }
             if ($entry->post_id) {
                 global $wpdb;
                 $post_status = $wpdb->get_var("SELECT post_status FROM {$wpdb->posts} WHERE ID=" . $entry->post_id);
                 if ($post_status != 'publish') {
                     continue;
                 }
             }
             $value = '';
             $meta = false;
             if ($field_key && $field_key != 'created_at') {
                 if ($entry->post_id and ($field and $field->field_options['post_field'] or $field->type == 'tag')) {
                     $value = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('type' => $field->type, 'form_id' => $field->form_id, 'field' => $field));
                 } else {
                     $meta = isset($entry->metas[$field_key]) ? $entry->metas[$field_key] : '';
                 }
             } else {
                 $meta = reset($entry->metas);
             }
             $value = ($field_key == 'created_at' or !isset($meta) or !$meta) ? $value : (is_object($meta) ? $meta->meta_value : $meta);
             if (empty($value)) {
                 $value = date_i18n(get_option('date_format'), strtotime($entry->created_at));
             } else {
                 $value = FrmProEntryMetaHelper::display_value($value, $field, array('type' => $field->type, 'show_filename' => false));
             }
             if ($param_value == 'key') {
                 $args = array($param_name => $entry->item_key);
             } else {
                 $args = array($param_name => $entry->id);
             }
             if ($edit) {
                 $args['frm_action'] = 'edit';
             }
             if ($link_type == 'scroll') {
                 $link = '#' . $entry->item_key;
             } else {
                 if ($link_type == 'admin') {
                     $link = add_query_arg($args, $_SERVER['REQUEST_URI']);
                 } else {
                     if ($page_id) {
                         $permalink = get_permalink($page_id);
                     } else {
                         $permalink = get_permalink($post->ID);
                     }
                     $link = add_query_arg($args, $permalink);
                 }
             }
             unset($args);
             $current = isset($_GET['entry']) && $_GET['entry'] == $entry->item_key ? true : false;
             if ($type == 'list') {
                 $content .= "<li><a href='{$link}'>" . stripslashes($value) . "</a>";
                 if ($show_delete and isset($permalink) and FrmProEntriesHelper::allow_delete($entry)) {
                     $content .= " <a href='" . add_query_arg(array('frm_action' => 'destroy', 'entry' => $entry->id), $permalink) . "' class='frm_delete_list'>{$show_delete}</a>\n";
                 }
                 $content .= "</li>\n";
             } else {
                 if ($type == 'collapse') {
                     $new_year = strftime('%G', strtotime($entry->created_at));
                     $new_month = strftime('%B', strtotime($entry->created_at));
                     if ($new_year != $year) {
                         if ($prev_year) {
                             if ($prev_month) {
                                 $content .= '</ul></div>';
                             }
                             $content .= '</div>';
                             $prev_month = false;
                         }
                         $style = $prev_year ? " style='display:none'" : '';
                         $triangle = $prev_year ? "e" : "s";
                         $content .= "\n<div class='frm_year_heading frm_year_heading_{$id}'>\n                            <span class='ui-icon ui-icon-triangle-1-{$triangle}'></span>\n\n                            <a>{$new_year}</a></div>\n\n                            <div class='frm_toggle_container' {$style}>\n";
                         $prev_year = true;
                     }
                     if ($new_month != $month) {
                         if ($prev_month) {
                             $content .= '</ul></div>';
                         }
                         $style = $prev_month ? " style='display:none'" : '';
                         $triangle = $prev_month ? "e" : "s";
                         $content .= "<div class='frm_month_heading frm_month_heading_{$id}'>\n                            <span class='ui-icon ui-icon-triangle-1-{$triangle}'></span>\n\n                            <a>{$new_month}</a>\n</div>\n\n                            <div class='frm_toggle_container frm_month_listing' {$style}><ul>\n";
                         $prev_month = true;
                     }
                     $content .= "<li><a href='{$link}'>" . stripslashes($value) . "</a></li>";
                     $year = $new_year;
                     $month = $new_month;
                 } else {
                     $selected = $current ? ' selected="selected"' : '';
                     $content .= "<option value='{$link}'{$selected}>" . stripslashes($value) . "</option>\n";
                 }
             }
         }
         if ($type == 'list') {
             $content .= "</ul>\n";
         } else {
             if ($type == 'collapse') {
                 if ($prev_year) {
                     $content .= '</div>';
                 }
                 if ($prev_month) {
                     $content .= '</ul></div>';
                 }
                 $content .= '</div>';
                 $content .= "<script type='text/javascript'>jQuery(document).ready(function(\$){ \$('.frm_month_heading_" . $id . ", .frm_year_heading_" . $id . "').toggle(function(){ \$(this).children('.ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s'); \$(this).children('.ui-icon-triangle-1-s').removeClass('ui-icon-triangle-1-e'); \$(this).next('.frm_toggle_container').fadeIn('slow');},function(){ \$(this).children('.ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e'); \$(this).children('.ui-icon-triangle-1-e').removeClass('ui-icon-triangle-1-s'); \$(this).next('.frm_toggle_container').hide();});})</script>\n";
             } else {
                 $content .= "</select>\n";
                 if ($show_delete and isset($_GET) and isset($_GET['entry']) and $_GET['entry']) {
                     $content .= " <a href='" . add_query_arg(array('frm_action' => 'destroy', 'entry' => $_GET['entry']), $permalink) . "' class='frm_delete_list'>{$show_delete}</a>\n";
                 }
             }
         }
     } else {
         $content = '';
     }
     return $content;
 }
Example #2
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;
 }