17d101cc1SGerry Weißbach<?php 27d101cc1SGerry Weißbach/** 37d101cc1SGerry Weißbach * Site Export Plugin 47d101cc1SGerry Weißbach * 57d101cc1SGerry Weißbach * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 67d101cc1SGerry Weißbach * @author i-net software <tools@inetsoftware.de> 77d101cc1SGerry Weißbach * @author Gerry Weissbach <gweissbach@inetsoftware.de> 87d101cc1SGerry Weißbach */ 97d101cc1SGerry Weißbach 107d101cc1SGerry Weißbach// must be run within Dokuwiki 117d101cc1SGerry Weißbachif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../../').'/'); 127d101cc1SGerry Weißbachif(!defined('DOKU_PLUGIN')) { 137d101cc1SGerry Weißbach // Just for sanity 147d101cc1SGerry Weißbach require_once(DOKU_INC.'inc/plugin.php'); 157d101cc1SGerry Weißbach define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 167d101cc1SGerry Weißbach} 177d101cc1SGerry Weißbach 187d101cc1SGerry Weißbachrequire_once(DOKU_PLUGIN.'action.php'); 197d101cc1SGerry Weißbachrequire_once(DOKU_INC.'/inc/search.php'); 207d101cc1SGerry Weißbach 217d101cc1SGerry Weißbachrequire_once(DOKU_PLUGIN.'siteexport/inc/functions.php'); 227d101cc1SGerry Weißbachrequire_once(DOKU_PLUGIN.'siteexport/inc/httpproxy.php'); 237d101cc1SGerry Weißbachrequire_once(DOKU_PLUGIN.'siteexport/inc/filewriter.php'); 247d101cc1SGerry Weißbachrequire_once(DOKU_PLUGIN.'siteexport/inc/toc.php'); 257d101cc1SGerry Weißbachrequire_once(DOKU_PLUGIN.'siteexport/inc/javahelp.php'); 267d101cc1SGerry Weißbach 277d101cc1SGerry Weißbachclass action_plugin_siteexport_ajax extends DokuWiki_Action_Plugin 287d101cc1SGerry Weißbach{ 297d101cc1SGerry Weißbach /** 307d101cc1SGerry Weißbach * New internal variables for better structure 317d101cc1SGerry Weißbach */ 327d101cc1SGerry Weißbach private $filewriter = null; 337d101cc1SGerry Weißbach public $functions = null; 347d101cc1SGerry Weißbach 357d101cc1SGerry Weißbach // List of files that have already been checked 367d101cc1SGerry Weißbach private $fileChecked = array(); 377d101cc1SGerry Weißbach 387d101cc1SGerry Weißbach // Namespace of the page to export 397d101cc1SGerry Weißbach private $namespace = ''; 407d101cc1SGerry Weißbach 417d101cc1SGerry Weißbach /** 427d101cc1SGerry Weißbach * Register Plugin in DW 437d101cc1SGerry Weißbach **/ 447d101cc1SGerry Weißbach function register(&$controller) { 457d101cc1SGerry Weißbach $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax_siteexport_provider'); 467d101cc1SGerry Weißbach $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'siteexport_action'); 477d101cc1SGerry Weißbach } 487d101cc1SGerry Weißbach 497d101cc1SGerry Weißbach /** 507d101cc1SGerry Weißbach * AJAX Provider - check what is going to be done 517d101cc1SGerry Weißbach * @param $event 527d101cc1SGerry Weißbach * @param $args 537d101cc1SGerry Weißbach */ 547d101cc1SGerry Weißbach function ajax_siteexport_provider(&$event, $args) { 557d101cc1SGerry Weißbach 567d101cc1SGerry Weißbach // If this is not a siteexport call, ignore it. 577d101cc1SGerry Weißbach if ( !strstr($event->data, '__siteexport' ) ) 587d101cc1SGerry Weißbach { 597d101cc1SGerry Weißbach return; 607d101cc1SGerry Weißbach } 617d101cc1SGerry Weißbach 622270cdc5SGerry Weißbach $this->__init_functions(true); 637d101cc1SGerry Weißbach 647d101cc1SGerry Weißbach switch( $event->data ) { 657d101cc1SGerry Weißbach case '__siteexport_getsitelist': $this->ajax_siteexport_getsitelist( $event ); break; 667d101cc1SGerry Weißbach case '__siteexport_addsite': $this->ajax_siteexport_addsite( $event ); break; 677d101cc1SGerry Weißbach case '__siteexport_generateurl': $this->ajax_siteexport_generateurl( $event ); break; 686792d0cfSGerry Weißbach case '__siteexport_aggregate': $this->ajax_siteexport_aggregate( $event ); break; 697d101cc1SGerry Weißbach } 707d101cc1SGerry Weißbach } 717d101cc1SGerry Weißbach 727d101cc1SGerry Weißbach /** 737d101cc1SGerry Weißbach * Export from a URL - action 747d101cc1SGerry Weißbach * @param $event 757d101cc1SGerry Weißbach */ 767d101cc1SGerry Weißbach function siteexport_action( &$event ) { 777d101cc1SGerry Weißbach global $ID; 787d101cc1SGerry Weißbach 797d101cc1SGerry Weißbach // Check if the 'do' was siteexport 807793901eSGerry Weißbach $command = is_array($event->data) ? array_shift(array_keys($event->data)) : $event->data; 81fd385364SGerry Weißbach if ( $command != 'siteexport' ) { return false; } 82fd385364SGerry Weißbach $event->data = act_clean($event->data); 83fd385364SGerry Weißbach 847d101cc1SGerry Weißbach if ( headers_sent() ) { 857d101cc1SGerry Weißbach msg("The siteexport function has to be called prior to any header output.", -1); 867d101cc1SGerry Weißbach } 877d101cc1SGerry Weißbach 887d101cc1SGerry Weißbach $this->__init_functions(); 897d101cc1SGerry Weißbach 907d101cc1SGerry Weißbach $this->functions->debug->message("========================================", null, 1); 917d101cc1SGerry Weißbach $this->functions->debug->message("Starting export from URL call", null, 1); 928da901a0SGerry Weißbach $this->functions->debug->message("----------------------------------------", null, 1); 937d101cc1SGerry Weißbach 947d101cc1SGerry Weißbach $event->preventDefault(); 957d101cc1SGerry Weißbach $event->stopPropagation(); 967d101cc1SGerry Weißbach 977d101cc1SGerry Weißbach // Fake security Token if none given 987d101cc1SGerry Weißbach if ( empty( $_REQUEST['sectok'] ) ) { 997d101cc1SGerry Weißbach $_REQUEST['sectok'] = getSecurityToken(); 1007d101cc1SGerry Weißbach } 1017d101cc1SGerry Weißbach 1027d101cc1SGerry Weißbach // The timer will be used to do redirects if needed to prevent timeouts 1037d101cc1SGerry Weißbach $starttimer = time(); 1047d101cc1SGerry Weißbach $timerdiff = $this->getConf('max_execution_time'); 1057d101cc1SGerry Weißbach 1067d101cc1SGerry Weißbach $data = $this->__get_siteexport_list_and_init_tocs($ID, !empty($_REQUEST['startcounter'])); 1077d101cc1SGerry Weißbach 1087d101cc1SGerry Weißbach if ( $data === false ) { 1097d101cc1SGerry Weißbach header("HTTP/1.0 401 Unauthorized"); 1107d101cc1SGerry Weißbach print 'Unauthorized'; 1117d101cc1SGerry Weißbach exit; 1127d101cc1SGerry Weißbach } 1137d101cc1SGerry Weißbach 1147d101cc1SGerry Weißbach $counter = 0; 1157d101cc1SGerry Weißbach 1167d101cc1SGerry Weißbach if ( count($data) == 0 && !$this->functions->settings->hasValidCacheFile ) { 1177d101cc1SGerry Weißbach exit(); 1187d101cc1SGerry Weißbach } 1197d101cc1SGerry Weißbach 1207d101cc1SGerry Weißbach foreach ( $data as $site ) { 1217d101cc1SGerry Weißbach 1227d101cc1SGerry Weißbach if ( intval($site['exists']) == 1 || !isset($site['exists']) ) { 1237d101cc1SGerry Weißbach 1247d101cc1SGerry Weißbach // Skip over the amount of urls that have been exported already 1257d101cc1SGerry Weißbach if ( empty($_REQUEST['startcounter']) || $counter >= intval($_REQUEST['startcounter']) ) { 1267d101cc1SGerry Weißbach $status = $this->__siteexport_add_site($site['id']); 1278da901a0SGerry Weißbach 1288da901a0SGerry Weißbach if ( $status === false ) { 1298da901a0SGerry Weißbach $this->functions->debug->message("----------------------------------------", null, 1); 1308da901a0SGerry Weißbach $this->functions->debug->message("Errors during export from URL call", null, 1); 1318da901a0SGerry Weißbach $this->functions->debug->message("========================================", null, 1); 1328da901a0SGerry Weißbach print $this->functions->debug->runtimeErrors; 1338da901a0SGerry Weißbach exit(0); // We need to stop 1348da901a0SGerry Weißbach } 1357d101cc1SGerry Weißbach } 1367d101cc1SGerry Weißbach } 1377d101cc1SGerry Weißbach 1387d101cc1SGerry Weißbach $counter ++; 1397d101cc1SGerry Weißbach if ( time() - $starttimer >= $timerdiff ) { 1407d101cc1SGerry Weißbach $this->functions->debug->message("Will Redirect", null, 1); 1417d101cc1SGerry Weißbach $this->handleRuntimeErrorOutput(); 1427d101cc1SGerry Weißbach $this->functions->startRedirctProcess($counter); 1437d101cc1SGerry Weißbach } 1447d101cc1SGerry Weißbach } 1457d101cc1SGerry Weißbach 1468da901a0SGerry Weißbach $this->functions->debug->message("----------------------------------------", null, 1); 1477d101cc1SGerry Weißbach $this->functions->debug->message("Finishing export from URL call", null, 1); 1487d101cc1SGerry Weißbach $this->functions->debug->message("========================================", null, 1); 1497d101cc1SGerry Weißbach 1507d101cc1SGerry Weißbach $this->cleanCacheFiles(); 1517d101cc1SGerry Weißbach 1527d101cc1SGerry Weißbach $URL = ml($this->functions->settings->origZipFile, array('cache' => 'nocache', 'siteexport' => $this->functions->settings->pattern, 'sectok' => getSecurityToken()), true, '&'); 1537d101cc1SGerry Weißbach $this->functions->debug->message("Redirecting to final file", $URL, 2); 1547d101cc1SGerry Weißbach 1557d101cc1SGerry Weißbach $this->handleRuntimeErrorOutput(); 1567d101cc1SGerry Weißbach send_redirect($URL); 1577d101cc1SGerry Weißbach exit(0); // Should not be reached, but anyways 1587d101cc1SGerry Weißbach } 1597d101cc1SGerry Weißbach 1607d101cc1SGerry Weißbach private function handleRuntimeErrorOutput() 1617d101cc1SGerry Weißbach { 1627d101cc1SGerry Weißbach if ( !empty($this->functions->debug->runtimeErrors) ) 1637d101cc1SGerry Weißbach { 1647d101cc1SGerry Weißbach $this->filewriter->__moveDataToZip($this->functions->debug->runtimeErrors, '_runtime_error/' . time() . '.html'); 1657d101cc1SGerry Weißbach } 1667d101cc1SGerry Weißbach } 1677d101cc1SGerry Weißbach 1682270cdc5SGerry Weißbach public function __init_functions($isAJAX=false) 1697d101cc1SGerry Weißbach { 1702270cdc5SGerry Weißbach $this->functions = new siteexport_functions(true, $isAJAX); 1717d101cc1SGerry Weißbach $this->filewriter = new siteexport_zipfilewriter($this->functions); 1727d101cc1SGerry Weißbach 1737d101cc1SGerry Weißbach // Check for PDF Capabilities 1747d101cc1SGerry Weißbach if ( $this->filewriter->canDoPDF() ) { 1757d101cc1SGerry Weißbach $this->functions->settings->fileType = 'pdf'; 1767d101cc1SGerry Weißbach } 1777d101cc1SGerry Weißbach } 1787d101cc1SGerry Weißbach 1797d101cc1SGerry Weißbach /** 1807d101cc1SGerry Weißbach * Prepares the generated URL for direct download access 1817d101cc1SGerry Weißbach * Also gives back the parameters for this URL 1827d101cc1SGerry Weißbach * @param $event init event of the ajax request 1837d101cc1SGerry Weißbach */ 1847d101cc1SGerry Weißbach function ajax_siteexport_prepareURL_and_POSTData( &$event ) { 1857d101cc1SGerry Weißbach 1867d101cc1SGerry Weißbach $event->preventDefault(); 1877d101cc1SGerry Weißbach $event->stopPropagation(); 1887d101cc1SGerry Weißbach 1897d101cc1SGerry Weißbach // Retrieve Information for download URL 190a609ae53SGerry Weißbach $this->functions->debug->message("Prepared URL and POST from Request:", $_REQUEST, 2); 1917d101cc1SGerry Weißbach $url = $this->functions->prepare_POSTData($_REQUEST); 1927d101cc1SGerry Weißbach $combined = $this->functions->urlToPathAndParams($url); 1937d101cc1SGerry Weißbach list($path, $query) = explode('?', $combined, 2); 1947d101cc1SGerry Weißbach $return = array($url, $combined, $path, $query); 1957d101cc1SGerry Weißbach 1967d101cc1SGerry Weißbach $this->functions->debug->message("Prepared URL and POST data:", $return, 2); 1977d101cc1SGerry Weißbach return $return; 1987d101cc1SGerry Weißbach } 1997d101cc1SGerry Weißbach 2007d101cc1SGerry Weißbach /** 2017d101cc1SGerry Weißbach * Executes a Cron Job Action 2027d101cc1SGerry Weißbach * @param $event 2037d101cc1SGerry Weißbach */ 2047d101cc1SGerry Weißbach function ajax_siteexport_cronaction( &$event ) 2057d101cc1SGerry Weißbach { 2067d101cc1SGerry Weißbach $cronOverwriteExisting = intval($_REQUEST['cronOverwriteExisting']) == 1; 2077d101cc1SGerry Weißbach list($url, $combined) = $this->ajax_siteexport_prepareURL_and_POSTData($event); 2087d101cc1SGerry Weißbach 2097d101cc1SGerry Weißbach if ( !$function =& plugin_load('cron', 'siteexport' ) ) 2107d101cc1SGerry Weißbach { 2117d101cc1SGerry Weißbach $this->functions->debug->message("Tried to do an action with siteexport/cron, but the cron plugin is missing.", null, 4); 2127d101cc1SGerry Weißbach } 2137d101cc1SGerry Weißbach 2147d101cc1SGerry Weißbach $status = null; 2157d101cc1SGerry Weißbach switch( $event->data ) { 2167d101cc1SGerry Weißbach case '__siteexport_savecron': $status = $function->saveCronDataWithParameters($combined, $cronOverwriteExisting); break; 2177d101cc1SGerry Weißbach case '__siteexport_deletecron': $status = $function->deleteCronDataWithParameters($combined); break; 2187d101cc1SGerry Weißbach } 2197d101cc1SGerry Weißbach 2207d101cc1SGerry Weißbach if ( !empty($status) ) 2217d101cc1SGerry Weißbach { 2227d101cc1SGerry Weißbach $this->functions->debug->message("Tried to do an action with siteexport/cron, but failed.", $status, 4); 2237d101cc1SGerry Weißbach } 2247d101cc1SGerry Weißbach } 2257d101cc1SGerry Weißbach 2267d101cc1SGerry Weißbach /** 2277d101cc1SGerry Weißbach * generate direct access URL 2287d101cc1SGerry Weißbach **/ 2297d101cc1SGerry Weißbach function ajax_siteexport_generateurl( &$event ) { 2307d101cc1SGerry Weißbach 2317d101cc1SGerry Weißbach list($url, $combined, $path, $POSTData) = $this->ajax_siteexport_prepareURL_and_POSTData($event); 2327d101cc1SGerry Weißbach 2337d101cc1SGerry Weißbach // WGET Redirects - this is an option for wget only. 2347d101cc1SGerry Weißbach // Calculate the maximum redirects that we want to allow. A Problem is that we don't know how long it will take to fetch one page 2357d101cc1SGerry Weißbach // Therefore we assume it takes about 5s for each page - that gives the freedom to have anough time for redirect. 2367d101cc1SGerry Weißbach $maxRedirectNumber = ceil( ( count($this->__get_siteexport_list($NS, true)) * 5) / $this->getConf('max_execution_time') ); 2377d101cc1SGerry Weißbach $maxRedirect = $maxRedirectNumber > 0 ? '--max-redirect=' . ($maxRedirectNumber+3) . ' ' : ''; 2387d101cc1SGerry Weißbach $maxRedirs = $maxRedirectNumber > 0 ? '--max-redirs ' . ($maxRedirectNumber+3) . ' ' : ''; 2397d101cc1SGerry Weißbach 2407d101cc1SGerry Weißbach $this->functions->debug->message("Generating Direct Download URL", $url, 2); 2417d101cc1SGerry Weißbach 2427d101cc1SGerry Weißbach // If there was a Runtime Exception 2437d101cc1SGerry Weißbach if ( !$this->functions->debug->firstRE() ) { 2447d101cc1SGerry Weißbach $this->functions->debug->message("There have been errors while generating the download URLs.", null, 4); 2457d101cc1SGerry Weißbach return; 2467d101cc1SGerry Weißbach } 2477d101cc1SGerry Weißbach 2487d101cc1SGerry Weißbach echo $url; 2497d101cc1SGerry Weißbach echo "\n"; 2507d101cc1SGerry Weißbach echo 'wget ' . $maxRedirect . '--output-document=' . array_pop(explode(":", ($this->getConf('zipfilename')))) . ' --post-data="' . $POSTData . '" ' . wl(cleanID($path), null, true) . ' --http-user=USER --http-passwd=PASSWD'; 2517d101cc1SGerry Weißbach echo "\n"; 2527d101cc1SGerry Weißbach echo 'curl -L ' . $maxRedirs . '-o ' . array_pop(explode(":", ($this->getConf('zipfilename')))) . ' -d "' . $POSTData . '" ' . wl(cleanID($path), null, true) . ' --anyauth --user USER:PASSWD'; 2537d101cc1SGerry Weißbach echo "\n"; 2547d101cc1SGerry Weißbach 2557d101cc1SGerry Weißbach $this->functions->debug->message("Checking for Cron parameters: ", $combined, 1); 2567d101cc1SGerry Weißbach if ( !$functions =& plugin_load('cron', 'siteexport' ) || 2577d101cc1SGerry Weißbach !$functions->hasCronJobForParameters($combined) ) { 2587d101cc1SGerry Weißbach echo "false"; 2597d101cc1SGerry Weißbach } else 2607d101cc1SGerry Weißbach { 2617d101cc1SGerry Weißbach echo "true"; 2627d101cc1SGerry Weißbach } 2637d101cc1SGerry Weißbach 2647d101cc1SGerry Weißbach return; 2657d101cc1SGerry Weißbach } 2667d101cc1SGerry Weißbach 2677d101cc1SGerry Weißbach /** 2687d101cc1SGerry Weißbach * Get List of sites to be exported for AJAX (wrapper) 2697d101cc1SGerry Weißbach **/ 2707d101cc1SGerry Weißbach function ajax_siteexport_getsitelist( &$event ) { 2717d101cc1SGerry Weißbach 2727d101cc1SGerry Weißbach $event->preventDefault(); 2737d101cc1SGerry Weißbach $event->stopPropagation(); 2747d101cc1SGerry Weißbach 2757d101cc1SGerry Weißbach $data = $this->__get_siteexport_list_and_init_tocs($_REQUEST['ns']); 2767d101cc1SGerry Weißbach 2777d101cc1SGerry Weißbach // Important for reconaisance of the session 2787d101cc1SGerry Weißbach 2797d101cc1SGerry Weißbach if ( $data === false ) 2807d101cc1SGerry Weißbach { 2817d101cc1SGerry Weißbach $this->functions->debug->runtimeException("No data generated. List of Files is 'false'."); 2827d101cc1SGerry Weißbach return; 2837d101cc1SGerry Weißbach } 2847d101cc1SGerry Weißbach 2857d101cc1SGerry Weißbach if ( empty($data) && !$this->functions->settings->hasValidCacheFile ) 2867d101cc1SGerry Weißbach { 2877d101cc1SGerry Weißbach $this->functions->debug->runtimeException("Generated list is empty."); 2887d101cc1SGerry Weißbach return; 2897d101cc1SGerry Weißbach } 2907d101cc1SGerry Weißbach 2917d101cc1SGerry Weißbach // If there was a Runtime Exception 2927d101cc1SGerry Weißbach if ( !$this->functions->debug->firstRE() ) 2937d101cc1SGerry Weißbach { 2947d101cc1SGerry Weißbach $this->functions->debug->message("There have been errors while generating site list.", null, 4); 2957d101cc1SGerry Weißbach return; 2967d101cc1SGerry Weißbach } 2977d101cc1SGerry Weißbach 2987d101cc1SGerry Weißbach echo "{$this->functions->settings->pattern}\n"; 2997d101cc1SGerry Weißbach echo $this->functions->downloadURL() . "\n"; 3007d101cc1SGerry Weißbach foreach($data as $line ){ 3017d101cc1SGerry Weißbach echo $line['id'] . "\n"; 3027d101cc1SGerry Weißbach } 3037d101cc1SGerry Weißbach 3047d101cc1SGerry Weißbach return; 3057d101cc1SGerry Weißbach } 3067d101cc1SGerry Weißbach 3076792d0cfSGerry Weißbach function ajax_siteexport_aggregate( &$event ) { 3086792d0cfSGerry Weißbach 3096792d0cfSGerry Weißbach // Quick preparations for one page only 3106792d0cfSGerry Weißbach if ( $this->filewriter->hasValidCacheFile($_REQUEST, $data) ) { 3116792d0cfSGerry Weißbach $this->functions->debug->message("Had a valid cache file and will use it.", null, 2); 3126792d0cfSGerry Weißbach print $this->functions->downloadURL(); 313b88e443eSGerry Weißbach 314b88e443eSGerry Weißbach $event->preventDefault(); 315b88e443eSGerry Weißbach $event->stopPropagation(); 3166792d0cfSGerry Weißbach } else { 3176792d0cfSGerry Weißbach // Then go for it! 3186792d0cfSGerry Weißbach $this->functions->debug->message("Will create a new cache thing.", null, 2); 3196792d0cfSGerry Weißbach $this->ajax_siteexport_addsite( $event ); 3206792d0cfSGerry Weißbach } 3216792d0cfSGerry Weißbach 3226792d0cfSGerry Weißbach } 3236792d0cfSGerry Weißbach 3247d101cc1SGerry Weißbach /** 3257d101cc1SGerry Weißbach * Add a page to the package (for AJAX calls - Wrapper) 3267d101cc1SGerry Weißbach **/ 3277d101cc1SGerry Weißbach function ajax_siteexport_addsite( &$event ) { 3287d101cc1SGerry Weißbach 3297d101cc1SGerry Weißbach $event->preventDefault(); 3307d101cc1SGerry Weißbach $event->stopPropagation(); 3317d101cc1SGerry Weißbach 3327d101cc1SGerry Weißbach $this->functions->debug->message("========================================", null, 1); 3337d101cc1SGerry Weißbach $this->functions->debug->message("Starting export from AJAX call", null, 1); 3348da901a0SGerry Weißbach $this->functions->debug->message("----------------------------------------", null, 1); 3357d101cc1SGerry Weißbach 3367d101cc1SGerry Weißbach $status = $this->__siteexport_add_site($_REQUEST['site']); 3378da901a0SGerry Weißbach if ( $status === false ) { 3388da901a0SGerry Weißbach $this->functions->debug->message("----------------------------------------", null, 1); 3398da901a0SGerry Weißbach $this->functions->debug->message("Errors during export from AJAX call", null, 1); 3408da901a0SGerry Weißbach $this->functions->debug->message("========================================", null, 1); 3418da901a0SGerry Weißbach return; 3428da901a0SGerry Weißbach } 3437d101cc1SGerry Weißbach 3448da901a0SGerry Weißbach $this->functions->debug->message("----------------------------------------", null, 1); 3457d101cc1SGerry Weißbach $this->functions->debug->message("Finishing export from AJAX call", null, 1); 3467d101cc1SGerry Weißbach $this->functions->debug->message("========================================", null, 1); 3477d101cc1SGerry Weißbach 3487d101cc1SGerry Weißbach // Print the download zip-File 3497d101cc1SGerry Weißbach $this->cleanCacheFiles(); 3507d101cc1SGerry Weißbach 3517d101cc1SGerry Weißbach // If there was a Runtime Exception 3527d101cc1SGerry Weißbach if ( !$this->functions->debug->firstRE() ) { 3537d101cc1SGerry Weißbach $this->functions->debug->message("There have been errors during the export.", null, 4); 3547d101cc1SGerry Weißbach return; 3557d101cc1SGerry Weißbach } 3567d101cc1SGerry Weißbach 3577d101cc1SGerry Weißbach print $this->functions->downloadURL(); 3587d101cc1SGerry Weißbach return; 3597d101cc1SGerry Weißbach } 3607d101cc1SGerry Weißbach 3617d101cc1SGerry Weißbach /** 3627d101cc1SGerry Weißbach * Fetch the list of pages to be exported 3637d101cc1SGerry Weißbach **/ 3647d101cc1SGerry Weißbach function __get_siteexport_list($NS, $overrideCache=false) { 3657d101cc1SGerry Weißbach global $conf; 3667d101cc1SGerry Weißbach 3677d101cc1SGerry Weißbach $NS = $this->namespace = $this->functions->getNamespaceFromID($NS, $PAGE); 3687d101cc1SGerry Weißbach 3697d101cc1SGerry Weißbach $depth = $this->getConf('depth'); 3707d101cc1SGerry Weißbach $query = ''; 3717d101cc1SGerry Weißbach $doSearch = 'search_allpages'; 3727d101cc1SGerry Weißbach 3737d101cc1SGerry Weißbach switch( intval($_REQUEST['depthType']) ) { 3747d101cc1SGerry Weißbach case 0: 3757d101cc1SGerry Weißbach $query = $this->functions->cleanID(str_replace(":", "/", $NS.':'.$PAGE)); 3767d101cc1SGerry Weißbach resolve_pageid($NS, $PAGE, $exists); 3777d101cc1SGerry Weißbach 3787d101cc1SGerry Weißbach if ( $exists ) { 3797d101cc1SGerry Weißbach $data = array( array( 'id' => $PAGE) ); 3807d101cc1SGerry Weißbach 3817d101cc1SGerry Weißbach $this->functions->debug->message("Checking for Cache", null, 2); 3827d101cc1SGerry Weißbach if ( !$overrideCache && $this->filewriter->hasValidCacheFile($_REQUEST, $data) ) 3837d101cc1SGerry Weißbach { 3847d101cc1SGerry Weißbach return array(); 3857d101cc1SGerry Weißbach } 3867d101cc1SGerry Weißbach 3877d101cc1SGerry Weißbach return $data; 3887d101cc1SGerry Weißbach } 3897d101cc1SGerry Weißbach case 1: $depth = 0; 3907d101cc1SGerry Weißbach break; 3917d101cc1SGerry Weißbach case 2: $depth = intval($_REQUEST['depth']); 3927d101cc1SGerry Weißbach break; 3937d101cc1SGerry Weißbach } 3947d101cc1SGerry Weißbach 3957d101cc1SGerry Weißbach $opts = array( 'depth' => $depth, 'skipacl' => $this->getConf('skipacl'), 'query' => $query); 396a609ae53SGerry Weißbach $this->functions->debug->message("Options", $opts, 2); 397a609ae53SGerry Weißbach 3987d101cc1SGerry Weißbach $data = array(); 3997d101cc1SGerry Weißbach require_once (DOKU_INC.'inc/search.php'); 4007d101cc1SGerry Weißbach 4017d101cc1SGerry Weißbach // Check, which TOC to take 4027d101cc1SGerry Weißbach if ( !$this->functions->settings->useTOCFile ) { 4037d101cc1SGerry Weißbach search($data, $conf['datadir'], $doSearch, $opts, $this->namespace); 4047d101cc1SGerry Weißbach } else { 4057d101cc1SGerry Weißbach $this->functions->debug->message("Using TOC for data", null, 2); 4067d101cc1SGerry Weißbach 4077d101cc1SGerry Weißbach $doSearch = 'search_pagename'; 4087d101cc1SGerry Weißbach 4097d101cc1SGerry Weißbach // Create Data of the TOC File should be used instead 4107d101cc1SGerry Weißbach $opts['query'] = 'toc.txt'; 4117d101cc1SGerry Weißbach 4127d101cc1SGerry Weißbach $RAWdata = array(); 4137d101cc1SGerry Weißbach search($RAWdata, $conf['datadir'], $doSearch, $opts, $this->namespace); 4147d101cc1SGerry Weißbach 4157d101cc1SGerry Weißbach // There may be more than one toc and all of them have to be merged. 4167d101cc1SGerry Weißbach $data = array(); 4177d101cc1SGerry Weißbach foreach( $RAWdata as $entry ) 4187d101cc1SGerry Weißbach { 4197d101cc1SGerry Weißbach $tmpData = p_get_metadata($entry['id'], 'sitetoc siteexportTOC', true); 4207d101cc1SGerry Weißbach 4217d101cc1SGerry Weißbach if ( is_array($tmpData) ) 4227d101cc1SGerry Weißbach { 4237d101cc1SGerry Weißbach $data = array_merge($data, $tmpData); 4247d101cc1SGerry Weißbach } 4257d101cc1SGerry Weißbach } 4267d101cc1SGerry Weißbach } 4277d101cc1SGerry Weißbach 4287d101cc1SGerry Weißbach $this->functions->debug->message("Checking for Cache", null, 2); 4297d101cc1SGerry Weißbach if ( !$overrideCache && $this->filewriter->hasValidCacheFile($_REQUEST, $data) ) 4307d101cc1SGerry Weißbach { 4317d101cc1SGerry Weißbach return array(); 4327d101cc1SGerry Weißbach } 4337d101cc1SGerry Weißbach 4347d101cc1SGerry Weißbach $this->functions->debug->message("Exporting the following sites: ", $data, 2); 4357d101cc1SGerry Weißbach return $data; 4367d101cc1SGerry Weißbach } 4377d101cc1SGerry Weißbach 4387d101cc1SGerry Weißbach function __get_siteexport_list_and_init_tocs($NS, $isRedirected=false ) { 4397d101cc1SGerry Weißbach 4407d101cc1SGerry Weißbach // Clean up if not redirected 4417d101cc1SGerry Weißbach if ( !$isRedirected && !$this->__removeOldZip() ) { 4427d101cc1SGerry Weißbach $this->functions->debug->runtimeException("Can't remove old files."); 4437d101cc1SGerry Weißbach return false; 4447d101cc1SGerry Weißbach } 4457d101cc1SGerry Weißbach 4467d101cc1SGerry Weißbach $data = $this->__get_siteexport_list($NS, $isRedirected); 4477d101cc1SGerry Weißbach if ( $isRedirected || empty($data) ) 4487d101cc1SGerry Weißbach { 4497d101cc1SGerry Weißbach // if we have been redirected, simply return the data 4507d101cc1SGerry Weißbach return $data; 4517d101cc1SGerry Weißbach } 4527d101cc1SGerry Weißbach 4537d101cc1SGerry Weißbach // Create Eclipse Documentation Pages - TOC.xml, Context.xml 4547d101cc1SGerry Weißbach if ( !empty($_REQUEST['absolutePath']) ) $this->namespace = ""; 4557d101cc1SGerry Weißbach// $this->__removeOldZip( $this->functions->settings->eclipseZipFile ); 4567d101cc1SGerry Weißbach 4577d101cc1SGerry Weißbach if ( !empty($_REQUEST['eclipseDocZip']) ) 4587d101cc1SGerry Weißbach { 4597d101cc1SGerry Weißbach $toc = new siteexport_toc($this->functions); 4607d101cc1SGerry Weißbach $this->functions->debug->message("Generating eclipseDocZip", null, 2); 4617d101cc1SGerry Weißbach $this->filewriter->__moveDataToZip($toc->__getTOCXML($data), 'toc.xml'); 4627d101cc1SGerry Weißbach $this->filewriter->__moveDataToZip($toc->__getContextXML($data), 'context.xml'); 4637d101cc1SGerry Weißbach } else if ( !empty($_REQUEST['JavaHelpDocZip']) ) 4647d101cc1SGerry Weißbach { 4657d101cc1SGerry Weißbach $toc = new siteexport_javahelp($this->functions, $this->filewriter); 4667d101cc1SGerry Weißbach $toc->createTOCFiles($data); 4677d101cc1SGerry Weißbach 4687d101cc1SGerry Weißbach/* $toc = new siteexport_toc($this->functions); 4697d101cc1SGerry Weißbach list($tocData, $mapData) = $toc->__getJavaHelpTOCXML($data); 4707d101cc1SGerry Weißbach $this->functions->debug->message("Generating JavaHelpDocZip", null, 2); 4717d101cc1SGerry Weißbach $this->filewriter->__moveDataToZip($tocData, 'toc.xml'); 4727d101cc1SGerry Weißbach $this->filewriter->__moveDataToZip($mapData, 'map.xml'); 4737d101cc1SGerry Weißbach*/ } 4747d101cc1SGerry Weißbach 4757d101cc1SGerry Weißbach return $data; 4767d101cc1SGerry Weißbach } 4777d101cc1SGerry Weißbach 4787d101cc1SGerry Weißbach /** 4797d101cc1SGerry Weißbach * Add page with ID to the package 4807d101cc1SGerry Weißbach **/ 4817d101cc1SGerry Weißbach function __siteexport_add_site( $ID ) { 4827d101cc1SGerry Weißbach global $conf, $currentID; 4837d101cc1SGerry Weißbach 4847d101cc1SGerry Weißbach // Which is the current ID? 4857d101cc1SGerry Weißbach $currentID = $ID; 4867d101cc1SGerry Weißbach 4877d101cc1SGerry Weißbach $this->functions->debug->message("========================================", null, 2); 4887d101cc1SGerry Weißbach $this->functions->debug->message("Adding Site: '$ID'", null, 2); 4894b7d84d7SGerry Weißbach $this->functions->debug->message("----------------------------------------", $_REQUEST, 2); 4907d101cc1SGerry Weißbach 4917d101cc1SGerry Weißbach $request = $this->functions->settings->additionalParameters; 4927d101cc1SGerry Weißbach unset($request['diPlu']); // This will not be needed for the first request. 4937d101cc1SGerry Weißbach unset($request['diInv']); // This will not be needed for the first request. 4947d101cc1SGerry Weißbach 4957d101cc1SGerry Weißbach // say, what to export and Build URL 4967d101cc1SGerry Weißbach // http://documentation:81/helpdesk/de/hds/getting-started?depthType=0&do=siteexport&ens=helpdesk%3Ade%3Ahds%3Agetting-started&pdfExport=1&renderer=siteexport_siteexportpdf&template=helpdesk 4977d101cc1SGerry Weißbach 4987d101cc1SGerry Weißbach $do = (intval($_REQUEST['exportbody']) == 1 ? (empty($_REQUEST['renderer']) ? $conf['renderer_xhtml'] : $_REQUEST['renderer'] ) : '' ); 4997d101cc1SGerry Weißbach 5007d101cc1SGerry Weißbach if ($do == 'pdf' && $this->filewriter->canDoPDF() ) 5017d101cc1SGerry Weißbach { 5027d101cc1SGerry Weißbach $do = 'export_siteexport_pdf'; 5037d101cc1SGerry Weißbach $_REQUEST['origRenderer'] = (empty($_REQUEST['renderer']) ? $conf['renderer_xhtml'] : $_REQUEST['renderer'] ); 5047d101cc1SGerry Weißbach } 5057d101cc1SGerry Weißbach 5067d101cc1SGerry Weißbach $do = ($do == $conf['renderer_xhtml'] && intval($_REQUEST['exportbody']) != 1) ? '' : 'export_' . $do; 5077d101cc1SGerry Weißbach 5087d101cc1SGerry Weißbach if ( $do != 'export_' && !empty($do) ) 5097d101cc1SGerry Weißbach { 5107d101cc1SGerry Weißbach $request['do'] = $do; 5117d101cc1SGerry Weißbach } 5127d101cc1SGerry Weißbach 5137d101cc1SGerry Weißbach // set Template 5147d101cc1SGerry Weißbach if ( !empty( $_REQUEST['template'] ) ) { 5157d101cc1SGerry Weißbach $request['template'] = $_REQUEST['template']; 5167d101cc1SGerry Weißbach } 5177d101cc1SGerry Weißbach 5187d101cc1SGerry Weißbach $this->functions->debug->message("REQUEST for add_site:", $request, 2); 5197d101cc1SGerry Weißbach 5207d101cc1SGerry Weißbach $ID = $this->functions->cleanID($ID); 5217d101cc1SGerry Weißbach $url = $this->functions->wl($ID, $request, true, '&'); 5227d101cc1SGerry Weißbach 5237d101cc1SGerry Weißbach // Parse URI PATH and add "html" 5247d101cc1SGerry Weißbach $fileName = $this->functions->getSiteName($ID, true); 5256792d0cfSGerry Weißbach $this->functions->debug->message("Filename could be:", $fileName, 2); 5267d101cc1SGerry Weißbach 5277d101cc1SGerry Weißbach $this->fileChecked[$url] = $fileName; // 2010-09-03 - One URL to one FileName 5287d101cc1SGerry Weißbach $this->functions->settings->depth = str_repeat('../', count(explode('/', $fileName))-1); 5297d101cc1SGerry Weißbach 5307d101cc1SGerry Weißbach // fetch URL and save it in temp file 5317d101cc1SGerry Weißbach $tmpFile = $this->__getHTTPFile($url); 5327d101cc1SGerry Weißbach if ( $tmpFile === false ) { 5338da901a0SGerry Weißbach // return $this->functions->debug->message("Creating temporary download file failed for '$url'. See log for more information."); 5348da901a0SGerry Weißbach $this->functions->debug->runtimeException("Creating temporary download file failed for '$url'. See log for more information."); 5358da901a0SGerry Weißbach return false; 5367d101cc1SGerry Weißbach } 5377d101cc1SGerry Weißbach 538281ed919SGerry Weißbach $dirname = dirname($fileName); 5397d101cc1SGerry Weißbach // If a Filename was given that does not comply to the original name, use this one! 540281ed919SGerry Weißbach if ( $this->filewriter->canDoPDF() ) { 5417d101cc1SGerry Weißbach 542281ed919SGerry Weißbach $this->functions->debug->message("Will replace old filename '{$fileName}' with {$tmpFile[2]}", null, 1); 543281ed919SGerry Weißbach $extension = array_pop(explode('.', $fileName)); 54446ccacefSGerry Weißbach 54546ccacefSGerry Weißbach // 2014-04-29 added cleanID to ensure that links are generated consistently when using [[this>...]] or another local, relativ linking 54646ccacefSGerry Weißbach $fileName = $dirname . '/' . $this->functions->cleanID($this->functions->getSiteTitle($ID)) . '.' . $extension; 547281ed919SGerry Weißbach } else if ( !empty($tmpFile[1]) && !strstr($DATA[2], $tmpFile[1]) ) { 5487d101cc1SGerry Weißbach 5496792d0cfSGerry Weißbach $this->functions->debug->message("Will replace old filename '{$fileName}' with {$dirname}/{$tmpFile[1]}", null, 1); 550281ed919SGerry Weißbach $fileName = $dirname . '/' . $tmpFile[1]; 5517d101cc1SGerry Weißbach } 5527d101cc1SGerry Weißbach 5537d101cc1SGerry Weißbach // Add to zip 55484d65497SGerry Weißbach $this->fileChecked[$url] = $fileName; 5557d101cc1SGerry Weißbach $status = $this->filewriter->__addFileToZip($tmpFile[0], $fileName); 5567d101cc1SGerry Weißbach @unlink($tmpFile[0]); 5577d101cc1SGerry Weißbach 5587d101cc1SGerry Weißbach return $status; 5597d101cc1SGerry Weißbach } 5607d101cc1SGerry Weißbach 561d3cbbad8SGerry Weißbach function __preg_quote($input) { 562d3cbbad8SGerry Weißbach return preg_quote($input, '/'); 563d3cbbad8SGerry Weißbach } 564d3cbbad8SGerry Weißbach 5657d101cc1SGerry Weißbach /** 5667d101cc1SGerry Weißbach * Download the file via HTTP URL + recurse if this is not an image 5677d101cc1SGerry Weißbach * The file will be saved as temporary file. The filename is the result. 5687d101cc1SGerry Weißbach **/ 5697d101cc1SGerry Weißbach function __getHTTPFile($URL, $RECURSE=false, $newAdditionalParameters=null) { 5707d101cc1SGerry Weißbach global $conf; 5717d101cc1SGerry Weißbach 572d3cbbad8SGerry Weißbach $EXCLUDE = $this->getConf('exclude'); 573d3cbbad8SGerry Weißbach if ( !empty($EXCLUDE) ) { 574d3cbbad8SGerry Weißbach $PATTERN = "/(" . implode('|', explode(' ', preg_quote($EXCLUDE, '/'))) . ")/i"; 5757d101cc1SGerry Weißbach 576d3cbbad8SGerry Weißbach $this->functions->debug->message("Checking for exclude: ", array( 577d3cbbad8SGerry Weißbach "pattern" => $PATTERN, 578d3cbbad8SGerry Weißbach "file" => $URL, 579d3cbbad8SGerry Weißbach "matches" => preg_match($PATTERN, $URL) ? 'match' : 'no match' 580d3cbbad8SGerry Weißbach ), 2); 581d3cbbad8SGerry Weißbach 582d3cbbad8SGerry Weißbach if ( preg_match($PATTERN, $URL) ) { return false; } 583d3cbbad8SGerry Weißbach } 5847d101cc1SGerry Weißbach 5857d101cc1SGerry Weißbach require_once( DOKU_INC . 'inc/HTTPClient.php'); 5867d101cc1SGerry Weißbach 5878da901a0SGerry Weißbach $http = new HTTPProxy($this->functions->debug, $this->functions->settings); 5887d101cc1SGerry Weißbach $http->max_bodysize = $conf['fetchsize']; 5897d101cc1SGerry Weißbach // $http->user = $_SERVER['PHP_AUTH_USER']; // Must not be set, or the files will be authenticated and have the edit thingies 5907d101cc1SGerry Weißbach // $http->pass = $_SERVER['PHP_AUTH_PW']; // Must not be set, or the files will be authenticated and have the edit thingies 5917d101cc1SGerry Weißbach 5927d101cc1SGerry Weißbach // Add additional Params 5937d101cc1SGerry Weißbach $this->functions->addAdditionalParametersToURL($URL, $newAdditionalParameters); 5947d101cc1SGerry Weißbach 5957d101cc1SGerry Weißbach $this->functions->debug->message("Fetching URL: '$URL'", null, 2); 5969d84786fSGerry Weißbach $getData = $http->get($URL, true); // true == sloopy, get 304 body as well. 5977d101cc1SGerry Weißbach 5987d101cc1SGerry Weißbach if( $getData === false ) { 599cb168401SGerry Weißbach 600cb168401SGerry Weißbach if ( $this->functions->settings->ignoreNon200 ) { 601cb168401SGerry Weißbach return null; 602cb168401SGerry Weißbach } 603cb168401SGerry Weißbach 6047d101cc1SGerry Weißbach $this->functions->debug->message("Sending request failed with error, HTTP status was '{$http->status}'.", $URL, 4); 6057d101cc1SGerry Weißbach return false; 6067d101cc1SGerry Weißbach } 6077d101cc1SGerry Weißbach 6087d101cc1SGerry Weißbach if( empty($getData) ) { 60933aa25baSGerry Weißbach $this->functions->debug->message("No data fetched", $URL, 4); 6107d101cc1SGerry Weißbach return false; 6117d101cc1SGerry Weißbach } 6127d101cc1SGerry Weißbach 613281ed919SGerry Weißbach $this->functions->debug->message("Headers received", $http->resp_headers, 2); 614281ed919SGerry Weißbach 6157d101cc1SGerry Weißbach if ( !$RECURSE ) { 6167d101cc1SGerry Weißbach // Parse URI PATH and add "html" 6177d101cc1SGerry Weißbach $this->functions->debug->message("========================================", null, 1); 6187d101cc1SGerry Weißbach $this->functions->debug->message("Starting to recurse file '$URL'", null , 1); 6198da901a0SGerry Weißbach $this->functions->debug->message("----------------------------------------", null, 1); 6207d101cc1SGerry Weißbach $this->__getInternalLinks($getData); 6218da901a0SGerry Weißbach $this->functions->debug->message("----------------------------------------", null, 1); 6227d101cc1SGerry Weißbach $this->functions->debug->message("Finished to recurse file '$URL'", null , 1); 6237d101cc1SGerry Weißbach $this->functions->debug->message("========================================", null, 1); 6247d101cc1SGerry Weißbach } 6257d101cc1SGerry Weißbach 6269d84786fSGerry Weißbach $tmpFile = tempnam($this->functions->settings->tmpDir , 'siteexport__'); 6279d84786fSGerry Weißbach $this->functions->debug->message("Temporary filename", $tmpFile, 1); 6289d84786fSGerry Weißbach 6299d84786fSGerry Weißbach $fp = fopen( $tmpFile, "w"); 6309d84786fSGerry Weißbach if(!$fp) { 6319d84786fSGerry Weißbach $this->functions->debug->message("Can't open temporary File '$tmpFile'.", null , 4); 6329d84786fSGerry Weißbach return false; 6339d84786fSGerry Weißbach } 6349d84786fSGerry Weißbach 6357d101cc1SGerry Weißbach fwrite($fp,$getData); 6367d101cc1SGerry Weißbach fclose($fp); 6377d101cc1SGerry Weißbach 638ccdae538SGerry Weißbach // plain/text; ... 639ccdae538SGerry Weißbach $extension = array_shift(explode(';', $http->resp_headers['content-type'], 2)); 640ccdae538SGerry Weißbach $extension = explode('/', $extension, 2); 641ccdae538SGerry Weißbach if ( $extension[0] == 'image' || $extension[1] == 'html' ) { 642ccdae538SGerry Weißbach $extension = $extension[1]; 643ccdae538SGerry Weißbach } else { 644ccdae538SGerry Weißbach unset($extension); 645ccdae538SGerry Weißbach } 646ccdae538SGerry Weißbach 647ccdae538SGerry Weißbach return array($tmpFile, preg_replace("/.*?filename=\"?(.*?)\"?;?$/", "$1", $http->resp_headers['content-disposition']), $extension); 6487d101cc1SGerry Weißbach } 6497d101cc1SGerry Weißbach 6507d101cc1SGerry Weißbach /** 6517d101cc1SGerry Weißbach * Find internal links in the currently downloaded file. This also matches inside CSS files 6527d101cc1SGerry Weißbach **/ 6537d101cc1SGerry Weißbach function __getInternalLinks(&$DATA) { 6547d101cc1SGerry Weißbach 6557d101cc1SGerry Weißbach $PATTERN = '(href|src|action)="([^"]*)"'; 6567d101cc1SGerry Weißbach $CALLBACK = array($this, '__fetchAndReplaceLink'); 6577d101cc1SGerry Weißbach $DATA = preg_replace_callback("/$PATTERN/i", $CALLBACK, $DATA); 6587d101cc1SGerry Weißbach 6590fc5c0e0SGerry Weißbach $PATTERNCSS = '(url\s*?)\(([^\)]*)\)'; 6607d101cc1SGerry Weißbach $DATA = preg_replace_callback("/$PATTERNCSS/i", $CALLBACK, $DATA); 6617d101cc1SGerry Weißbach } 6627d101cc1SGerry Weißbach 6637d101cc1SGerry Weißbach /** 6647d101cc1SGerry Weißbach * Deep Fetch and replace of links inside the texts matched by __getInternalLinks 6657d101cc1SGerry Weißbach **/ 6667d101cc1SGerry Weißbach function __fetchAndReplaceLink($DATA) { 6672316a5cfSGerry Weißbach global $conf, $currentID, $currentParent; 6687d101cc1SGerry Weißbach 6697d101cc1SGerry Weißbach $noDeepReplace = true; 6707d101cc1SGerry Weißbach $newAdditionalParameters = $this->functions->settings->additionalParameters; 6717d101cc1SGerry Weißbach $newDepth = $this->functions->settings->depth; 6727d101cc1SGerry Weißbach $hadBase = false; 6737d101cc1SGerry Weißbach 674d3cbbad8SGerry Weißbach // Clean data[2], remote ' and " 675d3cbbad8SGerry Weißbach $DATA[2] = preg_replace("/^\s*?['\"]?(.*?)['\"]?\s*?$/", '\1', trim($DATA[2])); 676d3cbbad8SGerry Weißbach 67767f4f6e5SGerry Weißbach $this->functions->debug->message("Starting Link Replacement", array( 'data' => $DATA, 'additional Params' => $newAdditionalParameters, 'newDepth' => $newDepth, 'currentID' => $currentID), 2); 6787d101cc1SGerry Weißbach 6797d101cc1SGerry Weißbach // $DATA[2] = urldecode($DATA[2]); // Leads to problems because it does not re-encode the url 6807d101cc1SGerry Weißbach // External and mailto links 6817d101cc1SGerry Weißbach if ( preg_match("%^(https?://|mailto:|javascript:|data:)%", $DATA[2]) ) { 6827d101cc1SGerry Weißbach $this->functions->debug->message("Don't like http, mailto, data or javascript links here", null, 1); 6837d101cc1SGerry Weißbach return $this->__rebuildLink($DATA, ""); 6847d101cc1SGerry Weißbach } 6857d101cc1SGerry Weißbach //if ( preg_match("%^(https?://|mailto:|" . DOKU_BASE . "/_export/)%", $DATA[2]) ) { return $this->__rebuildLink($DATA, ""); } 6867d101cc1SGerry Weißbach // External media - this is deep down in the link, so we have to grep it out 6877d101cc1SGerry Weißbach if ( preg_match("%media=(https?://.*?$)%", $DATA[2], $matches) ) { 6887d101cc1SGerry Weißbach $DATA[2] = $matches[1]; 6897d101cc1SGerry Weißbach $this->functions->debug->message("This is an HTTP like somewhere else", $DATA, 1); 6907d101cc1SGerry Weißbach return $this->__rebuildLink($DATA, ""); 6917d101cc1SGerry Weißbach } 6927d101cc1SGerry Weißbach // reference only links won't have to be rewritten 6937d101cc1SGerry Weißbach if ( preg_match("%^#.*?$%", $DATA[2]) ) { 6947d101cc1SGerry Weißbach $this->functions->debug->message("This is a refercence only", null, 1); 6957d101cc1SGerry Weißbach return $this->__rebuildLink($DATA, ""); 6967d101cc1SGerry Weißbach } 6977d101cc1SGerry Weißbach 6987d101cc1SGerry Weißbach // strip all things out 6997d101cc1SGerry Weißbach // changed Data 7007d101cc1SGerry Weißbach $PARAMS = @parse_url($DATA[2], PHP_URL_QUERY); 7017d101cc1SGerry Weißbach $ANCHOR = @parse_url($DATA[2], PHP_URL_FRAGMENT); 7027d101cc1SGerry Weißbach $DATA[2] = @parse_url($DATA[2], PHP_URL_PATH); 7037d101cc1SGerry Weißbach 70467f4f6e5SGerry Weißbach // 2014-05-12 - fix problem with URLs starting with a ./ or ../ ... they seem to need the current IDs root 7052316a5cfSGerry Weißbach if ( preg_match("#^\.\.?/#", $DATA[2])) { 70667f4f6e5SGerry Weißbach $DATA[2] = getNS($currentID) . ':' . $DATA[2]; 70767f4f6e5SGerry Weißbach } 70867f4f6e5SGerry Weißbach 7097d101cc1SGerry Weißbach // 2010-08-25 - fix problem with relative movement in links ( "test/../test2" ) 7102316a5cfSGerry Weißbach // 2014-06-30 - what? to what will this end relatively? 7117d101cc1SGerry Weißbach $tmpData2 = ''; 7127d101cc1SGerry Weißbach while( $tmpData2 != $DATA[2] ) { 7137d101cc1SGerry Weißbach $tmpData2 = $DATA[2]; 7147d101cc1SGerry Weißbach $DATA[2] = preg_replace("#/(?!\.\.)[^\/]*?/\.\./#", '/', $DATA[2]); 7157d101cc1SGerry Weißbach } 7167d101cc1SGerry Weißbach 7177d101cc1SGerry Weißbach $temp = preg_replace("%^" . DOKU_BASE . "%", "", $DATA[2]); 7187d101cc1SGerry Weißbach if ( $temp != $DATA[2] ) { 7197d101cc1SGerry Weißbach $DATA[2] = $temp; 7207d101cc1SGerry Weißbach $hadBase = true; // 2010-08-23 Check if there has been a rewrite here that will have to be considered later on 7217d101cc1SGerry Weißbach } 7227d101cc1SGerry Weißbach 7237d101cc1SGerry Weißbach $this->functions->debug->message("URL before rewriting option for others than 1", array($DATA, $PARAMS, $hadBase), 1); 7247d101cc1SGerry Weißbach 725d3cbbad8SGerry Weißbach // Handle rewrites other than 1 - just for non-lib-files 726d3cbbad8SGerry Weißbach // if ( !preg_match('$^/?lib/$', $DATA[2]) ) { 727d3cbbad8SGerry Weißbach if ( !preg_match('$^(' . DOKU_BASE . ')?lib/$', $DATA[2]) ) { 72867f4f6e5SGerry Weißbach $this->functions->debug->message("Did not match '$^(" . DOKU_BASE . ")?lib/$' userewrite == {$conf['userewrite']}", null, 2); 7297d101cc1SGerry Weißbach if ( $conf['userewrite'] == 2 ) { 7307d101cc1SGerry Weißbach $DATA[2] = $this->__getInternalRewriteURL($DATA[2]); 7317d101cc1SGerry Weißbach } elseif ( $conf['userewrite'] == 0 ) { 7327d101cc1SGerry Weißbach $this->__getParamsAndDataRewritten($DATA, $PARAMS); 7337d101cc1SGerry Weißbach } 7340fc5c0e0SGerry Weißbach } else { 7350fc5c0e0SGerry Weißbach $this->functions->debug->message("This file must be inside lib ...", null, 2); 7367d101cc1SGerry Weißbach } 7377d101cc1SGerry Weißbach 7387d101cc1SGerry Weißbach $this->functions->debug->message("URL before rewriting option", array($DATA, $PARAMS), 2); 7397d101cc1SGerry Weißbach 7407d101cc1SGerry Weißbach $ORIGDATA2 = $DATA; 7417d101cc1SGerry Weißbach // $ORIGDATA2 = $DATA[2]; // 08/10/2010 - this line required a $this->functions->wl which may mess up with the base URL 7427d101cc1SGerry Weißbach $this->functions->debug->message("OrigDATA is:", $ORIGDATA2, 1); 7437d101cc1SGerry Weißbach 7447d101cc1SGerry Weißbach // Generate ID 7457d101cc1SGerry Weißbach $DATA[2] = str_replace('/', ':', $DATA[2]); 7467d101cc1SGerry Weißbach 7477d101cc1SGerry Weißbach // If Data was empty this must be the same file!; 7487d101cc1SGerry Weißbach if ( empty( $DATA[2] ) ) { 7497d101cc1SGerry Weißbach $DATA[2] = $currentID; 7507d101cc1SGerry Weißbach } 7517d101cc1SGerry Weißbach 7527d101cc1SGerry Weißbach $ID = $DATA[2]; 7537d101cc1SGerry Weißbach $MEDIAMATCHER = "#(_media(/|:)|media=|_detail(/|:)|_export(/|:)|do=export_)#i"; // 2010-10-23 added "(/|:)" for the ID may not contain slashes anymore 7547d101cc1SGerry Weißbach $ID = $this->functions->cleanID($DATA[2], null, preg_match($MEDIAMATCHER, $DATA[2]) ); 7557d101cc1SGerry Weißbach // $ID = $this->functions->cleanID($DATA[2], null, strstr($DATA[2], 'media') ); // Export anpassung nun weiter unten 7567d101cc1SGerry Weißbach 7577d101cc1SGerry Weißbach // $IDexists = page_exists($ID); // 08/10/2010 - Not needed. This will be done in the next block. 7587d101cc1SGerry Weißbach // $this->functions->debug->message("Current ID: '$ID' exists: '" . ($IDexists ? 'true' : 'false') . "' (will be set to 'false' anyway)", null, 1); 7597d101cc1SGerry Weißbach 7607d101cc1SGerry Weißbach $IDifIDnotExists = $ID; // 08/10/2010 - Save ID - with possible upper cases to preserve them 7617d101cc1SGerry Weißbach $IDexists = false; 7627d101cc1SGerry Weißbach 7637d101cc1SGerry Weißbach $this->functions->debug->message("Resolving ID: '$ID'", null, 2); 7647d101cc1SGerry Weißbach if ( preg_match($MEDIAMATCHER, $DATA[2]) ) { 7657d101cc1SGerry Weißbach resolve_mediaid(null, $ID, $IDexists); 7667d101cc1SGerry Weißbach 7677d101cc1SGerry Weißbach $this->functions->debug->message("Current mediaID to filename: '" . mediaFN($ID) . "'", null, 2); 7687d101cc1SGerry Weißbach } else { 7697d101cc1SGerry Weißbach resolve_pageid(null, $ID, $IDexists); 7707d101cc1SGerry Weißbach $this->functions->debug->message("Current ID to filename: '" . wikiFN($ID) . "'", null, 2); 7717d101cc1SGerry Weißbach } 7727d101cc1SGerry Weißbach 7737d101cc1SGerry Weißbach $this->functions->debug->message("Current ID after resolvement: '$ID' the ID does exist: '" . ($IDexists ? 'true' : 'false') . "'", null, 2); 7747d101cc1SGerry Weißbach // $ORIGDATA2 = @parse_url($this->functions->wl($ORIGDATA2, null, true)); // What was the next 2 line for? It did mess up with links from {{jdoc>}} 7757d101cc1SGerry Weißbach // $this->functions->debug->message("OrigData ID after parse:", $ORIGDATA2, 1); // 08/10/2010 - The lines are obsolete when the $ORIGDATA2 = $DATA. $ORIGDATA is only for fallback 7767d101cc1SGerry Weißbach 7777d101cc1SGerry Weißbach // 08/10/2010 - If the ID does not exist, we may have a problem here with upper cases - they will all be lower by now! 7787d101cc1SGerry Weißbach if ( !$IDexists ) { 7797d101cc1SGerry Weißbach $ID = $IDifIDnotExists; // there may have been presevered Upper cases. We will need them! 7807d101cc1SGerry Weißbach } 7817d101cc1SGerry Weißbach 7827d101cc1SGerry Weißbach // $this->functions->cleanID($DATA[2], null, strstr($DATA[2], 'media') || strstr($DATA[2], 'export') ); 7837d101cc1SGerry Weißbach if ( substr($ID, -1) == ':' || empty($ID) ) $ID .= $conf['start']; 7847d101cc1SGerry Weißbach 7857d101cc1SGerry Weißbach // Generate Download URL 7867d101cc1SGerry Weißbach // $PARAMS = trim(str_replace('&', '&', $PARAMS)); 7877d101cc1SGerry Weißbach $PARAMS = trim($PARAMS); 7887d101cc1SGerry Weißbach $this->functions->removeWikiVariables($PARAMS, false, true); 7897d101cc1SGerry Weißbach 7907d101cc1SGerry Weißbach $url = $this->functions->wl($ID, null, true, null, null, true, $hadBase) . ( !empty( $ANCHOR) ? '#' . $ANCHOR : '' ) . ( !empty( $PARAMS) ? '?' . $PARAMS : '' ); 7917d101cc1SGerry Weißbach $this->functions->debug->message("URL from ID: '$url'", null, 2); 7927d101cc1SGerry Weißbach 7937d101cc1SGerry Weißbach // Parse URI PATH and add "html" 7947d101cc1SGerry Weißbach $uri = @parse_url($url); 7957d101cc1SGerry Weißbach $DATA[2] = $uri['path']; 7967d101cc1SGerry Weißbach $DATA['ANCHOR'] = $ANCHOR; 7977d101cc1SGerry Weißbach $DATA['PARAMS'] = $PARAMS; 7987d101cc1SGerry Weißbach 7997d101cc1SGerry Weißbach $this->functions->debug->message("DATA after parsing.", $DATA, 2); 8007d101cc1SGerry Weißbach 8017d101cc1SGerry Weißbach // Second Rewrite for UseRewrite = 2 8027d101cc1SGerry Weißbach if ( $conf['userewrite'] == 2 ) { 8037d101cc1SGerry Weißbach $DATA[2] = preg_replace( '$/lib/.*?fetch\.php$', '', $DATA[2]); 8047d101cc1SGerry Weißbach $DATA[2] = preg_replace( '%(/lib/.*?detail\.php.*$)%', '\1' . '.' . $this->functions->settings->fileType, $DATA[2]); 8057d101cc1SGerry Weißbach 8067d101cc1SGerry Weißbach if ( preg_match( '%/(lib/.*?detail|doku)\.php%', $DATA[2])) { 8077d101cc1SGerry Weißbach $noDeepReplace = false; 8087d101cc1SGerry Weißbach $fileName = $this->functions->getSiteName($ID); 8097d101cc1SGerry Weißbach $newDepth = str_repeat('../', count(explode('/', $fileName))-1); 8107d101cc1SGerry Weißbach } 8117d101cc1SGerry Weißbach 8127d101cc1SGerry Weißbach $this->functions->debug->message("DATA after second rewrite with UseRewrite = 2", array($DATA, $noDeepReplace, $fileName, $newDepth), 1); 8137d101cc1SGerry Weißbach } 8147d101cc1SGerry Weißbach 8157d101cc1SGerry Weißbach switch ( array_pop(explode('/', $DATA[2])) ) { 8167d101cc1SGerry Weißbach // CSS Extra Handling with extra rewrites 8177d101cc1SGerry Weißbach case 'css.php' : // $DATA[2] .= ( !$this->functions->settings->addParams || empty($PARAMS) ? '' : '.' . $this->functions->cleanID(preg_replace("/(=|\?|&)/", ".", $PARAMS))) . '.css'; 8187d101cc1SGerry Weißbach $DATA[2] .= '.' . $this->functions->cleanID(preg_replace("/(=|\?|&)/", ".", $PARAMS)) . '.css'; // allways put parameters behind 8197d101cc1SGerry Weißbach // No paramters needed since they are rewritten. 8207d101cc1SGerry Weißbach $DATA['PARAMS'] = ""; 8217d101cc1SGerry Weißbach $noDeepReplace = false; 8227d101cc1SGerry Weißbach $fileName = $this->functions->getSiteName($ID); 823fde5bd1dSGerry Weißbach 824fde5bd1dSGerry Weißbach // NewDepth has to be relative to the css file itself ... 825fde5bd1dSGerry Weißbach $newDepth = './' . str_repeat('../', count(explode(':', $fileName))-1); // it is an ID at this point. 8267d101cc1SGerry Weißbach $newAdditionalParameters['do'] = 'siteexport'; 8277d101cc1SGerry Weißbach 8287d101cc1SGerry Weißbach $this->functions->debug->message("This is CSS file", array($DATA, $noDeepReplace, $fileName, $newDepth, $newAdditionalParameters), 2); 8297d101cc1SGerry Weißbach 8307d101cc1SGerry Weißbach break; 8317d101cc1SGerry Weißbach case 'js.php' : // $DATA[2] .= ( !$this->functions->settings->addParams || empty($PARAMS) ? '' : '.' . $this->functions->cleanID(preg_replace("/(=|\?|&)/", ".", $PARAMS))) . '.js'; 8327d101cc1SGerry Weißbach $DATA[2] .= '.t.' . $this->functions->cleanID($_REQUEST['template']) . '.js'; // allways put parameters behind 8337d101cc1SGerry Weißbach // set Template 8347d101cc1SGerry Weißbach if ( !empty( $_REQUEST['template'] ) ) { 8357d101cc1SGerry Weißbach $url .= ( strstr($url, '?') ? '&' : '?' ) . 'template=' . $_REQUEST['template']; 8367d101cc1SGerry Weißbach } 8377d101cc1SGerry Weißbach // No paramters needed since they are rewritten. 8387d101cc1SGerry Weißbach $DATA['PARAMS'] = ""; 8397d101cc1SGerry Weißbach $newAdditionalParameters['do'] = 'siteexport'; 8407d101cc1SGerry Weißbach 8417d101cc1SGerry Weißbach $this->functions->debug->message("This is JS file", array($DATA, $url, $fileName, $newAdditionalParameters), 2); 8427d101cc1SGerry Weißbach 8437d101cc1SGerry Weißbach break; 8447d101cc1SGerry Weißbach // Detail Handling with extra Rewrites if Paramaters are available - otherwise this is just the fetch 8457d101cc1SGerry Weißbach case 'indexer.php' : 8467d101cc1SGerry Weißbach $this->functions->debug->message("Skipping indexer", null, 2); 8477d101cc1SGerry Weißbach return ""; 8487d101cc1SGerry Weißbach break; 8497d101cc1SGerry Weißbach case 'detail.php' : 8507d101cc1SGerry Weißbach $fileName = $this->functions->getSiteName($ID, true); // 2010-09-03 - rewrite with override enabled 8519d84786fSGerry Weißbach $noDeepReplace = true; 8527d101cc1SGerry Weißbach 8539d84786fSGerry Weißbach $this->__getParamsAndDataRewritten($DATA, $PARAMS, 'id'); 8549d84786fSGerry Weißbach $ID = $this->functions->cleanID($DATA[2], null, strstr($DATA[2], 'id')); 8557d101cc1SGerry Weißbach 8567d101cc1SGerry Weißbach $newDepth = str_repeat('../', count(explode('/', $fileName))-1); 8577d101cc1SGerry Weißbach $this->__rebuildDataForNormalFiles($DATA, $PARAMS); 8589d84786fSGerry Weißbach $DATA[2] .= '.' . array_pop(explode('/', $fileName)); 8597d101cc1SGerry Weißbach 8609d84786fSGerry Weißbach $this->functions->debug->message("This is detail.php file with addParams", array($DATA, $ID, $fileName, $newDepth, $newAdditionalParameters), 2); 8617d101cc1SGerry Weißbach break; 8629d84786fSGerry Weißbach case 'doku.php' : 8637d101cc1SGerry Weißbach 8649d84786fSGerry Weißbach $noDeepReplace = false; 8659d84786fSGerry Weißbach $this->__getParamsAndDataRewritten($DATA, $PARAMS, 'id'); 8669d84786fSGerry Weißbach $ID = $this->functions->cleanID($DATA[2], null, strstr($DATA[2], 'id')); 8679d84786fSGerry Weißbach 8689d84786fSGerry Weißbach $this->functions->debug->message("Current ID to filename (doku.php): '" . wikiFN($ID) . "'", null, 2); 8699d84786fSGerry Weißbach 8709d84786fSGerry Weißbach $fileName = $this->functions->getSiteName($ID); // 2010-09-03 - rewrite with override enabled 8719d84786fSGerry Weißbach 8729d84786fSGerry Weißbach $newDepth = str_repeat('../', count(explode('/', $fileName))-1); 8739d84786fSGerry Weißbach $this->__rebuildDataForNormalFiles($DATA, $PARAMS); 8749d84786fSGerry Weißbach $DATA[2] .= '.' . array_pop(explode('/', $fileName)); 8759d84786fSGerry Weißbach 8769d84786fSGerry Weißbach $this->functions->debug->message("This is doku.php file with addParams", array($DATA, $ID, $fileName, $newDepth, $newAdditionalParameters), 2); 8779d84786fSGerry Weißbach return $this->__rebuildLink($DATA); 8789d84786fSGerry Weißbach break; 8799d84786fSGerry Weißbach 8807d101cc1SGerry Weißbach // Fetch Handling for media - rewriting everything 8817d101cc1SGerry Weißbach case 'fetch.php': 8827d101cc1SGerry Weißbach $this->__getParamsAndDataRewritten($DATA, $PARAMS, 'media'); 8837d101cc1SGerry Weißbach 8847d101cc1SGerry Weißbach $DATA[2] = str_replace('/', ':', $DATA[2]); 8857d101cc1SGerry Weißbach $ID = $this->functions->cleanID($DATA[2], null, strstr($DATA[2], 'media')); 8869d84786fSGerry Weißbach resolve_mediaid(null, $ID, $IDexists); 8877d101cc1SGerry Weißbach 8889d84786fSGerry Weißbach $DATA[2] = $this->functions->wl($ID, null, null, null, $IDexists, true); 8899d84786fSGerry Weißbach $this->__rebuildDataForNormalFiles($DATA, $PARAMS); 8907d101cc1SGerry Weißbach 8917d101cc1SGerry Weißbach $DATA['PARAMS'] = ""; 8927d101cc1SGerry Weißbach $newAdditionalParameters = array(); 8937d101cc1SGerry Weißbach 8940b4abc9fSGerry Weißbach $this->functions->debug->message("This is fetch.php file", array($DATA, $ID, $PARAMS), 2); 8957d101cc1SGerry Weißbach break; 8967d101cc1SGerry Weißbach 8977d101cc1SGerry Weißbach // default Handling for Pages 8989d84786fSGerry Weißbach case 'feed.php': 8999d84786fSGerry Weißbach return ""; // Ignore. Has no sense to export. 9009d84786fSGerry Weißbach break; 9017d101cc1SGerry Weißbach default: 9027d101cc1SGerry Weißbach if ( preg_match("%" . DOKU_BASE . "_detail/%", $DATA[2]) ) { 9037d101cc1SGerry Weißbach 9047d101cc1SGerry Weißbach // GET ID Param from origdata2 9057d101cc1SGerry Weißbach preg_match("#id=(.*?)(&|\")#i", $DATA[0], $backlinkID); 9067d101cc1SGerry Weißbach $this->__rebuildDataForNormalFiles($DATA, $PARAMS); 9077d101cc1SGerry Weißbach 9087d101cc1SGerry Weißbach $fileIDPart = isset($backlinkID[1]) && !empty($backlinkID[1]) ? $this->functions->cleanID(urldecode($backlinkID[1])) : 'detail'; 9097d101cc1SGerry Weißbach 9107d101cc1SGerry Weißbach $DATA[2] .= '/' . $fileIDPart . '.' . $this->functions->settings->fileType; // add namespace and subpage for back button and add filetype 9117d101cc1SGerry Weißbach 9127d101cc1SGerry Weißbach $noDeepReplace = false; 9137d101cc1SGerry Weißbach $fileName = $this->functions->shortenName($DATA[2]); 9147d101cc1SGerry Weißbach $newDepth = str_repeat('../', count(explode('/', $fileName))-1); 9157d101cc1SGerry Weißbach $url .= ( strstr($url, '?') ? '&' : '?' ) . 'id=' . $fileIDPart; // add id-part to URL for backlinks 9167d101cc1SGerry Weißbach 9177d101cc1SGerry Weißbach $DATA['PARAMS'] = ""; 9187d101cc1SGerry Weißbach 9197d101cc1SGerry Weißbach $this->functions->debug->message("This is something with '_detail' file", array($DATA, $backlinkID, $newDepth, $url), 2); 9207d101cc1SGerry Weißbach } else if ( preg_match("%" . DOKU_BASE . "_export/(.*?)/%", $DATA[2], $fileType) ) { 9217d101cc1SGerry Weißbach 9227d101cc1SGerry Weißbach // Fixes multiple codeblocks in one file 9237d101cc1SGerry Weißbach $this->__rebuildDataForNormalFiles($DATA, $PARAMS); 9247d101cc1SGerry Weißbach 9257d101cc1SGerry Weißbach // add the Params no matter what they are. This is export. We don't mess with other files 9267d101cc1SGerry Weißbach // adding the "/" fixes the usage of multiple codeblocks in the same namespace 9277d101cc1SGerry Weißbach $DATA[2] .= (empty( $PARAMS ) ? '' : '/' . $PARAMS) . '.'. $fileType[1]; 9287d101cc1SGerry Weißbach 9297d101cc1SGerry Weißbach $DATA['PARAMS'] = ""; 9307d101cc1SGerry Weißbach $this->functions->debug->message("This is something with '_export' file", $DATA, 2); 9317d101cc1SGerry Weißbach 9327d101cc1SGerry Weißbach } else if ( $IDexists ) { // 08/10/2010 - was page_exists($ID) - but this should do as well. 9337d101cc1SGerry Weißbach // If this is a page ... skip it! 9347d101cc1SGerry Weißbach $DATA[2] .= ( !$this->functions->settings->addParams || empty($PARAMS) ? '' : '.' . $this->functions->cleanID(preg_replace("/(=|\?|&)/", ".", $PARAMS))) . '.' . $this->functions->settings->fileType; 9357d101cc1SGerry Weißbach 9367d101cc1SGerry Weißbach // 2012-06-15 originally has an absolute path ... we might need a relative one if not in our namespace 9377d101cc1SGerry Weißbach $this->functions->debug->message("OK, this is to be absolute: " . (empty($_REQUEST['absolutePath'])?'false':'true'), null, 1); 9387d101cc1SGerry Weißbach if ( empty($_REQUEST['absolutePath']) ) 9397d101cc1SGerry Weißbach { 9407d101cc1SGerry Weißbach $DATA[2] = $this->functions->getRelativeURL($DATA[2], $currentID); 9417d101cc1SGerry Weißbach } 9427d101cc1SGerry Weißbach 9437d101cc1SGerry Weißbach $DATA[2] = $this->functions->shortenName($DATA[2]); 9447d101cc1SGerry Weißbach 9457d101cc1SGerry Weißbach // If Parameters are to be included in the filename - they must not be added twice 9467d101cc1SGerry Weißbach if ( $this->functions->settings->addParams ) $DATA['PARAMS'] = ""; 9477d101cc1SGerry Weißbach 9487d101cc1SGerry Weißbach $this->functions->debug->message("This page really exists", $DATA, 1); 9497d101cc1SGerry Weißbach 9507d101cc1SGerry Weißbach return $this->__rebuildLink($DATA); 9517d101cc1SGerry Weißbach } else { 9529d84786fSGerry Weißbach $this->__rebuildDataForNormalFiles($DATA, $PARAMS, true); 9539d84786fSGerry Weißbach $newAdditionalParameters = null; // 2014-06-27 - when using the "normal" files way we will not need any additional stuff. 9549d84786fSGerry Weißbach // This would make problems with e.g. ditaa plugin 9557d101cc1SGerry Weißbach } 9567d101cc1SGerry Weißbach 9577d101cc1SGerry Weißbach unset($newAdditionalParameters['diPlu']); 9587d101cc1SGerry Weißbach } 9597d101cc1SGerry Weißbach 9607d101cc1SGerry Weißbach $this->functions->debug->message("DATA after SWITCH CASE decision", array($DATA, $noDeepReplace, $fileName, $newDepth), 1); 9617d101cc1SGerry Weißbach 9627d101cc1SGerry Weißbach if ( $this->filewriter->canDoPDF() ) { 9637d101cc1SGerry Weißbach $this->functions->addAdditionalParametersToURL($url, $newAdditionalParameters); 9647d101cc1SGerry Weißbach $DATA[2] = $url; 9657d101cc1SGerry Weißbach unset($DATA['PARAMS']); 9667d101cc1SGerry Weißbach $url = $this->__rebuildLink($DATA, ''); 9677d101cc1SGerry Weißbach 9687d101cc1SGerry Weißbach $this->functions->debug->message("Creating PDF with URL '$url'", null, 2); 9697d101cc1SGerry Weißbach 9707d101cc1SGerry Weißbach return $url; 9717d101cc1SGerry Weißbach } 9727d101cc1SGerry Weißbach 9737d101cc1SGerry Weißbach // Create Name to save the file at 9747d101cc1SGerry Weißbach $DATA[2] = str_replace(':', '_', $DATA[2]); 9757d101cc1SGerry Weißbach $DATA[2] = $this->functions->shortenName($DATA[2]); 9767d101cc1SGerry Weißbach 9777d101cc1SGerry Weißbach 9787d101cc1SGerry Weißbach // File already loaded? 9797d101cc1SGerry Weißbach // 2010-10-23 - changes in_array from DATA[2] to $url - to check real URLs, the DATA[2] file will be checked with fileExistsInZip 9807d101cc1SGerry Weißbach if ( in_array($url, array_keys($this->fileChecked)) ) { 9817d101cc1SGerry Weißbach $DATA[2] = $this->fileChecked[$url]; 9827d101cc1SGerry Weißbach $this->functions->debug->message("File has been checked before.", array($DATA, $url), 2); 9837d101cc1SGerry Weißbach return $this->__rebuildLink($DATA); 9847d101cc1SGerry Weißbach } 9857d101cc1SGerry Weißbach 9867d101cc1SGerry Weißbach // 2010-09-03 - second check if the file is in the ZIP already. 9877d101cc1SGerry Weißbach if ( $this->filewriter->fileExistsInZip($DATA[2]) ) { 9887d101cc1SGerry Weißbach $this->functions->debug->message("File with DATA exists in ZIP.", $DATA, 3); 9897d101cc1SGerry Weißbach return $this->__rebuildLink($DATA); 9907d101cc1SGerry Weißbach } 9917d101cc1SGerry Weißbach 9927d101cc1SGerry Weißbach // 2010-10-23 - What if this is a fetch.php? than we produced an error. 9937d101cc1SGerry Weißbach // $this->fileChecked[] = $DATA[2]; 9947d101cc1SGerry Weißbach 9957d101cc1SGerry Weißbach // get tempFile and save it 9967d101cc1SGerry Weißbach $origDepth = $this->functions->settings->depth; 9977d101cc1SGerry Weißbach $this->functions->settings->depth = $newDepth; 9987d101cc1SGerry Weißbach 9997d101cc1SGerry Weißbach $tmpID = $currentID; 10002316a5cfSGerry Weißbach $tmpParent = $currentParent; 10019d84786fSGerry Weißbach $tmpFile = false; 10027d101cc1SGerry Weißbach 10032316a5cfSGerry Weißbach $currentParent = dirname($DATA[2]); 10047d101cc1SGerry Weißbach $this->functions->debug->message("Going to get the file", array($url, $noDeepReplace, $newAdditionalParameters), 2); 10057d101cc1SGerry Weißbach $tmpFile = $this->__getHTTPFile($url, $noDeepReplace, $newAdditionalParameters); 10069d84786fSGerry Weißbach $this->functions->debug->message("The getHTTPFile result is still empty", $tmpFile === false ? 'YES' : 'NO', 2); 10077d101cc1SGerry Weißbach 10082316a5cfSGerry Weißbach $currentParent = $tmpParent; 10097d101cc1SGerry Weißbach $currentID = $tmpID; 10107d101cc1SGerry Weißbach $this->functions->settings->depth = $origDepth; // 2010-09-03 - Reset depth at the very end 10117d101cc1SGerry Weißbach 10127d101cc1SGerry Weißbach if ( $tmpFile === false ) { 10137d101cc1SGerry Weißbach // Keep an potentially extra link intact 10147d101cc1SGerry Weißbach 10157d101cc1SGerry Weißbach $this->functions->debug->message("The fetched file '$url' is 'false'", null, 3); 10167d101cc1SGerry Weißbach if ( $IDexists === false ) { 10177d101cc1SGerry Weißbach $this->functions->debug->message("The file does not exist, fallback to ORIGDATA", $ORIGDATA2, 2); 10187d101cc1SGerry Weißbach $DATA[2] = $this->functions->shortenName($ORIGDATA2[2]); // get Origdata Path 10197d101cc1SGerry Weißbach } 10207d101cc1SGerry Weißbach 10217d101cc1SGerry Weißbach $this->fileChecked[$url] = $DATA[2]; // 2010-09-03 - One URL to one FileName 10227d101cc1SGerry Weißbach $link = $this->__rebuildLink($DATA); 10237d101cc1SGerry Weißbach $this->functions->debug->message("Final Link after empty file from '$url'", null, 2); 10247d101cc1SGerry Weißbach 10257d101cc1SGerry Weißbach return $link; 10267d101cc1SGerry Weißbach } 10277d101cc1SGerry Weißbach 10287d101cc1SGerry Weißbach $this->functions->debug->message("The fetched file looks good.", $tmpFile, 1); 1029281ed919SGerry Weißbach $dirname = dirname($DATA[2]); 10307d101cc1SGerry Weißbach 10317d101cc1SGerry Weißbach // If a Filename was given that does not comply to the original name, us this one! 103284d65497SGerry Weißbach // 2014-02-28 But only if we are on PDF Mode. Does this produce any other Problems? 103384d65497SGerry Weißbach if ( $this->filewriter->canDoPDF() && !empty($tmpFile[1]) && !strstr($DATA[2], $tmpFile[1]) ) { 1034281ed919SGerry Weißbach $DATA[2] = $dirname . '/' . $tmpFile[1]; 10357d101cc1SGerry Weißbach } 10367d101cc1SGerry Weißbach 103793b3a486SGerry Weißbach // Custom extension if not set already 1038*569e317aSGerry Weißbach if ( !empty($tmpFile[2]) && !preg_match("$\.{$tmpFile[2]}$", $DATA[2]) ) { 10392316a5cfSGerry Weißbach $DATA[2] .= '.' . $tmpFile[2]; 10402316a5cfSGerry Weißbach } 10412316a5cfSGerry Weißbach 10427d101cc1SGerry Weißbach // Add to zip 10437d101cc1SGerry Weißbach $this->fileChecked[$url] = $DATA[2]; // 2010-09-03 - One URL to one FileName 10447d101cc1SGerry Weißbach 10457d101cc1SGerry Weißbach $status = $this->filewriter->__addFileToZip($tmpFile[0], $DATA[2]); 10467d101cc1SGerry Weißbach @unlink($tmpFile[0]); 10477d101cc1SGerry Weißbach 10487d101cc1SGerry Weißbach $newURL = $this->__rebuildLink($DATA); 10497d101cc1SGerry Weißbach $this->functions->debug->message("Returning final Link to document: '$newURL'", null, 2); 10507d101cc1SGerry Weißbach 10517d101cc1SGerry Weißbach return $newURL; 10527d101cc1SGerry Weißbach } 10537d101cc1SGerry Weißbach 10547d101cc1SGerry Weißbach /** 10557d101cc1SGerry Weißbach * build the new link to be put in place for the donwloaded site 10567d101cc1SGerry Weißbach **/ 10577d101cc1SGerry Weißbach function __rebuildLink($DATA, $DEPTH = null) { 10582316a5cfSGerry Weißbach global $currentID, $currentParent; 10597d101cc1SGerry Weißbach 10607d101cc1SGerry Weißbach // depth is set, skip this one 10617d101cc1SGerry Weißbach if ( is_null( $DEPTH ) ) $DEPTH = $this->functions->settings->depth; 106284d65497SGerry Weißbach $DATA[2] .= ( !empty( $DATA['PARAMS']) && $this->functions->settings->addParams? '?' . $DATA['PARAMS'] : '' ) . ( !empty( $DATA['ANCHOR'] ) ? '#' . $DATA['ANCHOR'] : '' ); 10637d101cc1SGerry Weißbach 106467f4f6e5SGerry Weißbach $intermediateURL = $DEPTH . $DATA[2]; 106567f4f6e5SGerry Weißbach 10662316a5cfSGerry Weißbach $this->functions->debug->message("currentID: '{$currentID}'; currentParent: '{$currentParent}'", null, 1); 10672316a5cfSGerry Weißbach 10682316a5cfSGerry Weißbach if ( preg_match("#^(\.\./)+#", $intermediateURL) ) { 10692316a5cfSGerry Weißbach // Experimental 10702316a5cfSGerry Weißbach $intermediateURL = $this->functions->getRelativeURL($intermediateURL, $currentParent); 10712316a5cfSGerry Weißbach $this->functions->debug->message("relative URL is: '{$relativeURL}'", null, 1); 10722316a5cfSGerry Weißbach } 10732316a5cfSGerry Weißbach 10742316a5cfSGerry Weißbach/* 10755ae1a484SGerry Weißbach // Check if the URL has a ../../something/somethingelse 10765ae1a484SGerry Weißbach // and basically goes back to our current page or something in parallel 10775ae1a484SGerry Weißbach // 1) remove all ../ at begining 10782316a5cfSGerry Weißbach 10792316a5cfSGerry Weißbach $this->functions->debug->message("currentID: '{$currentID}'", null, 1); 10805ae1a484SGerry Weißbach $checkURL = preg_replace("#^(\.\./)+#", '', $intermediateURL); 10815ae1a484SGerry Weißbach if ( $checkURL != $intermediateURL ) { 10822316a5cfSGerry Weißbach $this->functions->debug->message("Found ../: '$checkURL' / currentIDPart: '{$currentIDPart}'", null, 2); 10835ae1a484SGerry Weißbach 10845ae1a484SGerry Weißbach // 2) check if the URLs next parts match the current ENS to all NS parts of the current ID 10855ae1a484SGerry Weißbach // $this->functions->debug->message("Found ENS: '{$this->functions->settings->exportNamespace}', currentID: {$currentID}'", null, 2); 10865ae1a484SGerry Weißbach $currentIDPart = preg_replace("#^{$this->functions->settings->exportNamespace}/#", "", str_replace(':', '/', getNS($currentID) . '/')); 10875ae1a484SGerry Weißbach 10885ae1a484SGerry Weißbach if ( ($newURL = preg_replace("#^{$currentIDPart}#", "./", $checkURL)) != $checkURL ) { 10895ae1a484SGerry Weißbach // 3) if so, remove these parts 10905ae1a484SGerry Weißbach $intermediateURL = $newURL; 10915ae1a484SGerry Weißbach $this->functions->debug->message("Found ./ URL: '$newURL'", null, 2); 10925ae1a484SGerry Weißbach } 10935ae1a484SGerry Weißbach } 10942316a5cfSGerry Weißbach*/ 109567f4f6e5SGerry Weißbach $newURL = $DATA[1] == 'url' ? $DATA[1] . '(' . $intermediateURL . ')' : $DATA[1] . '="' . $intermediateURL . '"'; 10967c726ed8SGerry Weißbach $this->functions->debug->message("Re-created URL: '$newURL'", $DEPTH, 2); 10977d101cc1SGerry Weißbach 10987d101cc1SGerry Weißbach return $newURL; 10997d101cc1SGerry Weißbach } 11007d101cc1SGerry Weißbach 11017d101cc1SGerry Weißbach 11027d101cc1SGerry Weißbach /** 11037d101cc1SGerry Weißbach * remove an old zip file 11047d101cc1SGerry Weißbach **/ 11057d101cc1SGerry Weißbach function __removeOldZip( $FILENAMEID=null, $checkForMore=true ) { 11067d101cc1SGerry Weißbach global $INFO; 11077d101cc1SGerry Weißbach global $conf; 11087d101cc1SGerry Weißbach 11097d101cc1SGerry Weißbach $returnValue = true; 11107d101cc1SGerry Weißbach 11117d101cc1SGerry Weißbach if ( empty($FILENAMEID) ) { 11127d101cc1SGerry Weißbach $FILENAMEID = $this->functions->settings->origZipFile; 11137d101cc1SGerry Weißbach } 11147d101cc1SGerry Weißbach 11158da901a0SGerry Weißbach if ( !file_exists(mediaFN($FILENAMEID)) ) { 11168da901a0SGerry Weißbach $returnValue = true; 11178da901a0SGerry Weißbach } else { 11188da901a0SGerry Weißbach 11197d101cc1SGerry Weißbach require_once( DOKU_INC . 'inc/media.php'); 11207d101cc1SGerry Weißbach if ( !media_delete($FILENAMEID, $INFO['perm']) ) { 11217d101cc1SGerry Weißbach $returnValue = false; 11227d101cc1SGerry Weißbach } 11237d101cc1SGerry Weißbach } 11247d101cc1SGerry Weißbach 11257d101cc1SGerry Weißbach if ( $checkForMore ) { 11267d101cc1SGerry Weißbach // Try to remove more files. 11277d101cc1SGerry Weißbach $ns = getNS($FILENAMEID); 11287d101cc1SGerry Weißbach $fn = $this->functions->getSpecialExportFileName(noNS($FILENAMEID), '.+'); 11297d101cc1SGerry Weißbach 11307d101cc1SGerry Weißbach $data = array(); 11317d101cc1SGerry Weißbach search($data, $conf['mediadir'], 'search_media', array('pattern' => "/$fn$/i"), $ns); 11327d101cc1SGerry Weißbach 11337d101cc1SGerry Weißbach if ( count($data > 0) ) { 11347d101cc1SGerry Weißbach 11357d101cc1SGerry Weißbach // 30 Minuten Cache Zeit 1136f8fd18e7SGerry Weißbach $cache = $this->functions->settings->cachetime; 11377d101cc1SGerry Weißbach foreach ( $data as $media ) { 11387d101cc1SGerry Weißbach 11397d101cc1SGerry Weißbach //decide if has to be deleted needed: 11407d101cc1SGerry Weißbach if( $media['mtime'] < time()-$cache) { 11417d101cc1SGerry Weißbach $this->__removeOldZip($media['id'], false); 11427d101cc1SGerry Weißbach } 11437d101cc1SGerry Weißbach } 11447d101cc1SGerry Weißbach } 11457d101cc1SGerry Weißbach 11467d101cc1SGerry Weißbach } 11477d101cc1SGerry Weißbach 11487d101cc1SGerry Weißbach return $returnValue; 11497d101cc1SGerry Weißbach } 11507d101cc1SGerry Weißbach 11517d101cc1SGerry Weißbach /** 11527d101cc1SGerry Weißbach * if confrewrite is set to internal rewrite, use this function - taken from a DW renderer 11537d101cc1SGerry Weißbach **/ 11547d101cc1SGerry Weißbach function __getInternalRewriteURL($url) { 11557d101cc1SGerry Weißbach global $conf; 11567d101cc1SGerry Weißbach 11577d101cc1SGerry Weißbach //construct page id from request URI 11587d101cc1SGerry Weißbach if( $conf['userewrite'] != 2) { return $url; } 11597d101cc1SGerry Weißbach 11607d101cc1SGerry Weißbach //get the script URL 11617d101cc1SGerry Weißbach if($conf['basedir']) { 11627d101cc1SGerry Weißbach $relpath = ''; 11637d101cc1SGerry Weißbach $script = $conf['basedir'].$relpath.basename($_SERVER['SCRIPT_FILENAME']); 11647d101cc1SGerry Weißbach } elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){ 11657d101cc1SGerry Weißbach $script = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','', 11667d101cc1SGerry Weißbach $_SERVER['SCRIPT_FILENAME']); 11677d101cc1SGerry Weißbach $script = '/'.$script; 11687d101cc1SGerry Weißbach }else{ 11697d101cc1SGerry Weißbach $script = $_SERVER['SCRIPT_NAME']; 11707d101cc1SGerry Weißbach } 11717d101cc1SGerry Weißbach 11727d101cc1SGerry Weißbach //clean script and request (fixes a windows problem) 11737d101cc1SGerry Weißbach $script = preg_replace('/\/\/+/','/',$script); 11747d101cc1SGerry Weißbach $request = preg_replace('/\/\/+/','/',$url); 11757d101cc1SGerry Weißbach 11767d101cc1SGerry Weißbach //remove script URL and Querystring to gain the id 11777d101cc1SGerry Weißbach if(preg_match('/^'.preg_quote($script,'/').'(.*)/',$request, $match)){ 11787d101cc1SGerry Weißbach $id = preg_replace ('/\?.*/','',$match[1]); 11797d101cc1SGerry Weißbach } 11807d101cc1SGerry Weißbach $id = urldecode($id); 11817d101cc1SGerry Weißbach //strip leading slashes 11827d101cc1SGerry Weißbach $id = preg_replace('!^/+!','',$id); 11837d101cc1SGerry Weißbach 11847d101cc1SGerry Weißbach return $id; 11857d101cc1SGerry Weißbach } 11867d101cc1SGerry Weißbach 11877d101cc1SGerry Weißbach /** 11887d101cc1SGerry Weißbach * rewrite parameter calls 11897d101cc1SGerry Weißbach **/ 11907d101cc1SGerry Weißbach function __getParamsAndDataRewritten(&$DATA, &$PARAMS, $IDKEY='id') { 11917d101cc1SGerry Weißbach 11927d101cc1SGerry Weißbach $PARRAY = explode('&', str_replace('&', '&', $PARAMS) ); 11939d84786fSGerry Weißbach $PARAMS = array(); 11947d101cc1SGerry Weißbach 11957d101cc1SGerry Weißbach foreach ( $PARRAY as $item ) { 11967d101cc1SGerry Weißbach list($key, $value) = explode('=', $item, 2); 11977d101cc1SGerry Weißbach if ( empty($key) || empty($value) ) 11987d101cc1SGerry Weißbach continue; 11997d101cc1SGerry Weißbach 12007d101cc1SGerry Weißbach if ( strtolower(trim($key)) == $IDKEY ) { 12017d101cc1SGerry Weißbach $DATA[2] = preg_replace("%^" . DOKU_BASE . "%", "", $value); 12027d101cc1SGerry Weißbach continue; 12037d101cc1SGerry Weißbach } 12047d101cc1SGerry Weißbach 12059d84786fSGerry Weißbach $PARAMS[] = "$key=$value"; 12067d101cc1SGerry Weißbach } 12077d101cc1SGerry Weißbach 12089d84786fSGerry Weißbach $PARAMS = implode('&', $PARAMS); 12097d101cc1SGerry Weißbach } 12107d101cc1SGerry Weißbach 12117d101cc1SGerry Weißbach /** 12127d101cc1SGerry Weißbach * rewrite detail.php calls 12137d101cc1SGerry Weißbach **/ 12149d84786fSGerry Weißbach function __rebuildDataForNormalFiles(&$DATA, &$PARAMS, $addHash=false) { 12157d101cc1SGerry Weißbach $PARTS = explode('.', $DATA[2]); 12167d101cc1SGerry Weißbach if ( count($PARTS) > 1 ) { 12177d101cc1SGerry Weißbach $EXT = '.' . array_pop($PARTS); 12187d101cc1SGerry Weißbach } 12197d101cc1SGerry Weißbach 12209d84786fSGerry Weißbach $internalParams = $PARAMS = preg_replace("/(=|\?|&)/", ".", $PARAMS); 12219d84786fSGerry Weißbach 12229d84786fSGerry Weißbach // add anyways - if on overridde 12239d84786fSGerry Weißbach if ( !$this->functions->settings->addParams && !empty($PARAMS) && $addHash ) { 12249d84786fSGerry Weißbach $internalParams = md5($PARAMS); 12259d84786fSGerry Weißbach } else if ( !$this->functions->settings->addParams ){ 12269d84786fSGerry Weißbach $internalParams = null; 12279d84786fSGerry Weißbach } 12289d84786fSGerry Weißbach 12299d84786fSGerry Weißbach $DATA[2] = implode('.', $PARTS) . ( empty($internalParams) ? '' : '.' . $this->functions->cleanID($internalParams)) . ( $EXT == '.php' ? '.' . $this->functions->settings->fileType : $EXT ); 12307d101cc1SGerry Weißbach $DATA[2] = preg_replace("/\.+/", ".", $DATA[2]); 12319d84786fSGerry Weißbach $this->functions->debug->message("Rebuilding Data for normal file.", $DATA[2], 1); 12327d101cc1SGerry Weißbach } 12337d101cc1SGerry Weißbach 12347d101cc1SGerry Weißbach 12357d101cc1SGerry Weißbach 12367d101cc1SGerry Weißbach 12377d101cc1SGerry Weißbach /* 12387d101cc1SGerry Weißbach * Clean JS and CSS cache files 12397d101cc1SGerry Weißbach */ 12407d101cc1SGerry Weißbach function cleanCacheFiles() { 12417d101cc1SGerry Weißbach 12427d101cc1SGerry Weißbach $_SERVER['HTTP_HOST'] = preg_replace("/:?\d+$/", '', $_SERVER['HTTP_HOST']); 12437d101cc1SGerry Weißbach $cache = getCacheName('scripts'.$_SERVER['HTTP_HOST'].'-siteexport-js-'.$_SERVER['SERVER_PORT'],'.js'); 12447d101cc1SGerry Weißbach $this->unlinkIfExists($cache); 12457d101cc1SGerry Weißbach 12467d101cc1SGerry Weißbach $tpl = trim(preg_replace('/[^\w-]+/','',$_REQUEST['template'])); 12477d101cc1SGerry Weißbach if($tpl) 12487d101cc1SGerry Weißbach { 12497d101cc1SGerry Weißbach $tplinc = DOKU_INC.'lib/tpl/'.$tpl.'/'; 12507d101cc1SGerry Weißbach $tpldir = DOKU_BASE.'lib/tpl/'.$tpl.'/'; 12517d101cc1SGerry Weißbach } else { 12527d101cc1SGerry Weißbach $tplinc = DOKU_TPLINC; 12537d101cc1SGerry Weißbach $tpldir = DOKU_TPL; 12547d101cc1SGerry Weißbach } 12557d101cc1SGerry Weißbach 12567d101cc1SGerry Weißbach // The generated script depends on some dynamic options 12577d101cc1SGerry Weißbach $cache = getCacheName('styles'.$_SERVER['HTTP_HOST'].'-siteexport-js-'.$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$style,'.css'); 12587d101cc1SGerry Weißbach $this->unlinkIfExists($cache); 12597d101cc1SGerry Weißbach } 12607d101cc1SGerry Weißbach 12617d101cc1SGerry Weißbach function unlinkIfExists($cache) { 12627d101cc1SGerry Weißbach if ( file_exists($cache) ) { 12637d101cc1SGerry Weißbach @unlink($cache); 12647d101cc1SGerry Weißbach if(function_exists('gzopen')) @unlink("$cache.gz"); 12657d101cc1SGerry Weißbach } 12667d101cc1SGerry Weißbach } 12677d101cc1SGerry Weißbach 12687d101cc1SGerry Weißbach // Private unset function 12697d101cc1SGerry Weißbach private function clear(&$variable) 12707d101cc1SGerry Weißbach { 12717d101cc1SGerry Weißbach if ( isset($variable) ) 12727d101cc1SGerry Weißbach { 12737d101cc1SGerry Weißbach unset($variable); 12747d101cc1SGerry Weißbach } 12757d101cc1SGerry Weißbach } 12767d101cc1SGerry Weißbach}