Source for file menu.php

Documentation is available at menu.php

  1. <?php
  2. /**
  3. * Main menu for admin and normal users
  4. *
  5. @author    Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id$
  9. @package    Bumblebee
  10. @subpackage Misc
  11. */
  12.  
  13. /** Load ancillary functions */
  14. require_once 'inc/typeinfo.php';
  15.  
  16. /** permission codes */
  17. require_once 'inc/permissions.php';
  18.  
  19. /**
  20. * Main menu for admin and normal users
  21. *
  22. @package    Bumblebee
  23. @subpackage Misc
  24. @todo //TODO: combine the data storage with action.php for cleaner implementation
  25. */
  26. class UserMenu {
  27.   /**
  28.   * list of available actions
  29.   * @var ActionListing 
  30.   */
  31.   var $actionListing;
  32.   /**
  33.   * text output before start of menu block
  34.   * @var string 
  35.   */
  36.   var $menuPrologue   = '';
  37.   /**
  38.   * text output after end of menu block
  39.   * @var string 
  40.   */
  41.   var $menuEpilogue   = '';
  42.   /**
  43.   * html id for the enclosing DIV
  44.   * @var string 
  45.   */
  46.   var $menuDivId      = 'menulist';
  47.   /**
  48.   * html start-tag for the menu section
  49.   * @var string 
  50.   */
  51.   var $menuStart      = '<ul>';
  52.   /**
  53.   * html menu entry (complete!) for the link to the online help
  54.   * @var string 
  55.   */
  56.   var $menuHelp;
  57.   /**
  58.   * html stop-tag for the menu section
  59.   * @var string 
  60.   */
  61.   var $menuStop       = '</ul>';
  62.   /**
  63.   * html start-tag for each menu entry
  64.   * @var string 
  65.   */
  66.   var $itemStart      = '<li>';
  67.   /**
  68.   * html stop-tag for each menu entry
  69.   * @var string 
  70.   */
  71.   var $itemStop       = '</li>';
  72.   /**
  73.   * html id for div that alerts to current Masquerade setting
  74.   * @var string 
  75.   */
  76.   var $masqDivId      = 'masquerade';
  77.   /**
  78.   * html start-tag for each menu section
  79.   * @var string 
  80.   */
  81.   var $headerStart    = '<li class="menuSection">';
  82.   /**
  83.   * html stop-tag for each menu section
  84.   * @var string 
  85.   */
  86.   var $headerStop     = '</li>';
  87.   /**
  88.   * text to include at start of main menu section
  89.   * @var string 
  90.   */
  91.   var $mainMenuHeader;
  92.   /**
  93.   * text to include at start of admin menu section
  94.   * @var string 
  95.   */
  96.   var $adminHeader;
  97.   /**
  98.   * tag to use for the masq alert style (be careful of using div in an ul!)
  99.   * @var string 
  100.   */
  101.   var $masqAlertTag  = 'li';
  102.   /**
  103.   * display the menu
  104.   * @var boolean 
  105.   */
  106.   var $showMenu       = true;
  107.  
  108.   /**
  109.   * logged in user's credentials
  110.   * @var BumblebeeAuth 
  111.   */
  112.   var $_auth;
  113.   /**
  114.   * currently selected action
  115.   * @var string 
  116.   */
  117.   var $_verb;
  118.  
  119.   /**
  120.   * Constructor
  121.   * @param BumblebeeAuth $auth  user's credentials
  122.   * @param string        $verb  current action
  123.   */
  124.   function UserMenu($auth$verb{
  125.     $this->_auth = $auth;
  126.     $this->_verb = $verb;
  127.     $this->menuHelp       = '<li class="last"><a href="http://bumblebeeman.sf.net/docs?section=__section__&amp;version=__version__">' T_('Help''</a></li>';
  128.     $this->mainMenuHeader = T_('Main Menu');
  129.     $this->adminHeader    = T_('Administration');
  130.   }
  131.  
  132.   /**
  133.   * Generates an html representation of the menu
  134.   * @return string       menu in html format
  135.   */
  136.   function getMenu({
  137.     if ($this->showMenu{
  138.       return '';
  139.     }
  140.     $menu  '<div'.($this->menuDivId ? ' id="'.$this->menuDivId.'"' :'' ).'>';
  141.     $menu .= $this->menuStart;
  142.     $menu .= $this->_constructMenuEntries();
  143.     if ($this->_auth->amMasqed(&& $this->_verb != 'masquerade')
  144.           $menu .= $this->_getMasqAlert();
  145.     $menu .= $this->_getHelpMenu();
  146.     $menu .= $this->menuStop;
  147.     $menu .= '</div>';
  148.     return $menu;
  149.   }
  150.  
  151.   /**
  152.   * Generates an html representation of the menu according to the current user's permissions
  153.   * @return string       menu in html format
  154.   */
  155.   function _constructMenuEntries({
  156.     $t '';
  157.     if ($this->mainMenuHeader{
  158.       $t .= $this->headerStart.$this->mainMenuHeader.$this->headerStop;
  159.     }
  160.     $first_admin true;
  161.     #preDump($this->actionListing->actions);
  162.     foreach ($this->actionListing->actions as $action{
  163.       #print $action->name()."<br />\n";
  164.       #print $action->name(). " requires " . $action->permissions() . " have " .$this->_auth->system_permissions."<br />\n";
  165.       if ($action->menu_visible(&& $this->_auth->permitted($action->permissions())) {
  166.         #print " visible";
  167.         if ($first_admin && $action->requires_admin()) {
  168.           #print " admin header";
  169.           $first_admin false;
  170.           if ($this->adminHeader{
  171.             $t .= $this->headerStart.$this->adminHeader.$this->headerStop;
  172.           }
  173.         }
  174.         $t .= $this->itemStart
  175.               .'<a href="'.makeURL($action->name()).'">'.$action->menu().'</a>'
  176.             .$this->itemStop;
  177.       }
  178.       #print "<br/>";
  179.     }
  180.     return $t;
  181.   }
  182.  
  183.   /**
  184.   * Generates an html div to alert the user that masquerading is in action
  185.   * @return string       menu in html format
  186.   */
  187.   function _getMasqAlert({
  188.     $t '<'.$this->masqAlertTag.' id="'.$this->masqDivId.'">'
  189.              .'Mask: '.xssqw($this->_auth->eusername)
  190.              .' (<a href="'.makeURL('masquerade'array('id'=>-1)).'">end</a>)'
  191.         .'</'.$this->masqAlertTag.'>';
  192.     return $t;
  193.   }
  194.  
  195.   /**
  196.   * Generates an html snippet to for the link to the online help
  197.   * @return string       menu in html format
  198.   * @global string       version of the Bumblebee installation (can serve different versions if necessary)
  199.   */
  200.   function _getHelpMenu({
  201.     global $BUMBLEBEEVERSION;
  202.     $help $this->menuHelp;
  203.     $help preg_replace(array('/__version__/',   '/__section__/'),
  204.                          array($BUMBLEBEEVERSION$this->_verb),
  205.                          $help);
  206.     return $help;
  207.   }
  208.  
  209. // class UserMenu
  210.  
  211.  
  212. /**
  213. * create a URL for an anchor
  214. @param string  $action    action to be performed
  215. @param array   $list      (optional) key => value data to be added to the URL
  216. @param boolean $escape    use &amp; rather than & in the URL
  217. @return string URL
  218. */
  219. function makeURL($action=NULL$list=NULL$escape=true{
  220.   $conf ConfigReader::getInstance();
  221.   $list is_array($list$list array();
  222.   if ($action !== NULL$list['action'$action;
  223.   $args array();
  224.   foreach ($list as $field => $value{
  225.     if (is_array($value)) $value join(','$value);
  226.     $args[$field.'='.urlencode($value);
  227.   }
  228.   $delim $escape '&amp;' '&';
  229.   if (count($args0return $conf->BaseURL.'?'.join($delim$args);
  230.  
  231.   return $conf->BaseURL;
  232. }
  233.  
  234.  
  235. /**
  236. * Create an absolute URL for an anchor (include protocol and port)
  237. *
  238. @param mixed   $target 
  239. @param array   $list      (optional) key => value data to be added to the URL
  240. @param boolean $escape    use &amp; rather than & in the URL
  241. @return  string  Absolute URL
  242. */
  243. function makeAbsURL($target=NULL$escape=true{
  244.  
  245.   if (isset($_SERVER['HTTPS']&& !strcasecmp($_SERVER['HTTPS']'on')) {
  246.     $protocol 'https';
  247.   else {
  248.     $protocol 'http';
  249.   }
  250.  
  251.   $port = isset($_SERVER['SERVER_PORT']$_SERVER['SERVER_PORT'80;
  252.  
  253.   // filter out well known ports from the URL
  254.   if (($protocol == 'http' && $port == 80|| ($protocol == 'https' && $port == 443)) {
  255.     unset($port);
  256.   }
  257.  
  258.   $host $_SERVER['SERVER_NAME'];
  259.   if (empty($host)) {
  260.     list($hostexplode(':'$_SERVER['HTTP_HOST']);
  261.   }
  262.  
  263.   $serverPart $protocol .'://'$host (isset($port':'$port '');
  264.  
  265.   if (is_array($target|| $target === NULL{
  266.     $pathPart makeURL($target[0]$target[1]$escape);
  267.   else {
  268.     $conf ConfigReader::getInstance();
  269.     $pathPart $conf->BasePath $target;
  270.   }
  271.  
  272.   $pathPart preg_replace('@//+@''/'$pathPart);
  273.  
  274.   return $serverPart $pathPart;
  275. }
  276.  
  277. /**
  278. * Bounces the user to an alternative location, terminating execution of this script
  279. *
  280. @param    string   $location    URL that the user should be redirected to
  281. @returns  NEVER RETURNS
  282. */
  283. function redirectUser($location{
  284.   header("Location: "$location);
  285.   exit;
  286. }
  287.  
  288. ?>

Documentation generated on Tue, 06 Mar 2007 10:01:46 +0000 by phpDocumentor 1.3.0