1
0

BxBaseModTextFormEntry.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
  15. {
  16. protected $_sGhostTemplateVideo = 'form_ghost_template_video.html';
  17. protected $_sGhostTemplateSound = 'form_ghost_template_sound.html';
  18. protected $_sGhostTemplateFile = 'form_ghost_template_file.html';
  19. public function __construct($aInfo, $oTemplate = false)
  20. {
  21. parent::__construct($aInfo, $oTemplate);
  22. }
  23. function getCode($bDynamicMode = false)
  24. {
  25. $CNF = &$this->_oModule->_oConfig->CNF;
  26. $sResult = parent::getCode($bDynamicMode);
  27. if(!empty($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS'])){
  28. $oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS']);
  29. $oMenu->setContentId((int)$this->_iContentId);
  30. $sResult = $this->_oModule->_oTemplate->parseHtmlByContent($sResult, array(
  31. 'attachments_menu' => $oMenu->getCode()
  32. ));
  33. }
  34. if(isset($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] === true) {
  35. $sInclude = '';
  36. $sInclude .= $this->_oModule->_oTemplate->addCss(array('polls.css'), $bDynamicMode);
  37. $sInclude .= $this->_oModule->_oTemplate->addJs(array('modules/base/text/js/|polls.js', 'polls.js'), $bDynamicMode);
  38. $sResult .= ($bDynamicMode ? $sInclude : '') . $this->_oModule->_oTemplate->getJsCode('poll');
  39. }
  40. if(isset($CNF['PARAM_LINKS_ENABLED']) && $CNF['PARAM_LINKS_ENABLED'] === true) {
  41. $sInclude = '';
  42. $sInclude .= $this->_oModule->_oTemplate->addJs(array('modules/base/text/js/|links.js', 'links.js'), $bDynamicMode);
  43. $sResult .= ($bDynamicMode ? $sInclude : '') . $this->_oModule->_oTemplate->getJsCode('links', ['sFormId' => $this->getId(), 'iContentId' => (int)$this->_iContentId,]);
  44. }
  45. return $sResult;
  46. }
  47. function initChecker ($aValues = array (), $aSpecificValues = array())
  48. {
  49. $CNF = &$this->_oModule->_oConfig->CNF;
  50. $bValues = $aValues && !empty($aValues['id']);
  51. $iValueId = $bValues ? (int)$aValues['id'] : 0;
  52. $iUserId = $this->_oModule->getUserId();
  53. $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
  54. if (isset($CNF['FIELD_VIDEO']) && isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
  55. if ($bValues)
  56. $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = $aValues['id'];
  57. $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateVideo, $this->_getVideoGhostTmplVars($aContentInfo));
  58. }
  59. if(isset($CNF['FIELD_LINK']) && isset($this->aInputs[$CNF['FIELD_LINK']]))
  60. $this->aInputs[$CNF['FIELD_LINK']]['content'] = $this->_oModule->_oTemplate->getAttachLinkField($iUserId, $iValueId);
  61. if (isset($CNF['FIELD_SOUND']) && isset($this->aInputs[$CNF['FIELD_SOUND']])) {
  62. if ($bValues)
  63. $this->aInputs[$CNF['FIELD_SOUND']]['content_id'] = $aValues['id'];
  64. $this->aInputs[$CNF['FIELD_SOUND']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateSound, $this->_getSoundGhostTmplVars($aContentInfo));
  65. }
  66. if (isset($CNF['FIELD_FILE']) && isset($this->aInputs[$CNF['FIELD_FILE']])) {
  67. if ($bValues)
  68. $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = $aValues['id'];
  69. $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateFile, $this->_getFileGhostTmplVars($aContentInfo));
  70. }
  71. if (isset($CNF['FIELD_POLL']) && isset($this->aInputs[$CNF['FIELD_POLL']])) {
  72. if ($bValues)
  73. $this->aInputs[$CNF['FIELD_POLL']]['content_id'] = $aValues['id'];
  74. }
  75. parent::initChecker ($aValues, $aSpecificValues);
  76. }
  77. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  78. {
  79. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  80. }
  81. protected function genCustomInputAttachments ($aInput)
  82. {
  83. return '__attachments_menu__';
  84. }
  85. protected function genCustomInputPolls ($aInput)
  86. {
  87. return $this->_oModule->_oTemplate->getPollField(!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0);
  88. }
  89. public function processPolls ($sFieldPoll, $iContentId = 0)
  90. {
  91. $CNF = &$this->_oModule->_oConfig->CNF;
  92. if (!isset($this->aInputs[$sFieldPoll]))
  93. return true;
  94. $aPollIds = $this->getCleanValue($sFieldPoll);
  95. if(empty($aPollIds) || !is_array($aPollIds))
  96. return true;
  97. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  98. $aPollsDbIds = $this->_oModule->_oDb->getPolls(array('type' => 'content_id_ids', 'content_id' => $iContentId));
  99. //--- Remove deleted
  100. $this->_oModule->_oDb->deletePollsByIds(array_diff($aPollsDbIds, $aPollIds));
  101. //--- Add new
  102. if($iContentId) {
  103. $aPollsAddIds = array_diff($aPollIds, $aPollsDbIds);
  104. foreach($aPollsAddIds as $iPollId)
  105. $this->_oModule->_oDb->updatePolls(array($CNF['FIELD_POLL_CONTENT_ID'] => $iContentId), array($CNF['FIELD_POLL_ID'] => $iPollId, $CNF['FIELD_POLL_CONTENT_ID'] => 0));
  106. }
  107. return true;
  108. }
  109. public function processLinks ($sFieldLink, $iContentId = 0)
  110. {
  111. if (!isset($this->aInputs[$sFieldLink]))
  112. return true;
  113. $aLinkIds = $this->getCleanValue($sFieldLink);
  114. if(empty($aLinkIds) || !is_array($aLinkIds))
  115. return true;
  116. foreach($aLinkIds as $iLinkId)
  117. $this->_oModule->_oDb->saveLink($iContentId, $iLinkId);
  118. }
  119. protected function _getVideoGhostTmplVars($aContentInfo = array())
  120. {
  121. $CNF = &$this->_oModule->_oConfig->CNF;
  122. return array (
  123. 'name' => $this->aInputs[$CNF['FIELD_VIDEO']]['name'],
  124. 'content_id' => (int)$this->aInputs[$CNF['FIELD_VIDEO']]['content_id'],
  125. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  126. 'embed_url' => BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'file_embed_video/',
  127. );
  128. }
  129. protected function _getSoundGhostTmplVars($aContentInfo = array())
  130. {
  131. $CNF = &$this->_oModule->_oConfig->CNF;
  132. return array (
  133. 'name' => $this->aInputs[$CNF['FIELD_SOUND']]['name'],
  134. 'content_id' => (int)$this->aInputs[$CNF['FIELD_SOUND']]['content_id'],
  135. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  136. 'embed_url' => BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'file_embed_sound/',
  137. );
  138. }
  139. protected function _getFileGhostTmplVars($aContentInfo = array())
  140. {
  141. $CNF = &$this->_oModule->_oConfig->CNF;
  142. return array (
  143. 'name' => $this->aInputs[$CNF['FIELD_FILE']]['name'],
  144. 'content_id' => (int)$this->aInputs[$CNF['FIELD_FILE']]['content_id'],
  145. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  146. );
  147. }
  148. }
  149. /** @} */