__disablePlugins(); } private function __disablePlugins() { global $plugin_controller_class; $plugin_controller_class = 'preload_plugin_siteexport_controller'; } public function __create_preload_function() { $PRELOADFILE = DOKU_INC . 'inc/preload.php'; $CURRENTFILE = 'DOKU_INC' . " . 'lib/plugins/siteexport/preload.php'"; $CONTENT = <<__register_template(); \$siteexport_preload->__temporary_disable_plugins(); unset(\$siteexport_preload); } /* SITE EXPORT END *********************************************************** */ OUTPUT; if (file_exists($PRELOADFILE)) { if (!is_readable($PRELOADFILE)) { $this->error = "Preload File locked. It exists, but it can't be read."; msg($this->error, -1); return false; } if (!is_writeable($PRELOADFILE)) { $this->error = "Preload File locked. It exists and is readable, but it can't be written."; msg($this->error, -1); return false; } $fileContent = file($PRELOADFILE); if (!strstr(implode("", $fileContent ?: array()), $CONTENT)) { $fp = fopen($PRELOADFILE, "a"); if ( !$fp ) { return false; } if (!strstr(implode("", $fileContent), "error = "Could not create/modify preload.php. Please check the write permissions for your DokuWiki/inc directory."; msg($this->error, -1); return false; } } // return a custom plugin list class preload_plugin_siteexport_controller extends _preload_plugin_siteexport_controller { protected $tmp_plugins = array(); /** * Setup disabling */ public function __construct() { parent::__construct(); $disabledPlugins = array(); // support of old syntax if (is_array($_REQUEST['diPlu'] ?? null)) { $disabledPlugins = $_REQUEST['diPlu']; } if (!empty($_REQUEST['diInv'])) { $allPlugins = array(); foreach ($this->tmp_plugins as $plugin => $enabled) { // All plugins // check for CSS or JS if ($enabled == 1 && !file_exists(DOKU_PLUGIN . "$plugin/script.js") && !file_exists(DOKU_PLUGIN . "$plugin/style.css") && !file_exists(DOKU_PLUGIN . "$plugin/print.css")) { continue; } $allPlugins[] = $plugin; } $disabledPlugins = empty($_REQUEST['diPlu']) ? $allPlugins : array_diff($allPlugins, $_REQUEST['diPlu']); } // if this is defined, it overrides the settings made above. obviously. $disabledPlugins = empty($_REQUEST['disableplugin']) ? $disabledPlugins : $_REQUEST['disableplugin']; foreach ($disabledPlugins as $plugin) { $this->disable($plugin); } // always enabled - JS and CSS will be cut out later. $this->enable('siteexport'); } /** * Disable the plugin * * @param string $plugin name of plugin * @return bool; true allways. */ public function disable($plugin) { $this->tmp_plugins[$plugin] = 0; return true; } /** * Enable the plugin * * @param string $plugin name of plugin * @return bool; true allways. */ public function enable($plugin) { $this->tmp_plugins[$plugin] = 1; return true; } public function hasSiteexportHeaders() { $headers = function_exists('getallheaders') ? getallheaders() : null; return is_array($headers) && array_key_exists('X-Site-Exporter', $headers) /* && $headers['X-Site-Exporter'] = getSecurityToken() */; } /** * Filter the List of Plugins for the siteexport plugin */ private function isSiteexportPlugin($item) { return $item != 'siteexport'; } /** * Get the list of plugins, bute remove Siteexport from Style and * JS if in export Mode */ public function getList($type = '', $all = false) { $plugins = parent::getList($type, $all); list(,, $caller) = debug_backtrace(); if ($this->hasSiteexportHeaders() && $caller != null && preg_match("/^(js|css)_/", $caller['function']) && preg_match("/(js|css)\.php$/", $caller['file'])) { $plugins = array_filter($plugins, array($this, 'isSiteexportPlugin')); } return $plugins; } }