1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/* Exit if accessed directly. */ |
4
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; } |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Zillow Review Widget (https://www.zillow.com/webtools/widgets/review-widget/) |
8
|
|
|
* |
9
|
|
|
* @package RE-PRO |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Zillow Review Widget class. |
14
|
|
|
* |
15
|
|
|
* @extends WP_Widget |
16
|
|
|
*/ |
17
|
|
|
class ZillowReviewWidget 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_review_widget', |
30
|
|
|
__( 'Zillow Reviews', 're-pro' ), |
31
|
|
|
array( |
32
|
|
|
'description' => __( 'Display a ratings link to your Zillow Reviews.', 're-pro' ), |
33
|
|
|
'classname' => 're-pro re-pro-widget zillow-widget zillow-widget-reviews', |
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
|
|
|
$screenname = ! empty( $instance['screenname'] ) ? $instance['screenname'] : ''; |
52
|
|
|
$zuid = ! empty( $instance['zuid'] ) ? $instance['zuid'] : ''; |
53
|
|
|
$size = ! empty( $instance['size'] ) ? $instance['size'] : 'wide'; |
54
|
|
|
$zmod = ! empty( $instance['zmod'] ) ? $instance['zmod'] : 'true'; |
55
|
|
|
$height = ! empty( $instance['height'] ) ? $instance['height'] : ''; |
56
|
|
|
$width = ! empty( $instance['width'] ) ? $instance['width'] : ''; |
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_review_widget( $iframe_id, $zuid, $screenname, $size, $zmod, $width, $height ); |
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
|
|
|
'screenname' => '', |
82
|
|
|
'zuid' => '', |
83
|
|
|
'size' => 'wide', |
84
|
|
|
'zmod' => 'true', |
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
|
|
|
$zuid = ! empty( $instance['zuid'] ) ? $instance['zuid'] : ''; |
91
|
|
|
$size = ! empty( $instance['size'] ) ? $instance['size'] : ''; |
|
|
|
|
92
|
|
|
$zmod = ! empty( $instance['zmod'] ) ? $instance['zmod'] : ''; |
|
|
|
|
93
|
|
|
$height = ! empty( $instance['height'] ) ? $instance['height'] : ''; |
94
|
|
|
$width = ! empty( $instance['width'] ) ? $instance['width'] : ''; |
95
|
|
|
|
96
|
|
|
// Title. |
97
|
|
|
echo '<p>'; |
98
|
|
|
echo ' <label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>'; |
99
|
|
|
echo ' <input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title . '" class="widefat">'; |
100
|
|
|
echo '</p>'; |
101
|
|
|
|
102
|
|
|
// Zillow Screenname. |
103
|
|
|
echo '<p>'; |
104
|
|
|
echo ' <label for="' . $this->get_field_id( 'screenname' ) . '" class="title-label">' . __( 'Zillow Screenname:', 're-pro' ) . '</label>'; |
105
|
|
|
echo ' <input id="' . $this->get_field_id( 'screenname' ) . '" name="' . $this->get_field_name( 'screenname' ) . '" value="' . $screenname . '" class="widefat">'; |
106
|
|
|
echo '</p>'; |
107
|
|
|
|
108
|
|
|
// Zillow User ID. |
109
|
|
|
echo '<p>'; |
110
|
|
|
echo ' <label for="' . $this->get_field_id( 'zuid' ) . '" class="title-label">' . __( 'Zillow User ID:', 're-pro' ) . '</label>'; |
111
|
|
|
echo ' <input id="' . $this->get_field_id( 'zuid' ) . '" name="' . $this->get_field_name( 'zuid' ) . '" value="' . $zuid . '" class="widefat">'; |
112
|
|
|
echo '</p>'; |
113
|
|
|
|
114
|
|
|
// Width Option. |
115
|
|
|
echo '<p>'; |
116
|
|
|
echo ' <label for="' . $this->get_field_id( 'width' ) . '" class="title-label">' . __( 'Width:', 're-pro' ) . '</label>'; |
117
|
|
|
echo ' <input id="' . $this->get_field_id( 'width' ) . '" name="' . $this->get_field_name( 'width' ) . '" value="' . $width . '" class="widefat">'; |
118
|
|
|
echo '</p>'; |
119
|
|
|
|
120
|
|
|
// Height Option |
121
|
|
|
echo '<p>'; |
122
|
|
|
echo ' <label for="' . $this->get_field_id( 'height' ) . '" class="title-label">' . __( 'Height:', 're-pro' ) . '</label>'; |
123
|
|
|
echo ' <input id="' . $this->get_field_id( 'height' ) . '" name="' . $this->get_field_name( 'height' ) . '" value="' . $height . '" class="widefat">'; |
124
|
|
|
echo '</p>'; |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Update. |
130
|
|
|
* |
131
|
|
|
* @access public |
132
|
|
|
* @param mixed $new_instance New Instance. |
133
|
|
|
* @param mixed $old_instance Old Instance. |
134
|
|
|
* @return $instance |
|
|
|
|
135
|
|
|
*/ |
136
|
|
|
public function update( $new_instance, $old_instance ) { |
137
|
|
|
|
138
|
|
|
$instance = $old_instance; |
139
|
|
|
|
140
|
|
|
$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
141
|
|
|
$instance['screenname'] = ! empty( $new_instance['screenname'] ) ? strip_tags( $new_instance['screenname'] ) : ''; |
142
|
|
|
$instance['zuid'] = ! empty( $new_instance['zuid'] ) ? strip_tags( $new_instance['zuid'] ) : ''; |
143
|
|
|
$instance['size'] = ! empty( $new_instance['size'] ) ? strip_tags( $new_instance['size'] ) : ''; |
144
|
|
|
$instance['zmod'] = ! empty( $new_instance['zmod'] ) ? strip_tags( $new_instance['zmod'] ) : ''; |
145
|
|
|
$instance['height'] = ! empty( $new_instance['height'] ) ? strip_tags( $new_instance['height'] ) : ''; |
146
|
|
|
$instance['width'] = ! empty( $new_instance['width'] ) ? strip_tags( $new_instance['width'] ) : ''; |
147
|
|
|
|
148
|
|
|
return $instance; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Register Zillow Review Widget. |
154
|
|
|
* |
155
|
|
|
* @access public |
156
|
|
|
* @return void |
157
|
|
|
*/ |
158
|
|
|
function repro_zillow_review_widget() { |
159
|
|
|
|
160
|
|
|
register_widget( 'ZillowReviewWidget' ); |
161
|
|
|
} |
162
|
|
|
add_action( 'widgets_init', 'repro_zillow_review_widget' ); |
163
|
|
|
|
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.