* @license PHP License * @package wb * @subpackage Markup */ WBClass::load('WBMarkup_Converter'); /** * Tag converter * * Convert node to node * * @deprecated Vfsfile ist the successor for this class * @version 0.2.1 * @package wb * @subpackage Markup */ class WBMarkup_Converter_Wb_Media extends WBMarkup_Converter { /** * 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) { $xml = array( 'ns' => 'wb', 'tag' => 'media', 'attributes' => array(), 'isEmpty' => true, 'cData' => array() ); $size = array(200, 200); if (isset($node['attributes']['width'])) { $width = intval($node['attribute']['width']); $width = max($width, 400); $size[0] = $width; } if (isset($node['attributes']['height'])) { $height = intval($node['attribute']['height']); $height = max($height, 400); $size[0] = $height; } $atts = array( 'src' => ltrim($node['attributes']['wb:value'], '/'), 'size' => implode('x',$size), 'title' => $node['attributes']['title'] ); if (isset($node['attributes']['class'])) { $atts['class'] = $node['attributes']['class']; } return true; } /** * 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) { $wxml = array( 'ns' => '', 'tag' => 'img', 'attributes' => array(), 'isEmpty' => true, 'cData' => array() ); $size = '200x200'; if (isset($node['attributes']['size'])) { $size = $node['attributes']['size']; } $src = '[[SERVICE_FILE]]' . ltrim($node['attributes']['src'], '/') . '?size=' . $size; $atts = array( 'wb:dialog' => 'media', 'wb:value' => $node['attributes']['src'], 'src' => $src, 'alt' => $node['attributes']['src'], 'title' => $node['attributes']['title'] ); $atts = array_merge($this->getDefaultAttributes(WBMarkup_Converter::TARGET_WXML), $atts); 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) { $video = false; $html = array( 'ns' => null, 'tag' => 'img', 'attributes' => array(), 'isEmpty' => true, 'cData' => null ); // merge with default attributes $attsDef = array( 'src' => '', 'title' => '', 'class' => '', 'size' => '', ); $node['attributes'] = array_merge($attsDef, $node['attributes']); // html attributes $atts = array( 'title' => $node['attributes']['title'], ); if (strlen($node['attributes']['class'])) { $atts['class'] = $node['attributes']['class']; } // extract vfsfile $src = ltrim( $node['attributes']['src'], '/'); /* * valid mime types are either "image" or "video" all other mime * type will become "image" */ $mime = explode('/', $src); $atts['alt'] = end($mime); if (count($mime) > 2) { if($mime[2] == 'video') { $video = true; } else if($mime[2] != 'image') { $mime[2] = 'image'; $atts['src'] = implode('/', $mime); } } if ($video) { // @todo implament video feature // pass reference to just created html node $html['attributes'] = $atts; $node = $html; return true; } $size = array(); if (strlen($node['attributes']['size'])) { $size = explode('x', $node['attributes']['size']); if (count($size) != 2) { $size = array(); } } // finalize src /* if (!empty($size)) { $src .= '?' . implode('x', $size); $atts['width'] = $size[0]; $atts['height'] = $size[1]; } */ $atts['src'] = '[[SERVICE_FILE]]' . $src; // pass reference to just created html node $html['attributes'] = $atts; $node = $html; return true; } }