From f24a6982891c067f657220b199f13ce30d587dd4 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 17 Jul 2013 08:49:50 +0000 Subject: [PATCH] --- inc/ws/Util/html5/class.ws.html5.compiler.php | 12 ++- inc/ws/Util/html5/class.ws.html5.links.php | 95 ++++++++++++++----- 2 files changed, 80 insertions(+), 27 deletions(-) diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php index 5355fd083..6244f5c87 100644 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/class.ws.html5.compiler.php @@ -383,14 +383,14 @@ class wsHTML5Compiler { $lines[] = 'CACHE:'; $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dest), RecursiveIteratorIterator::SELF_FIRST); - - $exclude=array('index.html','indexu.html','widget.html','indext.html'); - + + $exclude = array('index.html', 'indexu.html', 'widget.html', 'indext.html'); + foreach ($iterator as $path) { if (!$path->isFile()) { continue; } - + $p = str_replace($dest . '/', '', $path); if (in_array($p, $exclude)) { continue; @@ -1206,6 +1206,10 @@ class wsHTML5Compiler { return $str; } + public function copyLinkDir($source, $dest) { + `cp -a $source $this->vdir/$dest`; + } + public function copyLinkFile($source, $dest, $video = false) { if ($video && $this->book->parametres->mobileVideosPath != '') { return; diff --git a/inc/ws/Util/html5/class.ws.html5.links.php b/inc/ws/Util/html5/class.ws.html5.links.php index 8bad840b2..c66544003 100644 --- a/inc/ws/Util/html5/class.ws.html5.links.php +++ b/inc/ws/Util/html5/class.ws.html5.links.php @@ -23,6 +23,11 @@ class wsHTML5Link { public $display_area; public $infobulle; public $id; + + /** + * + * @var wsHTML5Compiler + */ public $compiler; /** @@ -127,8 +132,12 @@ class wsHTML5Link { $this->compiler->copyLinkFile($file, 'data/links/', $video); } - public function unzipFile($file) { - $fdir = 'data/links/' . $this->id; + public function copyExternalDir($dir) { + $this->compiler->copyLinkDir($dir, 'data/links'); + } + + public function unzipFile($file, $moveAssets = false) { + $fdir = 'data/links/' . $file; $dir = $this->compiler->vdir . '/' . $fdir; if (!file_exists($dir)) { mkdir($dir, 0777, true); @@ -137,6 +146,12 @@ class wsHTML5Link { $unzip->setArg(null, $this->compiler->wdir . '/' . $file); $unzip->setArg('d', $dir); $unzip->execute(); + + if ($moveAssets) { + `mv $dir/Assets/* $dir`; + rmdir($dir . '/Assets'); + } + return array('dir' => $dir, 'fdir' => $fdir); } @@ -426,31 +441,65 @@ class multimediaLink extends wsHTML5Link { class htmlMultimediaLink extends wsHTML5Link { + protected $_config = null; + protected $_content = ''; + public function getHTMLContent() { - $d = $this->unzipFile($this->to); - $w = $this->width * $this->getCssScale(); - $h = $this->height * $this->getCssScale(); + if ($this->_content == '') { + $d = $this->unzipFile($this->to, true); - $dr = opendir($d['dir']); - while ($file = readdir($dr)) { - if ($file == '.' || $file == '..') { - continue; - } + $this->_config = $this->getConfig($d['dir']); + + + $this->_correctFiles($d['dir']); + + $w = $this->width * $this->getCssScale(); + $h = $this->height * $this->getCssScale(); - $ext = files::getExtension($file); - - if ($ext == 'js') { - $this->compiler->pluginJs[] = $d['fdir'] . '/' . $file; - $e = explode('.', $file); - $name = $e[0]; - $code = '$("#l_' . $this->id . '").' . $name . '();'; - $this->compiler->htmlmultimedia[] = $code; - } else if ($ext == 'css') { - $this->compiler->pluginCSS[] = $d['fdir'] . '/' . $file; - } else if ($ext == 'html') { - $res = file_get_contents($d['dir'] . '/' . $file); - unlink($d['dir'] . '/' . $file); + $res = ''; + $res.=$this->_config['content']; + + $this->copyExternalDir($d['dir']); + $this->_content = $res; + } + return $this->_content; + } + + protected function _correctFiles($dir) { + + $preloadFile = $d['dir'] . '/' . $this->_config['name'] . '_edgePreload.js'; + $preload = file_get_contents($preloadFile); + $preload = str_replace('load:"', 'load:"data/links/' . $this->to . '/', $preload); + file_put_contents($preloadFile, $preload); + } + + protected function _correctFile($file) { + $content = file_get_contents($file); + + file_put_contents($file, $content); + } + + public function getConfig($d) { + $x = simplexml_load_file($d . '/config.xml'); + $config = (string) $x->oamfile['src']; + $config = str_replace('/Assets', '', $d . '/' . $config); + $x = simplexml_load_file($config, 'SimpleXMLElement', LIBXML_NOCDATA); + $c = CubeIT_Util_Xml::toObject($x); + + $props = array('default-width' => 'width', 'default-height' => 'height'); + + + $res = array('content' => trim($c->content), 'name' => $c->_name, 'assets' => array()); + foreach ($c->properties->property as $p) { + if (isset($props[$p->_name])) { + $res[$props[$p->_name]] = $p->_defaultValue; + } + } + foreach ($c->require as $r) { + if ($r->_type == 'folder') { + continue; } + $res['assets'][] = $r->_src; } return $res; -- 2.39.5