/** * execute the action from the parsing * * @access protected * @param array $action */ protected function _executeAction($action) { $action['name'] = strtoupper($action['name']); if ($this->_firstPage && $action['name'] !== 'PAGE' && !$action['close']) { $this->_setNewPage(); } // properties of the action $properties = $action['param']; // name of the action (old method) $fnc = ($action['close'] ? '_tag_close_' : '_tag_open_') . strtoupper($action['name']); $tagObject = $this->getTagObject($action['name']); if (!is_null($tagObject)) { if ($action['close']) { $res = $tagObject->close($properties); } else { $res = $tagObject->open($properties); } } elseif (is_callable(array(&$this, $fnc))) { $res = $this->{$fnc}($properties); } else { $e = new HtmlParsingException('The html tag [' . $action['name'] . '] is not known by Html2Pdf not exists.' . 'You can create it and push it on the Html2Pdf GitHub project.'); $e->setInvalidTag($action['name']); $e->setHtmlLine($action['line']); throw $e; } // save the name of the action $this->_previousCall = $fnc; // return the result return $res; }
/** * TODO remove the reference on the $parents variable * * @param Token $token * @param array $parents * * @return array * @throws HtmlParsingException */ protected function getTagAction(Token $token, &$parents) { // tag that can be not closed $tagsNotClosed = array('br', 'hr', 'img', 'col', 'input', 'link', 'option', 'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline'); // analyze the HTML code $node = $this->tagParser->analyzeTag($token->getData()); // save the current position in the HTML code $node->setLine($token->getLine()); $actions = array(); // if the tag must be closed if (!in_array($node->getName(), $tagsNotClosed)) { // if it is a closure tag if ($node->isClose()) { // HTML validation if (count($parents) < 1) { $e = new HtmlParsingException('Too many tag closures found for [' . $node->getName() . ']'); $e->setInvalidTag($node->getName()); $e->setHtmlLine($token->getLine()); throw $e; } elseif (end($parents) != $node->getName()) { $e = new HtmlParsingException('Tags are closed in a wrong order for [' . $node->getName() . ']'); $e->setInvalidTag($node->getName()); $e->setHtmlLine($token->getLine()); throw $e; } else { array_pop($parents); } } else { // if it is an auto-closed tag if ($node->isAutoClose()) { // save the opened tag $actions[] = $node; // prepare the closed tag $node = clone $node; $node->setParams(array()); $node->setClose(true); } else { // else: add a child for validation array_push($parents, $node->getName()); } } // if it is a <pre> tag (or <code> tag) not auto-closed => update the flag if (($node->getName() == 'pre' || $node->getName() == 'code') && !$node->isAutoClose()) { $this->tagPreIn = !$node->isClose(); } } // save the actions to convert $actions[] = $node; return $actions; }