1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/* Exit if accessed directly. */ |
4
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; } |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Zillow Newest For Sale Homes Widget (http://www.zillow.com/webtools/widgets/NewestForSaleHomes.htm) |
8
|
|
|
* |
9
|
|
|
* @package RE-PRO |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* ZillowNewestHomesWidget class. |
14
|
|
|
* |
15
|
|
|
* @extends WP_Widget |
16
|
|
|
*/ |
17
|
|
View Code Duplication |
class ZillowNewestHomesWidget 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_newest_forsale_homes_widget', |
30
|
|
|
__( 'Zillow Newest For Sale Homes', 're-pro' ), |
31
|
|
|
array( |
32
|
|
|
'description' => __( 'Display the most recent for sale homes from Zillow.', 're-pro' ), |
33
|
|
|
'classname' => 're-pro re-pro-widget zillow-widget zillow-widget-newest-homes', |
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
|
|
|
$size = ! empty( $instance['size'] ) ? $instance['size'] : ''; |
|
|
|
|
53
|
|
|
$location = ! empty( $instance['location'] ) ? $instance['location'] : ''; |
54
|
|
|
|
55
|
|
|
echo $args['before_widget']; |
56
|
|
|
|
57
|
|
|
echo $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
$zillow_widgets = new ZillowWidgets(); |
61
|
|
|
|
62
|
|
|
$zillow_widgets->get_newest_forsale_homes_widget( $iframe_id, $location, 'iframe', 'wide' ); |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
echo $args['after_widget']; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Form function. |
70
|
|
|
* |
71
|
|
|
* @access public |
72
|
|
|
* @param mixed $instance Instance. |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
public function form( $instance ) { |
76
|
|
|
|
77
|
|
|
// Set default values. |
78
|
|
|
$instance = wp_parse_args( (array) $instance, array( |
79
|
|
|
'title' => '', |
80
|
|
|
'type' => 'iframe', |
81
|
|
|
'size' => 'wide', |
82
|
|
|
'location' => 'El Segundo, CA', |
83
|
|
|
)); |
84
|
|
|
|
85
|
|
|
// Retrieve an existing value from the database. |
86
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
87
|
|
|
$location = ! empty( $instance['location'] ) ? $instance['location'] : ''; |
88
|
|
|
|
89
|
|
|
// Title. |
90
|
|
|
echo '<p>'; |
91
|
|
|
echo ' <label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>'; |
92
|
|
|
echo ' <input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title . '" class="widefat">'; |
93
|
|
|
echo '</p>'; |
94
|
|
|
|
95
|
|
|
// Location. |
96
|
|
|
echo '<p>'; |
97
|
|
|
echo ' <label for="' . $this->get_field_id( 'location' ) . '" class="title-label">' . __( 'Location:', 're-pro' ) . '</label>'; |
98
|
|
|
echo ' <input id="' . $this->get_field_id( 'location' ) . '" placeholder="El Segundo, CA" name="' . $this->get_field_name( 'location' ) . '" value="' . $location . '" class="widefat">'; |
99
|
|
|
echo '</p>'; |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Update Widget Instance. |
105
|
|
|
* |
106
|
|
|
* @access public |
107
|
|
|
* @param mixed $new_instance New Instance. |
108
|
|
|
* @param mixed $old_instance Old Instance. |
109
|
|
|
* @return $instance |
|
|
|
|
110
|
|
|
*/ |
111
|
|
|
public function update( $new_instance, $old_instance ) { |
112
|
|
|
|
113
|
|
|
$instance = $old_instance; |
114
|
|
|
|
115
|
|
|
$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
116
|
|
|
$instance['type'] = ! empty( $new_instance['type'] ) ? strip_tags( $new_instance['type'] ) : ''; |
117
|
|
|
$instance['size'] = ! empty( $new_instance['size'] ) ? strip_tags( $new_instance['size'] ) : ''; |
118
|
|
|
$instance['location'] = ! empty( $new_instance['location'] ) ? strip_tags( $new_instance['location'] ) : ''; |
119
|
|
|
|
120
|
|
|
return $instance; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Register Zillow Affordability Calculator Widget. |
126
|
|
|
* |
127
|
|
|
* @access public |
128
|
|
|
* @return void |
129
|
|
|
*/ |
130
|
|
|
function repro_zillow_newest_homes_widget() { |
131
|
|
|
|
132
|
|
|
register_widget( 'ZillowNewestHomesWidget' ); |
133
|
|
|
} |
134
|
|
|
add_action( 'widgets_init', 'repro_zillow_newest_homes_widget' ); |
135
|
|
|
|
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.