Skip to content
Merged
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
58 changes: 34 additions & 24 deletions syntax/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ function render($format, &$renderer, $data) {
}
}

/* Get template file name and check existance and access rights.
/**
* Get template file name and check existance and access rights.
*
* @returns 0 if the file does not exist
* @param string $template value of 'template' key in entry
* @return int|string
* 0 if the file does not exist
* -1 if no permission to read the file
* the file name otherwise
*/
Expand All @@ -85,25 +88,27 @@ function _getFile($template) {
return $file;
}


/**
* Generate wiki output from instructions
*
* @param $data array as returned by handle()
* @param $R Doku_Renderer_xhtml
* @return bool|void
*/
function _showData($data, &$R) {
global $ID;

if(!array_key_exists('template', $data)) {
// If keyword "template" not present, we can leave
// the rendering to the parent class.
parent::_showData($data, $R);
return;
return true;
}
$instr = $this->_getInstructions($data);
// Treat possible errors first
if($instr == 0) {
$R->doc .= '<div class="datatemplateentry">';
$R->doc .= "Template {$wikipage[0]} not found. ";
$R->internalLink($wikipage[0], '[Click here to create it]');
$R->doc .= "Template {$data['template']} not found. ";
$R->internalLink($data['template'], '[Click here to create it]');
$R->doc .= '</div>';
return true;
} elseif ($instr == -1) {
Expand Down Expand Up @@ -132,30 +137,31 @@ function _showData($data, &$R) {


/**
* Read and process template file and return wiki instructions. Passes through the return
* value of _getFile if the file does not exist or cannot be accessed. If no template was specified,
* return empty array.
* Read and process template file and return wiki instructions.
* Passes through the return value of _getFile if the file does not exist or cannot be accessed.
* If no template was specified, return empty array.
*
* @param array $data return of handle()
* @return bool|int|string
* 0 if the template file does not exist
* -1 if no permission to read the template file
* otherwise the template page as list of instructions with replacements performed
*/
function _getInstructions($data){
global $ID;

// Get the raw file, and parse it into its instructions. This could be cached... maybe.
$file = $this->_getFile($data['template']);
if(!is_string($file)) return $file;
$rawFile = io_readfile($file);

$replacers['raw_keys'] = array();
$replacers['raw_vals'] = array();
$replacers['keys'] = array();
$replacers['vals'] = array();

foreach($data['data'] as $key => $val){
if($val == '' || !count($val)) continue;
$type = $data['cols'][$key]['type'];
if (is_array($type)) $type = $type['type'];
switch ($type) {
case 'pageid':
$type = 'title';
case 'wiki':
$val = $ID . '|' . $val;
break;
}
$replacers['keys'][] = "@@" . $key . "@@";

$replacers['keys'][] = "@@" . $key . "@@";
$replacers['raw_keys'][] = "@@!" . $key . "@@";
if(is_array($val)){
$cnt = count($val);
Expand Down Expand Up @@ -191,9 +197,12 @@ function _getInstructions($data){
* We want to let the dokuwiki renderer generate the required output, such
* that also metadata is handled correctly. Hence, we will try to translate
* each column type to the corresponding dokuwiki syntax.
*
* @param array $column
* @param string $value value of column.
* @return string DokuWiki syntax interpretation of value
*/
function _formatData($column, $value){
global $conf;
$vals = explode("\n",$value);
$outs = array();
foreach($vals as $val){
Expand All @@ -205,6 +214,7 @@ function _formatData($column, $value){
case 'page':
$outs[] = '[[' . $val. ']]';
break;
case 'pageid':
case 'title':
list($id,$title) = explode('|',$val,2);
$outs[] = '[[' . $id . '|' . $title . ']]';
Expand All @@ -227,7 +237,7 @@ function _formatData($column, $value){
'" class="wikilink1">'.hsc($val).'</a>';
break;
case 'wiki':
$outs[] = $data;
$outs[] = $val;
break;
default:
//$val = $this->_addPrePostFixes($column['type'], $val);
Expand Down
10 changes: 5 additions & 5 deletions syntax/inc/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class datatemplate_cache {
/**
* Remove any metadata that might have been stored by previous versions
* of the plugin.
* @param $renderer an instance of the dokuwiki renderer.
* @param Doku_Renderer_metadata $renderer an instance of the dokuwiki renderer.
*/
public function removeMeta(&$renderer) {
global $ID;
Expand All @@ -32,11 +32,11 @@ public function removeMeta(&$renderer) {
*
* @param array $data from the handle function
* @param string $sql stripped SQL for hash generation
* @param reference $dtlist the calling datatemplate list instance
* @param syntax_plugin_datatemplate_list $dtlist reference, the calling datatemplate list instance
*/
public function checkAndBuildCache($data, $sql, &$dtlist) {
global $ID;
// We know that the datatemplate list has a datahelper.
/** @var $sqlite helper_plugin_sqlite */
$sqlite = $dtlist->dthlp->_getDB();

// Build minimalistic data array for checking the cache
Expand All @@ -53,7 +53,7 @@ public function checkAndBuildCache($data, $sql, &$dtlist) {
$dtcc['filter'] = $data['filter'];
$sqlcc = $dtlist->_buildSQL($dtcc);
$res = $sqlite->query($sqlcc);
$pageids = sqlite_fetch_all($res, SQLITE_NUM);
$pageids = $sqlite->res2arr($res, $assoc = false);

// Ask dokuwiki for cache file name
$cachefile = getCacheName($sql, '.datatemplate');
Expand All @@ -72,7 +72,7 @@ public function checkAndBuildCache($data, $sql, &$dtlist) {
}
if(!$cachedate || $latest > (int) $cachedate || isset($_REQUEST['purge'])) {
$res = $sqlite->query($sql);
$rows = sqlite_fetch_all($res, SQLITE_NUM);
$rows = $sqlite->res2arr($res, $assoc = false);
file_put_contents($cachefile, serialize($rows), LOCK_EX);
} else {
// We arrive here when the cache seems up-to-date. However,
Expand Down
8 changes: 5 additions & 3 deletions syntax/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function _buildSQL(&$data) {
* Create output
*/
function render($format, &$R, $data) {
global $ID;

if(is_null($data)) return false;

$sql = $this->_buildSQL($data);
Expand Down Expand Up @@ -147,7 +147,7 @@ function render($format, &$R, $data) {
}

if ($cnt === 0) {
$this->nullList($data, $clist, $R);
$this->nullList($data, $clist = array(), $R);
return true;
}

Expand All @@ -169,7 +169,7 @@ function render($format, &$R, $data) {
* @param string $wikipage the id of the wikipage containing the template
* @param array $data output of the handle function
* @param array $rows the result of the sql query
* @param reference $R the dokuwiki renderer
* @param Doku_Renderer_xhtml $R the dokuwiki renderer
* @return boolean Whether the page has been correctly (not: succesfully) processed.
*/
function _renderTemplate($wikipage, $data, $rows, &$R) {
Expand Down Expand Up @@ -264,6 +264,7 @@ function _renderTemplate($wikipage, $data, $rows, &$R) {
*/
function _renderPagination($data, $numrows) {
global $ID;
$text = '';
// Add pagination controls
if($data['limit']){
$params = $this->dthlp->_a2ua('dataflt',$_REQUEST['dataflt']);
Expand Down Expand Up @@ -304,6 +305,7 @@ function _renderPagination($data, $numrows) {
}
return '<div class="prevnext">' . $text . '</div>';
}
return $text;
}

/**
Expand Down