From 6854cb3f4d8219cf1829e32122eb2502a916eae9 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 1 Feb 2020 09:05:48 +0100 Subject: initial checkin --- plugins/dokuwiki/inc/init.php | 367 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100644 plugins/dokuwiki/inc/init.php (limited to 'plugins/dokuwiki/inc/init.php') diff --git a/plugins/dokuwiki/inc/init.php b/plugins/dokuwiki/inc/init.php new file mode 100644 index 0000000..272f759 --- /dev/null +++ b/plugins/dokuwiki/inc/init.php @@ -0,0 +1,367 @@ + 'pages', + 'olddir' => 'attic', + 'mediadir' => 'media', + 'metadir' => 'meta', + 'cachedir' => 'cache', + 'lockdir' => 'locks'); + + foreach($paths as $c => $p){ + if(empty($conf[$c])) $conf[$c] = $conf['savedir'].'/'.$p; + $conf[$c] = init_path($conf[$c]); + if(empty($conf[$c])) nice_die("The $c does not exist, isn't accessable or writable. + You should check your config and permission settings. + Or maybe you want to run the + installer?"); + } + + // path to old changelog only needed for upgrading + $conf['changelog_old'] = init_path((isset($conf['changelog']))?($conf['changelog']):($conf['savedir'].'/changes.log')); + if ($conf['changelog_old']=='') { unset($conf['changelog_old']); } + // hardcoded changelog because it is now a cache that lives in meta + $conf['changelog'] = $conf['metadir'].'/_dokuwiki.changes'; +} + +/** + * Checks the existance of certain files and creates them if missing. + */ +function init_files(){ + global $conf; + + $files = array( $conf['cachedir'].'/word.idx', + $conf['cachedir'].'/page.idx', + $conf['cachedir'].'/index.idx'); + + foreach($files as $file){ + if(!@file_exists($file)){ + $fh = @fopen($file,'a'); + if($fh){ + fclose($fh); + if($conf['fperm']) chmod($file, $conf['fperm']); + }else{ + nice_die("$file is not writable. Check your permissions settings!"); + } + } + } +} + +/** + * Returns absolute path + * + * This tries the given path first, then checks in DOKU_INC. + * Check for accessability on directories as well. + * + * @author Andreas Gohr + */ +function init_path($path){ + // check existance + $p = realpath($path); + if(!@file_exists($p)){ + $p = realpath(DOKU_INC.$path); + if(!@file_exists($p)){ + return ''; + } + } + + // check writability + if(!@is_writable($p)){ + return ''; + } + + // check accessability (execute bit) for directories + if(@is_dir($p) && !@file_exists("$p/.")){ + return ''; + } + + return $p; +} + +/** + * Sets the internal config values fperm and dperm which, when set, + * will be used to change the permission of a newly created dir or + * file with chmod. Considers the influence of the system's umask + * setting the values only if needed. + */ +function init_creationmodes(){ + global $conf; + + // Legacy support for old umask/dmask scheme + unset($conf['dmask']); + unset($conf['fmask']); + unset($conf['umask']); + unset($conf['fperm']); + unset($conf['dperm']); + + // get system umask, fallback to 0 if none available + $umask = @umask(); + if(!$umask) $umask = 0000; + + // check what is set automatically by the system on file creation + // and set the fperm param if it's not what we want + $auto_fmode = 0666 & ~$umask; + if($auto_fmode != $conf['fmode']) $conf['fperm'] = $conf['fmode']; + + // check what is set automatically by the system on file creation + // and set the dperm param if it's not what we want + $auto_dmode = $conf['dmode'] & ~$umask; + if($auto_dmode != $conf['dmode']) $conf['dperm'] = $conf['dmode']; +} + +/** + * remove magic quotes recursivly + * + * @author Andreas Gohr + */ +function remove_magic_quotes(&$array) { + foreach (array_keys($array) as $key) { + if (is_array($array[$key])) { + remove_magic_quotes($array[$key]); + }else { + $array[$key] = stripslashes($array[$key]); + } + } +} + +/** + * Returns the full absolute URL to the directory where + * DokuWiki is installed in (includes a trailing slash) + * + * @author Andreas Gohr + */ +function getBaseURL($abs=false){ + global $conf; + //if canonical url enabled always return absolute + if($conf['canonical']) $abs = true; + + if($conf['basedir']){ + $dir = $conf['basedir'].'/'; + }elseif(substr($_SERVER['SCRIPT_NAME'],-4) == '.php'){ + $dir = dirname($_SERVER['SCRIPT_NAME']).'/'; + }elseif(substr($_SERVER['PHP_SELF'],-4) == '.php'){ + $dir = dirname($_SERVER['PHP_SELF']).'/'; + }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){ + $dir = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','', + $_SERVER['SCRIPT_FILENAME']); + $dir = dirname('/'.$dir).'/'; + }else{ + $dir = './'; //probably wrong + } + + $dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour + $dir = preg_replace('#//+#','/',$dir); + + //handle script in lib/exe dir + $dir = preg_replace('!lib/exe/$!','',$dir); + + //handle script in lib/plugins dir + $dir = preg_replace('!lib/plugins/.*$!','',$dir); + + //finish here for relative URLs + if(!$abs) return $dir; + + //use config option if available + if($conf['baseurl']) return $conf['baseurl'].$dir; + + //split hostheader into host and port + list($host,$port) = explode(':',$_SERVER['HTTP_HOST']); + if(!$port) $port = $_SERVER['SERVER_PORT']; + if(!$port) $port = 80; + + // see if HTTPS is enabled - apache leaves this empty when not available, + // IIS sets it to 'off', 'false' and 'disabled' are just guessing + if (preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){ + $proto = 'http://'; + if ($port == '80') { + $port=''; + } + }else{ + $proto = 'https://'; + if ($port == '443') { + $port=''; + } + } + + if($port) $port = ':'.$port; + + return $proto.$host.$port.$dir; +} + +/** + * Append a PHP extension to a given file and adds an exit call + * + * This is used to migrate some old configfiles. An added PHP extension + * ensures the contents are not shown to webusers even if .htaccess files + * do not work + * + * @author Jan Decaluwe + */ +function scriptify($file) { + // checks + if (!is_readable($file)) { + return; + } + $fn = $file.'.php'; + if (@file_exists($fn)) { + return; + } + $fh = fopen($fn, 'w'); + if (!$fh) { + nice_die($fn.' is not writable. Check your permission settings!'); + } + // write php exit hack first + fwrite($fh, "# $fn\n"); + fwrite($fh, '# '."\n"); + fwrite($fh, "# Don't modify the lines above\n"); + fwrite($fh, "#\n"); + // copy existing lines + $lines = file($file); + foreach ($lines as $line){ + fwrite($fh, $line); + } + fclose($fh); + //try to rename the old file + io_rename($file,"$file.old"); +} + +/** + * print a nice message even if no styles are loaded yet. + */ +function nice_die($msg){ + echo<< + + DokuWiki Setup Error + +
+

DokuWiki Setup Error

+

$msg

+
+ + +EOT; + exit; +} + + +//Setup VIM: ex: et ts=2 enc=utf-8 : -- cgit v1.2.3-70-g09d2