BxBaseSearchResult.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolSearch');
  10. class BxBaseSearchResult extends BxDolSearchResult
  11. {
  12. public $isError;
  13. protected $sBrowseUrl; ///< currect browse url, used for paginate and other links in browsing
  14. protected $sUnitTemplate = 'unit.html'; ///< common template to try to use for displaying one item
  15. protected $aGetParams = array(); ///< get params to keep in paginate and other browsing links
  16. protected $iDesignBoxTemplate = BX_DB_PADDING_DEF; ///< design box ID to warp result in
  17. protected $aConstants;
  18. protected $sCenterContentUnitSelector = false;
  19. function __construct($oFunctions = false)
  20. {
  21. parent::__construct();
  22. if ($oFunctions) {
  23. $this->oFunctions = $oFunctions;
  24. } else {
  25. bx_import('BxTemplFunctions');
  26. $this->oFunctions = BxTemplFunctions::getInstance();
  27. }
  28. }
  29. function getMain()
  30. {
  31. // override this to return main module class
  32. }
  33. function displayResultBlock ()
  34. {
  35. $sCode = '';
  36. $aData = $this->getSearchData();
  37. if ($this->aCurrent['paginate']['num'] > 0) {
  38. $sCode .= $this->addCustomParts();
  39. foreach ($aData as $aValue)
  40. $sCode .= $this->displaySearchUnit($aValue);
  41. $sSearchResultBlockId = 'bx-search-result-block-' . rand(0, PHP_INT_MAX);
  42. $sCode = '<div id="' . $sSearchResultBlockId . '" class="bx-search-result-block bx-clearfix">' . $sCode . '</div>';
  43. if ($this->sCenterContentUnitSelector) {
  44. $sCode .= "
  45. <script>
  46. $(document).ready(function() {
  47. bx_center_content('#{$sSearchResultBlockId}', '{$this->sCenterContentUnitSelector}');
  48. });
  49. </script>";
  50. }
  51. }
  52. return $sCode;
  53. }
  54. function displaySearchBox ($sCode, $sPaginate = '')
  55. {
  56. $sTitle = _t($this->aCurrent['title']);
  57. $sCode = $this->oFunctions->designBoxContent($sTitle, $sCode . $sPaginate, $this->iDesignBoxTemplate, $this->getDesignBoxMenu());
  58. if (!isset($_GET['searchMode']))
  59. $sCode = '<div id="page_block_' . $this->id . '" class="bx-clearfix">' . $sCode . '</div>';
  60. return $sCode;
  61. }
  62. function displaySearchUnit ($aData)
  63. {
  64. $oMain = $this->getMain();
  65. return $oMain->_oTemplate->unit($aData, $this->bProcessPrivateContent, $this->sUnitTemplate);
  66. }
  67. function getDesignBoxMenu ()
  68. {
  69. if (false === ($sLink = $this->getRssPageUrl ()))
  70. return false;
  71. return array(
  72. array('name' => 'rss', 'title' => _t('_sys_menu_title_rss'), 'link' => $sLink, 'icon' => 'rss')
  73. );
  74. }
  75. function getRssPageUrl ()
  76. {
  77. if (!isset($this->aCurrent['rss']) || !$this->aCurrent['rss']['link'])
  78. return false;
  79. bx_import('BxDolPermalinks');
  80. $oPermalinks = BxDolPermalinks::getInstance();
  81. return BX_DOL_URL_ROOT . bx_append_url_params($oPermalinks->permalink($this->aCurrent['rss']['link']), 'rss=1');
  82. }
  83. function showAdminActionsPanel($sWrapperId, $aButtons, $sCheckboxName = 'entry', $bSelectAll = true, $bSelectAllChecked = false, $sCustomHtml = '')
  84. {
  85. $aBtns = array();
  86. foreach ($aButtons as $k => $v) {
  87. if(is_array($v)) {
  88. $aBtns[] = $v;
  89. continue;
  90. }
  91. $aBtns[] = array(
  92. 'type' => 'submit',
  93. 'name' => $k,
  94. 'value' => '_' == $v[0] ? _t($v) : $v,
  95. 'onclick' => '',
  96. );
  97. }
  98. $aUnit = array(
  99. 'bx_repeat:buttons' => $aBtns,
  100. 'bx_if:customHTML' => array(
  101. 'condition' => strlen($sCustomHtml) > 0,
  102. 'content' => array(
  103. 'custom_HTML' => $sCustomHtml,
  104. )
  105. ),
  106. 'bx_if:selectAll' => array(
  107. 'condition' => $bSelectAll,
  108. 'content' => array(
  109. 'wrapperId' => $sWrapperId,
  110. 'checkboxName' => $sCheckboxName,
  111. 'checked' => ($bSelectAll && $bSelectAllChecked ? 'checked="checked"' : '')
  112. )
  113. ),
  114. );
  115. return BxDolTemplate::getInstance()->parseHtmlByName('adminActionsPanel.html', $aUnit, array('{','}'));
  116. }
  117. function showAdminFilterPanel($sFilterValue, $sInputId = 'filter_input_id', $sCheckboxId = 'filter_checkbox_id', $sFilterName = 'filter', $sOnApply = '')
  118. {
  119. $sFilter = _t('_sys_admin_filter');
  120. $sApply = _t('_sys_admin_apply');
  121. $sFilterValue = bx_html_attribute($sFilterValue);
  122. $isChecked = $sFilterValue ? ' checked="checked" ' : '';
  123. $sJsContent = "";
  124. if(empty($sOnApply)) {
  125. $sOnApply = 'on_filter_apply(this)';
  126. ob_start();
  127. ?>
  128. <script type="text/javascript">
  129. function on_filter_apply (e) {
  130. var s = ('' + document.location).replace (/[&]{0,1}<?=$sFilterName;?>=.*/, ''); // remove filter
  131. s = s.replace(/page=\d+/, 'page=1'); // goto 1st page
  132. if (e.checked && $('#<?=$sInputId;?>').val().length > 2)
  133. s += (-1 == s.indexOf('?') ? '?' : '&') + '<?=$sFilterName;?>=' + $('#<?=$sInputId;?>').val(); // append filter
  134. document.location = s;
  135. }
  136. function on_filter_key_up (e) {
  137. if (13 == e.keyCode) {
  138. $('#<?php echo $sCheckboxId; ?>').attr('checked', 'checked');
  139. on_filter_apply($('#<?php echo $sCheckboxId; ?>').get(0));
  140. return false;
  141. } else {
  142. $('#<?php echo $sCheckboxId; ?>').attr('checked', '');
  143. return true;
  144. }
  145. }
  146. </script>
  147. <?
  148. $sJsContent = ob_get_clean();
  149. }
  150. return <<<EOF
  151. {$sJsContent}
  152. <div class="admin_filter_panel">
  153. <table>
  154. <tr>
  155. <td>{$sFilter}</td>
  156. <td>
  157. <div class="input_wrapper input_wrapper_text">
  158. <input type="text" id="{$sInputId}" value="{$sFilterValue}" class="form_input_text" onkeypress="return on_filter_key_up(event)" />
  159. <div class="input_close input_close_text">&nbsp;</div>
  160. </div>
  161. </td>
  162. <td><input type="checkbox" id="{$sCheckboxId}" $isChecked onclick="{$sOnApply}" /></td>
  163. <td><label for="{$sCheckboxId}">{$sApply}</label></td>
  164. </tr>
  165. </table>
  166. </div>
  167. EOF;
  168. }
  169. function showPagination($bAdmin = false, $bChangePage = true, $bPageReload = true)
  170. {
  171. $oMain = $this->getMain();
  172. $oConfig = $oMain->_oConfig;
  173. $sUrlStart = $this->getCurrentUrl(array(), false);
  174. bx_import('BxTemplPaginate');
  175. $oPaginate = new BxTemplPaginate(array(
  176. 'page_url' => $sUrlStart,
  177. 'num' => $this->aCurrent['paginate']['num'],
  178. 'per_page' => $this->aCurrent['paginate']['perPage'],
  179. 'start' => $this->aCurrent['paginate']['start'],
  180. ));
  181. return $oPaginate->getPaginate();
  182. }
  183. /**
  184. * Get current browse URL with current page and additional params
  185. * @param $aAdditionalParams set custom additional params as key value pair
  186. * @param $bReplacePagesParams replace paginate params with current values or leave markers for use in paginate class
  187. * @return ready to use URL string with BX_DOL_URL_ROOT added in the beginning
  188. */
  189. protected function getCurrentUrl($aAdditionalParams = array(), $bReplacePagesParams = true)
  190. {
  191. bx_import('BxDolPermalinks');
  192. $oPermalinks = BxDolPermalinks::getInstance();
  193. // base url
  194. $sUrlStart = BX_DOL_URL_ROOT . $oPermalinks->permalink($this->sBrowseUrl);
  195. // add pages params
  196. $sUrlStart = bx_append_url_params($sUrlStart, array (
  197. 'start' => $bReplacePagesParams ? (int)$this->aCurrent['paginate']['start'] : '{start}',
  198. 'per_page' => $bReplacePagesParams ? (int)$this->aCurrent['paginate']['perPage'] : '{per_page}',
  199. ));
  200. // add additional params
  201. foreach ($this->aGetParams as $sGetParam) {
  202. $sValue = false;
  203. if (isset($aAdditionalParams[$sGetParam]))
  204. $sValue = $aAdditionalParams[$sGetParam];
  205. elseif (false !== bx_get($sGetParam))
  206. $sValue = bx_get($sGetParam);
  207. if (false !== $sValue)
  208. $sUrlStart = bx_append_url_params($sUrlStart, $sGetParam . '=' . rawurlencode($sValue));
  209. }
  210. return $sUrlStart;
  211. }
  212. function showPaginationAjax($sBlockId)
  213. {
  214. bx_import('BxTemplPaginate');
  215. $oPaginate = new BxTemplPaginate(array(
  216. 'page_url' => 'javascript:void(0);',
  217. 'num' => $this->aCurrent['paginate']['num'],
  218. 'per_page' => $this->aCurrent['paginate']['perPage'],
  219. 'start' => $this->aCurrent['paginate']['start'],
  220. ));
  221. return $oPaginate->getSimplePaginate(false, -1, -1, false);
  222. }
  223. function clearFilters ($aPassParams = array(), $aPassJoins = array())
  224. {
  225. //clear sorting
  226. $this->aCurrent['sorting'] = 'last';
  227. //clear restrictions
  228. foreach ($this->aCurrent['restriction'] as $sKey => $aValue) {
  229. if (!in_array($sKey, $aPassParams))
  230. $this->aCurrent['restriction'][$sKey]['value'] = '';
  231. }
  232. //clear unnecessary joins (remains only profile join)
  233. $aPassJoins[] = 'profile';
  234. $aTemp = array();
  235. foreach ($aPassJoins as $sValue) {
  236. if (isset($this->aCurrent['join'][$sValue]) && is_array($this->aCurrent['join'][$sValue]))
  237. $aTemp[$sValue] = $this->aCurrent['join'][$sValue];
  238. }
  239. $this->aCurrent['join'] = $aTemp;
  240. }
  241. function fillFilters ($aParams)
  242. {
  243. // transform all given values to fields values
  244. if (is_array($aParams)) {
  245. foreach ($aParams as $sKey => $mixedValue) {
  246. if (isset($this->aCurrent['restriction'][$sKey]))
  247. $this->aCurrent['restriction'][$sKey]['value'] = $mixedValue;
  248. }
  249. }
  250. }
  251. /**
  252. * Set design box template id to use to wrap search results in
  253. */
  254. function setDesignBoxTemplateId ($i)
  255. {
  256. $this->iDesignBoxTemplate = $i;
  257. }
  258. }
  259. /** @} */