1
0

BxBaseModTextFormEntry.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxTemplFormView');
  12. /**
  13. * Create/Edit entry form
  14. */
  15. class BxBaseModTextFormEntry extends BxTemplFormView
  16. {
  17. protected static $MODULE;
  18. protected $_oModule;
  19. public function __construct($aInfo, $oTemplate = false)
  20. {
  21. parent::__construct($aInfo, $oTemplate);
  22. $this->_oModule = BxDolModule::getInstance(self::$MODULE);
  23. $CNF = &$this->_oModule->_oConfig->CNF;
  24. if (isset($this->aInputs[$CNF['FIELD_TEXT']])) {
  25. $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] = array_merge (
  26. array ('id' => $CNF['FIELD_TEXT_ID']),
  27. is_array($this->aInputs[$CNF['FIELD_TEXT']]['attrs']) ? $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] : array ()
  28. );
  29. }
  30. if (isset($this->aInputs[$CNF['FIELD_SUMMARY']])) {
  31. $this->aInputs[$CNF['FIELD_SUMMARY']]['attrs'] = array_merge (
  32. array ('id' => $CNF['FIELD_SUMMARY_ID']),
  33. is_array($this->aInputs[$CNF['FIELD_SUMMARY']]['attrs']) ? $this->aInputs[$CNF['FIELD_SUMMARY']]['attrs'] : array ()
  34. );
  35. }
  36. if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  37. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE'];
  38. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = array('sys_simple', 'sys_html5');
  39. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
  40. $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
  41. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
  42. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
  43. }
  44. if (isset($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']])) {
  45. bx_import('BxDolPrivacy');
  46. $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']);
  47. }
  48. }
  49. function initChecker ($aValues = array (), $aSpecificValues = array())
  50. {
  51. $CNF = &$this->_oModule->_oConfig->CNF;
  52. if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  53. $aContentInfo = false;
  54. if ($aValues && !empty($aValues['id'])) {
  55. $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($aValues['id']);
  56. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = $aValues['id'];
  57. }
  58. $aVars = array (
  59. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  60. 'content_id' => $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  61. 'editor_id' => $CNF['FIELD_TEXT_ID'],
  62. 'summary_id' => $CNF['FIELD_SUMMARY_ID'],
  63. 'thumb_id' => $aContentInfo[$CNF['FIELD_THUMB']],
  64. 'bx_if:set_thumb' => array (
  65. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb(),
  66. 'content' => array (
  67. 'name_thumb' => $CNF['FIELD_THUMB'],
  68. ),
  69. ),
  70. );
  71. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName('form_ghost_template.html', $aVars);
  72. }
  73. return parent::initChecker($aValues, $aSpecificValues);
  74. }
  75. public function insert ($aValsToAdd = array(), $isIgnore = false)
  76. {
  77. $CNF = &$this->_oModule->_oConfig->CNF;
  78. $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id ();
  79. $aValsToAdd[$CNF['FIELD_ADDED']] = time();
  80. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  81. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb()) {
  82. $aThumb = isset($_POST[$CNF['FIELD_THUMB']]) ? bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT) : false;
  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 ($iContentId = parent::insert ($aValsToAdd, $isIgnore))
  88. $this->_processFiles ($this->getCleanValue($CNF['FIELD_PHOTO']), $iContentId, true);
  89. return $iContentId;
  90. }
  91. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  92. {
  93. $CNF = &$this->_oModule->_oConfig->CNF;
  94. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  95. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb()) {
  96. $aThumb = bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT);
  97. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  98. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  99. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  100. }
  101. if ($iRet = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges))
  102. $this->_processFiles ($this->getCleanValue($CNF['FIELD_PHOTO']), $iContentId, false);
  103. return $iRet;
  104. }
  105. function delete ($iContentId)
  106. {
  107. $CNF = &$this->_oModule->_oConfig->CNF;
  108. // delete associated files
  109. bx_import('BxDolStorage');
  110. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  111. if (!$oStorage)
  112. return false;
  113. $aGhostFiles = $oStorage->getGhosts (bx_get_logged_profile_id(), $iContentId);
  114. if ($aGhostFiles)
  115. foreach ($aGhostFiles as $aFile)
  116. $this->_deleteFile($aFile['id']);
  117. // delete db record
  118. bx_import('BxDolView');
  119. BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId)->onObjectDelete();
  120. bx_import('BxDolVote');
  121. BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId)->onObjectDelete();
  122. bx_import('BxDolCmts');
  123. BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId)->onObjectDelete();
  124. return parent::delete($iContentId);
  125. }
  126. function _processFiles ($mixedFileIds, $iContentId = 0, $isAssociateWithContent = false)
  127. {
  128. $CNF = &$this->_oModule->_oConfig->CNF;
  129. if (!$mixedFileIds)
  130. return true;
  131. bx_import('BxDolStorage');
  132. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  133. if (!$oStorage)
  134. return false;
  135. $iProfileId = bx_get_logged_profile_id();
  136. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId);
  137. if (!$aGhostFiles)
  138. return true;
  139. foreach ($aGhostFiles as $aFile) {
  140. if ($aFile['private'])
  141. $oStorage->setFilePrivate ($aFile['id'], 0);
  142. if ($isAssociateWithContent && $iContentId)
  143. $oStorage->updateGhostsContentId ($aFile['id'], $iProfileId, $iContentId);
  144. }
  145. return true;
  146. }
  147. function _deleteFile ($iFileId)
  148. {
  149. $CNF = &$this->_oModule->_oConfig->CNF;
  150. if (!$iFileId)
  151. return true;
  152. bx_import('BxDolStorage');
  153. if (!($oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])))
  154. return false;
  155. if (!$oStorage->getFile($iFileId))
  156. return true;
  157. $iProfileId = bx_get_logged_profile_id();
  158. return $oStorage->deleteFile($iFileId, $iProfileId);
  159. }
  160. function addCssJs ()
  161. {
  162. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  163. if (self::$_isCssJsAdded)
  164. return;
  165. $this->_oModule->_oTemplate->addJs('forms.js');
  166. $this->_oModule->_oTemplate->addCss('forms.css');
  167. }
  168. return parent::addCssJs ();
  169. }
  170. }
  171. /** @} */