Пример #1
0
 /**
  * @return object form
  */
 public static function getOne($id, $blog_id = false)
 {
     global $wpdb;
     if ($blog_id && is_multisite()) {
         global $wpmuBaseTablePrefix;
         $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix($blog_id);
         $table_name = $prefix . 'frm_forms';
     } else {
         $table_name = $wpdb->prefix . 'frm_forms';
         $cache = wp_cache_get($id, 'frm_form');
         if ($cache) {
             if (isset($cache->options)) {
                 $cache->options = maybe_unserialize($cache->options);
             }
             return stripslashes_deep($cache);
         }
     }
     if (is_numeric($id)) {
         $where = array('id' => $id);
     } else {
         $where = array('form_key' => $id);
     }
     $results = FrmDb::get_row($table_name, $where);
     if (isset($results->options)) {
         wp_cache_set($results->id, $results, 'frm_form');
         $results->options = maybe_unserialize($results->options);
     }
     return stripslashes_deep($results);
 }
 public static function ajax_destroy($form_id = false, $ajax = true, $echo = true)
 {
     global $wpdb, $frm_vars;
     $entry_key = FrmAppHelper::get_param('entry', '', 'get', 'sanitize_title');
     if (!$form_id) {
         $form_id = FrmAppHelper::get_param('form_id', '', 'get', 'absint');
     }
     if (!$entry_key) {
         return;
     }
     if (isset($frm_vars['deleted_entries']) && is_array($frm_vars['deleted_entries']) && in_array($entry_key, $frm_vars['deleted_entries'])) {
         return;
     }
     if (is_numeric($entry_key)) {
         $where = array('id' => $entry_key);
     } else {
         $where = array('item_key' => $entry_key);
     }
     $entry = FrmDb::get_row($wpdb->prefix . 'frm_items', $where, 'id, form_id, is_draft, user_id');
     unset($where);
     if (!$entry || $form_id && $entry->form_id != (int) $form_id) {
         return;
     }
     $message = self::maybe_delete_entry($entry);
     if ($message && !is_numeric($message)) {
         if ($echo) {
             echo '<div class="frm_message">' . $message . '</div>';
         }
         return;
     }
     if (!isset($frm_vars['deleted_entries']) || empty($frm_vars['deleted_entries'])) {
         $frm_vars['deleted_entries'] = array();
     }
     $frm_vars['deleted_entries'][] = $entry->id;
     if ($ajax && $echo) {
         echo $message = 'success';
     } else {
         if (!$ajax) {
             $message = apply_filters('frm_delete_message', __('Your entry was successfully deleted', 'formidable'), $entry);
             if ($echo) {
                 echo '<div class="frm_message">' . $message . '</div>';
             }
         } else {
             $message = '';
         }
     }
     return $message;
 }
Пример #3
0
 public static function get_form_custom_display($form_id)
 {
     global $wpdb;
     $display_ids = self::get_display_ids_by_form($form_id);
     if (!$display_ids) {
         return false;
     }
     $display = FrmDb::get_row($wpdb->posts . ' p LEFT JOIN ' . $wpdb->postmeta . ' pm ON (p.ID = pm.post_ID)', array('pm.meta_key' => 'frm_show_count', 'post_type' => 'frm_display', 'p.ID' => $display_ids, 'pm.meta_value' => array('dynamic', 'calendar', 'one'), 'p.post_status' => 'publish'), 'p.*', array('order_by' => 'p.ID ASC'));
     return $display;
 }
 /**
  * Get values for user ID graph
  *
  * @since 2.0
  *
  * @param array $values
  * @param array $labels
  * @param array $tooltips
  * @param boolean $pie - boolean for pie graph
  * @param array $temp_values - temporary values
  * @param object $field
  */
 public static function get_user_id_values(&$values, &$labels, &$tooltips, &$pie, $temp_values, $field)
 {
     global $wpdb;
     // Get form options
     $form = FrmDb::get_row($wpdb->prefix . 'frm_forms', array('id' => $field->form_id));
     $form_options = maybe_unserialize($form->options);
     // Remove deleted users from values and show display name instead of user ID number
     foreach ($temp_values as $user_id => $count) {
         $user_info = get_userdata($user_id);
         if (!$user_info) {
             unset($temp_values[$user_id]);
             continue;
         }
         $labels[] = $user_info ? $user_info->display_name : __('Deleted User', 'formidable');
         $values[] = $count;
     }
     // If only one response per user, do a pie chart of users who have submitted the form
     if (isset($form_options['single_entry']) && $form_options['single_entry'] && isset($form_options['single_entry_type']) && $form_options['single_entry_type'] == 'user') {
         // Get number of users on site
         $total_users = count(get_users());
         // Get number of users that have completed entries
         $id_count = count($values);
         // Get the difference
         $not_completed = (int) $total_users - (int) $id_count;
         $labels = array(__('Completed', 'formidable'), __('Not Completed', 'formidable'));
         $temp_values = array($id_count, $not_completed);
         $pie = true;
     } else {
         if (count($labels) < 10) {
             $pie = true;
         }
     }
     $values = $temp_values;
 }
 function _get_expected_entry_result($test, $entry_id)
 {
     if ($test > 0 && $test < 5) {
         $e_result = FrmDb::get_row('frm_items', array('id' => $entry_id), 'post_id, id', array('order_by' => 'created_at DESC'));
     } else {
         if ($test >= 5) {
             $e_result = false;
         }
     }
     return $e_result;
 }
 public static function get_content($content)
 {
     global $post;
     if (!$post) {
         return $content;
     }
     $entry_id = false;
     $filter = apply_filters('frm_filter_auto_content', true);
     if ($post->post_type == self::$post_type && in_the_loop()) {
         global $frm_displayed;
         if (!$frm_displayed) {
             $frm_displayed = array();
         }
         if (in_array($post->ID, $frm_displayed)) {
             return $content;
         }
         $frm_displayed[] = $post->ID;
         return self::get_display_data($post, $content, false, compact('filter'));
     }
     if (is_singular() && post_password_required()) {
         return $content;
     }
     $display_id = get_post_meta($post->ID, 'frm_display_id', true);
     if (!$display_id || !is_single() && !is_page()) {
         return $content;
     }
     $display = FrmProDisplay::getOne($display_id);
     if (!$display) {
         return $content;
     }
     global $frm_displayed, $frm_display_position;
     if ($post->post_type != self::$post_type) {
         $display = FrmProDisplaysHelper::setup_edit_vars($display, false);
     }
     if (!isset($display->frm_insert_pos)) {
         $display->frm_insert_pos = 1;
     }
     if (!$frm_displayed) {
         $frm_displayed = array();
     }
     if (!$frm_display_position) {
         $frm_display_position = array();
     }
     if (!isset($frm_display_position[$display->ID])) {
         $frm_display_position[$display->ID] = 0;
     }
     $frm_display_position[$display->ID]++;
     //make sure this isn't loaded multiple times but still works with themes and plugins that call the_content multiple times
     if (!in_the_loop() || in_array($display->ID, (array) $frm_displayed) || $frm_display_position[$display->ID] < (int) $display->frm_insert_pos) {
         return $content;
     }
     global $wpdb;
     //get the entry linked to this post
     if ((is_single() || is_page()) && $post->post_type != self::$post_type && ($display->frm_insert_loc == 'none' || $display->frm_insert_loc != 'none' && $display->frm_post_id != $post->ID)) {
         $entry = FrmDb::get_row('frm_items', array('post_id' => $post->ID), 'id, item_key');
         if (!$entry) {
             return $content;
         }
         $entry_id = $entry->id;
         if (in_array($display->frm_show_count, array('dynamic', 'calendar')) && $display->frm_type == 'display_key') {
             $entry_id = $entry->item_key;
         }
     }
     $frm_displayed[] = $display->ID;
     $content = self::get_display_data($display, $content, $entry_id, array('filter' => $filter, 'auto_id' => $entry_id));
     return $content;
 }