<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -31,7 +31,9 @@
  * the &quot;&quot; around a field, then it should be surrounded by &quot;&quot; as well.
  *
  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
- * @author     Steven Danz (steven-danz@kc.rr.com)
+ * @author     Steven Danz &lt;steven-danz@kc.rr.com&gt;
+ * @author     Gert
+ * @author     Andreas Gohr &lt;gohr@cosmocode.de&gt;
  */
 
 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
@@ -49,12 +51,12 @@ class syntax_plugin_csv extends DokuWiki_Syntax_Plugin {
      */
     function getInfo(){
         return array(
-            'author' =&gt; 'Steven Danz',
-            'email'  =&gt; 'steven-danz@kc.rr.com',
-            'date'   =&gt; '2005-11-08',
+            'author' =&gt; 'Andreas Gohr',
+            'email'  =&gt; 'gohr@cosmocode.de',
+            'date'   =&gt; '2008-04-16',
             'name'   =&gt; 'CSV Plugin',
             'desc'   =&gt; 'Displays a CSV file, or inline CSV data, as a table',
-            'url'    =&gt; 'http://www.dokuwiki.org/plugin:csv',
+            'url'    =&gt; 'http://wiki.splitbrain.org/plugin:csv',
         );
     }
 
@@ -62,7 +64,7 @@ class syntax_plugin_csv extends DokuWiki_Syntax_Plugin {
      * What kind of syntax are we?
      */
     function getType(){
-        return 'container';
+        return 'substition';
     }
 
     /*
@@ -83,173 +85,128 @@ class syntax_plugin_csv extends DokuWiki_Syntax_Plugin {
      * Connect pattern to lexer
      */
     function connectTo($mode) {
-      $this-&gt;Lexer-&gt;addEntryPattern(&quot;&lt;csv[^&gt;]*&gt;(?=.*?\x3C/csv\x3E)&quot;,$mode,'plugin_csv');
+        $this-&gt;Lexer-&gt;addSpecialPattern(&quot;&lt;csv[^&gt;]*&gt;.*?(?:&lt;\/csv&gt;)&quot;,$mode,'plugin_csv');
     }
 
-    function postConnect() {
-      $this-&gt;Lexer-&gt;addExitPattern(&quot;&lt;/csv&gt;&quot;,'plugin_csv');
-    }
 
     /*
      * Handle the matches
      */
     function handle($match, $state, $pos, &amp;$handler){
-        if ($state == DOKU_LEXER_ENTER) {
-            // default values for options
-            $hdr_rows  = 1;
-            $span_cols = 0;
-            $file      = '';
-
-            /* process possible options */
-            $match = trim(substr($match, 4, -1));
-            $data = preg_split(&quot;/\s/&quot;,$match,-1);
-            while (count($data) &gt; 0) {
-                $entry = array_shift($data);
-                if (preg_match(&quot;/^hdr_rows=([0-9]*)/&quot;,$entry,$matches)) {
-                    $hdr_rows = $matches[1];
-                } elseif (preg_match(&quot;/^span_empty_cols=([0-9]*)/&quot;,$entry,$matches)) {
-                    $span_cols = $matches[1];
-                } else {
-                    $file = $entry;
-                }
-            }
+        $match = substr($match,4,-6);
+
+        //default options
+        $opt = array(
+            'hdr'     =&gt; 1,
+            'colspan' =&gt; 0,
+            'file'    =&gt; '',
+            'delim'   =&gt; ',',
+            'content' =&gt; ''
+        );
 
-            if ($file != '') {
-                return array('file', $file, $hdr_rows, $span_cols);
+        list($optstr,$opt['content']) = explode('&gt;',$match,2);
+        unset($match);
+
+        // parse options
+        $optsin = explode(' ',$optstr);
+        foreach($optsin as $o){
+            $o = trim($o);
+            if (preg_match(&quot;/^hdr_rows=([0-9]+)/&quot;,$o,$matches)) {
+                $opt['hdr'] = $matches[1];
+            } elseif (preg_match(&quot;/^span_empty_cols=([0-9]+)/&quot;,$o,$matches)) {
+                $opt['hdr'] = $matches[1];
+            } elseif (preg_match(&quot;/^delim=(.+)/&quot;,$o,$matches)) {
+                $opt['delim'] = $matches[1];
+                if($opt['delim'] == 'tab') $opt['delim'] = &quot;\t&quot;;
             } else {
-                return array('options', $hdr_rows, $span_cols);
-            }
-        } elseif ($state == DOKU_LEXER_UNMATCHED) {
-            // clear out all the spaces, if anything is left, use it
-            $clean = preg_replace('/\s/', '', $match);
-            if ($clean != '') {
-                return array('inline', $match);
+                $opt['file'] = cleanID($o);
             }
         }
-        return array();
+
+        return $opt;
     }
 
     /*
      * Create output
      */
-    function render($mode, &amp;$renderer, $data) {
-        global $csv_hdr_rows;   // global since the lexer_enter sets these in one match,
-        global $csv_span_cols;  // then uses them in for the data (for inline data)
-
-        if($mode == 'xhtml'){
-            if (!isset($csv_hdr_rows)) $csv_hdr_rows = 1;
-            if (count($data) &gt; 0) {
-                $type = array_shift($data);
-                $process = 1;
-                if ($type == 'file') {
-                    // prevent caching to ensure the included data is always fresh
-                    // and so we don't cache any errors that might be generated
-                    // from permission problems
-                    $renderer-&gt;info['cache'] = FALSE;
+    function render($mode, &amp;$renderer, $opt) {
+        if($mode == 'metadata') return false;
+
+        // load file data
+        if($opt['file']){
+            $renderer-&gt;info['cache'] = false; //no caching
+            if (auth_quickaclcheck(getNS($opt['file']).':*') &lt; AUTH_READ) {
+                $renderer-&gt;cdata('Access denied to CSV data');
+                return true;
+            } else {
+                $file = mediaFN($opt['file']);
+                $opt['content'] = io_readFile($file);
+            }
+        }
 
-                    $file = $data[0];
-                    if (auth_quickaclcheck(getNS($file).':*') &lt; AUTH_READ) {
-                        $auth = 0;
-                        $content = &quot;&quot;;
-                    } else {
-                        $auth = 1;
-                        $file = mediaFN($file);
-                        $csv_hdr_rows = $data[1];
-                        $csv_span_cols = $data[2];
-                        if(@file_exists($file)) {
-                            // grab the entire file as a string
-                            $content = file_get_contents($file);
-                        }
-                    }
-                } elseif ($type == 'options') {
-                    $csv_hdr_rows = $data[0];
-                    $csv_span_cols = $data[1];
-                    $process = 0;
-                } elseif ($type == 'inline') {
-                    $content = $data[0];
-                } else {
-                    $renderer-&gt;doc .= &quot;Not sure what this is about &quot; . $type ;
-                    $process = 0;
-                }
+        $content =&amp; $opt['content'];
 
-                if ($process) {
-                    // clean up the input data
-                    // clear any trailing or leading empty lines from the data set
-                    $content = preg_replace(&quot;/[\r\n]*$/&quot;,&quot;&quot;,$content);
-                    $content = preg_replace(&quot;/^\s*[\r\n]*/&quot;,&quot;&quot;,$content);
+        // clear any trailing or leading empty lines from the data set
+        $content = preg_replace(&quot;/[\r\n]*$/&quot;,&quot;&quot;,$content);
+        $content = preg_replace(&quot;/^\s*[\r\n]*/&quot;,&quot;&quot;,$content);
 
-                    // Not sure if PHP handles the DOS \r\n or Mac \r, so being paranoid
-                    // and converting them if the exist to \n
-                    $content = preg_replace(&quot;/\r\n/&quot;,&quot;\n&quot;,$content);
-                    $content = preg_replace(&quot;/\r/&quot;,&quot;\n&quot;,$content);
+        if(!trim($content)){
+            $renderer-&gt;cdata('No csv data found');
+        }
 
-                    if ($content != &quot;&quot;) {
-                        $renderer-&gt;table_open();
-                        $row = 1;
-                        while($content != &quot;&quot;) {
-                            $renderer-&gt;tablerow_open();
-                            $cells = $this-&gt;csv_explode_row($content);
-                            // some spreadsheet systems (i.e., excell) appear to
-                            // denote column spans with a completely empty cell
-                            // (to adjacent commas) and an 'empty' cell will
-                            // contain at least one blank space, so if the user
-                            // asks, use that for attempting to span columns
-                            // together
-                            $spans = array();
-                            $span  = 0;
-                            $current = 0;
-                            foreach($cells as $cell) {
-                                if ($cell == '' &amp;&amp; $csv_span_cols) {
-                                    $spans[$current] = 0;
-                                    $spans[$span]++;
-                                } else {
-                                    $spans[$current] = 1;
-                                    $span = $current;
-                                }
-                                $current++;
-                            }
-                            $current = 0;
-                            foreach($cells as $cell) {
-                                $cell = preg_replace('/\\\\\\\\/','&lt;br&gt;',$cell);
-                                if ($spans[$current] &gt; 0) {
-                                    $align = 'left';
-                                    if ($spans[$current] &gt; 1) {
-                                        $align = 'center';
-                                    }
-                                    if ($row &lt;= $csv_hdr_rows) {
-                                        $renderer-&gt;tableheader_open($spans[$current], $align);
-                                    } else {
-                                        $renderer-&gt;tablecell_open($spans[$current], $align);
-                                    }
-                                    $renderer-&gt;doc .= $cell;
-                                    if ($row &lt;= $csv_hdr_rows) {
-                                        $renderer-&gt;tableheader_close();
-                                    } else {
-                                        $renderer-&gt;tablecell_close();
-                                    }
-                                }
-                                $current++;
-                            }
-                            $renderer-&gt;tablerow_close();
-                            $row++;
-                        }
-                        $renderer-&gt;table_close();
+        // render table
+        $renderer-&gt;table_open();
+        $row = 1;
+        while($content != &quot;&quot;) {
+            $renderer-&gt;tablerow_open();
+            $cells = $this-&gt;csv_explode_row($content,$opt['delim']);
+            // some spreadsheet systems (i.e., excell) appear to
+            // denote column spans with a completely empty cell
+            // (to adjacent commas) and an 'empty' cell will
+            // contain at least one blank space, so if the user
+            // asks, use that for attempting to span columns
+            // together
+            $spans = array();
+            $span  = 0;
+            $current = 0;
+            foreach($cells as $cell) {
+                if ($cell == '' &amp;&amp; $opt['colspan']) {
+                    $spans[$current] = 0;
+                    $spans[$span]++;
+                } else {
+                    $spans[$current] = 1;
+                    $span = $current;
+                }
+                $current++;
+            }
+            $current = 0;
+            foreach($cells as $cell) {
+                $cell = preg_replace('/\\\\\\\\/',' ',$cell);
+                if ($spans[$current] &gt; 0) {
+                    $align = 'left';
+                    if ($spans[$current] &gt; 1) {
+                        $align = 'center';
+                    }
+                    if ($row &lt;= $opt['hdr']) {
+                        $renderer-&gt;tableheader_open($spans[$current], $align);
+                    } else {
+                        $renderer-&gt;tablecell_open($spans[$current], $align);
+                    }
+                    $renderer-&gt;cdata($cell);
+                    if ($row &lt;= $opt['hdr']) {
+                        $renderer-&gt;tableheader_close();
                     } else {
-                        if ($type == 'file') {
-                            if ($auth == 0) {
-                                $renderer-&gt;doc .= &quot;You do not have authorization to read &quot; . $data[0];
-                            } elseif(@file_exists($file)) {
-                                $renderer-&gt;doc .= &quot;Data file from &quot; . $data[0] . &quot; is empty&quot;;
-                            } else {
-                                $renderer-&gt;doc .= &quot;Could not locate &quot; . $data[0];
-                            }
-                        }
+                        $renderer-&gt;tablecell_close();
                     }
                 }
-                return true;
+                $current++;
             }
+            $renderer-&gt;tablerow_close();
+            $row++;
         }
-        return false;
+        $renderer-&gt;table_close();
+
+        return true;
     }
 
     // Explode CSV string, consuming it as we go</diff>
      <filename>syntax.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>3b762773affc01a16ec679e0ad2ecda86d27805f</id>
    </parent>
  </parents>
  <author>
    <name>Andreas Gohr</name>
    <login>cosmocode</login>
    <email>gohr@cosmocode.de</email>
  </author>
  <url>http://github.com/cosmocode/csv/commit/4b0a863ed892ae8c14189be65d12f8484d8107ba</url>
  <id>4b0a863ed892ae8c14189be65d12f8484d8107ba</id>
  <committed-date>2009-05-15T02:13:32-07:00</committed-date>
  <authored-date>2009-05-15T02:13:32-07:00</authored-date>
  <message>major updates

This patch fixes the XSS security problem, incorporates changes by 'Gert'
and features an extended syntax (with rewritten config parsing)</message>
  <tree>0be5b62cc12500fd82dfdd3b8e40356cb16db9eb</tree>
  <committer>
    <name>Andreas Gohr</name>
    <login>splitbrain</login>
    <email>andi@splitbrain.org</email>
  </committer>
</commit>
