* @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_Wb_Smiley 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' => 'smiley', 'attributes' => array(), 'isEmpty' => false, 'cData' => array($node['attributes']['wb:value']) ); $atts = array( 'size' => '16', ); // extract smiley size from class if (isset($node['attributes']['class']) && !empty($node['attributes']['class'])) { $class = explode(' ', trim($node['attributes']['class'])); if (preg_match('/^\smiley(\d+)$/', $class[0], $match)) { $atts['size'] = intval($match[1]); array_shift($class); } } $xml['attributes'] = $atts; $node = $xml; 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() ); $value = implode('', $node['cData']); $size = $node['attributes']['size']; $atts = array( 'wb:dialog' => 'smiley', 'wb:value' => $value, 'class' => 'smiley' . $size . ' ' . $value, 'src' => '[[DOCROOT]]/s/px.gif', 'alt' => $value, 'width' => $size, 'height' => $size ); $atts = array_merge($this->getDefaultAttributes(WBMarkup_Converter::TARGET_WXML), $atts); $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' => 'img', 'attributes' => array( 'class' => 'smiley16', 'src' => '[[DOCROOT]]/s/px.gif', 'width' => '16', 'height' => '16', 'alt' => 'smiley', 'title' => 'smiley', 'onmouseover' => 'new WB.Tooltip(this).smiley();' ), 'isEmpty' => true, 'cData' => array() ); // size $size = '16'; if (isset($node['attributes']['size']) && !empty($node['attributes']['size'])) { $size = $node['attributes']['size']; $html['attributes']['width'] = $size; $html['attributes']['height'] = $size; } // emoticon $smiley = trim(implode(' ', $node['cData'])); $html['attributes']['alt'] = $smiley; $html['attributes']['title'] = $smiley; // class $class = 'smiley'; if (isset($node['attributes']['class']) && !empty($node['attributes']['class'])) { $class = $node['attributes']['class']; } $html['attributes']['class'] = $class . $size . ' ' . $smiley; $node = $html; return true; } }