Skip to content

Commit

Permalink
Added support for external CSV files shared via HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Nov 3, 2009
1 parent f0c6cc4 commit c81a5ec
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions syntax.php
Expand Up @@ -26,7 +26,7 @@ function getInfo(){
return array( return array(
'author' => 'Andreas Gohr', 'author' => 'Andreas Gohr',
'email' => 'gohr@cosmocode.de', 'email' => 'gohr@cosmocode.de',
'date' => '2009-08-31', 'date' => '2009-11-14',
'name' => 'CSV Plugin', 'name' => 'CSV Plugin',
'desc' => 'Displays a CSV file, or inline CSV data, as a table', 'desc' => 'Displays a CSV file, or inline CSV data, as a table',
'url' => 'http://www.dokuwiki.org/plugin:csv', 'url' => 'http://www.dokuwiki.org/plugin:csv',
Expand Down Expand Up @@ -86,26 +86,16 @@ function handle($match, $state, $pos, &$handler){
$optsin = explode(' ',$optstr); $optsin = explode(' ',$optstr);
foreach($optsin as $o){ foreach($optsin as $o){
$o = trim($o); $o = trim($o);
/*
if (preg_match("/^hdr_rows=([0-9]+)/",$o,$matches)) {
$opt['hdr'] = $matches[1];
} elseif ($o == 'span_empty_cols=1') {
$opt['colspan'] = 1;
} elseif (preg_match("/^delim=(.+)/",$o,$matches)) {
$opt['delim'] = $matches[1];
if($opt['delim'] == 'tab') $opt['delim'] = "\t";
} else {
$opt['file'] = cleanID($o);
if(!strlen(getNS($opt['file'])))
$opt['file'] = $INFO['namespace'].':'.$opt['file'];
}
*/
if (preg_match("/(\w+)=(.*)/",$o,$matches)) { if (preg_match("/(\w+)=(.*)/",$o,$matches)) {
$opt[$matches[1]] = $matches[2]; $opt[$matches[1]] = $matches[2];
} else { } else {
$opt['file'] = cleanID($o); if(preg_match('/^https?:\/\//i',$o)){
if(!strlen(getNS($opt['file']))) $opt['file'] = $o;
$opt['file'] = $INFO['namespace'].':'.$opt['file']; }else{
$opt['file'] = cleanID($o);
if(!strlen(getNS($opt['file'])))
$opt['file'] = $INFO['namespace'].':'.$opt['file'];
}
} }
} }
if($opt['delim'] == 'tab') $opt['delim'] = "\t"; if($opt['delim'] == 'tab') $opt['delim'] = "\t";
Expand All @@ -121,15 +111,25 @@ function render($mode, &$renderer, $opt) {


// load file data // load file data
if($opt['file']){ if($opt['file']){
$renderer->info['cache'] = false; //no caching if(preg_match('/^https?:\/\//i',$opt['file'])){
if (auth_quickaclcheck(getNS($opt['file']).':*') < AUTH_READ) { require_once(DOKU_INC.'inc/HTTPClient.php');
$renderer->cdata('Access denied to CSV data'); $http = new DokuHTTPClient();
return true; $opt['content'] = $http->get($opt['file']);
} else { if(!$opt['content']){
$file = mediaFN($opt['file']); $renderer->cdata('Failed to fetch remote CSV data');
$opt['content'] = io_readFile($file); return true;
// if not valid UTF-8 is given we assume ISO-8859-1 }
if(!utf8_check($opt['content'])) $opt['content'] = utf8_encode($opt['content']); }else{
$renderer->info['cache'] = false; //no caching
if (auth_quickaclcheck(getNS($opt['file']).':*') < AUTH_READ) {
$renderer->cdata('Access denied to CSV data');
return true;
} else {
$file = mediaFN($opt['file']);
$opt['content'] = io_readFile($file);
// if not valid UTF-8 is given we assume ISO-8859-1
if(!utf8_check($opt['content'])) $opt['content'] = utf8_encode($opt['content']);
}
} }
} }


Expand Down

0 comments on commit c81a5ec

Please sign in to comment.