1
0

BxBaseModTextFormEntry.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 $MODULE;
  18. protected $_oModule;
  19. public function __construct($aInfo, $oTemplate = false)
  20. {
  21. parent::__construct($aInfo, $oTemplate);
  22. $this->_oModule = BxDolModule::getInstance($this->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. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  120. if ($o) $o->onObjectDelete();
  121. bx_import('BxDolVote');
  122. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  123. if ($o) $o->onObjectDelete();
  124. bx_import('BxDolCmts');
  125. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  126. if ($o) $o->onObjectDelete();
  127. return parent::delete($iContentId);
  128. }
  129. function _processFiles ($mixedFileIds, $iContentId = 0, $isAssociateWithContent = false)
  130. {
  131. $CNF = &$this->_oModule->_oConfig->CNF;
  132. if (!$mixedFileIds)
  133. return true;
  134. bx_import('BxDolStorage');
  135. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  136. if (!$oStorage)
  137. return false;
  138. $iProfileId = bx_get_logged_profile_id();
  139. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId);
  140. if (!$aGhostFiles)
  141. return true;
  142. foreach ($aGhostFiles as $aFile) {
  143. if ($aFile['private'])
  144. $oStorage->setFilePrivate ($aFile['id'], 0);
  145. if ($isAssociateWithContent && $iContentId)
  146. $oStorage->updateGhostsContentId ($aFile['id'], $iProfileId, $iContentId);
  147. }
  148. return true;
  149. }
  150. function _deleteFile ($iFileId)
  151. {
  152. $CNF = &$this->_oModule->_oConfig->CNF;
  153. if (!$iFileId)
  154. return true;
  155. bx_import('BxDolStorage');
  156. if (!($oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])))
  157. return false;
  158. if (!$oStorage->getFile($iFileId))
  159. return true;
  160. $iProfileId = bx_get_logged_profile_id();
  161. return $oStorage->deleteFile($iFileId, $iProfileId);
  162. }
  163. function addCssJs ()
  164. {
  165. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  166. if (self::$_isCssJsAdded)
  167. return;
  168. $this->_oModule->_oTemplate->addJs('modules/base/text/js/|forms.js');
  169. $this->_oModule->_oTemplate->addCss('forms.css');
  170. }
  171. return parent::addCssJs ();
  172. }
  173. }
  174. /** @} */