BxBaseModTextFormEntry.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 $_sGhostTemplate = 'form_ghost_template.html';
  17. public function __construct($aInfo, $oTemplate = false)
  18. {
  19. parent::__construct($aInfo, $oTemplate);
  20. $CNF = &$this->_oModule->_oConfig->CNF;
  21. if (isset($this->aInputs[$CNF['FIELD_TEXT']])) {
  22. $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] = array_merge (
  23. array ('id' => $CNF['FIELD_TEXT_ID']),
  24. is_array($this->aInputs[$CNF['FIELD_TEXT']]['attrs']) ? $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] : array ()
  25. );
  26. }
  27. if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  28. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE'];
  29. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $CNF['OBJECT_UPLOADERS'];
  30. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
  31. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
  32. $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
  33. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
  34. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
  35. }
  36. if (isset($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]))
  37. $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = array_merge($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']], BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']));
  38. if (isset($this->aInputs['do_publish']) && !isset($this->aInputs['do_submit']))
  39. $this->aParams['db']['submit_name'] = 'do_publish';
  40. }
  41. function initChecker ($aValues = array (), $aSpecificValues = array())
  42. {
  43. $CNF = &$this->_oModule->_oConfig->CNF;
  44. if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  45. $aContentInfo = false;
  46. if ($aValues && !empty($aValues['id'])) {
  47. $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($aValues['id']);
  48. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = $aValues['id'];
  49. }
  50. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplate, $this->_getPhotoGhostTmplVars($aContentInfo));
  51. }
  52. return parent::initChecker($aValues, $aSpecificValues);
  53. }
  54. public function insert ($aValsToAdd = array(), $isIgnore = false)
  55. {
  56. $CNF = &$this->_oModule->_oConfig->CNF;
  57. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb()) {
  58. $aThumb = isset($_POST[$CNF['FIELD_THUMB']]) ? bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT) : false;
  59. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  60. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  61. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  62. }
  63. $iContentId = parent::insert ($aValsToAdd, $isIgnore);
  64. if(!empty($iContentId))
  65. $this->processFiles ($CNF['FIELD_PHOTO'], $iContentId, true);
  66. return $iContentId;
  67. }
  68. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  69. {
  70. $CNF = &$this->_oModule->_oConfig->CNF;
  71. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb()) {
  72. $aThumb = bx_process_input (bx_get($CNF['FIELD_THUMB']), BX_DATA_INT);
  73. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  74. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  75. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  76. }
  77. $iRet = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  78. $this->processFiles ($CNF['FIELD_PHOTO'], $iContentId, false);
  79. return $iRet;
  80. }
  81. function _deleteFile ($iFileId, $sStorage = '')
  82. {
  83. $CNF = &$this->_oModule->_oConfig->CNF;
  84. if (!$iFileId)
  85. return true;
  86. $sStorage = !empty($sStorage) ? $sStorage : $CNF['OBJECT_STORAGE'];
  87. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  88. if (!$oStorage)
  89. return false;
  90. if (!$oStorage->getFile($iFileId))
  91. return true;
  92. $iProfileId = bx_get_logged_profile_id();
  93. return $oStorage->deleteFile($iFileId, $iProfileId);
  94. }
  95. protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
  96. {
  97. $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId);
  98. }
  99. protected function _getPhotoGhostTmplVars($aContentInfo = array())
  100. {
  101. $CNF = &$this->_oModule->_oConfig->CNF;
  102. return array (
  103. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  104. 'content_id' => $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  105. 'editor_id' => $CNF['FIELD_TEXT_ID'],
  106. 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
  107. 'bx_if:set_thumb' => array (
  108. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb(),
  109. 'content' => array (
  110. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '',
  111. 'txt_pict_use_as_thumb' => _t(!empty($CNF['T']['txt_pict_use_as_thumb']) ? $CNF['T']['txt_pict_use_as_thumb'] : '_sys_txt_form_entry_input_picture_use_as_thumb')
  112. ),
  113. ),
  114. );
  115. }
  116. }
  117. /** @} */