-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.php
More file actions
120 lines (86 loc) · 3.89 KB
/
Copy pathfeed.php
File metadata and controls
120 lines (86 loc) · 3.89 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
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
require_once 'vendor/autoload.php';
use Suin\RSSWriter\Channel;
use Suin\RSSWriter\Feed;
use Suin\RSSWriter\Item;
// Configs for MyAEGEE retriving.
$config = new stdClass();
$config->api_url = "https://my.aegee.eu/api/events?limit=50&offset=0&starts=" . date('Y-m-d');
$config->cache = __DIR__ . "/json.cache"; // make this file in same dir
$config->force_refresh = false; // dev
$config->refresh = 60 * 60; // once an hour
function retrive_events_from_myaegee() {
global $config;
if ($config->force_refresh || !file_exists($config->cache) || ((time() - filectime($config->cache)) > ($config->refresh) || 0 == filesize($config->cache))) {
// The cache is invalid or expired, retriving from MyAEGEE
$ch = curl_init($config->api_url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$curlcontent = curl_exec($ch);
curl_close($ch);
$handle = fopen($config->cache, 'wb') or die('no fopen');
// Put the data in cache.
$json_cache = $curlcontent;
fwrite($handle, $json_cache);
fclose($handle);
}
else {
// The data is cached.
$json_cache = file_get_contents($config->cache);
}
// If we have some data, cached or not, return it.
if (!empty($json_cache)) {
$response = json_decode($json_cache);
return $response->data;
}
else {
return FALSE;
}
}
$feed = new Feed();
$channel = new Channel();
$channel
->title('AEGEE European events')
->description('All the european events from MyAEGEE')
->url('https://my.aegee.eu/calendar')
->language('en-US')
->lastBuildDate(time())
->ttl(60)
->appendTo($feed);
$events = retrive_events_from_myaegee();
foreach ($events as $event) {
// Skip events not open for application
if ($event->application_status == 'closed') continue;
$item = new Item();
$custom_description = '';
$bodies = [];
foreach ($event->organizing_bodies as $body) {
$bodies[]= $body->body_name;
}
//if (!empty($event->image)) {
// $custom_description .= '<img src="https://my.aegee.eu/media/events/headimages/' . $event->image . '"/>';
//}
$bodies_string = join(' and ', array_filter(array_merge(array(join(', ', array_slice($bodies, 0, -1))), array_slice($bodies, -1)), 'strlen'));
$custom_description .= "<br/>\n";
$custom_description .= '<p>▶ Event type: <strong>' . strtoupper($event->type) ."</strong></p><br/>\n";
$custom_description .= '<p>🌐 Organized by <strong>' . $bodies_string . "</strong></p><br/>\n";
$custom_description .= '<p>📆 From <strong>' . date('j F Y', strtotime($event->starts)) . '</strong> to <strong>' . date('j F Y', strtotime($event->ends)) . "</strong></p><br/>\n";
$custom_description .= '<p>⏰ Apply from <strong>' . date('j F Y', strtotime($event->application_starts)) . '</strong> to <strong>' . date('j F Y', strtotime($event->application_ends)) . "</strong></p><br/>\n";
$custom_description .= '<p>👫 Participants: <strong>' . $event->max_participants . "</strong></p><br/>\n";
$custom_description .= '<p>💰 Fee: <strong>' . $event->fee . " €</strong></p>\n";
$item
->title($event->name)
->description($custom_description)
//->contentEncoded($custom_description)
->url('https://my.aegee.eu/events/' . $event->url)
->creator('MyAEGEE')
->pubDate(strtotime($event->application_starts))
->guid('https://my.aegee.eu/events/' . $event->id, TRUE)
->preferCdata(TRUE) // By this, title and description become CDATA wrapped HTML.
->appendTo($channel);
}
header("Content-type: application/xml");
echo $feed->render();