BxBaseModGeneralFormEntry.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. function addCssJs ()
  112. {
  113. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  114. if (self::$_isCssJsAdded)
  115. return;
  116. $this->_oModule->_oTemplate->addCss('forms.css');
  117. }
  118. return parent::addCssJs ();
  119. }
  120. function genViewRowValue(&$aInput)
  121. {
  122. $s = parent::genViewRowValue($aInput);
  123. if ($this->_oMetatagsObject && in_array($aInput['name'], $this->_aMetatagsFieldsWithKeywords) && $s)
  124. $s = $this->_oMetatagsObject->keywordsParse($this->_oMetatagsContentId, $s);
  125. return $s;
  126. }
  127. function setMetatagsKeywordsData($iId, $a, $o)
  128. {
  129. $this->_oMetatagsContentId = $iId;
  130. $this->_aMetatagsFieldsWithKeywords = $a;
  131. $this->_oMetatagsObject = $o;
  132. }
  133. }
  134. /** @} */