1
0

BxBaseModTextFormEntry.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseText Base classes for text modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
  15. {
  16. public function __construct($aInfo, $oTemplate = false)
  17. {
  18. parent::__construct($aInfo, $oTemplate);
  19. $CNF = &$this->_oModule->_oConfig->CNF;
  20. if (isset($this->aInputs[$CNF['FIELD_TEXT']])) {
  21. $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] = array_merge (
  22. array ('id' => $CNF['FIELD_TEXT_ID']),
  23. is_array($this->aInputs[$CNF['FIELD_TEXT']]['attrs']) ? $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] : array ()
  24. );
  25. }
  26. if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  27. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE'];
  28. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = $CNF['OBJECT_UPLOADERS'];
  29. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
  30. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
  31. $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
  32. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
  33. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
  34. }
  35. if (isset($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]))
  36. $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']);
  37. if (isset($this->aInputs['do_publish']) && !isset($this->aInputs['do_submit']))
  38. $this->aParams['db']['submit_name'] = 'do_publish';
  39. }
  40. function initChecker ($aValues = array (), $aSpecificValues = array())
  41. {
  42. $CNF = &$this->_oModule->_oConfig->CNF;
  43. if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  44. $aContentInfo = false;
  45. if ($aValues && !empty($aValues['id'])) {
  46. $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($aValues['id']);
  47. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = $aValues['id'];
  48. }
  49. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName('form_ghost_template.html', $this->_getPhotoGhostTmplVars($aContentInfo));
  50. }
  51. return parent::initChecker($aValues, $aSpecificValues);
  52. }
  53. public function insert ($aValsToAdd = array(), $isIgnore = false)
  54. {
  55. $CNF = &$this->_oModule->_oConfig->CNF;
  56. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb()) {
  57. $aThumb = isset($_POST[$CNF['FIELD_THUMB']]) ? bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT) : false;
  58. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  59. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  60. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  61. }
  62. $iContentId = parent::insert ($aValsToAdd, $isIgnore);
  63. if(!empty($iContentId))
  64. $this->_processFiles ($CNF['FIELD_PHOTO'], $iContentId, true);
  65. return $iContentId;
  66. }
  67. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  68. {
  69. $CNF = &$this->_oModule->_oConfig->CNF;
  70. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb()) {
  71. $aThumb = bx_process_input (bx_get($CNF['FIELD_THUMB']), BX_DATA_INT);
  72. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  73. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  74. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  75. }
  76. $iRet = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  77. $this->_processFiles ($CNF['FIELD_PHOTO'], $iContentId, false);
  78. return $iRet;
  79. }
  80. function _processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
  81. {
  82. $CNF = &$this->_oModule->_oConfig->CNF;
  83. $mixedFileIds = $this->getCleanValue($sFieldFile);
  84. if(!$mixedFileIds)
  85. return true;
  86. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldFile]['storage_object']);
  87. if (!$oStorage)
  88. return false;
  89. $iProfileId = bx_get_logged_profile_id();
  90. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId);
  91. if (!$aGhostFiles)
  92. return true;
  93. foreach ($aGhostFiles as $aFile) {
  94. if ($aFile['private'])
  95. $oStorage->setFilePrivate ($aFile['id'], 0);
  96. if ($iContentId)
  97. $this->_associalFileWithContent($oStorage, $aFile['id'], $iProfileId, $iContentId);
  98. }
  99. return true;
  100. }
  101. function _deleteFile ($iFileId, $sStorage = '')
  102. {
  103. $CNF = &$this->_oModule->_oConfig->CNF;
  104. if (!$iFileId)
  105. return true;
  106. $sStorage = !empty($sStorage) ? $sStorage : $CNF['OBJECT_STORAGE'];
  107. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  108. if (!$oStorage)
  109. return false;
  110. if (!$oStorage->getFile($iFileId))
  111. return true;
  112. $iProfileId = bx_get_logged_profile_id();
  113. return $oStorage->deleteFile($iFileId, $iProfileId);
  114. }
  115. function addCssJs ()
  116. {
  117. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  118. if (self::$_isCssJsAdded)
  119. return;
  120. $this->_oModule->_oTemplate->addJs('modules/base/text/js/|forms.js');
  121. }
  122. return parent::addCssJs ();
  123. }
  124. protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId)
  125. {
  126. $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId);
  127. }
  128. protected function _getPhotoGhostTmplVars($aContentInfo = array())
  129. {
  130. $CNF = &$this->_oModule->_oConfig->CNF;
  131. return array (
  132. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  133. 'content_id' => $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  134. 'editor_id' => $CNF['FIELD_TEXT_ID'],
  135. 'thumb_id' => isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
  136. 'bx_if:set_thumb' => array (
  137. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb(),
  138. 'content' => array (
  139. 'name_thumb' => $CNF['FIELD_THUMB'],
  140. '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')
  141. ),
  142. ),
  143. );
  144. }
  145. }
  146. /** @} */