本文整理汇总了PHP中FrmDb类的典型用法代码示例。如果您正苦于以下问题:PHP FrmDb类的具体用法?PHP FrmDb怎么用?PHP FrmDb使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FrmDb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
public static function install($force = false)
{
$db_version = 1.2;
// this is the version of the database we're moving to
$old_db_version = get_site_option('frmpro_copies_db_version');
global $wpdb;
if ($db_version != $old_db_version || $force) {
$force = true;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$frmdb = new FrmDb();
$charset_collate = $frmdb->collation();
/* Create/Upgrade Display Table */
$sql = 'CREATE TABLE ' . self::table_name() . ' (
id int(11) NOT NULL auto_increment,
type varchar(255) default NULL,
copy_key varchar(255) default NULL,
form_id int(11) default NULL,
blog_id int(11) default NULL,
created_at datetime NOT NULL,
PRIMARY KEY id (id),
KEY form_id (form_id),
KEY blog_id (blog_id)
) ' . $charset_collate . ';';
dbDelta($sql);
update_site_option('frmpro_copies_db_version', $db_version);
}
self::copy_forms($force);
}
示例2: test_uninstall
/**
* @covers FrmDb::uninstall
*/
public function test_uninstall()
{
$this->set_as_user_role('administrator');
$frmdb = new FrmDb();
$uninstalled = $frmdb->uninstall();
$this->assertTrue($uninstalled);
$this->markTestIncomplete('Make sure uninstall is complete');
$this->do_tables_exist(false);
$this->assertEmpty(get_option('frm_db_version', true));
$this->assertEmpty(get_option('frm_options', true));
// TODO: Check if roles exist FrmAppHelper::frm_capabilities()
// TODO: Check if any posts exist for extra types
// TODO: Check if transients exist: frmpro_css, frm_options, frmpro_options, %frm_form_fields%
}
示例3: form
function form($form_action, $args = array())
{
global $wpdb;
extract($args);
$post_types = FrmProAppHelper::get_custom_post_types();
if (!$post_types) {
return;
}
$post_type = FrmProFormsHelper::post_type($args['values']['id']);
$taxonomies = get_object_taxonomies($post_type);
$action_control = $this;
$echo = true;
$form_id = $form->id;
$display = false;
$displays = array();
$display_ids = FrmDb::get_col($wpdb->postmeta, array('meta_key' => 'frm_form_id', 'meta_value' => $form_id), 'post_ID');
if ($display_ids) {
$query_args = array('pm.meta_key' => 'frm_show_count', 'post_type' => 'frm_display', 'pm.meta_value' => array('dynamic', 'calendar', 'one'), 'p.post_status' => array('publish', 'private'), 'p.ID' => $display_ids);
$displays = FrmDb::get_results($wpdb->posts . ' p LEFT JOIN ' . $wpdb->postmeta . ' pm ON (p.ID = pm.post_ID)', $query_args, 'p.ID, p.post_title', array('order_by' => 'p.post_title ASC'));
if (isset($form_action->post_content['display_id'])) {
// get view from settings
if (is_numeric($form_action->post_content['display_id'])) {
$display = FrmProDisplay::getOne($form_action->post_content['display_id'], false, true);
}
} else {
if (!is_numeric($form_action->post_content['post_content']) && !empty($display_ids)) {
// get auto view
$display = FrmProDisplay::get_form_custom_display($form_id);
if ($display) {
$display = FrmProDisplaysHelper::setup_edit_vars($display, true);
}
}
}
}
// Get array of all custom fields
$custom_fields = array();
if (isset($form_action->post_content['post_custom_fields'])) {
foreach ($form_action->post_content['post_custom_fields'] as $custom_field_opts) {
if (isset($custom_field_opts['meta_name'])) {
$custom_fields[] = $custom_field_opts['meta_name'];
}
unset($custom_field_opts);
}
}
unset($display_ids);
include dirname(__FILE__) . '/post_options.php';
}
示例4: prepare_items
public function prepare_items()
{
global $wpdb, $per_page, $mode;
$mode = empty($_REQUEST['mode']) ? 'list' : $_REQUEST['mode'];
$default_orderby = 'name';
$default_order = 'ASC';
$orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : $default_orderby;
$order = isset($_REQUEST['order']) ? $_REQUEST['order'] : $default_order;
$page = $this->get_pagenum();
$per_page = $this->get_items_per_page('formidable_page_formidable_per_page');
$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : ($page - 1) * $per_page;
$s_query = array();
$s_query[] = array('or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 1);
switch ($this->status) {
case 'template':
$s_query['is_template'] = 1;
$s_query['status !'] = 'trash';
break;
case 'draft':
$s_query['is_template'] = 0;
$s_query['status'] = 'draft';
break;
case 'trash':
$s_query['status'] = 'trash';
break;
default:
$s_query['is_template'] = 0;
$s_query['status !'] = 'trash';
break;
}
$s = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : '';
if ($s != '') {
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
$search_terms = array_map('trim', $matches[0]);
foreach ((array) $search_terms as $term) {
$s_query[] = array('or' => true, 'name LIKE' => $term, 'description LIKE' => $term, 'created_at LIKE' => $term);
unset($term);
}
}
$this->items = FrmForm::getAll($s_query, $orderby . ' ' . $order, $start . ',' . $per_page);
$total_items = FrmDb::get_count('frm_forms', $s_query);
$this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page));
}
示例5: generate_csv
public static function generate_csv($atts)
{
global $frm_vars;
$frm_vars['prevent_caching'] = true;
self::$fields = $atts['form_cols'];
self::$form_id = $atts['form']->id;
self::set_class_paramters();
$filename = apply_filters('frm_csv_filename', date('ymdHis', time()) . '_' . sanitize_title_with_dashes($atts['form']->name) . '_formidable_entries.csv', $atts['form']);
unset($atts['form'], $atts['form_cols']);
self::print_file_headers($filename);
unset($filename);
$comment_count = FrmDb::get_count('frm_item_metas', array('item_id' => $atts['entry_ids'], 'field_id' => 0, 'meta_value like' => '{'), array('group_by' => 'item_id', 'order_by' => 'count(*) DESC', 'limit' => 1));
self::$comment_count = $comment_count;
self::prepare_csv_headings();
// fetch 20 posts at a time rather than loading the entire table into memory
while ($next_set = array_splice($atts['entry_ids'], 0, 20)) {
self::prepare_next_csv_rows($next_set);
}
}
示例6: formidable_shortcode_atts
public static function formidable_shortcode_atts($atts, $all_atts)
{
global $frm_vars, $wpdb;
// reset globals
$frm_vars['readonly'] = $atts['readonly'];
$frm_vars['editing_entry'] = false;
$frm_vars['show_fields'] = array();
$frm_vars['editing_entry'] = false;
if (!is_array($atts['fields'])) {
$frm_vars['show_fields'] = explode(',', $atts['fields']);
}
if (!empty($atts['exclude_fields'])) {
if (!is_array($atts['exclude_fields'])) {
$atts['exclude_fields'] = explode(',', $atts['exclude_fields']);
}
$query = array('form_id' => (int) $atts['id'], 'id NOT' => $atts['exclude_fields'], 'field_key NOT' => $atts['exclude_fields']);
$frm_vars['show_fields'] = FrmDb::get_col($wpdb->prefix . 'frm_fields', $query);
}
if ($atts['entry_id'] && $atts['entry_id'] == 'last') {
$user_ID = get_current_user_id();
if ($user_ID) {
$frm_vars['editing_entry'] = FrmDb::get_var($wpdb->prefix . 'frm_items', array('form_id' => $atts['id'], 'user_id' => $user_ID), 'id', array('order_by' => 'created_at DESC'));
}
} else {
if ($atts['entry_id']) {
$frm_vars['editing_entry'] = $atts['entry_id'];
}
}
foreach ($atts as $unset => $val) {
if (is_array($all_atts) && isset($all_atts[$unset])) {
unset($all_atts[$unset]);
}
unset($unset, $val);
}
if (is_array($all_atts)) {
foreach ($all_atts as $att => $val) {
$_GET[$att] = urlencode($val);
unset($att, $val);
}
}
}
示例7: _deprecated_function
/**
* @param string $table_name
*/
public static function &getRecordCount($where = '', $table_name)
{
_deprecated_function(__FUNCTION__, '2.0', 'FrmDb::get_count');
$count = FrmDb::get_count($table_name, $where);
return $count;
}
示例8: duplicate
public static function duplicate()
{
check_ajax_referer('frm_ajax', 'nonce');
global $wpdb;
$field_id = FrmAppHelper::get_post_param('field_id', 0, 'absint');
$form_id = FrmAppHelper::get_post_param('form_id', 0, 'absint');
$copy_field = FrmField::getOne($field_id);
if (!$copy_field) {
wp_die();
}
do_action('frm_duplicate_field', $copy_field, $form_id);
do_action('frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id);
$values = array('id' => $form_id);
FrmFieldsHelper::fill_field($values, $copy_field, $form_id);
$field_count = FrmDb::get_count($wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array('or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id));
$values['field_order'] = $field_count + 1;
if (!($field_id = FrmField::create($values))) {
wp_die();
}
self::include_single_field($field_id, $values);
wp_die();
}
示例9: generate_xml
public static function generate_xml($type, $args = array())
{
global $wpdb;
$type = (array) $type;
if (in_array('items', $type) && !in_array('forms', $type)) {
// make sure the form is included if there are entries
$type[] = 'forms';
}
if (in_array('forms', $type)) {
// include actions with forms
$type[] = 'actions';
}
$tables = array('items' => $wpdb->prefix . 'frm_items', 'forms' => $wpdb->prefix . 'frm_forms', 'posts' => $wpdb->posts, 'styles' => $wpdb->posts, 'actions' => $wpdb->posts);
$defaults = array('ids' => false);
$args = wp_parse_args($args, $defaults);
$sitename = sanitize_key(get_bloginfo('name'));
if (!empty($sitename)) {
$sitename .= '.';
}
$filename = $sitename . 'formidable.' . date('Y-m-d') . '.xml';
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=' . $filename);
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
//make sure ids are numeric
if (is_array($args['ids']) && !empty($args['ids'])) {
$args['ids'] = array_filter($args['ids'], 'is_numeric');
}
$records = array();
foreach ($type as $tb_type) {
$where = array();
$join = '';
$table = $tables[$tb_type];
$select = $table . '.id';
$query_vars = array();
switch ($tb_type) {
case 'forms':
//add forms
if ($args['ids']) {
$where[] = array('or' => 1, $table . '.id' => $args['ids'], $table . '.parent_form_id' => $args['ids']);
} else {
$where[$table . '.status !'] = 'draft';
}
break;
case 'actions':
$select = $table . '.ID';
$where['post_type'] = FrmFormActionsController::$action_post_type;
if (!empty($args['ids'])) {
$where['menu_order'] = $args['ids'];
}
break;
case 'items':
//$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
if ($args['ids']) {
$where[$table . '.form_id'] = $args['ids'];
}
break;
case 'styles':
// Loop through all exported forms and get their selected style IDs
$form_ids = $args['ids'];
$style_ids = array();
foreach ($form_ids as $form_id) {
$form_data = FrmForm::getOne($form_id);
// For forms that have not been updated while running 2.0, check if custom_style is set
if (isset($form_data->options['custom_style'])) {
$style_ids[] = $form_data->options['custom_style'];
}
unset($form_id, $form_data);
}
$select = $table . '.ID';
$where['post_type'] = 'frm_styles';
// Only export selected styles
if (!empty($style_ids)) {
$where['ID'] = $style_ids;
}
break;
default:
$select = $table . '.ID';
$join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
$where['pm.meta_key'] = 'frm_form_id';
if (empty($args['ids'])) {
$where['pm.meta_value >'] = 1;
} else {
$where['pm.meta_value'] = $args['ids'];
}
break;
}
$records[$tb_type] = FrmDb::get_col($table . $join, $where, $select);
unset($tb_type);
}
echo '<?xml version="1.0" encoding="' . esc_attr(get_bloginfo('charset')) . "\" ?>\n";
include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php';
}
示例10: get_records
function get_records($table, $args = array(), $order_by = '', $limit = '', $fields = '*')
{
global $wpdb;
extract(FrmDb::get_where_clause_and_values($args));
if (!empty($order_by)) {
$order_by = " ORDER BY {$order_by}";
}
if (!empty($limit)) {
$limit = " LIMIT {$limit}";
}
$query = "SELECT {$fields} FROM {$table}{$where}{$order_by}{$limit}";
$query = $wpdb->prepare($query, $values);
return $wpdb->get_results($query);
}
示例11: get_search_ids
public static function get_search_ids($s, $form_id, $args = array())
{
global $wpdb;
if (empty($s)) {
return false;
}
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
$search_terms = array_map('trim', $matches[0]);
$spaces = '';
$e_ids = $p_search = array();
$search = array('or' => 1);
$data_field = FrmProFormsHelper::has_field('data', $form_id, false);
foreach ((array) $search_terms as $term) {
$p_search[] = array($spaces . $wpdb->posts . '.post_title like' => $term, $spaces . $wpdb->posts . '.post_content like' => $term, 'or' => 1);
$search[$spaces . 'meta_value like'] = $term;
$spaces .= ' ';
// add a space to keep the array keys unique
if (is_numeric($term)) {
$e_ids[] = (int) $term;
}
if ($data_field) {
$df_form_ids = array();
//search the joined entry too
foreach ((array) $data_field as $df) {
FrmProFieldsHelper::get_subform_ids($df_form_ids, $df);
unset($df);
}
$data_form_ids = FrmDb::get_col($wpdb->prefix . 'frm_fields', array('id' => $df_form_ids), 'form_id');
unset($df_form_ids);
if ($data_form_ids) {
$data_entry_ids = FrmEntryMeta::getEntryIds(array('fi.form_id' => $data_form_ids, 'meta_value like' => $term));
if ($data_entry_ids) {
if (!isset($search['meta_value'])) {
$search['meta_value'] = array();
}
$search['meta_value'] = array_merge($search['meta_value'], $data_entry_ids);
}
}
unset($data_form_ids);
}
}
$matching_posts = FrmDb::get_col($wpdb->posts, $p_search, 'ID');
$p_ids = array($search, 'or' => 1);
if ($matching_posts) {
$post_ids = FrmDb::get_col($wpdb->prefix . 'frm_items', array('post_id' => $matching_posts, 'form_id' => (int) $form_id));
if ($post_ids) {
$p_ids['item_id'] = $post_ids;
}
}
if (!empty($e_ids)) {
$p_ids['item_id'] = $e_ids;
}
$query = array('fi.form_id' => $form_id);
$query[] = $p_ids;
return FrmEntryMeta::getEntryIds($query, '', '', true, $args);
}
示例12: get_id_by_key
/**
* @param string $key
* @return int entry_id
*/
public static function get_id_by_key($key)
{
$entry_id = FrmDb::get_var('frm_items', array('item_key' => sanitize_title($key)));
return $entry_id;
}
示例13: csv
/**
* Export to CSV
* @since 2.0.19
*/
public static function csv($form_id = false, $search = '', $fid = '')
{
FrmAppHelper::permission_check('frm_view_entries');
if (!$form_id) {
$form_id = FrmAppHelper::get_param('form', '', 'get', 'sanitize_text_field');
$search = FrmAppHelper::get_param(isset($_REQUEST['s']) ? 's' : 'search', '', 'get', 'sanitize_text_field');
$fid = FrmAppHelper::get_param('fid', '', 'get', 'sanitize_text_field');
}
if (!ini_get('safe_mode')) {
set_time_limit(0);
//Remove time limit to execute this function
$mem_limit = str_replace('M', '', ini_get('memory_limit'));
if ((int) $mem_limit < 256) {
ini_set('memory_limit', '256M');
}
}
global $wpdb;
$form = FrmForm::getOne($form_id);
$form_id = $form->id;
$form_cols = self::get_fields_for_csv_export($form_id, $form);
$item_id = FrmAppHelper::get_param('item_id', 0, 'get', 'sanitize_text_field');
if (!empty($item_id)) {
$item_id = explode(',', $item_id);
}
$query = array('form_id' => $form_id);
if ($item_id) {
$query['id'] = $item_id;
}
/**
* Allows the query to be changed for fetching the entry ids to include in the export
*
* $query is the array of options to be filtered. It includes form_id, and maybe id (array of entry ids),
* and the search query. This should return an array, but it can be handled as a string as well.
*/
$query = apply_filters('frm_csv_where', $query, compact('form_id', 'search', 'fid', 'item_id'));
$entry_ids = FrmDb::get_col($wpdb->prefix . 'frm_items it', $query);
unset($query);
if (empty($entry_ids)) {
esc_html_e('There are no entries for that form.', 'formidable');
} else {
FrmCSVExportHelper::generate_csv(compact('form', 'entry_ids', 'form_cols'));
}
wp_die();
}
示例14: prepare_post_filter
/**
* if there are posts linked to entries for this form
*/
private static function prepare_post_filter($args, $where_field, &$new_ids)
{
if (empty($args['form_posts'])) {
// there are not posts related to this view
return;
}
if (!isset($where_field->field_options['post_field']) || !in_array($where_field->field_options['post_field'], array('post_category', 'post_custom', 'post_status', 'post_content', 'post_excerpt', 'post_title', 'post_name', 'post_date'))) {
// this is not a post field
return;
}
$post_ids = array();
foreach ($args['form_posts'] as $form_post) {
$post_ids[$form_post->post_id] = $form_post->id;
if (!in_array($form_post->id, $new_ids)) {
$new_ids[] = $form_post->id;
}
}
if (empty($post_ids)) {
return;
}
global $wpdb;
$filter_args = array();
if ($where_field->field_options['post_field'] == 'post_category') {
//check categories
$args['temp_where_is'] = FrmDb::append_where_is(str_replace(array('!', 'not '), '', $args['where_is']));
$t_where = array('or' => 1, 't.term_id ' . $args['temp_where_is'] => $args['where_val'], 't.slug ' . $args['temp_where_is'] => $args['where_val'], 't.name ' . $args['temp_where_is'] => $args['where_val']);
unset($args['temp_where_is']);
$query = array('tt.taxonomy' => $where_field->field_options['taxonomy']);
$query[] = $t_where;
self::add_group_by($filter_args, $args, 'tr.object_id');
$add_posts = FrmDb::get_col($wpdb->terms . ' AS t INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON tt.term_id = t.term_id INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id', $query, 'tr.object_id', $filter_args);
$add_posts = array_intersect($add_posts, array_keys($post_ids));
if (in_array($args['where_is'], array('!=', 'not LIKE'))) {
$remove_posts = $add_posts;
$add_posts = false;
} else {
if (empty($add_posts)) {
$new_ids = array();
return;
}
}
} else {
$query = array();
if ($where_field->field_options['post_field'] == 'post_custom' && $where_field->field_options['custom_field'] != '') {
//check custom fields
$get_field = 'post_id';
$get_table = $wpdb->postmeta;
$query['meta_key'] = $where_field->field_options['custom_field'];
$query_key = 'meta_value';
} else {
//if field is post field
$get_field = 'ID';
$get_table = $wpdb->posts;
$query_key = sanitize_title($where_field->field_options['post_field']);
}
self::add_group_by($filter_args, $args, $query_key);
$query_key .= (in_array($where_field->type, array('number', 'scale')) ? ' +0 ' : ' ') . FrmDb::append_where_is($args['where_is']);
$query[$query_key] = $args['where_val'];
$add_posts = FrmDb::get_col($get_table, $query, $get_field, $filter_args);
$add_posts = array_intersect($add_posts, array_keys($post_ids));
}
if ($add_posts && !empty($add_posts)) {
$new_ids = array();
foreach ($add_posts as $add_post) {
if (!in_array($post_ids[$add_post], $new_ids)) {
$new_ids[] = $post_ids[$add_post];
}
}
}
if (isset($remove_posts)) {
if (!empty($remove_posts)) {
foreach ($remove_posts as $remove_post) {
$key = array_search($post_ids[$remove_post], $new_ids);
if ($key && $new_ids[$key] == $post_ids[$remove_post]) {
unset($new_ids[$key]);
}
unset($key);
}
}
} else {
if (!$add_posts) {
$new_ids = array();
}
}
}
示例15: get_shortcode_select
//.........这里部分代码省略.........
<option class="frm_subopt" value="<?php
echo esc_attr($field->field_key);
?>
size=thumbnail"><?php
_e('Thumbnail', 'formidable');
?>
</option>
<option class="frm_subopt" value="<?php
echo esc_attr($field->field_key);
?>
size=medium"><?php
_e('Medium', 'formidable');
?>
</option>
<option class="frm_subopt" value="<?php
echo esc_attr($field->field_key);
?>
size=large"><?php
_e('Large', 'formidable');
?>
</option>
<option class="frm_subopt" value="<?php
echo esc_attr($field->field_key);
?>
size=full"><?php
_e('Full Size', 'formidable');
?>
</option>
<?php
} else {
if ($field->type == 'data') {
//get all fields from linked form
if (isset($field->field_options['form_select']) && is_numeric($field->field_options['form_select'])) {
$linked_form = FrmDb::get_var('frm_fields', array('id' => $field->field_options['form_select']), 'form_id');
if (!in_array($linked_form, $linked_forms)) {
$linked_forms[] = $linked_form;
$linked_fields = FrmField::getAll(array('fi.type not' => FrmField::no_save_fields(), 'fi.form_id' => (int) $linked_form));
foreach ($linked_fields as $linked_field) {
?>
<option class="frm_subopt" value="<?php
echo esc_attr($field->id . ' show=' . $linked_field->id);
?>
"><?php
echo esc_html(FrmAppHelper::truncate($linked_field->name, 60));
?>
(<?php
_e('ID', 'formidable');
?>
)</option>
<option class="frm_subopt" value="<?php
echo esc_attr($field->field_key . ' show=' . $linked_field->field_key);
?>
"><?php
echo esc_html(FrmAppHelper::truncate($linked_field->name, 60));
?>
(<?php
_e('Key', 'formidable');
?>
)</option>
<?php
}
}
}
}
}
}