BxTimelineFormPost.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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 Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxTimelineFormPost extends BxBaseModGeneralFormEntry
  15. {
  16. protected $_bAccountMode;
  17. protected $_bPublicMode;
  18. protected $_bProfileMode;
  19. protected $_sType; //--- Is needed for Edit form. Determines which timeline the form was called from.
  20. protected $_bVisibilityAutoselect;
  21. protected $_aUploadersInfo;
  22. public function __construct($aInfo, $oTemplate = false)
  23. {
  24. $this->MODULE = 'bx_timeline';
  25. $this->_bAllowChangeUserForAdmins = false;
  26. parent::__construct($aInfo, $oTemplate);
  27. $this->_sGhostTemplate = 'uploader_nfw.html';
  28. $this->_resetMode();
  29. if(isset($this->aParams['display']))
  30. switch($this->aParams['display']) {
  31. case $this->_oModule->_oConfig->getObject('form_display_post_add'):
  32. $this->setModeAccount();
  33. break;
  34. case $this->_oModule->_oConfig->getObject('form_display_post_add_public'):
  35. $this->setModePublic();
  36. break;
  37. case $this->_oModule->_oConfig->getObject('form_display_post_add_profile'):
  38. $this->setModeProfile();
  39. break;
  40. }
  41. $this->_sType = '';
  42. $this->_bVisibilityAutoselect = true;
  43. $this->_aUploadersInfo = [];
  44. }
  45. public function addCssJsPolls($bDynamicMode = false)
  46. {
  47. $sInclude = parent::addCssJsPolls($bDynamicMode);
  48. $sInclude .= $this->_oModule->_oTemplate->addJs(['polls.js'], $bDynamicMode);
  49. return $bDynamicMode ? $sInclude : '';
  50. }
  51. public function getUploadersInfo($sField = '')
  52. {
  53. if(empty($sField))
  54. return $this->_aUploadersInfo;
  55. $aUploaders = !empty($this->aInputs[$sField]['value']) ? unserialize($this->aInputs[$sField]['value']) : $this->_oModule->_oConfig->getUploaders($sField);
  56. return $this->_aUploadersInfo[array_shift($aUploaders)];
  57. }
  58. public function initChecker($aValues = array (), $aSpecificValues = array())
  59. {
  60. $CNF = &$this->_oModule->_oConfig->CNF;
  61. $bEdit = $this->aParams['display'] == $this->_oModule->_oConfig->getObject('form_display_post_edit');
  62. $iUserId = $this->_oModule->getUserId();
  63. $bValueId = $aValues && !empty($aValues['id']);
  64. $iValueId = $bValueId ? (int)$aValues['id'] : 0;
  65. if($bEdit && isset($aValues[$CNF['FIELD_OWNER_ID']]) && (int)$aValues[$CNF['FIELD_OWNER_ID']] === 0)
  66. $this->setType(BX_BASE_MOD_NTFS_TYPE_PUBLIC);
  67. if(isset($this->aInputs[$CNF['FIELD_ATTACHMENTS']]) && ($oMenu = $this->_oModule->getAttachmentsMenuObject()) !== false) {
  68. $oMenu->setEventById($iValueId);
  69. $oMenu->setUploadersInfo($this->_aUploadersInfo);
  70. $this->aInputs['attachments']['content'] = $oMenu->getCode() . $this->_oModule->_oTemplate->parseHtmlByName('uploader_progress.html', []);;
  71. }
  72. foreach(['FIELD_VIDEO', 'FIELD_FILE'] as $sSetting){
  73. if(!isset($CNF[$sSetting]) || !isset($this->aInputs[$CNF[$sSetting]]))
  74. continue;
  75. $aContentInfo = false;
  76. if($bValueId) {
  77. $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($iValueId);
  78. $this->aInputs[$CNF[$sSetting]]['content_id'] = $iValueId;
  79. }
  80. $this->aInputs[$CNF[$sSetting]]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplate, $this->_getGhostTmplVars($CNF[$sSetting], $aContentInfo));
  81. }
  82. if($bEdit && isset($CNF['FIELD_PUBLISHED']) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
  83. if(isset($aValues[$CNF['FIELD_STATUS']]) && in_array($aValues[$CNF['FIELD_STATUS']], array(BX_TIMELINE_STATUS_ACTIVE, BX_TIMELINE_STATUS_HIDDEN)))
  84. unset($this->aInputs[$CNF['FIELD_PUBLISHED']]);
  85. if(isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && isset($aValues[$CNF['FIELD_OBJECT_ID']]))
  86. $this->aInputs[$CNF['FIELD_ANONYMOUS']]['checked'] = $aValues[$CNF['FIELD_OBJECT_ID']] < 0;
  87. parent::initChecker ($aValues, $aSpecificValues);
  88. if(isset($this->aInputs[$CNF['FIELD_LINK']])) {
  89. if(!$bValueId && !$this->isSubmitted())
  90. $this->_oModule->deleteLinksUnused($iUserId);
  91. $this->aInputs[$CNF['FIELD_LINK']]['content'] = $this->_oModule->_oTemplate->getAttachLinkField($iUserId, $iValueId);
  92. }
  93. }
  94. public function insert($aValsToAdd = array(), $isIgnore = false)
  95. {
  96. $CNF = &$this->_oModule->_oConfig->CNF;
  97. $aValsToAdd[$CNF['FIELD_SYSTEM']] = 0;
  98. $aValsToAdd[$CNF['FIELD_OBJECT_ID']] *= isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && $this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1;
  99. if(isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']])) {
  100. $iAdded = 0;
  101. if(isset($this->aInputs[$CNF['FIELD_ADDED']]))
  102. $iAdded = $this->getCleanValue($CNF['FIELD_ADDED']);
  103. if(empty($iAdded))
  104. $iAdded = time();
  105. $aValsToAdd[$CNF['FIELD_ADDED']] = $iAdded;
  106. if(isset($CNF['FIELD_REACTED']))
  107. $aValsToAdd[$CNF['FIELD_REACTED']] = $iAdded;
  108. }
  109. if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']])) {
  110. $iPublished = 0;
  111. if(isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
  112. $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
  113. if(empty($iPublished))
  114. $iPublished = time();
  115. $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
  116. }
  117. $aValsToAdd[$CNF['FIELD_STATUS']] = $aValsToAdd[$CNF['FIELD_PUBLISHED']] > $aValsToAdd[$CNF['FIELD_ADDED']] ? BX_TIMELINE_STATUS_AWAITING : BX_TIMELINE_STATUS_ACTIVE;
  118. $iContentId = parent::insert ($aValsToAdd, $isIgnore);
  119. if(empty($iContentId))
  120. return $iContentId;
  121. if($this->_bIsApi && ($sKeyF = 'FIELD_OBJECT_PRIVACY_VIEW') && ($mixedAllowViewTo = $this->getCleanValue($CNF[$sKeyF])) !== false) {
  122. $aAllowViewToItems = [];
  123. if(($mixedAllowViewToItems = $this->getCleanValue($CNF[$sKeyF] . '_items')) !== false)
  124. $aAllowViewToItems = explode(',', $mixedAllowViewToItems);
  125. if(($sKeyO = 'OBJECT_PRIVACY_VIEW') && ($sObject = $CNF[$sKeyO]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($sObject)) !== false)
  126. $oPrivacy->addGroupCustom([
  127. 'profile_id' => $aValsToAdd['object_owner_id'],
  128. 'content_id' => 0,
  129. 'object' => $sObject,
  130. 'group_id' => (int)$mixedAllowViewTo
  131. ], $aAllowViewToItems);
  132. }
  133. return $iContentId;
  134. }
  135. function update($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  136. {
  137. $CNF = &$this->_oModule->_oConfig->CNF;
  138. if (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']])) {
  139. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  140. $aValsToAdd[$CNF['FIELD_OBJECT_ID']] = ($this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * abs($aContentInfo[$CNF['FIELD_OBJECT_ID']]);
  141. }
  142. if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']]) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) {
  143. $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
  144. if(empty($iPublished))
  145. $iPublished = time();
  146. $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
  147. }
  148. $mixedResult = parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  149. if($mixedResult !== false) {
  150. if($this->_bIsApi && ($sKeyF = 'FIELD_OBJECT_PRIVACY_VIEW') && ($mixedAllowViewTo = $this->getCleanValue($CNF[$sKeyF])) !== false) {
  151. $aAllowViewToItems = [];
  152. if(($mixedAllowViewToItems = $this->getCleanValue($CNF[$sKeyF] . '_items')) !== false)
  153. $aAllowViewToItems = explode(',', $mixedAllowViewToItems);
  154. if(($sKeyO = 'OBJECT_PRIVACY_VIEW') && ($sObject = $CNF[$sKeyO]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($sObject)) !== false) {
  155. $oPrivacy->editGroupCustom([
  156. 'profile_id' => $iAuthor,
  157. 'content_id' => $iContentId,
  158. 'object' => $sObject,
  159. 'group_id' => (int)$mixedAllowViewTo
  160. ], $aAllowViewToItems);
  161. }
  162. }
  163. }
  164. return $mixedResult;
  165. }
  166. public function addHtmlEditor($iViewMode, &$aInput, $sUniq)
  167. {
  168. $CNF = &$this->_oModule->_oConfig->CNF;
  169. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  170. if (!$oEditor)
  171. return false;
  172. if(in_array($this->aParams['display'], array($this->_oModule->_oConfig->getObject('form_display_post_add'), $this->_oModule->_oConfig->getObject('form_display_post_add_public'))))
  173. $oEditor->setCustomConf("
  174. placeholderText: '" . _t('_bx_timeline_txt_some_text_here') . "',
  175. initOnClick: false,
  176. ");
  177. if(!$this->_oModule->_oConfig->isEditorToolbar())
  178. $oEditor->setCustomToolbarButtons('');
  179. $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]);
  180. return true;
  181. }
  182. public function init()
  183. {
  184. $CNF = &$this->_oModule->_oConfig->CNF;
  185. $iUserId = $this->_oModule->getUserId();
  186. $iOwnerId = $this->_oModule->getOwnerId();
  187. $this->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'post/';
  188. $this->aInputs['owner_id']['value'] = $iOwnerId;
  189. if(isset($this->aInputs['text'])) {
  190. if(empty($this->aInputs['text']['attrs']) || !is_array($this->aInputs['text']['attrs']))
  191. $this->aInputs['text']['attrs'] = array();
  192. $this->aInputs['text']['attrs']['id'] = $this->_oModule->_oConfig->getEditorId();
  193. }
  194. $this->_initPrivacyFields();
  195. if(isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  196. $sStorage = $this->_oModule->_oConfig->getObject('storage_photos');
  197. $sUploadersId = genRndPwd(8, false);
  198. $aUploaders = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $this->_oModule->_oConfig->getUploaders($CNF['FIELD_PHOTO']);
  199. foreach($aUploaders as $sUploader)
  200. $this->_aUploadersInfo[$sUploader] = array(
  201. 'id' => $sUploadersId,
  202. 'name' => $sUploader,
  203. 'js_object' => BxDolUploader::getObjectInstance($sUploader, $sStorage, $sUploadersId)->getNameJsInstanceUploader()
  204. );
  205. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $sStorage;
  206. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
  207. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $this->_oModule->_oConfig->getObject('transcoder_photos_preview');
  208. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders_id'] = $sUploadersId;
  209. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = $aUploaders;
  210. $this->aInputs[$CNF['FIELD_PHOTO']]['upload_buttons_titles'] = array('Simple' => 'camera');
  211. $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
  212. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
  213. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
  214. }
  215. if(isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
  216. $sStorage = $this->_oModule->_oConfig->getObject('storage_videos');
  217. $sUploadersId = genRndPwd(8, false);
  218. $aUploaders = !empty($this->aInputs[$CNF['FIELD_VIDEO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_VIDEO']]['value']) : $this->_oModule->_oConfig->getUploaders($CNF['FIELD_VIDEO']);
  219. foreach($aUploaders as $sUploader)
  220. $this->_aUploadersInfo[$sUploader] = array(
  221. 'id' => $sUploadersId,
  222. 'name' => $sUploader,
  223. 'js_object' => BxDolUploader::getObjectInstance($sUploader, $sStorage, $sUploadersId)->getNameJsInstanceUploader()
  224. );
  225. $this->aInputs[$CNF['FIELD_VIDEO']]['storage_object'] = $sStorage;
  226. $this->aInputs[$CNF['FIELD_VIDEO']]['storage_private'] = 0;
  227. $this->aInputs[$CNF['FIELD_VIDEO']]['images_transcoder'] = $this->_oModule->_oConfig->getObject('transcoder_videos_preview');
  228. $this->aInputs[$CNF['FIELD_VIDEO']]['uploaders_id'] = $sUploadersId;
  229. $this->aInputs[$CNF['FIELD_VIDEO']]['uploaders'] = $aUploaders;
  230. $this->aInputs[$CNF['FIELD_VIDEO']]['upload_buttons_titles'] = array('Simple' => 'video');
  231. $this->aInputs[$CNF['FIELD_VIDEO']]['multiple'] = true;
  232. $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = 0;
  233. $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = '';
  234. }
  235. if(isset($this->aInputs[$CNF['FIELD_FILE']])) {
  236. $sStorage = $this->_oModule->_oConfig->getObject('storage_files');
  237. $sUploadersId = genRndPwd(8, false);
  238. $aUploaders = !empty($this->aInputs[$CNF['FIELD_FILE']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_FILE']]['value']) : $this->_oModule->_oConfig->getUploaders($CNF['FIELD_FILE']);
  239. foreach($aUploaders as $sUploader){
  240. $this->_aUploadersInfo[$sUploader] = array(
  241. 'id' => $sUploadersId,
  242. 'name' => $sUploader,
  243. 'js_object' => BxDolUploader::getObjectInstance($sUploader, $sStorage, $sUploadersId)->getNameJsInstanceUploader()
  244. );
  245. }
  246. $this->aInputs[$CNF['FIELD_FILE']]['storage_object'] = $sStorage;
  247. $this->aInputs[$CNF['FIELD_FILE']]['storage_private'] = 0;
  248. $this->aInputs[$CNF['FIELD_FILE']]['images_transcoder'] = '';
  249. $this->aInputs[$CNF['FIELD_FILE']]['uploaders_id'] = $sUploadersId;
  250. $this->aInputs[$CNF['FIELD_FILE']]['uploaders'] = $aUploaders;
  251. $this->aInputs[$CNF['FIELD_FILE']]['upload_buttons_titles'] = array('Simple' => 'file');
  252. $this->aInputs[$CNF['FIELD_FILE']]['multiple'] = true;
  253. $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = 0;
  254. $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = '';
  255. }
  256. if (isset($this->_oModule->_oConfig->CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$this->_oModule->_oConfig->CNF['FIELD_LOCATION_PREFIX']]))
  257. $this->aInputs[$this->_oModule->_oConfig->CNF['FIELD_LOCATION_PREFIX']]['manual_input'] = false;
  258. }
  259. public function setModePublic()
  260. {
  261. $this->_resetMode();
  262. $this->_bPublicMode = true;
  263. }
  264. public function setModeProfile()
  265. {
  266. $this->_resetMode();
  267. $this->_bProfileMode = true;
  268. }
  269. public function setModeAccount()
  270. {
  271. $this->_resetMode();
  272. $this->_bAccountMode = true;
  273. }
  274. public function setType($sType)
  275. {
  276. $this->_sType = $sType;
  277. switch($this->_sType) {
  278. case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
  279. $this->setModePublic();
  280. break;
  281. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  282. $this->setModeProfile();
  283. break;
  284. case BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS:
  285. case BX_TIMELINE_TYPE_CONNECTED_CONTEXTS:
  286. case BX_TIMELINE_TYPE_FEED:
  287. case BX_TIMELINE_TYPE_FOR_YOU:
  288. $this->setModeAccount();
  289. break;
  290. }
  291. $this->_initPrivacyFields();
  292. }
  293. public function setVisibilityAutoselect($bVisibilityAutoselect)
  294. {
  295. $this->_bVisibilityAutoselect = $bVisibilityAutoselect;
  296. }
  297. protected function genCustomRowObjectCf(&$aInput)
  298. {
  299. return parent::genCustomRowCf($aInput);
  300. }
  301. protected function _getPrivacyFields($aKeysF2O = array())
  302. {
  303. if(empty($aKeysF2O))
  304. $aKeysF2O = array(
  305. 'FIELD_OBJECT_PRIVACY_VIEW' => 'OBJECT_PRIVACY_VIEW'
  306. );
  307. return parent::_getPrivacyFields($aKeysF2O);
  308. }
  309. protected function _initPrivacyFields()
  310. {
  311. $aPrivacyFields = $this->_getPrivacyFields();
  312. foreach($aPrivacyFields as $sField => $sPrivacyObject)
  313. $this->_initPrivacyField($sField, $sPrivacyObject);
  314. }
  315. /**
  316. * The method inherited from BxBaseModGeneralFormEntry class is disabled
  317. * because own variant (method BxTimelineFormPost::_initPrivacyField) is
  318. * used instead.
  319. */
  320. protected function _preparePrivacyField($sField, $sPrivacyObject)
  321. {
  322. return;
  323. }
  324. protected function _initPrivacyField($sField, $sPrivacyObject)
  325. {
  326. $CNF = &$this->_oModule->_oConfig->CNF;
  327. $iUserId = $this->_oModule->getUserId();
  328. $iOwnerId = $this->_oModule->getOwnerId();
  329. $this->aInputs[$sField] = array_merge($this->aInputs[$sField], BxDolPrivacy::getGroupChooser($sPrivacyObject, 0, array(
  330. 'object' => $this->aParams['object'],
  331. 'display' => $this->aParams['display'],
  332. 'title' => _t($CNF['T']['form_input_title_' . $sField]),
  333. 'dynamic_mode' => $this->_bDynamicMode
  334. )));
  335. //--- Show field as is when 'Autoselect' is disabled.
  336. if(!$this->_bVisibilityAutoselect)
  337. return;
  338. //--- Show default privacy groups and followed contexts on Account (Profile + Connections) post form.
  339. if($this->_bAccountMode)
  340. return;
  341. //--- Preselect Context and hide privacy selector when posting in some context (profile, group, space, etc).
  342. if($this->_bProfileMode && $iOwnerId != $iUserId) {
  343. $this->aInputs[$sField]['type'] = 'hidden';
  344. $this->aInputs[$sField]['value'] = -$iOwnerId;
  345. return;
  346. }
  347. $bProfileModeOwner = $this->_bProfileMode && $iOwnerId == $iUserId;
  348. if($this->_bPublicMode || $bProfileModeOwner) {
  349. $iGc = 0;
  350. $iKeyGh = false;
  351. foreach($this->aInputs[$sField]['values'] as $iKey => $aValue) {
  352. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  353. if($iKeyGh !== false && $iGc == 0) {
  354. unset($this->aInputs[$sField]['values'][$iKeyGh]);
  355. $iKeyGh = false;
  356. if($aValue['type'] == 'group_end')
  357. unset($this->aInputs[$sField]['values'][$iKey]);
  358. }
  359. if($aValue['type'] == 'group_header') {
  360. $iGc = 0;
  361. $iKeyGh = $iKey;
  362. }
  363. continue;
  364. }
  365. //--- Show 'Public' privacy group only in Public post form.
  366. if($this->_bPublicMode && $aValue['key'] == BX_DOL_PG_ALL) {
  367. $iGc += 1;
  368. continue;
  369. }
  370. //--- Show a default privacy groups in Profile (for Owner) post form.
  371. if($bProfileModeOwner && (int)$aValue['key'] >= 0) {
  372. $iGc += 1;
  373. continue;
  374. }
  375. unset($this->aInputs[$sField]['values'][$iKey]);
  376. }
  377. }
  378. }
  379. protected function _preloadPrivacyField($sField, $sPrivacyObject, $aValues)
  380. {
  381. $CNF = &$this->_oModule->_oConfig->CNF;
  382. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  383. if(!$oPrivacy)
  384. return;
  385. $iContentId = !empty($aValues[$CNF['FIELD_ID']]) ? (int)$aValues[$CNF['FIELD_ID']] : 0;
  386. $iProfileId = !empty($iContentId) ? (int)$this->getContentOwnerProfileId($iContentId) : bx_get_logged_profile_id();
  387. $iGroupId = !empty($aValues[$sField]) ? $aValues[$sField] : 0;
  388. if(!$this->_bIsApi) {
  389. if(!isset($this->aInputs[$sField]['content']))
  390. $this->aInputs[$sField]['content'] = '';
  391. $this->aInputs[$sField]['content'] .= $oPrivacy->initGroupChooser($sPrivacyObject, $iProfileId, array(
  392. 'content_id' => $iContentId,
  393. 'group_id' => $iGroupId,
  394. 'html_ids' => array(
  395. 'form' => $this->getId()
  396. )
  397. ));
  398. }
  399. else
  400. $this->aInputs[$sField]['subvalue'] = $oPrivacy->initGroupChooserAPI($sPrivacyObject, $iProfileId, [
  401. 'content_id' => $iContentId,
  402. 'group_id' => $iGroupId,
  403. ]);
  404. }
  405. protected function _getGhostTmplVars($sName, $aContentInfo = [])
  406. {
  407. return [
  408. 'js_object' => $this->_oModule->_oConfig->getJsObject('post'),
  409. 'name' => $this->aInputs[$sName]['name'],
  410. 'content_id' => (int)$this->aInputs[$sName]['content_id'],
  411. ];
  412. }
  413. protected function _getPhotoGhostTmplVars($aContentInfo = [])
  414. {
  415. return array_merge(parent::_getPhotoGhostTmplVars($aContentInfo), [
  416. 'js_object' => $this->_oModule->_oConfig->getJsObject('post'),
  417. ]);
  418. }
  419. protected function _resetMode()
  420. {
  421. $this->_bPublicMode = false;
  422. $this->_bProfileMode = false;
  423. $this->_bAccountMode = false;
  424. }
  425. }
  426. /** @} */