FOSSology  4.4.0
Open Source License Compliance by Open Source Software
common-folders.php File Reference

Common Folder Functions Design note: Folders could be stored in a menu listing (using menu_insert). However, since menu_insert() runs a usort() during each insert, this can be really slow. For speed, folders are handled separately. More...

Go to the source code of this file.

Functions

 FolderGetTop ()
 DEPRECATED! Find the top-of-tree folder_pk for the current user. More...
 
 GetUserRootFolder ()
 Get the top-of-tree folder_pk for the current user. Fail if there is no user session. More...
 
 Folder2Path ($folder_pk)
 Return an array of folder_pk, folder_name from the users.root_folder_fk to $folder_pk. More...
 
 GetFolderFromItem ($upload_pk="", $uploadtree_pk="")
 Find what folder an item is in. More...
 
 FolderListOption ($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
 Create the folder tree, using OPTION tags. More...
 
 FolderGetName ($FolderPk, $Top=-1)
 Given a folder_pk, return the full path to this folder. More...
 
 FolderGetFromUpload ($Uploadpk, $Folder=-1, $Stop=-1)
 DEPRECATED! Given an upload number, return the folder path in an array containing folder_pk and name. More...
 
 FolderListUploads_perm ($ParentFolder, $perm)
 Returns an array of uploads in a folder. More...
 
 FolderListUploadsRecurse ($ParentFolder=-1, $FolderPath='', $perm=Auth::PERM_READ)
 Get uploads and folder info, starting from $ParentFolder. More...
 
 GetFolderArray ($RootFolder, &$FolderArray)
 Get an array of all the folders from a $RootFolder on down. More...
 
 ContainExcludeString ($FilePath, $ExcludingText)
 Check if one file path contains an excluding text. More...
 

Detailed Description

Common Folder Functions Design note: Folders could be stored in a menu listing (using menu_insert). However, since menu_insert() runs a usort() during each insert, this can be really slow. For speed, folders are handled separately.

Definition in file common-folders.php.

Function Documentation

◆ ContainExcludeString()

ContainExcludeString (   $FilePath,
  $ExcludingText 
)

Check if one file path contains an excluding text.

Parameters
string$FilePathFile path
string$ExcludingTextExcluding text
Returns
1: include, 0: not include

Definition at line 573 of file common-folders.php.

◆ Folder2Path()

Folder2Path (   $folder_pk)

Return an array of folder_pk, folder_name from the users.root_folder_fk to $folder_pk.

Array is in top down order. If you need to know the folder_pk of an upload or uploadtree, use GetFolderFromItem()

Parameters
int$folder_pk
Returns
The folder list:
FolderList = array({'folder_pk'=>folder_pk, 'folder_name'=>folder_name}, ...
const char * folder_name
Definition: sqlstatements.h:54
Examples
/home/runner/work/fossology/fossology/src/www/ui/ui-picker.php.

Definition at line 90 of file common-folders.php.

◆ FolderGetFromUpload()

FolderGetFromUpload (   $Uploadpk,
  $Folder = -1,
  $Stop = -1 
)

DEPRECATED! Given an upload number, return the folder path in an array containing folder_pk and name.

Note
This is recursive!
If there is a recursive loop in the folder table, then this will loop INFINITELY.
Deprecated:
Use Folder2Path() and GetFolderFromItem()

Definition at line 294 of file common-folders.php.

◆ FolderGetName()

FolderGetName (   $FolderPk,
  $Top = -1 
)

Given a folder_pk, return the full path to this folder.

Note
This is recursive!
If there is a recursive loop in the folder table, then this will loop INFINITELY.
Parameters
int$FolderPkFolder id
int$TopOptional, default is user's top folder. folder_pk of top of desired path.
Returns
string full path of this folder

Definition at line 263 of file common-folders.php.

◆ FolderGetTop()

FolderGetTop ( )

DEPRECATED! Find the top-of-tree folder_pk for the current user.

Deprecated:
Use GetUserRootFolder()

Definition at line 26 of file common-folders.php.

◆ FolderListOption()

FolderListOption (   $ParentFolder,
  $Depth,
  $IncludeTop = 1,
  $SelectId = -1,
  $linkParent = false,
  $OldParent = 0 
)

Create the folder tree, using OPTION tags.

Note
The caller must already have created the FORM and SELECT tags.
This is recursive!
If there is a recursive loop in the folder table, then this will loop INFINITELY.
Parameters
int$ParentFolderParents folder_fk
int$DepthTree depth to create
bool$IncludeTopTrue to include fossology root folder
int$SelectIdfolder_fk of selected folder
bool$linkParentIf true, the option tag will have $OldParent and $ParentFolder as the value
int$OldParentParent of the parent folder
Returns
HTML of the folder tree

Definition at line 178 of file common-folders.php.

◆ FolderListUploads_perm()

FolderListUploads_perm (   $ParentFolder,
  $perm 
)

Returns an array of uploads in a folder.

Only uploads for which the user has permission >= $perm are returned. This does NOT recurse. The returned array is sorted by ufile_name and upload_pk.

Parameters
int$ParentFolderOptional folder_pk, default is users root folder.
int$permMinimum permission
Returns
array{upload_pk, upload_desc, upload_ts, ufile_name} for all uploads in a given folder.

Definition at line 361 of file common-folders.php.

◆ FolderListUploadsRecurse()

FolderListUploadsRecurse (   $ParentFolder = -1,
  $FolderPath = '',
  $perm = Auth::PERM_READ 
)

Get uploads and folder info, starting from $ParentFolder.

The array is sorted by folder and upload name. Folders that are empty do not show up.

Note
This is recursive!
If there is a recursive loop in the folder table, then this will loop INFINITELY.
Parameters
int$ParentFolderfolder_pk, -1 for users root folder
string$FolderPathUsed for recursion, caller should not specify.
Auth::PERM_READ | Auth::PERM_WRITE$permPermission required
Returns
array of {upload_pk, upload_desc, name, folder}

Definition at line 428 of file common-folders.php.

◆ GetFolderArray()

GetFolderArray (   $RootFolder,
$FolderArray 
)

Get an array of all the folders from a $RootFolder on down.

Recursive. This is typically used to build a select list of folder names.

Parameters
int$RootFolderDefault is entire software repository
[out]array$FolderArrayReturned array of folder_pk=>folder_name's
Returns
$FolderArray of {folder_pk=>folder_name, folder_pk=>folder_name, ...} in folder order. If no folders are in the list, an empty array is returned.
Todo:
Possibly this could be a common function and FolderListOption() could use this for its data. In general data collection and data formatting should be separate functions.

Definition at line 525 of file common-folders.php.

◆ GetFolderFromItem()

GetFolderFromItem (   $upload_pk = "",
  $uploadtree_pk = "" 
)

Find what folder an item is in.

Parameters
int$upload_pkNULL if $uploadtree_pk is passed in
int$uploadtree_pkNULL if $upload_pk is passed in
Note
If both $upload_pk and $uploadtree_pk are passed in, $upload_pk will be used.
Returns
The folder_pk that the upload_pk (or uploadtree_pk) is in
Examples
/home/runner/work/fossology/fossology/src/www/ui/ui-picker.php.

Definition at line 138 of file common-folders.php.

◆ GetUserRootFolder()

GetUserRootFolder ( )

Get the top-of-tree folder_pk for the current user. Fail if there is no user session.

Returns
folder_pk for the current user

Definition at line 50 of file common-folders.php.