-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
94 lines (67 loc) · 2 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
<?php
// TODO: sparklines in place of count
// TODO: increase score if user is in my network
$username = 'hublicious'; // edit this
/*****************/
cleanup();
global $urls;
global $meta;
global $users;
bookmarks($username, 20);
$my_bookmarks = $urls;
array_walk(array_keys($urls), 'users', 20);
//$urls = array(); // reset
unset($users[$username]);
array_walk(array_keys($users), 'bookmarks', 100);
foreach (array_keys($my_bookmarks) as $url)
unset($urls[$url]);
arsort($urls);
require 'index.tpl.php';
function bookmarks($username, $key, $count = 20){
global $urls;
global $meta;
$url = sprintf('http://feeds.delicious.com/v2/rss/%s?count=%d', $username, $count);
foreach (items($url) as $item){
$link = (string) $item->link;
$title = (string) $item->title;
$description = (string) $item->description;
$urls[$link]++;
$meta[$link]['title'] = $title;
if ($description)
$meta[$link]['descriptions'][$username] = filter_var($description, FILTER_SANITIZE_STRING);
}
}
function users($url, $key, $count = 20){
global $users;
$url = sprintf('http://feeds.delicious.com/v2/rss/url/%s?count=%d', md5($url), $count);
foreach (items($url) as $item){
$user = (string) current($item->xpath('dc:creator'));
$users[$user]++;
}
}
function items($url){
$data = cget($url);
$xml = simplexml_load_string($data);
$xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/');
return $xml->channel->item;
}
function cget($url){
//print $url . "\n";
$key = md5($url);
$file = 'cache/' . $key;
if (file_exists($file) && filesize($file))
return file_get_contents($file);
$data = file_get_contents($url);
if ($data){
file_put_contents($file, $data);
sleep(1);
return $data;
}
}
function cleanup(){
$expire = time() - 60*60*24*7; // 7 days
$files = scandir('cache');
foreach ($files as $file)
if (!strstr($file, '.') && filemtime('cache/' . $file) < $expire)
unlink('cache/' . $file);
}