1<?php 2if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../../').'/'); 3 4@include_once(DOKU_INC . 'inc/plugincontroller.class.php'); 5 6class preload_plugin_siteexport { 7 8 function __register_template() { 9 10 if ( !empty($_REQUEST['q']) ) { 11 12 require_once( DOKU_INC . 'inc/JSON.php'); 13 $json = new JSON(); 14 $tempREQUEST = (array)$json->dec(stripslashes($_REQUEST['q'])); 15 16 } else if ( !empty( $_REQUEST['template'] ) ) { 17 $tempREQUEST = $_REQUEST; 18 } else { 19 return; 20 } 21 22 // define Template baseURL 23 if ( empty($tempREQUEST['template']) ) { return; } 24 $tplDir = DOKU_INC.'lib/tpl/'.$tempREQUEST['template'].'/'; 25 26 if ( !file_exists($tplDir) ) { return; } 27 28 if (!defined('SITEEXPORT_TPL')) define('SITEEXPORT_TPL', $tempREQUEST['template']); 29 if (!defined('DOKU_TPL')) define('DOKU_TPL', (empty($tempREQUEST['base']) ? '/' : $tempREQUEST['base']) . 'lib/tpl/'.$tempREQUEST['template'].'/'); 30 if (!defined('DOKU_TPLINC')) define('DOKU_TPLINC', $tplDir); 31 } 32 33 function __temporary_disable_plugins() { 34 35 // Check for siteexport - otherwise this does not matter. 36 if ( empty($_REQUEST['do']) || $_REQUEST['do'] != 'siteexport' ) { 37 return; 38 } 39 40 // check for css and js as well ... 41 if ( !preg_match("/(js|css)\.php$/", $_SERVER['SCRIPT_NAME']) ) { 42 return; 43 } 44 45 // print "removing plugins "; 46 $_GET['purge'] = 'purge'; //activate purging 47 $_POST['purge'] = 'purge'; //activate purging 48 $_REQUEST['purge'] = 'purge'; //activate purging 49 50 $_SERVER['HTTP_HOST'] = 'siteexport.js'; // fake everything in here 51 52 require_once(DOKU_INC.'inc/plugincontroller.class.php'); // Have to get the pluginutils already 53 require_once(DOKU_INC.'inc/pluginutils.php'); // Have to get the pluginutils already 54 $this->__disablePlugins(); 55 } 56 57 function __disablePlugins() { 58 global $plugin_controller_class, $plugin_controller; 59 60 $plugin_controller_class = 'preload_plugin_siteexport_controller'; 61 } 62 63 function __create_preload_function() { 64 65 $PRELOADFILE = DOKU_INC.'inc/preload.php'; 66 $CURRENTFILE = 'DOKU_INC' . " . 'lib/plugins/siteexport/preload.php'"; 67 $CONTENT = <<<OUTPUT 68/* SITE EXPORT *********************************************************** */ 69 if ( file_exists($CURRENTFILE) ) { 70 include_once($CURRENTFILE); 71 \$siteexport_preload = new preload_plugin_siteexport(); 72 \$siteexport_preload->__register_template(); 73 \$siteexport_preload->__temporary_disable_plugins(); 74 unset(\$siteexport_preload); 75 } 76/* SITE EXPORT END *********************************************************** */ 77 78OUTPUT; 79 80 if ( file_exists($PRELOADFILE) ) { 81 82 if ( ! is_readable($PRELOADFILE) ) { 83 msg("Preload File locked. It exists, but it can't be read.", -1); 84 return false; 85 } 86 87 if ( !is_writeable($PRELOADFILE) ) { 88 msg("Preload File locked. It exists and is readable, but it can't be written.", -1); 89 return false; 90 } 91 92 $fileContent = file($PRELOADFILE); 93 if ( !strstr(implode("", $fileContent), $CONTENT) ) { 94 95 $fp = fopen($PRELOADFILE, "a"); 96 fputs($fp, "\n".$CONTENT); 97 fclose($fp); 98 } 99 100 return true; 101 102 } else if ( is_writeable(DOKU_INC . 'inc/') ) { 103 104 $fp = fopen($PRELOADFILE,"w"); 105 fputs($fp, "<?php\n/*\n * Dokuwiki Preload File\n * Auto-generated by Site Export plugin \n * Date: ".date('Y-m-d H:s:i')."\n */\n"); 106 fputs($fp, $CONTENT); 107 fputs($fp, "// end auto-generated content\n\n"); 108 fclose($fp); 109 110 return true; 111 } 112 113 msg("Could not create/modify preload.php. Please check the write permissions for your DokuWiki/inc directory.", -1); 114 return false; 115 } 116 117} 118 119// return a custom plugin list 120class preload_plugin_siteexport_controller extends Doku_Plugin_Controller { 121 122 function getList($type='',$all=false){ 123 124 $allPlugin = parent::getList(null, true); 125 $oldPluginsEnabled = parent::getList(null, false); 126 $currentPluginsDisabled = empty($_REQUEST['diPlu']) ? array() : $_REQUEST['diPlu']; 127 $pluginsDisabledInverse = !empty($_REQUEST['diInv']); 128 129 // All plugins that are not already disabled are to be disabled 130 $toDisable = !$pluginsDisabledInverse ? array_diff($currentPluginsDisabled, array_diff($allPlugin, $oldPluginsEnabled)) : array_diff(array_diff($allPlugin, $currentPluginsDisabled), array_diff($allPlugin, $oldPluginsEnabled)); 131 132 foreach ( $toDisable as $plugin ) { 133 if ( !in_array($plugin, $allPlugin) ) { continue; } 134 $this->list_enabled = array_diff($this->list_enabled, array($plugin)); 135 $this->list_disabled[] = $plugin; 136 } 137 138 foreach($this->list_enabled as $plugin ) { 139 // check for CSS or JS 140 if ( !file_exists(DOKU_PLUGIN."$plugin/script.js") && !file_exists(DOKU_PLUGIN."$plugin/style.css") ) { 141 unset($this->list_enabled[$plugin]); 142 $this->list_disabled[] = $plugin; 143 } 144 } 145 146 return parent::getList($type='',$all=false); 147 } 148} 149 150 151?>