/
ecs_widgets.php
469 lines (405 loc) · 24.3 KB
/
ecs_widgets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<?php
function ecs_widget_post_display($excerpt_length = 20, $cat = '', $has_comments = false ,$has_date = false) {
// $excerpt_length = empty($instance['excerpt_length']) ? $excerpt_length : $instance['excerpt_length'];
if (empty($cat) && $excerpt_length==0)
echo '<li class="sidebar-link">';
else
echo '<li>';
?>
<?php if (!empty($cat)) :
if ($cat->parent == 0)
$parent = $cat;
else
$parent = get_category($cat->parent);
?>
<span style="color:<?php echo $parent->description ?>"><span style="background-color:<?php echo $parent->description ?>"><i class="icon-chevron-right icon-white"></i></span><?php echo $cat->name ?></span><br/>
<? endif; ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
<?php
$comments_number = get_comments_number();;
if ($has_comments && $comments_number > 0) : ?>
<span class="badge" title="Nb de commentaires"><?php echo get_comments_number(); ?></span>
<? endif; ?>
<p>
<?php
if ($excerpt_length>0)
echo ecs_short_excerpt($excerpt_length);
?>
<?php if ($has_date) : ?>
<br/>
<span class="post-info">Publié le <?php the_time('j/m/Y') ?></span>
<? endif; ?>
</p>
</li>
<?php
}
// RSS Feeds
class Ecs_RSS_Widget extends WP_Widget {
function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? ' ECS RSS Widget' : apply_filters('widget_title', $instance['title']);
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
?>
<a href="<?php bloginfo('rss2_url'); ?>">Fil d'information des articles</a><br/>
<a href="<?php bloginfo('comments_rss2_url'); ?>">Fil d'information des commentaires</a>
<?php
echo $after_widget;
}
function Ecs_RSS_Widget() {
// use parent constructor to re-write standard class properties
parent::WP_Widget('ecs_rss', 'EcoRes RSS Widget', array('description' => 'Liste les flux RSS des articles et des commentaires', 'class' => 'ecores'));
}
function update($new_instance, $old_instance) {
// fill current state with old data to be sure we not loose anything
$instance = $old_instance;
// for example we want title always have capitalized first letter
$instance['title'] = strip_tags($new_instance['title']);
// and now we return new values and wordpress do all work for you
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$default = array( 'title' => __('EcoRes Flux RSS') );
$instance = wp_parse_args( (array) $instance, $default );
$field_id = $this->get_field_id('title');
$field_name = $this->get_field_name('title');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Title').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['title'] ).'" /><label></p>';
}
}
// White on color Menu
class Ecs_Menu_Widget extends WP_Widget {
function widget($args, $instance) {
extract($args, EXTR_SKIP);
$title = empty($instance['title']) ? ' ECS Menu Widget' : apply_filters('widget_title', $instance['title']);
$nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
$color = $instance['color'];
echo '<div class="menu-reverse" style="background-color:'.$color.'">';
echo $before_widget;
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
$args = array(
'menu' => $nav_menu,
);
wp_nav_menu($args);
echo $after_widget;
echo '</div>';
}
function Ecs_Menu_Widget() {
// use parent constructor to re-write standard class properties
parent::WP_Widget('ecs_menu', 'EcoRes Menu Widget', array('description' => 'Affiche le menu dont le nom est saisi ci-dessous', 'class' => 'ecores'));
}
function update($new_instance, $old_instance) {
// fill current state with old data to be sure we not loose anything
$instance = $old_instance;
// for example we want title always have capitalized first letter
$instance['title'] = strip_tags($new_instance['title']);
$instance['color'] = strip_tags($new_instance['color']);
$instance['nav_menu'] = strip_tags($new_instance['nav_menu']);
// and now we return new values and wordpress do all work for you
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$default = array( 'title' => __('EcoRes Menu'),'color' => '', 'nav_menu' => '' );
$instance = wp_parse_args( (array) $instance, $default );
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$color = isset( $instance['color'] ) ? $instance['color'] : '';
$nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
// Get menus
$menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
// If no menus exists, direct the user to go and create some.
if ( !$menus ) {
echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
return;
}
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
<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; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
<?php
foreach ( $menus as $menu ) {
$selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
}
?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('color'); ?>"><?php _e('Color:') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('color'); ?>" name="<?php echo $this->get_field_name('color'); ?>" value="<?php echo $color; ?>" />
</p>
<?php
}
}
// Most viewed
class Ecs_Most_Viewed_Widget extends WP_Widget {
function widget($args, $instance) {
extract($args, EXTR_SKIP);
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
echo $before_widget;
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
global $wpdb;
$temp = '';
$output = '';
$limit = empty($instance['nbposts']) ? -1 : $instance['nbposts'];
// $most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE post_date < '".current_time('mysql')."' AND $wpdb->term_taxonomy.taxonomy = 'post_tag' AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");
// $most_viewed = new WP_Query("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE post_date < '".current_time('mysql')."' AND $wpdb->term_taxonomy.taxonomy = 'post_tag' AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");
$args = array(
'post_status' => 'publish',
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'posts_per_page' => $limit
);
//$request = "SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE post_date < '".current_time('mysql')."' AND $wpdb->term_taxonomy.taxonomy = 'post_tag' AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT ".$limit;
$most_viewed = new WP_Query($args);
// $most_viewed = new WP_Query();
// $most_viewed->request = $request;
// print_r($most_viewed);
if ($most_viewed->have_posts()): ?>
<ul>
<?php while ($most_viewed->have_posts()) : $most_viewed->the_post(); if($instance['show_category']) {$cat = get_post_child_category(get_the_ID());} ?>
<? echo ecs_widget_post_display($instance['excerpt_length'], $cat, $instance['show_comments'], $instance['show_date']); ?>
<?php endwhile; ?>
</ul>
<?php else: ?>
<ul><li>
<p>Pas d'articles les plus lus.</p>
</li></ul>
<?php endif;
echo $after_widget;
wp_reset_query();
}
function Ecs_Most_Viewed_Widget() {
// use parent constructor to re-write standard class properties
parent::WP_Widget('ecs_most_viewed', 'EcoRes Articles les plus lus', array('description' => 'Liste les articles les plus lus', 'class' => 'ecores'));
}
function update($new_instance, $old_instance) {
// fill current state with old data to be sure we not loose anything
$instance = $old_instance;
// for example we want title always have capitalized first letter
$instance['title'] = strip_tags($new_instance['title']);
$instance['nbposts'] = strip_tags($new_instance['nbposts']);
$instance['excerpt_length'] = strip_tags($new_instance['excerpt_length']);
$instance['show_category'] = strip_tags($new_instance['show_category']);
$instance['show_comments'] = strip_tags($new_instance['show_comments']);
$instance['show_date'] = strip_tags($new_instance['show_date']);
// and now we return new values and wordpress do all work for you
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$default = array( 'title' => __('Articles les plus lus'), 'nbposts' => 5, 'show_category' => true, 'show_comments' => false, 'show_date' => false, 'excerpt_length' => 20 );
$instance = wp_parse_args( (array) $instance, $default );
$field_id = $this->get_field_id('title');
$field_name = $this->get_field_name('title');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Title').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['title'] ).'" /><label></p>';
$field_id = $this->get_field_id('nbposts');
$field_name = $this->get_field_name('nbposts');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Nb Articles').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['nbposts'] ).'" /><label></p>';
$field_id = $this->get_field_id('excerpt_length');
$field_name = $this->get_field_name('excerpt_length');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Longueur extrait').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['excerpt_length'] ).'" /><label></p>';
$field_id = $this->get_field_id('show_category');
$field_name = $this->get_field_name('show_category');
echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_category'], true, false ).' /> '.__('Afficher la catégorie').'<label></p>';
$field_id = $this->get_field_id('show_comments');
$field_name = $this->get_field_name('show_comments');
echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_comments'], true, false ).' /> '.__('Afficher nb de commentaires').'<label></p>';
$field_id = $this->get_field_id('show_date');
$field_name = $this->get_field_name('show_date');
echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_date'], true, false ).' /> '.__('Afficher date de publication').'<label></p>';
}
}
// Related Posts Widget
class Ecs_Related_Posts_Widget extends WP_Widget {
function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
if (!function_exists('related_posts') || !related_posts()) {} ;
echo $after_widget;
}
function Ecs_Related_Posts_Widget() {
// use parent constructor to re-write standard class properties
parent::WP_Widget('ecs_related_posts', 'EcoRes Articles similaires', array('description' => 'Articles similaires issus du plugin YARPP', 'class' => 'ecores'));
}
function update($new_instance, $old_instance) {
// fill current state with old data to be sure we not loose anything
$instance = $old_instance;
// for example we want title always have capitalized first letter
$instance['title'] = strip_tags($new_instance['title']);
// $instance['nbposts'] = strip_tags($new_instance['nbposts']);
// $instance['excerpt_length'] = strip_tags($new_instance['excerpt_length']);
// $instance['show_category'] = strip_tags($new_instance['show_category']);
// $instance['show_comments'] = strip_tags($new_instance['show_comments']);
// $instance['show_date'] = strip_tags($new_instance['show_date']);
// and now we return new values and wordpress do all work for you
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$default = array( 'title' => __('Articles similaires') /*, 'nbposts' => 5, 'show_category' => true, 'show_comments' => false, 'show_date' => false, 'excerpt_length' => 20 */ );
$instance = wp_parse_args( (array) $instance, $default );
$field_id = $this->get_field_id('title');
$field_name = $this->get_field_name('title');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Title').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['title'] ).'" /><label></p>';
// $field_id = $this->get_field_id('nbposts');
// $field_name = $this->get_field_name('nbposts');
// echo "\r\n".'<p><label for="'.$field_id.'">'.__('Nb Articles').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['nbposts'] ).'" /><label></p>';
// $field_id = $this->get_field_id('excerpt_length');
// $field_name = $this->get_field_name('excerpt_length');
// echo "\r\n".'<p><label for="'.$field_id.'">'.__('Longueur extrait').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['excerpt_length'] ).'" /><label></p>';
// $field_id = $this->get_field_id('show_category');
// $field_name = $this->get_field_name('show_category');
// echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_category'], true, false ).' /> '.__('Afficher la catégorie').'<label></p>';
// $field_id = $this->get_field_id('show_comments');
// $field_name = $this->get_field_name('show_comments');
// echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_comments'], true, false ).' /> '.__('Afficher nb de commentaires').'<label></p>';
// $field_id = $this->get_field_id('show_date');
// $field_name = $this->get_field_name('show_date');
// echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_date'], true, false ).' /> '.__('Afficher date de publication').'<label></p>';
}
}
// Recent Posts Widget
class Ecs_Recent_Posts_Widget extends WP_Widget {
function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
$nbposts = empty($instance['nbposts']) ? -1 : $instance['nbposts'];
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
$recent_posts = new WP_Query(array('post_type'=>'post','posts_per_page'=>$nbposts)); ?>
<?php if ($recent_posts->have_posts()):?>
<ul>
<?php while ($recent_posts->have_posts()) : $recent_posts->the_post(); if($instance['show_category']) {$cat = get_post_child_category(get_the_ID());} ?>
<? echo ecs_widget_post_display($instance['excerpt_length'], $cat, $instance['show_comments'], $instance['show_date']); ?>
<?php endwhile; ?>
</ul>
<?php else: ?>
<ul><li>
<p>Pas d'articles récents.</p>
</li></ul>
<?php endif; ?>
<?php
echo $after_widget;
wp_reset_query();
}
function Ecs_Recent_Posts_Widget() {
// use parent constructor to re-write standard class properties
parent::WP_Widget('ecs_recent_posts', 'EcoRes Articles récents', array('description' => 'Articles récents de votre blog', 'class' => 'ecores'));
}
function update($new_instance, $old_instance) {
// fill current state with old data to be sure we not loose anything
$instance = $old_instance;
// for example we want title always have capitalized first letter
$instance['title'] = strip_tags($new_instance['title']);
$instance['nbposts'] = strip_tags($new_instance['nbposts']);
$instance['excerpt_length'] = strip_tags($new_instance['excerpt_length']);
$instance['show_category'] = strip_tags($new_instance['show_category']);
$instance['show_comments'] = strip_tags($new_instance['show_comments']);
$instance['show_date'] = strip_tags($new_instance['show_date']);
// and now we return new values and wordpress do all work for you
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$default = array( 'title' => __('Articles récents'), 'nbposts' => 5, 'show_category' => true, 'show_comments' => false, 'show_date' => false, 'excerpt_length' => 20 );
$instance = wp_parse_args( (array) $instance, $default );
$field_id = $this->get_field_id('title');
$field_name = $this->get_field_name('title');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Title').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['title'] ).'" /><label></p>';
$field_id = $this->get_field_id('nbposts');
$field_name = $this->get_field_name('nbposts');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Nb Articles').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['nbposts'] ).'" /><label></p>';
$field_id = $this->get_field_id('excerpt_length');
$field_name = $this->get_field_name('excerpt_length');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Longueur extrait').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['excerpt_length'] ).'" /><label></p>';
$field_id = $this->get_field_id('show_category');
$field_name = $this->get_field_name('show_category');
echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_category'], true, false ).' /> '.__('Afficher la catégorie').'<label></p>';
$field_id = $this->get_field_id('show_comments');
$field_name = $this->get_field_name('show_comments');
echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_comments'], true, false ).' /> '.__('Afficher nb de commentaires').'<label></p>';
$field_id = $this->get_field_id('show_date');
$field_name = $this->get_field_name('show_date');
echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_date'], true, false ).' /> '.__('Afficher date de publication').'<label></p>';
}
}
// Most Commented Posts Widget
class Ecs_Commented_Posts_Widget extends WP_Widget {
function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
$nbposts = empty($instance['nbposts']) ? -1 : $instance['nbposts'];
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
$recent_posts = new WP_Query(array('post_type'=>'post','posts_per_page'=>$nbposts, 'orderby' => 'comment_count')); ?>
<?php if ($recent_posts->have_posts()):?>
<ul>
<?php while ($recent_posts->have_posts()) : $recent_posts->the_post(); if($instance['show_category']) {$cat = get_post_child_category(get_the_ID());} ?>
<? echo ecs_widget_post_display($instance['excerpt_length'], $cat, $instance['show_comments'], $instance['show_date']); ?>
<?php endwhile; ?>
</ul>
<?php else: ?>
<ul><li>
<p>Pas d'articles récents.</p>
</li></ul>
<?php endif; ?>
<?php
echo $after_widget;
wp_reset_query();
}
function Ecs_Commented_Posts_Widget() {
// use parent constructor to re-write standard class properties
parent::WP_Widget('ecs_commented_posts', 'EcoRes Articles commentés', array('description' => 'Articles les plus commentés de votre blog', 'class' => 'ecores'));
}
function update($new_instance, $old_instance) {
// fill current state with old data to be sure we not loose anything
$instance = $old_instance;
// for example we want title always have capitalized first letter
$instance['title'] = strip_tags($new_instance['title']);
$instance['nbposts'] = strip_tags($new_instance['nbposts']);
$instance['excerpt_length'] = strip_tags($new_instance['excerpt_length']);
$instance['show_category'] = strip_tags($new_instance['show_category']);
$instance['show_comments'] = strip_tags($new_instance['show_comments']);
$instance['show_date'] = strip_tags($new_instance['show_date']);
// and now we return new values and wordpress do all work for you
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$default = array( 'title' => __('Articles commentés'), 'nbposts' => 5, 'show_category' => true, 'show_comments' => false, 'show_date' => false, 'excerpt_length' => 20 );
$instance = wp_parse_args( (array) $instance, $default );
$field_id = $this->get_field_id('title');
$field_name = $this->get_field_name('title');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Title').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['title'] ).'" /><label></p>';
$field_id = $this->get_field_id('nbposts');
$field_name = $this->get_field_name('nbposts');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Nb Articles').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['nbposts'] ).'" /><label></p>';
$field_id = $this->get_field_id('excerpt_length');
$field_name = $this->get_field_name('excerpt_length');
echo "\r\n".'<p><label for="'.$field_id.'">'.__('Longueur extrait').': <input type="text" class="widefat" id="'.$field_id.'" name="'.$field_name.'" value="'.attribute_escape( $instance['excerpt_length'] ).'" /><label></p>';
$field_id = $this->get_field_id('show_category');
$field_name = $this->get_field_name('show_category');
echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_category'], true, false ).' /> '.__('Afficher la catégorie').'<label></p>';
$field_id = $this->get_field_id('show_comments');
$field_name = $this->get_field_name('show_comments');
echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_comments'], true, false ).' /> '.__('Afficher nb de commentaires').'<label></p>';
$field_id = $this->get_field_id('show_date');
$field_name = $this->get_field_name('show_date');
echo "\r\n".'<p><label for="'.$field_id.'"><input type="checkbox" id="'.$field_id.'" name="'.$field_name.'" value="1"'.checked($instance['show_date'], true, false ).' /> '.__('Afficher date de publication').'<label></p>';
}
}
register_widget('Ecs_RSS_Widget');
register_widget('Ecs_Menu_Widget');
register_widget('Ecs_Most_Viewed_Widget');
register_widget('Ecs_Related_Posts_Widget');
register_widget('Ecs_Recent_Posts_Widget');
register_widget('Ecs_Commented_Posts_Widget');
?>