-
Notifications
You must be signed in to change notification settings - Fork 2
/
images.php
113 lines (86 loc) · 3.17 KB
/
images.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
<?php
/*
#####################################################
Builds XML file for a gallery based on the filesystem
FileName: images.php
Author: Uptonic
Version: 2011.05.16
#####################################################
*/
// Include class file
require_once(dirname(__FILE__).'/scripts/protos.utils.php');
require_once(dirname(__FILE__).'/scripts/function.recurse.php');
require_once(dirname(__FILE__).'/scripts/config.php');
// Get file structure
$albums = scan_directory_recursively('albums');
// Let's build some XML
$doc = new DOMDocument("1.0", "UTF-8");
$doc->formatOutput = TRUE;
// Create root node for the gallery
$r = $doc->createElement( "gallery" );
$doc->appendChild($r);
// Cycle through albums
foreach($albums as $album) {
// Ignore albums that don't contain content
if($album['content'] != NULL){
// New album tag
$a = $doc->createElement('album');
$a->setAttribute('name', $album['name']);
$a->setAttribute('modified', $album['modified']);
// Expecting subfolders like "prototypes" and "wireframes"
foreach($album['content'] as $category) {
// Ignore categories that don't contain any prototypes
if($category['content'] != NULL){
// New category tag
$c = $doc->createElement('category');
$c->setAttribute('name', $category['name']);
$c->setAttribute('modified', $category['modified']);
// Sort the date sets so newest is first
$category['content'] = orderDesc($category['content'], 'name');
// Build the list of images in each album
foreach($category['content'] as $set) {
// Ignore any datefolder that doesn't contain images
if($set['content'] != NULL){
// New subfolder tag
$g = $doc->createElement('set');
$g->setAttribute('name', $set['name']);
$g->setAttribute('modified', $set['modified']);
// Sort the images so newest is first
$set['content'] = orderAsc($set['content'], 'file');
foreach($set['content'] as $image) {
if($image['extension'] == "txt"){
// Read in text file and use contents for description
$f = $image['path'].'/'.$image['file'];
$fh = fopen($f, 'r');
$contents = fread($fh, filesize($f));
fclose($fh);
// Add description attribute to this set if available
$g->setAttribute('description', $contents);
} else {
$img = $doc->createElement('img');
//$img->setAttribute('path', $image['path']);
$img->setAttribute('src', $image['file']);
$img->setAttribute('width', $image['width']);
$img->setAttribute('height', $image['height']);
$img->setAttribute('title', getImageTitle($image['file']));
$img->setAttribute('data-extension', $image['extension']);
$img->setAttribute('data-last-modified', $image['modified']);
$g->appendChild($img);
}
}
$c->appendChild($g);
}
}
// Close the category tag
$a->appendChild($c);
}
}
// Close the album tag
$r->appendChild($a);
}
}
//header('Content-Type: text/xml');
//echo $doc->saveXML();
$doc->save("images.xml");
header('Location: images_success.php');
?>