backport
[platal.git] / classes / platalpage.php
index 9998a97..eac986a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -64,9 +64,9 @@ class PlatalPage extends Smarty
 
     function changeTpl($tpl, $type = SKINNED)
     {
-       $this->_tpl       = $tpl;
-       $this->_page_type = $type;
-       $this->assign('xorg_tpl', $tpl);
+       $this->_tpl       = $tpl;
+           $this->_page_type = $type;
+       $this->assign('xorg_tpl', $tpl);
     }
 
     // }}}
@@ -82,6 +82,14 @@ class PlatalPage extends Smarty
         $this->assign('xorg_failure', $this->_failure);
         $this->assign('globals', $globals);
 
+        if (Env::v('display') == 'light') {
+            $this->_page_type = SIMPLE;
+        } elseif (Env::v('display') == 'raw') {
+            $this->_page_type = NO_SKIN;
+        } elseif (Env::v('display') == 'full') {
+            $this->_page_typ = SKINNED;
+        }
+
         switch ($this->_page_type) {
           case NO_SKIN:
             error_reporting(0);
@@ -97,7 +105,7 @@ class PlatalPage extends Smarty
         }
         $this->register_outputfilter('hide_emails');
         $this->addJsLink('wiki.js');
-        header("Accept-Charset: iso-8859-15, latin9, us-ascii, ascii");
+        header("Accept-Charset: utf-8");
 
         if (!$globals->debug) {
             error_reporting(0);
@@ -106,17 +114,18 @@ class PlatalPage extends Smarty
         }
 
         if ($globals->debug & 1) {
-            $this->assign('db_trace', XDB::trace_format($this, 'skin/common.database-debug.tpl'));
+            PlBacktrace::clean();
+            $this->assign_by_ref('backtraces', PlBacktrace::$bt);
         }
 
         $this->assign('validate', true);
         error_reporting(0);
         $result = $this->fetch($skin);
-        $ttime  = sprintf('Temps total: %.02fs<br />', microtime_float() - $TIME_BEGIN);
+        $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 />";
 
         if ($globals->debug & 2) {
-
             $fd = fopen($this->compile_dir."/valid.html","w");
             fwrite($fd, $result);
             fclose($fd);
@@ -184,6 +193,16 @@ class PlatalPage extends Smarty
     }
 
     // }}}
+    // {{{ function addCssInline
+
+    function addCssInline($css)
+    {
+        if (!empty($css)) {
+            $this->append('xorg_inline_css', $css);
+        }    
+    }
+
+    // }}}
     // {{{ function setRssLink
 
     function setRssLink($title, $path)
@@ -245,20 +264,14 @@ function at_to_globals($tpl_source, &$smarty)
 
 function trimwhitespace($source, &$smarty)
 {
-    $tags = array('script', 'pre', 'textarea');
-
-    foreach ($tags as $tag) {
-        preg_match_all("!<{$tag}[^>]+>.*?</{$tag}>!is", $source, ${$tag});
-        $source = preg_replace("!<{$tag}[^>]+>.*?</{$tag}>!is", "&&&{$tag}&&&", $source);
-    }
+    $tags = '(script|pre|textarea)';
+    preg_match_all("!<$tags.*?>.*?</$tags>!ius", $source, $tagsmatches);
+    $source = preg_replace("!<$tags.*?>.*?</$tags>!ius", "&&&tags&&&", $source);
 
     // remove all leading spaces, tabs and carriage returns NOT
     // preceeded by a php close tag.
     $source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source);
-
-    foreach ($tags as $tag) {
-        $source = preg_replace("!&&&{$tag}&&&!e",  'array_shift(${$tag}[0])', $source);
-    }
+    $source = preg_replace("!&&&tags&&&!e",  'array_shift($tagsmatches[0])', $source);
 
     return $source; 
 }
@@ -269,7 +282,7 @@ function trimwhitespace($source, &$smarty)
 function form_force_encodings($source, &$smarty)
 {
     return preg_replace('/<form[^\w]/',
-                        '\0 accept-charset="iso-8859-15 latin9 us-ascii ascii" ',
+                        '\0 accept-charset="utf-8" ',
                         $source);
 }
 
@@ -287,35 +300,30 @@ function _hide_email($source)
 function hide_emails($source, &$smarty)
 {
     //prevent email replacement in <script> and <textarea>
-    $tags = array('script', 'textarea', 'select');
-
-    foreach ($tags as $tag) {
-        preg_match_all("!<{$tag}[^>]+>.*?</{$tag}>!is", $source, ${$tag});
-        $source = preg_replace("!<{$tag}[^>]+>.*?</{$tag}>!is", "&&&{$tag}&&&", $source);
-    }
+    $tags = '(script|textarea|select)';
+    preg_match_all("!<$tags.*?>.*?</$tags>!ius", $source, $tagsmatches);
+    $source = preg_replace("!<$tags.*?>.*?</$tags>!ius", "&&&tags&&&", $source);
 
     //catch all emails in <a href="mailto:...">
-    preg_match_all("!<a[^>]+href=[\"'][^\"']*[-a-z0-9_.]+@[-a-z0-9_.]+[^\"']*[\"'][^>]*>.*?</a>!is", $source, $ahref);
-    $source = preg_replace("!<a[^>]+href=[\"'][^\"']*[-a-z0-9_.]+@[-a-z0-9_.]+[^\"']*[\"'][^>]*>.*?</a>!is", '&&&ahref&&&', $source);
+    preg_match_all("!<a[^>]+href=[\"'][^\"']*[-a-z0-9+_.]+@[-a-z0-9_.]+[^\"']*[\"'].*?>.*?</a>!ius", $source, $ahref);
+    $source = preg_replace("!<a[^>]+href=[\"'][^\"']*[-a-z0-9+_.]+@[-a-z0-9_.]+[^\"']*[\"'].*?>.*?</a>!ius", '&&&ahref&&&', $source);
 
     //prevant replacement in tag attributes
-    preg_match_all("!<[^>]+[-a-z0-9_.]+@[-a-z0-9_.]+[^>]+>!is", $source, $misc);
-    $source = preg_replace("!<[^>]+[-a-z0-9_.]+@[-a-z0-9_.]+[^>]+>!is", '&&&misc&&&', $source);
+    preg_match_all("!<[^>]+[-a-z0-9_+.]+@[-a-z0-9_.]+.+?>!is", $source, $misc);
+    $source = preg_replace("!<[^>]+[-a-z0-9_+.]+@[-a-z0-9_.]+.+?>!is", '&&&misc&&&', $source);
 
     //catch !
-    $source = preg_replace('!([-a-z0-9_.]+@[-a-z0-9_.]+)!ie', '_hide_email("\1")', $source); 
+    $source = preg_replace('!([-a-z0-9_+.]+@[-a-z0-9_.]+)!ie', '_hide_email("\1")', $source); 
     $source = preg_replace('!&&&ahref&&&!e', '_hide_email(array_shift($ahref[0]))', $source);
 
     // restore data
     $source = preg_replace('!&&&misc&&&!e', 'array_shift($misc[0])', $source);
-    foreach ($tags as $tag) {
-        $source = preg_replace("!&&&{$tag}&&&!e",  'array_shift(${$tag}[0])', $source);
-    }
+    $source = preg_replace("!&&&tags&&&!e",  'array_shift($tagsmatches[0])', $source);
 
     return $source;
 }
 
 // }}}
 
-// 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:
 ?>