| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup Files Files
- * @ingroup UnaModules
- *
- * @{
- */
- /**
- * Files module
- */
- class BxFilesModule extends BxBaseModTextModule
- {
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- }
- /**
- * Display entries of the author
- * @return HTML string
- */
- public function serviceBrowseGroupAuthor ($iProfileId = 0, $aParams = array())
- {
- if (!$iProfileId)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- if (!$iProfileId)
- return '';
- if (!($oGroupProfile = BxDolProfile::getInstance($iProfileId)))
- return '';
- if (!BxDolService::call($oGroupProfile->getModule(), 'is_group_profile'))
- return '';
-
- return $this->_serviceBrowse ('group_author', array_merge(array('author' => $iProfileId), $aParams), BX_DB_PADDING_DEF, true);
- }
- public function serviceIsAllowedAddContentToProfile($iGroupProfileId)
- {
- if (!$iGroupProfileId || !($oProfile = BxDolProfile::getInstance((int)$iGroupProfileId)))
- return false;
- 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;
- }
- 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 ()
- {
- return _t('_sys_txt_access_denied');
- }
- public function actionDownload($iContentId)
- {
- $sToken = bx_get('token');
- $CNF = $this->_oConfig->CNF;
-
- $aData = $this->_oDb->getContentInfoById((int)$iContentId);
- if (!$aData) {
- $this->_oTemplate->displayPageNotFound();
- return;
- }
- if (CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedView($aData)) {
- $this->_oTemplate->displayAccessDenied();
- return;
- }
- $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)) {
- $this->_oTemplate->displayErrorOccured();
- return;
- }
-
- exit;
- }
-
- public function getContentFile($aData)
- {
- $CNF = $this->_oConfig->CNF;
- if (!isset($aData[$CNF['FIELD_AUTHOR']]) || !isset($aData[$CNF['FIELD_ID']]))
- return false;
- $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
- if (!$oStorage)
- return false;
- if (isset($aData[$CNF['FIELD_FILE_ID']]) && $aData[$CNF['FIELD_FILE_ID']])
- return $oStorage->getFile($aData[$CNF['FIELD_FILE_ID']]);
-
- $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]);
- if (!$aGhostFiles)
- return false;
- return array_pop($aGhostFiles);
- }
- 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') . '" -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);
- }
- }
- }
- /** @} */
|