1
0

BxBaseModGeneralFormEntry.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/edit entry form
  13. */
  14. class BxBaseModGeneralFormEntry extends BxTemplFormView
  15. {
  16. protected $MODULE;
  17. protected $_oModule;
  18. protected $_aMetatagsFieldsWithKeywords = array();
  19. protected $_oMetatagsObject = null;
  20. protected $_oMetatagsContentId = 0;
  21. public function __construct($aInfo, $oTemplate = false)
  22. {
  23. parent::__construct($aInfo, $oTemplate);
  24. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  25. $CNF = &$this->_oModule->_oConfig->CNF;
  26. if (isset($CNF['FIELD_ADDED']) && isset($this->aInputs[$CNF['FIELD_ADDED']])) {
  27. $this->aInputs[$CNF['FIELD_ADDED']]['date_filter'] = BX_DATA_INT;
  28. $this->aInputs[$CNF['FIELD_ADDED']]['date_format'] = BX_FORMAT_DATE;
  29. }
  30. if (isset($CNF['FIELD_CHANGED']) && isset($this->aInputs[$CNF['FIELD_CHANGED']])) {
  31. $this->aInputs[$CNF['FIELD_CHANGED']]['date_filter'] = BX_DATA_INT;
  32. $this->aInputs[$CNF['FIELD_CHANGED']]['date_format'] = BX_FORMAT_DATE;
  33. }
  34. if (isset($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']])) {
  35. $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['manual_input'] = true;
  36. }
  37. }
  38. function initChecker ($aValues = array (), $aSpecificValues = array())
  39. {
  40. $CNF = &$this->_oModule->_oConfig->CNF;
  41. if (!empty($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]) && isset($aValues[$CNF['FIELD_ID']]) && !empty($CNF['OBJECT_METATAGS']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->locationsIsEnabled())
  42. $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['value'] = $oMetatags->locationsString($aValues[$CNF['FIELD_ID']], false);
  43. parent::initChecker ($aValues, $aSpecificValues);
  44. }
  45. public function insert ($aValsToAdd = array(), $isIgnore = false)
  46. {
  47. $CNF = &$this->_oModule->_oConfig->CNF;
  48. if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]))
  49. $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id ();
  50. if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]) && empty($this->getCleanValue($CNF['FIELD_ADDED'])))
  51. $aValsToAdd[$CNF['FIELD_ADDED']] = time();
  52. if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]) && empty($this->getCleanValue($CNF['FIELD_CHANGED'])))
  53. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  54. return parent::insert ($aValsToAdd, $isIgnore);
  55. }
  56. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  57. {
  58. $CNF = &$this->_oModule->_oConfig->CNF;
  59. if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]) && empty($this->getCleanValue($CNF['FIELD_CHANGED'])))
  60. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  61. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  62. }
  63. function delete ($iContentId, $aContentInfo = array())
  64. {
  65. $CNF = &$this->_oModule->_oConfig->CNF;
  66. // delete associated files
  67. if (!empty($CNF['OBJECT_STORAGE'])) {
  68. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  69. if ($oStorage)
  70. $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
  71. }
  72. // delete associated objects data
  73. if (!empty($CNF['OBJECT_VIEWS'])) {
  74. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  75. if ($o) $o->onObjectDelete();
  76. }
  77. if (!empty($CNF['OBJECT_VOTES'])) {
  78. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  79. if ($o) $o->onObjectDelete();
  80. }
  81. if (!empty($CNF['OBJECT_COMMENTS'])) {
  82. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  83. if ($o) $o->onObjectDelete();
  84. }
  85. if (!empty($CNF['OBJECT_METATAGS'])) {
  86. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  87. $oMetatags->onDeleteContent($iContentId);
  88. }
  89. // delete db record
  90. return parent::delete($iContentId);
  91. }
  92. protected function _isAdmin ($iContentId = 0)
  93. {
  94. return $this->_oModule->_isModerator();
  95. }
  96. public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
  97. {
  98. $CNF = &$this->_oModule->_oConfig->CNF;
  99. if (!isset($this->aInputs[$sFieldFile]))
  100. return true;
  101. $mixedFileIds = $this->getCleanValue($sFieldFile);
  102. if(!$mixedFileIds)
  103. return true;
  104. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldFile]['storage_object']);
  105. if (!$oStorage)
  106. return false;
  107. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  108. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId, true, $this->_isAdmin($iContentId));
  109. if (!$aGhostFiles)
  110. return true;
  111. foreach ($aGhostFiles as $aFile) {
  112. if (is_array($mixedFileIds) && !in_array($aFile['id'], $mixedFileIds))
  113. continue;
  114. if ($aFile['private'])
  115. $oStorage->setFilePrivate ($aFile['id'], 1);
  116. if ($iContentId)
  117. $this->_associalFileWithContent($oStorage, $aFile['id'], $iProfileId, $iContentId, $sFieldFile);
  118. }
  119. return true;
  120. }
  121. function addCssJs ()
  122. {
  123. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  124. if (self::$_isCssJsAdded)
  125. return;
  126. $this->_oModule->_oTemplate->addCss('forms.css');
  127. $this->_oModule->_oTemplate->addJs('modules/base/general/js/|forms.js');
  128. }
  129. return parent::addCssJs ();
  130. }
  131. function genViewRowValue(&$aInput)
  132. {
  133. $s = parent::genViewRowValue($aInput);
  134. if ($this->_oMetatagsObject && in_array($aInput['name'], $this->_aMetatagsFieldsWithKeywords) && $s)
  135. $s = $this->_oMetatagsObject->keywordsParse($this->_oMetatagsContentId, $s);
  136. return $s;
  137. }
  138. function setMetatagsKeywordsData($iId, $a, $o)
  139. {
  140. $this->_oMetatagsContentId = $iId;
  141. $this->_aMetatagsFieldsWithKeywords = $a;
  142. $this->_oMetatagsObject = $o;
  143. }
  144. function getContentOwnerProfileId ($iContentId)
  145. {
  146. $CNF = &$this->_oModule->_oConfig->CNF;
  147. // file owner must be author of the content or profile itself in case of profile based module
  148. if ($iContentId) {
  149. if ($this->_oModule instanceof iBxDolProfileService) {
  150. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  151. }
  152. else {
  153. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  154. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  155. }
  156. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  157. }
  158. else {
  159. $iProfileId = bx_get_logged_profile_id();
  160. }
  161. return $iProfileId;
  162. }
  163. }
  164. /** @} */