16 use Symfony\Component\HttpFoundation\RedirectResponse;
17 use Symfony\Component\HttpFoundation\Response;
19 define(
"TITLE_UI_BROWSE", _(
"Browse"));
30 $this->Name =
"browse";
31 $this->Title = TITLE_UI_BROWSE;
32 $this->MenuList =
"Browse";
33 $this->MenuOrder = 80;
34 $this->MenuTarget =
"";
39 $this->uploadDao = $container->get(
'dao.upload');
40 $this->folderDao = $container->get(
'dao.folder');
42 parent::__construct();
50 menu_insert(
"Main::" . $this->MenuList, $this->MenuOrder, $this->Name, $this->Name);
63 return ($this->
State == PLUGIN_STATE_READY);
70 function ShowItem($Upload, $Item, $Show, $Folder, $uploadtree_tablename)
74 $dbManager = $container->get(
'db.manager');
75 $RowStyle1 =
"style='background-color:#ecfaff'";
76 $RowStyle2 =
"style='background-color:#ffffe3'";
82 $Uri =
Traceback_uri() .
"?mod=" . $this->Name .
"&folder=$Folder";
86 $MenuPfile =
menu_find(
"Browse-Pfile", $MenuDepth);
88 $MenuPfileNoCompare =
menu_remove($MenuPfile,
"Compare");
91 foreach ($MenuPfile as $value) {
92 if (($value->Name ==
'Tag') || ($value->Name ==
'Compare')) {
97 $Results = GetNonArtifactChildren($Item, $uploadtree_tablename);
99 $V .=
"<table class='text' style='border-collapse: collapse' border=0 padding=0>\n";
100 $stmtGetFirstChild = __METHOD__.
'.getFirstChild';
101 $dbManager->prepare($stmtGetFirstChild,
"SELECT uploadtree_pk FROM $uploadtree_tablename WHERE parent=$1 limit 1");
102 foreach ($Results as $Row) {
103 if (empty($Row[
'uploadtree_pk'])) {
107 $Name = $Row[
'ufile_name'];
110 $RowStyle = (($RowNum++ % (2 * $ColorSpanRows)) < $ColorSpanRows) ? $RowStyle1 : $RowStyle2;
111 $V .=
"<tr $RowStyle>";
114 $result = $dbManager->execute($stmtGetFirstChild,array($Row[
'uploadtree_pk']));
115 $HasChildren = $dbManager->fetchArray($result);
116 $dbManager->freeResult($result);
118 $Parm =
"upload=$Upload&show=$Show&item=" . $Row[
'uploadtree_pk'];
119 $Link = $HasChildren ?
"$Uri&show=$Show&upload=$Upload&item=$Row[uploadtree_pk]" : NULL;
121 if ($Show ==
'detail') {
122 $V .=
"<td class='mono'>" .
DirMode2String($Row[
'ufile_mode']) .
"</td>";
123 if (!
Isdir($Row[
'ufile_mode'])) {
124 $V .=
"<td align='right'> " . number_format($Row[
'pfile_size'], 0,
"",
",") .
" </td>";
126 $V .=
"<td> </td>";
130 $displayItem =
Isdir($Row[
'ufile_mode']) ?
"$Name/" :
$Name;
132 $displayItem =
"<a href=\"$Link\">$displayItem</a>";
135 $displayItem =
"<b>$displayItem</b>";
137 $V .=
"<td>$displayItem</td>\n";
140 $V .=
menu_to_1list($MenuPfileNoCompare, $Parm,
"<td>",
"</td>\n", 1, $Upload);
141 }
else if (!
Isdir($Row[
'ufile_mode'])) {
142 $V .=
menu_to_1list($MenuPfile, $Parm,
"<td>",
"</td>\n", 1, $Upload);
144 $V .=
menu_to_1list($MenuTag, $Parm,
"<td>",
"</td>\n", 1, $Upload);
148 if (! $ShowSomething) {
149 $text = _(
"No files");
150 $V .=
"<b>$text</b>\n";
153 if (count($Results) == 1) {
158 $V .= count($Results) .
" $text\n";
170 $rootFolder = $this->folderDao->getDefaultFolder(Auth::getUserId());
171 if ($rootFolder == NULL) {
172 $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId());
175 $uiFolderNav = $GLOBALS[
'container']->get(
'ui.folder.nav');
177 $folderNav =
'<div id="sidetree" class="container justify-content-center" style="min-width: 234px;">';
178 if ($folderId != $rootFolder->getId()) {
179 $folderNav .=
'<div class="treeheader" style="display:inline;"><a class="btn btn-outline-success btn-sm" href="' .
180 Traceback_uri() .
'?mod=' . $this->Name .
'">Top folder</a> | </div>';
182 $folderNav .=
'<div id="sidetreecontrol" class="treeheader" style="display:inline;">
183 <a class="btn btn-outline-success btn-sm" href="?#">Collapse All</a> |
184 <a class="btn btn-outline-success btn-sm" href="?#">Expand All</a>
187 <div class="col-sm-20" style="margin-top:-10px;">
188 <input id="searchFolderTree" type="text" class="form-control" name="searchFolderTree" placeholder="Search folder" autofocus="autofocus"">
190 $folderNav .= $uiFolderNav->showFolderTree($folderId).
'</div>';
192 $this->vars[
'folderNav'] = $folderNav;
194 $assigneeArray = $this->getAssigneeArray();
195 $this->vars[
'assigneeOptions'] = $assigneeArray;
196 $this->vars[
'statusOptions'] = $this->uploadDao->getStatusTypeMap();
197 $this->vars[
'folder'] = $folderId;
198 $this->vars[
'folderName'] = $this->folderDao->getFolder($folderId)->getName();
206 if ($this->
State != PLUGIN_STATE_READY) {
209 $this->folderDao->ensureTopLevelFolder();
216 if (!empty($folder_pk) && !$this->folderDao->isFolderAccessible($folder_pk)) {
217 $this->vars[
'message'] = _(
"Permission Denied");
218 return $this->
render(
'include/base.html.twig');
222 if (!empty($Upload) && !$this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
223 $this->vars[
'message'] = _(
"Permission Denied");
224 return $this->
render(
'include/base.html.twig');
227 if (empty($folder_pk)) {
230 }
catch (Exception $exc) {
231 return $exc->getMessage();
236 if ($output instanceof Response) {
240 $this->vars[
'content'] = $output;
241 $modsUploadMulti = MenuHook::getAgentPluginNames(
'UploadMulti');
242 if (!empty($modsUploadMulti)) {
243 $multiUploadAgents = array();
244 foreach ($modsUploadMulti as $mod) {
245 $multiUploadAgents[$mod] = $GLOBALS[
'Plugins'][$mod]->title;
247 $this->vars[
'multiUploadAgents'] = $multiUploadAgents;
249 $this->vars[
'folderId'] = $folder_pk;
251 return $this->
render(
'ui-browse.html.twig');
260 $rootFolder = $this->folderDao->getDefaultFolder(Auth::getUserId());
261 if ($rootFolder == NULL) {
262 $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId());
264 if (empty($uploadId)) {
265 return $rootFolder->getId();
270 $dbManager = $container->get(
'db.manager');
271 $uploadExists = $dbManager->getSingleRow(
272 "SELECT count(*) cnt FROM upload WHERE upload_pk=$1 " .
273 "AND (expire_action IS NULL OR expire_action!='d') AND pfile_fk IS NOT NULL", array($uploadId));
274 if ($uploadExists[
'cnt']< 1) {
275 throw new Exception(
"This upload no longer exists on this system.");
278 $folderTreeCte = $this->folderDao->getFolderTreeCte($rootFolder);
280 $parent = $dbManager->getSingleRow(
282 " SELECT ft.folder_pk FROM foldercontents fc LEFT JOIN folder_tree ft ON fc.parent_fk=ft.folder_pk "
283 .
"WHERE child_id=$2 AND foldercontents_mode=$3 ORDER BY depth LIMIT 1",
284 array($rootFolder->getId(), $uploadId, FolderDao::MODE_UPLOAD),
285 __METHOD__.
'.parent');
287 throw new Exception(
"Upload $uploadId missing from foldercontents in your foldertree.");
289 return $parent[
'folder_pk'];
301 $dbManager = $container->get(
'db.manager');
304 $uploadtree_tablename =
"";
305 if (! empty($uploadTreeId)) {
306 $sql =
"SELECT ufile_mode, upload_fk FROM uploadtree WHERE uploadtree_pk = $1";
307 $row = $dbManager->getSingleRow($sql, array($uploadTreeId));
308 $Upload = $row[
'upload_fk'];
309 if (! $this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
310 $this->vars[
'message'] = _(
"Permission Denied");
311 return $this->
render(
'include/base.html.twig');
315 $parentItemBounds = $this->uploadDao->getParentItemBounds($Upload);
316 if (! $parentItemBounds->containsFiles()) {
318 return new RedirectResponse(
Traceback_uri() .
'?mod=view-license'
322 $View = &$Plugins[plugin_find_id(
"view")];
323 if (! empty($View)) {
324 $this->vars[
'content'] = $View->ShowView(NULL,
"browse");
325 return $this->
render(
'include/base.html.twig');
328 $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($row[
'upload_fk']);
329 $html .=
Dir2Browse($this->Name, $uploadTreeId, NULL, 1,
"Browse", -1,
'',
'', $uploadtree_tablename) .
"\n";
330 }
else if (!empty($Upload)) {
331 $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload);
333 $uploadtree_tablename) .
"\n";
336 if (empty($Upload)) {
337 $this->vars[
'show'] = $show;
342 if (empty($uploadTreeId)) {
344 $uploadTreeId = $this->uploadDao->getUploadParent($Upload);
345 }
catch(Exception $e) {
346 $this->vars[
'message'] = $e->getMessage();
347 return $this->
render(
'include/base.html.twig');
350 $html .= $this->ShowItem($Upload, $uploadTreeId, $show, $Folder, $uploadtree_tablename);
351 $this->vars[
'content'] = $html;
352 return $this->
render(
'include/base.html.twig');
358 private function getAssigneeArray()
362 $userDao = $container->get(
'dao.user');
363 $assigneeArray = $userDao->getUserChoices();
364 $assigneeArray[Auth::getUserId()] = _(
'-- Me --');
365 $assigneeArray[1] = _(
'Unassigned');
366 $assigneeArray[0] =
'';
367 return $assigneeArray;
372 $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.