-
Notifications
You must be signed in to change notification settings - Fork 0
/
comparisons.php
68 lines (65 loc) · 2.25 KB
/
comparisons.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
class WPCustomFieldsSearch_Equals extends WPCustomFieldsSearch_Comparison {
function get_sql_where_clause($params,$field_name,$value){
return "$field_name = '".mysql_escape_string($value)."'";
}
}
class WPCustomFieldsSearch_WordsIn extends WPCustomFieldsSearch_Comparison {
function get_sql_where_clause($params,$field_name,$value){
throw new Exception("Unimplemented");
}
}
class WPCustomFieldsSearch_PhraseIn extends WPCustomFieldsSearch_Comparison {
function get_sql_where_clause($params,$field_name,$value){
throw new Exception("Unimplemented");
}
}
abstract class WPCustomFieldsSearch_OrderedComparison extends WPCustomFieldsSearch_Comparison {
function prepare_field_name($params,$name){
if($params['is_numeric']){
$name = $name."*1";
}
return $name;
}
function prepare_value($params,$value){
$value = mysql_escape_string($value);
if(!$params['is_numeric']){
$value="'$value'";
}
return $value;
}
function getEditorOptions(){
$options = parent::getEditorOptions();
$options['extra_config_form'] = plugin_dir_url(__FILE__).'/ng/partials/comparisons/ordered.html';
return $options;
}
}
class WPCustomFieldsSearch_GreaterThan extends WPCustomFieldsSearch_OrderedComparison {
function get_sql_where_clause($params,$field_name,$value){
$field_name = $this->prepare_field_name($params,$field_name);
$value = $this->prepare_value($params,$value);
return "$field_name > $value";
}
}
class WPCustomFieldsSearch_LessThan extends WPCustomFieldsSearch_OrderedComparison {
function get_sql_where_clause($params,$field_name,$value){
$field_name = $this->prepare_field_name($params,$field_name);
$value = $this->prepare_value($params,$value);
return "$field_name < $value";
}
}
class WPCustomFieldsSearch_Range extends WPCustomFieldsSearch_OrderedComparison {
function get_sql_where_clause($params,$field_name,$value){
$field_name = $this->prepare_field_name($params,$field_name);
list($value1,$value2) = explode(":",$value);
$clauses = array();
foreach(array(array($value1,">"),array($value2,"<")) as $clause_config){
list($value,$comparison) = $clause_config;
if(strlen($value)>0){
$value = $this->prepare_value($params,$value);
$clauses[] = "$field_name $comparison $value";
}
}
return join(" AND ",$clauses);
}
}