source: extensions/whois_online/reload.php @ 27153

Last change on this file since 27153 was 21667, checked in by plg, 11 years ago

function get_thumbnail_url is deprecated (since Piwigo 2.4)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1<?php
2// Reload might be :
3// - accessed thru a direct link from admin.php?page=plugin&section=whois_online%2Fconfig.php&tab=report
4// - or included directly by admin.php (include_one in reporting part)
5// Reload won't work if Whois_Online is deactivated
6$included = true;
7if (!isset($_url)) {
8                define('PHPWG_ROOT_PATH','../../');
9                define('IN_ADMIN', true);
10                include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
11                $conf['show_gt'] = true;
12                $included = false;
13                load_language('plugin.lang', WHOIS_ONLINE_PATH);
14}
15
16// This is MANDATORY to secure your website !
17check_status(ACCESS_ADMINISTRATOR);
18
19pwg_debug('*********** Radar reload ***********');
20$conf_whois = whois_online_conf();
21
22$sort = ' WHERE `IP` = "global" or ( 1=1 ';
23
24// Filtering on direct link parameters
25$case = '';
26if (isset($_GET['req'])) {
27        $case = $_GET['req'];
28        switch($_GET['req']) { 
29                case 'members': 
30                        $sort.= ' AND `user_id` <> "' . $conf['guest_id'] . '"';
31                        break;
32                case 'guest': 
33                        $sort.= ' AND `user_id` = "' . $conf['guest_id'] . '"';
34                        break;
35                case 'less_24': 
36                        $sort.= ' AND `last_access` > "' . (time()-(24*3600)) . '"';
37                        break;
38                case 'over_24': 
39                        $sort.= ' AND `last_access` < "' . (time()-(24*3600)) . '"';
40                        break;
41                case 'pics': 
42                        $sort.= ' AND `last_elm_ids` > "0 0 0 0 0 0 0 0 0 0"';
43                        break;
44                case 'no_pic': 
45                        $sort.= ' AND `last_elm_ids` = "0 0 0 0 0 0 0 0 0 0"';
46                        break;
47                case 'country': 
48                        $sort.= ' AND `country` <> \'' . htmlspecialchars(serialize(Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',))) . '\'';
49                        break;
50                case 'no_country': 
51                        $sort.= ' AND `country` = \'' . htmlspecialchars(serialize(Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',))) . '\'';
52                        break;
53                case 'single': 
54                        $sort.= ' AND LENGTH(`last_dates`) < 12';
55                        break;
56                case 'multi': 
57                        $sort.= ' AND LENGTH(`last_dates`) > 12';
58                        break;
59                case 'IPs': 
60                        $sort.= ' AND `hidden_IP` = "true"';
61                        break;
62        } 
63}
64$sort .= ')
65ORDER BY `db_timestamp` DESC;';
66$online = whois_online_get_data($sort);
67$global = $online[0]; unset($online[0]);
68$sid = session_id();
69
70$iflag = 0; // Get the 10 first new flags on included requests ONLY (Duration reasons)
71
72// prefetch to optimize
73$local_guest = pwg_db_fetch_assoc(pwg_query('SELECT * FROM ' . USER_INFOS_TABLE .
74        ' WHERE user_id = ' . $conf['guest_id'] .';'));
75       
76$lang_tab = get_languages();
77foreach ($lang_tab as $k => $v) $lang_code[substr($k,0,2)] = substr($v,0,strrpos($v,'[')-1);
78
79$bypass = false;
80$limit = 20;
81$ql = 0; 
82$inlist = '0';
83foreach ($online as $k => $v) {
84  $inlist .= ', ' . implode( ', ', explode(' ',$online[$k]['last_elm_ids']));
85        $ql++;
86        if ($ql >= $conf_whois['Radar limit']) break;
87}
88$image = array();
89$result = pwg_query('SELECT * FROM ' . IMAGES_TABLE .
90        ' WHERE id IN (' . $inlist .');');
91while ($row = pwg_db_fetch_assoc($result)) {
92        $images[$row['id']] = $row;
93        $images[$row['id']]['tn_url'] = DerivativeImage::thumb_url($row);
94}
95foreach ($online as $k => $v) {
96  // The stupid History search will be reused instead of created... (even if History search will recreate it)   
97    if ($conf['log']) { 
98                if ( $conf['history_guest'] or $online[$k]['user_id'] != $conf['guest_id'])
99                        $online[$k]['url_user'] = 
100                        PHPWG_ROOT_PATH .'admin.php?page=history&amp;user_id='.$online[$k]['user_id'].'&amp;search_id='.$conf_whois['Search id'];
101        }
102
103        $online[$k]['Language'] = (isset($lang_code[$v['lang']])) ? $lang_code[$v['lang']]:l10n('Deleted language');
104        $online[$k]['Country'] = whois_country($v, $bypass);
105        $iflag++;
106        $online[$k]['Flag'] = ($included) ? whois_flag($online[$k], $iflag) : whois_flag($online[$k], $iflag, $limit);
107        if (!$included) $online[$k]['Flag'] = substr($online[$k]['Flag'],4);
108        if ($iflag > 5) $bypass = true; // Don't search already unknown countries over 5 countries
109        if ($v['user_id'] == $conf['guest_id']) { 
110                $online[$k]['username'] =  ucwords(l10n('guest'));
111                $online[$k]['guest'] =  true;
112                $online[$k]['user'] = $local_guest; // Prefetched guest data
113        }
114        else {
115                $online[$k]['user'] = pwg_db_fetch_assoc(pwg_query('SELECT * FROM ' . USER_INFOS_TABLE .
116                 ' WHERE user_id = ' . $v['user_id'] .';'));
117                $online[$k]['guest'] =  false;
118        }
119        // Images queries are limited (no cluetip over $conf_whois['Radar limit'])
120        // For performance reasons
121        $online[$k]['Bot'] = is_a_bot($online[$k]['user_agent']);
122        $online[$k]['last_ids'] = explode(' ',$online[$k]['last_elm_ids']);
123        foreach ($online[$k]['last_ids'] as $id) {
124                        if (isset($images[$id])) {
125                                $online[$k]['images'][$id] = $images[$id];
126                                $online[$k]['images'][$id]['ws_level'] = ($images[$id]['level']>$online[$k]['user']['level']) ? 'ws':'';
127                        }
128                        $online[$k]['images'][$id]['id'] = $id;
129                        $online[$k]['images'][$id]['url_modify'] = PHPWG_ROOT_PATH . 'admin.php?page=picture_modify&image_id='.$id;
130                }
131        }
132
133pwg_debug('*********** Radar reloaded ***********');
134$template->assign('search_results', $online);
135$template->assign('Case', $case);
136// Send reloadable HTML
137if ( !$included ) {
138        $template->set_filenames(array('reload'=> dirname(__FILE__) . '/report.tpl'));
139        $template->pparse('reload');
140}
141
142?>
Note: See TracBrowser for help on using the repository browser.