| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup Timeline Timeline
- * @ingroup UnaModules
- *
- * @{
- */
- class BxTimelineResponse extends BxBaseModNotificationsResponse
- {
- public function __construct()
- {
- $this->_sModule = 'bx_timeline';
- parent::__construct();
- }
- /**
- * Overwtire the method of parent class.
- *
- * @param BxDolAlerts $oAlert an instance of alert.
- */
- public function response($oAlert)
- {
- bx_alert($this->_sModule, 'before_register_alert', 0, 0, array(
- 'unit' => $oAlert->sUnit,
- 'action' => $oAlert->sAction,
- 'alert' => &$oAlert,
- ));
-
- $CNF = &$this->_oModule->_oConfig->CNF;
- $sMethod = '_process' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
- if(method_exists($this, $sMethod))
- return $this->$sMethod($oAlert);
- $iObjectAuthorId = $this->_getObjectOwnerId($oAlert->aExtras);
- $iObjectPrivacyView = $this->_getObjectPrivacyView($oAlert->aExtras);
- if($iObjectPrivacyView == BX_DOL_PG_HIDDEN)
- return;
- $aHandler = $this->_oModule->_oConfig->getHandlers($oAlert->sUnit . '_' . $oAlert->sAction);
- if(empty($aHandler) || !is_array($aHandler))
- return;
- $iSilentMode = $this->_oModule->getSilentMode($oAlert->aExtras);
- if(in_array($iSilentMode, array(BX_BASE_MOD_NTFS_SLTMODE_ABSOLUTE, BX_TIMELINE_SLTMODE_ABSOLUTE)))
- return;
- switch($aHandler['type']) {
- case BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT:
- $iOwnerId = abs($oAlert->iSender);
- if($iObjectPrivacyView < 0)
- $iOwnerId = abs($iObjectPrivacyView);
- $sContent = '';
- if(!empty($oAlert->aExtras) && is_array($oAlert->aExtras))
- $sContent = serialize(bx_process_input($oAlert->aExtras));
- $sSource = '';
- if(!empty($oAlert->aExtras['timeline_group']))
- $sSource = $oAlert->aExtras['timeline_group']['by'];
- else
- $sSource = $oAlert->sUnit . '_' . abs($iObjectAuthorId) . '_' . $oAlert->iObject;
- $iDate = time();
- $aEvent = [
- 'owner_id' => $iOwnerId,
- 'type' => $oAlert->sUnit,
- 'action' => $oAlert->sAction,
- 'object_id' => $oAlert->iObject,
- 'object_owner_id' => $iObjectAuthorId,
- 'object_privacy_view' => $iObjectPrivacyView,
- 'object_cf' => $this->_getObjectCf($oAlert->aExtras),
- 'content' => $sContent,
- 'source' => $sSource,
- 'title' => '',
- 'description' => '',
- 'date' => $iDate,
- 'reacted' => $iDate,
- 'status' => $this->_getStatus($oAlert->aExtras),
- 'status_admin' => $this->_getStatus($oAlert->aExtras, 'status_admin'),
- ];
- $sMethod = '_prepareEvent' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
- if(method_exists($this, $sMethod))
- $this->$sMethod($oAlert, $aEvent);
- $sMethod = 'get_timeline_insert_data';
- if(bx_is_srv($oAlert->sUnit, $sMethod))
- $aEvent = bx_srv($oAlert->sUnit, $sMethod, [$oAlert, $aHandler, $aEvent]);
- bx_alert($this->_sModule, 'before_insert_data', 0, 0, [
- 'unit' => $oAlert->sUnit,
- 'action' => $oAlert->sAction,
- 'alert' => $oAlert,
- 'data' => &$aEvent,
- 'data_ref' => &$aEvent,
- ]);
- $iId = $this->_oModule->_oDb->insertEvent($aEvent);
- if(!empty($iId))
- $this->_oModule->onPost($iId);
- break;
- case BX_BASE_MOD_NTFS_HANDLER_TYPE_UPDATE:
- $sMethod = '_getEventUpdate' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
- if(!method_exists($this, $sMethod))
- $sMethod = '_getEventUpdate';
- $aEvent = $this->$sMethod($oAlert, $aHandler);
- if(empty($aEvent) || !is_array($aEvent))
- break;
- $aContent = [];
- if(!empty($aEvent['content']) && is_string($aEvent['content']))
- $aContent = unserialize($aEvent['content']);
- if(!empty($oAlert->aExtras) && is_array($oAlert->aExtras))
- $aContent = array_merge($aContent, bx_process_input($oAlert->aExtras));
- $aParamsSet = ['content' => serialize($aContent)];
- $aParamsSetBySource = [];
- if($iObjectAuthorId != $aEvent['object_owner_id']) {
- $aParamsSet['object_owner_id'] = $iObjectAuthorId;
- $aParamsSetBySource['object_owner_id'] = $iObjectAuthorId;
- }
- if($iObjectPrivacyView > 0)
- $aParamsSet = array_merge($aParamsSet, [
- 'owner_id' => $iObjectAuthorId,
- 'object_privacy_view' => $iObjectPrivacyView
- ]);
- else if($iObjectPrivacyView < 0)
- $aParamsSet = array_merge($aParamsSet, [
- 'owner_id' => abs($iObjectPrivacyView),
- 'object_privacy_view' => $iObjectPrivacyView
- ]);
- $bSource = false;
- $sSource = $aEvent[$CNF['FIELD_SOURCE']];
- if(($bSource = !empty($sSource)) !== false) {
- $sSourceNew = '';
- if(!empty($oAlert->aExtras['timeline_group']))
- $sSourceNew = $oAlert->aExtras['timeline_group']['by'];
- if($sSourceNew && strcmp($sSourceNew, $sSource) != 0) {
- $aParamsSet['source'] = $sSourceNew;
- $aParamsSetBySource['source'] = $sSourceNew;
- }
- }
- foreach(['status', 'status_admin'] as $sStatusKey)
- if(!empty($aContent[$sStatusKey])) {
- $aParamsSet[$sStatusKey] = $aContent[$sStatusKey];
- $aParamsSetBySource[$sStatusKey] = $aContent[$sStatusKey];
- }
- $sMethod = 'get_timeline_update_data';
- if(bx_is_srv($oAlert->sUnit, $sMethod))
- list($aParamsSet, $aParamsSetBySource) = bx_srv($oAlert->sUnit, $sMethod, [$oAlert, $aHandler, $aEvent, [$aParamsSet, $aParamsSetBySource]]);
- bx_alert($this->_sModule, 'before_update_data', 0, 0, [
- 'unit' => $oAlert->sUnit,
- 'action' => $oAlert->sAction,
- 'alert' => $oAlert,
- 'data' => &$aParamsSet,
- 'data_by_source' => &$aParamsSetBySource,
- 'data_ref' => &$aParamsSet,
- 'data_by_source_ref' => &$aParamsSetBySource,
- ]);
- $this->_oModule->_oDb->updateEvent($aParamsSet, ['id' => $aEvent[$CNF['FIELD_ID']]]);
- //--- Delete item cache.
- $this->_oModule->deleteCacheItem($aEvent[$CNF['FIELD_ID']]);
- //--- Update related events.
- if($bSource && !empty($aParamsSetBySource)) {
- $aEventsBySource = $this->_oModule->_oDb->getEvents(['browse' => 'source', 'value' => $sSource]);
- foreach($aEventsBySource as $aEventBySource) {
- if($aEventBySource[$CNF['FIELD_ID']] == $aEvent[$CNF['FIELD_ID']])
- continue;
- $this->_oModule->_oDb->updateEvent($aParamsSetBySource, ['id' => $aEventBySource[$CNF['FIELD_ID']]]);
- //--- Delete item cache.
- $this->_oModule->deleteCacheItem($aEventBySource[$CNF['FIELD_ID']]);
- }
- }
- $this->_oModule->rebuildSlice();
- break;
- case BX_BASE_MOD_NTFS_HANDLER_TYPE_DELETE:
- if($oAlert->sUnit == 'profile' && $oAlert->sAction == 'delete') {
- $aEvents = $this->_oModule->_oDb->getEvents(array('browse' => 'owner_id', 'value' => $oAlert->iObject));
- foreach($aEvents as $aEvent)
- $this->_oModule->deleteEvent($aEvent);
- if(!isset($oAlert->aExtras['delete_with_content']) || !$oAlert->aExtras['delete_with_content'])
- break;
- $aEvents = $this->_oModule->_oDb->getEvents(array('browse' => 'common_by_object', 'value' => $oAlert->iObject));
- foreach($aEvents as $aEvent)
- $this->_oModule->deleteEvent($aEvent);
- break;
- }
- $sMethod = '_getEventDelete' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
- if(!method_exists($this, $sMethod))
- $sMethod = '_getEventDelete';
- $aEvent = $this->$sMethod($oAlert, $aHandler);
- if(empty($aEvent) || !is_array($aEvent))
- break;
- $sMethod = 'get_timeline_delete_data';
- if(bx_is_srv($oAlert->sUnit, $sMethod))
- $aEvent = bx_srv($oAlert->sUnit, $sMethod, [$oAlert, $aHandler, $aEvent]);
- $this->_oModule->deleteEvent($aEvent);
- break;
- }
- }
- protected function _prepareEventCommentAdded($oAlert, &$aEvent)
- {
- $aEvent = array_merge($aEvent, array(
- 'object_id' => $oAlert->aExtras['comment_uniq_id'],
- 'object_owner_id' => $oAlert->aExtras['comment_author_id'],
- ));
- }
- protected function _getEventUpdateCommentEdited(&$oAlert, &$aHandler)
- {
- $aHandlers = $this->_oModule->_oDb->getHandlers([
- 'type' => 'by_group_key_type',
- 'group' => $aHandler['group']
- ]);
- return $this->_oModule->_oDb->getEvents([
- 'browse' => 'descriptor',
- 'type' => $oAlert->sUnit,
- 'action' => $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'],
- 'object_id' => $oAlert->aExtras['comment_uniq_id']
- ]);
- }
- protected function _getEventDelete(&$oAlert, &$aHandler)
- {
- $aHandlers = $this->_oModule->_oDb->getHandlers([
- 'type' => 'by_group_key_type',
- 'group' => $aHandler['group']
- ]);
- return $this->_oModule->_oDb->getEvents([
- 'browse' => 'descriptor',
- 'type' => $oAlert->sUnit,
- 'action' => $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'],
- 'object_id' => $oAlert->iObject
- ]);
- }
-
- protected function _getEventDeleteCommentDeleted(&$oAlert, &$aHandler)
- {
- $aHandlers = $this->_oModule->_oDb->getHandlers([
- 'type' => 'by_group_key_type',
- 'group' => $aHandler['group']
- ]);
- return $this->_oModule->_oDb->getEvents([
- 'browse' => 'descriptor',
- 'type' => $oAlert->sUnit,
- 'action' => $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'],
- 'object_id' => $oAlert->aExtras['comment_uniq_id']
- ]);
- }
- protected function _getStatus($aExtras, $sField = 'status')
- {
- return ($sValue = $this->_getFieldValue($aExtras, $sField)) !== false ? $sValue : 'active';
- }
- protected function _getFieldValue($aExtras, $sField)
- {
- return isset($aExtras[$sField]) ? $aExtras[$sField] : false;
- }
- protected function _processSystemClearCache($oAlert)
- {
- if(!in_array($oAlert->aExtras['type'], array('all', 'custom')))
- return;
- $this->_clearCache();
- }
- protected function _processSystemEnable($oAlert)
- {
- $aModuleConfig = $oAlert->aExtras['config'];
- if(empty($aModuleConfig) || !is_array($aModuleConfig))
- return false;
- $sName = $aModuleConfig['name'];
- if(!bx_srv_ii('system', 'is_module_context', [$sName]))
- return false;
- return $this->_oModule->serviceFeedsMenuAdd($sName);
- }
- protected function _processSystemDisable($oAlert)
- {
- $aModuleConfig = $oAlert->aExtras['config'];
- if(empty($aModuleConfig) || !is_array($aModuleConfig))
- return false;
- $sName = $aModuleConfig['name'];
- if(!bx_srv_ii('system', 'is_module_context', [$sName]))
- return false;
- return $this->_oModule->serviceFeedsMenuDelete($sName);
- }
- protected function _processSystemSaveSetting($oAlert)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if($CNF['PARAM_SEARCHABLE_FIELDS'] != $oAlert->aExtras['option'])
- return;
- $this->_oModule->_oDb->alterFulltextIndex();
- }
- protected function _processAccountConfirm($oAlert)
- {
- $this->_clearCache();
- }
- protected function _processAccountUnconfirm($oAlert)
- {
- $this->_clearCache();
- }
- protected function _processProfileApprove($oAlert)
- {
- $this->_clearCache();
- }
- protected function _processProfileDisapprove($oAlert)
- {
- $this->_clearCache();
- }
- protected function _processProfileActivate($oAlert)
- {
- $this->_clearCache();
- }
- protected function _processProfileSuspend($oAlert)
- {
- $this->_clearCache();
- }
- protected function _clearCache()
- {
- //--- Clear item cache.
- $this->_oModule->getCacheItemObject()->removeAllByPrefix($this->_oModule->_oConfig->getPrefix('cache_item'));
- }
- protected function _processBxTimelineVideosMp4Transcoded($oAlert)
- {
- $this->_onVideoTranscoded($oAlert->iObject, $oAlert->aExtras['ret']);
- }
- protected function _onVideoTranscoded($iMediaId, $bResult, $aParams = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if(!isset($CNF['FIELD_STATUS']))
- return;
- $aMedia = $this->_oModule->_oDb->getMediaById($CNF['FIELD_VIDEO'], $iMediaId);
- if(empty($aMedia) || !is_array($aMedia))
- return;
- $iContentId = (int)$aMedia['event_id'];
- $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return;
- if(!isset($aContentInfo[$CNF['FIELD_STATUS']]) || $aContentInfo[$CNF['FIELD_STATUS']] != 'awaiting')
- return;
- $iNow = time();
- $bNotify = $iNow - $aContentInfo[$CNF['FIELD_ADDED']] > $this->_oModule->_oConfig->getDpnTime();
- $iSystemBotProfileId = (int)getParam('sys_profile_bot');
- $iAuthorProfileId = $aContentInfo[$CNF['FIELD_' . ((int)$aContentInfo[$CNF['FIELD_SYSTEM']] == 0 ? 'OBJECT_ID' : 'OWNER_ID')]];
- if(!$bResult) {
- if((int)$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'failed'), array($CNF['FIELD_ID'] => $iContentId)) > 0) {
- $this->_oModule->onFailed($iContentId);
- if($bNotify)
- bx_alert($this->_sModule, 'publish_failed', $aContentInfo[$CNF['FIELD_ID']], $iSystemBotProfileId, array(
- 'object_author_id' => $iAuthorProfileId,
- 'privacy_view' => BX_DOL_PG_ALL
- ));
- }
- return;
- }
- if(isset($CNF['FIELD_PUBLISHED']) && isset($aContentInfo[$CNF['FIELD_PUBLISHED']]) && $aContentInfo[$CNF['FIELD_PUBLISHED']] > $iNow)
- return;
- $oTranscoder = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
- $aMediasToCheck = $this->_oModule->_oDb->getMedia($CNF['FIELD_VIDEO'], $iContentId, 0, true);
- foreach($aMediasToCheck as $aMediaToCheck)
- if($oTranscoder->isMimeTypeSupported($aMediaToCheck['mime_type']) && !$oTranscoder->isFileReady($aMediaToCheck['id']))
- return;
- if(!$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'active'), array($CNF['FIELD_ID'] => $iContentId)))
- return;
- $this->_oModule->onPublished($iContentId);
- if($bNotify)
- bx_alert($this->_sModule, 'publish_succeeded', $aContentInfo[$CNF['FIELD_ID']], $iSystemBotProfileId, array(
- 'object_author_id' => $iAuthorProfileId,
- 'privacy_view' => BX_DOL_PG_ALL
- ));
- }
- }
- /** @} */
|