| 1 |
<?php |
| 2 |
/* |
| 3 |
+----------------------------------------------------------------+ |
| 4 |
| | |
| 5 |
| WordPress 2.6 Plugin: WP-PostViews 1.40 | |
| 6 |
| Copyright (c) 2008 Lester "GaMerZ" Chan | |
| 7 |
| | |
| 8 |
| File Written By: | |
| 9 |
| - Lester "GaMerZ" Chan | |
| 10 |
| - http://lesterchan.net | |
| 11 |
| | |
| 12 |
| File Information: | |
| 13 |
| - Post Views Options Page | |
| 14 |
| - wp-content/plugins/wp-postviews/postviews-options.php | |
| 15 |
| | |
| 16 |
+----------------------------------------------------------------+ |
| 17 |
*/ |
| 18 |
|
| 19 |
|
| 20 |
### Variables Variables Variables |
| 21 |
$base_name = plugin_basename('wp-postviews/postviews-options.php'); |
| 22 |
$base_page = 'admin.php?page='.$base_name; |
| 23 |
$id = intval($_GET['id']); |
| 24 |
$mode = trim($_GET['mode']); |
| 25 |
$views_settings = array('views_options', 'widget_views_most_viewed'); |
| 26 |
$views_postmetas = array('views'); |
| 27 |
|
| 28 |
|
| 29 |
### Form Processing |
| 30 |
// Update Options |
| 31 |
if(!empty($_POST['Submit'])) { |
| 32 |
$views_options = array(); |
| 33 |
$views_options['count'] = intval($_POST['views_count']); |
| 34 |
$views_options['exclude_bots'] = intval($_POST['views_exclude_bots']); |
| 35 |
$views_options['display_home'] = intval($_POST['views_display_home']); |
| 36 |
$views_options['display_single'] = intval($_POST['views_display_single']); |
| 37 |
$views_options['display_page'] = intval($_POST['views_display_page']); |
| 38 |
$views_options['display_archive'] = intval($_POST['views_display_archive']); |
| 39 |
$views_options['display_search'] = intval($_POST['views_display_search']); |
| 40 |
$views_options['display_other'] = intval($_POST['views_display_other']); |
| 41 |
$views_options['template'] = trim($_POST['views_template_template']); |
| 42 |
$views_options['most_viewed_template'] = trim($_POST['views_template_most_viewed']); |
| 43 |
$update_views_queries = array(); |
| 44 |
$update_views_text = array(); |
| 45 |
$update_views_queries[] = update_option('views_options', $views_options); |
| 46 |
$update_views_text[] = __('Post Views Options', 'wp-postviews'); |
| 47 |
$i=0; |
| 48 |
$text = ''; |
| 49 |
foreach($update_views_queries as $update_views_query) { |
| 50 |
if($update_views_query) { |
| 51 |
$text .= '<font color="green">'.$update_views_text[$i].' '.__('Updated', 'wp-postviews').'</font><br />'; |
| 52 |
} |
| 53 |
$i++; |
| 54 |
} |
| 55 |
if(empty($text)) { |
| 56 |
$text = '<font color="red">'.__('No Post Views Option Updated', 'wp-postviews').'</font>'; |
| 57 |
} |
| 58 |
} |
| 59 |
// Decide What To Do |
| 60 |
if(!empty($_POST['do'])) { |
| 61 |
// Uninstall WP-PostViews |
| 62 |
switch($_POST['do']) { |
| 63 |
case __('UNINSTALL WP-PostViews', 'wp-postviews') : |
| 64 |
if(trim($_POST['uninstall_views_yes']) == 'yes') { |
| 65 |
echo '<div id="message" class="updated fade">'; |
| 66 |
echo '<p>'; |
| 67 |
foreach($views_settings as $setting) { |
| 68 |
$delete_setting = delete_option($setting); |
| 69 |
if($delete_setting) { |
| 70 |
echo '<font color="green">'; |
| 71 |
printf(__('Setting Key \'%s\' has been deleted.', 'wp-postviews'), "<strong><em>{$setting}</em></strong>"); |
| 72 |
echo '</font><br />'; |
| 73 |
} else { |
| 74 |
echo '<font color="red">'; |
| 75 |
printf(__('Error deleting Setting Key \'%s\'.', 'wp-postviews'), "<strong><em>{$setting}</em></strong>"); |
| 76 |
echo '</font><br />'; |
| 77 |
} |
| 78 |
} |
| 79 |
echo '</p>'; |
| 80 |
echo '<p>'; |
| 81 |
foreach($views_postmetas as $postmeta) { |
| 82 |
$remove_postmeta = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = '$postmeta'"); |
| 83 |
if($remove_postmeta) { |
| 84 |
echo '<font color="green">'; |
| 85 |
printf(__('Post Meta Key \'%s\' has been deleted.', 'wp-postviews'), "<strong><em>{$postmeta}</em></strong>"); |
| 86 |
echo '</font><br />'; |
| 87 |
} else { |
| 88 |
echo '<font color="red">'; |
| 89 |
printf(__('Error deleting Post Meta Key \'%s\'.', 'wp-postviews'), "<strong><em>{$postmeta}</em></strong>"); |
| 90 |
echo '</font><br />'; |
| 91 |
} |
| 92 |
} |
| 93 |
echo '</p>'; |
| 94 |
echo '</div>'; |
| 95 |
$mode = 'end-UNINSTALL'; |
| 96 |
} |
| 97 |
break; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
### Determines Which Mode It Is |
| 103 |
switch($mode) { |
| 104 |
// Deactivating WP-PostViews |
| 105 |
case 'end-UNINSTALL': |
| 106 |
$deactivate_url = 'plugins.php?action=deactivate&plugin=wp-postviews/wp-postviews.php'; |
| 107 |
if(function_exists('wp_nonce_url')) { |
| 108 |
$deactivate_url = wp_nonce_url($deactivate_url, 'deactivate-plugin_wp-postviews/wp-postviews.php'); |
| 109 |
} |
| 110 |
echo '<div class="wrap">'; |
| 111 |
echo '<h2>'.__('Uninstall WP-PostViews', 'wp-postviews').'</h2>'; |
| 112 |
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>'; |
| 113 |
echo '</div>'; |
| 114 |
break; |
| 115 |
// Main Page |
| 116 |
default: |
| 117 |
$views_options = get_option('views_options'); |
| 118 |
?> |
| 119 |
<script type="text/javascript"> |
| 120 |
/* <![CDATA[*/ |
| 121 |
function views_default_templates(template) { |
| 122 |
var default_template; |
| 123 |
switch(template) { |
| 124 |
case 'template': |
| 125 |
default_template = "<?php _e('%VIEW_COUNT% views', 'wp-postviews'); ?>"; |
| 126 |
break; |
| 127 |
case 'most_viewed': |
| 128 |
default_template = "<li><a href=\"%POST_URL%\" title=\"%POST_TITLE%\">%POST_TITLE%</a> - %VIEW_COUNT% <?php _e('views', 'wp-postviews'); ?></li>"; |
| 129 |
break; |
| 130 |
} |
| 131 |
document.getElementById("views_template_" + template).value = default_template; |
| 132 |
} |
| 133 |
/* ]]> */ |
| 134 |
</script> |
| 135 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> |
| 136 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 137 |
<div class="wrap"> |
| 138 |
<?php screen_icon(); ?> |
| 139 |
<h2><?php _e('Post Views Options', 'wp-postviews'); ?></h2> |
| 140 |
<table class="form-table"> |
| 141 |
<tr> |
| 142 |
<td valign="top" width="30%"><strong><?php _e('Count Views From:', 'wp-postviews'); ?></strong></td> |
| 143 |
<td valign="top"> |
| 144 |
<select name="views_count" size="1"> |
| 145 |
<option value="0"<?php selected('0', $views_options['count']); ?>><?php _e('Everyone', 'wp-postviews'); ?></option> |
| 146 |
<option value="1"<?php selected('1', $views_options['count']); ?>><?php _e('Guests Only', 'wp-postviews'); ?></option> |
| 147 |
<option value="2"<?php selected('2', $views_options['count']); ?>><?php _e('Registered Users Only', 'wp-postviews'); ?></option> |
| 148 |
</select> |
| 149 |
</td> |
| 150 |
</tr> |
| 151 |
<tr> |
| 152 |
<td valign="top" width="30%"><strong><?php _e('Exclude Bot Views:', 'wp-postviews'); ?></strong></td> |
| 153 |
<td valign="top"> |
| 154 |
<select name="views_exclude_bots" size="1"> |
| 155 |
<option value="0"<?php selected('0', $views_options['exclude_bots']); ?>><?php _e('No', 'wp-postviews'); ?></option> |
| 156 |
<option value="1"<?php selected('1', $views_options['exclude_bots']); ?>><?php _e('Yes', 'wp-postviews'); ?></option> |
| 157 |
</select> |
| 158 |
</td> |
| 159 |
</tr> |
| 160 |
<tr> |
| 161 |
<td valign="top"> |
| 162 |
<strong><?php _e('Views Template:', 'wp-postviews'); ?></strong><br /><br /> |
| 163 |
<?php _e('Allowed Variables:', 'wp-postviews'); ?><br /> |
| 164 |
- %VIEW_COUNT%<br /><br /> |
| 165 |
<input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-postviews'); ?>" onclick="views_default_templates('template');" class="button" /> |
| 166 |
</td> |
| 167 |
<td valign="top"> |
| 168 |
<input type="text" id="views_template_template" name="views_template_template" size="70" value="<?php echo htmlspecialchars(stripslashes($views_options['template'])); ?>" /> |
| 169 |
</td> |
| 170 |
</tr> |
| 171 |
<tr> |
| 172 |
<td valign="top"> |
| 173 |
<strong><?php _e('Most Viewed Template:', 'wp-postviews'); ?></strong><br /><br /> |
| 174 |
<?php _e('Allowed Variables:', 'wp-postviews'); ?><br /> |
| 175 |
- %VIEW_COUNT%<br /> |
| 176 |
- %POST_TITLE%<br /> |
| 177 |
- %POST_EXCERPT%<br /> |
| 178 |
- %POST_CONTENT%<br /> |
| 179 |
- %POST_URL%<br /><br /> |
| 180 |
<input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-postviews'); ?>" onclick="views_default_templates('most_viewed');" class="button" /> |
| 181 |
</td> |
| 182 |
<td valign="top"> |
| 183 |
<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> |
| 184 |
</td> |
| 185 |
</tr> |
| 186 |
</table> |
| 187 |
<h3><?php _e('Display Options', 'wp-postviews'); ?></h3> |
| 188 |
<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> |
| 189 |
<table class="form-table"> |
| 190 |
<tr> |
| 191 |
<td valign="top"><strong><?php _e('Home Page:', 'wp-postviews'); ?></strong></td> |
| 192 |
<td> |
| 193 |
<select name="views_display_home" size="1"> |
| 194 |
<option value="0"<?php selected('0', $views_options['display_home']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option> |
| 195 |
<option value="1"<?php selected('1', $views_options['display_home']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option> |
| 196 |
<option value="2"<?php selected('2', $views_options['display_home']); ?>><?php _e('Don\'t display on home page', 'wp-postviews'); ?></option> |
| 197 |
</select> |
| 198 |
</td> |
| 199 |
</tr> |
| 200 |
<tr> |
| 201 |
<td valign="top"><strong><?php _e('Singe Posts:', 'wp-postviews'); ?></strong></td> |
| 202 |
<td> |
| 203 |
<select name="views_display_single" size="1"> |
| 204 |
<option value="0"<?php selected('0', $views_options['display_single']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option> |
| 205 |
<option value="1"<?php selected('1', $views_options['display_single']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option> |
| 206 |
<option value="2"<?php selected('2', $views_options['display_single']); ?>><?php _e('Don\'t display on single posts', 'wp-postviews'); ?></option> |
| 207 |
</select> |
| 208 |
</td> |
| 209 |
</tr> |
| 210 |
<tr> |
| 211 |
<td valign="top"><strong><?php _e('Pages:', 'wp-postviews'); ?></strong></td> |
| 212 |
<td> |
| 213 |
<select name="views_display_page" size="1"> |
| 214 |
<option value="0"<?php selected('0', $views_options['display_page']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option> |
| 215 |
<option value="1"<?php selected('1', $views_options['display_page']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option> |
| 216 |
<option value="2"<?php selected('2', $views_options['display_page']); ?>><?php _e('Don\'t display on pages', 'wp-postviews'); ?></option> |
| 217 |
</select> |
| 218 |
</td> |
| 219 |
</tr> |
| 220 |
<tr> |
| 221 |
<td valign="top"><strong><?php _e('Archive Pages:', 'wp-postviews'); ?></strong></td> |
| 222 |
<td> |
| 223 |
<select name="views_display_archive" size="1"> |
| 224 |
<option value="0"<?php selected('0', $views_options['display_archive']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option> |
| 225 |
<option value="1"<?php selected('1', $views_options['display_archive']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option> |
| 226 |
<option value="2"<?php selected('2', $views_options['display_archive']); ?>><?php _e('Don\'t display on archive pages', 'wp-postviews'); ?></option> |
| 227 |
</select> |
| 228 |
</td> |
| 229 |
</tr> |
| 230 |
<tr> |
| 231 |
<td valign="top"><strong><?php _e('Search Pages:', 'wp-postviews'); ?></strong></td> |
| 232 |
<td> |
| 233 |
<select name="views_display_search" size="1"> |
| 234 |
<option value="0"<?php selected('0', $views_options['display_search']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option> |
| 235 |
<option value="1"<?php selected('1', $views_options['display_search']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option> |
| 236 |
<option value="2"<?php selected('2', $views_options['display_search']); ?>><?php _e('Don\'t display on search pages', 'wp-postviews'); ?></option> |
| 237 |
</select> |
| 238 |
</td> |
| 239 |
</tr> |
| 240 |
<tr> |
| 241 |
<td valign="top"><strong><?php _e('Other Pages:', 'wp-postviews'); ?></strong></td> |
| 242 |
<td> |
| 243 |
<select name="views_display_other" size="1"> |
| 244 |
<option value="0"<?php selected('0', $views_options['display_other']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option> |
| 245 |
<option value="1"<?php selected('1', $views_options['display_other']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option> |
| 246 |
<option value="2"<?php selected('2', $views_options['display_other']); ?>><?php _e('Don\'t display on other pages', 'wp-postviews'); ?></option> |
| 247 |
</select> |
| 248 |
</td> |
| 249 |
</tr> |
| 250 |
</table> |
| 251 |
<p class="submit"> |
| 252 |
<input type="submit" name="Submit" class="button" value="<?php _e('Save Changes', 'wp-postviews'); ?>" /> |
| 253 |
</p> |
| 254 |
</div> |
| 255 |
</form> |
| 256 |
<p> </p> |
| 257 |
|
| 258 |
<!-- Uninstall WP-PostViews --> |
| 259 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 260 |
<div class="wrap"> |
| 261 |
<h3><?php _e('Uninstall WP-PostViews', 'wp-postviews'); ?></h3> |
| 262 |
<p> |
| 263 |
<?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'); ?> |
| 264 |
</p> |
| 265 |
<p style="color: red"> |
| 266 |
<strong><?php _e('WARNING:', 'wp-postviews'); ?></strong><br /> |
| 267 |
<?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'); ?> |
| 268 |
</p> |
| 269 |
<p style="color: red"> |
| 270 |
<strong><?php _e('The following WordPress Options/PostMetas will be DELETED:', 'wp-postviews'); ?></strong><br /> |
| 271 |
</p> |
| 272 |
<table class="widefat"> |
| 273 |
<thead> |
| 274 |
<tr> |
| 275 |
<th><?php _e('WordPress Options', 'wp-postviews'); ?></th> |
| 276 |
<th><?php _e('WordPress PostMetas', 'wp-postviews'); ?></th> |
| 277 |
</tr> |
| 278 |
</thead> |
| 279 |
<tr> |
| 280 |
<td valign="top"> |
| 281 |
<ol> |
| 282 |
<?php |
| 283 |
foreach($views_settings as $settings) { |
| 284 |
echo '<li>'.$settings.'</li>'."\n"; |
| 285 |
} |
| 286 |
?> |
| 287 |
</ol> |
| 288 |
</td> |
| 289 |
<td valign="top" class="alternate"> |
| 290 |
<ol> |
| 291 |
<?php |
| 292 |
foreach($views_postmetas as $postmeta) { |
| 293 |
echo '<li>'.$postmeta.'</li>'."\n"; |
| 294 |
} |
| 295 |
?> |
| 296 |
</ol> |
| 297 |
</td> |
| 298 |
</tr> |
| 299 |
</table> |
| 300 |
<p> </p> |
| 301 |
<p style="text-align: center;"> |
| 302 |
<input type="checkbox" name="uninstall_views_yes" value="yes" /> <?php _e('Yes', 'wp-postviews'); ?><br /><br /> |
| 303 |
<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'); ?>')" /> |
| 304 |
</p> |
| 305 |
</div> |
| 306 |
</form> |
| 307 |
<?php |
| 308 |
} // End switch($mode) |
| 309 |
?> |