| 1 |
<?php |
| 2 |
### Variables Variables Variables |
| 3 |
$base_name = plugin_basename( 'wp-postviews/postviews-options.php' ); |
| 4 |
$base_page = 'admin.php?page='.$base_name; |
| 5 |
$id = (isset($_GET['id'] ) ? intval($_GET['id'] ) : 0); |
| 6 |
$mode = (isset($_GET['mode'] ) ? trim($_GET['mode'] ) : '' ); |
| 7 |
$text = ''; |
| 8 |
|
| 9 |
### Form Processing |
| 10 |
if(!empty($_POST['Submit'] )) { |
| 11 |
check_admin_referer( 'wp-postviews_options' ); |
| 12 |
$views_options = array( |
| 13 |
'count' => intval( views_options_parse('views_count') ) |
| 14 |
, 'exclude_bots' => intval( views_options_parse('views_exclude_bots') ) |
| 15 |
, 'display_home' => intval( views_options_parse('views_display_home') ) |
| 16 |
, 'display_single' => intval( views_options_parse('views_display_single') ) |
| 17 |
, 'display_page' => intval( views_options_parse('views_display_page') ) |
| 18 |
, 'display_archive' => intval( views_options_parse('views_display_archive') ) |
| 19 |
, 'display_search' => intval( views_options_parse('views_display_search') ) |
| 20 |
, 'display_other' => intval( views_options_parse('views_display_other') ) |
| 21 |
, 'use_ajax' => intval( views_options_parse('views_use_ajax') ) |
| 22 |
, 'template' => trim( views_options_parse('views_template_template') ) |
| 23 |
, 'most_viewed_template' => trim( views_options_parse('views_template_most_viewed') ) |
| 24 |
); |
| 25 |
$update_views_queries = array(); |
| 26 |
$update_views_text = array(); |
| 27 |
$update_views_queries[] = update_option( 'views_options', $views_options ); |
| 28 |
$update_views_text[] = __( 'Post Views Options', 'wp-postviews' ); |
| 29 |
$i = 0; |
| 30 |
|
| 31 |
foreach( $update_views_queries as $update_views_query ) { |
| 32 |
if( $update_views_query ) { |
| 33 |
$text .= '<p style="color: green;">' . $update_views_text[$i] . ' ' . __( 'Updated', 'wp-postviews' ) . '</p>'; |
| 34 |
} |
| 35 |
$i++; |
| 36 |
} |
| 37 |
if( empty( $text ) ) { |
| 38 |
$text = '<p style="color: red;">' . __( 'No Post Views Option Updated', 'wp-postviews' ) . '</p>'; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
$views_options = get_option( 'views_options' ); |
| 43 |
|
| 44 |
// Default |
| 45 |
if( !isset ( $views_options['use_ajax'] ) ) { |
| 46 |
$views_options['use_ajax'] = 1; |
| 47 |
} |
| 48 |
?> |
| 49 |
<script type="text/javascript"> |
| 50 |
/* <![CDATA[*/ |
| 51 |
function views_default_templates(template) { |
| 52 |
var default_template; |
| 53 |
switch(template) { |
| 54 |
case 'template': |
| 55 |
default_template = "<?php _e( '%VIEW_COUNT% views', 'wp-postviews' ); ?>"; |
| 56 |
break; |
| 57 |
case 'most_viewed': |
| 58 |
default_template = "<li><a href=\"%POST_URL%\" title=\"%POST_TITLE%\">%POST_TITLE%</a> - %VIEW_COUNT% <?php _e( 'views', 'wp-postviews' ); ?></li>"; |
| 59 |
break; |
| 60 |
} |
| 61 |
jQuery("#views_template_" + template).val(default_template); |
| 62 |
} |
| 63 |
/* ]]> */ |
| 64 |
</script> |
| 65 |
<?php if( !empty( $text ) ) { echo '<div id="message" class="updated fade"><p>' . $text . '</p></div>'; } ?> |
| 66 |
<form method="post" action="<?php echo admin_url( 'admin.php?page=' . plugin_basename( __FILE__ ) ); ?>"> |
| 67 |
<?php wp_nonce_field( 'wp-postviews_options' ); ?> |
| 68 |
<div class="wrap"> |
| 69 |
<h2><?php _e( 'Post Views Options', 'wp-postviews' ); ?></h2> |
| 70 |
<table class="form-table"> |
| 71 |
<tr> |
| 72 |
<td valign="top" width="30%"><strong><?php _e( 'Count Views From:', 'wp-postviews' ); ?></strong></td> |
| 73 |
<td valign="top"> |
| 74 |
<select name="views_count" size="1"> |
| 75 |
<option value="0"<?php selected( '0', $views_options['count'] ); ?>><?php _e( 'Everyone', 'wp-postviews' ); ?></option> |
| 76 |
<option value="1"<?php selected( '1', $views_options['count'] ); ?>><?php _e( 'Guests Only', 'wp-postviews' ); ?></option> |
| 77 |
<option value="2"<?php selected( '2', $views_options['count'] ); ?>><?php _e( 'Registered Users Only', 'wp-postviews' ); ?></option> |
| 78 |
</select> |
| 79 |
</td> |
| 80 |
</tr> |
| 81 |
<tr> |
| 82 |
<td valign="top" width="30%"><strong><?php _e( 'Exclude Bot Views:', 'wp-postviews' ); ?></strong></td> |
| 83 |
<td valign="top"> |
| 84 |
<select name="views_exclude_bots" size="1"> |
| 85 |
<option value="0"<?php selected( '0', $views_options['exclude_bots'] ); ?>><?php _e( 'No', 'wp-postviews' ); ?></option> |
| 86 |
<option value="1"<?php selected( '1', $views_options['exclude_bots'] ); ?>><?php _e( 'Yes', 'wp-postviews' ); ?></option> |
| 87 |
</select> |
| 88 |
</td> |
| 89 |
</tr> |
| 90 |
<?php if( defined( 'WP_CACHE' ) && WP_CACHE ): ?> |
| 91 |
<tr> |
| 92 |
<td valign="top" width="30%"><strong><?php _e( 'Use AJAX To Update Views:', 'wp-postviews' ); ?></strong></td> |
| 93 |
<td valign="top"> |
| 94 |
<select name="views_use_ajax" size="1"> |
| 95 |
<option value="0"<?php selected( '0', $views_options['use_ajax'] ); ?>><?php _e( 'No', 'wp-postviews' ); ?></option> |
| 96 |
<option value="1"<?php selected( '1', $views_options['use_ajax'] ); ?>><?php _e( 'Yes', 'wp-postviews' ); ?></option> |
| 97 |
</select> |
| 98 |
<p> |
| 99 |
<?php _e( 'You have caching enabled for your WordPress installation, by default WP-PostViews will use AJAX to update the view count. However in some cases, you might not want it.', 'wp-postviews' ); ?> |
| 100 |
</p> |
| 101 |
</td> |
| 102 |
</tr> |
| 103 |
<?php else: ?> |
| 104 |
<input type="hidden" name="views_use_ajax" value="0" /> |
| 105 |
<?php endif; ?> |
| 106 |
<tr> |
| 107 |
<td valign="top"> |
| 108 |
<strong><?php _e( 'Views Template:', 'wp-postviews' ); ?></strong><br /><br /> |
| 109 |
<?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br /> |
| 110 |
- %VIEW_COUNT%<br /> |
| 111 |
- %VIEW_COUNT_ROUNDED%<br /><br /> |
| 112 |
<input type="button" name="RestoreDefault" value="<?php _e( 'Restore Default Template', 'wp-postviews' ); ?>" onclick="views_default_templates( 'template' );" class="button" /> |
| 113 |
</td> |
| 114 |
<td valign="top"> |
| 115 |
<input type="text" id="views_template_template" name="views_template_template" size="70" value="<?php echo htmlspecialchars(stripslashes($views_options['template'] )); ?>" /> |
| 116 |
</td> |
| 117 |
</tr> |
| 118 |
<tr> |
| 119 |
<td valign="top"> |
| 120 |
<strong><?php _e( 'Most Viewed Template:', 'wp-postviews' ); ?></strong><br /><br /> |
| 121 |
<?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br /> |
| 122 |
- %VIEW_COUNT%<br /> |
| 123 |
- %VIEW_COUNT_ROUNDED%<br /> |
| 124 |
- %POST_TITLE%<br /> |
| 125 |
- %POST_DATE%<br /> |
| 126 |
- %POST_TIME%<br /> |
| 127 |
- %POST_EXCERPT%<br /> |
| 128 |
- %POST_CONTENT%<br /> |
| 129 |
- %POST_URL%<br /> |
| 130 |
- %POST_THUMBNAIL%<br /> |
| 131 |
- %POST_CATEGORY_ID%<br /><br /> |
| 132 |
<input type="button" name="RestoreDefault" value="<?php _e( 'Restore Default Template', 'wp-postviews' ); ?>" onclick="views_default_templates( 'most_viewed' );" class="button" /> |
| 133 |
</td> |
| 134 |
<td valign="top"> |
| 135 |
<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> |
| 136 |
</td> |
| 137 |
</tr> |
| 138 |
</table> |
| 139 |
<h3><?php _e( 'Display Options', 'wp-postviews' ); ?></h3> |
| 140 |
<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> |
| 141 |
<table class="form-table"> |
| 142 |
<tr> |
| 143 |
<td valign="top"><strong><?php _e( 'Home Page:', 'wp-postviews' ); ?></strong></td> |
| 144 |
<td> |
| 145 |
<select name="views_display_home" size="1"> |
| 146 |
<option value="0"<?php selected( '0', $views_options['display_home'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option> |
| 147 |
<option value="1"<?php selected( '1', $views_options['display_home'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option> |
| 148 |
<option value="2"<?php selected( '2', $views_options['display_home'] ); ?>><?php _e( 'Don\'t display on home page', 'wp-postviews' ); ?></option> |
| 149 |
</select> |
| 150 |
</td> |
| 151 |
</tr> |
| 152 |
<tr> |
| 153 |
<td valign="top"><strong><?php _e( 'Single Posts:', 'wp-postviews' ); ?></strong></td> |
| 154 |
<td> |
| 155 |
<select name="views_display_single" size="1"> |
| 156 |
<option value="0"<?php selected( '0', $views_options['display_single'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option> |
| 157 |
<option value="1"<?php selected( '1', $views_options['display_single'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option> |
| 158 |
<option value="2"<?php selected( '2', $views_options['display_single'] ); ?>><?php _e( 'Don\'t display on single posts', 'wp-postviews' ); ?></option> |
| 159 |
</select> |
| 160 |
</td> |
| 161 |
</tr> |
| 162 |
<tr> |
| 163 |
<td valign="top"><strong><?php _e( 'Pages:', 'wp-postviews' ); ?></strong></td> |
| 164 |
<td> |
| 165 |
<select name="views_display_page" size="1"> |
| 166 |
<option value="0"<?php selected( '0', $views_options['display_page'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option> |
| 167 |
<option value="1"<?php selected( '1', $views_options['display_page'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option> |
| 168 |
<option value="2"<?php selected( '2', $views_options['display_page'] ); ?>><?php _e( 'Don\'t display on pages', 'wp-postviews' ); ?></option> |
| 169 |
</select> |
| 170 |
</td> |
| 171 |
</tr> |
| 172 |
<tr> |
| 173 |
<td valign="top"><strong><?php _e( 'Archive Pages:', 'wp-postviews' ); ?></strong></td> |
| 174 |
<td> |
| 175 |
<select name="views_display_archive" size="1"> |
| 176 |
<option value="0"<?php selected( '0', $views_options['display_archive'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option> |
| 177 |
<option value="1"<?php selected( '1', $views_options['display_archive'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option> |
| 178 |
<option value="2"<?php selected( '2', $views_options['display_archive'] ); ?>><?php _e( 'Don\'t display on archive pages', 'wp-postviews' ); ?></option> |
| 179 |
</select> |
| 180 |
</td> |
| 181 |
</tr> |
| 182 |
<tr> |
| 183 |
<td valign="top"><strong><?php _e( 'Search Pages:', 'wp-postviews' ); ?></strong></td> |
| 184 |
<td> |
| 185 |
<select name="views_display_search" size="1"> |
| 186 |
<option value="0"<?php selected( '0', $views_options['display_search'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option> |
| 187 |
<option value="1"<?php selected( '1', $views_options['display_search'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option> |
| 188 |
<option value="2"<?php selected( '2', $views_options['display_search'] ); ?>><?php _e( 'Don\'t display on search pages', 'wp-postviews' ); ?></option> |
| 189 |
</select> |
| 190 |
</td> |
| 191 |
</tr> |
| 192 |
<tr> |
| 193 |
<td valign="top"><strong><?php _e( 'Other Pages:', 'wp-postviews' ); ?></strong></td> |
| 194 |
<td> |
| 195 |
<select name="views_display_other" size="1"> |
| 196 |
<option value="0"<?php selected( '0', $views_options['display_other'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option> |
| 197 |
<option value="1"<?php selected( '1', $views_options['display_other'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option> |
| 198 |
<option value="2"<?php selected( '2', $views_options['display_other'] ); ?>><?php _e( 'Don\'t display on other pages', 'wp-postviews' ); ?></option> |
| 199 |
</select> |
| 200 |
</td> |
| 201 |
</tr> |
| 202 |
</table> |
| 203 |
<p class="submit"> |
| 204 |
<input type="submit" name="Submit" class="button-primary" value="<?php _e( 'Save Changes', 'wp-postviews' ); ?>" /> |
| 205 |
</p> |
| 206 |
</div> |
| 207 |
</form> |
| 208 |
|