1
0

BxBaseModTextFormsEntryHelper.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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('BxBaseModGeneralFormsEntryHelper');
  12. bx_import('BxDolProfile');
  13. /**
  14. * Entry forms helper functions
  15. */
  16. class BxBaseModTextFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
  17. {
  18. public function __construct($oModule)
  19. {
  20. parent::__construct($oModule);
  21. }
  22. /**
  23. * @return main content text
  24. */
  25. public function viewDataText ($iContentId)
  26. {
  27. $CNF = &$this->_oModule->_oConfig->CNF;
  28. // get content data and profile info
  29. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  30. if (!$aContentInfo)
  31. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  32. // check access
  33. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  34. return MsgBox($sMsg);
  35. return $aContentInfo[$CNF['FIELD_TEXT']];
  36. }
  37. /**
  38. * @return main content text
  39. */
  40. public function viewDataEntry ($iContentId)
  41. {
  42. // get content data and profile info
  43. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  44. if (!$aContentInfo)
  45. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  46. // check access
  47. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  48. return MsgBox($sMsg);
  49. return $this->_oModule->_oTemplate->entryText($aContentInfo);
  50. }
  51. /**
  52. * @return array of profile object and content info
  53. */
  54. protected function _getProfileAndContentData ($iContentId)
  55. {
  56. $CNF = &$this->_oModule->_oConfig->CNF;
  57. $aContentInfo = array();
  58. $oProfile = false;
  59. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  60. if (!$aContentInfo)
  61. return array (false, false);
  62. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  63. if (!$oProfile) {
  64. bx_import('BxDolProfileUndefined');
  65. $oProfile = BxDolProfileUndefined::getInstance();
  66. }
  67. return array ($oProfile, $aContentInfo);
  68. }
  69. protected function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  70. {
  71. return '';
  72. }
  73. protected function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges)
  74. {
  75. }
  76. protected function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile)
  77. {
  78. $CNF = &$this->_oModule->_oConfig->CNF;
  79. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  80. return MsgBox(_t('_sys_txt_error_occured'));
  81. // change profile to 'pending' only if profile is 'active'
  82. if ($oProfile->isActive() && !empty($aTrackTextFieldsChanges['changed_fields']))
  83. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  84. if (!empty($CNF['OBJECT_METATAGS'])) { // && isset($aTrackTextFieldsChanges['changed_fields'][$CNF['FIELD_TEXT']])) { // TODO: check if aTrackTextFieldsChanges works
  85. bx_import('BxDolMetatags');
  86. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  87. $oMetatags->keywordsAdd($aContentInfo[$CNF['FIELD_ID']], $aContentInfo[$CNF['FIELD_TEXT']]);
  88. $oMetatags->locationsAddFromForm($aContentInfo[$CNF['FIELD_ID']], $CNF['FIELD_LOCATION_PREFIX']);
  89. }
  90. // create an alert
  91. bx_import('BxDolPrivacy');
  92. bx_alert($this->_oModule->getName(), 'edited', $aContentInfo[$CNF['FIELD_ID']], false, array('privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]));
  93. return '';
  94. }
  95. protected function onDataAddAfter ($iContentId)
  96. {
  97. $CNF = &$this->_oModule->_oConfig->CNF;
  98. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  99. return MsgBox(_t('_sys_txt_error_occured'));
  100. if (!empty($CNF['OBJECT_METATAGS'])) {
  101. bx_import('BxDolMetatags');
  102. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  103. $oMetatags->keywordsAdd($aContentInfo[$CNF['FIELD_ID']], $aContentInfo[$CNF['FIELD_TEXT']]);
  104. $oMetatags->locationsAddFromForm($aContentInfo[$CNF['FIELD_ID']], $CNF['FIELD_LOCATION_PREFIX']);
  105. }
  106. // alert
  107. bx_import('BxDolPrivacy');
  108. $aParams = isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) ? array('privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) : array();
  109. bx_alert($this->_oModule->getName(), 'added', $iContentId, false, $aParams);
  110. return '';
  111. }
  112. }
  113. /** @} */