* @license PHP License * @package wb * @subpackage Markup */ WBClass::load('WBMarkup_Converter'); /** * Tag converter * * Convert node to node * * @version 0.5.0 * @package wb * @subpackage Markup */ class WBMarkup_Converter_Wb_Url extends WBMarkup_Converter { /** * URL dictionary * @var WBDictionary_Url */ protected $dict; /** * constructor * * start dictionary */ public function __construct() { $this->dict = WBClass::create('WBDictionary_URL'); } /** * 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) { $xml = array( 'ns' => 'wb', 'tag' => 'url', 'attributes' => array(), 'isEmpty' => $node['isEmpty'], 'cData' => $node['cData'] ); if (empty($node['attributes']['urlid'])) { // try to create a new URLid using given URL if (empty($node['attributes']['href'])) { return false; } $this->dict->addWord($node['attributes']['href']); $node['attributes']['urlid'] = $this->dict->getId(); } $this->dict->load($node['attributes']['urlid']); $atts = array( 'title' => $node['attributes']['wb:value'], 'urlid' => $this->dict->getId() ); if (isset($node['attributes']['class'])) { $atts['class'] = $node['attributes']['class']; } $xml['attributes'] = $atts; $node = $xml; return true; } /** * transform Xml to Wxml (html) tags * * @param array $node to be modified document node * @return bool true on success */ public function toWxml(&$node) { $wxml = array( 'ns' => '', 'tag' => 'a', 'attributes' => array(), 'isEmpty' => $node['isEmpty'], 'cData' => $node['cData'] ); $this->dict->load($node['attributes']['urlid']); $atts = array( 'wb:dialog' => 'url', 'wb:value' => $node['attributes']['title'], 'href' => $this->dict->getWord(), 'urlid' => $this->dict->getid(), 'target' => '_blank' ); $atts = array_merge($this->getDefaultAttributes(WBMarkup_Converter::TARGET_WXML), $atts); $data = $this->dict->get(); if ($data['protocol'] != 'self') { $atts['target'] = '_blank'; } if (isset($node['attributes']['class'])) { $atts['class'] = $node['attributes']['class']; } $node = $wxml; $node['attributes'] = $atts; return true; } /** * transform XML to Html * * @param array $node to be modified document node * @return bool true on success */ public function toHtml(&$node) { $this->dict->load($node['attributes']['urlid']); // html attributes $node['ns'] = ''; $node['tag'] = 'a'; $atts = array( 'title' => $node['attributes']['title'], 'href' => $this->dict->getWord(), ); if (isset($node['attributes']['class']) && strlen($node['attributes']['class'])) { $atts['class'] = $node['attributes']['class']; } $data = $this->dict->get(); // mailto if ($data['protocol'] == 'mailto') { $atts['maillocal'] = $data['path']; $atts['mailhost'] = $data['host']; $atts['href'] = sprintf('mailto:%s@example.com', $data['path']); $atts['onmouseover'] = 'new WB.Obfuscate.Mailto(this).illuminate();'; $cData = implode("\n", $node['cData']); $cData = str_replace($this->dict->getWord(), $data['path'] . '(at)' . $data['host'], $cData); $node['cData'] = array($cData); $node['attributes'] = $atts; WBClass::load('WBHtml_JS'); WBHtml_JS::add('WB/Obfuscate'); WBHtml_JS::add('WB/Obfuscate/Mailto'); return true; } // others if ($data['protocol'] != 'self') { $atts['target'] = '_blank'; $node['attributes'] = $atts; return true; } // normal internal link if (strncmp('[[SERVICE_FILE]]', $data['path'], 16) != 0) { $node['attributes'] = $atts; return true; } // VFSFile $class = array(); if (isset($atts['class'])) { $class[] = $atts['class']; } // add mime type to class $href = explode('/', $data['path']); if (count($href) > 1) { $class[] = $href[1]; } if (!empty($class)) { $atts['class'] = implode(' ', $class); } $node['attributes'] = $atts; return true; } }