/** * Create output */ function render($mode, Doku_Renderer &$renderer, $opt) { if ($mode == 'metadata') { return false; } // load file data if ($opt['file']) { if (preg_match('/^https?:\\/\\//i', $opt['file'])) { require_once DOKU_INC . 'inc/HTTPClient.php'; $http = new DokuHTTPClient(); $opt['content'] = $http->get($opt['file']); if ($opt['content'] === false) { $renderer->cdata('Failed to fetch remote CSV data'); return true; } } else { $renderer->info['cache'] = false; 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']); } } // check if there is content $content =& $opt['content']; $content = trim($content); if ($content === '') { $renderer->cdata('No csv data found'); return true; } // Export the csv file $targetfile = ''; $export = $opt['export']; if ($export != '') { $targetfile = htmlspecialchars(trim($export)); if (auth_quickaclcheck(getNS($targetfile . ':*')) < AUTH_EDIT) { $renderer->cdata('Access denied: Could not create download link.'); $targetfile = ''; return true; } else { $file = mediaFN($targetfile); if (file_put_contents($file, $content, LOCK_EX) > 0) { $linkname = $opt['linkname']; if ($linkname == '') { $linkname = 'Download CSV file'; } } else { $targetfile = ''; $renderer->cdata('Failed to write ' . $file . ': Could not create download link.'); return true; } } } // get the first row - it will define the structure $row = $this->csv_explode_row($content, $opt['delim'], $opt['enclosure'], $opt['escape']); $maxcol = count($row); $line = 0; // create the table and start rendering $renderer->table_open($maxcol); while ($row !== false) { // make sure we have enough columns $row = array_pad($row, $maxcol, ''); // render $renderer->tablerow_open(); for ($i = 0; $i < $maxcol;) { $span = 1; // lookahead to find spanning cells if ($opt['span_empty_cols']) { for ($j = $i + 1; $j < $maxcol; $j++) { if ($row[$j] === '') { $span++; } else { break; } } } // open cell if ($line < $opt['hdr_rows'] || $i < $opt['hdr_cols']) { $renderer->tableheader_open($span); } else { $renderer->tablecell_open($span); } // print cell content, call linebreak() for newlines $lines = explode("\n", $row[$i]); $cnt = count($lines); for ($k = 0; $k < $cnt; $k++) { $renderer->cdata($lines[$k]); if ($k < $cnt - 1) { $renderer->linebreak(); } } // close cell if ($line < $opt['hdr_rows'] || $i < $opt['hdr_cols']) { $renderer->tableheader_close(); } else { $renderer->tablecell_close(); } $i += $span; } $renderer->tablerow_close(); // get next row $row = $this->csv_explode_row($content, $opt['delim'], $opt['enclosure'], $opt['escape']); $line++; } $renderer->table_close(); if ($targetfile != '') { $renderer->internalmedia($targetfile, $linkname); } return true; }
/** * Create output */ function render($mode, Doku_Renderer $R, $data) { global $ID; if ($mode == 'xhtml') { $R->info['cache'] &= $data['cache']; $R->doc .= $this->_gallery($data); return true; } elseif ($mode == 'metadata') { $rel = p_get_metadata($ID, 'relation', METADATA_RENDER_USING_CACHE); $img = $rel['firstimage']; if (empty($img)) { $files = $this->_findimages($data); if (count($files)) { $R->internalmedia($files[0]['id']); } } return true; } return false; }
/** * Return formated data, depending on column type * * @param array $column * @param string $value * @param Doku_Renderer $R * @return string */ function _formatDataNew($column, $value, Doku_Renderer $R) { global $conf; $vals = explode("\n", $value); $outs = array(); //multivalued line from db result for pageid and wiki has only in first value the ID $storedID = ''; foreach ($vals as $val) { $val = trim($val); if ($val == '') { continue; } $type = $column['type']; if (is_array($type)) { $type = $type['type']; } switch ($type) { case 'page': $val = $this->_addPrePostFixes($column['type'], $val); $val = $this->ensureAbsoluteId($val); $outs[] = $R->internallink($val, null, null, true); break; case 'title': list($id, $title) = explode('|', $val, 2); $id = $this->_addPrePostFixes($column['type'], $id); $id = $this->ensureAbsoluteId($id); $outs[] = $R->internallink($id, $title, null, true); break; case 'pageid': list($id, $title) = explode('|', $val, 2); //use ID from first value of the multivalued line if ($title == null) { $title = $id; if (!empty($storedID)) { $id = $storedID; } } else { $storedID = $id; } $id = $this->_addPrePostFixes($column['type'], $id); $outs[] = $R->internallink($id, $title, null, true); break; case 'nspage': // no prefix/postfix here $val = ':' . $column['key'] . ":{$val}"; $outs[] = $R->internallink($val, null, null, true); break; case 'mail': list($id, $title) = explode(' ', $val, 2); $id = $this->_addPrePostFixes($column['type'], $id); if (!$title) { $title = $id; } else { $title = hsc($title); } $outs[] = $R->emaillink($id, $title, true); break; case 'url': $val = $this->_addPrePostFixes($column['type'], $val); $outs[] = $R->externallink($val, null, true); break; case 'tag': // per default use keyname as target page, but prefix on aliases if (!is_array($column['type'])) { $target = $column['key'] . ':'; } else { $target = $this->_addPrePostFixes($column['type'], ''); } $params = buildURLparams($this->_getTagUrlparam($column, $val)); $url = str_replace('/', ':', cleanID($target)) . '?' . $params; // FIXME: The title is lost when moving to $R->internallink, // but this syntax is required to support different renderers. // $title = sprintf($this->getLang('tagfilter'), hsc($val)); $outs[] = $R->internallink($url, hsc($val), true); break; case 'timestamp': $outs[] = dformat($val); break; case 'wiki': global $ID; $oldid = $ID; list($ID, $data) = explode('|', $val, 2); //use ID from first value of the multivalued line if ($data == null) { $data = $ID; $ID = $storedID; } else { $storedID = $ID; } $data = $this->_addPrePostFixes($column['type'], $data); // Trim document_{start,end}, p_{open,close} from instructions $allinstructions = p_get_instructions($data); $wraps = 1; if (isset($allinstructions[1]) && $allinstructions[1][0] == 'p_open') { $wraps++; } $instructions = array_slice($allinstructions, $wraps, -$wraps); $outs[] = p_render($R->getFormat(), $instructions, $byref_ignore); $ID = $oldid; break; default: $val = $this->_addPrePostFixes($column['type'], $val); //type '_img' or '_img<width>' if (substr($type, 0, 3) == 'img') { $width = (int) substr($type, 3); if (!$width) { $width = $this->getConf('image_width'); } list($mediaid, $title) = explode('|', $val, 2); if ($title === null) { $title = $column['key'] . ': ' . basename(str_replace(':', '/', $mediaid)); } else { $title = trim($title); } if (media_isexternal($val)) { $html = $R->externalmedia($mediaid, $title, $align = null, $width, $height = null, $cache = null, $linking = 'direct', true); } else { $html = $R->internalmedia($mediaid, $title, $align = null, $width, $height = null, $cache = null, $linking = 'direct', true); } if (strpos($html, 'mediafile') === false) { $html = str_replace('href', 'rel="lightbox" href', $html); } $outs[] = $html; } else { $outs[] = hsc($val); } } } return join(', ', $outs); }