tabs -> spaces

This commit is contained in:
Gina Haeussge
2009-03-08 15:57:06 +01:00
parent a69ad0ee57
commit de99b7c740

View File

@@ -7,7 +7,7 @@
*/
if(!defined('DOKU_INC'))
define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
@@ -23,13 +23,13 @@ define('DOKU_PLUGIN_FILELIST_OUTSIDEJAIL', -2);
*/
class syntax_plugin_filelist extends DokuWiki_Syntax_Plugin {
var $mediadir;
function syntax_plugin_filelist() {
global $conf;
$this->mediadir = rp(DOKU_INC.'/'.$conf['savedir'].'/media').'/';
}
var $mediadir;
function syntax_plugin_filelist() {
global $conf;
$this->mediadir = rp(DOKU_INC.'/'.$conf['savedir'].'/media').'/';
}
/**
* return some info
@@ -44,55 +44,55 @@ class syntax_plugin_filelist extends DokuWiki_Syntax_Plugin {
'url' => 'http://wiki.foosel.net/snippets/dokuwiki/filelist',
);
}
function getType(){ return 'substition'; }
function getPType(){ return 'block'; }
function getSort(){ return 222; }
function connectTo($mode) {
$this->Lexer->addSpecialPattern('\{\{filename>.+?\}\}',$mode,'plugin_filelist');
$this->Lexer->addSpecialPattern('\{\{filelist>.+?\}\}',$mode,'plugin_filelist');
$this->Lexer->addSpecialPattern('\{\{filename>.+?\}\}',$mode,'plugin_filelist');
$this->Lexer->addSpecialPattern('\{\{filelist>.+?\}\}',$mode,'plugin_filelist');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler) {
// do not allow the syntax in comments
if (!$this->getConf('allow_in_comments') && isset($_REQUEST['comment']))
return false;
return false;
$match = substr($match, 2, -2);
list($type, $match) = split('>', $match, 2);
list($pattern, $flags) = split('&', $match, 2);
if ($type == 'filename') {
if (strpos($flags, '|') !== FALSE) {
list($flags, $title) = split('\|', $flags);
} else {
$title = '';
}
if (strpos($flags, '|') !== FALSE) {
list($flags, $title) = split('\|', $flags);
} else {
$title = '';
}
}
$flags = split('&', $flags);
$params = array(
'sort' => 'name',
'order' => 'asc',
'index' => 0,
'limit' => 0,
'offset' => 0,
'style' => 'list',
'tableheader' => 0,
'tableshowsize' => 0,
'tableshowdate' => 0,
'direct' => 0,
'sort' => 'name',
'order' => 'asc',
'index' => 0,
'limit' => 0,
'offset' => 0,
'style' => 'list',
'tableheader' => 0,
'tableshowsize' => 0,
'tableshowdate' => 0,
'direct' => 0,
);
foreach($flags as $flag) {
list($name, $value) = split('=', $flag);
$params[trim($name)] = trim($value);
}
return array($type, $pattern, $params, $title);
}
@@ -101,17 +101,17 @@ class syntax_plugin_filelist extends DokuWiki_Syntax_Plugin {
*/
function render($mode, &$renderer, $data) {
global $conf;
$renderer->info['cache'] = false;
list($type, $pattern, $params, $title) = $data;
$files = $this->_create_filelist($pattern, $params);
if ($files == DOKU_PLUGIN_FILELIST_NOMATCH) {
$renderer->doc .= '[n/a: ' . $this->getLang('error_nomatch') . ']';
return true;
$renderer->doc .= '[n/a: ' . $this->getLang('error_nomatch') . ']';
return true;
} else if ($files == DOKU_PLUGIN_FILELIST_OUTSIDEJAIL) {
$renderer->doc .= '[n/a: ' . $this->getLang('error_outsidejail') . ']';
return true;
$renderer->doc .= '[n/a: ' . $this->getLang('error_outsidejail') . ']';
return true;
}
// if limit is set for a filelist, cut out the relevant slice from the files
@@ -121,110 +121,110 @@ class syntax_plugin_filelist extends DokuWiki_Syntax_Plugin {
$files['ctimes'] = array_slice($files['ctimes'], $params['offset'], $params['limit']);
$files['sizes'] = array_slice($files['sizes'], $params['offset'], $params['limit']);
}
if ($mode == 'xhtml') {
switch ($type) {
case 'filename':
$filename = $files['names'][$params['index']];
if ($title == '') {
$title = basename($filename);
}
$this->_create_link($filename, $files['basedir'], $files['webdir'], $params, $renderer);
return true;
case 'filelist':
if (count($files['names']) == 0)
break;
$renderer->doc .= '<div class="filelist-plugin">'.DOKU_LF;
switch ($params['style']) {
case 'list':
$renderer->listu_open();
foreach ($files['names'] as $filename) {
$renderer->listitem_open(1);
$this->_create_link($filename, $files['basedir'], $files['webdir'], $params, $renderer);
$renderer->listitem_close();
}
$renderer->listu_close();
break;
case 'olist':
$renderer->listo_open();
foreach ($files['names'] as $filename) {
$renderer->listitem_open(1);
$this->_create_link($filename, $files['basedir'], $files['webdir'], $params, $renderer);
$renderer->listitem_close();
}
$renderer->listo_close();
break;
case 'table':
$renderer->table_open();
if ($params['tableheader']) {
$renderer->tableheader_open();
$renderer->doc .= $this->getLang('filename');
$renderer->tableheader_close();
case 'filename':
$filename = $files['names'][$params['index']];
if ($title == '') {
$title = basename($filename);
}
if ($params['tableshowsize']) {
$renderer->tableheader_open();
$renderer->doc .= $this->getLang('filesize');
$renderer->tableheader_close();
}
$this->_create_link($filename, $files['basedir'], $files['webdir'], $params, $renderer);
return true;
case 'filelist':
if (count($files['names']) == 0)
break;
$renderer->doc .= '<div class="filelist-plugin">'.DOKU_LF;
switch ($params['style']) {
case 'list':
$renderer->listu_open();
foreach ($files['names'] as $filename) {
$renderer->listitem_open(1);
$this->_create_link($filename, $files['basedir'], $files['webdir'], $params, $renderer);
$renderer->listitem_close();
}
$renderer->listu_close();
break;
case 'olist':
$renderer->listo_open();
foreach ($files['names'] as $filename) {
$renderer->listitem_open(1);
$this->_create_link($filename, $files['basedir'], $files['webdir'], $params, $renderer);
$renderer->listitem_close();
}
$renderer->listo_close();
break;
case 'table':
$renderer->table_open();
if ($params['tableheader']) {
$renderer->tableheader_open();
$renderer->doc .= $this->getLang('filename');
$renderer->tableheader_close();
if ($params['tableshowsize']) {
$renderer->tableheader_open();
$renderer->doc .= $this->getLang('filesize');
$renderer->tableheader_close();
}
if ($params['tableshowdate']) {
$renderer->tableheader_open();
$renderer->doc .= $this->getLang('lastmodified');
$renderer->tableheader_close();
}
}
for ($i = 0; $i < count($files['names']); $i++) {
$filename = $files['names'][$i];
$filemtime = $files['mtimes'][$i];
$filectime = $files['ctimes'][$i];
$filesize = $files['sizes'][$i];
$renderer->tablerow_open();
$renderer->tablecell_open();
$this->_create_link($filename, $files['basedir'], $files['webdir'], $params, $renderer);
$renderer->tablecell_close();
if ($params['tableshowsize']) {
$renderer->tablecell_open(1, 'right');
$renderer->doc .= $filesize;
$renderer->tablecell_close();
}
if ($params['tableshowdate']) {
$renderer->tablecell_open();
$renderer->doc .= strftime($conf['dformat'], $filemtime);
$renderer->tablecell_close();
}
$renderer->tablerow_close();
}
$renderer->table_close();
break;
}
$renderer->doc .= '</div>'.DOKU_LF;
return true;
if ($params['tableshowdate']) {
$renderer->tableheader_open();
$renderer->doc .= $this->getLang('lastmodified');
$renderer->tableheader_close();
}
}
for ($i = 0; $i < count($files['names']); $i++) {
$filename = $files['names'][$i];
$filemtime = $files['mtimes'][$i];
$filectime = $files['ctimes'][$i];
$filesize = $files['sizes'][$i];
$renderer->tablerow_open();
$renderer->tablecell_open();
$this->_create_link($filename, $files['basedir'], $files['webdir'], $params, $renderer);
$renderer->tablecell_close();
if ($params['tableshowsize']) {
$renderer->tablecell_open(1, 'right');
$renderer->doc .= $filesize;
$renderer->tablecell_close();
}
if ($params['tableshowdate']) {
$renderer->tablecell_open();
$renderer->doc .= strftime($conf['dformat'], $filemtime);
$renderer->tablecell_close();
}
$renderer->tablerow_close();
}
$renderer->table_close();
break;
}
$renderer->doc .= '</div>'.DOKU_LF;
return true;
}
}
return false;
}
/**
* Creates the downloadlink for the given filename, based on the given
* Creates the downloadlink for the given filename, based on the given
* parameters, and adds it to the output of the renderer.
*/
function _create_link($filename, $basedir, $webdir, $params, &$renderer) {
global $conf;
global $conf;
//prepare for formating
$link['target'] = $conf['target']['extern'];
$link['style'] = '';
@@ -232,105 +232,105 @@ class syntax_plugin_filelist extends DokuWiki_Syntax_Plugin {
$link['suf'] = '';
$link['more'] = '';
$link['class'] = 'media';
if (!$params['direct']) {
$link['url'] = ml(':'.str_replace('/', ':', substr($filename, strlen($this->mediadir))));
} else {
$link['url'] = $webdir.substr($filename, strlen($basedir));
}
if (!$params['direct']) {
$link['url'] = ml(':'.str_replace('/', ':', substr($filename, strlen($this->mediadir))));
} else {
$link['url'] = $webdir.substr($filename, strlen($basedir));
}
$link['name'] = basename($filename);
$link['title'] = $renderer->_xmlEntities($link['url']);
if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
list($ext,$mime) = mimetype(basename($filename));
$link['class'] .= ' mediafile mf_'.$ext;
//output formatted
$renderer->doc .= $renderer->_formatLink($link);
}
/**
* Creates the filelist based on the given glob-pattern and
* sorting and ordering parameters.
*/
function _create_filelist($pattern, $params) {
global $conf;
global $ID;
// we don't want to use $conf['media'] here as that path has symlinks resolved
global $conf;
global $ID;
// we don't want to use $conf['media'] here as that path has symlinks resolved
$files = array(
'names' => array(),
'mtimes' => array(),
'ctimes' => array(),
'sizes' => array(),
'basedir' => false,
'webdir' => false,
'names' => array(),
'mtimes' => array(),
'ctimes' => array(),
'sizes' => array(),
'basedir' => false,
'webdir' => false,
);
if (!$params['direct']) {
// if media path is not absolute, precede it with the current namespace
if (substr($pattern, 0, 1) != ':')
$pattern = ':'.getNS($ID) . ':' . $pattern;
// replace : with / and prepend mediadir
$pattern = $this->mediadir . str_replace(':', '/', $pattern);
// if media path is not absolute, precede it with the current namespace
if (substr($pattern, 0, 1) != ':')
$pattern = ':'.getNS($ID) . ':' . $pattern;
// replace : with / and prepend mediadir
$pattern = $this->mediadir . str_replace(':', '/', $pattern);
} else {
// if path is not absolute, precede it with DOKU_INC
if (substr($pattern, 0, 1) != '/')
$pattern = DOKU_INC.$pattern;
// if path is not absolute, precede it with DOKU_INC
if (substr($pattern, 0, 1) != '/')
$pattern = DOKU_INC.$pattern;
}
// get the canonicalized basedir (without resolving symlinks)
$dir = rp(dirname($pattern)).'/';
// if the directory is non existant, we of course have no matches
// if the directory is non existant, we of course have no matches
if (!$dir || !file_exists($dir))
return DOKU_PLUGIN_FILELIST_NOMATCH;
return DOKU_PLUGIN_FILELIST_NOMATCH;
$allowed_absolute_paths = split(',', $this->getConf('allowed_absolute_paths'));
$web_paths = split(',', $this->getConf('web_paths'));
$basedir = false;
$webdir = false;
if (count($allowed_absolute_paths) == count($web_paths)) {
for($i = 0; $i < count($allowed_absolute_paths); $i++) {
if (strstr($dir, trim($allowed_absolute_paths[$i])) == $dir) {
$basedir = trim($allowed_absolute_paths[$i]);
$webdir = trim($web_paths[$i]);
break;
}
}
for($i = 0; $i < count($allowed_absolute_paths); $i++) {
if (strstr($dir, trim($allowed_absolute_paths[$i]) == $dir) {
$basedir = trim($allowed_absolute_paths[$i]);
$webdir = trim($web_paths[$i]);
break;
}
}
}
// $basedir is false if $dir was not in one of the allowed paths
if ($basedir === false)
return DOKU_PLUGIN_FILELIST_OUTSIDEJAIL;
return DOKU_PLUGIN_FILELIST_OUTSIDEJAIL;
// glob away
$filenames = @safe_glob($pattern);
if (!$filenames)
return DOKU_PLUGIN_FILELIST_NOMATCH;
if (!$filenames)
return DOKU_PLUGIN_FILELIST_NOMATCH;
// retrieve fileinformation and filter out directories
$files['basedir'] = $basedir;
$files['webdir'] = $webdir;
// retrieve fileinformation and filter out directories
$files['basedir'] = $basedir;
$files['webdir'] = $webdir;
foreach ($filenames as $filename) {
if ($filename[0]=='.') continue; // exclude hidden files
if ($filename[0]=='.') continue; // exclude hidden files
$filename = $dir.$filename;
if (is_dir($filename)) continue; // exclude directories
if (!$params['direct']) { // exclude prohibited media files via ACLs
$mid = str_replace('/', ':', substr($filename, strlen($this->mediadir)));
$perm = auth_quickaclcheck($mid);
if ($perm < AUTH_READ) continue;
$mid = str_replace('/', ':', substr($filename, strlen($this->mediadir)));
$perm = auth_quickaclcheck($mid);
if ($perm < AUTH_READ) continue;
} else { // exclude not readable files
if (!is_readable($filename)) continue;
if (!is_readable($filename)) continue;
}
array_push($files['names'], $filename);
array_push($files['mtimes'], filemtime($filename));
array_push($files['ctimes'], filectime($filename));
array_push($files['sizes'], filesize($filename));
}
$reverseflag = false;
$reverseflag = false;
if ($params['sort'] == 'mtime') {
array_multisort($files['mtimes'], $files['names'], $files['ctimes'], $files['sizes']);
if ($params['order'] == 'asc') $reverseflag = true;
@@ -344,21 +344,19 @@ class syntax_plugin_filelist extends DokuWiki_Syntax_Plugin {
array_multisort($files['names'], $files['ctimes'], $files['mtimes'], $files['sizes']);
if ($params['order'] == 'desc') $reverseflag = true;
}
if ($reverseflag) {
$files['names'] = array_reverse($files['names']);
$files['ctimes'] = array_reverse($files['ctimes']);
$files['mtimes'] = array_reverse($files['mtimes']);
$files['sizes'] = array_reverse($files['sizes']);
$files['names'] = array_reverse($files['names']);
$files['ctimes'] = array_reverse($files['ctimes']);
$files['mtimes'] = array_reverse($files['mtimes']);
$files['sizes'] = array_reverse($files['sizes']);
}
if (count($files['names']) > 0)
return $files;
return $files;
else
return DOKU_PLUGIN_FILELIST_NOMATCH;
return DOKU_PLUGIN_FILELIST_NOMATCH;
}
}
/**
@@ -386,12 +384,12 @@ function safe_glob($pattern, $flags=0) {
return $glob;
} else {
return false;
}
}
}
/**
* Replacement for fnmatch() for windows systems.
*
*
* @author jk at ricochetsolutions dot com
* @see <http://www.php.net/manual/en/function.fnmatch.php#71725>
*/
@@ -403,7 +401,7 @@ if(!function_exists('fnmatch')) {
/**
* Canonicalizes a given path. A bit like realpath, but without the resolving of symlinks.
*
*
* @author anonymous
* @see <http://www.php.net/manual/en/function.realpath.php#73563>
*/