| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: WP-PostViews Widget |
| 4 |
Plugin URI: http://lesterchan.net/portfolio/programming/php/ |
| 5 |
Description: Adds a PostViews Widget to display most viewed posts and/or pages on your sidebar. You will need to activate WP-PostViews first. |
| 6 |
Version: 1.40 |
| 7 |
Author: Lester 'GaMerZ' Chan |
| 8 |
Author URI: http://lesterchan.net |
| 9 |
*/ |
| 10 |
|
| 11 |
|
| 12 |
/* |
| 13 |
Copyright 2008 Lester Chan (email : lesterchan@gmail.com) |
| 14 |
|
| 15 |
This program is free software; you can redistribute it and/or modify |
| 16 |
it under the terms of the GNU General Public License as published by |
| 17 |
the Free Software Foundation; either version 2 of the License, or |
| 18 |
(at your option) any later version. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public License |
| 26 |
along with this program; if not, write to the Free Software |
| 27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 |
*/ |
| 29 |
|
| 30 |
|
| 31 |
### Function: Init WP-PostViews Widget |
| 32 |
function widget_views_init() { |
| 33 |
if (!function_exists('register_sidebar_widget')) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
### Function: WP-PostViews Most Viewed Widget |
| 38 |
function widget_views_most_viewed($args) { |
| 39 |
extract($args); |
| 40 |
$options = get_option('widget_views_most_viewed'); |
| 41 |
$title = htmlspecialchars(stripslashes($options['title'])); |
| 42 |
if (function_exists('get_most_viewed')) { |
| 43 |
echo $before_widget.$before_title.$title.$after_title; |
| 44 |
echo '<ul>'."\n"; |
| 45 |
get_most_viewed($options['mode'], $options['limit'], $options['chars']); |
| 46 |
echo '</ul>'."\n"; |
| 47 |
echo $after_widget; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
### Function: WP-PostViews Most Viewed Widget Options |
| 52 |
function widget_views_most_viewed_options() { |
| 53 |
$options = get_option('widget_views_most_viewed'); |
| 54 |
if (!is_array($options)) { |
| 55 |
$options = array('title' => __('Most Viewed', 'wp-postviews'), 'mode' => 'post', 'limit' => 10, 'chars' => 0); |
| 56 |
} |
| 57 |
if ($_POST['most_viewed-submit']) { |
| 58 |
$options['title'] = strip_tags($_POST['most_viewed-title']); |
| 59 |
$options['mode'] = strip_tags($_POST['most_viewed-mode']); |
| 60 |
$options['limit'] = intval($_POST['most_viewed-limit']); |
| 61 |
$options['chars'] = intval($_POST['most_viewed-chars']); |
| 62 |
update_option('widget_views_most_viewed', $options); |
| 63 |
} |
| 64 |
echo '<p><label for="most_viewed-title">'; |
| 65 |
_e('Title', 'wp-postviews'); |
| 66 |
echo ': </label><input type="text" id="most_viewed-title" name="most_viewed-title" value="'.htmlspecialchars(stripslashes($options['title'])).'" /></p>'."\n"; |
| 67 |
echo '<p><label for="most_viewed-mode">'; |
| 68 |
_e('Show Views For: ', 'wp-postviews'); |
| 69 |
echo ' </label>'."\n"; |
| 70 |
echo '<select id="most_viewed-mode" name="most_viewed-mode" size="1">'."\n"; |
| 71 |
echo '<option value="both"'; |
| 72 |
selected('both', $options['mode']); |
| 73 |
echo '>'; |
| 74 |
_e('Posts & Pages', 'wp-postviews'); |
| 75 |
echo '</option>'."\n"; |
| 76 |
echo '<option value="post"'; |
| 77 |
selected('post', $options['mode']); |
| 78 |
echo '>'; |
| 79 |
_e('Posts', 'wp-postviews'); |
| 80 |
echo '</option>'."\n"; |
| 81 |
echo '<option value="page"'; |
| 82 |
selected('page', $options['mode']); |
| 83 |
echo '>'; |
| 84 |
_e('Pages', 'wp-postviews'); |
| 85 |
echo '</option>'."\n"; |
| 86 |
echo '</select> '; |
| 87 |
_e('Only', 'wp-postviews'); |
| 88 |
echo '</p>'."\n"; |
| 89 |
echo '<p><label for="most_viewed-limit">'; |
| 90 |
_e('Limit', 'wp-postviews'); |
| 91 |
echo ': </label><input type="text" id="most_viewed-limit" name="most_viewed-limit" value="'.intval($options['limit']).'" size="3" /></p>'."\n"; |
| 92 |
echo '<p><label for="most_viewed-chars">'; |
| 93 |
_e('Post Title Length (Characters)', 'wp-postviews'); |
| 94 |
echo ': </label><input type="text" id="most_viewed-chars" name="most_viewed-chars" value="'.intval($options['chars']).'" size="5" /> '."\n"; |
| 95 |
_e('(<strong>0</strong> to disable)', 'wp-postviews'); |
| 96 |
echo '</p>'."\n"; |
| 97 |
echo '<input type="hidden" id="most_viewed-submit" name="most_viewed-submit" value="1" />'."\n"; |
| 98 |
} |
| 99 |
// Register Widgets |
| 100 |
register_sidebar_widget(array('Most Viewed', 'wp-postviews'), 'widget_views_most_viewed'); |
| 101 |
register_widget_control(array('Most Viewed', 'wp-postviews'), 'widget_views_most_viewed_options', 400, 200); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
### Function: Load The WP-PostViews Widget |
| 106 |
add_action('plugins_loaded', 'widget_views_init') |
| 107 |
?> |