BxFilesModule.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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 _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  203. {
  204. $CNF = &$this->_oConfig->CNF;
  205. $aFile = $this->getContentFile($aContentInfo);
  206. if(!$aFile || $aFile['is_image'])
  207. return [];
  208. $sIconSrc = '';
  209. if(($oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])) !== false)
  210. $sIconSrc = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
  211. return [[
  212. 'id' => $aFile['id'],
  213. 'src' => $sIconSrc,
  214. 'src_medium' => $sIconSrc,
  215. 'src_orig' => '',
  216. 'url' => $sUrl
  217. ]];
  218. }
  219. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  220. {
  221. $aFile = $this->getContentFile($aContentInfo);
  222. if (!$aFile)
  223. return [];
  224. if (!$aFile['is_image'])
  225. return [];
  226. $sPhotoThumb = '';
  227. if ($oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  228. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aFile['id']);
  229. return [[
  230. 'id' => $aFile['id'],
  231. 'url' => $sUrl,
  232. 'src' => $sPhotoThumb
  233. ]];
  234. }
  235. public function actionBookmark($iContentId) {
  236. if (!$this->isLogged()) return;
  237. $aFilesToBookmark = [];
  238. if ($iContentId) $aFilesToBookmark = [$iContentId];
  239. elseif (isset($_POST['bulk'])) $aFilesToBookmark = $_POST['bulk'];
  240. if ($aFilesToBookmark)
  241. foreach ($aFilesToBookmark as $iContentId) {
  242. if ($iContentId <= 0) continue;
  243. $aData = $this->_oDb->getContentInfoById((int)$iContentId);
  244. if (!$aData) continue;
  245. $this->_oDb->bookmarkFile((int)$iContentId, bx_get_logged_profile_id());
  246. }
  247. }
  248. public function actionEntryPreview($iContentId) {
  249. $aData = $this->_oDb->getContentInfoById((int)$iContentId);
  250. $sJsCss = '';
  251. $sPreviewCode = $this->_serviceTemplateFunc ('entryFilePreview', $iContentId);
  252. // various init scripts could be there, which fail to work properly
  253. // because of a fact that it is inside a popup which is at the moment is hidden
  254. // so we need a way to postpone that initialization
  255. $aScripts = [];
  256. $sPreviewCode = preg_replace_callback('/<script>(.*)<\/script>/s', function($aMatch) use (&$aScripts) {
  257. $aScripts[] = ['code' => $aMatch[1]];
  258. return '';
  259. }, $sPreviewCode);
  260. // if there is a script then most likely it is a text + codemirror initialization, so include it here.
  261. if ($aScripts) {
  262. $sJsCss .= $this->_oTemplate->addJs('codemirror/codemirror-ext.min.js', true);
  263. $sJsCss .= $this->_oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css', true);
  264. }
  265. $sJsCss .= $this->_oTemplate->addCss('file_handler.css', true);
  266. $sPopupCode = $this->_oTemplate->parseHtmlByName('entry-popup.html', [
  267. 'content' => $sPreviewCode,
  268. 'bx_repeat:init_scripts' => $aScripts,
  269. ]);
  270. echoJson([
  271. 'popup' => [
  272. 'html' => PopupBox('bx-files-popup', bx_process_output($aData['title']), $sJsCss.$sPopupCode),
  273. 'options' => [
  274. 'onShow' => 'bx_files_popup_init()',
  275. ],
  276. ],
  277. ]);
  278. }
  279. public function actionEntryInfo($iContentId) {
  280. $aData = $this->_oDb->getContentInfoById((int)$iContentId);
  281. if (CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedView($aData)) {
  282. echoJson([
  283. 'popup' => [
  284. 'html' => PopupBox('bx-files-popup', _t('_Access denied'), _t('_Access denied')),
  285. ],
  286. ]);
  287. return;
  288. }
  289. echoJson([
  290. 'popup' => [
  291. 'html' => PopupBox('bx-files-popup', bx_process_output($aData['title']), $this->_oTemplate->entryInfoPopup($aData)),
  292. ],
  293. ]);
  294. }
  295. public function actionEntryEditTitle($iContentId) {
  296. $iContentId = intval($iContentId);
  297. $aData = $this->_oDb->getContentInfoById($iContentId);
  298. $CNF = &$this->_oConfig->CNF;
  299. if (!$aData) {
  300. echoJson(['message' => _t('_bx_files_txt_error')]);
  301. exit;
  302. }
  303. if ($this->checkAllowedEdit($aData, false) !== CHECK_ACTION_RESULT_ALLOWED) {
  304. echoJson(['message' => _t('_bx_files_txt_permission_denied')]);
  305. exit;
  306. }
  307. setlocale(LC_ALL,'C.UTF-8'); //otherwise pathinfo returns empty string on a non-latin characters filenames
  308. if (isset($_POST['title'])) {
  309. if ($sNewTitle = bx_get('title')) {
  310. $sExt = pathinfo($aData[$CNF['FIELD_TITLE']], PATHINFO_EXTENSION);
  311. if ($sExt) $sExt = '.'.$sExt;
  312. $this->_oDb->updateEntryTitle($iContentId, $sNewTitle.$sExt);
  313. $aData = $this->_oDb->getContentInfoById($iContentId);
  314. echo bx_process_output($aData[$CNF['FIELD_TITLE']]);
  315. }
  316. exit;
  317. }
  318. $sActionUrl = BX_DOL_URL_ROOT.$this->_oConfig->getBaseUri();
  319. echoJson([
  320. 'eval' => "bx_prompt('"._t('_bx_files_form_entry_input_title')."', '".bx_js_string(pathinfo($aData[$CNF['FIELD_TITLE']], PATHINFO_FILENAME))."', function(val) {
  321. $.post('{$sActionUrl}entry_edit_title/{$iContentId}', {title: val.getValue()}, function(sTitle) {
  322. if (sTitle)
  323. $('.bx-file-entry[file_id=".$aData[$CNF['FIELD_ID']]."] .bx-files-filename a').html(sTitle);
  324. });
  325. })",
  326. ]);
  327. }
  328. public function actionEntryDelete($iContentId) {
  329. $aFilesToDelete = [];
  330. if ($iContentId) $aFilesToDelete = [$iContentId];
  331. elseif (isset($_POST['bulk'])) $aFilesToDelete = $_POST['bulk'];
  332. if ($aFilesToDelete)
  333. foreach ($aFilesToDelete as $iContentId) {
  334. $iContentId = intval($iContentId);
  335. if ($iContentId <= 0) continue;
  336. $aData = $this->_oDb->getContentInfoById($iContentId);
  337. $CNF = &$this->_oConfig->CNF;
  338. if (!$aData) {
  339. echoJson(['message' => _t('_bx_files_txt_error')]);
  340. exit;
  341. }
  342. if ($this->checkAllowedDelete($aData, false) !== CHECK_ACTION_RESULT_ALLOWED) {
  343. continue;
  344. }
  345. $this->serviceDeleteEntity($iContentId);
  346. }
  347. if (!isset($_POST['bulk'])) {
  348. echoJson([
  349. 'eval' => "
  350. $('.bx-file-entry[file_id={$iContentId}]').fadeOut();
  351. $(window).trigger('files_browser.update');
  352. ",
  353. ]);
  354. } else {
  355. echoJson([]);
  356. }
  357. }
  358. public function actionClearGhosts() {
  359. if (!isLogged()) die;
  360. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->CNF['OBJECT_STORAGE']);
  361. if ($oStorage) {
  362. $aFiles = $oStorage->getGhosts(bx_get_logged_profile_id(), 0);
  363. if ($aFiles) foreach ($aFiles as $aFile) {
  364. $oStorage->deleteFile($aFile['id']);
  365. }
  366. }
  367. }
  368. public function actionUploadCompleted() {
  369. $iContext = intval(bx_get('context'));
  370. $iFolder = intval(bx_get('folder'));
  371. if (!isLogged()) {
  372. echoJson(['message' => _t('_Access denied')]);
  373. exit;
  374. }
  375. if ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || $iContext && !$this->serviceIsAllowedAddContentToProfile($iContext)) {
  376. echoJson(['message' => _t('_Access denied')]);
  377. exit;
  378. }
  379. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->CNF['OBJECT_STORAGE']);
  380. if ($oStorage) {
  381. $iAuthorProfile = bx_get_logged_profile_id();
  382. $aFiles = $oStorage->getGhosts($iAuthorProfile, 0);
  383. if ($aFiles) {
  384. $aFilesIDs = [];
  385. foreach($aFiles as $aFile) {
  386. $aFilesIDs[] = $aFile['id'];
  387. bx_set('title-'.$aFile['id'], $aFile['file_name'], 'post');
  388. }
  389. bx_set('attachments', $aFilesIDs, 'post');
  390. bx_set('profile_id', $iAuthorProfile, 'post');
  391. bx_set('allow_view_to', !$iContext ? BX_DOL_PG_ALL : -$iContext, 'post');
  392. bx_set('cf', 1, 'post');
  393. $oForm = BxDolForm::getObjectInstance($this->_oConfig->CNF['OBJECT_FORM_ENTRY_UPLOAD'], $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_UPLOAD']);
  394. $aFiles = $oForm->insert();
  395. if ($iFolder != 0 && !empty($aFiles))
  396. $this->_oDb->moveFilesToFolder($aFiles, $iFolder);
  397. }
  398. }
  399. echoJson(['success' => true]);
  400. }
  401. public function actionCreateFolder() {
  402. $iContext = intval(bx_get('context'));
  403. $iFolder = intval(bx_get('current_folder'));
  404. $sName = trim(bx_get('name'));
  405. if (!isLogged()) {
  406. echoJson(['message' => _t('_Access denied')]);
  407. exit;
  408. }
  409. if ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || $iContext && !$this->serviceIsAllowedAddContentToProfile($iContext)) {
  410. echoJson(['message' => _t('_Access denied')]);
  411. exit;
  412. }
  413. if (!empty($sName)) {
  414. $iAuthor = bx_get_logged_profile_id();
  415. // in case it is posted to context make the context profile as an author of an entry
  416. // to leave folder in case creator is removed
  417. // and to delete folder when context profile is being deleted
  418. $this->_oDb->createFolder($iFolder, $iContext ? $iContext : $iAuthor, !$iContext || $iAuthor == $iContext ? BX_DOL_PG_ALL : -$iContext, $sName);
  419. }
  420. echoJson([]);
  421. exit;
  422. }
  423. public function actionMoveFiles() {
  424. $iContentId = intval(bx_get('file'));
  425. $aFilesToMove = [];
  426. if ($iContentId) $aFilesToMove = [$iContentId];
  427. elseif (isset($_POST['bulk'])) $aFilesToMove = $_POST['bulk'];
  428. $iContentId = reset($aFilesToMove);
  429. $aData = $this->_oDb->getContentInfoById($iContentId);
  430. if (!$aData) {
  431. echoJson(['message' => _t('_bx_files_txt_error')]);
  432. exit;
  433. }
  434. $CNF = &$this->_oConfig->CNF;
  435. $iContext = $aData[$CNF['FIELD_ALLOW_VIEW_TO']] < 0 ? -$aData[$CNF['FIELD_ALLOW_VIEW_TO']] : $aData[$CNF['FIELD_AUTHOR']];
  436. if (!isAdmin() && ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || !$this->serviceIsAllowedAddContentToProfile($iContext))) {
  437. echoJson(['message' => _t('_Access denied')]);
  438. exit;
  439. }
  440. if (isset($_POST['move_to'])) {
  441. $iMoveTo = intval(bx_get('move_to'));
  442. if ($iMoveTo) {
  443. $aDataMoveTo = $this->_oDb->getContentInfoById($iMoveTo);
  444. if (!$aDataMoveTo) {
  445. echoJson(['message' => _t('_bx_files_txt_error')]);
  446. exit;
  447. }
  448. $iContextMoveTo = $aDataMoveTo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0 ? -$aDataMoveTo[$CNF['FIELD_ALLOW_VIEW_TO']] : $aDataMoveTo[$CNF['FIELD_AUTHOR']];
  449. if (!isAdmin() && ($this->checkAllowedAdd() != CHECK_ACTION_RESULT_ALLOWED || !$this->serviceIsAllowedAddContentToProfile($iContextMoveTo))) {
  450. echoJson(['message' => _t('_Access denied')]);
  451. exit;
  452. }
  453. }
  454. $this->_oDb->moveFilesToFolder($aFilesToMove, $iMoveTo);
  455. echoJson([
  456. 'eval' => "
  457. $(window).trigger('files_browser.update');
  458. ",
  459. ]);
  460. exit;
  461. }
  462. $aFolders = $this->_oDb->getFoldersInContext($iContext);
  463. if (!$aFolders) {
  464. echoJson(['message' => _t('_bx_files_txt_move_to_nowhere')]);
  465. exit;
  466. }
  467. echoJson([
  468. 'popup' => [
  469. 'html' => PopupBox('bx-files-popup', _t('_bx_files_txt_move_to'), $this->_oTemplate->getJsTree($aFilesToMove, $aFolders)),
  470. 'options' => [],
  471. ],
  472. ]);
  473. }
  474. public function serviceDeleteEntitiesByAuthor ($iProfileId) {
  475. $this->_oDb->deleteProfileBookmarks($iProfileId);
  476. return parent::serviceDeleteEntitiesByAuthor ($iProfileId);
  477. }
  478. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData') {
  479. $aData = $this->_oDb->getContentInfoById($iContentId);
  480. if ($aData['type'] == 'folder') {
  481. $aNestedFiles = $this->_oDb->getFolderFiles($aData[$this->_oConfig->CNF['FIELD_ID']]);
  482. if ($aNestedFiles)
  483. foreach ($aNestedFiles as $iFile) {
  484. $this->serviceDeleteEntity($iFile);
  485. }
  486. }
  487. parent::serviceDeleteEntity($iContentId, $sFuncDelete);
  488. }
  489. public function serviceBrowseContext ($iProfileId = 0, $aParams = array()) {
  490. if(!$iProfileId)
  491. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  492. if (!$iProfileId)
  493. return;
  494. // do not show files in context block for persons profiles
  495. $oProfile = BxDolProfile::getInstance($iProfileId);
  496. if ($oProfile && $oProfile->getModule() == 'bx_persons') return;
  497. return parent::serviceBrowseContext($iProfileId, $aParams);
  498. }
  499. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0, $bFilterMode = false)
  500. {
  501. if((empty($aParams) || !is_array($aParams)) && !$bFilterMode)
  502. return array();
  503. $aParams['type'] = [
  504. 'type' => 'text',
  505. 'value' => 'file',
  506. 'operator' => '=',
  507. ];
  508. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  509. }
  510. }
  511. /** @} */