*/ WBClass::load('patI18n'); /** * patTemplate modifier Wxml * * Convert Wombat XML format to HTML * * Parameter: * - tmpldir * - gettext: use gettext for translation * - domain: gettext domain * - mode: "html" or "tex" * * @version 1.0.1 * @package patTemplate * @package Modifiers * @author gERD Schaufelberger */ class patTemplate_Modifier_Wxml extends patTemplate_Modifier { /** * modify the value * * @param string value * @param array list of parameter * @return string modified value */ public function modify($value, $params = array()) { $params = array_merge(array( 'domain' => '', 'gettext' => '', 'tmpldir' => '', 'handler' => '', // deprecated 'mode' => 'html', 'tag' => 'div', // container: either span or div or __none 'class' => '' // class of container ), $params); /* @var $scan WBMarkup_Scanner */ $scan = WBClass::create( 'WBMarkup_Scanner' ); // accept deprecated parameter "handler" if (!empty($params['handler'])) { $params['mode'] = $params['handler']; } switch (strtolower($params['mode'])) { case 'tex': /** @var WBMarkup_Handler_Xml2Tex */ $hdl = WBClass::create( 'WBMarkup_Handler_Xml2Tex' ); break; default: /** @var WBMarkup_Handler_Xml2Html */ $hdl = WBClass::create( 'WBMarkup_Handler_Xml2Html' ); break; } $hdl->setOption($params); if (!empty($params['tmpldir'])) { $hdl->setTmplDir($params['tmpldir']); } $value = $this->translate($value, $params); $scan->setHandler($hdl); $scan->scan($value); $value = $hdl->getParsedContent(); if ('tex' == strtolower($params['mode'])) { return $value; } $tag = 'div'; switch ($params['tag']) { case '__none': // no container tag at all return $value; break; case 'span': $tag = 'span'; break; default: case 'div': break; } $class = array(); if (!empty($params['class'])) { $class = array_map('trim', explode(' ', trim($params['class']))); } $class[] = 'wb-wxml-content'; $class = implode(' ', $class); $value = sprintf('<%s class="%s">%s', $tag, $class, $value); return $value; } /** * Translate the value * * @param string value * @param array list of parameter * @return string translated value */ private function translate($value, $params) { if (empty($params['gettext'])) { return $value; } if (!empty($params['domain'])) { return patI18n::dgettext($params['domain'], $value); } return patI18n::gettext($value); } }