FOSSology  4.4.0
Open Source License Compliance by Open Source Software
popup-license.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
10 
11 define("TITLE_POPUPLICENSE", _("Show Reference License"));
12 
13 class PopupLicense extends FO_Plugin
14 {
16  private $licenseDao;
17 
18 
19  function __construct()
20  {
21  $this->Name = "popup-license";
22  $this->Title = TITLE_POPUPLICENSE;
23  $this->DBaccess = PLUGIN_DB_WRITE;
24  $this->LoginFlag = 0;
25  $this->NoMenu = 0;
26  parent::__construct();
27 
28  global $container;
29  $this->licenseDao = $container->get('dao.license');
30  }
31 
32  function Output()
33  {
34  if ($this->State != PLUGIN_STATE_READY) {
35  return 0;
36  }
37  $licenseShortname = GetParm("lic", PARM_TEXT);
38  $licenseId = GetParm("rf", PARM_NUMBER);
39  $groupId = $_SESSION[Auth::GROUP_ID];
40  if (empty($licenseShortname) && empty($licenseId)) {
41  return;
42  }
43  if ($licenseId) {
44  $license = $this->licenseDao->getLicenseById($licenseId, $groupId);
45  } else {
46  $license = $this->licenseDao->getLicenseByShortName($licenseShortname,
47  $groupId);
48  }
49  if ($license === null) {
50  return;
51  }
52  $this->vars['shortName'] = $license->getShortName();
53  $this->vars['spdxId'] = $license->getSpdxId();
54  $this->vars['fullName'] = $license->getFullName();
55  $parent = $this->licenseDao->getLicenseParentById($license->getId());
56  if ($parent !== null) {
57  $this->vars['parentId'] = $parent->getId();
58  $this->vars['parentShortName'] = $parent->getShortName();
59  }
60  $licenseUrl = $license->getUrl();
61  if (strtolower($licenseUrl) == 'none') {
62  $licenseUrl = NULL;
63  }
64  $this->vars['url'] = $licenseUrl;
65  $this->vars['text'] = $license->getText();
66  $this->vars['risk'] = $license->getRisk() ?: 0;
67  return $this->render('popup_license.html.twig');
68  }
69 }
70 
71 $NewPlugin = new PopupLicense();
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
render($templateName, $vars=null)
Definition: FO_Plugin.php:434
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
__construct()
base constructor. Most plugins will just use this
Output()
This function is called when user output is requested. This function is responsible for content....
Definition: state.hpp:16
const PARM_NUMBER
Definition: common-parm.php:16
const PARM_TEXT
Definition: common-parm.php:20
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:46
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
Definition: libfossology.h:38