PluginProbe
WebberZone Top 10 — Popular Posts / 1.1
WebberZone Top 10 — Popular Posts v1.1
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.1, at admin.inc.php

162 lines 6.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[limit] = ($_POST['limit']);
15 $tptn_settings[count_disp_form] = ($_POST['count_disp_form']);
16 $tptn_settings[add_to_content] = (($_POST['add_to_content']) ? true : false);
17 $tptn_settings[exclude_pages] = (($_POST['exclude_pages']) ? true : false);
18 $tptn_settings[show_credit] = (($_POST['show_credit']) ? true : false);
19
20 update_option('ald_tptn_settings', $tptn_settings);
21
22 $str = '<div id="message" class="updated fade"><p>'. __('Options saved successfully.','ald_tptn_plugin') .'</p></div>';
23 echo $str;
24 }
25
26 if ($_POST['tptn_default']){
27 delete_option('ald_tptn_settings');
28 $tptn_settings = tptn_default_options();
29 update_option('ald_tptn_settings', $tptn_settings);
30
31 $str = '<div id="message" class="updated fade"><p>'. __('Options set to Default.','ald_tptn_plugin') .'</p></div>';
32 echo $str;
33 }
34 ?>
35
36 <div class="wrap">
37 <h2>Top 10 </h2>
38 <div style="border: #ccc 1px solid; padding: 10px">
39 <fieldset class="options">
40 <legend>
41 <h3>
42 <?php _e('Support the Development','ald_tptn_plugin'); ?>
43 </h3>
44 </legend>
45 <p>
46 <?php _e('If you find ','ald_tptn_plugin'); ?>
47 <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10</a>
48 <?php _e('useful, please do','ald_tptn_plugin'); ?>
49 <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>.
50 (<a href="http://ajaydsouza.com/donate/"><?php _e('Some reasons why you should.','ald_tptn_plugin'); ?></a>)</p>
51 </fieldset>
52 </div>
53 <form method="post" id="tptn_options" name="tptn_options" style="border: #ccc 1px solid; padding: 10px">
54 <fieldset class="options">
55 <legend>
56 <h3>
57 <?php _e('Options:','ald_tptn_plugin'); ?>
58 </h3>
59 </legend>
60 <p>
61 <label>
62 <?php _e('Format to display the count in: ','ald_tptn_plugin'); ?><br />
63 <textarea name="count_disp_form" id="count_disp_form" cols="45" rows="5"><?php echo htmlspecialchars(stripslashes($tptn_settings[count_disp_form])); ?></textarea>
64 </label>
65 </p>
66 <p><?php _e('Use <code>%totalcount%</code> to display the total count. e.g. the default options displays <code>(Visited 123 times)</code>','ald_tptn_plugin'); ?></p>
67 <p>
68 <label>
69 <?php _e('Number of popular posts to display: ','ald_tptn_plugin'); ?>
70 <input type="textbox" name="limit" id="limit" value="<?php echo stripslashes($tptn_settings[limit]); ?>">
71 </label>
72 </p>
73 <p>
74 <label>
75 <?php _e('Title of popular posts: ','ald_tptn_plugin'); ?>
76 <input type="textbox" name="title" id="title" value="<?php echo stripslashes($tptn_settings[title]); ?>">
77 </label>
78 </p>
79 <p>
80 <label>
81 <input type="checkbox" name="exclude_pages" id="exclude_pages" <?php if ($tptn_settings[exclude_pages]) echo 'checked="checked"' ?> />
82 <?php _e('Exclude Pages in display of Popular Posts? Number of views on Pages will continue to be counted.','ald_tptn_plugin'); ?>
83 </label>
84 </p>
85 <p>
86 <label>
87 <input type="checkbox" name="add_to_content" id="add_to_content" <?php if ($tptn_settings[add_to_content]) echo 'checked="checked"' ?> />
88 <?php _e('Add post count to content?','ald_tptn_plugin'); ?>
89 </label>
90 </p>
91 <p>
92 <label>
93 <input type="checkbox" name="show_credit" id="show_credit" <?php if ($tptn_settings[show_credit]) echo 'checked="checked"' ?> />
94 <?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'); ?>
95 </label>
96 </p>
97 <p>
98 <input type="submit" name="tptn_save" id="tptn_save" value="Save Options" style="border:#00CC00 1px solid" />
99 <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;" />
100 </p>
101 </fieldset>
102 </form>
103 </div>
104 <?php
105
106 }
107
108 /* Add menu item in WP-Admin */
109 function tptn_adminmenu() {
110 if (function_exists('current_user_can')) {
111 // In WordPress 2.x
112 if (current_user_can('manage_options')) {
113 $tptn_is_admin = true;
114 }
115 } else {
116 // In WordPress 1.x
117 global $user_ID;
118 if (user_can_edit_user($user_ID, 0)) {
119 $tptn_is_admin = true;
120 }
121 }
122
123 if ((function_exists('add_options_page'))&&($tptn_is_admin)) {
124 add_options_page(__("Top 10", 'myald_tptn_plugin'), __("Top 10", 'myald_tptn_plugin'), 9, 'tptn_options', 'tptn_options');
125 }
126 }
127 add_action('admin_menu', 'tptn_adminmenu');
128
129
130 /* Create a Dashboard Widget */
131 function tptn_pop_dashboard() {
132 global $wpdb, $siteurl, $tableposts, $id;
133
134 $table_name = $wpdb->prefix . "top_ten";
135 $tptn_settings = tptn_read_options();
136 $limit = $tptn_settings['limit'];
137
138 $sql = "SELECT postnumber, cntaccess , ID, post_type ";
139 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
140 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
141 $sql .= "ORDER BY cntaccess DESC LIMIT $limit";
142
143 $results = $wpdb->get_results($sql);
144
145 echo '<ul>';
146 if ($results) {
147 foreach ($results as $result) {
148 echo '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a> ('.$result->cntaccess.')</li>';
149 }
150 }
151 if ($tptn_settings['show_credit']) echo '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
152 echo '</ul>';
153 }
154
155 function tptn_pop_dashboard_setup() {
156 if (function_exists('wp_add_dashboard_widget')) {
157 wp_add_dashboard_widget( 'tptn_pop_dashboard', __( 'Popular Posts' ), 'tptn_pop_dashboard' );
158 }
159 }
160 add_action('wp_dashboard_setup', 'tptn_pop_dashboard_setup');
161
162 ?>