You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

190 lines
5.7 KiB

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