FOSSology  4.4.0
Open Source License Compliance by Open Source Software
email-hist.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2010-2014 Hewlett-Packard Development Company, L.P.
4  SPDX-FileCopyrightText: © 2014-2017 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 require_once('HistogramBase.php');
10 
11 define("TITLE_EMAILHISTOGRAM", _("Email/URL/Author Browser"));
12 
14 {
15  function __construct()
16  {
17  $this->Name = "email-hist";
18  $this->Title = TITLE_EMAILHISTOGRAM;
19  $this->viewName = "email-view";
20  $this->agentName = "copyright";
21  parent::__construct();
22  }
23 
32  protected function getTableContent($upload_pk, $uploadtreeId, $filter, $agentId)
33  {
34  $typeDescriptionPairs = array(
35  'email' => _("Email"),
36  'url' => _("URL"),
37  'author' => _("Author"),
38  'scancode_author' => _("Author"),
39  'scancode_url' => _("URL"),
40  'scancode_email' => _("Email")
41  );
42 
43  $tableVars = array();
44  $output = array();
45  foreach ($typeDescriptionPairs as $type=>$description) {
46  if ($type =="scancode_author" || $type =="scancode_email" || $type =="scancode_url") {
47  $agentId=LatestAgentpk($upload_pk, 'scancode_ars');
48  $this->agentName = "scancode";
49  }
50  list($out, $vars) = $this->getTableForSingleType($type, $description, $upload_pk, $uploadtreeId, $filter, $agentId);
51  $tableVars[$type] = $vars;
52  $output[] = $out;
53  }
54 
55  $output[] = $tableVars;
56  return $output;
57  }
58 
59 
64  protected function fillTables($upload_pk, $Uploadtree_pk, $filter, $agentId, $VF)
65  {
66  list($VEmail, $VUrl, $VAuthor, $VScanAuthor, $VScanUrl, $VScanEmail, $tableVars) = $this->getTableContent($upload_pk, $Uploadtree_pk, $filter, $agentId);
67 
68  $out = $this->renderString('emailhist_tables.html.twig',
69  array('contEmail'=>$VEmail,
70  'contUrl'=>$VUrl,
71  'contAuthor'=>$VAuthor,
72  'contScanAuthor' => $VScanAuthor,
73  'contScanUrl' => $VScanUrl,
74  'contScanEmail' => $VScanEmail,
75  'fileList'=>$VF));
76  return array($out, $tableVars);
77  }
78 
83  function RegisterMenus()
84  {
85  // For all other menus, permit coming back here.
86  $URI = $this->Name . Traceback_parm_keep(array("show","format","page","upload","item"));
87  $Item = GetParm("item",PARM_INTEGER);
88  $Upload = GetParm("upload",PARM_INTEGER);
89  if (!empty($Item) && !empty($Upload)) {
90  if (GetParm("mod",PARM_STRING) == $this->Name) {
91  menu_insert("Browse::Email/URL/Author",10);
92  menu_insert("Browse::[BREAK]",100);
93  } else {
94  $text = _("View email/URL/author histogram");
95  menu_insert("Browse::Email/URL/Author",10,$URI,$text);
96  }
97  }
98  }
99 
105  protected function createScriptBlock()
106  {
107  return "
108 
109  var emailTabCookie = 'stickyEmailTab';
110  var emailTabFossCookie = 'stickyEmailFossTab';
111  var emailTabScanCookie = 'stickyEmailScanTab';
112  $(document).ready(function() {
113  tableEmail = createTableemail();
114  tableUrl = createTableurl();
115  tableAuthor = createTableauthor();
116  tableScanEmail = createTablescancode_email();
117  tableScanUrl = createTablescancode_url();
118  tableScanAuthor = createTablescancode_author();
119  $('#testReplacementemail').click(function() {
120  testReplacement(tableEmail, 'email');
121  });
122  $('#testReplacementurl').click(function() {
123  testReplacement(tableUrl, 'url');
124  });
125  $('#testReplacementauthor').click(function() {
126  testReplacement(tableAuthor, 'author');
127  });
128  $('#testReplacementScanemail').click(function() {
129  testReplacement(tableScanEmail, 'email');
130  });
131  $('#testReplacementScanurl').click(function() {
132  testReplacement(tableScanUrl, 'url');
133  });
134  $('#testReplacementScanauthor').click(function() {
135  testReplacement(tableScanAuthor, 'author');
136  });
137  $('#EmailUrlAuthorTabs').tabs({
138  active: ($.cookie(emailTabCookie) || 0),
139  activate: function(e, ui){
140  // Get active tab index and update cookie
141  var idString = $(e.currentTarget).attr('id');
142  idString = parseInt(idString.slice(-1)) - 1;
143  $.cookie(emailTabCookie, idString);
144  }
145  });
146  $('#FossEmailUrlAuthorTabs').tabs({
147  active: ($.cookie(emailTabFossCookie) || 0),
148  activate: function(e, ui){
149  // Get active tab index and update cookie
150  var tabIdFoss = $(ui.newPanel).attr('id');
151  var idStringFoss = 0;
152  if (tabIdFoss == 'FossEmailTab') {
153  idStringFoss = 0;
154  } else if (tabIdFoss == 'FossUrlTab') {
155  idStringFoss = 1;
156  } else if (tabIdFoss == 'FossAuthorTab') {
157  idStringFoss = 2;
158  }
159  $.cookie(emailTabFossCookie, idStringFoss);
160  }
161  });
162  $('#ScanEmailUrlAuthorTabs').tabs({
163  active: ($.cookie(emailTabScanCookie) || 0),
164  activate: function(e, ui){
165  // Get active tab index and update cookie
166  var tabIdScan = $(ui.newPanel).attr('id');
167  var idStringScan = 0;
168  if (tabIdScan == 'ScanEmailTab') {
169  idStringScan = 0;
170  } else if (tabIdScan == 'ScanUrlTab') {
171  idStringScan = 1;
172  } else if (tabIdScan == 'ScanAuthorTab') {
173  idStringScan = 2;
174  }
175  $.cookie(emailTabScanCookie, idStringScan);
176  }
177  });
178  });
179  ";
180  }
181 }
182 
183 $NewPlugin = new EmailHistogram;
createScriptBlock()
Create JavaScript block for histogram.
Definition: email-hist.php:105
RegisterMenus()
While menus can be added to any time at or after the PostInitialize phase, this is the standard locat...
Definition: email-hist.php:83
getTableContent($upload_pk, $uploadtreeId, $filter, $agentId)
Get contents for author table.
Definition: email-hist.php:32
__construct()
base constructor. Most plugins will just use this
Definition: email-hist.php:15
fillTables($upload_pk, $Uploadtree_pk, $filter, $agentId, $VF)
Get copyright statements and fill the main content table.
Definition: email-hist.php:64
renderString($templateName, $vars=null)
Definition: FO_Plugin.php:414
Base class for histogram plugins.
getTableForSingleType($type, $description, $uploadId, $uploadTreeId, $filter, $agentId)
LatestAgentpk($upload_pk, $arsTableName, $arsSuccess=false)
Given an upload_pk, find the latest enabled agent_pk with results.
menu_insert($Path, $LastOrder=0, $URI=NULL, $Title=NULL, $Target=NULL, $HTML=NULL)
Given a Path, order level for the last item, and optional plugin name, insert the menu item.
const PARM_INTEGER
Definition: common-parm.php:14
const PARM_STRING
Definition: common-parm.php:18
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:46
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308