-
Notifications
You must be signed in to change notification settings - Fork 1
/
postviews-options.php
309 lines (302 loc) · 14 KB
/
postviews-options.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
<?php
/*
+----------------------------------------------------------------+
| |
| WordPress Plugin: WP-PostViews |
| Copyright (c) 2012 Lester "GaMerZ" Chan |
| |
| File Written By: |
| - Lester "GaMerZ" Chan |
| - http://lesterchan.net |
| |
| File Information: |
| - Post Views Options Page |
| - wp-content/plugins/wp-postviews/postviews-options.php |
| |
+----------------------------------------------------------------+
*/
### Variables Variables Variables
$base_name = plugin_basename('wp-postviews/postviews-options.php');
$base_page = 'admin.php?page='.$base_name;
$id = (isset($_GET['id']) ? intval($_GET['id']) : 0);
$mode = (isset($_GET['mode']) ? trim($_GET['mode']) : '');
$views_settings = array('views_options', 'widget_views_most_viewed', 'widget_views');
$views_postmetas = array('views');
### Form Processing
// Update Options
if(!empty($_POST['Submit'])) {
$views_options = array();
$views_options['count'] = intval($_POST['views_count']);
$views_options['exclude_bots'] = intval($_POST['views_exclude_bots']);
$views_options['display_home'] = intval($_POST['views_display_home']);
$views_options['display_single'] = intval($_POST['views_display_single']);
$views_options['display_page'] = intval($_POST['views_display_page']);
$views_options['display_archive'] = intval($_POST['views_display_archive']);
$views_options['display_search'] = intval($_POST['views_display_search']);
$views_options['display_other'] = intval($_POST['views_display_other']);
$views_options['template'] = trim($_POST['views_template_template']);
$views_options['most_viewed_template'] = trim($_POST['views_template_most_viewed']);
$update_views_queries = array();
$update_views_text = array();
$update_views_queries[] = update_option('views_options', $views_options);
$update_views_text[] = __('Post Views Options', 'wp-postviews');
$i=0;
$text = '';
foreach($update_views_queries as $update_views_query) {
if($update_views_query) {
$text .= '<font color="green">'.$update_views_text[$i].' '.__('Updated', 'wp-postviews').'</font><br />';
}
$i++;
}
if(empty($text)) {
$text = '<font color="red">'.__('No Post Views Option Updated', 'wp-postviews').'</font>';
}
}
// Decide What To Do
if(!empty($_POST['do'])) {
// Uninstall WP-PostViews
switch($_POST['do']) {
case __('UNINSTALL WP-PostViews', 'wp-postviews') :
if(trim($_POST['uninstall_views_yes']) == 'yes') {
echo '<div id="message" class="updated fade">';
echo '<p>';
foreach($views_settings as $setting) {
$delete_setting = delete_option($setting);
if($delete_setting) {
echo '<font color="green">';
printf(__('Setting Key \'%s\' has been deleted.', 'wp-postviews'), "<strong><em>{$setting}</em></strong>");
echo '</font><br />';
} else {
echo '<font color="red">';
printf(__('Error deleting Setting Key \'%s\'.', 'wp-postviews'), "<strong><em>{$setting}</em></strong>");
echo '</font><br />';
}
}
echo '</p>';
echo '<p>';
foreach($views_postmetas as $postmeta) {
$remove_postmeta = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = '$postmeta'");
if($remove_postmeta) {
echo '<font color="green">';
printf(__('Post Meta Key \'%s\' has been deleted.', 'wp-postviews'), "<strong><em>{$postmeta}</em></strong>");
echo '</font><br />';
} else {
echo '<font color="red">';
printf(__('Error deleting Post Meta Key \'%s\'.', 'wp-postviews'), "<strong><em>{$postmeta}</em></strong>");
echo '</font><br />';
}
}
echo '</p>';
echo '</div>';
$mode = 'end-UNINSTALL';
}
break;
}
}
### Determines Which Mode It Is
switch($mode) {
// Deactivating WP-PostViews
case 'end-UNINSTALL':
$deactivate_url = 'plugins.php?action=deactivate&plugin=wp-postviews/wp-postviews.php';
if(function_exists('wp_nonce_url')) {
$deactivate_url = wp_nonce_url($deactivate_url, 'deactivate-plugin_wp-postviews/wp-postviews.php');
}
echo '<div class="wrap">';
echo '<h2>'.__('Uninstall WP-PostViews', 'wp-postviews').'</h2>';
echo '<p><strong>'.sprintf(__('<a href="%s">Click Here</a> To Finish The Uninstallation And WP-PostViews Will Be Deactivated Automatically.', 'wp-postviews'), $deactivate_url).'</strong></p>';
echo '</div>';
break;
// Main Page
default:
$views_options = get_option('views_options');
?>
<script type="text/javascript">
/* <![CDATA[*/
function views_default_templates(template) {
var default_template;
switch(template) {
case 'template':
default_template = "<?php _e('%VIEW_COUNT% views', 'wp-postviews'); ?>";
break;
case 'most_viewed':
default_template = "<li><a href=\"%POST_URL%\" title=\"%POST_TITLE%\">%POST_TITLE%</a> - %VIEW_COUNT% <?php _e('views', 'wp-postviews'); ?></li>";
break;
}
jQuery("#views_template_" + template).val(default_template);
}
/* ]]> */
</script>
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php _e('Post Views Options', 'wp-postviews'); ?></h2>
<table class="form-table">
<tr>
<td valign="top" width="30%"><strong><?php _e('Count Views From:', 'wp-postviews'); ?></strong></td>
<td valign="top">
<select name="views_count" size="1">
<option value="0"<?php selected('0', $views_options['count']); ?>><?php _e('Everyone', 'wp-postviews'); ?></option>
<option value="1"<?php selected('1', $views_options['count']); ?>><?php _e('Guests Only', 'wp-postviews'); ?></option>
<option value="2"<?php selected('2', $views_options['count']); ?>><?php _e('Registered Users Only', 'wp-postviews'); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top" width="30%"><strong><?php _e('Exclude Bot Views:', 'wp-postviews'); ?></strong></td>
<td valign="top">
<select name="views_exclude_bots" size="1">
<option value="0"<?php selected('0', $views_options['exclude_bots']); ?>><?php _e('No', 'wp-postviews'); ?></option>
<option value="1"<?php selected('1', $views_options['exclude_bots']); ?>><?php _e('Yes', 'wp-postviews'); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top">
<strong><?php _e('Views Template:', 'wp-postviews'); ?></strong><br /><br />
<?php _e('Allowed Variables:', 'wp-postviews'); ?><br />
- %VIEW_COUNT%<br /><br />
<input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-postviews'); ?>" onclick="views_default_templates('template');" class="button" />
</td>
<td valign="top">
<input type="text" id="views_template_template" name="views_template_template" size="70" value="<?php echo htmlspecialchars(stripslashes($views_options['template'])); ?>" />
</td>
</tr>
<tr>
<td valign="top">
<strong><?php _e('Most Viewed Template:', 'wp-postviews'); ?></strong><br /><br />
<?php _e('Allowed Variables:', 'wp-postviews'); ?><br />
- %VIEW_COUNT%<br />
- %POST_TITLE%<br />
- %POST_EXCERPT%<br />
- %POST_CONTENT%<br />
- %POST_URL%<br /><br />
<input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-postviews'); ?>" onclick="views_default_templates('most_viewed');" class="button" />
</td>
<td valign="top">
<textarea cols="80" rows="15" id="views_template_most_viewed" name="views_template_most_viewed"><?php echo htmlspecialchars(stripslashes($views_options['most_viewed_template'])); ?></textarea>
</td>
</tr>
</table>
<h3><?php _e('Display Options', 'wp-postviews'); ?></h3>
<p><?php _e('These options specify where the view counts should be displayed and to whom. By default view counts will be displayed to all visitors. Note that the theme files must contain a call to <code>the_views()</code> in order for any view count to be displayed.', 'wp-postviews'); ?></p>
<table class="form-table">
<tr>
<td valign="top"><strong><?php _e('Home Page:', 'wp-postviews'); ?></strong></td>
<td>
<select name="views_display_home" size="1">
<option value="0"<?php selected('0', $views_options['display_home']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
<option value="1"<?php selected('1', $views_options['display_home']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
<option value="2"<?php selected('2', $views_options['display_home']); ?>><?php _e('Don\'t display on home page', 'wp-postviews'); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong><?php _e('Singe Posts:', 'wp-postviews'); ?></strong></td>
<td>
<select name="views_display_single" size="1">
<option value="0"<?php selected('0', $views_options['display_single']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
<option value="1"<?php selected('1', $views_options['display_single']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
<option value="2"<?php selected('2', $views_options['display_single']); ?>><?php _e('Don\'t display on single posts', 'wp-postviews'); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong><?php _e('Pages:', 'wp-postviews'); ?></strong></td>
<td>
<select name="views_display_page" size="1">
<option value="0"<?php selected('0', $views_options['display_page']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
<option value="1"<?php selected('1', $views_options['display_page']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
<option value="2"<?php selected('2', $views_options['display_page']); ?>><?php _e('Don\'t display on pages', 'wp-postviews'); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong><?php _e('Archive Pages:', 'wp-postviews'); ?></strong></td>
<td>
<select name="views_display_archive" size="1">
<option value="0"<?php selected('0', $views_options['display_archive']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
<option value="1"<?php selected('1', $views_options['display_archive']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
<option value="2"<?php selected('2', $views_options['display_archive']); ?>><?php _e('Don\'t display on archive pages', 'wp-postviews'); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong><?php _e('Search Pages:', 'wp-postviews'); ?></strong></td>
<td>
<select name="views_display_search" size="1">
<option value="0"<?php selected('0', $views_options['display_search']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
<option value="1"<?php selected('1', $views_options['display_search']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
<option value="2"<?php selected('2', $views_options['display_search']); ?>><?php _e('Don\'t display on search pages', 'wp-postviews'); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong><?php _e('Other Pages:', 'wp-postviews'); ?></strong></td>
<td>
<select name="views_display_other" size="1">
<option value="0"<?php selected('0', $views_options['display_other']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
<option value="1"<?php selected('1', $views_options['display_other']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
<option value="2"<?php selected('2', $views_options['display_other']); ?>><?php _e('Don\'t display on other pages', 'wp-postviews'); ?></option>
</select>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Changes', 'wp-postviews'); ?>" />
</p>
</div>
</form>
<p> </p>
<!-- Uninstall WP-PostViews -->
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
<div class="wrap">
<h3><?php _e('Uninstall WP-PostViews', 'wp-postviews'); ?></h3>
<p>
<?php _e('Deactivating WP-PostViews plugin does not remove any data that may have been created, such as the views data. To completely remove this plugin, you can uninstall it here.', 'wp-postviews'); ?>
</p>
<p style="color: red">
<strong><?php _e('WARNING:', 'wp-postviews'); ?></strong><br />
<?php _e('Once uninstalled, this cannot be undone. You should use a Database Backup plugin of WordPress to back up all the data first.', 'wp-postviews'); ?>
</p>
<p style="color: red">
<strong><?php _e('The following WordPress Options/PostMetas will be DELETED:', 'wp-postviews'); ?></strong><br />
</p>
<table class="widefat">
<thead>
<tr>
<th><?php _e('WordPress Options', 'wp-postviews'); ?></th>
<th><?php _e('WordPress PostMetas', 'wp-postviews'); ?></th>
</tr>
</thead>
<tr>
<td valign="top">
<ol>
<?php
foreach($views_settings as $settings) {
echo '<li>'.$settings.'</li>'."\n";
}
?>
</ol>
</td>
<td valign="top" class="alternate">
<ol>
<?php
foreach($views_postmetas as $postmeta) {
echo '<li>'.$postmeta.'</li>'."\n";
}
?>
</ol>
</td>
</tr>
</table>
<p> </p>
<p style="text-align: center;">
<input type="checkbox" name="uninstall_views_yes" value="yes" /> <?php _e('Yes', 'wp-postviews'); ?><br /><br />
<input type="submit" name="do" value="<?php _e('UNINSTALL WP-PostViews', 'wp-postviews'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Uninstall WP-PostViews From WordPress.\nThis Action Is Not Reversible.\n\n Choose [Cancel] To Stop, [OK] To Uninstall.', 'wp-postviews'); ?>')" />
</p>
</div>
</form>
<?php
} // End switch($mode)
?>