diogenes.page.inc.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2004 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 
00022 require_once 'diogenes/diogenes.core.page.inc.php';
00023 require_once 'diogenes/diogenes.misc.inc.php';
00024 
00030 class DiogenesPage extends DiogenesCorePage
00031  {
00032 
00034   var $dbh;
00035 
00037   var $head = array();
00038 
00040   var $menu = array();
00041 
00043   var $_dying = false;
00044 
00047   function DiogenesPage()
00048   {
00049     global $globals;
00050     $this->dbh =& $globals->db;
00051 
00052     // call parent constructor
00053     $this->DiogenesCorePage();
00054 
00055     // register Smarty functions
00056     $this->register_function("menu","diogenes_func_menu");
00057 
00058     // common Smarty assignments
00059     $this->assign('poweredby', $globals->urlise(__("Powered by Diogenes") . " {$globals->version}"));
00060     $this->assign('phplayersmenu', $this->url("phplayersmenu"));
00061     $this->assign_by_ref('head', $this->head);
00062     $this->assign_by_ref('menuitems', $this->menu);
00063 
00064     // debugging assignments
00065     $this->assign('msg_debug_bar', __("debugging"));
00066     $this->assign('msg_debug_calltrace', __("call trace"));
00067     $this->assign('msg_debug_dbtrace', __("database trace"));
00068     $this->assign('msg_debug_plugins', __("plugins"));
00069   }
00070 
00071  
00077   function display($template, $master = '') {
00078     global $globals;
00079     
00080     $this->assign('page_template', $template);
00081     $this->makeMenu();
00082     if ($globals->debugdatabase) 
00083       $this->assign('db_trace',$globals->db->trace_format($this)); 
00084     if ($globals->debugplugins)
00085       $this->assign('plugins_trace',$globals->plugins->trace_format($this));
00086     if (($globals->debugplugins) || ($globals->debugdatabase))
00087       $this->assign('debug_css', $this->url("common.css"));
00088 
00089     if (!$master)
00090       $master = $this->getTemplate();
00091 
00092     parent::display($master);
00093   }
00094 
00095 
00099   function doLogout()
00100   {
00101     global $globals;
00102     $this->log('auth_logout', '');
00103     unset($_SESSION['log']);
00104     $_SESSION['session'] = new $globals->session;
00105   }
00106 
00107 
00110   function getTemplate()
00111   {
00112     global $globals;
00113 
00114     if ($globals->template) {
00115       // we have a system-wide default template, get its full path
00116       $tpl = $this->templatePath($globals->template);
00117     } else {
00118       // fall back on the default template
00119       $tpl = 'master.tpl';
00120     }
00121     return $tpl;
00122   }
00123 
00124 
00126   function getTemplates()
00127   {
00128     global $globals;
00129     
00130     // the default template
00131     $templates[0] = "<default>";
00132 
00133     // lookup templates in the template directory
00134     if ($globals->template_dir && is_dir($globals->template_dir)) {
00135       $files = System::find($globals->template_dir.' -maxdepth 1 -name *.tpl');
00136       foreach ($files as $file)
00137         $templates["global:".basename($file)] = "[global] ".basename($file);
00138     }
00139     return $templates; 
00140   }
00141 
00142 
00147   function httpStatus($code)
00148   {
00149     $message = array(
00150       400 => "HTTP/1.0 400 Bad Request",
00151       403 => "HTTP/1.0 403 Forbidden; Access Denied; Banned",
00152       404 => "HTTP/1.0 404 Not Found",
00153       500 => "HTTP/1.0 500 Internal Server Error",
00154     );
00155     
00156     if (!headers_sent())
00157       header(isset($message[$code]) ? $message[$code] : "HTTP/1.0 $code");
00158   }
00159 
00160   
00165   function info($msg) {
00166     $this->append('status',$msg);
00167   }
00168 
00169 
00171   function isLogged() {
00172     return isset($_SESSION['session']) && $_SESSION['session']->hasPerms('auth');
00173   }
00174 
00175 
00177   function isRoot() {
00178     return isset($_SESSION['session']) && $_SESSION['session']->hasPerms('root');
00179   }
00180 
00181 
00187   function kill($msg, $code = 500) {
00188     if ($this->_dying)
00189     {
00190       // We're in a loop of kills.  This is very, very bad.
00191       // We need to bale as quick as possible, because we can't rely on
00192       // *any* system code to not be the source of the kill() call.
00193       echo "<h1>Very fatal error: $msg</h1>\n";
00194       exit;
00195     }
00196     
00197     $this->_dying = true;
00198     $this->httpStatus($code);
00199     $this->assign('greeting', __("Diogenes error"));
00200     $this->assign('page', __("Error"));
00201     $this->assign('page_content', "<p>$msg</p>");
00202     $this->display('');
00203     exit;
00204   }
00205 
00206 
00211   function kill404($msg = "") {
00212     if ($msg)
00213       $this->info($msg);
00214     $this->kill( __("The requested document was not found."), 404);
00215   }
00216 
00217 
00223   function log($action,$data="") {
00224     if (isset($_SESSION['log']) && is_object($_SESSION['log']))
00225       $_SESSION['log']->log($action,$data);
00226   }
00227 
00228 
00231   function makeMenu() {
00232   
00233   }
00234 
00235 
00238   function startSession() {
00239     global $globals;
00240     
00241     session_start();
00242     if (!isset($_SESSION['session']))
00243       $_SESSION['session'] = new $globals->session;
00244   }
00245 
00246 
00248   function templatePath($template)
00249   {
00250     global $globals;
00251     
00252     $bits = split(":", $template);
00253     switch ($bits[0]) {
00254     case "global":
00255       $path = $globals->template_dir."/". $bits[1];
00256       break;
00257     default:
00258       $this->kill("Unkown template type : '$template'");
00259     }
00260     return $path;
00261   }
00262 
00263 
00269   function toolbar($title, $items) {
00270     $this->append('toolbars', array('title'=>$title, 'items'=>$items));
00271   }
00272 
00273 
00280   function urlBarrel($alias,$vhost,$rel="") {
00281     global $globals;
00282     return $vhost ? "http://$vhost/$rel" : "{$globals->rooturl}site/$alias/$rel";
00283   }
00284 
00285 }
00286 
00287 
00297 function diogenes_func_menu($params)
00298 {
00299   global $globals;
00300   
00301   extract($params);
00302   if (empty($items))
00303     return;
00304 
00305   switch($style) {
00306   case 1: case 2:      
00307     include("phplayersmenu/PHPLIB.php");
00308     include("phplayersmenu/layersmenu-common.inc.php");
00309     include("phplayersmenu/treemenu.inc.php");
00310     $tmp = "";
00311     $firstlevel = 0;
00312     $counter = 0;
00313     foreach ($items as $item) {
00314       $level = array_shift($item);
00315       // remember the level of the first entry
00316       if ($counter == 0)
00317         $firstlevel = $level;
00318       $dots = str_repeat(".",$level+1);
00319       $link = array_shift($item);
00320       $text = array_shift($item);
00321       $expanded = array_shift($item);
00322       $tmp .= "$dots|$link|$text||||$expanded\n";      
00323       $counter++;
00324     }
00325 
00326     $mid = new TreeMenu();
00327     $mid->setLibjsdir($globals->root."/htdocs/phplayersmenu/");
00328     $mid->setImgwww($globals->rooturl."phplayersmenu/$theme/");
00329     $mid->setMenuStructureString($tmp);
00330     $mid->parseStructureForMenu("diogenesmenu");
00331     $out = $mid->newTreeMenu("diogenesmenu");
00332 
00333     // this hack takes care of menus starting with 'orphan' child entries
00334     if (($firstlevel > 0) && ($pos = strpos($out,"<div id=\"jt1\" class=\"treemenudiv\">"))) {
00335       $insert = str_repeat("<div class=\"treemenudiv\">\n", $firstlevel);
00336       $out = substr($out,0,$pos) . $insert . substr($out,$pos);
00337     }
00338     break;
00339     
00340   case 0: default:
00341     $out = "<div class=\"menu\">";
00342     $oLevel = 0;
00343     $oExpanded = 1;
00344     foreach($items as $item) {
00345       $level = $item[0];
00346       $expanded  = isset($item[3]) ? $item[3] : 0;
00347       if ($oExpanded || $level <= $oLevel) {
00348         $out .= diogenes_func_menu_item(compact("item"));
00349         $oLevel = $level;
00350         $oExpanded = $expanded;
00351       }
00352     }
00353     $out .= "</div>";
00354     break;
00355   }
00356   return $out;
00357 }
00358 
00359 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1