本文整理汇总了PHP中FrmAppHelper::esc_like方法的典型用法代码示例。如果您正苦于以下问题:PHP FrmAppHelper::esc_like方法的具体用法?PHP FrmAppHelper::esc_like怎么用?PHP FrmAppHelper::esc_like使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrmAppHelper
的用法示例。
在下文中一共展示了FrmAppHelper::esc_like方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare_items
function prepare_items()
{
global $wpdb, $per_page, $frm_settings;
$paged = $this->get_pagenum();
$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();
$default_count = empty($this->page_name) ? 20 : 10;
$per_page = $this->get_items_per_page('formidable_page_formidable' . str_replace('-', '_', $this->page_name) . '_per_page', $default_count);
$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : ($page - 1) * $per_page;
$s = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : '';
$fid = isset($_REQUEST['fid']) ? $_REQUEST['fid'] : '';
if ($s != '') {
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
$search_terms = array_map('trim', $matches[0]);
}
$s_query = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = " . (int) $this->params['template'];
if ($s != '') {
foreach ((array) $search_terms as $term) {
if (!empty($s_query)) {
$s_query .= " AND";
}
$term = FrmAppHelper::esc_like($term);
$s_query .= $wpdb->prepare(" (name like %s OR description like %s OR created_at like %s)", '%' . $term . '%', '%' . $term . '%', '%' . $term . '%');
unset($term);
}
}
$frm_form = new FrmForm();
$this->items = $frm_form->getAll($s_query, " ORDER BY {$orderby} {$order}", " LIMIT {$start}, {$per_page}", true, false);
$total_items = FrmAppHelper::getRecordCount($s_query, $this->table_name);
$this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page));
}
示例2: interpret_array_to_sql
/**
* @param string $key
* @param string $where
*/
private static function interpret_array_to_sql($key, $value, &$where, &$values)
{
$key = trim($key);
if (strpos($key, 'created_at') !== false || strpos($key, 'updated_at') !== false) {
$k = explode(' ', $key);
$where .= ' DATE_FORMAT(' . reset($k) . ', %s) ' . str_replace(reset($k), '', $key);
$values[] = '%Y-%m-%d %H:%i:%s';
} else {
$where .= ' ' . $key;
}
$lowercase_key = explode(' ', strtolower($key));
$lowercase_key = end($lowercase_key);
if (is_array($value)) {
// translate array of values to "in"
if (strpos($lowercase_key, 'like') !== false) {
$where = preg_replace('/' . $key . '$/', '', $where);
$where .= '(';
$start = true;
foreach ($value as $v) {
if (!$start) {
$where .= ' OR ';
}
$start = false;
$where .= $key . ' %s';
$values[] = '%' . FrmAppHelper::esc_like($v) . '%';
}
$where .= ')';
} else {
if (!empty($value)) {
$where .= ' in (' . FrmAppHelper::prepare_array_values($value, '%s') . ')';
$values = array_merge($values, $value);
}
}
} else {
if (strpos($lowercase_key, 'like') !== false) {
/**
* Allow string to start or end with the value
* If the key is like% then skip the first % for starts with
* If the key is %like then skip the last % for ends with
*/
$start = $end = '%';
if ($lowercase_key == 'like%') {
$start = '';
$where = rtrim($where, '%');
} else {
if ($lowercase_key == '%like') {
$end = '';
$where = rtrim(rtrim($where, '%like'), '%LIKE');
$where .= 'like';
}
}
$where .= ' %s';
$values[] = $start . FrmAppHelper::esc_like($value) . $end;
} else {
if ($value === null) {
$where .= ' IS NULL';
} else {
// allow a - to prevent = from being added
if (substr($key, -1) == '-') {
$where = rtrim($where, '-');
} else {
$where .= '=';
}
$where .= is_numeric($value) ? strpos($value, '.') !== false ? '%f' : '%d' : '%s';
$values[] = $value;
}
}
}
}
示例3: filter_where
public static function filter_where($entry_ids, $args)
{
global $wpdb, $frmdb, $frm_entry_meta, $frm_field;
$defaults = array('where_opt' => false, 'where_is' => '=', 'where_val' => '', 'form_id' => false, 'form_posts' => array(), 'after_where' => false, 'display' => false, 'drafts' => 0);
extract(wp_parse_args($args, $defaults));
$form_id = (int) $form_id;
if (!$form_id or !$where_opt or !is_numeric($where_opt)) {
return $entry_ids;
}
$where_field = $frm_field->getOne($where_opt);
if (!$where_field) {
return $entry_ids;
}
if ($where_val == 'NOW') {
$where_val = date_i18n('Y-m-d', strtotime(current_time('mysql')));
}
if ($where_field->type == 'date' and !empty($where_val)) {
$where_val = date('Y-m-d', strtotime($where_val));
} else {
if ($where_is == '=' and $where_val != '' and ($where_field->type == 'checkbox' or $where_field->type == 'select' and isset($where_field->field_options['multiple']) and $where_field->field_options['multiple'] or $where_field->type == 'data' and $where_field->field_options['data_type'] == 'checkbox' and is_numeric($where_val))) {
$where_is = 'LIKE';
}
}
if ($where_field->form_id != $form_id) {
//TODO: get linked entry IDs and get entries where data field value(s) in linked entry IDs
}
$temp_where_is = str_replace(array('!', 'not '), '', $where_is);
//get values that aren't blank and then remove them from entry list
if ($where_val == '' and $temp_where_is == '=') {
$temp_where_is = '!=';
}
$orig_where_val = $where_val;
if ($where_is == 'LIKE' or $where_is == 'not LIKE') {
//add extra slashes to match values that are escaped in the database
$where_val_esc = "'%" . esc_sql(FrmAppHelper::esc_like(addslashes($where_val))) . "%'";
$where_val = "'%" . esc_sql(FrmAppHelper::esc_like($where_val)) . "%'";
} else {
if (!strpos($where_is, 'in')) {
$where_val_esc = "'" . str_replace('\\', '\\\\\\', esc_sql($where_val)) . "'";
$where_val = "'" . esc_sql($where_val) . "'";
}
}
$where_val = apply_filters('frm_filter_where_val', $where_val, $args);
$field_options = maybe_unserialize($where_field->field_options);
//Filter by DFE text
if ($where_field->type == 'data' && !is_numeric($where_val) && $orig_where_val != '' && (!isset($field_options['post_field']) || $field_options['post_field'] != 'post_category')) {
//Get entry IDs by DFE text
if ($where_is == 'LIKE' or $where_is == 'not LIKE') {
$linked_id = $frm_entry_meta->search_entry_metas($orig_where_val, $where_field->field_options['form_select'], $temp_where_is);
} else {
$linked_id = $wpdb->get_col($wpdb->prepare("SELECT item_id FROM {$frmdb->entry_metas} WHERE field_id=%d AND meta_value {$temp_where_is} %s", $where_field->field_options['form_select'], $orig_where_val));
}
//If text doesn't return any entry IDs, get entry IDs from entry key
if (!$linked_id) {
$linked_field = $frm_field->getOne($where_field->field_options['form_select']);
$linked_id = $wpdb->get_col("SELECT id FROM {$frmdb->entries} WHERE form_id={$linked_field->form_id} AND item_key {$temp_where_is} {$where_val}");
}
//Change $where_val to linked entry IDs
if ($linked_id) {
$linked_id = (array) $linked_id;
if ($where_field->field_options['data_type'] == 'checkbox' || $where_field->field_options['data_type'] == 'select' && isset($where_field->field_options['multiple']) && $where_field->field_options['multiple'] == 1) {
$where_val = "'%" . implode("%' OR meta_value LIKE '%", $linked_id) . "%'";
if ($where_is == '!=' or $where_is == 'not LIKE') {
$temp_where_is = 'LIKE';
} else {
if ($where_is == '=' or $where_is == 'LIKE') {
$where_is = $temp_where_is = 'LIKE';
}
}
} else {
$where_is = $temp_where_is = (strpos($where_is, '!') === false and strpos($where_is, 'not') === false) ? ' in ' : ' not in ';
$where_val = '(' . implode(',', $linked_id) . ')';
}
unset($where_val_esc);
$where_val = apply_filters('frm_filter_dfe_where_val', $where_val, $args);
}
unset($linked_id);
}
$where_statement = "(meta_value " . (in_array($where_field->type, array('number', 'scale')) ? ' +0 ' : '') . $temp_where_is . " " . $where_val . " ";
if (isset($where_val_esc) and $where_val_esc != $where_val) {
$where_statement .= " OR meta_value " . (in_array($where_field->type, array('number', 'scale')) ? ' +0 ' : '') . $temp_where_is . " " . $where_val_esc;
}
$where_statement .= ") and fi.id=" . (int) $where_opt;
$where_statement = apply_filters('frm_where_filter', $where_statement, $args);
$new_ids = $frm_entry_meta->getEntryIds($where_statement, '', '', true, $drafts);
if ($where_is != $temp_where_is) {
$new_ids = array_diff($entry_ids, $new_ids);
}
unset($temp_where_is);
if (!empty($form_posts)) {
//if there are posts linked to entries for this form
if (isset($field_options['post_field']) and in_array($field_options['post_field'], array('post_category', 'post_custom', 'post_status', 'post_content', 'post_excerpt', 'post_title', 'post_name', 'post_date'))) {
$post_ids = array();
foreach ($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)) {
//.........这里部分代码省略.........
示例4: get_field_stats
public static function get_field_stats($id, $type = 'total', $user_id = false, $value = false, $round = 100, $limit = '', $atts = array(), $drafts = false)
{
global $frm_entry_meta, $wpdb, $frmdb, $frm_post_ids, $frm_field;
$field = $frm_field->getOne($id);
if (!$field) {
return 0;
}
$id = $field->id;
if (isset($atts['thousands_sep']) && $atts['thousands_sep']) {
$thousands_sep = $atts['thousands_sep'];
unset($atts['thousands_sep']);
$round = $round == 100 ? 2 : $round;
}
$where_value = '';
if ($value) {
$slash_val = strpos($value, '\\') === false ? addslashes($value) : $value;
if ($field->type == 'checkbox' || $field->type == 'select' && isset($field->field_options['multiple']) && $field->field_options['multiple']) {
$where_value = $wpdb->prepare(" AND (meta_value LIKE %s OR meta_value LIKE %s )", '%' . FrmAppHelper::esc_like($value) . '%', '%' . FrmAppHelper::esc_like($slash_val) . '%');
//add extra slashes to match values that are escaped in the database
} else {
$where_value = $wpdb->prepare(" AND (meta_value = %s OR meta_value = %s )", FrmAppHelper::esc_like($value), addcslashes($slash_val, '_%'));
}
unset($slash_val);
}
//if(!$frm_post_ids)
$frm_post_ids = array();
$post_ids = array();
if (isset($frm_post_ids[$id])) {
$form_posts = $frm_post_ids[$id];
} else {
$where_post = array('form_id' => $field->form_id, 'post_id >' => 1);
if ($drafts != 'both') {
$where_post['is_draft'] = $drafts;
}
if ($user_id) {
$where_post['user_id'] = $user_id;
}
$form_posts = $frmdb->get_records($frmdb->entries, $where_post, '', '', 'id,post_id');
$frm_post_ids[$id] = $form_posts;
}
if ($form_posts) {
foreach ($form_posts as $form_post) {
$post_ids[$form_post->id] = $form_post->post_id;
}
}
if (!empty($limit)) {
$limit = " LIMIT " . $limit;
}
if ($value) {
$atts[$id] = $value;
}
if (!empty($atts)) {
$entry_ids = array();
if (isset($atts['entry_id']) and $atts['entry_id'] and is_numeric($atts['entry_id'])) {
$entry_ids[] = $atts['entry_id'];
}
$after_where = false;
foreach ($atts as $orig_f => $val) {
if (strpos($val, '"') === 0 and substr($val, -1) != '"' or strpos($val, "'") === 0 and substr($val, -1) != "'") {
//parse atts back together if they were broken at spaces
$next_val = array('char' => substr($val, 0, 1), 'val' => $val);
continue;
} else {
if (!isset($next_val)) {
$temp = FrmAppHelper::replace_quotes($val);
foreach (array('"', "'") as $q) {
if (substr($temp, -1) != $q and (strpos($temp, '<' . $q) or strpos($temp, '>' . $q))) {
$next_val = array('char' => $q, 'val' => $val);
$cont = true;
}
unset($q);
}
unset($temp);
if (isset($cont)) {
unset($cont);
continue;
}
}
}
if (isset($next_val)) {
if (substr(FrmAppHelper::replace_quotes($val), -1) == $next_val['char']) {
$val = $next_val['val'] . ' ' . $val;
unset($next_val);
} else {
$next_val['val'] .= ' ' . $val;
continue;
}
}
$entry_ids = self::get_field_matches(compact('entry_ids', 'orig_f', 'val', 'id', 'atts', 'field', 'form_posts', 'after_where', 'drafts'));
$after_where = true;
}
if (empty($entry_ids)) {
if ($type == 'star') {
$stat = '';
ob_start();
include FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/star_disabled.php';
$contents = ob_get_contents();
ob_end_clean();
return $contents;
} else {
//.........这里部分代码省略.........
示例5: get_search_str
public static function get_search_str($where_clause = '', $search_str, $form_id = false, $fid = false)
{
global $frm_entry_meta, $wpdb;
$where_item = '';
$join = ' (';
if (!is_array($search_str)) {
$search_str = explode(" ", $search_str);
}
foreach ($search_str as $search_param) {
$unescaped_search_param = $search_param;
$search_param = FrmAppHelper::esc_like($search_param);
if (!is_numeric($fid)) {
$where_item .= empty($where_item) ? ' (' : ' OR';
if (in_array($fid, array('created_at', 'user_id', 'updated_at', 'id'))) {
if ($fid == 'user_id' && !is_numeric($search_param)) {
$search_param = FrmProAppHelper::get_user_id_param($unescaped_search_param);
}
$where_item .= $wpdb->prepare(" it.{$fid} like %s", '%' . $search_param . '%');
} else {
$where_item .= $wpdb->prepare(' it.name like %s OR it.item_key like %s OR it.description like %s OR it.created_at like %s', '%' . $search_param . '%', '%' . $search_param . '%', '%' . $search_param . '%', '%' . $search_param . '%');
}
}
if (empty($fid) || is_numeric($fid)) {
$where_entries = $wpdb->prepare('(meta_value LIKE %s', '%' . $search_param . '%');
if ($data_fields = FrmProFormsHelper::has_field('data', $form_id, false)) {
$df_form_ids = array();
//search the joined entry too
foreach ((array) $data_fields as $df) {
//don't check if a different field is selected
if (is_numeric($fid) && (int) $fid != $df->id) {
continue;
}
$df->field_options = maybe_unserialize($df->field_options);
if (isset($df->field_options['form_select']) && is_numeric($df->field_options['form_select'])) {
$df_form_ids[] = $df->field_options['form_select'];
}
unset($df);
}
unset($data_fields);
if (!empty($df_form_ids)) {
$data_form_ids = $wpdb->get_col("SELECT form_id FROM {$wpdb->prefix}frm_fields WHERE id in (" . implode(',', array_filter($df_form_ids, 'is_numeric')) . ")");
if ($data_form_ids) {
$data_entry_ids = $frm_entry_meta->getEntryIds("fi.form_id in (" . implode(',', $data_form_ids) . ") " . $wpdb->prepare("and meta_value LIKE %s", '%' . $search_param . '%'));
if (!empty($data_entry_ids)) {
$where_entries .= " OR meta_value in (" . implode(',', $data_entry_ids) . ")";
}
}
unset($data_form_ids);
}
unset($df_form_ids);
}
$where_entries .= ")";
if (is_numeric($fid)) {
$where_entries .= $wpdb->prepare(' AND field_id=%d', $fid);
}
if (is_admin() && isset($_GET) && isset($_GET['page']) && $_GET['page'] == 'formidable-entries') {
$include_drafts = true;
} else {
$include_drafts = false;
}
$meta_ids = $frm_entry_meta->getEntryIds($where_entries, '', '', true, $include_drafts);
if (!empty($where_clause)) {
$where_clause .= " AND" . $join;
if (!empty($join)) {
$join = '';
}
}
if (!empty($meta_ids)) {
$where_clause .= " it.id in (" . implode(',', $meta_ids) . ")";
} else {
$where_clause .= " it.id=0";
}
}
}
if (!empty($where_item)) {
$where_item .= ')';
if (!empty($where_clause)) {
$where_clause .= empty($fid) ? ' OR' : ' AND';
}
$where_clause .= $where_item;
}
if (empty($join)) {
$where_clause .= ')';
}
return $where_clause;
}
示例6: get_search_ids
public static function get_search_ids($s, $form_id)
{
global $wpdb, $frm_entry_meta;
if (empty($s)) {
return false;
}
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
$search_terms = array_map('trim', $matches[0]);
$n = '%';
//!empty($q['exact']) ? '' : '%';
$p_search = $search = '';
$search_or = '';
$e_ids = array();
$data_field = FrmProFormsHelper::has_field('data', $form_id, false);
foreach ((array) $search_terms as $term) {
$term = FrmAppHelper::esc_like($term);
$p_search .= $wpdb->prepare(" AND (({$wpdb->posts}.post_title LIKE %s) OR ({$wpdb->posts}.post_content LIKE %s))", $n . $term . $n, $n . $term . $n);
$search .= $wpdb->prepare($search_or . 'meta_value LIKE %s', $n . $term . $n);
$search_or = ' OR ';
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) {
if (is_numeric($df->field_options['form_select'])) {
$df_form_ids[] = (int) $df->field_options['form_select'];
}
unset($df);
}
$data_form_ids = $wpdb->get_col("SELECT form_id FROM {$wpdb->prefix}frm_fields WHERE id in (" . implode(',', $df_form_ids) . ")");
unset($df_form_ids);
if ($data_form_ids) {
$data_entry_ids = $frm_entry_meta->getEntryIds("fi.form_id in (" . implode(',', $data_form_ids) . ")" . $wpdb->prepare(' AND meta_value LIKE %s', '%' . $term . '%'));
if ($data_entry_ids) {
$search .= "{$search_or}meta_value in (" . implode(',', $data_entry_ids) . ")";
}
}
unset($data_form_ids);
}
}
$p_ids = '';
$matching_posts = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE 1=1 {$p_search}");
if ($matching_posts) {
$p_ids = $wpdb->get_col("SELECT id FROM {$wpdb->prefix}frm_items WHERE post_id in (" . implode(',', $matching_posts) . ") AND form_id=" . (int) $form_id);
$p_ids = $p_ids ? " OR item_id in (" . implode(',', $p_ids) . ")" : '';
}
if (!empty($e_ids)) {
$p_ids .= " OR item_id in (" . implode(',', $e_ids) . ")";
}
return $frm_entry_meta->getEntryIds("(({$search}){$p_ids}) and fi.form_id=" . (int) $form_id);
}
示例7: get_display_data
//.........这里部分代码省略.........
$where_val = isset($display->frm_where_val[$where_key]) ? $display->frm_where_val[$where_key] : '';
if (preg_match("/\\[(get|get-(.?))\\b(.*?)(?:(\\/))?\\]/s", $where_val)) {
$where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
//if this param doesn't exist, then don't include it
if ($where_val == '') {
if (!$after_where) {
$continue = true;
}
continue;
}
} else {
$where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
}
$continue = false;
if ($where_val == 'current_user') {
if ($user_id and is_numeric($user_id)) {
$where_val = $user_id;
$uid_used = true;
} else {
$where_val = get_current_user_id();
}
}
$where_val = do_shortcode($where_val);
if (in_array($where_opt, array('id', 'item_key', 'post_id')) && !is_array($where_val) && strpos($where_val, ',')) {
$where_val = explode(',', $where_val);
}
if (is_array($where_val) and !empty($where_val)) {
$new_where = '(';
if (strpos($display->frm_where_is[$where_key], 'LIKE') !== false) {
foreach ($where_val as $w) {
if ($new_where != '(') {
$new_where .= ',';
}
$new_where .= $wpdb->prepare('%s', '%' . FrmAppHelper::esc_like($w) . '%');
unset($w);
}
} else {
foreach ($where_val as $w) {
if ($new_where != '(') {
$new_where .= ',';
}
$new_where .= $wpdb->prepare('%s', $w);
unset($w);
}
}
$new_where .= ')';
$where_val = $new_where;
unset($new_where);
if (strpos($display->frm_where_is[$where_key], '!') === false && strpos($display->frm_where_is[$where_key], 'not') === false) {
$display->frm_where_is[$where_key] = ' in ';
} else {
$display->frm_where_is[$where_key] = ' not in ';
}
}
if (is_numeric($where_opt)) {
$filter_opts = apply_filters('frm_display_filter_opt', array('where_opt' => $where_opt, 'where_is' => $display->frm_where_is[$where_key], 'where_val' => $where_val, 'form_id' => $display->frm_form_id, 'form_posts' => $form_posts, 'after_where' => $after_where, 'display' => $display, 'drafts' => $is_draft));
$entry_ids = FrmProAppHelper::filter_where($entry_ids, $filter_opts);
unset($filter_opts);
$after_where = true;
$continue = false;
if (empty($entry_ids)) {
break;
}
} else {
if ($where_opt == 'created_at' or $where_opt == 'updated_at') {
if ($where_val == 'NOW') {