* @license PHP License * @package wb * @subpackage Markup */ WBClass::load('WBMarkup_Converter'); /** * Tag converter * * Convert node to node * * @version 0.1.0 * @package wb * @subpackage Markup */ class WBMarkup_Converter_Cf_Fetcher extends WBMarkup_Converter { /** * URL dictionary * @var WBDictionary_Url */ protected $dict; /** * transform Xinha Tags to XML * * @todo implement this method * @param array $node to be modified document node * @return bool true on success */ public function toXml(&$node) { } /** * transform Xml to WXml (html) tags * * @todo implement this method * @param array $node to be modified document node * @return bool true on success */ public function toWxml(&$node) { $xinha = array( 'ns' => '', 'tag' => 'a', 'attributes' => array(), 'isEmpty' => false, 'cData' => $node['cData'] ); list($type, $uri) = explode('://', $node['attributes']['url']); $type = strtolower($type); if ('link' != $type) { WBClass::load('WBException_Xml'); throw new WBException_Xml('Unkonwn type "' . $type . '" to convert!', 1, __CLASS__); $node = $xinha; return false; } $this->dict = WBClass::create('WBDictionary_URL'); list($proto, $url, $cData) = explode('/', $uri); $proto = strtolower($proto); $url = htmlspecialchars_decode(str_replace('|', '/', $url)); $xinha['cData'][] = $cData; switch ($proto) { case 'wikipedia': $url = 'http://' . $url; $p = parse_url($url); parse_str($p['query'], $query); if (isset($query[`title`])) { $title = 'Wikipedia Article "' . $query[`title`] . '"'; } else { $title = 'Wikipedia Article'; } break; case 'path': /** * @todo do something useful */ $title = htmlspecialchars($cData); $url = '#' . $url; break; default: $title = htmlspecialchars($url); $url = $proto . '://' . $url; break; } $this->dict->addWord($url); $atts = array( 'wb:dialog' => 'url', 'wb:value' => $title, 'href' => $this->dict->getWord(), 'urlid' => $this->dict->getid(), 'title' => 'Double click to edit', 'target' => '_blank' ); $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) { list($type, $uri) = explode('://', $node['attributes']['url']); $type = strtolower($type); $copy = $node; $node = array( 'ns' => null, 'tag' => null, 'attributes' => array(), 'isEmpty' => $copy['isEmpty'], 'cData' => $copy['cData'] ); switch ($type) { case 'link': $node['tag'] = 'a'; list($proto, $url, $cData) = explode('/', $uri); $proto = strtolower($proto); $url = htmlspecialchars_decode(str_replace('|', '/', $url)); $node['isEmpty'] = false; $node['cData'][] = $cData; switch ($proto) { case 'wikipedia': $url = 'http://' . $url; $p = parse_url($url); parse_str($p['query'], $query); if (isset($query[`title`])) { $title = $query[`title`]; } $node['attributes']['title'] = 'Wikipedia Article "' . $title . '"'; $node['attributes']['target'] = '_blank'; break; case 'http'; $url = 'http://' . $url; $node['attributes']['title'] = 'Visit site "' . htmlspecialchars($url) . '"'; $node['attributes']['target'] = '_blank'; break; case 'ftp': $url = 'ftp://' . $url; $node['attributes']['title'] = 'FTP download "' . htmlspecialchars($url) . '"'; $node['attributes']['target'] = '_blank'; break; case 'path': /** * @todo do something useful */ $url = '#' . $url; $node['attributes']['title'] = htmlspecialchars($cData); break; default: echo $proto . "
" . var_export( $copy, true ) . "\n"; break; } $node['attributes']['href'] = $url; break; default: WBClass::load('WBException_Xml'); throw new WBException_Xml('Unkonwn type "' . $type . '" to convert!', 1, __CLASS__); break; } } }