1
0

BxBaseCategories.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /**
  3. * @package Dolphin Core
  4. * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * @license CC-BY - http://creativecommons.org/licenses/by/3.0/
  6. */
  7. defined('BX_DOL') or die('hack attempt');
  8. bx_import('BxDolTemplate');
  9. bx_import('BxDolCategories');
  10. class BxBaseCategories extends BxDolCategories
  11. {
  12. var $_sCategTmplName;
  13. var $_sCategTmplContent;
  14. function BxBaseCategories ()
  15. {
  16. parent::BxDolCategories();
  17. $this->_sCategTmplName = 'view_categ.html';
  18. $this->_sCategTmplContent = '';
  19. }
  20. function getCategoriesView ($aTotalCategories, $sHrefTempl, $iColumns) {
  21. $oSysTemplate = BxDolTemplate::getInstance();
  22. if (empty($aTotalCategories))
  23. return MsgBox(_t( '_Empty' ));
  24. if (!$iColumns)
  25. $iColumns = 1;
  26. $iCount = count($aTotalCategories);
  27. $iRowCount = floor($iCount / $iColumns) + (($iCount % $iColumns) ? 1 : 0);
  28. $iWidthPr = floor(100 / $iColumns);
  29. $i = 0;
  30. $sCode = '<div class="categories_wrapper">';
  31. foreach( $aTotalCategories as $sCategory => $iCatCount )
  32. {
  33. if (!($i % $iRowCount))
  34. {
  35. if ($i)
  36. $sCode .= '</div>';
  37. $sCode .= '<div class="categories_col" style="width: ' . $iWidthPr . '%">';
  38. }
  39. $aUnit['catHref'] = str_replace( '{tag}', urlencode(title2uri($sCategory)), $sHrefTempl);
  40. $aUnit['category'] = htmlspecialchars_adv($sCategory );
  41. $aUnit['count'] = $iCatCount;
  42. if ($this->_sCategTmplContent)
  43. $sCode .= $oSysTemplate->parseHtmlByContent($this->_sCategTmplContent, $aUnit);
  44. else
  45. $sCode .= $oSysTemplate->parseHtmlByName($this->_sCategTmplName, $aUnit);
  46. $i++;
  47. }
  48. $sCode .= '</div></div>';
  49. return $sCode;
  50. }
  51. function getCategTopMenu ($aParam, $sAction = '')
  52. {
  53. $aTopMenu = array();
  54. $aParamTmp = $aParam;
  55. foreach ($this->aTagObjects as $sKey => $aTagUnit)
  56. {
  57. $sName = _t($aTagUnit['LangKey']);
  58. $sHref = bx_html_attribute($_SERVER['PHP_SELF']) . "?tags_mode=$sKey" . ($sAction ? '&action=' . $sAction : '');
  59. if (isset($aParam['filter']) && $aParam['filter'])
  60. {
  61. $aParamTmp['type'] = $sKey;
  62. $sName .= '(' . $this->getTagsCount($aParamTmp) . ')';
  63. $sHref .= '&filter=' . $aParam['filter'];
  64. }
  65. if (isset($aParam['date']) && $aParam['date'])
  66. $sHref .= '&year=' . $aParam['date']['year'] .
  67. '&month=' . $aParam['date']['month'] .
  68. '&day=' . $aParam['date']['day'];
  69. $aTopMenu[$sName] = array('href' => $sHref, 'dynamic' => true, 'active' => ( $sKey == $aParam['type']));
  70. }
  71. return $aTopMenu;
  72. }
  73. function getCategTopMenuHtml($aParam, $iBoxId, $sAction = '')
  74. {
  75. $aItems = array();
  76. $aTopMenu = $this->getCategTopMenu($aParam, $sAction);
  77. foreach ($aTopMenu as $sName => $aItem)
  78. {
  79. $aItems[$sName] = array(
  80. 'dynamic' => true,
  81. 'active' => $aItem['active'],
  82. 'href' => $aItem['href']
  83. );
  84. }
  85. return BxDolPageView::getBlockCaptionItemCode($iBoxId, $aItems);
  86. }
  87. function display($aParam, $iBoxId, $sAction = '', $bOrderPanel = false, $iColumns, $sUrl = '')
  88. {
  89. if (!isset($aParam['type']) || !$aParam['type'])
  90. return MsgBox(_t( '_Empty' ));
  91. $sPaginate = '';
  92. $sCode = '';
  93. $sPageUrl = $sUrl ? $sUrl : bx_html_attribute($_SERVER['PHP_SELF']);
  94. $sPageUrl .= '?tags_mode=' . $aParam['type'];
  95. if (!isset($aParam['orderby']) && isset($_REQUEST['orderby']) && $_REQUEST['orderby'])
  96. $aParam['orderby'] = $_REQUEST['orderby'];
  97. if (isset($aParam['filter']) && $aParam['filter'])
  98. $sPageUrl .= '&filter=' . $aParam['filter'];
  99. if (isset($aParam['orderby']) && $aParam['orderby'])
  100. $sPageUrl .= '&orderby=' . $aParam['orderby'];
  101. if ($sAction)
  102. $sPageUrl .= '&action=' . $sAction;
  103. if (isset($aParam['date']) && $aParam['date'])
  104. {
  105. $sPageUrl .= '&year=' . $aParam['date']['year'] .
  106. '&month=' . $aParam['date']['month'] .
  107. '&day=' . $aParam['date']['day'];
  108. }
  109. if (isset($aParam['pagination']) && $aParam['pagination'])
  110. {
  111. bx_import('BxDolPaginate');
  112. $aPaginate = array(
  113. 'page_url' => $sPageUrl . '&page={page}&per_page={per_page}',
  114. 'info' => true,
  115. 'page_links' => true,
  116. 'on_change_page' => "!loadDynamicBlock($iBoxId, this.href)"
  117. );
  118. $aParam['limit'] = $aPaginate['per_page'] = $aParam['pagination'];
  119. $aPaginate['count'] = $this->getTagsCount($aParam);
  120. $aPaginate['page'] = isset($_REQUEST['page']) ? (int)$_REQUEST['page'] : 1;
  121. $aParam['start'] = $aParam['limit'] * ($aPaginate['page'] - 1);
  122. if ($aParam['start'] <=0)
  123. $aParam['start'] = 0;
  124. $oPaginate = new BxDolPaginate($aPaginate);
  125. $sPaginate = '<div class="clear_both"></div>'.$oPaginate->getPaginate();
  126. }
  127. $sHrefTmpl = $this->getHrefWithType($aParam['type']);
  128. $aTotalTags = $this->getTagList($aParam);
  129. if ($aTotalTags)
  130. {
  131. if ($bOrderPanel)
  132. $sCode .= $this->_getTopBox($aParam, $iBoxId, $sPageUrl);
  133. $sCode .= $this->getCategoriesView($aTotalTags, $sHrefTmpl, $iColumns) . $sPaginate;
  134. }
  135. else
  136. return MsgBox(_t( '_Empty' ));
  137. return $sCode;
  138. }
  139. function setTemplateName($sTmplName)
  140. {
  141. $this->_sCategTmplName = $sTmplName;
  142. }
  143. function setTemplateContent($sTmplContent)
  144. {
  145. $this->_sCategTmplContent = $sTmplContent;
  146. }
  147. function _getTopBox($aParam, $iBoxId, $sPageUrl) {
  148. $sCode = '';
  149. $aValues = array(
  150. 'none' => _t('_categ_order_none'),
  151. 'popular' => _t('_categ_order_popular'),
  152. 'recent' => _t('_categ_order_recent')
  153. );
  154. $sTopCode = _t('_categ_order_order_by');
  155. $sTopCode .= '<select onchange="loadDynamicBlock(' . $iBoxId . ', \'' . $sPageUrl . '&orderby=\' + this.value + \'' . '\')">';
  156. foreach ($aValues as $sKey => $sVal)
  157. $sTopCode .= '<option value="' . $sKey . '" ' . ($sKey == $aParam['orderby'] ? 'selected' : '') . '>' . $sVal . '</option>';
  158. $sTopCode .= '</select>';
  159. $sCode = BxDolTemplate::getInstance()->parseHtmlByName('top_block.html', array('code' => $sTopCode));
  160. return $sCode;
  161. }
  162. }