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