This repository was archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.php
More file actions
88 lines (73 loc) · 2.78 KB
/
Copy pathfeed.php
File metadata and controls
88 lines (73 loc) · 2.78 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
<?php
header("Content-Type: application/rss+xml; charset=UTF-8");
# Use the Curl extension to query the URL and get back a page of results
$url = "https://www.studiareinformatica.uniroma1.it";
# Init the Curl process
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url . "/avvisi");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
# store in $HTML array the curl output
$html = curl_exec($ch);
curl_close($ch);
# Create a DOM parser object
$dom = new DOMDocument();
# Parse the HTML from array.
# The @ before the method call suppresses any warnings that
# loadHTML might throw because of invalid HTML in the page.
@$dom->loadHTML($html);
#Init the rssfeed variable
$rssfeed = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$rssfeed .= '<rss version="2.0">' . "\n";
$rssfeed .= '<channel>' . "\n";
$rssfeed .= "\t" . '<title>Università La Sapienza</title>' . "\n";
$rssfeed .= "\t" . '<link>https://www.gasparini.cloud/sapienza-feed</link>' . "\n";
$rssfeed .= "\t" . '<description>Bacheca Avvisi - Corso di Laurea in Informatica</description>' . "\n";
$rssfeed .= "\t" . '<language>it-IT</language>' . "\n";
$rssfeed .= "\t" . '<copyright>Copyright (C) 2018 gasparini.cloud</copyright>' . "\n";
$rssfeed .= "\t" . '<lastBuildDate>' . date("D, d M Y H:i:s O") . '</lastBuildDate>' . "\n";
#Init the temp array
$array = array();
$count = 0;
# Iterate over all the <span> tags
# the even spans are title entries, while the odd ones are date entries
# e.g. array[0] = "Avviso numero 1"; array[1] = "16/03/2021";
# array[2] = "Avviso numero 2"; array[3] = "17/03/2021";
foreach($dom->getElementsByTagName('span') as $link)
{
$array[$count] = array();
$array[$count] = $link->nodeValue;
$count++;
}
$count = 0;
while ($count < count($array))
{
$description = $array[$count];
$count++;
$data_description = $array[$count];
$count++;
$new_date = date_create_from_format('d/m/Y', $data_description);
$data_description = date_format($new_date, 'Y-m-d');
$hyperlink = "";
foreach($dom->getElementsByTagName('a') as $anchor)
{
if(strcmp($anchor->nodeValue, $description) == 0)
{
$hyperlink = $anchor->getAttribute('href');
break;
}
}
$rssfeed .= "\n";
$rssfeed .= "\t" . '<item>' . "\n";
$rssfeed .= "\t" . '<title>' . $description. '</title>' . "\n";
$rssfeed .= "\t" . '<description>' . $description. '</description>' . "\n";
$rssfeed .= "\t" . '<link>' . $url . $hyperlink. '</link>' . "\n";
#$DATA = str_replace('/', '-', $DATA);
$rssfeed .= "\t" . '<pubDate>' . date("D, d M Y H:i:s O", strtotime($data_description)). '</pubDate>' . "\n";
$rssfeed .= "\t" . '</item>' . "\n";
}
$rssfeed .= '</channel>' . "\n";
$rssfeed .= '</rss>' . "\n";
echo $rssfeed;
?>