Skip to content

Support for odt export in datatable and datalist #169

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions _test/helper.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ function testFormatData() {
$helper = new helper_plugin_data();
$renderer = new data_dummy_renderer();

$dwVersion = getVersionData();

$matchString = '<a href=\'http://www.dokuwiki.org\' class=\'urlextern\' rel="nofollow">http://www.dokuwiki.org</a>';
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, 7, 30, 2015))
{
$matchString = '<a href="http://www.dokuwiki.org" class="urlextern" title="http://www.dokuwiki.org" rel="nofollow">http://www.dokuwiki.org</a>';
}
}

$this->assertEquals('value1, value2, val',
$helper->_formatData(array('type' => ''), "value1\n value2\n val", $renderer));

Expand All @@ -156,16 +168,20 @@ function testFormatData() {
$helper->_formatData(array('type' => 'mail'), "pa:ge some user", $renderer));

$conf['mailguard'] = 'visible';
$this->assertEquals('<a href="mailto:pa%3Age" class="mail" title="pa%3Age">pa:ge</a>',
$this->assertEquals('<a href="mailto:pa%3Age" class="mail" title="pa:ge">pa:ge</a>',
$helper->_formatData(array('type' => 'mail'), "pa:ge", $renderer));

$this->assertEquals('<a href="mailto:pa%3Age" class="mail" title="pa%3Age">some user</a>',
$this->assertEquals('<a href="mailto:pa%3Age" class="mail" title="pa:ge">some user</a>',
$helper->_formatData(array('type' => 'mail'), "pa:ge some user", $renderer));

$this->assertEquals('<a href=\'url\' class=\'urlextern\' rel="nofollow">url</a>',
$this->assertEquals('url',
$helper->_formatData(array('type' => 'url'), "url", $renderer));

$this->assertEquals('<a href="' . wl('start', array('dataflt[0]'=>'_=value')) . '" title="Show pages matching \'value\'" class="wikilink1">value</a>',
// This test's output is different across dokuwiki versions (order of arguments)
$this->assertEquals($matchString,
$helper->_formatData(array('type' => 'url'), "http://www.dokuwiki.org", $renderer));

$this->assertEquals('link: ?dataflt%5B0%5D=_%3Dvalue value',
$helper->_formatData(array('type' => 'tag'), "value", $renderer));

$this->assertEquals(strftime('%Y/%m/%d %H:%M', 1234567),
Expand Down
202 changes: 192 additions & 10 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, 7, 30, 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 @@ -275,6 +297,7 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R) {
list($id, $title) = explode(' ', $val, 2);
$id = $this->_addPrePostFixes($column['type'], $id);
$id = obfuscate(hsc($id));
$titleId = $id;
if(!$title) {
$title = $id;
} else {
Expand All @@ -283,11 +306,21 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R) {
if($conf['mailguard'] == 'visible') {
$id = rawurlencode($id);
}
$outs[] = '<a href="mailto:' . $id . '" class="mail" title="' . $id . '">' . $title . '</a>';
$outs[] = '<a href="mailto:' . $id . '" class="mail" title="' . $titleId . '">' . $title . '</a>';
break;
case 'url':
$val = $this->_addPrePostFixes($column['type'], $val);
$outs[] = $this->external_link($val, false, 'urlextern');
$url = $val;
$schemes = getSchemes();
list($scheme) = explode('://', $url);
if(!in_array($scheme, $schemes)) $url = '';

// is there still an URL?
if(!$url) {
$outs[] = $val;
} else {
$outs[] = $this->external_link($val, false, 'urlextern');
}
break;
case 'tag':
// per default use keyname as target page, but prefix on aliases
Expand All @@ -296,10 +329,9 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R) {
} else {
$target = $this->_addPrePostFixes($column['type'], '');
}

$outs[] = '<a href="' . wl(str_replace('/', ':', cleanID($target)), $this->_getTagUrlparam($column, $val))
. '" title="' . sprintf($this->getLang('tagfilter'), hsc($val))
. '" class="wikilink1">' . hsc($val) . '</a>';
$params = buildURLparams($this->_getTagUrlparam($column, $val));
$url = str_replace('/', ':', cleanID($target)) . '?' . $params;
$outs[] = $R->internallink($url, hsc($val), true);
break;
case 'timestamp':
$outs[] = dformat($val);
Expand Down Expand Up @@ -363,6 +395,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
Loading