This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
/
wppa-bestof-widget.php
211 lines (183 loc) · 10.5 KB
/
wppa-bestof-widget.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
<?php
/* wppa-bestof-widget.php
* Package: wp-photo-album-plus
*
* display the best rated photos
* Version 6.3.0
*
*/
if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
class BestOfWidget extends WP_Widget {
/** constructor */
function __construct() {
$widget_ops = array('classname' => 'wppa_bestof_widget', 'description' => __( 'WPPA+ Best Of Rated Photos', 'wp-photo-album-plus') );
parent::__construct('wppa_bestof_widget', __('Best Of Photos', 'wp-photo-album-plus'), $widget_ops);
}
/** @see WP_Widget::widget */
function widget( $args, $instance ) {
global $wpdb;
global $wppa;
require_once(dirname(__FILE__) . '/wppa-links.php');
require_once(dirname(__FILE__) . '/wppa-styles.php');
require_once(dirname(__FILE__) . '/wppa-functions.php');
require_once(dirname(__FILE__) . '/wppa-thumbnails.php');
require_once(dirname(__FILE__) . '/wppa-boxes-html.php');
require_once(dirname(__FILE__) . '/wppa-slideshow.php');
wppa_initialize_runtime();
$wppa['in_widget'] = 'bestof';
$wppa['mocc']++;
extract( $args );
$instance = wp_parse_args( (array) $instance, array(
'title' => '',
'count' => '1',
'sortby' => 'maxratingcount',
'display' => 'photo',
'period' => 'thisweek',
'maxratings'=> 'yes',
'meanrat' => 'yes',
'ratcount' => 'yes',
'linktype' => 'none',
) );
$widget_title = apply_filters('widget_title', $instance['title'] );
$page = in_array( $instance['linktype'], $wppa['links_no_page'] ) ? '' : wppa_get_the_landing_page('wppa_bestof_widget_linkpage', __('Best Of Photos', 'wp-photo-album-plus'));
$count = $instance['count'];
$sortby = $instance['sortby'];
$display = $instance['display'];
$period = $instance['period'];
$maxratings = $instance['maxratings'];
$meanrat = $instance['meanrat'];
$ratcount = $instance['ratcount'];
$linktype = $instance['linktype'];
$size = wppa_opt( 'wppa_widget_width' );
// $data = wppa_get_the_bestof( $count, $period, $sortby, $display );
$lineheight = wppa_opt( 'wppa_fontsize_widget_thumb' ) * 1.5;
$widget_content = "\n".'<!-- WPPA+ BestOf Widget start -->';
$widget_content .= wppa_bestof_html( array ( 'page' => $page,
'count' => $count,
'sortby' => $sortby,
'display' => $display,
'period' => $period,
'maxratings' => $maxratings,
'meanrat' => $meanrat,
'ratcount' => $ratcount,
'linktype' => $linktype,
'size' => $size,
'lineheight' => $lineheight
) );
$widget_content .= '<div style="clear:both"></div>';
$widget_content .= "\n".'<!-- WPPA+ BestOf Widget end -->';
echo "\n" . $before_widget;
if ( !empty( $widget_title ) ) { echo $before_title . $widget_title . $after_title; }
echo $widget_content . $after_widget;
}
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['count'] = $new_instance['count'];
$instance['sortby'] = $new_instance['sortby'];
$instance['display'] = $new_instance['display'];
$instance['period'] = $new_instance['period'];
$instance['maxratings'] = $new_instance['maxratings'];
$instance['meanrat'] = $new_instance['meanrat'];
$instance['ratcount'] = $new_instance['ratcount'];
$instance['linktype'] = $new_instance['linktype'];
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
//Defaults
$instance = wp_parse_args( (array) $instance, array(
'title' => __('Best Of Photos', 'wp-photo-album-plus'),
'count' => '1',
'sortby' => 'maxratingcount',
'display' => 'photo',
'period' => 'thisweek',
'maxratings'=> 'yes',
'meanrat' => 'yes',
'ratcount' => 'yes',
'linktype' => 'none'
) );
$widget_title = $instance['title'];
$count = $instance['count'];
$sortby = $instance['sortby'];
$display = $instance['display'];
$period = $instance['period'];
$maxratings = $instance['maxratings'];
$meanrat = $instance['meanrat'];
$ratcount = $instance['ratcount'];
$linktype = $instance['linktype'];
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'wp-photo-album-plus'); ?></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 $widget_title; ?>" />
</p>
<?php
$count_html = '
<select id="'.$this->get_field_id('count').'" name="'.$this->get_field_name('count').'" >
<option value="1" '.( $count == '1' ? 'selected="selected"' : '' ).' >1</option>
<option value="2" '.( $count == '2' ? 'selected="selected"' : '' ).' >2</option>
<option value="3" '.( $count == '3' ? 'selected="selected"' : '' ).' >3</option>
<option value="4" '.( $count == '4' ? 'selected="selected"' : '' ).' >4</option>
<option value="5" '.( $count == '5' ? 'selected="selected"' : '' ).' >5</option>
<option value="6" '.( $count == '6' ? 'selected="selected"' : '' ).' >6</option>
<option value="7" '.( $count == '7' ? 'selected="selected"' : '' ).' >7</option>
<option value="8" '.( $count == '8' ? 'selected="selected"' : '' ).' >8</option>
<option value="9" '.( $count == '9' ? 'selected="selected"' : '' ).' >9</option>
<option value="10" '.( $count == '10' ? 'selected="selected"' : '' ).' >10</option>
</select>
';
$what_html = '
<select id="'.$this->get_field_id('display').'" name="'.$this->get_field_name('display').'" >
<option value="photo" '.( $display == 'photo' ? 'selected="selected"' : '' ).' >'.__('Photo(s)', 'wp-photo-album-plus').'</option>
<option value="owner" '.( $display == 'owner' ? 'selected="selected"' : '' ).' >'.__('Owner(s)', 'wp-photo-album-plus').'</option>
</select>
';
$period_html = '
<select id="'.$this->get_field_id('period').'" name="'.$this->get_field_name('period').'" >
<option value="lastweek" '.( $period == 'lastweek' ? 'selected="selected"' : '' ).' >'.__('Last week', 'wp-photo-album-plus').'</option>
<option value="thisweek" '.( $period == 'thisweek' ? 'selected="selected"' : '' ).' >'.__('This week', 'wp-photo-album-plus').'</option>
<option value="lastmonth" '.( $period == 'lastmonth' ? 'selected="selected"' : '' ).' >'.__('Last month', 'wp-photo-album-plus').'</option>
<option value="thismonth" '.( $period == 'thismonth' ? 'selected="selected"' : '' ).' >'.__('This month', 'wp-photo-album-plus').'</option>
<option value="lastyear" '.( $period == 'lastyear' ? 'selected="selected"' : '' ).' >'.__('Last year', 'wp-photo-album-plus').'</option>
<option value="thisyear" '.( $period == 'thisyear' ? 'selected="selected"' : '' ).' >'.__('This year', 'wp-photo-album-plus').'</option>
</select>
';
$sort_html = '
<select id="'.$this->get_field_id('sortby').'" name="'.$this->get_field_name('sortby').'" >
<option value="maxratingcount" '.( $sortby == 'maxratingcount' ? 'selected="selected"' : '' ).' >'.__('Number of max ratings', 'wp-photo-album-plus').'</option>
<option value="meanrating" '.( $sortby == 'meanrating' ? 'selected="selected"' : '' ).' >'.__('Mean value', 'wp-photo-album-plus').'</option>
<option value="ratingcount" '.( $sortby == 'ratingcount' ? 'selected="selected"' : '' ).' >'.__('Number of votes', 'wp-photo-album-plus').'</option>
</select>
';
_e( sprintf( 'Display the %1s best %2s based on ratings given during %3s and sorted by %4s', $count_html, $what_html, $period_html, $sort_html ) , 'wp-photo-album-plus');
?>
<p><label ><?php _e('Subtitle:', 'wp-photo-album-plus'); ?></label>
<br /><?php _e('No of max ratings:', 'wp-photo-album-plus'); ?>
<select id="<?php echo $this->get_field_id('maxratings'); ?>" name="<?php echo $this->get_field_name('maxratings'); ?>" >
<option value="yes" <?php if ( $meanrat == 'yes' ) echo 'selected="selected"' ?>><?php _e('yes', 'wp-photo-album-plus') ?></option>
<option value="no" <?php if ( $meanrat == 'no' ) echo 'selected="selected"' ?>><?php _e('no', 'wp-photo-album-plus') ?></option>
</select>
<br /><?php _e('Mean rating:', 'wp-photo-album-plus'); ?>
<select id="<?php echo $this->get_field_id('meanrat'); ?>" name="<?php echo $this->get_field_name('meanrat'); ?>" >
<option value="yes" <?php if ( $meanrat == 'yes' ) echo 'selected="selected"' ?>><?php _e('yes', 'wp-photo-album-plus') ?></option>
<option value="no" <?php if ( $meanrat == 'no' ) echo 'selected="selected"' ?>><?php _e('no', 'wp-photo-album-plus') ?></option>
</select>
<br /><?php _e('Rating count:', 'wp-photo-album-plus'); ?>
<select id="<?php echo $this->get_field_id('ratcount'); ?>" name="<?php echo $this->get_field_name('ratcount'); ?>" >
<option value="yes" <?php if ( $ratcount == 'yes' ) echo 'selected="selected"' ?>><?php _e('yes', 'wp-photo-album-plus') ?></option>
<option value="no" <?php if ( $ratcount == 'no' ) echo 'selected="selected"' ?>><?php _e('no', 'wp-photo-album-plus') ?></option>
</select>
</p>
<p><label><?php _e('Link to:', 'wp-photo-album-plus') ?></label>
<select id="<?php echo $this->get_field_id('linktype'); ?>" name="<?php echo $this->get_field_name('linktype'); ?>" >
<option value="none" <?php if ( $linktype == 'none' ) echo 'selected="selected"' ?>><?php _e('--- none ---', 'wp-photo-album-plus') ?></option>
<option value="owneralbums" <?php if ( $linktype == 'owneralbums' ) echo 'selected="selected"' ?>><?php _e('The authors album(s)', 'wp-photo-album-plus') ?></option>
<option value="ownerphotos" <?php if ( $linktype == 'ownerphotos' ) echo 'selected="selected"' ?>><?php _e('The photos in the authors album(s)', 'wp-photo-album-plus') ?></option>
<option value="upldrphotos" <?php if ( $linktype == 'upldrphotos' ) echo 'selected="selected"' ?>><?php _e('All the authors photos', 'wp-photo-album-plus') ?></option>
</select>
</p>
<?php
}
} // class BestOfWidget
// register BestOfWidget widget
add_action( 'widgets_init', create_function( '', 'return register_widget("BestOfWidget" );' ) );