X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations%2Fphotos.inc.php;h=c62cff7d04c70050fd2e9edabfa1b45e6a78df55;hb=787bb3d745141f2f85bd947ad7dd775d2c63f908;hp=fa0f4b39e958c3f12dd27956284c1497b10816d5;hpb=20d7932b9db32f4dbf96312efc1981a5bebd9b7d;p=platal.git diff --git a/include/validations/photos.inc.php b/include/validations/photos.inc.php index fa0f4b3..c62cff7 100644 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@ -1,6 +1,6 @@ Validate($_uid, true, 'photo', $_stamp); + parent::__construct($_uid, true, 'photo', $_stamp); + $this->read($upload); } // }}} - // {{{ function _get_image() + // {{{ function read - function _get_image($_data) + private function read(PlUpload &$upload) { - global $page; - - VarStream::init(); - - // calcul de la taille de l'image - $GLOBALS['photoreq'] = $_data; - $image_infos = getimagesize('var://photoreq'); - unset ($GLOBALS['photoreq']); - - if (empty($image_infos)) { - $page->trig("Image invalide"); - return false; + $this->valid = $upload->resizeImage(240, 300, 160, 0, SIZE_MAX); + if (!$this->valid) { + $this->trig('Le fichier que tu as transmis n\'est pas une image valide, ou est trop gros pour être traité'); } - list($this->x, $this->y, $this->mimetype) = $image_infos; - - switch ($this->mimetype) { - case 1: $this->mimetype = "gif"; break; - case 2: $this->mimetype = "jpeg"; break; - case 3: $this->mimetype = "png"; break; - default: - $page->trig("Type d'image invalide"); - return false; - } - - if (strlen($_data) > SIZE_MAX) { - $img = imagecreatefromstring($_data); - if (!$img) { - $page->trig("image trop grande et impossible à retailler automatiquement"); - return false; - } - - $nx = $x = imagesx($img); - $ny = $y = imagesy($img); - - if ($nx > 240) { $ny = intval($ny*240/$nx); $nx = 240; } - if ($ny > 300) { $ny = intval($nx*300/$nx); $ny = 300; } - if ($nx < 160) { $ny = intval($ny*160/$nx); $nx = 160; } - - $comp = '90'; - $file = tempnam('/tmp', 'photo'); - - while (strlen($_data) > SIZE_MAX) { - $img2 = imagecreatetruecolor($nx, $ny); - imagecopyresampled($img2, $img, 0, 0, 0, 0, $nx, $ny, $x, $y); - imagejpeg($img2, $file, $comp); - $_data = file_get_contents($file); - $this->mimetype = 'jpeg'; + $this->data = $upload->getContents(); + list($this->x, $this->y, $this->mimetype) = $upload->imageInfo(); + $upload->rm(); + } - $comp --; - } + // }}} + // {{{ function isValid() - unlink($file); - } - $this->data = $_data; - return true; + public function isValid() + { + return $this->valid; } // }}} // {{{ function get_request() - function get_request($uid) + static public function get_request($uid) { return parent::get_typed_request($uid,'photo'); } @@ -120,13 +82,15 @@ class PhotoReq extends Validate // }}} // {{{ function formu() - function formu() - { return 'include/form.valid.photos.tpl'; } + public function formu() + { + return 'include/form.valid.photos.tpl'; + } // }}} // {{{ function editor() - function editor() + public function editor() { return 'include/form.valid.edit-photo.tpl'; } @@ -134,25 +98,24 @@ class PhotoReq extends Validate // }}} // {{{ function handle_editor() - function handle_editor() + protected function handle_editor() { - if (isset($_FILES['userfile']['tmp_name'])) { - $file = $_FILES['userfile']['tmp_name']; - if ($data = file_get_contents($file)) { - if ($this->_get_image($data)) { - return true; - } - } else { - $page->trig('Fichier inexistant ou vide'); + if (isset($_FILES['userfile'])) { + $upload =& PlUpload::get($_FILES['userfile'], S::v('forlife'), 'photo'); + if (!$upload) { + $this->trig('Une erreur est survenue lors du téléchargement du fichier'); + return false; } + $this->read($upload); + return $this->valid; } - return false; + return false; } // }}} // {{{ function _mail_subj - function _mail_subj() + protected function _mail_subj() { return "[Polytechnique.org/PHOTO] Changement de photo"; } @@ -160,25 +123,25 @@ class PhotoReq extends Validate // }}} // {{{ function _mail_body - function _mail_body($isok) + protected function _mail_body($isok) { if ($isok) { - return "Le changement de photo que tu as demandé vient d'être effectué."; + return "Le changement de photo que tu as demandé vient d'être effectué."; } else { - return "La demande de changement de photo que tu avais faite a été refusée."; + return "La demande de changement de photo que tu avais faite a été refusée."; } } // }}} // {{{ function commit() - function commit() + public function commit() { XDB::execute('REPLACE INTO photo (uid, attachmime, attach, x, y) - VALUES ({?},{?},{?},{?},{?})', - $this->uid, $this->mimetype, $this->data, $this->x, $this->y); - require_once('notifs.inc.php'); - register_watch_op($this->uid,WATCH_FICHE); + VALUES ({?},{?},{?},{?},{?})', + $this->uid, $this->mimetype, $this->data, $this->x, $this->y); + require_once('notifs.inc.php'); + register_watch_op($this->uid, WATCH_FICHE); return true; } @@ -187,5 +150,5 @@ class PhotoReq extends Validate // }}} -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>