public static function getRecordCount($where = '') { global $wpdb; $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; if (is_numeric($where)) { $table_join = 'frm_items'; $where = array('form_id' => $where); } if (is_array($where)) { $count = FrmDb::get_count($table_join, $where); } else { global $wpdb; $cache_key = 'count_' . maybe_serialize($where); $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmAppHelper::prepend_and_or_where(' WHERE ', $where); $count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var'); } return $count; }
public static function get_field($field = 'is_draft', $id) { $entry = FrmAppHelper::check_cache($id, 'frm_entry'); if ($entry && isset($entry->{$field})) { return $entry->{$field}; } $var = FrmDb::get_var('frm_items', array('id' => $id), $field); return $var; }
public static function get_var($table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var') { $group = ''; self::get_group_and_table_name($table, $group); self::convert_options_to_array($args, '', $limit); $query = 'SELECT ' . $field . ' FROM ' . $table; if (is_array($where) || empty($where)) { // only separate into array values and query string if is array self::get_where_clause_and_values($where); global $wpdb; $query = $wpdb->prepare($query . $where['where'] . ' ' . implode(' ', $args), $where['values']); } else { /** * Allow the $where to be prepared before we recieve it here. * This is a fallback for reverse compatability, but is not recommended */ _deprecated_argument('where', '2.0', __('Use the query in an array format so it can be properly prepared.', 'formidable')); $query .= $where . ' ' . implode(' ', $args); } $cache_key = str_replace(array(' ', ','), '_', trim(implode('_', FrmAppHelper::array_flatten($where)) . implode('_', $args) . $field . '_' . $type, ' WHERE')); $results = FrmAppHelper::check_cache($cache_key, $group, $query, 'get_' . $type); return $results; }
public function get_all($form_id = false, $limit = 99) { if ($form_id) { $this->form_id = $form_id; } $type = $this->id_base; global $frm_vars; $frm_vars['action_type'] = $type; add_filter('posts_where', 'FrmFormActionsController::limit_by_type'); $query = self::action_args($form_id, $limit); $query['post_status'] = 'any'; $query['suppress_filters'] = false; $actions = FrmAppHelper::check_cache(serialize($query) . '_type_' . $type, 'frm_actions', $query, 'get_posts'); unset($query); remove_filter('posts_where', 'FrmFormActionsController::limit_by_type'); if (empty($actions)) { return array(); } $settings = array(); foreach ($actions as $action) { if (count($settings) >= $limit) { continue; } $action = $this->prepare_action($action); $settings[$action->ID] = $action; } if (1 === $limit) { $settings = reset($settings); } return $settings; }
public static function getIds($where = '', $order_by = '', $limit = '') { _deprecated_function(__FUNCTION__, '2.0'); global $wpdb; if (!empty($order_by) && !strpos($order_by, 'ORDER BY') !== false) { $order_by = ' ORDER BY ' . $order_by; } $query = 'SELECT fi.id FROM ' . $wpdb->prefix . 'frm_fields fi ' . 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON fi.form_id=fr.id' . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; $method = $limit == ' LIMIT 1' || $limit == 1 ? 'get_var' : 'get_col'; $cache_key = 'getIds_' . maybe_serialize($where) . $order_by . $limit; $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); return $results; }
public function get_all($orderby = 'title', $order = 'ASC', $limit = 99) { $post_atts = array('post_type' => FrmStylesController::$post_type, 'post_status' => 'publish', 'numberposts' => $limit, 'orderby' => $orderby, 'order' => $order); $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts'); if (empty($temp_styles)) { global $wpdb; // make sure there wasn't a conflict with the query $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish'); $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results'); if (empty($temp_styles)) { // create a new style if there are none $new = $this->get_new(); $new->post_title = $new->post_name = __('Formidable Style', 'formidable'); $new->menu_order = 1; $new = $this->save((array) $new); $this->update('default'); $post_atts['include'] = $new; $temp_styles = get_posts($post_atts); } } $default_values = $this->get_defaults(); $default_style = false; $styles = array(); foreach ($temp_styles as $style) { $this->id = $style->ID; if ($style->menu_order) { if ($default_style) { // only return one default $style->menu_order = 0; } else { // check for a default style $default_style = $style->ID; } } $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); // fill default values $style->post_content = $this->override_defaults($style->post_content); $style->post_content = wp_parse_args($style->post_content, $default_values); $styles[$style->ID] = $style; } if (!$default_style) { $default_style = reset($styles); $styles[$default_style->ID]->menu_order = 1; } return $styles; }
/** * @param int $id * @return string form key */ public static function &getKeyById($id) { $id = (int) $id; $cache = FrmAppHelper::check_cache($id, 'frm_form'); if ($cache) { return $cache->form_key; } $key = FrmDb::get_var('frm_forms', array('id' => $id), 'form_key'); return $key; }
public static function getEntryIds($where = array(), $order_by = '', $limit = '', $unique = true, $args = array()) { $defaults = array('is_draft' => false, 'user_id' => '', 'group_by' => ''); $args = wp_parse_args($args, $defaults); $query = array(); self::get_ids_query($where, $order_by, $limit, $unique, $args, $query); $query = implode(' ', $query); $cache_key = 'ids_' . maybe_serialize($where) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize($args); $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, $limit == ' LIMIT 1' ? 'get_var' : 'get_col'); return $results; }
/** * Copy forms that are set to copy from one site to another */ private static function copy_forms($force) { if (!$force) { //don't check on every page load $last_checked = get_option('frmpro_copies_checked'); if (!$last_checked || time() - $last_checked >= 60 * 60) { //check every hour $force = true; } } if (!$force) { return; } global $wpdb, $blog_id; //get all forms to be copied from global table $query = $wpdb->prepare('SELECT c.*, p.post_name FROM ' . self::table_name() . ' c LEFT JOIN ' . $wpdb->prefix . 'frm_forms f ON (c.copy_key = f.form_key) LEFT JOIN ' . $wpdb->posts . ' p ON (c.copy_key = p.post_name) WHERE blog_id != %d AND ((type = %s AND f.form_key is NULL) OR (type = %s AND p.post_name is NULL)) ORDER BY type DESC', $blog_id, 'form', 'display'); $templates = FrmAppHelper::check_cache('all_templates_' . $blog_id, 'frm_copy', $query, 'get_results'); foreach ($templates as $temp) { if ($temp->type == 'form') { FrmForm::duplicate($temp->form_id, false, true, $temp->blog_id); continue; } $values = FrmProDisplay::getOne($temp->form_id, $temp->blog_id, true); if (!$values || 'trash' == $values->post_status) { continue; } // check if post with slug already exists $post_name = wp_unique_post_slug($values->post_name, 0, 'publish', 'frm_display', 0); if ($post_name != $values->post_name) { continue; } if ($values->post_name != $temp->copy_key) { $wpdb->update(self::table_name(), array('copy_key' => $values->post_name), array('id' => $temp->id)); } FrmProDisplay::duplicate($temp->form_id, true, $temp->blog_id); //TODO: replace any ids with field keys in the display before duplicated unset($temp); } update_option('frmpro_copies_checked', time()); }
/** * Get the associative array results for the given columns, table, and where query * * @since 2.02.05 * @param string $columns * @param string $table * @param array $where * @return mixed */ public static function get_associative_array_results($columns, $table, $where) { $group = ''; self::get_group_and_table_name($table, $group); $query = self::generate_query_string_from_pieces($columns, $table, $where); $cache_key = str_replace(array(' ', ','), '_', trim(implode('_', FrmAppHelper::array_flatten($where)) . $columns . '_results_ARRAY_A', ' WHERE')); $results = FrmAppHelper::check_cache($cache_key, $group, $query, 'get_associative_results'); return $results; }