1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* HomeFinder Affiliate Search Widget (http://www.homefinder.com/widgets/) |
4
|
|
|
* |
5
|
|
|
* @package RE-PRO |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/* Exit if accessed directly. */ |
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; } |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* HomeFinderAffiliateSearch class. |
13
|
|
|
* |
14
|
|
|
* @extends WP_Widget |
15
|
|
|
*/ |
16
|
|
|
class HomeFinderAffiliateSearch extends WP_Widget { |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* __construct function. |
20
|
|
|
* |
21
|
|
|
* @access public |
22
|
|
|
* @return void |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
public function __construct() { |
25
|
|
|
|
26
|
|
|
parent::__construct( |
27
|
|
|
'homefinder_affiliate_search', |
28
|
|
|
__( 'HomeFinder Affiliate Search', 're-pro' ), |
29
|
|
|
array( |
30
|
|
|
'description' => __( 'Display an affiliate search box from HomeFinder.com', 're-pro' ), |
31
|
|
|
'classname' => 're-pro re-pro-widget homefinder-widget homefinder-affiliate-search', |
32
|
|
|
'customize_selective_refresh' => true, |
33
|
|
|
) |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Widget function. |
39
|
|
|
* |
40
|
|
|
* @access public |
41
|
|
|
* @param mixed $args Arguments. |
42
|
|
|
* @param mixed $instance Instance. |
43
|
|
|
*/ |
44
|
|
|
public function widget( $args, $instance ) { |
45
|
|
|
|
46
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
47
|
|
|
$affiliate = ! empty( $instance['affiliate'] ) ? $instance['affiliate'] : ''; |
|
|
|
|
48
|
|
|
$primary_city = ! empty( $instance['primary_city'] ) ? $instance['primary_city'] : ''; |
|
|
|
|
49
|
|
|
$primary_state = ! empty( $instance['primary_state'] ) ? $instance['primary_state'] : ''; |
|
|
|
|
50
|
|
|
$nearby_city_1 = ! empty( $instance['nearby_city_1'] ) ? $instance['nearby_city_1'] : ''; |
|
|
|
|
51
|
|
|
$nearby_state_1 = ! empty( $instance['nearby_state_1'] ) ? $instance['nearby_state_1'] : ''; |
|
|
|
|
52
|
|
|
$nearby_city_2 = ! empty( $instance['nearby_city_2'] ) ? $instance['nearby_city_2'] : ''; |
|
|
|
|
53
|
|
|
$nearby_state_2 = ! empty( $instance['nearby_state_2'] ) ? $instance['nearby_state_2'] : ''; |
|
|
|
|
54
|
|
|
$nearby_city_3 = ! empty( $instance['nearby_city_3'] ) ? $instance['nearby_city_3'] : ''; |
|
|
|
|
55
|
|
|
$nearby_state_3 = ! empty( $instance['nearby_state_3'] ) ? $instance['nearby_state_3'] : ''; |
|
|
|
|
56
|
|
|
$nearby_city_4 = ! empty( $instance['nearby_city_4'] ) ? $instance['nearby_city_4'] : ''; |
|
|
|
|
57
|
|
|
$nearby_state_4 = ! empty( $instance['nearby_state_4'] ) ? $instance['nearby_state_4'] : ''; |
|
|
|
|
58
|
|
|
|
59
|
|
|
echo $args['before_widget']; |
60
|
|
|
|
61
|
|
|
echo $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
62
|
|
|
|
63
|
|
|
$homefinder_widgets = new HomeFinderWidgets(); |
64
|
|
|
|
65
|
|
|
$homefinder_widgets->get_affiliates_widget( 'search', $instance ); |
66
|
|
|
|
67
|
|
|
echo $args['after_widget']; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Form function. |
72
|
|
|
* |
73
|
|
|
* @access public |
74
|
|
|
* @param mixed $instance Instance. |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function form( $instance ) { |
78
|
|
|
|
79
|
|
|
// Set default values. |
80
|
|
|
$instance = wp_parse_args( (array) $instance, array( |
81
|
|
|
'title' => '', |
82
|
|
|
'affiliate' => '', |
83
|
|
|
'primary_city' => '', |
84
|
|
|
'primary_state' => '', |
85
|
|
|
'nearby_city_1' => '', |
86
|
|
|
'nearby_state_1' => '', |
87
|
|
|
'nearby_city_2' => '', |
88
|
|
|
'nearby_state_2' => '', |
89
|
|
|
'nearby_city_3' => '', |
90
|
|
|
'nearby_state_3' => '', |
91
|
|
|
'nearby_city_4' => '', |
92
|
|
|
'nearby_state_4' => '', |
93
|
|
|
) ); |
94
|
|
|
|
95
|
|
|
// Retrieve an existing value from the database. |
96
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
97
|
|
|
$affiliate = ! empty( $instance['affiliate'] ) ? $instance['affiliate'] : ''; |
98
|
|
|
$primary_city = ! empty( $instance['primary_city'] ) ? $instance['primary_city'] : ''; |
99
|
|
|
$primary_state = ! empty( $instance['primary_state'] ) ? $instance['primary_state'] : ''; |
100
|
|
|
$nearby_city_1 = ! empty( $instance['nearby_city_1'] ) ? $instance['nearby_city_1'] : ''; |
101
|
|
|
$nearby_state_1 = ! empty( $instance['nearby_state_1'] ) ? $instance['nearby_state_1'] : ''; |
102
|
|
|
$nearby_city_2 = ! empty( $instance['nearby_city_2'] ) ? $instance['nearby_city_2'] : ''; |
103
|
|
|
$nearby_state_2 = ! empty( $instance['nearby_state_2'] ) ? $instance['nearby_state_2'] : ''; |
104
|
|
|
$nearby_city_3 = ! empty( $instance['nearby_city_3'] ) ? $instance['nearby_city_3'] : ''; |
105
|
|
|
$nearby_state_3 = ! empty( $instance['nearby_state_3'] ) ? $instance['nearby_state_3'] : ''; |
106
|
|
|
$nearby_city_4 = ! empty( $instance['nearby_city_4'] ) ? $instance['nearby_city_4'] : ''; |
107
|
|
|
$nearby_state_4 = ! empty( $instance['nearby_state_4'] ) ? $instance['nearby_state_4'] : ''; |
108
|
|
|
|
109
|
|
|
// Title. |
110
|
|
|
echo '<p>'; |
111
|
|
|
echo ' <label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>'; |
112
|
|
|
echo ' <input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title . '" class="widefat">'; |
113
|
|
|
echo '</p>'; |
114
|
|
|
|
115
|
|
|
// Affiliate Name. |
116
|
|
|
echo '<p>'; |
117
|
|
|
echo ' <label for="' . $this->get_field_id( 'affiliate' ) . '" class="title-label">' . __( 'Affiliate Name:', 're-pro' ) . '</label>'; |
118
|
|
|
echo ' <input id="' . $this->get_field_id( 'affiliate' ) . '" name="' . $this->get_field_name( 'affiliate' ) . '" value="' . $affiliate . '" class="widefat">'; |
119
|
|
|
echo '</p>'; |
120
|
|
|
|
121
|
|
|
// Primary Search Area. |
122
|
|
|
echo '<p>'; |
123
|
|
|
echo ' <label for="primary-search-area" class="title-label">' . __( 'Primary Search Area:', 're-pro' ) . '</label>'; |
124
|
|
|
echo ' <input id="' . $this->get_field_id( 'primary_city' ) . '" name="' . $this->get_field_name( 'primary_city' ) . '" value="' . $primary_city . '" class="widefat">'; |
125
|
|
|
echo ' <span class="description">' . __( 'City', 're-pro' ) . '</span>'; |
126
|
|
|
echo ' <input id="' . $this->get_field_id( 'primary_state' ) . '" name="' . $this->get_field_name( 'primary_state' ) . '" value="' . $primary_state . '" class="widefat">'; |
127
|
|
|
echo ' <span class="description">' . __( 'State', 're-pro' ) . '</span>'; |
128
|
|
|
echo '</p>'; |
129
|
|
|
|
130
|
|
|
// Nearby Area 1. |
131
|
|
|
echo '<p>'; |
132
|
|
|
echo ' <label for="nearby-area-1" class="title-label">' . __( 'Nearby Area 1:', 're-pro' ) . '</label>'; |
133
|
|
|
echo ' <input id="' . $this->get_field_id( 'nearby_city_1' ) . '" name="' . $this->get_field_name( 'nearby_city_1' ) . '" value="' . $nearby_city_1 . '" class="widefat">'; |
134
|
|
|
echo ' <span class="description">' . __( 'City', 're-pro' ) . '</span>'; |
135
|
|
|
echo ' <input id="' . $this->get_field_id( 'nearby_state_1' ) . '" name="' . $this->get_field_name( 'nearby_state_1' ) . '" value="' . $nearby_state_1 . '" class="widefat">'; |
136
|
|
|
echo ' <span class="description">' . __( 'State', 're-pro' ) . '</span>'; |
137
|
|
|
echo '</p>'; |
138
|
|
|
|
139
|
|
|
// Nearby Area 2. |
140
|
|
|
echo '<p>'; |
141
|
|
|
echo ' <label for="nearby-area-2" class="title-label">' . __( 'Nearby Area 2:', 're-pro' ) . '</label>'; |
142
|
|
|
echo ' <input id="' . $this->get_field_id( 'nearby_city_2' ) . '" name="' . $this->get_field_name( 'nearby_city_2' ) . '" value="' . $nearby_city_2 . '" class="widefat">'; |
143
|
|
|
echo ' <span class="description">' . __( 'City', 're-pro' ) . '</span>'; |
144
|
|
|
echo ' <input id="' . $this->get_field_id( 'nearby_state_2' ) . '" name="' . $this->get_field_name( 'nearby_state_2' ) . '" value="' . $nearby_state_2 . '" class="widefat">'; |
145
|
|
|
echo ' <span class="description">' . __( 'State', 're-pro' ) . '</span>'; |
146
|
|
|
echo '</p>'; |
147
|
|
|
|
148
|
|
|
// Nearby Area 3. |
149
|
|
|
echo '<p>'; |
150
|
|
|
echo ' <label for="nearby-area-3" class="title-label">' . __( 'Nearby Area 3:', 're-pro' ) . '</label>'; |
151
|
|
|
echo ' <input id="' . $this->get_field_id( 'nearby_city_3' ) . '" name="' . $this->get_field_name( 'nearby_city_3' ) . '" value="' . $nearby_city_3 . '" class="widefat">'; |
152
|
|
|
echo ' <span class="description">' . __( 'City', 're-pro' ) . '</span>'; |
153
|
|
|
echo ' <input id="' . $this->get_field_id( 'nearby_state_3' ) . '" name="' . $this->get_field_name( 'nearby_state_3' ) . '" value="' . $nearby_state_3 . '" class="widefat">'; |
154
|
|
|
echo ' <span class="description">' . __( 'State', 're-pro' ) . '</span>'; |
155
|
|
|
echo '</p>'; |
156
|
|
|
|
157
|
|
|
// Nearby Area 4. |
158
|
|
|
echo '<p>'; |
159
|
|
|
echo ' <label for="nearby-area-4" class="title-label">' . __( 'Nearby Area 4:', 're-pro' ) . '</label>'; |
160
|
|
|
echo ' <input id="' . $this->get_field_id( 'nearby_city_4' ) . '" name="' . $this->get_field_name( 'nearby_city_4' ) . '" value="' . $nearby_city_4 . '" class="widefat">'; |
161
|
|
|
echo ' <span class="description">' . __( 'City', 're-pro' ) . '</span>'; |
162
|
|
|
echo ' <input id="' . $this->get_field_id( 'nearby_state_4' ) . '" name="' . $this->get_field_name( 'nearby_state_4' ) . '" value="' . $nearby_state_4 . '" class="widefat">'; |
163
|
|
|
echo ' <span class="description">' . __( 'State', 're-pro' ) . '</span>'; |
164
|
|
|
echo '</p>'; |
165
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Update Widget Instance. |
170
|
|
|
* |
171
|
|
|
* @access public |
172
|
|
|
* @param mixed $new_instance New Instance. |
173
|
|
|
* @param mixed $old_instance Old Instance. |
174
|
|
|
* @return $instance |
|
|
|
|
175
|
|
|
*/ |
176
|
|
|
public function update( $new_instance, $old_instance ) { |
177
|
|
|
|
178
|
|
|
$instance = $old_instance; |
179
|
|
|
|
180
|
|
|
$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
181
|
|
|
$instance['affiliate'] = ! empty( $new_instance['affiliate'] ) ? strip_tags( $new_instance['affiliate'] ) : ''; |
182
|
|
|
$instance['primary_city'] = ! empty( $new_instance['primary_city'] ) ? strip_tags( $new_instance['primary_city'] ) : ''; |
183
|
|
|
$instance['primary_state'] = ! empty( $new_instance['primary_state'] ) ? strip_tags( $new_instance['primary_state'] ) : ''; |
184
|
|
|
$instance['nearby_city_1'] = ! empty( $new_instance['nearby_city_1'] ) ? strip_tags( $new_instance['nearby_city_1'] ) : ''; |
185
|
|
|
$instance['nearby_city_2'] = ! empty( $new_instance['nearby_city_2'] ) ? strip_tags( $new_instance['nearby_city_2'] ) : ''; |
186
|
|
|
$instance['nearby_city_3'] = ! empty( $new_instance['nearby_city_3'] ) ? strip_tags( $new_instance['nearby_city_3'] ) : ''; |
187
|
|
|
$instance['nearby_city_4'] = ! empty( $new_instance['nearby_city_4'] ) ? strip_tags( $new_instance['nearby_city_4'] ) : ''; |
188
|
|
|
$instance['nearby_state_1'] = ! empty( $new_instance['nearby_state_1'] ) ? strip_tags( $new_instance['nearby_state_1'] ) : ''; |
189
|
|
|
$instance['nearby_state_2'] = ! empty( $new_instance['nearby_state_2'] ) ? strip_tags( $new_instance['nearby_state_2'] ) : ''; |
190
|
|
|
$instance['nearby_state_3'] = ! empty( $new_instance['nearby_state_3'] ) ? strip_tags( $new_instance['nearby_state_3'] ) : ''; |
191
|
|
|
$instance['nearby_state_4'] = ! empty( $new_instance['nearby_state_4'] ) ? strip_tags( $new_instance['nearby_state_4'] ) : ''; |
192
|
|
|
|
193
|
|
|
return $instance; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Register HomeFinder.com Homes for Sale Widget. |
199
|
|
|
* |
200
|
|
|
* @access public |
201
|
|
|
* @return void |
202
|
|
|
*/ |
203
|
|
|
function repro_homefinder_affiliate_search() { |
204
|
|
|
if ( ! is_ssl() ) { |
205
|
|
|
register_widget( 'HomeFinderAffiliateSearch' ); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
add_action( 'widgets_init', 'repro_homefinder_affiliate_search' ); |
209
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.