PluginProbe
WebberZone Top 10 — Popular Posts / 1.2
WebberZone Top 10 — Popular Posts v1.2
4.5.1 4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 All 117 releases
top-10 / admin.inc.php

admin.inc.php in WebberZone Top 10 — Popular Posts 1.2, at admin.inc.php

262 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**********************************************************************
3 * Admin Page *
4 *********************************************************************/
5 function tptn_options() {
6
7 global $wpdb;
8 $poststable = $wpdb->posts;
9
10 $tptn_settings = tptn_read_options();
11
12 if($_POST['tptn_save']){
13 $tptn_settings[title] = ($_POST['title']);
14 $tptn_settings[title_daily] = ($_POST['title_daily']);
15 $tptn_settings[limit] = ($_POST['limit']);
16 $tptn_settings[count_disp_form] = ($_POST['count_disp_form']);
17 $tptn_settings[add_to_content] = (($_POST['add_to_content']) ? true : false);
18 $tptn_settings[exclude_pages] = (($_POST['exclude_pages']) ? true : false);
19 $tptn_settings[track_authors] = (($_POST['track_authors']) ? true : false);
20 $tptn_settings[pv_in_admin] = (($_POST['pv_in_admin']) ? true : false);
21 $tptn_settings[show_credit] = (($_POST['show_credit']) ? true : false);
22
23 update_option('ald_tptn_settings', $tptn_settings);
24
25 $str = '<div id="message" class="updated fade"><p>'. __('Options saved successfully.','ald_tptn_plugin') .'</p></div>';
26 echo $str;
27 }
28
29 if ($_POST['tptn_default']){
30 delete_option('ald_tptn_settings');
31 $tptn_settings = tptn_default_options();
32 update_option('ald_tptn_settings', $tptn_settings);
33
34 $str = '<div id="message" class="updated fade"><p>'. __('Options set to Default.','ald_tptn_plugin') .'</p></div>';
35 echo $str;
36 }
37 ?>
38
39 <div class="wrap">
40 <h2>Top 10 </h2>
41 <div style="border: #ccc 1px solid; padding: 10px">
42 <fieldset class="options">
43 <legend>
44 <h3>
45 <?php _e('Support the Development','ald_tptn_plugin'); ?>
46 </h3>
47 </legend>
48 <p>
49 <?php _e('If you find ','ald_tptn_plugin'); ?>
50 <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10</a>
51 <?php _e('useful, please do','ald_tptn_plugin'); ?>
52 <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;[email protected]&amp;item_name=Top%10%20(From%20WP-Admin)&amp;no_shipping=1&amp;return=http://ajaydsouza.com/wordpress/plugins/top-10/&amp;cancel_return=http://ajaydsouza.com/wordpress/plugins/top-10/&amp;cn=Note%20to%20Author&amp;tax=0&amp;currency_code=USD&amp;bn=PP-DonationsBF&amp;charset=UTF-8" title="Donate via PayPal"><?php _e('drop in your contribution','ald_tptn_plugin'); ?></a>.
53 (<a href="http://ajaydsouza.com/donate/"><?php _e('Some reasons why you should.','ald_tptn_plugin'); ?></a>)</p>
54 </fieldset>
55 </div>
56 <form method="post" id="tptn_options" name="tptn_options" style="border: #ccc 1px solid; padding: 10px">
57 <fieldset class="options">
58 <legend>
59 <h3>
60 <?php _e('Options:','ald_tptn_plugin'); ?>
61 </h3>
62 </legend>
63 <p>
64 <label>
65 <?php _e('Format to display the count in: ','ald_tptn_plugin'); ?><br />
66 <textarea name="count_disp_form" id="count_disp_form" cols="50" rows="5"><?php echo htmlspecialchars(stripslashes($tptn_settings[count_disp_form])); ?></textarea>
67 </label>
68 </p>
69 <p><?php _e('Use <code>%totalcount%</code> to display the total count and <code>%dailycount%</code> to display the daily count. e.g. the default options displays <code>(Visited 123 times, 23 visits today)</code>','ald_tptn_plugin'); ?></p>
70 <p>
71 <label>
72 <?php _e('Number of popular posts to display: ','ald_tptn_plugin'); ?>
73 <input type="textbox" name="limit" id="limit" value="<?php echo stripslashes($tptn_settings[limit]); ?>">
74 </label>
75 </p>
76 <p>
77 <label>
78 <?php _e('Title of popular posts: ','ald_tptn_plugin'); ?>
79 <input type="textbox" name="title" id="title" value="<?php echo stripslashes($tptn_settings[title]); ?>">
80 </label>
81 </p>
82 <p>
83 <label>
84 <?php _e('Title of daily popular posts: ','ald_tptn_plugin'); ?>
85 <input type="textbox" name="title_daily" id="title_daily" value="<?php echo stripslashes($tptn_settings[title_daily]); ?>">
86 </label>
87 </p>
88 <p>
89 <label>
90 <input type="checkbox" name="exclude_pages" id="exclude_pages" <?php if ($tptn_settings[exclude_pages]) echo 'checked="checked"' ?> />
91 <?php _e('Exclude Pages in display of Popular Posts? Number of views on Pages will continue to be counted.','ald_tptn_plugin'); ?>
92 </label>
93 </p>
94 <p>
95 <label>
96 <input type="checkbox" name="track_authors" id="track_authors" <?php if ($tptn_settings[track_authors]) echo 'checked="checked"' ?> />
97 <?php _e('Track visits of authors on their own posts?','ald_tptn_plugin'); ?>
98 </label>
99 </p>
100 <p>
101 <label>
102 <input type="checkbox" name="pv_in_admin" id="pv_in_admin" <?php if ($tptn_settings[pv_in_admin]) echo 'checked="checked"' ?> />
103 <?php _e('Display page views on Edit posts/pages in WP-Admin? An extra column is added with the count','ald_tptn_plugin'); ?>
104 </label>
105 </p>
106 <p>
107 <label>
108 <input type="checkbox" name="add_to_content" id="add_to_content" <?php if ($tptn_settings[add_to_content]) echo 'checked="checked"' ?> />
109 <?php _e('Add post count to content?','ald_tptn_plugin'); ?>
110 </label>
111 </p>
112 <p>
113 <label>
114 <input type="checkbox" name="show_credit" id="show_credit" <?php if ($tptn_settings[show_credit]) echo 'checked="checked"' ?> />
115 <?php _e('A link to the plugin is added as an extra list item to the list of popular posts. Not mandatory, but thanks if you do it!','ald_tptn_plugin'); ?>
116 </label>
117 </p>
118 <p>
119 <input type="submit" name="tptn_save" id="tptn_save" value="Save Options" style="border:#00CC00 1px solid" />
120 <input name="tptn_default" type="submit" id="tptn_default" value="Default Options" style="border:#FF0000 1px solid" onclick="if (!confirm('<?php _e('Do you want to set options to Default? If you don\'t have a copy of the username, please hit Cancel and copy it first.','ald_tptn_plugin'); ?>')) return false;" />
121 </p>
122 </fieldset>
123 </form>
124 </div>
125 <?php
126
127 }
128
129 /* Add menu item in WP-Admin */
130 function tptn_adminmenu() {
131 if (function_exists('current_user_can')) {
132 // In WordPress 2.x
133 if (current_user_can('manage_options')) {
134 $tptn_is_admin = true;
135 }
136 } else {
137 // In WordPress 1.x
138 global $user_ID;
139 if (user_can_edit_user($user_ID, 0)) {
140 $tptn_is_admin = true;
141 }
142 }
143
144 if ((function_exists('add_options_page'))&&($tptn_is_admin)) {
145 add_options_page(__("Top 10", 'myald_tptn_plugin'), __("Top 10", 'myald_tptn_plugin'), 9, 'tptn_options', 'tptn_options');
146 }
147 }
148 add_action('admin_menu', 'tptn_adminmenu');
149
150
151 /* Create a Dashboard Widget */
152 // Dashboard for Popular Posts
153 function tptn_pop_dashboard() {
154 global $wpdb, $siteurl, $tableposts, $id;
155
156 $table_name = $wpdb->prefix . "top_ten";
157 $tptn_settings = tptn_read_options();
158 $limit = $tptn_settings['limit'];
159
160 $sql = "SELECT postnumber, cntaccess , ID, post_type ";
161 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
162 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
163 $sql .= "AND post_status = 'publish' ";
164 $sql .= "ORDER BY cntaccess DESC LIMIT $limit";
165
166 $results = $wpdb->get_results($sql);
167
168 echo '<ul>';
169 if ($results) {
170 foreach ($results as $result) {
171 echo '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a> ('.$result->cntaccess.')</li>';
172 }
173 }
174 if ($tptn_settings['show_credit']) echo '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
175 echo '</ul>';
176 }
177
178 // Dashboard for Daily Popular Posts
179 function tptn_pop_daily_dashboard() {
180 global $wpdb, $siteurl, $tableposts, $id;
181
182 $table_name = $wpdb->prefix . "top_ten_daily";
183 $tptn_settings = tptn_read_options();
184 $limit = $tptn_settings['limit'];
185
186 $sql = "SELECT postnumber, cntaccess , ID, post_type ";
187 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
188 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
189 $sql .= "AND post_status = 'publish' ";
190 $sql .= "ORDER BY cntaccess DESC LIMIT $limit";
191
192 $results = $wpdb->get_results($sql);
193
194 echo '<ul>';
195 if ($results) {
196 foreach ($results as $result) {
197 echo '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a> ('.$result->cntaccess.')</li>';
198 }
199 }
200 if ($tptn_settings['show_credit']) echo '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
201 echo '</ul>';
202 }
203
204 function tptn_pop_dashboard_setup() {
205 if (function_exists('wp_add_dashboard_widget')) {
206 wp_add_dashboard_widget( 'tptn_pop_dashboard', __( 'Popular Posts' ), 'tptn_pop_dashboard' );
207 wp_add_dashboard_widget( 'tptn_pop_daily_dashboard', __( 'Daily Popular' ), 'tptn_pop_daily_dashboard' );
208 }
209 }
210 add_action('wp_dashboard_setup', 'tptn_pop_dashboard_setup');
211
212 /* Display page views on the Edit Posts / Pages screen */
213 // Add an extra column
214 function tptn_column($cols) {
215 $tptn_settings = tptn_read_options();
216
217 if ($tptn_settings[pv_in_admin]) $cols['tptn'] = __('Total / Today\'s Views','ald_tptn_plugin');
218 return $cols;
219 }
220
221 // Display page views for each column
222 function tptn_value($column_name, $id) {
223 $tptn_settings = tptn_read_options();
224 if (($column_name == 'tptn')&&($tptn_settings[pv_in_admin])) {
225 global $wpdb;
226
227 $table_name = $wpdb->prefix . "top_ten";
228
229 $resultscount = $wpdb->get_row("select postnumber, cntaccess from $table_name WHERE postnumber = $id");
230 $cntaccess = number_format((($resultscount) ? $resultscount->cntaccess : 0));
231
232 $cntaccess .= ' / ';
233
234 $table_name = $wpdb->prefix . "top_ten_daily";
235
236 $resultscount = $wpdb->get_row("select postnumber, cntaccess from $table_name WHERE postnumber = $id");
237 $cntaccess .= number_format((($resultscount) ? $resultscount->cntaccess : 0));
238 echo $cntaccess;
239 }
240 }
241
242 // Output CSS for width of new column
243 function tptn_css() {
244 ?>
245 <style type="text/css">
246 #tptn { width: 50px; }
247 </style>
248 <?php
249 }
250
251 // Actions/Filters for various tables and the css output
252 add_filter('manage_posts_columns', 'tptn_column');
253 add_action('manage_posts_custom_column', 'tptn_value', 10, 2);
254 add_filter('manage_pages_columns', 'tptn_column');
255 add_action('manage_pages_custom_column', 'tptn_value', 10, 2);
256 add_filter('manage_media_columns', 'tptn_column');
257 add_action('manage_media_custom_column', 'tptn_value', 10, 2);
258 add_filter('manage_link-manager_columns', 'tptn_column');
259 add_action('manage_link_custom_column', 'tptn_value', 10, 2);
260 add_action('admin_head', 'tptn_css');
261
262 ?>