New upload manager to handle images and attachments
[platal.git] / classes / platalpage.php
index c07f6c6..0fe8ec6 100644 (file)
@@ -23,24 +23,22 @@ require_once 'smarty/libs/Smarty.class.php';
 
 class PlatalPage extends Smarty
 {
-    var $_page_type;
-    var $_tpl;
-    var $_errors;
-    var $_failure;
-
-    // defaults
-    var $caching          = false;
-    var $config_overwrite = false;
-    var $use_sub_dirs     = false;
+    private $_page_type;
+    private $_tpl;
+    private $_errors;
+    private $_failure;
 
     // {{{ function PlatalPage()
 
-    function PlatalPage($tpl, $type = SKINNED)
+    public function __construct($tpl, $type = SKINNED)
     {
-        global $globals;
+        parent::Smarty();
 
-        $this->Smarty();
+        global $globals;
 
+        $this->caching       = false;
+        $this->config_overwrite = false;
+        $this->use_sub_dirs  = false;
         $this->template_dir  = $globals->spoolroot."/templates/";
         $this->compile_dir   = $globals->spoolroot."/spool/templates_c/";
         array_unshift($this->plugins_dir, $globals->spoolroot."/plugins/");
@@ -62,7 +60,7 @@ class PlatalPage extends Smarty
     // }}}
     // {{{ function changeTpl()
 
-    function changeTpl($tpl, $type = SKINNED)
+    public function changeTpl($tpl, $type = SKINNED)
     {
        $this->_tpl       = $tpl;
            $this->_page_type = $type;
@@ -72,7 +70,7 @@ class PlatalPage extends Smarty
     // }}}
     // {{{ function _run()
 
-    function _run($skin)
+    protected function _run($skin)
     {
         global $globals, $TIME_BEGIN;
 
@@ -114,17 +112,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);
@@ -149,7 +148,7 @@ class PlatalPage extends Smarty
     // }}}
     // {{{ function nb_errs()
 
-    function nb_errs()
+    public function nb_errs()
     {
         return count($this->_errors);
     }
@@ -157,7 +156,7 @@ class PlatalPage extends Smarty
     // }}}
     // {{{ function trig()
 
-    function trig($msg)
+    public function trig($msg)
     {
         $this->_errors[] = $msg;
     }
@@ -165,7 +164,7 @@ class PlatalPage extends Smarty
     // }}}
     // {{{ function kill()
 
-    function kill($msg)
+    public function kill($msg)
     {
         global $platal;
 
@@ -178,7 +177,7 @@ class PlatalPage extends Smarty
     // }}}
     // {{{ function addJsLink
 
-    function addJsLink($path)
+    public function addJsLink($path)
     {
         $this->append('xorg_js', $path);
     }
@@ -186,7 +185,7 @@ class PlatalPage extends Smarty
     // }}}
     // {{{ function addCssLink
 
-    function addCssLink($path)
+    public function addCssLink($path)
     {
         $this->append('xorg_css', $path);
     }
@@ -194,7 +193,7 @@ class PlatalPage extends Smarty
     // }}}
     // {{{ function addCssInline
 
-    function addCssInline($css)
+    public function addCssInline($css)
     {
         if (!empty($css)) {
             $this->append('xorg_inline_css', $css);
@@ -204,7 +203,7 @@ class PlatalPage extends Smarty
     // }}}
     // {{{ function setRssLink
 
-    function setRssLink($title, $path)
+    public function setRssLink($title, $path)
     {
         $this->assign('xorg_rss', array('title' => $title, 'href' => $path));
     }
@@ -226,7 +225,7 @@ function escape_html($string)
 {
     if (is_string($string)) {
        $transtbl = Array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;', '\'' => '&#39;');
-       return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/", "&amp;" , strtr($string, $transtbl));
+       return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/u", "&amp;", strtr(pl_entities($string), $transtbl));
     } else {
        return $string;
     }
@@ -264,8 +263,8 @@ function at_to_globals($tpl_source, &$smarty)
 function trimwhitespace($source, &$smarty)
 {
     $tags = '(script|pre|textarea)';
-    preg_match_all("!<$tags.*?>.*?</$tags>!is", $source, $tagsmatches);
-    $source = preg_replace("!<$tags.*?>.*?</$tags>!is", "&&&tags&&&", $source);
+    preg_match_all("!<$tags.*?>.*?</(\\1)>!ius", $source, $tagsmatches);
+    $source = preg_replace("!<$tags.*?>.*?</(\\1)>!ius", "&&&tags&&&", $source);
 
     // remove all leading spaces, tabs and carriage returns NOT
     // preceeded by a php close tag.
@@ -300,19 +299,19 @@ function hide_emails($source, &$smarty)
 {
     //prevent email replacement in <script> and <textarea>
     $tags = '(script|textarea|select)';
-    preg_match_all("!<$tags.*?>.*?</$tags>!is", $source, $tagsmatches);
-    $source = preg_replace("!<$tags.*?>.*?</$tags>!is", "&&&tags&&&", $source);
+    preg_match_all("!<$tags.*?>.*?</(\\1)>!ius", $source, $tagsmatches);
+    $source = preg_replace("!<$tags.*?>.*?</(\\1)>!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_.]+.+?>!ius", $source, $misc);
+    $source = preg_replace("!<[^>]+[-a-z0-9_+.]+@[-a-z0-9_.]+.+?>!ius", '&&&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_.]+)!iue', '_hide_email("\1")', $source); 
     $source = preg_replace('!&&&ahref&&&!e', '_hide_email(array_shift($ahref[0]))', $source);
 
     // restore data