Explorar o código

Ticket #4700 - Files: add ability to preview video files.

AntonLV %!s(int64=2) %!d(string=hai) anos
pai
achega
ce8d497093

+ 2 - 1
install/sql/system.sql

@@ -121,7 +121,8 @@ INSERT INTO `sys_objects_file_handlers` (`object`, `title`, `preg_ext`, `active`
 ('sys_google_viewer', '_sys_file_handlers_google_viewer', '/\\.(pdf|doc|docx|xls|xlsx|ppt|pptx|ai|svg|ps|tif|tiff)$/i', 1, 2, 'BxTemplFileHandlerGoogleViewer', ''),
 ('sys_images_viewer', '_sys_file_handlers_images_viewer', '/\\.(jpg|jpeg|png|gif|webp)$/i', 1, 3, 'BxTemplFileHandlerImagesViewer', ''),
 ('sys_code_viewer', '_sys_file_handlers_code_viewer', '/\\.(1st|aspx|asp|json|js|jsp|java|php|xml|html|htm|rdf|xsd|xsl|xslt|sax|rss|cfm|js|asm|pl|prl|bas|b|vbs|fs|src|cs|ws|cgi|bat|py|c|cpp|cc|cp|h|hh|cxx|hxx|c++|m|lua|swift|sh|as|cob|tpl|lsp|x|cmd|rb|cbl|pas|pp|vb|f|perl|jl|lol|bal|pli|css|less|sass|saas|bcc|coffee|jade|j|tea|c#|sas|diff|pro|for|sh|bsh|bash|twig|csh|lisp|lsp|cobol|pl|d|git|rb|hrl|cr|inp|a|go|as3|m|sql|md|txt|csv)$/i', 1, 4, 'BxTemplFileHandlerCodeViewer', ''),
-('sys_sounds_viewer', '_sys_file_handlers_sounds_viewer', '/\\.(mp3|m4a|m4b|wma|wav|3gp)$/i', 1, 5, 'BxTemplFileHandlerSoundsViewer', '');
+('sys_sounds_viewer', '_sys_file_handlers_sounds_viewer', '/\\.(mp3|m4a|m4b|wma|wav|3gp)$/i', 1, 5, 'BxTemplFileHandlerSoundsViewer', ''),
+('sys_videos_viewer', '_sys_file_handlers_videos_viewer', '/\\.(avi|flv|mpg|mpeg|wmv|mp4|m4v|mov|qt|divx|xvid|3gp|3g2|webm|mkv|ogv|ogg|rm|rmvb|asf|drc|ts)$/i', 1, 5, 'BxTemplFileHandlerVideosViewer', '');
 
 
 -- --------------------------------------------------------

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -2473,6 +2473,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_file_handlers_images_viewer"><![CDATA[Images Viewer]]></string>
 	<string name="_sys_file_handlers_code_viewer"><![CDATA[Code Viewer]]></string>
         <string name="_sys_file_handlers_sounds_viewer"><![CDATA[Sounds Player]]></string>
+        <string name="_sys_file_handlers_videos_viewer"><![CDATA[Videos Player]]></string>
 	<string name="_sys_form_account"><![CDATA[Account]]></string>
 	<string name="_sys_form_account_input_agreement"><![CDATA[]]></string>
 	<string name="_sys_form_account_input_agreement_value"><![CDATA[By signing up, you agree to the <a href="{0}">Terms of Service</a> and <a href="{1}">Privacy Policy</a>.]]></string>

+ 6 - 1
modules/boonex/files/classes/BxFilesConfig.php

@@ -96,7 +96,12 @@ class BxFilesConfig extends BxBaseModTextConfig
             'OBJECT_IMAGES_TRANSCODER_PREVIEW' => 'bx_files_preview',
             'OBJECT_IMAGES_TRANSCODER_GALLERY' => 'bx_files_gallery',
             'OBJECT_SOUNDS_TRANSCODER' => 'bx_files_sounds_mp3',
-            'OBJECT_VIDEOS_TRANSCODERS' => array(),
+            'OBJECT_VIDEOS_TRANSCODERS' => [
+                'poster' => 'bx_files_videos_poster', 
+            	'poster_preview' => 'bx_files_videos_poster_preview',
+            	'mp4' => 'bx_files_videos_mp4', 
+            	'mp4_hd' => 'bx_files_videos_mp4_hd'
+            ],
             'OBJECT_REPORTS' => 'bx_files',
             'OBJECT_VIEWS' => 'bx_files',
             'OBJECT_VOTES' => 'bx_files',

+ 11 - 3
modules/boonex/files/classes/BxFilesTemplate.php

@@ -103,9 +103,17 @@ class BxFilesTemplate extends BxBaseModTextTemplate
             return $sNoPreview;
         if (!($sFileUrl = $oStorage->getFileUrlById($aFile['id'])))
             return $sNoPreview;
-        
-        if(strncmp('audio/', $aFile['mime_type'], 6) === 0 && ($oTranscoder = BxDolTranscoderAudio::getObjectInstance($CNF['OBJECT_SOUNDS_TRANSCODER'])) !== false)
-            $oFileHandler->setTranscoder($oTranscoder);
+
+        if(strncmp('audio/', $aFile['mime_type'], 6) === 0 && !empty($CNF['OBJECT_SOUNDS_TRANSCODER']))
+            $oFileHandler->setTranscoder(BxDolTranscoderAudio::getObjectInstance($CNF['OBJECT_SOUNDS_TRANSCODER']));
+        else if(strncmp('video/', $aFile['mime_type'], 6) === 0 && !empty($CNF['OBJECT_VIDEOS_TRANSCODERS']) && is_array($CNF['OBJECT_VIDEOS_TRANSCODERS'])) {
+            $aTranscoders = $CNF['OBJECT_VIDEOS_TRANSCODERS'];
+            array_walk($aTranscoders, function(&$sValue) {
+                $sValue = BxDolTranscoderVideo::getObjectInstance($sValue);
+            });
+
+            $oFileHandler->setTranscoder($aTranscoders);
+        }
 
         return $oFileHandler->display($sFileUrl, $aFile);
     }

+ 7 - 1
modules/boonex/files/install/config.php

@@ -69,7 +69,13 @@ $aConfig = array(
     'transcoders' => array(
         'bx_files_preview',
         'bx_files_gallery',
-        'bx_files_sounds_mp3'
+
+        'bx_files_sounds_mp3',
+
+        'bx_files_videos_poster',
+        'bx_files_videos_poster_preview',
+        'bx_files_videos_mp4',
+        'bx_files_videos_mp4_hd'
     ),
 
 	/**

+ 31 - 3
modules/boonex/files/install/sql/install.sql

@@ -87,6 +87,22 @@ CREATE TABLE IF NOT EXISTS `bx_files_sounds_resized` (
   UNIQUE KEY `remote_id` (`remote_id`)
 );
 
+CREATE TABLE IF NOT EXISTS `bx_files_videos_resized` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `profile_id` int(10) unsigned NOT NULL,
+  `remote_id` varchar(128) NOT NULL,
+  `path` varchar(255) NOT NULL,
+  `file_name` varchar(255) NOT NULL,
+  `mime_type` varchar(128) NOT NULL,
+  `ext` varchar(32) NOT NULL,
+  `size` bigint(20) NOT NULL,
+  `added` int(11) NOT NULL,
+  `modified` int(11) NOT NULL,
+  `private` int(11) NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `remote_id` (`remote_id`)
+);
+
 -- TABLE: comments
 CREATE TABLE IF NOT EXISTS `bx_files_cmts` (
   `cmt_id` int(11) NOT NULL AUTO_INCREMENT,
@@ -286,19 +302,31 @@ CREATE TABLE IF NOT EXISTS `bx_files_scores_track` (
 INSERT INTO `sys_objects_storage` (`object`, `engine`, `params`, `token_life`, `cache_control`, `levels`, `table_files`, `ext_mode`, `ext_allow`, `ext_deny`, `quota_size`, `current_size`, `quota_number`, `current_number`, `max_file_size`, `ts`) VALUES
 ('bx_files_files', @sStorageEngine, '', 360, 2592000, 3, 'bx_files_files', 'deny-allow', '', '{dangerous}', 0, 0, 0, 0, 0, 0),
 ('bx_files_photos_resized', @sStorageEngine, '', 360, 2592000, 3, 'bx_files_photos_resized', 'allow-deny', '{image}', '', 0, 0, 0, 0, 0, 0),
-('bx_files_sounds_resized', @sStorageEngine, '', 360, 2592000, 3, 'bx_files_sounds_resized', 'allow-deny', '{audio}', '', 0, 0, 0, 0, 0, 0);
+('bx_files_sounds_resized', @sStorageEngine, '', 360, 2592000, 3, 'bx_files_sounds_resized', 'allow-deny', '{audio}', '', 0, 0, 0, 0, 0, 0),
+('bx_files_videos_resized', @sStorageEngine, '', 360, 2592000, 3, 'bx_files_videos_resized', 'allow-deny', '{video}', '', 0, 0, 0, 0, 0, 0);
 
 INSERT INTO `sys_objects_transcoder` (`object`, `storage_object`, `source_type`, `source_params`, `private`, `atime_tracking`, `atime_pruning`, `ts`, `override_class_name`, `override_class_file`) VALUES 
 ('bx_files_preview', 'bx_files_photos_resized', 'Storage', 'a:1:{s:6:"object";s:14:"bx_files_files";}', 'no', '1', '2592000', '0', '', ''),
 ('bx_files_gallery', 'bx_files_photos_resized', 'Storage', 'a:1:{s:6:"object";s:14:"bx_files_files";}', 'no', '1', '2592000', '0', '', ''),
 
-('bx_files_sounds_mp3', 'bx_files_sounds_resized', 'Storage', 'a:1:{s:6:"object";s:14:"bx_files_files";}', 'no', '0', '0', '0', 'BxDolTranscoderAudio', '');
+('bx_files_sounds_mp3', 'bx_files_sounds_resized', 'Storage', 'a:1:{s:6:"object";s:14:"bx_files_files";}', 'no', '0', '0', '0', 'BxDolTranscoderAudio', ''),
+
+('bx_files_videos_poster', 'bx_files_videos_resized', 'Storage', 'a:1:{s:6:"object";s:14:"bx_files_files";}', 'no', '0', '0', '0', 'BxDolTranscoderVideo', ''),
+('bx_files_videos_poster_preview', 'bx_files_videos_resized', 'Storage', 'a:1:{s:6:"object";s:14:"bx_files_files";}', 'no', '0', '0', '0', 'BxDolTranscoderVideo', ''),
+('bx_files_videos_mp4', 'bx_files_videos_resized', 'Storage', 'a:1:{s:6:"object";s:14:"bx_files_files";}', 'no', '0', '0', '0', 'BxDolTranscoderVideo', ''),
+('bx_files_videos_mp4_hd', 'bx_files_videos_resized', 'Storage', 'a:1:{s:6:"object";s:14:"bx_files_files";}', 'no', '0', '0', '0', 'BxDolTranscoderVideo', '');
 
 INSERT INTO `sys_transcoder_filters` (`transcoder_object`, `filter`, `filter_params`, `order`) VALUES 
 ('bx_files_preview', 'Resize', 'a:3:{s:1:"w";s:3:"300";s:1:"h";s:3:"200";s:11:"crop_resize";s:1:"1";}', '0'),
 ('bx_files_gallery', 'Resize', 'a:1:{s:1:"w";s:3:"500";}', '0'),
 
-('bx_files_sounds_mp3', 'Mp3', 'a:0:{}', 0);
+('bx_files_sounds_mp3', 'Mp3', 'a:0:{}', 0),
+
+('bx_files_videos_poster_preview', 'Resize', 'a:3:{s:1:"w";s:3:"300";s:1:"h";s:3:"200";s:13:"square_resize";s:1:"1";}', 10),
+('bx_files_videos_poster_preview', 'Poster', 'a:2:{s:1:"h";s:3:"480";s:10:"force_type";s:3:"jpg";}', 0),
+('bx_files_videos_poster', 'Poster', 'a:2:{s:1:"h";s:3:"318";s:10:"force_type";s:3:"jpg";}', 0),
+('bx_files_videos_mp4', 'Mp4', 'a:2:{s:1:"h";s:3:"318";s:10:"force_type";s:3:"mp4";}', 0),
+('bx_files_videos_mp4_hd', 'Mp4', 'a:3:{s:1:"h";s:3:"720";s:13:"video_bitrate";s:4:"1536";s:10:"force_type";s:3:"mp4";}', 0);
 
 -- FORMS
 INSERT INTO `sys_objects_form`(`object`, `module`, `title`, `action`, `form_attrs`, `table`, `key`, `uri`, `uri_title`, `submit_name`, `params`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES 

+ 1 - 1
modules/boonex/files/install/sql/uninstall.sql

@@ -1,6 +1,6 @@
 
 -- TABLES
-DROP TABLE IF EXISTS `bx_files_main`, `bx_files_files`, `bx_files_photos_resized`, `bx_files_sounds_resized`, `bx_files_cmts`, `bx_files_cmts_notes`, `bx_files_votes`, `bx_files_votes_track`, `bx_files_reactions`, `bx_files_reactions_track`, `bx_files_views_track`, `bx_files_meta_keywords`, `bx_files_meta_mentions`, `bx_files_reports`, `bx_files_reports_track`, `bx_files_favorites_track`, `bx_files_favorites_lists`, `bx_files_scores`, `bx_files_scores_track`, `bx_files_bookmarks`, `bx_files_downloading_jobs`;
+DROP TABLE IF EXISTS `bx_files_main`, `bx_files_files`, `bx_files_photos_resized`, `bx_files_sounds_resized`, `bx_files_videos_resized`, `bx_files_cmts`, `bx_files_cmts_notes`, `bx_files_votes`, `bx_files_votes_track`, `bx_files_reactions`, `bx_files_reactions_track`, `bx_files_views_track`, `bx_files_meta_keywords`, `bx_files_meta_mentions`, `bx_files_reports`, `bx_files_reports_track`, `bx_files_favorites_track`, `bx_files_favorites_lists`, `bx_files_scores`, `bx_files_scores_track`, `bx_files_bookmarks`, `bx_files_downloading_jobs`;
 
 -- STORAGES & TRANSCODERS
 DELETE FROM `sys_objects_storage` WHERE `object` = 'bx_files_files' OR `object` = 'bx_files_photos_resized';

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -2436,6 +2436,7 @@
 	<string name="_sys_file_handlers_images_viewer"><![CDATA[Просмотр изображений]]></string>
 	<string name="_sys_file_handlers_code_viewer"><![CDATA[Просмотр програмного кода]]></string>
         <string name="_sys_file_handlers_sounds_viewer"><![CDATA[Звуковой плеер]]></string>
+        <string name="_sys_file_handlers_videos_viewer"><![CDATA[Видео плеер]]></string>
 	<string name="_sys_form_account"><![CDATA[Аккаунт]]></string>
 	<string name="_sys_form_account_input_agreement"><![CDATA[]]></string>
 	<string name="_sys_form_account_input_agreement_value"><![CDATA[Присоединяясь, Вы соглашаетесь с <a href="{0}">Правилами пользования</a> и <a href="{1}">Политикой конфиденциальности</a>.]]></string>

+ 1 - 1
template/scripts/BxBaseFileHandlerSoundsViewer.php

@@ -22,7 +22,7 @@ class BxBaseFileHandlerSoundsViewer extends BxBaseFileHandler
         $this->_oTranscoder = null;
     }
 
-    public function setTranscoder(&$oTranscoder)
+    public function setTranscoder($oTranscoder)
     {
         $this->_oTranscoder = $oTranscoder;
     }

+ 47 - 0
template/scripts/BxBaseFileHandlerVideosViewer.php

@@ -0,0 +1,47 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaBaseView UNA Base Representation Classes
+ * @{
+ */
+
+/**
+ * Videos viewer (player) preview video files.
+ * @see BxDolFileHandler
+ */
+class BxBaseFileHandlerVideosViewer extends BxBaseFileHandler
+{
+    protected $_aTranscoders;
+
+    public function __construct ($aObject, $oTemplate)
+    {
+        parent::__construct ($aObject, $oTemplate);
+
+        $this->_aTranscoders = [];
+    }
+
+    public function setTranscoder($aTranscoders)
+    {
+        $this->_aTranscoders = $aTranscoders;
+    }
+
+    public function display ($sFileUrl, $aFile)
+    {
+        $this->addCssJs();
+
+        $sVideoUrlHd = '';
+        if(!empty($aFile['dimensions']) && $this->_aTranscoders['mp4_hd']->isProcessHD($aFile['dimensions']))
+            $sVideoUrlHd = $this->_aTranscoders['mp4_hd']->getFileUrl($aFile['id']);
+
+        return $this->_aTranscoders ? BxTemplFunctions::getInstance()->videoPlayer(
+            $this->_aTranscoders['poster']->getFileUrl($aFile['id']), 
+            $this->_aTranscoders['mp4']->getFileUrl($aFile['id']), 
+            $sVideoUrlHd,
+            false, ''
+        ) : '';
+    }
+}
+
+/** @} */

+ 21 - 0
template/scripts_templ/BxTemplFileHandlerVideosViewer.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolFileHandler
+ */
+class BxTemplFileHandlerVideosViewer extends BxBaseFileHandlerVideosViewer
+{    
+    public function __construct ($aObject, $oTemplate = false)
+    {
+        parent::__construct ($aObject, $oTemplate);
+    }
+}
+
+/** @} */