From ed7b5f0908941f1bacef7e7c3a02c106a42cd5cc Mon Sep 17 00:00:00 2001 From: andi Date: Sat, 19 Feb 2005 11:20:55 +0100 Subject: added init.php - may have broken something! (related to #153) darcs-hash:20050219102055-9977f-575d654e742934c911ffab855d82aa91f198b5cf.gz --- inc/auth.php | 15 +++---- inc/common.php | 128 ++++++++++----------------------------------------------- inc/format.php | 15 +++---- inc/html.php | 47 +++++++++++---------- inc/init.php | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ inc/io.php | 7 ++-- inc/mail.php | 7 ++-- inc/parser.php | 15 +++---- inc/search.php | 5 ++- inc/utf8.php | 2 +- 10 files changed, 193 insertions(+), 158 deletions(-) create mode 100644 inc/init.php (limited to 'inc') diff --git a/inc/auth.php b/inc/auth.php index 0266899a8..094319377 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -1,4 +1,4 @@ - */ - require_once("inc/common.php"); - require_once("inc/io.php"); - require_once("inc/blowfish.php"); - require_once("inc/mail.php"); + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + require_once(DOKU_INC.'inc/common.php'); + require_once(DOKU_INC.'inc/io.php'); + require_once(DOKU_INC.'inc/blowfish.php'); + require_once(DOKU_INC.'inc/mail.php'); // load the the auth functions - require_once('inc/auth_'.$conf['authtype'].'.php'); + require_once(DOKU_INC.'inc/auth_'.$conf['authtype'].'.php'); // some ACL level defines define('AUTH_NONE',0); @@ -324,7 +325,7 @@ function auth_sendPassword($user,$password){ if(!$userinfo['mail']) return false; $text = rawLocale('password'); - $text = str_replace('@DOKUWIKIURL@',getBaseURL(true),$text); + $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text); $text = str_replace('@FULLNAME@',$userinfo['name'],$text); $text = str_replace('@LOGIN@',$user,$text); $text = str_replace('@PASSWORD@',$password,$text); diff --git a/inc/common.php b/inc/common.php index 2e146d485..24e9583f3 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1,4 +1,4 @@ - */ - require_once("conf/dokuwiki.php"); - require_once("inc/io.php"); - require_once('inc/utf8.php'); - require_once('inc/mail.php'); - - //set up error reporting to sane values - error_reporting(E_ALL ^ E_NOTICE); - - //make session rewrites XHTML compliant - ini_set('arg_separator.output', '&'); - - //init session - session_name("DokuWiki"); - session_start(); - - //kill magic quotes - if (get_magic_quotes_gpc()) { - if (!empty($_GET)) remove_magic_quotes($_GET); - if (!empty($_POST)) remove_magic_quotes($_POST); - if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE); - if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST); - if (!empty($_SESSION)) remove_magic_quotes($_SESSION); - ini_set('magic_quotes_gpc', 0); - } - set_magic_quotes_runtime(0); - ini_set('magic_quotes_sybase',0); - - //disable gzip if not available - if($conf['usegzip'] && !function_exists('gzopen')){ - $conf['usegzip'] = 0; - } - - //remember original umask - $conf['oldumask'] = umask(); - - //make absolute mediaweb - if(!preg_match('#^(https?://|/)#i',$conf['mediaweb'])){ - $conf['mediaweb'] = getBaseURL().$conf['mediaweb']; - } - -/** - * 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; - - $dir = dirname($_SERVER['PHP_SELF']).'/'; - - $dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour - $dir = preg_replace('#//+#','/',$dir); - - //finish here for relative URLs - if(!$abs) return $dir; - - $port = ':'.$_SERVER['SERVER_PORT']; - //remove port from hostheader as sent by IE - $host = preg_replace('/:.*$/','',$_SERVER['HTTP_HOST']); - - // 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 ($_SERVER['SERVER_PORT'] == '80') { - $port=''; - } - }else{ - $proto = 'https://'; - if ($_SERVER['SERVER_PORT'] == '443') { - $port=''; - } - } - - return $proto.$host.$port.$dir; -} + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + require_once(DOKU_INC.'conf/dokuwiki.php'); + require_once(DOKU_INC.'inc/io.php'); + require_once(DOKU_INC.'inc/utf8.php'); + require_once(DOKU_INC.'inc/mail.php'); /** * Return info about the current document as associative @@ -257,20 +168,23 @@ function idfilter($id,$ue=true){ } /** - * This builds a link to a wikipage (using getBaseURL) + * This builds a link to a wikipage * * @author Andreas Gohr */ -function wl($id='',$more='',$script='doku.php',$canonical=false){ +function wl($id='',$more='',$abs=false){ global $conf; $more = str_replace(',','&',$more); $id = idfilter($id); - $xlink = getBaseURL($canonical); + if($abs){ + $xlink = DOKU_URL; + }else{ + $xlink = DOKU_BASE; + } if(!$conf['userewrite']){ - $xlink .= $script; - $xlink .= '?id='.$id; + $xlink .= DOKU_SCRIPT.'?id='.$id; if($more) $xlink .= '&'.$more; }else{ $xlink .= $id; @@ -283,12 +197,14 @@ function wl($id='',$more='',$script='doku.php',$canonical=false){ /** * Just builds a link to a script * + * @todo maybe obsolete * @author Andreas Gohr */ function script($script='doku.php'){ - $link = getBaseURL(); - $link .= $script; - return $link; +# $link = getBaseURL(); +# $link .= $script; +# return $link; + return DOKU_BASE.DOKU_SCRIPT; } /** @@ -825,14 +741,14 @@ function notify($id,$rev="",$summary=""){ $text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text); $text = str_replace('@IPADDRESS@',$_SERVER['REMOTE_ADDR'],$text); $text = str_replace('@HOSTNAME@',gethostbyaddr($_SERVER['REMOTE_ADDR']),$text); - $text = str_replace('@NEWPAGE@',wl($id,'','doku.php',true),$text); - $text = str_replace('@DOKUWIKIURL@',getBaseURL(true),$text); + $text = str_replace('@NEWPAGE@',wl($id,'',true),$text); + $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text); $text = str_replace('@SUMMARY@',$summary,$text); $text = str_replace('@USER@',$_SERVER['REMOTE_USER'],$text); if($rev){ $subject = $lang['mail_changed'].' '.$id; - $text = str_replace('@OLDPAGE@',wl($id,"rev=$rev",'doku.php',true),$text); + $text = str_replace('@OLDPAGE@',wl($id,"rev=$rev",true),$text); require_once("inc/DifferenceEngine.php"); $df = new Diff(split("\n",rawWiki($id,$rev)), split("\n",rawWiki($id))); diff --git a/inc/format.php b/inc/format.php index 44d39e22f..4a5415ab4 100644 --- a/inc/format.php +++ b/inc/format.php @@ -1,4 +1,4 @@ - */ - require_once("conf/dokuwiki.php"); - require_once("inc/common.php"); + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + require_once(DOKU_INC.'conf/dokuwiki.php'); + require_once(DOKU_INC.'inc/common.php'); /** @@ -248,7 +249,7 @@ function format_link_interwiki($link){ $iwlinks = file('conf/interwiki.conf'); //add special case 'this' - $iwlinks[] = 'this '.getBaseURL(true).'{NAME}'; + $iwlinks[] = 'this '.DOKU_URL.'{NAME}'; //go through iwlinks and find URL for wiki foreach ($iwlinks as $line){ @@ -266,13 +267,13 @@ function format_link_interwiki($link){ //if ico exists set additonal style if(@file_exists('interwiki/'.$ico.'.png')){ - $link['style']='background: transparent url('.getBaseURL().'interwiki/'.$ico.'.png) 0px 1px no-repeat;'; + $link['style']='background: transparent url('.DOKU_BASE.'interwiki/'.$ico.'.png) 0px 1px no-repeat;'; }elseif(@file_exists('interwiki/'.$ico.'.gif')){ - $link['style']='background: transparent url('.getBaseURL().'interwiki/'.$ico.'.gif) 0px 1px no-repeat;'; + $link['style']='background: transparent url('.DOKU_BASE.'interwiki/'.$ico.'.gif) 0px 1px no-repeat;'; } //do we stay at the same server? Use local target - if( strpos($url,getBaseURL(true)) === 0 ){ + if( strpos($url,DOKU_URL) === 0 ){ $link['target'] = $conf['target']['wiki']; } diff --git a/inc/html.php b/inc/html.php index b21ab4e57..d848f89b4 100644 --- a/inc/html.php +++ b/inc/html.php @@ -1,4 +1,4 @@ - */ - include_once("inc/format.php"); + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + require_once(DOKU_INC.'inc/format.php'); /** * Convenience function to quickly build a wikilink @@ -188,13 +189,13 @@ function html_head(){ <?=$ID?> [<?=$conf['title']?>] - - - + + + - - + + var alertText = ''; var notSavedYet = ''; - var baseURL = ''; + var DOKU_BASE = ''; - + @@ -246,13 +247,11 @@ function html_btn($name,$id,$akey,$params,$method='get'){ $id = idfilter($id,false); //make nice URLs even for buttons - $link = getBaseURL().'/'; - $link = preg_replace('#//$#','/',$link); if(!$conf['userewrite']){ - $script = $link.'doku.php'; + $script = DOKU_BASE.DOKUSCRIPT; $params['id'] = $id; }else{ - $script = $link.$id; + $script = DOKU_BASE.$id; } $ret .= '
'; @@ -529,7 +528,7 @@ function html_hilight($html,$query){ * @author Andreas Gohr */ function html_search(){ - require_once("inc/search.php"); + require_once(DOKU_INC.'inc/search.php'); global $conf; global $QUERY; global $ID; @@ -648,7 +647,7 @@ function html_revisions(){ print ') '; print ''; - print ''; + print ''; print ''; print ''; } @@ -686,7 +685,7 @@ function html_recent(){ * @author Andreas Gohr */ function html_index($ns){ - require_once("inc/search.php"); + require_once(DOKU_INC.'inc/search.php'); global $conf; global $ID; $dir = $conf['datadir']; @@ -814,7 +813,7 @@ function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ * @author Andreas Gohr */ function html_backlinks(){ - require_once("inc/search.php"); + require_once(DOKU_INC.'inc/search.php'); global $ID; global $conf; @@ -847,7 +846,7 @@ function html_backlinks(){ * @author Andreas Gohr */ function html_diff($text='',$intro=true){ - require_once("inc/DifferenceEngine.php"); + require_once(DOKU_INC.'inc/DifferenceEngine.php'); global $ID; global $REV; global $lang; @@ -1136,11 +1135,15 @@ function html_debug(){ print_r($cnf); print ''; - print 'abs baseURL:
';
-  print getBaseURL(true);
+  print 'DOKU_BASE:
';
+  print DOKU_BASE;
+  print '
'; + + print 'abs DOKU_BASE:
';
+  print DOKU_URL;
   print '
'; - print 'rel baseURL:
';
+  print 'rel DOKU_BASE:
';
   print dirname($_SERVER['PHP_SELF']).'/';
   print '
'; diff --git a/inc/init.php b/inc/init.php new file mode 100644 index 000000000..9314008e1 --- /dev/null +++ b/inc/init.php @@ -0,0 +1,110 @@ + + */ +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; + + $dir = dirname($_SERVER['PHP_SELF']).'/'; + + $dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour + $dir = preg_replace('#//+#','/',$dir); + + //finish here for relative URLs + if(!$abs) return $dir; + + $port = ':'.$_SERVER['SERVER_PORT']; + //remove port from hostheader as sent by IE + $host = preg_replace('/:.*$/','',$_SERVER['HTTP_HOST']); + + // 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 ($_SERVER['SERVER_PORT'] == '80') { + $port=''; + } + }else{ + $proto = 'https://'; + if ($_SERVER['SERVER_PORT'] == '443') { + $port=''; + } + } + + return $proto.$host.$port.$dir; +} + + +?> diff --git a/inc/io.php b/inc/io.php index dfdbc4e1c..6586a554e 100644 --- a/inc/io.php +++ b/inc/io.php @@ -1,4 +1,4 @@ - */ - require_once("inc/common.php"); - require_once("inc/parser.php"); + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + require_once(DOKU_INC.'inc/common.php'); + require_once(DOKU_INC.'inc/parser.php'); /** * Returns the parsed text from the given sourcefile. Uses cache diff --git a/inc/mail.php b/inc/mail.php index b66678b02..451fa6cb6 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -1,4 +1,4 @@ - */ -require_once('inc/utf8.php'); + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + require_once(DOKU_INC.'inc/utf8.php'); -define('MAILHEADER_EOL',"\n"); //end of line for mail headers + define('MAILHEADER_EOL',"\n"); //end of line for mail headers /** * UTF-8 autoencoding replacement for PHPs mail function diff --git a/inc/parser.php b/inc/parser.php index 73bbee765..5c3c78851 100644 --- a/inc/parser.php +++ b/inc/parser.php @@ -1,4 +1,4 @@ - */ - include_once("inc/common.php"); - include_once("inc/html.php"); - include_once("inc/format.php"); - require_once("lang/en/lang.php"); - require_once("lang/".$conf['lang']."/lang.php"); + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + include_once(DOKU_INC.'inc/common.php'); + include_once(DOKU_INC.'inc/html.php'); + include_once(DOKU_INC.'inc/format.php'); + require_once(DOKU_INC.'lang/en/lang.php'); + require_once(DOKU_INC.'lang/'.$conf['lang'].'/lang.php'); /** * The main parser function. @@ -469,7 +470,7 @@ function smileys(&$table,&$text){ $smiley = trim($smiley); if(empty($smiley)) continue; $sm = preg_split('/\s+/',$smiley,2); - $sm[1] = ''.$sm[0].''; + $sm[1] = ''.$sm[0].''; $sm[0] = preg_quote($sm[0],'/'); firstpass($table,$text,'/(\W)'.$sm[0].'(\W)/s',$sm[1],"\\1","\\2"); } diff --git a/inc/search.php b/inc/search.php index 725cd22c9..d66d51af3 100644 --- a/inc/search.php +++ b/inc/search.php @@ -1,4 +1,4 @@ - */ - require_once("inc/common.php"); + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + require_once(DOKU_INC.'inc/common.php'); /** * recurse direcory diff --git a/inc/utf8.php b/inc/utf8.php index bb9b15799..222f40261 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -1,4 +1,4 @@ -