Alexander 5 лет назад
Родитель
Сommit
0a01087292

+ 12 - 0
modules/boonex/files/classes/BxFilesAlertsResponse.php

@@ -16,6 +16,18 @@ class BxFilesAlertsResponse extends BxBaseModTextAlertsResponse
         $this->MODULE = 'bx_files';
         parent::__construct();
     }
+
+    public function response($oAlert)
+    {
+        $CNF = $this->_oModule->_oConfig->CNF;
+
+        if('system' == $oAlert->sUnit && 'save_setting' == $oAlert->sAction && isset($CNF['PARAM_ALLOWED_EXT']) && $CNF['PARAM_ALLOWED_EXT'] == $oAlert->aExtras['option']) {
+            $this->_oModule->_oDb->setStorageAllowedExtensions($oAlert->aExtras['value']);
+            BxDolCacheUtilities::getInstance()->clear('db');
+        }
+
+        return parent::response($oAlert);
+    }
 }
 
 /** @} */

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

@@ -86,6 +86,8 @@ class BxFilesConfig extends BxBaseModTextConfig
             'PARAM_LINK_TO_PREVIEW' => 'bx_files_show_link_to_preview',
             'PARAM_MAX_NESTING_LEVEL' => 'bx_files_max_nesting_level',
             'PARAM_MAX_BULK_DOWNLOAD_SIZE' => 'bx_files_max_bulk_download_size',
+            'PARAM_ALLOWED_EXT' => 'bx_files_allowed_ext',
+            'PARAM_DEFAULT_LAYOUT_MODE' => 'bx_files_default_layout_mode',
 
             // objects
             'OBJECT_STORAGE' => 'bx_files_files',

+ 17 - 0
modules/boonex/files/classes/BxFilesDb.php

@@ -228,6 +228,23 @@ class BxFilesDb extends BxBaseModFilesDb
             $this->query("DELETE FROM `bx_files_downloading_jobs` WHERE UNIX_TIMESTAMP() - `started` > 24*3600");
         return $aFiles;
     }
+
+    public function setStorageAllowedExtensions($sExtensions) {
+        $CNF = &$this->_oConfig->CNF;
+
+        $aExtensions = explode(',', $sExtensions);
+        if ($aExtensions) foreach ($aExtensions as $iKey => $sExtension) {
+            $aExtensions[$iKey] = trim($sExtension, ' .');
+        }
+
+        $sExtensionsSet = implode(',', $aExtensions);
+
+        $this->query("UPDATE `sys_objects_storage` SET `ext_mode` = :ext_mode, `ext_allow` = :extensions WHERE `sys_objects_storage`.`object` = :storage_object", [
+            'extensions' => $sExtensionsSet,
+            'ext_mode' => empty($sExtensionsSet) ? 'deny-allow' : 'allow-deny',
+            'storage_object' => $CNF['OBJECT_STORAGE'],
+        ]);
+    }
 }
 
 /** @} */

+ 31 - 20
modules/boonex/files/classes/BxFilesModule.php

@@ -27,13 +27,7 @@ class BxFilesModule extends BxBaseModTextModule
         if ($iGroupProfileId == bx_get_logged_profile_id())
             return true;
 
-        $sProfileModule = $oProfile->getModule();
-
-        $aContentInfo = BxDolService::call($sProfileModule, 'get_content_info_by_id', array($oProfile->getContentId()));
-        if (BxDolService::call($sProfileModule, 'is_group_profile') && (BxDolService::call($sProfileModule, 'is_fan', array($iGroupProfileId)) || bx_get_logged_profile_id() == $aContentInfo['author']))
-            return true;
-
-        return false;
+        return bx_srv($oProfile->getModule(), 'check_allowed_post_in_profile', array($oProfile->getContentId(), $this->getName())) === CHECK_ACTION_RESULT_ALLOWED;
     }
 
     public function serviceMyEntriesActions ($iProfileId = 0)
@@ -367,23 +361,29 @@ class BxFilesModule extends BxBaseModTextModule
             exit;
         }
 
-        if ($aData[$CNF['FIELD_AUTHOR']] != bx_get_logged_profile_id()) {
+        if ($this->checkAllowedEdit($aData, false) !== CHECK_ACTION_RESULT_ALLOWED) {
             echoJson(['message' => _t('_bx_files_txt_permission_denied')]);
             exit;
         }
 
+        setlocale(LC_ALL,'C.UTF-8'); //otherwise pathinfo returns empty string on a non-latin characters filenames
+
         if (isset($_POST['title'])) {
             if ($sNewTitle = bx_get('title')) {
-                $this->_oDb->updateEntryTitle($iContentId, $sNewTitle);
+                $sExt = pathinfo($aData[$CNF['FIELD_TITLE']], PATHINFO_EXTENSION);
+                if ($sExt) $sExt = '.'.$sExt;
+
+                $this->_oDb->updateEntryTitle($iContentId, $sNewTitle.$sExt);
                 $aData = $this->_oDb->getContentInfoById($iContentId);
                 echo bx_process_output($aData[$CNF['FIELD_TITLE']]);
             }
             exit;
         }
 
+
         $sActionUrl = BX_DOL_URL_ROOT.$this->_oConfig->getBaseUri();
         echoJson([
-            'eval' => "bx_prompt('"._t('_bx_files_form_entry_input_title')."', '".bx_js_string($aData[$CNF['FIELD_TITLE']])."', function(val) {                
+            'eval' => "bx_prompt('"._t('_bx_files_form_entry_input_title')."', '".bx_js_string(pathinfo($aData[$CNF['FIELD_TITLE']], PATHINFO_FILENAME))."', function(val) {                
                 $.post('{$sActionUrl}entry_edit_title/{$iContentId}', {title: val.getValue()}, function(sTitle) {
                     if (sTitle)
                         $('.bx-file-entry[file_id=".$aData[$CNF['FIELD_ID']]."] .bx-files-filename a').html(sTitle);
@@ -411,9 +411,8 @@ class BxFilesModule extends BxBaseModTextModule
                     exit;
                 }
 
-                if ($aData[$CNF['FIELD_AUTHOR']] != bx_get_logged_profile_id() && !($aData[$CNF['FIELD_ALLOW_VIEW_TO']] < 0 && $this->serviceIsAllowedAddContentToProfile(-$aData[$CNF['FIELD_ALLOW_VIEW_TO']]))) {
-                    echoJson(['message' => _t('_bx_files_txt_permission_denied')]);
-                    exit;
+                if ($this->checkAllowedDelete($aData, false) !== CHECK_ACTION_RESULT_ALLOWED) {
+                    continue;
                 }
 
                 $this->serviceDeleteEntity($iContentId);
@@ -453,7 +452,7 @@ class BxFilesModule extends BxBaseModTextModule
             exit;
         }
 
-        if ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || !$this->serviceIsAllowedAddContentToProfile($iContext)) {
+        if ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || $iContext && !$this->serviceIsAllowedAddContentToProfile($iContext)) {
             echoJson(['message' => _t('_Access denied')]);
             exit;
         }
@@ -470,11 +469,10 @@ class BxFilesModule extends BxBaseModTextModule
                     bx_set('title-'.$aFile['id'], $aFile['file_name'], 'post');
                 }
                 bx_set('attachments', $aFilesIDs, 'post');
+                bx_set('profile_id', $iAuthorProfile, 'post');
+                bx_set('allow_view_to', !$iContext ? BX_DOL_PG_ALL : -$iContext, 'post');
 
                 $oForm = BxDolForm::getObjectInstance($this->_oConfig->CNF['OBJECT_FORM_ENTRY_UPLOAD'], $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_UPLOAD']);
-                $oForm->aInputs['profile_id']['value'] = $iAuthorProfile;
-                $oForm->aInputs['allow_view_to']['value'] = $iContext == $iAuthorProfile ? 3 : -$iContext;
-
                 $aFiles = $oForm->insert();
 
                 if ($iFolder != 0 && !empty($aFiles))
@@ -500,7 +498,8 @@ class BxFilesModule extends BxBaseModTextModule
 
         if (!empty($sName)) {
             $iAuthor = bx_get_logged_profile_id();
-            //in case it is posted to context make the context profile as an author of an entry
+            // in case it is posted to context make the context profile as an author of an entry
+            // to leave folder in case creator is removed
             $this->_oDb->createFolder($iFolder, $iAuthor == $iContext ? $iAuthor : $iContext, $iAuthor == $iContext ? BX_DOL_PG_ALL : -$iContext, $sName);
         }
 
@@ -528,7 +527,7 @@ class BxFilesModule extends BxBaseModTextModule
 
         $iContext = $aData[$CNF['FIELD_ALLOW_VIEW_TO']] < 0 ? -$aData[$CNF['FIELD_ALLOW_VIEW_TO']] : $aData[$CNF['FIELD_AUTHOR']];
 
-        if ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || !$this->serviceIsAllowedAddContentToProfile($iContext)) {
+        if (!isAdmin() && ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || !$this->serviceIsAllowedAddContentToProfile($iContext))) {
             echoJson(['message' => _t('_Access denied')]);
             exit;
         }
@@ -544,7 +543,7 @@ class BxFilesModule extends BxBaseModTextModule
 
                 $iContextMoveTo = $aDataMoveTo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0 ? -$aDataMoveTo[$CNF['FIELD_ALLOW_VIEW_TO']] : $aDataMoveTo[$CNF['FIELD_AUTHOR']];
 
-                if ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || !$this->serviceIsAllowedAddContentToProfile($iContextMoveTo)) {
+                if (!isAdmin() && ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || !$this->serviceIsAllowedAddContentToProfile($iContextMoveTo))) {
                     echoJson(['message' => _t('_Access denied')]);
                     exit;
                 }
@@ -590,6 +589,18 @@ class BxFilesModule extends BxBaseModTextModule
         }
         parent::serviceDeleteEntity($iContentId, $sFuncDelete);
     }
+
+    public function serviceBrowseContext ($iProfileId = 0, $aParams = array()) {
+        if(!$iProfileId)
+            $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
+        if (!$iProfileId)
+            return;
+        // do not show files in context block for persons profiles
+        $oProfile = BxDolProfile::getInstance($iProfileId);
+        if ($oProfile && $oProfile->getModule() == 'bx_persons') return;
+
+        return parent::serviceBrowseContext($iProfileId, $aParams);
+    }
 }
 
 /** @} */

+ 24 - 5
modules/boonex/files/classes/BxFilesSearchResult.php

@@ -18,6 +18,7 @@ class BxFilesSearchResult extends BxBaseModTextSearchResult
     protected $sCurrentView;
     protected $bFileManagerMode = false;
     protected $iFileManagerUploadTo = 0;
+    protected $sMode = '';
 
     function __construct($sMode = '', $aParams = array())
     {
@@ -33,8 +34,13 @@ class BxFilesSearchResult extends BxBaseModTextSearchResult
         if (($sMode == 'author' || $sMode == 'context') && !isset($aParams['no_toolbar'])) {
             $this->bFileManagerMode = true;
             $this->setUnitParams(['show_inline_menu' => true]);
+
+            if (!bx_get('unit_view'))
+                $aParams['unit_view'] = getParam('bx_files_default_layout_mode');
         }
 
+        $this->sMode = $sMode;
+
         parent::__construct($sMode, $aParams);
 
         $this->sCurrentView = array_flip($aParams['unit_views'])[$this->sUnitTemplate];
@@ -62,7 +68,7 @@ class BxFilesSearchResult extends BxBaseModTextSearchResult
             'object_metatags' => 'bx_files',
             'title' => _t('_bx_files_page_title_browse'),
             'table' => 'bx_files_main',
-            'ownFields' => array('id', 'file_id', 'title', 'desc', 'author', 'added', 'type', 'parent_folder_id'),
+            'ownFields' => array('id', 'file_id', 'title', 'desc', 'author', 'added', 'type', 'parent_folder_id', 'allow_view_to'),
             'searchFields' => array(),
             'restriction' => array(
                 'author' => array('value' => '', 'field' => 'author', 'operator' => '='),
@@ -187,7 +193,7 @@ class BxFilesSearchResult extends BxBaseModTextSearchResult
             $this->removeContainerClass('bx-def-margin-sec-lefttopright-neg');
 
             if (!$this->isError) {
-                if ($sMode == 'author' || $oProfileAuthor->id() != bx_get_logged_profile_id())
+                if ($sMode == 'author' && $oProfileAuthor->id() == bx_get_logged_profile_id() || $sMode == 'context')
                     $this->iFileManagerUploadTo = $oProfileAuthor->id();
             }
 
@@ -236,7 +242,7 @@ class BxFilesSearchResult extends BxBaseModTextSearchResult
 
         $this->aCurrent['join'] = array_merge($this->aCurrent['join'], [
             'files' => [
-                'type' => 'INNER',
+                'type' => 'LEFT',
                 'table' => $CNF['TABLE_FILES'],
                 'mainTable' => $CNF['TABLE_ENTRIES'],
                 'mainField' => $CNF['FIELD_ID'],
@@ -285,7 +291,7 @@ class BxFilesSearchResult extends BxBaseModTextSearchResult
                 $CNF['FIELD_ID'] => '-1',
                 $CNF['FIELD_FILE_ID'] => '0',
                 $CNF['FIELD_TITLE'] => '..',
-                $CNF['FIELD_AUTHOR'] => 0,
+                $CNF['FIELD_AUTHOR'] => bx_get_logged_profile_id(),
                 $CNF['FIELD_ADDED'] => 0,
                 $CNF['FIELD_ALLOW_VIEW_TO'] => BX_DOL_PG_ALL,
                 'type' => 'folder',
@@ -298,6 +304,19 @@ class BxFilesSearchResult extends BxBaseModTextSearchResult
 
     function processing ()
     {
+        $iViewedProfile = 0;
+        if ($this->_sMode == 'context' && $this->iFileManagerUploadTo) $iViewedProfile = $this->iFileManagerUploadTo;
+        if ($this->_sMode == 'author' && $this->aCurrent['restriction']['author']['value']) $iViewedProfile = $this->aCurrent['restriction']['author']['value'];
+
+        if ($iViewedProfile) {
+            if (is_array($iViewedProfile)) $iViewedProfile = abs($iViewedProfile[0]);
+            $oProfile = BxDolProfile::getInstance($iViewedProfile);
+            if ($oProfile->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED) {
+                $this->aCurrent['paginate']['num'] = 1;
+                return MsgBox(_t('_sys_access_denied_to_private_content'));
+            }
+        }
+
         $sCode = parent::processing();
         if (!$this->aCurrent['paginate']['num']  && $this->bFileManagerMode) {
             //to show toolbar in case of empty results
@@ -485,7 +504,7 @@ class BxFilesSearchResult extends BxBaseModTextSearchResult
 
         $sUniqueIdent = mt_rand();
         $aParams['unique_ident'] = $sUniqueIdent;
-        $aParams['context'] = $this->iFileManagerUploadTo;
+        $aParams['context'] = $this->sMode == 'context' ? $this->iFileManagerUploadTo : '';
 
         $sJsCode = $this->oModule->_oTemplate->getJsCode(['type' => 'toolbar_tools', 'uniq' => $sUniqueIdent], $aParams);
         $sJsObject = $this->oModule->_oConfig->getJsObject(['type' => 'toolbar_tools', 'uniq' => $sUniqueIdent]);

+ 5 - 6
modules/boonex/files/classes/BxFilesTemplate.php

@@ -38,11 +38,9 @@ class BxFilesTemplate extends BxBaseModTextTemplate
     {
         $oModule = $this->getModule();
 
-        if ($aData['type'] != 'folder') {
-            $sResult = $this->checkPrivacy($aData, $isCheckPrivateContent, $oModule, $sTemplateName);
-            if ($sResult)
-                return $sResult;
-        }
+        $sResult = $this->checkPrivacy($aData, $isCheckPrivateContent, $oModule, $sTemplateName);
+        if ($sResult)
+            return $sResult;
 
         $CNF = &$oModule->_oConfig->CNF;
 
@@ -67,7 +65,8 @@ class BxFilesTemplate extends BxBaseModTextTemplate
             if ($oMenu) {
                 $oMenu->setContentId($aData[$CNF['FIELD_ID']]);
                 $oMenu->setBookmarked($this->_oDb->isFileBookmarked($aData[$CNF['FIELD_ID']], bx_get_logged_profile_id()));
-                $oMenu->setAllowEditOptions($aData[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id());
+                $bEditAllowed = $this->getModule()->checkAllowedEdit($aData, false) === CHECK_ACTION_RESULT_ALLOWED;
+                $oMenu->setAllowEditOptions($bEditAllowed);
                 $aVars['bx_if:inline_menu']['content']['menu'] = $oMenu->getCode();
             }
         }

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

@@ -301,4 +301,6 @@
     <string name="_bx_files_txt_status_downloading_msg"><![CDATA[The download will start shortly...]]></string>
     <string name="_bx_files_txt_status_downloading_ready_msg"><![CDATA[Click <a href={0}>here</a> if the download doesn't start automatically.]]></string>
 
+    <string name="_bx_files_option_allowed_ext"><![CDATA[Allow only the following extensions (comma separated list)]]></string>
+    <string name="_bx_files_option_default_layout_mode"><![CDATA[Files default layout]]></string>
 </resources>

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

@@ -13,9 +13,11 @@ SET @iCategId = LAST_INSERT_ID();
 INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_error`, `extra`, `order`) VALUES
 ('bx_files_enable_auto_approve', 'on', @iCategId, '_bx_files_option_enable_auto_approve', 'checkbox', '', '', '', 0),
 ('bx_files_summary_chars', '700', @iCategId, '_bx_files_option_summary_chars', 'digit', '', '', '', 1),
+('bx_files_default_layout_mode', 'showcase', @iCategId, '_bx_files_option_default_layout_mode', 'select', '', '', 'showcase,table', 4),
 ('bx_files_show_link_to_preview', '', @iCategId, '_bx_files_option_link_to_preview', 'checkbox', '', '', '', 5),
 ('bx_files_max_nesting_level', '3', @iCategId, '_bx_files_option_max_nesting_level', 'digit', '', '', '', 6),
 ('bx_files_max_bulk_download_size', '100', @iCategId, '_bx_files_option_max_bulk_download_size', 'digit', '', '', '', 7),
+('bx_files_allowed_ext', '', @iCategId, '_bx_files_option_allowed_ext', 'digit', '', '', '', 8),
 ('bx_files_per_page_browse', '12', @iCategId, '_bx_files_option_per_page_browse', 'digit', '', '', '', 10),
 ('bx_files_per_page_profile', '6', @iCategId, '_bx_files_option_per_page_profile', 'digit', '', '', '', 12),
 ('bx_files_per_page_browse_showcase', '32', @iCategId, '_sys_option_per_page_browse_showcase', 'digit', '', '', '', 15),

+ 5 - 2
modules/boonex/files/js/toolbar_tools.js

@@ -17,8 +17,10 @@ function BxFilesBrowserTools(oOptions) {
 
     var $this = this;
 
-    $('input[type=checkbox]', $(this._oToolbarObject).parent()).change(function(){
-        $this.updateBulkActionsPanelVisivility();
+    $(document).ready(function(){
+        $('input[type=checkbox]', $($this._oToolbarObject).parent()).change(function(){
+            $this.updateBulkActionsPanelVisivility();
+        });
     });
 
     $(window).on('files_browser.update', function(){
@@ -41,6 +43,7 @@ BxFilesBrowserTools.prototype.updateBulkActionsPanelVisivility = function() {
 }
 
 BxFilesBrowserTools.prototype.reloadBlock = function(iPage) {
+    if (typeof iPage == 'undefined') iPage = 0;
     loadDynamicBlockAutoPaginate(this._oToolbarObject, iPage, '0', this.getRequestUrl());
 }
 

+ 3 - 0
modules/boonex/russian/data/langs/bx_files/ru.xml

@@ -298,4 +298,7 @@
     <string name="_bx_files_txt_status_downloading"><![CDATA[Скачивание...]]></string>
     <string name="_bx_files_txt_status_downloading_msg"><![CDATA[Скачивание скоро начнется...]]></string>
     <string name="_bx_files_txt_status_downloading_ready_msg"><![CDATA[Нажмите <a href={0}>здесь</a>, если скачивание не началось автоматически.]]></string>
+
+    <string name="_bx_files_option_allowed_ext"><![CDATA[Разрешать файлы только со следующими расширениями (через запятую)]]></string>
+    <string name="_bx_files_option_default_layout_mode"><![CDATA[Режим отображения файлов по умолчанию]]></string>
 </resources>