* @license PHP License * @package wb * @subpackage Markup */ WBClass::load('WBMarkup_Converter'); /** * Tag converter for simple link tags. * * Convert node to node. * Reads and converts simple hyper-links. The newer convert Url provides the same * features but utilizes the Dictionary-URL. Therefore the usage of this converter * is not recommended. * * @deprecated Content Fetcher was used in Wombat version 1.x * @see WBMarkup_Converter_Wb_Url * @version 0.2.2 * @package wb * @subpackage Markup */ class WBMarkup_Converter_Wb_A extends WBMarkup_Converter { /** * 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' => 'a', 'attributes' => array(), 'isEmpty' => $node['isEmpty'], 'cData' => $node['cData'] ); $atts = array( 'type' => 'external', 'href' => $node['attributes']['href'], 'title' => $node['attributes']['wb:value'] ); if (isset($node['attributes']['class'])) { $atts['class'] = $node['attributes']['class']; } // html service $service = WBString::replaceSuperPlaceholders('[[SERVICE_HTML]]'); // URL relative to base URL if ($atts['href'][0] == '/') { $atts['type'] = 'internal'; } // complete URL else if (strncmp($atts['href'], $service, strlen($service)) == 0) { $atts['href'] = substr($atts['href'], strlen($service)); $atts['type'] = 'internal'; } else if (!preg_match('#^\w+://#', $atts['href'])) { $atts['type'] = 'internal'; } else { // file service $service = WBString::replaceSuperPlaceholders('[[SERVICE_FILE]]'); if (strncmp($atts['href'], $service, strlen($service)) == 0) { $atts['href'] = substr($atts['href'], strlen($service)); $atts['type'] = 'vfsfile'; } } // strip default type from XML if ($atts['type'] == 'internal') { unset($atts['type']); } $xml['attributes'] = $atts; $node = $xml; return true; // remove superglobal placeholder switch ($atts['type']) { case 'internal': $service = $this->getConfigService('html'); $atts['href'] = substr($atts['href'], strlen($service)); break; case 'vfsfile': $service = $this->getConfigService('file'); $atts['href'] = substr($atts['href'], strlen($service)); // strip mime-type and extension from class if (isset($atts['class'])) { $uri = explode('/', $atts['href']); $class = array_flip(explode(' ', $atts['class'])); // remove filetype if (isset($uri[2]) && isset($class[$uri[2]])) { unset($class[$uri[2]]); } // remove extension if (isset($uri[3])) { $ext = explode('.', $uri[3]); if (is_array($ext)) { $ext = array_pop($ext); if (isset($class[$ext])) { unset($class[$ext]); } } } $class = array_flip($class); $atts['class'] = implode(' ', $class); if (empty($atts['class'])) { unset($atts['class']); } } break; default: break; } // strip default type from XML if ($atts['type'] == 'internal') { unset($atts['type']); } $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'] ); $atts = array( 'wb:dialog' => 'a', 'wb:value' => $node['attributes']['title'], 'href' => $node['attributes']['href'], 'target' => '_blank' ); $atts = array_merge($this->getDefaultAttributes(WBMarkup_Converter::TARGET_WXML), $atts); if (isset($node['attributes']['class'])) { $atts['class'] = $node['attributes']['class']; } // set default type if (!isset($atts['type'])) { $atts['type'] = 'internal'; } switch ($atts['type']) { case 'external': break; case 'vfsfile': $atts['href'] = ltrim($atts['href'], '/'); $atts['href'] = '[[SERVICE_FILE]]' . $atts['href']; break; case 'internal': default: $atts['href'] = ltrim($atts['href'], '/'); $atts['href'] = '[[SERVICE_HTML]]' . $atts['href']; break; } $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) { $html = array( 'ns' => null, 'tag' => 'a', 'attributes' => array(), 'isEmpty' => $node['isEmpty'], 'cData' => $node['cData'] ); // merge with default attributes $attsDef = array( 'type' => '', 'href' => '', 'title' => '', 'class' => '' ); $node['attributes'] = array_merge($attsDef, $node['attributes']); // html attributes $atts = array( 'title' => $node['attributes']['title'], 'href' => $node['attributes']['href'] ); if (strlen($node['attributes']['class'])) { $atts['class'] = $node['attributes']['class']; } switch (strtolower($node['attributes']['type'])) { case 'external': $atts['target'] = '_blank'; break; case 'vfsfile': $atts['href'] = ltrim($atts['href'], '/'); $class = array(); if (isset($atts['class'])) { $class[] = $atts['class']; } // add mime type to class $href = explode('/', $atts['href']); if (count($href) > 1) { $class[] = $href[1]; } // add file extension to class $href = explode('.', end($href)); if (count($href) > 1) { $class[] = array_pop($href); } if (!empty($class)) { $atts['class'] = implode(' ', $class); } $atts['href'] = '[[SERVICE_FILE]]' . $atts['href']; break; case 'internal': default: $atts['href'] = ltrim($atts['href'], '/'); $atts['href'] = '[[SERVICE_HTML]]' . $atts['href']; break; } // pass reference to just created html node $html['attributes'] = $atts; $node = $html; return true; } }