1
0

BxAdsTemplate.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 Ads Ads
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Module representation.
  13. */
  14. class BxAdsTemplate extends BxBaseModTextTemplate
  15. {
  16. function __construct(&$oConfig, &$oDb)
  17. {
  18. $this->MODULE = 'bx_ads';
  19. parent::__construct($oConfig, $oDb);
  20. $this->aMethodsToCallAddJsCss[] = 'categories';
  21. }
  22. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  23. {
  24. $CNF = &$this->_oConfig->CNF;
  25. $oPermalink = BxDolPermalinks::getInstance();
  26. $aTmplVarsItems = array();
  27. $this->_entryBreadcrumb($aContentInfo[$CNF['FIELD_CATEGORY']], $oPermalink, $aTmplVarsItems);
  28. $aTmplVarsItems = array_reverse($aTmplVarsItems);
  29. $aTmplVarsItems[] = array(
  30. 'url' => BX_DOL_URL_ROOT . $oPermalink->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  31. 'title' => bx_process_output($aContentInfo[$CNF['FIELD_TITLE']])
  32. );
  33. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  34. }
  35. public function categoriesList($aParams = array())
  36. {
  37. $CNF = &$this->_oConfig->CNF;
  38. $sResult = $this->_categoriesList(0, array(
  39. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORIES'], array('category' => ''))
  40. ));
  41. if(empty($sResult) && isset($aParams['show_empty']) && $aParams['show_empty'] === true)
  42. $sResult = MsgBox(_t('_Empty'));
  43. return $sResult;
  44. }
  45. /**
  46. * Use Gallery image for both because currently there is no Unit types with small thumbnails.
  47. */
  48. protected function getUnitThumbAndGallery ($aData)
  49. {
  50. list($sPhotoThumb, $sPhotoGallery) = parent::getUnitThumbAndGallery($aData);
  51. return array($sPhotoGallery, $sPhotoGallery);
  52. }
  53. protected function _categoriesList($iParentId, $aParams = array())
  54. {
  55. $aCategories = $this->_oDb->getCategories(array('type' => 'parent_id', 'parent_id' => $iParentId));
  56. $aTmplVars = array();
  57. foreach($aCategories as $aCategory) {
  58. $iItems = (int)$aCategory['items'];
  59. $sSibcategories = $this->_categoriesList($aCategory['id'], $aParams);
  60. if($iItems == 0 && empty($sSibcategories))
  61. continue;
  62. $aTmplVars[] = array(
  63. 'url' => $aParams['url'] . $aCategory['id'],
  64. 'title' => _t($aCategory['title']),
  65. 'bx_if:show_icon' => array(
  66. 'condition' => !empty($aCategory['icon']),
  67. 'content' => array(
  68. 'icon' => $aCategory['icon'],
  69. )
  70. ),
  71. 'bx_if:show_counter' => array(
  72. 'condition' => $iItems != 0,
  73. 'content' => array(
  74. 'items' => $iItems,
  75. )
  76. ),
  77. 'bx_if:show_subcategories' => array(
  78. 'condition' => !empty($sSibcategories),
  79. 'content' => array(
  80. 'subcategories' => $sSibcategories
  81. )
  82. )
  83. );
  84. }
  85. if(empty($aTmplVars))
  86. return '';
  87. return $this->parseHtmlByName('categories.html', array(
  88. 'bx_repeat:categories' => $aTmplVars
  89. ));
  90. }
  91. protected function _entryBreadcrumb($iCategory, &$oPermalink, &$aTmplVarsItems)
  92. {
  93. $CNF = &$this->_oConfig->CNF;
  94. $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategory));
  95. if(empty($aCategory) || !is_array($aCategory))
  96. return;
  97. $aTmplVarsItems[] = array(
  98. 'url' => BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_CATEGORIES'], array($CNF['GET_PARAM_CATEGORY'] => $aCategory['id'])),
  99. 'title' => bx_process_output(_t($aCategory['title']))
  100. );
  101. if(empty($aCategory['parent_id']))
  102. return;
  103. $this->_entryBreadcrumb((int)$aCategory['parent_id'], $oPermalink, $aTmplVarsItems);
  104. }
  105. }
  106. /** @} */