forked from php/web-php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ug.php
134 lines (121 loc) · 4.38 KB
/
ug.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
<?php
$_SERVER['BASE_PAGE'] = 'ug.php';
include_once __DIR__ . '/include/prepend.inc';
mirror_setcookie("LAST_UG", $_SERVER["REQUEST_TIME"]+60*60*24, 60*60*24);
site_header("Hypertext Preprocessor",
array(
'current' => 'community',
)
);
function print_cc_header($country) {
global $COUNTRIES;
?>
<div class="country" id="<?php echo $country ?>">
<h2 class="title countrytitle">User Groups in <?php echo $COUNTRIES[$country] ?>
<img height="25" width="45" src="/images/flags/beta/<?php echo strtolower($country) ?>.png">
</h2>
<ul class="ugs">
<?php
}
function ug_get_more_info($group) {
if (! trim($group["icalendar_url"])) {
return null;
}
$url = $group["icalendar_url"];
$filename = "backend/events/" . md5($url);
/* Broken icalendar link */
if (!file_exists($filename)) {
return null;
}
$data = file($filename, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
$retval = ug_get_next_even_from_ical_array($data);
return $retval;
}
function ug_get_next_even_from_ical_array($ical) {
$ok = false;
$data = array();
foreach($ical as $line) {
if ($line == "BEGIN:VEVENT") {
foreach ($ical as $n => $line) {
if ("END:VEVENT" == $line) {
break;
}
if ($line[0] == " ") {
// data continued from previous key
$data[$lastkey] .= ltrim($line);
} else {
list($lastkey, $value) = explode(":", $line, 2);
$data[$lastkey] = $value;
}
}
break;
}
}
if (!isset($data["DTSTAMP"])) {
/* There is no scheduled next meeting */
return array();
}
/* Meetup.com seems to have fetish for injecting the TZ into the keyname */
if (isset($data["TZID"])) {
$data["STARTSAT"] = $data["DTSTART;TZID={$data["TZID"]}"];
} else {
$data["STARTSAT"] = $data["DTSTART"];
}
// Yes.. Replace literal '\n' with new line
$data["DESCRIPTION"] = str_replace('\n', "\n", $data["DESCRIPTION"]);
return array("event" => $data);
}
function print_ug_matches($matches) {
global $COUNTRIES, $country;
$content = "";
echo '<dl>';
foreach($matches as $group) {
$data = ug_get_more_info($group);
$details = "";
if ($data && $data["event"]) {
$d = date(DATE_RSS, strtotime($data["event"]["STARTSAT"], $_SERVER["REQUEST_TIME"]));
$url = isset($data["event"]["URL"]) ? addslashes($data["event"]["URL"]) : "";
$summary = htmlspecialchars($data["event"]["SUMMARY"]);
/* The icalendar has all sorts of weird trailing slashes and totally weirdo
* newlines making this look like geocities */
//$description = nl2br(htmlspecialchars($data["event"]["DESCRIPTION"]), false);
if ($url) { /* Google Calendar doesn't have this */
$details = "{$d} - <a href='$url'>{$summary}</a>"; //<br>" . $description;
} else {
$details = "{$d} - $summary";// . $description;
}
}
echo '<dt class="ug"><a href="'. $group["url"].'">' . $group["name"] . "</a></dt><dd>$details</dd>";
}
if (!$matches) {
echo "<dt>Sorry</dt><dd>There are no known User Groups in {$COUNTRIES[$country]} at this time :(</dd>";
}
echo "</dl>";
}
$country = isset($_GET["cc"]) ? $_GET["cc"] : $COUNTRY;
$country_alpha_2 = isset($COUNTRY_ALPHA_3_TO_2[$country]) ? $COUNTRY_ALPHA_3_TO_2[$country] : "NA";
$allcountries = array();
$matches = get_usergroups_in($country_alpha_2, $allcountries);
if (isset($COUNTRIES[$country])) {
print_cc_header($country);
print_ug_matches($matches);
} else {
echo "<h1>Unknown country</h1>";
}
uksort($allcountries, function($first, $second){
global $COUNTRIES;
return strnatcasecmp($COUNTRIES[$first], $COUNTRIES[$second]);
});
$SIDEBAR_DATA = <<< EOF
<p class="panel"><a href="http://php.ug/ug/promote">Register new UG</a></p>
EOF;
foreach($allcountries as $country => $nada) {
$SIDEBAR_DATA .= '<p class="panel"><a href="/ug.php?cc=' . $country . '">' . $COUNTRIES[$country] . '</a></p>';
}
// Print the common footer.
site_footer(
array(
"atom" => "/feed.atom", // Add a link to the feed at the bottom
"sidebar" => $SIDEBAR_DATA,
)
);