diff --git a/src/lib/php/Plugin/DefaultPlugin.php b/src/lib/php/Plugin/DefaultPlugin.php index ebdd6044..9aec619d 100644 --- a/src/lib/php/Plugin/DefaultPlugin.php +++ b/src/lib/php/Plugin/DefaultPlugin.php @@ -1,423 +1,422 @@ name = $name; foreach ($parameters as $key => $value) { $this->setParameter($key, $value); } global $container; $this->container = $container; $this->session = $this->getObject('session'); $this->renderer = $this->getObject('twig.environment'); $this->logger = $this->getObject('logger'); $this->menu = $this->getObject('ui.component.menu'); $this->microMenu = $this->getObject('ui.component.micromenu'); } private function setParameter($key, $value) { switch ($key) { case self::TITLE: $this->title = $value; break; case self::PERMISSION: $this->permission = $value; break; case self::REQUIRES_LOGIN: $this->requiresLogin = $value; break; case self::LEVEL: $this->PluginLevel = $value; break; case self::DEPENDENCIES: $this->dependencies = $value; break; case self::INIT_ORDER: $this->InitOrder = $value; break; case self::MENU_LIST: $this->MenuList = $value; break; case self::MENU_ORDER: $this->MenuOrder = $value; break; case self::MENU_TARGET: $this->MenuTarget = $value; break; default: throw new \Exception("unhandled parameter $key in module " . $this->name); } } /** * @return string */ public function getName() { return $this->name; } /** * @return string */ public function getVersion() { return $this->version; } /** * @return string */ public function getTitle() { return $this->title; } /** * @return int */ public function isRequiresLogin() { return $this->requiresLogin; } /** * @return array */ public function getDependency() { return $this->dependencies; } /** * @return int */ public function getPluginLevel() { return $this->PluginLevel; } /** * @return int */ public function getDBaccess() { return $this->permission; } /** * @return int */ public function getState() { return PLUGIN_STATE_READY; } /** * @return int */ public function getInitOrder() { return $this->InitOrder; } public function getNoMenu() { return 0; } /** * \brief Customize submenus. */ protected function RegisterMenus() { if (isset($this->MenuList) && (!$this->requiresLogin || $this->isLoggedIn())) { menu_insert("Main::" . $this->MenuList, $this->MenuOrder, $this->name, $this->name); } } /** * @return Response */ public function getResponse() { $request = Request::createFromGlobals(); $request->setSession($this->session); $this->checkPrerequisites(); $startTime = microtime(true); $response = $this->handle($request); $response->prepare($request); $this->logger->debug(sprintf("handle request in %.3fs", microtime(true) - $startTime)); return $response; } /** * @param $name * @return object */ public function getObject($name) { return $this->container->get($name); } public function preInstall() { $this->RegisterMenus(); } public function postInstall() { } public function unInstall() { } public function execute() { $startTime = microtime(true); $response = $this->getResponse(); $this->logger->debug(sprintf("prepare response in %.3fs", microtime(true) - $startTime)); $response->send(); } /** * @param Request $request * @return Response */ protected abstract function handle(Request $request); /** * @param string $templateName * @param array $vars * @param string[] $headers * @return Response */ protected function render($templateName, $vars = null, $headers = null) { if ($this->requiresLogin && !$this->isLoggedIn()) { new Response("permission denied", Response::HTTP_FORBIDDEN, array("contentType" => "text/plain")); } $startTime = microtime(true); $content = $this->renderer->loadTemplate($templateName) ->render($vars ?: $this->getDefaultVars()); $this->logger->debug(sprintf("%s: render response in %.3fs", get_class($this), microtime(true) - $startTime)); return new Response( $content, Response::HTTP_OK, $headers ?: $this->getDefaultHeaders() ); } public function isLoggedIn() { return (!empty($_SESSION[Auth::USER_NAME]) && $_SESSION[Auth::USER_NAME] != 'Default User'); } private function checkPrerequisites() { if ($this->requiresLogin && !$this->isLoggedIn()) { throw new \Exception("not allowed without login"); } foreach ($this->dependencies as $dependency) { $id = plugin_find_id($dependency); if ($id < 0) { $this->unInstall(); throw new \Exception("unsatisfied dependency '$dependency' in module '" . $this->getName() . "'"); } } } /** * @return array */ protected function getDefaultHeaders() { return array( 'Content-type' => 'text/html', 'Pragma' => 'no-cache', 'Cache-Control' => 'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0', 'Expires' => 'Expires: Thu, 19 Nov 1981 08:52:00 GMT'); } /** * @return array */ protected function getDefaultVars() { $vars = array(); $metadata = "\n"; $metadata .= "\n"; $vars['metadata'] = $metadata; if (!empty($this->title)) { $vars[self::TITLE] = htmlentities($this->title); } $styles = "\n"; $styles .= "\n"; $styles .= "\n"; $styles .= "\n"; $styles .= "\n"; $styles .= $this->menu->OutputCSS(); $vars['styles'] = $styles; $vars['menu'] = $this->menu->Output($this->title); global $SysConf; if (array_key_exists('BUILD', $SysConf)) { $vars['versionInfo'] = array( 'version' => $SysConf['BUILD']['VERSION'], 'buildDate' => $SysConf['BUILD']['BUILD_DATE'], 'commitHash' => $SysConf['BUILD']['COMMIT_HASH'], - 'commitDate' => $SysConf['BUILD']['COMMIT_DATE'] + 'commitDate' => $SysConf['BUILD']['COMMIT_DATE'], + 'branchName' => $SysConf['BUILD']['BRANCH'] ); } return $vars; } protected function mergeWithDefault($vars) { return array_merge($this->getDefaultVars(), $vars); } protected function flushContent($content) { return $this->render("include/base.html.twig",$this->mergeWithDefault(array("content"=>$content))); } /** * @param string $name * @throws \Exception * @return string|null */ public function __get($name) { if (method_exists($this, ($method = 'get' . ucwords($name)))) { return $this->$method(); } else { throw new \Exception("property '$name' not found in module " . $this->name); } } function __toString() { return getStringRepresentation(get_object_vars($this), get_class($this)); } - - } diff --git a/src/lib/php/Plugin/FO_Plugin.php b/src/lib/php/Plugin/FO_Plugin.php index 72ea3b42..aec6322a 100644 --- a/src/lib/php/Plugin/FO_Plugin.php +++ b/src/lib/php/Plugin/FO_Plugin.php @@ -1,510 +1,510 @@ $NoneText, Auth::PERM_READ => $ReadText, Auth::PERM_WRITE => $WriteText, Auth::PERM_ADMIN => $AdminText); /** * \class FO_Plugin * \brief This is the Plugin class. All plugins should: * 1. Use this class or extend this class. * 2. After defining the necessary functions and values, the plugin * must add the new element to the Plugins array. * For example: * $NewPlugin = new Plugin; * $NewPlugin->Name="Fred"; * if ($NewPlugin->Initialize() != 0) { destroy $NewPlugin; } */ class FO_Plugin implements Plugin { /** * All public fields can be empty, indicating that it does not apply. */ var $State = PLUGIN_STATE_INVALID; /** * Name defines the official name of this plugin. Other plugins may * call this plugin based on this name. */ var $Name = ""; var $Version = "1.0"; var $Title = ""; // used for HTML title tags and window menu bars /** * Access level restrictions */ var $DBaccess = PLUGIN_DB_NONE; /* what kind of access is needed? */ var $LoginFlag = 0; /* Must you be logged in to access this plugin? 1=yes, 0=no */ /** * Common for HTML output */ var $NoMenu = 0; /* 1 = Don't show the HTML menu at the top of page */ var $NoHeader = 0; /* 1 = Don't show the HTML header at the top of page */ /** * This array lists plugin dependencies by name and initialization order. * These are used to call PostInitialize in the correct order. * PostInitialize will be called when all dependencies are ready. * InitOrder says "after all dependencies are ready, do higher value * items first." For example, this allows for menus to be initialized * before anything else. (You probably won't need to change InitOrder.) */ var $PluginLevel = 10; /* used for sorting plugins -- higher comes first after dependencies are met */ var $Dependency = array(); var $InitOrder = 0; /** @var Menu */ private $menu; /** @var MicroMenu */ protected $microMenu; /** @var Twig_Environment */ protected $renderer; /** @var Request|NULL */ private $request; /** @var string[] */ private $headers = array(); protected $vars = array(); /** * Plugins may define a menu item. * The menu name defines where it belongs. * Each menu item belongs in a category (menu list) and could be in * subcategories (menu sublists). The MenuList identifies * the list (and sublists) where this item belongs. The menu heirarchy * is defined by a name and a "::" to denote a submenu item. * * The MenuName defines the name for this item in the menu. * * Finally, multiple plugins may place multiple items under the same menu. * The MenuOrder assigns a numeric ranking for items. All items * at the same level are sorted alphabetically by MenuName. * * For example, to define an "About" menu item under the "Help" menu: * $MenuList = "Help::About"; * $MenuOrder=0; * And a "delete" agent under the tool, administration menu would be: * $MenuList = "Tools::Administration::Delete"; * $MenuOrder=0; * * Since menus may link to results that belong in a specific window, * $MenuTarget can identify the window. If not defined, the UI will use * a default results window. * * /note * 1. If the MenuList location does not exist, then it will be created. * 2. If a plugin does not have a menulist item, then it will not appear * in any menus. * 3. MenuList is case and SPACE sensitive. "Help :: About" defines * "Help " and " About". While "Help::About" defines "Help" and "About". */ var $MenuList = NULL; var $MenuOrder = 0; var $MenuTarget = NULL; /** * These next variables define required functionality. * If the functions exist, then they are called. However, plugins are * not required to define any of these. */ /** * \brief This function (when defined) is only called when * the plugin is first installed. It should make sure all * requirements are available and create anything it needs to run. * It returns 0 on success, non-zero on failure. * A failed install is not inserted in the system. * * \note It may be called multiple times. It must check that * changes are needed BEFORE doing any changes. * Also, it must check for partial installs in case the user is * recovering from an installation failure. */ function Install() { return 0; } /** * \brief This function (when defined) is only called once, * when the plugin is removed. It should uninstall and remove * all items that are only used by this plugin. There should be * no residues -- if the plugin is ever installed again, it should * act like a clean install. Thus, any DB, files, or state variables * specific to this plugin must be removed. * This function must always succeed. */ function Remove() { return; } /** * \brief base constructor. Most plugins will just use this * * Makes sure the plugin is in the correct state. If so, the plugin is * inserted into the Plugins data structure. * * The constructor assumes that Install() was already run one time (possibly * years ago and not during this object's creation). * * \return true on success, false on failure. * * On failure the plugin is not used by the system. NOTE: This function must * NOT assume that other plugins are installed. See PostInitialize. */ public function __construct() { $this->OutputType = $this->OutputType ?: "HTML"; $this->State = PLUGIN_STATE_VALID; register_plugin($this); global $container; $this->menu = $container->get('ui.component.menu'); $this->microMenu = $container->get('ui.component.micromenu'); $this->renderer = $container->get('twig.environment'); } /** * \brief dummy stub till all references are removed. */ function Initialize() { return (TRUE); } // Initialize() /** * \brief This function is called before the plugin * is used and after all plugins have been initialized. * If there is any initialization step that is dependent on other * plugins, put it here. * * \return true on success, false on failure. * * \note Do not assume that the plugin exists! Actually check it! */ function PostInitialize() { if ($this->State != PLUGIN_STATE_VALID) { return 0; } // don't run if (empty($_SESSION['User']) && $this->LoginFlag) { return 0; } // Make sure dependencies are met foreach ($this->Dependency as $key => $val) { $id = plugin_find_id($val); if ($id < 0) { $this->Destroy(); return (0); } } // Put your code here! // If this fails, set $this->State to PLUGIN_STATE_INVALID. // If it succeeds, then set $this->State to PLUGIN_STATE_READY. // It worked, so mark this plugin as ready. $this->State = PLUGIN_STATE_READY; // Add this plugin to the menu if ($this->MenuList !== "") { menu_insert("Main::" . $this->MenuList, $this->MenuOrder, $this->Name, $this->MenuTarget); } return ($this->State == PLUGIN_STATE_READY); } // PostInitialize() /** * \brief While menus can be added to any time at or after * the PostInitialize phase, this is the standard location for * registering this item with menus. * * \note 1: Menu registration may be plugin specific! * \note 2: This is intended for cross-plugin registration and not * for the main menu. */ function RegisterMenus() { if ($this->State != PLUGIN_STATE_READY) { return (0); } // don't run // Add your own menu items here. // E.g., menu_insert("Menu_Name::Item"); } /** * \brief This is a destructor called after the plugin * is no longer needed. It should assume that PostInitialize() was * already run one time (this session) and succeeded. * This function must always succeed. */ function Destroy() { $this->State = PLUGIN_STATE_INVALID; } /** * The output functions generate "output" for use in a text CLI or web page. * For agents, the outputs generate status information. */ /* Possible values: Text, HTML, XML, JSON */ var $OutputType = "HTML"; var $OutputToStdout = 0; /** * \brief This function is called when user output is * requested. This function is responsible for assigning headers. * * @internal param $vars */ function OutputOpen() { if ($this->State != PLUGIN_STATE_READY) { return (0); } $this->headers['Content-type'] = 'text/html'; $this->headers['Pragma'] = 'no-cache'; $this->headers['Cache-Control'] = 'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0'; $this->headers['Expires'] = 'Expires: Thu, 19 Nov 1981 08:52:00 GMT'; $metadata = "\n"; $metadata .= "\n"; $this->vars['metadata'] = $metadata; if (!empty($this->Title)) { $this->vars['title'] = htmlentities($this->Title); } $styles = "\n"; $styles .= "\n"; $styles .= "\n"; $styles .= "\n"; $styles .= "\n"; if ($this->NoMenu == 0) { $styles .= $this->menu->OutputCSS(); } $this->vars['styles'] = $styles; if ($this->NoMenu == 0) { $this->vars['menu'] = $this->menu->Output($this->Title); } global $SysConf; $this->vars['versionInfo'] = array( 'version' => $SysConf['BUILD']['VERSION'], 'buildDate' => $SysConf['BUILD']['BUILD_DATE'], 'commitHash' => $SysConf['BUILD']['COMMIT_HASH'], - 'commitDate' => $SysConf['BUILD']['COMMIT_DATE'] + 'commitDate' => $SysConf['BUILD']['COMMIT_DATE'], + 'branchName' => $SysConf['BUILD']['BRANCH'] ); } // OutputOpen() /** * @brief Similar to OutputClose, this ends the output type * for this object. However, this does NOT change any global * settings. This is called when this object is a dependency * for another object. */ function OutputUnSet() { if ($this->State != PLUGIN_STATE_READY) { return 0; } return ""; } /** * @return Response */ function getResponse() { ob_start(); $output = $this->Output(); if($output instanceof Response) { $response = $output; } else { if (empty($this->vars['content']) && $output) { $this->vars['content'] = $output; } elseif (empty($this->vars['content'])) { $this->vars['content'] = ob_get_contents(); } $response = $this->render($this->getTemplateName()); } ob_end_clean(); return $response; } /** * @brief This function is called when user output is * requested. This function is responsible for content. * (OutputOpen and Output are separated so one plugin * can call another plugin's Output.) */ function Output() { return new Response("ERROR: Output() method of FO_Plugin not defined in class '" . get_class($this) . "'", Response::HTTP_INTERNAL_SERVER_ERROR); } public function getTemplateName() { return "include/base.html.twig"; } /** * @param string $templateName * @param array $vars * @return string */ public function renderString($templateName, $vars = null) { return $this->renderer->loadTemplate($templateName)->render($vars ?: $this->vars); } /** * @param string $templateName * @param array $vars * @return Response */ protected function render($templateName, $vars = null) { $content = $this->renderString($templateName, $vars); return new Response( $content, Response::HTTP_OK, $this->headers ); } /** * @return Request */ public function getRequest() { if (!isset($this->request)) { $this->request = Request::createFromGlobals(); } return $this->request; } public function execute() { $this->OutputOpen(); $response = $this->getResponse(); $response->prepare($this->getRequest()); $response->send(); } function preInstall() { if ($this->State == PLUGIN_STATE_VALID) { $this->PostInitialize(); } if ($this->State == PLUGIN_STATE_READY) { $this->RegisterMenus(); } } function postInstall() { $state = $this->Install(); if ($state != 0) { throw new Exception("install of plugin " . $this->Name . " failed"); } } function unInstall() { $this->Destroy(); } public function getName() { return $this->Name; } function __toString() { return getStringRepresentation(get_object_vars($this), get_class($this)); } - } diff --git a/src/lib/php/UI/Component/Menu.php b/src/lib/php/UI/Component/Menu.php index fc24ebd3..d72f9eca 100644 --- a/src/lib/php/UI/Component/Menu.php +++ b/src/lib/php/UI/Component/Menu.php @@ -1,330 +1,330 @@ Documentation"); $this->renderer = $renderer; } /** * \brief Recursively generate the menu in HTML. */ function menu_html(&$menu, $indent) { if (empty($menu)) { return; } $output = ""; $output .= "\n"; $output .= "
\n"; $output .= "\n"; return preg_replace("|
|
{{ mainMenu }} | ||||
{{ title }}
{% if versionInfo %} {# versionInfo contains all the variables defined at build time in the [BUILD] section of /VERSION #} - {{ versionInfo.version }}, commit: [#{{ versionInfo.commitHash }}] {{ versionInfo.commitDate }} built @ {{ versionInfo.buildDate }} + {% set extractVersion = versionInfo.version|split('-') %} + Version: [{{ extractVersion[0] }}], Branch: [{{ versionInfo.branchName }}], Commit: [#{{ versionInfo.commitHash }}] {{ versionInfo.commitDate }} built @ {{ versionInfo.buildDate }} {% endif %} |
{% if isLoggedOut %}
{% if isLoginPage %}{{ 'Login'|trans }}{% else %}{{ 'Login'|trans }}{% endif %}
{% else %}
logout
|