BxBaseModTextFormEntry.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. $sResult = $this->_oModule->_oTemplate->parseHtmlByContent($sResult, array(
  29. 'attachments_menu' => BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS'])->getCode()
  30. ));
  31. if(isset($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] === true) {
  32. $sInclude = '';
  33. $sInclude .= $this->_oModule->_oTemplate->addCss(array('polls.css'), $bDynamicMode);
  34. $sInclude .= $this->_oModule->_oTemplate->addJs(array('modules/base/text/js/|polls.js', 'polls.js'), $bDynamicMode);
  35. $sResult .= ($bDynamicMode ? $sInclude : '') . $this->_oModule->_oTemplate->getJsCode('poll');
  36. }
  37. return $sResult;
  38. }
  39. function initChecker ($aValues = array (), $aSpecificValues = array())
  40. {
  41. $CNF = &$this->_oModule->_oConfig->CNF;
  42. $bValues = $aValues && !empty($aValues['id']);
  43. $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
  44. if (isset($CNF['FIELD_VIDEO']) && isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
  45. if ($bValues)
  46. $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = $aValues['id'];
  47. $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateVideo, $this->_getVideoGhostTmplVars($aContentInfo));
  48. }
  49. if (isset($CNF['FIELD_SOUND']) && isset($this->aInputs[$CNF['FIELD_SOUND']])) {
  50. if ($bValues)
  51. $this->aInputs[$CNF['FIELD_SOUND']]['content_id'] = $aValues['id'];
  52. $this->aInputs[$CNF['FIELD_SOUND']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateSound, $this->_getSoundGhostTmplVars($aContentInfo));
  53. }
  54. if (isset($CNF['FIELD_FILE']) && isset($this->aInputs[$CNF['FIELD_FILE']])) {
  55. if ($bValues)
  56. $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = $aValues['id'];
  57. $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateFile, $this->_getFileGhostTmplVars($aContentInfo));
  58. }
  59. if (isset($CNF['FIELD_POLL']) && isset($this->aInputs[$CNF['FIELD_POLL']])) {
  60. if ($bValues)
  61. $this->aInputs[$CNF['FIELD_POLL']]['content_id'] = $aValues['id'];
  62. }
  63. parent::initChecker ($aValues, $aSpecificValues);
  64. }
  65. public function insert ($aValsToAdd = array(), $isIgnore = false)
  66. {
  67. $CNF = &$this->_oModule->_oConfig->CNF;
  68. if(!$this->_oModule->_isModerator() && !$this->_oModule->_oConfig->isAutoApproveEnabled())
  69. $aValsToAdd[$CNF['FIELD_STATUS_ADMIN']] = BX_BASE_MOD_TEXT_STATUS_PENDING;
  70. return parent::insert($aValsToAdd, $isIgnore);
  71. }
  72. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  73. {
  74. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  75. }
  76. protected function genCustomInputAttachments ($aInput)
  77. {
  78. return '__attachments_menu__';
  79. }
  80. protected function genCustomInputPolls ($aInput)
  81. {
  82. return $this->_oModule->_oTemplate->getPollField(!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0);
  83. }
  84. public function processPolls ($sFieldPoll, $iContentId = 0)
  85. {
  86. $CNF = &$this->_oModule->_oConfig->CNF;
  87. if (!isset($this->aInputs[$sFieldPoll]))
  88. return true;
  89. $aPollIds = $this->getCleanValue($sFieldPoll);
  90. if(empty($aPollIds) || !is_array($aPollIds))
  91. return true;
  92. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  93. $aPollsDbIds = $this->_oModule->_oDb->getPolls(array('type' => 'content_id_ids', 'content_id' => $iContentId));
  94. //--- Remove deleted
  95. $this->_oModule->_oDb->deletePollsByIds(array_diff($aPollsDbIds, $aPollIds));
  96. //--- Add new
  97. if($iContentId) {
  98. $aPollsAddIds = array_diff($aPollIds, $aPollsDbIds);
  99. foreach($aPollsAddIds as $iPollId)
  100. $this->_oModule->_oDb->updatePolls(array($CNF['FIELD_POLL_CONTENT_ID'] => $iContentId), array($CNF['FIELD_POLL_ID'] => $iPollId, $CNF['FIELD_POLL_CONTENT_ID'] => 0));
  101. }
  102. return true;
  103. }
  104. protected function _getVideoGhostTmplVars($aContentInfo = array())
  105. {
  106. $CNF = &$this->_oModule->_oConfig->CNF;
  107. return array (
  108. 'name' => $this->aInputs[$CNF['FIELD_VIDEO']]['name'],
  109. 'content_id' => (int)$this->aInputs[$CNF['FIELD_VIDEO']]['content_id'],
  110. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  111. 'embed_url' => BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'file_embed_video/',
  112. );
  113. }
  114. protected function _getSoundGhostTmplVars($aContentInfo = array())
  115. {
  116. $CNF = &$this->_oModule->_oConfig->CNF;
  117. return array (
  118. 'name' => $this->aInputs[$CNF['FIELD_SOUND']]['name'],
  119. 'content_id' => (int)$this->aInputs[$CNF['FIELD_SOUND']]['content_id'],
  120. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  121. 'embed_url' => BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'file_embed_sound/',
  122. );
  123. }
  124. protected function _getFileGhostTmplVars($aContentInfo = array())
  125. {
  126. $CNF = &$this->_oModule->_oConfig->CNF;
  127. return array (
  128. 'name' => $this->aInputs[$CNF['FIELD_FILE']]['name'],
  129. 'content_id' => (int)$this->aInputs[$CNF['FIELD_FILE']]['content_id'],
  130. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  131. );
  132. }
  133. }
  134. /** @} */