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

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

New: Piwigo 2.1 support
Fix: Flags could be based on Languages if api calls are forbidden by a provider.
Part of a code review.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 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,$conf;
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( 255 ) NOT NULL DEFAULT '',
19  `user_agent` VARCHAR( 160 ) NOT NULL DEFAULT '',
20  `any_previous` VARCHAR( 255 ) NOT NULL DEFAULT '',
21  `same_previous` VARCHAR( 255 ) NOT NULL DEFAULT '',
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,
33  PRIMARY KEY  (`session_id`)
34) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
35";
36        $result = pwg_query($query);
37        pwg_query('ALTER TABLE '. WHOIS_ONLINE_TABLE .' CHANGE `lang` `lang` CHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT \'en\'');
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');");
42        }
43        if (isset($conf_whois['Keep data']) and !$conf_whois['Keep data']) {
44                pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE);
45        }
46        list($hits) = mysql_fetch_row(pwg_query('SELECT SUM(hit) FROM '.IMAGES_TABLE.';'));
47        $pags = floor($hits * 1.69); /* estimate : 1.69 is a frequent ratio between images hits and pages hits */
48        pwg_query('INSERT IGNORE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`, `user_id`,`username`,`lang`,`permanent`,`last_access`,
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
61function 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
69function 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?>
Note: See TracBrowser for help on using the repository browser.