]> _ Git - cubeextranet.git/commitdiff
WIP #897
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 30 May 2017 16:59:02 +0000 (16:59 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 30 May 2017 16:59:02 +0000 (16:59 +0000)
inc/ws/Util/html5/html5video/class.ws.html5.compiler.php
inc/ws/Util/html5/html5video/class.ws.html5.links.php

index d5e2bdf5f813e55e4e9215a85af20ce106a038db..dd5782561da743f68521a70724f57c944f02f28f 100644 (file)
@@ -350,14 +350,18 @@ class wsHTML5Compiler {
                array_push($this->jsFiles, $main);
        }
 
-       protected function getVideosFormats($poster = true) {
-               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');
-               }
+       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');
+//             }
+
+        $res[] = 'mp4';
 
                if ($poster) {
                        $res[] = 'jpg';
@@ -414,7 +418,36 @@ class wsHTML5Compiler {
                file_put_contents($cacheFile, implode("\n", $lines));
        }
 
-       protected function writeIndex($numCSS) {
+    /**
+     * 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 CSS stack
+     * Duplicate paths are ignored.
+     * @param $path
+     */
+    public function addCSS($path) {
+        if (!in_array($path, $this->pluginCSS)) {
+            $this->pluginCSS[] = $path;
+        }
+       }
+
+    protected function writeIndex($numCSS) {
                global $core;
 
                $html = file_get_contents($this->assets . '/_index.html');
@@ -454,7 +487,7 @@ class wsHTML5Compiler {
                for ($i = 0; $i < $numCSS; $i++) {
                        $sheets[] = 'data/style/style_' . $i . '.css';
                }
-               $sheets = array_merge($sheets, $this->pluginCSS, $this->specialCSS);
+               $sheets = array_merge($this->pluginCSS, $this->specialCSS, $sheets);
 
                $style = array();
                foreach ($sheets as $sheet) {
@@ -493,12 +526,6 @@ class wsHTML5Compiler {
                $description = '<meta name="description" content="' . html::escapeHTML(isset($this->book->parametres->seoDescription) && $this->book->parametres->seoDescription ? $this->book->parametres->seoDescription : $titre . ' - Powered by Fluidbook') . '">';
 
 
-        if ($this->version == 'html5video|local') {
-            $script .= '<script src="https://vjs.zencdn.net/5.19.2/video.js"></script>';
-            $script .= '<link href="https://vjs.zencdn.net/5.19.2/video-js.css" rel="stylesheet">';
-        }
-
-
                $favicon = '';
                if ($this->theme->parametres->favicon != '') {
                        copy($this->themeRoot . '/' . $this->theme->parametres->favicon, $this->vdir . '/data/favicon.png');
index 24e4b6a0991d0f119f39a4e9bc69c85eae2995e8..2327439d498c16605b3f24943de251a93e49fded 100644 (file)
@@ -52,15 +52,10 @@ class wsHTML5Link {
                        case 5:
                                return new internalLink($id, $init, $compiler);
                        case 4:
-                if ($compiler->version == 'stable') {
-                    if ($init['inline']) {
-                        return new videoLink($id, $init, $compiler);
-                    } else {
-                        return new videoPopupLink($id, $init, $compiler);
-                    }
+                if ($init['inline']) {
+                    return new videoLink($id, $init, $compiler);
                 } else {
-                    // ToDo: handle popup mode
-                    return new videoLinkV2($id, $init, $compiler);
+                    return new videoPopupLink($id, $init, $compiler);
                 }
                        case 7:
                                switch ($compiler->book->parametres->customLinkClass) {
@@ -512,17 +507,38 @@ class internalLink extends normalLink {
 
 class videoLink extends wsHTML5Link {
 
-       public function getHTMLContent() {
+    public static function addVideoJS($compiler) {
+        $compiler->addJs('js/libs/videojs/video.js');
+        $compiler->addCSS('style/videojs/videojs.css');
+    }
+
+    public function getClasses() {
+        return array_merge(['videoLink'], parent::getClasses());
+    }
+
+    public function getHTMLContent() {
+
+        static::addVideoJS($this->compiler);
+
                $this->copyExternalFile($this->to, true);
 
                $w = round($this->width * $this->getCssScale());
                $h = round($this->height * $this->getCssScale());
 
-               return self::makeVideoTag($this, $w, $h, $this->compiler);
+               return $this->makeVideoTag($this, $w, $h, $this->compiler);
        }
 
        public static function makeVideoTag($linkDatas, $w = null, $h = null, $compiler = null) {
-               return '<div class="videoContainer" '. $this->getVideoAttributes($linkDatas, $w, $h, $compiler) .'></div>';
+
+        $attributes = static::getVideoAttributes($linkDatas, $w, $h, $compiler);
+
+        $res  = '<div class="videoContainer"';
+        foreach ($attributes as $name => $value) {
+            $res .= " data-{$name}='{$value}'";
+        }
+        $res .= '></div>';
+
+        return $res;
        }
 
     public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null) {
@@ -532,28 +548,24 @@ class videoLink extends wsHTML5Link {
         $ext = array_pop($e);
         $basename = implode('.', $e);
 
-        $autoplay = ($data->video_auto_start ? '1' : '0');
-        $controls = ($data->video_controls ? '1' : '0');
-        $loop = ($data->video_loop ? '1' : '0');
-        $sound = ($data->video_sound_on ? '1' : '0');
-
-        $res = '';
+        $attr['name'] = $basename;
+        $attr['id'] = 'video_' . $data->id;
+        $attr['autoplay'] = ($data->video_auto_start ? '1' : '0');
+        $attr['controls'] = ($data->video_controls ? '1' : '0');
+        $attr['loop'] = ($data->video_loop ? '1' : '0');
+        $attr['sound'] = ($data->video_sound_on ? '1' : '0');
 
         if (!is_null($w) && !is_null($h)) {
-            $res .= 'data-width="' . $w . '" data-height="' . $h . '" ';
+            $attr['width'] = $w;
+            $attr['height'] = $h;
         } else if (!is_null($compiler)) {
-
             $path = WS_BOOKS . '/working/' . $compiler->book_id . '/' . $basename . '.jpg';
             $dim = getimagesize($path);
-            $res .= 'data-width="' . $dim[0] . '" data-height="' . $dim[1] . '" ';
+            $attr['width'] = $dim[0];
+            $attr['height'] = $dim[1];
         }
-        $res .= ' data-autoplay="' . $autoplay . '"';
-        $res .= ' data-controls="' . $controls . '"';
-        $res .= ' data-loop="' . $loop . '"';
-        $res .= ' data-sound="' . $sound . '"';
-        $res .= ' data-name="' . $basename . '"';
 
-        return $res . ' ';
+        return $attr;
        }
 
 }
@@ -571,6 +583,7 @@ class videoPopupLink extends normalLink {
        }
 
        public function getAdditionnalContent() {
+        $this->video_auto_start = true; // Videos should always autoplay
                return ' data-video="' . rawurlencode(videoLink::makeVideoTag($this, $this->video_width, $this->video_height, $this->compiler)) . '" ';
        }
 
@@ -584,25 +597,6 @@ class videoPopupLink extends normalLink {
 
 }
 
-class videoLinkV2 extends videoPopupLink {
-
-    public function getClasses() {
-        return array_merge(['videoPopupLink'], parent::getClasses());
-    }
-
-    public function getURL() {
-
-        // Todo: Copy files...
-
-        return '#';
-    }
-
-    public function getAdditionnalContent() {
-        return videoLink::getVideoAttributes($this, $this->video_width, $this->video_height, $this->compiler);
-    }
-
-
-}
 
 
 class audioPopupLink extends normalLink {
@@ -633,8 +627,78 @@ class audioPopupLink extends normalLink {
 
 class webVideoLink extends videoLink {
 
-       public function getHTMLContent() {
-               return $this->getEmbed();
+    public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null) {
+        $attributes =  parent::getVideoAttributes($data, $w, $h, $compiler);
+
+        // Since the admin interface doesn't offer options for setting controls or sound, we will set some defaults here
+        $attributes['controls'] = '1';
+        $attributes['sound'] = '1';
+
+        $attributes['setup'] = static::getVideoSetup($data, $compiler);
+
+        return $attributes;
+    }
+
+    public static function getVideoSetup($data, $compiler) {
+
+        static::addVideoJS($compiler); // Ensure videoJS core is included first
+
+        switch($data->video_service) {
+            case 0: // YouTube
+                $compiler->addJs('js/libs/videojs/Youtube.js');
+//                $compiler->addJs('https://rawgit.com/videojs/videojs-youtube/master/dist/Youtube.js');
+                $setup = [
+                            'techOrder' => ['youtube'],
+                            'sources' => [
+                                [
+                                    'type' => 'video/youtube',
+                                    'src' => 'https://www.youtube.com/watch?v=' . $data->to
+                                ]
+                            ]
+                        ];
+                break;
+            case 1: // Dailymotion
+                // Todo: add local version of script...
+                // Note: this plugin doesn't seem to work currently so it is not included
+                //$compiler->addJs('https://rawgit.com/benjipott/video.js-dailymotion/master/dist-test/videojs-dailymotion.js');
+                $setup = [
+//                    'techOrder' => ['dailymotion'],
+//                    'sources' => [
+//                        [
+//                            'src' => 'http://www.dailymotion.com/video/' . $data->to
+//                        ]
+//                    ]
+                ];
+                break;
+            case 2: // Vimeo
+                // Todo: add local version of script...
+                // Note: Vimeo plugin doesn't seem to be working currently - might need updates to work with latest VideoJS module
+                //$compiler->addJs('https://rawgit.com/videojs/videojs-vimeo/master/dist/videojs-vimeo.min.js');
+                $setup = [
+//                    'techOrder' => ['vimeo'],
+//                    'sources' => [
+//                        [
+//                            'type' => 'vimeo/vimeo',
+//                            'src' => 'https://www.vimeo.com/' . $data->to
+//                        ]
+//                    ]
+                ];
+                break;
+            default:
+                $setup = [];
+        }
+
+        return json_encode($setup, JSON_UNESCAPED_SLASHES);
+
+    }
+
+    public function getHTMLContent() {
+               //return $this->getEmbed();
+
+        $w = round($this->width * $this->getCssScale());
+        $h = round($this->height * $this->getCssScale());
+
+        return $this->makeVideoTag($this, $w, $h, $this->compiler);
        }
 
        public function getEmbed() {
@@ -914,18 +978,27 @@ class htmlMultimediaLink extends wsHTML5Link {
 
 class webVideoPopupLink extends videoPopupLink {
 
-       public function getURL() {
-               if ($this->video_service == 0) {
-                       $service = 'youtube';
-               } elseif ($this->video_service == 1) {
-                       $service = 'dailymotion';
-               } elseif ($this->video_service == 2) {
-                       $service = 'vimeo';
-               } elseif ($this->video_service == 3) {
-                       $service = 'brightcove';
-               }
-               return '#/webvideo/' . $service . '/' . $this->to;
-       }
+//     public function getURL() {
+//             if ($this->video_service == 0) {
+//                     $service = 'youtube';
+//             } elseif ($this->video_service == 1) {
+//                     $service = 'dailymotion';
+//             } elseif ($this->video_service == 2) {
+//                     $service = 'vimeo';
+//             } elseif ($this->video_service == 3) {
+//                     $service = 'brightcove';
+//             }
+//             return '#/webvideo/' . $service . '/' . $this->to;
+//     }
+
+    public function getURL() {
+        return '#/video/' . $this->to;
+    }
+
+    public function getAdditionnalContent() {
+        $this->video_auto_start = true; // Videos should always autoplay
+        return ' data-video="' . rawurlencode(webVideoLink::makeVideoTag($this, $this->video_width, $this->video_height, $this->compiler)) . '" ';
+    }
 
 }
 
@@ -1144,37 +1217,45 @@ class zoomLink extends normalLink {
                return $res;
        }
 
-       public function generateImage() {
-               $left = CubeIT_Files::tempnam();
+    public function generateImage() {
+        $left = CubeIT_Files::tempnam();
 
-               $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page);
-               $pdfpath = wsDocument::getDir($p['document_id']) . 'original.pdf';
+        $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page);
+        $pdfpath = wsDocument::getDir($p['document_id']) . 'original.pdf';
 
-               CubeIT_CommandLine_Poppler::extractArea($pdfpath,
-                       $p['document_page'],
-                       array('x' => $this->left, 'y' => $this->top, 'width' => $this->width, 'height' => $this->height),
-                       $left, array(), WS_CACHE . '/zoomarea/');
+        $leftfile = CubeIT_CommandLine_Poppler::extractArea($pdfpath,
+            $p['document_page'],
+            array('x' => $this->left, 'y' => $this->top, 'width' => $this->width, 'height' => $this->height),
+            $left, array(), WS_CACHE . '/zoomarea/' . $this->compiler->book_id . '/');
 
-               $bookwidth = $this->compiler->book->parametres->width;
+        $bookwidth = $this->compiler->book->parametres->width;
 
-               if (($this->left + $this->width) > $bookwidth) {
-                       $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page + 1);
-                       $pdfpath = wsDocument::getDir($p['document_id']) . 'original.pdf';
-                       $diff = ($this->width + $this->left) - $bookwidth;
-                       $right = CubeIT_Files::tempnam();
-                       CubeIT_CommandLine_Poppler::extractArea($pdfpath,
-                               $p['document_page'],
-                               array('x' => 0, 'y' => $this->top, 'width' => $diff, 'height' => $this->height),
-                               $right, array(), WS_CACHE . '/zoomarea/');
+        if (($this->left + $this->width) > $bookwidth) {
+            $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page + 1);
+            $pdfpath = wsDocument::getDir($p['document_id']) . 'original.pdf';
+            $diff = ($this->width + $this->left) - $bookwidth;
+            $right = CubeIT_Files::tempnam();
+            $rightfile = CubeIT_CommandLine_Poppler::extractArea($pdfpath,
+                $p['document_page'],
+                array('x' => 0, 'y' => $this->top, 'width' => $diff, 'height' => $this->height),
+                $right, array(), WS_CACHE . '/zoomarea/' . $this->compiler->book_id . '/');
 
-                       $both = CubeIT_Files::tempnam() . '.png';
-                       CubeIT_CommandLine_Imagemagick::append(array($left . '.png', $right . '.png'), $both, 'horizontal');
-               } else {
-                       $both = $left . '.png';
-               }
+            $both = CubeIT_Files::tempnam() . '.jpg';
+            CubeIT_CommandLine_Imagemagick::append(array($leftfile, $rightfile), $both, 'horizontal');
+        } else {
+            $both = $leftfile;
+        }
 
-               $this->compiler->simpleCopyLinkFile($both, 'data/links/zoom_' . $this->id . '.png');
-       }
+        $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);
+            }
+        }
+    }
 
 
        public function getClasses() {