Merge remote branch 'origin/xorg/maint' into xorg/master
[platal.git] / include / validations / evts.inc.php
index 4a3a0ce..7dcbce0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -30,7 +30,7 @@ class EvtReq extends Validate
     public $texte;
     public $pmin;
     public $pmax;
-    public $peremption;
+    public $expiration;
     public $comment;
 
     public $imgtype;
@@ -41,14 +41,14 @@ class EvtReq extends Validate
     // }}}
     // {{{ constructor
 
-    public function __construct($_titre, $_texte, $_pmin, $_pmax, $_peremption, $_comment, $_uid, PlUpload &$upload = null)
+    public function __construct($_titre, $_texte, $_pmin, $_pmax, $_expiration, $_comment, User $_user, PlUpload $upload = null)
     {
-        parent::__construct($_uid, false, 'evts');
+        parent::__construct($_user, false, 'evts');
         $this->titre      = $_titre;
         $this->texte      = $_texte;
         $this->pmin       = $_pmin;
         $this->pmax       = $_pmax;
-        $this->peremption = $_peremption;
+        $this->expiration = $_expiration;
         $this->comment    = $_comment;
         if ($upload) {
             $this->readImage($upload);
@@ -58,7 +58,7 @@ class EvtReq extends Validate
     // }}}
     // {{{ function readImage()
 
-    private function readImage(PlUpload &$upload)
+    private function readImage(PlUpload $upload)
     {
         if ($upload->exists() && $upload->isType('image')) {
             list($this->imgx, $this->imgy, $this->imgtype) = $upload->imageInfo();
@@ -92,16 +92,16 @@ class EvtReq extends Validate
         $this->texte      = Env::v('texte');
         $this->pmin       = Env::i('promo_min');
         $this->pmax       = Env::i('promo_max');
-        $this->peremption = Env::v('peremption');
+        $this->expiration = Env::v('expiration');
         if (@$_FILES['image']['tmp_name']) {
-            $upload = PlUpload::get($_FILES['image'], S::v('forlife'), 'event');
+            $upload = PlUpload::get($_FILES['image'], S::user()->login(), 'event');
             if (!$upload) {
-                $this->trig("Impossible de télécharger le fichier");
+                $this->trigError("Impossible de télécharger le fichier");
             } elseif (!$upload->isType('image')) {
-                $page->trig('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG');
+                $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG');
                 $upload->rm();
             } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) {
-                $page->trig('Impossible de retraiter l\'image');
+                $page->trigError('Impossible de retraiter l\'image');
             } else {
                 $this->readImage($upload);
             }
@@ -122,10 +122,11 @@ class EvtReq extends Validate
 
     protected function _mail_body($isok)
     {
+        $you_have = ($this->formal ? 'vous aviez' : 'tu avais');
         if ($isok) {
-            return "  L'annonce que tu avais proposée ({$this->titre}) vient d'être validée.";
+            return "  L'annonce que $you_have proposée ({$this->titre}) vient d'être validée.";
         } else {
-            return "  L'annonce que tu avais proposée ({$this->titre}) a été refusée.";
+            return "  L'annonce que $you_have proposée ({$this->titre}) a été refusée.";
         }
     }
 
@@ -134,33 +135,27 @@ class EvtReq extends Validate
 
     public function commit()
     {
-        if (XDB::execute("INSERT INTO  evenements
-                         SET  user_id = {?}, creation_date=NOW(), titre={?}, texte={?},
-                              peremption={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide')",
-                $this->uid, $this->titre, $this->texte,
-                $this->peremption, $this->pmin, $this->pmax)) {
+        /* TODO: refines this filter on promotions by using userfilter. */
+        if (XDB::execute("INSERT INTO  announces
+                         SET  uid = {?}, creation_date=NOW(), titre={?}, texte={?},
+                              expiration={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide,wiki')",
+                $this->user->id(), $this->titre, $this->texte,
+                $this->expiration, $this->pmin, $this->pmax)) {
             $eid = XDB::insertId();
             if ($this->img) {
-                XDB::execute("INSERT INTO evenements_photo
+                XDB::execute("INSERT INTO announce_photos
                                       SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
                              XDB::insertId(), $this->imgtype, $this->imgx, $this->imgy, $this->img);
             }
             global $globals;
             if ($globals->banana->event_forum) {
-                require_once 'user.func.inc.php';
-                $forlife = get_user_forlife($this->uid);
                 require_once 'banana/forum.inc.php';
-                $banana = new ForumsBanana($forlife);
-                $text = strip_tags($this->texte, '<p><br><li><ul><ol><a>');
-                $text = preg_replace(',<a href="([^"]+)">(.*?)</a>,', '$1', $text);
-                $text = preg_replace('/<li>/', '* ', $text);
-                $text = preg_replace(',</?.+?>,i', "\n", $text);
-                $text = preg_replace("/\n{2,}/", "\n\n", $text);
+                $banana = new ForumsBanana($this->user);
                 $post = $banana->post($globals->banana->event_forum,
                                       $globals->banana->event_reply,
-                                      $this->titre, pl_entity_decode($text));
+                                      $this->titre, MiniWiki::wikiToText($this->texte, false, 0, 80));
                 if ($post != -1) {
-                    XDB::execute("UPDATE  evenements
+                    XDB::execute("UPDATE  announces
                                      SET  creation_date = creation_date, post_id = {?}
                                    WHERE  id = {?}", $post, $eid);
                 }