1
0

BxBaseModTextFormEntry.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 addCssJsPolls($bDynamicMode = false)
  24. {
  25. $sInclude = parent::addCssJsPolls($bDynamicMode);
  26. $sInclude .= $this->_oModule->_oTemplate->addJs(['modules/base/text/js/|polls.js', 'polls.js'], $bDynamicMode);
  27. return $bDynamicMode ? $sInclude : '';
  28. }
  29. function getCode($bDynamicMode = false)
  30. {
  31. $CNF = &$this->_oModule->_oConfig->CNF;
  32. $sResult = parent::getCode($bDynamicMode);
  33. if(!empty($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS'])){
  34. $oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS']);
  35. $oMenu->setContentId((int)$this->_iContentId);
  36. $sResult = $this->_oModule->_oTemplate->parseHtmlByContent($sResult, array(
  37. 'attachments_menu' => $oMenu->getCode()
  38. ));
  39. }
  40. if(isset($CNF['PARAM_LINKS_ENABLED']) && $CNF['PARAM_LINKS_ENABLED'] === true) {
  41. $sInclude = '';
  42. $sInclude .= $this->_oModule->_oTemplate->addCss(array('links.css'), $bDynamicMode);
  43. $sInclude .= $this->_oModule->_oTemplate->addJs(array('modules/base/text/js/|links.js', 'links.js'), $bDynamicMode);
  44. $sResult .= ($bDynamicMode ? $sInclude : '') . $this->_oModule->_oTemplate->getJsCode('links', [
  45. 'sFormId' => $this->getId(),
  46. 'iContentId' => (int)$this->_iContentId,
  47. 'iLimitAttachLinks' => (int)getParam($CNF['PARAM_LINKS_LIMIT']),
  48. 'sLimitAttachLinksErr' => bx_js_string(_t('_sys_txt_err_attach_links')),
  49. 'oAttachedLinks' => []
  50. ]);
  51. }
  52. return $sResult;
  53. }
  54. function initChecker ($aValues = array (), $aSpecificValues = array())
  55. {
  56. $CNF = &$this->_oModule->_oConfig->CNF;
  57. $bValues = $aValues && !empty($aValues['id']);
  58. $iValueId = $bValues ? (int)$aValues['id'] : 0;
  59. $iUserId = $this->_oModule->getUserId();
  60. $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
  61. if (isset($CNF['FIELD_VIDEO']) && isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
  62. if ($bValues)
  63. $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = $aValues['id'];
  64. $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateVideo, $this->_getVideoGhostTmplVars($aContentInfo));
  65. }
  66. if (isset($CNF['FIELD_SOUND']) && isset($this->aInputs[$CNF['FIELD_SOUND']])) {
  67. if ($bValues)
  68. $this->aInputs[$CNF['FIELD_SOUND']]['content_id'] = $aValues['id'];
  69. $this->aInputs[$CNF['FIELD_SOUND']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateSound, $this->_getSoundGhostTmplVars($aContentInfo));
  70. }
  71. if (isset($CNF['FIELD_FILE']) && isset($this->aInputs[$CNF['FIELD_FILE']])) {
  72. if ($bValues)
  73. $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = $aValues['id'];
  74. $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateFile, $this->_getFileGhostTmplVars($aContentInfo));
  75. }
  76. parent::initChecker ($aValues, $aSpecificValues);
  77. if(isset($CNF['FIELD_LINK']) && isset($this->aInputs[$CNF['FIELD_LINK']])) {
  78. if(!$iValueId && !$this->isSubmitted())
  79. $this->_oModule->deleteAttachLinksUnused($iUserId);
  80. $this->aInputs[$CNF['FIELD_LINK']]['content'] = $this->_oModule->_oTemplate->getAttachLinkField($iUserId, $iValueId);
  81. }
  82. }
  83. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  84. {
  85. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  86. }
  87. protected function genCustomInputAttachments ($aInput)
  88. {
  89. return '__attachments_menu__' . $this->_oModule->_oTemplate->parseHtmlByName('uploader_progress.html', []);
  90. }
  91. public function processLinks ($sFieldLink, $iContentId = 0)
  92. {
  93. if (!isset($this->aInputs[$sFieldLink]))
  94. return true;
  95. $aLinkIds = $this->getCleanValue($sFieldLink);
  96. if(empty($aLinkIds) || !is_array($aLinkIds))
  97. return true;
  98. foreach($aLinkIds as $iLinkId)
  99. $this->_oModule->_oDb->saveLink($iContentId, $iLinkId);
  100. }
  101. protected function _getVideoGhostTmplVars($aContentInfo = array())
  102. {
  103. $CNF = &$this->_oModule->_oConfig->CNF;
  104. return array (
  105. 'name' => $this->aInputs[$CNF['FIELD_VIDEO']]['name'],
  106. 'content_id' => (int)$this->aInputs[$CNF['FIELD_VIDEO']]['content_id'],
  107. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  108. 'embed_url' => BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'file_embed_video/',
  109. );
  110. }
  111. protected function _getSoundGhostTmplVars($aContentInfo = array())
  112. {
  113. $CNF = &$this->_oModule->_oConfig->CNF;
  114. return array (
  115. 'name' => $this->aInputs[$CNF['FIELD_SOUND']]['name'],
  116. 'content_id' => (int)$this->aInputs[$CNF['FIELD_SOUND']]['content_id'],
  117. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  118. 'embed_url' => BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'file_embed_sound/',
  119. );
  120. }
  121. protected function _getFileGhostTmplVars($aContentInfo = array())
  122. {
  123. $CNF = &$this->_oModule->_oConfig->CNF;
  124. return array (
  125. 'name' => $this->aInputs[$CNF['FIELD_FILE']]['name'],
  126. 'content_id' => (int)$this->aInputs[$CNF['FIELD_FILE']]['content_id'],
  127. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  128. );
  129. }
  130. }
  131. /** @} */