-
Notifications
You must be signed in to change notification settings - Fork 82
/
postratings-templates.php
261 lines (253 loc) · 16.1 KB
/
postratings-templates.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
<?php
/**
* WP-PostRatings Templates.
*
* @package WordPress
* @subpackage WP-PostRatings Plugin
*/
/**
* Security check
* Prevent direct access to the file.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Permission check
* Check whether the user can manage ratings
*/
if ( ! current_user_can( 'manage_ratings' ) ) {
wp_die( esc_html__( 'Access Denied', 'wp-postratings' ) );
}
### Ratings Variables
$base_name = plugin_basename('wp-postratings/postratings-manager.php');
$base_page = 'admin.php?page='.$base_name;
### If Form Is Submitted
if ( isset( $_POST['Submit'] ) ) {
check_admin_referer('wp-postratings_templates');
$postratings_template_vote = wp_kses_post(trim($_POST['postratings_template_vote']));
$postratings_template_text = wp_kses_post(trim($_POST['postratings_template_text']));
$postratings_template_permission = wp_kses_post(trim($_POST['postratings_template_permission']));
$postratings_template_none = wp_kses_post(trim($_POST['postratings_template_none']));
$postratings_template_highestrated = wp_kses_post(trim($_POST['postratings_template_highestrated']));
$postratings_template_mostrated = wp_kses_post(trim($_POST['postratings_template_mostrated']));
$update_ratings_queries = array();
$update_ratings_text = array();
$update_ratings_queries[] = update_option('postratings_template_vote', $postratings_template_vote);
$update_ratings_queries[] = update_option('postratings_template_text', $postratings_template_text);
$update_ratings_queries[] = update_option('postratings_template_permission', $postratings_template_permission);
$update_ratings_queries[] = update_option('postratings_template_none', $postratings_template_none);
$update_ratings_queries[] = update_option('postratings_template_highestrated', $postratings_template_highestrated);
$update_ratings_queries[] = update_option('postratings_template_mostrated', $postratings_template_mostrated);
$update_ratings_text[] = esc_html__('Ratings Template Vote', 'wp-postratings');
$update_ratings_text[] = esc_html__('Ratings Template Voted', 'wp-postratings');
$update_ratings_text[] = esc_html__('Ratings Template No Permission', 'wp-postratings');
$update_ratings_text[] = esc_html__('Ratings Template For No Ratings', 'wp-postratings');
$update_ratings_text[] = esc_html__('Ratings Template For Highest Rated', 'wp-postratings');
$update_ratings_text[] = esc_html__('Ratings Template For Most Rated', 'wp-postratings');
$i = 0;
$text = '';
foreach($update_ratings_queries as $update_ratings_query) {
if($update_ratings_query) {
$text .= '<p style="color: green;">'.$update_ratings_text[$i].' '.esc_html__('Updated', 'wp-postratings').'</p>';
}
$i++;
}
if(empty($text)) {
$text = '<p style="color: red;">'.esc_html__('No Ratings Templates Updated', 'wp-postratings').'</p>';
}
}
?>
<script language="JavaScript" type="text/javascript">
/* <![CDATA[*/
function ratings_updown_templates(template, print) {
var default_template;
switch(template) {
case "vote":
default_template = "%RATINGS_IMAGES_VOTE% (<strong>%RATINGS_SCORE%</strong> <?php esc_html_e('rating', 'wp-postratings'); ?><?php esc_html_e(',', 'wp-postratings'); ?> <strong>%RATINGS_USERS%</strong> <?php esc_html_e('votes', 'wp-postratings'); ?>)<br />%RATINGS_TEXT%";
break;
case "text":
default_template = "%RATINGS_IMAGES% (<em><strong>%RATINGS_SCORE%</strong> <?php esc_html_e('rating', 'wp-postratings'); ?><?php esc_html_e(',', 'wp-postratings'); ?> <strong>%RATINGS_USERS%</strong> <?php esc_html_e('votes', 'wp-postratings'); ?><?php esc_html_e(',', 'wp-postratings'); ?> <strong><?php esc_html_e('rated', 'wp-postratings'); ?></strong></em>)";
break;
case "permission":
default_template = "%RATINGS_IMAGES% (<em><strong>%RATINGS_SCORE%</strong> <?php esc_html_e('rating', 'wp-postratings'); ?><?php esc_html_e(',', 'wp-postratings'); ?> <strong>%RATINGS_USERS%</strong> <?php esc_html_e('votes', 'wp-postratings'); ?><?php esc_html_e(',', 'wp-postratings'); ?> <strong><?php esc_html_e('rated', 'wp-postratings'); ?></strong></em>)<br /><em><?php esc_html_e('You need to be a registered member to rate this.', 'wp-postratings'); ?></em>";
break;
case "none":
default_template = "%RATINGS_IMAGES_VOTE% (<?php esc_html_e('No Ratings Yet', 'wp-postratings'); ?>)<br />%RATINGS_TEXT%";
break;
case "highestrated":
default_template = "<li><a href=\"%POST_URL%\" title=\"%POST_TITLE%\">%POST_TITLE%</a> (%RATINGS_SCORE% <?php esc_html_e('rating', 'wp-postratings'); ?><?php esc_html_e(',', 'wp-postratings'); ?> %RATINGS_USERS% <?php esc_html_e('votes', 'wp-postratings'); ?>)</li>";
break;
case "mostrated":
default_template = "<li><a href=\"%POST_URL%\" title=\"%POST_TITLE%\">%POST_TITLE%</a> - %RATINGS_USERS% <?php esc_html_e('votes', 'wp-postratings'); ?></li>";
break;
}
if(print) {
jQuery("#postratings_template_" + template).val(default_template);
} else {
return default_template;
}
}
function ratings_default_templates(template, print) {
var default_template;
switch(template) {
case "vote":
default_template = "%RATINGS_IMAGES_VOTE% (<strong>%RATINGS_USERS%</strong> <?php esc_html_e('votes', 'wp-postratings'); ?><?php esc_html_e(',', 'wp-postratings'); ?> <?php esc_html_e('average', 'wp-postratings'); ?>: <strong>%RATINGS_AVERAGE%</strong> <?php esc_html_e('out of', 'wp-postratings'); ?> %RATINGS_MAX%)<br />%RATINGS_TEXT%";
break;
case "text":
default_template = "%RATINGS_IMAGES% (<em><strong>%RATINGS_USERS%</strong> <?php esc_html_e('votes', 'wp-postratings'); ?><?php esc_html_e(',', 'wp-postratings'); ?> <?php esc_html_e('average', 'wp-postratings'); ?>: <strong>%RATINGS_AVERAGE%</strong> <?php esc_html_e('out of', 'wp-postratings'); ?> %RATINGS_MAX%<?php esc_html_e(',', 'wp-postratings'); ?> <strong><?php esc_html_e('rated', 'wp-postratings'); ?></strong></em>)";
break;
case "permission":
default_template = "%RATINGS_IMAGES% (<em><strong>%RATINGS_USERS%</strong> <?php esc_html_e('votes', 'wp-postratings'); ?><?php esc_html_e(',', 'wp-postratings'); ?> <?php esc_html_e('average', 'wp-postratings'); ?>: <strong>%RATINGS_AVERAGE%</strong> <?php esc_html_e('out of', 'wp-postratings'); ?> %RATINGS_MAX%</em>)<br /><em><?php esc_html_e('You need to be a registered member to rate this.', 'wp-postratings'); ?></em>";
break;
case "none":
default_template = "%RATINGS_IMAGES_VOTE% (<?php esc_html_e('No Ratings Yet', 'wp-postratings'); ?>)<br />%RATINGS_TEXT%";
break;
case "highestrated":
default_template = "<li><a href=\"%POST_URL%\" title=\"%POST_TITLE%\">%POST_TITLE%</a> %RATINGS_IMAGES% (%RATINGS_AVERAGE% <?php esc_html_e('out of', 'wp-postratings'); ?> %RATINGS_MAX%)</li>";
break;
case "mostrated":
default_template = "<li><a href=\"%POST_URL%\" title=\"%POST_TITLE%\">%POST_TITLE%</a> - %RATINGS_USERS% <?php esc_html_e('votes', 'wp-postratings'); ?></li>";
break;
}
if(print) {
jQuery("#postratings_template_" + template).val(default_template);
} else {
return default_template;
}
}
/* ]]> */
</script>
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
<div class="wrap">
<h1><?php esc_html_e('Post Ratings Templates', 'wp-postratings'); ?></h1>
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
<?php wp_nonce_field('wp-postratings_templates'); ?>
<h2><?php esc_html_e('Template Variables', 'wp-postratings'); ?></h2>
<table class="form-table">
<tr>
<td><strong>%RATINGS_IMAGES%</strong> - <?php esc_html_e('Display the ratings images', 'wp-postratings'); ?></td>
<td><strong>%RATINGS_IMAGES_VOTE%</strong> - <?php esc_html_e('Display the ratings voting image', 'wp-postratings'); ?></td>
</tr>
<tr>
<td><strong>%RATINGS_AVERAGE%</strong> - <?php esc_html_e('Display the average ratings', 'wp-postratings'); ?></td>
<td><strong>%RATINGS_USERS%</strong> - <?php esc_html_e('Display the total number of users rated for the post', 'wp-postratings'); ?></td>
</tr>
<tr>
<td><strong>%RATINGS_MAX%</strong> - <?php esc_html_e('Display the max number of ratings', 'wp-postratings'); ?></td>
<td><strong>%RATINGS_PERCENTAGE%</strong> - <?php esc_html_e('Display the ratings percentage', 'wp-postratings'); ?></td>
</tr>
<tr>
<td><strong>%RATINGS_SCORE%</strong> - <?php esc_html_e('Display the total score of the ratings', 'wp-postratings'); ?></td>
<td><strong>%RATINGS_TEXT%</strong> - <?php esc_html_e('Display the individual rating text. Eg: 1 Star, 2 Stars, etc', 'wp-postratings'); ?></td>
</tr>
</table>
<h2><?php esc_html_e('Ratings Templates', 'wp-postratings'); ?></h2>
<table class="form-table">
<tr>
<td width="30%">
<strong><?php esc_html_e('Ratings Vote Text:', 'wp-postratings'); ?></strong><br /><br />
<?php esc_html_e('Allowed Variables:', 'wp-postratings'); ?>
<p style="margin: 2px 0">- %RATINGS_IMAGES_VOTE%</p>
<p style="margin: 2px 0">- %RATINGS_MAX%</p>
<p style="margin: 2px 0">- %RATINGS_SCORE%</p>
<p style="margin: 2px 0">- %RATINGS_TEXT%</p>
<p style="margin: 2px 0">- %RATINGS_USERS%</p>
<p style="margin: 2px 0">- %RATINGS_AVERAGE%</p>
<p style="margin: 2px 0">- %RATINGS_PERCENTAGE%</p>
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Normal Rating)', 'wp-postratings'); ?>" onclick="ratings_default_templates('vote', true);" class="button" />
<br />
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Up/Down Rating)', 'wp-postratings'); ?>" onclick="ratings_updown_templates('vote', true);" class="button" />
</td>
<td><textarea cols="80" rows="15" id="postratings_template_vote" name="postratings_template_vote"><?php echo esc_attr(stripslashes(get_option('postratings_template_vote'))); ?></textarea></td>
</tr>
<tr>
<td width="30%">
<strong><?php esc_html_e('Ratings Voted Text:', 'wp-postratings'); ?></strong><br /><br />
<?php esc_html_e('Allowed Variables:', 'wp-postratings'); ?>
<p style="margin: 2px 0">- %RATINGS_IMAGES%</p>
<p style="margin: 2px 0">- %RATINGS_MAX%</p>
<p style="margin: 2px 0">- %RATINGS_SCORE%</p>
<p style="margin: 2px 0">- %RATINGS_USERS%</p>
<p style="margin: 2px 0">- %RATINGS_AVERAGE%</p>
<p style="margin: 2px 0">- %RATINGS_PERCENTAGE%</p>
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Normal Rating)', 'wp-postratings'); ?>" onclick="ratings_default_templates('text', true);" class="button" /><br />
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Up/Down Rating)', 'wp-postratings'); ?>" onclick="ratings_updown_templates('text', true);" class="button" />
</td>
<td><textarea cols="80" rows="15" id="postratings_template_text" name="postratings_template_text"><?php echo esc_attr(stripslashes(get_option('postratings_template_text'))); ?></textarea></td>
</tr>
<tr>
<td width="30%">
<strong><?php esc_html_e('Ratings No Permission Text:', 'wp-postratings'); ?></strong><br /><br />
<?php esc_html_e('Allowed Variables:', 'wp-postratings'); ?>
<p style="margin: 2px 0">- %RATINGS_IMAGES%</p>
<p style="margin: 2px 0">- %RATINGS_MAX%</p>
<p style="margin: 2px 0">- %RATINGS_SCORE%</p>
<p style="margin: 2px 0">- %RATINGS_USERS%</p>
<p style="margin: 2px 0">- %RATINGS_AVERAGE%</p>
<p style="margin: 2px 0">- %RATINGS_PERCENTAGE%</p>
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Normal Rating)', 'wp-postratings'); ?>" onclick="ratings_default_templates('permission', true);" class="button" /><br />
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Up/Down Rating)', 'wp-postratings'); ?>" onclick="ratings_updown_templates('permission', true);" class="button" />
</td>
<td><textarea cols="80" rows="15" id="postratings_template_permission" name="postratings_template_permission"><?php echo esc_attr(stripslashes(get_option('postratings_template_permission'))); ?></textarea></td>
</tr>
<tr>
<td width="30%">
<strong><?php esc_html_e('Ratings None:', 'wp-postratings'); ?></strong><br /><br />
<?php esc_html_e('Allowed Variables:', 'wp-postratings'); ?><br />
<p style="margin: 2px 0">- %RATINGS_IMAGES_VOTE%</p>
<p style="margin: 2px 0">- %RATINGS_MAX%</p>
<p style="margin: 2px 0">- %RATINGS_SCORE%</p>
<p style="margin: 2px 0">- %RATINGS_TEXT%</p>
<p style="margin: 2px 0">- %RATINGS_USERS%</p>
<p style="margin: 2px 0">- %RATINGS_AVERAGE%</p>
<p style="margin: 2px 0">- %RATINGS_PERCENTAGE%</p>
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Normal Rating)', 'wp-postratings'); ?>" onclick="ratings_default_templates('none', true);" class="button" /><br />
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Up/Down Rating)', 'wp-postratings'); ?>" onclick="ratings_updown_templates('none', true);" class="button" />
</td>
<td><textarea cols="80" rows="15" id="postratings_template_none" name="postratings_template_none"><?php echo esc_attr(stripslashes(get_option('postratings_template_none'))); ?></textarea></td>
</tr>
<tr>
<td width="30%">
<strong><?php esc_html_e('Highest Rated:', 'wp-postratings'); ?></strong><br /><br />
<?php esc_html_e('Allowed Variables:', 'wp-postratings'); ?><br />
<p style="margin: 2px 0">- %RATINGS_IMAGES%</p>
<p style="margin: 2px 0">- %RATINGS_MAX%</p>
<p style="margin: 2px 0">- %RATINGS_SCORE%</p>
<p style="margin: 2px 0">- %RATINGS_USERS%</p>
<p style="margin: 2px 0">- %RATINGS_AVERAGE%</p>
<p style="margin: 2px 0">- %RATINGS_PERCENTAGE%</p>
<p style="margin: 2px 0">- %POST_ID%</p>
<p style="margin: 2px 0">- %POST_TITLE%</p>
<p style="margin: 2px 0">- %POST_EXCERPT%</p>
<p style="margin: 2px 0">- %POST_CONTENT%</p>
<p style="margin: 2px 0">- %POST_URL%</p>
<p style="margin: 2px 0">- %POST_THUMBNAIL%</p>
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Normal Rating)', 'wp-postratings'); ?>" onclick="ratings_default_templates('highestrated', true);" class="button" /><br />
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Up/Down Rating)', 'wp-postratings'); ?>" onclick="ratings_updown_templates('highestrated', true);" class="button" />
</td>
<td><textarea cols="80" rows="15" id="postratings_template_highestrated" name="postratings_template_highestrated"><?php echo esc_attr(stripslashes(get_option('postratings_template_highestrated'))); ?></textarea></td>
</tr>
<tr>
<td width="30%">
<strong><?php esc_html_e('Most Rated:', 'wp-postratings'); ?></strong><br /><br />
<?php esc_html_e('Allowed Variables:', 'wp-postratings'); ?><br />
<p style="margin: 2px 0">- %RATINGS_USERS%</p>
<p style="margin: 2px 0">- %RATINGS_AVERAGE%</p>
<p style="margin: 2px 0">- %POST_ID%</p>
<p style="margin: 2px 0">- %POST_TITLE%</p>
<p style="margin: 2px 0">- %POST_EXCERPT%</p>
<p style="margin: 2px 0">- %POST_CONTENT%</p>
<p style="margin: 2px 0">- %POST_URL%</p>
<p style="margin: 2px 0">- %POST_THUMBNAIL%</p>
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Normal Rating)', 'wp-postratings'); ?>" onclick="ratings_default_templates('mostrated', true);" class="button" /><br />
<input type="button" name="RestoreDefault" value="<?php esc_html_e('Restore Default Template (Up/Down Rating)', 'wp-postratings'); ?>" onclick="ratings_updown_templates('mostrated', true);" class="button" />
</td>
<td><textarea cols="80" rows="15" id="postratings_template_mostrated" name="postratings_template_mostrated"><?php echo esc_attr(stripslashes(get_option('postratings_template_mostrated'))); ?></textarea></td>
</tr>
</table>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="<?php esc_html_e('Save Changes', 'wp-postratings'); ?>" />
</p>
</form>
</div>