forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
public.php
310 lines (268 loc) · 8.56 KB
/
public.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
/**
* Shows the list of public groups and files
*
* @package ProjectSend
* @subpackage Files
*
*/
$allowed_levels = array(9,8,7,0);
require_once('bootstrap.php');
/**
* If the option to show this page is not enabled, redirect
*/
if ( PUBLIC_LISTING_PAGE_ENABLE != 1 ) {
header("location:" . BASE_URI . "index.php");
die();
}
/**
* Check the option to show the page to logged in users only
*/
if ( PUBLIC_LISTING_LOGGED_ONLY == 1 ) {
check_for_session();
}
/**
* Temp? Mode defines if current view is loose files or a group
*/
$mode = 'files';
/**
* If viewing a particular group, make sure it's public
*/
if (!empty($_GET['token']) && !empty($_GET['id'])) {
$got_group = $_GET['id'];
$got_token = $_GET['token'];
$can_view_group = false;
$test_group = get_group_by_id( $got_group );
if ( $test_group['public_token'] == $got_token ) {
if ( $test_group['public'] == 1 ) {
$can_view_group = true;
}
}
if ( !$can_view_group ) {
header("location:" . BASE_URI . "index.php");
die();
}
$mode = 'group';
}
$page_title = __('Public groups and files','cftp_admin');
$dont_redirect_if_logged = 1;
include_once ADMIN_TEMPLATES_DIR . DS . 'header-unlogged.php';
/**
* General function that defines the formating of files lines
*/
function list_file($data, $origin) {
$show = false;
if ( $origin == 'group' && PUBLIC_LISTING_SHOW_ALL_FILES == 1 ) {
}
else {
if ( $data['public'] != 1 ) {
return;
}
}
$output = '<li class="file"><i class="fa fa-file-o" aria-hidden="true"></i> ';
if ( PUBLIC_LISTING_USE_DOWNLOAD_LINK == 1 && $data['expired'] != true && $data['public'] == 1 ) {
$download_link = BASE_URI . 'download.php?id=' . $data['id'] . '&token=' . $data['token'];
$output .= '<a href="' . $download_link . '">' . $data['filename'] . '</a>';
}
else {
$output .= $data['filename'];
}
$output .= '</li>';
return $output;
}
?>
<div class="col-xs-12 col-sm-12 col-lg-6 col-lg-offset-3">
<div class="row">
<div class="col-xs-12 branding_unlogged">
<?php echo get_branding_layout(); ?>
</div>
</div>
<div class="white-box">
<div class="white-box-interior">
<div class="text-center">
<?php
switch ( $mode ) {
case 'files':
$title = __('Public groups and files','cftp_admin');
$desc = ''; //__('Public navigation','cftp_admin');
break;
case 'group':
$title = $test_group['name'];
$desc = $test_group['description'];
break;
}
?>
<h3><?php echo $title; ?></h3>
<div class="intro">
<?php echo $desc; ?>
</div>
</div>
<div class="treeview">
<div class="listing">
<ul>
<?php
/**
* 1- Make a list of files IDs
*/
$all_files = array();
$public_files = array();
$expired_files = array();
$remove_files = array(); // used to remove file ids from the complete list after showing the groups so the files don't appear again on the list.
$files_sql = "SELECT * FROM " . TABLE_FILES;
/** All files or just the public ones? */
if ( PUBLIC_LISTING_SHOW_ALL_FILES != 1 && $mode != 'group' ) {
$files_sql .= " WHERE public_allow=1";
}
$sql = $dbh->prepare($files_sql);
$sql->execute();
$sql->setFetchMode(PDO::FETCH_ASSOC);
while ( $row = $sql->fetch() ) {
/** Does it expire? */
$add_file = true;
$expired = false;
if ($row['expires'] == '1') {
if (time() > strtotime($row['expiry_date'])) {
if (EXPIRED_FILES_HIDE == '1') {
$add_file = false;
}
$expired = true;
}
}
if ($add_file == true) {
$filename_on_disk = (!empty( $row['original_url'] ) ) ? $row['original_url'] : $row['url'];
$all_files[$row['id']] = array(
'id' => encode_html($row['id']),
'filename' => encode_html($filename_on_disk),
'title' => encode_html($row['filename']),
'public' => encode_html($row['public_allow']),
'token' => encode_html($row['public_token']),
'expired' => $expired,
'expire_date' => encode_html($row['expiry_date']),
);
if ( $row['public_allow'] == 1 ) {
$public_files[] = $row['id'];
}
}
else {
$expired_files[] = $row['id'];
}
}
//print_array($all_files);
/**
* 2- Get public groups
*/
$groups = array();
$get_groups = new \ProjectSend\GroupActions();
$get_arguments = array(
'public' => true,
);
$found_groups = $get_groups->get_groups($get_arguments);
foreach ($found_groups as $group_id => $group_data) {
$groups[$group_id] = array(
'id' => $group_data['id'],
'name' => $group_data['name'],
'token' => $group_data['public_token'],
'files' => array(),
);
/**
* 3- Get list of files from this group
*/
$group_files = array();
$files_groups_sql = "SELECT id, file_id, client_id, group_id FROM " . TABLE_FILES_RELATIONS . " WHERE group_id=:group_id AND hidden = '0'";
// Don't include private files
if ( PUBLIC_LISTING_SHOW_ALL_FILES != 1 ) {
$files_groups_sql .= " AND FIND_IN_SET(file_id, :public_files)";
}
// Don't include expired files
if (EXPIRED_FILES_HIDE == '1') {
$files_groups_sql .= " AND !FIND_IN_SET(file_id, :excluded_files)";
}
$sql = $dbh->prepare($files_groups_sql);
$sql->bindParam(':group_id', $group_id, PDO::PARAM_INT);
if ( PUBLIC_LISTING_SHOW_ALL_FILES != 1 ) {
$included_files = implode( ',', array_map( 'intval', array_unique( $public_files ) ) );
$sql->bindParam(':public_files', $included_files);
}
if (EXPIRED_FILES_HIDE == '1') {
$excluded_files = implode( ',', array_map( 'intval', array_unique( $expired_files ) ) );
$sql->bindParam(':excluded_files', $excluded_files);
}
$sql->execute();
$sql->setFetchMode(PDO::FETCH_ASSOC);
while ( $row = $sql->fetch() ) {
$groups[$group_id]['files'][$row['file_id']] = $all_files[$row['file_id']];
$remove_files[] = $row['file_id'];
}
}
/**
* Removes from the array of files those that are on, at least, one group
* so in the list of groupless files they are not repeated.
* Done here so if a file is on 2 groups, it won't get removed from any of them.
*/
foreach ( $remove_files as $file_id ) {
unset($all_files[$file_id]);
}
//print_r($groups);
//print_r($all_files);
/**
* Finally, generate the list
* 1- Groups
*/
switch ( $mode ) {
/**
* 1- Loose files
*/
case 'files':
if ( empty( $all_files ) && empty( $groups ) ) {
_e("There are no files available.",'cftp_admin');
}
else {
foreach ( $groups as $group ) {
$group_link = PUBLIC_GROUP_URI . '?group=' . $group['id'] . '&token=' . $group['token'];
?>
<li>
<a href="<?php echo $group_link; ?>">
<i class="fa fa-th-large fa-fw" aria-hidden="true"></i> <?php echo $group['name']; ?>
</a>
</li>
<?php
}
foreach ( $all_files as $id => $file_info) {
echo list_file($file_info, 'loose');
}
}
break;
/**
* 2- Group files
*/
case 'group':
if ( !empty( $groups[$test_group['id']]['files'] ) ) {
foreach ( $groups[$test_group['id']]['files'] as $id => $file_info) {
echo list_file($file_info, 'group');
}
}
else {
_e("There are no files available.",'cftp_admin');
}
break;
}
//print_array($all_files);
?>
</ul>
</div>
</div>
</div>
</div>
<div class="login_form_links">
<?php
if ( !check_for_session(false) && CLIENTS_CAN_REGISTER == '1') {
?>
<p id="register_link"><?php _e("Don't have an account yet?",'cftp_admin'); ?> <a href="<?php echo BASE_URI; ?>register.php"><?php _e('Register as a new client.','cftp_admin'); ?></a></p>
<?php
}
?>
<p><a href="<?php echo BASE_URI; ?>" target="_self"><?php _e('Go back to the homepage.','cftp_admin'); ?></a></p>
</div>
</div>
<?php
include_once ADMIN_TEMPLATES_DIR . DS . 'footer.php';