forked from poppyred/1.6.x
/
miniadm.webstats.notcategorized.php
executable file
·342 lines (286 loc) · 10.3 KB
/
miniadm.webstats.notcategorized.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?php
session_start();
ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string',null);
ini_set('error_append_string',null);
if(!isset($_SESSION["uid"])){header("location:miniadm.logon.php");}
include_once(dirname(__FILE__)."/ressources/class.templates.inc");
include_once(dirname(__FILE__)."/ressources/class.users.menus.inc");
include_once(dirname(__FILE__)."/ressources/class.miniadm.inc");
include_once(dirname(__FILE__)."/ressources/class.mysql.postfix.builder.inc");
include_once(dirname(__FILE__)."/ressources/class.user.inc");
if(isset($_GET["content"])){content();exit;}
if(isset($_GET["master-content"])){master_content();exit;}
if(isset($_GET["title-not-categorized"])){title_not_categorized();exit;}
if(isset($_GET["search-websites"])){search_websites();exit;}
if(isset($_POST["CATEGORIZE"])){CATEGORIZE();exit;}
$users=new usersMenus();
if(!$users->AsWebStatisticsAdministrator){header("location:miniadm.logon.php");die();}
main_page();
function main_page(){
$page=CurrentPageName();
buildCategoriesCache(true);
$tplfile="ressources/templates/endusers/index.html";
if(!is_file($tplfile)){echo "$tplfile no such file";die();}
$content=@file_get_contents($tplfile);
$content=str_replace("{SCRIPT}", "<script>LoadAjax('globalContainer','$page?content=yes')</script>", $content);
echo $content;
}
function content(){
$page=CurrentPageName();
$tpl=new templates();
$q=new mysql_squid_builder();
$t=time();
$html="
<div class=BodyContent>
<div style='font-size:14px'><a href=\"miniadm.index.php\">{myaccount}</a>
» <a href=\"miniadm.webstats-start.php\">{web_statistics}</a>
</div>
<H1 id='title-not-categorized'></H1>
<p>{not_categorized_explain_why}<hr><span style='font-weight:bold'>{categorize_becare}</span></p>
</div>
<div id='master-content'></div>
<script>
LoadAjax('master-content','$page?master-content=yes');
</script>
";
echo $tpl->_ENGINE_parse_body($html);
}
function master_content(){
$page=CurrentPageName();
$tpl=new templates();
$t=time();
$boot=new boostrap_form();
$SearchQuery=$boot->SearchFormGen("sitename,familysite,domain,country","search-websites")."
<script>
function RefreshNotCategorizedTitle(){
LoadAjaxTiny('title-not-categorized','$page?title-not-categorized=yes');
}
RefreshNotCategorizedTitle();
</script>
";
echo $SearchQuery;
}
function title_not_categorized(){
$tpl=new templates();
$q=new mysql_squid_builder();
$number=FormatNumber($q->COUNT_ROWS("notcategorized"));
echo $tpl->_ENGINE_parse_body("$number {not_categorized}");
}
function FormatNumber($number, $decimals = 0, $thousand_separator = ' ', $decimal_point = '.'){
$tmp1 = round((float) $number, $decimals);
while (($tmp2 = preg_replace('/(\d+)(\d\d\d)/', '\1 \2', $tmp1)) != $tmp1)
$tmp1 = $tmp2;
return strtr($tmp1, array(' ' => $thousand_separator, '.' => $decimal_point));
}
function CATEGORIZE(){
$category=$_POST["CATEGORIZE"];
$www=$_POST["WWW"];
$q=new mysql_squid_builder();
$q->categorize($www, $category);
$q->QUERY_SQL("DELETE FROM notcategorized WHERE sitename='$www'");
if(!$q->ok){echo $q->mysql_error;}
}
function search_websites(){
$q=new mysql_squid_builder();
$tpl=new templates();
$searchstring=string_to_flexquery("search-websites");
$Params=url_decode_special_tool($_GET["Params"]);
$table="notcategorized";
$boot=new boostrap_form();
$ORDER=$boot->TableOrder(array("hits"=>"DESC"));
$sql="SELECT * FROM $table WHERE 1 $searchstring ORDER BY $ORDER LIMIT 0,30";
writelogs($sql,__FUNCTION__,__FILE__,__LINE__);
$results = $q->QUERY_SQL($sql);
if(!$q->ok){
echo "<p class=text-error>$q->mysql_error<hr><code>$sql</code></p>";
}
while ($ligne = mysql_fetch_assoc($results)) {
$id=md5($ligne["sitename"]);
$ligne["size"]=FormatBytes($ligne["size"]/1024);
$ligne["hits"]=FormatNumber($ligne["hits"]);
$dates=unserialize($ligne["seen"]);
$trg=array();
if(is_array($dates)){
while (list ($none, $xtime) = each ($dates) ){
$trg[]=time_to_date($xtime);
}
}
$params=BuildDiv($ligne["sitename"]);
$link=$boot->trswitch($params[2]);
$content=$params[0];
$js[]=$params[1];
$tr[]="
<tr id='$id'>
<td $link><i class='icon-globe'></i> {$ligne["sitename"]}$content<br><i style='font-size:10px'>". @implode(", ", $trg)."</td>
<td $link nowrap><i class='icon-globe'></i> {$ligne["familysite"]}</td>
<td $link nowrap><i class='icon-globe'></i> {$ligne["country"]}</td>
<td $link nowrap><i class='icon-globe'></i> {$ligne["size"]}</td>
<td $link nowrap><i class='icon-star'></i> {$ligne["hits"]}</td>
</tr>";
}
echo $boot->TableCompile(
array("sitename"=>"{website}","familysite"=>"{familysite}","country"=>"{country}",
"size"=>"{size}",
"hits"=>"{hits}"
),
$tr
)."
<script>".@implode("\n", $js)."</script>
";
}
function BuildDiv($sitename){
$tpl=new templates();
$page=CurrentPageName();
$md5=md5($sitename);
$boot=new boostrap_form();
$sitename=urlencode($sitename);
$categories=buildCategoriesCache();
$ARTICA=$categories["CATEGORIES_ARTICA"];
$CATEGORIES_PERSO=$categories["CATEGORIES_PERSO"];
$categorize=$tpl->_ENGINE_parse_body("{categorize}");
$generic_categories=$tpl->_ENGINE_parse_body("{categories}");
$your_categories=$tpl->_ENGINE_parse_body("{your_categories}");
$find=$tpl->_ENGINE_parse_body("{search}");
if(!is_array($CATEGORIES_PERSO)){$CATEGORIES_PERSO=array();}
$t=time();
$ART[]="
<center id='animate-$md5'></center>
<div style='text-align:right;margin-bottom:10px' >
<input id='s-$md5' class='input-medium search-query' onkeypress='javascript:SearchQuery$md5()' type='text'>
<button type='button' id='$md5-$t' class='btn' OnClick=\"javascript:SearchQuery$md5()\">$find</button>
</div>
<table class='table table-bordered table-hover'>
<thead>
<tr>
<th colspan=2>". $tpl->_ENGINE_parse_body("{category}")."</th>
<th>". $tpl->_ENGINE_parse_body("{description}")."</th>
</tr>
</thead>
";
while (list ($category, $params) = each ($ARTICA) ){
$categoryID=trim($category);
$categoryID=str_replace(" ", "", $categoryID);
$categoryID=str_replace("/", "-", $categoryID);
$link=$boot->trswitch("Categorize$md5('$category','$sitename','$md5')");
$ART[]="
<tr id='$md5-tr-$categoryID'>
<td $link width=1% nowrap>{$params["IMG"]}</td>
<td $link width=1% nowrap>$category</td>
<td $link>{$params["DESC"]}</td>
</tr>";
}
$ART[]="</table>";
$PERS[]="<table class='table table-bordered table-hover'>
<thead>
<tr>
<th colspan=2>". $tpl->_ENGINE_parse_body("{category}")."</th>
<th>". $tpl->_ENGINE_parse_body("{description}")."</th>
</tr>
</thead>
";
while (list ($category, $params) = each ($CATEGORIES_PERSO) ){
$categoryID=trim($category);
$categoryID=str_replace(" ", "", $categoryID);
$categoryID=str_replace("/", "-", $categoryID);
$link=$boot->trswitch("Categorize$md5('$category','$sitename','$md5')");
$PERS[]="
<tr id='$md5-tr-$categoryID'>
<td $link width=1% nowrap>{$params["IMG"]}</td>
<td $link width=1% nowrap>$category</td>
<td $link>{$params["DESC"]}</td>
</tr>";
}
$PERS[]="</table>";
$html="
<div id='dialog-$md5' title='$sitename'>
<div id='logs-$md5'></div>
<H3>$sitename</H3>
<ul class='nav nav-tabs' id='site-$md5'>
<li class='active' id='gen-$md5'><a href='javascript:blur();' OnClick=\"javascript:Gecat$md5()\">$generic_categories</a></li>
";
if(count($CATEGORIES_PERSO)>0){$html=$html."<li><a href='javascript:blur();' OnClick=\"javascript:Pers$md5()\" id='pers-$md5'>$your_categories</a></li>";}
$html=$html."</ul>
<div class='tab-pane active' id='site-$md5-art'>
".@implode("\n",$ART)."
</div>
<div class='tab-pane' id='site-$md5-pers' style='display:none'>
".@implode("\n",$PERS)."
</div>
</div>
<script>
var md{$md5}='';
function Gecat$md5(){
document.getElementById('gen-$md5').className='active';
document.getElementById('site-$md5-art').className='tab-pane active';
document.getElementById('site-$md5-art').style.display='block';
if(document.getElementById('pers-$md5')){
document.getElementById('pers-$md5').className='';
document.getElementById('site-$md5-pers').classList.remove('active');
document.getElementById('site-$md5-pers').style.display='none';
}
}
function SearchQuery$md5(){
var sid='';
var xlogs='';
var pos=0;
var category='';
var pattern=document.getElementById('s-$md5').value;
if(pattern.length==0){
$('#dialog-$md5 [id^=\"$md5-tr-\"]').show();
return;
}
$('#dialog-$md5 [id^=\"$md5-tr-\"]').hide();
$('#dialog-$md5 [id^=\"$md5-tr-\"]').each(function(){
if(this.id){
sid=this.id;
var myRegexp = /$md5-tr-(.*?)$/;
var match = myRegexp.exec(sid);
category=' '+match[1];
xlogs=xlogs+'Found <b>'+category+'</b>';
pos=category.search(pattern);
if ( pos>0 ) {
$('#'+sid).show();
xlogs=xlogs+' <span style=color:red>found</span><br>';
}else{
xlogs=xlogs+' '+pattern+' '+'<b>'+pos+'</b> not found<br>';
}
}
});
//document.getElementById('logs-$md5').innerHTML=xlogs;
}
var xCategorize$md5= function (obj) {
var results=obj.responseText;
document.getElementById('animate-$md5').innerHTML='';
if(results.length>2){
alert(results);
return;
}
$('#dialog-$md5').empty();
$('#dialog-$md5').dialog('destroy');
$('#'+md{$md5}).remove();
RefreshNotCategorizedTitle();
}
function Categorize$md5(cat,site,md){
md{$md5}=md;
if(!confirm(site +' --> '+cat+' ?')){return;}
var XHR = new XHRConnection();
XHR.appendData('CATEGORIZE',cat);
XHR.appendData('WWW',site);
AnimateDiv('animate-$md5');
XHR.sendAndLoad('$page', 'POST',xCategorize$md5);
}
function Pers$md5(){
document.getElementById('gen-$md5').className='';
document.getElementById('pers-$md5').className='active';
document.getElementById('site-$md5-pers').className='tab-pane active';
document.getElementById('site-$md5-art').classList.remove('active');
document.getElementById('site-$md5-art').style.display='none';
document.getElementById('site-$md5-pers').style.display='block';
}
</script>
";
return array($html,
"$('#dialog-$md5').dialog({autoOpen: false,width: '800px',position: 'top',zIndex:8999});\n$('#dialog-$md5').dialog( 'option', 'height', 700 );"
,"$( '#dialog-$md5' ).dialog( 'open' );");
}
?>