public function compile(BBCodeToken $token) { if ($token->getTagName() == 'table') { $table = ''; foreach ($token->getChilds() as $child) { if ($child instanceof BBCodeToken && $child->getTagName() == 'tr') { $table .= '<tr>'; foreach ($child->getChilds() as $subchild) { if ($subchild instanceof BBCodeToken) { $cellContent = $this->compiler->compile($subchild, self::DT_ALL); if ($subchild->getTagName() == 'th') { $table .= "<th>{$cellContent}</th>"; } elseif ($subchild->getTagName() == 'td') { $table .= "<td>{$cellContent}</td>"; } } } $table .= '</tr>'; } } return "<table border='1' cellspacing='0'>{$table}</table>"; } }
private function executeCompiler(BBCodeToken $parent) { $text = ''; $childs = $parent->getChilds(); foreach ($childs as $child) { if ($parent->getTagName() != 'viscacha_root_node' && $parent->isValidChild($child) == false) { if ($child instanceof BBCodeToken) { // Invalid child, add as text only $text .= $child->totext(); } // Else: Invalid child, remove it (applies also on strings) } else { if (is_string($child)) { // Valid child, add the text $text .= $child; } elseif ($child instanceof BBCodeToken) { // Valid child, add the compiled token $text .= $child->getTagObject()->compile($child); } } } return $text; }