Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for odt export in datatable and datalist #169

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
180 changes: 176 additions & 4 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,37 @@ public function ensureAbsoluteId($id) {
return $id;
}

/**
* Return formated data, depending on column type and DokuWiki version
*
* @param array $column
* @param string $value
* @param Doku_Renderer $R
* @return string
*/
function _formatData($column, $value, Doku_Renderer $R)
{
$dwVersion = getVersionData();
if(isset($dwVersion['date']))
{
preg_match('/(\d+)-(\d+)-(\d+)/',$dwVersion['date'],$dwDate);
if(mktime(0, 0, 0, $dwDate[2], $dwDate[3], $dwDate[1]) > mktime(0, 0, 0, 07, 19, 2015))
{
return $this->_formatDataNew($column, $value, $R);
}
}
return $this->_formatDataOld($column, $value, $R);
}

/**
* Return XHTML formated data, depending on column type
*
* @param array $column
* @param string $value
* @param Doku_Renderer_xhtml $R
* @param array $column
* @param string $value
* @param Doku_Renderer $R
* @return string
*/
function _formatData($column, $value, Doku_Renderer_xhtml $R) {
function _formatDataOld($column, $value, Doku_Renderer $R) {
global $conf;
$vals = explode("\n", $value);
$outs = array();
Expand Down Expand Up @@ -363,6 +385,156 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R) {
return join(', ', $outs);
}

/**
* 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _formatDataOld() has some rawurlencoding applied, which is applied to the content of the title attribute as well. For the title attribute this encoding is not required.
My proposal is to improve the unittest and to modify the behavior in the _formatDataOld() such that it matches the new behavior.

The old code reuses the encoded $id:

if($conf['mailguard'] == 'visible') {
    $id = rawurlencode($id);
}
$outs[] = '<a href="mailto:' . $id . '" class="mail" title="' . $id . '">' . $title . '</a>';

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich kehre zur�ck am 10.08.2015.

Ich werde Ihre Nachricht nach meiner R�ckkehr beantworten. Herzlichen Dank
f�r ihr Verst�ndnis.

I will answer your message after returning.

Hinweis: Dies ist eine automatische Antwort auf Ihre Nachricht "Re:
[dokuwiki-plugin-data] Support for odt export in datatable and datalist
(#169)" gesendet am 30.07.2015 22:50:48.

Diese ist die einzige Benachrichtigung, die Sie empfangen werden, w�hrend
diese Person abwesend ist.

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);
}

/**
* Split a column name into its parts
*
Expand Down
149 changes: 119 additions & 30 deletions syntax/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,121 @@ function connectTo($mode) {
$this->Lexer->addSpecialPattern('----+ *datalist(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+', $mode, 'plugin_data_list');
}

protected $before_item = '<li><div class="li">';
protected $after_item = '</div></li>';
protected $before_val = '';
protected $after_val = ' ';
/**
* Before item in list
*
* @param Doku_Renderer $R
*/
protected function before_item(Doku_Renderer $R)
{
switch($R->getFormat())
{
case 'xhtml':
$R->doc .= '<li><div class="li">';
break;
case 'odt':
$R->listitem_open();
$R->listcontent_open();
break;
}
}

/**
* After item in list
*
* @param Doku_Renderer $R
*/
protected function after_item(Doku_Renderer $R)
{
switch($R->getFormat())
{
case 'xhtml':
$R->doc .= '</div></li>';
break;
case 'odt':
$R->listcontent_close();
$R->listitem_close();
break;
}
}

/**
* Before value in listitem
*
* @param array $data instructions by handler
* @param int $colno column number
* @return string
* @param string $class The CSS class
* @param Doku_Renderer $R
*/
protected function beforeVal(&$data, $colno) {
protected function before_val($class, Doku_Renderer $R)
{
return;
}

/**
* After value in listitem
*
* @param Doku_Renderer $R
*/
protected function after_val(Doku_Renderer $R)
{
switch($R->getFormat())
{
case 'xhtml':
$R->doc .= ' ';
break;
case 'odt':
$R->doc .= ' ';
break;
}
}

/**
* Before value in listitem
*
* @param array $data instructions by handler
* @param int $colno column number
* @param string $class the xhtml class
* @param Doku_Renderer $R the current DokuWiki renderer
*/
protected function beforeVal(&$data, $colno, $class, Doku_Renderer $R) {
if($data['sepbyheaders'] AND $colno === 0) {
return $data['headers'][$colno];
$R->doc .= $data['headers'][$colno];
} else {
return $this->before_val;
$this->before_val($class, $R);
}
}

/**
* After value in listitem
*
* @param array $data
* @param int $colno
* @return string
* @param array $data
* @param int $colno
* @param Doku_Renderer $R
*/
protected function afterVal(&$data, $colno) {
protected function afterVal(&$data, $colno, Doku_Renderer $R) {
if($data['sepbyheaders']) {
return $data['headers'][$colno + 1];
$R->doc .= $data['headers'][$colno + 1];
} else {
return $this->after_val;
$this->after_val($R);
}
}

/**
* Create list header
*
* @param array $clist keys of the columns
* @param array $data instruction by handler
* @return string html of table header
* @param array $clist keys of the columns
* @param array $data instruction by handler
* @param Doku_Renderer $R the current DokuWiki renderer
*/
function preList($clist, $data) {
return '<div class="dataaggregation"><ul class="dataplugin_list ' . $data['classes'] . '">';
function preList($clist, $data, Doku_Renderer $R) {
switch($R->getFormat())
{
case 'xhtml':
$R->doc .= '<div class="dataaggregation"><ul class="dataplugin_list ' . $data['classes'] . '">';
break;
case 'odt':
$R->listu_open();
break;
}
}

/**
Expand All @@ -73,21 +144,39 @@ function preList($clist, $data) {
* @param array $clist keys of the columns
* @param Doku_Renderer $R
*/
function nullList($data, $clist, $R) {
$R->doc .= '<div class="dataaggregation"><p class="dataplugin_list ' . $data['classes'] . '">';
$R->cdata($this->getLang('none'));
$R->doc .= '</p></div>';
function nullList($data, $clist, Doku_Renderer $R) {
switch($R->getFormat())
{
case 'xhtml':
$R->doc .= '<div class="dataaggregation"><p class="dataplugin_list ' . $data['classes'] . '">';
$R->cdata($this->getLang('none'));
$R->doc .= '</p></div>';
break;
case 'odt':
$R->p_open();
$R->cdata($this->getLang('none'));
$R->p_close();
break;
}
}

/**
* Create list footer
*
* @param array $data instruction by handler()
* @param int $rowcnt number of rows
* @return string html of table footer
* @param array $data instruction by handler()
* @param int $rowcnt number of rows
* @param Doku_Renderer $R the current DokuWiki renderer
*/
function postList($data, $rowcnt) {
return '</ul></div>';
function postList($data, $rowcnt, Doku_Renderer $R) {
switch($R->getFormat())
{
case 'xhtml':
$R->doc .= '</ul></div>';
break;
case 'odt':
$R->listu_close();
break;
}
}

}
Loading