$)/','',$header);
}
/**
* Handles the body of the syntax. This method is called before any
* of the body is handled.
*
* @param tree array the parsed tree
* @param result array the result array passed to the render method
*/
function handleBody(&$tree, &$result) {
}
/**
* Handles the footer of the syntax. This method is called after the
* data has been parsed and normalized.
*
* @param footer string the footer string
* @param result array the result array passed to the render method
* @return a string containing the unhandled parts of the footer
*/
function handleFooter($footer, &$result) {
return '';
}
protected function getPositions($data) {
global $ID;
// determine positions of other data entries
// (self::$previewMetadata is only filled if a preview_metadata was run)
if(isset(self::$previewMetadata[$ID])) {
$positions = self::$previewMetadata[$ID]['strata']['positions'];
} else {
$positions = p_get_metadata($ID, 'strata positions');
}
// only read positions if we have them
if(is_array($positions) && isset($positions[$data['entry']])) {
$positions = $positions[$data['entry']];
$currentPosition = array_search($data['position'],$positions);
$previousPosition = isset($positions[$currentPosition-1])?'data_fragment_'.$positions[$currentPosition-1]:null;
$nextPosition = isset($positions[$currentPosition+1])?'data_fragment_'.$positions[$currentPosition+1]:null;
$currentPosition = 'data_fragment_'.$positions[$currentPosition];
}
return array($currentPosition, $previousPosition, $nextPosition);
}
function render($mode, Doku_Renderer $R, $data) {
global $ID;
if($data == array()) {
return false;
}
if($mode == 'xhtml' || $mode == 'odt') {
// determine actual header text
$heading = '';
if(isset($data['data'][$this->util->getTitleKey()])) {
// use title triple if possible
$heading = $data['data'][$this->util->getTitleKey()][0]['value'];
} elseif (!empty($data['title candidate'])) {
// use title candidate if possible
$heading = $data['title candidate']['value'];
} else {
if(useHeading('content')) {
// fall back to page title, depending on wiki configuration
$heading = p_get_first_heading($ID);
}
if(!$heading) {
// use page id if all else fails
$heading = noNS($ID);
}
}
list($currentPosition, $previousPosition, $nextPosition) = $this->getPositions($data);
// render table header
if($mode == 'xhtml') { $R->doc .= ''; }
if($mode == 'odt' && isset($currentPosition) && method_exists ($R, 'insertBookmark')) {
$R->insertBookmark($currentPosition, false);
}
$R->table_open();
$R->tablerow_open();
$R->tableheader_open(2);
$R->cdata($heading);
// display a comma-separated list of classes if the entry has classes
if(isset($data['data'][$this->util->getIsaKey()])) {
$R->emphasis_open();
$R->cdata(' (');
$values = $data['data'][$this->util->getIsaKey()];
$this->util->openField($mode, $R, $this->util->getIsaKey());
for($i=0;$icdata(', ');
$type = $this->util->loadType($triple['type']);
$this->util->renderValue($mode, $R, $this->triples, $triple['value'], $triple['type'], $type, $triple['hint']);
}
$this->util->closeField($mode, $R);
$R->cdata(')');
$R->emphasis_close();
}
$R->tableheader_close();
$R->tablerow_close();
// render a row for each key, displaying the values as comma-separated list
foreach($data['data'] as $key=>$values) {
// skip isa and title keys
if($key == $this->util->getTitleKey() || $key == $this->util->getIsaKey()) continue;
// render row header
$R->tablerow_open();
$R->tableheader_open();
$this->util->renderPredicate($mode, $R, $this->triples, $key);
$R->tableheader_close();
// render row content
$R->tablecell_open();
$this->util->openField($mode, $R, $key);
for($i=0;$icdata(', ');
$this->util->renderValue($mode, $R, $this->triples, $triple['value'], $triple['type'], $triple['hint']);
}
$this->util->closeField($mode, $R);
$R->tablecell_close();
$R->tablerow_close();
}
if($previousPosition || $nextPosition) {
$R->tablerow_open();
$R->tableheader_open(2);
if($previousPosition) {
if($mode == 'xhtml') { $R->doc .= ''; }
$R->locallink($previousPosition, $this->util->getLang('data_entry_previous'));
if($mode == 'xhtml') { $R->doc .= ''; }
}
$R->cdata(' ');
if($nextPosition) {
if($mode == 'xhtml') { $R->doc .= ''; }
$R->locallink($nextPosition, $this->util->getLang('data_entry_next'));
if($mode == 'xhtml') { $R->doc .= ''; }
}
$R->tableheader_close();
$R->tablerow_close();
}
$R->table_close();
if($mode == 'xhtml') { $R->doc .= '
'; }
return true;
} elseif($mode == 'metadata' || $mode == 'preview_metadata') {
$triples = array();
$subject = $ID.'#'.$data['entry'];
// resolve the subject to normalize everything
resolve_pageid(getNS($ID),$subject,$exists);
$titleKey = $this->util->getTitleKey();
$fixTitle = false;
// we only use the title determination if no explicit title was given
if(empty($data['data'][$titleKey])) {
if(!empty($data['title candidate'])) {
// we have a candidate from somewhere
$data['data'][$titleKey][] = $data['title candidate'];
} else {
if(!empty($R->meta['title'])) {
// we do not have a candidate, so we use the page title
// (this is possible because fragments set the candidate)
$data['data'][$titleKey][] = array(
'value'=>$R->meta['title'],
'type'=>'text',
'hint'=>null
);
} else {
// we were added before the page title is known
// however, we do require a page title (iff we actually store data)
$fixTitle = true;
}
}
}
// store positions information
if($mode == 'preview_metadata') {
self::$previewMetadata[$ID]['strata']['positions'][$data['entry']][] = $data['position'];
} else {
$R->meta['strata']['positions'][$data['entry']][] = $data['position'];
}
// process triples
foreach($data['data'] as $property=>$bucket) {
$this->util->renderPredicate($mode, $R, $this->triples, $property);
foreach($bucket as $triple) {
// render values for things like backlinks
$type = $this->util->loadType($triple['type']);
$type->render($mode, $R, $this->triples, $triple['value'], $triple['hint']);
// prepare triples for storage
$triples[] = array('subject'=>$subject, 'predicate'=>$property, 'object'=>$triple['value']);
}
}
// we're done if nodata is flagged.
if(!isset($R->info['data']) || $R->info['data']==true) {
// batch-store triples if we're allowed to store
$this->triples->addTriples($triples, $ID);
// set flag for title addendum
if($fixTitle) {
$R->meta['strata']['fixTitle'] = true;
}
}
return true;
}
return false;
}
}