From f62ea8a1d1cf10eddeae777b11420624e111b7ea Mon Sep 17 00:00:00 2001 From: andi Date: Sun, 5 Jun 2005 12:38:42 +0200 Subject: directory layout cleanup !IMPORTANT This patch changes the directory structure of dokuwiki as suggested in http://www.freelists.org/archives/dokuwiki/06-2005/msg00045.html As the changes.log is not managed through darcs you need to move it your self to the new location in data/changes.log I think I modified the code at all nessessary places, but I may have forgotten a few things. darcs-hash:20050605103842-9977f-af20f63c1d604888375d175d89ac6bd71566d47d.gz --- inc/actions.php | 2 +- inc/admin_acl.php | 10 +- inc/auth.php | 4 +- inc/auth/ldap.php | 281 ++++++++++++++++++++++++++++++++++++++++++++ inc/auth/mysql.php | 182 ++++++++++++++++++++++++++++ inc/auth/pgsql.php | 135 +++++++++++++++++++++ inc/auth/plain.php | 113 ++++++++++++++++++ inc/auth_ldap.php | 281 -------------------------------------------- inc/auth_mysql.php | 182 ---------------------------- inc/auth_pgsql.php | 135 --------------------- inc/auth_plain.php | 113 ------------------ inc/common.php | 10 +- inc/html.php | 40 +++---- inc/init.php | 30 +++-- inc/io.php | 49 -------- inc/parser/xhtml.php | 26 ++-- inc/plugins/info/syntax.php | 110 ----------------- inc/plugins/syntax.php | 66 ----------- inc/template.php | 19 +-- 19 files changed, 792 insertions(+), 996 deletions(-) create mode 100644 inc/auth/ldap.php create mode 100644 inc/auth/mysql.php create mode 100644 inc/auth/pgsql.php create mode 100644 inc/auth/plain.php delete mode 100644 inc/auth_ldap.php delete mode 100644 inc/auth_mysql.php delete mode 100644 inc/auth_pgsql.php delete mode 100644 inc/auth_plain.php delete mode 100644 inc/plugins/info/syntax.php delete mode 100644 inc/plugins/syntax.php (limited to 'inc') diff --git a/inc/actions.php b/inc/actions.php index 25a2e14c2..aef63b94c 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -69,7 +69,7 @@ function act_dispatch(){ //call template FIXME: all needed vars available? header('Content-Type: text/html; charset=utf-8'); - include(DOKU_INC.'tpl/'.$conf['template'].'/main.php'); + include(DOKU_INC.'lib/tpl/'.$conf['template'].'/main.php'); // output for the commands is now handled in inc/templates.php // in function tpl_content() } diff --git a/inc/admin_acl.php b/inc/admin_acl.php index fcf9d9ae3..15332b3b4 100644 --- a/inc/admin_acl.php +++ b/inc/admin_acl.php @@ -43,7 +43,7 @@ function admin_acl_handler(){ } // reload ACL config - $AUTH_ACL = file('conf/acl.auth.php'); + $AUTH_ACL = file(DOKU_INC.'conf/acl.auth.php'); } /** @@ -117,7 +117,7 @@ function get_acl_config($id){ * @author Frank Schubert */ function admin_acl_add($acl_scope, $acl_user, $acl_level){ - $acl_config = join("",file('conf/acl.auth.php')); + $acl_config = join("",file(DOKU_INC.'conf/acl.auth.php')); // max level for pagenames is edit if(strpos($acl_scope,'*') === false) { @@ -128,7 +128,7 @@ function admin_acl_add($acl_scope, $acl_user, $acl_level){ $new_config = $acl_config.$new_acl; - return io_saveFile("conf/acl.auth.php", $new_config); + return io_saveFile(DOKU_INC.'conf/acl.auth.php', $new_config); } /** @@ -137,14 +137,14 @@ function admin_acl_add($acl_scope, $acl_user, $acl_level){ * @author Frank Schubert */ function admin_acl_del($acl_scope, $acl_user){ - $acl_config = file('conf/acl.auth.php'); + $acl_config = file(DOKU_INC.'conf/acl.auth.php'); $acl_pattern = '^'.preg_quote($acl_scope,'/').'\s+'.$acl_user.'\s+[0-8].*$'; // save all non!-matching #FIXME invert is available from 4.2.0 only! $new_config = preg_grep("/$acl_pattern/", $acl_config, PREG_GREP_INVERT); - return io_saveFile("conf/acl.auth.php", join("",$new_config)); + return io_saveFile(DOKU_INC.'conf/acl.auth.php', join('',$new_config)); } // --- HTML OUTPUT FUNCTIONS BELOW --- // diff --git a/inc/auth.php b/inc/auth.php index a55cfbc51..863bb3c49 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -15,7 +15,7 @@ require_once(DOKU_INC.'inc/blowfish.php'); require_once(DOKU_INC.'inc/mail.php'); // load the the auth functions - require_once(DOKU_INC.'inc/auth_'.$conf['authtype'].'.php'); + require_once(DOKU_INC.'inc/auth/'.$conf['authtype'].'.php'); // some ACL level defines define('AUTH_NONE',0); @@ -29,7 +29,7 @@ if($conf['useacl']){ auth_login($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']); //load ACL into a global array - $AUTH_ACL = file('conf/acl.auth.php'); + $AUTH_ACL = file(DOKU_INC.'conf/acl.auth.php'); } /** diff --git a/inc/auth/ldap.php b/inc/auth/ldap.php new file mode 100644 index 000000000..2f0f4f1ff --- /dev/null +++ b/inc/auth/ldap.php @@ -0,0 +1,281 @@ + + */ + +//check for LDAP extension on load +if(!function_exists('ldap_connect')) + msg("LDAP extension not found",-1); + +/** + * Connect to the LDAP server + * + * Holds the connection in global scope for multiple use + * + * @author Andreas Gohr + */ +function auth_ldap_connect(){ + global $LDAP_CONNECTION; + global $conf; + $cnf = $conf['auth']['ldap']; + + if(!$LDAP_CONNECTION){ + $LDAP_CONNECTION = @ldap_connect($cnf['server']); + if(!$LDAP_CONNECTION){ + msg("LDAP: couldn't connect to LDAP server",-1); + return false; + } + //set protocol version + if($cnf['version']){ + if(!@ldap_set_option($LDAP_CONNECTION, + LDAP_OPT_PROTOCOL_VERSION, + $cnf['version'])){ + msg('Setting LDAP Protocol version '.$cnf['version'].' failed',-1); + if($cnf['debug']) + msg('LDAP errstr: '.htmlspecialchars(ldap_error($LDAP_CONNECTION)),0); + + } else { + //use TLS (needs version 3) + if($cnf['starttls']) { + if (!@ldap_start_tls($LDAP_CONNECTION)){ + msg('Starting TLS failed',-1); + if($cnf['debug']) + msg('LDAP errstr: '.htmlspecialchars(ldap_error($LDAP_CONNECTION)),0); + } + } + // needs version 3 + if(isset($cnf['referrals'])) { + if(!@ldap_set_option($LDAP_CONNECTION, + LDAP_OPT_REFERRALS, + $cnf['referrals'])){ + msg('Setting LDAP referrals to off failed',-1); + if($cnf['debug']) + msg('LDAP errstr: '.htmlspecialchars(ldap_error($LDAP_CONNECTION)),0); + } + } + } + } + } + return $LDAP_CONNECTION; +} + +/** + * Check user+password [required auth function] + * + * Checks if the given user exists and the given + * plaintext password is correct by trying to bind + * to the LDAP server + * + * @author Andreas Gohr + * @return bool + */ +function auth_checkPass($user,$pass){ + global $conf; + $cnf = $conf['auth']['ldap']; + + //reject empty password + if(empty($pass)) return false; + + //connect to LDAP Server + $conn = auth_ldap_connect(); + if(!$conn) return false; + + // indirect user bind + if(!empty($cnf['binddn']) and !empty($cnf['bindpw'])) { + //use superuser credentials + if(!@ldap_bind($conn,$cnf['binddn'],$cnf['bindpw'])){ + if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); + return false; + } + + // special bind string + } else if(!empty($cnf['binddn']) and !empty($cnf['usertree']) and !empty($cnf['userfilter'])) { + $dn = auth_ldap_makeFilter($cnf['binddn'], array('user'=>$user,'server'=>$cnf['server'])); + + // direct user bind + } else if(strpos($cnf['usertree'], '%{user}')) { + $dn = auth_ldap_makeFilter($cnf['usertree'], array('user'=>$user,'server'=>$cnf['server'])); + + // Anonymous bind + } else { + if(!@ldap_bind($conn)){ + msg("LDAP: can not bind anonymously",-1); + if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); + return false; + } + } + + // Try to bind to with the dn if we have one. + if(!empty($dn)) { + // User/Password bind + if(!@ldap_bind($conn,$dn,$pass)){ + if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); + return false; + } + return true; + } else { + // See if we can find the user + $info = auth_getUserData($user); + if(empty($info['dn'])) { + return false; + } else { + $dn = $info['dn']; + } + // Try to bind with the dn provided + if(!@ldap_bind($conn,$dn,$pass)){ + if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); + return false; + } + return true; + } + + return false; +} + +/** + * Return user info [required auth function] + * + * Returns info about the given user needs to contain + * at least these fields: + * + * name string full name of the user + * mail string email addres of the user + * grps array list of groups the user is in + * + * This LDAP specific function returns the following + * addional fields: + * + * dn string distinguished name (DN) + * uid string Posix User ID + * + * @author Andreas Gohr + * @author Trouble + * @author Dan Allen + * @auhtor + */ +function auth_getUserData($user){ + global $conf; + $cnf = $conf['auth']['ldap']; + + //connect to LDAP Server + $conn = auth_ldap_connect(); + if(!$conn) return false; + + $info['user']= $user; + $info['server']= $cnf['server']; + + //get info for given user + $base = auth_ldap_makeFilter($cnf['usertree'], $info); + if(!empty($cnf['userfilter'])) { + $filter = auth_ldap_makeFilter($cnf['userfilter'], $info); + } else { + $filter = "(ObjectClass=*)"; + } + + $sr = @ldap_search($conn, $base, $filter); + $result = @ldap_get_entries($conn, $sr); + if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); + + // Don't accept more or less than one response + if($result['count'] != 1){ + return false; //user not found + } + + $user_result = $result[0]; + + //general user info + $info['dn']= $user_result['dn']; + $info['mail']= $user_result['mail'][0]; + $info['name']= $user_result['cn'][0]; + + #overwrite if other attribs are specified. + foreach($cnf['mapping'] as $localkey => $key) { + if(is_array($key)) { + //use regexp to clean up user_result + list($key, $regexp) = each($key); + foreach($user_result[$key] as $grp){ + if (preg_match($regexp,$grp,$match)) { + if($localkey == 'grps') { + $info[$localkey][] = $match[1]; + } else { + $info[$localkey] = $match[1]; + } + } + } + } else { + $info[$localkey] = $user_result[$key][0]; + } + } + + //get groups for given user if grouptree is given + if (!empty($cnf['grouptree'])) { + $base = auth_ldap_makeFilter($cnf['grouptree'], $user_result); + $filter = auth_ldap_makeFilter($cnf['groupfilter'], $user_result); + + $sr = @ldap_search($conn, $base, $filter); + if(!$sr){ + msg("LDAP: Reading group memberships failed",-1); + if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); + return false; + } + $result = ldap_get_entries($conn, $sr); + foreach($result as $grp){ + if(!empty($grp['cn'][0])) + $info['grps'][] = $grp['cn'][0]; + } + } + + //if no groups were found always return the default group + if(!count($info['grps'])) $info['grps'][] = $conf['defaultgroup']; + + return $info; +} + +/** + * Create a new User [required auth function] + * + * Not implemented + * + * @author Andreas Gohr + */ +function auth_createUser($user,$pass,$name,$mail){ + msg("Sorry. Creating users is not supported by the LDAP backend",-1); + return null; +} + + +/** + * Make ldap filter strings. + * + * Used by auth_getUserData to make the filter + * strings for grouptree and groupfilter + * + * filter string ldap search filter with placeholders + * placeholders array array with the placeholders + * + * @author Troels Liebe Bentsen + * @return string + */ +function auth_ldap_makeFilter($filter, $placeholders) { + preg_match_all("/%{([^}]+)/", $filter, $matches, PREG_PATTERN_ORDER); + //replace each match + foreach ($matches[1] as $match) { + //take first element if array + if(is_array($placeholders[$match])) { + $value = $placeholders[$match][0]; + } else { + $value = $placeholders[$match]; + } + $filter = str_replace('%{'.$match.'}', $value, $filter); + } + return $filter; +} + +//Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/auth/mysql.php b/inc/auth/mysql.php new file mode 100644 index 000000000..758fe3b77 --- /dev/null +++ b/inc/auth/mysql.php @@ -0,0 +1,182 @@ + + */ + +//check for MySQL extension on load +if(!function_exists('mysql_connect')) + msg("MySQL extension not found",-1); + +/** + * Execute SQL + * + * Executes SQL statements and returns the results as list + * of hashes. Returns false on error. Returns auto_increment + * IDs on INSERT statements. + * + * @author Andreas Gohr + */ +function auth_mysql_runsql($sql_string) { + global $conf; + $cnf = $conf['auth']['mysql']; + + $link = @mysql_connect ($cnf['server'], $cnf['user'], $cnf['password']); + if(!$link){ + msg('MySQL: Connection to database failed!',-1); + return false; + } + $result = @mysql_db_query($cnf['database'],$sql_string,$link); + if(!$result){ + msg('MySQL: '.mysql_error($link)); + return false; + } + + //mysql_db_query returns 1 on a insert statement -> no need to ask for results + if ($result != 1) { + for($i=0; $i< mysql_num_rows($result); $i++) { + $temparray = mysql_fetch_assoc($result); + $resultarray[]=$temparray; + } + mysql_free_result ($result); + } elseif (mysql_insert_id($link)) { + $resultarray = mysql_insert_id($link); //give back ID on insert + } else + $resultarray = 0; // asure that the return value is valid + + mysql_close ($link); + return $resultarray; +} + +/** + * Check user+password [required auth function] + * + * Checks if the given user exists and the given + * plaintext password is correct. Furtheron it + * might be checked wether the user is member of + * the right group + * + * @author Andreas Gohr + * @author Matthias Grimm + * @return bool + */ +function auth_checkPass($user,$pass){ + global $conf; + $cnf = $conf['auth']['mysql']; + + $sql = str_replace('%u',addslashes($user),$cnf['passcheck']); + $sql = str_replace('%g',addslashes($conf['defaultgroup']),$sql); + $result = auth_mysql_runsql($sql); + + if(count($result)){ + return(auth_verifyPassword($pass,$result[0]['pass'])); + }else{ + return(false); + } +} + +/** + * Return user info [required auth function] + * + * Returns info about the given user needs to contain + * at least these fields: + * + * name string full name of the user + * mail string email addres of the user + * grps array list of groups the user is in + * + * @author Andreas Gohr + */ +function auth_getUserData($user){ + global $conf; + $cnf = $conf['auth']['mysql']; + + $sql = str_replace('%u',addslashes($user),$cnf['userinfo']); + $result = auth_mysql_runsql($sql); + if(!count($result)) return false; + $info = $result[0]; + + $sql = str_replace('%u',addslashes($user),$cnf['groups']); + $result = auth_mysql_runsql($sql); + if(!count($result)){ + $info['grps'][] = $conf['defaultgroup']; + }else{ + foreach($result as $row){ + $info['grps'][] = $row['group']; + } + } + + return $info; +} + +/** + * Create a new User [required auth function] + * + * user string username + * pass string password + * name string full name of the user + * mail string email address + * + * Returns false if the user already exists, null when an error + * occoured and the cleartext password of the new user if + * everything went well. + * + * The user HAS TO be added to the default group by this + * function + * + * @author Matthias Grimm + */ +function auth_createUser($user,$pass,$name,$mail){ + global $conf; + $cnf = $conf['auth']['mysql']; + + //check if user exists + $info = auth_getUserData($user); + if ($info != false) return false; + + //get groupid of default group + if($cnf['getgroupid']){ + $sql = str_replace('%g',addslashes($conf['defaultgroup']),$cnf['getgroupid']); + $result = auth_mysql_runsql($sql); + if($result === false) return null; + if (count($result) == 1){ + $gid = $result[0]['gid']; + }else{ + msg("MySQL: Couldn't find the default group",-1); + return null; + } + } + + //prepare the insert + $sql = str_replace('%u' ,addslashes($user),$cnf['adduser']); + $sql = str_replace('%p' ,addslashes(auth_cryptPassword($pass)),$sql); + $sql = str_replace('%n' ,addslashes($name),$sql); + $sql = str_replace('%e' ,addslashes($mail),$sql); + $sql = str_replace('%gid',addslashes($gid),$sql); + $sql = str_replace('%g' ,addslashes($conf['defaultgroup']),$sql); + + //do the insert + $uid = auth_mysql_runsql($sql); + if($uid == 0){ + msg("Registering of the new user '$user' failed!", -1); + return null; + } + + //add to default group + if ($cnf['addusergroup']) { + $sql = str_replace('%uid',addslashes($uid),$cnf['addusergroup']); + $sql = str_replace('%u' ,addslashes($user),$sql); + $sql = str_replace('%gid',addslashes($gid),$sql); + $sql = str_replace('%g' ,addslashes($conf['defaultgroup']),$sql); + $result = auth_mysql_runsql($sql); + if($result === false) msg("MySQL: couldn't add user to the default group"); + } + + return $pass; +} + +//Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/auth/pgsql.php b/inc/auth/pgsql.php new file mode 100644 index 000000000..b063f405e --- /dev/null +++ b/inc/auth/pgsql.php @@ -0,0 +1,135 @@ + + */ + +//check for Postgresql extension on load +if(!function_exists('pg_connect')) + msg("PgSQL extension not found",-1); + +/** + * Execute SQL + * + * Executes SQL statements and returns the results as list + * of hashes. Returns false on error. + * + */ +function auth_pgsql_runsql($sql_string) { + global $conf; + $cnf = $conf['auth']['pgsql']; + + if($cnf['port']) { + $port=" port=".$cnf['port']; + } + + $dsn="host=".$cnf['server']." dbname=".$cnf['database'].$port." user=".$cnf['user']." password=".$cnf['password']; + $link = pg_connect($dsn); + if(!$link){ + msg('PgSQL: Connection to database failed!',-1); + return false; + } + + $result = pg_query($link, $sql_string); + if(!$result){ + msg('PgSQL: '.pg_last_error($link)); + return false; + } + + for($i=0; $i< pg_num_rows($result); $i++) { + $temparray = pg_fetch_assoc($result); + $resultarray[]=$temparray; + } + pg_free_result($result); + pg_close($link); + return $resultarray; +} + +/** + * Check user+password [required auth function] + * + * Checks if the given user exists and the given + * plaintext password is correct + * + * @author Andreas Gohr + * @return bool + */ +function auth_checkPass($user,$pass){ + global $conf; + $cnf = $conf['auth']['pgsql']; + + $sql = str_replace('%u',addslashes($user),$cnf['userinfo']); + $result = auth_pgsql_runsql($sql); + if(count($result)>0) { + $info=$result[0]; + return auth_verifyPassword($pass, $info['pass']); + } else { + return false; + } +} + +/** + * Return user info [required auth function] + * + * Returns info about the given user needs to contain + * at least these fields: + * + * name string full name of the user + * mail string email addres of the user + * grps array list of groups the user is in + * + * @author Andreas Gohr + */ +function auth_getUserData($user){ + global $conf; + $cnf = $conf['auth']['pgsql']; + + $sql = str_replace('%u',addslashes($user),$cnf['userinfo']); + $result = auth_pgsql_runsql($sql); + if(!count($result)) return false; + $info = $result[0]; + + $sql = str_replace('%u',addslashes($user),$cnf['groups']); + $result = auth_pgsql_runsql($sql); + if(!count($result)) return false; + foreach($result as $row){ + $info['grps'][] = $row['group']; + } + + return $info; +} + +/** + * Create a new User [required auth function] + */ +function auth_createUser($user,$pass,$name,$mail) { + global $conf; + $cnf = $conf['auth']['pgsql']; + + if($cnf['createuser']) { + $sql = str_replace('%u',addslashes($user),$cnf['userinfo']); + $result = auth_pgsql_runsql($sql); + if(count($result)>0) return false; + + $sql = str_replace('%u',addslashes($user),$cnf['createuser']); + $sql = str_replace('%p',auth_cryptPassword($pass),$sql); + $sql = str_replace('%f',addslashes($name),$sql); + $sql = str_replace('%e',addslashes($mail),$sql); + $sql = str_replace('%g',addslashes($conf['defaultgroup']),$sql); + + $result=auth_pgsql_runsql($sql); + if(count($result)) + return $pass; + } else { + msg("Sorry. Your PgSQL backend is not configured to create new users.",-1); + } + return null; +} + +//Setup VIM: ex: et ts=2 enc=utf-8 : + diff --git a/inc/auth/plain.php b/inc/auth/plain.php new file mode 100644 index 000000000..eaa01b79d --- /dev/null +++ b/inc/auth/plain.php @@ -0,0 +1,113 @@ + + */ + +// we only accept page ids for auth_plain +if(isset($_REQUEST['u'])) + $_REQUEST['u'] = cleanID($_REQUEST['u']); + +/** + * Check user+password [required auth function] + * + * Checks if the given user exists and the given + * plaintext password is correct + * + * @author Andreas Gohr + * @return bool + */ +function auth_checkPass($user,$pass){ + $users = auth_plain_loadUserData(); + + if(!isset($users[$user])) return false; + + return auth_verifyPassword($pass,$users[$user]['pass']); +} + +/** + * Return user info [required auth function] + * + * Returns info about the given user needs to contain + * at least these fields: + * + * name string full name of the user + * mail string email addres of the user + * grps array list of groups the user is in + * + * @author Andreas Gohr + */ +function auth_getUserData($user){ + $users = auth_plain_loadUserData(); + return $users[$user]; +} + +/** + * Create a new User [required auth function] + * + * Returns false if the user already exists, null when an error + * occured and the cleartext password of the new user if + * everything went well. + * + * The new user HAS TO be added to the default group by this + * function! + * + * @author Andreas Gohr + */ +function auth_createUser($user,$pass,$name,$mail){ + global $conf; + + $users = auth_plain_loadUserData(); + if(isset($users[$user])) return false; + + $userline = join(':',array($user, + auth_cryptPassword($pass), + $name, + $mail, + $conf['defaultgroup'])); + $userline .= "\n"; + $fh = fopen(DOKU_INC.'conf/users.auth.php','a'); + if($fh){ + fwrite($fh,$userline); + fclose($fh); + return $pass; + } + msg('The users.auth.php file is not writable. Please inform the Wiki-Admin',-1); + return null; +} + +/** + * Load all user data + * + * Used by the plaintext auth functions + * loads the user file into a datastructure + * + * @author Andreas Gohr + */ +function auth_plain_loadUserData(){ + $data = array(); + $lines = file(DOKU_INC.'conf/users.auth.php'); + foreach($lines as $line){ + $line = preg_replace('/#.*$/','',$line); //ignore comments + $line = trim($line); + if(empty($line)) continue; + + $row = split(":",$line,5); + $groups = split(",",$row[4]); + $data[$row[0]]['pass'] = $row[1]; + $data[$row[0]]['name'] = urldecode($row[2]); + $data[$row[0]]['mail'] = $row[3]; + $data[$row[0]]['grps'] = $groups; + } + return $data; +} + + +//Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/auth_ldap.php b/inc/auth_ldap.php deleted file mode 100644 index 2f0f4f1ff..000000000 --- a/inc/auth_ldap.php +++ /dev/null @@ -1,281 +0,0 @@ - - */ - -//check for LDAP extension on load -if(!function_exists('ldap_connect')) - msg("LDAP extension not found",-1); - -/** - * Connect to the LDAP server - * - * Holds the connection in global scope for multiple use - * - * @author Andreas Gohr - */ -function auth_ldap_connect(){ - global $LDAP_CONNECTION; - global $conf; - $cnf = $conf['auth']['ldap']; - - if(!$LDAP_CONNECTION){ - $LDAP_CONNECTION = @ldap_connect($cnf['server']); - if(!$LDAP_CONNECTION){ - msg("LDAP: couldn't connect to LDAP server",-1); - return false; - } - //set protocol version - if($cnf['version']){ - if(!@ldap_set_option($LDAP_CONNECTION, - LDAP_OPT_PROTOCOL_VERSION, - $cnf['version'])){ - msg('Setting LDAP Protocol version '.$cnf['version'].' failed',-1); - if($cnf['debug']) - msg('LDAP errstr: '.htmlspecialchars(ldap_error($LDAP_CONNECTION)),0); - - } else { - //use TLS (needs version 3) - if($cnf['starttls']) { - if (!@ldap_start_tls($LDAP_CONNECTION)){ - msg('Starting TLS failed',-1); - if($cnf['debug']) - msg('LDAP errstr: '.htmlspecialchars(ldap_error($LDAP_CONNECTION)),0); - } - } - // needs version 3 - if(isset($cnf['referrals'])) { - if(!@ldap_set_option($LDAP_CONNECTION, - LDAP_OPT_REFERRALS, - $cnf['referrals'])){ - msg('Setting LDAP referrals to off failed',-1); - if($cnf['debug']) - msg('LDAP errstr: '.htmlspecialchars(ldap_error($LDAP_CONNECTION)),0); - } - } - } - } - } - return $LDAP_CONNECTION; -} - -/** - * Check user+password [required auth function] - * - * Checks if the given user exists and the given - * plaintext password is correct by trying to bind - * to the LDAP server - * - * @author Andreas Gohr - * @return bool - */ -function auth_checkPass($user,$pass){ - global $conf; - $cnf = $conf['auth']['ldap']; - - //reject empty password - if(empty($pass)) return false; - - //connect to LDAP Server - $conn = auth_ldap_connect(); - if(!$conn) return false; - - // indirect user bind - if(!empty($cnf['binddn']) and !empty($cnf['bindpw'])) { - //use superuser credentials - if(!@ldap_bind($conn,$cnf['binddn'],$cnf['bindpw'])){ - if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); - return false; - } - - // special bind string - } else if(!empty($cnf['binddn']) and !empty($cnf['usertree']) and !empty($cnf['userfilter'])) { - $dn = auth_ldap_makeFilter($cnf['binddn'], array('user'=>$user,'server'=>$cnf['server'])); - - // direct user bind - } else if(strpos($cnf['usertree'], '%{user}')) { - $dn = auth_ldap_makeFilter($cnf['usertree'], array('user'=>$user,'server'=>$cnf['server'])); - - // Anonymous bind - } else { - if(!@ldap_bind($conn)){ - msg("LDAP: can not bind anonymously",-1); - if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); - return false; - } - } - - // Try to bind to with the dn if we have one. - if(!empty($dn)) { - // User/Password bind - if(!@ldap_bind($conn,$dn,$pass)){ - if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); - return false; - } - return true; - } else { - // See if we can find the user - $info = auth_getUserData($user); - if(empty($info['dn'])) { - return false; - } else { - $dn = $info['dn']; - } - // Try to bind with the dn provided - if(!@ldap_bind($conn,$dn,$pass)){ - if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); - return false; - } - return true; - } - - return false; -} - -/** - * Return user info [required auth function] - * - * Returns info about the given user needs to contain - * at least these fields: - * - * name string full name of the user - * mail string email addres of the user - * grps array list of groups the user is in - * - * This LDAP specific function returns the following - * addional fields: - * - * dn string distinguished name (DN) - * uid string Posix User ID - * - * @author Andreas Gohr - * @author Trouble - * @author Dan Allen - * @auhtor - */ -function auth_getUserData($user){ - global $conf; - $cnf = $conf['auth']['ldap']; - - //connect to LDAP Server - $conn = auth_ldap_connect(); - if(!$conn) return false; - - $info['user']= $user; - $info['server']= $cnf['server']; - - //get info for given user - $base = auth_ldap_makeFilter($cnf['usertree'], $info); - if(!empty($cnf['userfilter'])) { - $filter = auth_ldap_makeFilter($cnf['userfilter'], $info); - } else { - $filter = "(ObjectClass=*)"; - } - - $sr = @ldap_search($conn, $base, $filter); - $result = @ldap_get_entries($conn, $sr); - if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); - - // Don't accept more or less than one response - if($result['count'] != 1){ - return false; //user not found - } - - $user_result = $result[0]; - - //general user info - $info['dn']= $user_result['dn']; - $info['mail']= $user_result['mail'][0]; - $info['name']= $user_result['cn'][0]; - - #overwrite if other attribs are specified. - foreach($cnf['mapping'] as $localkey => $key) { - if(is_array($key)) { - //use regexp to clean up user_result - list($key, $regexp) = each($key); - foreach($user_result[$key] as $grp){ - if (preg_match($regexp,$grp,$match)) { - if($localkey == 'grps') { - $info[$localkey][] = $match[1]; - } else { - $info[$localkey] = $match[1]; - } - } - } - } else { - $info[$localkey] = $user_result[$key][0]; - } - } - - //get groups for given user if grouptree is given - if (!empty($cnf['grouptree'])) { - $base = auth_ldap_makeFilter($cnf['grouptree'], $user_result); - $filter = auth_ldap_makeFilter($cnf['groupfilter'], $user_result); - - $sr = @ldap_search($conn, $base, $filter); - if(!$sr){ - msg("LDAP: Reading group memberships failed",-1); - if($cnf['debug']) msg('LDAP errstr: '.htmlspecialchars(ldap_error($conn)),0); - return false; - } - $result = ldap_get_entries($conn, $sr); - foreach($result as $grp){ - if(!empty($grp['cn'][0])) - $info['grps'][] = $grp['cn'][0]; - } - } - - //if no groups were found always return the default group - if(!count($info['grps'])) $info['grps'][] = $conf['defaultgroup']; - - return $info; -} - -/** - * Create a new User [required auth function] - * - * Not implemented - * - * @author Andreas Gohr - */ -function auth_createUser($user,$pass,$name,$mail){ - msg("Sorry. Creating users is not supported by the LDAP backend",-1); - return null; -} - - -/** - * Make ldap filter strings. - * - * Used by auth_getUserData to make the filter - * strings for grouptree and groupfilter - * - * filter string ldap search filter with placeholders - * placeholders array array with the placeholders - * - * @author Troels Liebe Bentsen - * @return string - */ -function auth_ldap_makeFilter($filter, $placeholders) { - preg_match_all("/%{([^}]+)/", $filter, $matches, PREG_PATTERN_ORDER); - //replace each match - foreach ($matches[1] as $match) { - //take first element if array - if(is_array($placeholders[$match])) { - $value = $placeholders[$match][0]; - } else { - $value = $placeholders[$match]; - } - $filter = str_replace('%{'.$match.'}', $value, $filter); - } - return $filter; -} - -//Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/auth_mysql.php b/inc/auth_mysql.php deleted file mode 100644 index 758fe3b77..000000000 --- a/inc/auth_mysql.php +++ /dev/null @@ -1,182 +0,0 @@ - - */ - -//check for MySQL extension on load -if(!function_exists('mysql_connect')) - msg("MySQL extension not found",-1); - -/** - * Execute SQL - * - * Executes SQL statements and returns the results as list - * of hashes. Returns false on error. Returns auto_increment - * IDs on INSERT statements. - * - * @author Andreas Gohr - */ -function auth_mysql_runsql($sql_string) { - global $conf; - $cnf = $conf['auth']['mysql']; - - $link = @mysql_connect ($cnf['server'], $cnf['user'], $cnf['password']); - if(!$link){ - msg('MySQL: Connection to database failed!',-1); - return false; - } - $result = @mysql_db_query($cnf['database'],$sql_string,$link); - if(!$result){ - msg('MySQL: '.mysql_error($link)); - return false; - } - - //mysql_db_query returns 1 on a insert statement -> no need to ask for results - if ($result != 1) { - for($i=0; $i< mysql_num_rows($result); $i++) { - $temparray = mysql_fetch_assoc($result); - $resultarray[]=$temparray; - } - mysql_free_result ($result); - } elseif (mysql_insert_id($link)) { - $resultarray = mysql_insert_id($link); //give back ID on insert - } else - $resultarray = 0; // asure that the return value is valid - - mysql_close ($link); - return $resultarray; -} - -/** - * Check user+password [required auth function] - * - * Checks if the given user exists and the given - * plaintext password is correct. Furtheron it - * might be checked wether the user is member of - * the right group - * - * @author Andreas Gohr - * @author Matthias Grimm - * @return bool - */ -function auth_checkPass($user,$pass){ - global $conf; - $cnf = $conf['auth']['mysql']; - - $sql = str_replace('%u',addslashes($user),$cnf['passcheck']); - $sql = str_replace('%g',addslashes($conf['defaultgroup']),$sql); - $result = auth_mysql_runsql($sql); - - if(count($result)){ - return(auth_verifyPassword($pass,$result[0]['pass'])); - }else{ - return(false); - } -} - -/** - * Return user info [required auth function] - * - * Returns info about the given user needs to contain - * at least these fields: - * - * name string full name of the user - * mail string email addres of the user - * grps array list of groups the user is in - * - * @author Andreas Gohr - */ -function auth_getUserData($user){ - global $conf; - $cnf = $conf['auth']['mysql']; - - $sql = str_replace('%u',addslashes($user),$cnf['userinfo']); - $result = auth_mysql_runsql($sql); - if(!count($result)) return false; - $info = $result[0]; - - $sql = str_replace('%u',addslashes($user),$cnf['groups']); - $result = auth_mysql_runsql($sql); - if(!count($result)){ - $info['grps'][] = $conf['defaultgroup']; - }else{ - foreach($result as $row){ - $info['grps'][] = $row['group']; - } - } - - return $info; -} - -/** - * Create a new User [required auth function] - * - * user string username - * pass string password - * name string full name of the user - * mail string email address - * - * Returns false if the user already exists, null when an error - * occoured and the cleartext password of the new user if - * everything went well. - * - * The user HAS TO be added to the default group by this - * function - * - * @author Matthias Grimm - */ -function auth_createUser($user,$pass,$name,$mail){ - global $conf; - $cnf = $conf['auth']['mysql']; - - //check if user exists - $info = auth_getUserData($user); - if ($info != false) return false; - - //get groupid of default group - if($cnf['getgroupid']){ - $sql = str_replace('%g',addslashes($conf['defaultgroup']),$cnf['getgroupid']); - $result = auth_mysql_runsql($sql); - if($result === false) return null; - if (count($result) == 1){ - $gid = $result[0]['gid']; - }else{ - msg("MySQL: Couldn't find the default group",-1); - return null; - } - } - - //prepare the insert - $sql = str_replace('%u' ,addslashes($user),$cnf['adduser']); - $sql = str_replace('%p' ,addslashes(auth_cryptPassword($pass)),$sql); - $sql = str_replace('%n' ,addslashes($name),$sql); - $sql = str_replace('%e' ,addslashes($mail),$sql); - $sql = str_replace('%gid',addslashes($gid),$sql); - $sql = str_replace('%g' ,addslashes($conf['defaultgroup']),$sql); - - //do the insert - $uid = auth_mysql_runsql($sql); - if($uid == 0){ - msg("Registering of the new user '$user' failed!", -1); - return null; - } - - //add to default group - if ($cnf['addusergroup']) { - $sql = str_replace('%uid',addslashes($uid),$cnf['addusergroup']); - $sql = str_replace('%u' ,addslashes($user),$sql); - $sql = str_replace('%gid',addslashes($gid),$sql); - $sql = str_replace('%g' ,addslashes($conf['defaultgroup']),$sql); - $result = auth_mysql_runsql($sql); - if($result === false) msg("MySQL: couldn't add user to the default group"); - } - - return $pass; -} - -//Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/auth_pgsql.php b/inc/auth_pgsql.php deleted file mode 100644 index b063f405e..000000000 --- a/inc/auth_pgsql.php +++ /dev/null @@ -1,135 +0,0 @@ - - */ - -//check for Postgresql extension on load -if(!function_exists('pg_connect')) - msg("PgSQL extension not found",-1); - -/** - * Execute SQL - * - * Executes SQL statements and returns the results as list - * of hashes. Returns false on error. - * - */ -function auth_pgsql_runsql($sql_string) { - global $conf; - $cnf = $conf['auth']['pgsql']; - - if($cnf['port']) { - $port=" port=".$cnf['port']; - } - - $dsn="host=".$cnf['server']." dbname=".$cnf['database'].$port." user=".$cnf['user']." password=".$cnf['password']; - $link = pg_connect($dsn); - if(!$link){ - msg('PgSQL: Connection to database failed!',-1); - return false; - } - - $result = pg_query($link, $sql_string); - if(!$result){ - msg('PgSQL: '.pg_last_error($link)); - return false; - } - - for($i=0; $i< pg_num_rows($result); $i++) { - $temparray = pg_fetch_assoc($result); - $resultarray[]=$temparray; - } - pg_free_result($result); - pg_close($link); - return $resultarray; -} - -/** - * Check user+password [required auth function] - * - * Checks if the given user exists and the given - * plaintext password is correct - * - * @author Andreas Gohr - * @return bool - */ -function auth_checkPass($user,$pass){ - global $conf; - $cnf = $conf['auth']['pgsql']; - - $sql = str_replace('%u',addslashes($user),$cnf['userinfo']); - $result = auth_pgsql_runsql($sql); - if(count($result)>0) { - $info=$result[0]; - return auth_verifyPassword($pass, $info['pass']); - } else { - return false; - } -} - -/** - * Return user info [required auth function] - * - * Returns info about the given user needs to contain - * at least these fields: - * - * name string full name of the user - * mail string email addres of the user - * grps array list of groups the user is in - * - * @author Andreas Gohr - */ -function auth_getUserData($user){ - global $conf; - $cnf = $conf['auth']['pgsql']; - - $sql = str_replace('%u',addslashes($user),$cnf['userinfo']); - $result = auth_pgsql_runsql($sql); - if(!count($result)) return false; - $info = $result[0]; - - $sql = str_replace('%u',addslashes($user),$cnf['groups']); - $result = auth_pgsql_runsql($sql); - if(!count($result)) return false; - foreach($result as $row){ - $info['grps'][] = $row['group']; - } - - return $info; -} - -/** - * Create a new User [required auth function] - */ -function auth_createUser($user,$pass,$name,$mail) { - global $conf; - $cnf = $conf['auth']['pgsql']; - - if($cnf['createuser']) { - $sql = str_replace('%u',addslashes($user),$cnf['userinfo']); - $result = auth_pgsql_runsql($sql); - if(count($result)>0) return false; - - $sql = str_replace('%u',addslashes($user),$cnf['createuser']); - $sql = str_replace('%p',auth_cryptPassword($pass),$sql); - $sql = str_replace('%f',addslashes($name),$sql); - $sql = str_replace('%e',addslashes($mail),$sql); - $sql = str_replace('%g',addslashes($conf['defaultgroup']),$sql); - - $result=auth_pgsql_runsql($sql); - if(count($result)) - return $pass; - } else { - msg("Sorry. Your PgSQL backend is not configured to create new users.",-1); - } - return null; -} - -//Setup VIM: ex: et ts=2 enc=utf-8 : - diff --git a/inc/auth_plain.php b/inc/auth_plain.php deleted file mode 100644 index 55e1fa9f6..000000000 --- a/inc/auth_plain.php +++ /dev/null @@ -1,113 +0,0 @@ - - */ - -// we only accept page ids for auth_plain -if(isset($_REQUEST['u'])) - $_REQUEST['u'] = cleanID($_REQUEST['u']); - -/** - * Check user+password [required auth function] - * - * Checks if the given user exists and the given - * plaintext password is correct - * - * @author Andreas Gohr - * @return bool - */ -function auth_checkPass($user,$pass){ - $users = auth_plain_loadUserData(); - - if(!isset($users[$user])) return false; - - return auth_verifyPassword($pass,$users[$user]['pass']); -} - -/** - * Return user info [required auth function] - * - * Returns info about the given user needs to contain - * at least these fields: - * - * name string full name of the user - * mail string email addres of the user - * grps array list of groups the user is in - * - * @author Andreas Gohr - */ -function auth_getUserData($user){ - $users = auth_plain_loadUserData(); - return $users[$user]; -} - -/** - * Create a new User [required auth function] - * - * Returns false if the user already exists, null when an error - * occured and the cleartext password of the new user if - * everything went well. - * - * The new user HAS TO be added to the default group by this - * function! - * - * @author Andreas Gohr - */ -function auth_createUser($user,$pass,$name,$mail){ - global $conf; - - $users = auth_plain_loadUserData(); - if(isset($users[$user])) return false; - - $userline = join(':',array($user, - auth_cryptPassword($pass), - $name, - $mail, - $conf['defaultgroup'])); - $userline .= "\n"; - $fh = fopen('conf/users.auth.php','a'); - if($fh){ - fwrite($fh,$userline); - fclose($fh); - return $pass; - } - msg('The users.auth.php file is not writable. Please inform the Wiki-Admin',-1); - return null; -} - -/** - * Load all user data - * - * Used by the plaintext auth functions - * loads the user file into a datastructure - * - * @author Andreas Gohr - */ -function auth_plain_loadUserData(){ - $data = array(); - $lines = file('conf/users.auth.php'); - foreach($lines as $line){ - $line = preg_replace('/#.*$/','',$line); //ignore comments - $line = trim($line); - if(empty($line)) continue; - - $row = split(":",$line,5); - $groups = split(",",$row[4]); - $data[$row[0]]['pass'] = $row[1]; - $data[$row[0]]['name'] = urldecode($row[2]); - $data[$row[0]]['mail'] = $row[3]; - $data[$row[0]]['grps'] = $groups; - } - return $data; -} - - -//Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/common.php b/inc/common.php index 162a1a8e4..99cec10a9 100644 --- a/inc/common.php +++ b/inc/common.php @@ -105,7 +105,11 @@ function msg($message,$lvl=0){ }else{ $MSG = array(); $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message); - html_msgarea(); + if(function_exists('html_msgarea')){ + html_msgarea(); + }else{ + print "ERROR($lvl) $message"; + } } } @@ -244,7 +248,7 @@ function checkwordblock(){ if(!$conf['usewordblock']) return false; - $blockfile = file('conf/wordblock.conf'); + $blockfile = file(DOKU_INC.'conf/wordblock.conf'); //how many lines to read at once (to work around some PCRE limits) if(version_compare(phpversion(),'4.3.0','<')){ //old versions of PCRE define a maximum of parenthesises even if no @@ -799,7 +803,7 @@ function check(){ msg('Mediadir is not writable',-1); } - if(is_writable('conf/users.auth.php')){ + if(is_writable(DOKU_INC.'conf/users.auth.php')){ msg('conf/users.auth.php is writable',1); }else{ msg('conf/users.auth.php is not writable',0); diff --git a/inc/html.php b/inc/html.php index 411e230c7..acdfaecba 100644 --- a/inc/html.php +++ b/inc/html.php @@ -364,7 +364,7 @@ function html_revisions(){ print $date; - print ' '; + print ' '; print ''.$ID.' '; @@ -386,7 +386,7 @@ function html_revisions(){ print $date; print ' '; - print ''; + print ''; print ' '; print ''.$ID.' '; @@ -438,11 +438,11 @@ function html_recent($first=0){ print $date.' '; print ''; - print ''; + print ''; print ' '; print ''; - print ''; + print ''; print ' '; print html_wikilink($id,$id); @@ -848,29 +848,29 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed? textChanged = ; - formatButton('images/bold.png','','**','**','','b'); - formatButton('images/italic.png','',"\/\/","\/\/",'','i'); - formatButton('images/underline.png','','__','__','','u'); - formatButton('images/code.png','','\'\'','\'\'','','c'); + formatButton('bold.png','','**','**','','b'); + formatButton('italic.png','',"\/\/","\/\/",'','i'); + formatButton('underline.png','','__','__','','u'); + formatButton('code.png','','\'\'','\'\'','','c'); - formatButton('images/fonth1.png','','====== ',' ======\n','','1'); - formatButton('images/fonth2.png','','===== ',' =====\n','','2'); - formatButton('images/fonth3.png','','==== ',' ====\n','','3'); - formatButton('images/fonth4.png','','=== ',' ===\n','','4'); - formatButton('images/fonth5.png','','== ',' ==\n','','5'); + formatButton('fonth1.png','','====== ',' ======\n','','1'); + formatButton('fonth2.png','','===== ',' =====\n','','2'); + formatButton('fonth3.png','','==== ',' ====\n','','3'); + formatButton('fonth4.png','','=== ',' ===\n','','4'); + formatButton('fonth5.png','','== ',' ==\n','','5'); - formatButton('images/link.png','','[[',']]','','l'); - formatButton('images/extlink.png','','[[',']]','http://www.example.com|'); + formatButton('link.png','','[[',']]','','l'); + formatButton('extlink.png','','[[',']]','http://www.example.com|'); - formatButton('images/list.png','',' - ','\n',''); - formatButton('images/list_ul.png','',' * ','\n',''); + formatButton('list.png','',' - ','\n',''); + formatButton('list_ul.png','',' * ','\n',''); - insertButton('images/rule.png','','----\n'); - mediaButton('images/image.png','','m',''); + insertButton('rule.png','','----\n'); + mediaButton('image.png','','m',''); diff --git a/inc/init.php b/inc/init.php index 363518b65..dd5614d42 100644 --- a/inc/init.php +++ b/inc/init.php @@ -30,14 +30,14 @@ if(!defined('DOKU_URL')) define('DOKU_URL',getBaseURL(true)); // define Plugin dir - if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'inc/plugins/'); + if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); // define main script if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php'); // define Template baseURL if(!defined('DOKU_TPL')) define('DOKU_TPL', - DOKU_BASE.'tpl/'.$conf['template'].'/'); + DOKU_BASE.'lib/tpl/'.$conf['template'].'/'); // make session rewrites XHTML compliant @ini_set('arg_separator.output', '&'); @@ -72,16 +72,29 @@ } // make real paths and check them - $conf['datadir'] = realpath($conf['datadir']); + $conf['datadir'] = init_path($conf['datadir']); if(!$conf['datadir']) die('Wrong datadir! Check config!'); - $conf['olddir'] = realpath($conf['olddir']); + $conf['olddir'] = init_path($conf['olddir']); if(!$conf['olddir']) die('Wrong olddir! Check config!'); - $conf['mediadir'] = realpath($conf['mediadir']); + $conf['mediadir'] = init_path($conf['mediadir']); if(!$conf['mediadir']) die('Wrong mediadir! Check config!'); // automatic upgrade to script versions of certain files - scriptify('conf/users.auth'); - scriptify('conf/acl.auth'); + scriptify(DOKU_INC.'conf/users.auth'); + scriptify(DOKU_INC.'conf/acl.auth'); + + +/** + * returns absolute path + * + * This tries the given past first, then checks in DOKU_INC + */ +function init_path($path){ + $p = realpath($path); + if($p) return $p; + $p = realpath(DOKU_INC.$path); + return $p; +} /** * remove magic quotes recursivly @@ -123,6 +136,9 @@ function getBaseURL($abs=false){ $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); //finish here for relative URLs if(!$abs) return $dir; diff --git a/inc/io.php b/inc/io.php index 3981757da..a3e5f85c4 100644 --- a/inc/io.php +++ b/inc/io.php @@ -9,55 +9,6 @@ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); require_once(DOKU_INC.'inc/common.php'); -/** - * Returns the parsed text from the given sourcefile. Uses cache - * if exists. Creates it if not. - * - * @author Andreas Gohr - * @deprecated -> parserutils - */ -function io_cacheParse($file){ - trigger_error("deprecated io_cacheParse called"); - - global $conf; - global $CACHEGROUP; - global $parser; //we read parser options - $parsed = ''; - $cache = $conf['datadir'].'/_cache/'; - $cache .= md5($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].$CACHEGROUP); - $purge = $conf['datadir'].'/_cache/purgefile'; - - // check if cache can be used - $cachetime = @filemtime($cache); - - if( @file_exists($cache) // does the cachefile exist - && @file_exists($file) // and does the source exist - && !isset($_REQUEST['purge']) // no purge param was set - && filesize($cache) // and contains the cachefile any data - && ((time() - $cachetime) < $conf['cachetime']) // and is cachefile young enough - && ($cachetime > filemtime($file)) // and newer than the source - && ($cachetime > @filemtime($purge)) // and newer than the purgefile - && ($cachetime > filemtime('conf/dokuwiki.php')) // and newer than the config file - && ($cachetime > @filemtime('conf/local.php')) // and newer than the local config file - && ($cachetime > filemtime('inc/parser.php')) // and newer than the parser - && ($cachetime > filemtime('inc/format.php'))) // and newer than the formating functions - { - $parsed = io_readFile($cache); //give back cache - $parsed .= "\n\n"; - }elseif(@file_exists($file)){ - $parsed = parse(io_readFile($file)); //sets global parseroptions - if($parser['cache']){ - io_saveFile($cache,$parsed); //save cachefile - $parsed .= "\n\n"; - }else{ - @unlink($cache); //try to delete cachefile - $parsed .= "\n\n"; - } - } - - return $parsed; -} - /** * Removes empty directories * diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 5c3c8f86e..dde735b2f 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -73,8 +73,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { /* The (+/-) version will work too but needs some CSS tweaking to look fine */ /* $this->doc .= ' '; $this->doc .= $lang['toc']; $this->doc .= ''.DOKU_LF; @@ -376,12 +376,10 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } } - /** - */ function smiley($smiley) { if ( array_key_exists($smiley, $this->smileys) ) { $title = $this->_xmlEntities($this->smileys[$smiley]); - $this->doc .= 'smileys[$smiley]. '" align="middle" alt="'. $this->_xmlEntities($smiley).'" />'; } else { @@ -389,7 +387,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } } - /** + /* * not used function wordblock($word) { if ( array_key_exists($word, $this->badwords) ) { @@ -566,10 +564,10 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(!$isImage){ //if ico exists set additional style - if(@file_exists(DOKU_INC.'interwiki/'.$wikiName.'.png')){ - $link['style']='background-image: url('.DOKU_BASE.'interwiki/'.$wikiName.'.png)'; + if(@file_exists(DOKU_INC.'lib/images/interwiki/'.$wikiName.'.png')){ + $link['style']='background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$wikiName.'.png)'; }elseif(@file_exists(DOKU_INC.'interwiki/'.$wikiName.'.gif')){ - $link['style']='background-image: url('.DOKU_BASE.'interwiki/'.$wikiName.'.gif)'; + $link['style']='background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$wikiName.'.gif)'; } } @@ -714,7 +712,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['target'] = $conf['target']['media']; $link['title'] = $this->_xmlEntities($src); - $link['url'] = DOKU_BASE.'fetch.php?cache='.$cache.'&media='.urlencode($src); + $link['url'] = DOKU_BASE.'lib/exe/fetch.php?cache='.$cache.'&media='.urlencode($src); $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); @@ -738,7 +736,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['target'] = $conf['target']['media']; $link['title'] = $this->_xmlEntities($src); - $link['url'] = DOKU_BASE.'fetch.php?cache='.$cache.'&media='.urlencode($src); + $link['url'] = DOKU_BASE.'lib/exe/fetch.php?cache='.$cache.'&media='.urlencode($src); $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); @@ -893,7 +891,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { list($ext,$mime) = mimetype($src); if(substr($mime,0,5) == 'image'){ //add image tag - $ret .= '_xmlEntities($width).'"'; if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; $ret .= '>'.DOKU_LF; - $ret .= ''.DOKU_LF; + $ret .= ''.DOKU_LF; $ret .= ''.DOKU_LF; - $ret .= '_xmlEntities($width).'"'; if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; diff --git a/inc/plugins/info/syntax.php b/inc/plugins/info/syntax.php deleted file mode 100644 index bf45e5d11..000000000 --- a/inc/plugins/info/syntax.php +++ /dev/null @@ -1,110 +0,0 @@ - - */ - -if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); -if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'inc/plugins/'); -require_once(DOKU_PLUGIN.'syntax.php'); - -/** - * All DokuWiki plugins to extend the parser/rendering mechanism - * need to inherit from this class - */ -class syntax_plugin_info extends DokuWiki_Syntax_Plugin { - - /** - * What kind of syntax are we? - */ - function getType(){ - return 'substition'; - } - - /** - * Where to sort in? - */ - function getSort(){ - return 155; - } - - - /** - * Connect pattern to lexer - */ - function connectTo($mode) { - $this->Lexer->addSpecialPattern('~~INFO:\w+~~',$mode,'plugin_info'); - } - - - /** - * Handle the match - */ - function handle($match, $state, $pos, &$handler){ - $match = substr($match,7,-2); //strip ~~INFO: from start and ~~ from end - return array(strtolower($match)); - } - - /** - * Create output - */ - function render($mode, &$renderer, $data) { - if($mode == 'xhtml'){ - //handle various info stuff - switch ($data[0]){ - case 'version'; - $renderer->doc .= getVersion(); - break; - case 'syntaxmodes'; - $renderer->doc .= $this->_syntaxmodes_xhtml(); - break; - case 'syntaxtypes'; - $renderer->doc .= $this->_syntaxtypes_xhtml(); - break; - default: - $renderer->doc .= "no info about ".htmlspecialchars($data[0]); - } - return true; - } - return false; - } - - /** - * lists all known syntax types and their registered modes - */ - function _syntaxtypes_xhtml(){ - global $PARSER_MODES; - $doc = ''; - - $doc .= ''; - foreach($PARSER_MODES as $mode => $modes){ - $doc .= ''; - $doc .= ''; - $doc .= ''; - $doc .= ''; - } - $doc .= '
'; - $doc .= $mode; - $doc .= ''; - $doc .= join(', ',$modes); - $doc .= '
'; - return $doc; - } - - /** - * lists all known syntax modes and their sorting value - */ - function _syntaxmodes_xhtml(){ - $modes = p_get_parsermodes(); - $doc = ''; - - foreach ($modes as $mode){ - $doc .= $mode['mode'].' ('.$mode['sort'].'), '; - } - return $doc; - } -} - -//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/inc/plugins/syntax.php b/inc/plugins/syntax.php deleted file mode 100644 index bb5680cd3..000000000 --- a/inc/plugins/syntax.php +++ /dev/null @@ -1,66 +0,0 @@ - - */ - -if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); -if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'inc/plugins/'); -require_once(DOKU_INC.'inc/parser/parser.php'); - -/** - * All DokuWiki plugins to extend the parser/rendering mechanism - * need to inherit from this class - */ -class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { - - /** - * Needs to return one of the mode types defined in $PARSER_MODES in parser.php - */ - function getType(){ - trigger_error('getType() not implemented in '.get_class($this), E_USER_WARNING); - } - - /** - * Handler to prepare matched data for the rendering process - * - * Usually you should only need the $match param. - * - * @param $match string The text matched by the patterns - * @param $state int The lexer state for the match - * @param $pos int The character position of the matched text - * @param $handler ref Reference to the Doku_Handler object - * @return array Return an array with all data you want to use in render - */ - function handle($match, $state, $pos, &$handler){ - trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING); - } - - /** - * Handles the actual output creation. - * - * The function should always check for the given mode and return false - * when a mode isn't supported. - * - * $renderer contains a reference to the renderer object which is - * currently handling the rendering. You need to use it for writing - * the output. How this is done depends on the renderer used (specified - * by $mode - * - * The contents of the $data array depends on what the handler() function above - * created - * - * @param $mode string current Rendermode - * @param $renderer ref reference to the current renderer object - * @param $data array data created by handler() - * @return boolean rendered correctly? - */ - function render($mode, &$renderer, $data) { - trigger_error('render() not implemented in '.get_class($this), E_USER_WARNING); - } - -} - -//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/inc/template.php b/inc/template.php index 11a1112d0..43c224926 100644 --- a/inc/template.php +++ b/inc/template.php @@ -145,7 +145,7 @@ function tpl_metaheaders(){ ptln('',$it); ptln('',$it); ptln('',$it); - ptln('',$it); + ptln('',$it); // setup robot tags apropriate for different modes if( ($ACT=='show' || $ACT=='export_html') && !$REV){ @@ -172,9 +172,12 @@ function tpl_metaheaders(){ ptln('',$it); // load the default JavaScript files - ptln('',$it); - ptln('',$it); - ptln('',$it); + ptln('',$it); + ptln('',$it); + ptln('',$it); //FIXME include some default CSS ? IE FIX? } @@ -571,9 +574,9 @@ function tpl_mediafilelist(){ $ask = $lang['del_confirm'].'\\n'; $ask .= $item['id']; - $del = ''. - ''.$lang['btn_delete'].''; }else{ $del = ''; @@ -589,9 +592,9 @@ function tpl_mediafilelist(){ ptln(''); if($w>120){ - print ''; + print ''; }else{ - print ''; + print ''; } print ''; -- cgit v1.2.3