Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 Polytechnique.org * |
0337d704 | 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 | ||
c3d1e6b6 | 24 | class PhotoReq extends ProfileValidate |
0337d704 | 25 | { |
26 | // {{{ properties | |
63528107 | 27 | |
612a2d8a | 28 | public $mimetype; |
29 | public $data; | |
30 | public $x; | |
31 | public $y; | |
0337d704 | 32 | |
612a2d8a | 33 | public $unique = true; |
34 | public $valid = false; | |
0337d704 | 35 | |
612a2d8a | 36 | public $rules = "Refuser les photos copyrightées, de mineurs, ou ayant |
6e828e47 | 37 | un caractère pornographique, violent… Si une photo est mal |
612a2d8a | 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."; | |
0337d704 | 42 | |
43 | // }}} | |
44 | // {{{ constructor | |
63528107 | 45 | |
26ba053e | 46 | public function __construct(User $_user, Profile $_profile, PlUpload $upload, $_stamp = 0) |
0337d704 | 47 | { |
c3d1e6b6 | 48 | parent::__construct($_user, $_profile, true, 'photo', $_stamp); |
abe7e055 | 49 | $this->read($upload); |
5af85e81 | 50 | } |
51 | ||
52 | // }}} | |
abe7e055 | 53 | // {{{ function read |
5af85e81 | 54 | |
26ba053e | 55 | private function read(PlUpload $upload) |
5af85e81 | 56 | { |
eaf30d86 | 57 | $this->valid = $upload->resizeImage(240, 300, 160, 0, SIZE_MAX); |
abe7e055 | 58 | if (!$this->valid) { |
c3d1e6b6 | 59 | $this->trigError('Le fichier que tu as transmis n\'est pas une image valide, ou est trop gros pour être traité.'); |
0337d704 | 60 | } |
abe7e055 | 61 | $this->data = $upload->getContents(); |
62 | list($this->x, $this->y, $this->mimetype) = $upload->imageInfo(); | |
63 | $upload->rm(); | |
0337d704 | 64 | } |
eaf30d86 | 65 | |
0337d704 | 66 | // }}} |
c3d1e6b6 | 67 | // {{{ function isValid() |
eef2d586 | 68 | |
612a2d8a | 69 | public function isValid() |
eef2d586 | 70 | { |
71 | return $this->valid; | |
72 | } | |
73 | ||
74 | // }}} | |
0337d704 | 75 | // {{{ function get_request() |
76 | ||
c3d1e6b6 | 77 | static public function get_request($pid) |
0337d704 | 78 | { |
c3d1e6b6 | 79 | return parent::get_typed_request($pid, 'photo'); |
0337d704 | 80 | } |
81 | ||
82 | // }}} | |
83 | // {{{ function formu() | |
84 | ||
612a2d8a | 85 | public function formu() |
86 | { | |
87 | return 'include/form.valid.photos.tpl'; | |
88 | } | |
0337d704 | 89 | |
90 | // }}} | |
5af85e81 | 91 | // {{{ function editor() |
92 | ||
612a2d8a | 93 | public function editor() |
5af85e81 | 94 | { |
95 | return 'include/form.valid.edit-photo.tpl'; | |
96 | } | |
97 | ||
98 | // }}} | |
99 | // {{{ function handle_editor() | |
100 | ||
612a2d8a | 101 | protected function handle_editor() |
5af85e81 | 102 | { |
abe7e055 | 103 | if (isset($_FILES['userfile'])) { |
f3df6d38 | 104 | $upload =& PlUpload::get($_FILES['userfile'], S::user()->login(), 'photo'); |
abe7e055 | 105 | if (!$upload) { |
c3d1e6b6 | 106 | $this->trigError('Une erreur est survenue lors du téléchargement du fichier.'); |
abe7e055 | 107 | return false; |
5af85e81 | 108 | } |
abe7e055 | 109 | $this->read($upload); |
110 | return $this->valid; | |
5af85e81 | 111 | } |
abe7e055 | 112 | return false; |
5af85e81 | 113 | } |
114 | ||
115 | // }}} | |
0337d704 | 116 | // {{{ function _mail_subj |
117 | ||
612a2d8a | 118 | protected function _mail_subj() |
0337d704 | 119 | { |
120 | return "[Polytechnique.org/PHOTO] Changement de photo"; | |
121 | } | |
122 | ||
123 | // }}} | |
124 | // {{{ function _mail_body | |
63528107 | 125 | |
612a2d8a | 126 | protected function _mail_body($isok) |
0337d704 | 127 | { |
128 | if ($isok) { | |
a7de4ef7 | 129 | return "Le changement de photo que tu as demandé vient d'être effectué."; |
0337d704 | 130 | } else { |
a7de4ef7 | 131 | return "La demande de changement de photo que tu avais faite a été refusée."; |
0337d704 | 132 | } |
133 | } | |
134 | ||
135 | // }}} | |
136 | // {{{ function commit() | |
63528107 | 137 | |
612a2d8a | 138 | public function commit() |
0337d704 | 139 | { |
00ba8a74 SJ |
140 | XDB::execute('INSERT INTO profile_photos (pid, attachmime, attach, x, y) |
141 | VALUES ({?}, {?}, {?}, {?}, {?}) | |
85dce290 | 142 | ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), |
00ba8a74 | 143 | x = VALUES(x), y = VALUES(y)', |
c3d1e6b6 | 144 | $this->profile->id(), $this->mimetype, $this->data, $this->x, $this->y); |
ef071632 | 145 | |
0337d704 | 146 | return true; |
147 | } | |
148 | ||
149 | // }}} | |
150 | } | |
151 | ||
152 | // }}} | |
153 | ||
a7de4ef7 | 154 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 155 | ?> |