1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/* Exit if accessed directly. */ |
4
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; } |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Zillow Large Search Box Widget (http://www.zillow.com/webtools/widgets/ZillowLargeSearchBox.htm) |
8
|
|
|
* |
9
|
|
|
* @package RE-PRO |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* ZillowLargeSearchBox class. |
14
|
|
|
* |
15
|
|
|
* @extends WP_Widget |
16
|
|
|
*/ |
17
|
|
|
class ZillowLargeSearchBox extends WP_Widget { |
|
|
|
|
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* __construct function. |
22
|
|
|
* |
23
|
|
|
* @access public |
24
|
|
|
* @return void |
|
|
|
|
25
|
|
|
*/ |
26
|
|
|
public function __construct() { |
27
|
|
|
|
28
|
|
|
parent::__construct( |
29
|
|
|
'zillow_large_search_box', |
30
|
|
|
__( 'Zillow Large Search Box', 're-pro' ), |
31
|
|
|
array( |
32
|
|
|
'description' => __( 'Display a Large Search Box from Zillow.', 're-pro' ), |
33
|
|
|
'classname' => 're-pro re-pro-widget zillow-widget zillow-widget-search-box', |
34
|
|
|
'customize_selective_refresh' => true, |
35
|
|
|
) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Widget function. |
41
|
|
|
* |
42
|
|
|
* @access public |
43
|
|
|
* @param mixed $args Arguments. |
44
|
|
|
* @param mixed $instance Instance. |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
public function widget( $args, $instance ) { |
48
|
|
|
|
49
|
|
|
$iframe_id = ! empty( $args['widget_id'] ) ? $args['widget_id'] : ''; |
50
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
51
|
|
|
$type = ! empty( $instance['type'] ) ? $instance['type'] : ''; |
|
|
|
|
52
|
|
|
$screenname = ! empty( $instance['screenname'] ) ? $instance['screenname'] : ''; |
53
|
|
|
$location = ! empty( $instance['location'] ) ? $instance['location'] : ''; |
54
|
|
|
$home_val_info = ! empty( $instance['home_val_info'] ) ? $instance['home_val_info'] : ''; |
55
|
|
|
$home_val_info = ( $home_val_info ) ? 'no' : 'yes'; |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
echo $args['before_widget']; |
59
|
|
|
|
60
|
|
|
echo $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
61
|
|
|
|
62
|
|
|
$zillow_widgets = new ZillowWidgets(); |
63
|
|
|
|
64
|
|
|
$zillow_widgets->get_lg_zillow_search_widget( $iframe_id, $screenname, 'iframe', $location, $home_val_info ); |
65
|
|
|
|
66
|
|
|
echo $args['after_widget']; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Form function. |
71
|
|
|
* |
72
|
|
|
* @access public |
73
|
|
|
* @param mixed $instance Instance. |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
public function form( $instance ) { |
77
|
|
|
|
78
|
|
|
// Set default values. |
79
|
|
|
$instance = wp_parse_args( (array) $instance, array( |
80
|
|
|
'title' => '', |
81
|
|
|
'type' => 'iframe', |
82
|
|
|
'screenname' => '', |
83
|
|
|
'location' => '', |
84
|
|
|
'home_val_info' => 0, |
85
|
|
|
)); |
86
|
|
|
|
87
|
|
|
// Retrieve an existing value from the database. |
88
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
89
|
|
|
$screenname = ! empty( $instance['screenname'] ) ? $instance['screenname'] : ''; |
90
|
|
|
$location = ! empty( $instance['location'] ) ? $instance['location'] : ''; |
91
|
|
|
$home_val_info = ! empty( $instance['home_val_info'] ) ? $instance['home_val_info'] : 0; |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
// Title. |
95
|
|
|
echo '<p>'; |
96
|
|
|
echo ' <label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>'; |
97
|
|
|
echo ' <input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title . '" class="widefat">'; |
98
|
|
|
echo '</p>'; |
99
|
|
|
|
100
|
|
|
// Zillow Screenname. |
101
|
|
|
echo '<p>'; |
102
|
|
|
echo ' <label for="' . $this->get_field_id( 'screenname' ) . '" class="title-label">' . __( 'Zillow Screenname:', 're-pro' ) . '</label>'; |
103
|
|
|
echo ' <input id="' . $this->get_field_id( 'screenname' ) . '" name="' . $this->get_field_name( 'screenname' ) . '" value="' . $screenname . '" class="widefat">'; |
104
|
|
|
echo '</p>'; |
105
|
|
|
|
106
|
|
|
// Location. |
107
|
|
|
echo '<p>'; |
108
|
|
|
echo ' <label for="' . $this->get_field_id( 'location' ) . '" class="title-label">' . __( 'Location:', 're-pro' ) . '</label>'; |
109
|
|
|
echo ' <input id="' . $this->get_field_id( 'location' ) . '" placeholder="El Segundo, CA" name="' . $this->get_field_name( 'location' ) . '" value="' . $location . '" class="widefat">'; |
110
|
|
|
echo '</p>'; |
111
|
|
|
|
112
|
|
|
// Home Value Info |
113
|
|
|
echo '<p>'; |
114
|
|
|
echo '<input value="1" type="checkbox"' . checked( esc_attr( $home_val_info ), 1, false ) . 'id="' . esc_attr( $this->get_field_id( 'home_val_info' ) ) . '" name="' . esc_attr( $this->get_field_name( 'home_val_info' ) ) . '" />'; |
115
|
|
|
echo '<label for="' . $this->get_field_id( 'home_val_info' ) . '">Hide home value information</label>'; |
116
|
|
|
echo '</p>'; |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Update. |
123
|
|
|
* |
124
|
|
|
* @access public |
125
|
|
|
* @param mixed $new_instance New Instance. |
126
|
|
|
* @param mixed $old_instance Old Instance. |
127
|
|
|
* @return $instance |
|
|
|
|
128
|
|
|
*/ |
129
|
|
|
public function update( $new_instance, $old_instance ) { |
130
|
|
|
|
131
|
|
|
$instance = $old_instance; |
132
|
|
|
|
133
|
|
|
$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
134
|
|
|
$instance['screenname'] = ! empty( $new_instance['screenname'] ) ? strip_tags( $new_instance['screenname'] ) : ''; |
135
|
|
|
$instance['location'] = ! empty( $new_instance['location'] ) ? strip_tags( $new_instance['location'] ) : ''; |
136
|
|
|
$instance['home_val_info'] = ! empty( $new_instance['home_val_info'] ) ? strip_tags( $new_instance['home_val_info'] ) : 0; |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
return $instance; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Register Zillow Large Search Box. |
145
|
|
|
* |
146
|
|
|
* @access public |
147
|
|
|
* @return void |
148
|
|
|
*/ |
149
|
|
|
function repro_zillow_search_box_widget() { |
150
|
|
|
|
151
|
|
|
register_widget( 'ZillowLargeSearchBox' ); |
152
|
|
|
} |
153
|
|
|
add_action( 'widgets_init', 'repro_zillow_search_box_widget' ); |
154
|
|
|
|
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.