Moving to GitHub.
[platal.git] / include / validations / photos.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2014 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 // {{{ class PhotoReq
23
24 class PhotoReq extends ProfileValidate
25 {
26 // {{{ properties
27
28 public $mimetype;
29 public $data;
30 public $x;
31 public $y;
32
33 public $unique = true;
34 public $valid = false;
35
36 public $rules = "Refuser les photos copyrightées, de mineurs, ou ayant
37 un caractère pornographique, violent&hellip; Si une photo est mal
38 cadrée (20% de photo et 80% de blanc par exemple), si c'est un
39 camarade antique, on lui arrange sinon on lui
40 refuse en lui expliquant gentiment le problème. Idem si les dimensions de
41 la photo sont archi trop grandes ou archi trop petites.";
42
43 // }}}
44 // {{{ constructor
45
46 public function __construct(User $_user, Profile $_profile, PlUpload $upload, $_stamp = 0)
47 {
48 parent::__construct($_user, $_profile, true, 'photo', $_stamp);
49 $this->read($upload);
50 }
51
52 // }}}
53 // {{{ function read
54
55 private function read(PlUpload $upload)
56 {
57 $this->valid = $upload->resizeImage(240, 300, 160, 0, SIZE_MAX);
58 if (!$this->valid) {
59 $this->trigError('Le fichier que tu as transmis n\'est pas une image valide, ou est trop gros pour être traité.');
60 }
61 $this->data = $upload->getContents();
62 list($this->x, $this->y, $this->mimetype) = $upload->imageInfo();
63 $upload->rm();
64 }
65
66 // }}}
67 // {{{ function isValid()
68
69 public function isValid()
70 {
71 return $this->valid;
72 }
73
74 // }}}
75 // {{{ function get_request()
76
77 static public function get_request($pid)
78 {
79 return parent::get_typed_request($pid, 'photo');
80 }
81
82 // }}}
83 // {{{ function formu()
84
85 public function formu()
86 {
87 return 'include/form.valid.photos.tpl';
88 }
89
90 // }}}
91 // {{{ function editor()
92
93 public function editor()
94 {
95 return 'include/form.valid.edit-photo.tpl';
96 }
97
98 // }}}
99 // {{{ function handle_editor()
100
101 protected function handle_editor()
102 {
103 if (isset($_FILES['userfile'])) {
104 $upload =& PlUpload::get($_FILES['userfile'], S::user()->login(), 'photo');
105 if (!$upload) {
106 $this->trigError('Une erreur est survenue lors du téléchargement du fichier.');
107 return false;
108 }
109 $this->read($upload);
110 return $this->valid;
111 }
112 return false;
113 }
114
115 // }}}
116 // {{{ function _mail_subj
117
118 protected function _mail_subj()
119 {
120 return "[Polytechnique.org/PHOTO] Changement de photo";
121 }
122
123 // }}}
124 // {{{ function _mail_body
125
126 protected function _mail_body($isok)
127 {
128 if ($isok) {
129 return "Le changement de photo que tu as demandé vient d'être effectué.";
130 } else {
131 return "La demande de changement de photo que tu avais faite a été refusée.";
132 }
133 }
134
135 // }}}
136 // {{{ function commit()
137
138 public function commit()
139 {
140 XDB::execute('INSERT INTO profile_photos (pid, attachmime, attach, x, y)
141 VALUES ({?}, {?}, {?}, {?}, {?})
142 ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach),
143 x = VALUES(x), y = VALUES(y)',
144 $this->profile->id(), $this->mimetype, $this->data, $this->x, $this->y);
145
146 return true;
147 }
148
149 // }}}
150 }
151
152 // }}}
153
154 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
155 ?>