Project

General

Profile

Bug #15473 ยป render_table.txt

Administrator Admin, 2006-01-24 22:11

 

/**
* Rendering the "Table" type content element, called from TypoScript (tt_content.table.20)
*
* @param string Content input. Not used, ignore.
* @param array TypoScript configuration
* @return string HTML output.
* @access private
*/
function render_table($content,$conf) {

// Look for hook before running default code for function
if ($hookObj = &$this->hookRequest('render_table')) {
return $hookObj->render_table($content,$conf);
} else {
// Init FlexForm configuration
$this->pi_initPIflexForm();

// Get bodytext field content
$content = trim($this->cObj->data['bodytext']);
if (!strcmp($content,'')) return '';

// get flexform values
$caption = trim(htmlspecialchars($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_caption')));
$summary = trim(htmlspecialchars($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_summary')));
$useTfoot = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_tfoot'));
$headerPos = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_headerpos');
$noStyles = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_nostyles');
$tableClass = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_tableclass');

$delimiter = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'tableparsing_delimiter','s_parsing'));
if ($delimiter) {
$delimiter = chr(intval($delimiter));
} else {
$delimiter = '|';
}
$quotedInput = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'tableparsing_quote','s_parsing'));
if ($quotedInput) {
$quotedInput = chr(intval($quotedInput));
} else {
$quotedInput = '';
}
// generate id prefix for header
if($headerPos == 'top' || $headerPos == 'bottom') $headerScope = 'col'; else $headerScope = 'row';
$headerId = $headerScope.$this->cObj->data['uid'].'-';

// Split into single lines (will become table-rows):
$rows = t3lib_div::trimExplode(chr(10),$content);

// Find number of columns to render:
$cols = t3lib_div::intInRange($this->cObj->data['cols']?$this->cObj->data['cols']:count(explode($delimiter,current($rows))),0,100);

// Traverse rows (rendering the table here)
$rCount = count($rows);
$rLast = $rCount-1;
$cLast = $cols-1;
foreach($rows as $k => $v) {
$cells = explode($delimiter,$v);
$newCells=array();
for($a=0;$a<$cols;$a++) {
// remove quotes if needed
if ($quotedInput && substr($cells[$a],0,1) == $quotedInput && substr($cells[$a],-1,1) == $quotedInput) {
$cells[$a] = substr($cells[$a],1,-1);
}

if (!strcmp(trim($cells[$a]),'')) $cells[$a]='&nbsp;';
$cellAttribs = ($noStyles?'':(($a>0 && $a==$cLast) ? ' class="td-last"' : ' class="td-'.$a.'"'));
if ((!$k && $headerPos == 'top') || (!$a && $headerPos == 'left') || ($a == $cLast && $headerPos == 'right') || ($k == $rLast && $headerPos == 'bottom')) {
$scope = ' scope="'.$headerScope.'" id="'.$headerId.(($headerScope=='col')?$a:$k).'"';
$newCells[$a] = '
<th'.$cellAttribs.$scope.'>'.$this->cObj->stdWrap($cells[$a],$conf['innerStdWrap.']).'</th>';
} else {
$headers = ' headers="'.$headerId.(($headerScope=='col')?$a:$k).'"';
$newCells[$a] = '
<td'.$cellAttribs.$headers.'>'.$this->cObj->stdWrap($cells[$a],$conf['innerStdWrap.']).'</td>';
}
}
if (!$noStyles) {
$oddEven = $k%2 ? 'tr-odd' : 'tr-even';
$rowAttribs = ($k>0 && $k==$rLast) ? ' class="'.$oddEven.' tr-last"' : ' class="'.$oddEven.' tr-'.$k.'"';
}
$rows[$k]='
<tr'.$rowAttribs.'>'.implode('',$newCells).'
</tr>';
}

$addTbody = 0;
$tableContents = '';
if ($caption) {
$tableContents .= '
<caption>'.$caption.'</caption>';
}
if ($headerPos == 'top' && $rows[0]) {
$tableContents .= '<thead>'. $rows[0] .'
</thead>';
unset($rows[0]);
$addTbody = 1;
}
if ($useTfoot) {
$tableContents .= '
<tfoot>'.$rows[$rLast].'</tfoot>';
unset($rows[$rLast]);
$addTbody = 1;
}
$tmpTable = implode('',$rows);
if ($addTbody) {
$tmpTable = '<tbody>'.$tmpTable.'</tbody>';
}
$tableContents .= $tmpTable;

// Set header type:
$type = intval($this->cObj->data['layout']);

// Table tag params.
$tableTagParams = $this->getTableAttributes($conf,$type);
if (!$noStyles) {
$tableTagParams['class'] = 'contenttable contenttable-'.$type;
} elseif ($tableClass) {
$tableTagParams['class'] = $tableClass;
}


// Compile table output:
$out = '
<table '.t3lib_div::implodeAttributes($tableTagParams).($summary?' summary="'.$summary.'"':'').'>'. // Omitted xhtmlSafe argument TRUE - none of the values will be needed to be converted anyways, no need to spend processing time on that.
$tableContents.'
</table>';

// Calling stdWrap:
if ($conf['stdWrap.']) {
$out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
}

// Return value
return $out;
}
}
    (1-1/1)