BxBaseModGeneralFormEntry.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. bx_import('BxTemplFormView');
  12. /**
  13. * Create/edit entry form
  14. */
  15. class BxBaseModGeneralFormEntry extends BxTemplFormView
  16. {
  17. protected $MODULE;
  18. protected $_oModule;
  19. protected $_aMetatagsFieldsWithKeywords = array();
  20. protected $_oMetatagsObject = null;
  21. protected $_oMetatagsContentId = 0;
  22. public function __construct($aInfo, $oTemplate = false)
  23. {
  24. parent::__construct($aInfo, $oTemplate);
  25. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  26. }
  27. public function insert ($aValsToAdd = array(), $isIgnore = false)
  28. {
  29. $CNF = &$this->_oModule->_oConfig->CNF;
  30. if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]))
  31. $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id ();
  32. if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]))
  33. $aValsToAdd[$CNF['FIELD_ADDED']] = time();
  34. if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]))
  35. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  36. return parent::insert ($aValsToAdd, $isIgnore);
  37. }
  38. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  39. {
  40. $CNF = &$this->_oModule->_oConfig->CNF;
  41. if (isset($CNF['FIELD_CHANGED']))
  42. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  43. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  44. }
  45. function delete ($iContentId, $aContentInfo = array())
  46. {
  47. $CNF = &$this->_oModule->_oConfig->CNF;
  48. // delete associated files
  49. if (!empty($CNF['OBJECT_STORAGE'])) {
  50. bx_import('BxDolStorage');
  51. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  52. if ($oStorage)
  53. $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
  54. }
  55. // delete associated objects data
  56. if (!empty($CNF['OBJECT_VIEWS'])) {
  57. bx_import('BxDolView');
  58. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  59. if ($o) $o->onObjectDelete();
  60. }
  61. if (!empty($CNF['OBJECT_VOTES'])) {
  62. bx_import('BxDolVote');
  63. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  64. if ($o) $o->onObjectDelete();
  65. }
  66. if (!empty($CNF['OBJECT_COMMENTS'])) {
  67. bx_import('BxDolCmts');
  68. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  69. if ($o) $o->onObjectDelete();
  70. }
  71. if (!empty($CNF['OBJECT_METATAGS'])) {
  72. bx_import('BxDolMetatags');
  73. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  74. $oMetatags->onDeleteContent($iContentId);
  75. }
  76. // delete db record
  77. return parent::delete($iContentId);
  78. }
  79. protected function genCustomInputLocation ($aInput)
  80. {
  81. $sProto = (0 == strncmp('https', BX_DOL_URL_ROOT, 5)) ? 'https' : 'http';
  82. $this->oTemplate->addJs($sProto . '://maps.google.com/maps/api/js?sensor=false');
  83. $aInput['checked'] = $this->getCleanValue($aInput['name'] . '_lat') && $this->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  84. $aVars = array (
  85. 'name' => $aInput['name'],
  86. 'id_status' => $this->getInputId($aInput) . '_status',
  87. 'location_string' => _t('_sys_location_undefined'),
  88. );
  89. $aLocationIndexes = array ('lat', 'lng', 'country', 'state', 'city', 'zip');
  90. foreach ($aLocationIndexes as $sKey)
  91. $aVars[$sKey] = $this->getLoctionVal($aInput, $sKey);
  92. if ($aVars['country']) {
  93. $aCountries = BxDolFormQuery::getDataItems('Country');
  94. $aVars['location_string'] = ($aVars['city'] ? $aVars['city'] . ', ' : '') . $aCountries[$aVars['country']];
  95. }
  96. if ($this->getLoctionVal($aInput, 'lat') && $this->getLoctionVal($aInput, 'lng'))
  97. $aInput['checked'] = true;
  98. $aVars['input'] = $this->genInputSwitcher($aInput);
  99. return $this->oTemplate->parseHtmlByName('form_field_location.html', $aVars);
  100. }
  101. protected function getLoctionVal ($aInput, $sIndex)
  102. {
  103. $s = $aInput['name'] . '_' . $sIndex;
  104. if (isset($this->_aSpecificValues[$s]))
  105. return $this->_aSpecificValues[$s];
  106. return $this->getCleanValue($s);
  107. }
  108. function addCssJs ()
  109. {
  110. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  111. if (self::$_isCssJsAdded)
  112. return;
  113. $this->_oModule->_oTemplate->addCss('forms.css');
  114. }
  115. return parent::addCssJs ();
  116. }
  117. function genViewRowValue(&$aInput)
  118. {
  119. $s = parent::genViewRowValue($aInput);
  120. if ($this->_oMetatagsObject && in_array($aInput['name'], $this->_aMetatagsFieldsWithKeywords))
  121. $s = $this->_oMetatagsObject->keywordsParse($this->_oMetatagsContentId, $s);
  122. return $s;
  123. }
  124. function setMetatagsKeywordsData($iId, $a, $o)
  125. {
  126. $this->_oMetatagsContentId = $iId;
  127. $this->_aMetatagsFieldsWithKeywords = $a;
  128. $this->_oMetatagsObject = $o;
  129. }
  130. }
  131. /** @} */