Exemplo n.º 1
0
 public static function email_value($value, $meta, $entry)
 {
     global $frm_field, $frm_entry;
     if ($entry->id != $meta->item_id) {
         $entry = $frm_entry->getOne($meta->item_id);
     }
     $field = $frm_field->getOne($meta->field_id);
     if (!$field) {
         return $value;
     }
     $field->field_options = maybe_unserialize($field->field_options);
     if (isset($field->field_options['post_field']) and $field->field_options['post_field']) {
         $value = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, array('truncate' => true));
         $value = maybe_unserialize($value);
     }
     switch ($field->type) {
         case 'user_id':
             $value = FrmProFieldsHelper::get_display_name($value);
             break;
         case 'data':
             if (is_array($value)) {
                 $new_value = array();
                 foreach ($value as $val) {
                     $new_value[] = FrmProFieldsHelper::get_data_value($val, $field);
                 }
                 $value = $new_value;
             } else {
                 $value = FrmProFieldsHelper::get_data_value($value, $field);
             }
             break;
         case 'file':
             $value = FrmProFieldsHelper::get_file_name($value);
             break;
         case 'date':
             $value = FrmProFieldsHelper::get_date($value);
     }
     if (is_array($value)) {
         $new_value = '';
         foreach ($value as $val) {
             if (is_array($val)) {
                 $new_value .= implode(', ', $val) . "\n";
             }
         }
         if ($new_value != '') {
             $value = $new_value;
         }
     }
     return $value;
 }
 public static function prepare_display_value($entry, $field, $atts)
 {
     $field_value = isset($entry->metas[$field->id]) ? $entry->metas[$field->id] : false;
     if (FrmAppHelper::pro_is_installed()) {
         FrmProEntriesHelper::get_dynamic_list_values($field, $entry, $field_value);
     }
     if ($field->form_id == $entry->form_id || empty($atts['embedded_field_id'])) {
         return self::display_value($field_value, $field, $atts);
     }
     // this is an embeded form
     $val = '';
     if (strpos($atts['embedded_field_id'], 'form') === 0) {
         //this is a repeating section
         $child_entries = FrmEntry::getAll(array('it.parent_item_id' => $entry->id));
     } else {
         // get all values for this field
         $child_values = isset($entry->metas[$atts['embedded_field_id']]) ? $entry->metas[$atts['embedded_field_id']] : false;
         if ($child_values) {
             $child_entries = FrmEntry::getAll(array('it.id' => (array) $child_values));
         }
     }
     $field_value = array();
     if (!isset($child_entries) || !$child_entries || !FrmAppHelper::pro_is_installed()) {
         return $val;
     }
     foreach ($child_entries as $child_entry) {
         $atts['item_id'] = $child_entry->id;
         $atts['post_id'] = $child_entry->post_id;
         // get the value for this field -- check for post values as well
         $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field);
         if ($entry_val) {
             // foreach entry get display_value
             $field_value[] = self::display_value($entry_val, $field, $atts);
         }
         unset($child_entry);
     }
     $val = implode(', ', (array) $field_value);
     $val = wp_kses_post($val);
     return $val;
 }
 function build_calendar($new_content, $entries, $shortcodes, $display, $show = 'one')
 {
     if (!$display or $display->show_count != 'calendar') {
         return $new_content;
     }
     global $frm_entry_meta, $wp_locale;
     $display_options = maybe_unserialize($display->options);
     $current_year = date_i18n('Y');
     $current_month = date_i18n('n');
     $year = FrmAppHelper::get_param('frmcal-year', date('Y'));
     //4 digit year
     $month = FrmAppHelper::get_param('frmcal-month', $current_month);
     //Numeric month without leading zeros
     $timestamp = mktime(0, 0, 0, $month, 1, $year);
     $maxday = date('t', $timestamp);
     //Number of days in the given month
     $this_month = getdate($timestamp);
     $startday = $this_month['wday'];
     if ($current_year == $year and $current_month == $month) {
         $today = date_i18n('j');
     }
     $cal_end = $maxday + $startday;
     $t = $cal_end > 35 ? 42 : ($cal_end == 28 ? 28 : 35);
     $extrarows = $t - $maxday - $startday;
     $show_entres = false;
     $daily_entries = array();
     if (isset($display_options['date_field_id']) and is_numeric($display_options['date_field_id'])) {
         $field = FrmField::getOne($display_options['date_field_id']);
     }
     if (isset($display_options['edate_field_id']) and is_numeric($display_options['edate_field_id'])) {
         $efield = FrmField::getOne($display_options['edate_field_id']);
     } else {
         $efield = false;
     }
     foreach ($entries as $entry) {
         if (isset($display_options['date_field_id']) and is_numeric($display_options['date_field_id'])) {
             if (isset($entry->metas)) {
                 $date = isset($entry->metas[$display_options['date_field_id']]) ? $entry->metas[$display_options['date_field_id']] : false;
             } else {
                 $date = $frm_entry_meta->get_entry_meta_by_field($entry->id, $display_options['date_field_id']);
             }
             if ($entry->post_id and !$date) {
                 if ($field) {
                     $field->field_options = maybe_unserialize($field->field_options);
                     if ($field->field_options['post_field']) {
                         $date = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('form_id' => $display->form_id, 'type' => $field->type, 'field' => $field));
                     }
                 }
             }
         } else {
             if ($display_options['date_field_id'] == 'updated_at') {
                 $date = $entry->updated_at;
                 $i18n = true;
             } else {
                 $date = $entry->created_at;
                 $i18n = true;
             }
         }
         if (empty($date)) {
             continue;
         }
         if (isset($il8n) and $il8n) {
             $date = date_i18n('Y-m-d', strtotime($date));
         } else {
             $date = date('Y-m-d', strtotime($date));
         }
         unset($i18n);
         $dates = array($date);
         if (isset($display_options['edate_field_id']) and !empty($display_options['edate_field_id'])) {
             if (is_numeric($display_options['edate_field_id']) and $efield) {
                 $edate = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $efield);
                 if ($efield and $efield->type == 'number' and is_numeric($edate)) {
                     $edate = date('Y-m-d', strtotime('+' . $edate . ' days', strtotime($date)));
                 }
             } else {
                 if ($display_options['edate_field_id'] == 'updated_at') {
                     $edate = date_i18n('Y-m-d', strtotime($entry->updated_at));
                 } else {
                     $edate = date_i18n('Y-m-d', strtotime($entry->created_at));
                 }
             }
             if ($edate and !empty($edate)) {
                 $from_date = strtotime($date);
                 $to_date = strtotime($edate);
                 if (!empty($from_date) and $from_date < $to_date) {
                     for ($current_ts = $from_date; $current_ts <= $to_date; $current_ts += 60 * 60 * 24) {
                         $dates[] = date('Y-m-d', $current_ts);
                     }
                     unset($current_ts);
                 }
                 unset($from_date);
                 unset($to_date);
             }
             unset($edate);
             $used_entries = array();
         }
         unset($date);
         $dates = apply_filters('frm_show_entry_dates', $dates, $entry);
         for ($i = 0; $i < $maxday + $startday; $i++) {
             $day = $i - $startday + 1;
             if (in_array(date('Y-m-d', strtotime("{$year}-{$month}-{$day}")), $dates)) {
                 $show_entres = true;
                 $daily_entres[$i][] = $entry;
             }
             unset($day);
         }
         unset($dates);
     }
     $day_names = $wp_locale->weekday_abbrev;
     $day_names = FrmProAppHelper::reset_keys($day_names);
     //switch keys to order
     ob_start();
     include FRMPRO_VIEWS_PATH . '/displays/calendar.php';
     $content = ob_get_contents();
     ob_end_clean();
     return $content;
 }
 /**
  * Get the value from a specific field and entry
  *
  * @since 2.01.02
  * @param object $entry
  * @param int $field_id
  * @return array|bool|mixed|string
  */
 private static function get_value_from_entry($entry, $field_id)
 {
     $observed_value = '';
     if (isset($entry->metas[$field_id])) {
         $observed_value = $entry->metas[$field_id];
     } else {
         if ($entry->post_id && FrmAppHelper::pro_is_installed()) {
             $field = FrmField::getOne($field_id);
             $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, array('links' => false, 'truncate' => false));
         }
     }
     return $observed_value;
 }
Exemplo n.º 5
0
 public static function replace_single_shortcode($shortcodes, $short_key, $tag, $entry, $display, $args, &$content)
 {
     global $post;
     $conditional = preg_match('/^\\[if/s', $shortcodes[0][$short_key]) ? true : false;
     $foreach = preg_match('/^\\[foreach/s', $shortcodes[0][$short_key]) ? true : false;
     $atts = shortcode_parse_atts($shortcodes[3][$short_key]);
     $tag = FrmFieldsHelper::get_shortcode_tag($shortcodes, $short_key, compact('conditional', 'foreach'));
     if (strpos($tag, '-')) {
         $switch_tags = array('post-id', 'created-at', 'updated-at', 'created-by', 'updated-by', 'parent-id');
         if (in_array($tag, $switch_tags)) {
             $tag = str_replace('-', '_', $tag);
         }
         unset($switch_tags);
     }
     $tags = array('event_date', 'entry_count', 'detaillink', 'editlink', 'deletelink', 'created_at', 'updated_at', 'created_by', 'updated_by', 'evenodd', 'post_id', 'parent_id', 'id');
     if (in_array($tag, $tags)) {
         $args['entry'] = $entry;
         $args['tag'] = $tag;
         $args['conditional'] = $conditional;
         $function = 'do_shortcode_' . $tag;
         self::$function($content, $atts, $shortcodes, $short_key, $args, $display);
         return;
     }
     $field = FrmField::getOne($tag);
     if (!$field) {
         return;
     }
     if (!$foreach && !$conditional && isset($atts['show']) && ($atts['show'] == 'field_label' || $atts['show'] == 'description')) {
         // get the field label or description and return before any other checking
         $replace_with = $atts['show'] == 'field_label' ? $field->name : $field->description;
         $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
         return;
     }
     $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
     if ($field->form_id == $entry->form_id) {
         $replace_with = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, $atts);
     } else {
         // get entry ids linked through repeat field or embeded form
         $child_entries = FrmProEntry::get_sub_entries($entry->id, true);
         $replace_with = FrmProEntryMetaHelper::get_sub_meta_values($child_entries, $field, $atts);
         $replace_with = FrmAppHelper::array_flatten($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);
     self::get_file_from_atts($atts, $field, $replace_with);
     if (isset($atts['show']) && $atts['show'] == 'count') {
         $replace_with = is_array($replace_with) ? count($replace_with) : !empty($replace_with);
     } else {
         if (is_array($replace_with) && !$foreach) {
             $replace_with = FrmAppHelper::array_flatten($replace_with);
             $replace_with = implode($sep, $replace_with);
         }
     }
     if ($foreach) {
         $atts['short_key'] = $shortcodes[0][$short_key];
         $args['display'] = $display;
         self::check_conditional_shortcode($content, $replace_with, $atts, $tag, 'foreach', $args);
     } else {
         if ($conditional) {
             $atts['short_key'] = $shortcodes[0][$short_key];
             self::check_conditional_shortcode($content, $replace_with, $atts, $tag, 'if', array('field' => $field));
         } else {
             if (empty($replace_with) && $replace_with != '0') {
                 $replace_with = '';
                 if ($field->type == 'number') {
                     $replace_with = '0';
                 }
             } else {
                 $replace_with = FrmFieldsHelper::get_display_value($replace_with, $field, $atts);
             }
             self::trigger_shortcode_atts($atts, $display, $args, $replace_with);
             $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
         }
     }
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 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;
 }
 public static function get_field_value_shortcode($sc_atts)
 {
     $atts = shortcode_atts(array('entry' => false, 'field_id' => false, 'user_id' => false, 'ip' => false, 'show' => '', 'format' => '', 'return_array' => false, 'default' => ''), $sc_atts);
     // Include all user-defined atts as well
     $atts = (array) $atts + (array) $sc_atts;
     // For reverse compatibility
     if (isset($atts['entry_id']) && !$atts['entry']) {
         $atts['entry'] = $atts['entry_id'];
     }
     if (!$atts['field_id']) {
         return __('You are missing options in your shortcode. field_id is required.', 'formidable');
     }
     $field = FrmField::getOne($atts['field_id']);
     if (!$field) {
         return $atts['default'];
     }
     $entry = self::get_frm_field_value_entry($field, $atts);
     if (!$entry) {
         return $atts['default'];
     }
     $value = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, $atts);
     $atts['type'] = $field->type;
     $atts['post_id'] = $entry->post_id;
     $atts['entry_id'] = $entry->id;
     if (!isset($atts['show_filename'])) {
         $atts['show_filename'] = false;
     }
     if ($field->type == 'file' && !isset($atts['html'])) {
         // default to show the image instead of the url
         $atts['html'] = 1;
     }
     if (!empty($atts['format']) || isset($atts['show']) && !empty($atts['show'])) {
         $value = FrmFieldsHelper::get_display_value($value, $field, $atts);
     } else {
         $value = FrmEntriesHelper::display_value($value, $field, $atts);
     }
     return $value;
 }
Exemplo n.º 9
0
 public static function ajax_get_data()
 {
     $entry_id = trim(FrmAppHelper::get_param('entry_id'), ',');
     $field_id = FrmAppHelper::get_param('field_id');
     $current_field = (int) FrmAppHelper::get_param('current_field');
     global $frm_entry_meta, $frm_field;
     $data_field = $frm_field->getOne($field_id);
     $current = $frm_field->getOne($current_field);
     if (strpos($entry_id, ',')) {
         $entry_id = explode(',', $entry_id);
         $meta_value = array();
         foreach ($entry_id as $eid) {
             $new_meta = FrmProEntryMetaHelper::get_post_or_meta_value($eid, $data_field);
             if ($new_meta) {
                 if (is_array($new_meta)) {
                     foreach ($new_meta as $nm) {
                         array_push($meta_value, $nm);
                         unset($nm);
                     }
                 } else {
                     array_push($meta_value, $new_meta);
                 }
             }
             unset($new_meta);
             unset($eid);
         }
     } else {
         $meta_value = FrmProEntryMetaHelper::get_post_or_meta_value($entry_id, $data_field);
     }
     $value = FrmProFieldsHelper::get_display_value($meta_value, $data_field, array('html' => true));
     if (is_array($value)) {
         $value = implode(', ', $value);
     }
     if (is_array($meta_value)) {
         $meta_value = implode(', ', $meta_value);
     }
     if ($value && !empty($value)) {
         echo apply_filters('frm_show_it', "<p class='frm_show_it'>" . $value . "</p>\n", $value, array('field' => $data_field, 'value' => $meta_value, 'entry_id' => $entry_id));
     }
     $current_field = (array) $current;
     foreach ($current->field_options as $o => $v) {
         if (!isset($current_field[$o])) {
             $current_field[$o] = $v;
         }
         unset($o);
         unset($v);
     }
     echo '<input type="hidden" id="field_' . $current->field_key . '" name="item_meta[' . $current->id . ']" value="' . esc_attr($meta_value) . '" ' . do_action('frm_field_input_html', $current_field, false) . '/>';
     die;
 }
Exemplo n.º 10
0
 public static function get_field_value_shortcode($atts)
 {
     extract(shortcode_atts(array('entry_id' => false, 'field_id' => false, 'user_id' => false, 'ip' => false, 'show' => '', 'format' => ''), $atts));
     if (!$field_id) {
         return __('You are missing options in your shortcode. field_id is required.', 'formidable');
     }
     global $frm_field, $wpdb, $frmdb;
     $field = $frm_field->getOne($field_id);
     if (!$field) {
         return '';
     }
     $query = $wpdb->prepare("SELECT post_id, id FROM {$frmdb->entries} WHERE form_id=%d", $field->form_id);
     if ($user_id) {
         // make sure we are not getting entries for logged-out users
         $query .= $wpdb->prepare(' AND user_id=%d AND user_id > 0', (int) FrmProAppHelper::get_user_id_param($user_id));
     }
     if ($entry_id) {
         if (!is_numeric($entry_id)) {
             $entry_id = isset($_GET[$entry_id]) ? $_GET[$entry_id] : $entry_id;
         }
         if ((int) $entry_id < 1) {
             // don't run the sql query if we know there will be no results
             return;
         }
         $query .= $wpdb->prepare(' AND id=%d', (int) $entry_id);
     }
     if ($ip) {
         $query .= $wpdb->prepare(' AND ip=%s', $ip == true ? $_SERVER['REMOTE_ADDR'] : $ip);
     }
     $query .= " ORDER BY created_at DESC LIMIT 1";
     $entry = $wpdb->get_row($query);
     if (!$entry) {
         return;
     }
     $value = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, $atts);
     $atts['type'] = $field->type;
     $atts['post_id'] = $entry->post_id;
     $atts['entry_id'] = $entry->id;
     if (!isset($atts['show_filename'])) {
         $atts['show_filename'] = false;
     }
     if (isset($show) and !empty($show)) {
         $atts['show'] = $show;
         $value = FrmProFieldsHelper::get_display_value($value, $field, $atts);
     } else {
         $value = FrmProEntryMetaHelper::display_value($value, $field, $atts);
     }
     return $value;
 }
Exemplo n.º 11
0
 public static function ajax_get_data()
 {
     //check_ajax_referer( 'frm_ajax', 'nonce' );
     $entry_id = FrmAppHelper::get_param('entry_id');
     if (is_array($entry_id)) {
         $entry_id = implode(',', $entry_id);
     }
     $entry_id = trim($entry_id, ',');
     $field_id = FrmAppHelper::get_param('field_id', '', 'get', 'sanitize_title');
     $current_field = FrmAppHelper::get_param('current_field', '', 'get', 'absint');
     $hidden_field_id = FrmAppHelper::get_param('hide_id');
     $data_field = FrmField::getOne($field_id);
     $current = FrmField::getOne($current_field);
     if (strpos($entry_id, ',')) {
         $entry_id = explode(',', $entry_id);
         $meta_value = array();
         foreach ($entry_id as $eid) {
             $new_meta = FrmProEntryMetaHelper::get_post_or_meta_value($eid, $data_field);
             if ($new_meta) {
                 foreach ((array) $new_meta as $nm) {
                     array_push($meta_value, $nm);
                     unset($nm);
                 }
             }
             unset($new_meta, $eid);
         }
         $meta_value = array_unique($meta_value);
     } else {
         $meta_value = FrmProEntryMetaHelper::get_post_or_meta_value($entry_id, $data_field);
     }
     $data_display_opts = apply_filters('frm_display_data_opts', array('html' => true));
     $value = FrmFieldsHelper::get_display_value($meta_value, $data_field, $data_display_opts);
     if (is_array($value)) {
         $value = implode(', ', $value);
     }
     if (is_array($meta_value)) {
         $meta_value = implode(', ', $meta_value);
     }
     if ($value && !empty($value)) {
         echo apply_filters('frm_show_it', "<p class='frm_show_it'>" . $value . "</p>\n", $value, array('field' => $data_field, 'value' => $meta_value, 'entry_id' => $entry_id));
     }
     $current_field = (array) $current;
     foreach ($current->field_options as $o => $v) {
         if (!isset($current_field[$o])) {
             $current_field[$o] = $v;
         }
         unset($o, $v);
     }
     // Set up HTML ID and HTML name
     $html_id = '';
     $field_name = 'item_meta';
     FrmProFieldsHelper::get_html_id_from_container($field_name, $html_id, (array) $current, $hidden_field_id);
     echo '<input type="hidden" id="' . esc_attr($html_id) . '" name="' . esc_attr($field_name) . '" value="' . esc_attr($value) . '" ' . do_action('frm_field_input_html', $current_field, false) . '/>';
     wp_die();
 }
Exemplo n.º 12
0
 public static function build_calendar($new_content, $entries, $shortcodes, $display, $show = 'one')
 {
     if (!$display || $display->frm_show_count != 'calendar' || $show == 'one') {
         return $new_content;
     }
     global $frm_entry_meta, $wp_locale, $frm_field;
     $current_year = date_i18n('Y');
     $current_month = date_i18n('m');
     $year = FrmAppHelper::get_param('frmcal-year', date('Y'));
     //4 digit year
     $month = FrmAppHelper::get_param('frmcal-month', $current_month);
     //Numeric month with leading zeros
     $timestamp = mktime(0, 0, 0, $month, 1, $year);
     $maxday = date('t', $timestamp);
     //Number of days in the given month
     $this_month = getdate($timestamp);
     $startday = $this_month['wday'];
     // week_begins = 0 stands for Sunday
     $week_begins = apply_filters('frm_cal_week_begins', intval(get_option('start_of_week')), $display);
     if ($week_begins > $startday) {
         $startday = $startday + 7;
     }
     $week_ends = 6 + (int) $week_begins;
     if ($week_ends > 6) {
         $week_ends = (int) $week_ends - 7;
     }
     if ($current_year == $year and $current_month == $month) {
         $today = date_i18n('j');
     }
     $daily_entries = array();
     if (isset($display->frm_date_field_id) && is_numeric($display->frm_date_field_id)) {
         $field = $frm_field->getOne($display->frm_date_field_id);
     }
     if (isset($display->frm_edate_field_id) && is_numeric($display->frm_edate_field_id)) {
         $efield = $frm_field->getOne($display->frm_edate_field_id);
     } else {
         $efield = false;
     }
     foreach ($entries as $entry) {
         if (isset($display->frm_date_field_id) && is_numeric($display->frm_date_field_id)) {
             if (isset($entry->metas)) {
                 $date = isset($entry->metas[$display->frm_date_field_id]) ? $entry->metas[$display->frm_date_field_id] : false;
             } else {
                 $date = $frm_entry_meta->get_entry_meta_by_field($entry->id, $display->frm_date_field_id);
             }
             if ($entry->post_id && !$date && $field && isset($field->field_options['post_field']) && $field->field_options['post_field']) {
                 $date = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('form_id' => $display->frm_form_id, 'type' => $field->type, 'field' => $field));
             }
         } else {
             if ($display->frm_date_field_id == 'updated_at') {
                 $date = $entry->updated_at;
                 $i18n = true;
             } else {
                 $date = $entry->created_at;
                 $i18n = true;
             }
         }
         if (empty($date)) {
             continue;
         }
         if (isset($i18n) && $i18n) {
             $date = get_date_from_gmt($date);
             $date = date_i18n('Y-m-d', strtotime($date));
         } else {
             $date = date('Y-m-d', strtotime($date));
         }
         unset($i18n);
         $dates = array($date);
         if (isset($display->frm_edate_field_id) && !empty($display->frm_edate_field_id)) {
             if (is_numeric($display->frm_edate_field_id) and $efield) {
                 $edate = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $efield);
                 if ($efield && $efield->type == 'number' && is_numeric($edate)) {
                     $edate = date('Y-m-d', strtotime('+' . ($edate - 1) . ' days', strtotime($date)));
                 }
             } else {
                 if ($display->frm_edate_field_id == 'updated_at') {
                     $edate = get_date_from_gmt($entry->updated_at);
                     $edate = date_i18n('Y-m-d', strtotime($edate));
                 } else {
                     $edate = get_date_from_gmt($entry->created_at);
                     $edate = date_i18n('Y-m-d', strtotime($edate));
                 }
             }
             if ($edate and !empty($edate)) {
                 $from_date = strtotime($date);
                 $to_date = strtotime($edate);
                 if (!empty($from_date) and $from_date < $to_date) {
                     for ($current_ts = $from_date; $current_ts <= $to_date; $current_ts += 60 * 60 * 24) {
                         $dates[] = date('Y-m-d', $current_ts);
                     }
                     unset($current_ts);
                 }
                 unset($from_date);
                 unset($to_date);
             }
             unset($edate);
             $used_entries = array();
         }
         unset($date);
         //Recurring events
         if (isset($display->frm_repeat_event_field_id) && is_numeric($display->frm_repeat_event_field_id)) {
             if (isset($entry->metas)) {
                 //When is $entry->metas not set? Is it when posts are created?
                 $repeat_period = isset($entry->metas[$display->frm_repeat_event_field_id]) ? $entry->metas[$display->frm_repeat_event_field_id] : false;
                 $stop_repeat = isset($entry->metas[$display->frm_repeat_edate_field_id]) ? $entry->metas[$display->frm_repeat_edate_field_id] : false;
             } else {
                 //Test this else section
                 $repeat_period = $frm_entry_meta->get_entry_meta_by_field($entry->id, $display->frm_repeat_event_field_id);
                 $stop_repeat = $frm_entry_meta->get_entry_meta_by_field($entry->id, $display->frm_repeat_edate_field_id);
             }
             //If site is not set to English, convert day(s), week(s), month(s), and year(s) (in repeat_period string) to English
             //Check for a few common repeat periods like daily, weekly, monthly, and yearly as well
             $t_strings = array(__('day', 'formidable'), __('days', 'formidable'), __('daily', 'formidable'), __('week', 'formidable'), __('weeks', 'formidable'), __('weekly', 'formidable'), __('month', 'formidable'), __('months', 'formidable'), __('monthly', 'formidable'), __('year', 'formidable'), __('years', 'formidable'), __('yearly', 'formidable'));
             $t_strings = apply_filters('frm_recurring_strings', $t_strings, $display);
             $e_strings = array('day', 'days', '1 day', 'week', 'weeks', '1 week', 'month', 'months', '1 month', 'year', 'years', '1 year');
             if ($t_strings != $e_strings) {
                 $repeat_period = str_ireplace($t_strings, $e_strings, $repeat_period);
             }
             unset($t_strings, $e_strings);
             //Switch [frmcal-date] for current calendar date (for use in "Third Wednesday of [frmcal-date]")
             $repeat_period = str_replace('[frmcal-date]', $year . '-' . $month . '-01', $repeat_period);
             //Filter for repeat_period
             $repeat_period = apply_filters('frm_repeat_period', $repeat_period, $display);
             //If repeat period is set and is valid
             if (!empty($repeat_period) && is_numeric(strtotime($repeat_period))) {
                 //Set up end date to minimize dates array - allow for no end repeat field set, nothing selected for end, or any date
                 if (isset($display->frm_repeat_edate_field_id) && !empty($stop_repeat)) {
                     //If field is selected for recurring end date and the date is not empty
                     $maybe_stop_repeat = strtotime($stop_repeat);
                 }
                 //Repeat until next viewable month
                 $cal_date = $year . '-' . $month . '-01';
                 $stop_repeat = strtotime('+1 month', strtotime($cal_date));
                 //If the repeat should end before $stop_repeat (+1 month), use $maybe_stop_repeat
                 if (isset($maybe_stop_repeat) && $maybe_stop_repeat < $stop_repeat) {
                     $stop_repeat = $maybe_stop_repeat;
                     unset($maybe_stop_repeat);
                 }
                 $temp_dates = array();
                 foreach ($dates as $d) {
                     $last_i = 0;
                     for ($i = strtotime($d); $i <= $stop_repeat; $i = strtotime($repeat_period, $i)) {
                         //Break endless loop
                         if ($i == $last_i) {
                             break;
                         }
                         $last_i = $i;
                         //Add to dates array
                         $temp_dates[] = date('Y-m-d', $i);
                     }
                     unset($last_i);
                     unset($d);
                 }
                 $dates = $temp_dates;
                 unset($repeat_period, $to_date, $start_date, $stop_repeat, $temp_dates);
             }
         }
         $dates = apply_filters('frm_show_entry_dates', $dates, $entry);
         for ($i = 0; $i < $maxday + $startday; $i++) {
             $day = $i - $startday + 1;
             if (in_array(date('Y-m-d', strtotime("{$year}-{$month}-{$day}")), $dates)) {
                 $daily_entres[$i][] = $entry;
             }
             unset($day);
         }
         unset($dates);
     }
     $day_names = $wp_locale->weekday_abbrev;
     $day_names = FrmProAppHelper::reset_keys($day_names);
     //switch keys to order
     if ($week_begins) {
         for ($i = $week_begins; $i < $week_begins + 7; $i++) {
             if (!isset($day_names[$i])) {
                 $day_names[$i] = $day_names[$i - 7];
             }
         }
         unset($i);
     }
     ob_start();
     include FrmAppHelper::plugin_path() . '/pro/classes/views/displays/calendar.php';
     $content = ob_get_contents();
     ob_end_clean();
     return $content;
 }
Exemplo n.º 13
0
 public static function entry_created($entry_id, $form_id, $create = true)
 {
     if (defined('WP_IMPORTING')) {
         return;
     }
     global $frm_field, $frm_entry, $frm_entry_meta, $frmpro_settings;
     $frm_form = new FrmForm();
     $form = $frm_form->getOne($form_id);
     if (!$form) {
         return;
     }
     $form_options = maybe_unserialize($form->options);
     $entry = $frm_entry->getOne($entry_id, true);
     if (!$entry or $entry->form_id != $form_id or $entry->is_draft) {
         return;
     }
     $sent_to = array();
     $notifications = isset($form_options['notification']) ? $form_options['notification'] : array(0 => $form_options);
     $fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
     $temp_fields = array();
     foreach ($fields as $k => $f) {
         if (!isset($entry->metas[$f->id])) {
             $f->field_options = maybe_unserialize($f->field_options);
             if (isset($f->field_options['post_field']) and !empty($f->field_options['post_field'])) {
                 //get value from linked post
                 $entry->metas[$f->id] = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $f, array('links' => false));
                 if ($entry->metas[$f->id] == '') {
                     //and !include_blank
                     unset($entry->metas[$f->id]);
                 }
                 //}else if(include_blank){
                 //    $entry->metas[$f->id] = '';
             }
         }
         $temp_fields[$f->id] = $f;
         unset($fields[$k]);
         unset($k);
         unset($f);
     }
     $fields = $temp_fields;
     unset($temp_fields);
     $frm_notification = new FrmNotification();
     foreach ($notifications as $email_key => $notification) {
         if (isset($notification['update_email'])) {
             if ($create and $notification['update_email'] == 2) {
                 continue;
             }
             if (!$create and empty($notification['update_email'])) {
                 continue;
             }
         }
         //check if conditions are met
         $stop = self::conditions_met($notification, $entry);
         if ($stop) {
             continue;
         }
         unset($stop);
         $to_email = explode(',', $notification['email_to']);
         $email_fields = isset($notification['also_email_to']) ? (array) $notification['also_email_to'] : array();
         $email_fields = array_merge($email_fields, $to_email);
         $entry_ids = array($entry->id);
         $exclude_fields = array();
         foreach ($email_fields as $key => $email_field) {
             $email_field = str_replace(array('[', ']'), '', trim($email_field));
             if (is_numeric($email_field)) {
                 $email_fields[$key] = (int) $email_field;
             }
             if (preg_match('/|/', $email_field)) {
                 $email_opt = explode('|', $email_field);
                 if (isset($email_opt[1])) {
                     if (isset($entry->metas[$email_opt[0]])) {
                         $add_id = $entry->metas[$email_opt[0]];
                         $add_id = maybe_unserialize($add_id);
                         if (is_array($add_id)) {
                             foreach ($add_id as $add) {
                                 $entry_ids[] = $add;
                             }
                         } else {
                             $entry_ids[] = $add_id;
                         }
                     }
                     //skip the data field if it will be fetched through the other form
                     $exclude_fields[] = $email_opt[0];
                     $email_fields[$key] = (int) $email_opt[1];
                 }
                 unset($email_opt);
             }
         }
         if (empty($to_email) and empty($email_fields)) {
             continue;
         }
         foreach ($email_fields as $email_field) {
             if (isset($notification['reply_to_name']) and preg_match('/|/', $email_field)) {
                 $email_opt = explode('|', $notification['reply_to_name']);
                 if (isset($email_opt[1])) {
                     if (isset($entry->metas[$email_opt[0]])) {
                         $entry_ids[] = $entry->metas[$email_opt[0]];
                     }
                     //skip the data field if it will be fetched through the other form
                     $exclude_fields[] = $email_opt[0];
                 }
                 unset($email_opt);
             }
         }
         $where = '';
         if (!empty($exclude_fields)) {
             $where = " and it.field_id not in (" . implode(',', $exclude_fields) . ")";
         }
         $values = $frm_entry_meta->getAll("it.field_id != 0 and it.item_id in (" . implode(',', $entry_ids) . ")" . $where, " ORDER BY fi.field_order");
         $to_emails = $to_email ? $to_email : array();
         $plain_text = (isset($notification['plain_text']) and $notification['plain_text']) ? true : false;
         $custom_message = false;
         $mail_body = '';
         if (isset($notification['email_message']) and trim($notification['email_message']) != '') {
             if (isset($notification['ar']) and $notification['ar']) {
                 //don't continue with blank autoresponder message for reverse compatability
                 if ($notification['email_message'] == '') {
                     continue;
                 }
                 $notification['email_message'] = apply_filters('frm_ar_message', $notification['email_message'], array('entry' => $entry, 'form' => $form));
             }
             $custom_message = true;
             $shortcodes = FrmProAppHelper::get_shortcodes($notification['email_message'], $entry->form_id);
             $mail_body = FrmProFieldsHelper::replace_shortcodes($notification['email_message'], $entry, $shortcodes);
         }
         $reply_to_name = $frm_blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
         //default sender name
         $odd = true;
         $attachments = array();
         foreach ($values as $value) {
             $field = isset($fields[$value->field_id]) ? $fields[$value->field_id] : false;
             $prev_val = maybe_unserialize($value->meta_value);
             if ($value->field_type == 'file') {
                 global $frmdb;
                 if ($field) {
                     $file_options = $field->field_options;
                 } else {
                     $file_options = $frmdb->get_var($frmdb->fields, array('id' => $value->field_id), 'field_options');
                 }
                 $file_options = maybe_unserialize($file_options);
                 if (isset($file_options['attach']) and $file_options['attach']) {
                     foreach ((array) $prev_val as $m) {
                         $file = get_post_meta($m, '_wp_attached_file', true);
                         if ($file) {
                             if (!isset($uploads) or !isset($uploads['basedir'])) {
                                 $uploads = wp_upload_dir();
                             }
                             $attachments[] = $uploads['basedir'] . "/{$file}";
                         }
                         unset($m);
                     }
                 }
                 unset($file_options);
             }
             $val = apply_filters('frm_email_value', $prev_val, $value, $entry);
             if ($value->field_type == 'textarea' and !$plain_text) {
                 $val = str_replace(array("\r\n", "\r", "\n"), ' <br/>', $val);
             }
             if (is_array($val)) {
                 $val = implode(', ', $val);
             }
             if (isset($notification['reply_to']) and (int) $notification['reply_to'] == $value->field_id) {
                 if ($value->field_type == 'user_id') {
                     $user_data = get_userdata($value->meta_value);
                     $reply_to = $user_data->user_email;
                 } else {
                     if (is_email($val)) {
                         $reply_to = $val;
                     } else {
                         if (is_email($prev_val)) {
                             $reply_to = $prev_val;
                         }
                     }
                 }
             }
             if (isset($notification['reply_to_name']) and (int) $notification['reply_to_name'] == $value->field_id) {
                 if ($value->field_type == 'user_id') {
                     $user_data = get_userdata($value->meta_value);
                     $reply_to_name = $user_data->display_name;
                 } else {
                     $reply_to_name = $val;
                 }
             }
             if (in_array($value->field_id, $email_fields)) {
                 if ($value->field_type == 'user_id') {
                     $user_data = get_userdata($value->meta_value);
                     $to_emails[] = $user_data->user_email;
                 } else {
                     $val = explode(',', $val);
                     $prev_val = explode(',', $prev_val);
                     if (is_array($val) or is_array($prev_val)) {
                         foreach ((array) $val as $v) {
                             $v = trim($v);
                             if (is_email($v)) {
                                 $to_emails[] = $v;
                             }
                             unset($v);
                         }
                         foreach ((array) $prev_val as $v) {
                             $v = trim($v);
                             if (is_email($v) and !in_array($v, $to_emails)) {
                                 $to_emails[] = $v;
                             }
                             unset($v);
                         }
                     } else {
                         if (is_email($val)) {
                             $to_emails[] = $val;
                         } else {
                             if (is_email($prev_val)) {
                                 $to_emails[] = $prev_val;
                             }
                         }
                     }
                 }
             }
         }
         unset($prev_val);
         $attachments = apply_filters('frm_notification_attachment', $attachments, $form, array('entry' => $entry, 'email_key' => $email_key));
         if (isset($notification['ar']) and $notification['ar']) {
             $attachments = apply_filters('frm_autoresponder_attachment', array(), $form);
         }
         if (!isset($reply_to)) {
             $reply_to = '[admin_email]';
         }
         if ($notification['reply_to'] == 'custom') {
             $reply_to = isset($notification['cust_reply_to']) ? $notification['cust_reply_to'] : $reply_to;
         }
         if (empty($reply_to)) {
             $reply_to = '[admin_email]';
             //global $frm_settings;
             //$reply_to = $frm_settings->email_to;
         }
         if ($notification['reply_to_name'] == 'custom') {
             $reply_to_name = isset($notification['cust_reply_to_name']) ? $notification['cust_reply_to_name'] : $reply_to_name;
             $reply_to_name = apply_filters('frm_content', $reply_to_name, $form, $entry_id);
         }
         $prev_mail_body = $mail_body;
         $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array('id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text, 'fields' => $fields, 'user_info' => isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false));
         if (isset($notification['inc_user_info']) && $notification['inc_user_info'] && $prev_mail_body == $mail_body) {
             $data = maybe_unserialize($entry->description);
             $mail_body .= "\r\n\r\n" . __('User Information', 'formidable') . "\r\n";
             $mail_body .= __('IP Address', 'formidable') . ": " . $entry->ip . "\r\n";
             $mail_body .= __('User-Agent (Browser/OS)', 'formidable') . ": " . $data['browser'] . "\r\n";
             $mail_body .= __('Referrer', 'formidable') . ": " . $data['referrer'] . "\r\n";
         }
         unset($prev_mail_body);
         if (isset($notification['email_subject']) and $notification['email_subject'] != '') {
             $shortcodes = FrmProAppHelper::get_shortcodes($notification['email_subject'], $entry->form_id);
             $subject = FrmProFieldsHelper::replace_shortcodes($notification['email_subject'], $entry, $shortcodes);
             $subject = apply_filters('frm_email_subject', $subject, compact('form', 'entry', 'email_key'));
             if (isset($notification['ar']) and $notification['ar']) {
                 $subject = apply_filters('frm_ar_subject', $subject, $form);
             }
         } else {
             //set default subject
             $subject = sprintf(__('%1$s Form submitted on %2$s', 'formidable'), $form->name, $frm_blogname);
         }
         $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form_id, compact('email_key', 'entry'));
         $to_emails = array_unique((array) $to_emails);
         $sent = array();
         foreach ((array) $to_emails as $to_email) {
             $to_email = apply_filters('frm_content', $to_email, $form, $entry_id);
             $to_email = do_shortcode($to_email);
             if (strpos($to_email, ',')) {
                 $to_email = explode(',', $to_email);
             }
             foreach ((array) $to_email as $e) {
                 $e = trim($e);
                 if (($e == '[admin_email]' or is_email($e)) and !in_array($e, $sent)) {
                     $sent_to[] = $sent[] = $e;
                     $frm_notification->send_notification_email($e, $subject, $mail_body, $reply_to, $reply_to_name, $plain_text, $attachments);
                 } else {
                     if (!in_array($e, $sent)) {
                         do_action('frm_send_to_not_email', compact('e', 'subject', 'mail_body', 'reply_to', 'reply_to_name', 'plain_text', 'attachments', 'form', 'email_key'));
                     }
                 }
                 unset($e);
             }
             unset($to_email);
         }
         unset($sent, $to_emails, $notification, $subject, $mail_body);
         unset($reply_to, $reply_to_name, $plain_text, $attachments);
     }
     return $sent_to;
 }
Exemplo n.º 14
0
 function ajax_get_data($entry_id, $field_id, $current_field)
 {
     global $frm_entry_meta, $frm_field;
     $data_field = $frm_field->getOne($field_id);
     $current = $frm_field->getOne($current_field);
     $meta_value = FrmProEntryMetaHelper::get_post_or_meta_value($entry_id, $data_field);
     $value = FrmProFieldsHelper::get_display_value($meta_value, $data_field);
     if ($value and !empty($value)) {
         echo "<p class='frm_show_it'>" . $value . "</p>\n";
     }
     echo '<input type="hidden" id="field_' . $current->field_key . '" name="item_meta[' . $current_field . ']" value="' . stripslashes(esc_attr($meta_value)) . '"/>';
     die;
 }
Exemplo n.º 15
0
 private static function get_repeating_dates($entry, $display, $args, array &$dates)
 {
     if (!is_numeric($display->frm_repeat_event_field_id)) {
         return;
     }
     //Get meta values for repeat field and end repeat field
     if (isset($entry->metas[$display->frm_repeat_event_field_id])) {
         $repeat_period = $entry->metas[$display->frm_repeat_event_field_id];
     } else {
         $repeat_field = FrmField::getOne($display->frm_repeat_event_field_id);
         $repeat_period = FrmProEntryMetaHelper::get_post_or_meta_value($entry->id, $repeat_field);
         unset($repeat_field);
     }
     if (isset($entry->metas[$display->frm_repeat_edate_field_id])) {
         $stop_repeat = $entry->metas[$display->frm_repeat_edate_field_id];
     } else {
         $stop_field = FrmField::getOne($display->frm_repeat_edate_field_id);
         $stop_repeat = FrmProEntryMetaHelper::get_post_or_meta_value($entry->id, $stop_field);
         unset($stop_field);
     }
     //If site is not set to English, convert day(s), week(s), month(s), and year(s) (in repeat_period string) to English
     //Check for a few common repeat periods like daily, weekly, monthly, and yearly as well
     $t_strings = array(__('day', 'formidable'), __('days', 'formidable'), __('daily', 'formidable'), __('week', 'formidable'), __('weeks', 'formidable'), __('weekly', 'formidable'), __('month', 'formidable'), __('months', 'formidable'), __('monthly', 'formidable'), __('year', 'formidable'), __('years', 'formidable'), __('yearly', 'formidable'));
     $t_strings = apply_filters('frm_recurring_strings', $t_strings, $display);
     $e_strings = array('day', 'days', '1 day', 'week', 'weeks', '1 week', 'month', 'months', '1 month', 'year', 'years', '1 year');
     if ($t_strings != $e_strings) {
         $repeat_period = str_ireplace($t_strings, $e_strings, $repeat_period);
     }
     unset($t_strings, $e_strings);
     //Switch [frmcal-date] for current calendar date (for use in "Third Wednesday of [frmcal-date]")
     $repeat_period = str_replace('[frmcal-date]', $args['year'] . '-' . $args['month'] . '-01', $repeat_period);
     //Filter for repeat_period
     $repeat_period = apply_filters('frm_repeat_period', $repeat_period, $display);
     //If repeat period is set and is valid
     if (empty($repeat_period) || !is_numeric(strtotime($repeat_period))) {
         return;
     }
     //Set up end date to minimize dates array - allow for no end repeat field set, nothing selected for end, or any date
     if (!empty($stop_repeat)) {
         //If field is selected for recurring end date and the date is not empty
         $maybe_stop_repeat = strtotime($stop_repeat);
     }
     //Repeat until next viewable month
     $cal_date = $args['year'] . '-' . $args['month'] . '-01';
     $stop_repeat = strtotime('+1 month', strtotime($cal_date));
     //If the repeat should end before $stop_repeat (+1 month), use $maybe_stop_repeat
     if (isset($maybe_stop_repeat) && $maybe_stop_repeat < $stop_repeat) {
         $stop_repeat = $maybe_stop_repeat;
         unset($maybe_stop_repeat);
     }
     $temp_dates = array();
     foreach ($dates as $d) {
         $last_i = 0;
         for ($i = strtotime($d); $i <= $stop_repeat; $i = strtotime($repeat_period, $i)) {
             //Break endless loop
             if ($i == $last_i) {
                 break;
             }
             $last_i = $i;
             //Add to dates array
             $temp_dates[] = date('Y-m-d', $i);
         }
         unset($last_i, $d);
     }
     $dates = $temp_dates;
 }