1<?php 2 3class admin_plugin_move_tree extends DokuWiki_Admin_Plugin 4{ 5 public const TYPE_PAGES = 1; 6 public const TYPE_MEDIA = 2; 7 8 /** 9 * @param $language 10 * @return bool 11 */ 12 public function getMenuText($language) 13 { 14 return false; // do not show in Admin menu 15 } 16 17 /** 18 * If this admin plugin is for admins only 19 * 20 * @return bool false 21 */ 22 public function forAdminOnly() 23 { 24 return false; 25 } 26 27 /** 28 * no-op 29 */ 30 public function handle() 31 { 32 } 33 34 35 public function html() 36 { 37 global $ID; 38 global $INPUT; 39 echo $this->locale_xhtml('tree'); 40 41 $dual = $INPUT->bool('dual', $this->getConf('dual')); 42 43 /** @var helper_plugin_move_plan $plan */ 44 $plan = plugin_load('helper', 'move_plan'); 45 if ($plan->isCommited()) { 46 echo '<div class="error">' . $this->getLang('moveinprogress') . '</div>'; 47 } else { 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>'; 89 } 90 } 91 92 /** 93 * Print the root of the tree 94 * 95 * @param string $classes The classes to apply to the root 96 * @return void 97 */ 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>'; 110 } 111 112 /** 113 * Build a tree info structure from media or page directories 114 * 115 * @param int $type 116 * @param string $open The hierarchy to open FIXME not supported yet 117 * @param string $base The namespace to start from 118 * @return array 119 */ 120 public function tree($type = self::TYPE_PAGES, $open = '', $base = '') 121 { 122 global $conf; 123 124 $opendir = utf8_encodeFN(str_replace(':', '/', $open)); 125 $basedir = utf8_encodeFN(str_replace(':', '/', $base)); 126 127 $opts = array( 128 'pagesonly' => ($type == self::TYPE_PAGES), 129 'listdirs' => true, 130 'listfiles' => true, 131 'sneakyacl' => $conf['sneaky_index'], 132 'showmsg' => false, 133 'depth' => 1, 134 'showhidden' => true 135 ); 136 137 $data = array(); 138 if ($type == self::TYPE_PAGES) { 139 search($data, $conf['datadir'], 'search_universal', $opts, $basedir); 140 } elseif ($type == self::TYPE_MEDIA) { 141 search($data, $conf['mediadir'], 'search_universal', $opts, $basedir); 142 } 143 144 return $data; 145 } 146} 147