BxBaseModGeneralTemplate.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. * Module representation.
  13. */
  14. class BxBaseModGeneralTemplate extends BxDolModuleTemplate
  15. {
  16. protected $MODULE;
  17. protected $_oModule;
  18. function __construct(&$oConfig, &$oDb)
  19. {
  20. parent::__construct($oConfig, $oDb);
  21. $this->addCss ('main.css');
  22. }
  23. public function getModule()
  24. {
  25. if (!$this->_oModule) {
  26. $sName = $this->_oConfig->getName();
  27. $this->_oModule = BxDolModule::getInstance($sName);
  28. }
  29. return $this->_oModule;
  30. }
  31. public function getJsCode($sType, $aParams = array(), $bWrap = true)
  32. {
  33. $sBaseUri = $this->_oConfig->getBaseUri();
  34. $sJsClass = $this->_oConfig->getJsClass($sType);
  35. $sJsObject = $this->_oConfig->getJsObject($sType);
  36. $aParams = array_merge(array(
  37. 'sActionUri' => $sBaseUri,
  38. 'sActionUrl' => BX_DOL_URL_ROOT . $sBaseUri,
  39. 'sObjName' => $sJsObject,
  40. 'aHtmlIds' => array(),
  41. 'oRequestParams' => array()
  42. ), $aParams);
  43. $sContent = "var " . $sJsObject . " = new " . $sJsClass . "(" . json_encode($aParams) . ");";
  44. return !$bWrap ? $sContent : $this->_wrapInTagJsCode($sContent);
  45. }
  46. function entryText ($aData, $sTemplateName = 'entry-text.html')
  47. {
  48. $CNF = &$this->getModule()->_oConfig->CNF;
  49. $aVars = $aData;
  50. $aVars['entry_title'] = !empty($CNF['FIELD_TITLE']) && isset($aData[$CNF['FIELD_TITLE']]) ? bx_process_output($aData[$CNF['FIELD_TITLE']]) : '';
  51. $aVars['entry_text'] = !empty($CNF['FIELD_TEXT']) && isset($aData[$CNF['FIELD_TEXT']]) ? bx_process_output($aData[$CNF['FIELD_TEXT']], BX_DATA_HTML) : '';
  52. if (!empty($CNF['OBJECT_METATAGS'])) {
  53. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  54. // keywords
  55. if ($oMetatags->keywordsIsEnabled()) {
  56. $aFields = array_merge($oMetatags->keywordsFields($aData, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']), array('entry_title', 'entry_text'));
  57. foreach ($aFields as $sField)
  58. $aVars[$sField] = $oMetatags->keywordsParse($aData[$CNF['FIELD_ID']], $aVars[$sField]);
  59. }
  60. // location
  61. $aVars['location'] = $oMetatags->locationsIsEnabled() ? $oMetatags->locationsString($aData[$CNF['FIELD_ID']]) : '';
  62. }
  63. if (empty($aVars['entry_text']))
  64. return false;
  65. return $this->parseHtmlByName($sTemplateName, $aVars);
  66. }
  67. function entryLocation ($iContentId)
  68. {
  69. $CNF = &$this->getModule()->_oConfig->CNF;
  70. if (empty($CNF['OBJECT_METATAGS']))
  71. return '';
  72. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  73. if (!($sLocationString = $oMetatags->locationsString($iContentId)))
  74. return '';
  75. $aVars = array (
  76. 'location' => $sLocationString
  77. );
  78. return $this->parseHtmlByName('entry-location.html', $aVars);
  79. }
  80. public function entryInfo($aData, $aValues = array())
  81. {
  82. $CNF = $this->_oConfig->CNF;
  83. $aValuesDefault = array();
  84. if (isset($aData[$CNF['FIELD_ADDED']]))
  85. $aValuesDefault[] = array(
  86. 'title' => _t('_sys_txt_field_created'),
  87. 'value' => bx_time_js($aData[$CNF['FIELD_ADDED']]),
  88. );
  89. if (isset($aData[$CNF['FIELD_CHANGED']]))
  90. $aValuesDefault[] = array(
  91. 'title' => _t('_sys_txt_field_updated'),
  92. 'value' => bx_time_js($aData[$CNF['FIELD_CHANGED']]),
  93. );
  94. $aValues = array_merge($aValuesDefault, $aValues);
  95. return $this->parseHtmlByName('entry-info.html', array(
  96. 'bx_repeat:info' => $aValues,
  97. ));
  98. }
  99. function entryAllActions ($sActionsEntity, $sActionsSocial)
  100. {
  101. $aVars = array (
  102. 'actions_entity' => $sActionsEntity,
  103. 'actions_social' => $sActionsSocial,
  104. );
  105. return $this->parseHtmlByName('entry-all-actions.html', $aVars);
  106. }
  107. }
  108. /** @} */