2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
24 class PhotoReq
extends Validate
35 var $rules = "Refuser les photos copyrightées, de mineurs, ou ayant
36 un caractère pornographique, violent, etc... Si une photo est mal
37 cadrée (20% de photo et 80% de blanc par exemple), si c'est un
38 camarade antique, on lui arrange sinon on lui
39 refuse en lui expliquant gentiment le problème. Idem si les dimensions de
40 la photo sont archi trop grandes ou archi trop petites.";
45 function PhotoReq($_uid, $_data, $_stamp=0)
47 $this->Validate($_uid, true
, 'photo', $_stamp);
48 if (!$this->_get_image($_data)) {
49 return ($this = null
);
54 // {{{ function _get_image()
56 function _get_image($_data)
60 // calcul de la taille de l'image
61 require_once dirname(__FILE__
).'/../../classes/VarStream.php';
62 $GLOBALS['photoreq'] = $_data;
63 $image_infos = getimagesize('var://photoreq');
64 unset ($GLOBALS['photoreq']);
66 if (empty($image_infos)) {
67 $page->trig("Image invalide");
70 list($this->x
, $this->y
, $this->mimetype
) = $image_infos;
72 switch ($this->mimetype
) {
73 case 1: $this->mimetype
= "gif"; break;
74 case 2: $this->mimetype
= "jpeg"; break;
75 case 3: $this->mimetype
= "png"; break;
77 $page->trig("Type d'image invalide");
81 if (strlen($_data) > SIZE_MAX
) {
82 $img = imagecreatefromstring($_data);
84 $page->trig("image trop grande et impossible à retailler automatiquement");
88 $nx = $x = imagesx($img);
89 $ny = $y = imagesy($img);
91 if ($nx > 240) { $ny = intval($ny*240/$nx); $nx = 240; }
92 if ($ny > 300) { $ny = intval($nx*300/$nx); $ny = 300; }
93 if ($nx < 160) { $ny = intval($ny*160/$nx); $nx = 160; }
96 $file = tempnam('/tmp', 'photo');
98 while (strlen($_data) > SIZE_MAX
) {
99 $img2 = imagecreatetruecolor($nx, $ny);
100 imagecopyresampled($img2, $img, 0, 0, 0, 0, $nx, $ny, $x, $y);
101 imagejpeg($img2, $file, $comp);
102 $_data = file_get_contents($file);
103 $this->mimetype
= 'jpeg';
110 $this->data
= $_data;
115 // {{{ function get_request()
117 function get_request($uid)
119 return parent
::get_request($uid,'photo');
123 // {{{ function formu()
126 { return 'include/form.valid.photos.tpl'; }
129 // {{{ function editor()
133 return 'include/form.valid.edit-photo.tpl';
137 // {{{ function handle_editor()
139 function handle_editor()
141 if (isset($_FILES['userfile']['tmp_name'])) {
142 $file = $_FILES['userfile']['tmp_name'];
143 if ($data = file_get_contents($file)) {
144 if ($this->_get_image($data)) {
148 $page->trig('Fichier inexistant ou vide');
155 // {{{ function _mail_subj
157 function _mail_subj()
159 return "[Polytechnique.org/PHOTO] Changement de photo";
163 // {{{ function _mail_body
165 function _mail_body($isok)
168 return "Le changement de photo que tu as demandé vient d'être effectué.";
170 return "La demande de changement de photo que tu avais faite a été refusée.";
175 // {{{ function commit()
179 XDB
::execute('REPLACE INTO photo (uid, attachmime, attach, x, y)
180 VALUES ({?},{?},{?},{?},{?})',
181 $this->uid
, $this->mimetype
, $this->data
, $this->x
, $this->y
);
182 require_once('notifs.inc.php');
183 register_watch_op($this->uid
,WATCH_FICHE
);
192 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: