Better email-hidder
[platal.git] / classes / platalpage.php
index 25112c2..fad9a66 100644 (file)
@@ -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);
@@ -184,6 +192,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)
@@ -286,6 +304,8 @@ function _hide_email($source)
 
 function hide_emails($source, &$smarty)
 {
+    fix_encoding($source);
+
     //prevent email replacement in <script> and <textarea>
     $tags = array('script', 'textarea', 'select');
 
@@ -295,15 +315,15 @@ function hide_emails($source, &$smarty)
     }
 
     //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>!is", $source, $ahref);
+    $source = preg_replace("!<a[^>]+href=[\"'][^\"']*[-a-z0-9+_.]+@[-a-z0-9_.]+[^\"']*[\"'][^>]*>.*?</a>!is", '&&&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