| @@ -1,86 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace AcyMailing\Types; | |
| 4 | - | |
| 5 | -use AcyMailing\Core\AcymObject; | |
| 6 | - | |
| 7 | -class FileTreeType extends AcymObject | |
| 8 | -{ | |
| 9 | - public function display(array $folders, string $currentFolder, string $nameInput): string | |
| 10 | - { | |
| 11 | - $tree = []; | |
| 12 | - foreach ($folders as $root => $children) { | |
| 13 | - $tree = array_merge($tree, $this->searchChildren($children, $root)); | |
| 14 | - } | |
| 15 | - | |
| 16 | - $treeView = '<div id="displaytree" class="cell medium-11"><input type="text" readonly name="currentPath" id="currentPath" value="'.acym_escape($currentFolder).'"></div>'; | |
| 17 | - $treeView .= '<div class="cell" id="treefile" style="display: none;">'.$this->displayTree($tree, $currentFolder).'</div>'; | |
| 18 | - $treeView .= '<input type="hidden" name="'.acym_escape($nameInput).'" id="'.acym_escape($nameInput).'" value="'.acym_escape($currentFolder).'">'; | |
| 19 | - | |
| 20 | - return $treeView; | |
| 21 | - } | |
| 22 | - | |
| 23 | - private function searchChildren(array $folders, string $root): array | |
| 24 | - { | |
| 25 | - $tree = []; | |
| 26 | - $tree[$root] = []; | |
| 27 | - | |
| 28 | - foreach ($folders as $folder) { | |
| 29 | - $folder = trim(str_replace($root, '', $folder), '/\\'); | |
| 30 | - if (empty($folder)) { | |
| 31 | - continue; | |
| 32 | - } | |
| 33 | - | |
| 34 | - $pathParts = explode('/', $folder); | |
| 35 | - $variable = &$tree[$root]; | |
| 36 | - foreach ($pathParts as $pathPart) { | |
| 37 | - if (empty($variable[$pathPart])) { | |
| 38 | - $variable[$pathPart] = []; | |
| 39 | - } | |
| 40 | - $variable = &$variable[$pathPart]; | |
| 41 | - } | |
| 42 | - } | |
| 43 | - | |
| 44 | - return $tree; | |
| 45 | - } | |
| 46 | - | |
| 47 | - private function displayTree(array $tree, string $pathValue, string $path = ''): string | |
| 48 | - { | |
| 49 | - if (empty($tree)) { | |
| 50 | - return ''; | |
| 51 | - } | |
| 52 | - | |
| 53 | - $results = '<ul>'; | |
| 54 | - foreach ($tree as $key => $treeItem) { | |
| 55 | - if (empty($path)) { | |
| 56 | - $currentPath = $key; | |
| 57 | - $title = '/'; | |
| 58 | - } else { | |
| 59 | - $currentPath = rtrim($path, '/').'/'.trim($key, '/').'/'; | |
| 60 | - $title = $key; | |
| 61 | - } | |
| 62 | - | |
| 63 | - $extraClass = 'tree-closed'; | |
| 64 | - $icon = 'acymicon-folder'; | |
| 65 | - | |
| 66 | - if (strpos($pathValue, $currentPath) !== false) { | |
| 67 | - $extraClass = $pathValue == $currentPath ? 'tree-current' : ''; | |
| 68 | - $icon .= '-open'; | |
| 69 | - } | |
| 70 | - | |
| 71 | - if (empty($treeItem)) { | |
| 72 | - $extraClass .= ' tree-empty'; | |
| 73 | - } | |
| 74 | - | |
| 75 | - $subTree = $this->displayTree($treeItem, $pathValue, $currentPath); | |
| 76 | - $results .= '<li class="tree-child-item '.acym_escape($extraClass).'" data-path="'.acym_escape($currentPath).'"> | |
| 77 | - <span class="tree-child-title"> | |
| 78 | - <i class="'.acym_escape($icon).'"></i> '.$title.' | |
| 79 | - </span>'.$subTree.' | |
| 80 | - </li>'; | |
| 81 | - } | |
| 82 | - $results .= '</ul>'; | |
| 83 | - | |
| 84 | - return $results; | |
| 85 | - } | |
| 86 | -} | |