Add trigWarning() too. Update xnet CSS.
[platal.git] / classes / platalpage.php
index 950f73e..59c3c20 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -48,16 +48,17 @@ abstract class PlatalPage extends Smarty
         $this->compile_check = !empty($globals->debug);
 
         $this->changeTpl($tpl, $type);
-        $this->_errors    = array();
+        $this->_errors    = array('errors' => array());
         $this->_jsonVars  = array();
         $this->_failure   = false;
 
         if ($globals->mode != 'rw') {
-            $this->_errors[] = "En raison d'une maintenance, une partie des fonctionnalités du site sont actuellement"
-                             . " désactivée, en particuliers aucune donnée ne sera sauvegardée";
+            $this->trig("En raison d'une maintenance, une partie des fonctionnalités du site sont"
+                      . " actuellement désactivée, en particuliers aucune donnée ne sera sauvegardée");
         }
         $this->register_prefilter('at_to_globals');
         $this->addJsLink('xorg.js');
+        $this->addJsLink('jquery.js');
     }
 
     // }}}
@@ -92,7 +93,9 @@ abstract class PlatalPage extends Smarty
         $this->register_prefilter('trimwhitespace');
         $this->register_prefilter('form_force_encodings');
         $this->register_prefilter('wiki_include');
-        $this->assign('xorg_errors', $this->_errors);
+        $this->register_prefilter('if_has_perms');
+        $this->assign('xorg_triggers', $this->_errors);
+        $this->assign('xorg_errors', $this->nb_errs());
         $this->assign('xorg_failure', $this->_failure);
         $this->assign('globals', $globals);
 
@@ -120,10 +123,12 @@ abstract class PlatalPage extends Smarty
             $this->assign('simple', true);
 
           case SKINNED:
-          $this->register_modifier('escape_html', 'escape_html');
-          $this->default_modifiers = Array('@escape_html');
+            $this->register_modifier('escape_html', 'escape_html');
+            $this->default_modifiers = Array('@escape_html');
+        }
+        if (S::i('auth') <= AUTH_PUBLIC) {
+            $this->register_outputfilter('hide_emails');
         }
-        $this->register_outputfilter('hide_emails');
         $this->addJsLink('wiki.js');
         header("Accept-Charset: utf-8");
         if (Env::v('forceXml')) {
@@ -136,20 +141,24 @@ abstract class PlatalPage extends Smarty
             exit;
         }
 
-        if ($globals->debug & DEBUG_BT) {
-            PlBacktrace::clean();
-            $this->assign_by_ref('backtraces', PlBacktrace::$bt);
-        }
-
         $this->assign('validate', true);
         if (!($globals->debug & DEBUG_SMARTY)) {
             error_reporting(0);
         }
+        $START_SMARTY = microtime(true);
         $result = $this->fetch($skin);
-        $ttime  = sprintf('Temps total: %.02fs - Mémoire totale : %dKo<br />', microtime(true) - $TIME_BEGIN
-                                                                                , memory_get_peak_usage(true) / 1024);
-        $replc  = "<span class='erreur'>VALIDATION HTML INACTIVE</span><br />";
+        $ttime  = sprintf('Temps total: %.02fs (Smarty %.02fs) - Mémoire totale : %dKo<br />',
+                          microtime(true) - $TIME_BEGIN, microtime(true) - $START_SMARTY,
+                          memory_get_peak_usage(true) / 1024);
+        if ($globals->debug & DEBUG_BT) {
+            PlBacktrace::clean();
+            $this->assign_by_ref('backtraces', PlBacktrace::$bt);
+            $result = str_replace('@@BACKTRACE@@', $this->fetch('skin/common.backtrace.tpl'), $result);
+        } else {
+            $result = str_replace('@@BACKTRACE@@', '', $result);
+        }
 
+        $replc  = "<span class='erreur'>VALIDATION HTML INACTIVE</span><br />";
         if ($globals->debug & DEBUG_VALID) {
             $fd = fopen($this->compile_dir."/valid.html","w");
             fwrite($fd, $result);
@@ -179,15 +188,33 @@ abstract class PlatalPage extends Smarty
 
     public function nb_errs()
     {
-        return count($this->_errors);
+        return count($this->_errors['errors']);
     }
 
     // }}}
     // {{{ function trig()
 
-    public function trig($msg)
+    public function trig($msg, $type = 'errors')
+    {
+        if (!isset($this->_errors[$type])) {
+            $this->_errors[$type] = array();
+        }
+        $this->_errors[$type][] = $msg;
+    }
+
+    public function trigError($msg)
+    {
+        $this->trig($msg, 'errors');
+    }
+
+    public function trigWarning($msg)
+    {
+        $this->trig($msg, 'warnings');
+    }
+
+    public function trigSuccess($msg)
     {
-        $this->_errors[] = $msg;
+        $this->trig($msg, 'success');
     }
 
     // }}}
@@ -349,6 +376,19 @@ function wiki_include($source, &$smarty)
 }
 
 // }}}
+//{{{ function hasPerm
+
+function if_has_perms($source, &$smarty)
+{
+    $source = preg_replace('/\{if([^}]*) (\!?)hasPerms\(([^)]+)\)([^}]*)\}/',
+                           '{if\1 \2$smarty.session.perms->hasFlagCombination(\3)\4}',
+                           $source);
+    return preg_replace('/\{if([^}]*) (\!?)hasPerm\(([^)]+)\)([^}]*)\}/',
+                        '{if\1 \2($smarty.session.perms && $smarty.session.perms->hasFlag(\3))\4}',
+                        $source);
+}
+
+// }}}
 // {{{
 
 function form_force_encodings($source, &$smarty)