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 // Set hint for Dokuwiki_Started event 29 if (!defined('SITEEXPORT_TPL')) define('SITEEXPORT_TPL', $tempREQUEST['template']); 30 31 // define baseURL 32 // This should be DEPRECATED - as it is in init.php which suggest tpl_basedir and tpl_incdir 33 /* **************************************************************************************** */ 34 if(!defined('DOKU_REL')) define('DOKU_REL',getBaseURL(false)); 35 if(!defined('DOKU_URL')) define('DOKU_URL',getBaseURL(true)); 36 if(!defined('DOKU_BASE')){ 37 if( isset($conf['canonical']) ){ 38 define('DOKU_BASE',DOKU_URL); 39 }else{ 40 define('DOKU_BASE',DOKU_REL); 41 } 42 } 43 44 // This should be DEPRECATED - as it is in init.php which suggest tpl_basedir and tpl_incdir 45 if (!defined('DOKU_TPL')) define('DOKU_TPL', (empty($tempREQUEST['base']) ? DOKU_BASE : $tempREQUEST['base']) . 'lib/tpl/'.$tempREQUEST['template'].'/'); 46 if (!defined('DOKU_TPLINC')) define('DOKU_TPLINC', $tplDir); 47 /* **************************************************************************************** */ 48 } 49 50 function __temporary_disable_plugins() { 51 52 // Check for siteexport - otherwise this does not matter. 53 if ( empty($_REQUEST['do']) || $_REQUEST['do'] != 'siteexport' ) { 54 return; 55 } 56 57 // check for css and js ... only disable in that case. 58 if ( !preg_match("/(js|css)\.php$/", $_SERVER['SCRIPT_NAME']) ) { 59 return; 60 } 61 62 // print "removing plugins "; 63 $_GET['purge'] = 'purge'; //activate purging 64 $_POST['purge'] = 'purge'; //activate purging 65 $_REQUEST['purge'] = 'purge'; //activate purging 66 67 $_SERVER['HTTP_HOST'] = 'siteexport.js'; // fake everything in here 68 69 require_once(DOKU_INC.'inc/plugincontroller.class.php'); // Have to get the pluginutils already 70 require_once(DOKU_INC.'inc/pluginutils.php'); // Have to get the pluginutils already 71 $this->__disablePlugins(); 72 } 73 74 function __disablePlugins() { 75 global $plugin_controller_class, $plugin_controller; 76 $plugin_controller_class = 'preload_plugin_siteexport_controller'; 77 } 78 79 function __create_preload_function() { 80 81 $PRELOADFILE = DOKU_INC.'inc/preload.php'; 82 $CURRENTFILE = 'DOKU_INC' . " . 'lib/plugins/siteexport/preload.php'"; 83 $CONTENT = <<<OUTPUT 84/* SITE EXPORT *********************************************************** */ 85 if ( file_exists($CURRENTFILE) ) { 86 include_once($CURRENTFILE); 87 \$siteexport_preload = new preload_plugin_siteexport(); 88 \$siteexport_preload->__register_template(); 89 \$siteexport_preload->__temporary_disable_plugins(); 90 unset(\$siteexport_preload); 91 } 92/* SITE EXPORT END *********************************************************** */ 93 94OUTPUT; 95 96 if ( file_exists($PRELOADFILE) ) { 97 98 if ( ! is_readable($PRELOADFILE) ) { 99 msg("Preload File locked. It exists, but it can't be read.", -1); 100 return false; 101 } 102 103 if ( !is_writeable($PRELOADFILE) ) { 104 msg("Preload File locked. It exists and is readable, but it can't be written.", -1); 105 return false; 106 } 107 108 $fileContent = file($PRELOADFILE); 109 if ( !strstr(implode("", $fileContent), $CONTENT) ) { 110 111 $fp = fopen($PRELOADFILE, "a"); 112 fputs($fp, "\n".$CONTENT); 113 fclose($fp); 114 } 115 116 return true; 117 118 } else if ( is_writeable(DOKU_INC . 'inc/') ) { 119 120 $fp = fopen($PRELOADFILE,"w"); 121 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"); 122 fputs($fp, $CONTENT); 123 fputs($fp, "// end auto-generated content\n\n"); 124 fclose($fp); 125 126 return true; 127 } 128 129 msg("Could not create/modify preload.php. Please check the write permissions for your DokuWiki/inc directory.", -1); 130 return false; 131 } 132 133} 134 135// return a custom plugin list 136class preload_plugin_siteexport_controller extends Doku_Plugin_Controller { 137 138 /** 139 * Setup disabling 140 */ 141 public function __construct() { 142 parent::__construct(); 143 144 $disabledPlugins = array(); 145 146 // support of old syntax 147 if ( is_array($_REQUEST['diPlu']) ) { 148 $disabledPlugins = $_REQUEST['diPlu']; 149 } 150 151 if ( !empty($_REQUEST['diInv']) ) { 152 // Invert disabled plugins! 153 $disabledPlugins = array_diff(array_keys($this->tmp_plugins), $_REQUEST['diPlu']); 154 } 155 156 // if this is defined, it overrides the settings made above. obviously. 157 $disabledPlugins = empty($_REQUEST['disableplugin']) ? $disabledPlugins : $_REQUEST['disableplugin']; 158 159 foreach( $disabledPlugins as $plugin ) { 160 $this->disable($plugin); 161 } 162 } 163 164 /** 165 * Disable the plugin 166 * 167 * @param string $plugin name of plugin 168 * @return bool; true allways. 169 */ 170 public function disable($plugin) { 171 $this->tmp_plugins[$plugin] = 0; 172 return true; 173 } 174} 175 176 177?>