Add javascript flag in templates
[banana.git] / banana / page.inc.php
index 630f1e3..b325330 100644 (file)
@@ -7,7 +7,9 @@
 * Copyright: See COPYING files that comes with this distribution
 ********************************************************************************/
 
-require_once 'smarty/libs/Smarty.class.php';
+if (@!include_once('Smarty.class.php')) {
+    require_once 'smarty/libs/Smarty.class.php';
+}
 
 class BananaPage extends Smarty
 {
@@ -28,7 +30,9 @@ class BananaPage extends Smarty
         $this->template_dir  = dirname(__FILE__) . '/templates/';
         $this->compile_dir   = Banana::$spool_root . '/templates_c/';
         $this->register_prefilter('banana_trimwhitespace');
-    
+        if (!is_dir($this->compile_dir)) {
+            mkdir($this->compile_dir);
+        }
     }
 
     /** Add an error message
@@ -178,26 +182,29 @@ class BananaPage extends Smarty
         $this->assign('withtabs'   , Banana::$withtabs);
         $this->assign('feed_format', Banana::$feed_format);
         $this->assign('feed_active', Banana::$feed_active);
+        $this->assign('with_javascript', Banana::$msgshow_javascript);
 
         $this->register_function('url',     array($this, 'makeUrl'));
         $this->register_function('link',    array($this, 'makeLink'));
         $this->register_function('imglink', array($this, 'makeImgLink'));
         $this->register_function('img',     array($this, 'makeImg'));
         $this->register_modifier('b',       '_b_');
-        $this->register_modifier('htmlentities', 'banana_htmlentities');
 
         $this->assign('errors',    $this->error);
         $this->assign('page',      $this->page);
         $this->assign('pages',     $this->pages);
         $this->assign('actions',   $this->actions);
+        $this->register_modifier('banana_utf8entities', 'banana_utf8entities');
+        $this->register_modifier('banana_entities', 'banana_entities');
+
+        if ($ent) {
+            $this->default_modifiers = Array('@banana_entities');
+        }
 
         if (!Banana::$debug_smarty) {
             $error_level = error_reporting(0);
         }
         $text = $this->fetch($tpl);
-        if ($ent) {
-            $text = banana_utf8entities($text);
-        }
         if (!Banana::$debug_smarty) {
             error_reporting($error_level);
         }
@@ -226,7 +233,7 @@ class BananaPage extends Smarty
             return $res;
         }   
         $proto = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
-        $host  = $_SERVER['HTTP_HOST'];
+        $host  = Banana::$baseurl ? Banana::$baseurl : $_SERVER['SERVER_NAME'];
         $file  = $_SERVER['PHP_SELF'];
     
         if (count($params) != 0) {
@@ -259,7 +266,7 @@ class BananaPage extends Smarty
      */
     public function makeLink(array $params, &$smarty = null)
     {
-        $catch = array('text', 'popup', 'class', 'accesskey');
+        $catch = array('text', 'popup', 'class', 'accesskey', 'style');
         foreach ($catch as $key) {
             ${$key} = isset($params[$key]) ? $params[$key] : null;
             unset($params[$key]);
@@ -272,16 +279,19 @@ class BananaPage extends Smarty
             $popup .= ' (raccourci : ' . $accesskey . ')';
         }
         if (!is_null($popup)) {
-            $popup = ' title="' . banana_htmlentities($popup) . '"';
+            $popup = ' title="' . banana_entities($popup) . '"';
         }
         if (!is_null($class)) {
             $class = ' class="' . $class . '"';
         }
+        if (!is_null($style)) {
+            $style = ' style="' . $style . '"';
+        }
         if (!is_null($accesskey)) {
             $accesskey = ' accesskey="' . $accesskey . '"';
         }
-        return '<a href="' . banana_htmlentities($link) . '"'
-              . $popup . $class . $accesskey
+        return '<a href="' . banana_entities($link) . '"'
+              . $popup . $class . $style . $accesskey
               . '>' . $text . '</a>';
     }
 
@@ -318,7 +328,7 @@ class BananaPage extends Smarty
         }
 
         $proto = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
-        $host  = $_SERVER['HTTP_HOST'];
+        $host  = Banana::$baseurl ? Banana::$baseurl : $_SERVER['SERVER_NAME'];
         $file  = dirname($_SERVER['PHP_SELF']) . '/img/' . $img;
         $url   = $proto . $host . $file;
 
@@ -329,15 +339,18 @@ class BananaPage extends Smarty
      * @param src STRING javascript name
      * @return Javascript tag
      */
-    public function makeJs(array $src)
+    public function makeJs($src)
     {
+        if (!Banana::$msgshow_javascript) {
+            return '';
+        }
         if (function_exists('hook_makeJs')
                 && $res = hook_makeJs($src)) {
             return $res;
         }
 
         $proto = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
-        $host  = $_SERVER['HTTP_HOST'];
+        $host  = Banana::$baseurl ? Banana::$baseurl : $_SERVER['SERVER_NAME'];
         $file  = dirname($_SERVER['PHP_SELF']) . '/javascript/' . $src . '.js';
         $url   = $proto . $host . $file;
 
@@ -377,6 +390,7 @@ class BananaPage extends Smarty
     public function redirect(array $params = array())
     {
         header('Location: ' . $this->makeUrl($params));
+        exit;
     }
 }