-
Notifications
You must be signed in to change notification settings - Fork 42
/
postviews-options.php
209 lines (205 loc) · 10.8 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
<?php
### Variables Variables Variables
$base_name = plugin_basename( 'wp-postviews/postviews-options.php' );
$base_page = 'admin.php?page='.$base_name;
$id = ( isset($_GET['id'] ) ? (int) sanitize_key( $_GET['id'] ) : 0 );
$mode = ( isset($_GET['mode'] ) ? sanitize_key( trim( $_GET['mode'] ) ) : '' );
$text = '';
### Form Processing
if(!empty($_POST['Submit'] )) {
check_admin_referer( 'wp-postviews_options' );
$views_options = array(
'count' => (int) sanitize_key( views_options_parse('views_count') )
, 'exclude_bots' => (int) sanitize_key( views_options_parse('views_exclude_bots') )
, 'display_home' => (int) sanitize_key( views_options_parse('views_display_home') )
, 'display_single' => (int) sanitize_key( views_options_parse('views_display_single') )
, 'display_page' => (int) sanitize_key( views_options_parse('views_display_page') )
, 'display_archive' => (int) sanitize_key( views_options_parse('views_display_archive') )
, 'display_search' => (int) sanitize_key( views_options_parse('views_display_search') )
, 'display_other' => (int) sanitize_key( views_options_parse('views_display_other') )
, 'use_ajax' => (int) sanitize_key( views_options_parse('views_use_ajax') )
, 'template' => wp_kses_post( trim( views_options_parse('views_template_template') ) )
, 'most_viewed_template' => wp_kses_post( trim( views_options_parse('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;
foreach( $update_views_queries as $update_views_query ) {
if( $update_views_query ) {
$text .= '<p style="color: green;">' . $update_views_text[$i] . ' ' . __( 'Updated', 'wp-postviews' ) . '</p>';
}
$i++;
}
if( empty( $text ) ) {
$text = '<p style="color: red;">' . __( 'No Post Views Option Updated', 'wp-postviews' ) . '</p>';
}
}
$views_options = get_option( 'views_options' );
// Default
if( !isset ( $views_options['use_ajax'] ) ) {
$views_options['use_ajax'] = 1;
}
?>
<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 '<div id="message" class="updated fade"><p>' . $text . '</p></div>'; } ?>
<form method="post" action="<?php echo admin_url( 'admin.php?page=' . plugin_basename( __FILE__ ) ); ?>">
<?php wp_nonce_field( 'wp-postviews_options' ); ?>
<div class="wrap">
<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>
<?php if( defined( 'WP_CACHE' ) && WP_CACHE ): ?>
<tr>
<td valign="top" width="30%"><strong><?php _e( 'Use AJAX To Update Views:', 'wp-postviews' ); ?></strong></td>
<td valign="top">
<select name="views_use_ajax" size="1">
<option value="0"<?php selected( '0', $views_options['use_ajax'] ); ?>><?php _e( 'No', 'wp-postviews' ); ?></option>
<option value="1"<?php selected( '1', $views_options['use_ajax'] ); ?>><?php _e( 'Yes', 'wp-postviews' ); ?></option>
</select>
<p>
<?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' ); ?>
</p>
</td>
</tr>
<?php else: ?>
<input type="hidden" name="views_use_ajax" value="0" />
<?php endif; ?>
<tr>
<td valign="top">
<strong><?php _e( 'Views Template:', 'wp-postviews' ); ?></strong><br /><br />
<?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br />
- %VIEW_COUNT%<br />
- %VIEW_COUNT_ROUNDED%<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 />
- %VIEW_COUNT_ROUNDED%<br />
- %POST_TITLE%<br />
- %POST_DATE%<br />
- %POST_TIME%<br />
- %POST_EXCERPT%<br />
- %POST_CONTENT%<br />
- %POST_URL%<br />
- %POST_THUMBNAIL%<br />
- %POST_THUMBNAIL_URL%<br />
- %POST_CATEGORY_ID%<br />
- %POST_AUTHOR%<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( 'Single 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>