1: <?php
2: 3: 4: 5: 6:
7:
8:
9: if (!defined('OFFSET_PATH')) {
10: define('OFFSET_PATH', 3);
11: require_once(dirname(dirname(__FILE__)) . '/admin-functions.php');
12: if (isset($_GET['action'])) {
13: if (sanitize($_GET['action']) == 'reset_all_hitcounters') {
14: if (!zp_loggedin(ADMIN_RIGHTS)) {
15:
16: header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin.php?from=' . currentRelativeURL());
17: exitZP();
18: }
19: zp_session_start();
20: XSRFdefender('hitcounter');
21: query('UPDATE ' . prefix('albums') . ' SET `hitcounter`= 0');
22: query('UPDATE ' . prefix('images') . ' SET `hitcounter`= 0');
23: query('UPDATE ' . prefix('news') . ' SET `hitcounter`= 0');
24: query('UPDATE ' . prefix('pages') . ' SET `hitcounter`= 0');
25: query('UPDATE ' . prefix('news_categories') . ' SET `hitcounter`= 0');
26: query('DELETE FROM ' . prefix('options') . ' WHERE `name` LIKE "Page-Hitcounter-%"');
27: query("DELETE FROM " . prefix('plugin_storage') . " WHERE `type` = 'rsshitcounter'");
28: header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin.php?action=external&msg=' . gettext('All hitcounters have been set to zero.'));
29: exitZP();
30: }
31: }
32: }
33:
34: $plugin_is_filter = 5 | ADMIN_PLUGIN | FEATURE_PLUGIN;
35: $plugin_description = gettext('Automatically increments hitcounters on Zenphoto objects viewed by a <em>visitor</em>.');
36: $plugin_author = "Stephen Billard (sbillard)";
37:
38: $option_interface = 'hitcounter';
39:
40: zp_register_filter('load_theme_script', 'hitcounter::load_script');
41: zp_register_filter('admin_utilities_buttons', 'hitcounter::button');
42:
43: 44: 45: 46:
47: class hitcounter {
48:
49: var $defaultbots = 'Teoma, alexa, froogle, Gigabot,inktomi, looksmart, URL_Spider_SQL, Firefly, NationalDirectory, Ask Jeeves, TECNOSEEK, InfoSeek, WebFindBot, girafabot, crawler, www.galaxy.com, Googlebot, Scooter, Slurp, msnbot, appie, FAST, WebBug, Spade, ZyBorg, rabaz ,Baiduspider, Feedfetcher-Google, TechnoratiSnoop, Rankivabot, Mediapartners-Google, Sogou web spider, WebAlta Crawler';
50:
51: function __construct() {
52: setOptionDefault('hitcounter_ignoreIPList_enable', 0);
53: setOptionDefault('hitcounter_ignoreSearchCrawlers_enable', 0);
54: setOptionDefault('hitcounter_ignoreIPList', '');
55: setOptionDefault('hitcounter_searchCrawlerList', $this->defaultbots);
56: }
57:
58: function getOptionsSupported() {
59: return array(gettext('IP Address list') => array(
60: 'order' => 1,
61: 'key' => 'hitcounter_ignoreIPList',
62: 'type' => OPTION_TYPE_CUSTOM,
63: 'desc' => gettext('Comma-separated list of IP addresses to ignore.'),
64: ),
65: gettext('Filter') => array(
66: 'order' => 0,
67: 'key' => 'hitcounter_ignore',
68: 'type' => OPTION_TYPE_CHECKBOX_ARRAY,
69: 'checkboxes' => array(gettext('IP addresses') => 'hitcounter_ignoreIPList_enable', gettext('Search Crawlers') => 'hitcounter_ignoreSearchCrawlers_enable'),
70: 'desc' => gettext('Check to enable. If a filter is enabled, viewers from in its associated list will not count hits.'),
71: ),
72: gettext('Search Crawler list') => array(
73: 'order' => 2,
74: 'key' => 'hitcounter_searchCrawlerList',
75: 'type' => OPTION_TYPE_TEXTAREA,
76: 'multilingual' => false,
77: 'desc' => gettext('Comma-separated list of search bot user agent names.'),
78: ),
79: ' ' => array(
80: 'order' => 3,
81: 'key' => 'hitcounter_set_defaults',
82: 'type' => OPTION_TYPE_CUSTOM,
83: 'desc' => gettext('Reset options to their default settings.')
84: )
85: );
86: }
87:
88: function handleOption($option, $currentValue) {
89: switch ($option) {
90: case 'hitcounter_set_defaults':
91: ?>
92: <script type="text/javascript">
93:
94: var reset = "<?php echo $this->defaultbots; ?>";
95: function hitcounter_defaults() {
96: $('#hitcounter_ignoreIPList').val('');
97: $('#hitcounter_ip_button').removeAttr('disabled');
98: $('#hitcounter_ignoreIPList_enable').prop('checked', false);
99: $('#hitcounter_ignoreSearchCrawlers_enable').prop('checked', false);
100:
101: $('#hitcounter_searchCrawlerList').val(reset);
102:
103:
104:
105: }
106:
107: </script>
108: <label><input id="hitcounter_reset_button" type="button" value="<?php echo gettext('Defaults'); ?>" onclick="hitcounter_defaults();" /></label>
109: <?php
110: break;
111: case 'hitcounter_ignoreIPList':
112: ?>
113: <input type="hidden" name="<?php echo CUSTOM_OPTION_PREFIX; ?>'text-hitcounter_ignoreIPList" value="0" />
114: <input type="text" size="30" id="hitcounter_ignoreIPList" name="hitcounter_ignoreIPList" value="<?php echo html_encode($currentValue); ?>" />
115: <script type="text/javascript">
116:
117: function hitcounter_insertIP() {
118: if ($('#hitcounter_ignoreIPList').val() == '') {
119: $('#hitcounter_ignoreIPList').val('<?php echo getUserIP(); ?>');
120: } else {
121: $('#hitcounter_ignoreIPList').val($('#hitcounter_ignoreIPList').val() + ',<?php echo getUserIP(); ?>');
122: }
123: $('#hitcounter_ip_button').attr('disabled', 'disabled');
124: }
125: jQuery(window).load(function() {
126: var current = $('#hitcounter_ignoreIPList').val();
127: if (current.indexOf('<?php echo getUserIP(); ?>') < 0) {
128: $('#hitcounter_ip_button').removeAttr('disabled');
129: }
130: });
131:
132: </script>
133: <label><input id="hitcounter_ip_button" type="button" value="<?php echo gettext('Insert my IP'); ?>" onclick="hitcounter_insertIP();" disabled="disabled" /></label>
134: <?php
135: break;
136: }
137: }
138:
139: 140: 141: 142: 143: 144: 145:
146: static function load_script($script, $valid) {
147: if ($script && $valid) {
148: if (getOption('hitcounter_ignoreIPList_enable')) {
149: $ignoreIPAddressList = explode(',', str_replace(' ', '', getOption('hitcounter_ignoreIPList')));
150: $skip = in_array(getUserIP(), $ignoreIPAddressList);
151: } else {
152: $skip = false;
153: }
154: if (getOption('hitcounter_ignoreSearchCrawlers_enable') && !$skip && array_key_exists('HTTP_USER_AGENT', $_SERVER) && ($agent = $_SERVER['HTTP_USER_AGENT'])) {
155: $botList = explode(',', getOption('hitcounter_searchCrawlerList'));
156: foreach ($botList as $bot) {
157: if (stripos($agent, trim($bot))) {
158: $skip = true;
159: break;
160: }
161: }
162: }
163:
164: if (!$skip) {
165: global $_zp_gallery_page, $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_news, $_zp_current_zenpage_page, $_zp_current_category;
166: if (checkAccess()) {
167:
168: switch ($_zp_gallery_page) {
169: case 'album.php':
170: if (!$_zp_current_album->isMyItem(ALBUM_RIGHTS) && getCurrentPage() == 1) {
171: $_zp_current_album->countHit();
172: }
173: break;
174: case 'image.php':
175: if (!$_zp_current_album->isMyItem(ALBUM_RIGHTS)) {
176:
177: $_zp_current_image->countHit();
178: }
179: break;
180: case 'pages.php':
181: if (class_exists('Zenpage') && !zp_loggedin(ZENPAGE_PAGES_RIGHTS)) {
182: $_zp_current_zenpage_page->countHit();
183: }
184: break;
185: case 'news.php':
186: if (class_exists('Zenpage') && !zp_loggedin(ZENPAGE_NEWS_RIGHTS)) {
187: if (is_NewsArticle()) {
188: $_zp_current_zenpage_news->countHit();
189: } else if (is_NewsCategory()) {
190: $_zp_current_category->countHit();
191: }
192: }
193: break;
194: default:
195: if (!zp_loggedin()) {
196: $page = stripSuffix($_zp_gallery_page);
197: setOption('Page-Hitcounter-' . $page, getOption('Page-Hitcounter-' . $page) + 1);
198: }
199: break;
200: }
201: }
202: }
203: }
204: return $script;
205: }
206:
207: static function button($buttons) {
208: $buttons[] = array(
209: 'XSRFTag' => 'hitcounter',
210: 'category' => gettext('Database'),
211: 'enable' => true,
212: 'button_text' => gettext('Reset all hitcounters'),
213: 'formname' => 'reset_all_hitcounters.php',
214: 'action' => PLUGIN_FOLDER . '/hitcounter.php?action=reset_all_hitcounters',
215: 'icon' => 'images/reset.png',
216: 'alt' => '',
217: 'title' => gettext('Reset all hitcounters to zero'),
218: 'hidden' => '<input type="hidden" name="action" value="reset_all_hitcounters" />',
219: 'rights' => ADMIN_RIGHTS
220: );
221: return $buttons;
222: }
223:
224: }
225:
226: 227: 228: 229: 230: 231:
232: function getHitcounter($obj = NULL) {
233: global $_zp_current_album, $_zp_current_image, $_zp_gallery_page, $_zp_current_zenpage_news, $_zp_current_zenpage_page, $_zp_current_category;
234: if (is_null($obj)) {
235: switch ($_zp_gallery_page) {
236: case 'album.php':
237: $obj = $_zp_current_album;
238: break;
239: case 'image.php':
240: $obj = $_zp_current_image;
241: break;
242: case 'pages.php':
243: $obj = $_zp_current_zenpage_page;
244: break;
245: case 'news.php':
246: if (in_context(ZP_ZENPAGE_NEWS_CATEGORY)) {
247: $obj = $_zp_current_category;
248: } else {
249: $obj = $_zp_current_zenpage_news;
250: if (is_null($obj))
251: return 0;
252: }
253: break;
254: case 'search.php':
255: return NULL;
256: default:
257: $page = stripSuffix($_zp_gallery_page);
258: return getOption('Page-Hitcounter-' . $page);
259: }
260: }
261: return $obj->getHitcounter();
262: }
263: ?>