forked from M4t1ss/TwitEdiens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtops.php
149 lines (144 loc) · 4.54 KB
/
tops.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
<?php
if($_POST['submit']) //ja piespiests parādīt
{
header('Content-type: text/HTML; charset=utf-8');
//ievācam visus mainīgos
$no = strip_tags($_POST['from']);
$lidz = strip_tags($_POST['to']);
if($no==""){
$no=date("y-m-d");
}
if($lidz==""){
$lidz=date("y-m-d");
}
if($no==$lidz) {
$no--;
$no = date("y-m-d",strtotime($no."-24 hours"));
}
$ns=strtotime($no);
$ls=strtotime($lidz);
if($ns>$ls){
$x=$no;
$no=$lidz;
$lidz=$x;
}
$no=strtotime($no);
$no=date("Y-m-d", $no);
$lidz=strtotime($lidz);
$lidz=date("Y-m-d", $lidz);
}else{//ja ne, lai parādās pēdējā mēneša dati...
//dabū šodienas datumu
$menesiss = $menesis = date("m");
$dienasz = $diena = date("d");
$gadss = $gads = date("Y");
//izrēķina datumu pirms mēneša
$menesis--;
if($menesis==0){
$menesis=12;
$gads--;
}
$no = $gads."-".$menesis."-".$diena;
$lidz = $gadss."-".$menesiss."-".$dienasz;
}
$nn=strtotime($no);
$nn=date("d-m-Y", $nn);
$ll=strtotime($lidz);
$ll=date("d-m-Y", $ll);
//pirms cik dienām bija pirmais tvīts?
$die = mysqli_query($connection, "SELECT min( created_at ) diena FROM tweets");
$mdie=mysqli_fetch_array($die);
$laiks=strtotime($mdie['diena']);
$laiks=date("U", $laiks);
$seconds = time() - $laiks;
$days = ceil($seconds / 60 / 60 / 24);
?>
<script type="text/javascript">
$(function() {
$( "#from, #to" ).datepicker({ minDate: -<?php echo $days; ?>, maxDate: "+0D" });
var dates = $( "#from, #to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
$( "#from, #to" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
$( "#from, #to" ).datepicker($.datepicker.regional['fr']);
$( "#to" ).datepicker({ currentText: 'Today' });
});
</script>
<h2 style='margin:auto auto; text-align:center;'>Twitter gardēžu TOPS</h2>
<h5 style='margin:auto auto; text-align:center;'>
<form method="post" action="?id=tops">
No <input value="<?php echo $nn;?>" readonly size=9 type="text" id="from" name="from"/> līdz <input value="<?php echo $ll;?>" readonly size=9 type="text" id="to" name="to"/>
<INPUT TYPE="submit" name="submit" value="Parādīt"/>
</form>
</h5>
<br/>
<div id="toptable">
<?php
$krasa=TRUE;
$i=1;
echo "<table class='sortable' id='toptable2'>";
echo "<tr>
<th class='tb1'>Nr.</th>
<th class='tb2'>Lietotājs</th>
<th class='tb3'>Tvīti</th>
<th class='tb4'>Ēdieni</th>
<th class='tb5'>Vietas</th>
</tr>";
//Sevi un ziņu portālus neslavināsim :)
$blacklist = array(
'laiki', 'epadomi', 'edienbots', 'gardedis_lv', 'LA_lv', 'JaunsLV', 'FOLKKLUBS',
'StilaparksLv', 'ifaktors', 'nralv', 'DelfiLV', 'Twitediens', 'budzis', 'cafeleningrad'
);
$q = mysqli_query($connection, "SELECT screen_name, count( * ) skaits FROM tweets
WHERE screen_name NOT IN ('".implode("','",$blacklist)."')
AND created_at between '$no' AND '$lidz'
GROUP BY screen_name
ORDER BY count( * ) DESC
LIMIT 0 , 20");
$qv = mysqli_query($connection, "SELECT screen_name, count( words.tvits ) varduskaits FROM tweets
JOIN words on tweets.id = words.tvits
WHERE screen_name NOT IN ('".implode("','",$blacklist)."')
AND created_at between '$no' AND '$lidz'
GROUP BY screen_name
ORDER BY count( * ) DESC
LIMIT 0 , 100");
while($rx=mysqli_fetch_array($qv)){
$edieni[$rx["screen_name"]] = $rx["varduskaits"];
$users[] = $rx["screen_name"];
}
$qa = mysqli_query($connection, "SELECT screen_name, count( tweets.geo ) geoskaits FROM tweets
WHERE geo != ''
AND screen_name IN ('".implode("','",$users)."')
AND created_at between '$no' AND '$lidz'
GROUP BY screen_name
ORDER BY geoskaits DESC
LIMIT 0 , 400");
while($rz=mysqli_fetch_array($qa)){
$geo[$rz["screen_name"]] = $rz["geoskaits"];
}
while($r=mysqli_fetch_array($q)){
if ($krasa==TRUE) {$kr=" class='even'";}else{$kr="";}
$vards=$r["screen_name"];
$skaits=$r["skaits"];
echo "<tr".$kr.">
<td class='tb1'>".$i.".</td>
<td class='tb2'><b><a style='text-decoration:none;color:#808080;' href='/draugs/".$vards."'>".$vards."</a></b></td>
<td class='tb3'>".$skaits."</td>
<td class='tb4'>".$edieni[$vards]."</td>
<td class='tb5'> ".$geo[$vards]."</td>
</tr>";
$krasa=!$krasa;
$i++;
}
echo "</table>";
?>
</div>