<?php
 set_include_path( dirname(__FILE__). '/services' . PATH_SEPARATOR . dirname(__FILE__). '/services/vo' . PATH_SEPARATOR . get_include_path() ); class SimpleMediaPlayerRender { private $content, $structure, $config; private $service = null; private $parent = null; function __construct($parent) { $this->content = $parent->getContent(); $this->structure = $parent->getStructure(); $this->config = $parent->getConfig(); $this->parent = $parent; } function renderModule($id) { if (is_null($this->service)) $this->service = new SimpleMediaPlayerModuleService(); $data = array('structure' => null, 'data' => null); $moduleVO = ModuleVO::findById($id, $this->content); $xmlfilename = ''; $checkDom = new MotoXML(); $checkDom->loadXML($moduleVO->data); $data = array( 'data' => array(), 'style' => array( 'width' => $moduleVO->width, 'height' => $moduleVO->height, 'x' => $moduleVO->x, 'y' => $moduleVO->y, ), ); $root = MotoXML::findOneByXPath('.', $checkDom); if ( $root == null ) return ''; $nodes = MotoXML::findByXPath('./*', $root); if ( $nodes == null ) return ''; foreach($nodes as $node) { $data['data'][$node->nodeName] = $node->nodeValue; } $html = $this->renderHtml($data); return $this->renderHtml($data); } function get($obj, $name, $default = null) { if (is_array($obj) ) return ( isset($obj[$name]) ? $obj[$name] : $default ); if (is_object($obj) ) return ( isset($obj->$name) ? $obj->$name : $default ); return $default; } protected function _render_youTubeVideo($module) { $data = $this->get($module, 'data'); $html = ''; $style = $this->get($module, 'style'); $html .= '<iframe width="' . $this->get($style, 'width', 320) . '" height="' . $this->get($style, 'height', 192) . '" src="http://www.youtube.com/embed/' . $this->get($data, 'source') . '" frameborder="0"' . ( $this->get($data, 'fullScreenMode', '') != 'disable' ? ' allowfullscreen' : '') . '></iframe>'; return $html; } function renderHtml($module) { $data = $this->get($module, 'data'); if ($data == null) return ''; $html = ''; $method_name = '_render_' . $this->get($data, 'mediaType', ''); if (method_exists($this, $method_name)) { $html .= "\n".'	<div class="simpleMediaPlayerModule ' . $this->get($data, 'mediaType', '') . '">'; $html .= $this->$method_name($module); $html .= '</div>'."\n"; } return $html; } function render($tmpl, $data) { $vars = explode(',', '%' . implode("%,%", array_keys($data)) . '%'); $values = array_values($data); return str_replace($vars, $values, $tmpl); } } 