getModule(), 'check_allowed_post_in_profile', array($oProfile->getContentId(), $this->getName())) === CHECK_ACTION_RESULT_ALLOWED; } public function serviceMyEntriesActions ($iProfileId = 0) { if (!$iProfileId) $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT); if (!$this->serviceIsAllowedAddContentToProfile($iProfileId)) return false; $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']); return $oMenu ? $oMenu->getCode() : false; } public function checkAllowedSetThumb ($iContentId = 0) { return _t('_sys_txt_access_denied'); } public function actionDownload($sToken, $iContentId, $sBulk = '') { $CNF = $this->_oConfig->CNF; $aFilesToDownload = [$iContentId]; if (!empty($sBulk)) { $aFilesToDownload = json_decode($sBulk); } if (!is_array($aFilesToDownload)) { $this->_oTemplate->displayPageNotFound(); return; } $iContentId = reset($aFilesToDownload); $aData = $this->_oDb->getContentInfoById((int)$iContentId); if (!$aData) { $this->_oTemplate->displayPageNotFound(); return; } if (CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedView($aData)) { $this->_oTemplate->displayAccessDenied(); return; } if ($aData['type'] == 'folder' || $aFilesToDownload && count($aFilesToDownload) > 1) { bx_import('BulkDownloader', $this->_aModule); $oDownloader = new BxFilesBulkDownloader($this); $aResult = $oDownloader->createDownloadingJob($aFilesToDownload, $aData[$CNF['FIELD_TITLE']]); switch ($aResult['status']) { case BX_FILES_DOWNLOADER_STATUS_TOO_LARGE: $this->_oTemplate->displayMsg(_t('_bx_files_txt_max_size_reached', _t_format_size(intval(getParam('bx_files_max_bulk_download_size')) * 1024 * 1024))); break; case BX_FILES_DOWNLOADER_STATUS_DOWNLOADING: $this->_oTemplate->addJsTranslation('_bx_files_txt_status_downloading_ready_msg'); $this->_oTemplate->displayMsg(['title' => _t('_bx_files_txt_status_downloading'), 'content' => $this->_oTemplate->parseHtmlByName('bulk_downloader_process.html', [ 'timeout' => BX_FILES_DOWNLOADER_TIMEOUT_REQUESTS, 'action_url' => BX_DOL_URL_ROOT.$this->_oConfig->getBaseUri().'process_download/'.$aResult['job'], ])]); break; case BX_FILES_DOWNLOADER_STATUS_READY: bx_smart_readfile($aResult['file'], $aResult['filename'], 'application/zip'); break; case BX_FILES_DOWNLOADER_STATUS_EMPTY: default: $this->_oTemplate->displayPageNotFound(); break; } exit; } $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, true)) { $this->_oTemplate->displayErrorOccured(); return; } exit; } public function actionProcessDownload($iDownloadingJobId) { if (!$iDownloadingJobId) die; $aJob = $this->_oDb->getDownloadingJob($iDownloadingJobId); if (!$aJob || $aJob['owner'] != bx_get_logged_profile_id()) die; if ($aJob['result']) { bx_smart_readfile($aJob['result'], $aJob['name'], 'application/zip'); exit; } bx_import('BulkDownloader', $this->_aModule); $oDownloader = new BxFilesBulkDownloader($this); $mRes = $oDownloader->processDownloading($aJob['files']); if ($mRes === BX_FILES_DOWNLOADER_STATUS_DOWNLOADING) { $this->_oDb->updateDownloadingJob($iDownloadingJobId, $aJob['files'], ''); echoJson([ 'status' => 'downloading', ]); } else { $this->_oDb->updateDownloadingJob($iDownloadingJobId, $aJob['files'], $mRes); echoJson([ 'status' => 'ready', ]); } } public function getContentFile($aData) { $CNF = $this->_oConfig->CNF; if (!isset($aData[$CNF['FIELD_AUTHOR']]) || !isset($aData[$CNF['FIELD_ID']])) return false; if (isset($aData['type']) && $aData['type'] == 'folder') { return [ 'id' => $aData[$CNF['FIELD_ID']], 'profile_id' => $aData[$CNF['FIELD_AUTHOR']], 'remote_id' => 0, 'path' => '', 'file_name' => $aData[$CNF['FIELD_TITLE']], 'mime_type' => '', 'ext' => '', 'size' => 0, 'added' => $aData[$CNF['FIELD_ADDED']], 'modified' => 0, 'private' => false, 'is_image' => false, ]; } $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']); if (!$oStorage) return false; if (isset($aData[$CNF['FIELD_FILE_ID']]) && $aData[$CNF['FIELD_FILE_ID']]) return $this->_addFileFields($oStorage->getFile($aData[$CNF['FIELD_FILE_ID']])); $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]); if (!$aGhostFiles) return false; return $this->_addFileFields(array_pop($aGhostFiles)); } protected function _addFileFields($aFile) { if (is_array($aFile)) $aFile['is_image'] = in_array($aFile['ext'], array('jpg', 'jpeg', 'png', 'gif', /* when ImageMagick is used - 'tif', 'tiff', 'bmp', 'ico', 'psd' */)); return $aFile; } public function serviceEntityFilePreview($iContentId = 0) { return $this->_serviceTemplateFunc ('entryFilePreview', $iContentId); } public function serviceProcessFilesData($iNumberOfFilesToProcessAtOnce = 3) { $CNF = $this->_oConfig->CNF; if (!defined('BX_SYSTEM_JAVA') || !constant('BX_SYSTEM_JAVA')) return; $a = $this->_oDb->getNotProcessedFiles($iNumberOfFilesToProcessAtOnce); if (!$a) return; $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']); if (!$oStorage) return false; foreach ($a as $aContentInfo) { $aFile = $this->getContentFile($aContentInfo); if (!$aFile) { $this->_oDb->updateFileData ($aContentInfo[$CNF['FIELD_ID']], ''); continue; } $sFileUrl = $oStorage->getFileUrlById($aFile['id']); $sFilePath = BX_DIRECTORY_PATH_TMP . $aFile['remote_id'] . '.' . $aFile['ext']; @file_put_contents($sFilePath, file_get_contents($sFileUrl)); if (!file_exists($sFilePath)) { $this->_oDb->updateFileData ($aContentInfo[$CNF['FIELD_ID']], ''); continue; } $sCommand = '"' . constant('BX_SYSTEM_JAVA') . '" -Djava.awt.headless=true -jar "' . $this->_oConfig->getHomePath() . 'data/tika-app.jar" --encoding=UTF-8 --text "' . $sFilePath . '"'; $sData = `$sCommand`; @unlink($sFilePath); $this->_oDb->updateFileData ($aContentInfo[$CNF['FIELD_ID']], $sData); } } public function servicePruneDownloadingJobs() { $aFiles = $this->_oDb->deleteOldDownloadingJobs(); if ($aFiles) foreach ($aFiles as $sFile) @unlink($sFile); } protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array()) { $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams); $aFile = $this->getContentFile($aContentInfo); if (!$aFile['is_image']) { $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->CNF['OBJECT_STORAGE']); $sIcon = $oStorage ? $oStorage->getFontIconNameByFileName($aFile['file_name']) : 'far file'; $aResult['raw'] = $this->_oTemplate->parseHtmlByName('timeline_post.html', array( 'title' => $aResult['title'], 'title_attr' => bx_html_attribute($aResult['title']), 'url' => $aResult['url'], 'icon' => $sIcon, )); $aResult['title'] = ''; } return $aResult; } protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array()) { $aFile = $this->getContentFile($aContentInfo); if (!$aFile) return array(); if (!$aFile['is_image']) return array(); $sPhotoThumb = ''; if ($oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'])) $sPhotoThumb = $oImagesTranscoder->getFileUrl($aFile['id']); return array( array('id' => $aFile['id'], 'url' => $sUrl, 'src' => $sPhotoThumb), ); } public function actionBookmark($iContentId) { if (!$this->isLogged()) return; $aFilesToBookmark = []; if ($iContentId) $aFilesToBookmark = [$iContentId]; elseif (isset($_POST['bulk'])) $aFilesToBookmark = $_POST['bulk']; if ($aFilesToBookmark) foreach ($aFilesToBookmark as $iContentId) { if ($iContentId <= 0) continue; $aData = $this->_oDb->getContentInfoById((int)$iContentId); if (!$aData) continue; $this->_oDb->bookmarkFile((int)$iContentId, bx_get_logged_profile_id()); } } public function actionEntryPreview($iContentId) { $aData = $this->_oDb->getContentInfoById((int)$iContentId); $sJsCss = ''; $sPreviewCode = $this->_serviceTemplateFunc ('entryFilePreview', $iContentId); // various init scripts could be there, which fail to work properly // because of a fact that it is inside a popup which is at the moment is hidden // so we need a way to postpone that initialization $aScripts = []; $sPreviewCode = preg_replace_callback('/