6c058db1bbc7f736d73eb70bfffd0c17711188b9
3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 require_once 'diogenes/diogenes.core.page.inc.php';
23 require_once 'diogenes/diogenes.misc.inc.php';
25 /** This class describes a generic Diogenes page. This class
26 * is inherited to display barrel, admin or toplevel pages.
28 * @see DiogenesBarrel DiogenesAdmin DiogenesToplevel
30 class DiogenesPage
extends DiogenesCorePage
33 /** Handle to database */
36 /** An array holding the contents of the 'head' tag */
39 /** An array of items for the 'menu' area */
42 /** Whether we're into kill() or not */
47 function DiogenesPage()
50 $this->dbh
=& $globals->db
;
52 // call parent constructor
53 $this->DiogenesCorePage();
55 // register Smarty functions
56 $this->register_function("menu","diogenes_func_menu");
58 // common Smarty assignments
59 $this->assign('poweredby', $globals->urlise(__("Powered by Diogenes") . " {$globals->version}"));
60 $this->assign('phplayersmenu', $this->url("phplayersmenu"));
61 $this->assign_by_ref('head', $this->head
);
62 $this->assign_by_ref('menuitems', $this->menu
);
64 // debugging assignments
65 $this->assign('msg_debug_bar', __("debugging"));
66 $this->assign('msg_debug_calltrace', __("call trace"));
67 $this->assign('msg_debug_dbtrace', __("database trace"));
68 $this->assign('msg_debug_plugins', __("plugins"));
72 /** Display a Smarty template.
74 * @param $template the template for the current page
75 * @param $master the master template
77 function display($template, $master = '') {
80 $this->assign('page_template', $template);
82 if ($globals->debugdatabase
)
83 $this->assign('db_trace',$globals->db
->trace_format($this));
84 if ($globals->debugplugins
)
85 $this->assign('plugins_trace',$globals->plugins
->trace_format($this));
86 if (($globals->debugplugins
) ||
($globals->debugdatabase
))
87 $this->assign('debug_css', $this->url("common.css"));
90 $master = $this->getTemplate();
92 parent
::display($master);
96 /** Perform a logout. This should destroy both the session
97 * and the logger objects.
102 $this->log('auth_logout', '');
103 unset($_SESSION['log']);
104 $_SESSION['session'] = new $globals->session
;
108 /** Returns the master template for the current context.
110 function getTemplate()
114 if ($globals->template
) {
115 // we have a system-wide default template, get its full path
116 $tpl = $this->templatePath($globals->template
);
118 // fall back on the default template
125 /** Returns the available master templates. */
126 function getTemplates()
130 // the default template
131 $templates[0] = "<default>";
133 // lookup templates in the template directory
134 if ($globals->template_dir
&& is_dir($globals->template_dir
)) {
135 $files = System
::find($globals->template_dir
.' -maxdepth 1 -name *.tpl');
136 foreach ($files as $file)
137 $templates["global:".basename($file)] = "[global] ".basename($file);
143 /** Send an HTTP status header.
145 * @param code the HTTP status code
147 function httpStatus($code)
150 400 => "HTTP/1.0 400 Bad Request",
151 403 => "HTTP/1.0 403 Forbidden; Access Denied; Banned",
152 404 => "HTTP/1.0 404 Not Found",
153 500 => "HTTP/1.0 500 Internal Server Error",
157 header(isset($message[$code]) ?
$message[$code] : "HTTP/1.0 $code");
161 /** Report an information.
165 function info($msg) {
166 $this->append('status',$msg);
170 /** Is the user logged in ? */
171 function isLogged() {
172 return isset($_SESSION['session']) && $_SESSION['session']->hasPerms('auth');
176 /** Is the user a root ("toplevel") admin ? */
178 return isset($_SESSION['session']) && $_SESSION['session']->hasPerms('root');
182 /** Die and display an error message.
184 * @param $msg the message to display
185 * @param $code the HTTP status code to send
187 function kill($msg, $code = 500) {
190 // We're in a loop of kills. This is very, very bad.
191 // We need to bale as quick as possible, because we can't rely on
192 // *any* system code to not be the source of the kill() call.
193 echo "<h1>Very fatal error: $msg</h1>\n";
197 $this->_dying
= true
;
198 $this->httpStatus($code);
199 $this->assign('greeting', __("Diogenes error"));
200 $this->assign('page', __("Error"));
201 $this->assign('page_content', "<p>$msg</p>");
207 /** Display the dreaded "file not found page".
209 * @param msg optional extra error message
211 function kill404($msg = "") {
214 $this->kill( __("The requested document was not found."), 404);
218 /** Log an information.
223 function log($action,$data="") {
224 if (isset($_SESSION['log']) && is_object($_SESSION['log']))
225 $_SESSION['log']->log($action,$data);
231 function makeMenu() {
236 /** Start session handling.
238 function startSession() {
242 if (!isset($_SESSION['session']))
243 $_SESSION['session'] = new $globals->session
;
247 /** Returns the path to a given template. */
248 function templatePath($template)
252 $bits = split(":", $template);
255 $path = $globals->template_dir
."/". $bits[1];
258 $this->kill("Unkown template type : '$template'");
264 /** Adds a toolbar to the top of the page.
269 function toolbar($title, $items) {
270 $this->append('toolbars', array('title'=>$title, 'items'=>$items));
274 /** Returns the URL to a Diogenes barrel.
280 function urlBarrel($alias,$vhost,$rel="") {
282 return $vhost ?
"http://$vhost/$rel" : "{$globals->rooturl}site/$alias/$rel";
288 /** Displays a full menu.
291 * +items the menu items
292 * +style menu style (0, 1, 2)
295 * @param params the function input
297 function diogenes_func_menu($params)
307 include("phplayersmenu/PHPLIB.php");
308 include("phplayersmenu/layersmenu-common.inc.php");
309 include("phplayersmenu/treemenu.inc.php");
313 foreach ($items as $item) {
314 $level = array_shift($item);
315 // remember the level of the first entry
317 $firstlevel = $level;
318 $dots = str_repeat(".",$level+
1);
319 $link = array_shift($item);
320 $text = array_shift($item);
321 $expanded = array_shift($item);
322 $tmp .= "$dots|$link|$text||||$expanded\n";
326 $mid = new TreeMenu();
327 $mid->setLibjsdir($globals->root
."/htdocs/phplayersmenu/");
328 $mid->setImgwww($globals->rooturl
."phplayersmenu/$theme/");
329 $mid->setMenuStructureString($tmp);
330 $mid->parseStructureForMenu("diogenesmenu");
331 $out = $mid->newTreeMenu("diogenesmenu");
333 // this hack takes care of menus starting with 'orphan' child entries
334 if (($firstlevel > 0) && ($pos = strpos($out,"<div id=\"jt1\" class=\"treemenudiv\">"))) {
335 $insert = str_repeat("<div class=\"treemenudiv\">\n", $firstlevel);
336 $out = substr($out,0,$pos) . $insert . substr($out,$pos);
341 $out = "<div class=\"menu\">";
344 foreach($items as $item) {
346 $expanded = isset($item[3]) ?
$item[3] : 0;
347 if ($oExpanded ||
$level <= $oLevel) {
348 $out .= diogenes_func_menu_item(compact("item"));
350 $oExpanded = $expanded;