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