This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
137 lines (125 loc) · 3.47 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
require('header.php');
$limit = $thumbs_per_row * $rows_of_thumbs;
$page = (isset($_GET['page']) ? intval($_GET['page']) : 0);
$offset = $limit * $page;
if(isset($_GET['album'])) {
$album = $_GET['album'];
} else {
$album = '/';
}
if(substr($album, -1) != '/') {
$album .= '/';
}
$visibility = false;
if($album == '/') {
$album = '';
$order = 'id DESC';
$humanname = 'Fotoalbum';
$parentalbums = array();
} else {
$row = getUnitByFullPath(substr($album, 0, -1));
if(!$row) {
header('HTTP/1.1 404 Not Found');
die('Album not found');
}
$parentalbums = loadPathAlbums($row['path']);
if(!in_array($row['visibility'], getVisibleVisibilities()) || !isPathVisible($parentalbums)) {
header('HTTP/1.1 403 Access denied');
die('Access denied');
}
$id = $row['id'];
$visibility = $row['visibility'];
$humanname = $row['humanname'];
$order = 'name';
}
$extra_params = '';
if(!empty($_GET['search_album'])) {
// Zoeken op naam album
$keyword = trim($_GET['search_album']);
$res = sql_query("SELECT SQL_CALC_FOUND_ROWS 'album'
AS type, fa_albums.*
FROM fa_albums
WHERE path LIKE %s
AND visibility IN (%S)
AND (name LIKE %s
OR humanname LIKE %s)
ORDER BY ". $order ."
LIMIT %i, %i",
$album.'%', getVisibleVisibilities(),
'%'.$keyword.'%', '%'.$keyword.'%',
$offset, $limit);
$extra_params .= '&search_album='. $keyword;
} elseif(!empty($_GET['search_tag'])) {
// Zoeken op tags
$keyword = trim($_GET['search_tag']);
$res = sql_query("SELECT SQL_CALC_FOUND_ROWS 'photo' AS type, fa_photos.*
FROM fa_photos, fa_tags
WHERE fa_tags.username = %s
AND fa_tags.photo_id = fa_photos.id
AND fa_photos.path LIKE %s
AND fa_photos.visibility IN (%S)
ORDER BY ". $order ."
LIMIT %i, %i",
$keyword, $album.'%', getVisibleVisibilities(),
$offset, $limit);
$extra_params .= '&search_tag='. $keyword;
} else {
$keyword = '';
$res = sql_query("
(SELECT SQL_CALC_FOUND_ROWS
'photo' as `type`, `id`, name,
path, visibility, name as humanname
FROM fa_photos WHERE path=%s AND visibility IN (%S))
UNION (SELECT
'album' as `type`, `id`, name,
path, visibility, humanname
FROM fa_albums WHERE path=%s AND visibility IN (%S))
ORDER BY ". $order ."
LIMIT %i, %i",
$album, getVisibleVisibilities(),
$album, getVisibleVisibilities(), $offset, $limit);
}
$albums = array();
$photos = array();
while($row = mysql_fetch_assoc($res)) {
if($row['type'] == 'album') {
$albums[] = array(
'name' => $row['name'],
'fullpath' => $row['path'] . $row['name'],
'humanname' => $row['humanname'] ? $row['humanname'] : $row['name']
);
} else {
$photos[] = array(
'name' => $row['name'],
'fullpath' => $row['path'] . $row['name'],
);
}
}
$res = sql_query('SELECT FOUND_ROWS()');
$row = mysql_fetch_row($res);
$last = floor($row[0] / $limit);
$mode = 'index';
template_assign('mode');
template_assign('albums');
template_assign('photos');
if($album != '') {
$parentalbum = dirname($album);
if($parentalbum == '.') {
$parentalbum = '';
}
template_assign('parentalbum');
}
template_assign('parentalbums');
template_assign('title', $humanname); // XXX
template_assign('id');
template_assign('visibility');
template_assign('humanname');
// Paging
$url = './?album='. urlencode($album) . $extra_params;
template_assign('url');
template_assign('page');
template_assign('last');
show_template('index.tpl');
require('footer.php');
?>