forked from cternes/Lychee-RSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
78 lines (67 loc) · 2.23 KB
/
index.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
<?php
###
# @author cternes
# @copyright 2014 by cternes
# @version 1.0.0
# @description This plugin generates an RSS feed out of your latest public photos
###
# Config
if (is_readable('config.ini')) {
$config = parse_ini_file('config.ini');
}
else {
die('Error: config.ini not found');
}
# Include
require($config['lychee'] . 'php/define.php');
require($config['lychee'] . 'php/autoload.php');
require($config['lychee'] . 'data/config.php');
require('RssGenerator.php');
require('JsonGenerator.php');
require('DataProvider.php');
require('vendor/autoload.php');
# Set Mime Type
if (!empty($_GET['format']) && $_GET['format'] === "json") {
header('Content-Type: application/json');
} else {
header('Content-type: application/rss+xml');
}
$rssGenerator = new RssGenerator($config);
$jsonGenerator = new JsonGenerator($config);
$dataProvider = new DataProvider($dbHost, $dbUser, $dbPassword, $dbName, $dbTablePrefix);
# If a album name is provided, we'll create a feed only for this album
if(!empty($_GET['album'])) {
$albums = $dataProvider->getPublicAlbums();
$albumId = getAlbumIdByName($albums, $_GET['album']);
if(empty($albumId)) {
die('Could not find a public album with title: ' .$_GET['album'] . '. Please make sure that this album exists and that it is public!');
}
$photos = $dataProvider->getPhotosByAlbum($albumId);
if (!empty($_GET['format']) && $_GET['format'] === "json") {
# Generate RSS as JSON
echo $jsonGenerator->buildJsonFeedForAlbum($_GET['album'], $photos);
} else {
# Generate RSS
echo $rssGenerator->buildRssFeedForAlbum($_GET['album'], $photos);
}
}
# If no album name is provided, we'll create a feed with all public photos
else {
# Get latest photos
$photos = $dataProvider->getPhotostream();
if (!empty($_GET['format']) && $_GET['format'] === "json") {
# Generate RSS as JSON
echo $jsonGenerator->buildJsonFeedLatestPhotos($photos);
} else {
# Generate RSS
echo $rssGenerator->buildRssFeedLatestPhotos($photos);
}
}
function getAlbumIdByName($albums, $name) {
foreach ($albums['content'] as $album) {
if(strtolower($album['title']) === strtolower($name)) {
return $album['id'];
}
}
}
?>