block.table.php
Блок «Таблица»
Вызывается из:
Исходный код
<?php
$data = strval($block['data']['table']);
$rows = explode("\n", $data);
$cols = 0;
foreach ($rows as $i => $row) {
if (!strlen($row = rtrim($row))) continue;
if (strpos($row, "\t") !== false) $row = explode("\t", $row);
else $row = explode('|', $row);
$rows[$i] = $row;
$cols = max($cols, count($row));
}
$head = array_shift($rows);
$classNames = array('uk-table');
if ($block['data']['table-options']) foreach (is_array($block['data']['table-options']) ? $block['data']['table-options'] : explode('|', $block['data']['table-options']) as $option) if ($option) {
if (substr($option, 0, 3) === 'uk-') $classNames[] = $option;
}
$responsive = in_array('uk-table-responsive', $classNames);
print '<div class="uk-overflow-auto">';
print '<table class="' . implode(' ', $classNames) . '">';
if ($head) {
print '<thead>';
foreach ($head as $label) print '<th>' . $label . '</th>';
for ($i = count($head); $i < $cols; $i ++) print '<th></th>';
print '</thead>';
}
print '<tbody>';
foreach ($rows as $row) {
print '<tr>';
foreach ($row as $i => $value) {
print '<td>';
if ($responsive && strlen($value) && strlen($label = $head[$i])) {
print '<div class="uk-text-meta uk-hidden@m">' . $label . '</div>';
}
print $value;
print '</td>';
}
for ($i = count($row); $i < $cols; $i ++) print '<td></td>';
print '</tr>';
}
print '</tbody>';
print '</table>';
print '</div>';
$html = ob_get_clean();
ob_start();
print $Main->callTemplate('block/block', 'block', $Page, array( 'block' => $block, 'html' => $html ));
?>