Coding Standard Cleanup

Ignore-this: 259cb5773c3144c6c706d87298dcf674

darcs-hash:20091020212338-7ad00-6bf1c5c403491f136a1c02af5ecd9f84d7227107.gz
This commit is contained in:
Andreas Gohr 2009-10-20 23:23:38 +02:00
parent 8ec3f7bdbf
commit db959ae307
20 changed files with 4318 additions and 4294 deletions

102
doku.php
View File

@ -8,74 +8,74 @@
// xdebug_start_profiling();
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/events.php');
require_once(DOKU_INC.'inc/pageutils.php');
require_once(DOKU_INC.'inc/html.php');
require_once(DOKU_INC.'inc/auth.php');
require_once(DOKU_INC.'inc/actions.php');
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/events.php');
require_once(DOKU_INC.'inc/pageutils.php');
require_once(DOKU_INC.'inc/html.php');
require_once(DOKU_INC.'inc/auth.php');
require_once(DOKU_INC.'inc/actions.php');
//import variables
$QUERY = trim($_REQUEST['id']);
$ID = getID();
$NS = getNS($ID);
$REV = $_REQUEST['rev'];
$ACT = $_REQUEST['do'];
$IDX = $_REQUEST['idx'];
$DATE = $_REQUEST['date'];
$RANGE = $_REQUEST['lines'];
$HIGH = $_REQUEST['s'];
if(empty($HIGH)) $HIGH = getGoogleQuery();
//import variables
$QUERY = trim($_REQUEST['id']);
$ID = getID();
$NS = getNS($ID);
$REV = $_REQUEST['rev'];
$ACT = $_REQUEST['do'];
$IDX = $_REQUEST['idx'];
$DATE = $_REQUEST['date'];
$RANGE = $_REQUEST['lines'];
$HIGH = $_REQUEST['s'];
if(empty($HIGH)) $HIGH = getGoogleQuery();
$TEXT = cleanText($_POST['wikitext']);
$PRE = cleanText($_POST['prefix']);
$SUF = cleanText($_POST['suffix']);
$SUM = $_REQUEST['summary'];
$TEXT = cleanText($_POST['wikitext']);
$PRE = cleanText($_POST['prefix']);
$SUF = cleanText($_POST['suffix']);
$SUM = $_REQUEST['summary'];
//sanitize revision
$REV = preg_replace('/[^0-9]/','',$REV);
//sanitize revision
$REV = preg_replace('/[^0-9]/','',$REV);
//we accept the do param as HTTP header, too:
if(!empty($_SERVER['HTTP_X_DOKUWIKI_DO'])){
//we accept the do param as HTTP header, too:
if(!empty($_SERVER['HTTP_X_DOKUWIKI_DO'])){
$ACT = trim(strtolower($_SERVER['HTTP_X_DOKUWIKI_DO']));
}
}
if(!empty($IDX)) $ACT='index';
//set default #FIXME not needed here? done in actions?
if(empty($ACT)) $ACT = 'show';
if(!empty($IDX)) $ACT='index';
//set default #FIXME not needed here? done in actions?
if(empty($ACT)) $ACT = 'show';
//make infos about the selected page available
$INFO = pageinfo();
//make infos about the selected page available
$INFO = pageinfo();
// handle debugging
if($conf['allowdebug'] && $ACT == 'debug'){
// handle debugging
if($conf['allowdebug'] && $ACT == 'debug'){
html_debug();
exit;
}
}
//send 404 for missing pages if configured or ID has special meaning to bots
if(!$INFO['exists'] &&
($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/',$ID)) &&
($ACT == 'show' || substr($ACT,0,7) == 'export_') ){
//send 404 for missing pages if configured or ID has special meaning to bots
if(!$INFO['exists'] &&
($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/',$ID)) &&
($ACT == 'show' || substr($ACT,0,7) == 'export_') ){
header('HTTP/1.0 404 Not Found');
}
}
//prepare breadcrumbs (initialize a static var)
if ($conf['breadcrumbs']) breadcrumbs();
//prepare breadcrumbs (initialize a static var)
if ($conf['breadcrumbs']) breadcrumbs();
// check upstream
checkUpdateMessages();
// check upstream
checkUpdateMessages();
trigger_event('DOKUWIKI_STARTED',$tmp=array());
trigger_event('DOKUWIKI_STARTED',$tmp=array());
//close session
session_write_close();
//close session
session_write_close();
//do the work
act_dispatch($ACT);
//do the work
act_dispatch($ACT);
trigger_event('DOKUWIKI_DONE', $tmp=array());
trigger_event('DOKUWIKI_DONE', $tmp=array());
// xdebug_dump_function_profile(1);

141
feed.php
View File

@ -6,74 +6,74 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/events.php');
require_once(DOKU_INC.'inc/parserutils.php');
require_once(DOKU_INC.'inc/feedcreator.class.php');
require_once(DOKU_INC.'inc/auth.php');
require_once(DOKU_INC.'inc/pageutils.php');
require_once(DOKU_INC.'inc/httputils.php');
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/events.php');
require_once(DOKU_INC.'inc/parserutils.php');
require_once(DOKU_INC.'inc/feedcreator.class.php');
require_once(DOKU_INC.'inc/auth.php');
require_once(DOKU_INC.'inc/pageutils.php');
require_once(DOKU_INC.'inc/httputils.php');
//close session
session_write_close();
//close session
session_write_close();
// get params
$opt = rss_parseOptions();
// get params
$opt = rss_parseOptions();
// the feed is dynamic - we need a cache for each combo
// (but most people just use the default feed so it's still effective)
$cache = getCacheName(join('',array_values($opt)).$_SERVER['REMOTE_USER'],'.feed');
$cmod = @filemtime($cache); // 0 if not exists
if ($cmod && (@filemtime(DOKU_CONF.'local.php')>$cmod || @filemtime(DOKU_CONF.'dokuwiki.php')>$cmod)) {
// the feed is dynamic - we need a cache for each combo
// (but most people just use the default feed so it's still effective)
$cache = getCacheName(join('',array_values($opt)).$_SERVER['REMOTE_USER'],'.feed');
$cmod = @filemtime($cache); // 0 if not exists
if ($cmod && (@filemtime(DOKU_CONF.'local.php')>$cmod || @filemtime(DOKU_CONF.'dokuwiki.php')>$cmod)) {
// ignore cache if feed prefs may have changed
$cmod = 0;
}
}
// check cacheage and deliver if nothing has changed since last
// time or the update interval has not passed, also handles conditional requests
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Type: application/xml; charset=utf-8');
header('X-Robots-Tag: noindex');
if($cmod && (($cmod+$conf['rss_update']>time()) || ($cmod>@filemtime($conf['changelog'])))){
// check cacheage and deliver if nothing has changed since last
// time or the update interval has not passed, also handles conditional requests
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Type: application/xml; charset=utf-8');
header('X-Robots-Tag: noindex');
if($cmod && (($cmod+$conf['rss_update']>time()) || ($cmod>@filemtime($conf['changelog'])))){
http_conditionalRequest($cmod);
if($conf['allowdebug']) header("X-CacheUsed: $cache");
print io_readFile($cache);
exit;
} else {
} else {
http_conditionalRequest(time());
}
}
// create new feed
$rss = new DokuWikiFeedCreator();
$rss->title = $conf['title'].(($opt['namespace']) ? ' '.$opt['namespace'] : '');
$rss->link = DOKU_URL;
$rss->syndicationURL = DOKU_URL.'feed.php';
$rss->cssStyleSheet = DOKU_URL.'lib/exe/css.php?s=feed';
// create new feed
$rss = new DokuWikiFeedCreator();
$rss->title = $conf['title'].(($opt['namespace']) ? ' '.$opt['namespace'] : '');
$rss->link = DOKU_URL;
$rss->syndicationURL = DOKU_URL.'feed.php';
$rss->cssStyleSheet = DOKU_URL.'lib/exe/css.php?s=feed';
$image = new FeedImage();
$image->title = $conf['title'];
$image->url = DOKU_URL."lib/images/favicon.ico";
$image->link = DOKU_URL;
$rss->image = $image;
$image = new FeedImage();
$image->title = $conf['title'];
$image->url = DOKU_URL."lib/images/favicon.ico";
$image->link = DOKU_URL;
$rss->image = $image;
if($opt['feed_mode'] == 'list'){
if($opt['feed_mode'] == 'list'){
rssListNamespace($rss,$opt);
}elseif($opt['feed_mode'] == 'search'){
}elseif($opt['feed_mode'] == 'search'){
rssSearch($rss,$opt);
}else{
}else{
rssRecentChanges($rss,$opt);
}
}
$feed = $rss->createFeed($opt['feed_type'],'utf-8');
$feed = $rss->createFeed($opt['feed_type'],'utf-8');
// save cachefile
io_saveFile($cache,$feed);
// save cachefile
io_saveFile($cache,$feed);
// finally deliver
print $feed;
// finally deliver
print $feed;
// ---------------------------------------------------------------- //
@ -101,25 +101,25 @@ function rss_parseOptions(){
$opt['guardmail'] = ($conf['mailguard'] != '' && $conf['mailguard'] != 'none');
switch ($opt['feed_type']){
case 'rss':
$opt['feed_type'] = 'RSS0.91';
$opt['mime_type'] = 'text/xml';
break;
case 'rss2':
$opt['feed_type'] = 'RSS2.0';
$opt['mime_type'] = 'text/xml';
break;
case 'atom':
$opt['feed_type'] = 'ATOM0.3';
$opt['mime_type'] = 'application/xml';
break;
case 'atom1':
$opt['feed_type'] = 'ATOM1.0';
$opt['mime_type'] = 'application/atom+xml';
break;
default:
$opt['feed_type'] = 'RSS1.0';
$opt['mime_type'] = 'application/xml';
case 'rss':
$opt['feed_type'] = 'RSS0.91';
$opt['mime_type'] = 'text/xml';
break;
case 'rss2':
$opt['feed_type'] = 'RSS2.0';
$opt['mime_type'] = 'text/xml';
break;
case 'atom':
$opt['feed_type'] = 'ATOM0.3';
$opt['mime_type'] = 'application/xml';
break;
case 'atom1':
$opt['feed_type'] = 'ATOM1.0';
$opt['mime_type'] = 'application/atom+xml';
break;
default:
$opt['feed_type'] = 'RSS1.0';
$opt['mime_type'] = 'application/xml';
}
return $opt;
}
@ -229,7 +229,6 @@ function rss_buildItems(&$rss,&$data,$opt){
}
$item->description = $content; //FIXME a plugin hook here could be senseful
// add user
# FIXME should the user be pulled from metadata as well?
$user = null;
@ -256,8 +255,8 @@ function rss_buildItems(&$rss,&$data,$opt){
if($meta['subject']){
$item->category = $meta['subject'];
}else{
$cat = getNS($id);
if($cat) $item->category = $cat;
$cat = getNS($id);
if($cat) $item->category = $cat;
}
// finally add the item to the feed object, after handing it to registered plugins
@ -267,7 +266,7 @@ function rss_buildItems(&$rss,&$data,$opt){
'rss' => &$rss);
$evt = new Doku_Event('FEED_ITEM_ADD', $evdata);
if ($evt->advise_before()){
$rss->addItem($item);
$rss->addItem($item);
}
$evt->advise_after(); // for completeness
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -19,45 +19,45 @@ define('HTTP_CHUNK_SIZE',16*1024);
* @returns void or exits with previously header() commands executed
*/
function http_conditionalRequest($timestamp){
// A PHP implementation of conditional get, see
// http://fishbowl.pastiche.org/archives/001132.html
$last_modified = substr(gmdate('r', $timestamp), 0, -5).'GMT';
$etag = '"'.md5($last_modified).'"';
// Send the headers
header("Last-Modified: $last_modified");
header("ETag: $etag");
// See if the client has provided the required headers
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
$if_modified_since = stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']);
}else{
$if_modified_since = false;
}
// A PHP implementation of conditional get, see
// http://fishbowl.pastiche.org/archives/001132.html
$last_modified = substr(gmdate('r', $timestamp), 0, -5).'GMT';
$etag = '"'.md5($last_modified).'"';
// Send the headers
header("Last-Modified: $last_modified");
header("ETag: $etag");
// See if the client has provided the required headers
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
$if_modified_since = stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']);
}else{
$if_modified_since = false;
}
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])){
$if_none_match = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
}else{
$if_none_match = false;
}
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])){
$if_none_match = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
}else{
$if_none_match = false;
}
if (!$if_modified_since && !$if_none_match){
return;
}
if (!$if_modified_since && !$if_none_match){
return;
}
// At least one of the headers is there - check them
if ($if_none_match && $if_none_match != $etag) {
return; // etag is there but doesn't match
}
// At least one of the headers is there - check them
if ($if_none_match && $if_none_match != $etag) {
return; // etag is there but doesn't match
}
if ($if_modified_since && $if_modified_since != $last_modified) {
return; // if-modified-since is there but doesn't match
}
if ($if_modified_since && $if_modified_since != $last_modified) {
return; // if-modified-since is there but doesn't match
}
// Nothing has changed since their last request - serve a 304 and exit
header('HTTP/1.0 304 Not Modified');
// Nothing has changed since their last request - serve a 304 and exit
header('HTTP/1.0 304 Not Modified');
// don't produce output, even if compression is on
ob_end_clean();
exit;
// don't produce output, even if compression is on
ob_end_clean();
exit;
}
/**
@ -67,24 +67,24 @@ function http_conditionalRequest($timestamp){
* @returns void or exits with previously header() commands executed
*/
function http_sendfile($file) {
global $conf;
global $conf;
//use x-sendfile header to pass the delivery to compatible webservers
if($conf['xsendfile'] == 1){
header("X-LIGHTTPD-send-file: $file");
ob_end_clean();
exit;
}elseif($conf['xsendfile'] == 2){
header("X-Sendfile: $file");
ob_end_clean();
exit;
}elseif($conf['xsendfile'] == 3){
header("X-Accel-Redirect: $file");
ob_end_clean();
exit;
}
//use x-sendfile header to pass the delivery to compatible webservers
if($conf['xsendfile'] == 1){
header("X-LIGHTTPD-send-file: $file");
ob_end_clean();
exit;
}elseif($conf['xsendfile'] == 2){
header("X-Sendfile: $file");
ob_end_clean();
exit;
}elseif($conf['xsendfile'] == 3){
header("X-Accel-Redirect: $file");
ob_end_clean();
exit;
}
return false;
return false;
}
/**
@ -166,11 +166,11 @@ function http_rangeRequest($fh,$size,$mime){
fseek($fh,$start); //seek to start of range
$chunk = ($len > HTTP_CHUNK_SIZE) ? HTTP_CHUNK_SIZE : $len;
while (!feof($fh) && $chunk > 0) {
@set_time_limit(30); // large files can take a lot of time
print fread($fh, $chunk);
flush();
$len -= $chunk;
$chunk = ($len > HTTP_CHUNK_SIZE) ? HTTP_CHUNK_SIZE : $len;
@set_time_limit(30); // large files can take a lot of time
print fread($fh, $chunk);
flush();
$len -= $chunk;
$chunk = ($len > HTTP_CHUNK_SIZE) ? HTTP_CHUNK_SIZE : $len;
}
}
if($parts > 1){

View File

@ -227,18 +227,18 @@ function idx_getPageWords($page){
// ensure the deaccented or romanised page names of internal links are added to the token array
// (this is necessary for the backlink function -- there maybe a better way!)
if ($conf['deaccent']) {
$links = p_get_metadata($page,'relation references');
$links = p_get_metadata($page,'relation references');
if (!empty($links)) {
$tmp = join(' ',array_keys($links)); // make a single string
$tmp = strtr($tmp, ':', ' '); // replace namespace separator with a space
$link_tokens = array_unique(explode(' ', $tmp)); // break into tokens
if (!empty($links)) {
$tmp = join(' ',array_keys($links)); // make a single string
$tmp = strtr($tmp, ':', ' '); // replace namespace separator with a space
$link_tokens = array_unique(explode(' ', $tmp)); // break into tokens
foreach ($link_tokens as $link_token) {
if (isset($tokens[$link_token])) continue;
$tokens[$link_token] = 1;
foreach ($link_tokens as $link_token) {
if (isset($tokens[$link_token])) continue;
$tokens[$link_token] = 1;
}
}
}
}
$words = array();
@ -537,7 +537,7 @@ function idx_getIndexWordsSorted($words,&$result){
}
}
}
return $wids;
return $wids;
}
/**
@ -664,7 +664,9 @@ function idx_upgradePageWords(){
if (empty($page_idx)) return;
$pagewords = array();
$len = count($page_idx);
for ($n=0;$n<$len;$n++) $pagewords[] = array();
for ($n=0;$n<$len;$n++){
$pagewords[] = array();
}
unset($page_idx);
$n=0;

View File

@ -49,25 +49,25 @@ function checkUpdateMessages(){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getVersion(){
//import version string
if(@file_exists(DOKU_INC.'VERSION')){
//official release
return 'Release '.trim(io_readfile(DOKU_INC.'VERSION'));
}elseif(is_dir(DOKU_INC.'_darcs')){
//darcs checkout - read last 2000 bytes of inventory
$sz = filesize(DOKU_INC.'_darcs/inventory');
$seek = max(0,$sz-2000);
$fh = fopen(DOKU_INC.'_darcs/inventory','rb');
fseek($fh,$seek);
$chunk = fread($fh,2000);
fclose($fh);
$inv = preg_grep('#\*\*\d{14}[\]$]#',explode("\n",$chunk));
$cur = array_pop($inv);
preg_match('#\*\*(\d{4})(\d{2})(\d{2})#',$cur,$matches);
return 'Darcs '.$matches[1].'-'.$matches[2].'-'.$matches[3];
}else{
return 'snapshot?';
}
//import version string
if(@file_exists(DOKU_INC.'VERSION')){
//official release
return 'Release '.trim(io_readfile(DOKU_INC.'VERSION'));
}elseif(is_dir(DOKU_INC.'_darcs')){
//darcs checkout - read last 2000 bytes of inventory
$sz = filesize(DOKU_INC.'_darcs/inventory');
$seek = max(0,$sz-2000);
$fh = fopen(DOKU_INC.'_darcs/inventory','rb');
fseek($fh,$seek);
$chunk = fread($fh,2000);
fclose($fh);
$inv = preg_grep('#\*\*\d{14}[\]$]#',explode("\n",$chunk));
$cur = array_pop($inv);
preg_match('#\*\*(\d{4})(\d{2})(\d{2})#',$cur,$matches);
return 'Darcs '.$matches[1].'-'.$matches[2].'-'.$matches[3];
}else{
return 'snapshot?';
}
}
/**
@ -76,148 +76,147 @@ function getVersion(){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function check(){
global $conf;
global $INFO;
global $conf;
global $INFO;
msg('DokuWiki version: '.getVersion(),1);
msg('DokuWiki version: '.getVersion(),1);
if(version_compare(phpversion(),'5.0.0','<')){
msg('Your PHP version is too old ('.phpversion().' vs. 5.0.0+ recommended)',-1);
}else{
msg('PHP version '.phpversion(),1);
}
$mem = (int) php_to_byte(ini_get('memory_limit'));
if($mem){
if($mem < 16777216){
msg('PHP is limited to less than 16MB RAM ('.$mem.' bytes). Increase memory_limit in php.ini',-1);
}elseif($mem < 20971520){
msg('PHP is limited to less than 20MB RAM ('.$mem.' bytes), you might encounter problems with bigger pages. Increase memory_limit in php.ini',-1);
}elseif($mem < 33554432){
msg('PHP is limited to less than 32MB RAM ('.$mem.' bytes), but that should be enough in most cases. If not, increase memory_limit in php.ini',0);
if(version_compare(phpversion(),'5.0.0','<')){
msg('Your PHP version is too old ('.phpversion().' vs. 5.0.0+ recommended)',-1);
}else{
msg('More than 32MB RAM ('.$mem.' bytes) available.',1);
msg('PHP version '.phpversion(),1);
}
}
if(is_writable($conf['changelog'])){
msg('Changelog is writable',1);
}else{
if (@file_exists($conf['changelog'])) {
msg('Changelog is not writable',-1);
$mem = (int) php_to_byte(ini_get('memory_limit'));
if($mem){
if($mem < 16777216){
msg('PHP is limited to less than 16MB RAM ('.$mem.' bytes). Increase memory_limit in php.ini',-1);
}elseif($mem < 20971520){
msg('PHP is limited to less than 20MB RAM ('.$mem.' bytes), you might encounter problems with bigger pages. Increase memory_limit in php.ini',-1);
}elseif($mem < 33554432){
msg('PHP is limited to less than 32MB RAM ('.$mem.' bytes), but that should be enough in most cases. If not, increase memory_limit in php.ini',0);
}else{
msg('More than 32MB RAM ('.$mem.' bytes) available.',1);
}
}
}
if (isset($conf['changelog_old']) && @file_exists($conf['changelog_old'])) {
msg('Old changelog exists', 0);
}
if (@file_exists($conf['changelog'].'_failed')) {
msg('Importing old changelog failed', -1);
} else if (@file_exists($conf['changelog'].'_importing')) {
msg('Importing old changelog now.', 0);
} else if (@file_exists($conf['changelog'].'_import_ok')) {
msg('Old changelog imported', 1);
if (!plugin_isdisabled('importoldchangelog')) {
msg('Importoldchangelog plugin not disabled after import', -1);
}
}
if(is_writable($conf['datadir'])){
msg('Datadir is writable',1);
}else{
msg('Datadir is not writable',-1);
}
if(is_writable($conf['olddir'])){
msg('Attic is writable',1);
}else{
msg('Attic is not writable',-1);
}
if(is_writable($conf['mediadir'])){
msg('Mediadir is writable',1);
}else{
msg('Mediadir is not writable',-1);
}
if(is_writable($conf['cachedir'])){
msg('Cachedir is writable',1);
}else{
msg('Cachedir is not writable',-1);
}
if(is_writable($conf['lockdir'])){
msg('Lockdir is writable',1);
}else{
msg('Lockdir is not writable',-1);
}
if($conf['authtype'] == 'plain'){
if(is_writable(DOKU_CONF.'users.auth.php')){
msg('conf/users.auth.php is writable',1);
if(is_writable($conf['changelog'])){
msg('Changelog is writable',1);
}else{
msg('conf/users.auth.php is not writable',0);
if (@file_exists($conf['changelog'])) {
msg('Changelog is not writable',-1);
}
}
}
if(function_exists('mb_strpos')){
if(defined('UTF8_NOMBSTRING')){
msg('mb_string extension is available but will not be used',0);
if (isset($conf['changelog_old']) && @file_exists($conf['changelog_old'])) {
msg('Old changelog exists', 0);
}
if (@file_exists($conf['changelog'].'_failed')) {
msg('Importing old changelog failed', -1);
} else if (@file_exists($conf['changelog'].'_importing')) {
msg('Importing old changelog now.', 0);
} else if (@file_exists($conf['changelog'].'_import_ok')) {
msg('Old changelog imported', 1);
if (!plugin_isdisabled('importoldchangelog')) {
msg('Importoldchangelog plugin not disabled after import', -1);
}
}
if(is_writable($conf['datadir'])){
msg('Datadir is writable',1);
}else{
msg('mb_string extension is available and will be used',1);
if(ini_get('mbstring.func_overload') != 0){
msg('mb_string function overloading is enabled, this will cause problems and should be disabled',-1);
}
msg('Datadir is not writable',-1);
}
}else{
msg('mb_string extension not available - PHP only replacements will be used',0);
}
if($conf['allowdebug']){
msg('Debugging support is enabled. If you don\'t need it you should set $conf[\'allowdebug\'] = 0',-1);
}else{
msg('Debugging support is disabled',1);
}
if(is_writable($conf['olddir'])){
msg('Attic is writable',1);
}else{
msg('Attic is not writable',-1);
}
if($INFO['userinfo']['name']){
msg('You are currently logged in as '.$_SERVER['REMOTE_USER'].' ('.$INFO['userinfo']['name'].')',0);
msg('You are part of the groups '.join($INFO['userinfo']['grps'],', '),0);
}else{
msg('You are currently not logged in',0);
}
if(is_writable($conf['mediadir'])){
msg('Mediadir is writable',1);
}else{
msg('Mediadir is not writable',-1);
}
msg('Your current permission for this page is '.$INFO['perm'],0);
if(is_writable($conf['cachedir'])){
msg('Cachedir is writable',1);
}else{
msg('Cachedir is not writable',-1);
}
if(is_writable($INFO['filepath'])){
msg('The current page is writable by the webserver',0);
}else{
msg('The current page is not writable by the webserver',0);
}
if(is_writable($conf['lockdir'])){
msg('Lockdir is writable',1);
}else{
msg('Lockdir is not writable',-1);
}
if($INFO['writable']){
msg('The current page is writable by you',0);
}else{
msg('The current page is not writable by you',0);
}
if($conf['authtype'] == 'plain'){
if(is_writable(DOKU_CONF.'users.auth.php')){
msg('conf/users.auth.php is writable',1);
}else{
msg('conf/users.auth.php is not writable',0);
}
}
require_once(DOKU_INC.'inc/HTTPClient.php');
$check = wl('','',true).'data/_dummy';
$http = new DokuHTTPClient();
$http->timeout = 6;
$res = $http->get($check);
if(strpos($res,'data directory') !== false){
msg('It seems like the data directory is accessible from the web.
Make sure this directory is properly protected
(See <a href="http://www.dokuwiki.org/security">security</a>)',-1);
}elseif($http->status == 404 || $http->status == 403){
msg('The data directory seems to be properly protected',1);
}else{
msg('Failed to check if the data directory is accessible from the web.
Make sure this directory is properly protected
(See <a href="http://www.dokuwiki.org/security">security</a>)',-1);
}
if(function_exists('mb_strpos')){
if(defined('UTF8_NOMBSTRING')){
msg('mb_string extension is available but will not be used',0);
}else{
msg('mb_string extension is available and will be used',1);
if(ini_get('mbstring.func_overload') != 0){
msg('mb_string function overloading is enabled, this will cause problems and should be disabled',-1);
}
}
}else{
msg('mb_string extension not available - PHP only replacements will be used',0);
}
if($conf['allowdebug']){
msg('Debugging support is enabled. If you don\'t need it you should set $conf[\'allowdebug\'] = 0',-1);
}else{
msg('Debugging support is disabled',1);
}
if($INFO['userinfo']['name']){
msg('You are currently logged in as '.$_SERVER['REMOTE_USER'].' ('.$INFO['userinfo']['name'].')',0);
msg('You are part of the groups '.join($INFO['userinfo']['grps'],', '),0);
}else{
msg('You are currently not logged in',0);
}
msg('Your current permission for this page is '.$INFO['perm'],0);
if(is_writable($INFO['filepath'])){
msg('The current page is writable by the webserver',0);
}else{
msg('The current page is not writable by the webserver',0);
}
if($INFO['writable']){
msg('The current page is writable by you',0);
}else{
msg('The current page is not writable by you',0);
}
require_once(DOKU_INC.'inc/HTTPClient.php');
$check = wl('','',true).'data/_dummy';
$http = new DokuHTTPClient();
$http->timeout = 6;
$res = $http->get($check);
if(strpos($res,'data directory') !== false){
msg('It seems like the data directory is accessible from the web.
Make sure this directory is properly protected
(See <a href="http://www.dokuwiki.org/security">security</a>)',-1);
}elseif($http->status == 404 || $http->status == 403){
msg('The data directory seems to be properly protected',1);
}else{
msg('Failed to check if the data directory is accessible from the web.
Make sure this directory is properly protected
(See <a href="http://www.dokuwiki.org/security">security</a>)',-1);
}
}
/**
@ -238,26 +237,26 @@ function check(){
* @see html_msgarea
*/
function msg($message,$lvl=0,$line='',$file=''){
global $MSG;
$errors[-1] = 'error';
$errors[0] = 'info';
$errors[1] = 'success';
$errors[2] = 'notify';
global $MSG;
$errors[-1] = 'error';
$errors[0] = 'info';
$errors[1] = 'success';
$errors[2] = 'notify';
if($line || $file) $message.=' ['.basename($file).':'.$line.']';
if($line || $file) $message.=' ['.basename($file).':'.$line.']';
if(!headers_sent()){
if(!isset($MSG)) $MSG = array();
$MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
}else{
$MSG = array();
$MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
if(function_exists('html_msgarea')){
html_msgarea();
if(!headers_sent()){
if(!isset($MSG)) $MSG = array();
$MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
}else{
print "ERROR($lvl) $message";
$MSG = array();
$MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
if(function_exists('html_msgarea')){
html_msgarea();
}else{
print "ERROR($lvl) $message";
}
}
}
}
/**
@ -268,9 +267,9 @@ function msg($message,$lvl=0,$line='',$file=''){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function dbg($msg,$hidden=false){
(!$hidden) ? print '<pre class="dbg">' : print "<!--\n";
print_r($msg);
(!$hidden) ? print '</pre>' : print "\n-->";
(!$hidden) ? print '<pre class="dbg">' : print "<!--\n";
print_r($msg);
(!$hidden) ? print '</pre>' : print "\n-->";
}
/**
@ -279,19 +278,19 @@ function dbg($msg,$hidden=false){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function dbglog($msg,$header=''){
global $conf;
if(is_object($msg) || is_array($msg)){
$msg = print_r($msg,true);
}
global $conf;
if(is_object($msg) || is_array($msg)){
$msg = print_r($msg,true);
}
if($header) $msg = "$header\n$msg";
if($header) $msg = "$header\n$msg";
$file = $conf['cachedir'].'/debug.log';
$fh = fopen($file,'a');
if($fh){
fwrite($fh,date('H:i:s ').$_SERVER['REMOTE_ADDR'].': '.$msg."\n");
fclose($fh);
}
$file = $conf['cachedir'].'/debug.log';
$fh = fopen($file,'a');
if($fh){
fwrite($fh,date('H:i:s ').$_SERVER['REMOTE_ADDR'].': '.$msg."\n");
fclose($fh);
}
}
/**
@ -300,44 +299,44 @@ function dbglog($msg,$header=''){
* @author Gary Owen <gary_owen@bigfoot.com>
*/
function dbg_backtrace(){
// Get backtrace
$backtrace = debug_backtrace();
// Get backtrace
$backtrace = debug_backtrace();
// Unset call to debug_print_backtrace
array_shift($backtrace);
// Unset call to debug_print_backtrace
array_shift($backtrace);
// Iterate backtrace
$calls = array();
$depth = count($backtrace) - 1;
foreach ($backtrace as $i => $call) {
$location = $call['file'] . ':' . $call['line'];
$function = (isset($call['class'])) ?
$call['class'] . $call['type'] . $call['function'] : $call['function'];
// Iterate backtrace
$calls = array();
$depth = count($backtrace) - 1;
foreach ($backtrace as $i => $call) {
$location = $call['file'] . ':' . $call['line'];
$function = (isset($call['class'])) ?
$call['class'] . $call['type'] . $call['function'] : $call['function'];
$params = array();
if (isset($call['args'])){
foreach($call['args'] as $arg){
if(is_object($arg)){
$params[] = '[Object '.get_class($arg).']';
}elseif(is_array($arg)){
$params[] = '[Array]';
}elseif(is_null($arg)){
$param[] = '[NULL]';
}else{
$params[] = (string) '"'.$arg.'"';
$params = array();
if (isset($call['args'])){
foreach($call['args'] as $arg){
if(is_object($arg)){
$params[] = '[Object '.get_class($arg).']';
}elseif(is_array($arg)){
$params[] = '[Array]';
}elseif(is_null($arg)){
$param[] = '[NULL]';
}else{
$params[] = (string) '"'.$arg.'"';
}
}
}
$params = implode(', ',$params);
$calls[$depth - $i] = sprintf('%s(%s) called at %s',
$function,
str_replace("\n", '\n', $params),
$location);
}
$params = implode(', ',$params);
ksort($calls);
$calls[$depth - $i] = sprintf('%s(%s) called at %s',
$function,
str_replace("\n", '\n', $params),
$location);
}
ksort($calls);
return implode("\n", $calls);
return implode("\n", $calls);
}
/**

View File

@ -3,292 +3,297 @@
* Initialize some defaults needed for DokuWiki
*/
// start timing Dokuwiki execution
function delta_time($start=0) {
// start timing Dokuwiki execution
function delta_time($start=0) {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec+(float)$sec)-((float)$start);
}
define('DOKU_START_TIME', delta_time());
}
define('DOKU_START_TIME', delta_time());
global $config_cascade;
$config_cascade = '';
global $config_cascade;
$config_cascade = '';
// if available load a preload config file
$preload = fullpath(dirname(__FILE__)).'/preload.php';
if (@file_exists($preload)) include($preload);
// if available load a preload config file
$preload = fullpath(dirname(__FILE__)).'/preload.php';
if (@file_exists($preload)) include($preload);
// define the include path
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
// define the include path
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
// define config path (packagers may want to change this to /etc/dokuwiki/)
if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
// define config path (packagers may want to change this to /etc/dokuwiki/)
if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
// check for error reporting override or set error reporting to sane values
if (!defined('DOKU_E_LEVEL') && @file_exists(DOKU_CONF.'report_e_all')) {
// check for error reporting override or set error reporting to sane values
if (!defined('DOKU_E_LEVEL') && @file_exists(DOKU_CONF.'report_e_all')) {
define('DOKU_E_LEVEL', E_ALL);
}
if (!defined('DOKU_E_LEVEL')) {
}
if (!defined('DOKU_E_LEVEL')) {
if(defined('E_DEPRECATED')){ // since php 5.3
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
}else{
error_reporting(E_ALL ^ E_NOTICE);
error_reporting(E_ALL ^ E_NOTICE);
}
} else {
} else {
error_reporting(DOKU_E_LEVEL);
}
}
// init memory caches
global $cache_revinfo; $cache_revinfo = array();
global $cache_wikifn; $cache_wikifn = array();
global $cache_cleanid; $cache_cleanid = array();
global $cache_authname; $cache_authname = array();
global $cache_metadata; $cache_metadata = array();
// init memory caches
global $cache_revinfo;
$cache_revinfo = array();
global $cache_wikifn;
$cache_wikifn = array();
global $cache_cleanid;
$cache_cleanid = array();
global $cache_authname;
$cache_authname = array();
global $cache_metadata;
$cache_metadata = array();
//set the configuration cascade - but only if its not already been set in preload.php
if (empty($config_cascade)) {
//set the configuration cascade - but only if its not already been set in preload.php
if (empty($config_cascade)) {
$config_cascade = array(
'main' => array(
'default' => array(DOKU_CONF.'dokuwiki.php'),
'local' => array(DOKU_CONF.'local.php'),
'protected' => array(DOKU_CONF.'local.protected.php'),
),
'acronyms' => array(
'default' => array(DOKU_CONF.'acronyms.conf'),
'local' => array(DOKU_CONF.'acronyms.local.conf'),
),
'entities' => array(
'default' => array(DOKU_CONF.'entities.conf'),
'local' => array(DOKU_CONF.'entities.local.conf'),
),
'interwiki' => array(
'default' => array(DOKU_CONF.'interwiki.conf'),
'local' => array(DOKU_CONF.'interwiki.local.conf'),
),
'license' => array(
'default' => array(DOKU_CONF.'license.php'),
'local' => array(DOKU_CONF.'license.local.php'),
),
'mediameta' => array(
'default' => array(DOKU_CONF.'mediameta.php'),
'local' => array(DOKU_CONF.'mediameta.local.php'),
),
'mime' => array(
'default' => array(DOKU_CONF.'mime.conf'),
'local' => array(DOKU_CONF.'mime.local.conf'),
),
'scheme' => array(
'default' => array(DOKU_CONF.'scheme.conf'),
'local' => array(DOKU_CONF.'scheme.local.conf'),
),
'smileys' => array(
'default' => array(DOKU_CONF.'smileys.conf'),
'local' => array(DOKU_CONF.'smileys.local.conf'),
),
'wordblock' => array(
'default' => array(DOKU_CONF.'wordblock.conf'),
'local' => array(DOKU_CONF.'wordblock.local.conf'),
),
);
}
'main' => array(
'default' => array(DOKU_CONF.'dokuwiki.php'),
'local' => array(DOKU_CONF.'local.php'),
'protected' => array(DOKU_CONF.'local.protected.php'),
),
'acronyms' => array(
'default' => array(DOKU_CONF.'acronyms.conf'),
'local' => array(DOKU_CONF.'acronyms.local.conf'),
),
'entities' => array(
'default' => array(DOKU_CONF.'entities.conf'),
'local' => array(DOKU_CONF.'entities.local.conf'),
),
'interwiki' => array(
'default' => array(DOKU_CONF.'interwiki.conf'),
'local' => array(DOKU_CONF.'interwiki.local.conf'),
),
'license' => array(
'default' => array(DOKU_CONF.'license.php'),
'local' => array(DOKU_CONF.'license.local.php'),
),
'mediameta' => array(
'default' => array(DOKU_CONF.'mediameta.php'),
'local' => array(DOKU_CONF.'mediameta.local.php'),
),
'mime' => array(
'default' => array(DOKU_CONF.'mime.conf'),
'local' => array(DOKU_CONF.'mime.local.conf'),
),
'scheme' => array(
'default' => array(DOKU_CONF.'scheme.conf'),
'local' => array(DOKU_CONF.'scheme.local.conf'),
),
'smileys' => array(
'default' => array(DOKU_CONF.'smileys.conf'),
'local' => array(DOKU_CONF.'smileys.local.conf'),
),
'wordblock' => array(
'default' => array(DOKU_CONF.'wordblock.conf'),
'local' => array(DOKU_CONF.'wordblock.local.conf'),
),
);
}
//prepare config array()
global $conf;
$conf = array();
//prepare config array()
global $conf;
$conf = array();
// load the global config file(s)
foreach (array('default','local','protected') as $config_group) {
// load the global config file(s)
foreach (array('default','local','protected') as $config_group) {
if (empty($config_cascade['main'][$config_group])) continue;
foreach ($config_cascade['main'][$config_group] as $config_file) {
if (@file_exists($config_file)) {
include($config_file);
}
if (@file_exists($config_file)) {
include($config_file);
}
}
}
}
//prepare language array
global $lang;
$lang = array();
//prepare language array
global $lang;
$lang = array();
//load the language files
require_once(DOKU_INC.'inc/lang/en/lang.php');
if ( $conf['lang'] && $conf['lang'] != 'en' ) {
//load the language files
require_once(DOKU_INC.'inc/lang/en/lang.php');
if ( $conf['lang'] && $conf['lang'] != 'en' ) {
require_once(DOKU_INC.'inc/lang/'.$conf['lang'].'/lang.php');
}
}
//prepare license array()
global $license;
$license = array();
//prepare license array()
global $license;
$license = array();
// load the license file(s)
foreach (array('default','local') as $config_group) {
// load the license file(s)
foreach (array('default','local') as $config_group) {
if (empty($config_cascade['license'][$config_group])) continue;
foreach ($config_cascade['license'][$config_group] as $config_file) {
if(@file_exists($config_file)){
include($config_file);
}
if(@file_exists($config_file)){
include($config_file);
}
}
}
}
// define baseURL
if(!defined('DOKU_REL')) define('DOKU_REL',getBaseURL(false));
if(!defined('DOKU_URL')) define('DOKU_URL',getBaseURL(true));
if(!defined('DOKU_BASE')){
// define baseURL
if(!defined('DOKU_REL')) define('DOKU_REL',getBaseURL(false));
if(!defined('DOKU_URL')) define('DOKU_URL',getBaseURL(true));
if(!defined('DOKU_BASE')){
if($conf['canonical']){
define('DOKU_BASE',DOKU_URL);
define('DOKU_BASE',DOKU_URL);
}else{
define('DOKU_BASE',DOKU_REL);
define('DOKU_BASE',DOKU_REL);
}
}
}
// define whitespace
if(!defined('DOKU_LF')) define ('DOKU_LF',"\n");
if(!defined('DOKU_TAB')) define ('DOKU_TAB',"\t");
// define whitespace
if(!defined('DOKU_LF')) define ('DOKU_LF',"\n");
if(!defined('DOKU_TAB')) define ('DOKU_TAB',"\t");
// define cookie and session id, append server port when securecookie is configured FS#1664
if (!defined('DOKU_COOKIE')) define('DOKU_COOKIE', 'DW'.md5(DOKU_REL.(($conf['securecookie'])?$_SERVER['SERVER_PORT']:'')));
// define cookie and session id, append server port when securecookie is configured FS#1664
if (!defined('DOKU_COOKIE')) define('DOKU_COOKIE', 'DW'.md5(DOKU_REL.(($conf['securecookie'])?$_SERVER['SERVER_PORT']:'')));
// define Plugin dir
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
// define Plugin dir
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
// define main script
if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php');
// define main script
if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php');
// define Template baseURL
if(!defined('DOKU_TPL')) define('DOKU_TPL',
DOKU_BASE.'lib/tpl/'.$conf['template'].'/');
// define Template baseURL
if(!defined('DOKU_TPL')) define('DOKU_TPL',
DOKU_BASE.'lib/tpl/'.$conf['template'].'/');
// define real Template directory
if(!defined('DOKU_TPLINC')) define('DOKU_TPLINC',
DOKU_INC.'lib/tpl/'.$conf['template'].'/');
// define real Template directory
if(!defined('DOKU_TPLINC')) define('DOKU_TPLINC',
DOKU_INC.'lib/tpl/'.$conf['template'].'/');
// make session rewrites XHTML compliant
@ini_set('arg_separator.output', '&amp;');
// make session rewrites XHTML compliant
@ini_set('arg_separator.output', '&amp;');
// make sure global zlib does not interfere FS#1132
@ini_set('zlib.output_compression', 'off');
// make sure global zlib does not interfere FS#1132
@ini_set('zlib.output_compression', 'off');
// increase PCRE backtrack limit
@ini_set('pcre.backtrack_limit', '20971520');
// increase PCRE backtrack limit
@ini_set('pcre.backtrack_limit', '20971520');
// enable gzip compression if supported
$conf['gzip_output'] &= (strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false);
if ($conf['gzip_output'] &&
!defined('DOKU_DISABLE_GZIP_OUTPUT') &&
function_exists('ob_gzhandler')) {
// enable gzip compression if supported
$conf['gzip_output'] &= (strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false);
if ($conf['gzip_output'] &&
!defined('DOKU_DISABLE_GZIP_OUTPUT') &&
function_exists('ob_gzhandler')) {
ob_start('ob_gzhandler');
}
}
// init session
if (!headers_sent() && !defined('NOSESSION')){
// init session
if (!headers_sent() && !defined('NOSESSION')){
session_name("DokuWiki");
if (version_compare(PHP_VERSION, '5.2.0', '>')) {
session_set_cookie_params(0,DOKU_REL,'',($conf['securecookie'] && is_ssl()),true);
session_set_cookie_params(0,DOKU_REL,'',($conf['securecookie'] && is_ssl()),true);
}else{
session_set_cookie_params(0,DOKU_REL,'',($conf['securecookie'] && is_ssl()));
session_set_cookie_params(0,DOKU_REL,'',($conf['securecookie'] && is_ssl()));
}
session_start();
// load left over messages
if(isset($_SESSION[DOKU_COOKIE]['msg'])){
$MSG = $_SESSION[DOKU_COOKIE]['msg'];
unset($_SESSION[DOKU_COOKIE]['msg']);
$MSG = $_SESSION[DOKU_COOKIE]['msg'];
unset($_SESSION[DOKU_COOKIE]['msg']);
}
}
}
// kill magic quotes
if (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
// kill magic quotes
if (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
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);
@ini_set('magic_quotes_gpc', 0);
define('MAGIC_QUOTES_STRIPPED',1);
}
@set_magic_quotes_runtime(0);
@ini_set('magic_quotes_sybase',0);
}
@set_magic_quotes_runtime(0);
@ini_set('magic_quotes_sybase',0);
// don't let cookies ever interfere with request vars
$_REQUEST = array_merge($_GET,$_POST);
// don't let cookies ever interfere with request vars
$_REQUEST = array_merge($_GET,$_POST);
// we don't want a purge URL to be digged
if($_REQUEST['purge'] && $_SERVER['HTTP_REFERER']) unset($_REQUEST['purge']);
// we don't want a purge URL to be digged
if($_REQUEST['purge'] && $_SERVER['HTTP_REFERER']) unset($_REQUEST['purge']);
// disable gzip if not available
if($conf['compression'] == 'bz2' && !function_exists('bzopen')){
// disable gzip if not available
if($conf['compression'] == 'bz2' && !function_exists('bzopen')){
$conf['compression'] = 'gz';
}
if($conf['compression'] == 'gz' && !function_exists('gzopen')){
}
if($conf['compression'] == 'gz' && !function_exists('gzopen')){
$conf['compression'] = 0;
}
}
// fix dateformat for upgraders
if(strpos($conf['dformat'],'%') === false){
// fix dateformat for upgraders
if(strpos($conf['dformat'],'%') === false){
$conf['dformat'] = '%Y/%m/%d %H:%M';
}
}
// precalculate file creation modes
init_creationmodes();
// precalculate file creation modes
init_creationmodes();
// make real paths and check them
init_paths();
init_files();
// make real paths and check them
init_paths();
init_files();
// automatic upgrade to script versions of certain files
scriptify(DOKU_CONF.'users.auth');
scriptify(DOKU_CONF.'acl.auth');
// automatic upgrade to script versions of certain files
scriptify(DOKU_CONF.'users.auth');
scriptify(DOKU_CONF.'acl.auth');
/**
* Checks paths from config file
*/
function init_paths(){
global $conf;
global $conf;
$paths = array('datadir' => 'pages',
'olddir' => 'attic',
'mediadir' => 'media',
'metadir' => 'meta',
'cachedir' => 'cache',
'indexdir' => 'index',
'lockdir' => 'locks',
'tmpdir' => 'tmp');
$paths = array('datadir' => 'pages',
'olddir' => 'attic',
'mediadir' => 'media',
'metadir' => 'meta',
'cachedir' => 'cache',
'indexdir' => 'index',
'lockdir' => 'locks',
'tmpdir' => 'tmp');
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 ('$p') does not exist, isn't accessible or writable.
You should check your config and permission settings.
Or maybe you want to <a href=\"install.php\">run the
installer</a>?");
}
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 ('$p') does not exist, isn't accessible or writable.
You should check your config and permission settings.
Or maybe you want to <a href=\"install.php\">run the
installer</a>?");
}
// 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';
$conf['media_changelog'] = $conf['metadir'].'/_media.changes';
// 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';
$conf['media_changelog'] = $conf['metadir'].'/_media.changes';
}
/**
* Checks the existance of certain files and creates them if missing.
*/
function init_files(){
global $conf;
global $conf;
$files = array( $conf['indexdir'].'/page.idx');
$files = array( $conf['indexdir'].'/page.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!");
}
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!");
}
}
}
}
}
/**
@ -300,26 +305,26 @@ function init_files(){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function init_path($path){
// check existance
$p = fullpath($path);
if(!@file_exists($p)){
$p = fullpath(DOKU_INC.$path);
// check existance
$p = fullpath($path);
if(!@file_exists($p)){
return '';
$p = fullpath(DOKU_INC.$path);
if(!@file_exists($p)){
return '';
}
}
}
// check writability
if(!@is_writable($p)){
return '';
}
// check writability
if(!@is_writable($p)){
return '';
}
// check accessability (execute bit) for directories
if(@is_dir($p) && !@file_exists("$p/.")){
return '';
}
// check accessability (execute bit) for directories
if(@is_dir($p) && !@file_exists("$p/.")){
return '';
}
return $p;
return $p;
}
/**
@ -329,28 +334,28 @@ function init_path($path){
* setting the values only if needed.
*/
function init_creationmodes(){
global $conf;
global $conf;
// Legacy support for old umask/dmask scheme
unset($conf['dmask']);
unset($conf['fmask']);
unset($conf['umask']);
unset($conf['fperm']);
unset($conf['dperm']);
// 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;
// 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 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'];
// 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'];
}
/**
@ -359,22 +364,22 @@ function init_creationmodes(){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function remove_magic_quotes(&$array) {
foreach (array_keys($array) as $key) {
// handle magic quotes in keynames (breaks order)
$sk = stripslashes($key);
if($sk != $key){
$array[$sk] = $array[$key];
unset($array[$key]);
$key = $sk;
}
foreach (array_keys($array) as $key) {
// handle magic quotes in keynames (breaks order)
$sk = stripslashes($key);
if($sk != $key){
$array[$sk] = $array[$key];
unset($array[$key]);
$key = $sk;
}
// do recursion if needed
if (is_array($array[$key])) {
remove_magic_quotes($array[$key]);
}else {
$array[$key] = stripslashes($array[$key]);
}
}
// do recursion if needed
if (is_array($array[$key])) {
remove_magic_quotes($array[$key]);
}else {
$array[$key] = stripslashes($array[$key]);
}
}
}
/**
@ -384,59 +389,59 @@ function remove_magic_quotes(&$array) {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getBaseURL($abs=null){
global $conf;
//if canonical url enabled always return absolute
if(is_null($abs)) $abs = $conf['canonical'];
global $conf;
//if canonical url enabled always return absolute
if(is_null($abs)) $abs = $conf['canonical'];
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/"); // ensure leading and trailing slashes
//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, trim any slash from end of baseurl to avoid multiple consecutive slashes in the path
if($conf['baseurl']) return rtrim($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;
if(!is_ssl()){
$proto = 'http://';
if ($port == '80') {
$port='';
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
}
}else{
$proto = 'https://';
if ($port == '443') {
$port='';
$dir = str_replace('\\','/',$dir); // bugfix for weird WIN behaviour
$dir = preg_replace('#//+#','/',"/$dir/"); // ensure leading and trailing slashes
//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, trim any slash from end of baseurl to avoid multiple consecutive slashes in the path
if($conf['baseurl']) return rtrim($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;
if(!is_ssl()){
$proto = 'http://';
if ($port == '80') {
$port='';
}
}else{
$proto = 'https://';
if ($port == '443') {
$port='';
}
}
}
if($port) $port = ':'.$port;
if($port) $port = ':'.$port;
return $proto.$host.$port.$dir;
return $proto.$host.$port.$dir;
}
/**
@ -465,52 +470,52 @@ function is_ssl(){
* @author Jan Decaluwe <jan@jandecaluwe.com>
*/
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, '# <?php exit()?>'."\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");
// 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, '# <?php exit()?>'."\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<<<EOT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>DokuWiki Setup Error</title></head>
<body style="font-family: Arial, sans-serif">
<div style="width:60%; margin: auto; background-color: #fcc;
border: 1px solid #faa; padding: 0.5em 1em;">
<h1 style="font-size: 120%">DokuWiki Setup Error</h1>
<p>$msg</p>
</div>
</body>
</html>
echo<<<EOT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>DokuWiki Setup Error</title></head>
<body style="font-family: Arial, sans-serif">
<div style="width:60%; margin: auto; background-color: #fcc;
border: 1px solid #faa; padding: 0.5em 1em;">
<h1 style="font-size: 120%">DokuWiki Setup Error</h1>
<p>$msg</p>
</div>
</body>
</html>
EOT;
exit;
exit;
}
@ -560,9 +565,9 @@ function fullpath($path,$exists=false){
$newpath=array();
foreach($path as $p) {
if ($p === '' || $p === '.') continue;
if ($p==='..') {
array_pop($newpath);
continue;
if ($p==='..') {
array_pop($newpath);
continue;
}
array_push($newpath, $p);
}
@ -577,4 +582,3 @@ function fullpath($path,$exists=false){
//Setup VIM: ex: et ts=2 enc=utf-8 :

View File

@ -28,26 +28,26 @@ require_once(DOKU_INC.'inc/utf8.php');
* @author Ben Coburn <btcoburn@silicodon.net>
*/
function io_sweepNS($id,$basedir='datadir'){
global $conf;
$types = array ('datadir'=>'pages', 'mediadir'=>'media');
$ns_type = (isset($types[$basedir])?$types[$basedir]:false);
global $conf;
$types = array ('datadir'=>'pages', 'mediadir'=>'media');
$ns_type = (isset($types[$basedir])?$types[$basedir]:false);
$delone = false;
$delone = false;
//scan all namespaces
while(($id = getNS($id)) !== false){
$dir = $conf[$basedir].'/'.utf8_encodeFN(str_replace(':','/',$id));
//scan all namespaces
while(($id = getNS($id)) !== false){
$dir = $conf[$basedir].'/'.utf8_encodeFN(str_replace(':','/',$id));
//try to delete dir else return
if(@rmdir($dir)) {
if ($ns_type!==false) {
$data = array($id, $ns_type);
$delone = true; // we deleted at least one dir
trigger_event('IO_NAMESPACE_DELETED', $data);
}
} else { return $delone; }
}
return $delone;
//try to delete dir else return
if(@rmdir($dir)) {
if ($ns_type!==false) {
$data = array($id, $ns_type);
$delone = true; // we deleted at least one dir
trigger_event('IO_NAMESPACE_DELETED', $data);
}
} else { return $delone; }
}
return $delone;
}
/**
@ -94,35 +94,35 @@ function _io_readWikiPage_action($data) {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function io_readFile($file,$clean=true){
$ret = '';
if(@file_exists($file)){
if(substr($file,-3) == '.gz'){
$ret = join('',gzfile($file));
}else if(substr($file,-4) == '.bz2'){
$ret = bzfile($file);
}else{
$ret = file_get_contents($file);
$ret = '';
if(@file_exists($file)){
if(substr($file,-3) == '.gz'){
$ret = join('',gzfile($file));
}else if(substr($file,-4) == '.bz2'){
$ret = bzfile($file);
}else{
$ret = file_get_contents($file);
}
}
if($clean){
return cleanText($ret);
}else{
return $ret;
}
}
if($clean){
return cleanText($ret);
}else{
return $ret;
}
}
/**
* Returns the content of a .bz2 compressed file as string
* @author marcel senf <marcel@rucksackreinigung.de>
*/
* Returns the content of a .bz2 compressed file as string
* @author marcel senf <marcel@rucksackreinigung.de>
*/
function bzfile($file){
$bz = bzopen($file,"r");
while (!feof($bz)){
//8192 seems to be the maximum buffersize?
$str = $str . bzread($bz,8192);
}
bzclose($bz);
return $str;
$bz = bzopen($file,"r");
while (!feof($bz)){
//8192 seems to be the maximum buffersize?
$str = $str . bzread($bz,8192);
}
bzclose($bz);
return $str;
}
@ -174,44 +174,44 @@ function _io_writeWikiPage_action($data) {
* @return bool true on success
*/
function io_saveFile($file,$content,$append=false){
global $conf;
$mode = ($append) ? 'ab' : 'wb';
global $conf;
$mode = ($append) ? 'ab' : 'wb';
$fileexists = @file_exists($file);
io_makeFileDir($file);
io_lock($file);
if(substr($file,-3) == '.gz'){
$fh = @gzopen($file,$mode.'9');
if(!$fh){
msg("Writing $file failed",-1);
io_unlock($file);
return false;
$fileexists = @file_exists($file);
io_makeFileDir($file);
io_lock($file);
if(substr($file,-3) == '.gz'){
$fh = @gzopen($file,$mode.'9');
if(!$fh){
msg("Writing $file failed",-1);
io_unlock($file);
return false;
}
gzwrite($fh, $content);
gzclose($fh);
}else if(substr($file,-4) == '.bz2'){
$fh = @bzopen($file,$mode{0});
if(!$fh){
msg("Writing $file failed", -1);
io_unlock($file);
return false;
}
bzwrite($fh, $content);
bzclose($fh);
}else{
$fh = @fopen($file,$mode);
if(!$fh){
msg("Writing $file failed",-1);
io_unlock($file);
return false;
}
fwrite($fh, $content);
fclose($fh);
}
gzwrite($fh, $content);
gzclose($fh);
}else if(substr($file,-4) == '.bz2'){
$fh = @bzopen($file,$mode{0});
if(!$fh){
msg("Writing $file failed", -1);
io_unlock($file);
return false;
}
bzwrite($fh, $content);
bzclose($fh);
}else{
$fh = @fopen($file,$mode);
if(!$fh){
msg("Writing $file failed",-1);
io_unlock($file);
return false;
}
fwrite($fh, $content);
fclose($fh);
}
if(!$fileexists and !empty($conf['fperm'])) chmod($file, $conf['fperm']);
io_unlock($file);
return true;
if(!$fileexists and !empty($conf['fperm'])) chmod($file, $conf['fperm']);
io_unlock($file);
return true;
}
/**
@ -227,55 +227,55 @@ function io_saveFile($file,$content,$append=false){
* @return bool true on success
*/
function io_deleteFromFile($file,$badline,$regex=false){
if (!@file_exists($file)) return true;
if (!@file_exists($file)) return true;
io_lock($file);
io_lock($file);
// load into array
if(substr($file,-3) == '.gz'){
$lines = gzfile($file);
}else{
$lines = file($file);
}
// remove all matching lines
if ($regex) {
$lines = preg_grep($badline,$lines,PREG_GREP_INVERT);
} else {
$pos = array_search($badline,$lines); //return null or false if not found
while(is_int($pos)){
unset($lines[$pos]);
$pos = array_search($badline,$lines);
}
}
if(count($lines)){
$content = join('',$lines);
// load into array
if(substr($file,-3) == '.gz'){
$fh = @gzopen($file,'wb9');
if(!$fh){
msg("Removing content from $file failed",-1);
io_unlock($file);
return false;
}
gzwrite($fh, $content);
gzclose($fh);
$lines = gzfile($file);
}else{
$fh = @fopen($file,'wb');
if(!$fh){
msg("Removing content from $file failed",-1);
io_unlock($file);
return false;
}
fwrite($fh, $content);
fclose($fh);
$lines = file($file);
}
}else{
@unlink($file);
}
io_unlock($file);
return true;
// remove all matching lines
if ($regex) {
$lines = preg_grep($badline,$lines,PREG_GREP_INVERT);
} else {
$pos = array_search($badline,$lines); //return null or false if not found
while(is_int($pos)){
unset($lines[$pos]);
$pos = array_search($badline,$lines);
}
}
if(count($lines)){
$content = join('',$lines);
if(substr($file,-3) == '.gz'){
$fh = @gzopen($file,'wb9');
if(!$fh){
msg("Removing content from $file failed",-1);
io_unlock($file);
return false;
}
gzwrite($fh, $content);
gzclose($fh);
}else{
$fh = @fopen($file,'wb');
if(!$fh){
msg("Removing content from $file failed",-1);
io_unlock($file);
return false;
}
fwrite($fh, $content);
fclose($fh);
}
}else{
@unlink($file);
}
io_unlock($file);
return true;
}
/**
@ -290,24 +290,24 @@ function io_deleteFromFile($file,$badline,$regex=false){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function io_lock($file){
global $conf;
// no locking if safemode hack
if($conf['safemodehack']) return;
global $conf;
// no locking if safemode hack
if($conf['safemodehack']) return;
$lockDir = $conf['lockdir'].'/'.md5($file);
@ignore_user_abort(1);
$lockDir = $conf['lockdir'].'/'.md5($file);
@ignore_user_abort(1);
$timeStart = time();
do {
//waited longer than 3 seconds? -> stale lock
if ((time() - $timeStart) > 3) break;
$locked = @mkdir($lockDir, $conf['dmode']);
if($locked){
if(!empty($conf['dperm'])) chmod($lockDir, $conf['dperm']);
break;
}
usleep(50);
} while ($locked === false);
$timeStart = time();
do {
//waited longer than 3 seconds? -> stale lock
if ((time() - $timeStart) > 3) break;
$locked = @mkdir($lockDir, $conf['dmode']);
if($locked){
if(!empty($conf['dperm'])) chmod($lockDir, $conf['dperm']);
break;
}
usleep(50);
} while ($locked === false);
}
/**
@ -316,13 +316,13 @@ function io_lock($file){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function io_unlock($file){
global $conf;
// no locking if safemode hack
if($conf['safemodehack']) return;
global $conf;
// no locking if safemode hack
if($conf['safemodehack']) return;
$lockDir = $conf['lockdir'].'/'.md5($file);
@rmdir($lockDir);
@ignore_user_abort(0);
$lockDir = $conf['lockdir'].'/'.md5($file);
@rmdir($lockDir);
@ignore_user_abort(0);
}
/**
@ -370,12 +370,12 @@ function io_createNamespace($id, $ns_type='pages') {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function io_makeFileDir($file){
global $conf;
global $conf;
$dir = dirname($file);
if(!@is_dir($dir)){
io_mkdir_p($dir) || msg("Creating directory $dir failed",-1);
}
$dir = dirname($file);
if(!@is_dir($dir)){
io_mkdir_p($dir) || msg("Creating directory $dir failed",-1);
}
}
/**
@ -386,21 +386,21 @@ function io_makeFileDir($file){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function io_mkdir_p($target){
global $conf;
if (@is_dir($target)||empty($target)) return 1; // best case check first
if (@file_exists($target) && !is_dir($target)) return 0;
//recursion
if (io_mkdir_p(substr($target,0,strrpos($target,'/')))){
if($conf['safemodehack']){
$dir = preg_replace('/^'.preg_quote(fullpath($conf['ftp']['root']),'/').'/','', $target);
return io_mkdir_ftp($dir);
}else{
$ret = @mkdir($target,$conf['dmode']); // crawl back up & create dir tree
if($ret && $conf['dperm']) chmod($target, $conf['dperm']);
return $ret;
global $conf;
if (@is_dir($target)||empty($target)) return 1; // best case check first
if (@file_exists($target) && !is_dir($target)) return 0;
//recursion
if (io_mkdir_p(substr($target,0,strrpos($target,'/')))){
if($conf['safemodehack']){
$dir = preg_replace('/^'.preg_quote(fullpath($conf['ftp']['root']),'/').'/','', $target);
return io_mkdir_ftp($dir);
}else{
$ret = @mkdir($target,$conf['dmode']); // crawl back up & create dir tree
if($ret && $conf['dperm']) chmod($target, $conf['dperm']);
return $ret;
}
}
}
return 0;
return 0;
}
/**
@ -411,31 +411,31 @@ function io_mkdir_p($target){
* @author <andi@splitbrain.org>
*/
function io_mkdir_ftp($dir){
global $conf;
global $conf;
if(!function_exists('ftp_connect')){
msg("FTP support not found - safemode workaround not usable",-1);
return false;
}
if(!function_exists('ftp_connect')){
msg("FTP support not found - safemode workaround not usable",-1);
return false;
}
$conn = @ftp_connect($conf['ftp']['host'],$conf['ftp']['port'],10);
if(!$conn){
msg("FTP connection failed",-1);
return false;
}
$conn = @ftp_connect($conf['ftp']['host'],$conf['ftp']['port'],10);
if(!$conn){
msg("FTP connection failed",-1);
return false;
}
if(!@ftp_login($conn, $conf['ftp']['user'], conf_decodeString($conf['ftp']['pass']))){
msg("FTP login failed",-1);
return false;
}
if(!@ftp_login($conn, $conf['ftp']['user'], conf_decodeString($conf['ftp']['pass']))){
msg("FTP login failed",-1);
return false;
}
//create directory
$ok = @ftp_mkdir($conn, $dir);
//set permissions
@ftp_site($conn,sprintf("CHMOD %04o %s",$conf['dmode'],$dir));
//create directory
$ok = @ftp_mkdir($conn, $dir);
//set permissions
@ftp_site($conn,sprintf("CHMOD %04o %s",$conf['dmode'],$dir));
@ftp_close($conn);
return $ok;
@ftp_close($conn);
return $ok;
}
/**
@ -464,7 +464,7 @@ function io_mktmpdir() {
* if $useAttachment is false,
* - $file is the full filename to save the file, incl. path
* - if successful will return true, false otherwise
*
* if $useAttachment is true,
* - $file is the directory where the file should be saved
* - if successful will return the name used for the saved file, false otherwise
@ -473,43 +473,43 @@ function io_mktmpdir() {
* @author Chris Smith <chris@jalakai.co.uk>
*/
function io_download($url,$file,$useAttachment=false,$defaultName='',$maxSize=2097152){
global $conf;
$http = new DokuHTTPClient();
$http->max_bodysize = $maxSize;
$http->timeout = 25; //max. 25 sec
global $conf;
$http = new DokuHTTPClient();
$http->max_bodysize = $maxSize;
$http->timeout = 25; //max. 25 sec
$data = $http->get($url);
if(!$data) return false;
$data = $http->get($url);
if(!$data) return false;
if ($useAttachment) {
$name = '';
if (isset($http->resp_headers['content-disposition'])) {
$content_disposition = $http->resp_headers['content-disposition'];
$match=array();
if (is_string($content_disposition) &&
preg_match('/attachment;\s*filename\s*=\s*"([^"]*)"/i', $content_disposition, $match)) {
if ($useAttachment) {
$name = '';
if (isset($http->resp_headers['content-disposition'])) {
$content_disposition = $http->resp_headers['content-disposition'];
$match=array();
if (is_string($content_disposition) &&
preg_match('/attachment;\s*filename\s*=\s*"([^"]*)"/i', $content_disposition, $match)) {
$name = basename($match[1]);
}
$name = basename($match[1]);
}
}
if (!$name) {
if (!$defaultName) return false;
$name = $defaultName;
}
$file = $file.$name;
}
if (!$name) {
if (!$defaultName) return false;
$name = $defaultName;
}
$file = $file.$name;
}
$fileexists = @file_exists($file);
$fp = @fopen($file,"w");
if(!$fp) return false;
fwrite($fp,$data);
fclose($fp);
if(!$fileexists and $conf['fperm']) chmod($file, $conf['fperm']);
if ($useAttachment) return $name;
return true;
$fileexists = @file_exists($file);
$fp = @fopen($file,"w");
if(!$fp) return false;
fwrite($fp,$data);
fclose($fp);
if(!$fileexists and $conf['fperm']) chmod($file, $conf['fperm']);
if ($useAttachment) return $name;
return true;
}
/**
@ -519,16 +519,16 @@ function io_download($url,$file,$useAttachment=false,$defaultName='',$maxSize=20
* this function will use copy/unlink instead
*/
function io_rename($from,$to){
global $conf;
if(!@rename($from,$to)){
if(@copy($from,$to)){
if($conf['fperm']) chmod($to, $conf['fperm']);
@unlink($from);
return true;
global $conf;
if(!@rename($from,$to)){
if(@copy($from,$to)){
if($conf['fperm']) chmod($to, $conf['fperm']);
@unlink($from);
return true;
}
return false;
}
return false;
}
return true;
return true;
}
@ -540,14 +540,14 @@ function io_rename($from,$to){
* @deprecated
*/
function io_runcmd($cmd){
$fh = popen($cmd, "r");
if(!$fh) return false;
$ret = '';
while (!feof($fh)) {
$ret .= fread($fh, 8192);
}
pclose($fh);
return $ret;
$fh = popen($cmd, "r");
if(!$fh) return false;
$ret = '';
while (!feof($fh)) {
$ret .= fread($fh, 8192);
}
pclose($fh);
return $ret;
}
/**
@ -565,30 +565,29 @@ function io_runcmd($cmd){
* @return matching lines or backref, false on error
*/
function io_grep($file,$pattern,$max=0,$backref=false){
$fh = @fopen($file,'r');
if(!$fh) return false;
$matches = array();
$fh = @fopen($file,'r');
if(!$fh) return false;
$matches = array();
$cnt = 0;
$line = '';
while (!feof($fh)) {
$line .= fgets($fh, 4096); // read full line
if(substr($line,-1) != "\n") continue;
// check if line matches
if(preg_match($pattern,$line,$match)){
if($backref){
$matches[] = $match;
}else{
$matches[] = $line;
}
$cnt++;
}
if($max && $max == $cnt) break;
$cnt = 0;
$line = '';
}
fclose($fh);
return $matches;
while (!feof($fh)) {
$line .= fgets($fh, 4096); // read full line
if(substr($line,-1) != "\n") continue;
// check if line matches
if(preg_match($pattern,$line,$match)){
if($backref){
$matches[] = $match;
}else{
$matches[] = $line;
}
$cnt++;
}
if($max && $max == $cnt) break;
$line = '';
}
fclose($fh);
return $matches;
}
//Setup VIM: ex: et ts=2 enc=utf-8 :

View File

@ -27,7 +27,7 @@ if(!defined('MAILHEADER_EOL')) define('MAILHEADER_EOL',"\n");
*
* @author Chris Smith <chris@jalakai.co.uk>
* Check if a given mail address is valid
*/
*/
if (!defined('RFC2822_ATEXT')) define('RFC2822_ATEXT',"0-9a-zA-Z!#$%&'*+/=?^_`{|}~-");
if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '['.RFC2822_ATEXT.']+(?:\.['.RFC2822_ATEXT.']+)*@(?i:[0-9a-z][0-9a-z-]*\.)+(?i:[a-z]{2,4}|museum|travel)');
@ -54,59 +54,59 @@ if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '['
*/
function mail_send($to, $subject, $body, $from='', $cc='', $bcc='', $headers=null, $params=null){
$message = compact('to','subject','body','from','cc','bcc','headers','params');
return trigger_event('MAIL_MESSAGE_SEND',$message,'_mail_send_action');
$message = compact('to','subject','body','from','cc','bcc','headers','params');
return trigger_event('MAIL_MESSAGE_SEND',$message,'_mail_send_action');
}
function _mail_send_action($data) {
// retrieve parameters from event data, $to, $subject, $body, $from, $cc, $bcc, $headers, $params
$to = $data['to'];
$subject = $data['subject'];
$body = $data['body'];
// retrieve parameters from event data, $to, $subject, $body, $from, $cc, $bcc, $headers, $params
$to = $data['to'];
$subject = $data['subject'];
$body = $data['body'];
// add robustness in case plugin removes any of these optional values
$from = isset($data['from']) ? $data['from'] : '';
$cc = isset($data['cc']) ? $data['cc'] : '';
$bcc = isset($data['bcc']) ? $data['bcc'] : '';
$headers = isset($data['headers']) ? $data['headers'] : null;
$params = isset($data['params']) ? $data['params'] : null;
// add robustness in case plugin removes any of these optional values
$from = isset($data['from']) ? $data['from'] : '';
$cc = isset($data['cc']) ? $data['cc'] : '';
$bcc = isset($data['bcc']) ? $data['bcc'] : '';
$headers = isset($data['headers']) ? $data['headers'] : null;
$params = isset($data['params']) ? $data['params'] : null;
// end additional code to support event ... original mail_send() code from here
// end additional code to support event ... original mail_send() code from here
if(defined('MAILHEADER_ASCIIONLY')){
$subject = utf8_deaccent($subject);
$subject = utf8_strip($subject);
}
if(defined('MAILHEADER_ASCIIONLY')){
$subject = utf8_deaccent($subject);
$subject = utf8_strip($subject);
}
if(!utf8_isASCII($subject)) {
$subject = '=?UTF-8?Q?'.mail_quotedprintable_encode($subject,0).'?=';
// Spaces must be encoded according to rfc2047. Use the "_" shorthand
$subject = preg_replace('/ /', '_', $subject);
}
if(!utf8_isASCII($subject)) {
$subject = '=?UTF-8?Q?'.mail_quotedprintable_encode($subject,0).'?=';
// Spaces must be encoded according to rfc2047. Use the "_" shorthand
$subject = preg_replace('/ /', '_', $subject);
}
$header = '';
$header = '';
// No named recipients for To: in Windows (see FS#652)
$usenames = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? false : true;
// No named recipients for To: in Windows (see FS#652)
$usenames = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? false : true;
$to = mail_encode_address($to,'',$usenames);
$header .= mail_encode_address($from,'From');
$header .= mail_encode_address($cc,'Cc');
$header .= mail_encode_address($bcc,'Bcc');
$header .= 'MIME-Version: 1.0'.MAILHEADER_EOL;
$header .= 'Content-Type: text/plain; charset=UTF-8'.MAILHEADER_EOL;
$header .= 'Content-Transfer-Encoding: quoted-printable'.MAILHEADER_EOL;
$header .= $headers;
$header = trim($header);
$to = mail_encode_address($to,'',$usenames);
$header .= mail_encode_address($from,'From');
$header .= mail_encode_address($cc,'Cc');
$header .= mail_encode_address($bcc,'Bcc');
$header .= 'MIME-Version: 1.0'.MAILHEADER_EOL;
$header .= 'Content-Type: text/plain; charset=UTF-8'.MAILHEADER_EOL;
$header .= 'Content-Transfer-Encoding: quoted-printable'.MAILHEADER_EOL;
$header .= $headers;
$header = trim($header);
$body = mail_quotedprintable_encode($body);
$body = mail_quotedprintable_encode($body);
if($params == null){
return @mail($to,$subject,$body,$header);
}else{
return @mail($to,$subject,$body,$header,$params);
}
if($params == null){
return @mail($to,$subject,$body,$header);
}else{
return @mail($to,$subject,$body,$header,$params);
}
}
/**
@ -124,66 +124,66 @@ function _mail_send_action($data) {
* @param boolean $names Allow named Recipients?
*/
function mail_encode_address($string,$header='',$names=true){
$headers = '';
$parts = explode(',',$string);
foreach ($parts as $part){
$part = trim($part);
$headers = '';
$parts = explode(',',$string);
foreach ($parts as $part){
$part = trim($part);
// parse address
if(preg_match('#(.*?)<(.*?)>#',$part,$matches)){
$text = trim($matches[1]);
$addr = $matches[2];
}else{
$addr = $part;
// parse address
if(preg_match('#(.*?)<(.*?)>#',$part,$matches)){
$text = trim($matches[1]);
$addr = $matches[2];
}else{
$addr = $part;
}
// skip empty ones
if(empty($addr)){
continue;
}
// FIXME: is there a way to encode the localpart of a emailaddress?
if(!utf8_isASCII($addr)){
msg(htmlspecialchars("E-Mail address <$addr> is not ASCII"),-1);
continue;
}
if(!mail_isvalid($addr)){
msg(htmlspecialchars("E-Mail address <$addr> is not valid"),-1);
continue;
}
// text was given
if(!empty($text) && $names){
// add address quotes
$addr = "<$addr>";
if(defined('MAILHEADER_ASCIIONLY')){
$text = utf8_deaccent($text);
$text = utf8_strip($text);
}
if(!utf8_isASCII($text)){
$text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text,0).'?=';
}
}else{
$text = '';
}
// add to header comma seperated
if($headers != ''){
$headers .= ',';
if($header) $headers .= MAILHEADER_EOL.' '; // avoid overlong mail headers
}
$headers .= $text.' '.$addr;
}
// skip empty ones
if(empty($addr)){
continue;
}
if(empty($headers)) return null;
// FIXME: is there a way to encode the localpart of a emailaddress?
if(!utf8_isASCII($addr)){
msg(htmlspecialchars("E-Mail address <$addr> is not ASCII"),-1);
continue;
}
//if headername was given add it and close correctly
if($header) $headers = $header.': '.$headers.MAILHEADER_EOL;
if(!mail_isvalid($addr)){
msg(htmlspecialchars("E-Mail address <$addr> is not valid"),-1);
continue;
}
// text was given
if(!empty($text) && $names){
// add address quotes
$addr = "<$addr>";
if(defined('MAILHEADER_ASCIIONLY')){
$text = utf8_deaccent($text);
$text = utf8_strip($text);
}
if(!utf8_isASCII($text)){
$text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text,0).'?=';
}
}else{
$text = '';
}
// add to header comma seperated
if($headers != ''){
$headers .= ',';
if($header) $headers .= MAILHEADER_EOL.' '; // avoid overlong mail headers
}
$headers .= $text.' '.$addr;
}
if(empty($headers)) return null;
//if headername was given add it and close correctly
if($header) $headers = $header.': '.$headers.MAILHEADER_EOL;
return $headers;
return $headers;
}
/**
@ -204,64 +204,63 @@ function mail_isvalid($email){
* @link http://www.php.net/manual/en/function.imap-8bit.php#61216
*/
function mail_quotedprintable_encode($sText,$maxlen=74,$bEmulate_imap_8bit=true) {
// split text into lines
$aLines= preg_split("/(?:\r\n|\r|\n)/", $sText);
// split text into lines
$aLines= preg_split("/(?:\r\n|\r|\n)/", $sText);
$cnt = count($aLines);
for ($i=0;$i<count($aLines);$i++) {
$sLine =& $aLines[$i];
if (strlen($sLine)===0) continue; // do nothing, if empty
for ($i=0;$i<$cnt;$i++) {
$sLine =& $aLines[$i];
if (strlen($sLine)===0) continue; // do nothing, if empty
$sRegExp = '/[^\x09\x20\x21-\x3C\x3E-\x7E]/e';
$sRegExp = '/[^\x09\x20\x21-\x3C\x3E-\x7E]/e';
// imap_8bit encodes x09 everywhere, not only at lineends,
// for EBCDIC safeness encode !"#$@[\]^`{|}~,
// for complete safeness encode every character :)
if ($bEmulate_imap_8bit)
$sRegExp = '/[^\x20\x21-\x3C\x3E-\x7E]/e';
// imap_8bit encodes x09 everywhere, not only at lineends,
// for EBCDIC safeness encode !"#$@[\]^`{|}~,
// for complete safeness encode every character :)
if ($bEmulate_imap_8bit)
$sRegExp = '/[^\x20\x21-\x3C\x3E-\x7E]/e';
$sReplmt = 'sprintf( "=%02X", ord ( "$0" ) ) ;';
$sLine = preg_replace( $sRegExp, $sReplmt, $sLine );
$sReplmt = 'sprintf( "=%02X", ord ( "$0" ) ) ;';
$sLine = preg_replace( $sRegExp, $sReplmt, $sLine );
// encode x09,x20 at lineends
{
$iLength = strlen($sLine);
$iLastChar = ord($sLine{$iLength-1});
// encode x09,x20 at lineends
{
$iLength = strlen($sLine);
$iLastChar = ord($sLine{$iLength-1});
// !!!!!!!!
// imap_8_bit does not encode x20 at the very end of a text,
// here is, where I don't agree with imap_8_bit,
// please correct me, if I'm wrong,
// or comment next line for RFC2045 conformance, if you like
if (!($bEmulate_imap_8bit && ($i==count($aLines)-1)))
// !!!!!!!!
// imap_8_bit does not encode x20 at the very end of a text,
// here is, where I don't agree with imap_8_bit,
// please correct me, if I'm wrong,
// or comment next line for RFC2045 conformance, if you like
if (!($bEmulate_imap_8bit && ($i==count($aLines)-1))){
if (($iLastChar==0x09)||($iLastChar==0x20)) {
$sLine{$iLength-1}='=';
$sLine .= ($iLastChar==0x09)?'09':'20';
}
}
} // imap_8bit encodes x20 before chr(13), too
// although IMHO not requested by RFC2045, why not do it safer :)
// and why not encode any x20 around chr(10) or chr(13)
if ($bEmulate_imap_8bit) {
$sLine=str_replace(' =0D','=20=0D',$sLine);
//$sLine=str_replace(' =0A','=20=0A',$sLine);
//$sLine=str_replace('=0D ','=0D=20',$sLine);
//$sLine=str_replace('=0A ','=0A=20',$sLine);
}
if (($iLastChar==0x09)||($iLastChar==0x20)) {
$sLine{$iLength-1}='=';
$sLine .= ($iLastChar==0x09)?'09':'20';
}
} // imap_8bit encodes x20 before chr(13), too
// although IMHO not requested by RFC2045, why not do it safer :)
// and why not encode any x20 around chr(10) or chr(13)
if ($bEmulate_imap_8bit) {
$sLine=str_replace(' =0D','=20=0D',$sLine);
//$sLine=str_replace(' =0A','=20=0A',$sLine);
//$sLine=str_replace('=0D ','=0D=20',$sLine);
//$sLine=str_replace('=0A ','=0A=20',$sLine);
// finally split into softlines no longer than $maxlen chars,
// for even more safeness one could encode x09,x20
// at the very first character of the line
// and after soft linebreaks, as well,
// but this wouldn't be caught by such an easy RegExp
if($maxlen){
preg_match_all( '/.{1,'.($maxlen - 2).'}([^=]{0,2})?/', $sLine, $aMatch );
$sLine = implode( '=' . MAILHEADER_EOL, $aMatch[0] ); // add soft crlf's
}
}
// finally split into softlines no longer than $maxlen chars,
// for even more safeness one could encode x09,x20
// at the very first character of the line
// and after soft linebreaks, as well,
// but this wouldn't be caught by such an easy RegExp
if($maxlen){
preg_match_all( '/.{1,'.($maxlen - 2).'}([^=]{0,2})?/', $sLine, $aMatch );
$sLine = implode( '=' . MAILHEADER_EOL, $aMatch[0] ); // add soft crlf's
}
}
// join lines into text
return implode(MAILHEADER_EOL,$aLines);
// join lines into text
return implode(MAILHEADER_EOL,$aLines);
}
//Setup VIM: ex: et ts=2 enc=utf-8 :

View File

@ -32,10 +32,10 @@ function media_filesinuse($data,$id){
echo '<span class="mediaref_ref">'.hsc($row).'</span>';
echo '</div>';
}else
$hidden++;
$hidden++;
}
if ($hidden){
print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
}
}
@ -86,14 +86,14 @@ function media_metaform($id,$auth){
static $fields = null;
if(is_null($fields)){
foreach (array('default','local') as $config_group) {
if (empty($config_cascade['mediameta'][$config_group])) continue;
foreach ($config_cascade['mediameta'][$config_group] as $config_file) {
if(@file_exists($config_file)){
include($config_file);
}
foreach (array('default','local') as $config_group) {
if (empty($config_cascade['mediameta'][$config_group])) continue;
foreach ($config_cascade['mediameta'][$config_group] as $config_file) {
if(@file_exists($config_file)){
include($config_file);
}
}
}
}
}
$src = mediaFN($id);
@ -136,9 +136,9 @@ function media_metaform($id,$auth){
echo '<div class="buttons">'.NL;
echo '<input type="hidden" name="img" value="'.hsc($id).'" />'.NL;
echo '<input name="do[save]" type="submit" value="'.$lang['btn_save'].
'" title="'.$lang['btn_save'].' [S]" accesskey="s" class="button" />'.NL;
'" title="'.$lang['btn_save'].' [S]" accesskey="s" class="button" />'.NL;
echo '<input name="do[cancel]" type="submit" value="'.$lang['btn_cancel'].
'" title="'.$lang['btn_cancel'].' [C]" accesskey="c" class="button" />'.NL;
'" title="'.$lang['btn_cancel'].' [C]" accesskey="c" class="button" />'.NL;
echo '</div>'.NL;
echo '</form>'.NL;
}
@ -446,7 +446,7 @@ function media_filelist($ns,$auth=null,$jump=''){
$dir = utf8_encodeFN(str_replace(':','/',$ns));
$data = array();
search($data,$conf['mediadir'],'search_media',
array('showmsg'=>true,'depth'=>1),$dir);
array('showmsg'=>true,'depth'=>1),$dir);
if(!count($data)){
echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL;
@ -471,19 +471,19 @@ function media_searchlist($query,$ns,$auth=null){
if ($query) {
$evdata = array(
'ns' => $ns,
'data' => array(),
'query' => $query
);
'ns' => $ns,
'data' => array(),
'query' => $query
);
$evt = new Doku_Event('MEDIA_SEARCH', $evdata);
if ($evt->advise_before()) {
$dir = utf8_encodeFN(str_replace(':','/',$evdata['ns']));
$pattern = '/'.preg_quote($evdata['query'],'/').'/i';
search($evdata['data'],
$conf['mediadir'],
'search_media',
array('showmsg'=>false,'pattern'=>$pattern),
$dir);
$conf['mediadir'],
'search_media',
array('showmsg'=>false,'pattern'=>$pattern),
$dir);
}
$evt->advise_after();
unset($evt);
@ -502,8 +502,6 @@ function media_searchlist($query,$ns,$auth=null){
/**
* Print action links for a file depending on filetype
* and available permissions
*
* @todo contains inline javascript
*/
function media_fileactions($item,$auth){
global $lang;
@ -511,8 +509,7 @@ function media_fileactions($item,$auth){
// view button
$link = ml($item['id'],'',true);
echo ' <a href="'.$link.'" target="_blank"><img src="'.DOKU_BASE.'lib/images/magnifier.png" '.
'alt="'.$lang['mediaview'].'" title="'.$lang['mediaview'].'" class="btn" /></a>';
'alt="'.$lang['mediaview'].'" title="'.$lang['mediaview'].'" class="btn" /></a>';
// no further actions if not writable
if(!$item['writable']) return;
@ -520,16 +517,16 @@ function media_fileactions($item,$auth){
// delete button
if($auth >= AUTH_DELETE){
echo ' <a href="'.DOKU_BASE.'lib/exe/mediamanager.php?delete='.rawurlencode($item['id']).
'&amp;sectok='.getSecurityToken().'" class="btn_media_delete" title="'.$item['id'].'">'.
'<img src="'.DOKU_BASE.'lib/images/trash.png" alt="'.$lang['btn_delete'].'" '.
'title="'.$lang['btn_delete'].'" class="btn" /></a>';
'&amp;sectok='.getSecurityToken().'" class="btn_media_delete" title="'.$item['id'].'">'.
'<img src="'.DOKU_BASE.'lib/images/trash.png" alt="'.$lang['btn_delete'].'" '.
'title="'.$lang['btn_delete'].'" class="btn" /></a>';
}
// edit button
if($auth >= AUTH_UPLOAD && $item['isimg'] && $item['meta']->getField('File.Mime') == 'image/jpeg'){
echo ' <a href="'.DOKU_BASE.'lib/exe/mediamanager.php?edit='.rawurlencode($item['id']).'">'.
'<img src="'.DOKU_BASE.'lib/images/pencil.png" alt="'.$lang['metaedit'].'" '.
'title="'.$lang['metaedit'].'" class="btn" /></a>';
'<img src="'.DOKU_BASE.'lib/images/pencil.png" alt="'.$lang['metaedit'].'" '.
'title="'.$lang['metaedit'].'" class="btn" /></a>';
}
}
@ -622,8 +619,8 @@ function media_printimgdetail($item){
// read EXIF/IPTC data
$t = $item['meta']->getField(array('IPTC.Headline','xmp.dc:title'));
$d = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment',
'EXIF.TIFFImageDescription',
'EXIF.TIFFUserComment'));
'EXIF.TIFFImageDescription',
'EXIF.TIFFUserComment'));
if(utf8_strlen($d) > 250) $d = utf8_substr($d,0,250).'...';
$k = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category','xmp.dc:subject'));
@ -662,47 +659,47 @@ function media_uploadform($ns, $auth){
$form->addElement(form_makeCloseTag('p'));
if($auth >= AUTH_DELETE){
$form->addElement(form_makeOpenTag('p'));
$form->addElement(form_makeCheckboxField('ow', 1, $lang['txt_overwrt'], 'dw__ow', 'check'));
$form->addElement(form_makeCloseTag('p'));
$form->addElement(form_makeOpenTag('p'));
$form->addElement(form_makeCheckboxField('ow', 1, $lang['txt_overwrt'], 'dw__ow', 'check'));
$form->addElement(form_makeCloseTag('p'));
}
html_form('upload', $form);
// prepare flashvars for multiupload
$opt = array(
'L_gridname' => $lang['mu_gridname'] ,
'L_gridsize' => $lang['mu_gridsize'] ,
'L_gridstat' => $lang['mu_gridstat'] ,
'L_namespace' => $lang['mu_namespace'] ,
'L_overwrite' => $lang['txt_overwrt'],
'L_browse' => $lang['mu_browse'],
'L_upload' => $lang['btn_upload'],
'L_toobig' => $lang['mu_toobig'],
'L_ready' => $lang['mu_ready'],
'L_done' => $lang['mu_done'],
'L_fail' => $lang['mu_fail'],
'L_authfail' => $lang['mu_authfail'],
'L_progress' => $lang['mu_progress'],
'L_filetypes' => $lang['mu_filetypes'],
'L_info' => $lang['mu_info'],
'L_lasterr' => $lang['mu_lasterr'],
'L_gridname' => $lang['mu_gridname'] ,
'L_gridsize' => $lang['mu_gridsize'] ,
'L_gridstat' => $lang['mu_gridstat'] ,
'L_namespace' => $lang['mu_namespace'] ,
'L_overwrite' => $lang['txt_overwrt'],
'L_browse' => $lang['mu_browse'],
'L_upload' => $lang['btn_upload'],
'L_toobig' => $lang['mu_toobig'],
'L_ready' => $lang['mu_ready'],
'L_done' => $lang['mu_done'],
'L_fail' => $lang['mu_fail'],
'L_authfail' => $lang['mu_authfail'],
'L_progress' => $lang['mu_progress'],
'L_filetypes' => $lang['mu_filetypes'],
'L_info' => $lang['mu_info'],
'L_lasterr' => $lang['mu_lasterr'],
'O_ns' => ":$ns",
'O_backend' => 'mediamanager.php?'.session_name().'='.session_id(),
'O_maxsize' => php_to_byte(ini_get('upload_max_filesize')),
'O_extensions'=> join('|',array_keys(getMimeTypes())),
'O_overwrite' => ($auth >= AUTH_DELETE),
'O_sectok' => getSecurityToken(),
'O_authtok' => auth_createToken(),
);
'O_ns' => ":$ns",
'O_backend' => 'mediamanager.php?'.session_name().'='.session_id(),
'O_maxsize' => php_to_byte(ini_get('upload_max_filesize')),
'O_extensions'=> join('|',array_keys(getMimeTypes())),
'O_overwrite' => ($auth >= AUTH_DELETE),
'O_sectok' => getSecurityToken(),
'O_authtok' => auth_createToken(),
);
$var = buildURLparams($opt);
// output the flash uploader
?>
<div id="dw__flashupload" style="display:none">
<div class="upload"><?php echo $lang['mu_intro']?></div>
<?php echo html_flashobject('multipleUpload.swf','500','190',null,$opt); ?>
</div>
<?php
<div id="dw__flashupload" style="display:none">
<div class="upload"><?php echo $lang['mu_intro']?></div>
<?php echo html_flashobject('multipleUpload.swf','500','190',null,$opt); ?>
</div>
<?php
}
/**
@ -748,7 +745,7 @@ function media_nstree($ns){
// wrap a list with the root level around the other namespaces
$item = array( 'level' => 0, 'id' => '',
'open' =>'true', 'label' => '['.$lang['mediaroot'].']');
'open' =>'true', 'label' => '['.$lang['mediaroot'].']');
echo '<ul class="idx">';
echo media_nstree_li($item);
@ -796,7 +793,7 @@ function media_nstree_li($item){
$alt = '+';
}
return '<li class="'.$class.'">'.
'<img src="'.$img.'" alt="'.$alt.'" />';
'<img src="'.$img.'" alt="'.$alt.'" />';
}
/**
@ -805,28 +802,28 @@ function media_nstree_li($item){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function media_resize_image($file, $ext, $w, $h=0){
global $conf;
global $conf;
$info = @getimagesize($file); //get original size
if($info == false) return $file; // that's no image - it's a spaceship!
$info = @getimagesize($file); //get original size
if($info == false) return $file; // that's no image - it's a spaceship!
if(!$h) $h = round(($w * $info[1]) / $info[0]);
if(!$h) $h = round(($w * $info[1]) / $info[0]);
// we wont scale up to infinity
if($w > 2000 || $h > 2000) return $file;
// we wont scale up to infinity
if($w > 2000 || $h > 2000) return $file;
//cache
$local = getCacheName($file,'.media.'.$w.'x'.$h.'.'.$ext);
$mtime = @filemtime($local); // 0 if not exists
//cache
$local = getCacheName($file,'.media.'.$w.'x'.$h.'.'.$ext);
$mtime = @filemtime($local); // 0 if not exists
if( $mtime > filemtime($file) ||
media_resize_imageIM($ext,$file,$info[0],$info[1],$local,$w,$h) ||
media_resize_imageGD($ext,$file,$info[0],$info[1],$local,$w,$h) ){
if($conf['fperm']) chmod($local, $conf['fperm']);
return $local;
}
//still here? resizing failed
return $file;
if( $mtime > filemtime($file) ||
media_resize_imageIM($ext,$file,$info[0],$info[1],$local,$w,$h) ||
media_resize_imageGD($ext,$file,$info[0],$info[1],$local,$w,$h) ){
if($conf['fperm']) chmod($local, $conf['fperm']);
return $local;
}
//still here? resizing failed
return $file;
}
/**
@ -839,49 +836,49 @@ function media_resize_image($file, $ext, $w, $h=0){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function media_crop_image($file, $ext, $w, $h=0){
global $conf;
global $conf;
if(!$h) $h = $w;
$info = @getimagesize($file); //get original size
if($info == false) return $file; // that's no image - it's a spaceship!
if(!$h) $h = $w;
$info = @getimagesize($file); //get original size
if($info == false) return $file; // that's no image - it's a spaceship!
// calculate crop size
$fr = $info[0]/$info[1];
$tr = $w/$h;
if($tr >= 1){
if($tr > $fr){
$cw = $info[0];
$ch = (int) $info[0]/$tr;
// calculate crop size
$fr = $info[0]/$info[1];
$tr = $w/$h;
if($tr >= 1){
if($tr > $fr){
$cw = $info[0];
$ch = (int) $info[0]/$tr;
}else{
$cw = (int) $info[1]*$tr;
$ch = $info[1];
}
}else{
$cw = (int) $info[1]*$tr;
$ch = $info[1];
if($tr < $fr){
$cw = (int) $info[1]*$tr;
$ch = $info[1];
}else{
$cw = $info[0];
$ch = (int) $info[0]/$tr;
}
}
}else{
if($tr < $fr){
$cw = (int) $info[1]*$tr;
$ch = $info[1];
}else{
$cw = $info[0];
$ch = (int) $info[0]/$tr;
// calculate crop offset
$cx = (int) ($info[0]-$cw)/2;
$cy = (int) ($info[1]-$ch)/3;
//cache
$local = getCacheName($file,'.media.'.$cw.'x'.$ch.'.crop.'.$ext);
$mtime = @filemtime($local); // 0 if not exists
if( $mtime > filemtime($file) ||
media_crop_imageIM($ext,$file,$info[0],$info[1],$local,$cw,$ch,$cx,$cy) ||
media_resize_imageGD($ext,$file,$cw,$ch,$local,$cw,$ch,$cx,$cy) ){
if($conf['fperm']) chmod($local, $conf['fperm']);
return media_resize_image($local,$ext, $w, $h);
}
}
// calculate crop offset
$cx = (int) ($info[0]-$cw)/2;
$cy = (int) ($info[1]-$ch)/3;
//cache
$local = getCacheName($file,'.media.'.$cw.'x'.$ch.'.crop.'.$ext);
$mtime = @filemtime($local); // 0 if not exists
if( $mtime > filemtime($file) ||
media_crop_imageIM($ext,$file,$info[0],$info[1],$local,$cw,$ch,$cx,$cy) ||
media_resize_imageGD($ext,$file,$cw,$ch,$local,$cw,$ch,$cx,$cy) ){
if($conf['fperm']) chmod($local, $conf['fperm']);
return media_resize_image($local,$ext, $w, $h);
}
//still here? cropping failed
return media_resize_image($file,$ext, $w, $h);
//still here? cropping failed
return media_resize_image($file,$ext, $w, $h);
}
/**
@ -894,31 +891,31 @@ function media_crop_image($file, $ext, $w, $h=0){
* @author Pavel Vitis <Pavel.Vitis@seznam.cz>
*/
function media_get_from_URL($url,$ext,$cache){
global $conf;
global $conf;
// if no cache or fetchsize just redirect
if ($cache==0) return false;
if (!$conf['fetchsize']) return false;
// if no cache or fetchsize just redirect
if ($cache==0) return false;
if (!$conf['fetchsize']) return false;
$local = getCacheName(strtolower($url),".media.$ext");
$mtime = @filemtime($local); // 0 if not exists
$local = getCacheName(strtolower($url),".media.$ext");
$mtime = @filemtime($local); // 0 if not exists
//decide if download needed:
if( ($mtime == 0) || // cache does not exist
($cache != -1 && $mtime < time()-$cache) // 'recache' and cache has expired
){
if(media_image_download($url,$local)){
return $local;
}else{
return false;
}
}
//decide if download needed:
if( ($mtime == 0) || // cache does not exist
($cache != -1 && $mtime < time()-$cache) // 'recache' and cache has expired
){
if(media_image_download($url,$local)){
return $local;
}else{
return false;
}
}
//if cache exists use it else
if($mtime) return $local;
//if cache exists use it else
if($mtime) return $local;
//else return false
return false;
//else return false
return false;
}
/**
@ -927,30 +924,30 @@ function media_get_from_URL($url,$ext,$cache){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function media_image_download($url,$file){
global $conf;
$http = new DokuHTTPClient();
$http->max_bodysize = $conf['fetchsize'];
$http->timeout = 25; //max. 25 sec
$http->header_regexp = '!\r\nContent-Type: image/(jpe?g|gif|png)!i';
global $conf;
$http = new DokuHTTPClient();
$http->max_bodysize = $conf['fetchsize'];
$http->timeout = 25; //max. 25 sec
$http->header_regexp = '!\r\nContent-Type: image/(jpe?g|gif|png)!i';
$data = $http->get($url);
if(!$data) return false;
$data = $http->get($url);
if(!$data) return false;
$fileexists = @file_exists($file);
$fp = @fopen($file,"w");
if(!$fp) return false;
fwrite($fp,$data);
fclose($fp);
if(!$fileexists and $conf['fperm']) chmod($file, $conf['fperm']);
$fileexists = @file_exists($file);
$fp = @fopen($file,"w");
if(!$fp) return false;
fwrite($fp,$data);
fclose($fp);
if(!$fileexists and $conf['fperm']) chmod($file, $conf['fperm']);
// check if it is really an image
$info = @getimagesize($file);
if(!$info){
@unlink($file);
return false;
}
// check if it is really an image
$info = @getimagesize($file);
if(!$info){
@unlink($file);
return false;
}
return true;
return true;
}
/**
@ -960,22 +957,22 @@ function media_image_download($url,$file){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function media_resize_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){
global $conf;
global $conf;
// check if convert is configured
if(!$conf['im_convert']) return false;
// check if convert is configured
if(!$conf['im_convert']) return false;
// prepare command
$cmd = $conf['im_convert'];
$cmd .= ' -resize '.$to_w.'x'.$to_h.'!';
if ($ext == 'jpg' || $ext == 'jpeg') {
$cmd .= ' -quality '.$conf['jpg_quality'];
}
$cmd .= " $from $to";
// prepare command
$cmd = $conf['im_convert'];
$cmd .= ' -resize '.$to_w.'x'.$to_h.'!';
if ($ext == 'jpg' || $ext == 'jpeg') {
$cmd .= ' -quality '.$conf['jpg_quality'];
}
$cmd .= " $from $to";
@exec($cmd,$out,$retval);
if ($retval == 0) return true;
return false;
@exec($cmd,$out,$retval);
if ($retval == 0) return true;
return false;
}
/**
@ -984,22 +981,22 @@ function media_resize_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function media_crop_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x,$ofs_y){
global $conf;
global $conf;
// check if convert is configured
if(!$conf['im_convert']) return false;
// check if convert is configured
if(!$conf['im_convert']) return false;
// prepare command
$cmd = $conf['im_convert'];
$cmd .= ' -crop '.$to_w.'x'.$to_h.'+'.$ofs_x.'+'.$ofs_y;
if ($ext == 'jpg' || $ext == 'jpeg') {
$cmd .= ' -quality '.$conf['jpg_quality'];
}
$cmd .= " $from $to";
// prepare command
$cmd = $conf['im_convert'];
$cmd .= ' -crop '.$to_w.'x'.$to_h.'+'.$ofs_x.'+'.$ofs_y;
if ($ext == 'jpg' || $ext == 'jpeg') {
$cmd .= ' -quality '.$conf['jpg_quality'];
}
$cmd .= " $from $to";
@exec($cmd,$out,$retval);
if ($retval == 0) return true;
return false;
@exec($cmd,$out,$retval);
if ($retval == 0) return true;
return false;
}
/**
@ -1009,98 +1006,98 @@ function media_crop_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x,$o
* @author Sebastian Wienecke <s_wienecke@web.de>
*/
function media_resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x=0,$ofs_y=0){
global $conf;
global $conf;
if($conf['gdlib'] < 1) return false; //no GDlib available or wanted
if($conf['gdlib'] < 1) return false; //no GDlib available or wanted
// check available memory
if(!is_mem_available(($from_w * $from_h * 4) + ($to_w * $to_h * 4))){
return false;
}
// create an image of the given filetype
if ($ext == 'jpg' || $ext == 'jpeg'){
if(!function_exists("imagecreatefromjpeg")) return false;
$image = @imagecreatefromjpeg($from);
}elseif($ext == 'png') {
if(!function_exists("imagecreatefrompng")) return false;
$image = @imagecreatefrompng($from);
}elseif($ext == 'gif') {
if(!function_exists("imagecreatefromgif")) return false;
$image = @imagecreatefromgif($from);
}
if(!$image) return false;
if(($conf['gdlib']>1) && function_exists("imagecreatetruecolor") && $ext != 'gif'){
$newimg = @imagecreatetruecolor ($to_w, $to_h);
}
if(!$newimg) $newimg = @imagecreate($to_w, $to_h);
if(!$newimg){
imagedestroy($image);
return false;
}
//keep png alpha channel if possible
if($ext == 'png' && $conf['gdlib']>1 && function_exists('imagesavealpha')){
imagealphablending($newimg, false);
imagesavealpha($newimg,true);
}
//keep gif transparent color if possible
if($ext == 'gif' && function_exists('imagefill') && function_exists('imagecolorallocate')) {
if(function_exists('imagecolorsforindex') && function_exists('imagecolortransparent')) {
$transcolorindex = @imagecolortransparent($image);
if($transcolorindex >= 0 ) { //transparent color exists
$transcolor = @imagecolorsforindex($image, $transcolorindex);
$transcolorindex = @imagecolorallocate($newimg, $transcolor['red'], $transcolor['green'], $transcolor['blue']);
@imagefill($newimg, 0, 0, $transcolorindex);
@imagecolortransparent($newimg, $transcolorindex);
}else{ //filling with white
$whitecolorindex = @imagecolorallocate($newimg, 255, 255, 255);
@imagefill($newimg, 0, 0, $whitecolorindex);
}
}else{ //filling with white
$whitecolorindex = @imagecolorallocate($newimg, 255, 255, 255);
@imagefill($newimg, 0, 0, $whitecolorindex);
// check available memory
if(!is_mem_available(($from_w * $from_h * 4) + ($to_w * $to_h * 4))){
return false;
}
}
//try resampling first
if(function_exists("imagecopyresampled")){
if(!@imagecopyresampled($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h)) {
imagecopyresized($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h);
// create an image of the given filetype
if ($ext == 'jpg' || $ext == 'jpeg'){
if(!function_exists("imagecreatefromjpeg")) return false;
$image = @imagecreatefromjpeg($from);
}elseif($ext == 'png') {
if(!function_exists("imagecreatefrompng")) return false;
$image = @imagecreatefrompng($from);
}elseif($ext == 'gif') {
if(!function_exists("imagecreatefromgif")) return false;
$image = @imagecreatefromgif($from);
}
}else{
imagecopyresized($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h);
}
if(!$image) return false;
$okay = false;
if ($ext == 'jpg' || $ext == 'jpeg'){
if(!function_exists('imagejpeg')){
$okay = false;
if(($conf['gdlib']>1) && function_exists("imagecreatetruecolor") && $ext != 'gif'){
$newimg = @imagecreatetruecolor ($to_w, $to_h);
}
if(!$newimg) $newimg = @imagecreate($to_w, $to_h);
if(!$newimg){
imagedestroy($image);
return false;
}
//keep png alpha channel if possible
if($ext == 'png' && $conf['gdlib']>1 && function_exists('imagesavealpha')){
imagealphablending($newimg, false);
imagesavealpha($newimg,true);
}
//keep gif transparent color if possible
if($ext == 'gif' && function_exists('imagefill') && function_exists('imagecolorallocate')) {
if(function_exists('imagecolorsforindex') && function_exists('imagecolortransparent')) {
$transcolorindex = @imagecolortransparent($image);
if($transcolorindex >= 0 ) { //transparent color exists
$transcolor = @imagecolorsforindex($image, $transcolorindex);
$transcolorindex = @imagecolorallocate($newimg, $transcolor['red'], $transcolor['green'], $transcolor['blue']);
@imagefill($newimg, 0, 0, $transcolorindex);
@imagecolortransparent($newimg, $transcolorindex);
}else{ //filling with white
$whitecolorindex = @imagecolorallocate($newimg, 255, 255, 255);
@imagefill($newimg, 0, 0, $whitecolorindex);
}
}else{ //filling with white
$whitecolorindex = @imagecolorallocate($newimg, 255, 255, 255);
@imagefill($newimg, 0, 0, $whitecolorindex);
}
}
//try resampling first
if(function_exists("imagecopyresampled")){
if(!@imagecopyresampled($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h)) {
imagecopyresized($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h);
}
}else{
$okay = imagejpeg($newimg, $to, $conf['jpg_quality']);
imagecopyresized($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h);
}
}elseif($ext == 'png') {
if(!function_exists('imagepng')){
$okay = false;
}else{
$okay = imagepng($newimg, $to);
}
}elseif($ext == 'gif') {
if(!function_exists('imagegif')){
$okay = false;
}else{
$okay = imagegif($newimg, $to);
}
}
// destroy GD image ressources
if($image) imagedestroy($image);
if($newimg) imagedestroy($newimg);
$okay = false;
if ($ext == 'jpg' || $ext == 'jpeg'){
if(!function_exists('imagejpeg')){
$okay = false;
}else{
$okay = imagejpeg($newimg, $to, $conf['jpg_quality']);
}
}elseif($ext == 'png') {
if(!function_exists('imagepng')){
$okay = false;
}else{
$okay = imagepng($newimg, $to);
}
}elseif($ext == 'gif') {
if(!function_exists('imagegif')){
$okay = false;
}else{
$okay = imagegif($newimg, $to);
}
}
return $okay;
// destroy GD image ressources
if($image) imagedestroy($image);
if($newimg) imagedestroy($newimg);
return $okay;
}
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

View File

@ -19,68 +19,68 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getID($param='id',$clean=true){
global $conf;
global $conf;
$id = isset($_REQUEST[$param]) ? $_REQUEST[$param] : null;
$id = isset($_REQUEST[$param]) ? $_REQUEST[$param] : null;
$request = $_SERVER['REQUEST_URI'];
$request = $_SERVER['REQUEST_URI'];
//construct page id from request URI
if(empty($id) && $conf['userewrite'] == 2){
//get the script URL
if($conf['basedir']){
$relpath = '';
if($param != 'id') {
$relpath = 'lib/exe/';
}
$script = $conf['basedir'].$relpath.basename($_SERVER['SCRIPT_FILENAME']);
//construct page id from request URI
if(empty($id) && $conf['userewrite'] == 2){
//get the script URL
if($conf['basedir']){
$relpath = '';
if($param != 'id') {
$relpath = 'lib/exe/';
}
$script = $conf['basedir'].$relpath.basename($_SERVER['SCRIPT_FILENAME']);
}elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['PATH_TRANSLATED']){
$request = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
$_SERVER['PATH_TRANSLATED']);
}elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){
$script = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
$_SERVER['SCRIPT_FILENAME']);
$script = '/'.$script;
}else{
$script = $_SERVER['SCRIPT_NAME'];
}elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['PATH_TRANSLATED']){
$request = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
$_SERVER['PATH_TRANSLATED']);
}elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){
$script = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
$_SERVER['SCRIPT_FILENAME']);
$script = '/'.$script;
}else{
$script = $_SERVER['SCRIPT_NAME'];
}
//clean script and request (fixes a windows problem)
$script = preg_replace('/\/\/+/','/',$script);
$request = preg_replace('/\/\/+/','/',$request);
//remove script URL and Querystring to gain the id
if(preg_match('/^'.preg_quote($script,'/').'(.*)/',$request, $match)){
$id = preg_replace ('/\?.*/','',$match[1]);
}
$id = urldecode($id);
//strip leading slashes
$id = preg_replace('!^/+!','',$id);
}
//clean script and request (fixes a windows problem)
$script = preg_replace('/\/\/+/','/',$script);
$request = preg_replace('/\/\/+/','/',$request);
//remove script URL and Querystring to gain the id
if(preg_match('/^'.preg_quote($script,'/').'(.*)/',$request, $match)){
$id = preg_replace ('/\?.*/','',$match[1]);
// Namespace autolinking from URL
if(substr($id,-1) == ':' || ($conf['useslash'] && substr($id,-1) == '/')){
if(page_exists($id.$conf['start'])){
// start page inside namespace
$id = $id.$conf['start'];
}elseif(page_exists($id.noNS(cleanID($id)))){
// page named like the NS inside the NS
$id = $id.noNS(cleanID($id));
}elseif(page_exists($id)){
// page like namespace exists
$id = substr($id,0,-1);
}else{
// fall back to default
$id = $id.$conf['start'];
}
send_redirect(wl($id,'',true));
}
$id = urldecode($id);
//strip leading slashes
$id = preg_replace('!^/+!','',$id);
}
// Namespace autolinking from URL
if(substr($id,-1) == ':' || ($conf['useslash'] && substr($id,-1) == '/')){
if(page_exists($id.$conf['start'])){
// start page inside namespace
$id = $id.$conf['start'];
}elseif(page_exists($id.noNS(cleanID($id)))){
// page named like the NS inside the NS
$id = $id.noNS(cleanID($id));
}elseif(page_exists($id)){
// page like namespace exists
$id = substr($id,0,-1);
}else{
// fall back to default
$id = $id.$conf['start'];
}
send_redirect(wl($id,'',true));
}
if($clean) $id = cleanID($id);
if(empty($id) && $param=='id') $id = $conf['start'];
if($clean) $id = cleanID($id);
if(empty($id) && $param=='id') $id = $conf['start'];
return $id;
return $id;
}
/**
@ -95,49 +95,49 @@ function getID($param='id',$clean=true){
* @param boolean $media Allow leading or trailing _ for media files
*/
function cleanID($raw_id,$ascii=false,$media=false){
global $conf;
global $lang;
static $sepcharpat = null;
global $conf;
global $lang;
static $sepcharpat = null;
global $cache_cleanid;
$cache = & $cache_cleanid;
global $cache_cleanid;
$cache = & $cache_cleanid;
// check if it's already in the memory cache
if (isset($cache[(string)$raw_id])) {
return $cache[(string)$raw_id];
// check if it's already in the memory cache
if (isset($cache[(string)$raw_id])) {
return $cache[(string)$raw_id];
}
$sepchar = $conf['sepchar'];
if($sepcharpat == null) // build string only once to save clock cycles
$sepcharpat = '#\\'.$sepchar.'+#';
$sepchar = $conf['sepchar'];
if($sepcharpat == null) // build string only once to save clock cycles
$sepcharpat = '#\\'.$sepchar.'+#';
$id = trim((string)$raw_id);
$id = utf8_strtolower($id);
$id = trim((string)$raw_id);
$id = utf8_strtolower($id);
//alternative namespace seperator
$id = strtr($id,';',':');
if($conf['useslash']){
$id = strtr($id,'/',':');
}else{
$id = strtr($id,'/',$sepchar);
}
//alternative namespace seperator
$id = strtr($id,';',':');
if($conf['useslash']){
$id = strtr($id,'/',':');
}else{
$id = strtr($id,'/',$sepchar);
}
if($conf['deaccent'] == 2 || $ascii) $id = utf8_romanize($id);
if($conf['deaccent'] || $ascii) $id = utf8_deaccent($id,-1);
if($conf['deaccent'] == 2 || $ascii) $id = utf8_romanize($id);
if($conf['deaccent'] || $ascii) $id = utf8_deaccent($id,-1);
//remove specials
$id = utf8_stripspecials($id,$sepchar,'\*');
//remove specials
$id = utf8_stripspecials($id,$sepchar,'\*');
if($ascii) $id = utf8_strip($id);
if($ascii) $id = utf8_strip($id);
//clean up
$id = preg_replace($sepcharpat,$sepchar,$id);
$id = preg_replace('#:+#',':',$id);
$id = ($media ? trim($id,':.-') : trim($id,':._-'));
$id = preg_replace('#:[:\._\-]+#',':',$id);
//clean up
$id = preg_replace($sepcharpat,$sepchar,$id);
$id = preg_replace('#:+#',':',$id);
$id = ($media ? trim($id,':.-') : trim($id,':._-'));
$id = preg_replace('#:[:\._\-]+#',':',$id);
$cache[(string)$raw_id] = $id;
return($id);
$cache[(string)$raw_id] = $id;
return($id);
}
/**
@ -146,11 +146,11 @@ function cleanID($raw_id,$ascii=false,$media=false){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getNS($id){
$pos = strrpos((string)$id,':');
if($pos!==false){
return substr((string)$id,0,$pos);
}
return false;
$pos = strrpos((string)$id,':');
if($pos!==false){
return substr((string)$id,0,$pos);
}
return false;
}
/**
@ -159,12 +159,12 @@ function getNS($id){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function noNS($id) {
$pos = strrpos($id, ':');
if ($pos!==false) {
return substr($id, $pos+1);
} else {
return $id;
}
$pos = strrpos($id, ':');
if ($pos!==false) {
return substr($id, $pos+1);
} else {
return $id;
}
}
/**
@ -225,14 +225,14 @@ function sectionID($title,&$check) {
/**
* Wiki page existence check
* Wiki page existence check
*
* parameters as for wikiFN
* parameters as for wikiFN
*
* @author Chris Smith <chris@jalakai.co.uk>
* @author Chris Smith <chris@jalakai.co.uk>
*/
function page_exists($id,$rev='',$clean=true) {
return @file_exists(wikiFN($id,$rev,$clean));
return @file_exists(wikiFN($id,$rev,$clean));
}
/**
@ -248,39 +248,39 @@ function page_exists($id,$rev='',$clean=true) {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function wikiFN($raw_id,$rev='',$clean=true){
global $conf;
global $conf;
global $cache_wikifn;
$cache = & $cache_wikifn;
global $cache_wikifn;
$cache = & $cache_wikifn;
if (isset($cache[$raw_id]) && isset($cache[$raw_id][$rev])) {
return $cache[$raw_id][$rev];
}
$id = $raw_id;
if ($clean) $id = cleanID($id);
$id = str_replace(':','/',$id);
if(empty($rev)){
$fn = $conf['datadir'].'/'.utf8_encodeFN($id).'.txt';
}else{
$fn = $conf['olddir'].'/'.utf8_encodeFN($id).'.'.$rev.'.txt';
if($conf['compression']){
//test for extensions here, we want to read both compressions
if (@file_exists($fn . '.gz')){
$fn .= '.gz';
}else if(@file_exists($fn . '.bz2')){
$fn .= '.bz2';
}else{
//file doesnt exist yet, so we take the configured extension
$fn .= '.' . $conf['compression'];
}
if (isset($cache[$raw_id]) && isset($cache[$raw_id][$rev])) {
return $cache[$raw_id][$rev];
}
}
if (!isset($cache[$raw_id])) { $cache[$raw_id] = array(); }
$cache[$raw_id][$rev] = $fn;
return $fn;
$id = $raw_id;
if ($clean) $id = cleanID($id);
$id = str_replace(':','/',$id);
if(empty($rev)){
$fn = $conf['datadir'].'/'.utf8_encodeFN($id).'.txt';
}else{
$fn = $conf['olddir'].'/'.utf8_encodeFN($id).'.'.$rev.'.txt';
if($conf['compression']){
//test for extensions here, we want to read both compressions
if (@file_exists($fn . '.gz')){
$fn .= '.gz';
}else if(@file_exists($fn . '.bz2')){
$fn .= '.bz2';
}else{
//file doesnt exist yet, so we take the configured extension
$fn .= '.' . $conf['compression'];
}
}
}
if (!isset($cache[$raw_id])) { $cache[$raw_id] = array(); }
$cache[$raw_id][$rev] = $fn;
return $fn;
}
/**
@ -289,8 +289,8 @@ function wikiFN($raw_id,$rev='',$clean=true){
* @author Ben Coburn <btcoburn@silicodon.net>
*/
function wikiLockFN($id) {
global $conf;
return $conf['lockdir'].'/'.md5(cleanID($id)).'.lock';
global $conf;
return $conf['lockdir'].'/'.md5(cleanID($id)).'.lock';
}
@ -302,11 +302,11 @@ function wikiLockFN($id) {
* @author Steven Danz <steven-danz@kc.rr.com>
*/
function metaFN($id,$ext){
global $conf;
$id = cleanID($id);
$id = str_replace(':','/',$id);
$fn = $conf['metadir'].'/'.utf8_encodeFN($id).$ext;
return $fn;
global $conf;
$id = cleanID($id);
$id = str_replace(':','/',$id);
$fn = $conf['metadir'].'/'.utf8_encodeFN($id).$ext;
return $fn;
}
/**
@ -315,20 +315,20 @@ function metaFN($id,$ext){
* @author Esther Brunner <esther@kaffeehaus.ch>
*/
function metaFiles($id){
$name = noNS($id);
$ns = getNS($id);
$dir = ($ns) ? metaFN($ns,'').'/' : metaFN($ns,'');
$files = array();
$name = noNS($id);
$ns = getNS($id);
$dir = ($ns) ? metaFN($ns,'').'/' : metaFN($ns,'');
$files = array();
$dh = @opendir($dir);
if(!$dh) return $files;
while(($file = readdir($dh)) !== false){
if(strpos($file,$name.'.') === 0 && !is_dir($dir.$file))
$files[] = $dir.$file;
}
closedir($dh);
$dh = @opendir($dir);
if(!$dh) return $files;
while(($file = readdir($dh)) !== false){
if(strpos($file,$name.'.') === 0 && !is_dir($dir.$file))
$files[] = $dir.$file;
}
closedir($dh);
return $files;
return $files;
}
/**
@ -339,11 +339,11 @@ function metaFiles($id){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function mediaFN($id){
global $conf;
$id = cleanID($id);
$id = str_replace(':','/',$id);
global $conf;
$id = cleanID($id);
$id = str_replace(':','/',$id);
$fn = $conf['mediadir'].'/'.utf8_encodeFN($id);
return $fn;
return $fn;
}
/**
@ -353,13 +353,13 @@ function mediaFN($id){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function localeFN($id){
global $conf;
$file = DOKU_INC.'inc/lang/'.$conf['lang'].'/'.$id.'.txt';
if(!@file_exists($file)){
//fall back to english
$file = DOKU_INC.'inc/lang/en/'.$id.'.txt';
}
return $file;
global $conf;
$file = DOKU_INC.'inc/lang/'.$conf['lang'].'/'.$id.'.txt';
if(!@file_exists($file)){
//fall back to english
$file = DOKU_INC.'inc/lang/en/'.$id.'.txt';
}
return $file;
}
/**
@ -374,43 +374,43 @@ function localeFN($id){
* @author <bart at mediawave dot nl>
*/
function resolve_id($ns,$id,$clean=true){
global $conf;
global $conf;
// some pre cleaning for useslash:
if($conf['useslash']) $id = str_replace('/',':',$id);
// some pre cleaning for useslash:
if($conf['useslash']) $id = str_replace('/',':',$id);
// if the id starts with a dot we need to handle the
// relative stuff
if($id{0} == '.'){
// normalize initial dots without a colon
$id = preg_replace('/^(\.+)(?=[^:\.])/','\1:',$id);
// prepend the current namespace
$id = $ns.':'.$id;
// if the id starts with a dot we need to handle the
// relative stuff
if($id{0} == '.'){
// normalize initial dots without a colon
$id = preg_replace('/^(\.+)(?=[^:\.])/','\1:',$id);
// prepend the current namespace
$id = $ns.':'.$id;
// cleanup relatives
$result = array();
$pathA = explode(':', $id);
if (!$pathA[0]) $result[] = '';
foreach ($pathA AS $key => $dir) {
if ($dir == '..') {
if (end($result) == '..') {
$result[] = '..';
} elseif (!array_pop($result)) {
$result[] = '..';
// cleanup relatives
$result = array();
$pathA = explode(':', $id);
if (!$pathA[0]) $result[] = '';
foreach ($pathA AS $key => $dir) {
if ($dir == '..') {
if (end($result) == '..') {
$result[] = '..';
} elseif (!array_pop($result)) {
$result[] = '..';
}
} elseif ($dir && $dir != '.') {
$result[] = $dir;
}
}
} elseif ($dir && $dir != '.') {
$result[] = $dir;
}
if (!end($pathA)) $result[] = '';
$id = implode(':', $result);
}elseif($ns !== false && strpos($id,':') === false){
//if link contains no namespace. add current namespace (if any)
$id = $ns.':'.$id;
}
if (!end($pathA)) $result[] = '';
$id = implode(':', $result);
}elseif($ns !== false && strpos($id,':') === false){
//if link contains no namespace. add current namespace (if any)
$id = $ns.':'.$id;
}
if($clean) $id = cleanID($id);
return $id;
if($clean) $id = cleanID($id);
return $id;
}
/**
@ -419,9 +419,9 @@ function resolve_id($ns,$id,$clean=true){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function resolve_mediaid($ns,&$page,&$exists){
$page = resolve_id($ns,$page);
$file = mediaFN($page);
$exists = @file_exists($file);
$page = resolve_id($ns,$page);
$file = mediaFN($page);
$exists = @file_exists($file);
}
/**
@ -430,63 +430,63 @@ function resolve_mediaid($ns,&$page,&$exists){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function resolve_pageid($ns,&$page,&$exists){
global $conf;
$exists = false;
global $conf;
$exists = false;
//keep hashlink if exists then clean both parts
if (strpos($page,'#')) {
list($page,$hash) = explode('#',$page,2);
} else {
$hash = '';
}
$hash = cleanID($hash);
$page = resolve_id($ns,$page,false); // resolve but don't clean, yet
// get filename (calls clean itself)
$file = wikiFN($page);
// if ends with colon or slash we have a namespace link
if(substr($page,-1) == ':' || ($conf['useslash'] && substr($page,-1) == '/')){
if(page_exists($page.$conf['start'])){
// start page inside namespace
$page = $page.$conf['start'];
$exists = true;
}elseif(page_exists($page.noNS(cleanID($page)))){
// page named like the NS inside the NS
$page = $page.noNS(cleanID($page));
$exists = true;
}elseif(page_exists($page)){
// page like namespace exists
$page = $page;
$exists = true;
}else{
// fall back to default
$page = $page.$conf['start'];
//keep hashlink if exists then clean both parts
if (strpos($page,'#')) {
list($page,$hash) = explode('#',$page,2);
} else {
$hash = '';
}
}else{
//check alternative plural/nonplural form
if(!@file_exists($file)){
if( $conf['autoplural'] ){
if(substr($page,-1) == 's'){
$try = substr($page,0,-1);
$hash = cleanID($hash);
$page = resolve_id($ns,$page,false); // resolve but don't clean, yet
// get filename (calls clean itself)
$file = wikiFN($page);
// if ends with colon or slash we have a namespace link
if(substr($page,-1) == ':' || ($conf['useslash'] && substr($page,-1) == '/')){
if(page_exists($page.$conf['start'])){
// start page inside namespace
$page = $page.$conf['start'];
$exists = true;
}elseif(page_exists($page.noNS(cleanID($page)))){
// page named like the NS inside the NS
$page = $page.noNS(cleanID($page));
$exists = true;
}elseif(page_exists($page)){
// page like namespace exists
$page = $page;
$exists = true;
}else{
$try = $page.'s';
// fall back to default
$page = $page.$conf['start'];
}
if(page_exists($try)){
$page = $try;
$exists = true;
}
}
}else{
$exists = true;
//check alternative plural/nonplural form
if(!@file_exists($file)){
if( $conf['autoplural'] ){
if(substr($page,-1) == 's'){
$try = substr($page,0,-1);
}else{
$try = $page.'s';
}
if(page_exists($try)){
$page = $try;
$exists = true;
}
}
}else{
$exists = true;
}
}
}
// now make sure we have a clean page
$page = cleanID($page);
// now make sure we have a clean page
$page = cleanID($page);
//add hash if any
if(!empty($hash)) $page .= '#'.$hash;
//add hash if any
if(!empty($hash)) $page .= '#'.$hash;
}
/**
@ -501,11 +501,11 @@ function resolve_pageid($ns,&$page,&$exists){
* @return string The filename of the cachefile
*/
function getCacheName($data,$ext=''){
global $conf;
$md5 = md5($data);
$file = $conf['cachedir'].'/'.$md5{0}.'/'.$md5.$ext;
io_makeFileDir($file);
return $file;
global $conf;
$md5 = md5($data);
$file = $conf['cachedir'].'/'.$md5{0}.'/'.$md5.$ext;
io_makeFileDir($file);
return $file;
}
/**
@ -514,15 +514,15 @@ function getCacheName($data,$ext=''){
* @author Andreas Gohr <gohr@cosmocode.de>
*/
function isHiddenPage($id){
global $conf;
global $ACT;
if(empty($conf['hidepages'])) return false;
if($ACT == 'admin') return false;
global $conf;
global $ACT;
if(empty($conf['hidepages'])) return false;
if($ACT == 'admin') return false;
if(preg_match('/'.$conf['hidepages'].'/ui',':'.$id)){
return true;
}
return false;
if(preg_match('/'.$conf['hidepages'].'/ui',':'.$id)){
return true;
}
return false;
}
/**
@ -531,8 +531,7 @@ function isHiddenPage($id){
* @author Andreas Gohr <gohr@cosmocode.de>
*/
function isVisiblePage($id){
return !isHiddenPage($id);
return !isHiddenPage($id);
}
//Setup VIM: ex: et ts=2 enc=utf-8 :

View File

@ -22,32 +22,32 @@ require_once(DOKU_INC.'inc/cache.php');
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_wiki_xhtml($id, $rev='', $excuse=true){
$file = wikiFN($id,$rev);
$ret = '';
$file = wikiFN($id,$rev);
$ret = '';
//ensure $id is in global $ID (needed for parsing)
global $ID;
$keep = $ID;
$ID = $id;
//ensure $id is in global $ID (needed for parsing)
global $ID;
$keep = $ID;
$ID = $id;
if($rev){
if(@file_exists($file)){
$ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info); //no caching on old revisions
}elseif($excuse){
$ret = p_locale_xhtml('norev');
if($rev){
if(@file_exists($file)){
$ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info); //no caching on old revisions
}elseif($excuse){
$ret = p_locale_xhtml('norev');
}
}else{
if(@file_exists($file)){
$ret = p_cached_output($file,'xhtml',$id);
}elseif($excuse){
$ret = p_locale_xhtml('newpage');
}
}
}else{
if(@file_exists($file)){
$ret = p_cached_output($file,'xhtml',$id);
}elseif($excuse){
$ret = p_locale_xhtml('newpage');
}
}
//restore ID (just in case)
$ID = $keep;
//restore ID (just in case)
$ID = $keep;
return $ret;
return $ret;
}
/**
@ -63,48 +63,48 @@ function p_wiki_xhtml($id, $rev='', $excuse=true){
* @author Harry Fuecks <hfuecks@gmail.com>
*/
function p_wiki_xhtml_summary($id, &$title, $rev='', $excuse=true){
$file = wikiFN($id,$rev);
$ret = '';
$file = wikiFN($id,$rev);
$ret = '';
//ensure $id is in global $ID (needed for parsing)
global $ID;
$keep = $ID;
$ID = $id;
//ensure $id is in global $ID (needed for parsing)
global $ID;
$keep = $ID;
$ID = $id;
if($rev){
if(@file_exists($file)){
//no caching on old revisions
$ins = p_get_instructions(io_readWikiPage($file,$id,$rev));
}elseif($excuse){
$ret = p_locale_xhtml('norev');
//restore ID (just in case)
$ID = $keep;
return $ret;
if($rev){
if(@file_exists($file)){
//no caching on old revisions
$ins = p_get_instructions(io_readWikiPage($file,$id,$rev));
}elseif($excuse){
$ret = p_locale_xhtml('norev');
//restore ID (just in case)
$ID = $keep;
return $ret;
}
}else{
if(@file_exists($file)){
// The XHTML for a summary is not cached so use the instruction cache
$ins = p_cached_instructions($file);
}elseif($excuse){
$ret = p_locale_xhtml('newpage');
//restore ID (just in case)
$ID = $keep;
return $ret;
}
}
}else{
$ret = p_render('xhtmlsummary',$ins,$info);
if(@file_exists($file)){
// The XHTML for a summary is not cached so use the instruction cache
$ins = p_cached_instructions($file);
}elseif($excuse){
$ret = p_locale_xhtml('newpage');
//restore ID (just in case)
$ID = $keep;
return $ret;
if ( $info['sum_pagetitle'] ) {
$title = $info['sum_pagetitle'];
} else {
$title = $id;
}
}
$ret = p_render('xhtmlsummary',$ins,$info);
if ( $info['sum_pagetitle'] ) {
$title = $info['sum_pagetitle'];
} else {
$title = $id;
}
$ID = $keep;
return $ret;
$ID = $keep;
return $ret;
}
/**
@ -113,9 +113,9 @@ function p_wiki_xhtml_summary($id, &$title, $rev='', $excuse=true){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_locale_xhtml($id){
//fetch parsed locale
$html = p_cached_output(localeFN($id));
return $html;
//fetch parsed locale
$html = p_cached_output(localeFN($id));
return $html;
}
/**
@ -132,7 +132,7 @@ function p_locale_xhtml($id){
* @todo rewrite to use mode instead of hardcoded XHTML
*/
function p_cached_xhtml($file){
return p_cached_output($file);
return p_cached_output($file);
}
/**
@ -142,25 +142,25 @@ function p_cached_xhtml($file){
* @author Chris Smith <chris@jalakai.co.uk>
*/
function p_cached_output($file, $format='xhtml', $id='') {
global $conf;
global $conf;
$cache = new cache_renderer($id, $file, $format);
if ($cache->useCache()) {
$parsed = $cache->retrieveCache(false);
if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- cachefile {$cache->cache} used -->\n";
} else {
$parsed = p_render($format, p_cached_instructions($file,false,$id), $info);
$cache = new cache_renderer($id, $file, $format);
if ($cache->useCache()) {
$parsed = $cache->retrieveCache(false);
if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- cachefile {$cache->cache} used -->\n";
} else {
$parsed = p_render($format, p_cached_instructions($file,false,$id), $info);
if ($info['cache']) {
$cache->storeCache($parsed); //save cachefile
if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- no cachefile used, but created {$cache->cache} -->\n";
}else{
$cache->removeCache(); //try to delete cachefile
if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- no cachefile used, caching forbidden -->\n";
if ($info['cache']) {
$cache->storeCache($parsed); //save cachefile
if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- no cachefile used, but created {$cache->cache} -->\n";
}else{
$cache->removeCache(); //try to delete cachefile
if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- no cachefile used, caching forbidden -->\n";
}
}
}
return $parsed;
return $parsed;
}
/**
@ -171,26 +171,26 @@ function p_cached_output($file, $format='xhtml', $id='') {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_cached_instructions($file,$cacheonly=false,$id='') {
global $conf;
static $run = null;
if(is_null($run)) $run = array();
global $conf;
static $run = null;
if(is_null($run)) $run = array();
$cache = new cache_instructions($id, $file);
$cache = new cache_instructions($id, $file);
if ($cacheonly || $cache->useCache() || isset($run[$file])) {
return $cache->retrieveCache();
} else if (@file_exists($file)) {
// no cache - do some work
$ins = p_get_instructions(io_readWikiPage($file,$id));
if ($cache->storeCache($ins)) {
$run[$file] = true; // we won't rebuild these instructions in the same run again
} else {
msg('Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.',-1);
if ($cacheonly || $cache->useCache() || isset($run[$file])) {
return $cache->retrieveCache();
} else if (@file_exists($file)) {
// no cache - do some work
$ins = p_get_instructions(io_readWikiPage($file,$id));
if ($cache->storeCache($ins)) {
$run[$file] = true; // we won't rebuild these instructions in the same run again
} else {
msg('Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.',-1);
}
return $ins;
}
return $ins;
}
return null;
return null;
}
/**
@ -201,24 +201,24 @@ function p_cached_instructions($file,$cacheonly=false,$id='') {
*/
function p_get_instructions($text){
$modes = p_get_parsermodes();
$modes = p_get_parsermodes();
// Create the parser
$Parser = & new Doku_Parser();
// Create the parser
$Parser = & new Doku_Parser();
// Add the Handler
$Parser->Handler = & new Doku_Handler();
// Add the Handler
$Parser->Handler = & new Doku_Handler();
//add modes to parser
foreach($modes as $mode){
$Parser->addMode($mode['mode'],$mode['obj']);
}
//add modes to parser
foreach($modes as $mode){
$Parser->addMode($mode['mode'],$mode['obj']);
}
// Do the parsing
trigger_event('PARSER_WIKITEXT_PREPROCESS', $text);
$p = $Parser->parse($text);
// dbg($p);
return $p;
// Do the parsing
trigger_event('PARSER_WIKITEXT_PREPROCESS', $text);
$p = $Parser->parse($text);
// dbg($p);
return $p;
}
/**
@ -227,37 +227,37 @@ function p_get_instructions($text){
* @author Esther Brunner <esther@kaffeehaus.ch>
*/
function p_get_metadata($id, $key=false, $render=false){
global $ID, $INFO, $cache_metadata;
global $ID, $INFO, $cache_metadata;
// cache the current page
// Benchmarking shows the current page's metadata is generally the only page metadata
// accessed several times. This may catch a few other pages, but that shouldn't be an issue.
$cache = ($ID == $id);
$meta = p_read_metadata($id, $cache);
// cache the current page
// Benchmarking shows the current page's metadata is generally the only page metadata
// accessed several times. This may catch a few other pages, but that shouldn't be an issue.
$cache = ($ID == $id);
$meta = p_read_metadata($id, $cache);
// metadata has never been rendered before - do it! (but not for non-existent pages)
if ($render && !isset($meta['current']['description']['abstract']) && page_exists($id)){
$meta = p_render_metadata($id, $meta);
io_saveFile(metaFN($id, '.meta'), serialize($meta));
// metadata has never been rendered before - do it! (but not for non-existent pages)
if ($render && !isset($meta['current']['description']['abstract']) && page_exists($id)){
$meta = p_render_metadata($id, $meta);
io_saveFile(metaFN($id, '.meta'), serialize($meta));
// sync cached copies, including $INFO metadata
if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta;
if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }
}
// filter by $key
if ($key){
list($key, $subkey) = explode(' ', $key, 2);
$subkey = trim($subkey);
if ($subkey) {
return isset($meta['current'][$key][$subkey]) ? $meta['current'][$key][$subkey] : null;
// sync cached copies, including $INFO metadata
if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta;
if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }
}
return isset($meta['current'][$key]) ? $meta['current'][$key] : null;
}
// filter by $key
if ($key){
list($key, $subkey) = explode(' ', $key, 2);
$subkey = trim($subkey);
return $meta['current'];
if ($subkey) {
return isset($meta['current'][$key][$subkey]) ? $meta['current'][$key][$subkey] : null;
}
return isset($meta['current'][$key]) ? $meta['current'][$key] : null;
}
return $meta['current'];
}
/**
@ -266,59 +266,59 @@ function p_get_metadata($id, $key=false, $render=false){
* @author Esther Brunner <esther@kaffeehaus.ch>
*/
function p_set_metadata($id, $data, $render=false, $persistent=true){
if (!is_array($data)) return false;
if (!is_array($data)) return false;
global $ID;
global $ID;
// cache the current page
$cache = ($ID == $id);
$orig = p_read_metadata($id, $cache);
// cache the current page
$cache = ($ID == $id);
$orig = p_read_metadata($id, $cache);
// render metadata first?
$meta = $render ? p_render_metadata($id, $orig) : $orig;
// render metadata first?
$meta = $render ? p_render_metadata($id, $orig) : $orig;
// now add the passed metadata
$protected = array('description', 'date', 'contributor');
foreach ($data as $key => $value){
// now add the passed metadata
$protected = array('description', 'date', 'contributor');
foreach ($data as $key => $value){
// be careful with sub-arrays of $meta['relation']
if ($key == 'relation'){
// be careful with sub-arrays of $meta['relation']
if ($key == 'relation'){
foreach ($value as $subkey => $subvalue){
$meta['current'][$key][$subkey] = !empty($meta['current'][$key][$subkey]) ? array_merge($meta['current'][$key][$subkey], $subvalue) : $subvalue;
if ($persistent)
$meta['persistent'][$key][$subkey] = !empty($meta['persistent'][$key][$subkey]) ? array_merge($meta['persistent'][$key][$subkey], $subvalue) : $subvalue;
}
foreach ($value as $subkey => $subvalue){
$meta['current'][$key][$subkey] = !empty($meta['current'][$key][$subkey]) ? array_merge($meta['current'][$key][$subkey], $subvalue) : $subvalue;
if ($persistent)
$meta['persistent'][$key][$subkey] = !empty($meta['persistent'][$key][$subkey]) ? array_merge($meta['persistent'][$key][$subkey], $subvalue) : $subvalue;
}
// be careful with some senisitive arrays of $meta
} elseif (in_array($key, $protected)){
// be careful with some senisitive arrays of $meta
} elseif (in_array($key, $protected)){
// these keys, must have subkeys - a legitimate value must be an array
if (is_array($value)) {
$meta['current'][$key] = !empty($meta['current'][$key]) ? array_merge($meta['current'][$key],$value) : $value;
// these keys, must have subkeys - a legitimate value must be an array
if (is_array($value)) {
$meta['current'][$key] = !empty($meta['current'][$key]) ? array_merge($meta['current'][$key],$value) : $value;
if ($persistent) {
$meta['persistent'][$key] = !empty($meta['persistent'][$key]) ? array_merge($meta['persistent'][$key],$value) : $value;
if ($persistent) {
$meta['persistent'][$key] = !empty($meta['persistent'][$key]) ? array_merge($meta['persistent'][$key],$value) : $value;
}
}
// no special treatment for the rest
} else {
$meta['current'][$key] = $value;
if ($persistent) $meta['persistent'][$key] = $value;
}
}
// no special treatment for the rest
} else {
$meta['current'][$key] = $value;
if ($persistent) $meta['persistent'][$key] = $value;
}
}
// save only if metadata changed
if ($meta == $orig) return true;
// save only if metadata changed
if ($meta == $orig) return true;
// sync cached copies, including $INFO metadata
global $cache_metadata, $INFO;
// sync cached copies, including $INFO metadata
global $cache_metadata, $INFO;
if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta;
if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }
if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta;
if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }
return io_saveFile(metaFN($id, '.meta'), serialize($meta));
return io_saveFile(metaFN($id, '.meta'), serialize($meta));
}
/**
@ -356,38 +356,38 @@ function p_purge_metadata($id) {
* @return array metadata
*/
function p_read_metadata($id,$cache=false) {
global $cache_metadata;
global $cache_metadata;
if (isset($cache_metadata[(string)$id])) return $cache_metadata[(string)$id];
if (isset($cache_metadata[(string)$id])) return $cache_metadata[(string)$id];
$file = metaFN($id, '.meta');
$meta = @file_exists($file) ? unserialize(io_readFile($file, false)) : array('current'=>array(),'persistent'=>array());
$file = metaFN($id, '.meta');
$meta = @file_exists($file) ? unserialize(io_readFile($file, false)) : array('current'=>array(),'persistent'=>array());
// convert $meta from old format to new (current+persistent) format
if (!isset($meta['current'])) {
$meta = array('current'=>$meta,'persistent'=>$meta);
// convert $meta from old format to new (current+persistent) format
if (!isset($meta['current'])) {
$meta = array('current'=>$meta,'persistent'=>$meta);
// remove non-persistent keys
unset($meta['persistent']['title']);
unset($meta['persistent']['description']['abstract']);
unset($meta['persistent']['description']['tableofcontents']);
unset($meta['persistent']['relation']['haspart']);
unset($meta['persistent']['relation']['references']);
unset($meta['persistent']['date']['valid']);
// remove non-persistent keys
unset($meta['persistent']['title']);
unset($meta['persistent']['description']['abstract']);
unset($meta['persistent']['description']['tableofcontents']);
unset($meta['persistent']['relation']['haspart']);
unset($meta['persistent']['relation']['references']);
unset($meta['persistent']['date']['valid']);
if (empty($meta['persistent']['description'])) unset($meta['persistent']['description']);
if (empty($meta['persistent']['relation'])) unset($meta['persistent']['relation']);
if (empty($meta['persistent']['date'])) unset($meta['persistent']['date']);
if (empty($meta['persistent']['description'])) unset($meta['persistent']['description']);
if (empty($meta['persistent']['relation'])) unset($meta['persistent']['relation']);
if (empty($meta['persistent']['date'])) unset($meta['persistent']['date']);
// save converted metadata
io_saveFile($file, serialize($meta));
}
// save converted metadata
io_saveFile($file, serialize($meta));
}
if ($cache) {
$cache_metadata[(string)$id] = $meta;
}
if ($cache) {
$cache_metadata[(string)$id] = $meta;
}
return $meta;
return $meta;
}
/**
@ -396,43 +396,42 @@ function p_read_metadata($id,$cache=false) {
* @author Esther Brunner <esther@kaffeehaus.ch>
*/
function p_render_metadata($id, $orig){
// make sure the correct ID is in global ID
global $ID;
$keep = $ID;
$ID = $id;
// make sure the correct ID is in global ID
global $ID;
$keep = $ID;
$ID = $id;
// add an extra key for the event - to tell event handlers the page whose metadata this is
$orig['page'] = $id;
$evt = new Doku_Event('PARSER_METADATA_RENDER', $orig);
if ($evt->advise_before()) {
// add an extra key for the event - to tell event handlers the page whose metadata this is
$orig['page'] = $id;
$evt = new Doku_Event('PARSER_METADATA_RENDER', $orig);
if ($evt->advise_before()) {
require_once DOKU_INC."inc/parser/metadata.php";
require_once DOKU_INC."inc/parser/metadata.php";
// get instructions
$instructions = p_cached_instructions(wikiFN($id),false,$id);
if(is_null($instructions)){
$ID = $keep;
return null; // something went wrong with the instructions
}
// get instructions
$instructions = p_cached_instructions(wikiFN($id),false,$id);
if(is_null($instructions)){
$ID = $keep;
return null; // something went wrong with the instructions
// set up the renderer
$renderer = & new Doku_Renderer_metadata();
$renderer->meta = $orig['current'];
$renderer->persistent = $orig['persistent'];
// loop through the instructions
foreach ($instructions as $instruction){
// execute the callback against the renderer
call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1]);
}
$evt->result = array('current'=>$renderer->meta,'persistent'=>$renderer->persistent);
}
$evt->advise_after();
// set up the renderer
$renderer = & new Doku_Renderer_metadata();
$renderer->meta = $orig['current'];
$renderer->persistent = $orig['persistent'];
// loop through the instructions
foreach ($instructions as $instruction){
// execute the callback against the renderer
call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1]);
}
$evt->result = array('current'=>$renderer->meta,'persistent'=>$renderer->persistent);
}
$evt->advise_after();
$ID = $keep;
return $evt->result;
$ID = $keep;
return $evt->result;
}
/**
@ -441,90 +440,89 @@ function p_render_metadata($id, $orig){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_get_parsermodes(){
global $conf;
global $conf;
//reuse old data
static $modes = null;
if($modes != null){
return $modes;
}
//import parser classes and mode definitions
require_once DOKU_INC . 'inc/parser/parser.php';
// we now collect all syntax modes and their objects, then they will
// be sorted and added to the parser in correct order
$modes = array();
// add syntax plugins
$pluginlist = plugin_list('syntax');
if(count($pluginlist)){
global $PARSER_MODES;
$obj = null;
foreach($pluginlist as $p){
if(!$obj =& plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj
$PARSER_MODES[$obj->getType()][] = "plugin_$p"; //register mode type
//add to modes
$modes[] = array(
'sort' => $obj->getSort(),
'mode' => "plugin_$p",
'obj' => $obj,
);
unset($obj); //remove the reference
//reuse old data
static $modes = null;
if($modes != null){
return $modes;
}
}
// add default modes
$std_modes = array('listblock','preformatted','notoc','nocache',
'header','table','linebreak','footnote','hr',
'unformatted','php','html','code','file','quote',
'internallink','rss','media','externallink',
'emaillink','windowssharelink','eol');
if($conf['typography']){
$std_modes[] = 'quotes';
$std_modes[] = 'multiplyentity';
}
foreach($std_modes as $m){
$class = "Doku_Parser_Mode_$m";
$obj = new $class();
$modes[] = array(
'sort' => $obj->getSort(),
'mode' => $m,
'obj' => $obj
);
}
//import parser classes and mode definitions
require_once DOKU_INC . 'inc/parser/parser.php';
// add formatting modes
$fmt_modes = array('strong','emphasis','underline','monospace',
'subscript','superscript','deleted');
foreach($fmt_modes as $m){
$obj = new Doku_Parser_Mode_formatting($m);
$modes[] = array(
'sort' => $obj->getSort(),
'mode' => $m,
'obj' => $obj
);
}
// we now collect all syntax modes and their objects, then they will
// be sorted and added to the parser in correct order
$modes = array();
// add modes which need files
$obj = new Doku_Parser_Mode_smiley(array_keys(getSmileys()));
$modes[] = array('sort' => $obj->getSort(), 'mode' => 'smiley','obj' => $obj );
$obj = new Doku_Parser_Mode_acronym(array_keys(getAcronyms()));
$modes[] = array('sort' => $obj->getSort(), 'mode' => 'acronym','obj' => $obj );
$obj = new Doku_Parser_Mode_entity(array_keys(getEntities()));
$modes[] = array('sort' => $obj->getSort(), 'mode' => 'entity','obj' => $obj );
// add syntax plugins
$pluginlist = plugin_list('syntax');
if(count($pluginlist)){
global $PARSER_MODES;
$obj = null;
foreach($pluginlist as $p){
if(!$obj =& plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj
$PARSER_MODES[$obj->getType()][] = "plugin_$p"; //register mode type
//add to modes
$modes[] = array(
'sort' => $obj->getSort(),
'mode' => "plugin_$p",
'obj' => $obj,
);
unset($obj); //remove the reference
}
}
// add default modes
$std_modes = array('listblock','preformatted','notoc','nocache',
'header','table','linebreak','footnote','hr',
'unformatted','php','html','code','file','quote',
'internallink','rss','media','externallink',
'emaillink','windowssharelink','eol');
if($conf['typography']){
$std_modes[] = 'quotes';
$std_modes[] = 'multiplyentity';
}
foreach($std_modes as $m){
$class = "Doku_Parser_Mode_$m";
$obj = new $class();
$modes[] = array(
'sort' => $obj->getSort(),
'mode' => $m,
'obj' => $obj
);
}
// add optional camelcase mode
if($conf['camelcase']){
$obj = new Doku_Parser_Mode_camelcaselink();
$modes[] = array('sort' => $obj->getSort(), 'mode' => 'camelcaselink','obj' => $obj );
}
// add formatting modes
$fmt_modes = array('strong','emphasis','underline','monospace',
'subscript','superscript','deleted');
foreach($fmt_modes as $m){
$obj = new Doku_Parser_Mode_formatting($m);
$modes[] = array(
'sort' => $obj->getSort(),
'mode' => $m,
'obj' => $obj
);
}
//sort modes
usort($modes,'p_sort_modes');
// add modes which need files
$obj = new Doku_Parser_Mode_smiley(array_keys(getSmileys()));
$modes[] = array('sort' => $obj->getSort(), 'mode' => 'smiley','obj' => $obj );
$obj = new Doku_Parser_Mode_acronym(array_keys(getAcronyms()));
$modes[] = array('sort' => $obj->getSort(), 'mode' => 'acronym','obj' => $obj );
$obj = new Doku_Parser_Mode_entity(array_keys(getEntities()));
$modes[] = array('sort' => $obj->getSort(), 'mode' => 'entity','obj' => $obj );
return $modes;
// add optional camelcase mode
if($conf['camelcase']){
$obj = new Doku_Parser_Mode_camelcaselink();
$modes[] = array('sort' => $obj->getSort(), 'mode' => 'camelcaselink','obj' => $obj );
}
//sort modes
usort($modes,'p_sort_modes');
return $modes;
}
/**
@ -533,8 +531,8 @@ function p_get_parsermodes(){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_sort_modes($a, $b){
if($a['sort'] == $b['sort']) return 0;
return ($a['sort'] < $b['sort']) ? -1 : 1;
if($a['sort'] == $b['sort']) return 0;
return ($a['sort'] < $b['sort']) ? -1 : 1;
}
/**
@ -546,64 +544,63 @@ function p_sort_modes($a, $b){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_render($mode,$instructions,&$info){
if(is_null($instructions)) return '';
if(is_null($instructions)) return '';
$Renderer =& p_get_renderer($mode);
if (is_null($Renderer)) return null;
$Renderer =& p_get_renderer($mode);
if (is_null($Renderer)) return null;
$Renderer->reset();
$Renderer->reset();
$Renderer->smileys = getSmileys();
$Renderer->entities = getEntities();
$Renderer->acronyms = getAcronyms();
$Renderer->interwiki = getInterwiki();
#$Renderer->badwords = getBadWords();
$Renderer->smileys = getSmileys();
$Renderer->entities = getEntities();
$Renderer->acronyms = getAcronyms();
$Renderer->interwiki = getInterwiki();
// Loop through the instructions
foreach ( $instructions as $instruction ) {
// Execute the callback against the Renderer
call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]);
}
// Loop through the instructions
foreach ( $instructions as $instruction ) {
// Execute the callback against the Renderer
call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]);
}
//set info array
$info = $Renderer->info;
//set info array
$info = $Renderer->info;
// Post process and return the output
$data = array($mode,& $Renderer->doc);
trigger_event('RENDERER_CONTENT_POSTPROCESS',$data);
return $Renderer->doc;
// Post process and return the output
$data = array($mode,& $Renderer->doc);
trigger_event('RENDERER_CONTENT_POSTPROCESS',$data);
return $Renderer->doc;
}
function & p_get_renderer($mode) {
global $conf, $plugin_controller;
global $conf, $plugin_controller;
$rname = !empty($conf['renderer_'.$mode]) ? $conf['renderer_'.$mode] : $mode;
$rname = !empty($conf['renderer_'.$mode]) ? $conf['renderer_'.$mode] : $mode;
// try default renderer first:
$file = DOKU_INC."inc/parser/$rname.php";
if(@file_exists($file)){
require_once $file;
$rclass = "Doku_Renderer_$rname";
// try default renderer first:
$file = DOKU_INC."inc/parser/$rname.php";
if(@file_exists($file)){
require_once $file;
$rclass = "Doku_Renderer_$rname";
if ( !class_exists($rclass) ) {
trigger_error("Unable to resolve render class $rclass",E_USER_WARNING);
msg("Renderer '$rname' for $mode not valid",-1);
return null;
}
$Renderer = & new $rclass();
}else{
// Maybe a plugin is available?
if (!$plugin_controller->isdisabled($rname)){
$Renderer =& $plugin_controller->load('renderer',$rname, true);
if ( !class_exists($rclass) ) {
trigger_error("Unable to resolve render class $rclass",E_USER_WARNING);
msg("Renderer '$rname' for $mode not valid",-1);
return null;
}
$Renderer = & new $rclass();
}else{
// Maybe a plugin is available?
if (!$plugin_controller->isdisabled($rname)){
$Renderer =& $plugin_controller->load('renderer',$rname, true);
}
if(is_null($Renderer)){
msg("No renderer '$rname' found for mode '$mode'",-1);
return null;
}
}
if(is_null($Renderer)){
msg("No renderer '$rname' found for mode '$mode'",-1);
return null;
}
}
return $Renderer;
return $Renderer;
}
/**
@ -620,7 +617,7 @@ function & p_get_renderer($mode) {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_get_first_heading($id, $render=true){
return p_get_metadata($id,'title',$render);
return p_get_metadata($id,'title',$render);
}
/**
@ -634,42 +631,41 @@ function p_get_first_heading($id, $render=true){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_xhtml_cached_geshi($code, $language, $wrapper='pre') {
global $conf, $config_cascade;
$language = strtolower($language);
global $conf, $config_cascade;
$language = strtolower($language);
// remove any leading or trailing blank lines
$code = preg_replace('/^\s*?\n|\s*?\n$/','',$code);
// remove any leading or trailing blank lines
$code = preg_replace('/^\s*?\n|\s*?\n$/','',$code);
$cache = getCacheName($language.$code,".code");
$ctime = @filemtime($cache);
if($ctime && !$_REQUEST['purge'] &&
$ctime > filemtime(DOKU_INC.'inc/geshi.php') && // geshi changed
$ctime > @filemtime(DOKU_INC.'inc/geshi/'.$language.'.php') && // language syntax definition changed
$ctime > filemtime(reset($config_cascade['main']['default']))){ // dokuwiki changed
$highlighted_code = io_readFile($cache, false);
$cache = getCacheName($language.$code,".code");
$ctime = @filemtime($cache);
if($ctime && !$_REQUEST['purge'] &&
$ctime > filemtime(DOKU_INC.'inc/geshi.php') && // geshi changed
$ctime > @filemtime(DOKU_INC.'inc/geshi/'.$language.'.php') && // language syntax definition changed
$ctime > filemtime(reset($config_cascade['main']['default']))){ // dokuwiki changed
$highlighted_code = io_readFile($cache, false);
} else {
} else {
require_once(DOKU_INC . 'inc/geshi.php');
require_once(DOKU_INC . 'inc/geshi.php');
$geshi = new GeSHi($code, $language, DOKU_INC . 'inc/geshi');
$geshi->set_encoding('utf-8');
$geshi->enable_classes();
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->set_link_target($conf['target']['extern']);
$geshi = new GeSHi($code, $language, DOKU_INC . 'inc/geshi');
$geshi->set_encoding('utf-8');
$geshi->enable_classes();
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->set_link_target($conf['target']['extern']);
// remove GeSHi's wrapper element (we'll replace it with our own later)
// we need to use a GeSHi wrapper to avoid <BR> throughout the highlighted text
$highlighted_code = trim(preg_replace('!^<pre[^>]*>|</pre>$!','',$geshi->parse_code()),"\n\r");
io_saveFile($cache,$highlighted_code);
}
// remove GeSHi's wrapper element (we'll replace it with our own later)
// we need to use a GeSHi wrapper to avoid <BR> throughout the highlighted text
$highlighted_code = trim(preg_replace('!^<pre[^>]*>|</pre>$!','',$geshi->parse_code()),"\n\r");
io_saveFile($cache,$highlighted_code);
}
// add a wrapper element if required
if ($wrapper) {
return "<$wrapper class=\"code $language\">$highlighted_code</$wrapper>";
} else {
return $highlighted_code;
}
// add a wrapper element if required
if ($wrapper) {
return "<$wrapper class=\"code $language\">$highlighted_code</$wrapper>";
} else {
return $highlighted_code;
}
}
//Setup VIM: ex: et ts=2 enc=utf-8 :

View File

@ -12,222 +12,234 @@
*/
class DokuWiki_Plugin {
var $localised = false; // set to true by setupLocale() after loading language dependent strings
var $lang = array(); // array to hold language dependent strings, best accessed via ->getLang()
var $configloaded = false; // set to true by loadConfig() after loading plugin configuration variables
var $conf = array(); // array to hold plugin settings, best accessed via ->getConf()
var $localised = false; // set to true by setupLocale() after loading language dependent strings
var $lang = array(); // array to hold language dependent strings, best accessed via ->getLang()
var $configloaded = false; // set to true by loadConfig() after loading plugin configuration variables
var $conf = array(); // array to hold plugin settings, best accessed via ->getConf()
/**
* General Info
*
* Needs to return a associative array with the following values:
*
* author - Author of the plugin
* email - Email address to contact the author
* date - Last modified date of the plugin in YYYY-MM-DD format
* name - Name of the plugin
* desc - Short description of the plugin (Text only)
* url - Website with more information on the plugin (eg. syntax description)
*/
function getInfo(){
trigger_error('getInfo() not implemented in '.get_class($this), E_USER_WARNING);
}
// plugin introspection methods
// extract from class name, format = <plugin type>_plugin_<name>[_<component name>]
function getPluginType() { list($t) = explode('_', get_class($this), 2); return $t; }
function getPluginName() { list($t, $p, $n) = explode('_', get_class($this), 4); return $n; }
function getPluginComponent() { list($t, $p, $n, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); }
// localisation methods
/**
* getLang($id)
* use this function to access plugin language strings
* to try to minimise unnecessary loading of the strings when the plugin doesn't require them
* e.g. when info plugin is querying plugins for information about themselves.
*
* @param $id id of the string to be retrieved
* @return string string in appropriate language or english if not available
*/
function getLang($id) {
if (!$this->localised) $this->setupLocale();
return (isset($this->lang[$id]) ? $this->lang[$id] : '');
}
/**
* locale_xhtml($id)
*
* retrieve a language dependent file and pass to xhtml renderer for display
* plugin equivalent of p_locale_xhtml()
*
* @param $id id of language dependent wiki page
* @return string parsed contents of the wiki page in xhtml format
*/
function locale_xhtml($id) {
return p_cached_output($this->localFN($id));
}
/**
* localFN($id)
* prepends appropriate path for a language dependent filename
* plugin equivalent of localFN()
*/
function localFN($id) {
global $conf;
$plugin = $this->getPluginName();
$file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt';
if(!@file_exists($file)){
//fall back to english
$file = DOKU_PLUGIN.$plugin.'/lang/en/'.$id.'.txt';
}
return $file;
}
/**
* setupLocale()
* reads all the plugins language dependent strings into $this->lang
* this function is automatically called by getLang()
*/
function setupLocale() {
if ($this->localised) return;
global $conf; // definitely don't invoke "global $lang"
$path = DOKU_PLUGIN.$this->getPluginName().'/lang/';
$lang = array();
// don't include once, in case several plugin components require the same language file
@include($path.'en/lang.php');
if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
$this->lang = $lang;
$this->localised = true;
}
// configuration methods
/**
* getConf($setting)
*
* use this function to access plugin configuration variables
*/
function getConf($setting){
if (!$this->configloaded){ $this->loadConfig(); }
return $this->conf[$setting];
}
/**
* loadConfig()
* merges the plugin's default settings with any local settings
* this function is automatically called through getConf()
*/
function loadConfig(){
global $conf;
$defaults = $this->readDefaultSettings();
$plugin = $this->getPluginName();
foreach ($defaults as $key => $value) {
if (isset($conf['plugin'][$plugin][$key])) continue;
$conf['plugin'][$plugin][$key] = $value;
/**
* General Info
*
* Needs to return a associative array with the following values:
*
* author - Author of the plugin
* email - Email address to contact the author
* date - Last modified date of the plugin in YYYY-MM-DD format
* name - Name of the plugin
* desc - Short description of the plugin (Text only)
* url - Website with more information on the plugin (eg. syntax description)
*/
function getInfo(){
trigger_error('getInfo() not implemented in '.get_class($this), E_USER_WARNING);
}
$this->configloaded = true;
$this->conf =& $conf['plugin'][$plugin];
}
/**
* read the plugin's default configuration settings from conf/default.php
* this function is automatically called through getConf()
*
* @return array setting => value
*/
function readDefaultSettings() {
$path = DOKU_PLUGIN.$this->getPluginName().'/conf/';
$conf = array();
if (@file_exists($path.'default.php')) {
include($path.'default.php');
// plugin introspection methods
// extract from class name, format = <plugin type>_plugin_<name>[_<component name>]
function getPluginType() {
list($t) = explode('_', get_class($this), 2);
return $t;
}
function getPluginName() {
list($t, $p, $n) = explode('_', get_class($this), 4);
return $n;
}
function getPluginComponent() {
list($t, $p, $n, $c) = explode('_', get_class($this), 4);
return (isset($c)?$c:'');
}
return $conf;
}
// localisation methods
/**
* getLang($id)
* use this function to access plugin language strings
* to try to minimise unnecessary loading of the strings when the plugin doesn't require them
* e.g. when info plugin is querying plugins for information about themselves.
*
* @param $id id of the string to be retrieved
* @return string string in appropriate language or english if not available
*/
function getLang($id) {
if (!$this->localised) $this->setupLocale();
/**
* Loads a given helper plugin (if enabled)
*
* @author Esther Brunner <wikidesign@gmail.com>
*
* @param $name name of plugin to load
* @param $msg message to display in case the plugin is not available
*
* @return object helper plugin object
*/
function loadHelper($name, $msg){
if (!plugin_isdisabled($name)) $obj =& plugin_load('helper',$name);
else $obj = NULL;
if (is_null($obj) && $msg) msg("Helper plugin $name is not available or invalid.",-1);
return $obj;
}
return (isset($this->lang[$id]) ? $this->lang[$id] : '');
}
// standard functions for outputing email addresses and links
// use these to avoid having to duplicate code to produce links in line with the installation configuration
/**
* locale_xhtml($id)
*
* retrieve a language dependent file and pass to xhtml renderer for display
* plugin equivalent of p_locale_xhtml()
*
* @param $id id of language dependent wiki page
* @return string parsed contents of the wiki page in xhtml format
*/
function locale_xhtml($id) {
return p_cached_output($this->localFN($id));
}
/**
* email
* standardised function to generate an email link according to obfuscation settings
*/
function email($email, $name='', $class='', $more='') {
if (!$email) return $name;
$email = obfuscate($email);
if (!$name) $name = $email;
$class = "class='".($class ? $class : 'mail')."'";
return "<a href='mailto:$email' $class title='$email' $more>$name</a>";
}
/**
* localFN($id)
* prepends appropriate path for a language dependent filename
* plugin equivalent of localFN()
*/
function localFN($id) {
global $conf;
$plugin = $this->getPluginName();
$file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt';
if(!@file_exists($file)){
//fall back to english
$file = DOKU_PLUGIN.$plugin.'/lang/en/'.$id.'.txt';
}
return $file;
}
/**
* external_link
* standardised function to generate an external link according to conf settings
*/
function external_link($link, $title='', $class='', $target='', $more='') {
global $conf;
/**
* setupLocale()
* reads all the plugins language dependent strings into $this->lang
* this function is automatically called by getLang()
*/
function setupLocale() {
if ($this->localised) return;
$link = htmlentities($link);
if (!$title) $title = $link;
if (!$target) $target = $conf['target']['extern'];
if ($conf['relnofollow']) $more .= ' rel="nofollow"';
global $conf; // definitely don't invoke "global $lang"
$path = DOKU_PLUGIN.$this->getPluginName().'/lang/';
if ($class) $class = " class='$class'";
if ($target) $target = " target='$target'";
if ($more) $more = " ".trim($more);
$lang = array();
return "<a href='$link'$class$target$more>$title</a>";
}
// don't include once, in case several plugin components require the same language file
@include($path.'en/lang.php');
if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
/**
* output text string through the parser, allows dokuwiki markup to be used
* very ineffecient for small pieces of data - try not to use
*/
function render($text, $format='xhtml') {
return p_render($format, p_get_instructions($text),$info);
}
$this->lang = $lang;
$this->localised = true;
}
/**
* Allow the plugin to prevent DokuWiki creating a second instance of itself
*
* @return bool true if the plugin can not be instantiated more than once
*/
function isSingleton() {
return false;
}
// configuration methods
/**
* getConf($setting)
*
* use this function to access plugin configuration variables
*/
function getConf($setting){
// deprecated functions
function plugin_localFN($id) { return $this->localFN($id); }
function plugin_locale_xhtml($id) { return $this->locale_xhtml($id); }
function plugin_email($e, $n='', $c='', $m='') { return $this->email($e, $n, $c, $m); }
function plugin_link($l, $t='', $c='', $to='', $m='') { return $this->external_link($l, $t, $c, $to, $m); }
function plugin_render($t, $f='xhtml') { return $this->render($t, $f); }
if (!$this->configloaded){ $this->loadConfig(); }
return $this->conf[$setting];
}
/**
* loadConfig()
* merges the plugin's default settings with any local settings
* this function is automatically called through getConf()
*/
function loadConfig(){
global $conf;
$defaults = $this->readDefaultSettings();
$plugin = $this->getPluginName();
foreach ($defaults as $key => $value) {
if (isset($conf['plugin'][$plugin][$key])) continue;
$conf['plugin'][$plugin][$key] = $value;
}
$this->configloaded = true;
$this->conf =& $conf['plugin'][$plugin];
}
/**
* read the plugin's default configuration settings from conf/default.php
* this function is automatically called through getConf()
*
* @return array setting => value
*/
function readDefaultSettings() {
$path = DOKU_PLUGIN.$this->getPluginName().'/conf/';
$conf = array();
if (@file_exists($path.'default.php')) {
include($path.'default.php');
}
return $conf;
}
/**
* Loads a given helper plugin (if enabled)
*
* @author Esther Brunner <wikidesign@gmail.com>
*
* @param $name name of plugin to load
* @param $msg message to display in case the plugin is not available
*
* @return object helper plugin object
*/
function loadHelper($name, $msg){
if (!plugin_isdisabled($name)){
$obj =& plugin_load('helper',$name);
}else{
$obj = null;
}
if (is_null($obj) && $msg) msg("Helper plugin $name is not available or invalid.",-1);
return $obj;
}
// standard functions for outputing email addresses and links
// use these to avoid having to duplicate code to produce links in line with the installation configuration
/**
* email
* standardised function to generate an email link according to obfuscation settings
*/
function email($email, $name='', $class='', $more='') {
if (!$email) return $name;
$email = obfuscate($email);
if (!$name) $name = $email;
$class = "class='".($class ? $class : 'mail')."'";
return "<a href='mailto:$email' $class title='$email' $more>$name</a>";
}
/**
* external_link
* standardised function to generate an external link according to conf settings
*/
function external_link($link, $title='', $class='', $target='', $more='') {
global $conf;
$link = htmlentities($link);
if (!$title) $title = $link;
if (!$target) $target = $conf['target']['extern'];
if ($conf['relnofollow']) $more .= ' rel="nofollow"';
if ($class) $class = " class='$class'";
if ($target) $target = " target='$target'";
if ($more) $more = " ".trim($more);
return "<a href='$link'$class$target$more>$title</a>";
}
/**
* output text string through the parser, allows dokuwiki markup to be used
* very ineffecient for small pieces of data - try not to use
*/
function render($text, $format='xhtml') {
return p_render($format, p_get_instructions($text),$info);
}
/**
* Allow the plugin to prevent DokuWiki creating a second instance of itself
*
* @return bool true if the plugin can not be instantiated more than once
*/
function isSingleton() {
return false;
}
// deprecated functions
function plugin_localFN($id) { return $this->localFN($id); }
function plugin_locale_xhtml($id) { return $this->locale_xhtml($id); }
function plugin_email($e, $n='', $c='', $m='') { return $this->email($e, $n, $c, $m); }
function plugin_link($l, $t='', $c='', $to='', $m='') { return $this->external_link($l, $t, $c, $to, $m); }
function plugin_render($t, $f='xhtml') { return $this->render($t, $f); }
}

View File

@ -11,162 +11,162 @@ if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
class Doku_Plugin_Controller {
var $list_enabled = array();
var $list_disabled = array();
var $list_bytype = array();
var $list_enabled = array();
var $list_disabled = array();
var $list_bytype = array();
function Doku_Plugin_Controller() {
$this->_populateMasterList();
}
/**
* Returns a list of available plugins of given type
*
* @param $type string, plugin_type name;
* the type of plugin to return,
* use empty string for all types
* @param $all bool;
* false to only return enabled plugins,
* true to return both enabled and disabled plugins
*
* @return array of plugin names
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getList($type='',$all=false){
// request the complete list
if (!$type) {
return $all ? array_merge($this->list_enabled,$this->list_disabled) : $this->list_enabled;
function Doku_Plugin_Controller() {
$this->_populateMasterList();
}
if (!isset($this->list_bytype[$type]['enabled'])) {
$this->list_bytype[$type]['enabled'] = $this->_getListByType($type,true);
}
if ($all && !isset($this->list_bytype[$type]['disabled'])) {
$this->list_bytype[$type]['disabled'] = $this->_getListByType($type,false);
}
/**
* Returns a list of available plugins of given type
*
* @param $type string, plugin_type name;
* the type of plugin to return,
* use empty string for all types
* @param $all bool;
* false to only return enabled plugins,
* true to return both enabled and disabled plugins
*
* @return array of plugin names
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getList($type='',$all=false){
return $all ? array_merge($this->list_bytype[$type]['enabled'],$this->list_bytype[$type]['disabled']) : $this->list_bytype[$type]['enabled'];
}
/**
* Loads the given plugin and creates an object of it
*
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param $type string type of plugin to load
* @param $name string name of the plugin to load
* @param $new bool true to return a new instance of the plugin, false to use an already loaded instance
* @return objectreference the plugin object or null on failure
*/
function &load($type,$name,$new=false){
//we keep all loaded plugins available in global scope for reuse
global $DOKU_PLUGINS;
//plugin already loaded?
if(!empty($DOKU_PLUGINS[$type][$name])){
if ($new && !$DOKU_PLUGINS[$type][$name]->isSingleton()) {
$class = $type.'_plugin_'.$name;
return class_exists($class) ? new $class : null;
} else {
return $DOKU_PLUGINS[$type][$name];
}
}
//try to load the wanted plugin file
list($plugin,$component) = $this->_splitName($name);
$dir = $this->get_directory($plugin);
$file = $component ? "$type/$component.php" : "$type.php";
if(!is_file(DOKU_PLUGIN."$dir/$file")){
return null;
}
if (!include_once(DOKU_PLUGIN."$dir/$file")) {
return null;
}
//construct class and instantiate
$class = $type.'_plugin_'.$name;
if (!class_exists($class)) return null;
$DOKU_PLUGINS[$type][$name] = new $class;
return $DOKU_PLUGINS[$type][$name];
}
function isdisabled($plugin) {
return (array_search($plugin, $this->list_enabled) === false);
}
function enable($plugin) {
if (array_search($plugin, $this->list_disabled) !== false) {
return @unlink(DOKU_PLUGIN.$plugin.'/disabled');
}
return false;
}
function disable($plugin) {
if (array_search($plugin, $this->list_enabled) !== false) {
return @touch(DOKU_PLUGIN.$plugin.'/disabled');
}
return false;
}
function get_directory($plugin) {
return $plugin;
}
function _populateMasterList() {
if ($dh = opendir(DOKU_PLUGIN)) {
while (false !== ($plugin = readdir($dh))) {
if ($plugin == '.' || $plugin == '..' || $plugin == 'tmp') continue;
if (is_file(DOKU_PLUGIN.$plugin)) continue;
if (substr($plugin,-9) == '.disabled') {
// the plugin was disabled by rc2009-01-26
// disabling mechanism was changed back very soon again
// to keep everything simple we just skip the plugin completely
}elseif(@file_exists(DOKU_PLUGIN.$plugin.'/disabled')){
$this->list_disabled[] = $plugin;
} else {
$this->list_enabled[] = $plugin;
// request the complete list
if (!$type) {
return $all ? array_merge($this->list_enabled,$this->list_disabled) : $this->list_enabled;
}
}
if (!isset($this->list_bytype[$type]['enabled'])) {
$this->list_bytype[$type]['enabled'] = $this->_getListByType($type,true);
}
if ($all && !isset($this->list_bytype[$type]['disabled'])) {
$this->list_bytype[$type]['disabled'] = $this->_getListByType($type,false);
}
return $all ? array_merge($this->list_bytype[$type]['enabled'],$this->list_bytype[$type]['disabled']) : $this->list_bytype[$type]['enabled'];
}
}
function _getListByType($type, $enabled) {
$master_list = $enabled ? $this->list_enabled : $this->list_disabled;
/**
* Loads the given plugin and creates an object of it
*
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param $type string type of plugin to load
* @param $name string name of the plugin to load
* @param $new bool true to return a new instance of the plugin, false to use an already loaded instance
* @return objectreference the plugin object or null on failure
*/
function &load($type,$name,$new=false){
//we keep all loaded plugins available in global scope for reuse
global $DOKU_PLUGINS;
$plugins = array();
foreach ($master_list as $plugin) {
$dir = $this->get_directory($plugin);
if (@file_exists(DOKU_PLUGIN."$dir/$type.php")){
$plugins[] = $plugin;
} else {
if ($dp = @opendir(DOKU_PLUGIN."$dir/$type/")) {
while (false !== ($component = readdir($dp))) {
if (substr($component,0,1) == '.' || strtolower(substr($component, -4)) != ".php") continue;
if (is_file(DOKU_PLUGIN."$dir/$type/$component")) {
$plugins[] = $plugin.'_'.substr($component, 0, -4);
//plugin already loaded?
if(!empty($DOKU_PLUGINS[$type][$name])){
if ($new && !$DOKU_PLUGINS[$type][$name]->isSingleton()) {
$class = $type.'_plugin_'.$name;
return class_exists($class) ? new $class : null;
} else {
return $DOKU_PLUGINS[$type][$name];
}
}
closedir($dp);
}
}
//try to load the wanted plugin file
list($plugin,$component) = $this->_splitName($name);
$dir = $this->get_directory($plugin);
$file = $component ? "$type/$component.php" : "$type.php";
if(!is_file(DOKU_PLUGIN."$dir/$file")){
return null;
}
if (!include_once(DOKU_PLUGIN."$dir/$file")) {
return null;
}
//construct class and instantiate
$class = $type.'_plugin_'.$name;
if (!class_exists($class)) return null;
$DOKU_PLUGINS[$type][$name] = new $class;
return $DOKU_PLUGINS[$type][$name];
}
return $plugins;
}
function _splitName($name) {
if (array_search($name, $this->list_enabled + $this->list_disabled) === false) {
return explode('_',$name,2);
function isdisabled($plugin) {
return (array_search($plugin, $this->list_enabled) === false);
}
return array($name,'');
}
function enable($plugin) {
if (array_search($plugin, $this->list_disabled) !== false) {
return @unlink(DOKU_PLUGIN.$plugin.'/disabled');
}
return false;
}
function disable($plugin) {
if (array_search($plugin, $this->list_enabled) !== false) {
return @touch(DOKU_PLUGIN.$plugin.'/disabled');
}
return false;
}
function get_directory($plugin) {
return $plugin;
}
function _populateMasterList() {
if ($dh = opendir(DOKU_PLUGIN)) {
while (false !== ($plugin = readdir($dh))) {
if ($plugin == '.' || $plugin == '..' || $plugin == 'tmp') continue;
if (is_file(DOKU_PLUGIN.$plugin)) continue;
if (substr($plugin,-9) == '.disabled') {
// the plugin was disabled by rc2009-01-26
// disabling mechanism was changed back very soon again
// to keep everything simple we just skip the plugin completely
}elseif(@file_exists(DOKU_PLUGIN.$plugin.'/disabled')){
$this->list_disabled[] = $plugin;
} else {
$this->list_enabled[] = $plugin;
}
}
}
}
function _getListByType($type, $enabled) {
$master_list = $enabled ? $this->list_enabled : $this->list_disabled;
$plugins = array();
foreach ($master_list as $plugin) {
$dir = $this->get_directory($plugin);
if (@file_exists(DOKU_PLUGIN."$dir/$type.php")){
$plugins[] = $plugin;
} else {
if ($dp = @opendir(DOKU_PLUGIN."$dir/$type/")) {
while (false !== ($component = readdir($dp))) {
if (substr($component,0,1) == '.' || strtolower(substr($component, -4)) != ".php") continue;
if (is_file(DOKU_PLUGIN."$dir/$type/$component")) {
$plugins[] = $plugin.'_'.substr($component, 0, -4);
}
}
closedir($dp);
}
}
}
return $plugins;
}
function _splitName($name) {
if (array_search($name, $this->list_enabled + $this->list_disabled) === false) {
return explode('_',$name,2);
}
return array($name,'');
}
}

View File

@ -20,10 +20,28 @@ $plugin_controller = new $plugin_controller_class();
/**
* Original plugin functions, remain for backwards compatibility
*/
function plugin_list($type='',$all=false) { global $plugin_controller; return $plugin_controller->getList($type,$all); }
function &plugin_load($type,$name,$new=false) { global $plugin_controller; return $plugin_controller->load($type,$name,$new); }
function plugin_isdisabled($plugin) { global $plugin_controller; return $plugin_controller->isdisabled($plugin); }
function plugin_enable($plugin) { global $plugin_controller; return $plugin_controller->enable($plugin); }
function plugin_disable($plugin) { global $plugin_controller; return $plugin_controller->disable($plugin); }
function plugin_directory($plugin) { global $plugin_controller; return $plugin_controller->get_directory($plugin); }
function plugin_list($type='',$all=false) {
global $plugin_controller;
return $plugin_controller->getList($type,$all);
}
function &plugin_load($type,$name,$new=false) {
global $plugin_controller;
return $plugin_controller->load($type,$name,$new);
}
function plugin_isdisabled($plugin) {
global $plugin_controller;
return $plugin_controller->isdisabled($plugin);
}
function plugin_enable($plugin) {
global $plugin_controller;
return $plugin_controller->enable($plugin);
}
function plugin_disable($plugin) {
global $plugin_controller;
return $plugin_controller->disable($plugin);
}
function plugin_directory($plugin) {
global $plugin_controller;
return $plugin_controller->get_directory($plugin);
}

View File

@ -23,34 +23,34 @@ require_once(DOKU_INC.'inc/common.php');
* @author Andreas Gohr <andi@splitbrain.org>
*/
function search(&$data,$base,$func,$opts,$dir='',$lvl=1){
$dirs = array();
$files = array();
$dirs = array();
$files = array();
//read in directories and files
$dh = @opendir($base.'/'.$dir);
if(!$dh) return;
while(($file = readdir($dh)) !== false){
if(preg_match('/^[\._]/',$file)) continue; //skip hidden files and upper dirs
if(is_dir($base.'/'.$dir.'/'.$file)){
$dirs[] = $dir.'/'.$file;
continue;
//read in directories and files
$dh = @opendir($base.'/'.$dir);
if(!$dh) return;
while(($file = readdir($dh)) !== false){
if(preg_match('/^[\._]/',$file)) continue; //skip hidden files and upper dirs
if(is_dir($base.'/'.$dir.'/'.$file)){
$dirs[] = $dir.'/'.$file;
continue;
}
$files[] = $dir.'/'.$file;
}
$files[] = $dir.'/'.$file;
}
closedir($dh);
sort($files);
sort($dirs);
closedir($dh);
sort($files);
sort($dirs);
//give directories to userfunction then recurse
foreach($dirs as $dir){
if (call_user_func_array($func, array(&$data,$base,$dir,'d',$lvl,$opts))){
search($data,$base,$func,$opts,$dir,$lvl+1);
//give directories to userfunction then recurse
foreach($dirs as $dir){
if (call_user_func_array($func, array(&$data,$base,$dir,'d',$lvl,$opts))){
search($data,$base,$func,$opts,$dir,$lvl+1);
}
}
//now handle the files
foreach($files as $file){
call_user_func_array($func, array(&$data,$base,$file,'f',$lvl,$opts));
}
}
//now handle the files
foreach($files as $file){
call_user_func_array($func, array(&$data,$base,$file,'f',$lvl,$opts));
}
}
/**
@ -59,7 +59,7 @@ function search(&$data,$base,$func,$opts,$dir='',$lvl=1){
* @deprecated
*/
function search_callback($func,&$data,$base,$file,$type,$lvl,$opts){
return call_user_func_array($func, array(&$data,$base,$file,$type,$lvl,$opts));
return call_user_func_array($func, array(&$data,$base,$file,$type,$lvl,$opts));
}
/**
@ -92,10 +92,10 @@ function search_callback($func,&$data,$base,$file,$type,$lvl,$opts){
*/
function search_qsearch(&$data,$base,$file,$type,$lvl,$opts){
$opts = array(
'idmatch' => '(^|:)'.preg_quote($opts['query'],'/').'/',
'listfiles' => true,
'pagesonly' => true,
);
'idmatch' => '(^|:)'.preg_quote($opts['query'],'/').'/',
'listfiles' => true,
'pagesonly' => true,
);
return search_universal($data,$base,$file,$type,$lvl,$opts);
}
@ -107,40 +107,40 @@ function search_qsearch(&$data,$base,$file,$type,$lvl,$opts){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function search_index(&$data,$base,$file,$type,$lvl,$opts){
global $conf;
$return = true;
global $conf;
$return = true;
$item = array();
$item = array();
if($type == 'd' && !preg_match('#^'.$file.'(/|$)#','/'.$opts['ns'])){
//add but don't recurse
$return = false;
}elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){
//don't add
return false;
}
if($type == 'd' && !preg_match('#^'.$file.'(/|$)#','/'.$opts['ns'])){
//add but don't recurse
$return = false;
}elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){
//don't add
return false;
}
$id = pathID($file);
$id = pathID($file);
if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){
return false;
}
if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){
return false;
}
//check hidden
if(isHiddenPage($id)){
return false;
}
//check hidden
if(isHiddenPage($id)){
return false;
}
//check ACL
if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){
return false;
}
//check ACL
if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){
return false;
}
$data[]=array( 'id' => $id,
'type' => $type,
'level' => $lvl,
'open' => $return );
return $return;
$data[]=array( 'id' => $id,
'type' => $type,
'level' => $lvl,
'open' => $return );
return $return;
}
/**
@ -150,8 +150,8 @@ function search_index(&$data,$base,$file,$type,$lvl,$opts){
*/
function search_namespaces(&$data,$base,$file,$type,$lvl,$opts){
$opts = array(
'listdirs' => true,
);
'listdirs' => true,
);
return search_universal($data,$base,$file,$type,$lvl,$opts);
}
@ -215,18 +215,18 @@ function search_media(&$data,$base,$file,$type,$lvl,$opts){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function search_list(&$data,$base,$file,$type,$lvl,$opts){
//we do nothing with directories
if($type == 'd') return false;
//only search txt files
if(substr($file,-4) == '.txt'){
//check ACL
$id = pathID($file);
if(auth_quickaclcheck($id) < AUTH_READ){
return false;
//we do nothing with directories
if($type == 'd') return false;
//only search txt files
if(substr($file,-4) == '.txt'){
//check ACL
$id = pathID($file);
if(auth_quickaclcheck($id) < AUTH_READ){
return false;
}
$data[]['id'] = $id;
}
$data[]['id'] = $id;
}
return false;
return false;
}
/**
@ -237,23 +237,23 @@ function search_list(&$data,$base,$file,$type,$lvl,$opts){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function search_pagename(&$data,$base,$file,$type,$lvl,$opts){
//we do nothing with directories
if($type == 'd') return true;
//only search txt files
if(substr($file,-4) != '.txt') return true;
//we do nothing with directories
if($type == 'd') return true;
//only search txt files
if(substr($file,-4) != '.txt') return true;
//simple stringmatching
if (!empty($opts['query'])){
if(strpos($file,$opts['query']) !== false){
//check ACL
$id = pathID($file);
if(auth_quickaclcheck($id) < AUTH_READ){
return false;
}
$data[]['id'] = $id;
//simple stringmatching
if (!empty($opts['query'])){
if(strpos($file,$opts['query']) !== false){
//check ACL
$id = pathID($file);
if(auth_quickaclcheck($id) < AUTH_READ){
return false;
}
$data[]['id'] = $id;
}
}
}
return true;
return true;
}
/**
@ -279,7 +279,7 @@ function search_allpages(&$data,$base,$file,$type,$lvl,$opts){
$item['id'] = pathID($file);
if(!$opts['skipacl'] && auth_quickaclcheck($item['id']) < AUTH_READ){
return false;
return false;
}
$item['rev'] = filemtime($base.'/'.$file);
@ -303,42 +303,42 @@ function search_allpages(&$data,$base,$file,$type,$lvl,$opts){
* @deprecated Replaced by ft_backlinks()
*/
function search_backlinks(&$data,$base,$file,$type,$lvl,$opts){
//we do nothing with directories
if($type == 'd') return true;
//only search txt files
if(substr($file,-4) != '.txt') return true;
//we do nothing with directories
if($type == 'd') return true;
//only search txt files
if(substr($file,-4) != '.txt') return true;
//absolute search id
$sid = cleanID($opts['ns'].':'.$opts['name']);
//absolute search id
$sid = cleanID($opts['ns'].':'.$opts['name']);
//current id and namespace
$cid = pathID($file);
$cns = getNS($cid);
//current id and namespace
$cid = pathID($file);
$cns = getNS($cid);
//check ACL
if(auth_quickaclcheck($cid) < AUTH_READ){
return false;
}
//fetch instructions
require_once(DOKU_INC.'inc/parserutils.php');
$instructions = p_cached_instructions($base.$file,true);
if(is_null($instructions)) return false;
//check all links for match
foreach($instructions as $ins){
if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink') ){
$mid = $ins[1][0];
resolve_pageid($cns,$mid,$exists); //exists is not used
if($mid == $sid){
//we have a match - finish
$data[]['id'] = $cid;
break;
}
//check ACL
if(auth_quickaclcheck($cid) < AUTH_READ){
return false;
}
}
return false;
//fetch instructions
require_once(DOKU_INC.'inc/parserutils.php');
$instructions = p_cached_instructions($base.$file,true);
if(is_null($instructions)) return false;
//check all links for match
foreach($instructions as $ins){
if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink') ){
$mid = $ins[1][0];
resolve_pageid($cns,$mid,$exists); //exists is not used
if($mid == $sid){
//we have a match - finish
$data[]['id'] = $cid;
break;
}
}
}
return false;
}
/**
@ -350,86 +350,86 @@ function search_backlinks(&$data,$base,$file,$type,$lvl,$opts){
* @deprecated - fulltext indexer is used instead
*/
function search_fulltext(&$data,$base,$file,$type,$lvl,$opts){
//we do nothing with directories
if($type == 'd') return true;
//only search txt files
if(substr($file,-4) != '.txt') return true;
//we do nothing with directories
if($type == 'd') return true;
//only search txt files
if(substr($file,-4) != '.txt') return true;
//check ACL
$id = pathID($file);
if(auth_quickaclcheck($id) < AUTH_READ){
return false;
}
//create regexp from queries
$poswords = array();
$negwords = array();
$qpreg = preg_split('/\s+/',$opts['query']);
foreach($qpreg as $word){
switch(substr($word,0,1)){
case '-':
if(strlen($word) > 1){ // catch single '-'
array_push($negwords,preg_quote(substr($word,1),'#'));
}
break;
case '+':
if(strlen($word) > 1){ // catch single '+'
array_push($poswords,preg_quote(substr($word,1),'#'));
}
break;
default:
array_push($poswords,preg_quote($word,'#'));
break;
//check ACL
$id = pathID($file);
if(auth_quickaclcheck($id) < AUTH_READ){
return false;
}
}
// a search without any posword is useless
if (!count($poswords)) return true;
//create regexp from queries
$poswords = array();
$negwords = array();
$qpreg = preg_split('/\s+/',$opts['query']);
$reg = '^(?=.*?'.join(')(?=.*?',$poswords).')';
$reg .= count($negwords) ? '((?!'.join('|',$negwords).').)*$' : '.*$';
search_regex($data,$base,$file,$reg,$poswords);
return true;
}
foreach($qpreg as $word){
switch(substr($word,0,1)){
case '-':
if(strlen($word) > 1){ // catch single '-'
array_push($negwords,preg_quote(substr($word,1),'#'));
}
break;
case '+':
if(strlen($word) > 1){ // catch single '+'
array_push($poswords,preg_quote(substr($word,1),'#'));
}
break;
default:
array_push($poswords,preg_quote($word,'#'));
break;
}
}
/**
* Reference search
* This fuction searches for existing references to a given media file
* and returns an array with the found pages. It doesn't pay any
* attention to ACL permissions to find every reference. The caller
* must check if the user has the appropriate rights to see the found
* page and eventually have to prevent the result from displaying.
*
* @param array $data Reference to the result data structure
* @param string $base Base usually $conf['datadir']
* @param string $file current file or directory relative to $base
* @param char $type Type either 'd' for directory or 'f' for file
* @param int $lvl Current recursion depht
* @param mixed $opts option array as given to search()
*
* $opts['query'] is the demanded media file name
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
// a search without any posword is useless
if (!count($poswords)) return true;
$reg = '^(?=.*?'.join(')(?=.*?',$poswords).')';
$reg .= count($negwords) ? '((?!'.join('|',$negwords).').)*$' : '.*$';
search_regex($data,$base,$file,$reg,$poswords);
return true;
}
/**
* Reference search
* This fuction searches for existing references to a given media file
* and returns an array with the found pages. It doesn't pay any
* attention to ACL permissions to find every reference. The caller
* must check if the user has the appropriate rights to see the found
* page and eventually have to prevent the result from displaying.
*
* @param array $data Reference to the result data structure
* @param string $base Base usually $conf['datadir']
* @param string $file current file or directory relative to $base
* @param char $type Type either 'd' for directory or 'f' for file
* @param int $lvl Current recursion depht
* @param mixed $opts option array as given to search()
*
* $opts['query'] is the demanded media file name
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function search_reference(&$data,$base,$file,$type,$lvl,$opts){
global $conf;
global $conf;
//we do nothing with directories
if($type == 'd') return true;
//we do nothing with directories
if($type == 'd') return true;
//only search txt files
if(substr($file,-4) != '.txt') return true;
//only search txt files
if(substr($file,-4) != '.txt') return true;
//we finish after 'cnt' references found. The return value
//'false' will skip subdirectories to speed search up.
$cnt = $conf['refshow'] > 0 ? $conf['refshow'] : 1;
if(count($data) >= $cnt) return false;
//we finish after 'cnt' references found. The return value
//'false' will skip subdirectories to speed search up.
$cnt = $conf['refshow'] > 0 ? $conf['refshow'] : 1;
if(count($data) >= $cnt) return false;
$reg = '\{\{ *\:?'.$opts['query'].' *(\|.*)?\}\}';
search_regex($data,$base,$file,$reg,array($opts['query']));
return true;
$reg = '\{\{ *\:?'.$opts['query'].' *(\|.*)?\}\}';
search_regex($data,$base,$file,$reg,array($opts['query']));
return true;
}
/* ------------- helper functions below -------------- */
@ -453,35 +453,35 @@ function search_reference(&$data,$base,$file,$type,$lvl,$opts){
*/
function search_regex(&$data,$base,$file,$reg,$words){
//get text
$text = io_readfile($base.'/'.$file);
//lowercase text (u modifier does not help with case)
$lctext = utf8_strtolower($text);
//get text
$text = io_readfile($base.'/'.$file);
//lowercase text (u modifier does not help with case)
$lctext = utf8_strtolower($text);
//do the fulltext search
$matches = array();
if($cnt = preg_match_all('#'.$reg.'#usi',$lctext,$matches)){
//this is not the best way for snippet generation but the fastest I could find
$q = $words[0]; //use first word for snippet creation
$p = utf8_strpos($lctext,$q);
$f = $p - 100;
$l = utf8_strlen($q) + 200;
if($f < 0) $f = 0;
$snippet = '<span class="search_sep"> ... </span>'.
htmlspecialchars(utf8_substr($text,$f,$l)).
'<span class="search_sep"> ... </span>';
$mark = '('.join('|', $words).')';
$snippet = preg_replace('#'.$mark.'#si','<strong class="search_hit">\\1</strong>',$snippet);
//do the fulltext search
$matches = array();
if($cnt = preg_match_all('#'.$reg.'#usi',$lctext,$matches)){
//this is not the best way for snippet generation but the fastest I could find
$q = $words[0]; //use first word for snippet creation
$p = utf8_strpos($lctext,$q);
$f = $p - 100;
$l = utf8_strlen($q) + 200;
if($f < 0) $f = 0;
$snippet = '<span class="search_sep"> ... </span>'.
htmlspecialchars(utf8_substr($text,$f,$l)).
'<span class="search_sep"> ... </span>';
$mark = '('.join('|', $words).')';
$snippet = preg_replace('#'.$mark.'#si','<strong class="search_hit">\\1</strong>',$snippet);
$data[] = array(
'id' => pathID($file),
'count' => preg_match_all('#'.$mark.'#usi',$lctext,$matches),
'poswords' => join(' ',$words),
'snippet' => $snippet,
);
}
$data[] = array(
'id' => pathID($file),
'count' => preg_match_all('#'.$mark.'#usi',$lctext,$matches),
'poswords' => join(' ',$words),
'snippet' => $snippet,
);
}
return true;
return true;
}
@ -494,13 +494,13 @@ function search_regex(&$data,$base,$file,$reg,$words){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function sort_search_fulltext($a,$b){
if($a['count'] > $b['count']){
return -1;
}elseif($a['count'] < $b['count']){
return 1;
}else{
return strcmp($a['id'],$b['id']);
}
if($a['count'] > $b['count']){
return -1;
}elseif($a['count'] < $b['count']){
return 1;
}else{
return strcmp($a['id'],$b['id']);
}
}
/**
@ -510,12 +510,12 @@ function sort_search_fulltext($a,$b){
* @todo move to pageutils
*/
function pathID($path,$keeptxt=false){
$id = utf8_decodeFN($path);
$id = str_replace('/',':',$id);
if(!$keeptxt) $id = preg_replace('#\.txt$#','',$id);
$id = preg_replace('#^:+#','',$id);
$id = preg_replace('#:+$#','',$id);
return $id;
$id = utf8_decodeFN($path);
$id = str_replace('/',':',$id);
if(!$keeptxt) $id = preg_replace('#\.txt$#','',$id);
$id = preg_replace('#^:+#','',$id);
$id = preg_replace('#:+$#','',$id);
return $id;
}

View File

@ -13,7 +13,7 @@ require_once(DOKU_INC.'inc/JSON.php');
/**
* Prepares and prints an JavaScript array with all toolbar buttons
*
* @todo add toolbar plugins
* @emits TOOLBAR_DEFINE
* @param string $varname Name of the JS variable to fill
* @author Andreas Gohr <andi@splitbrain.org>
*/
@ -209,9 +209,6 @@ function toolbar_JSdefines($varname){
'icon' => 'sig.png',
'key' => 'y',
),
));
} // end event TOOLBAR_DEFINE default action
$evt->advise_after();
@ -228,17 +225,17 @@ function toolbar_JSdefines($varname){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function toolbar_signature(){
global $conf;
global $INFO;
global $conf;
global $INFO;
$sig = $conf['signature'];
$sig = strftime($sig);
$sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
$sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
$sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
$sig = str_replace('@DATE@',dformat(),$sig);
$sig = str_replace('\\\\n','\\n',addslashes($sig));
return $sig;
$sig = $conf['signature'];
$sig = strftime($sig);
$sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
$sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
$sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
$sig = str_replace('@DATE@',dformat(),$sig);
$sig = str_replace('\\\\n','\\n',addslashes($sig));
return $sig;
}
//Setup VIM: ex: et ts=4 enc=utf-8 :

View File

@ -10,11 +10,11 @@
* check for mb_string support
*/
if(!defined('UTF8_MBSTRING')){
if(function_exists('mb_substr') && !defined('UTF8_NOMBSTRING')){
define('UTF8_MBSTRING',1);
}else{
define('UTF8_MBSTRING',0);
}
if(function_exists('mb_substr') && !defined('UTF8_NOMBSTRING')){
define('UTF8_MBSTRING',1);
}else{
define('UTF8_MBSTRING',0);
}
}
if(UTF8_MBSTRING){ mb_internal_encoding('UTF-8'); }
@ -34,12 +34,12 @@ if(!function_exists('utf8_encodeFN')){
* @see urlencode
*/
function utf8_encodeFN($file,$safe=true){
if($safe && preg_match('#^[a-zA-Z0-9/_\-.%]+$#',$file)){
if($safe && preg_match('#^[a-zA-Z0-9/_\-.%]+$#',$file)){
return $file;
}
$file = urlencode($file);
$file = str_replace('%2F','/',$file);
return $file;
}
$file = urlencode($file);
$file = str_replace('%2F','/',$file);
return $file;
}
}
@ -184,53 +184,53 @@ if(!function_exists('utf8_substr')){
// normalise -ve offsets (we could use a tail anchored pattern, but they are horribly slow!)
if ($offset < 0) {
$strlen = strlen(utf8_decode($str)); // see notes
$offset = $strlen + $offset;
if ($offset < 0) $offset = 0;
$strlen = strlen(utf8_decode($str)); // see notes
$offset = $strlen + $offset;
if ($offset < 0) $offset = 0;
}
// establish a pattern for offset, a non-captured group equal in length to offset
if ($offset > 0) {
$Ox = (int)($offset/65535);
$Oy = $offset%65535;
$Ox = (int)($offset/65535);
$Oy = $offset%65535;
if ($Ox) $offset_pattern = '(?:.{65535}){'.$Ox.'}';
$offset_pattern = '^(?:'.$offset_pattern.'.{'.$Oy.'})';
if ($Ox) $offset_pattern = '(?:.{65535}){'.$Ox.'}';
$offset_pattern = '^(?:'.$offset_pattern.'.{'.$Oy.'})';
} else {
$offset_pattern = '^'; // offset == 0; just anchor the pattern
$offset_pattern = '^'; // offset == 0; just anchor the pattern
}
// establish a pattern for length
if (is_null($length)) {
$length_pattern = '(.*)$'; // the rest of the string
$length_pattern = '(.*)$'; // the rest of the string
} else {
if (!isset($strlen)) $strlen = strlen(utf8_decode($str)); // see notes
if ($offset > $strlen) return ''; // another trivial case
if (!isset($strlen)) $strlen = strlen(utf8_decode($str)); // see notes
if ($offset > $strlen) return ''; // another trivial case
if ($length > 0) {
if ($length > 0) {
$length = min($strlen-$offset, $length); // reduce any length that would go passed the end of the string
$length = min($strlen-$offset, $length); // reduce any length that would go passed the end of the string
$Lx = (int)($length/65535);
$Ly = $length%65535;
$Lx = (int)($length/65535);
$Ly = $length%65535;
// +ve length requires ... a captured group of length characters
if ($Lx) $length_pattern = '(?:.{65535}){'.$Lx.'}';
$length_pattern = '('.$length_pattern.'.{'.$Ly.'})';
// +ve length requires ... a captured group of length characters
if ($Lx) $length_pattern = '(?:.{65535}){'.$Lx.'}';
$length_pattern = '('.$length_pattern.'.{'.$Ly.'})';
} else if ($length < 0) {
} else if ($length < 0) {
if ($length < ($offset - $strlen)) return '';
if ($length < ($offset - $strlen)) return '';
$Lx = (int)((-$length)/65535);
$Ly = (-$length)%65535;
$Lx = (int)((-$length)/65535);
$Ly = (-$length)%65535;
// -ve length requires ... capture everything except a group of -length characters
// anchored at the tail-end of the string
if ($Lx) $length_pattern = '(?:.{65535}){'.$Lx.'}';
$length_pattern = '(.*)(?:'.$length_pattern.'.{'.$Ly.'})$';
}
// -ve length requires ... capture everything except a group of -length characters
// anchored at the tail-end of the string
if ($Lx) $length_pattern = '(?:.{65535}){'.$Lx.'}';
$length_pattern = '(.*)(?:'.$length_pattern.'.{'.$Ly.'})$';
}
}
if (!preg_match('#'.$offset_pattern.$length_pattern.'#us',$str,$match)) return '';
@ -246,11 +246,11 @@ if(!function_exists('utf8_substr_replace')){
* @see substr_replace()
*/
function utf8_substr_replace($string, $replacement, $start , $length=0 ){
$ret = '';
if($start>0) $ret .= utf8_substr($string, 0, $start);
$ret .= $replacement;
$ret .= utf8_substr($string, $start+$length);
return $ret;
$ret = '';
if($start>0) $ret .= utf8_substr($string, 0, $start);
$ret .= $replacement;
$ret .= utf8_substr($string, $start+$length);
return $ret;
}
}
@ -263,12 +263,12 @@ if(!function_exists('utf8_ltrim')){
* @return string
*/
function utf8_ltrim($str,$charlist=''){
if($charlist == '') return ltrim($str);
if($charlist == '') return ltrim($str);
//quote charlist for use in a characterclass
$charlist = preg_replace('!([\\\\\\-\\]\\[/])!','\\\${1}',$charlist);
//quote charlist for use in a characterclass
$charlist = preg_replace('!([\\\\\\-\\]\\[/])!','\\\${1}',$charlist);
return preg_replace('/^['.$charlist.']+/u','',$str);
return preg_replace('/^['.$charlist.']+/u','',$str);
}
}
@ -281,12 +281,12 @@ if(!function_exists('utf8_rtrim')){
* @return string
*/
function utf8_rtrim($str,$charlist=''){
if($charlist == '') return rtrim($str);
if($charlist == '') return rtrim($str);
//quote charlist for use in a characterclass
$charlist = preg_replace('!([\\\\\\-\\]\\[/])!','\\\${1}',$charlist);
//quote charlist for use in a characterclass
$charlist = preg_replace('!([\\\\\\-\\]\\[/])!','\\\${1}',$charlist);
return preg_replace('/['.$charlist.']+$/u','',$str);
return preg_replace('/['.$charlist.']+$/u','',$str);
}
}
@ -299,9 +299,9 @@ if(!function_exists('utf8_trim')){
* @return string
*/
function utf8_trim($str,$charlist='') {
if($charlist == '') return trim($str);
if($charlist == '') return trim($str);
return utf8_ltrim(utf8_rtrim($str,$charlist),$charlist);
return utf8_ltrim(utf8_rtrim($str,$charlist),$charlist);
}
}
@ -316,10 +316,10 @@ if(!function_exists('utf8_strtolower')){
* @see utf8_strtoupper()
*/
function utf8_strtolower($string){
if(UTF8_MBSTRING) return mb_strtolower($string,'utf-8');
if(UTF8_MBSTRING) return mb_strtolower($string,'utf-8');
global $UTF8_UPPER_TO_LOWER;
return strtr($string,$UTF8_UPPER_TO_LOWER);
global $UTF8_UPPER_TO_LOWER;
return strtr($string,$UTF8_UPPER_TO_LOWER);
}
}
@ -334,10 +334,10 @@ if(!function_exists('utf8_strtoupper')){
* @see utf8_strtoupper()
*/
function utf8_strtoupper($string){
if(UTF8_MBSTRING) return mb_strtoupper($string,'utf-8');
if(UTF8_MBSTRING) return mb_strtoupper($string,'utf-8');
global $UTF8_LOWER_TO_UPPER;
return strtr($string,$UTF8_LOWER_TO_UPPER);
global $UTF8_LOWER_TO_UPPER;
return strtr($string,$UTF8_LOWER_TO_UPPER);
}
}
@ -351,15 +351,15 @@ if(!function_exists('utf8_ucfirst')){
* @return string with first character as upper case (if applicable)
*/
function utf8_ucfirst($str){
switch ( utf8_strlen($str) ) {
case 0:
return '';
case 1:
return utf8_strtoupper($str);
default:
preg_match('/^(.{1})(.*)$/us', $str, $matches);
return utf8_strtoupper($matches[1]).$matches[2];
}
switch ( utf8_strlen($str) ) {
case 0:
return '';
case 1:
return utf8_strtoupper($str);
default:
preg_match('/^(.{1})(.*)$/us', $str, $matches);
return utf8_strtoupper($matches[1]).$matches[2];
}
}
}
@ -374,12 +374,12 @@ if(!function_exists('utf8_ucwords')){
* @see http://www.php.net/ucwords
*/
function utf8_ucwords($str) {
// Note: [\x0c\x09\x0b\x0a\x0d\x20] matches;
// form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns
// This corresponds to the definition of a "word" defined at http://www.php.net/ucwords
$pattern = '/(^|([\x0c\x09\x0b\x0a\x0d\x20]+))([^\x0c\x09\x0b\x0a\x0d\x20]{1})[^\x0c\x09\x0b\x0a\x0d\x20]*/u';
// Note: [\x0c\x09\x0b\x0a\x0d\x20] matches;
// form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns
// This corresponds to the definition of a "word" defined at http://www.php.net/ucwords
$pattern = '/(^|([\x0c\x09\x0b\x0a\x0d\x20]+))([^\x0c\x09\x0b\x0a\x0d\x20]{1})[^\x0c\x09\x0b\x0a\x0d\x20]*/u';
return preg_replace_callback($pattern, 'utf8_ucwords_callback',$str);
return preg_replace_callback($pattern, 'utf8_ucwords_callback',$str);
}
/**
@ -393,10 +393,10 @@ if(!function_exists('utf8_ucwords')){
* @see utf8_strtoupper
*/
function utf8_ucwords_callback($matches) {
$leadingws = $matches[2];
$ucfirst = utf8_strtoupper($matches[3]);
$ucword = utf8_substr_replace(ltrim($matches[0]),$ucfirst,0,1);
return $leadingws . $ucword;
$leadingws = $matches[2];
$ucfirst = utf8_strtoupper($matches[3]);
$ucword = utf8_substr_replace(ltrim($matches[0]),$ucfirst,0,1);
return $leadingws . $ucword;
}
}
@ -550,13 +550,13 @@ if(!function_exists('utf8_unhtml')){
if(!function_exists('utf8_decode_numeric')){
function utf8_decode_numeric($ent) {
switch ($ent[2]) {
case 'X':
case 'x':
$cp = hexdec($ent[3]);
break;
default:
$cp = intval($ent[3]);
break;
case 'X':
case 'x':
$cp = hexdec($ent[3]);
break;
default:
$cp = intval($ent[3]);
break;
}
return unicode_to_utf8(array($cp));
}
@ -789,24 +789,24 @@ if(!function_exists('unicode_to_utf8')){
foreach (array_keys($arr) as $k) {
# ASCII range (including control chars)
if ( ($arr[$k] >= 0) && ($arr[$k] <= 0x007f) ) {
# ASCII range (including control chars)
echo chr($arr[$k]);
# 2 byte sequence
} else if ($arr[$k] <= 0x07ff) {
# 2 byte sequence
echo chr(0xc0 | ($arr[$k] >> 6));
echo chr(0x80 | ($arr[$k] & 0x003f));
# Byte order mark (skip)
} else if($arr[$k] == 0xFEFF) {
# Byte order mark (skip)
// nop -- zap the BOM
# Test for illegal surrogates
} else if ($arr[$k] >= 0xD800 && $arr[$k] <= 0xDFFF) {
# Test for illegal surrogates
// found a surrogate
if($strict){
@ -818,15 +818,15 @@ if(!function_exists('unicode_to_utf8')){
return false;
}
# 3 byte sequence
} else if ($arr[$k] <= 0xffff) {
# 3 byte sequence
echo chr(0xe0 | ($arr[$k] >> 12));
echo chr(0x80 | (($arr[$k] >> 6) & 0x003f));
echo chr(0x80 | ($arr[$k] & 0x003f));
# 4 byte sequence
} else if ($arr[$k] <= 0x10ffff) {
# 4 byte sequence
echo chr(0xf0 | ($arr[$k] >> 18));
echo chr(0x80 | (($arr[$k] >> 12) & 0x3f));
@ -957,163 +957,163 @@ if(!function_exists('utf8_correctIdx')){
// only needed if no mb_string available
if(!UTF8_MBSTRING){
/**
* UTF-8 Case lookup table
*
* This lookuptable defines the upper case letters to their correspponding
* lower case letter in UTF-8
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
global $UTF8_LOWER_TO_UPPER;
if(empty($UTF8_LOWER_TO_UPPER)) $UTF8_LOWER_TO_UPPER = array(
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"Ι",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"Ἷ",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"","ế"=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"","ṿ"=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"","ḿ"=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
"ֆ"=>"Ֆ","օ"=>"Օ","ք"=>"Ք","փ"=>"Փ","ւ"=>"Ւ","ց"=>"Ց","ր"=>"Ր","տ"=>"Տ","վ"=>"Վ","ս"=>"Ս",
"ռ"=>"Ռ","ջ"=>"Ջ","պ"=>"Պ","չ"=>"Չ","ո"=>"Ո","շ"=>"Շ","ն"=>"Ն","յ"=>"Յ","մ"=>"Մ","ճ"=>"Ճ",
"ղ"=>"Ղ","ձ"=>"Ձ","հ"=>"Հ","կ"=>"Կ","ծ"=>"Ծ","խ"=>"Խ","լ"=>"Լ","ի"=>"Ի","ժ"=>"Ժ","թ"=>"Թ",
"ը"=>"Ը","է"=>"Է","զ"=>"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"=>"Ď","č"=>"Č","ċ"=>"Ċ","ĉ"=>"Ĉ","ć"=>"Ć","ą"=>"Ą","ă"=>"Ă",
"ā"=>"Ā","ÿ"=>"Ÿ","þ"=>"Þ","ý"=>"Ý","ü"=>"Ü","û"=>"Û","ú"=>"Ú","ù"=>"Ù","ø"=>"Ø","ö"=>"Ö",
"õ"=>"Õ","ô"=>"Ô","ó"=>"Ó","ò"=>"Ò","ñ"=>"Ñ","ð"=>"Ð","ï"=>"Ï","î"=>"Î","í"=>"Í","ì"=>"Ì",
"ë"=>"Ë","ê"=>"Ê","é"=>"É","è"=>"È","ç"=>"Ç","æ"=>"Æ","å"=>"Å","ä"=>"Ä","ã"=>"Ã","â"=>"Â",
"á"=>"Á","à"=>"À","µ"=>"Μ","z"=>"Z","y"=>"Y","x"=>"X","w"=>"W","v"=>"V","u"=>"U","t"=>"T",
"s"=>"S","r"=>"R","q"=>"Q","p"=>"P","o"=>"O","n"=>"N","m"=>"M","l"=>"L","k"=>"K","j"=>"J",
"i"=>"I","h"=>"H","g"=>"G","f"=>"F","e"=>"E","d"=>"D","c"=>"C","b"=>"B","a"=>"A"
);
/**
* UTF-8 Case lookup table
*
* This lookuptable defines the upper case letters to their correspponding
* lower case letter in UTF-8
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
global $UTF8_LOWER_TO_UPPER;
if(empty($UTF8_LOWER_TO_UPPER)) $UTF8_LOWER_TO_UPPER = array(
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"Ι",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"Ἷ",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"","ế"=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"","ṿ"=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"","ḿ"=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
"ֆ"=>"Ֆ","օ"=>"Օ","ք"=>"Ք","փ"=>"Փ","ւ"=>"Ւ","ց"=>"Ց","ր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"Ŀ",
"ľ"=>"Ľ","ļ"=>"Ļ","ĺ"=>"Ĺ","ķ"=>"Ķ","ĵ"=>"Ĵ","ij"=>"IJ","ı"=>"I","į"=>"Į","ĭ"=>"Ĭ","ī"=>"Ī",
"ĩ"=>"Ĩ","ħ"=>"Ħ","ĥ"=>"Ĥ","ģ"=>"Ģ","ġ"=>"Ġ","ğ"=>"Ğ","ĝ"=>"Ĝ","ě"=>"Ě","ę"=>"Ę","ė"=>"Ė",
"ĕ"=>"Ĕ","ē"=>"Ē","đ"=>"Đ","ď"=>"Ď","č"=>"Č","ċ"=>"Ċ","ĉ"=>"Ĉ","ć"=>"Ć","ą"=>"Ą","ă"=>"Ă",
"ā"=>"Ā","ÿ"=>"Ÿ","þ"=>"Þ","ý"=>"Ý","ü"=>"Ü","û"=>"Û","ú"=>"Ú","ù"=>"Ù","ø"=>"Ø","ö"=>"Ö",
"õ"=>"Õ","ô"=>"Ô","ó"=>"Ó","ò"=>"Ò","ñ"=>"Ñ","ð"=>"Ð","ï"=>"Ï","î"=>"Î","í"=>"Í","ì"=>"Ì",
"ë"=>"Ë","ê"=>"Ê","é"=>"É","è"=>"È","ç"=>"Ç","æ"=>"Æ","å"=>"Å","ä"=>"Ä","ã"=>"Ã","â"=>"Â",
"á"=>"Á","à"=>"À","µ"=>"Μ","z"=>"Z","y"=>"Y","x"=>"X","w"=>"W","v"=>"V","u"=>"U","t"=>"T",
"s"=>"S","r"=>"R","q"=>"Q","p"=>"P","o"=>"O","n"=>"N","m"=>"M","l"=>"L","k"=>"K","j"=>"J",
"i"=>"I","h"=>"H","g"=>"G","f"=>"F","e"=>"E","d"=>"D","c"=>"C","b"=>"B","a"=>"A"
);
/**
* UTF-8 Case lookup table
*
* This lookuptable defines the lower case letters to their correspponding
* upper case letter in UTF-8
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
global $UTF8_UPPER_TO_LOWER;
if(empty($UTF8_UPPER_TO_LOWER)) $UTF8_UPPER_TO_LOWER = array (
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"","Ι"=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
"Ἷ"=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"ế",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"ṿ",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"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=>"r","Q"=>"q","P"=>"p","O"=>"o","N"=>"n","M"=>"m","L"=>"l","K"=>"k","J"=>"j",
"I"=>"i","H"=>"h","G"=>"g","F"=>"f","E"=>"e","D"=>"d","C"=>"c","B"=>"b","A"=>"a"
);
/**
* UTF-8 Case lookup table
*
* This lookuptable defines the lower case letters to their correspponding
* upper case letter in UTF-8
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
global $UTF8_UPPER_TO_LOWER;
if(empty($UTF8_UPPER_TO_LOWER)) $UTF8_UPPER_TO_LOWER = array (
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"","Ι"=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
"Ἷ"=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"ế",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"ṿ",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"ḿ",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",""=>"",
"Ֆ"=>"ֆ","Օ"=>"օ","Ք"=>"ք","Փ"=>"փ","Ւ"=>"ւ","Ց"=>"ց","Ր"=>"ր","Տ"=>"տ","Վ"=>"վ","Ս"=>"ս",
"Ռ"=>"ռ","Ջ"=>"ջ","Պ"=>"պ","Չ"=>"չ","Ո"=>"ո","Շ"=>"շ","Ն"=>"ն","Յ"=>"յ","Մ"=>"մ","Ճ"=>"ճ",
"Ղ"=>"ղ","Ձ"=>"ձ","Հ"=>"հ","Կ"=>"կ","Ծ"=>"ծ","Խ"=>"խ","Լ"=>"լ","Ի"=>"ի","Ժ"=>"ժ","Թ"=>"թ",
"Ը"=>"ը","Է"=>"է","Զ"=>"զ","Ե"=>"ե","Դ"=>"դ","Գ"=>"գ","Բ"=>"բ","Ա"=>"ա","Ԏ"=>"ԏ","Ԍ"=>"ԍ",
"Ԋ"=>"ԋ","Ԉ"=>"ԉ","Ԇ"=>"ԇ","Ԅ"=>"ԅ","Ԃ"=>"ԃ","Ԁ"=>"ԁ","Ӹ"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ö",
"Õ"=>"õ","Ô"=>"ô","Ó"=>"ó","Ò"=>"ò","Ñ"=>"ñ","Ð"=>"ð","Ï"=>"ï","Î"=>"î","Í"=>"í","Ì"=>"ì",
"Ë"=>"ë","Ê"=>"ê","É"=>"é","È"=>"è","Ç"=>"ç","Æ"=>"æ","Å"=>"å","Ä"=>"ä","Ã"=>"ã","Â"=>"â",
"Á"=>"á","À"=>"à","Μ"=>"µ","Z"=>"z","Y"=>"y","X"=>"x","W"=>"w","V"=>"v","U"=>"u","T"=>"t",
"S"=>"s","R"=>"r","Q"=>"q","P"=>"p","O"=>"o","N"=>"n","M"=>"m","L"=>"l","K"=>"k","J"=>"j",
"I"=>"i","H"=>"h","G"=>"g","F"=>"f","E"=>"e","D"=>"d","C"=>"c","B"=>"b","A"=>"a"
);
}; // end of case lookup tables
/**
@ -1642,7 +1642,7 @@ if(empty($UTF8_ROMANIZATION)) $UTF8_ROMANIZATION = array(
'่'=>'','้'=>'','๊'=>'','๋'=>'','็'=>'',
'์'=>'','๎'=>'','ํ'=>'','ฺ'=>'',
'ๆ'=>'2','๏'=>'o','ฯ'=>'-','๚'=>'-','๛'=>'-',
''=>'0','๑'=>'1','๒'=>'2','๓'=>'3','๔'=>'4',
''=>'0','๑'=>'1','๒'=>'2','๓'=>'3','๔'=>'4',
'๕'=>'5','๖'=>'6','๗'=>'7','๘'=>'8','๙'=>'9',
// Korean
@ -1654,5 +1654,4 @@ if(empty($UTF8_ROMANIZATION)) $UTF8_ROMANIZATION = array(
'ㅠ'=>'yu','ㅒ'=>'yay','ㅖ'=>'yey',
);
//Setup VIM: ex: et ts=2 enc=utf-8 :

View File

@ -1,8 +1,8 @@
<?php
/**
* Dokuwiki installation assistance
* Dokuwiki installation assistance
*
* @author Chris Smith <chris@jalakai.co.uk>
* @author Chris Smith <chris@jalakai.co.uk>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
@ -286,7 +286,6 @@ EOT;
}
$ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
if ($d['acl']) {
// create users.auth.php
// --- user:MD5password:Real Name:email:groups,comma,seperated
@ -473,7 +472,6 @@ function langsel(){
closedir($dh);
sort($langs);
echo '<form action="">';
echo $lang['i_chooselang'];
echo ': <select name="l" onchange="submit()">';