16 protected $MaxPerPage = 100;
21 private $searchHelperDao;
25 $this->Name =
"search";
26 $this->Title = _(
"Search");
27 $this->MenuList =
"Search";
28 $this->MenuOrder = 90;
29 $this->Dependency = array(
"browse");
32 parent::__construct();
34 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
35 $this->searchHelperDao = $GLOBALS[
'container']->get(
'dao.searchhelperdao');
40 $this->
State = PLUGIN_STATE_READY;
44 function loadUploads()
46 if (Auth::isAdmin()) {
47 return $this->uploadDao->getActiveUploadsArray();
50 if (Auth::getUserId() === 0) {
54 return $this->uploadDao->getAccessibleUploads(Auth::getGroupId());
62 menu_insert(
"Main::" . $this->MenuList,$this->MenuOrder,$this->Name,$this->MenuTarget);
71 menu_insert(
"Browse::Search", 1, $URI, $this->MenuList);
86 $Count = count($UploadtreeRecs);
88 $Outbuf .= _(
"No matching files.\n");
91 if (($Page > 0) || ($Count >= $this->MaxPerPage)) {
93 $PageChoices =
MenuEndlessPage($Page, ($Count >= $this->MaxPerPage), $Uri) .
95 $Outbuf .= $PageChoices;
99 $Outbuf .=
UploadtreeFileList($UploadtreeRecs,
"browse",
"view",$Page*$this->MaxPerPage + 1);
102 $Outbuf .= $PageChoices;
114 if ($this->
State != PLUGIN_STATE_READY) {
117 if ($this->OutputType !=
'HTML') {
126 $uploadsArray = $this->loadUploads();
127 $this->vars[
'uploadsArray'] = $uploadsArray;
131 $uploadFromRequest = ($Upload !==
null);
133 $itemRow = $this->uploadDao->getUploadEntry($Item);
134 $itemUpload = empty($itemRow) ? 0 : intval($itemRow[
'upload_fk']);
135 if (!$uploadFromRequest) {
137 $Upload = $itemUpload;
138 } elseif ($Upload != $itemUpload) {
143 $this->vars[
'Item'] = $Item;
146 $this->vars[
'pathOfItem'] =
Dir2Browse($this->Name, $Item, NULL, 1, NULL) .
148 $GETvars .=
"&item=$Item";
152 $GETvars .=
"&searchtype=" . urlencode($searchtype);
153 if ($searchtype ==
'containers') {
154 $this->vars[
"ContainersChecked"] =
"checked=\"checked\"";
155 }
else if ($searchtype ==
'directory') {
156 $this->vars[
"DirectoryChecked"] =
"checked=\"checked\"";
158 $this->vars[
"AllFilesChecked"] =
"checked=\"checked\"";
162 if (! empty($Filename)) {
164 $GETvars .=
"&filename=" . urlencode($Filename);
165 $this->vars[
"Filename"] = $Filename;
168 $SelectedUploadName =
"All uploads";
170 if ($uploadFromRequest) {
173 $GETvars .=
"&upload=" . urlencode($Upload);
174 $this->vars[
"Upload"] = $Upload;
175 foreach ($uploadsArray as $row) {
176 if ($row->getId() == $Upload) {
177 $SelectedUploadName = $row->getFilename() .
" from " .
Convert2BrowserTime(date(
"Y-m-d H:i:s",$row->getTimestamp()));
181 $this->vars[
"Upload"] = 0;
187 $GETvars .=
"&tag=" . urlencode($tag);
188 $this->vars[
"tag"] = $tag;
192 if (! empty($SizeMin) && is_numeric($SizeMin) && ($SizeMin >= 0)) {
193 $SizeMin = intval($SizeMin);
195 $GETvars .=
"&sizemin=$SizeMin";
196 $this->vars[
"SizeMin"] = $SizeMin;
200 if (! empty($SizeMax) && is_numeric($SizeMax) && ($SizeMax >= 0)) {
201 $SizeMax = intval($SizeMax);
203 $GETvars .=
"&sizemax=$SizeMax";
204 $this->vars[
"SizeMax"] = $SizeMax;
208 if (! empty($License)) {
210 $GETvars .=
"&license=" . urlencode($License);
211 $this->vars[
"License"] = $License;
215 if (! empty($Copyright)) {
217 $GETvars .=
"©right=" . urlencode($Copyright);
218 $this->vars[
"Copyright"] = $Copyright;
223 $GETvars .=
"&limit=" . urlencode($Limit);
224 $this->MaxPerPage = $Limit;
226 $Limit = $this->MaxPerPage;
231 $GETvars .=
"&page=" . urlencode($Page);
238 if ($CriteriaCount) {
242 $UploadtreeRecsResult = $this->searchHelperDao->GetResults($Item, $Filename, $Upload, $tag, $Page, $Limit, $SizeMin,
243 $SizeMax, $searchtype, $License, $Copyright, $this->uploadDao,
247 "The indented search results are same files in different folders");
248 $html .=
"<H4>$message</H4>\n";
249 $text = $UploadtreeRecsResult[1] .
" " . _(
"Files matching");
250 $html .=
"<H2>$text " . htmlentities($Filename) .
" in ". htmlentities($SelectedUploadName) .
"</H2>\n";
251 $html .= $this->
HTMLResults($UploadtreeRecsResult[0], $Page, $GETvars);
252 $this->vars[
"result"] = $html;
256 public function getTemplateName()
258 return "ui-search.html.twig";
263 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
HTMLResults($UploadtreeRecs, $Page, $GETvars)
print search results to stdout
__construct()
base constructor. Most plugins will just use this
Output()
Display the loaded menu and plugins.
PostInitialize()
This function is called before the plugin is used and after all plugins have been initialized....
RegisterMenus()
Customize submenus.
UploadtreeFileList($Listing, $IfDirPlugin, $IfFilePlugin, $Count=-1, $ShowPhrase=0)
Given an array of pfiles/uploadtree, sorted by pfile, list all of the breadcrumbs for each file....
Dir2Browse($Mod, $UploadtreePk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $Enumerate=-1, $PreText='', $PostText='', $uploadtree_tablename="uploadtree")
Get an html linked string of a file browse path.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN