1
0

BxBaseModTextFormEntry.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. bx_import('BxBaseModGeneralFormEntry');
  12. /**
  13. * Create/Edit entry form
  14. */
  15. class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
  16. {
  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'] = array('sys_simple', 'sys_html5');
  30. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
  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. bx_import('BxDolPrivacy');
  37. $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']);
  38. }
  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. $aVars = array (
  50. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  51. 'content_id' => $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  52. 'editor_id' => $CNF['FIELD_TEXT_ID'],
  53. 'thumb_id' => isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
  54. 'bx_if:set_thumb' => array (
  55. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb(),
  56. 'content' => array (
  57. 'name_thumb' => $CNF['FIELD_THUMB'],
  58. ),
  59. ),
  60. );
  61. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName('form_ghost_template.html', $aVars);
  62. }
  63. return parent::initChecker($aValues, $aSpecificValues);
  64. }
  65. public function insert ($aValsToAdd = array(), $isIgnore = false)
  66. {
  67. $CNF = &$this->_oModule->_oConfig->CNF;
  68. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb()) {
  69. $aThumb = isset($_POST[$CNF['FIELD_THUMB']]) ? bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT) : false;
  70. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  71. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  72. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  73. }
  74. if ($iContentId = parent::insert ($aValsToAdd, $isIgnore))
  75. $this->_processFiles ($this->getCleanValue($CNF['FIELD_PHOTO']), $iContentId, true);
  76. return $iContentId;
  77. }
  78. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  79. {
  80. $CNF = &$this->_oModule->_oConfig->CNF;
  81. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb()) {
  82. $aThumb = bx_process_input (bx_get($CNF['FIELD_THUMB']), BX_DATA_INT);
  83. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  84. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  85. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  86. }
  87. if ($iRet = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges))
  88. $this->_processFiles ($this->getCleanValue($CNF['FIELD_PHOTO']), $iContentId, true);
  89. return $iRet;
  90. }
  91. function delete ($iContentId, $aContentInfo = array())
  92. {
  93. $CNF = &$this->_oModule->_oConfig->CNF;
  94. // delete associated files
  95. bx_import('BxDolStorage');
  96. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  97. if ($oStorage)
  98. $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
  99. // delete associated objects data
  100. bx_import('BxDolView');
  101. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  102. if ($o) $o->onObjectDelete();
  103. bx_import('BxDolVote');
  104. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  105. if ($o) $o->onObjectDelete();
  106. bx_import('BxDolCmts');
  107. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  108. if ($o) $o->onObjectDelete();
  109. bx_import('BxDolMetatags');
  110. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  111. $oMetatags->onDeleteContent($iContentId);
  112. // delete db record
  113. return parent::delete($iContentId);
  114. }
  115. function _processFiles ($mixedFileIds, $iContentId = 0, $isAssociateWithContent = false)
  116. {
  117. $CNF = &$this->_oModule->_oConfig->CNF;
  118. if (!$mixedFileIds)
  119. return true;
  120. bx_import('BxDolStorage');
  121. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  122. if (!$oStorage)
  123. return false;
  124. $iProfileId = bx_get_logged_profile_id();
  125. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId);
  126. if (!$aGhostFiles)
  127. return true;
  128. foreach ($aGhostFiles as $aFile) {
  129. if ($aFile['private'])
  130. $oStorage->setFilePrivate ($aFile['id'], 0);
  131. if ($isAssociateWithContent && $iContentId)
  132. $oStorage->updateGhostsContentId ($aFile['id'], $iProfileId, $iContentId);
  133. }
  134. return true;
  135. }
  136. function _deleteFile ($iFileId)
  137. {
  138. $CNF = &$this->_oModule->_oConfig->CNF;
  139. if (!$iFileId)
  140. return true;
  141. bx_import('BxDolStorage');
  142. if (!($oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])))
  143. return false;
  144. if (!$oStorage->getFile($iFileId))
  145. return true;
  146. $iProfileId = bx_get_logged_profile_id();
  147. return $oStorage->deleteFile($iFileId, $iProfileId);
  148. }
  149. function addCssJs ()
  150. {
  151. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  152. if (self::$_isCssJsAdded)
  153. return;
  154. $this->_oModule->_oTemplate->addJs('modules/base/text/js/|forms.js');
  155. }
  156. return parent::addCssJs ();
  157. }
  158. }
  159. /** @} */