/** * Escapes expression in tokens. * @return MacroTokens */ public function escapeFilter(MacroTokens $tokens) { $tokens = clone $tokens; switch ($this->compiler->getContentType()) { case Compiler::CONTENT_XHTML: case Compiler::CONTENT_HTML: $context = $this->compiler->getContext(); switch ($context[0]) { case Compiler::CONTEXT_SINGLE_QUOTED_ATTR: case Compiler::CONTEXT_DOUBLE_QUOTED_ATTR: case Compiler::CONTEXT_UNQUOTED_ATTR: if ($context[1] === Compiler::CONTENT_JS) { $tokens->prepend('Latte\\Runtime\\Filters::escapeJs(')->append(')'); } elseif ($context[1] === Compiler::CONTENT_CSS) { $tokens->prepend('Latte\\Runtime\\Filters::escapeCss(')->append(')'); } $tokens->prepend('Latte\\Runtime\\Filters::escapeHtml(')->append($context[0] === Compiler::CONTEXT_SINGLE_QUOTED_ATTR ? ', ENT_QUOTES)' : ', ENT_COMPAT)'); if ($context[0] === Compiler::CONTEXT_UNQUOTED_ATTR) { $tokens->prepend("'\"', ")->append(", '\"'"); } return $tokens; case Compiler::CONTEXT_COMMENT: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlComment(')->append(')'); case Compiler::CONTENT_JS: case Compiler::CONTENT_CSS: return $tokens->prepend('Latte\\Runtime\\Filters::escape' . ucfirst($context[0]) . '(')->append(')'); default: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtml(')->append(', ENT_NOQUOTES)'); } case Compiler::CONTENT_XML: $context = $this->compiler->getContext(); switch ($context[0]) { case Compiler::CONTEXT_COMMENT: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlComment(')->append(')'); default: $tokens->prepend('Latte\\Runtime\\Filters::escapeXml(')->append(')'); if ($context[0] === Compiler::CONTEXT_UNQUOTED_ATTR) { $tokens->prepend("'\"', ")->append(", '\"'"); } return $tokens; } case Compiler::CONTENT_JS: case Compiler::CONTENT_CSS: case Compiler::CONTENT_ICAL: return $tokens->prepend('Latte\\Runtime\\Filters::escape' . ucfirst($this->compiler->getContentType()) . '(')->append(')'); case Compiler::CONTENT_TEXT: return $tokens; default: return $tokens->prepend('$template->escape(')->append(')'); } }
/** * Escapes expression in tokens. * @return MacroTokens */ public function escapeFilter(MacroTokens $tokens) { $tokens = clone $tokens; switch ($this->compiler->getContentType()) { case Compiler::CONTENT_XHTML: case Compiler::CONTENT_HTML: $context = $this->compiler->getContext(); switch ($context[0]) { case Compiler::CONTEXT_QUOTED_ATTRIBUTE: case Compiler::CONTEXT_TAG: if ($context[1] === Compiler::CONTENT_JS) { $tokens->prepend('Latte\\Runtime\\Filters::escapeJs(')->append(')'); } elseif ($context[1] === Compiler::CONTENT_CSS) { $tokens->prepend('Latte\\Runtime\\Filters::escapeCss(')->append(')'); } if ($context[0] === Compiler::CONTEXT_TAG) { $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlAttrUnquoted(')->append(')'); } else { $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlAttr(')->append(')'); } return $tokens; case Compiler::CONTEXT_COMMENT: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlComment(')->append(')'); case Compiler::CONTENT_JS: case Compiler::CONTENT_CSS: return $tokens->prepend('Latte\\Runtime\\Filters::escape' . ucfirst($context[0]) . '(')->append(')'); default: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlText(')->append(')'); } case Compiler::CONTENT_XML: $context = $this->compiler->getContext(); switch ($context[0]) { case Compiler::CONTEXT_COMMENT: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlComment(')->append(')'); case Compiler::CONTEXT_TAG: return $tokens->prepend('Latte\\Runtime\\Filters::escapeXmlAttrUnquoted(')->append(')'); default: return $tokens->prepend('Latte\\Runtime\\Filters::escapeXml(')->append(')'); } case Compiler::CONTENT_JS: case Compiler::CONTENT_CSS: case Compiler::CONTENT_ICAL: return $tokens->prepend('Latte\\Runtime\\Filters::escape' . ucfirst($this->compiler->getContentType()) . '(')->append(')'); case Compiler::CONTENT_TEXT: return $tokens; default: return $tokens->prepend('$template->escape(')->append(')'); } }