| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 |
- <?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
- *
- * @{
- */
- /**
- * Create/Edit entry form
- */
- class BxTimelineFormPost extends BxBaseModGeneralFormEntry
- {
- protected $_bAccountMode;
- protected $_bPublicMode;
- protected $_bProfileMode;
- protected $_sType; //--- Is needed for Edit form. Determines which timeline the form was called from.
- protected $_bVisibilityAutoselect;
- protected $_aUploadersInfo;
- public function __construct($aInfo, $oTemplate = false)
- {
- $this->MODULE = 'bx_timeline';
- parent::__construct($aInfo, $oTemplate);
- $this->_sGhostTemplate = 'uploader_nfw.html';
- $this->_resetMode();
- if(isset($this->aParams['display']))
- switch($this->aParams['display']) {
- case $this->_oModule->_oConfig->getObject('form_display_post_add'):
- $this->setModeAccount();
- break;
- case $this->_oModule->_oConfig->getObject('form_display_post_add_public'):
- $this->setModePublic();
- break;
- case $this->_oModule->_oConfig->getObject('form_display_post_add_profile'):
- $this->setModeProfile();
- break;
- }
- $this->_sType = '';
- $this->_bVisibilityAutoselect = true;
- $this->_aUploadersInfo = [];
- }
- public function getUploadersInfo($sField = '')
- {
- if(empty($sField))
- return $this->_aUploadersInfo;
- $aUploaders = !empty($this->aInputs[$sField]['value']) ? unserialize($this->aInputs[$sField]['value']) : $this->_oModule->_oConfig->getUploaders($sField);
- return $this->_aUploadersInfo[array_shift($aUploaders)];
- }
- public function initChecker($aValues = array (), $aSpecificValues = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $bEdit = $this->aParams['display'] == $this->_oModule->_oConfig->getObject('form_display_post_edit');
- $iUserId = $this->_oModule->getUserId();
- $bValueId = $aValues && !empty($aValues['id']);
- $iValueId = $bValueId ? (int)$aValues['id'] : 0;
- if($bEdit && isset($aValues[$CNF['FIELD_OWNER_ID']]) && (int)$aValues[$CNF['FIELD_OWNER_ID']] === 0)
- $this->setType(BX_BASE_MOD_NTFS_TYPE_PUBLIC);
- if(isset($this->aInputs[$CNF['FIELD_ATTACHMENTS']]) && ($oMenu = $this->_oModule->getAttachmentsMenuObject()) !== false) {
- $oMenu->setEventById($iValueId);
- $oMenu->setUploadersInfo($this->_aUploadersInfo);
- $this->aInputs['attachments']['content'] = $oMenu->getCode() . $this->_oModule->_oTemplate->parseHtmlByName('uploader_progress.html', []);;
- }
- if(isset($this->aInputs[$CNF['FIELD_LINK']]))
- $this->aInputs[$CNF['FIELD_LINK']]['content'] = $this->_oModule->_oTemplate->getAttachLinkField($iUserId, $iValueId);
- foreach(['FIELD_VIDEO', 'FIELD_FILE'] as $sSetting){
- if(!isset($CNF[$sSetting]) || !isset($this->aInputs[$CNF[$sSetting]]))
- continue;
- $aContentInfo = false;
- if($bValueId) {
- $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($iValueId);
- $this->aInputs[$CNF[$sSetting]]['content_id'] = $iValueId;
- }
- $this->aInputs[$CNF[$sSetting]]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplate, $this->_getGhostTmplVars($CNF[$sSetting], $aContentInfo));
- }
- if($bEdit && isset($CNF['FIELD_PUBLISHED']) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
- if(isset($aValues[$CNF['FIELD_STATUS']]) && in_array($aValues[$CNF['FIELD_STATUS']], array(BX_TIMELINE_STATUS_ACTIVE, BX_TIMELINE_STATUS_HIDDEN)))
- unset($this->aInputs[$CNF['FIELD_PUBLISHED']]);
- if(isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && isset($aValues[$CNF['FIELD_OBJECT_ID']]))
- $this->aInputs[$CNF['FIELD_ANONYMOUS']]['checked'] = $aValues[$CNF['FIELD_OBJECT_ID']] < 0;
- parent::initChecker ($aValues, $aSpecificValues);
- }
- public function insert($aValsToAdd = array(), $isIgnore = false)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $aValsToAdd[$CNF['FIELD_SYSTEM']] = 0;
- $aValsToAdd[$CNF['FIELD_OBJECT_ID']] *= isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && $this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1;
- if(isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']])) {
- $iAdded = 0;
- if(isset($this->aInputs[$CNF['FIELD_ADDED']]))
- $iAdded = $this->getCleanValue($CNF['FIELD_ADDED']);
-
- if(empty($iAdded))
- $iAdded = time();
- $aValsToAdd[$CNF['FIELD_ADDED']] = $iAdded;
- if(isset($CNF['FIELD_REACTED']))
- $aValsToAdd[$CNF['FIELD_REACTED']] = $iAdded;
- }
- if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']])) {
- $iPublished = 0;
- if(isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
- $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
-
- if(empty($iPublished))
- $iPublished = time();
- $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
- }
- $aValsToAdd[$CNF['FIELD_STATUS']] = $aValsToAdd[$CNF['FIELD_PUBLISHED']] > $aValsToAdd[$CNF['FIELD_ADDED']] ? BX_TIMELINE_STATUS_AWAITING : BX_TIMELINE_STATUS_ACTIVE;
- return parent::insert ($aValsToAdd, $isIgnore);
- }
- function update($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']])) {
- $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
- $aValsToAdd[$CNF['FIELD_OBJECT_ID']] = ($this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * abs($aContentInfo[$CNF['FIELD_OBJECT_ID']]);
- }
- if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']]) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) {
- $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
- if(empty($iPublished))
- $iPublished = time();
- $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
- }
- return parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
- }
- public function addHtmlEditor($iViewMode, &$aInput, $sUniq)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
- if (!$oEditor)
- return false;
- if(in_array($this->aParams['display'], array($this->_oModule->_oConfig->getObject('form_display_post_add'), $this->_oModule->_oConfig->getObject('form_display_post_add_public'))))
- $oEditor->setCustomConf("
- placeholderText: '" . _t('_bx_timeline_txt_some_text_here') . "',
- initOnClick: false,
- ");
- if(!$this->_oModule->_oConfig->isEditorToolbar())
- $oEditor->setCustomToolbarButtons('');
- $this->_sCodeAdd .= $oEditor->attachEditor ('#' . $this->aFormAttrs['id'] . ' [name=' . $aInput['name'] . ']', $iViewMode, $this->_bDynamicMode, ['form_id' => $this->aFormAttrs['id'], 'element_name' => $aInput['name'], 'query_params' => $this->getHtmlEditorQueryParams($aInput), 'uniq' => $sUniq]);
- return true;
- }
- public function init()
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $iUserId = $this->_oModule->getUserId();
- $iOwnerId = $this->_oModule->getOwnerId();
- $this->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'post/';
- $this->aInputs['owner_id']['value'] = $iOwnerId;
- if(isset($this->aInputs['text'])) {
- if(empty($this->aInputs['text']['attrs']) || !is_array($this->aInputs['text']['attrs']))
- $this->aInputs['text']['attrs'] = array();
- $this->aInputs['text']['attrs']['id'] = $this->_oModule->_oConfig->getHtmlIds('post', 'textarea') . time();
- }
- $this->_initPrivacyFields();
- if(isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
- $sStorage = $this->_oModule->_oConfig->getObject('storage_photos');
- $sUploadersId = genRndPwd(8, false);
- $aUploaders = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $this->_oModule->_oConfig->getUploaders($CNF['FIELD_PHOTO']);
- foreach($aUploaders as $sUploader)
- $this->_aUploadersInfo[$sUploader] = array(
- 'id' => $sUploadersId,
- 'name' => $sUploader,
- 'js_object' => BxDolUploader::getObjectInstance($sUploader, $sStorage, $sUploadersId)->getNameJsInstanceUploader()
- );
- $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $sStorage;
- $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
- $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $this->_oModule->_oConfig->getObject('transcoder_photos_preview');
- $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders_id'] = $sUploadersId;
- $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = $aUploaders;
- $this->aInputs[$CNF['FIELD_PHOTO']]['upload_buttons_titles'] = array('Simple' => 'camera');
- $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
- $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
- $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
- }
- if(isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
- $sStorage = $this->_oModule->_oConfig->getObject('storage_videos');
- $sUploadersId = genRndPwd(8, false);
- $aUploaders = !empty($this->aInputs[$CNF['FIELD_VIDEO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_VIDEO']]['value']) : $this->_oModule->_oConfig->getUploaders($CNF['FIELD_VIDEO']);
- foreach($aUploaders as $sUploader)
- $this->_aUploadersInfo[$sUploader] = array(
- 'id' => $sUploadersId,
- 'name' => $sUploader,
- 'js_object' => BxDolUploader::getObjectInstance($sUploader, $sStorage, $sUploadersId)->getNameJsInstanceUploader()
- );
- $this->aInputs[$CNF['FIELD_VIDEO']]['storage_object'] = $sStorage;
- $this->aInputs[$CNF['FIELD_VIDEO']]['storage_private'] = 0;
- $this->aInputs[$CNF['FIELD_VIDEO']]['images_transcoder'] = $this->_oModule->_oConfig->getObject('transcoder_videos_preview');
- $this->aInputs[$CNF['FIELD_VIDEO']]['uploaders_id'] = $sUploadersId;
- $this->aInputs[$CNF['FIELD_VIDEO']]['uploaders'] = $aUploaders;
- $this->aInputs[$CNF['FIELD_VIDEO']]['upload_buttons_titles'] = array('Simple' => 'video');
- $this->aInputs[$CNF['FIELD_VIDEO']]['multiple'] = true;
- $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = 0;
- $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = '';
- }
-
- if(isset($this->aInputs[$CNF['FIELD_FILE']])) {
- $sStorage = $this->_oModule->_oConfig->getObject('storage_files');
- $sUploadersId = genRndPwd(8, false);
- $aUploaders = !empty($this->aInputs[$CNF['FIELD_FILE']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_FILE']]['value']) : $this->_oModule->_oConfig->getUploaders($CNF['FIELD_FILE']);
-
- foreach($aUploaders as $sUploader){
- $this->_aUploadersInfo[$sUploader] = array(
- 'id' => $sUploadersId,
- 'name' => $sUploader,
- 'js_object' => BxDolUploader::getObjectInstance($sUploader, $sStorage, $sUploadersId)->getNameJsInstanceUploader()
- );
- }
-
- $this->aInputs[$CNF['FIELD_FILE']]['storage_object'] = $sStorage;
- $this->aInputs[$CNF['FIELD_FILE']]['storage_private'] = 0;
- $this->aInputs[$CNF['FIELD_FILE']]['images_transcoder'] = '';
- $this->aInputs[$CNF['FIELD_FILE']]['uploaders_id'] = $sUploadersId;
- $this->aInputs[$CNF['FIELD_FILE']]['uploaders'] = $aUploaders;
- $this->aInputs[$CNF['FIELD_FILE']]['upload_buttons_titles'] = array('Simple' => 'file');
- $this->aInputs[$CNF['FIELD_FILE']]['multiple'] = true;
- $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = 0;
- $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = '';
- }
- if (isset($this->_oModule->_oConfig->CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$this->_oModule->_oConfig->CNF['FIELD_LOCATION_PREFIX']]))
- $this->aInputs[$this->_oModule->_oConfig->CNF['FIELD_LOCATION_PREFIX']]['manual_input'] = false;
- }
- public function setModePublic()
- {
- $this->_resetMode();
- $this->_bPublicMode = true;
- }
- public function setModeProfile()
- {
- $this->_resetMode();
- $this->_bProfileMode = true;
- }
- public function setModeAccount()
- {
- $this->_resetMode();
- $this->_bAccountMode = true;
- }
- public function setType($sType)
- {
- $this->_sType = $sType;
- switch($this->_sType) {
- case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
- $this->setModePublic();
- break;
- case BX_BASE_MOD_NTFS_TYPE_OWNER:
- $this->setModeProfile();
- break;
- case BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS:
- case BX_TIMELINE_TYPE_CONNECTED_CONTEXTS:
- case BX_TIMELINE_TYPE_FEED:
- case BX_TIMELINE_TYPE_FEED_AND_HOT:
- $this->setModeAccount();
- break;
- }
- $this->_initPrivacyFields();
- }
- public function setVisibilityAutoselect($bVisibilityAutoselect)
- {
- $this->_bVisibilityAutoselect = $bVisibilityAutoselect;
- }
- protected function genCustomRowObjectCf(&$aInput)
- {
- return parent::genCustomRowCf($aInput);
- }
- protected function _getPrivacyFields($aKeysF2O = array())
- {
- if(empty($aKeysF2O))
- $aKeysF2O = array(
- 'FIELD_OBJECT_PRIVACY_VIEW' => 'OBJECT_PRIVACY_VIEW'
- );
- return parent::_getPrivacyFields($aKeysF2O);
- }
- protected function _initPrivacyFields()
- {
- $aPrivacyFields = $this->_getPrivacyFields();
- foreach($aPrivacyFields as $sField => $sPrivacyObject)
- $this->_initPrivacyField($sField, $sPrivacyObject);
- }
- /**
- * The method inherited from BxBaseModGeneralFormEntry class is disabled
- * because own variant (method BxTimelineFormPost::_initPrivacyField) is
- * used instead.
- */
- protected function _preparePrivacyField($sField, $sPrivacyObject)
- {
- return;
- }
-
-
- protected function _initPrivacyField($sField, $sPrivacyObject)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $iUserId = $this->_oModule->getUserId();
- $iOwnerId = $this->_oModule->getOwnerId();
- $this->aInputs[$sField] = array_merge($this->aInputs[$sField], BxDolPrivacy::getGroupChooser($sPrivacyObject, 0, array(
- 'object' => $this->aParams['object'],
- 'display' => $this->aParams['display'],
- 'title' => _t($CNF['T']['form_input_title_' . $sField]),
- 'dynamic_mode' => $this->_bDynamicMode
- )));
- //--- Show field as is when 'Autoselect' is disabled.
- if(!$this->_bVisibilityAutoselect)
- return;
- //--- Show default privacy groups and followed contexts on Account (Profile + Connections) post form.
- if($this->_bAccountMode)
- return;
- //--- Preselect Context and hide privacy selector when posting in some context (profile, group, space, etc).
- if($this->_bProfileMode && $iOwnerId != $iUserId) {
- $this->aInputs[$sField]['type'] = 'hidden';
- $this->aInputs[$sField]['value'] = -$iOwnerId;
- return;
- }
- $bProfileModeOwner = $this->_bProfileMode && $iOwnerId == $iUserId;
- if($this->_bPublicMode || $bProfileModeOwner) {
- $iGc = 0;
- $iKeyGh = false;
- foreach($this->aInputs[$sField]['values'] as $iKey => $aValue) {
- if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
- if($iKeyGh !== false && $iGc == 0) {
- unset($this->aInputs[$sField]['values'][$iKeyGh]);
- $iKeyGh = false;
- if($aValue['type'] == 'group_end')
- unset($this->aInputs[$sField]['values'][$iKey]);
- }
- if($aValue['type'] == 'group_header') {
- $iGc = 0;
- $iKeyGh = $iKey;
- }
- continue;
- }
- //--- Show 'Public' privacy group only in Public post form.
- if($this->_bPublicMode && $aValue['key'] == BX_DOL_PG_ALL) {
- $iGc += 1;
- continue;
- }
- //--- Show a default privacy groups in Profile (for Owner) post form.
- if($bProfileModeOwner && (int)$aValue['key'] >= 0) {
- $iGc += 1;
- continue;
- }
- unset($this->aInputs[$sField]['values'][$iKey]);
- }
- }
- }
-
- protected function _preloadPrivacyField($sField, $sPrivacyObject, $aValues)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
- if(!$oPrivacy)
- return;
- $iContentId = !empty($aValues[$CNF['FIELD_ID']]) ? (int)$aValues[$CNF['FIELD_ID']] : 0;
- $iProfileId = !empty($iContentId) ? (int)$this->getContentOwnerProfileId($iContentId) : bx_get_logged_profile_id();
- $iGroupId = !empty($aValues[$sField]) ? $aValues[$sField] : 0;
- if(!isset($this->aInputs[$sField]['content']))
- $this->aInputs[$sField]['content'] = '';
- $this->aInputs[$sField]['content'] .= $oPrivacy->initGroupChooser($sPrivacyObject, $iProfileId, array(
- 'content_id' => $iContentId,
- 'group_id' => $iGroupId,
- 'html_ids' => array(
- 'form' => $this->getId()
- )
- ));
- }
- protected function _getGhostTmplVars($sName, $aContentInfo = [])
- {
- return [
- 'js_object' => $this->_oModule->_oConfig->getJsObject('post'),
- 'name' => $this->aInputs[$sName]['name'],
- 'content_id' => (int)$this->aInputs[$sName]['content_id'],
- ];
- }
-
- protected function _getPhotoGhostTmplVars($aContentInfo = [])
- {
- return array_merge(parent::_getPhotoGhostTmplVars($aContentInfo), [
- 'js_object' => $this->_oModule->_oConfig->getJsObject('post'),
- ]);
- }
- protected function _resetMode()
- {
- $this->_bPublicMode = false;
- $this->_bProfileMode = false;
- $this->_bAccountMode = false;
- }
- }
- /** @} */
|