public
Description: Big Geek Days Out are "unEvents" intended to get people to go to places they want to visit but never get round to going to
Homepage: http://biggeekdayout.com
Clone URL: git://github.com/NeilCrosby/biggeekdayout.git
biggeekdayout / refresh.php
100644 92 lines (70 sloc) 2.789 kb
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
<?php
 
define("UPCOMING_EVENT", "2912229");
define("FILE_TEMPLATE", "/templates/index.tpl");
define("FILE_OUTPUT", "/index.html");
 
function __autoload($class_name) {
    require_once $class_name . '.php';
}
 
$url = "http://upcoming.yahoo.com/ajax/event_page_all_attendees.php?event_id=".UPCOMING_EVENT;
$data = simplexml_load_file( $url );
 
$attend = (string)$data->attend;
$watch = (string)$data->watch;
 
$attend = getHtmlUserList($attend);
$watch = getHtmlUserList($watch);
$ical = "webcal://upcoming.yahoo.com/calendar/v2/event/".UPCOMING_EVENT;
$sign_up = "http://upcoming.yahoo.com/event/".UPCOMING_EVENT."/";
 
$attend_num = getUserCount($data->attend);
$attend_num = ($attend_num) ? " ($attend_num)" : '';
 
$watch_num = getUserCount($data->watch);
$watch_num = ($watch_num) ? " ($watch_num)" : '';
 
mb_internal_encoding("UTF-8");
 
$template = getTemplate();
 
$template = str_replace( array('###attend###', '###watch###', '###ical###', '###sign-up###', '###attend-num###', '###watch-num###'),
                         array($attend, $watch, $ical, $sign_up, $attend_num, $watch_num),
                         $template );
saveOutput($template);
 
$server = ( 80 == $_SERVER['SERVER_PORT'])
        ? $_SERVER['SERVER_NAME']
        : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'];
 
header("Location: http://$server/");
 
 
function getTemplate() {
    return file_get_contents($_SERVER['DOCUMENT_ROOT'].FILE_TEMPLATE);
}
 
function saveOutput( $template ) {
    return file_put_contents($_SERVER['DOCUMENT_ROOT'].FILE_OUTPUT, $template);
}
 
function getHtmlUserList($html) {
    $doc = new DOMDocument();
    // have to give charset otherwise loadHTML gets confused
    $doc->loadHTML(
        '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>'.
        $html.
        '</body></html>'
    );
    $xpath = new DOMXPath($doc);
    $items = $xpath->query("//a[@property='vcard:fn']");
 
    $output = '';
    if ($items->length > 0) {
        $output = "<ul class='bd'>";
        foreach ($items as $item) {
            $href = $item->attributes->getNamedItem('href')->nodeValue;
            $text = (string)$item->firstChild->nodeValue;
 
            $output .= "<li><a href='${href}'>${text}</a></li>";
        }
        $output .= "</ul>";
    }
 
    return $output;
}
 
function getUserCount($html) {
    $doc = new DOMDocument();
    // have to give charset otherwise loadHTML gets confused
    $doc->loadHTML(
        '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>'.
        $html.
        '</body></html>'
    );
    $xpath = new DOMXPath($doc);
    $items = $xpath->query("//a[@property='vcard:fn']");
 
    return $items->length;
}
 
?>