1<?php 2/** 3 * Siteexport Plugin helper 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author i-net software <tools@inetsoftware.de> 7 * @author Gerry Weissbach <gweissbach@inetsoftware.de> 8 */ 9 10// must be run within Dokuwiki 11if(!defined('DOKU_INC')) die(); 12require_once(DOKU_PLUGIN.'siteexport/preload.php'); 13 14class helper_plugin_siteexport_page_remove { 15 private $start, $end; 16 17 /** 18 * @param integer $start 19 * @param integer $end 20 */ 21 public function __construct($start, $end=null) { 22 $this->start = $start; 23 $this->end = $end; 24 } 25 26 public function _page_remove($elem) { 27 return $elem[2] >= $this->start && ( is_null( $this->end ) || $elem[2] <= $this->end); 28 } 29} 30 31class helper_plugin_siteexport extends DokuWiki_Plugin { 32 33 /* 34 * return all the templates that this wiki has 35 */ 36 public function __getTemplates() { 37 38 // populate $this->_choices with a list of directories 39 $list = array(); 40 41 $_dir = DOKU_INC . 'lib/tpl/'; 42 $_pattern = '/^[\w-]+$/'; 43 if ($dh = @opendir($_dir)) { 44 while (false !== ($entry = readdir($dh))) { 45 if ($entry == '.' || $entry == '..') { 46 continue; 47 } 48 if ($entry == '.' || $entry == '..') { 49 continue; 50 } 51 if ($_pattern && !preg_match($_pattern,$entry)) { 52 continue; 53 } 54 55 $file = (is_link($_dir.$entry)) ? readlink($_dir.$entry) : $entry; 56 if (is_dir($_dir.$file)) { 57 $list[] = $entry; 58 } 59 } 60 closedir($dh); 61 } 62 63 64 sort($list); 65 return $list; 66 } 67 68 /* 69 * Return array list of plugins that exist 70 */ 71 public function __getPluginList() { 72 global $plugin_controller; 73 74 $allPlugins = array(); 75 foreach ($plugin_controller->getList(null, true) as $plugin) { // All plugins 76 // check for CSS or JS 77 if (!file_exists(DOKU_PLUGIN . "$plugin/script.js") && !file_exists(DOKU_PLUGIN . "$plugin/style.css") && !file_exists(DOKU_PLUGIN . "$plugin/print.css")) { continue; } 78 $allPlugins[] = $plugin; 79 } 80 81 return array($allPlugins, $plugin_controller->getList()); 82 } 83 84 public function _page_sort($a, $b) 85 { 86 if ( $a[2] == $b[2] ) { 87 return 0; 88 } 89 90 return $a[2] > $b[2] ? -1 : 1; 91 } 92 93 public function __getOrderedListOfPagesForID($ID, $start=null) 94 { 95 global $conf; 96 require_once(dirname(__FILE__)."/inc/functions.php"); 97 $functions = new siteexport_functions(false); 98 99 $sites = $values = array(); 100 $page = null; 101 search($sites, $conf['datadir'], 'search_allpages', array(), $functions->getNamespaceFromID($ID, $page)); 102 foreach( $sites as $site ) { 103 104 if ( $ID == $site['id'] ) { 105 continue; 106 } 107 $sortIdentifier = intval(p_get_metadata($site['id'], 'mergecompare')); 108 array_push($values, array(':' . $site['id'], $functions->getSiteTitle($site['id']), $sortIdentifier)); 109 } 110 111 if ( $start != null ) { 112 113 // filter using the newerThanPage indicator 114 $sortIdentifier = intval(p_get_metadata($start, 'mergecompare')); 115 $values = array_filter($values, array(new helper_plugin_siteexport_page_remove($sortIdentifier), '_page_remove')); 116 } 117 118 usort($values, array($this, '_page_sort')); 119 120 return $values; 121 } 122 123 public function __getOrderedListOfPagesForStartEnd($ID, $start, $end) 124 { 125 $values = $this->__getOrderedListOfPagesForID($ID); 126 127 // filter using the newerThanPage indicator 128 $values = array_filter($values, array(new helper_plugin_siteexport_page_remove(intval($start), intval($end)), '_page_remove')); 129 130 usort($values, array($this, '_page_sort')); 131 return $values; 132 } 133 134 public function __siteexport_addpage() { 135 136 global $ID, $conf; 137 138 $templateSwitching = false; 139 $pdfExport = false; 140 $translationAvailable = false; 141 $usenumberedheading = true; 142 $trans = array(); 143 144 $preload = plugin_load('preload', 'siteexport'); 145 if ($preload && $preload->__create_preload_function()) { 146 $templateSwitching = true; 147 } 148 149 $dw2pdf = plugin_load('action', 'dw2pdf'); 150 if ($dw2pdf) { 151 $pdfExport = true; 152 } 153 154 $translation = plugin_load('helper', 'autotranslation'); 155 if ($translation) { 156 $translationAvailable = true; 157 $trans = $translation->translations; 158 } 159 160 print $this->locale_xhtml((defined('DOKU_SITEEXPORT_MANAGER') ? 'manager' : '') . 'intro'); 161 162 $form = new Doku_Form('siteexport', null, 'post'); 163 $form->startFieldset($this->getLang('startingNamespace')); 164 165 $form->addElement(form_makeTextField('ns', $ID, $this->getLang('ns') . ':', 'ns')); 166 $form->addElement(form_makeTag('br')); 167 $form->addElement(form_makeTextField('ens', $ID, $this->getLang('ens') . ':', 'ens')); 168 169 $form->addElement(form_makeTag('br')); 170 $form->addElement(form_makeListboxField('depthType', array("0.0" => $this->getLang('depth.pageOnly'), "1.0" => $this->getLang('depth.allSubNameSpaces'), "2.0" => $this->getLang('depth.specifiedDepth')), (empty($_REQUEST['depthType']) ? $this->getLang('depth.allSubNameSpaces') : $_REQUEST['depthType']), $this->getLang('depthType') . ':', 'depthType', null, array_merge(array('class' => 'edit')))); 171 172 $form->addElement(form_makeTag('br')); 173 $form->addElement(form_makeOpenTag("div", array('style' => 'display:' . ($_REQUEST['depthType'] == "2" ? "block" : "none") . ';', 'id' => 'depthContainer'))); 174 $form->addElement(form_makeTextField('depth', $this->getConf('depth'), $this->getLang('depth') . ':', 'depth')); 175 $form->addElement(form_makeCloseTag("div")); 176 177 $form->endFieldset(); 178 $form->addElement(form_makeTag('br')); 179 180 $form->startFieldset($this->getLang('selectYourOptions')); 181 $form->addElement(form_makeCheckboxField('absolutePath', 1, $this->getLang('absolutePath') . ':', 'absolutePath')); 182 $form->addElement(form_makeTag('br')); 183 // The parameter needs lowercase 184 $form->addElement(form_makeCheckboxField('exportbody', 1, $this->getLang('exportBody') . ':', 'exportbody')); 185 $form->addElement(form_makeTag('br')); 186 $form->addElement(form_makeCheckboxField('exportLinkedPages', 1, $this->getLang('exportLinkedPages') . ':', 'exportLinkedPages', 'sendIfNotSet', array('checked' => 'checked'))); 187 $form->addElement(form_makeTag('br')); 188 $form->addElement(form_makeCheckboxField('disableCache', 1, $this->getLang('disableCache') . ':', 'disableCache')); 189 $form->addElement(form_makeTag('br')); 190 $form->addElement(form_makeCheckboxField('addParams', 1, $this->getLang('addParams') . ':', 'addParams', null, array_merge(array('checked' => ($conf['userewrite'] != 1 ? 'checked' : ''))))); 191 $form->addElement(form_makeTag('br')); 192 $form->addElement(form_makeTag('br')); 193 $form->addElement(form_makeListboxField('renderer', array_merge(array('', 'xhtml'), plugin_list('renderer')), '', $this->getLang('renderer') . ':', 'renderer', null, array_merge(array('class' => 'edit')))); 194 195 $form->addElement(form_makeTag('br')); 196 if ($templateSwitching) { 197 $form->addElement(form_makeListboxField('template', $this->__getTemplates(), $conf['template'], $this->getLang('template') . ':', 'template', null, array_merge(array('class' => 'edit')))); 198 $form->addElement(form_makeTag('br')); 199 } else 200 { 201 $form->addElement(form_makeTag('br')); 202 $form->addElement(form_makeOpenTag('p', array('style' => 'color: #a00;'))); 203 $form->addElement('Can\'t create preload file in \'inc\' directory. Template switching is not available. Plugin disabling is not available.'); 204 $form->addElement(form_makeCloseTag('p')); 205 } 206 207 $form->addElement(form_makeTag('br')); 208 $form->addElement(form_makeCheckboxField('pdfExport', 1, $this->getLang('pdfExport') . ':', 'pdfExport', null, $pdfExport ? array() : array_merge(array('disabled' => 'disabled')))); 209 210 // Hint for dw2pdf 211 $this->addPluginHint( $form, $pdfExport, "the PDF export", "dw2pdf" ); 212 213 $form->addElement(form_makeTag('br')); 214 $form->addElement(form_makeCheckboxField('usenumberedheading', 1, $this->getLang('usenumberedheading') . ':', 'usenumberedheading', null, $usenumberedheading && $pdfExport ? array() : array_merge(array('disabled' => 'disabled')))); 215 $form->addElement(form_makeTag('br')); 216 217 // Hint for nodetailsxhtml 218 $this->addPluginHint( $form, $usenumberedheading, "numbered headings", "nodetailsxhtml" ); 219 220 $form->endFieldset(); 221 $form->addElement(form_makeTag('br')); 222 223 $form->startFieldset($this->getLang('helpCreationOptions')); 224 $form->addElement(form_makeCheckboxField('eclipseDocZip', 1, $this->getLang('eclipseDocZip') . ':', 'eclipseDocZip')); 225 $form->addElement(form_makeTag('br')); 226 $form->addElement(form_makeCheckboxField('JavaHelpDocZip', 1, $this->getLang('JavaHelpDocZip') . ':', 'JavaHelpDocZip')); 227 $form->addElement(form_makeTag('br')); 228 $form->addElement(form_makeCheckboxField('useTocFile', 1, $this->getLang('useTocFile') . ':', 'useTocFile')); 229 $form->addElement(form_makeTag('br')); 230 $form->addElement(form_makeCheckboxField('emptyTocElem', 1, $this->getLang('emptyTocElem') . ':', 'emptyTocElem')); 231 $form->addElement(form_makeTag('br')); 232 if (!$translationAvailable) { 233 $form->addElement(form_makeCheckboxField('TOCMapWithoutTranslation', 1, $this->getLang('TOCMapWithoutTranslation') . ':', 'TOCMapWithoutTranslation')); 234 $form->addElement(form_makeTag('br')); 235 } else { 236 237 if (!is_array($trans)) { 238 $trans = array($trans); 239 } 240 241 $trans = array_unique(array_merge($trans, array($conf['lang']))); 242 $form->addElement(form_makeListboxField('defaultLang', $trans, $conf['lang'], $this->getLang('defaultLang') . ':', 'defaultLang')); 243 $form->addElement(form_makeTag('br')); 244 } 245 $form->endFieldset(); 246 $form->addElement(form_makeTag('br')); 247 248 if ($templateSwitching) 249 { 250 $form->startFieldset($this->getLang('disablePluginsOption')); 251 252 $form->addElement(form_makeCheckboxField("disableall", 1, 'Disable All:', "disableall", 'forceVisible')); 253 $form->addElement(form_makeTag('br')); 254 $form->addElement(form_makeTag('br')); 255 256 list($allPlugins, $enabledPlugins) = $this->__getPluginList(); 257 foreach ($allPlugins as $plugin) { 258 $form->addElement(form_makeCheckboxField("disableplugin[]", $plugin, $plugin . ':', "disableplugin_$plugin", null, (!in_array($plugin, $enabledPlugins) ? array('checked' => 'checked', 'disabled' => 'disabled') : array()))); 259 $form->addElement(form_makeTag('br')); 260 } 261 262 $form->endFieldset(); 263 $form->addElement(form_makeTag('br')); 264 } 265 266 $form->startFieldset( $this->getLang('customOptions') ); 267 $form->addElement(form_makeOpenTag('p')); 268 $form->addElement( $this->getLang('customOptionsDescription') ); 269 $form->addElement(form_makeCloseTag('p')); 270 271 $form->addElement(form_makeOpenTag('ul', array('id' => 'siteexport__customActions'))); 272 $form->addElement(form_makeCloseTag('ul')); 273 $form->addElement(form_makeTag('br', array('class'=>'clear'))); 274 $form->addElement(form_makeButton('submit', 'addoption', $this->getLang('addCustomOption') , array('style' => 'float:right;') )); 275 276 $form->endFieldset(); 277 $form->addElement(form_makeTag('br')); 278 279 if ( !defined('DOKU_SITEEXPORT_MANAGER') ) { 280 281 282 $form->startFieldset( $this->getLang('startProcess') ); 283 $form->addElement(form_makeTextField('copyurl', "", $this->getLang('directDownloadLink') . ':', 'copyurl', null, array('readonly' => 'readonly') )); 284 $form->addElement(form_makeTag('br')); 285 $form->addElement(form_makeTextField('wgeturl', "", $this->getLang('wgetURLLink') . ':', 'wgeturl', null, array('readonly' => 'readonly') )); 286 $form->addElement(form_makeTag('br')); 287 $form->addElement(form_makeTextField('curlurl', "", $this->getLang('curlURLLink') . ':', 'curlurl', null, array('readonly' => 'readonly') )); 288 $form->addElement(form_makeTag('br', array('class'=>'clear'))); 289 $form->addElement(form_makeButton('submit', 'siteexport', $this->getLang('start') , array('style' => 'float:right;'))); 290 $form->endFieldset(); 291 $form->addElement(form_makeTag('br')); 292 293 $form->endFieldset(); 294 $form->addElement(form_makeTag('br')); 295 296 $form->startFieldset( $this->getLang('status') ); 297 $form->addElement(form_makeOpenTag('span', array('id' => 'siteexport__out'))); 298 299 $form->addElement(form_makeCloseTag('span')); 300 $form->addElement(form_makeOpenTag('span', array('class' => 'siteexport__throbber'))); 301 302 $throbber = DOKU_BASE.'lib/images/loading.gif'; 303 if ( !file_exists( $throbber) ) { 304 $throbber = DOKU_BASE.'lib/images/throbber.gif'; 305 } 306 307 $form->addElement(form_makeTag('img', array('src' => $throbber, 'id' => 'siteexport__throbber'))); 308 $form->addElement(form_makeCloseTag('span')); 309 $form->endFieldset(); 310 $form->addElement(form_makeTag('br')); 311 312 } else { 313 $form->startFieldset( $this->getLang('startProcess') ); 314 $form->addElement(form_makeButton('submit', 'siteexport', $this->getLang('useOptionsInEditor') , array('style' => 'width:100%;'))); 315 } 316 317 $form->endFieldset(); 318 $form->addElement(form_makeTag('br')); 319 320 $form->printForm(); 321 } 322 323 private function addPluginHint( &$form, $condition, $hint, $plugin ) { 324 if ($condition) { return; } 325 326 $form->addElement(form_makeOpenTag('p', array('style' => 'color: #a00;'))); 327 $form->addElement('In order to use ' . $hint . ', please '); 328 $form->addElement(form_makeOpenTag('a', array('href' => 'http://www.dokuwiki.org/plugin:' . $plugin, 'alt' => 'install plugin', 'target' => '_blank'))); 329 $form->addElement('install the ' . $plugin . ' plugin.'); 330 $form->addElement(form_makeCloseTag('a')); 331 $form->addElement(form_makeCloseTag('p')); 332 } 333 334} 335