2 /********************************************************************************
3 * banana/page.inc.php : class for group lists
4 * ------------------------
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
10 require_once 'smarty/libs/Smarty.class.php';
12 class BananaPage
extends Smarty
14 private $error = array();
17 private $pages = array();
18 private $actions = array();
20 public function __construct()
24 $this->compile_check
= Banana
::$debug_smarty;
25 $this->template_dir
= dirname(__FILE__
) . '/templates/';
26 $this->compile_dir
= dirname(dirname(__FILE__
)) . '/spool/templates_c/';
27 $this->register_prefilter('banana_trimwhitespace');
31 public function trig($message)
33 $this->error
[] = $message;
36 public function kill($message)
38 $this->trig($message);
42 public function setPage($page)
47 public function registerAction($action_code, array $pages = null
)
49 $this->actions
[] = array('text' => $action_code, 'pages' => $pages);
53 public function registerPage($name, $text, $template = null
)
55 $this->pages
[$name] = array('text' => $text, 'template' => $template);
61 $this->registerPage('subscribe', _b_('Abonnements'), null
);
62 $this->registerPage('forums', _b_('Les forums'), null
);
63 if (!is_null(Banana
::$group)) {
64 $this->registerPage('thread', Banana
::$group, null
);
65 if (!is_null(Banana
::$artid)) {
66 $this->registerPage('message', _b_('Message'), null
);
67 if ($this->page
== 'cancel') {
68 $this->registerPage('cancel', _b_('Annulation'), null
);
69 } elseif ($this->page
== 'new') {
70 $this->registerPage('new', _b_('RĂ©pondre'), null
);
72 } elseif ($this->page
== 'new') {
73 $this->registerPage('new', _b_('Nouveau'), null
);
76 foreach ($this->actions
as $key=>&$action) {
77 if (!is_null($action['pages']) && !in_array($this->page
, $action['pages'])) {
78 unset($this->actions
[$key]);
81 $this->assign('group', Banana
::$group);
82 $this->assign('artid', Banana
::$artid);
83 $this->assign('part', Banana
::$part);
84 $this->assign('first', Banana
::$first);
85 $this->assign('action', Banana
::$action);
86 $this->assign('profile', Banana
::$profile);
87 $this->assign('spool', Banana
::$spool);
88 $this->assign('protocole', Banana
::$protocole);
90 $this->assign('errors', $this->error
);
91 $this->assign('page', $this->page
);
92 $this->assign('pages', $this->pages
);
93 $this->assign('actions', $this->actions
);
95 $this->register_function('url', array($this, 'makeUrl'));
96 $this->register_function('link', array($this, 'makeLink'));
97 $this->register_function('imglink', array($this, 'makeImgLink'));
98 $this->register_function('img', array($this, 'makeImg'));
99 if (!Banana
::$debug_smarty) {
100 $error_level = error_reporting(0);
102 $text = $this->fetch('banana-base.tpl');
103 $text = banana_utf8entities($text);
104 if (!Banana
::$debug_smarty) {
105 error_reporting($error_level);
110 public function makeUrl($params, &$smarty = null
)
112 if (function_exists('hook_makeLink')
113 && $res = hook_makeLink($params)) {
116 $proto = empty($_SERVER['HTTPS']) ?
'http://' : 'https://';
117 $host = $_SERVER['HTTP_HOST'];
118 $file = $_SERVER['PHP_SELF'];
120 if (count($params) != 0) {
122 foreach ($params as $key=>$value) {
123 if (strlen($get) != 1) {
126 $get .= $key . '=' . $value;
131 return $proto . $host . $file . $get;
134 public function makeLink($params, &$smarty = null
)
136 $catch = array('text', 'popup', 'class', 'accesskey');
137 foreach ($catch as $key) {
138 $
{$key} = isset($params[$key]) ?
$params[$key] : null
;
139 unset($params[$key]);
141 $link = $this->makeUrl($params, &$smarty);
142 if (is_null($text)) {
145 if (!is_null($accesskey)) {
146 $popup .= ' (raccourci : ' . $accesskey . ')';
148 if (!is_null($popup)) {
149 $popup = ' title="' . $popup . '"';
151 if (!is_null($class)) {
152 $class = ' class="' . $class . '"';
155 if (isset($params['action']) && $params['action'] == 'view') {
156 $target = ' target="_blank"';
158 if (!is_null($accesskey)) {
159 $accesskey = ' accesskey="' . $accesskey . '"';
161 return '<a href="' . htmlentities($link) . '"'
162 . $target . $popup . $class . $accesskey
163 . '>' . $text . '</a>';
166 public function makeImg($params, &$smarty = null
)
168 $catch = array('img', 'alt', 'height', 'width');
169 foreach ($catch as $key) {
170 $
{$key} = isset($params[$key]) ?
$params[$key] : null
;
173 if (function_exists('hook_makeImg')
174 && $res = hook_makeImg($img, $alt, $height, $width)) {
178 if (!is_null($width)) {
179 $width = ' width="' . $width . '"';
181 if (!is_null($height)) {
182 $height = ' height="' . $height . '"';
185 $proto = empty($_SERVER['HTTPS']) ?
'http://' : 'https://';
186 $host = $_SERVER['HTTP_HOST'];
187 $file = dirname($_SERVER['PHP_SELF']) . '/img/' . $img;
188 $url = $proto . $host . $file;
190 return '<img src="' . $url . '"' . $height . $width . ' alt="' . _b_($alt) . '" />';
193 public function makeImgLink($params, &$smarty = null
)
195 $params['alt'] = _b_($params['alt']);
196 $params['popup'] = $params['alt'];
197 $params['text'] = $this->makeImg($params, $smarty);
198 return $this->makeLink($params, $smarty);
201 /** Redirect to the page with the given parameter
204 public function redirect($params = array())
206 header('Location: ' . $this->makeUrl($params));
210 // {{{ function banana_trimwhitespace
212 function banana_trimwhitespace($source, &$smarty)
214 $tags = array('script', 'pre', 'textarea');
216 foreach ($tags as $tag) {
217 preg_match_all("!<{$tag}[^>]+>.*?</{$tag}>!is", $source, $
{$tag});
218 $source = preg_replace("!<{$tag}[^>]+>.*?</{$tag}>!is", "&&&{$tag}&&&", $source);
221 // remove all leading spaces, tabs and carriage returns NOT
222 // preceeded by a php close tag.
223 $source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source);
225 foreach ($tags as $tag) {
226 $source = preg_replace("!&&&{$tag}&&&!e", 'array_shift(${$tag}[0])', $source);
235 // vim:set et sw=4 sts=4 ts=4: