BxFilesModule.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Files Files
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Files module
  13. */
  14. class BxFilesModule extends BxBaseModTextModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. }
  20. public function serviceIsAllowedAddContentToProfile($iGroupProfileId)
  21. {
  22. if (!$iGroupProfileId || !($oProfile = BxDolProfile::getInstance((int)$iGroupProfileId)))
  23. return false;
  24. if ($iGroupProfileId == bx_get_logged_profile_id())
  25. return true;
  26. return bx_srv($oProfile->getModule(), 'check_allowed_post_in_profile', array($oProfile->getContentId(), $this->getName())) === CHECK_ACTION_RESULT_ALLOWED;
  27. }
  28. public function serviceMyEntriesActions ($iProfileId = 0)
  29. {
  30. if (!$iProfileId)
  31. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  32. if (!$this->serviceIsAllowedAddContentToProfile($iProfileId))
  33. return false;
  34. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  35. return $oMenu ? $oMenu->getCode() : false;
  36. }
  37. public function checkAllowedSetThumb ($iContentId = 0)
  38. {
  39. return _t('_sys_txt_access_denied');
  40. }
  41. public function actionDownload($sToken = '', $iContentId = 0, $sBulk = '')
  42. {
  43. $CNF = $this->_oConfig->CNF;
  44. $aFilesToDownload = [$iContentId];
  45. if (!empty($sBulk)) {
  46. $aFilesToDownload = json_decode($sBulk);
  47. }
  48. if (!is_array($aFilesToDownload)) {
  49. $this->_oTemplate->displayPageNotFound();
  50. return;
  51. }
  52. $iContentId = reset($aFilesToDownload);
  53. $aData = $this->_oDb->getContentInfoById((int)$iContentId);
  54. if (!$aData) {
  55. $this->_oTemplate->displayPageNotFound();
  56. return;
  57. }
  58. if (CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedView($aData)) {
  59. $this->_oTemplate->displayAccessDenied();
  60. return;
  61. }
  62. if ($aData['type'] == 'folder' || $aFilesToDownload && count($aFilesToDownload) > 1) {
  63. bx_import('BulkDownloader', $this->_aModule);
  64. $oDownloader = new BxFilesBulkDownloader($this);
  65. $aResult = $oDownloader->createDownloadingJob($aFilesToDownload, $aData[$CNF['FIELD_TITLE']]);
  66. switch ($aResult['status']) {
  67. case BX_FILES_DOWNLOADER_STATUS_TOO_LARGE:
  68. $this->_oTemplate->displayMsg(_t('_bx_files_txt_max_size_reached', _t_format_size(intval(getParam('bx_files_max_bulk_download_size')) * 1024 * 1024)));
  69. break;
  70. case BX_FILES_DOWNLOADER_STATUS_DOWNLOADING:
  71. $this->_oTemplate->addJsTranslation('_bx_files_txt_status_downloading_ready_msg');
  72. $this->_oTemplate->displayMsg(['title' => _t('_bx_files_txt_status_downloading'), 'content' => $this->_oTemplate->parseHtmlByName('bulk_downloader_process.html', [
  73. 'timeout' => BX_FILES_DOWNLOADER_TIMEOUT_REQUESTS,
  74. 'action_url' => BX_DOL_URL_ROOT.$this->_oConfig->getBaseUri().'process_download/'.$aResult['job'],
  75. ])]);
  76. break;
  77. case BX_FILES_DOWNLOADER_STATUS_READY:
  78. bx_smart_readfile($aResult['file'], $aResult['filename'], 'application/zip');
  79. break;
  80. case BX_FILES_DOWNLOADER_STATUS_EMPTY:
  81. default:
  82. $this->_oTemplate->displayPageNotFound();
  83. break;
  84. }
  85. exit;
  86. }
  87. $aFile = $this->getContentFile($aData);
  88. if (!$aFile) {
  89. $this->_oTemplate->displayPageNotFound();
  90. return;
  91. }
  92. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  93. if (!$oStorage) {
  94. $this->_oTemplate->displayErrorOccured();
  95. return;
  96. }
  97. if (!$oStorage->download($aFile['remote_id'], $sToken, true)) {
  98. $this->_oTemplate->displayErrorOccured();
  99. return;
  100. }
  101. exit;
  102. }
  103. public function actionProcessDownload($iDownloadingJobId) {
  104. if (!$iDownloadingJobId) die;
  105. $aJob = $this->_oDb->getDownloadingJob($iDownloadingJobId);
  106. if (!$aJob || $aJob['owner'] != bx_get_logged_profile_id()) die;
  107. if ($aJob['result']) {
  108. bx_smart_readfile($aJob['result'], $aJob['name'], 'application/zip');
  109. exit;
  110. }
  111. bx_import('BulkDownloader', $this->_aModule);
  112. $oDownloader = new BxFilesBulkDownloader($this);
  113. $mRes = $oDownloader->processDownloading($aJob['files']);
  114. if ($mRes === BX_FILES_DOWNLOADER_STATUS_DOWNLOADING) {
  115. $this->_oDb->updateDownloadingJob($iDownloadingJobId, $aJob['files'], '');
  116. echoJson([
  117. 'status' => 'downloading',
  118. ]);
  119. } else {
  120. $this->_oDb->updateDownloadingJob($iDownloadingJobId, $aJob['files'], $mRes);
  121. echoJson([
  122. 'status' => 'ready',
  123. ]);
  124. }
  125. }
  126. public function getContentFile($aData)
  127. {
  128. $CNF = $this->_oConfig->CNF;
  129. if (!isset($aData[$CNF['FIELD_AUTHOR']]) || !isset($aData[$CNF['FIELD_ID']]))
  130. return false;
  131. if (isset($aData['type']) && $aData['type'] == 'folder') {
  132. return [
  133. 'id' => $aData[$CNF['FIELD_ID']],
  134. 'profile_id' => $aData[$CNF['FIELD_AUTHOR']],
  135. 'remote_id' => 0,
  136. 'path' => '',
  137. 'file_name' => $aData[$CNF['FIELD_TITLE']],
  138. 'mime_type' => '',
  139. 'ext' => '',
  140. 'size' => 0,
  141. 'added' => $aData[$CNF['FIELD_ADDED']],
  142. 'modified' => 0,
  143. 'private' => false,
  144. 'is_image' => false,
  145. ];
  146. }
  147. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  148. if (!$oStorage)
  149. return false;
  150. if (isset($aData[$CNF['FIELD_FILE_ID']]) && $aData[$CNF['FIELD_FILE_ID']])
  151. return $this->_addFileFields($oStorage->getFile($aData[$CNF['FIELD_FILE_ID']]));
  152. $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]);
  153. if (!$aGhostFiles)
  154. return false;
  155. return $this->_addFileFields(array_pop($aGhostFiles));
  156. }
  157. protected function _addFileFields($aFile)
  158. {
  159. if (is_array($aFile))
  160. $aFile['is_image'] = in_array($aFile['ext'], array('jpg', 'jpeg', 'png', 'gif', /* when ImageMagick is used - 'tif', 'tiff', 'bmp', 'ico', 'psd' */));
  161. return $aFile;
  162. }
  163. public function serviceEntityFilePreview($iContentId = 0)
  164. {
  165. return $this->_serviceTemplateFunc ('entryFilePreview', $iContentId);
  166. }
  167. public function serviceProcessFilesData($iNumberOfFilesToProcessAtOnce = 3)
  168. {
  169. $CNF = $this->_oConfig->CNF;
  170. if (!defined('BX_SYSTEM_JAVA') || !constant('BX_SYSTEM_JAVA'))
  171. return;
  172. $a = $this->_oDb->getNotProcessedFiles($iNumberOfFilesToProcessAtOnce);
  173. if (!$a)
  174. return;
  175. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  176. if (!$oStorage)
  177. return false;
  178. foreach ($a as $aContentInfo) {
  179. $aFile = $this->getContentFile($aContentInfo);
  180. if (!$aFile) {
  181. $this->_oDb->updateFileData ($aContentInfo[$CNF['FIELD_ID']], '');
  182. continue;
  183. }
  184. $sFileUrl = $oStorage->getFileUrlById($aFile['id']);
  185. $sFilePath = BX_DIRECTORY_PATH_TMP . $aFile['remote_id'] . '.' . $aFile['ext'];
  186. @file_put_contents($sFilePath, file_get_contents($sFileUrl));
  187. if (!file_exists($sFilePath)) {
  188. $this->_oDb->updateFileData ($aContentInfo[$CNF['FIELD_ID']], '');
  189. continue;
  190. }
  191. $sCommand = '"' . constant('BX_SYSTEM_JAVA') . '" -Djava.awt.headless=true -jar "' . $this->_oConfig->getHomePath() . 'data/tika-app.jar" --encoding=UTF-8 --text "' . $sFilePath . '"';
  192. $sData = `$sCommand`;
  193. @unlink($sFilePath);
  194. $this->_oDb->updateFileData ($aContentInfo[$CNF['FIELD_ID']], $sData);
  195. }
  196. }
  197. public function servicePruneDownloadingJobs()
  198. {
  199. $aFiles = $this->_oDb->deleteOldDownloadingJobs();
  200. if ($aFiles) foreach ($aFiles as $sFile) @unlink($sFile);
  201. }
  202. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  203. {
  204. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  205. $aFile = $this->getContentFile($aContentInfo);
  206. if (!$aFile['is_image']) {
  207. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->CNF['OBJECT_STORAGE']);
  208. $sIcon = $oStorage ? $oStorage->getFontIconNameByFileName($aFile['file_name']) : 'far file';
  209. $aResult['raw'] = $this->_oTemplate->parseHtmlByName('timeline_post.html', array(
  210. 'title' => $aResult['title'],
  211. 'title_attr' => bx_html_attribute($aResult['title']),
  212. 'url' => $aResult['url'],
  213. 'icon' => $sIcon,
  214. ));
  215. $aResult['title'] = '';
  216. }
  217. return $aResult;
  218. }
  219. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  220. {
  221. $aFile = $this->getContentFile($aContentInfo);
  222. if (!$aFile)
  223. return array();
  224. if (!$aFile['is_image'])
  225. return array();
  226. $sPhotoThumb = '';
  227. if ($oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  228. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aFile['id']);
  229. return array(
  230. array('id' => $aFile['id'], 'url' => $sUrl, 'src' => $sPhotoThumb),
  231. );
  232. }
  233. public function actionBookmark($iContentId) {
  234. if (!$this->isLogged()) return;
  235. $aFilesToBookmark = [];
  236. if ($iContentId) $aFilesToBookmark = [$iContentId];
  237. elseif (isset($_POST['bulk'])) $aFilesToBookmark = $_POST['bulk'];
  238. if ($aFilesToBookmark)
  239. foreach ($aFilesToBookmark as $iContentId) {
  240. if ($iContentId <= 0) continue;
  241. $aData = $this->_oDb->getContentInfoById((int)$iContentId);
  242. if (!$aData) continue;
  243. $this->_oDb->bookmarkFile((int)$iContentId, bx_get_logged_profile_id());
  244. }
  245. }
  246. public function actionEntryPreview($iContentId) {
  247. $aData = $this->_oDb->getContentInfoById((int)$iContentId);
  248. $sJsCss = '';
  249. $sPreviewCode = $this->_serviceTemplateFunc ('entryFilePreview', $iContentId);
  250. // various init scripts could be there, which fail to work properly
  251. // because of a fact that it is inside a popup which is at the moment is hidden
  252. // so we need a way to postpone that initialization
  253. $aScripts = [];
  254. $sPreviewCode = preg_replace_callback('/<script>(.*)<\/script>/s', function($aMatch) use (&$aScripts) {
  255. $aScripts[] = ['code' => $aMatch[1]];
  256. return '';
  257. }, $sPreviewCode);
  258. // if there is a script then most likely it is a text + codemirror initialization, so include it here.
  259. if ($aScripts) {
  260. $sJsCss .= $this->_oTemplate->addJs('codemirror/codemirror-ext.min.js', true);
  261. $sJsCss .= $this->_oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css', true);
  262. }
  263. $sJsCss .= $this->_oTemplate->addCss('file_handler.css', true);
  264. $sPopupCode = $this->_oTemplate->parseHtmlByName('entry-popup.html', [
  265. 'content' => $sPreviewCode,
  266. 'bx_repeat:init_scripts' => $aScripts,
  267. ]);
  268. echoJson([
  269. 'popup' => [
  270. 'html' => PopupBox('bx-files-popup', bx_process_output($aData['title']), $sJsCss.$sPopupCode),
  271. 'options' => [
  272. 'onShow' => 'bx_files_popup_init()',
  273. ],
  274. ],
  275. ]);
  276. }
  277. public function actionEntryInfo($iContentId) {
  278. $aData = $this->_oDb->getContentInfoById((int)$iContentId);
  279. echoJson([
  280. 'popup' => [
  281. 'html' => PopupBox('bx-files-popup', bx_process_output($aData['title']), $this->_oTemplate->entryInfoPopup($aData)),
  282. ],
  283. ]);
  284. }
  285. public function actionEntryEditTitle($iContentId) {
  286. $iContentId = intval($iContentId);
  287. $aData = $this->_oDb->getContentInfoById($iContentId);
  288. $CNF = &$this->_oConfig->CNF;
  289. if (!$aData) {
  290. echoJson(['message' => _t('_bx_files_txt_error')]);
  291. exit;
  292. }
  293. if ($this->checkAllowedEdit($aData, false) !== CHECK_ACTION_RESULT_ALLOWED) {
  294. echoJson(['message' => _t('_bx_files_txt_permission_denied')]);
  295. exit;
  296. }
  297. setlocale(LC_ALL,'C.UTF-8'); //otherwise pathinfo returns empty string on a non-latin characters filenames
  298. if (isset($_POST['title'])) {
  299. if ($sNewTitle = bx_get('title')) {
  300. $sExt = pathinfo($aData[$CNF['FIELD_TITLE']], PATHINFO_EXTENSION);
  301. if ($sExt) $sExt = '.'.$sExt;
  302. $this->_oDb->updateEntryTitle($iContentId, $sNewTitle.$sExt);
  303. $aData = $this->_oDb->getContentInfoById($iContentId);
  304. echo bx_process_output($aData[$CNF['FIELD_TITLE']]);
  305. }
  306. exit;
  307. }
  308. $sActionUrl = BX_DOL_URL_ROOT.$this->_oConfig->getBaseUri();
  309. echoJson([
  310. 'eval' => "bx_prompt('"._t('_bx_files_form_entry_input_title')."', '".bx_js_string(pathinfo($aData[$CNF['FIELD_TITLE']], PATHINFO_FILENAME))."', function(val) {
  311. $.post('{$sActionUrl}entry_edit_title/{$iContentId}', {title: val.getValue()}, function(sTitle) {
  312. if (sTitle)
  313. $('.bx-file-entry[file_id=".$aData[$CNF['FIELD_ID']]."] .bx-files-filename a').html(sTitle);
  314. });
  315. })",
  316. ]);
  317. }
  318. public function actionEntryDelete($iContentId) {
  319. $aFilesToDelete = [];
  320. if ($iContentId) $aFilesToDelete = [$iContentId];
  321. elseif (isset($_POST['bulk'])) $aFilesToDelete = $_POST['bulk'];
  322. if ($aFilesToDelete)
  323. foreach ($aFilesToDelete as $iContentId) {
  324. $iContentId = intval($iContentId);
  325. if ($iContentId <= 0) continue;
  326. $aData = $this->_oDb->getContentInfoById($iContentId);
  327. $CNF = &$this->_oConfig->CNF;
  328. if (!$aData) {
  329. echoJson(['message' => _t('_bx_files_txt_error')]);
  330. exit;
  331. }
  332. if ($this->checkAllowedDelete($aData, false) !== CHECK_ACTION_RESULT_ALLOWED) {
  333. continue;
  334. }
  335. $this->serviceDeleteEntity($iContentId);
  336. }
  337. if (!isset($_POST['bulk'])) {
  338. echoJson([
  339. 'eval' => "
  340. $('.bx-file-entry[file_id={$iContentId}]').fadeOut();
  341. $(window).trigger('files_browser.update');
  342. ",
  343. ]);
  344. } else {
  345. echoJson([]);
  346. }
  347. }
  348. public function actionClearGhosts() {
  349. if (!isLogged()) die;
  350. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->CNF['OBJECT_STORAGE']);
  351. if ($oStorage) {
  352. $aFiles = $oStorage->getGhosts(bx_get_logged_profile_id(), 0);
  353. if ($aFiles) foreach ($aFiles as $aFile) {
  354. $oStorage->deleteFile($aFile['id']);
  355. }
  356. }
  357. }
  358. public function actionUploadCompleted() {
  359. $iContext = intval(bx_get('context'));
  360. $iFolder = intval(bx_get('folder'));
  361. if (!isLogged()) {
  362. echoJson(['message' => _t('_Access denied')]);
  363. exit;
  364. }
  365. if ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || $iContext && !$this->serviceIsAllowedAddContentToProfile($iContext)) {
  366. echoJson(['message' => _t('_Access denied')]);
  367. exit;
  368. }
  369. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->CNF['OBJECT_STORAGE']);
  370. if ($oStorage) {
  371. $iAuthorProfile = bx_get_logged_profile_id();
  372. $aFiles = $oStorage->getGhosts($iAuthorProfile, 0);
  373. if ($aFiles) {
  374. $aFilesIDs = [];
  375. foreach($aFiles as $aFile) {
  376. $aFilesIDs[] = $aFile['id'];
  377. bx_set('title-'.$aFile['id'], $aFile['file_name'], 'post');
  378. }
  379. bx_set('attachments', $aFilesIDs, 'post');
  380. bx_set('profile_id', $iAuthorProfile, 'post');
  381. bx_set('allow_view_to', !$iContext ? BX_DOL_PG_ALL : -$iContext, 'post');
  382. bx_set('cf', 1, 'post');
  383. $oForm = BxDolForm::getObjectInstance($this->_oConfig->CNF['OBJECT_FORM_ENTRY_UPLOAD'], $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_UPLOAD']);
  384. $aFiles = $oForm->insert();
  385. if ($iFolder != 0 && !empty($aFiles))
  386. $this->_oDb->moveFilesToFolder($aFiles, $iFolder);
  387. }
  388. }
  389. echoJson(['success' => true]);
  390. }
  391. public function actionCreateFolder() {
  392. $iContext = intval(bx_get('context'));
  393. $iFolder = intval(bx_get('current_folder'));
  394. $sName = trim(bx_get('name'));
  395. if (!isLogged()) {
  396. echoJson(['message' => _t('_Access denied')]);
  397. exit;
  398. }
  399. if ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || $iContext && !$this->serviceIsAllowedAddContentToProfile($iContext)) {
  400. echoJson(['message' => _t('_Access denied')]);
  401. exit;
  402. }
  403. if (!empty($sName)) {
  404. $iAuthor = bx_get_logged_profile_id();
  405. // in case it is posted to context make the context profile as an author of an entry
  406. // to leave folder in case creator is removed
  407. // and to delete folder when context profile is being deleted
  408. $this->_oDb->createFolder($iFolder, $iContext ? $iContext : $iAuthor, !$iContext || $iAuthor == $iContext ? BX_DOL_PG_ALL : -$iContext, $sName);
  409. }
  410. echoJson([]);
  411. exit;
  412. }
  413. public function actionMoveFiles() {
  414. $iContentId = intval(bx_get('file'));
  415. $aFilesToMove = [];
  416. if ($iContentId) $aFilesToMove = [$iContentId];
  417. elseif (isset($_POST['bulk'])) $aFilesToMove = $_POST['bulk'];
  418. $iContentId = reset($aFilesToMove);
  419. $aData = $this->_oDb->getContentInfoById($iContentId);
  420. if (!$aData) {
  421. echoJson(['message' => _t('_bx_files_txt_error')]);
  422. exit;
  423. }
  424. $CNF = &$this->_oConfig->CNF;
  425. $iContext = $aData[$CNF['FIELD_ALLOW_VIEW_TO']] < 0 ? -$aData[$CNF['FIELD_ALLOW_VIEW_TO']] : $aData[$CNF['FIELD_AUTHOR']];
  426. if (!isAdmin() && ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || !$this->serviceIsAllowedAddContentToProfile($iContext))) {
  427. echoJson(['message' => _t('_Access denied')]);
  428. exit;
  429. }
  430. if (isset($_POST['move_to'])) {
  431. $iMoveTo = intval(bx_get('move_to'));
  432. if ($iMoveTo) {
  433. $aDataMoveTo = $this->_oDb->getContentInfoById($iMoveTo);
  434. if (!$aDataMoveTo) {
  435. echoJson(['message' => _t('_bx_files_txt_error')]);
  436. exit;
  437. }
  438. $iContextMoveTo = $aDataMoveTo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0 ? -$aDataMoveTo[$CNF['FIELD_ALLOW_VIEW_TO']] : $aDataMoveTo[$CNF['FIELD_AUTHOR']];
  439. if (!isAdmin() && ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || !$this->serviceIsAllowedAddContentToProfile($iContextMoveTo))) {
  440. echoJson(['message' => _t('_Access denied')]);
  441. exit;
  442. }
  443. }
  444. $this->_oDb->moveFilesToFolder($aFilesToMove, $iMoveTo);
  445. echoJson([
  446. 'eval' => "
  447. $(window).trigger('files_browser.update');
  448. ",
  449. ]);
  450. exit;
  451. }
  452. $aFolders = $this->_oDb->getFoldersInContext($iContext);
  453. if (!$aFolders) {
  454. echoJson(['message' => _t('_bx_files_txt_move_to_nowhere')]);
  455. exit;
  456. }
  457. echoJson([
  458. 'popup' => [
  459. 'html' => PopupBox('bx-files-popup', _t('_bx_files_txt_move_to'), $this->_oTemplate->getJsTree($aFilesToMove, $aFolders)),
  460. 'options' => [],
  461. ],
  462. ]);
  463. }
  464. public function serviceDeleteEntitiesByAuthor ($iProfileId) {
  465. $this->_oDb->deleteProfileBookmarks($iProfileId);
  466. return parent::serviceDeleteEntitiesByAuthor ($iProfileId);
  467. }
  468. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData') {
  469. $aData = $this->_oDb->getContentInfoById($iContentId);
  470. if ($aData['type'] == 'folder') {
  471. $aNestedFiles = $this->_oDb->getFolderFiles($aData[$this->_oConfig->CNF['FIELD_ID']]);
  472. if ($aNestedFiles)
  473. foreach ($aNestedFiles as $iFile) {
  474. $this->serviceDeleteEntity($iFile);
  475. }
  476. }
  477. parent::serviceDeleteEntity($iContentId, $sFuncDelete);
  478. }
  479. public function serviceBrowseContext ($iProfileId = 0, $aParams = array()) {
  480. if(!$iProfileId)
  481. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  482. if (!$iProfileId)
  483. return;
  484. // do not show files in context block for persons profiles
  485. $oProfile = BxDolProfile::getInstance($iProfileId);
  486. if ($oProfile && $oProfile->getModule() == 'bx_persons') return;
  487. return parent::serviceBrowseContext($iProfileId, $aParams);
  488. }
  489. }
  490. /** @} */