author | Anthony Ly <anthonyly.com@gmail.com> |
Wed, 19 Dec 2012 17:50:20 -0800 | |
changeset 205 | a4f7897e21a9 |
parent 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* Default Widgets |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Widgets |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Pages widget class |
|
11 |
* |
|
12 |
* @since 2.8.0 |
|
13 |
*/ |
|
14 |
class WP_Widget_Pages extends WP_Widget { |
|
15 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
16 |
function __construct() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
17 |
$widget_ops = array('classname' => 'widget_pages', 'description' => __( 'Your site’s WordPress Pages') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
18 |
parent::__construct('pages', __('Pages'), $widget_ops); |
136 | 19 |
} |
20 |
||
21 |
function widget( $args, $instance ) { |
|
22 |
extract( $args ); |
|
23 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
24 |
$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base); |
136 | 25 |
$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby']; |
26 |
$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude']; |
|
27 |
||
28 |
if ( $sortby == 'menu_order' ) |
|
29 |
$sortby = 'menu_order, post_title'; |
|
30 |
||
31 |
$out = wp_list_pages( apply_filters('widget_pages_args', array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) ) ); |
|
32 |
||
33 |
if ( !empty( $out ) ) { |
|
34 |
echo $before_widget; |
|
35 |
if ( $title) |
|
36 |
echo $before_title . $title . $after_title; |
|
37 |
?> |
|
38 |
<ul> |
|
39 |
<?php echo $out; ?> |
|
40 |
</ul> |
|
41 |
<?php |
|
42 |
echo $after_widget; |
|
43 |
} |
|
44 |
} |
|
45 |
||
46 |
function update( $new_instance, $old_instance ) { |
|
47 |
$instance = $old_instance; |
|
48 |
$instance['title'] = strip_tags($new_instance['title']); |
|
49 |
if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) { |
|
50 |
$instance['sortby'] = $new_instance['sortby']; |
|
51 |
} else { |
|
52 |
$instance['sortby'] = 'menu_order'; |
|
53 |
} |
|
54 |
||
55 |
$instance['exclude'] = strip_tags( $new_instance['exclude'] ); |
|
56 |
||
57 |
return $instance; |
|
58 |
} |
|
59 |
||
60 |
function form( $instance ) { |
|
61 |
//Defaults |
|
62 |
$instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') ); |
|
63 |
$title = esc_attr( $instance['title'] ); |
|
64 |
$exclude = esc_attr( $instance['exclude'] ); |
|
65 |
?> |
|
66 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p> |
|
67 |
<p> |
|
68 |
<label for="<?php echo $this->get_field_id('sortby'); ?>"><?php _e( 'Sort by:' ); ?></label> |
|
69 |
<select name="<?php echo $this->get_field_name('sortby'); ?>" id="<?php echo $this->get_field_id('sortby'); ?>" class="widefat"> |
|
70 |
<option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option> |
|
71 |
<option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option> |
|
72 |
<option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option> |
|
73 |
</select> |
|
74 |
</p> |
|
75 |
<p> |
|
76 |
<label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e( 'Exclude:' ); ?></label> <input type="text" value="<?php echo $exclude; ?>" name="<?php echo $this->get_field_name('exclude'); ?>" id="<?php echo $this->get_field_id('exclude'); ?>" class="widefat" /> |
|
77 |
<br /> |
|
78 |
<small><?php _e( 'Page IDs, separated by commas.' ); ?></small> |
|
79 |
</p> |
|
80 |
<?php |
|
81 |
} |
|
82 |
||
83 |
} |
|
84 |
||
85 |
/** |
|
86 |
* Links widget class |
|
87 |
* |
|
88 |
* @since 2.8.0 |
|
89 |
*/ |
|
90 |
class WP_Widget_Links extends WP_Widget { |
|
91 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
92 |
function __construct() { |
136 | 93 |
$widget_ops = array('description' => __( "Your blogroll" ) ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
94 |
parent::__construct('links', __('Links'), $widget_ops); |
136 | 95 |
} |
96 |
||
97 |
function widget( $args, $instance ) { |
|
98 |
extract($args, EXTR_SKIP); |
|
99 |
||
100 |
$show_description = isset($instance['description']) ? $instance['description'] : false; |
|
101 |
$show_name = isset($instance['name']) ? $instance['name'] : false; |
|
102 |
$show_rating = isset($instance['rating']) ? $instance['rating'] : false; |
|
103 |
$show_images = isset($instance['images']) ? $instance['images'] : true; |
|
104 |
$category = isset($instance['category']) ? $instance['category'] : false; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
105 |
$orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
106 |
$order = $orderby == 'rating' ? 'DESC' : 'ASC'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
107 |
$limit = isset( $instance['limit'] ) ? $instance['limit'] : -1; |
136 | 108 |
|
109 |
$before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget); |
|
110 |
wp_list_bookmarks(apply_filters('widget_links_args', array( |
|
111 |
'title_before' => $before_title, 'title_after' => $after_title, |
|
112 |
'category_before' => $before_widget, 'category_after' => $after_widget, |
|
113 |
'show_images' => $show_images, 'show_description' => $show_description, |
|
114 |
'show_name' => $show_name, 'show_rating' => $show_rating, |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
115 |
'category' => $category, 'class' => 'linkcat widget', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
116 |
'orderby' => $orderby, 'order' => $order, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
117 |
'limit' => $limit, |
136 | 118 |
))); |
119 |
} |
|
120 |
||
121 |
function update( $new_instance, $old_instance ) { |
|
122 |
$new_instance = (array) $new_instance; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
123 |
$instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 ); |
136 | 124 |
foreach ( $instance as $field => $val ) { |
125 |
if ( isset($new_instance[$field]) ) |
|
126 |
$instance[$field] = 1; |
|
127 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
128 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
129 |
$instance['orderby'] = 'name'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
130 |
if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
131 |
$instance['orderby'] = $new_instance['orderby']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
132 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
133 |
$instance['category'] = intval( $new_instance['category'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
134 |
$instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1; |
136 | 135 |
|
136 |
return $instance; |
|
137 |
} |
|
138 |
||
139 |
function form( $instance ) { |
|
140 |
||
141 |
//Defaults |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
142 |
$instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
143 |
$link_cats = get_terms( 'link_category' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
144 |
if ( ! $limit = intval( $instance['limit'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
145 |
$limit = -1; |
136 | 146 |
?> |
147 |
<p> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
148 |
<label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label> |
136 | 149 |
<select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>"> |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
150 |
<option value=""><?php _ex('All Links', 'links widget'); ?></option> |
136 | 151 |
<?php |
152 |
foreach ( $link_cats as $link_cat ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
153 |
echo '<option value="' . intval( $link_cat->term_id ) . '"' |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
154 |
. selected( $instance['category'], $link_cat->term_id, false ) |
136 | 155 |
. '>' . $link_cat->name . "</option>\n"; |
156 |
} |
|
157 |
?> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
158 |
</select> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
159 |
<label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
160 |
<select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat"> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
161 |
<option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
162 |
<option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
163 |
<option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option> |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
164 |
<option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option> |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
165 |
</select> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
166 |
</p> |
136 | 167 |
<p> |
168 |
<input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" /> |
|
169 |
<label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br /> |
|
170 |
<input class="checkbox" type="checkbox" <?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" /> |
|
171 |
<label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br /> |
|
172 |
<input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" /> |
|
173 |
<label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br /> |
|
174 |
<input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" /> |
|
175 |
<label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label> |
|
176 |
</p> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
177 |
<p> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
178 |
<label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
179 |
<input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" /> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
180 |
</p> |
136 | 181 |
<?php |
182 |
} |
|
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* Search widget class |
|
187 |
* |
|
188 |
* @since 2.8.0 |
|
189 |
*/ |
|
190 |
class WP_Widget_Search extends WP_Widget { |
|
191 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
192 |
function __construct() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
193 |
$widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
194 |
parent::__construct('search', __('Search'), $widget_ops); |
136 | 195 |
} |
196 |
||
197 |
function widget( $args, $instance ) { |
|
198 |
extract($args); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
199 |
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
136 | 200 |
|
201 |
echo $before_widget; |
|
202 |
if ( $title ) |
|
203 |
echo $before_title . $title . $after_title; |
|
204 |
||
205 |
// Use current theme search form if it exists |
|
206 |
get_search_form(); |
|
207 |
||
208 |
echo $after_widget; |
|
209 |
} |
|
210 |
||
211 |
function form( $instance ) { |
|
212 |
$instance = wp_parse_args( (array) $instance, array( 'title' => '') ); |
|
213 |
$title = $instance['title']; |
|
214 |
?> |
|
215 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p> |
|
216 |
<?php |
|
217 |
} |
|
218 |
||
219 |
function update( $new_instance, $old_instance ) { |
|
220 |
$instance = $old_instance; |
|
221 |
$new_instance = wp_parse_args((array) $new_instance, array( 'title' => '')); |
|
222 |
$instance['title'] = strip_tags($new_instance['title']); |
|
223 |
return $instance; |
|
224 |
} |
|
225 |
||
226 |
} |
|
227 |
||
228 |
/** |
|
229 |
* Archives widget class |
|
230 |
* |
|
231 |
* @since 2.8.0 |
|
232 |
*/ |
|
233 |
class WP_Widget_Archives extends WP_Widget { |
|
234 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
235 |
function __construct() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
236 |
$widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s posts') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
237 |
parent::__construct('archives', __('Archives'), $widget_ops); |
136 | 238 |
} |
239 |
||
240 |
function widget( $args, $instance ) { |
|
241 |
extract($args); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
242 |
$c = ! empty( $instance['count'] ) ? '1' : '0'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
243 |
$d = ! empty( $instance['dropdown'] ) ? '1' : '0'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
244 |
$title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base); |
136 | 245 |
|
246 |
echo $before_widget; |
|
247 |
if ( $title ) |
|
248 |
echo $before_title . $title . $after_title; |
|
249 |
||
250 |
if ( $d ) { |
|
251 |
?> |
|
252 |
<select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo esc_attr(__('Select Month')); ?></option> <?php wp_get_archives(apply_filters('widget_archives_dropdown_args', array('type' => 'monthly', 'format' => 'option', 'show_post_count' => $c))); ?> </select> |
|
253 |
<?php |
|
254 |
} else { |
|
255 |
?> |
|
256 |
<ul> |
|
257 |
<?php wp_get_archives(apply_filters('widget_archives_args', array('type' => 'monthly', 'show_post_count' => $c))); ?> |
|
258 |
</ul> |
|
259 |
<?php |
|
260 |
} |
|
261 |
||
262 |
echo $after_widget; |
|
263 |
} |
|
264 |
||
265 |
function update( $new_instance, $old_instance ) { |
|
266 |
$instance = $old_instance; |
|
267 |
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') ); |
|
268 |
$instance['title'] = strip_tags($new_instance['title']); |
|
269 |
$instance['count'] = $new_instance['count'] ? 1 : 0; |
|
270 |
$instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0; |
|
271 |
||
272 |
return $instance; |
|
273 |
} |
|
274 |
||
275 |
function form( $instance ) { |
|
276 |
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') ); |
|
277 |
$title = strip_tags($instance['title']); |
|
278 |
$count = $instance['count'] ? 'checked="checked"' : ''; |
|
279 |
$dropdown = $instance['dropdown'] ? 'checked="checked"' : ''; |
|
280 |
?> |
|
281 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> |
|
282 |
<p> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
283 |
<input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e('Display as dropdown'); ?></label> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
284 |
<br/> |
136 | 285 |
<input class="checkbox" type="checkbox" <?php echo $count; ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label> |
286 |
</p> |
|
287 |
<?php |
|
288 |
} |
|
289 |
} |
|
290 |
||
291 |
/** |
|
292 |
* Meta widget class |
|
293 |
* |
|
294 |
* Displays log in/out, RSS feed links, etc. |
|
295 |
* |
|
296 |
* @since 2.8.0 |
|
297 |
*/ |
|
298 |
class WP_Widget_Meta extends WP_Widget { |
|
299 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
300 |
function __construct() { |
136 | 301 |
$widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
302 |
parent::__construct('meta', __('Meta'), $widget_ops); |
136 | 303 |
} |
304 |
||
305 |
function widget( $args, $instance ) { |
|
306 |
extract($args); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
307 |
$title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base); |
136 | 308 |
|
309 |
echo $before_widget; |
|
310 |
if ( $title ) |
|
311 |
echo $before_title . $title . $after_title; |
|
312 |
?> |
|
313 |
<ul> |
|
314 |
<?php wp_register(); ?> |
|
315 |
<li><?php wp_loginout(); ?></li> |
|
316 |
<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li> |
|
317 |
<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
318 |
<li><a href="<?php esc_attr_e( 'http://wordpress.org/' ); ?>" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>"><?php |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
319 |
/* translators: meta widget link text */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
320 |
_e( 'WordPress.org' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
321 |
?></a></li> |
136 | 322 |
<?php wp_meta(); ?> |
323 |
</ul> |
|
324 |
<?php |
|
325 |
echo $after_widget; |
|
326 |
} |
|
327 |
||
328 |
function update( $new_instance, $old_instance ) { |
|
329 |
$instance = $old_instance; |
|
330 |
$instance['title'] = strip_tags($new_instance['title']); |
|
331 |
||
332 |
return $instance; |
|
333 |
} |
|
334 |
||
335 |
function form( $instance ) { |
|
336 |
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); |
|
337 |
$title = strip_tags($instance['title']); |
|
338 |
?> |
|
339 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> |
|
340 |
<?php |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
/** |
|
345 |
* Calendar widget class |
|
346 |
* |
|
347 |
* @since 2.8.0 |
|
348 |
*/ |
|
349 |
class WP_Widget_Calendar extends WP_Widget { |
|
350 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
351 |
function __construct() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
352 |
$widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site’s posts') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
353 |
parent::__construct('calendar', __('Calendar'), $widget_ops); |
136 | 354 |
} |
355 |
||
356 |
function widget( $args, $instance ) { |
|
357 |
extract($args); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
358 |
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); |
136 | 359 |
echo $before_widget; |
360 |
if ( $title ) |
|
361 |
echo $before_title . $title . $after_title; |
|
362 |
echo '<div id="calendar_wrap">'; |
|
363 |
get_calendar(); |
|
364 |
echo '</div>'; |
|
365 |
echo $after_widget; |
|
366 |
} |
|
367 |
||
368 |
function update( $new_instance, $old_instance ) { |
|
369 |
$instance = $old_instance; |
|
370 |
$instance['title'] = strip_tags($new_instance['title']); |
|
371 |
||
372 |
return $instance; |
|
373 |
} |
|
374 |
||
375 |
function form( $instance ) { |
|
376 |
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); |
|
377 |
$title = strip_tags($instance['title']); |
|
378 |
?> |
|
379 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> |
|
380 |
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> |
|
381 |
<?php |
|
382 |
} |
|
383 |
} |
|
384 |
||
385 |
/** |
|
386 |
* Text widget class |
|
387 |
* |
|
388 |
* @since 2.8.0 |
|
389 |
*/ |
|
390 |
class WP_Widget_Text extends WP_Widget { |
|
391 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
392 |
function __construct() { |
136 | 393 |
$widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML')); |
394 |
$control_ops = array('width' => 400, 'height' => 350); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
395 |
parent::__construct('text', __('Text'), $widget_ops, $control_ops); |
136 | 396 |
} |
397 |
||
398 |
function widget( $args, $instance ) { |
|
399 |
extract($args); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
400 |
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
401 |
$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance ); |
136 | 402 |
echo $before_widget; |
403 |
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
404 |
<div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div> |
136 | 405 |
<?php |
406 |
echo $after_widget; |
|
407 |
} |
|
408 |
||
409 |
function update( $new_instance, $old_instance ) { |
|
410 |
$instance = $old_instance; |
|
411 |
$instance['title'] = strip_tags($new_instance['title']); |
|
412 |
if ( current_user_can('unfiltered_html') ) |
|
413 |
$instance['text'] = $new_instance['text']; |
|
414 |
else |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
415 |
$instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed |
136 | 416 |
$instance['filter'] = isset($new_instance['filter']); |
417 |
return $instance; |
|
418 |
} |
|
419 |
||
420 |
function form( $instance ) { |
|
421 |
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) ); |
|
422 |
$title = strip_tags($instance['title']); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
423 |
$text = esc_textarea($instance['text']); |
136 | 424 |
?> |
425 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> |
|
426 |
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> |
|
427 |
||
428 |
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea> |
|
429 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
430 |
<p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p> |
136 | 431 |
<?php |
432 |
} |
|
433 |
} |
|
434 |
||
435 |
/** |
|
436 |
* Categories widget class |
|
437 |
* |
|
438 |
* @since 2.8.0 |
|
439 |
*/ |
|
440 |
class WP_Widget_Categories extends WP_Widget { |
|
441 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
442 |
function __construct() { |
136 | 443 |
$widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
444 |
parent::__construct('categories', __('Categories'), $widget_ops); |
136 | 445 |
} |
446 |
||
447 |
function widget( $args, $instance ) { |
|
448 |
extract( $args ); |
|
449 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
450 |
$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
451 |
$c = ! empty( $instance['count'] ) ? '1' : '0'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
452 |
$h = ! empty( $instance['hierarchical'] ) ? '1' : '0'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
453 |
$d = ! empty( $instance['dropdown'] ) ? '1' : '0'; |
136 | 454 |
|
455 |
echo $before_widget; |
|
456 |
if ( $title ) |
|
457 |
echo $before_title . $title . $after_title; |
|
458 |
||
459 |
$cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h); |
|
460 |
||
461 |
if ( $d ) { |
|
462 |
$cat_args['show_option_none'] = __('Select Category'); |
|
463 |
wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args)); |
|
464 |
?> |
|
465 |
||
466 |
<script type='text/javascript'> |
|
467 |
/* <![CDATA[ */ |
|
468 |
var dropdown = document.getElementById("cat"); |
|
469 |
function onCatChange() { |
|
470 |
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
471 |
location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value; |
136 | 472 |
} |
473 |
} |
|
474 |
dropdown.onchange = onCatChange; |
|
475 |
/* ]]> */ |
|
476 |
</script> |
|
477 |
||
478 |
<?php |
|
479 |
} else { |
|
480 |
?> |
|
481 |
<ul> |
|
482 |
<?php |
|
483 |
$cat_args['title_li'] = ''; |
|
484 |
wp_list_categories(apply_filters('widget_categories_args', $cat_args)); |
|
485 |
?> |
|
486 |
</ul> |
|
487 |
<?php |
|
488 |
} |
|
489 |
||
490 |
echo $after_widget; |
|
491 |
} |
|
492 |
||
493 |
function update( $new_instance, $old_instance ) { |
|
494 |
$instance = $old_instance; |
|
495 |
$instance['title'] = strip_tags($new_instance['title']); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
496 |
$instance['count'] = !empty($new_instance['count']) ? 1 : 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
497 |
$instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
498 |
$instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0; |
136 | 499 |
|
500 |
return $instance; |
|
501 |
} |
|
502 |
||
503 |
function form( $instance ) { |
|
504 |
//Defaults |
|
505 |
$instance = wp_parse_args( (array) $instance, array( 'title' => '') ); |
|
506 |
$title = esc_attr( $instance['title'] ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
507 |
$count = isset($instance['count']) ? (bool) $instance['count'] :false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
508 |
$hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
509 |
$dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false; |
136 | 510 |
?> |
511 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label> |
|
512 |
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p> |
|
513 |
||
514 |
<p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> /> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
515 |
<label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br /> |
136 | 516 |
|
517 |
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> /> |
|
518 |
<label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br /> |
|
519 |
||
520 |
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> /> |
|
521 |
<label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p> |
|
522 |
<?php |
|
523 |
} |
|
524 |
||
525 |
} |
|
526 |
||
527 |
/** |
|
528 |
* Recent_Posts widget class |
|
529 |
* |
|
530 |
* @since 2.8.0 |
|
531 |
*/ |
|
532 |
class WP_Widget_Recent_Posts extends WP_Widget { |
|
533 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
534 |
function __construct() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
535 |
$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
536 |
parent::__construct('recent-posts', __('Recent Posts'), $widget_ops); |
136 | 537 |
$this->alt_option_name = 'widget_recent_entries'; |
538 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
539 |
add_action( 'save_post', array($this, 'flush_widget_cache') ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
540 |
add_action( 'deleted_post', array($this, 'flush_widget_cache') ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
541 |
add_action( 'switch_theme', array($this, 'flush_widget_cache') ); |
136 | 542 |
} |
543 |
||
544 |
function widget($args, $instance) { |
|
545 |
$cache = wp_cache_get('widget_recent_posts', 'widget'); |
|
546 |
||
547 |
if ( !is_array($cache) ) |
|
548 |
$cache = array(); |
|
549 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
550 |
if ( ! isset( $args['widget_id'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
551 |
$args['widget_id'] = $this->id; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
552 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
553 |
if ( isset( $cache[ $args['widget_id'] ] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
554 |
echo $cache[ $args['widget_id'] ]; |
136 | 555 |
return; |
556 |
} |
|
557 |
||
558 |
ob_start(); |
|
559 |
extract($args); |
|
560 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
561 |
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
562 |
if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
563 |
$number = 10; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
564 |
$show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; |
136 | 565 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
566 |
$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) ); |
136 | 567 |
if ($r->have_posts()) : |
568 |
?> |
|
569 |
<?php echo $before_widget; ?> |
|
570 |
<?php if ( $title ) echo $before_title . $title . $after_title; ?> |
|
571 |
<ul> |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
572 |
<?php while ( $r->have_posts() ) : $r->the_post(); ?> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
573 |
<li> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
574 |
<a href="<?php the_permalink() ?>" title="<?php echo esc_attr( get_the_title() ? get_the_title() : get_the_ID() ); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
575 |
<?php if ( $show_date ) : ?> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
576 |
<span class="post-date"><?php echo get_the_date(); ?></span> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
577 |
<?php endif; ?> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
578 |
</li> |
136 | 579 |
<?php endwhile; ?> |
580 |
</ul> |
|
581 |
<?php echo $after_widget; ?> |
|
582 |
<?php |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
583 |
// Reset the global $the_post as this query will have stomped on it |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
584 |
wp_reset_postdata(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
585 |
|
136 | 586 |
endif; |
587 |
||
588 |
$cache[$args['widget_id']] = ob_get_flush(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
589 |
wp_cache_set('widget_recent_posts', $cache, 'widget'); |
136 | 590 |
} |
591 |
||
592 |
function update( $new_instance, $old_instance ) { |
|
593 |
$instance = $old_instance; |
|
594 |
$instance['title'] = strip_tags($new_instance['title']); |
|
595 |
$instance['number'] = (int) $new_instance['number']; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
596 |
$instance['show_date'] = (bool) $new_instance['show_date']; |
136 | 597 |
$this->flush_widget_cache(); |
598 |
||
599 |
$alloptions = wp_cache_get( 'alloptions', 'options' ); |
|
600 |
if ( isset($alloptions['widget_recent_entries']) ) |
|
601 |
delete_option('widget_recent_entries'); |
|
602 |
||
603 |
return $instance; |
|
604 |
} |
|
605 |
||
606 |
function flush_widget_cache() { |
|
607 |
wp_cache_delete('widget_recent_posts', 'widget'); |
|
608 |
} |
|
609 |
||
610 |
function form( $instance ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
611 |
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
612 |
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
613 |
$show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false; |
136 | 614 |
?> |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
615 |
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
616 |
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p> |
136 | 617 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
618 |
<p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
619 |
<input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
620 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
621 |
<p><input class="checkbox" type="checkbox" <?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" /> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
622 |
<label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p> |
136 | 623 |
<?php |
624 |
} |
|
625 |
} |
|
626 |
||
627 |
/** |
|
628 |
* Recent_Comments widget class |
|
629 |
* |
|
630 |
* @since 2.8.0 |
|
631 |
*/ |
|
632 |
class WP_Widget_Recent_Comments extends WP_Widget { |
|
633 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
634 |
function __construct() { |
136 | 635 |
$widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
636 |
parent::__construct('recent-comments', __('Recent Comments'), $widget_ops); |
136 | 637 |
$this->alt_option_name = 'widget_recent_comments'; |
638 |
||
639 |
if ( is_active_widget(false, false, $this->id_base) ) |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
640 |
add_action( 'wp_head', array($this, 'recent_comments_style') ); |
136 | 641 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
642 |
add_action( 'comment_post', array($this, 'flush_widget_cache') ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
643 |
add_action( 'transition_comment_status', array($this, 'flush_widget_cache') ); |
136 | 644 |
} |
645 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
646 |
function recent_comments_style() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
647 |
if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
648 |
|| ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
649 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
650 |
?> |
136 | 651 |
<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style> |
652 |
<?php |
|
653 |
} |
|
654 |
||
655 |
function flush_widget_cache() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
656 |
wp_cache_delete('widget_recent_comments', 'widget'); |
136 | 657 |
} |
658 |
||
659 |
function widget( $args, $instance ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
660 |
global $comments, $comment; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
661 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
662 |
$cache = wp_cache_get('widget_recent_comments', 'widget'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
663 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
664 |
if ( ! is_array( $cache ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
665 |
$cache = array(); |
136 | 666 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
667 |
if ( ! isset( $args['widget_id'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
668 |
$args['widget_id'] = $this->id; |
136 | 669 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
670 |
if ( isset( $cache[ $args['widget_id'] ] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
671 |
echo $cache[ $args['widget_id'] ]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
672 |
return; |
136 | 673 |
} |
674 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
675 |
extract($args, EXTR_SKIP); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
676 |
$output = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
677 |
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Recent Comments' ) : $instance['title'], $instance, $this->id_base ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
678 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
679 |
if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
680 |
$number = 5; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
681 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
682 |
$comments = get_comments( apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
683 |
$output .= $before_widget; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
684 |
if ( $title ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
685 |
$output .= $before_title . $title . $after_title; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
686 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
687 |
$output .= '<ul id="recentcomments">'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
688 |
if ( $comments ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
689 |
// Prime cache for associated posts. (Prime post term cache if we need it for permalinks.) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
690 |
$post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
691 |
_prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
692 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
693 |
foreach ( (array) $comments as $comment) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
694 |
$output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
695 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
696 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
697 |
$output .= '</ul>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
698 |
$output .= $after_widget; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
699 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
700 |
echo $output; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
701 |
$cache[$args['widget_id']] = $output; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
702 |
wp_cache_set('widget_recent_comments', $cache, 'widget'); |
136 | 703 |
} |
704 |
||
705 |
function update( $new_instance, $old_instance ) { |
|
706 |
$instance = $old_instance; |
|
707 |
$instance['title'] = strip_tags($new_instance['title']); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
708 |
$instance['number'] = absint( $new_instance['number'] ); |
136 | 709 |
$this->flush_widget_cache(); |
710 |
||
711 |
$alloptions = wp_cache_get( 'alloptions', 'options' ); |
|
712 |
if ( isset($alloptions['widget_recent_comments']) ) |
|
713 |
delete_option('widget_recent_comments'); |
|
714 |
||
715 |
return $instance; |
|
716 |
} |
|
717 |
||
718 |
function form( $instance ) { |
|
719 |
$title = isset($instance['title']) ? esc_attr($instance['title']) : ''; |
|
720 |
$number = isset($instance['number']) ? absint($instance['number']) : 5; |
|
721 |
?> |
|
722 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> |
|
723 |
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p> |
|
724 |
||
725 |
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of comments to show:'); ?></label> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
726 |
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p> |
136 | 727 |
<?php |
728 |
} |
|
729 |
} |
|
730 |
||
731 |
/** |
|
732 |
* RSS widget class |
|
733 |
* |
|
734 |
* @since 2.8.0 |
|
735 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
736 |
class WP_Widget_RSS extends WP_Widget { |
136 | 737 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
738 |
function __construct() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
739 |
$widget_ops = array( 'description' => __('Entries from any RSS or Atom feed') ); |
136 | 740 |
$control_ops = array( 'width' => 400, 'height' => 200 ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
741 |
parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops ); |
136 | 742 |
} |
743 |
||
744 |
function widget($args, $instance) { |
|
745 |
||
746 |
if ( isset($instance['error']) && $instance['error'] ) |
|
747 |
return; |
|
748 |
||
749 |
extract($args, EXTR_SKIP); |
|
750 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
751 |
$url = ! empty( $instance['url'] ) ? $instance['url'] : ''; |
136 | 752 |
while ( stristr($url, 'http') != $url ) |
753 |
$url = substr($url, 1); |
|
754 |
||
755 |
if ( empty($url) ) |
|
756 |
return; |
|
757 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
758 |
// self-url destruction sequence |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
759 |
if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
760 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
761 |
|
136 | 762 |
$rss = fetch_feed($url); |
763 |
$title = $instance['title']; |
|
764 |
$desc = ''; |
|
765 |
$link = ''; |
|
766 |
||
767 |
if ( ! is_wp_error($rss) ) { |
|
768 |
$desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset')))); |
|
769 |
if ( empty($title) ) |
|
770 |
$title = esc_html(strip_tags($rss->get_title())); |
|
771 |
$link = esc_url(strip_tags($rss->get_permalink())); |
|
772 |
while ( stristr($link, 'http') != $link ) |
|
773 |
$link = substr($link, 1); |
|
774 |
} |
|
775 |
||
776 |
if ( empty($title) ) |
|
777 |
$title = empty($desc) ? __('Unknown Feed') : $desc; |
|
778 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
779 |
$title = apply_filters('widget_title', $title, $instance, $this->id_base); |
136 | 780 |
$url = esc_url(strip_tags($url)); |
781 |
$icon = includes_url('images/rss.png'); |
|
782 |
if ( $title ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
783 |
$title = "<a class='rsswidget' href='$url' title='" . esc_attr__( 'Syndicate this content' ) ."'><img style='border:0' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>"; |
136 | 784 |
|
785 |
echo $before_widget; |
|
786 |
if ( $title ) |
|
787 |
echo $before_title . $title . $after_title; |
|
788 |
wp_widget_rss_output( $rss, $instance ); |
|
789 |
echo $after_widget; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
790 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
791 |
if ( ! is_wp_error($rss) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
792 |
$rss->__destruct(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
793 |
unset($rss); |
136 | 794 |
} |
795 |
||
796 |
function update($new_instance, $old_instance) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
797 |
$testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) ); |
136 | 798 |
return wp_widget_rss_process( $new_instance, $testurl ); |
799 |
} |
|
800 |
||
801 |
function form($instance) { |
|
802 |
||
803 |
if ( empty($instance) ) |
|
804 |
$instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 ); |
|
805 |
$instance['number'] = $this->number; |
|
806 |
||
807 |
wp_widget_rss_form( $instance ); |
|
808 |
} |
|
809 |
} |
|
810 |
||
811 |
/** |
|
812 |
* Display the RSS entries in a list. |
|
813 |
* |
|
814 |
* @since 2.5.0 |
|
815 |
* |
|
816 |
* @param string|array|object $rss RSS url. |
|
817 |
* @param array $args Widget arguments. |
|
818 |
*/ |
|
819 |
function wp_widget_rss_output( $rss, $args = array() ) { |
|
820 |
if ( is_string( $rss ) ) { |
|
821 |
$rss = fetch_feed($rss); |
|
822 |
} elseif ( is_array($rss) && isset($rss['url']) ) { |
|
823 |
$args = $rss; |
|
824 |
$rss = fetch_feed($rss['url']); |
|
825 |
} elseif ( !is_object($rss) ) { |
|
826 |
return; |
|
827 |
} |
|
828 |
||
829 |
if ( is_wp_error($rss) ) { |
|
830 |
if ( is_admin() || current_user_can('manage_options') ) |
|
831 |
echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>'; |
|
832 |
return; |
|
833 |
} |
|
834 |
||
835 |
$default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 ); |
|
836 |
$args = wp_parse_args( $args, $default_args ); |
|
837 |
extract( $args, EXTR_SKIP ); |
|
838 |
||
839 |
$items = (int) $items; |
|
840 |
if ( $items < 1 || 20 < $items ) |
|
841 |
$items = 10; |
|
842 |
$show_summary = (int) $show_summary; |
|
843 |
$show_author = (int) $show_author; |
|
844 |
$show_date = (int) $show_date; |
|
845 |
||
846 |
if ( !$rss->get_item_quantity() ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
847 |
echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>'; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
848 |
$rss->__destruct(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
849 |
unset($rss); |
136 | 850 |
return; |
851 |
} |
|
852 |
||
853 |
echo '<ul>'; |
|
854 |
foreach ( $rss->get_items(0, $items) as $item ) { |
|
855 |
$link = $item->get_link(); |
|
856 |
while ( stristr($link, 'http') != $link ) |
|
857 |
$link = substr($link, 1); |
|
858 |
$link = esc_url(strip_tags($link)); |
|
859 |
$title = esc_attr(strip_tags($item->get_title())); |
|
860 |
if ( empty($title) ) |
|
861 |
$title = __('Untitled'); |
|
862 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
863 |
$desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
864 |
$desc = wp_html_excerpt( $desc, 360 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
865 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
866 |
// Append ellipsis. Change existing [...] to […]. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
867 |
if ( '[...]' == substr( $desc, -5 ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
868 |
$desc = substr( $desc, 0, -5 ) . '[…]'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
869 |
elseif ( '[…]' != substr( $desc, -10 ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
870 |
$desc .= ' […]'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
871 |
|
136 | 872 |
$desc = esc_html( $desc ); |
873 |
||
874 |
if ( $show_summary ) { |
|
875 |
$summary = "<div class='rssSummary'>$desc</div>"; |
|
876 |
} else { |
|
877 |
$summary = ''; |
|
878 |
} |
|
879 |
||
880 |
$date = ''; |
|
881 |
if ( $show_date ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
882 |
$date = $item->get_date( 'U' ); |
136 | 883 |
|
884 |
if ( $date ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
885 |
$date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>'; |
136 | 886 |
} |
887 |
} |
|
888 |
||
889 |
$author = ''; |
|
890 |
if ( $show_author ) { |
|
891 |
$author = $item->get_author(); |
|
892 |
if ( is_object($author) ) { |
|
893 |
$author = $author->get_name(); |
|
894 |
$author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>'; |
|
895 |
} |
|
896 |
} |
|
897 |
||
898 |
if ( $link == '' ) { |
|
899 |
echo "<li>$title{$date}{$summary}{$author}</li>"; |
|
900 |
} else { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
901 |
echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>"; |
136 | 902 |
} |
903 |
} |
|
904 |
echo '</ul>'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
905 |
$rss->__destruct(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
906 |
unset($rss); |
136 | 907 |
} |
908 |
||
909 |
/** |
|
910 |
* Display RSS widget options form. |
|
911 |
* |
|
912 |
* The options for what fields are displayed for the RSS form are all booleans |
|
913 |
* and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author', |
|
914 |
* 'show_date'. |
|
915 |
* |
|
916 |
* @since 2.5.0 |
|
917 |
* |
|
918 |
* @param array|string $args Values for input fields. |
|
919 |
* @param array $inputs Override default display options. |
|
920 |
*/ |
|
921 |
function wp_widget_rss_form( $args, $inputs = null ) { |
|
922 |
||
923 |
$default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true ); |
|
924 |
$inputs = wp_parse_args( $inputs, $default_inputs ); |
|
925 |
extract( $args ); |
|
926 |
extract( $inputs, EXTR_SKIP); |
|
927 |
||
928 |
$number = esc_attr( $number ); |
|
929 |
$title = esc_attr( $title ); |
|
930 |
$url = esc_url( $url ); |
|
931 |
$items = (int) $items; |
|
932 |
if ( $items < 1 || 20 < $items ) |
|
933 |
$items = 10; |
|
934 |
$show_summary = (int) $show_summary; |
|
935 |
$show_author = (int) $show_author; |
|
936 |
$show_date = (int) $show_date; |
|
937 |
||
938 |
if ( !empty($error) ) |
|
939 |
echo '<p class="widget-error"><strong>' . sprintf( __('RSS Error: %s'), $error) . '</strong></p>'; |
|
940 |
||
941 |
if ( $inputs['url'] ) : |
|
942 |
?> |
|
943 |
<p><label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?></label> |
|
944 |
<input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /></p> |
|
945 |
<?php endif; if ( $inputs['title'] ) : ?> |
|
946 |
<p><label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label> |
|
947 |
<input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p> |
|
948 |
<?php endif; if ( $inputs['items'] ) : ?> |
|
949 |
<p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label> |
|
950 |
<select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]"> |
|
951 |
<?php |
|
952 |
for ( $i = 1; $i <= 20; ++$i ) |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
953 |
echo "<option value='$i' " . selected( $items, $i, false ) . ">$i</option>"; |
136 | 954 |
?> |
955 |
</select></p> |
|
956 |
<?php endif; if ( $inputs['show_summary'] ) : ?> |
|
957 |
<p><input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/> |
|
958 |
<label for="rss-show-summary-<?php echo $number; ?>"><?php _e('Display item content?'); ?></label></p> |
|
959 |
<?php endif; if ( $inputs['show_author'] ) : ?> |
|
960 |
<p><input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/> |
|
961 |
<label for="rss-show-author-<?php echo $number; ?>"><?php _e('Display item author if available?'); ?></label></p> |
|
962 |
<?php endif; if ( $inputs['show_date'] ) : ?> |
|
963 |
<p><input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/> |
|
964 |
<label for="rss-show-date-<?php echo $number; ?>"><?php _e('Display item date?'); ?></label></p> |
|
965 |
<?php |
|
966 |
endif; |
|
967 |
foreach ( array_keys($default_inputs) as $input ) : |
|
968 |
if ( 'hidden' === $inputs[$input] ) : |
|
969 |
$id = str_replace( '_', '-', $input ); |
|
970 |
?> |
|
971 |
<input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" /> |
|
972 |
<?php |
|
973 |
endif; |
|
974 |
endforeach; |
|
975 |
} |
|
976 |
||
977 |
/** |
|
978 |
* Process RSS feed widget data and optionally retrieve feed items. |
|
979 |
* |
|
980 |
* The feed widget can not have more than 20 items or it will reset back to the |
|
981 |
* default, which is 10. |
|
982 |
* |
|
983 |
* The resulting array has the feed title, feed url, feed link (from channel), |
|
984 |
* feed items, error (if any), and whether to show summary, author, and date. |
|
985 |
* All respectively in the order of the array elements. |
|
986 |
* |
|
987 |
* @since 2.5.0 |
|
988 |
* |
|
989 |
* @param array $widget_rss RSS widget feed data. Expects unescaped data. |
|
990 |
* @param bool $check_feed Optional, default is true. Whether to check feed for errors. |
|
991 |
* @return array |
|
992 |
*/ |
|
993 |
function wp_widget_rss_process( $widget_rss, $check_feed = true ) { |
|
994 |
$items = (int) $widget_rss['items']; |
|
995 |
if ( $items < 1 || 20 < $items ) |
|
996 |
$items = 10; |
|
997 |
$url = esc_url_raw(strip_tags( $widget_rss['url'] )); |
|
998 |
$title = trim(strip_tags( $widget_rss['title'] )); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
999 |
$show_summary = isset($widget_rss['show_summary']) ? (int) $widget_rss['show_summary'] : 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1000 |
$show_author = isset($widget_rss['show_author']) ? (int) $widget_rss['show_author'] :0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1001 |
$show_date = isset($widget_rss['show_date']) ? (int) $widget_rss['show_date'] : 0; |
136 | 1002 |
|
1003 |
if ( $check_feed ) { |
|
1004 |
$rss = fetch_feed($url); |
|
1005 |
$error = false; |
|
1006 |
$link = ''; |
|
1007 |
if ( is_wp_error($rss) ) { |
|
1008 |
$error = $rss->get_error_message(); |
|
1009 |
} else { |
|
1010 |
$link = esc_url(strip_tags($rss->get_permalink())); |
|
1011 |
while ( stristr($link, 'http') != $link ) |
|
1012 |
$link = substr($link, 1); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1013 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1014 |
$rss->__destruct(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1015 |
unset($rss); |
136 | 1016 |
} |
1017 |
} |
|
1018 |
||
1019 |
return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); |
|
1020 |
} |
|
1021 |
||
1022 |
/** |
|
1023 |
* Tag cloud widget class |
|
1024 |
* |
|
1025 |
* @since 2.8.0 |
|
1026 |
*/ |
|
1027 |
class WP_Widget_Tag_Cloud extends WP_Widget { |
|
1028 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1029 |
function __construct() { |
136 | 1030 |
$widget_ops = array( 'description' => __( "Your most used tags in cloud format") ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1031 |
parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops); |
136 | 1032 |
} |
1033 |
||
1034 |
function widget( $args, $instance ) { |
|
1035 |
extract($args); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1036 |
$current_taxonomy = $this->_get_current_taxonomy($instance); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1037 |
if ( !empty($instance['title']) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1038 |
$title = $instance['title']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1039 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1040 |
if ( 'post_tag' == $current_taxonomy ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1041 |
$title = __('Tags'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1042 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1043 |
$tax = get_taxonomy($current_taxonomy); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1044 |
$title = $tax->labels->name; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1045 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1046 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1047 |
$title = apply_filters('widget_title', $title, $instance, $this->id_base); |
136 | 1048 |
|
1049 |
echo $before_widget; |
|
1050 |
if ( $title ) |
|
1051 |
echo $before_title . $title . $after_title; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1052 |
echo '<div class="tagcloud">'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1053 |
wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) ); |
136 | 1054 |
echo "</div>\n"; |
1055 |
echo $after_widget; |
|
1056 |
} |
|
1057 |
||
1058 |
function update( $new_instance, $old_instance ) { |
|
1059 |
$instance['title'] = strip_tags(stripslashes($new_instance['title'])); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1060 |
$instance['taxonomy'] = stripslashes($new_instance['taxonomy']); |
136 | 1061 |
return $instance; |
1062 |
} |
|
1063 |
||
1064 |
function form( $instance ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1065 |
$current_taxonomy = $this->_get_current_taxonomy($instance); |
136 | 1066 |
?> |
1067 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1068 |
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1069 |
<p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1070 |
<select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>"> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1071 |
<?php foreach ( get_taxonomies() as $taxonomy ) : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1072 |
$tax = get_taxonomy($taxonomy); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1073 |
if ( !$tax->show_tagcloud || empty($tax->labels->name) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1074 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1075 |
?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1076 |
<option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1077 |
<?php endforeach; ?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1078 |
</select></p><?php |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1079 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1080 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1081 |
function _get_current_taxonomy($instance) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1082 |
if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1083 |
return $instance['taxonomy']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1084 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1085 |
return 'post_tag'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1086 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1087 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1088 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1089 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1090 |
* Navigation Menu widget class |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1091 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1092 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1093 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1094 |
class WP_Nav_Menu_Widget extends WP_Widget { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1095 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1096 |
function __construct() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1097 |
$widget_ops = array( 'description' => __('Use this widget to add one of your custom menus as a widget.') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1098 |
parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1099 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1100 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1101 |
function widget($args, $instance) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1102 |
// Get menu |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1103 |
$nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1104 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1105 |
if ( !$nav_menu ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1106 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1107 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1108 |
$instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1109 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1110 |
echo $args['before_widget']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1111 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1112 |
if ( !empty($instance['title']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1113 |
echo $args['before_title'] . $instance['title'] . $args['after_title']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1114 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1115 |
wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1116 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1117 |
echo $args['after_widget']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1118 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1119 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1120 |
function update( $new_instance, $old_instance ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1121 |
$instance['title'] = strip_tags( stripslashes($new_instance['title']) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1122 |
$instance['nav_menu'] = (int) $new_instance['nav_menu']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1123 |
return $instance; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1124 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1125 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1126 |
function form( $instance ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1127 |
$title = isset( $instance['title'] ) ? $instance['title'] : ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1128 |
$nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1129 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1130 |
// Get menus |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1131 |
$menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1132 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1133 |
// If no menus exists, direct the user to go and create some. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1134 |
if ( !$menus ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1135 |
echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1136 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1137 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1138 |
?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1139 |
<p> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1140 |
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1141 |
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" /> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1142 |
</p> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1143 |
<p> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1144 |
<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1145 |
<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>"> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1146 |
<?php |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1147 |
foreach ( $menus as $menu ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1148 |
echo '<option value="' . $menu->term_id . '"' |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1149 |
. selected( $nav_menu, $menu->term_id, false ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1150 |
. '>'. $menu->name . '</option>'; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1151 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1152 |
?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1153 |
</select> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1154 |
</p> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1155 |
<?php |
136 | 1156 |
} |
1157 |
} |
|
1158 |
||
1159 |
/** |
|
1160 |
* Register all of the default WordPress widgets on startup. |
|
1161 |
* |
|
1162 |
* Calls 'widgets_init' action after all of the WordPress widgets have been |
|
1163 |
* registered. |
|
1164 |
* |
|
1165 |
* @since 2.2.0 |
|
1166 |
*/ |
|
1167 |
function wp_widgets_init() { |
|
1168 |
if ( !is_blog_installed() ) |
|
1169 |
return; |
|
1170 |
||
1171 |
register_widget('WP_Widget_Pages'); |
|
1172 |
||
1173 |
register_widget('WP_Widget_Calendar'); |
|
1174 |
||
1175 |
register_widget('WP_Widget_Archives'); |
|
1176 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1177 |
if ( get_option( 'link_manager_enabled' ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1178 |
register_widget('WP_Widget_Links'); |
136 | 1179 |
|
1180 |
register_widget('WP_Widget_Meta'); |
|
1181 |
||
1182 |
register_widget('WP_Widget_Search'); |
|
1183 |
||
1184 |
register_widget('WP_Widget_Text'); |
|
1185 |
||
1186 |
register_widget('WP_Widget_Categories'); |
|
1187 |
||
1188 |
register_widget('WP_Widget_Recent_Posts'); |
|
1189 |
||
1190 |
register_widget('WP_Widget_Recent_Comments'); |
|
1191 |
||
1192 |
register_widget('WP_Widget_RSS'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1193 |
|
136 | 1194 |
register_widget('WP_Widget_Tag_Cloud'); |
1195 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1196 |
register_widget('WP_Nav_Menu_Widget'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
144
diff
changeset
|
1197 |
|
136 | 1198 |
do_action('widgets_init'); |
1199 |
} |
|
1200 |
||
1201 |
add_action('init', 'wp_widgets_init', 1); |