* @license PHP License * @package wb * @subpackage Markup */ WBClass::load('WBMarkup_Converter'); /** * Tag converter * * Embed * * @version 0.2.0 * @package wb * @subpackage Markup */ class WBMarkup_Converter_Wb_Embed extends WBMarkup_Converter { const CSS_CLASS_WXML = 'wb-wxml-dialog wb-wxml-dialog-embed'; const CSS_CLASS_HTML = 'wb-wxml wb-wxml-embed'; /** * URL dictionary * @var WBDictionary_Url */ protected $dict; /** * 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) { $cData = trim(strip_tags(implode('', $node['cData']))); $xml = array( 'ns' => 'wb', 'tag' => 'embed', 'attributes' => array(), 'isEmpty' => $node['isEmpty'], 'cData' => array($cData) ); $atts = array( 'title' => $node['attributes']['wb:value'], 'urlid' => $node['attributes']['urlid'], 'class' => $node['attributes']['class'] ); // strip internal classes if (0 == strncmp($this::CSS_CLASS_WXML, $atts['class'], strlen($this::CSS_CLASS_WXML))) { $atts['class'] = trim(substr($atts['class'], strlen($this::CSS_CLASS_WXML))); } $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' => 'div', 'attributes' => array(), 'isEmpty' => $node['isEmpty'], 'cData' => $node['cData'] ); $atts = array( 'wb:dialog' => 'embed', 'wb:value' => $node['attributes']['title'], 'class' => self::CSS_CLASS_WXML . ' ' . $node['attributes']['class'], 'urlid' => $node['attributes']['urlid'] ); $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) { if (empty($this->dict)) { $this->dict = WBClass::create('WBDictionary_URL'); } try { $this->dict->load($node['attributes']['urlid']); } catch(WBException $e) { $node['ns'] = ''; $node['tag'] = 'div'; $atts = array( 'title' => $node['attributes']['title'], ); $node['attributes'] = $atts; $node['cData'] = array('invalid emded URL'); return $node; } if (!$this->loadTemplates('default')) { $node['ns'] = ''; $node['tag'] = 'iframe'; $atts = array( 'title' => $node['attributes']['title'], 'src' => $this->dict->getWord(), ); if (isset($node['attributes']['class']) && strlen($node['attributes']['class'])) { $atts['class'] = self::CSS_CLASS_HTML . ' ' . $node['attributes']['class']; } $atts['allow'] = 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'; $atts['frameborder'] = 0; $node['attributes'] = $atts; return true; } $data = $this->dict->get(); $data['title'] = $node['attributes']['title']; $data['class'] = $node['attributes']['class']; $data['href'] = $this->dict->getWord(); $data['cdata'] = implode(' ', $node['cData']); $data['href'] = WBString::replaceSuperPlaceholders($data['href']); $this->template2HtmlNode($node, $data); return true; } }