X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fpage.inc.php;fp=banana%2Fpage.inc.php;h=1d62313a6f7adaa6cdfcea38a9c02c3399304e64;hb=8f4ed5202870161e24cb9e6c91039158d3e902bf;hp=8b2602c775bb4d577d599039d0b7188ce46fb468;hpb=ade32c5593c555591eb5cf859ea64b8ef7fdaaf8;p=banana.git diff --git a/banana/page.inc.php b/banana/page.inc.php index 8b2602c..1d62313 100644 --- a/banana/page.inc.php +++ b/banana/page.inc.php @@ -20,12 +20,16 @@ class BananaPage extends Smarty protected $killed = array(); protected $actions = array(); + protected $mode; + protected $json_params = array(); + public $css = ''; - public function __construct() + public function __construct($mode) { parent::Smarty(); + $this->mode = strtolower($mode); $this->compile_check = Banana::$debug_smarty; $this->template_dir = dirname(__FILE__) . '/templates/'; $this->compile_dir = Banana::$spool_root . '/templates_c/'; @@ -63,6 +67,17 @@ class BananaPage extends Smarty return true; } + /** Assign a variable in the page. + */ + public function assign($var, $value) + { + if ($this->mode === 'json') { + $this->json_params[$var] = $value; + } else { + parent::assign($var, $value); + } + } + /** Register an action to show on banana page * @param action_code HTML code of the action * @param pages ARRAY pages where to show the action (null == every pages) @@ -148,6 +163,9 @@ class BananaPage extends Smarty */ public function run() { + if ($this->mode === 'json') { + return json_encode($this->json_params); + } $tpl = $this->prepare(); if (!isset($this->pages[$this->page])) { $this->trig(_b_('La page demandée n\'existe pas'));