19 if ($val ===
'' || !isset($idx[$val])) {
22 $filtered = array_filter($idx[$val],
function ($k) use ($key) {
25 if (empty($filtered)) {
28 $idx[$val] = array_values($filtered);
38 array &$byName, array &$byFuzzyExt, array &$byFuzzy)
41 $name = $child[
'ufile_name'];
42 if (isset($byName[$name])) {
43 foreach ($byName[$name] as $k) {
44 if (isset($pool[$k])) {
51 $fe = $child[
'fuzzynameext'] ??
'';
52 if ($fe !==
'' && isset($byFuzzyExt[$fe])) {
53 foreach ($byFuzzyExt[$fe] as $k) {
54 if (isset($pool[$k])) {
62 foreach ($pool as $k => $candidate) {
63 $cfe = $candidate[
'fuzzynameext'] ??
'';
64 if ($cfe !==
'' && levenshtein($fe, $cfe) === 1) {
71 $f = $child[
'fuzzyname'] ??
'';
72 if ($f !==
'' && isset($byFuzzy[$f])) {
73 foreach ($byFuzzy[$f] as $k) {
74 if (isset($pool[$k])) {
92 $N = count($ChildrenArrays);
103 foreach ($ChildrenArrays as $colIdx => $children) {
104 $remaining[$colIdx] = $children;
105 $byName[$colIdx] = [];
106 $byFuzzyExt[$colIdx] = [];
107 $byFuzzy[$colIdx] = [];
108 foreach ($children as $key => $child) {
109 $byName[$colIdx][$child[
'ufile_name']][] = $key;
110 $fe = $child[
'fuzzynameext'] ??
'';
112 $byFuzzyExt[$colIdx][$fe][] = $key;
114 $f = $child[
'fuzzyname'] ??
'';
116 $byFuzzy[$colIdx][$f][] = $key;
123 for ($anchor = 0; $anchor < $N; $anchor++) {
124 foreach ($remaining[$anchor] as $anchorKey => $anchorChild) {
125 $row = [$anchor => $anchorChild];
126 _mcIndexRemove($byName[$anchor], $anchorChild[
'ufile_name'], $anchorKey);
127 _mcIndexRemove($byFuzzyExt[$anchor], $anchorChild[
'fuzzynameext'] ??
'', $anchorKey);
128 _mcIndexRemove($byFuzzy[$anchor], $anchorChild[
'fuzzyname'] ??
'', $anchorKey);
129 unset($remaining[$anchor][$anchorKey]);
131 for ($other = 0; $other < $N; $other++) {
132 if ($other === $anchor || isset($row[$other])) {
137 $byName[$other], $byFuzzyExt[$other], $byFuzzy[$other]);
138 if ($matchKey !==
null) {
139 $matched = $remaining[$other][$matchKey];
140 $row[$other] = $matched;
141 _mcIndexRemove($byName[$other], $matched[
'ufile_name'], $matchKey);
142 _mcIndexRemove($byFuzzyExt[$other], $matched[
'fuzzynameext'] ??
'', $matchKey);
143 _mcIndexRemove($byFuzzy[$other], $matched[
'fuzzyname'] ??
'', $matchKey);
144 unset($remaining[$other][$matchKey]);
147 $masterRows[] = $row;
151 usort($masterRows,
function (array $a, array $b):
int {
154 $aName = $aChild[
'fuzzyname'] ?? $aChild[
'ufile_name'];
155 $bName = $bChild[
'fuzzyname'] ?? $bChild[
'ufile_name'];
156 return strcasecmp($aName, $bName);
176 function GetDiffLinkN(array $MasterRow,
int $colIdx,
int $agentPk,
string $filter,
177 string $pluginName, array $items,
string $mode,
int $baseline): string
182 static $viewLicId =
null;
183 if ($viewLicId ===
null) {
184 $viewLicId = plugin_find_id(
"view-license");
186 $ModLicView = ($viewLicId !==
false && isset($Plugins[$viewLicId]))
187 ? $Plugins[$viewLicId] :
null;
189 $Child = $MasterRow[$colIdx];
190 $IsDir =
Isdir($Child[
'ufile_mode']);
194 $newItems[$colIdx] = $Child[
'uploadtree_pk'];
196 foreach ($items as $c => $parentPk) {
197 if ($c === $colIdx) {
200 if (isset($MasterRow[$c]) && !empty($MasterRow[$c][
'uploadtree_pk'])) {
201 $newItems[$c] = $MasterRow[$c][
'uploadtree_pk'];
206 if (!empty($Child[
'pfile_fk']) && !empty($ModLicView)) {
208 $LinkUri .=
"?mod=view-license&napk=$agentPk&upload=$Child[upload_fk]&item=$Child[uploadtree_pk]";
213 $LicUri =
"?mod=$pluginName&items=" . implode(
",", $newItems);
214 $LicUri .=
"&col=$colIdx&filter=" . urlencode($filter);
215 $LicUri .=
"&mode=" . urlencode($mode);
216 $LicUri .=
"&baseline=$baseline";
220 if ($IsContainer && $LicUri) {
221 $parts[] =
"<a href='$LicUri'><b>";
222 } elseif ($LinkUri) {
223 $parts[] =
"<a href='$LinkUri'>";
226 $parts[] = htmlspecialchars($Child[
'ufile_name']);
231 if ($IsContainer && $LicUri) {
232 $parts[] =
"</b></a>";
233 } elseif ($LinkUri) {
237 return implode(
"", $parts);
252 function FileListN(array &$Master, array $agentPks,
string $filter,
string $pluginName,
253 array $items,
string $mode,
int $baseline): void
255 foreach ($Master as &$row) {
256 foreach ($row as $colIdx => &$child) {
260 $agentPk = $agentPks[$colIdx] ?? 0;
261 $child[
'linkurl'] =
GetDiffLinkN($row, $colIdx, $agentPk, $filter,
262 $pluginName, $items, $mode, $baseline);
282 function Dir2BrowseDiffN(array $path,
string $filter,
int $colIdx,
string $pluginName,
283 array $items,
string $mode,
int $baseline): string
285 static $folderCache = [];
288 return "<div class='card card-body p-1 bg-light'><em>No path</em></div>";
291 $Last = $path[count($path) - 1];
293 $baseQS =
"&filter=" . urlencode($filter) .
"&mode=" . urlencode($mode)
294 .
"&baseline=$baseline";
296 $FreezeText = _(
"Freeze");
297 $freezeBtnId =
"Freeze$colIdx";
298 $freezeOpts =
"id='$freezeBtnId' onclick='Freeze($colIdx)'"
299 .
" class='btn btn-outline-secondary'"
300 .
" style='font-size:0.65rem;padding:1px 5px;line-height:1.3;white-space:nowrap;flex-shrink:0'";
302 $uploadFk = $path[0][
'upload_fk'];
303 if (!isset($folderCache[$uploadFk])) {
306 $FolderList = $folderCache[$uploadFk];
309 $parts[] =
"<div class='card card-body p-1 bg-light'>";
310 $parts[] =
"<div class='d-flex justify-content-between align-items-start'>";
312 $parts[] =
"<strong>" . _(
"Folder") .
":</strong> ";
313 foreach ($FolderList as $Folder) {
314 $parts[] =
"<b>" . htmlspecialchars($Folder[
'folder_name']) .
"/</b>";
319 foreach ($path as $idx => $PathElt) {
320 $itemsForLink = $items;
321 $itemsForLink[$colIdx] = $PathElt[
'uploadtree_pk'];
322 $href = $Uri2 .
"&items=" . implode(
",", $itemsForLink) .
"&col=$colIdx$baseQS";
323 $isLast = ($PathElt[
'uploadtree_pk'] == $Last[
'uploadtree_pk']);
328 $parts[] =
"<b>" . htmlspecialchars($PathElt[
'ufile_name']) .
"</b>";
330 $parts[] =
"<a href='" . htmlspecialchars($href) .
"'>"
331 . htmlspecialchars($PathElt[
'ufile_name']) .
"</a>";
336 $parts[] =
"<button type='button' $freezeOpts>$FreezeText</button>";
339 return implode(
"", $parts);
FolderGetFromUpload($Uploadpk, $Folder=-1, $Stop=-1)
DEPRECATED! Given an upload number, return the folder path in an array containing folder_pk and name.
_mcFindBestMatch(array $child, array $pool, array &$byName, array &$byFuzzyExt, array &$byFuzzy)
Hashmap-accelerated best-match (O(1) for stages 1, 2, 4; O(M) only for rare stage 3).
_mcIndexRemove(array &$idx, string $val, $key)
Remove one key from a name-index bucket list (used by MakeMasterN).
GetDiffLinkN(array $MasterRow, int $colIdx, int $agentPk, string $filter, string $pluginName, array $items, string $mode, int $baseline)
Generate the navigation link for one cell in the multi-component table.
Dir2BrowseDiffN(array $path, string $filter, int $colIdx, string $pluginName, array $items, string $mode, int $baseline)
Render the folder/path breadcrumb banner for one column.
MakeMasterN(array $ChildrenArrays)
Build the master array for N file lists using hashmap-based O(M·N) matching.
FileListN(array &$Master, array $agentPks, string $filter, string $pluginName, array $items, string $mode, int $baseline)
Attach linkurl to every cell in Master (N-way version of FileList()).
Traceback_uri()
Get the URI without query to this location.