forked from php/web-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ug.php
121 lines (107 loc) · 3.73 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
<?php
// $Id$
$_SERVER['BASE_PAGE'] = 'ug.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc';
site_header("Hypertext Preprocessor",
array(
'current' => 'community',
'css' => array('home.css'),
//'intro' => $intro
)
);
$json = file_get_contents("./include/events.json");
$all = json_decode($json, true);
$groupped = array_fill_keys(array_keys($COUNTRIES), array("ug" => array(), "conf" => array()));
foreach($all as $type => $event) {
$category = $event["category"] == 1 ? "ug" : "conf";
$groupped[$event["country"]][$category][] = $event;
}
function format_event_date($starts, $ends, $usually) {
if ($ends) {
$starts = date_format(date_create($starts), 'F jS, Y');
$ends = date_format(date_create($ends), 'F jS, Y');
return "$starts to $ends";
}
if ($starts && !$usually) {
$starts = date_format(date_create($starts), 'Y-m-d');
return $starts;
}
$days = array(1 => "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$recur = array(
-3 => "third last",
-2 => "second last",
-1 => "last",
1 => "first",
2 => "second",
3 => "third",
4 => "fourth",
);
list($rec, $day) = explode(":", $usually);
$time = strtotime($recur[$rec]. " " . $days[$day] . " of this month");
if ($time > strtotime("tomorrow")) {
$time = strtotime($recur[$rec]. " " . $days[$day] . " of next month");
}
return date_format(date_create("@$time"), "l, F jS, Y");
}
$SIDEBAR = "";
$content = "";
$first = false;
foreach($groupped as $country => $events) {
if (!$events["ug"] && !$events["conf"]) continue;
$countrycode = $COUNTRIES[$country];
$SIDEBAR .= '<p class="panel"><a href="#' . $country . '">' . $countrycode . '</p>';
$entry = "";
$entry .= '<div class="mirror" id="' . $country. '">';
$entry .= '<div class="title">' . $countrycode;
$entry .= '<img alt="' . $countrycode . '" height="25" width="45" src="' . $_SERVER['STATIC_ROOT'] . '/images/flags/beta/' . strtolower($country) . '.png">';
$entry .= '</div>';
if ($events["ug"]) {
$entry .= "<h2>User Groups in $countrycode</h2>";
}
foreach($events["ug"] as $event) {
$link = $event["url"];
$date = format_event_date($event["sdato"], $event["edato"], $event["recur"]);
$entry .= '<div class="newsentry">';
$entry .= '<h3 class="newstitle"><a href="'. $link .'">' . $event["sdesc"];
$entry .= "<div class='newstime'>$date</div>";
$entry .= '</a>'.'</h3>';
$entry .= '<div class="newscontent">';
$entry .= nl2br($event["ldesc"]);
$entry .= '</div>';
$entry .= '</div>';
}
if ($events["conf"]) {
$entry .= "<h2>Conferences in $countrycode</h2>";
}
foreach($events["conf"] as $event) {
$link = $event["url"];
$date = format_event_date($event["sdato"], $event["edato"], $event["recur"]);
$entry .= '<div class="newsentry">';
$entry .= '<h3 class="newstitle"><a href="'. $link .'">' . $event["sdesc"];
$entry .= "<div class='newstime'>$date</div>";
$entry .= '</a>'.'</h3>';
$entry .= '<div class="newscontent">';
$entry .= $event["ldesc"];
$entry .= '</div>';
$entry .= '</div>';
}
$entry .= "</div>";
if ($COUNTRY == $country) {
$first = $entry;
}
$content .= $entry;
}
echo "<div class='home-content'>";
if ($first) {
echo $first;
}
echo $content;
echo "</div>";
// Print the common footer.
site_footer(
array(
"atom" => "/feed.atom", // Add a link to the feed at the bottom
//'elephpants' => true,
'sidebar' => $SIDEBAR
)
);