* @license PHP License * @package wb * @subpackage Markup */ WBClass::load('WBMarkup_Converter'); /** * Tag converter * * Table of content * * @version 0.1.0 * @package wb * @subpackage Markup */ class WBMarkup_Converter_Wb_Toc extends WBMarkup_Converter { /** * handler * @var WBMarkup_Handler_Xml2Html */ private $handler; /** * constructor * * start dictionary */ public function __construct() { } public function preset($handler, &$content) { parent::preset($handler, $content); $this->handler = $handler; } /** * transform Xinha Tags to XML * * @todo solve problem with internal but SSL links * @todo implement VFSFile links * @param array $node to be modified document node * @return bool true on success */ public function toXml(&$node) { $cData = trim(strip_tags(implode('', $node['cData']))); $xml = array( 'ns' => 'wb', 'tag' => 'toc', 'attributes' => array(), 'isEmpty' => $node['isEmpty'], 'cData' => array($cData) ); $atts = array( 'stopat' => $node['attributes']['stopat'], 'tags' => $node['attributes']['tags'], 'template' => $node['attributes']['template'], 'class' => $node['attributes']['wb:value'] ); $xml['attributes'] = $atts; $node = $xml; return true; } /** * transform Xml to Xinha (html) tags * * @param array $node to be modified document node * @return bool true on success */ public function toXinha(&$node) { $xinha = array( 'ns' => '', 'tag' => 'div', 'attributes' => array(), 'isEmpty' => $node['isEmpty'], 'cData' => $node['cData'] ); $atts = array( 'wb:dialog' => 'toc', 'wb:value' => $node['attributes']['class'], 'class' => 'wbxinha toc', 'title' => 'Double click to edit', 'template' => $node['attributes']['template'], 'stopat' => $node['attributes']['stopat'], 'tags' => $node['attributes']['tags'] ); $xinha['attributes'] = $atts; $node = $xinha; return true; } /** * transform XML to Html * * @param array $node to be modified document node * @return bool true on success */ public function toHtml(&$node) { $listener = WBClass::create('WBMarkup_Listener_Toc'); $config = $node['attributes']; $config['tags'] = explode(',', $config['tags']); $config['cData'] = $node['cData']; $config['needle'] = ''; $listener->configure($config); // html attributes $node['ns'] = ''; $node['tag'] = ''; $node['attributes'] = array(); $node['cData'] = array($config['needle']); $this->handler->addListener($listener); return true; } } ?>