FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ajax-notice-files.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2019-2022 Siemens AG
4  Author: Andreas J. Reichel <andreas.reichel@tngtech.com>
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 require_once dirname(dirname(dirname(__FILE__))) . "/lib/php/common-repo.php";
10 
15 use Symfony\Component\HttpFoundation\JsonResponse;
16 
18 {
20  private $uploadDao;
21 
23  private $searchHelperDao;
24 
25  function __construct()
26  {
27  $this->Name = "ajax-notice-files";
28  $this->Title = _("Ajax Notice Files");
29  $this->DBaccess = PLUGIN_DB_READ;
30  $this->OutputType = 'JSON';
31  $this->OutputToStdout = true;
32  parent::__construct();
33 
34  $this->uploadDao = $GLOBALS['container']->get('dao.upload');
35  $this->searchHelperDao = $GLOBALS['container']->get('dao.searchhelperdao');
36  }
37 
38  function PostInitialize()
39  {
40  $this->State = PLUGIN_STATE_READY;
41  return $this->State;
42  }
43 
44  function Output()
45  {
46  if ($this->State != PLUGIN_STATE_READY) {
47  return;
48  }
49 
50  $getuploadEntry = $this->uploadDao->getUploadEntry(GetParm("uploadTreeId", PARM_INTEGER));
51 
52  // Get the root of the upload tree where this item belongs to
53  $parentBounds = $this->uploadDao->getParentItemBounds($getuploadEntry['upload_fk'], null);
54  $uploadTreeId = $parentBounds->getItemId();
55 
56  // Search the upload tree for all files named NOTICE*
57  $Item = $uploadTreeId;
58  $Filename = "NOTICE%";
59  $uploadId = $getuploadEntry['upload_fk'];
60  $tag = "";
61  $Page = 0;
62  $Limit = 100;
63  $SizeMin = "";
64  $SizeMax = "";
65  $searchtype = "allfiles";
66  $License = "";
67  $Copyright = "";
68 
69  $UploadtreeRecsResult = $this->searchHelperDao->GetResults($Item, $Filename, $uploadId, $tag, $Page, $Limit, $SizeMin,
70  $SizeMax, $searchtype, $License, $Copyright, $this->uploadDao,
71  Auth::getGroupId());
72 
73  foreach ($UploadtreeRecsResult[0] as $k => $res) {
74 
75  $pfilefk = $res['pfile_fk'];
76  $repofile = RepPath($pfilefk);
77 
78  $UploadtreeRecsResult[0][$k]['repo_file'] = $repofile;
79 
80  // Get the contents of the file and attach it to the JSON output
81  if (is_readable($repofile)) {
82  $f = fopen($repofile, "r");
83  if ($f === false) {
84  continue;
85  }
86  $contents = fread($f, filesize($repofile));
87  $contents_short = "<textarea style='overflow:auto;width:400px;height:80px;'>" .$contents. "</textarea>";
88  $UploadtreeRecsResult[0][$k]['contents'] = $contents;
89  $UploadtreeRecsResult[0][$k]['contents_short'] = $contents_short;
90  fclose($f);
91  }
92  }
93  return new JsonResponse($UploadtreeRecsResult[0]);
94  }
95 }
96 
97 $NewPlugin = new AjaxNoticeFiles;
98 $NewPlugin->Initialize();
PostInitialize()
This function is called before the plugin is used and after all plugins have been initialized....
__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....
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
Definition: state.hpp:16
const PARM_INTEGER
Definition: common-parm.php:14
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:46
RepPath($PfilePk, $Repo="files")
Given a pfile id, retrieve the pfile path.
Definition: common-repo.php:58
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
Definition: libfossology.h:37