X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations%2Fphotos.inc.php;h=6d8fcc3edb1a3fa9ba908de12f567a306d4ca665;hb=5af85e819a8602f6720dff9e2efa6aa02d257d48;hp=a1596ccddb9bb075b51a545cf4c618d70668d269;hpb=08cce2ff528b38bde27cdec6d6bc28d6af4a42d4;p=platal.git diff --git a/include/validations/photos.inc.php b/include/validations/photos.inc.php index a1596cc..6d8fcc3 100644 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@ -24,7 +24,7 @@ class PhotoReq extends Validate { // {{{ properties - + var $mimetype; var $data; var $x; @@ -32,31 +32,40 @@ class PhotoReq extends Validate var $unique = true; - var $rules = "Refuser les photos copyrightées, de mineurs, ou ayant - un caractère pornographique, violent, etc... Si une photo est mal - cadrée (20% de photo et 80% de blanc par exemple), si c'est un - camarade antique, on lui arrange sinon on lui - refuse en lui expliquant gentiment le problème. Idem si les dimensions de + var $rules = "Refuser les photos copyrightées, de mineurs, ou ayant + un caractère pornographique, violent, etc... Si une photo est mal + cadrée (20% de photo et 80% de blanc par exemple), si c'est un + camarade antique, on lui arrange sinon on lui + refuse en lui expliquant gentiment le problème. Idem si les dimensions de la photo sont archi trop grandes ou archi trop petites."; // }}} // {{{ constructor - + function PhotoReq($_uid, $_data, $_stamp=0) { - global $globals, $page; - $this->Validate($_uid, true, 'photo', $_stamp); - + if (!$this->_get_image($_data)) { + return ($this = null); + } + } + + // }}} + // {{{ function _get_image() + + function _get_image($_data) + { + global $page; + // calcul de la taille de l'image - require_once('xorg.varstream.inc.php'); + require_once dirname(__FILE__).'/../../classes/VarStream.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 +75,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,8 +108,9 @@ class PhotoReq extends Validate unlink($file); } $this->data = $_data; + return true; } - + // }}} // {{{ function get_request() @@ -116,6 +126,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 +161,7 @@ class PhotoReq extends Validate // }}} // {{{ function _mail_body - + function _mail_body($isok) { if ($isok) { @@ -137,11 +173,9 @@ class PhotoReq extends Validate // }}} // {{{ function commit() - + function commit() { - global $globals; - XDB::execute('REPLACE INTO photo (uid, attachmime, attach, x, y) VALUES ({?},{?},{?},{?},{?})', $this->uid, $this->mimetype, $this->data, $this->x, $this->y);