Alex Trofimov 9 лет назад
Родитель
Сommit
6f17c26a6e

+ 1 - 0
inc/classes/BxDolStorage.php

@@ -838,6 +838,7 @@ abstract class BxDolStorage extends BxDolFactory implements iBxDolFactoryObject
             text/x-vue                  vue
             text/x-yaml                 yaml
             text/x-sql                  sql
+            text/x-markdown             md
             application/xquery          xq xquery
             application/x-powershell    ps1
             application/x-aspx          aps

+ 24 - 0
inc/classes/BxDolStorageS3.php

@@ -64,6 +64,30 @@ class BxDolStorageS3 extends BxDolStorage
         return $this->getObjectBaseUrl($aFile['private']) . $aFile['path'];
     }
 
+    /**
+     * Start file fownloading by remote id. If file is private then token is checked.
+     */
+    public function download ($sRemoteId, $sToken = false)
+    {
+        $this->setErrorCode(BX_DOL_STORAGE_ERR_OK);
+
+        $aFile = $this->_oDb->getFileByRemoteId($sRemoteId);
+        if (!$aFile) {
+            $this->setErrorCode(BX_DOL_STORAGE_ERR_FILE_NOT_FOUND);
+            return false;
+        }
+
+        if ($aFile['private'] && !$this->_oDb->isTokenValid($aFile['id'], $sToken)) {
+            $this->setErrorCode(BX_DOL_STORAGE_ERR_PERMISSION_DENIED);
+            return false;
+        }
+
+        $sUrl = $this->getFileUrlById($aFile['id']);
+        header("Location: " . $sUrl);
+
+        return parent::download($aFile);
+    }
+    
     /**
      * Set file private or public.
      */

+ 2 - 1
install/sql/system.sql

@@ -60,7 +60,7 @@ INSERT INTO `sys_objects_file_handlers` (`object`, `title`, `preg_ext`, `active`
 ('sys_ms_viewer', '_sys_file_handlers_ms_viewer', '/\\.(doc|docx|xls|xlsx|ppt|pptx)$/', 1, 1, 'BxTemplFileHandlerMsViewer', ''),
 ('sys_google_viewer', '_sys_file_handlers_google_viewer', '/\\.(pdf|doc|docx|xls|xlsx|ppt|pptx|pages|ai|psd|dxf|svg|eps|ps|ttf|xps|tif|tiff|zip|rar)$/', 1, 2, 'BxTemplFileHandlerGoogleViewer', ''),
 ('sys_images_viewer', '_sys_file_handlers_images_viewer', '/\\.(jpg|jpeg|png|gif|webp)$/', 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)$/', 1, 4, 'BxTemplFileHandlerCodeViewer', '');
+('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)$/', 1, 4, 'BxTemplFileHandlerCodeViewer', '');
 
 
 -- --------------------------------------------------------
@@ -2334,6 +2334,7 @@ INSERT INTO `sys_storage_mime_types` (`ext`, `mime_type`, `icon`, `icon_font`) V
 ('vbs', 'text/vbscript', '', 'file-code-o'),
 ('vue', 'text/x-vue', '', 'file-code-o'),
 ('yaml', 'text/x-yaml', '', 'file-text-o'),
+('md', 'text/x-markdown', '', 'file-text-o'),
 ('xq', 'application/xquery', '', 'file-code-o'),
 ('xquery', 'application/xquery', '', 'file-code-o'),
 ('ps1', 'application/x-powershell', '', 'file-code-o'),

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

@@ -16,6 +16,7 @@ class BxFilesConfig extends BxBaseModTextConfig
         parent::__construct($aModule);
 
         $aMenuItems2Methods = array (
+            'download-file' => 'checkAllowedView',
             'edit-file' => 'checkAllowedEdit',
             'delete-file' => 'checkAllowedDelete',
         );

+ 5 - 3
modules/boonex/files/classes/BxFilesFormUpload.php

@@ -50,6 +50,8 @@ class BxFilesFormUpload extends BxBaseModTextFormEntry
         if (!$aGhostFiles)
             return true;
 
+        bx_import('BxDolPrivacy');
+
         // get values form main form to pass it to each file later
         $aFormValues = array();
         foreach ($this->aInputs as $aInput) {
@@ -68,9 +70,9 @@ class BxFilesFormUpload extends BxBaseModTextFormEntry
             if (!$iContentId)
                 continue;
             $aContentIds[] = $iContentId;
-
-            if ($aFile['private'])
-                $oStorage->setFilePrivate ($aFile['id'], 0);
+            
+            if ($aFile['private'] || (isset($aFormValues[$CNF['FIELD_ALLOW_VIEW_TO']]) && BX_DOL_PG_ALL !== $aFormValues[$CNF['FIELD_ALLOW_VIEW_TO']]))
+                $oStorage->setFilePrivate ($aFile['id'], true);
             if ($iContentId)
                 $this->_associalFileWithContent($oStorage, $aFile['id'], $iProfileId, $iContentId, $sFieldFile);
         }

+ 35 - 0
modules/boonex/files/classes/BxFilesModule.php

@@ -24,6 +24,41 @@ class BxFilesModule extends BxBaseModTextModule
         return _t('_sys_txt_access_denied');
     }
 
+    public function actionDownload($iContentId, $sToken = '') 
+    {
+        $CNF = $this->_oConfig->CNF;
+        
+        $aData = $this->_oDb->getContentInfoById((int)$iContentId);
+        if (!$aData) {
+            $this->_oTemplate->displayPageNotFound();
+            return;
+        }
+
+        if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedView($aData)) {
+            $this->_oTemplate->displayAccessDenied();
+            return;
+        }
+
+        $aFile = $this->getContentFile($aData);
+        if (!$aFile) {
+            $this->_oTemplate->displayPageNotFound();
+            return;
+        }
+            
+        $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
+        if (!$oStorage) {
+            $this->_oTemplate->displayErrorOccured();
+            return;
+        }
+
+        if (!$oStorage->download($aFile['remote_id'], $sToken)) {
+            $this->_oTemplate->displayErrorOccured();
+            return;
+        }
+        
+        exit;   
+    }
+    
     public function getContentFile($aData) 
     {
         $CNF = $this->_oConfig->CNF;

+ 0 - 8
modules/boonex/files/classes/BxFilesPageEntry.php

@@ -19,14 +19,6 @@ class BxFilesPageEntry extends BxBaseModTextPageEntry
         $this->MODULE = 'bx_files';
         parent::__construct($aObject, $oTemplate);
     }
-
-    protected function _setSubmenu($aParams)
-    {
-    	parent::_setSubmenu(array_merge($aParams, array(
-    		'title' => '',
-    		'icon' => ''
-    	)));
-    }
 }
 
 /** @} */

+ 2 - 0
modules/boonex/files/install/langs/en.xml

@@ -146,6 +146,8 @@
 	<string name="_bx_files_menu_item_title_admt_files"><![CDATA[Files - {addon} hidden]]></string>
 	<string name="_bx_files_menu_item_title_manage_my"><![CDATA[My Files]]></string>
 	<string name="_bx_files_menu_item_title_manage_all"><![CDATA[All Files]]></string>
+	<string name="_bx_files_menu_item_title_system_download_file"><![CDATA[Download]]></string>
+	<string name="_bx_files_menu_item_title_download_file"><![CDATA[Download]]></string>
 
 	<string name="_bx_files_grid_filter_item_title_adm_select_one_filter1"><![CDATA[All Statuses]]></string>
 	<string name="_bx_files_grid_filter_item_title_adm_active"><![CDATA[Active]]></string>

+ 3 - 2
modules/boonex/files/install/sql/enable.sql

@@ -172,8 +172,9 @@ INSERT INTO `sys_menu_sets`(`set_name`, `module`, `title`, `deletable`) VALUES
 ('bx_files_view', 'bx_files', '_bx_files_menu_set_title_view_entry', 0);
 
 INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES 
-('bx_files_view', 'bx_files', 'edit-file', '_bx_files_menu_item_title_system_edit_entry', '_bx_files_menu_item_title_edit_entry', 'page.php?i=edit-file&id={content_id}', '', '', 'pencil', '', 2147483647, 1, 0, 1),
-('bx_files_view', 'bx_files', 'delete-file', '_bx_files_menu_item_title_system_delete_entry', '_bx_files_menu_item_title_delete_entry', 'page.php?i=delete-file&id={content_id}', '', '', 'remove', '', 2147483647, 1, 0, 2);
+('bx_files_view', 'bx_files', 'download-file', '_bx_files_menu_item_title_system_download_file', '_bx_files_menu_item_title_download_file', 'modules/?r=files/download/{content_id}', '', '_blank', 'download', '', 2147483647, 1, 0, 1),
+('bx_files_view', 'bx_files', 'edit-file', '_bx_files_menu_item_title_system_edit_entry', '_bx_files_menu_item_title_edit_entry', 'page.php?i=edit-file&id={content_id}', '', '', 'pencil', '', 2147483647, 1, 0, 2),
+('bx_files_view', 'bx_files', 'delete-file', '_bx_files_menu_item_title_system_delete_entry', '_bx_files_menu_item_title_delete_entry', 'page.php?i=delete-file&id={content_id}', '', '', 'remove', '', 2147483647, 1, 0, 3);
 
 
 -- MENU: actions menu for my entries

Разница между файлами не показана из-за своего большого размера
+ 4 - 0
plugins_public/codemirror/codemirror-ext.min.js


+ 2 - 8
plugins_public/codemirror/codemirror.css

@@ -206,9 +206,6 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
   display: inline-block;
   vertical-align: top;
   margin-bottom: -30px;
-  /* Hack to make IE7 behave */
-  *zoom:1;
-  *display:inline;
 }
 .CodeMirror-gutter-wrapper {
   position: absolute;
@@ -252,8 +249,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
   position: relative;
   overflow: visible;
   -webkit-tap-highlight-color: transparent;
-  -webkit-font-variant-ligatures: none;
-  font-variant-ligatures: none;
+  -webkit-font-variant-ligatures: contextual;
+  font-variant-ligatures: contextual;
 }
 .CodeMirror-wrap pre {
   word-wrap: break-word;
@@ -327,9 +324,6 @@ div.CodeMirror-dragcursors {
   background: rgba(255, 255, 0, .4);
 }
 
-/* IE7 hack to prevent it from returning funny offsetTops on the spans */
-.CodeMirror span { *vertical-align: text-bottom; }
-
 /* Used to force a border model for a node */
 .cm-force-border { padding-right: .1px; }
 

Разница между файлами не показана из-за своего большого размера
+ 3 - 16
plugins_public/codemirror/codemirror.min.js


+ 1 - 0
template/css/file_handler.css

@@ -1,6 +1,7 @@
 .bx_file_handler_img {
     width:100%;
     height:auto;
+    display:block;
 }
 
 .bx_file_handler_iframe {

+ 1 - 1
template/file_handler_img.html

@@ -1 +1 @@
-<img class="bx_file_handler_img" src="__src__" />
+<img class="bx_file_handler_img bx-def-round-corners" src="__src__" />

+ 1 - 1
template/scripts/BxBaseFileHandlerCodeViewer.php

@@ -33,7 +33,7 @@ class BxBaseFileHandlerCodeViewer extends BxBaseFileHandler
     {   
         parent::addCssJs();
         if (!self::$_isCssJsAdded) {
-    		$this->_oTemplate->addJs(array('codemirror/codemirror.min.js', ''));
+    		$this->_oTemplate->addJs(array('codemirror/codemirror-ext.min.js', ''));
             $this->_oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
             self::$_isCssJsAdded = true;
         }

Некоторые файлы не были показаны из-за большого количества измененных файлов