/*
+----------------------------------------------------------------+
| |
| 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 .= ''.$update_views_text[$i].' '.__('Updated', 'wp-postviews').'
';
}
$i++;
}
if(empty($text)) {
$text = ''.__('No Post Views Option Updated', 'wp-postviews').'';
}
}
// 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 '';
echo '';
foreach($views_settings as $setting) {
$delete_setting = delete_option($setting);
if($delete_setting) {
echo '';
printf(__('Setting Key \'%s\' has been deleted.', 'wp-postviews'), "{$setting}");
echo '
';
} else {
echo '';
printf(__('Error deleting Setting Key \'%s\'.', 'wp-postviews'), "{$setting}");
echo '
';
}
}
echo '
';
echo '';
foreach($views_postmetas as $postmeta) {
$remove_postmeta = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = '$postmeta'");
if($remove_postmeta) {
echo '';
printf(__('Post Meta Key \'%s\' has been deleted.', 'wp-postviews'), "{$postmeta}");
echo '
';
} else {
echo '';
printf(__('Error deleting Post Meta Key \'%s\'.', 'wp-postviews'), "{$postmeta}");
echo '
';
}
}
echo '
';
echo '';
$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 '';
echo ''.__('Uninstall WP-PostViews', 'wp-postviews').'
';
echo ''.sprintf(__('Click Here To Finish The Uninstallation And WP-PostViews Will Be Deactivated Automatically.', 'wp-postviews'), $deactivate_url).'
';
echo '';
break;
// Main Page
default:
$views_options = get_option('views_options');
?>
<script>
/* function views_default_templates(template) {
var default_template;
switch(template) {
case 'template':
default_template = "";
break;
case 'most_viewed':
default_template = "%POST_TITLE% - %VIEW_COUNT% ";
break;
}
jQuery("#views_template_" + template).val(default_template);
}
/* ]]> */
</script>
'.$text.'
'; } ?>
} // End switch($mode)
?>