X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations%2Fphotos.inc.php;h=2a2fec755f73e20b463e9691276631fbc3f3b59c;hb=2553b7686e0678b8e27858a7c377e73ecb410aec;hp=0f8e75e48023a949bd446d66bad4a5d0339042c4;hpb=eb5e2d26fe7319f50a4f8c121df23374c48455a5;p=platal.git diff --git a/include/validations/photos.inc.php b/include/validations/photos.inc.php index 0f8e75e..2a2fec7 100644 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@ -1,6 +1,6 @@ Validate($_uid, true, 'photo', $_stamp); - - // calcul de la taille de l'image - require_once('xorg.varstream.inc.php'); - $GLOBALS['photoreq'] = $_data; - $image_infos = getimagesize('var://photoreq'); - unset ($GLOBALS['photoreq']); - - if (empty($image_infos)) { - $page->trig("Image invalide"); - return ($this = null); - } - 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 ($this = null); - } + parent::__construct($_user, true, 'photo', $_stamp); + $this->read($upload); + } - if (strlen($_data) > SIZE_MAX) { - $img = imagecreatefromstring($_data); - if (!$img) { - $page->trig("image trop grande et impossible à retailler automatiquement"); - return ($this = null); - } + // }}} + // {{{ function read - $nx = $x = imagesx($img); - $ny = $y = imagesy($img); + private function read(PlUpload &$upload) + { + $this->valid = $upload->resizeImage(240, 300, 160, 0, SIZE_MAX); + if (!$this->valid) { + $this->trigError('Le fichier que tu as transmis n\'est pas une image valide, ou est trop gros pour être traité'); + } + $this->data = $upload->getContents(); + list($this->x, $this->y, $this->mimetype) = $upload->imageInfo(); + $upload->rm(); + } - 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; } + // }}} + // {{{ function isValid() - $comp = '90'; - $file = tempnam('/tmp', 'photo'); + public function isValid() + { + return $this->valid; + } - 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'; + // }}} + // {{{ function get_request() - $comp --; - } + static public function get_request($uid) + { + return parent::get_typed_request($uid, 'photo'); + } - unlink($file); - } - $this->data = $_data; + // }}} + // {{{ function formu() + + public function formu() + { + return 'include/form.valid.photos.tpl'; } - + // }}} - // {{{ function get_request() + // {{{ function editor() - function get_request($uid) + public function editor() { - return parent::get_request($uid,'photo'); + return 'include/form.valid.edit-photo.tpl'; } // }}} - // {{{ function formu() + // {{{ function handle_editor() - function formu() - { return 'include/form.valid.photos.tpl'; } + protected function handle_editor() + { + if (isset($_FILES['userfile'])) { + $upload =& PlUpload::get($_FILES['userfile'], S::user()->login(), 'photo'); + if (!$upload) { + $this->trigError('Une erreur est survenue lors du téléchargement du fichier'); + return false; + } + $this->read($upload); + return $this->valid; + } + return false; + } // }}} // {{{ function _mail_subj - function _mail_subj() + protected function _mail_subj() { return "[Polytechnique.org/PHOTO] Changement de photo"; } // }}} // {{{ 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() { - global $globals; - - $globals->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); + require_once 'notifs.inc.php'; + XDB::execute('REPLACE INTO photo (uid, attachmime, attach, x, y) + VALUES ({?},{?},{?},{?},{?})', + $this->user->id(), $this->mimetype, $this->data, $this->x, $this->y); + register_watch_op($this->user->id(), WATCH_FICHE, '', 'photo'); return true; } @@ -155,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: ?>