source: extensions/whois_online/maintain.inc.php @ 3319

Last change on this file since 3319 was 3319, checked in by vdigital, 15 years ago

+ Add Whois Online to depository

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1<?php
2
3global $prefixeTable, $conf;
4if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
5if (!defined('IN_ADMIN') or !IN_ADMIN) die('Hacking attempt!');
6if (!defined('WHOIS_ONLINE_TABLE')) define('WHOIS_ONLINE_TABLE', $prefixeTable.'whois_online');
7
8function plugin_activate()
9{
10        global $user;
11        $query = "CREATE TABLE IF NOT EXISTS ". WHOIS_ONLINE_TABLE ." (
12  `IP` varchar(39) NOT NULL default '',
13  `hidden_IP` enum('true','false') NOT NULL default 'false',
14  `session_id` varchar(40) NOT NULL,
15  `user_id` smallint(5) NOT NULL default '0',
16  `username` varchar(100) character set utf8 collate utf8_bin NOT NULL default '',
17  `lang` char(2) character set utf8 collate utf8_bin NOT NULL default 'en',
18  `country` VARCHAR( 256 ) NOT NULL default '',
19  `permanent` enum('true','false') NOT NULL default 'false',
20  `last_access` varchar(12) NOT NULL default '',
21  `last_elm_ids` varchar(75) NOT NULL default '',
22  `last_cat_ids` varchar(75) NOT NULL default '',
23  `last_tag_ids` varchar(75) NOT NULL default '',
24  `last_sch_ids` varchar(75) NOT NULL default '',
25  `first_access_date` varchar(45) NOT NULL default '',
26  `last_dates` varchar(110) character set utf8 collate utf8_bin NOT NULL default '',
27  `elm_hits` int(10) unsigned NOT NULL default '0',
28  `pag_hits` int(10) unsigned NOT NULL default '0',
29  `db_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
30  PRIMARY KEY  (`session_id`)
31) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
32";
33        $result = pwg_query($query);
34        if (isset($conf['Whois Online'])) {
35                $conf_whois = unserialize($conf['Whois Online']);
36                if (!isset($conf_whois['Active'])) $conf_whois['Active'] = true;
37                if (!isset($conf_whois['Delete level'])) $conf_whois['Delete level'] = 20;
38                if (!isset($conf_whois['Radar limit'])) $conf_whois['Radar limit'] = 25;
39                if (!isset($conf_whois['Webmasters'])) $conf_whois['Webmasters'] = 2;
40                if (!isset($conf_whois['Administrators'])) $conf_whois['Administrators'] = 2;
41                if (!isset($conf_whois['Obsolete limit'])) $conf_whois['Obsolete limit'] = 20;
42                if (!isset($conf_whois['Add to Plugins menu'])) $conf_whois['Add to Plugins menu'] = false;
43                if (!isset($conf_whois['Add icon to History'])) $conf_whois['Add icon to History'] = true;
44                if (!isset($conf_whois['Keep data'])) $conf_whois['Keep data'] = true;
45                if (!isset($conf_whois['Default display'])) $conf_whois['Default display'] = true;
46                if (!isset($conf_whois['Search id'])) $conf_whois['Search id'] = 0;
47                if (!isset($conf_whois['Users'])) 
48                        $conf_whois['Users'] = Array('max' => 0, 'When' => date('Y-m-d'), 'count' => 0);
49                $conf['Whois Online'] = serialize($conf_whois);
50        }
51        else {
52                $conf['Whois Online'] = serialize(Array(
53                        'Active' => true,
54                        'Delete level' => 20,
55                        'Radar limit' => 25,
56                        'Obsolete limit' => 20,
57                        'Webmasters' => 2,
58                        'Administrators' => 2,
59                        'Search id' => 0,
60                        'Users' => Array('max' => 0, 'When' => date('Y-m-d'), 'count' => 0),
61                        'Add to Plugins menu' => false,
62                        'Add icon to History' => true,
63                        'Keep data' => true,
64                        'Default display' => true,
65                ));
66        }
67        pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)
68        VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");
69        $conf_whois = unserialize($conf['Whois Online']);
70        if (isset($conf_whois['Keep data']) and !$conf_whois['Keep data']) {
71                pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE);
72        }
73        list($hits) = mysql_fetch_row(pwg_query('SELECT SUM(hit) FROM '.IMAGES_TABLE.';'));
74        $pags = floor($hits * 1.69); /* estimate : 1.69 is a frequent ratio between images hits and pages hits */
75        pwg_query('REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`, `user_id`,`username`,`lang`,`permanent`,`last_access`,
76        `last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`,
77        `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`)
78                VALUES (\'global\', \'true\',\'global\', 0, \'Administrator\', \'--\', \'true\', \''
79                . time() .'\', \''. implode(' ',array_fill(0, 12, 0))
80                . '\', \''. implode(' ',array_fill(0, 14, 0))
81                . '\', \''. implode(' ',array_fill(0, 14, 0))
82                . '\', \''. implode(' ',array_fill(0, 14, 0))
83                . '\', \'' 
84                . date('Y-m-d') . '\', \'\', \'' 
85                . $hits . '\', \'' . $pags . '\');');
86}
87
88function plugin_deactivate()
89{
90        global $conf;
91        if (isset($conf['Whois Online'])) $conf_whois = unserialize($conf['Whois Online']);
92        if (isset($conf_whois['Keep data']) and !$conf_whois['Keep data']) 
93                pwg_query('DROP TABLE IF EXISTS ' . WHOIS_ONLINE_TABLE);
94}
95
96function plugin_uninstall()
97{
98        global $conf;
99        if (isset($conf['Whois Online'])) $conf_whois = unserialize($conf['Whois Online']);
100        if (isset($conf_whois['Keep data']) and !$conf_whois['Keep data']) {
101                pwg_query('DELETE FROM ' . CONFIG_TABLE . ' WHERE param = ' . "'Whois Online'");
102                pwg_query('DROP TABLE IF EXISTS ' . WHOIS_ONLINE_TABLE);
103                unset($conf['Whois Online']);
104        }
105}
106?>
Note: See TracBrowser for help on using the repository browser.