-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
executable file
·230 lines (143 loc) · 6.17 KB
/
functions.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
function atts_are_valid($atts){
if(!isset($atts['address']) || !isset($atts['city']) || !isset($atts['state']) || !isset($atts['zip'])){
return false;
}
else{
return true;
}
}
function method_is_valid($zo, $method){
if( $method == 'all' || method_exists($zo, $method) ){
return true;
}
else{
return false;
}
}
function queue_styles(){
wp_enqueue_style( 'wp-zillow-bp-css', plugins_url('',__FILE__) . '/css/wp-zillow-bp.css', array(), '1', 'all' );
}
function wp_zillow_bp_doOuter($template){
require_once('templates/outerStructure.php');
$global = wp_zillowbp_generalMarkup();
return str_replace(WPZILLOWBP_TEMPLATESTR,$template,$global);
}
function wp_zillow_bp_doAllOuter($template, $data){
require_once('templates/outerStructure.php');
$global = wp_zillowbp_tabbedMarkup($data);
return str_replace(WPZILLOWBP_TEMPLATESTR,$template,$global);
}
function wp_zillowbp_shortcodes($atts){
//$atts = shortcode attributes
//[zillow-data method="getSearchResults" city="" state="" zip=""]
$method = $atts['method'];
$data;
$out = '';
$zwsid = get_option('wpzillow_zwsid');
require_once('templates/errTemplate.php');
require_once(WPZILLOW__PLUGIN_DIR . '/language.php');
$zo = new wpzillow($zwsid, wp_zillowbp_errorTemplate(), wp_zillow_bp_strings());
//removed init, made it constructor
//$zo->init($zwsid);
if(!$zwsid || !atts_are_valid($atts) || !method_is_valid($zo, $method)){
exit;
}
if($method == 'all'){
$allResults = wp_zillowbp_shortcodes_master($atts, $zo, $zwsid);
$out = $allResults['template'];
$data = $allResults['data'];
}
else if($method !== 'getSearchResults' && $method !== 'getDeepSearchResults'){
//must get zpid first
$zo->setZpid($atts);
$data = $zo->$method($atts);
$out = $zo->applyTemplate($method, $data);
}
else{
$data = $zo->$method($atts);
$out = $zo->applyTemplate($method, $data);
$out = wp_zillow_bp_doOuter($out);
}
global $wp_zillow_bp_gotdata;
$wp_zillow_bp_gotdata = true;
queue_styles();
return $out; //. wp_zillow_bp_providedby();
}
function wp_zillowbp_shortcodes_master($atts, $zo, $zwsid){
$data;
$out = '';
//search data is special instance of data because it
//is used more than once in the templates
//it gets its own var
$searchData = $zo->getDeepSearchResults($atts);
$out .= $zo->applyTemplate('getDeepSearchResults',$searchData);
$data = $zo->getComps($atts);
$out .= $zo->applyTemplate('getComps',$data);
$data = $zo->getChart($atts);
$out .= $zo->applyTemplate('getChart',$data);
//$data = $zo->getNeighborhood($atts);
//$out .= $zo->applyTemplate('getNeighborhood',$data);
$out = wp_zillow_bp_doAllOuter($out, $searchData);
//$out = $zo->applyTemplate('sectionHeader',$searchData) . $out;
//getSearchResults or getDeepSearchResults will set the zpid
//if called before other methods, make sure here
if(!$zo->zpid){
$zo->setZpid($atts);
}
return Array('template'=>$out, 'data'=>$searchData);
}
global $wp_zillow_bp_results;
global $wp_zillow_bp_errs;
$wp_zillow_bp_results = '';
$wp_zillow_bp_errs = '';
function wp_zillowbp_doPropertySearch($content){
if ( !isset( $_POST['wp_zillow_bp_search'] ) ) return;
//if( !wp_verify_nonce( $_REQUEST['zillowsearch'], 'zillowsearch' ) ){
// wp_nonce_ays();
//}
$err = '';
global $wp_zillow_bp_results;
global $wp_zillow_bp_errs;
require_once('language.php');
$strings = wp_zillow_bp_strings();
$address = ( isset($_POST['wp_zillow_bp_address']) ) ? trim(strip_tags($_POST['wp_zillow_bp_address'])) : null;
$city = ( isset($_POST['wp_zillow_bp_city']) ) ? trim(strip_tags($_POST['wp_zillow_bp_city'])) : null;
$zip = ( isset($_POST['wp_zillow_bp_zip']) ) ? trim(strip_tags($_POST['wp_zillow_bp_zip'])) : null;
if($address == '' || $city == '' || $zip == ''){
$wp_zillow_bp_errs = $strings['errroraddress'];
}
else{
$data = array(
'method' => 'all',
'address' => $address,
'city' => $city,
'state' => 'FL',
'zip' => $zip
);
$wp_zillow_bp_results = wp_zillowbp_shortcodes($data);
global $wp_zillow_bp_gotdata;
$wp_zillow_bp_gotdata = true;
}
}
function wp_zillowbp_showPropertySearch(){
global $wp_zillow_bp_results;
echo ( $wp_zillow_bp_results );
}
function wp_zillowbp_showSearchErrors(){
global $wp_zillow_bp_errs;
if($wp_zillow_bp_errs != ''){
require_once('templates/errTemplate.php');
echo ( str_replace(WPZILLOWBP_ERRSTR,$wp_zillow_bp_errs,wp_zillowbp_errorTemplate()) );
}
}
function wp_zillow_bp_footer(){
$out = '';
global $wp_zillow_bp_gotdata;
if($wp_zillow_bp_gotdata){
require_once('templates/outerStructure.php');
$out = wp_zillow_bp_global_footer();
}
echo($out);
}
?>