34 const PERMISSION =
"permission";
35 const REQUIRES_LOGIN =
"requiresLogin";
36 const ENABLE_MENU =
"ENABLE_MENU";
37 const LEVEL =
"level";
38 const DEPENDENCIES =
"dependencies";
39 const INIT_ORDER =
"initOrder";
40 const MENU_LIST =
"menuList";
41 const MENU_ORDER =
"menuOrder";
42 const MENU_TARGET =
"menuTarget";
43 const TITLE =
"title";
60 private $version =
"1.0";
66 private $requiresLogin =
true;
68 private $PluginLevel = 10;
70 private $dependencies = array();
71 private $InitOrder = 0;
73 private $MenuList = NULL;
74 private $MenuOrder = 0;
75 private $MenuTarget = NULL;
77 public function __construct($name, $parameters = array())
79 if ($name === null || $name ===
"") {
80 throw new \InvalidArgumentException(
"plugin requires a name");
83 foreach ($parameters as $key => $value) {
84 $this->setParameter($key, $value);
88 $this->container = $container;
89 $this->session = $this->
getObject(
'session');
90 $this->renderer = $this->
getObject(
'twig.environment');
91 $this->logger = $this->
getObject(
'logger');
93 $this->microMenu = $this->
getObject(
'ui.component.micromenu');
96 private function setParameter($key, $value)
100 $this->title = $value;
103 case self::PERMISSION:
104 $this->permission = $value;
107 case self::REQUIRES_LOGIN:
108 $this->requiresLogin = $value;
112 $this->PluginLevel = $value;
115 case self::DEPENDENCIES:
116 $this->dependencies = $value;
119 case self::INIT_ORDER:
120 $this->InitOrder = $value;
123 case self::MENU_LIST:
124 $this->MenuList = $value;
127 case self::MENU_ORDER:
128 $this->MenuOrder = $value;
131 case self::MENU_TARGET:
132 $this->MenuTarget = $value;
136 throw new \Exception(
"unhandled parameter $key in module " . $this->name);
153 return $this->version;
169 return $this->requiresLogin;
177 return $this->dependencies;
185 return $this->PluginLevel;
193 return $this->permission;
201 return PLUGIN_STATE_READY;
209 return $this->InitOrder;
213 public function getNoMenu()
223 if (isset($this->MenuList) && (!$this->requiresLogin || $this->isLoggedIn())) {
224 menu_insert(
"Main::" . $this->MenuList, $this->MenuOrder, $this->name, $this->name);
233 $request = Request::createFromGlobals();
234 $request->setSession($this->session);
236 $this->checkPrerequisites();
238 $startTime = microtime(
true);
239 $response = $this->
handle($request);
240 $response->prepare($request);
241 $this->logger->debug(sprintf(
"handle request in %.3fs", microtime(
true) - $startTime));
251 return $this->container->get($name);
254 public function preInstall()
259 public function postInstall()
263 public function unInstall()
267 public function execute()
269 $startTime = microtime(
true);
273 $this->logger->debug(sprintf(
"prepare response in %.3fs", microtime(
true) - $startTime));
282 protected abstract function handle(Request $request);
290 protected function render($templateName, $vars = null, $headers = null)
292 if ($this->requiresLogin && !$this->isLoggedIn()) {
293 new Response(
"permission denied", Response::HTTP_FORBIDDEN, array(
"contentType" =>
"text/plain"));
296 $startTime = microtime(
true);
298 $content = $this->renderer->loadTemplate($templateName)
301 $this->logger->debug(sprintf(
"%s: render response in %.3fs", get_class($this), microtime(
true) - $startTime));
309 public function isLoggedIn()
311 return (!empty($_SESSION[
Auth::USER_NAME]) && $_SESSION[Auth::USER_NAME] !=
'Default User');
314 private function checkPrerequisites()
316 if ($this->requiresLogin && !$this->isLoggedIn()) {
317 throw new \Exception(
"not allowed without login");
320 foreach ($this->dependencies as $dependency) {
321 $id = plugin_find_id($dependency);
324 throw new \Exception(
"unsatisfied dependency '$dependency' in module '" . $this->
getName() .
"'");
335 'Content-type' =>
'text/html',
336 'Pragma' =>
'no-cache',
337 'Cache-Control' =>
'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0',
338 'Expires' =>
'Expires: Thu, 19 Nov 1981 08:52:00 GMT');
348 $metadata =
"<meta name='description' content='The study of Open Source'>\n";
349 $metadata .=
"<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>\n";
351 $vars[
'metadata'] = $metadata;
353 if (!empty($this->title)) {
354 $vars[self::TITLE] = htmlentities($this->title);
357 $styles =
"<link rel='stylesheet' href='css/jquery-ui.css'>\n";
358 $styles .=
"<link rel='stylesheet' href='css/select2.min.css'>\n";
359 $styles .=
"<link rel='stylesheet' href='css/jquery.dataTables.css'>\n";
360 $styles .=
"<link rel='stylesheet' href='css/fossology.css'>\n";
361 $styles .=
"<link rel='icon' type='image/x-icon' href='favicon.ico'>\n";
362 $styles .=
"<link rel='shortcut icon' type='image/x-icon' href='favicon.ico'>\n";
364 $styles .= $this->
menu->OutputCSS();
366 $vars[
'styles'] = $styles;
368 $vars[
'menu'] = $this->
menu->Output($this->title);
371 if (array_key_exists(
'BUILD', $SysConf)) {
372 $vars[
'versionInfo'] = array(
373 'version' => $SysConf[
'BUILD'][
'VERSION'],
374 'buildDate' => $SysConf[
'BUILD'][
'BUILD_DATE'],
375 'commitHash' => $SysConf[
'BUILD'][
'COMMIT_HASH'],
376 'commitDate' => $SysConf[
'BUILD'][
'COMMIT_DATE'],
377 'branchName' => $SysConf[
'BUILD'][
'BRANCH']
384 protected function mergeWithDefault($vars)
389 protected function flushContent($content)
391 return $this->
render(
"include/base.html.twig",$this->mergeWithDefault(array(
"content"=>$content)));
401 if (method_exists($this, ($method =
'get' . ucwords($name)))) {
402 return $this->$method();
404 throw new \Exception(
"property '$name' not found in module " . $this->name);
408 function __toString()
render($templateName, $vars=null, $headers=null)
RegisterMenus()
Customize submenus.
getStringRepresentation($vars, $classname)