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