BxBaseModGeneralFormEntry.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 BaseGeneral Base classes for modules
  7. * @ingroup TridentModules
  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. }
  35. public function insert ($aValsToAdd = array(), $isIgnore = false)
  36. {
  37. $CNF = &$this->_oModule->_oConfig->CNF;
  38. if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]))
  39. $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id ();
  40. if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]))
  41. $aValsToAdd[$CNF['FIELD_ADDED']] = time();
  42. if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]))
  43. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  44. return parent::insert ($aValsToAdd, $isIgnore);
  45. }
  46. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  47. {
  48. $CNF = &$this->_oModule->_oConfig->CNF;
  49. if (isset($CNF['FIELD_CHANGED']))
  50. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  51. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  52. }
  53. function delete ($iContentId, $aContentInfo = array())
  54. {
  55. $CNF = &$this->_oModule->_oConfig->CNF;
  56. // delete associated files
  57. if (!empty($CNF['OBJECT_STORAGE'])) {
  58. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  59. if ($oStorage)
  60. $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
  61. }
  62. // delete associated objects data
  63. if (!empty($CNF['OBJECT_VIEWS'])) {
  64. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  65. if ($o) $o->onObjectDelete();
  66. }
  67. if (!empty($CNF['OBJECT_VOTES'])) {
  68. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  69. if ($o) $o->onObjectDelete();
  70. }
  71. if (!empty($CNF['OBJECT_COMMENTS'])) {
  72. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  73. if ($o) $o->onObjectDelete();
  74. }
  75. if (!empty($CNF['OBJECT_METATAGS'])) {
  76. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  77. $oMetatags->onDeleteContent($iContentId);
  78. }
  79. // delete db record
  80. return parent::delete($iContentId);
  81. }
  82. protected function genCustomInputLocation ($aInput)
  83. {
  84. $sProto = (0 == strncmp('https', BX_DOL_URL_ROOT, 5)) ? 'https' : 'http';
  85. $this->oTemplate->addJs($sProto . '://maps.google.com/maps/api/js?sensor=false');
  86. $aInput['checked'] = $this->getCleanValue($aInput['name'] . '_lat') && $this->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  87. $aVars = array (
  88. 'name' => $aInput['name'],
  89. 'id_status' => $this->getInputId($aInput) . '_status',
  90. 'location_string' => _t('_sys_location_undefined'),
  91. );
  92. $aLocationIndexes = array ('lat', 'lng', 'country', 'state', 'city', 'zip');
  93. foreach ($aLocationIndexes as $sKey)
  94. $aVars[$sKey] = $this->getLoctionVal($aInput, $sKey);
  95. if ($aVars['country']) {
  96. $aCountries = BxDolFormQuery::getDataItems('Country');
  97. $aVars['location_string'] = ($aVars['city'] ? $aVars['city'] . ', ' : '') . $aCountries[$aVars['country']];
  98. }
  99. if ($this->getLoctionVal($aInput, 'lat') && $this->getLoctionVal($aInput, 'lng'))
  100. $aInput['checked'] = true;
  101. $aVars['input'] = $this->genInputSwitcher($aInput);
  102. return $this->oTemplate->parseHtmlByName('form_field_location.html', $aVars);
  103. }
  104. protected function getLoctionVal ($aInput, $sIndex)
  105. {
  106. $s = $aInput['name'] . '_' . $sIndex;
  107. if (isset($this->_aSpecificValues[$s]))
  108. return $this->_aSpecificValues[$s];
  109. return $this->getCleanValue($s);
  110. }
  111. public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
  112. {
  113. $CNF = &$this->_oModule->_oConfig->CNF;
  114. if (!isset($this->aInputs[$sFieldFile]))
  115. return true;
  116. $mixedFileIds = $this->getCleanValue($sFieldFile);
  117. if(!$mixedFileIds)
  118. return true;
  119. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldFile]['storage_object']);
  120. if (!$oStorage)
  121. return false;
  122. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  123. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId, true);
  124. if (!$aGhostFiles)
  125. return true;
  126. foreach ($aGhostFiles as $aFile) {
  127. if (is_array($mixedFileIds) && !in_array($aFile['id'], $mixedFileIds))
  128. continue;
  129. if ($aFile['private'])
  130. $oStorage->setFilePrivate ($aFile['id'], 0);
  131. if ($iContentId)
  132. $this->_associalFileWithContent($oStorage, $aFile['id'], $iProfileId, $iContentId, $sFieldFile);
  133. }
  134. return true;
  135. }
  136. function addCssJs ()
  137. {
  138. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  139. if (self::$_isCssJsAdded)
  140. return;
  141. $this->_oModule->_oTemplate->addCss('forms.css');
  142. $this->_oModule->_oTemplate->addJs('modules/base/general/js/|forms.js');
  143. }
  144. return parent::addCssJs ();
  145. }
  146. function genViewRowValue(&$aInput)
  147. {
  148. $s = parent::genViewRowValue($aInput);
  149. if ($this->_oMetatagsObject && in_array($aInput['name'], $this->_aMetatagsFieldsWithKeywords) && $s)
  150. $s = $this->_oMetatagsObject->keywordsParse($this->_oMetatagsContentId, $s);
  151. return $s;
  152. }
  153. function setMetatagsKeywordsData($iId, $a, $o)
  154. {
  155. $this->_oMetatagsContentId = $iId;
  156. $this->_aMetatagsFieldsWithKeywords = $a;
  157. $this->_oMetatagsObject = $o;
  158. }
  159. function getContentOwnerProfileId ($iContentId)
  160. {
  161. $CNF = &$this->_oModule->_oConfig->CNF;
  162. // file owner must be author of the content or profile itself in case of profile based module
  163. if ($iContentId) {
  164. if ($this->_oModule instanceof iBxDolProfileService) {
  165. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  166. }
  167. else {
  168. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  169. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  170. }
  171. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  172. }
  173. else {
  174. $iProfileId = bx_get_logged_profile_id();
  175. }
  176. return $iProfileId;
  177. }
  178. }
  179. /** @} */