Browse the code
| Revision log Information on the revision | |
|---|---|
| Revision: | 498 (differences) |
| Author: | xbright |
| Log message: |
* 2012 gigayears! 2012 gigayears. Great Scott! |
| Change revision: | |
0
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
<?php // This file is a part of CodingTeam. Take a look at <http://codingteam.org>. // Copyright © 2007-2012 Erwan Briand <erwan@codingteam.net> // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, version 3 only. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public // License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. class View { private $ct_session, $ct_db, $page, $error, $langlist, $lang; public $metatags, $maincontent; function __construct($session, $db, $page, $error, $langlist, $lang) { // Variables $this->ct_session = $session; $this->ct_db = $db; $this->page = $page; $this->error = $error; $this->langlist = $langlist; $this->lang = $lang; // Security if (!$this->ct_session->isLogged()) $this->error->displayError(i18n('Please log-in…'), 0); // Create user directory $user = getUser($_SESSION['id'], $this->ct_db); $nickname = htmlspecialchars($user->getNickname()); $this->folder = CT_BASEDIR.'/public/upload/briefcase/'.$nickname; if (!file_exists($this->folder)) mkdir($this->folder, 0755, TRUE); // Preferences $cfg = getClass('config', $this->ct_db); $this->quota = $cfg->get('global', 'briefcase-max'); // Walk $this->content = array(); $this->size = 0; $this->files = 0; $dir = opendir($this->folder); while ($file = readdir($dir)) if (!in_array($file, array('.', '..'))) { $f = $this->folder.'/'.$file; $s = filesize($f); $l = 'users/briefcase/'.$nickname.'/'.$file; $this->size += $s; $this->files ++; array_push($this->content, array(format_size($s), $file, $l)); } closedir($dir); // Meta tags $this->metatags = array('title' => i18n('Briefcase')); } function showFeed() { } function treatForms() { $this->form_error = 0; $form_quota = $this->quota * 1000000; // Clean POST values foreach ($_POST as $key => $value) if (!is_scalar($value)) exit('Error.'); if (isset($_POST['delete-file'])) { $file = $this->ct_db->cleanentry($_POST['delete-file'], TRUE); if (file_exists($this->folder.'/'.$file)) unlink($this->folder.'/'.$file); Header('Location: '.CT_BASEURL.'users/briefcase'); } elseif (isset($_FILES['file_upload'])) { if (($this->size >= $form_quota)) $this->form_error = i18n('Your quota is exceeded.'); $content_dir = $this->folder.'/'; $tmp_file = $_FILES['file_upload']['tmp_name']; if(!is_uploaded_file($tmp_file)) $this->form_error = i18n('File not found.'); if(preg_match('#[\x00-\x1F\x7F-\x9F/\\\\]#', $_FILES['file_upload']['name'])) exit('Error: Unidentified error occurred.'); $filename = strtolower($_FILES['file_upload']['name']); if (file_exists($content_dir.$filename)) $this->form_error = i18n('This file already exists!'); if (!$this->form_error) { if(!move_uploaded_file($tmp_file, $content_dir.$filename)) $this->form_error = i18n('Error when trying to upload file.'); Header('Location: '.CT_BASEURL.'users/briefcase'); } } } function constructView() { $construct = array(); $construct['__tpl__'] = 'briefcase.tpl'; $construct['form_error'] = $this->form_error; $construct['quota'] = $this->quota; $construct['size'] = round($this->size / 1000000, 1); $construct['nb'] = $this->files; $construct['files'] = $this->content; return $construct; } } ?>

CodingTeam