1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/* Exit if accessed directly. */ |
4
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; } |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Zillow Past Sales Widget (https://www.zillow.com/webtools/widgets/PastListingsWidget.htm) |
8
|
|
|
* |
9
|
|
|
* @package RE-PRO |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* ZillowPastSalesWidget class. |
14
|
|
|
* |
15
|
|
|
* @extends WP_Widget |
16
|
|
|
*/ |
17
|
|
|
class ZillowPastSalesWidget 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_past_sales_widget', |
30
|
|
|
__( 'Zillow Past Sales', 're-pro' ), |
31
|
|
|
array( |
32
|
|
|
'description' => __( 'Display your past sales from Zillow.', 're-pro' ), |
33
|
|
|
'classname' => 're-pro re-pro-widget zillow-widget zillow-widget-past-sales', |
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
|
|
View Code Duplication |
public function widget( $args, $instance ) { |
|
|
|
|
48
|
|
|
|
49
|
|
|
$iframe_id = ! empty( $args['widget_id'] ) ? $args['widget_id'] : ''; |
50
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
51
|
|
|
$zuid = ! empty( $instance['zuid'] ) ? $instance['zuid'] : ''; |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
echo $args['before_widget']; |
55
|
|
|
|
56
|
|
|
echo $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
57
|
|
|
|
58
|
|
|
$zillow_widgets = new ZillowWidgets(); |
59
|
|
|
|
60
|
|
|
return $zillow_widgets->get_past_listings_widget( $iframe_id, $zuid ); |
61
|
|
|
|
62
|
|
|
echo $args['after_widget']; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Form function. |
67
|
|
|
* |
68
|
|
|
* @access public |
69
|
|
|
* @param mixed $instance Instance. |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
public function form( $instance ) { |
73
|
|
|
|
74
|
|
|
// Set default values. |
75
|
|
|
$instance = wp_parse_args( (array) $instance, array( |
76
|
|
|
'title' => '', |
77
|
|
|
'zuid' => '', |
78
|
|
|
)); |
79
|
|
|
|
80
|
|
|
// Retrieve an existing value from the database. |
81
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
82
|
|
|
$screenname = ! empty( $instance['screenname'] ) ? $instance['screenname'] : ''; |
|
|
|
|
83
|
|
|
$zuid = ! empty( $instance['zuid'] ) ? $instance['zuid'] : ''; |
84
|
|
|
$format = ! empty( $instance['format'] ) ? $instance['format'] : 'format'; |
|
|
|
|
85
|
|
|
|
86
|
|
|
// Title. |
87
|
|
|
echo '<p>'; |
88
|
|
|
echo ' <label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>'; |
89
|
|
|
echo ' <input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title . '" class="widefat">'; |
90
|
|
|
echo '</p>'; |
91
|
|
|
|
92
|
|
|
// Zillow User ID. |
93
|
|
|
echo '<p>'; |
94
|
|
|
echo ' <label for="' . $this->get_field_id( 'zuid' ) . '" class="title-label">' . __( 'Zillow User ID:', 're-pro' ) . '</label>'; |
95
|
|
|
echo ' <input id="' . $this->get_field_id( 'zuid' ) . '" name="' . $this->get_field_name( 'zuid' ) . '" value="' . $zuid . '" class="widefat">'; |
96
|
|
|
echo '</p>'; |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Update. |
102
|
|
|
* |
103
|
|
|
* @access public |
104
|
|
|
* @param mixed $new_instance New Instance. |
105
|
|
|
* @param mixed $old_instance Old Instance. |
106
|
|
|
* @return $instance |
|
|
|
|
107
|
|
|
*/ |
108
|
|
|
public function update( $new_instance, $old_instance ) { |
109
|
|
|
|
110
|
|
|
$instance = $old_instance; |
111
|
|
|
|
112
|
|
|
$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
113
|
|
|
$instance['zuid'] = ! empty( $new_instance['zuid'] ) ? strip_tags( $new_instance['zuid'] ) : ''; |
114
|
|
|
|
115
|
|
|
return $instance; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Register Zillow Review Widget. |
121
|
|
|
* |
122
|
|
|
* @access public |
123
|
|
|
* @return void |
124
|
|
|
*/ |
125
|
|
|
/*function repro_zillow_past_sales_widget() { |
|
|
|
|
126
|
|
|
|
127
|
|
|
register_widget( 'ZillowPastSalesWidget' ); |
128
|
|
|
} |
129
|
|
|
add_action( 'widgets_init', 'repro_zillow_past_sales_widget' );*/ |
130
|
|
|
|
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.