X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations%2Fphotos.inc.php;h=41a29b4ace0293ef7b63bed00f5fac02b1edfbc3;hb=5ddeb07cc787dd1dc3630a31f1528f5cc7c4d9b9;hp=b1c2375af59c1fbb89774758ef688d46b9710091;hpb=50a40a33a496131e817df875607ea5542d096a64;p=platal.git diff --git a/include/validations/photos.inc.php b/include/validations/photos.inc.php index b1c2375..41a29b4 100644 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@ -1,6 +1,6 @@ Validate($_uid, true, 'photo', $_stamp); - + $this->_get_image($_data); + } + + // }}} + // {{{ function _get_image() + + function _get_image($_data) + { + global $page; + + VarStream::init(); + // 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); + return false; } list($this->x, $this->y, $this->mimetype) = $image_infos; @@ -66,14 +74,14 @@ class PhotoReq extends Validate case 3: $this->mimetype = "png"; break; default: $page->trig("Type d'image invalide"); - return ($this = null); + return false; } if (strlen($_data) > SIZE_MAX) { $img = imagecreatefromstring($_data); if (!$img) { $page->trig("image trop grande et impossible à retailler automatiquement"); - return ($this = null); + return false; } $nx = $x = imagesx($img); @@ -99,14 +107,15 @@ class PhotoReq extends Validate unlink($file); } $this->data = $_data; + return true; } - + // }}} // {{{ function get_request() function get_request($uid) { - return parent::get_request($uid,'photo'); + return parent::get_typed_request($uid,'photo'); } // }}} @@ -116,6 +125,32 @@ class PhotoReq extends Validate { return 'include/form.valid.photos.tpl'; } // }}} + // {{{ function editor() + + function editor() + { + return 'include/form.valid.edit-photo.tpl'; + } + + // }}} + // {{{ function handle_editor() + + 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'); + } + } + return false; + } + + // }}} // {{{ function _mail_subj function _mail_subj() @@ -125,7 +160,7 @@ class PhotoReq extends Validate // }}} // {{{ function _mail_body - + function _mail_body($isok) { if ($isok) { @@ -137,12 +172,10 @@ class PhotoReq extends Validate // }}} // {{{ function commit() - + function commit() { - global $globals; - - $globals->xdb->execute('REPLACE INTO photo (uid, attachmime, attach, x, y) + 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');