BxTimelineFormPost.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 $_bPublicMode;
  17. protected $_bProfileMode;
  18. public function __construct($aInfo, $oTemplate = false)
  19. {
  20. $this->MODULE = 'bx_timeline';
  21. parent::__construct($aInfo, $oTemplate);
  22. $iUserId = $this->_oModule->getUserId();
  23. $iOwnerId = $this->_oModule->getOwnerId();
  24. $this->_bPublicMode = isset($this->aParams['display']) && $this->aParams['display'] == $this->_oModule->_oConfig->getObject('form_display_post_add_public');
  25. $this->_bProfileMode = isset($this->aParams['display']) && $this->aParams['display'] == $this->_oModule->_oConfig->getObject('form_display_post_add_profile');
  26. $this->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'post/';
  27. $this->aInputs['owner_id']['value'] = $iOwnerId;
  28. if(!$this->_bPublicMode && !$this->_bProfileMode) {
  29. $this->aInputs['owner_id']['values'] = array(
  30. array ('key' => $iUserId, 'value' => _t('_bx_timeline_form_post_input_owner_id_own')),
  31. );
  32. $oProfileQuery = BxDolProfileQuery::getInstance();
  33. $sConnections = $this->_oModule->_oConfig->getObject('conn_subscriptions');
  34. $aConnections = BxDolConnection::getObjectInstance($sConnections)->getConnectedContent($iUserId);
  35. $aCnnGroups = array();
  36. foreach($aConnections as $iId) {
  37. $aProfileInfo = $oProfileQuery->getInfoById($iId);
  38. if(empty($aProfileInfo) || !is_array($aProfileInfo))
  39. continue;
  40. $aCnnGroups[$aProfileInfo['type']][] = $aProfileInfo['id'];
  41. }
  42. $oProfile = BxDolProfile::getInstance();
  43. foreach($aCnnGroups as $sCnnGroup => $aCnnGroup) {
  44. $this->aInputs['owner_id']['values'][] = array('type' => 'group_header', 'value' => _t('_bx_timeline_form_post_input_owner_id_following_group', _t('_' . $sCnnGroup)));
  45. foreach($aCnnGroup as $iId)
  46. $this->aInputs['owner_id']['values'][] = array('key' => $iId, 'value' => $oProfile->getDisplayName($iId));
  47. $this->aInputs['owner_id']['values'][] = array('type' => 'group_end');
  48. }
  49. }
  50. else
  51. $this->aInputs['owner_id']['type'] = 'hidden';
  52. if(isset($this->aInputs['text'])) {
  53. if(empty($this->aInputs['text']['attrs']) || !is_array($this->aInputs['text']['attrs']))
  54. $this->aInputs['text']['attrs'] = array();
  55. $this->aInputs['text']['attrs']['id'] = $this->_oModule->_oConfig->getHtmlIds('post', 'textarea') . time();
  56. }
  57. if(isset($this->aInputs['object_privacy_view'])) {
  58. $this->aInputs['object_privacy_view'] = array_merge($this->aInputs['object_privacy_view'], BxDolPrivacy::getGroupChooser($this->_oModule->_oConfig->getObject('privacy_view'), 0, array(
  59. 'title' => _t('_bx_timeline_form_post_input_object_privacy_view')
  60. )));
  61. if($this->_bPublicMode || ($this->_bProfileMode && $iOwnerId != $iUserId))
  62. foreach($this->aInputs['object_privacy_view']['values'] as $iKey => $aValue)
  63. if($aValue['key'] !== BX_DOL_PG_ALL)
  64. unset($this->aInputs['object_privacy_view']['values'][$iKey]);
  65. }
  66. if(isset($this->aInputs['link']))
  67. $this->aInputs['link']['content'] = $this->_oModule->_oTemplate->getAttachLinkField($iUserId);
  68. if(isset($this->aInputs['photo'])) {
  69. $aFormNested = array(
  70. 'params' =>array(
  71. 'nested_form_template' => 'uploader_nfw.html'
  72. ),
  73. 'inputs' => array(),
  74. );
  75. $oFormNested = new BxDolFormNested('photo', $aFormNested, 'do_submit', $this->_oModule->_oTemplate);
  76. $this->aInputs['photo']['storage_object'] = $this->_oModule->_oConfig->getObject('storage_photos');
  77. $this->aInputs['photo']['images_transcoder'] = $this->_oModule->_oConfig->getObject('transcoder_photos_preview');
  78. $this->aInputs['photo']['uploaders'] = !empty($this->aInputs['photo']['value']) ? unserialize($this->aInputs['photo']['value']) : $this->_oModule->_oConfig->getUploaders('photo');
  79. $this->aInputs['photo']['upload_buttons_titles'] = array('Simple' => 'camera');
  80. $this->aInputs['photo']['multiple'] = true;
  81. $this->aInputs['photo']['ghost_template'] = $oFormNested;
  82. }
  83. if(isset($this->aInputs['video'])) {
  84. $aFormNested = array(
  85. 'params' =>array(
  86. 'nested_form_template' => 'uploader_nfw.html'
  87. ),
  88. 'inputs' => array(),
  89. );
  90. $oFormNested = new BxDolFormNested('video', $aFormNested, 'do_submit', $this->_oModule->_oTemplate);
  91. $this->aInputs['video']['storage_object'] = $this->_oModule->_oConfig->getObject('storage_videos');
  92. $this->aInputs['video']['images_transcoder'] = $this->_oModule->_oConfig->getObject('transcoder_videos_poster');
  93. $this->aInputs['video']['uploaders'] = !empty($this->aInputs['video']['value']) ? unserialize($this->aInputs['video']['value']) : $this->_oModule->_oConfig->getUploaders('video');
  94. $this->aInputs['video']['upload_buttons_titles'] = array('Simple' => 'video-camera');
  95. $this->aInputs['video']['multiple'] = true;
  96. $this->aInputs['video']['ghost_template'] = $oFormNested;
  97. }
  98. if(isset($this->aInputs['attachments']))
  99. $this->aInputs['attachments']['content'] = '__attachments_menu__';
  100. if (isset($this->_oModule->_oConfig->CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$this->_oModule->_oConfig->CNF['FIELD_LOCATION_PREFIX']]))
  101. $this->aInputs[$this->_oModule->_oConfig->CNF['FIELD_LOCATION_PREFIX']]['manual_input'] = false;
  102. }
  103. public function getCode($bDynamicMode = false)
  104. {
  105. $sResult = parent::getCode($bDynamicMode);
  106. return $this->_oModule->_oTemplate->parseHtmlByContent($sResult, array(
  107. 'attachments_menu' => $this->_oModule->getAttachmentsMenuObject()->getCode()
  108. ));
  109. }
  110. public function addHtmlEditor($iViewMode, &$aInput)
  111. {
  112. $CNF = &$this->_oModule->_oConfig->CNF;
  113. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  114. if (!$oEditor)
  115. return false;
  116. if(in_array($this->aParams['display'], array($this->_oModule->_oConfig->getObject('form_display_post_add'), $this->_oModule->_oConfig->getObject('form_display_post_add_public'))))
  117. $oEditor->setCustomConf("
  118. placeholderText: '" . _t('_bx_timeline_txt_some_text_here') . "',
  119. initOnClick: false,
  120. ");
  121. $oEditor->setCustomToolbarButtons('');
  122. $this->_sCodeAdd .= $oEditor->attachEditor ('#' . $this->aFormAttrs['id'] . ' [name='.$aInput['name'].']', $iViewMode, $this->_bDynamicMode);
  123. return true;
  124. }
  125. }
  126. /** @} */