private function parse($content)
{
$buffer = '';
$idx =& $this->idx;
$idx = 0;
$balise = $textarea = $select = $option = false;
for (; $this->offset < strlen($content); $this->offset++) {
$char = $content[$this->offset];
if ($char == "\n") {
$this->currentLine++;
}
if (!isset($this->data[$idx])) {
$this->data[] = '';
}
if (!$balise) {
if ($char == '<') {
$balise = true;
$buffer = '';
} else {
if ($textarea || $option) {
$this->data[$idx - 1]->addValue($char);
} else {
if (!$select) {
$this->data[$idx] .= $char;
}
}
}
} else {
if ($char == '>') {
$balise = false;
$newNode = $this->parseTag($buffer);
if (!is_object($newNode)) {
switch ($newNode) {
case '</textarea>':
$textarea = false;
break;
case '</select>':
$select = false;
break;
case '</option>':
$option = false;
break;
case '</multiple>':
return;
break;
case '</form>':
if (!isset($this->fields[PostIndicator::$fieldName])) {
$name = '';
if ($this->head && $this->head->has('name')) {
$name .= $this->head->get('name');
}
$this->push(new PostIndicator($name));
}
$this->push('</form>');
break;
default:
$this->data[$idx] .= $newNode;
}
if ($textarea) {
$this->data[$idx - 1]->addValue($newNode);
}
} else {
$this->needJs = $this->needJs || $newNode->needJs();
if ($newNode instanceof Fields\Options) {
if (!$this->data[$idx - 1] instanceof Fields\Select) {
throw new ParserException('<option> should always be in a <select>');
}
$this->sources[$newNode->getSource()] = $newNode;
$newNode->setParent($this->data[$idx - 1]);
} else {
if ($newNode instanceof Fields\Option) {
$option = true;
if (!$this->data[$idx - 1] instanceof Fields\Select) {
throw new ParserException('<option> should always be in a <select>');
} else {
$this->data[$idx - 1]->addOption($newNode);
}
} else {
if ($newNode instanceof Fields\RadioField) {
$this->push($newNode);
if (!isset($this->fields[$newNode->getName()])) {
$this->fields[$newNode->getName()] = $this->factory->getObject('radios');
$this->fields[$newNode->getName()]->setName($newNode->getName());
}
$this->fields[$newNode->getName()]->addRadio($newNode);
} else {
$this->push($newNode);
if ($newNode instanceof Fields\Multiple) {
$parser = $this->factory->getParser($content, $this->offset + 1);
$newNode->setParserData($parser);
$this->offset = $parser->getOffset();
}
if ($newNode instanceof Head) {
$this->head = $newNode;
} else {
if ($newNode->getIndex() === array()) {
$name = $newNode->getBaseName();
if (!isset($this->fields[$name])) {
$this->fields[$name] = new Fields\Group();
$this->fields[$name]->setName($name);
}
$this->fields[$name]->addChild($newNode);
} else {
$this->fields[$newNode->getName()] = $newNode;
}
}
if ($newNode instanceof Fields\FileField && $this->head) {
$this->head->set('enctype', 'multipart/form-data');
}
if ($newNode instanceof Fields\Textarea) {
$textarea = true;
}
if ($newNode instanceof Fields\Select) {
$select = true;
}
if ($newNode->getSource()) {
$this->sources[$newNode->getSource()] = $newNode;
}
}
}
}
}
} else {
$buffer .= $char;
}
}
}
if (null === $this->getHead()) {
throw new ParserException('The Formidable form should have a <form> tag');
}
$this->findPlaceholders();
}