From a14ae4c5112740a1fb95f27026d37bc0ebe14a45 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 7 Jun 2017 10:14:04 +0000 Subject: [PATCH] fix #1455 @1 --- .../html5/master/class.ws.html5.compiler.php | 145 ++++++++++-------- .../html5/master/class.ws.html5.links.php | 31 ++-- 2 files changed, 94 insertions(+), 82 deletions(-) diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index 2d0375a4c..1285813e8 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -87,10 +87,10 @@ class wsHTML5Compiler { 'js/widget.js' ); - // Collection of LESS files to be compiled - // Filename with no extension, relative to the /style directory in the player build folder - public $lessFiles = ['fluidbook']; - public $lessFilesExtras = []; // Extra files that will be copied when compiling LESS (eg. used to allow video-js-core.css to be copied) + // Collection of LESS files to be compiled + // Filename with no extension, relative to the /style directory in the player build folder + public $lessFiles = ['fluidbook']; + public $lessFilesExtras = []; // Extra files that will be copied when compiling LESS (eg. used to allow video-js-core.css to be copied) public $specialCSS = array(); public $phonegapStandardPlugins = array('ios' => array('ExternalFileUtil'), @@ -363,16 +363,16 @@ class wsHTML5Compiler { public function getVideosFormats($poster = true) { $res = []; -// -// if (!$this->phonegap) { -// $res = array('ogv', 'webm', 'mp4', 'flv'); -// } elseif ($this->phonegap == 'ios') { -// $res = array('mp4'); -// } else if ($this->phonegap == 'android') { -// $res = array('webm', 'mp4'); -// } + // + // if (!$this->phonegap) { + // $res = array('ogv', 'webm', 'mp4', 'flv'); + // } elseif ($this->phonegap == 'ios') { + // $res = array('mp4'); + // } else if ($this->phonegap == 'android') { + // $res = array('webm', 'mp4'); + // } - $res[] = 'mp4'; + $res[] = 'mp4'; if ($poster) { $res[] = 'jpg'; @@ -429,37 +429,37 @@ class wsHTML5Compiler { file_put_contents($cacheFile, implode("\n", $lines)); } - /** - * Helper function to add a unique script entry to the JS stack. - * Normally this is a relative path but it can be an external URL. - * External URLs are added to the pluginJs collection instead of jsFiles. - * Duplicate paths are ignored. - * @param $path - */ - public function addJs($path) { - - // If JS is external, it will be included via the pluginJs collection - // Otherwise, it will be compiled into the main JS file - $collection = (preg_match('#^https?://#i', $path) === 1) ? 'pluginJs' : 'jsFiles'; - - if (!in_array($path, $this->$collection)) { - $this->{$collection}[] = $path; - } + /** + * Helper function to add a unique script entry to the JS stack. + * Normally this is a relative path but it can be an external URL. + * External URLs are added to the pluginJs collection instead of jsFiles. + * Duplicate paths are ignored. + * @param $path + */ + public function addJs($path) { + + // If JS is external, it will be included via the pluginJs collection + // Otherwise, it will be compiled into the main JS file + $collection = (preg_match('#^https?://#i', $path) === 1) ? 'pluginJs' : 'jsFiles'; + + if (!in_array($path, $this->$collection)) { + $this->{$collection}[] = $path; + } } - /** - * Helper function to add a unique stylesheet entry to the LESS stack for compilation - * Duplicate paths are ignored. - * @param $path The path of the file relative to the /style folder, without any extension - * @param $extra_files Optional array of extra files that should be copied across for use during LESS compilation - */ - public function addLess($path, $extra_files = []) { - if (!in_array($path, $this->lessFiles)) { - $this->lessFiles[] = $path; - } - - // Make sure no duplicates are added here either - $this->lessFilesExtras = array_unique(array_merge($this->lessFilesExtras, $extra_files)); + /** + * Helper function to add a unique stylesheet entry to the LESS stack for compilation + * Duplicate paths are ignored. + * @param $path The path of the file relative to the /style folder, without any extension + * @param $extra_files Optional array of extra files that should be copied across for use during LESS compilation + */ + public function addLess($path, $extra_files = []) { + if (!in_array($path, $this->lessFiles)) { + $this->lessFiles[] = $path; + } + + // Make sure no duplicates are added here either + $this->lessFilesExtras = array_unique(array_merge($this->lessFilesExtras, $extra_files)); } protected function writeIndex() { @@ -866,15 +866,18 @@ class wsHTML5Compiler { foreach ($finals as $jsfinal => $files) { $mintime = 0; - $minimized = $this->assets . '/js/' . $jsfinal . '-min.js'; + $hash = hash('sha256', json_encode($files)); + $minimized = $this->assets . '/js/min/' . $jsfinal . '-' . $hash . '-min.js'; + if (!file_exists(dirname($minimized))) { + mkdir(dirname($minimized)); + } if (file_exists($minimized)) { $mintime = filemtime($minimized); - } - - $reminimize = false; - if ($jsfinal == 'special') { + } else { + $mintime = 0; $reminimize = true; } + if (!$reminimize) { foreach ($files as $file) { if (filemtime($this->assets . '/' . $file) > $mintime) { @@ -891,7 +894,7 @@ class wsHTML5Compiler { } if ($reminimize) { - $js = ''; + $js = 'var files=' . json_encode($files) . ';'; foreach ($files as $file) { $js .= file_get_contents($this->assets . '/' . $file); $js .= ";\n\n"; @@ -905,7 +908,9 @@ class wsHTML5Compiler { $uglify->setArg('no-copyright'); $uglify->setArg(null, $tmp); $uglify->execute(); - //$uglify->debug(); + $uglify->debug(); + + } $dest = $this->vdir . '/data/' . $jsfinal . '.js'; copy($minimized, $dest); @@ -1343,30 +1348,38 @@ class wsHTML5Compiler { } file_put_contents($tmp . '/book-variables.less', implode("\n", $bookVariables)); - // Also copy any "extra" files that might be needed by LESS compilation - // (eg. video-js-core.css is needed by videojs.less) - foreach ($this->lessFilesExtras as $extra) { - $destination_extra = $tmp . '/' . $extra; - if (!is_dir(dirname($destination_extra))) mkdir(dirname($destination_extra)); - copy($this->assets . '/style/' . $extra, $destination_extra); - } + // Also copy any "extra" files that might be needed by LESS compilation + // (eg. video-js-core.css is needed by videojs.less) + foreach ($this->lessFilesExtras as $extra) { + $destination_extra = $tmp . '/' . $extra; + if (!is_dir(dirname($destination_extra))) { + mkdir(dirname($destination_extra), 0777, true); + } + copy($this->assets . '/style/' . $extra, $destination_extra); + } foreach ($this->lessFiles as $f) { - $source_less = $this->assets . '/style/' . $f . '.less'; - $destination_less = $tmp . '/' . $f . '.less'; - $destination_css = 'style/' . $f . '.css'; + $source_less = $this->assets . '/style/' . $f . '.less'; + $destination_less = $tmp . '/' . $f . '.less'; + $destination_css = 'style/' . $f . '.css'; - if (!file_exists($source_less)) continue; + if (!file_exists($source_less)) { + continue; + } - // LESS file might be in a subfolder, so create if it doesn't exist - if (!is_dir(dirname($destination_less))) mkdir(dirname($destination_less)); - // Generated CSS file might be in a subfolder, so create if it doesn't exist - if (!is_dir(dirname($this->vdir . '/' . $f . '.css'))) mkdir(dirname($this->vdir . '/' . $f . '.css')); + // LESS file might be in a subfolder, so create if it doesn't exist + if (!is_dir(dirname($destination_less))) { + mkdir(dirname($destination_less), 0777, true); + } + // Generated CSS file might be in a subfolder, so create if it doesn't exist + if (!is_dir(dirname($this->vdir . '/' . $f . '.css'))) { + mkdir(dirname($this->vdir . '/' . $f . '.css'), 0777, true); + } // Less files must be copied to temporary directory so they'll - // have access to the variables generated in book-variables.less - copy($source_less, $destination_less); + // have access to the variables generated in book-variables.less + copy($source_less, $destination_less); $less = new CubeIT_CommandLine('lessc'); $less->setArg('plugin', 'less-plugin-clean-css'); $less->setArg(null, $destination_less); diff --git a/inc/ws/Util/html5/master/class.ws.html5.links.php b/inc/ws/Util/html5/master/class.ws.html5.links.php index 91111a9a7..174c45f26 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -506,11 +506,10 @@ class internalLink extends normalLink { } class videoLink extends wsHTML5Link { - - public static function addVideoJS($compiler) { - $compiler->addJs('js/libs/videojs/video.js'); - $compiler->addLess('videojs/videojs', ['videojs/video-js-core.css']); - } + public static function addVideoJS($compiler) { + $compiler->addJs('js/libs/videojs/video.js'); + $compiler->addLess('videojs/videojs', ['videojs/video-js-core.css']); + } public function getClasses() { return array_merge(['videoLink'], parent::getClasses()); @@ -518,7 +517,6 @@ class videoLink extends wsHTML5Link { public function getHTMLContent() { - static::addVideoJS($this->compiler); $this->copyExternalFile($this->to, true); @@ -529,6 +527,7 @@ class videoLink extends wsHTML5Link { } public static function makeVideoTag($linkDatas, $w = null, $h = null, $compiler = null) { + static::addVideoJS($compiler); $attributes = static::getVideoAttributes($linkDatas, $w, $h, $compiler); @@ -694,8 +693,8 @@ class webVideoLink extends videoLink { public function getHTMLContent() { if ($this->video_service !== 0) { - return $this->getEmbed(); - } + return $this->getEmbed(); + } $w = round($this->width * $this->getCssScale()); $h = round($this->height * $this->getCssScale()); @@ -996,7 +995,7 @@ class webVideoPopupLink extends videoPopupLink { public function getURL() { return '#/video/' . $this->to; - } + } public function getAdditionnalContent() { $this->video_auto_start = true; // Videos should always autoplay @@ -1251,13 +1250,13 @@ class zoomLink extends normalLink { $this->compiler->simpleCopyLinkFile($both, 'data/links/zoom_' . $this->id . '.jpg'); - // Perform tidy up and delete temporary files if they exist - $files_to_delete = ['left', 'leftfile', 'right', 'rightfile', 'both']; - foreach($files_to_delete as $file) { - if (isset($$file) && file_exists($$file)) { - unlink($$file); - } - } + // Perform tidy up and delete temporary files if they exist + $files_to_delete = ['left', 'leftfile', 'right', 'rightfile', 'both']; + foreach ($files_to_delete as $file) { + if (isset($$file) && file_exists($$file)) { + unlink($$file); + } + } } -- 2.39.5