1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
<?php
/**
* This is a view of the Horde topbar.
*
* Useful properties:
* - subinfo: (string) Right-aligned content of the sub-bar.
* - search: (boolean) Whether to show the search bar.
* - searchAction: (string) The form action attribute of the search form.
* - searchMenu: (boolean) whether to show a drop down icon inside the search
* field.
* - searchLabel: (string) Ghost label of the search field.
* - searchParameters: (array) Key-value-hash with additional hidden form
* fields.
*
* Copyright 2012-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL-2). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl LGPL-2
* @package Horde
*/
class Horde_View_Topbar extends Horde_View
{
/**
* Constructor.
*
* @param array $config Configuration key-value pairs.
*/
public function __construct($config = array())
{
global $injector, $prefs, $registry;
if (empty($config['templatePath'])) {
$config['templatePath'] = $registry->get('templates', 'horde') . '/topbar';
}
parent::__construct($config);
$this->addHelper('Text');
/* Logo. */
$this->portalUrl = $registry->getServiceLink(
'portal', $registry->getApp());
if (class_exists('Horde_Bundle')) {
$this->version = Horde_Bundle::SHORTNAME . ' ' . Horde_Bundle::VERSION;
} else {
$this->version = $registry->getVersion('horde');
}
/* Main menu. */
$topbar = $injector->getInstance('Horde_Core_Factory_Topbar')
->create('Horde_Tree_Renderer_Menu', array('nosession' => true));
$this->menu = $topbar->getTree();
/* Search form. */
$this->searchAction = '#';
$this->searchIcon = Horde_Themes::img('search-topbar.png');
$this->searchLabel = _("Search");
/* Login/Logout. */
if ($registry->getAuth()) {
if ($registry->showService('logout')) {
$this->logoutUrl =
$registry->getServiceLink(
'logout',
$registry->getApp()
)
->setRaw(false);
}
} else {
if ($registry->showService('login')) {
$this->loginUrl =
$registry->getServiceLink(
'login',
$registry->getApp()
)
->setRaw(false)
->add('url', Horde::selfUrl(true, true, true));
}
}
/* Sub bar. */
$this->date = strftime($prefs->getValue('date_format'));
$pageOutput = $injector->getInstance('Horde_PageOutput');
$pageOutput->addScriptPackage('Horde_Core_Script_Package_Datejs');
$pageOutput->addScriptFile('topbar.js', 'horde');
$pageOutput->addInlineJsVars(array('HordeTopbar.conf' => array(
/* Need explicit URI here, since topbar may be running in
* an application's scope. */
'URI_AJAX' => $registry->getServiceLink('ajax', 'horde')->url,
'app' => $registry->getApp(),
'format' => Horde_Core_Script_Package_Datejs::translateFormat($prefs->getValue('date_format')),
'hash' => $topbar->getHash(),
'refresh' => intval($prefs->getValue('menu_refresh_time'))
)));
/* Sidebar. */
$this->sidebarWidth = $prefs->getValue('sidebar_width');
}
/**
* Returns the HTML code for the topbar.
*
* @param string $name The template to process.
*
* @return string The topbar's HTML code.
*/
public function render($name = 'topbar', $locals = array())
{
if ($this->search) {
$GLOBALS['injector']->getInstance('Horde_PageOutput')
->addScriptFile('form_ghost.js', 'horde');
if (!isset($this->searchParameters)) {
$action = new Horde_Url($this->searchAction);
$this->searchAction = $action->url;
$this->searchParameters = $action->parameters;
}
}
$this->sidebar = $GLOBALS['page_output']->sidebar;
return parent::render($name, $locals);
}
/**
* Handler for string casting.
*
* @return string The sidebar's HTML code.
*/
public function __toString()
{
return $this->render();
}
}
|