|
1 | 1 | <?php |
2 | 2 |
|
3 | | -class admin_plugin_move_tree extends DokuWiki_Admin_Plugin { |
4 | | - |
5 | | - const TYPE_PAGES = 1; |
6 | | - const TYPE_MEDIA = 2; |
| 3 | +class admin_plugin_move_tree extends DokuWiki_Admin_Plugin |
| 4 | +{ |
| 5 | + public const TYPE_PAGES = 1; |
| 6 | + public const TYPE_MEDIA = 2; |
7 | 7 |
|
8 | 8 | /** |
9 | 9 | * @param $language |
10 | 10 | * @return bool |
11 | 11 | */ |
12 | | - public function getMenuText($language) { |
| 12 | + public function getMenuText($language) |
| 13 | + { |
13 | 14 | return false; // do not show in Admin menu |
14 | 15 | } |
15 | 16 |
|
16 | | - |
17 | 17 | /** |
18 | 18 | * If this admin plugin is for admins only |
19 | 19 | * |
20 | 20 | * @return bool false |
21 | 21 | */ |
22 | | - function forAdminOnly() { |
| 22 | + public function forAdminOnly() |
| 23 | + { |
23 | 24 | return false; |
24 | 25 | } |
25 | 26 |
|
26 | 27 | /** |
27 | 28 | * no-op |
28 | 29 | */ |
29 | | - public function handle() { |
| 30 | + public function handle() |
| 31 | + { |
30 | 32 | } |
31 | 33 |
|
32 | | - public function html() { |
33 | | - global $ID; |
34 | 34 |
|
| 35 | + public function html() |
| 36 | + { |
| 37 | + global $ID; |
| 38 | + global $INPUT; |
35 | 39 | echo $this->locale_xhtml('tree'); |
36 | 40 |
|
37 | | - echo '<noscript><div class="error">' . $this->getLang('noscript') . '</div></noscript>'; |
38 | | - |
39 | | - echo '<div id="plugin_move__tree">'; |
40 | | - |
41 | | - echo '<div class="tree_root tree_pages">'; |
42 | | - echo '<h3>' . $this->getLang('move_pages') . '</h3>'; |
43 | | - $this->htmlTree(self::TYPE_PAGES); |
44 | | - echo '</div>'; |
45 | | - |
46 | | - echo '<div class="tree_root tree_media">'; |
47 | | - echo '<h3>' . $this->getLang('move_media') . '</h3>'; |
48 | | - $this->htmlTree(self::TYPE_MEDIA); |
49 | | - echo '</div>'; |
| 41 | + $dual = $INPUT->bool('dual', $this->getConf('dual')); |
50 | 42 |
|
51 | 43 | /** @var helper_plugin_move_plan $plan */ |
52 | 44 | $plan = plugin_load('helper', 'move_plan'); |
53 | | - echo '<div class="controls">'; |
54 | | - if($plan->isCommited()) { |
| 45 | + if ($plan->isCommited()) { |
55 | 46 | echo '<div class="error">' . $this->getLang('moveinprogress') . '</div>'; |
56 | 47 | } else { |
57 | | - $form = new Doku_Form(array('action' => wl($ID), 'id' => 'plugin_move__tree_execute')); |
58 | | - $form->addHidden('id', $ID); |
59 | | - $form->addHidden('page', 'move_main'); |
60 | | - $form->addHidden('json', ''); |
61 | | - $form->addElement(form_makeCheckboxField('autoskip', '1', $this->getLang('autoskip'), '', '', ($this->getConf('autoskip') ? array('checked' => 'checked') : array()))); |
62 | | - $form->addElement('<br />'); |
63 | | - $form->addElement(form_makeCheckboxField('autorewrite', '1', $this->getLang('autorewrite'), '', '', ($this->getConf('autorewrite') ? array('checked' => 'checked') : array()))); |
64 | | - $form->addElement('<br />'); |
65 | | - $form->addElement('<br />'); |
66 | | - $form->addElement(form_makeButton('submit', 'admin', $this->getLang('btn_start'))); |
67 | | - $form->printForm(); |
| 48 | + echo '<noscript><div class="error">' . $this->getLang('noscript') . '</div></noscript>'; |
| 49 | + |
| 50 | + echo '<ul class="tabs">'; |
| 51 | + foreach ([1, 0] as $set) { |
| 52 | + echo '<li>'; |
| 53 | + if ($set == $dual) { |
| 54 | + echo '<strong>'; |
| 55 | + echo $this->getLang('dual' . $set); |
| 56 | + echo '</strong>'; |
| 57 | + } else { |
| 58 | + echo '<a href="' . wl($ID, ['do' => 'admin', 'page' => 'move_tree', 'dual' => $set]) . '">'; |
| 59 | + echo $this->getLang('dual' . $set); |
| 60 | + echo '</a>'; |
| 61 | + } |
| 62 | + echo '</li>'; |
| 63 | + } |
| 64 | + echo '</ul>'; |
| 65 | + |
| 66 | + echo '<div id="plugin_move__tree">'; |
| 67 | + echo '<div class="trees">'; |
| 68 | + if ($dual) { |
| 69 | + $this->printTreeRoot('move-pages'); |
| 70 | + $this->printTreeRoot('move-media'); |
| 71 | + } else { |
| 72 | + $this->printTreeRoot('move-pages move-media'); |
| 73 | + } |
| 74 | + echo '</div>'; |
| 75 | + |
| 76 | + |
| 77 | + $form = new dokuwiki\Form\Form(['method' => 'post']); |
| 78 | + $form->setHiddenField('page', 'move_main'); |
| 79 | + |
| 80 | + $cb = $form->addCheckbox('autoskip', $this->getLang('autoskip')); |
| 81 | + if ($this->getConf('autoskip')) $cb->attr('checked', 'checked'); |
| 82 | + |
| 83 | + $cb = $form->addCheckbox('autorewrite', $this->getLang('autorewrite')); |
| 84 | + if ($this->getConf('autorewrite')) $cb->attr('checked', 'checked'); |
| 85 | + |
| 86 | + $form->addButton('submit', $this->getLang('btn_start')); |
| 87 | + echo $form->toHTML(); |
| 88 | + echo '</div>'; |
68 | 89 | } |
69 | | - echo '</div>'; |
70 | | - |
71 | | - echo '</div>'; |
72 | 90 | } |
73 | 91 |
|
74 | 92 | /** |
75 | | - * print the HTML tree structure |
| 93 | + * Print the root of the tree |
76 | 94 | * |
77 | | - * @param int $type |
| 95 | + * @param string $classes The classes to apply to the root |
| 96 | + * @return void |
78 | 97 | */ |
79 | | - protected function htmlTree($type = self::TYPE_PAGES) { |
80 | | - $data = $this->tree($type); |
81 | | - |
82 | | - // wrap a list with the root level around the other namespaces |
83 | | - array_unshift( |
84 | | - $data, array( |
85 | | - 'level' => 0, 'id' => '*', 'type' => 'd', |
86 | | - 'open' => 'true', 'label' => $this->getLang('root') |
87 | | - ) |
88 | | - ); |
89 | | - echo html_buildlist( |
90 | | - $data, 'tree_list idx', |
91 | | - array($this, 'html_list'), |
92 | | - array($this, 'html_li') |
93 | | - ); |
| 98 | + protected function printTreeRoot($classes) { |
| 99 | + echo '<ul>'; |
| 100 | + echo '<li class="'.$classes.' move-ns open tree-root" data-id="" data-orig="" >'; |
| 101 | + echo '<div class="li">'; |
| 102 | + echo '<i class="icon">'; |
| 103 | + echo inlineSVG(DOKU_PLUGIN . 'move/images/folder-home.svg'); |
| 104 | + echo '</i>'; |
| 105 | + echo '<span>:</span>'; |
| 106 | + echo '</div>'; |
| 107 | + echo '<ul class="'.$classes.' move-ns open" data-id="" data-orig=""></ul>'; |
| 108 | + echo '</li>'; |
| 109 | + echo '</ul>'; |
94 | 110 | } |
95 | 111 |
|
96 | 112 | /** |
97 | 113 | * Build a tree info structure from media or page directories |
98 | 114 | * |
99 | | - * @param int $type |
| 115 | + * @param int $type |
100 | 116 | * @param string $open The hierarchy to open FIXME not supported yet |
101 | 117 | * @param string $base The namespace to start from |
102 | 118 | * @return array |
103 | 119 | */ |
104 | | - public function tree($type = self::TYPE_PAGES, $open = '', $base = '') { |
| 120 | + public function tree($type = self::TYPE_PAGES, $open = '', $base = '') |
| 121 | + { |
105 | 122 | global $conf; |
106 | 123 |
|
107 | 124 | $opendir = utf8_encodeFN(str_replace(':', '/', $open)); |
108 | 125 | $basedir = utf8_encodeFN(str_replace(':', '/', $base)); |
109 | 126 |
|
110 | 127 | $opts = array( |
111 | | - 'pagesonly' => ($type == self::TYPE_PAGES), |
112 | | - 'listdirs' => true, |
113 | | - 'listfiles' => true, |
114 | | - 'sneakyacl' => $conf['sneaky_index'], |
115 | | - 'showmsg' => false, |
116 | | - 'depth' => 1, |
| 128 | + 'pagesonly' => ($type == self::TYPE_PAGES), |
| 129 | + 'listdirs' => true, |
| 130 | + 'listfiles' => true, |
| 131 | + 'sneakyacl' => $conf['sneaky_index'], |
| 132 | + 'showmsg' => false, |
| 133 | + 'depth' => 1, |
117 | 134 | 'showhidden' => true |
118 | 135 | ); |
119 | 136 |
|
120 | 137 | $data = array(); |
121 | | - if($type == self::TYPE_PAGES) { |
| 138 | + if ($type == self::TYPE_PAGES) { |
122 | 139 | search($data, $conf['datadir'], 'search_universal', $opts, $basedir); |
123 | | - } elseif($type == self::TYPE_MEDIA) { |
| 140 | + } elseif ($type == self::TYPE_MEDIA) { |
124 | 141 | search($data, $conf['mediadir'], 'search_universal', $opts, $basedir); |
125 | 142 | } |
126 | 143 |
|
127 | 144 | return $data; |
128 | 145 | } |
129 | | - |
130 | | - /** |
131 | | - * Item formatter for the tree view |
132 | | - * |
133 | | - * User function for html_buildlist() |
134 | | - * |
135 | | - * @author Andreas Gohr <[email protected]> |
136 | | - */ |
137 | | - function html_list($item) { |
138 | | - $ret = ''; |
139 | | - // what to display |
140 | | - if(!empty($item['label'])) { |
141 | | - $base = $item['label']; |
142 | | - } else { |
143 | | - $base = ':' . $item['id']; |
144 | | - $base = substr($base, strrpos($base, ':') + 1); |
145 | | - } |
146 | | - |
147 | | - if($item['id'] == '*') $item['id'] = ''; |
148 | | - |
149 | | - if ($item['id']) { |
150 | | - $ret .= '<input type="checkbox" /> '; |
151 | | - } |
152 | | - |
153 | | - // namespace or page? |
154 | | - if($item['type'] == 'd') { |
155 | | - $ret .= '<a href="' . $item['id'] . '" class="idx_dir">'; |
156 | | - $ret .= $base; |
157 | | - $ret .= '</a>'; |
158 | | - } else { |
159 | | - $ret .= '<a class="wikilink1">'; |
160 | | - $ret .= noNS($item['id']); |
161 | | - $ret .= '</a>'; |
162 | | - } |
163 | | - |
164 | | - if($item['id']) $ret .= '<img class="rename" src="'. DOKU_BASE .'lib/plugins/move/images/rename.png" />'; |
165 | | - else $ret .= '<img class="add" src="' . DOKU_BASE . 'lib/plugins/move/images/folder_add.png" />'; |
166 | | - |
167 | | - return $ret; |
168 | | - } |
169 | | - |
170 | | - /** |
171 | | - * print the opening LI for a list item |
172 | | - * |
173 | | - * @param array $item |
174 | | - * @return string |
175 | | - */ |
176 | | - function html_li($item) { |
177 | | - if($item['id'] == '*') $item['id'] = ''; |
178 | | - |
179 | | - $params = array(); |
180 | | - $params['class'] = ' type-' . $item['type']; |
181 | | - if($item['type'] == 'd') $params['class'] .= ' ' . ($item['open'] ? 'open' : 'closed'); |
182 | | - $params['data-name'] = noNS($item['id']); |
183 | | - $params['data-id'] = $item['id']; |
184 | | - $attr = buildAttributes($params); |
185 | | - |
186 | | - return "<li $attr>"; |
187 | | - } |
188 | | - |
189 | 146 | } |
0 commit comments