source: extensions/whois_online/include/wo_functions.inc.php @ 6386

Last change on this file since 6386 was 6386, checked in by vdigital, 14 years ago

Cosmetic review for the clear admin theme and more

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1<?php
2/* Functions */
3
4/* Secure Config */
5if (!isset($conf['Whois Online']) or !isset($conf_whois['Active'])) $conf_whois = whois_online_conf();
6
7if (defined('IN_ADMIN') and IN_ADMIN) include_once(WHOIS_ONLINE_PATH.'include/wo_admin_functions.inc.php');
8
9function whois_online_conf()
10{
11        global $conf;
12        $default = array(
13          'Active' => true,
14          'Delete level' => 20,
15          'Radar limit' => 25,
16          'Webmasters' => 2, // Normal
17          'Administrators' => 2,
18          'Obsolete limit' => 20,
19                'Default display' => true,
20          'Add to Plugins menu' => false,
21          'Add icon to History' => true,
22          'Keep data' => true,
23          'Search id' => 0,
24          'Users' => Array('max' => 0, 'When' => date('Y-m-d'), 'count' => 0),
25        );
26        if (!isset($conf['Whois Online'])) $conf['Whois Online'] = serialize(Array());
27        $conf_whois = array_merge($default, unserialize($conf['Whois Online']));
28        if ((!isset($conf_whois['Version'])) or $conf_whois['Version'] != WHOIS_ONLINE_VER
29                or $conf['Whois Online'] != serialize($conf_whois)) {
30                $conf_whois['Version'] = WHOIS_ONLINE_VER;
31                $conf['Whois Online'] = serialize($conf_whois);
32                pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)
33          VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");
34        }
35        return $conf_whois;
36}
37
38// Assume the Default display on pages
39function whois_default_display() {
40        global $template;
41        $template->set_filenames(array( 'Whois_display' => dirname(__FILE__).'/../default.tpl'));
42        $template->pparse('Whois_display');
43}
44
45// New member
46function whois_online_register($who) {
47        global $conf, $conf_whois;
48        $conf_whois['Users']['count'] = $who['id'];
49        $conf['Whois Online'] = serialize($conf_whois);
50        pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)
51  VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");
52        return;
53}
54
55// Read all data
56function whois_online_get_data($order='') {
57        $remove = "''"; // Nothing to remove ( = an empty session_id)
58        $ctr = 0; $Online[0] = '';
59        $result = pwg_query('SELECT * FROM ' . WHOIS_ONLINE_TABLE . $order . ';');
60        while($row=mysql_fetch_array($result)) {
61                $row['delay'] = (int) time() - $row['last_access'];
62                $row['elm_ids'] = explode(' ', $row['last_elm_ids']);
63                $row['cat_ids'] = explode(' ', $row['last_cat_ids']);
64                $row['tag_ids'] = explode(' ', $row['last_tag_ids']);
65                $row['sch_ids'] = explode(' ', $row['last_sch_ids']);
66                $row['dates'] = explode(' ', $row['last_dates']);
67                $ctr++;
68                if ( $row['IP'] != 'global' and $row['permanent'] == 'false'
69                        and $row['delay'] > (float)( 60 * 60 * 24 * 3 )) $remove .= ", '" . $row['session_id'] . "'";
70                elseif ($row['IP'] == 'global') $Online[0] = $row;
71                else $Online[] = $row;
72        }
73        // Out of 7 visits: Reduce registered visits for 3 days without access
74        if ($remove != "''" and $ctr > (count($Online) * ONLINE_LEVEL)
75                and ($ctr-count($Online)) > ONLINE_LIMIT and ($Online[0]['pag_hits']%7)==0) {
76                pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE . ' WHERE `session_id` IN ('. $remove .')
77                                AND `permanent` = \'false\' AND `IP` <> \'global\';');
78                if (($Online[0]['pag_hits']%13)==0) @pwg_query('OPTIMIZE TABLE ' . WHOIS_ONLINE_TABLE . ';');
79        }
80        return $Online;
81}
82
83// Update global and update/create current session_id
84function whois_online_update(&$global, &$dedicated, &$gtrace)
85{
86        global $user;
87        // Rewrite the global record
88        if ( $gtrace == 2 ) {
89                $query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`,
90                `permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`,
91                `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`)
92                        VALUES (\'global\', \'true\',\'global\', 0, \''. $global['username'] .'\', \'--\', \'true\', \''
93                        . time()  .'\',  \''
94                        . implode(' ',$global['elm_ids']) . '\', \''
95                        . implode(' ',$global['cat_ids']) . '\', \''
96                        . implode(' ',$global['tag_ids']) . '\', \''
97                        . implode(' ',$global['sch_ids']) . '\', \''
98                        . $global['first_access_date'] . '\', \'\', \''
99                        . $global['elm_hits'] . '\', \'' . $global['pag_hits'] . '\');';
100                pwg_query($query);
101        }
102        // Write or Rewrite the dedicated record
103        $query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`, `user_agent`,
104        `any_previous`, `same_previous`, `permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`,
105        `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`)
106                VALUES (\''. $dedicated['IP'] .'\', \''
107                . $dedicated['hidden_IP'] .'\', \''. $dedicated['session_id'] .'\', \''
108                . $dedicated['user_id'] .'\', \''. $dedicated['username'] .'\', \''
109                . $user['language'] .'\', \''
110                . $dedicated['user_agent'] .'\', \''
111                . $dedicated['any_previous'] .'\', \''
112                . $dedicated['same_previous'] .'\', \''
113                . $dedicated['permanent'] . '\', \''. time() .'\',  \''
114                . implode(' ',$dedicated['elm_ids']) . '\', \''
115                . implode(' ',$dedicated['cat_ids']) . '\', \''
116                . implode(' ',$dedicated['tag_ids']) . '\', \''
117                . implode(' ',$dedicated['sch_ids']) . '\', \''
118                . $dedicated['first_access_date'] . '\', \''
119                . implode(' ',$dedicated['dates']) . '\', \''
120                . $dedicated['elm_hits'] . '\', \''
121                . $dedicated['pag_hits'] . '\');';
122        pwg_query($query);
123}
124
125// Data tracking
126// Parameters:
127//  - Array of Ids
128//  - New ID
129//  - Array of dates
130// => Add the ID if needed, Add Today if needed
131function whois_online_track(&$key, $id, &$date) {
132        if ($id != '') array_unshift($key, $id);
133        $key = array_unique($key);
134        if (count($key)>10) array_pop($key);
135        array_unshift($date, date('Y-m-d'));
136        $date = array_unique($date);
137        if (count($date)>5) array_pop($date);
138        return;
139}
140
141// Antiaspi delay conversion in seconds
142// delay in "HH:ii:ss" or "d :HH:ii:ss"
143// return delay in seconds
144function whois_online_duration($date_string)
145{
146 list($s, $i, $H, $d, $more) = 
147   array_merge(array_reverse(
148           explode(" ",str_ireplace(':',' ', $date_string))),
149                 array(0,0,0,0,0));
150 $t = time();
151 return strtotime(sprintf("+%s days %s hours %s minutes %s seconds", 
152   $d, $H, $i, $s), $t) - $t;
153}
154
155// Add admin links
156function whois_add_icon($menu) {
157        global $conf_whois, $template;
158        $url = get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php');
159        $lnk = ' <a class="external" style="display:inline;" href="' . $url . '">'
160                . '<img class="button" src="' . WHOIS_ONLINE_PATH . 'icons/Whois_tuner.png" '
161                . ' alt="Whois Online configuration" title="Whois Online configuration" /></a>';
162        if (isset($_GET['page']) and ($_GET['page'] == 'stats' or $_GET['page'] == 'history'))
163                $h2 = $lnk;
164        else $h2 = ''; 
165        if ($conf_whois['Add icon to History']) {
166                $template->append('footer_elements', '<!-- Whois Icon -->
167<script type="text/javascript">
168jQuery(document).ready(function() {
169        jQuery("#menubar li a[href*=\'admin.php?page=stats\']").after(\'' . $lnk . '\').css("display","inline");
170        jQuery(".tabsheet li a[href*=\'admin.php?page=configuration&section=history\']").next().remove();
171        jQuery("#content .titrePage h2").append(\'' . $h2 . '\');
172 
173        });
174</script>' );
175        }
176        if ($conf_whois['Add to Plugins menu']) array_push($menu, array(
177                                'NAME' => 'Whois Online',
178                                'URL' => $url,
179                        ));
180        return $menu;
181}
182
183?>
Note: See TracBrowser for help on using the repository browser.