public function defaultTreeProcess(optBlock $block) { if ($block->hasChildNodes()) { foreach ($block as $node) { $this->nodeProcess($node); } } }
public function processAttribute(optBlock $block) { switch ($block->getName()) { case 'sectionfirst': foreach ($this->sections as $id => &$void) { if ($void['name'] == $block->getAttributes()) { } $sid = $id; } if ($this->sections[$sid]['order'] == 'reversed') { $this->compiler->out(' if($__' . $block->getAttributes() . '_id == $__' . $block->getAttributes() . '_cnt - 1){ echo \'class="first"\'; } '); break; } $this->compiler->out('if($__' . $block->getAttributes() . '_id == 0){ echo \'class="first"\'; } '); break; case 'sectionlast': foreach ($this->sections as $id => &$void) { if ($void['name'] == $block->getAttributes()) { } $sid = $id; } if ($this->sections[$sid]['order'] == 'reversed') { $this->compiler->out('if($__' . $block->getAttributes() . '_id == 0){ echo \'class="last"\'; } '); break; } $this->compiler->out(' if($__' . $block->getAttributes() . '_id == $__' . $block->getAttributes() . '_cnt - 1){ echo \'class="last"\'; } '); break; case 'sectioncycle': $sid = 0; foreach ($this->sections as $id => &$void) { if (!isset($void['name'])) { continue; } if ($void['name'] == $block->getAttributes()) { $sid = $id; } } if (isset($this->sections[$sid]['cycle'])) { $this->compiler->out(' echo ' . $this->sections[$sid]['cycle'] . '.\'="\'.($__' . $this->sections[$sid]['name'] . '_cycle[$__' . $this->sections[$sid]['name'] . '_id % $__' . $this->sections[$sid]['name'] . '_cc]).\'"\'; '); } break; } }
public function debugBlockProcess(optBlock $block) { if ($block->hasChildNodes()) { foreach ($block as $node) { $this->debugNodeProcess($node); } } }
public function parse($code) { static $regex; if (count($this->tpl->codeFilters['pre']) > 0) { foreach ($this->tpl->codeFilters['pre'] as $name) { // @ used because of stupid notice // "Object of class opt_template to string conversion". // Whatever it means, I couldn't recognize, why PHP does such things. $this->code = @$name($code, $this->tpl); } } if ($regex == NULL) { if ($this->tpl->xmlsyntaxMode == 1) { $regex = '\\<\\!\\-\\-.+\\-\\-\\>|<\\!\\[CDATA\\[|\\]\\]>|' . $regex; $this->tpl->delimiters[] = '\\<(\\/?)opt\\:(.*?)()\\>'; $this->tpl->delimiters[] = '\\<()opt\\:(.*?)(\\/)\\>'; $this->tpl->delimiters[] = 'opt\\:put\\=\\"(.*?[^\\\\])\\"'; } $regex = implode('|', $this->tpl->delimiters); } // tokenizer preg_match_all('#({\\*.+?\\*\\}|' . $regex . '|(.?))#si', $code, $result, PREG_PATTERN_ORDER); foreach ($result as $i => &$void) { if ($i != 0) { unset($result[$i]); } } $output = $this->tpl->captureTo . ' \''; if (!$this->parseRun) { // register output foreach ($this->processors as $name => $processor) { $processor->setOutput($output); } $this->parseRun = 1; } else { $this->parseRun = 2; } // initialize the tree $root = $current = new optNode(NULL, OPT_ROOT, NULL); $rootBlock = $currentBlock = new optBlock(NULL); $root->addItem($rootBlock); $textAssign = 0; $commented = 0; $literal = 0; foreach ($result[0] as $i => $item) { // comment usage if (strlen($item) > 1) { if (preg_match('/{\\*.+?\\*\\}/s', trim($item)) || preg_match('/\\<\\!\\-\\-.+\\-\\-\\>/s', $item)) { continue; } // a command // literal processing if ($literal == 1) { if ($item != '{/literal}') { $item = str_replace(array('\\', '\''), array('\\\\', '\\\''), $item); $text->addItem($item); $textAssign = 1; } else { $literal = 0; } continue; } if ($item == '{literal}' && $literal == 0) { $literal = 1; continue; } $textAssign = 0; // grep the data $sortMatches = array(0 => '', 1 => '', 2 => ''); preg_match('/' . $regex . '/', $item, $matches); $foundCommand = 0; foreach ($matches as $id => $val) { $val = trim($val); if ($val != '') { if ($val == '/') { if (!$foundCommand) { $sortMatches[0] = '/'; } else { $sortMatches[2] = '/'; } } elseif ($id != 0) { $sortMatches[1] = $val; $foundCommand = 1; } } } if (preg_match('/^(([a-zA-Z0-9\\_]+)([= ]{1}(.*))?)$/', $sortMatches[1], $found)) { // we have an instruction $realname = $found[2]; if ($sortMatches[0] == '/') { $found[2] = '/' . $found[2]; } $found[6] = $item; // general instructions if (isset($this->translator[$found[2]])) { switch ($this->translator[$found[2]]) { case OPT_COMMAND: $node = new optNode($found[2], OPT_INSTRUCTION, $current); $node->addItem(new optBlock($found[2], $found, OPT_COMMAND)); $currentBlock->addNode($node); break; case OPT_MASTER: $current->storeBlock($currentBlock); $current = new optNode($found[2], OPT_INSTRUCTION, $current); $currentBlock->addNode($current); $currentBlock = new optBlock($found[2], $found, OPT_MASTER); $current->addItem($currentBlock); break; case OPT_ALT: $currentBlock = new optBlock($found[2], $found, OPT_ALT); $current->addItem($currentBlock); break; case OPT_ENDER: $currentBlock = new optBlock($found[2], $found, OPT_ENDER); $current->addItem($currentBlock); $current = $current->getParent(); if (!is_object($current)) { $this->tpl->error(E_USER_ERROR, 'Unexpected enclosing statement: `' . $found[2] . '`!', 113); } $currentBlock = $current->restoreBlock(); break; } } elseif ($realname == 'component' || isset($this->tpl->components[$realname])) { if ($sortMatches[0] == '/') { $currentBlock = new optBlock($found[2], $found); $current->addItem($currentBlock); $current = $current->getParent(); if (!is_object($current)) { $this->tpl->error(E_USER_ERROR, 'Unexpected enclosing statement: `' . $found[2] . '`!', 113); } $currentBlock = $current->restoreBlock(); } else { $current->storeBlock($currentBlock); $current = new optNode($realname, OPT_COMPONENT, $current); $currentBlock->addNode($current); $currentBlock = new optBlock($realname, $found); $current->addItem($currentBlock); } } else { // here come the undefined command. The instruction programmer may do with them whatever he wants // the compiler is going to recognize, what sort of command is it. $ending = substr($found[2], strlen($found[2]) - 4, 4); if ($sortMatches[0] == '/') { // ending command, like in XML: /command $currentBlock = new optBlock($found[2], $found, OPT_ENDER); $current->addItem($currentBlock); $current = $current->getParent(); if (!is_object($current)) { $this->tpl->error(E_USER_ERROR, 'Unexpected enclosing statement: `' . $found[2] . '`!', 113); } $currentBlock = $current->restoreBlock(); } elseif ($sortMatches[2] == '/') { // standalone command, like XML: command/ $node = new optNode($found[2], OPT_UNKNOWN, $current); $node->addItem(new optBlock($found[2], $found, OPT_COMMAND)); $currentBlock->addNode($node); } elseif ($ending == 'else') { // alternative command, doesn't exist in XML: commandelse $currentBlock = new optBlock($found[2], $found, OPT_ALT); $current->addItem($currentBlock); } else { // beginning command: command $current->storeBlock($currentBlock); $current = new optNode($realname, OPT_UNKNOWN, $current); $currentBlock->addNode($current); $currentBlock = new optBlock($realname, $found, OPT_MASTER); $current->addItem($currentBlock); } } } else { // we have an expression $node = new optNode(NULL, OPT_EXPRESSION, $current); $node->addItem(new optBlock(NULL, $sortMatches[1])); $currentBlock->addNode($node); } } else { // text item if ($textAssign == 0) { $text = new optTextNode(NULL, OPT_TEXT, $current); $currentBlock->addNode($text); } // character escaping if ($item == '\'') { $item = '\\\''; } if ($item == '\\') { $item = '\\\\'; } $text->addItem($item); $textAssign = 1; } } // execute the tree $this->processors['generic']->nodeProcess($root); if ($this->parseRun < 2) { $code = $output . '\';'; } // apply postfilters if (count($this->tpl->codeFilters['post']) > 0) { foreach ($this->tpl->codeFilters['post'] as $name) { $code = $name($code, $this->tpl); } } $this->parseRun--; return $code; }
public function processAttribute(optBlock $block) { if ($block->getName() == 'opf:classfor') { $this->compiler->out(' echo $this->data[$formName]->getClass(\'' . $block->getAttributes() . '\'); '); } }