1: <?php
2:
3: if (!defined('DEBUG_MODE')) { die(); }
4:
5: if (!hm_exists('add_tag')) {
6: function add_tag($name, $parent = null) {
7: $tag = array(
8: 'name' => $name,
9: 'parent' => $parent,
10: );
11:
12: Hm_Tags::add($tag);
13: }
14: }
15:
16: if (!hm_exists('generate_tree_view')) {
17: function generate_tree_view($folders, $request_Key, $parentId = null) {
18: static $counter = 0;
19: $ulClass = $parentId !== null ? 'list-group pt-2' : 'list-group';
20: $html = '<ul class="' . $ulClass . '">';
21: foreach ($folders as $folderId => $folder) {
22: $counter++;
23: $hasChildren = isset($folder['children']) && !empty($folder['children']);
24: $toggleIcon = $hasChildren ? '<i class="bi bi-caret-right"></i>' : '<i class="bi bi-tags"></i>';
25:
26: $html .= '<li class="list-group-item justify-content-between align-items-center">';
27: $html .= '<span>';
28: $html .= '<span data-bs-toggle="collapse" data-bs-target="#collapse-' . $counter . '" aria-expanded="false" aria-controls="collapse-' . $counter . '" role="button">';
29: $html .= $toggleIcon . ' ';
30: $html .= htmlspecialchars($folder['name']);
31: if($hasChildren) {
32: $html .= '<span class="badge rounded-pill text-bg-primary ms-2 px-1">'.count($folder['children']).'</span>';
33: }
34: $html .= '</span>';
35: $html .= '</span>';
36: $html .= '<div class="float-end">';
37: $html .= '<a id="edit_tag" href="?page=tags&tag_id='.$folder['id'].'" class="mr-4"><i class="bi bi-pencil-square"></i></a>';
38: $html .= '<form method="POST" action="?page=tags" style="display:inline;">';
39: $html .= '<input type="hidden" name="tag_delete" value="1">';
40: $html .= '<input type="hidden" name="tag_id" value="'.$folder['id'].'">';
41: $html .= '<input type="hidden" name="hm_page_key" value="'.$request_Key.'" />';
42:
43: $html .= '<button type="submit" id="destroy_tag" class=""><i class="bi bi-trash"></i></button>';
44: $html .= '</form>';
45: $html .= '</div>';
46:
47: if ($hasChildren) {
48: $html .= '<div class="collapse" id="collapse-' . $counter . '">';
49: $html .= generate_tree_view($folder['children'], $request_Key, $counter);
50: $html .= '</div>';
51: }
52: $html .= '</li>';
53: }
54: $html .= '</ul>';
55: return $html;
56: }
57: }
58: