15 use Symfony\Component\HttpFoundation\RedirectResponse;
16 use Symfony\Component\HttpFoundation\Response;
18 define(
"TITLE_UI_BROWSE", _(
"Browse"));
29 $this->Name =
"browse";
30 $this->Title = TITLE_UI_BROWSE;
31 $this->MenuList =
"Browse";
32 $this->MenuOrder = 80;
33 $this->MenuTarget =
"";
38 $this->uploadDao = $container->get(
'dao.upload');
39 $this->folderDao = $container->get(
'dao.folder');
41 parent::__construct();
49 menu_insert(
"Main::" . $this->MenuList, $this->MenuOrder, $this->Name, $this->Name);
62 return ($this->
State == PLUGIN_STATE_READY);
69 function ShowItem($Upload, $Item, $Show, $Folder, $uploadtree_tablename)
73 $dbManager = $container->get(
'db.manager');
74 $RowStyle1 =
"style='background-color:#ecfaff'";
75 $RowStyle2 =
"style='background-color:#ffffe3'";
81 $Uri =
Traceback_uri() .
"?mod=" . $this->Name .
"&folder=$Folder";
85 $MenuPfile =
menu_find(
"Browse-Pfile", $MenuDepth);
87 $MenuPfileNoCompare =
menu_remove($MenuPfile,
"Compare");
90 foreach ($MenuPfile as $value) {
91 if (($value->Name ==
'Tag') || ($value->Name ==
'Compare')) {
96 $Results = GetNonArtifactChildren($Item, $uploadtree_tablename);
98 $V .=
"<table class='text' style='border-collapse: collapse' border=0 padding=0>\n";
99 $stmtGetFirstChild = __METHOD__.
'.getFirstChild';
100 $dbManager->prepare($stmtGetFirstChild,
"SELECT uploadtree_pk FROM $uploadtree_tablename WHERE parent=$1 limit 1");
101 foreach ($Results as $Row) {
102 if (empty($Row[
'uploadtree_pk'])) {
106 $Name = $Row[
'ufile_name'];
109 $RowStyle = (($RowNum++ % (2 * $ColorSpanRows)) < $ColorSpanRows) ? $RowStyle1 : $RowStyle2;
110 $V .=
"<tr $RowStyle>";
113 $result = $dbManager->execute($stmtGetFirstChild,array($Row[
'uploadtree_pk']));
114 $HasChildren = $dbManager->fetchArray($result);
115 $dbManager->freeResult($result);
117 $Parm =
"upload=$Upload&show=$Show&item=" . $Row[
'uploadtree_pk'];
118 $Link = $HasChildren ?
"$Uri&show=$Show&upload=$Upload&item=$Row[uploadtree_pk]" : NULL;
120 if ($Show ==
'detail') {
121 $V .=
"<td class='mono'>" .
DirMode2String($Row[
'ufile_mode']) .
"</td>";
122 if (!
Isdir($Row[
'ufile_mode'])) {
123 $V .=
"<td align='right'> " . number_format($Row[
'pfile_size'], 0,
"",
",") .
" </td>";
125 $V .=
"<td> </td>";
129 $displayItem =
Isdir($Row[
'ufile_mode']) ?
"$Name/" :
$Name;
131 $displayItem =
"<a href=\"$Link\">$displayItem</a>";
134 $displayItem =
"<b>$displayItem</b>";
136 $V .=
"<td>$displayItem</td>\n";
139 $V .=
menu_to_1list($MenuPfileNoCompare, $Parm,
"<td>",
"</td>\n", 1, $Upload);
140 }
else if (!
Isdir($Row[
'ufile_mode'])) {
141 $V .=
menu_to_1list($MenuPfile, $Parm,
"<td>",
"</td>\n", 1, $Upload);
143 $V .=
menu_to_1list($MenuTag, $Parm,
"<td>",
"</td>\n", 1, $Upload);
147 if (! $ShowSomething) {
148 $text = _(
"No files");
149 $V .=
"<b>$text</b>\n";
152 if (count($Results) == 1) {
157 $V .= count($Results) .
" $text\n";
169 $rootFolder = $this->folderDao->getDefaultFolder(Auth::getUserId());
170 if ($rootFolder == NULL) {
171 $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId());
174 $folderNav =
'<div id="sidetree" class="container justify-content-center" style="min-width: 234px;">';
175 if ($folderId != $rootFolder->getId()) {
176 $folderNav .=
'<div class="treeheader" style="display:inline;"><a class="btn btn-outline-success btn-sm" href="' .
177 Traceback_uri() .
'?mod=' . $this->Name .
'">Top folder</a> | </div>';
179 $folderNav .=
'<div id="sidetreecontrol" class="treeheader" style="display:inline;">
180 <a class="btn btn-outline-success btn-sm" href="?#">Collapse All</a> |
181 <a class="btn btn-outline-success btn-sm" href="?#">Expand All</a>
184 <div class="col-sm-20" style="margin-top:-10px;">
185 <input id="searchFolderTree" type="text" class="form-control" name="searchFolderTree" placeholder="Search folder" autofocus="autofocus"">
188 $folderNav .=
'<div id="foldertree"></div></div>';
190 $this->vars[
'folderNav'] = $folderNav;
192 $assigneeArray = $this->getAssigneeArray();
193 $this->vars[
'assigneeOptions'] = $assigneeArray;
194 $this->vars[
'statusOptions'] = $this->uploadDao->getStatusTypeMap();
195 $this->vars[
'folder'] = $folderId;
196 $this->vars[
'folderName'] = $this->folderDao->getFolder($folderId)->getName();
204 if ($this->
State != PLUGIN_STATE_READY) {
207 $this->folderDao->ensureTopLevelFolder();
214 if (!empty($folder_pk) && !$this->folderDao->isFolderAccessible($folder_pk)) {
215 $this->vars[
'message'] = _(
"Permission Denied");
216 return $this->
render(
'include/base.html.twig');
220 if (!empty($Upload) && !$this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
221 $this->vars[
'message'] = _(
"Permission Denied");
222 return $this->
render(
'include/base.html.twig');
225 if (empty($folder_pk)) {
228 }
catch (Exception $exc) {
229 return $exc->getMessage();
234 if ($output instanceof Response) {
238 $this->vars[
'content'] = $output;
239 $modsUploadMulti = MenuHook::getAgentPluginNames(
'UploadMulti');
240 if (!empty($modsUploadMulti)) {
241 $multiUploadAgents = array();
242 foreach ($modsUploadMulti as $mod) {
243 $multiUploadAgents[$mod] = $GLOBALS[
'Plugins'][$mod]->title;
245 $this->vars[
'multiUploadAgents'] = $multiUploadAgents;
247 $this->vars[
'folderId'] = $folder_pk;
249 return $this->
render(
'ui-browse.html.twig');
258 $rootFolder = $this->folderDao->getDefaultFolder(Auth::getUserId());
259 if ($rootFolder == NULL) {
260 $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId());
262 if (empty($uploadId)) {
263 return $rootFolder->getId();
268 $dbManager = $container->get(
'db.manager');
269 $uploadExists = $dbManager->getSingleRow(
270 "SELECT count(*) cnt FROM upload WHERE upload_pk=$1 " .
271 "AND (expire_action IS NULL OR expire_action!='d') AND pfile_fk IS NOT NULL", array($uploadId));
272 if ($uploadExists[
'cnt']< 1) {
273 throw new Exception(
"This upload no longer exists on this system.");
276 $folderTreeCte = $this->folderDao->getFolderTreeCte($rootFolder);
278 $parent = $dbManager->getSingleRow(
280 " SELECT ft.folder_pk FROM foldercontents fc LEFT JOIN folder_tree ft ON fc.parent_fk=ft.folder_pk "
281 .
"WHERE child_id=$2 AND foldercontents_mode=$3 ORDER BY depth LIMIT 1",
282 array($rootFolder->getId(), $uploadId, FolderDao::MODE_UPLOAD),
283 __METHOD__.
'.parent');
285 throw new Exception(
"Upload $uploadId missing from foldercontents in your foldertree.");
287 return $parent[
'folder_pk'];
299 $dbManager = $container->get(
'db.manager');
302 $uploadtree_tablename =
"";
303 if (! empty($uploadTreeId)) {
304 $sql =
"SELECT ufile_mode, upload_fk FROM uploadtree WHERE uploadtree_pk = $1";
305 $row = $dbManager->getSingleRow($sql, array($uploadTreeId));
306 $Upload = $row[
'upload_fk'];
307 if (! $this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
308 $this->vars[
'message'] = _(
"Permission Denied");
309 return $this->
render(
'include/base.html.twig');
313 $parentItemBounds = $this->uploadDao->getParentItemBounds($Upload);
314 if (! $parentItemBounds->containsFiles()) {
316 return new RedirectResponse(
Traceback_uri() .
'?mod=view-license'
320 $View = &$Plugins[plugin_find_id(
"view")];
321 if (! empty($View)) {
322 $this->vars[
'content'] = $View->ShowView(NULL,
"browse");
323 return $this->
render(
'include/base.html.twig');
326 $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($row[
'upload_fk']);
327 $html .=
Dir2Browse($this->Name, $uploadTreeId, NULL, 1,
"Browse", -1,
'',
'', $uploadtree_tablename) .
"\n";
328 }
else if (!empty($Upload)) {
329 $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload);
331 $uploadtree_tablename) .
"\n";
334 if (empty($Upload)) {
335 $this->vars[
'show'] = $show;
340 if (empty($uploadTreeId)) {
342 $uploadTreeId = $this->uploadDao->getUploadParent($Upload);
343 }
catch(Exception $e) {
344 $this->vars[
'message'] = $e->getMessage();
345 return $this->
render(
'include/base.html.twig');
348 $html .= $this->ShowItem($Upload, $uploadTreeId, $show, $Folder, $uploadtree_tablename);
349 $this->vars[
'content'] = $html;
350 return $this->
render(
'include/base.html.twig');
356 private function getAssigneeArray()
360 $userDao = $container->get(
'dao.user');
361 $assigneeArray = $userDao->getUserChoices();
362 $assigneeArray[Auth::getUserId()] = _(
'-- Me --');
363 $assigneeArray[1] = _(
'Unassigned');
364 $assigneeArray[0] =
'';
365 return $assigneeArray;
370 $NewPlugin->Install();
This is the Plugin class. All plugins should:
render($templateName, $vars=null)
Contains the constants and helpers for authentication of user.
ShowFolder($folderId)
Given a folderId, list every item in it. If it is an individual file, then list the file contents.
Output()
This function returns the output html.
getFolderId($uploadId)
kludge for plugins not supplying a folder parameter. Find what folder this upload is in.
RegisterMenus()
Customize submenus.
__construct()
base constructor. Most plugins will just use this
outputItemHtml($uploadTreeId, $Folder, $Upload)
Dir2BrowseUpload($Mod, $UploadPk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $uploadtree_tablename='uploadtree')
Get an html links string of a file browse path.
DirMode2String($Mode)
Convert a file mode to string values.
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.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.