13 use Symfony\Component\HttpFoundation\Request;
14 use Symfony\Component\HttpFoundation\Response;
21 define(
"PLUGIN_STATE_FAIL", -1);
22 define(
"PLUGIN_STATE_INVALID", 0);
23 define(
"PLUGIN_STATE_VALID", 1);
24 define(
"PLUGIN_STATE_READY", 2);
30 define(
"PLUGIN_DB_NONE", 0);
31 define(
"PLUGIN_DB_READ", 1);
32 define(
"PLUGIN_DB_WRITE", 3);
33 define(
"PLUGIN_DB_CADMIN", 5);
34 define(
"PLUGIN_DB_ADMIN", 10);
38 $NoneText = _(
"None");
39 $ReadText = _(
"Read");
40 $WriteText = _(
"Write");
41 $AdminText = _(
"Admin");
42 $cAdminText = _(
"Clearing Admin");
93 var $Dependency = array();
100 protected $microMenu;
109 private $headers = array();
111 protected $vars = array();
147 var $MenuTarget = NULL;
202 $this->OutputType = $this->OutputType ?:
"HTML";
203 $this->
State = PLUGIN_STATE_VALID;
204 register_plugin($this);
207 $this->
menu = $container->get(
'ui.component.menu');
208 $this->microMenu = $container->get(
'ui.component.micromenu');
209 $this->renderer = $container->get(
'twig.environment');
232 if ($this->
State != PLUGIN_STATE_VALID) {
236 if (empty($_SESSION[
'User']) && $this->LoginFlag) {
240 foreach ($this->Dependency as $key => $val) {
241 $id = plugin_find_id($val);
253 $this->
State = PLUGIN_STATE_READY;
255 if ($this->MenuList !==
"") {
256 menu_insert(
"Main::" . $this->MenuList, $this->MenuOrder, $this->Name, $this->MenuTarget);
258 return ($this->
State == PLUGIN_STATE_READY);
272 if ($this->
State != PLUGIN_STATE_READY) {
287 $this->
State = PLUGIN_STATE_INVALID;
297 var $OutputToStdout = 0;
307 if ($this->
State != PLUGIN_STATE_READY) {
311 $this->headers[
'Content-type'] =
'text/html';
312 $this->headers[
'Pragma'] =
'no-cache';
313 $this->headers[
'Cache-Control'] =
'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0';
314 $this->headers[
'Expires'] =
'Expires: Thu, 19 Nov 1981 08:52:00 GMT';
316 $metadata =
"<meta name='description' content='The study of Open Source'>\n";
317 $metadata .=
"<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>\n";
318 $metadata .=
"<meta name='viewport' content='width=device-width,initial-scale=1.0'>\n";
320 $this->vars[
'metadata'] = $metadata;
322 if (!empty($this->Title)) {
323 $this->vars[
'title'] = htmlentities($this->Title);
326 $styles =
"<link rel='stylesheet' href='css/jquery-ui.css'>\n";
327 $styles .=
"<link rel='stylesheet' href='css/select2.min.css'>\n";
328 $styles .=
"<link rel='stylesheet' href='css/jquery.dataTables.css'>\n";
329 $styles .=
"<link rel='stylesheet' href='css/fossology.css'>\n";
330 $styles .=
"<link rel='stylesheet' href='css/bootstrap-icons.css'>\n";
331 $styles .=
"<link rel='stylesheet' href='css/bootstrap/bootstrap.min.css'>\n";
332 $styles .=
"<link rel='icon' type='image/x-icon' href='favicon.ico'>\n";
333 $styles .=
"<link rel='shortcut icon' type='image/x-icon' href='favicon.ico'>\n";
335 if ($this->NoMenu == 0) {
336 $styles .= $this->
menu->OutputCSS();
338 $this->vars[
'styles'] = $styles;
340 if ($this->NoMenu == 0) {
341 $this->vars[
'menu'] = $this->
menu->Output($this->Title);
345 $this->vars[
'versionInfo'] = array(
346 'version' => $SysConf[
'BUILD'][
'VERSION'],
347 'buildDate' => $SysConf[
'BUILD'][
'BUILD_DATE'],
348 'commitHash' => $SysConf[
'BUILD'][
'COMMIT_HASH'],
349 'commitDate' => $SysConf[
'BUILD'][
'COMMIT_DATE'],
350 'branchName' => $SysConf[
'BUILD'][
'BRANCH']
363 if ($this->
State != PLUGIN_STATE_READY) {
375 $output = $this->
Output();
377 if ($output instanceof Response) {
380 if (empty($this->vars[
'content']) && $output) {
381 $this->vars[
'content'] = $output;
382 } elseif (empty($this->vars[
'content'])) {
383 $this->vars[
'content'] = ob_get_contents();
385 $response = $this->
render($this->getTemplateName());
401 return new Response(
"ERROR: Output() method of FO_Plugin not defined in class '" . get_class($this) .
"'", Response::HTTP_INTERNAL_SERVER_ERROR);
404 public function getTemplateName()
406 return "include/base.html.twig";
416 return $this->renderer->load($templateName)->render($vars ?: $this->vars);
426 $this->vars[
'scripts'] = $scripts;
434 protected function render($templateName, $vars =
null)
450 if (!isset($this->request)) {
451 $this->request = Request::createFromGlobals();
453 return $this->request;
456 public function execute()
464 function preInstall()
466 if ($this->
State == PLUGIN_STATE_VALID) {
469 if ($this->
State == PLUGIN_STATE_READY) {
474 function postInstall()
478 throw new Exception(
"install of plugin " . $this->Name .
" failed");
492 function __toString()
This is the Plugin class. All plugins should:
Output()
This function is called when user output is requested. This function is responsible for content....
RegisterMenus()
While menus can be added to any time at or after the PostInitialize phase, this is the standard locat...
OutputOpen()
This function is called when user output is requested. This function is responsible for assigning hea...
renderString($templateName, $vars=null)
__construct()
base constructor. Most plugins will just use this
renderScripts($scripts)
Render JavaScript in the template's footer.
Install()
This function (when defined) is only called when the plugin is first installed. It should make sure a...
Remove()
This function (when defined) is only called once, when the plugin is removed. It should uninstall and...
PostInitialize()
This function is called before the plugin is used and after all plugins have been initialized....
Initialize()
dummy stub till all references are removed.
OutputUnSet()
Similar to OutputClose, this ends the output type for this object. However, this does NOT change any ...
Destroy()
This is a destructor called after the plugin is no longer needed. It should assume that PostInitializ...
render($templateName, $vars=null)
Contains the constants and helpers for authentication of user.
getStringRepresentation($vars, $classname)
#define PERM_WRITE
Read-Write permission.
#define PERM_READ
Read-only permission.
#define PLUGIN_DB_NONE
Plugin requires no DB permission.
#define PERM_ADMIN
Administrator.
#define PERM_NONE
User has no permission (not logged in)