-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmedia-rss.php
executable file
·122 lines (100 loc) · 3.31 KB
/
media-rss.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
<?php
/**
* Media RSS presenting the pictures in counter chronological order.
*
* @author Vincent Prat (http://www.vincentprat.info)
*
* @param mode The content we want to display (last_pictures|gallery|album).
* Defaults to last_pictures.
*
* Parameters for mode = last_pictures
*
* @param page The current picture ID (defaults to 0)
* @param show The number of pictures to include in one field (default 10)
*
* Parameters for mode = gallery
*
* @param gid The gallery ID to show (defaults to first gallery)
* @param prev_next Whether to link to previous and next galleries (true|false).
* Default to false.
*
* Parameters for mode = album
*
* @param aid The album ID to show
*/
require_once(dirname(__FILE__) . "/../lib/media-rss.php");
// Check we have the required GET parameters
$mode = isset ($_GET['mode']) ? $_GET['mode'] : 'last_pictures';
// Act according to the required mode
$rss = '';
if ( $mode == 'last_pictures' ) {
// Get additional parameters
$page = isset ($_GET['page']) ? (int) $_GET['page'] : 0;
$show = isset ($_GET['show']) ? (int) $_GET['show'] : 10;
$rss = nggMediaRss::get_last_pictures_mrss($page, $show);
} else if ( $mode == 'gallery' ) {
// Get all galleries
$galleries = $nggdb->find_all_galleries();
if ( count($galleries) == 0 ) {
header('content-type:text/plain;charset=utf-8');
echo sprintf(__("No galleries have been yet created.","nggallery"), $gid);
exit;
}
// Get additional parameters
$gid = isset ($_GET['gid']) ? (int) $_GET['gid'] : 0;
//if no gid is present, take the first gallery
if ( $gid == 0 ) {
$first = current($galleries);
$gid = $first->gid;
}
// Set the main gallery object
$gallery = $galleries[$gid];
if (!isset($gallery) || $gallery==null) {
header('content-type:text/plain;charset=utf-8');
echo sprintf(__("The gallery ID=%s does not exist.","nggallery"), intval($gid) );
exit;
}
// show other galleries if needed
$prev_next = ( isset($_GET['prev_next']) && $_GET['prev_next'] == 'true' ) ? true : false;
$prev_gallery = $next_gallery = null;
// Get previous and next galleries if required
if ($prev_next) {
reset($galleries);
while( current($galleries) ){
if( key($galleries) == $gid )
break;
next($galleries);
}
// one step back
$prev_gallery = prev( $galleries);
// two step forward... Could be easier ? How ?
next($galleries);
$next_gallery = next($galleries);
}
$rss = nggMediaRss::get_gallery_mrss($gallery, $prev_gallery, $next_gallery);
} else if ( $mode == 'album' ) {
// Get additional parameters
$aid = isset ($_GET['aid']) ? (int) $_GET['aid'] : 0;
if ( $aid == 0 ) {
header('content-type:text/plain;charset=utf-8');
_e("No album ID has been provided as parameter", "nggallery");
exit;
}
// Get the album object
$album = nggdb::find_album($aid);
if (!isset($album) || $album==null ) {
header('content-type:text/plain;charset=utf-8');
echo sprintf(__("The album ID=%s does not exist.", "nggallery"), intval($aid) );
exit;
}
$rss = nggMediaRss::get_album_mrss($album);
} else {
header('content-type:text/plain;charset=utf-8');
echo __('Invalid MediaRSS command', 'nggallery');
exit;
}
// Output header for media RSS
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n";
echo $rss;
?>