32 define(
"PLUGIN_STATE_FAIL", -1);
33 define(
"PLUGIN_STATE_INVALID", 0);
34 define(
"PLUGIN_STATE_VALID", 1);
35 define(
"PLUGIN_STATE_READY", 2);
41 define(
"PLUGIN_DB_NONE", 0);
42 define(
"PLUGIN_DB_READ", 1);
43 define(
"PLUGIN_DB_WRITE", 3);
44 define(
"PLUGIN_DB_CADMIN", 5);
45 define(
"PLUGIN_DB_ADMIN", 10);
49 $NoneText = _(
"None");
50 $ReadText = _(
"Read");
51 $WriteText = _(
"Write");
52 $AdminText = _(
"Admin");
53 $cAdminText = _(
"Clearing Admin");
104 var $Dependency = array();
111 protected $microMenu;
120 private $headers = array();
122 protected $vars = array();
158 var $MenuTarget = NULL;
213 $this->OutputType = $this->OutputType ?:
"HTML";
214 $this->
State = PLUGIN_STATE_VALID;
215 register_plugin($this);
218 $this->
menu = $container->get(
'ui.component.menu');
219 $this->microMenu = $container->get(
'ui.component.micromenu');
220 $this->renderer = $container->get(
'twig.environment');
243 if ($this->
State != PLUGIN_STATE_VALID) {
247 if (empty($_SESSION[
'User']) && $this->LoginFlag) {
251 foreach ($this->Dependency as $key => $val) {
252 $id = plugin_find_id($val);
264 $this->
State = PLUGIN_STATE_READY;
266 if ($this->MenuList !==
"") {
267 menu_insert(
"Main::" . $this->MenuList, $this->MenuOrder, $this->Name, $this->MenuTarget);
269 return ($this->
State == PLUGIN_STATE_READY);
283 if ($this->
State != PLUGIN_STATE_READY) {
298 $this->
State = PLUGIN_STATE_INVALID;
308 var $OutputToStdout = 0;
318 if ($this->
State != PLUGIN_STATE_READY) {
322 $this->headers[
'Content-type'] =
'text/html';
323 $this->headers[
'Pragma'] =
'no-cache';
324 $this->headers[
'Cache-Control'] =
'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0';
325 $this->headers[
'Expires'] =
'Expires: Thu, 19 Nov 1981 08:52:00 GMT';
327 $metadata =
"<meta name='description' content='The study of Open Source'>\n";
328 $metadata .=
"<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>\n";
330 $this->vars[
'metadata'] = $metadata;
332 if (!empty($this->Title)) {
333 $this->vars[
'title'] = htmlentities($this->Title);
336 $styles =
"<link rel='stylesheet' href='css/jquery-ui.css'>\n";
337 $styles .=
"<link rel='stylesheet' href='css/select2.min.css'>\n";
338 $styles .=
"<link rel='stylesheet' href='css/jquery.dataTables.css'>\n";
339 $styles .=
"<link rel='stylesheet' href='css/fossology.css'>\n";
340 $styles .=
"<link rel='icon' type='image/x-icon' href='favicon.ico'>\n";
341 $styles .=
"<link rel='shortcut icon' type='image/x-icon' href='favicon.ico'>\n";
343 if ($this->NoMenu == 0) {
344 $styles .= $this->
menu->OutputCSS();
346 $this->vars[
'styles'] = $styles;
348 if ($this->NoMenu == 0) {
349 $this->vars[
'menu'] = $this->
menu->Output($this->Title);
353 $this->vars[
'versionInfo'] = array(
354 'version' => $SysConf[
'BUILD'][
'VERSION'],
355 'buildDate' => $SysConf[
'BUILD'][
'BUILD_DATE'],
356 'commitHash' => $SysConf[
'BUILD'][
'COMMIT_HASH'],
357 'commitDate' => $SysConf[
'BUILD'][
'COMMIT_DATE'],
358 'branchName' => $SysConf[
'BUILD'][
'BRANCH']
371 if ($this->
State != PLUGIN_STATE_READY) {
383 $output = $this->
Output();
385 if ($output instanceof Response) {
388 if (empty($this->vars[
'content']) && $output) {
389 $this->vars[
'content'] = $output;
390 } elseif (empty($this->vars[
'content'])) {
391 $this->vars[
'content'] = ob_get_contents();
393 $response = $this->
render($this->getTemplateName());
409 return new Response(
"ERROR: Output() method of FO_Plugin not defined in class '" . get_class($this) .
"'", Response::HTTP_INTERNAL_SERVER_ERROR);
412 public function getTemplateName()
414 return "include/base.html.twig";
424 return $this->renderer->loadTemplate($templateName)->render($vars ?: $this->vars);
434 $this->vars[
'scripts'] = $scripts;
442 protected function render($templateName, $vars = null)
458 if (!isset($this->request)) {
459 $this->request = Request::createFromGlobals();
461 return $this->request;
464 public function execute()
472 function preInstall()
474 if ($this->
State == PLUGIN_STATE_VALID) {
477 if ($this->
State == PLUGIN_STATE_READY) {
482 function postInstall()
486 throw new Exception(
"install of plugin " . $this->Name .
" failed");
500 function __toString()
Remove()
This function (when defined) is only called once, when the plugin is removed. It should uninstall and...
#define PERM_NONE
User has no permission (not logged in)
renderScripts($scripts)
Render JavaScript in the template's footer.
__construct()
base constructor. Most plugins will just use this
RegisterMenus()
While menus can be added to any time at or after the PostInitialize phase, this is the standard locat...
getStringRepresentation($vars, $classname)
OutputUnSet()
Similar to OutputClose, this ends the output type for this object. However, this does NOT change any ...
renderString($templateName, $vars=null)
Initialize()
dummy stub till all references are removed.
#define PLUGIN_DB_NONE
Plugin requires no DB permission.
PostInitialize()
This function is called before the plugin is used and after all plugins have been initialized...
This is the Plugin class. All plugins should:
#define PERM_READ
Read-only permission.
OutputOpen()
This function is called when user output is requested. This function is responsible for assigning hea...
Output()
This function is called when user output is requested. This function is responsible for content...
Install()
This function (when defined) is only called when the plugin is first installed. It should make sure a...
Destroy()
This is a destructor called after the plugin is no longer needed. It should assume that PostInitializ...
#define PERM_ADMIN
Administrator.
render($templateName, $vars=null)
#define PERM_WRITE
Read-Write permission.