-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.php
142 lines (128 loc) · 4.43 KB
/
update.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
<?php
header('Content-Type: text/html; charset=utf-8');
require_once('./config.php');
if ($_GET['visitors']) {
// the `data` column in the mint__config table holds a serialized PHP array
$query = mysql_query("SELECT data FROM `".$mint_prefix."_config;");
$result = mysql_fetch_row($query);
foreach ($result as $field) {
// unserialize the $field
$f = unserialize($field);
// $f is a associative array, sorted ascending by date.
// by pop'ing the list twice, we get the stats for today and yesterday
$today = array_pop($f[0]['visits'][2]);
$yesterday = array_pop($f[0]['visits'][2]);
$ret = array();
$ret['today'] = array("unique" => $today['unique'], "total" => $today['total']);
$ret['yesterday'] = array("unique" => $yesterday['unique'], "total" => $yesterday['total']);
// echo the results as json, so that jQuery easily can pick it up.
echo json_encode($ret);
}
}
if ($_GET['referers']) {
$t = time();
// Get the referers that sent most traffic the last hour. Exclude local referers.
$query = "SELECT `referer`, `resource`, `resource_title`, COUNT(`referer`) as `total`, `dt`
FROM `".$mint_prefix."visit`
WHERE `referer_is_local` = 0 AND `search_terms` = '' AND dt > $t-(60*60)
GROUP BY `referer_checksum`
ORDER BY `total` DESC, `dt` DESC
LIMIT 0,5";
$query = mysql_query($query);
$i = 0;
while ($r = mysql_fetch_array($query)) {
if ($odd = $i%2) {
$class =' class="odd"';
} else {
$class = '';
}
$i++;
// remove http://www from the referer, and
// trim the remaining value to 10 characters for display's sake.
$ref = str_replace("http://", "", urldecode($r["referer"]));
$ref = str_replace("www.", "", $ref);
$ref = substr($ref, 0, 10);
// You might not need to do this, but I did.. :-)
$resource_title = substr(html_entity_decode($r['resource_title'], ENT_QUOTES, 'UTF-8'), 0, 28);
$s = <<<END
<dl$class>
<dt>
<span>$r[total]</span> fra <span>$ref</span>
til <span>$resource_title</span>
</dt>
<dd></dd>
<div class="clearer"></div>
</dl>
END;
echo $s;
}
}
if ($_GET['popular']) {
$t = time();
// Get the most popular (most read) posts the last 72 hours, exclude the front page.
$query = "SELECT `resource`, `resource_checksum`, `resource_title`, COUNT(`resource_checksum`) as `total`, `dt`
FROM `".$mint_prefix."visit` WHERE dt > $t-(72*60*60) AND `resource`!='".$front_page_url."'
GROUP BY `resource_checksum`
ORDER BY `total` DESC, `dt` DESC
LIMIT 0,5";
$query = mysql_query($query);
$i = 0;
while ($r = mysql_fetch_array($query)) {
if ($odd = $i%2) {
$class =' class="odd"';
} else {
$class = '';
}
$i++;
// You might not need to do this, but I did.. :-)
$resource_title = html_entity_decode($r['resource_title'], ENT_QUOTES, 'UTF-8');
echo <<<END
<dl$class>
<dt>$resource_title</dt>
<dd>$r[total]</dd>
<div class="clearer"></div>
</dl>
END;
}
}
if ($_GET['comments']) {
$doc = simplexml_load_file($rss_url);
$twitter = simplexml_load_file($twitter_search_url);
$i = 0;
$ret = array();
$ret['comments'] = array();
foreach($twitter->entry as $item) {
if ($i == 3) {
$i = 0;
break;
}
$comment = <<<END
<div class="comment">
<p>$item->content</p>
END;
$comment .= '<p class="author">Av @'.$item->author->name.'</p></div>';
$ret['comments'][] = $comment;
$i++;
}
foreach ($doc->channel->item as $item) {
if ($i == 0) {
$ret['last_comment'] = date('H:i', strtotime($item->pubDate));
}
if ($i == 3) {
$i = 0;
break;
}
$title = str_replace('Comment on', '<span>Kommentar til</span>', $item->title);
$description = substr($item->description, 0, 300);
$comment = <<<END
<div class="comment">
<p>$description</p>
<p class="author">– $title</p>
</div>
END;
$ret['comments'][] = $comment;
$i++;
}
echo json_encode($ret);
}
?>