root/wp-slimstat-ex/tags/1.3/wp-slimstat-ex-config.php

Revision 59, 4.0 KB (checked in by 082net, 2 years ago)

## wp-slimstat-ex ##
Added stats on blog option
Load css and js file only when it's needed
Added display available modules page to SlimStat? Admin
Fixed small bugs

Line 
1<?php
2
3class SlimCfg {
4        var $korean = true;
5        var $version = '1.3'; // Current SlimStat-Ex version
6        var $external_iptc = 'internal'; // set this 'external' to use external ip-to-country database
7        var $option;
8        var $table_stats;
9        var $table_countries;
10        var $table_feed;
11        var $table_dt;
12        var $table_pins;
13        var $pluginURL;
14        var $ajaxReq;
15        var $uaOption = false; // Personal use... please forget about this ;)
16
17        function SlimCfg() {
18                $this->_init();
19        }
20
21        function _init() {
22                global $table_prefix;
23                if (!defined('ABSPATH')) { // if external tracking
24                        global $slimtrack_ext;
25                        $table_prefix = $slimtrack_ext['table_prefix'];
26                } 
27                // We use a bunch of tables to store data
28                $this->table_stats = $table_prefix . "slimex_stats";    // common stats
29                $this->table_countries = $table_prefix . "slim_countries";      // ip-to-country
30                $this->table_feed = $table_prefix . "slimex_feed";       // feed stats
31                $this->table_dt = $table_prefix . "slimex_dt";   // compressed hit, vists, uniques
32                $this->table_pins = $table_prefix . "slimex_pins";      // Pin information
33                $this->base = dirname($this->_basename(__FILE__)) . '/wp-slimstat-ex.php';       //basename from plugins folder
34                $this->pluginURL =  get_settings('siteurl')."/wp-content/plugins/".dirname($this->_basename(__FILE__));  // Plugin URL(path)
35                $this->ajaxReq = $this->pluginURL."/lib/r";     // Ajax request URL
36                $this->web_path = $this->_getWebPath(); // wordpress intall folder related to site root
37                $this->option = get_settings('wp_slimstat_ex'); // SlimStat options
38                $this->get = $this->parse_GET(true, true, true);
39                $this->dt = array($this->_mktime(time()), $this->_mktime(time(), true));
40        }
41
42        function _basename($file) {
43                $file = preg_replace('|\\\\+|', '\\\\', $file);
44                $file = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', $file);
45                $file = str_replace('\\', '/', $file);
46                return $file;
47        }
48
49        function _getWebPath($url="home") {
50                $uris = parse_url(get_settings($url));
51                return $uris['path'];
52        }
53
54        function my_esc( $str = '' ) {
55                if( version_compare( phpversion(), '4.3.0', '>=' ) ) {
56                        return mysql_real_escape_string( $str );
57                } else {
58                        return mysql_escape_string( $str );
59                }
60        }
61        // end my_esc
62       
63        function select_table() {
64                $neededTable = ( $this->get['pn'] == 2 ) ? $this->table_feed : $this->table_stats;
65                return $neededTable;
66        }
67
68        function sstime($time, $back_to_server_time = false) {
69                $offset = ( intval($this->option['time_offset']) * 60 * 60 );
70                if ($offset !== 0) {
71                        $time = ($back_to_server_time)?($time - $offset):($time + $offset);
72                }
73                return $time;
74        }
75
76        function _mktime($time, $back_to_server_time = false) {
77                $dt = $this->sstime($time);
78                $new_dt = mktime( 0, 0, 0, date( "n", $dt ), date( "d", $dt ), date( "Y", $dt ) );
79                if($back_to_server_time)
80                        $new_dt = $this->sstime( $new_dt, true );
81                return $new_dt;
82        }
83
84        function parse_GET($filter_encode = false, $interval = true, $normal = true) {
85                $get = array();
86                $get['pn'] = (isset($_GET['panel']))?intval($_GET['panel']):1;
87                $f_interval = $_GET['fd'];
88                if( $normal && isset($_GET['fi']) && !empty($_GET['fi']) && intval($_GET['ff']) >= 0 ) {
89                        $get['ff'] = intval( $_GET['ff'] );
90                        $get['ft'] = intval( $_GET['ft'] );
91                        $get['fi'] = $_GET['fi'];
92                }
93                if ( $interval && !empty( $f_interval ) && strpos( $f_interval, "|" ) ) {
94                        $get['fd'] = array(0, 0);
95                        $interval = explode( "|", $f_interval, 2 );
96                        $interval[0] = intval($interval[0]);
97                        $interval[1] = intval($interval[1]);
98                        if( max( $interval ) > 0 && ($interval[1] > $interval[0]) ) {
99                                $get['fd'] = array( $interval[0], $interval[1] );
100                        }
101                }
102                //re-encode filter values
103                if($filter_encode) {
104                        $get['fi_encode'] = "";
105                        $get['fd_encode'] = "";
106                        if($normal && isset($get['fi'])) 
107                                $get['fi_encode'] = '&amp;ff='.$get['ff'].'&amp;ft='.$get['ft'].'&amp;fi='.$get['fi'];
108                        if ( $interval && isset($get['fd']) ) 
109                                $get['fd_encode'] = '&amp;fd='.$f_interval;
110                }
111                return $get;
112        }
113       
114        function &get_instance() {
115                static $instance = array();
116                if ( empty( $instance ) ) {
117                        $instance[] =& new SlimCfg();
118                }
119                return $instance[0];
120        }
121}
122
123$SlimCfg =& SlimCfg::get_instance();
124
125?>
Note: See TracBrowser for help on using the browser.