FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
popup-license.php
1 <?php
2 /*
3  Copyright (C) 2014, Siemens AG
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
21 
22 define("TITLE_POPUPLICENSE", _("Show Reference License"));
23 
24 class PopupLicense extends FO_Plugin
25 {
27  private $licenseDao;
28 
29 
30  function __construct()
31  {
32  $this->Name = "popup-license";
33  $this->Title = TITLE_POPUPLICENSE;
34  $this->DBaccess = PLUGIN_DB_WRITE;
35  $this->LoginFlag = 0;
36  $this->NoMenu = 0;
37  parent::__construct();
38 
39  global $container;
40  $this->licenseDao = $container->get('dao.license');
41  }
42 
43  function Output()
44  {
45  if ($this->State != PLUGIN_STATE_READY) {
46  return 0;
47  }
48  $licenseShortname = GetParm("lic", PARM_TEXT);
49  $licenseId = GetParm("rf", PARM_NUMBER);
50  $groupId = $_SESSION[Auth::GROUP_ID];
51  if (empty($licenseShortname) && empty($licenseId)) {
52  return;
53  }
54  if ($licenseId) {
55  $license = $this->licenseDao->getLicenseById($licenseId, $groupId);
56  } else {
57  $license = $this->licenseDao->getLicenseByShortName($licenseShortname,
58  $groupId);
59  }
60  if ($license === null) {
61  return;
62  }
63  $this->vars['shortName'] = $license->getShortName();
64  $this->vars['fullName'] = $license->getFullName();
65  $parent = $this->licenseDao->getLicenseParentById($license->getId());
66  if ($parent !== null) {
67  $this->vars['parentId'] = $parent->getId();
68  $this->vars['parentShortName'] = $parent->getShortName();
69  }
70  $licenseUrl = $license->getUrl();
71  if (strtolower($licenseUrl) == 'none') {
72  $licenseUrl = NULL;
73  }
74  $this->vars['url'] = $licenseUrl;
75  $this->vars['text'] = $license->getText();
76  $this->vars['risk'] = $license->getRisk() ?: 0;
77  return $this->render('popup_license.html.twig');
78  }
79 }
80 
81 $NewPlugin = new PopupLicense();
const PARM_TEXT
Definition: common-parm.php:31
const PARM_NUMBER
Definition: common-parm.php:27
Definition: state.hpp:26
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
Definition: libfossology.h:50
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
render($templateName, $vars=null)
Definition: FO_Plugin.php:442