| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: WP-SlimStat-Ex |
|---|
| 4 | Plugin URI: http://082net.com/tag/wp-slimstat-ex/ |
|---|
| 5 | Description: Track your blog stats. Based on <a href="http://www.duechiacchiere.it/">Mr. Coolmann</a>'s <a href="http://www.duechiacchiere.it/wp-slimstat/">Wp-SlimStat</a>. |
|---|
| 6 | Version: 1.604 |
|---|
| 7 | Author: Cheon, Young-Min |
|---|
| 8 | Author URI: http://082net.com/ |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | /* |
|---|
| 12 | ABOUT MODIFICATION :: |
|---|
| 13 | Almost php and sql codes has written by Mr. Coolmann(http://www.duechiacchiere.it) |
|---|
| 14 | What I've done is intergrating Ajax, constructing Pins(plugable panel) condition and some little patches. |
|---|
| 15 | Thanks, Coolmann. |
|---|
| 16 | |
|---|
| 17 | License :: |
|---|
| 18 | /* |
|---|
| 19 | This program is free software; you can redistribute it and/or |
|---|
| 20 | modify it under the terms of the GNU General Public License |
|---|
| 21 | as published by the Free Software Foundation; either version 2 |
|---|
| 22 | of the License, or (at your option) any later version. |
|---|
| 23 | |
|---|
| 24 | This program is distributed in the hope that it will be useful, |
|---|
| 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 27 | GNU General Public License for more details. |
|---|
| 28 | |
|---|
| 29 | http://www.gnu.org/licenses/gpl.txt |
|---|
| 30 | |
|---|
| 31 | You should have received a copy of the GNU General Public License |
|---|
| 32 | along with this program; if not, write to the Free Software |
|---|
| 33 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 34 | ______________________________________________________________*/ |
|---|
| 35 | |
|---|
| 36 | /* |
|---|
| 37 | Authors(others) :: |
|---|
| 38 | MooTools(and moo.fx) :: http://mootools.net by Mad4Milk (http://mad4milk.net/). |
|---|
| 39 | icons :: Mark James(http://www.famfamfam.com/) |
|---|
| 40 | Ajax.History :: Siegfried Puchbauer <rails-spinoffs@lists.rubyonrails.org> |
|---|
| 41 | SweetTitles :: Dustin Diaz (http://www.dustindiaz.com) |
|---|
| 42 | IP-Lookup is powered by http://ip-lookup.net/ |
|---|
| 43 | */ |
|---|
| 44 | |
|---|
| 45 | // Protect the script from direct access |
|---|
| 46 | if ( !defined('ABSPATH') ) { |
|---|
| 47 | header("Location: /"); |
|---|
| 48 | exit(); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | if(!function_exists('is_admin')) : // is_admin() included since v1.5.1 |
|---|
| 52 | function is_admin(){ |
|---|
| 53 | return (strstr($_SERVER['PHP_SELF'], 'wp-admin/') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/')); |
|---|
| 54 | } |
|---|
| 55 | endif; |
|---|
| 56 | |
|---|
| 57 | define('SLIMSTATPATH', realpath( dirname( __FILE__ ) ) . '/'); |
|---|
| 58 | define('wp_slimstat_ex', 'wp_slimstat_ex'); // for old Pins |
|---|
| 59 | |
|---|
| 60 | // include SlimStat config file |
|---|
| 61 | include(SLIMSTATPATH . 'wp-slimstat-ex-config.php'); |
|---|
| 62 | |
|---|
| 63 | // Always includes streams.php and gettext.php |
|---|
| 64 | if ( $SlimCfg->wp_version() < '2.1' && !defined('WPCTPATH') && !class_exists('gettext_reader') ) { |
|---|
| 65 | include_once(ABSPATH . WPINC . '/streams.php'); |
|---|
| 66 | include_once(ABSPATH . WPINC . '/gettext.php'); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | // localize plugin |
|---|
| 70 | load_plugin_textdomain('wp-slimstat-ex', 'wp-content/plugins/'.$SlimCfg->basedir.'/lang'); |
|---|
| 71 | |
|---|
| 72 | class wp_slimstat_ex { |
|---|
| 73 | |
|---|
| 74 | function admin_head() { |
|---|
| 75 | global $SlimCfg; |
|---|
| 76 | if(wp_slimstat_ex::is_slimstat_page()) { |
|---|
| 77 | $load_css = '<link rel="stylesheet" type="text/css" media="screen" href="'.$SlimCfg->pluginURL.'/css/slimstat.css?ver='.$SlimCfg->version.'" />'; |
|---|
| 78 | $load_css .= ($SlimCfg->option['nice_titles'])?"\n".'<link rel="stylesheet" type="text/css" media="screen" href="'.$SlimCfg->pluginURL.'/css/sweetTitles.css?ver='.$SlimCfg->version.'" />':''; |
|---|
| 79 | echo "\n".'<!-- Added by Wp-SlimStat-Ex '.$SlimCfg->version.' -->'."\n".$load_css."\n"; |
|---|
| 80 | if(!function_exists('wp_print_scripts')) |
|---|
| 81 | wp_slimstat_ex::admin_js(); |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | function admin_js() { |
|---|
| 86 | global $SlimCfg; |
|---|
| 87 | $before = '<script type="text/javascript" src="'.$SlimCfg->pluginURL.'/js/'; |
|---|
| 88 | $after = '"></script>'."\n"; |
|---|
| 89 | $load_js = ''; |
|---|
| 90 | $load_js .= $before.'prototype.js?ver=1.6.0_rc0'.$after; |
|---|
| 91 | $load_js .= $before.'moo.fx.base.js?ver=2.0'.$after; |
|---|
| 92 | $load_js .= $before.'ajax.history.js?ver='.$SlimCfg->version.$after; |
|---|
| 93 | $load_js .= $before.'ajax-slimstat-proto.js?ver='.$SlimCfg->version.$after; |
|---|
| 94 | if($SlimCfg->option['nice_titles']) { |
|---|
| 95 | $load_js .= $before.'addEvent.js?ver='.$SlimCfg->version.$after; |
|---|
| 96 | $load_js .= $before.'sweetTitles?ver='.$SlimCfg->version.$after; |
|---|
| 97 | } |
|---|
| 98 | echo $load_js; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | function enqueue_script_admin() { |
|---|
| 102 | global $SlimCfg; |
|---|
| 103 | $src_path = $SlimCfg->pluginURL.'/js/'; |
|---|
| 104 | $SlimCfg->base_jslib = 'prototype'; |
|---|
| 105 | if($SlimCfg->base_jslib == 'prototype') { |
|---|
| 106 | wp_register_script('moo.fx.base', $src_path.'moo.fx.base.js', array('prototype'), '2.0'); |
|---|
| 107 | wp_register_script('ajax.history', $src_path.'ajax.history.js', array('prototype'), $SlimCfg->version); |
|---|
| 108 | wp_enqueue_script('ajax-slimstat-proto', $src_path.'ajax-slimstat-proto.js', array('prototype', 'moo.fx.base','ajax.history'), $SlimCfg->version); |
|---|
| 109 | } else { |
|---|
| 110 | wp_register_script('mootools-Base', $src_path.'mootools/Base.js', false, '1.11'); |
|---|
| 111 | wp_register_script('mootools-Effects', $src_path.'mootools/Effects.js', array('mootools-Base'), '1.11'); |
|---|
| 112 | wp_register_script('mootools-Remote', $src_path.'mootools/Remote.js', array('mootools-Base'), '1.11'); |
|---|
| 113 | wp_register_script('mootools-Plugins-Remote', $src_path.'mootools/Plugins-Remote.js', array('mootools-Remote'), '1.11'); |
|---|
| 114 | wp_register_script('ajax.history.mootools', $src_path.'ajax.history.mootools.js', array('mootools-Base', 'mootools-Remote'), $SlimCfg->version); |
|---|
| 115 | wp_enqueue_script('ajax-slimstat-proto', $src_path.'ajax-slimstat-moo.js', array('mootools-Base', 'mootools-Effects','mootools-Remote', 'mootools-Plugins-Remote', 'ajax.history.mootools'), $SlimCfg->version); |
|---|
| 116 | } |
|---|
| 117 | if($SlimCfg->option['nice_titles']) { |
|---|
| 118 | wp_register_script('addEvent', $src_path.'addEvent.js', false, $SlimCfg->version); |
|---|
| 119 | wp_enqueue_script('sweetTitles', $src_path.'sweetTitles.js', array('addEvent'), $SlimCfg->version); |
|---|
| 120 | } |
|---|
| 121 | // wp_enqueue_script('minmax', $src_path.'minmax.js', false, $SlimCfg->version); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | function admin_footer() { |
|---|
| 125 | global $SlimCfg; |
|---|
| 126 | ?> |
|---|
| 127 | <script type="text/javascript">//<![CDATA[ |
|---|
| 128 | var current_hash_string = window.location.href.split('#'); |
|---|
| 129 | // use Ajax.History for ajax history |
|---|
| 130 | var historyHandler = Ajax.History.initialize({ |
|---|
| 131 | callback: function(hash){SlimStat.ajax(hash);}, |
|---|
| 132 | iframeSrc: "<?php echo $SlimCfg->pluginURL; ?>/js/_blank.html" |
|---|
| 133 | }); |
|---|
| 134 | if(current_hash_string[1] && current_hash_string[1] != '') |
|---|
| 135 | var SlimStatLoader = SlimStat.ajax(current_hash_string[1]); |
|---|
| 136 | else |
|---|
| 137 | var SlimStatLoader = SlimStat.panel('1'); |
|---|
| 138 | //]]></script> |
|---|
| 139 | <?php |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | function admin_notice() { |
|---|
| 143 | global $SlimCfg; |
|---|
| 144 | $ver = $SlimCfg->wp_version(); |
|---|
| 145 | if($ver < '2.0.2') { |
|---|
| 146 | add_action('admin_footer', array('wp_slimstat_ex', '__notice')); |
|---|
| 147 | } else { |
|---|
| 148 | add_action('admin_notices', array('wp_slimstat_ex', '_notice')); |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | function _notice() { |
|---|
| 153 | global $SlimCfg; |
|---|
| 154 | $slimstat_admin_url = get_option('siteurl') . '/wp-content/plugins/' . $SlimCfg->basedir . '/lib/ss-admin/upgrade.php'; |
|---|
| 155 | echo "<div id='wpssex_notice' class='updated fade'><p>".sprintf(__('WP-SlimStat-Ex needs <a href=\'%s\'>upgrade</a>', 'wp-slimstat-ex'), $slimstat_admin_url)."</p></div>"; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | function __notice() { |
|---|
| 159 | global $SlimCfg; |
|---|
| 160 | $slimstat_admin_url = get_option('siteurl') . '/wp-content/plugins/' . $SlimCfg->basedir . '/lib/ss-admin/upgrade.php'; |
|---|
| 161 | ?> |
|---|
| 162 | <script type="text/javascript">//<![CDATA[ |
|---|
| 163 | if(!div_wraper_082net) { |
|---|
| 164 | var div_wrapers_082net = document.getElementsByTagName('DIV'); |
|---|
| 165 | if(div_wrapers_082net) { |
|---|
| 166 | for(var i=0; i<div_wrapers_082net.length; i++) { |
|---|
| 167 | if(/wrap/.exec(div_wrapers_082net[i].className)) { |
|---|
| 168 | var div_wraper_082net = div_wrapers_082net[i]; |
|---|
| 169 | break; |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | if(div_wraper_082net) { |
|---|
| 175 | var wpssex_notice = document.createElement("DIV"); |
|---|
| 176 | wpssex_notice.innerHTML = "<p><?php printf(__('WP-SlimStat-Ex needs <a href=\'%s\'>upgrade</a>', 'wp-slimstat-ex'), $slimstat_admin_url); ?></p>"; |
|---|
| 177 | wpssex_notice.className = 'updated fade'; |
|---|
| 178 | wpssex_notice.id = 'wpssex_notice'; |
|---|
| 179 | div_wraper_082net.parentNode.insertBefore(wpssex_notice, div_wraper_082net); |
|---|
| 180 | Fat.fade_element('wpssex_notice'); |
|---|
| 181 | } |
|---|
| 182 | //]]></script> |
|---|
| 183 | <?php |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | function option_page() { |
|---|
| 187 | if (function_exists('add_options_page')) { |
|---|
| 188 | require_once(SLIMSTATPATH.'wp-slimstat-ex-options.php'); |
|---|
| 189 | $wp_slimstat_ex_options =& wp_slimstat_ex_options::get_instance(); |
|---|
| 190 | add_options_page("SlimStat", "SlimStat", 'manage_options', 'wp-slimstat-ex-options', array(&$wp_slimstat_ex_options, 'options_page')); |
|---|
| 191 | } |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | function is_slimstat_page () { |
|---|
| 195 | return ( (strstr($_SERVER['PHP_SELF'], 'wp-admin/') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/')) |
|---|
| 196 | && 'wp-slimstat-ex' == trim($_GET['page']) ); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | function set_options() { |
|---|
| 200 | global $SlimCfg; |
|---|
| 201 | // set options if not exists |
|---|
| 202 | if(!get_option('wp_slimstat_ex')) { |
|---|
| 203 | $options['tracking'] = 1; |
|---|
| 204 | $options['usepins'] = 1; |
|---|
| 205 | $options['cachelimit'] = 0; |
|---|
| 206 | $options['guesstitle'] = 1; |
|---|
| 207 | $options['dbmaxage'] = 0; |
|---|
| 208 | $options['limitrows'] = 20; |
|---|
| 209 | $options['iptohost'] = 0; |
|---|
| 210 | $options['whois'] = 1; |
|---|
| 211 | $options['meta'] = 0; |
|---|
| 212 | $options['visit_type'] = 'uniques'; |
|---|
| 213 | $options['count_type'] = 'hits'; |
|---|
| 214 | $options['stats_type'] = 'all'; |
|---|
| 215 | $options['time_offset'] = 0; |
|---|
| 216 | $options['use_ajax'] = 1; |
|---|
| 217 | $options['nice_titles'] = 1; |
|---|
| 218 | $options['ignore_bots'] = 0; |
|---|
| 219 | $SlimCfg->option = $options; |
|---|
| 220 | update_option('wp_slimstat_ex', $options); |
|---|
| 221 | } |
|---|
| 222 | // set exclude options |
|---|
| 223 | if(!get_option('wp_slimstat_ex_exclude')) { |
|---|
| 224 | $exclude['ignore_bots'] = 0; |
|---|
| 225 | $exclude['ig_bots'] = 0; |
|---|
| 226 | $exclude['ig_feeds'] = 0; |
|---|
| 227 | $exclude['ig_validators'] = 0; |
|---|
| 228 | $exclude['ig_tools'] = 0; |
|---|
| 229 | $exclude['black_ua'] = ''; |
|---|
| 230 | $exclude['white_ua'] = ''; |
|---|
| 231 | $exclude['ignore_ip'] = ''; |
|---|
| 232 | $SlimCfg->exclude = $exclude; |
|---|
| 233 | update_option('wp_slimstat_ex_exclude', $exclude); |
|---|
| 234 | } |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | function setup() { |
|---|
| 238 | require(SLIMSTATPATH . 'lib/setup.php'); |
|---|
| 239 | SSSetup::do_setup(); |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | function check_current_version() { |
|---|
| 243 | global $SlimCfg; |
|---|
| 244 | // if first install ? |
|---|
| 245 | if(strpos($_SERVER['PHP_SELF'], 'wp-admin/plugins.php') !== false && $_GET['action'] == 'activate' && $_GET['plugin'] == $SlimCfg->_basename(__FILE__) ) |
|---|
| 246 | return true; |
|---|
| 247 | $current = get_option('wp_slimstat_ex_version'); |
|---|
| 248 | if(!$current || $current == '0.1') { |
|---|
| 249 | require_once(SLIMSTATPATH . 'lib/ss-admin/_functions.php'); |
|---|
| 250 | if(!isset($ssAdmin)) |
|---|
| 251 | $ssAdmin =& SSAdmin::get_instance(); |
|---|
| 252 | $is_15 = $ssAdmin->maybe_add_column($SlimCfg->table_pins, 'type', '', true); |
|---|
| 253 | if(!$is_15) { |
|---|
| 254 | update_option('wp_slimstat_ex_version', '0.1'); |
|---|
| 255 | return false; |
|---|
| 256 | } |
|---|
| 257 | $is_16 = isset($SlimCfg->indexkey['common']['dt']) && isset($SlimCfg->indexkey['common']['remote_ip']); |
|---|
| 258 | if(!$is_16) { |
|---|
| 259 | update_option('wp_slimstat_ex_version', '1.5'); |
|---|
| 260 | return false; |
|---|
| 261 | } |
|---|
| 262 | update_option('wp_slimstat_ex_version', '1.6'); |
|---|
| 263 | } |
|---|
| 264 | $current = get_option('wp_slimstat_ex_version'); |
|---|
| 265 | if($current < $SlimCfg->last_db_update_version) |
|---|
| 266 | return false; |
|---|
| 267 | update_option('wp_slimstat_ex_version', $SlimCfg->version); |
|---|
| 268 | return true; |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | } |
|---|
| 272 | // end of class wp_slimstat_ex |
|---|
| 273 | |
|---|
| 274 | /* Check Options */ |
|---|
| 275 | if(!$SlimCfg->option || !$SlimCfg->exclude) { |
|---|
| 276 | wp_slimstat_ex::set_options(); |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | /* Setup, Option Page, Load CSS & Javascripts |
|---|
| 280 | -------------------------------------------*/ |
|---|
| 281 | // setup WP-SlimStat-Ex |
|---|
| 282 | if($SlimCfg->wp_version() < '2' && !defined('WPCTPATH')) { |
|---|
| 283 | if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/plugins.php') && isset($_GET['activate']) && $_GET['activate'] == 'true' ) |
|---|
| 284 | add_action('init', array('wp_slimstat_ex', 'setup')); |
|---|
| 285 | } |
|---|
| 286 | add_action('activate_'.$SlimCfg->_basename(__FILE__), array('wp_slimstat_ex', 'setup')); |
|---|
| 287 | |
|---|
| 288 | // load css and js on admin panel |
|---|
| 289 | add_action('admin_head', array('wp_slimstat_ex', 'admin_head'), 20); |
|---|
| 290 | |
|---|
| 291 | if (wp_slimstat_ex::is_slimstat_page() && $SlimCfg->option['use_ajax']) { |
|---|
| 292 | add_action('admin_footer', array('wp_slimstat_ex', 'admin_footer')); |
|---|
| 293 | add_action('wp_print_scripts', array('wp_slimstat_ex', 'enqueue_script_admin')); |
|---|
| 294 | } |
|---|
| 295 | // option page |
|---|
| 296 | add_action('admin_menu', array('wp_slimstat_ex', 'option_page')); |
|---|
| 297 | |
|---|
| 298 | /* Upgrade from previous version */ |
|---|
| 299 | if(!wp_slimstat_ex::check_current_version()) { |
|---|
| 300 | //if($SlimCfg->version > get_option('wp_slimstat_ex_version')) { |
|---|
| 301 | $SlimCfg->option['tracking'] = 0; |
|---|
| 302 | wp_slimstat_ex::admin_notice(); |
|---|
| 303 | return; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | /* Include functions |
|---|
| 307 | -------------------------------------------*/ |
|---|
| 308 | require_once(SLIMSTATPATH . 'lib/functions.php'); |
|---|
| 309 | // include Pin functions |
|---|
| 310 | if ($SlimCfg->option['usepins']) { |
|---|
| 311 | require(SLIMSTATPATH . 'lib/pins.php'); |
|---|
| 312 | // SSPins::_incPins(4);// include functionable pins |
|---|
| 313 | $current_pins = SSPins::_getPins(1, 4); |
|---|
| 314 | if(!empty($current_pins)) { |
|---|
| 315 | foreach($current_pins as $current_pin) { |
|---|
| 316 | $current_pin_file = SLIMSTATPATH . 'pins/'. $current_pin->name . '/pin.php'; |
|---|
| 317 | if('' != $current_pin->name && file_exists($current_pin_file)) |
|---|
| 318 | include_once($current_pin_file); |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | /* Stats Display |
|---|
| 324 | -------------------------------------------*/ |
|---|
| 325 | if(strstr($_SERVER['PHP_SELF'], 'wp-admin/') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/')) { // 1.5.x fix |
|---|
| 326 | require_once(SLIMSTATPATH . 'lib/display.php'); |
|---|
| 327 | add_action('admin_menu', array('SSDisplay','add_tab')); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | /* Track visitors |
|---|
| 331 | -------------------------------------------*/ |
|---|
| 332 | require_once(SLIMSTATPATH . 'lib/track.php'); |
|---|
| 333 | add_action( 'shutdown', array( &$SSTrack, 'slimtrack' ) ); |
|---|
| 334 | |
|---|
| 335 | ?> |
|---|