[3319] | 1 | <?php |
---|
| 2 | |
---|
| 3 | global $prefixeTable, $conf; |
---|
| 4 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 5 | if (!defined('IN_ADMIN') or !IN_ADMIN) die('Hacking attempt!'); |
---|
| 6 | if (!defined('WHOIS_ONLINE_TABLE')) define('WHOIS_ONLINE_TABLE', $prefixeTable.'whois_online'); |
---|
| 7 | |
---|
| 8 | function plugin_activate() |
---|
| 9 | { |
---|
[3695] | 10 | global $user,$conf; |
---|
[3319] | 11 | $query = "CREATE TABLE IF NOT EXISTS ". WHOIS_ONLINE_TABLE ." ( |
---|
[3695] | 12 | `IP` varchar(39) NOT NULL DEFAULT '', |
---|
| 13 | `hidden_IP` enum('true','false') NOT NULL DEFAULT 'false', |
---|
[3319] | 14 | `session_id` varchar(40) NOT NULL, |
---|
[3695] | 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', |
---|
[5810] | 18 | `country` VARCHAR( 255 ) NOT NULL DEFAULT '', |
---|
[3695] | 19 | `user_agent` VARCHAR( 160 ) NOT NULL DEFAULT '', |
---|
[5810] | 20 | `any_previous` VARCHAR( 255 ) NOT NULL DEFAULT '', |
---|
| 21 | `same_previous` VARCHAR( 255 ) NOT NULL DEFAULT '', |
---|
[3695] | 22 | `permanent` enum('true','false') NOT NULL DEFAULT 'false', |
---|
| 23 | `last_access` varchar(12) NOT NULL DEFAULT '', |
---|
| 24 | `last_elm_ids` varchar(75) NOT NULL DEFAULT '', |
---|
| 25 | `last_cat_ids` varchar(75) NOT NULL DEFAULT '', |
---|
| 26 | `last_tag_ids` varchar(75) NOT NULL DEFAULT '', |
---|
| 27 | `last_sch_ids` varchar(75) NOT NULL DEFAULT '', |
---|
| 28 | `first_access_date` varchar(45) NOT NULL DEFAULT '', |
---|
| 29 | `last_dates` varchar(110) character set utf8 collate utf8_bin NOT NULL DEFAULT '', |
---|
| 30 | `elm_hits` int(10) unsigned NOT NULL DEFAULT '0', |
---|
| 31 | `pag_hits` int(10) unsigned NOT NULL DEFAULT '0', |
---|
| 32 | `db_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, |
---|
[3319] | 33 | PRIMARY KEY (`session_id`) |
---|
| 34 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8; |
---|
| 35 | "; |
---|
| 36 | $result = pwg_query($query); |
---|
[6193] | 37 | pwg_query('ALTER TABLE '. WHOIS_ONLINE_TABLE .' CHANGE `lang` `lang` CHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT \'en\''); |
---|
[3695] | 38 | if (!isset($conf['Whois Online'])) { |
---|
| 39 | $conf['Whois Online'] = serialize(Array()); |
---|
| 40 | pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment) |
---|
| 41 | VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');"); |
---|
[3319] | 42 | } |
---|
| 43 | if (isset($conf_whois['Keep data']) and !$conf_whois['Keep data']) { |
---|
| 44 | pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE); |
---|
| 45 | } |
---|
[21237] | 46 | list($hits) = pwg_db_fetch_row(pwg_query('SELECT SUM(hit) FROM '.IMAGES_TABLE.';')); |
---|
[3319] | 47 | $pags = floor($hits * 1.69); /* estimate : 1.69 is a frequent ratio between images hits and pages hits */ |
---|
[5954] | 48 | pwg_query('INSERT IGNORE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`, `user_id`,`username`,`lang`,`permanent`,`last_access`, |
---|
[3319] | 49 | `last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`, |
---|
| 50 | `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`) |
---|
| 51 | VALUES (\'global\', \'true\',\'global\', 0, \'Administrator\', \'--\', \'true\', \'' |
---|
| 52 | . time() .'\', \''. implode(' ',array_fill(0, 12, 0)) |
---|
| 53 | . '\', \''. implode(' ',array_fill(0, 14, 0)) |
---|
| 54 | . '\', \''. implode(' ',array_fill(0, 14, 0)) |
---|
| 55 | . '\', \''. implode(' ',array_fill(0, 14, 0)) |
---|
| 56 | . '\', \'' |
---|
| 57 | . date('Y-m-d') . '\', \'\', \'' |
---|
| 58 | . $hits . '\', \'' . $pags . '\');'); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | function plugin_deactivate() |
---|
| 62 | { |
---|
| 63 | global $conf; |
---|
| 64 | if (isset($conf['Whois Online'])) $conf_whois = unserialize($conf['Whois Online']); |
---|
| 65 | if (isset($conf_whois['Keep data']) and !$conf_whois['Keep data']) |
---|
| 66 | pwg_query('DROP TABLE IF EXISTS ' . WHOIS_ONLINE_TABLE); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | function plugin_uninstall() |
---|
| 70 | { |
---|
| 71 | global $conf; |
---|
| 72 | if (isset($conf['Whois Online'])) $conf_whois = unserialize($conf['Whois Online']); |
---|
| 73 | if (isset($conf_whois['Keep data']) and !$conf_whois['Keep data']) { |
---|
| 74 | pwg_query('DELETE FROM ' . CONFIG_TABLE . ' WHERE param = ' . "'Whois Online'"); |
---|
| 75 | pwg_query('DROP TABLE IF EXISTS ' . WHOIS_ONLINE_TABLE); |
---|
| 76 | unset($conf['Whois Online']); |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | ?> |
---|