root/wp-stats/trunk/wp-stats-widget.php

Revision 53041, 11.3 kB (checked in by GamerZ, 3 days ago)

Rename Widget

Line 
1 <?php
2 /*
3 Plugin Name: WP-Stats Widget
4 Plugin URI: http://lesterchan.net/portfolio/programming/php/
5 Description: Adds a Stats Widget to display stats from WP-Stats Plugin. You will need to activate WP-Stats first.
6 Version: 2.31
7 Author: Lester 'GaMerZ' Chan
8 Author URI: http://lesterchan.net
9 */
10
11
12 /*  Copyright 2008  Lester Chan  (email : lesterchan@gmail.com)
13
14     This program is free software; you can redistribute it and/or modify
15     it under the terms of the GNU General Public License as published by
16     the Free Software Foundation; either version 2 of the License, or
17     (at your option) any later version.
18
19     This program is distributed in the hope that it will be useful,
20     but WITHOUT ANY WARRANTY; without even the implied warranty of
21     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22     GNU General Public License for more details.
23
24     You should have received a copy of the GNU General Public License
25     along with this program; if not, write to the Free Software
26     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 */
28
29
30 ### Function: Init WP-Stats Widget
31 function widget_stats_init() {
32     if (!function_exists('register_sidebar_widget')) {
33         return;
34     }
35
36     ### Function: WP-Stats Widget
37     function widget_stats($args) {
38         extract($args);
39         $options = get_option('widget_stats');
40         $stats_total_options = $options['stats_display_total'];
41         $stats_most_options = $options['stats_display_most'];
42         $limit = intval($options['most_limit']);
43         $chars = intval($options['snippet_chars']);
44         $title = htmlspecialchars(stripslashes($options['title']));
45         if (function_exists('display_stats')) {
46             echo $before_widget.$before_title.$title.$after_title;
47             if(!empty($stats_total_options)) {
48                 echo '<ul>'."\n";
49                 echo '<li><strong>'.__('Total Stats', 'wp-stats').'</strong></li>'."\n";
50                 echo '<li>'."\n";
51                 echo '<ul>'."\n";
52                 // Total Authors
53                 if($stats_total_options['authors'] == 1) {
54                     echo '<li><strong>'.get_totalauthors(false).'</strong> '.__('Authors', 'wp-stats').'</li>'."\n";
55                 }
56                 // Total Posts
57                 if($stats_total_options['posts'] == 1) {
58                     echo '<li><strong>'.get_totalposts(false).'</strong> '.__('Posts', 'wp-stats').'</li>'."\n";
59                 }
60                 // Total Pages
61                 if($stats_total_options['pages'] == 1) {
62                     echo '<li><strong>'.get_totalpages(false).'</strong> '.__('Pages', 'wp-stats').'</li>'."\n";
63                 }
64                 // Total Tags
65                 if($stats_total_options['tags'] == 1) {
66                     echo '<li><strong>'.wp_count_terms('post_tag').'</strong> '.__('Tags', 'wp-stats').'</li>'."\n";
67                 }
68                 // Total Comments
69                 if($stats_total_options['comments'] == 1) {
70                     echo '<li><strong>'.get_totalcomments(false).'</strong> '.__('Comments', 'wp-stats').'</li>'."\n";
71                 }
72                 // Total Comment Posters
73                 if($stats_total_options['commenters'] == 1) {
74                     echo '<li><strong>'.get_totalcommentposters(false).'</strong> '.__('Comment Posters', 'wp-stats').'</li>'."\n";
75                 }
76                 // Total Links
77                 if($stats_total_options['links'] == 1) {
78                     echo '<li><strong>'.get_totallinks(false).'</strong> '.__('Links', 'wp-stats').'</li>'."\n";
79                 }
80                 // Total Post Categories
81                 if($stats_total_options['post_cats'] == 1) {
82                     echo '<li><strong>'.wp_count_terms('category').'</strong> '.__('Post Categories', 'wp-stats').'</li>'."\n";
83                 }
84                 // Total Link Categories
85                 if($stats_total_options['link_cats'] == 1) {
86                     echo '<li><strong>'.wp_count_terms('link_category').'</strong> '.__('Link Categories', 'wp-stats').'</li>'."\n";
87                 }
88                 // Total Spam
89                 if($stats_total_options['spam'] == 1 && function_exists('akismet_spam_count')) {
90                     echo '<li><strong>'.number_format(akismet_spam_count()).'</strong> '.__('Spam Blocked', 'wp-stats').'</li>'."\n";
91                 }
92                 echo apply_filters('wp_stats_widget_general', $widget_general_stats);
93                 echo '</ul>'."\n";
94                 echo '</li>'."\n";
95                 echo '</ul>'."\n";
96             }
97             // Most Commented
98             if($stats_most_options['comments'] == 1) {
99                 echo '<ul>'."\n";
100                 echo '<li><strong>'.$limit.' '.__('Most Commented', 'wp-stats').'</strong></li>'."\n";
101                 echo '<li>'."\n";
102                 echo '<ul>'."\n";
103                 get_mostcommented('post', $limit, $chars);
104                 echo '</ul>'."\n";
105                 echo '</li>'."\n";
106                 echo '</ul>'."\n";
107             }
108             echo apply_filters('wp_stats_widget_most', $widget_most_stats);
109             if(intval($options['show_link']) == 1) {
110                 echo '<ul>'."\n";
111                 echo '<li><a href="'.stripslashes(get_option('stats_url')).'">'.__('My Blog Statistics', 'wp-stats').'</a></li>'."\n";
112                 echo '</ul>'."\n";
113             }
114             echo $after_widget;
115         }
116     }
117
118     ### Function: WP-Stats Widget Options
119     function widget_stats_options() {
120         global $wpdb;
121         $options = get_option('widget_stats');
122         $stats_options_total_array = array();
123         $stats_options_most_array = array();
124         if (!is_array($options)) {
125             $options = array('title' => __('Statistics', 'wp-stats'), 'stats_display_total' => array(), 'stats_display_most' => array(), 'most_limit' => '10', 'show_link' => '1', 'snippet_chars' => 12);
126         }
127         if ($_POST['stats-submit']) {
128             $most_limit = intval($_POST['most_limit']);
129             $show_link = intval($_POST['show_link']);
130             $snippet_chars = intval($_POST['snippet_chars']);
131             $post_total_stats = $_POST['stats_display_total'];
132             $post_most_stats = $_POST['stats_display_most'];
133             if($post_total_stats) {
134                 foreach($post_total_stats as $post_total_stat) {
135                     $post_total_stat = addslashes($post_total_stat);
136                     $stats_options_total_array[$post_total_stat] = 1;
137                 }
138             }
139             if($post_most_stats) {
140                 foreach($post_most_stats as $post_most_stat) {
141                     $post_most_stat = addslashes($post_most_stat);
142                     $stats_options_most_array[$post_most_stat] = 1;
143                 }
144             }
145             $options['stats_display_total'] = $stats_options_total_array;
146             $options['stats_display_most'] = $stats_options_most_array;
147             $options['most_limit'] = $most_limit;
148             $options['show_link'] = $show_link;
149             $options['snippet_chars'] = $snippet_chars;
150             $options['title'] = strip_tags($_POST['stats-title']);
151             update_option('widget_stats', $options);
152         }
153         echo '<p style="text-align: left;"><label for="stats-title">'.__('Widget Title', 'wp-stats').':</label>&nbsp;&nbsp;&nbsp;<input type="text" id="stats-title" name="stats-title" value="'.htmlspecialchars(stripslashes($options['title'])).'" />';
154         echo '<p style="text-align: left;">'.__('Statistics To Display?', 'wp-stats').'&nbsp;&nbsp;&nbsp;'."\n";
155         echo '<p style="text-align: left;">'."\n";
156         echo '<input type="checkbox" id="wpstats_widget_authors" name="stats_display_total[]" value="authors"';
157         checked(1, $options['stats_display_total']['authors']);
158         echo ' />&nbsp;&nbsp;<label for="wpstats_widget_authors">'.__('Total Authors', 'wp-stats').'</label><br />'."\n";
159         echo '<input type="checkbox" id="wpstats_widget_posts" name="stats_display_total[]" value="posts"';
160         checked(1, $options['stats_display_total']['posts']);
161         echo ' />&nbsp;&nbsp;<label for="wpstats_widget_posts">'.__('Total Posts', 'wp-stats').'</label><br />'."\n";
162         echo '<input type="checkbox" id="wpstats_widget_pages" name="stats_display_total[]" value="pages"';
163         checked(1, $options['stats_display_total']['pages']);
164         echo ' />&nbsp;&nbsp;<label for="wpstats_widget_pages">'.__('Total Pages', 'wp-stats').'</label><br />'."\n";
165         echo '<input type="checkbox" id="wpstats_widget_tags" name="stats_display_total[]" value="tags"';
166         checked(1, $options['stats_display_total']['tags']);
167         echo ' />&nbsp;&nbsp;<label for="wpstats_widget_tags">'.__('Total Tags', 'wp-stats').'</label><br />'."\n";
168         echo '<input type="checkbox" id="wpstats_widget_comments" name="stats_display_total[]" value="comments"';
169         checked(1, $options['stats_display_total']['comments']);
170         echo ' />&nbsp;&nbsp;<label for="wpstats_widget_comments">'.__('Total Comments', 'wp-stats').'</label><br />'."\n";
171         echo '<input type="checkbox" id="wpstats_widget_commenters" name="stats_display_total[]" value="commenters"';
172         checked(1, $options['stats_display_total']['commenters']);
173         echo ' />&nbsp;&nbsp;<label for="wpstats_widget_commenters">'.__('Total Comment Posters', 'wp-stats').'</label><br />'."\n";
174         echo '<input type="checkbox" id="wpstats_widget_links" name="stats_display_total[]" value="links"';
175         checked(1, $options['stats_display_total']['links']);
176         echo ' />&nbsp;&nbsp;<label for="wpstats_widget_links">'.__('Total Links', 'wp-stats').'</label><br />'."\n";
177         echo '<input type="checkbox" id="wpstats_widget_post_cats" name="stats_display_total[]" value="post_cats"';
178         checked(1, $options['stats_display_total']['post_cats']);
179         echo ' />&nbsp;&nbsp;<label for="wpstats_widget_post_cats">'.__('Total Post Categories', 'wp-stats').'</label><br />'."\n";
180         echo '<input type="checkbox" id="wpstats_widget_link_cats" name="stats_display_total[]" value="link_cats"';
181         checked(1, $options['stats_display_total']['link_cats']);
182         echo ' />&nbsp;&nbsp;<label for="wpstats_widget_link_cats">'.__('Total Link Categories', 'wp-stats').'</label><br />'."\n";
183         if(function_exists('akismet_spam_count')) {
184             echo '<input type="checkbox" id="wpstats_widget_spam" name="stats_display_total[]" value="spam"';
185             checked(1, $options['stats_display_total']['spam']);
186             echo ' />&nbsp;&nbsp;<label for="wpstats_widget_spam">'.__('Total Spam Blocked', 'wp-stats').'</label>';
187         }
188         echo apply_filters('wp_stats_widget_admin_general', $widget_admin_general_stats);
189         echo '<br /><br />'."\n";
190         echo '<input type="checkbox" id="wpstats_widget_most_comments" name="stats_display_most[]" value="comments"';
191         checked(1, $options['stats_display_most']['comments']);
192         echo ' />&nbsp;&nbsp;<label for="wpstats_widget_most_comments">'.$options['most_limit'].' '.__('Most Commented Posts', 'wp-stats').'</label><br />'."\n";
193         echo apply_filters('wp_stats_widget_admin_most', $widget_admin_most_stats);
194         echo '</p>'."\n";
195         echo '<p style="text-align: left;"><label for="most_limit">'.__('Post Title Length (Characters)', 'wp-stats').':</label>&nbsp;&nbsp;&nbsp;'."\n";
196         echo '<p style="text-align: left;"><input type="text" id="snippet_chars" name="snippet_chars" value="'.$options['snippet_chars'].'" size="3" maxlength="3" /></p>'."\n";
197         echo '<p style="text-align: left;"><label for="most_limit">'.__('Most Limit', 'wp-stats').':</label>&nbsp;&nbsp;&nbsp;'."\n";
198         echo '<p style="text-align: left;"><input type="text" id="most_limit" name="most_limit" value="'.$options['most_limit'].'" size="2" maxlength="2" /></p>'."\n";
199         echo '<p style="text-align: left;">'.__('Show Link To Full Stats?', 'wp-stats').'&nbsp;&nbsp;&nbsp;'."\n";
200         echo '<p style="text-align: left;">';
201         echo '<input type="radio" id="show_link-1" name="show_link" value="1"';
202         checked(1, intval($options['show_link']));
203         echo ' />&nbsp;<label for="show_link-1">'.__('Yes', 'wp-stats').'</label>&nbsp;&nbsp;&nbsp;<input type="radio" id="show_link-0" name="show_link" value="0"';
204         checked(0, intval($options['show_link']));       
205         echo ' />&nbsp;<label for="show_link-0">'.__('No', 'wp-stats').'</label></p>'."\n";
206         echo '<input type="hidden" id="stats-submit" name="stats-submit" value="1" />'."\n";
207     }
208
209     // Register Widgets
210     register_sidebar_widget('WP-Stats', 'widget_stats');
211     register_widget_control('WP-Stats', 'widget_stats_options', 400, 550);
212 }
213
214
215 ### Function: Load The WP-Stats Widget
216 add_action('plugins_loaded', 'widget_stats_init');
217 ?>
Note: See TracBrowser for help on using the browser.