| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaBaseView UNA Base Representation Classes
- * @{
- */
- bx_import('BxDolSearch');
- class BxBaseSearchResult extends BxDolSearchResult
- {
- public $isError;
- protected $sBrowseUrl; ///< currect browse url, used for paginate and other links in browsing
- protected $sUnitTemplate = 'unit.html'; ///< common template to try to use for displaying one item
- protected $sUnitTemplateLiveSearch = 'unit_live_search.html'; ///< common template to try to use for displaying live search results
- protected $aGetParams = array(); ///< get params to keep in paginate and other browsing links
- protected $iDesignBoxTemplate = 11; ///< design box ID to wrap result in, or false to disable design box wrapping
- protected $aConstants;
- protected $sCenterContentUnitSelector = false;
- protected $aContainerAttrs = array();
- protected $aContainerClasses = array('bx-search-result-block', 'bx-clearfix');
- protected $aUnitParams = array(); ///< additional params array to pass to unit display function
- function __construct($oFunctions = false)
- {
- parent::__construct();
- if ($oFunctions)
- $this->oFunctions = $oFunctions;
- else
- $this->oFunctions = BxTemplFunctions::getInstance();
- }
- function getMain()
- {
- // override this to return main module class
- }
- function displayResultBlock ()
- {
- $sCode = '';
- $aData = $this->getSearchData();
- if ($this->aCurrent['paginate']['num'] > 0) {
- $sCode .= $this->addCustomParts();
- foreach ($aData as $aValue)
- $sCode .= $this->displaySearchUnit($aValue);
- $sSearchResultBlockId = 'bx-search-result-block-' . rand(0, PHP_INT_MAX);
- $sClasses = implode(' ', $this->aContainerClasses);
- $sAttributes = '';
- if(is_array($this->aContainerAttrs) && !empty($this->aContainerAttrs))
- foreach ($this->aContainerAttrs as $sName => $sValue)
- $sAttributes .= ' ' . $sName . '="' . $sValue . '"';
- $sCode = '<div id="' . $sSearchResultBlockId . '" class="' . $sClasses . '"' . $sAttributes . '>' . $sCode . '</div>';
- if (!$this->_bLiveSearch && $this->sCenterContentUnitSelector) {
- $sCode .= "
- <script>
- $(document).ready(function() {
- bx_center_content('#{$sSearchResultBlockId}', '{$this->sCenterContentUnitSelector}', true);
- });
- </script>";
- }
- }
- return $sCode;
- }
- function displaySearchBox ($sContent, $sPaginate = '')
- {
- $sContent .= $sPaginate;
- $sMenu = $this->getDesignBoxMenu();
- if ($this->id) {
- $sTitle = _t($this->aCurrent['title']);
- $sCode = $this->oFunctions->designBoxContent($sTitle, $sContent, $this->iDesignBoxTemplate, $sMenu);
- return '<div class="bx-page-block-container bx-search-results bx-def-padding-sec-topbottom bx-clearfix" id="bx-page-block-' . $this->id . '">' . $sCode . '</div>';
- }
- $this->addPageRssLink ();
- return array(
- 'content' => $sContent,
- 'menu' => $sMenu,
- );
- }
- function displaySearchUnit ($aData)
- {
- $oMain = $this->getMain();
- return $oMain->_oTemplate->unit($aData, $this->bProcessPrivateContent, $this->_bLiveSearch ? $this->sUnitTemplateLiveSearch : $this->sUnitTemplate, $this->aUnitParams);
- }
- function setUnitTemplate ($s)
- {
- $this->sUnitTemplate = $s;
- }
- function getDesignBoxMenu ()
- {
- return array();
- }
- protected function addPageRssLink ()
- {
- if (false === ($sLink = $this->getRssPageUrl ()))
- return;
- if (!($oTemplate = BxDolTemplate::getInstance()))
- return;
- $oTemplate->addPageRssLink($this->aCurrent['title'], $sLink);
- }
- function getRssPageUrl ()
- {
- if (!isset($this->aCurrent['rss']) || !$this->aCurrent['rss']['link'])
- return false;
- $oPermalinks = BxDolPermalinks::getInstance();
- return BX_DOL_URL_ROOT . bx_append_url_params($oPermalinks->permalink($this->aCurrent['rss']['link']), 'rss=1');
- }
- function showAdminActionsPanel($sWrapperId, $aButtons, $sCheckboxName = 'entry', $bSelectAll = true, $bSelectAllChecked = false, $sCustomHtml = '')
- {
- $aBtns = array();
- foreach ($aButtons as $k => $v) {
- if(is_array($v)) {
- $aBtns[] = $v;
- continue;
- }
- $aBtns[] = array(
- 'type' => 'submit',
- 'name' => $k,
- 'value' => '_' == $v[0] ? _t($v) : $v,
- 'onclick' => '',
- );
- }
- return BxDolTemplate::getInstance()->parseHtmlByName('adminActionsPanel.html', array(
- 'bx_repeat:buttons' => $aBtns,
- 'bx_if:custom_html' => array(
- 'condition' => strlen($sCustomHtml) > 0,
- 'content' => array(
- 'custom_html' => $sCustomHtml,
- )
- ),
- 'bx_if:selectAll' => array(
- 'condition' => $bSelectAll,
- 'content' => array(
- 'wrapper_id' => $sWrapperId,
- 'checkbox_name' => $sCheckboxName,
- 'checked' => ($bSelectAll && $bSelectAllChecked ? 'checked="checked"' : '')
- )
- ),
- ));
- }
- function showAdminFilterPanel($sFilterValue, $sInputId = 'filter_input_id', $sCheckboxId = 'filter_checkbox_id', $sFilterName = 'filter', $sOnApply = '')
- {
- $sFilterValue = bx_html_attribute($sFilterValue);
- $isChecked = $sFilterValue ? ' checked="checked" ' : '';
- if(empty($sOnApply))
- $sOnApply = "on_filter_apply(this, '" . $sInputId . "', '" . $sFilterName . "')";
- return BxDolTemplate::getInstance()->parseHtmlByName('adminFilterPanel.html', array(
- 'input_id' => $sInputId,
- 'filter_value' => $sFilterValue,
- 'checkbox_id' => $sCheckboxId,
- 'is_checked' => $isChecked,
- 'on_apply' => $sOnApply,
- ));
- }
- function showPagination($bAdmin = false, $bChangePage = true, $bPageReload = true)
- {
- $oMain = $this->getMain();
- $sPageUrl = $this->getCurrentUrl(array(), false);
- $sOnClick = $this->getCurrentOnclick(array(), false);
- $oPaginate = new BxTemplPaginate(array(
- 'page_url' => $sPageUrl,
- 'on_change_page' => $sOnClick,
- 'num' => $this->aCurrent['paginate']['num'],
- 'per_page' => $this->aCurrent['paginate']['perPage'],
- 'start' => $this->aCurrent['paginate']['start'],
- ));
- return $sOnClick ? $oPaginate->getSimplePaginate() : $oPaginate->getPaginate();
- }
- /**
- * Get current browse URL with current page and additional params
- * @param $aAdditionalParams set custom additional params as key value pair
- * @param $bReplacePagesParams replace paginate params with current values or leave markers for use in paginate class
- * @return ready to use URL string with BX_DOL_URL_ROOT added in the beginning
- */
- protected function getCurrentUrl($aAdditionalParams = array(), $bReplacePagesParams = true)
- {
- if (BX_DOL_SEARCH_KEYWORD_PAGE === $this->sBrowseUrl || $this->bForceAjaxPaginate)
- return 'javascript:void(0);';
- $oPermalinks = BxDolPermalinks::getInstance();
- $sUrlStart = BX_DOL_URL_ROOT . $oPermalinks->permalink($this->sBrowseUrl);
- return $this->addAdditionalUrlParams($sUrlStart, $aAdditionalParams, $bReplacePagesParams);
- }
- /**
- * Get current browse URL with current page and additional params
- * @param $aAdditionalParams set custom additional params as key value pair
- * @param $bReplacePagesParams replace paginate params with current values or leave markers for use in paginate class
- * @return ready to use URL string with BX_DOL_URL_ROOT added in the beginning
- */
- protected function getCurrentOnclick($aAdditionalParams = array(), $bReplacePagesParams = true)
- {
- if (BX_DOL_SEARCH_KEYWORD_PAGE !== $this->sBrowseUrl && !$this->bForceAjaxPaginate)
- return '';
- if (BX_DOL_SEARCH_KEYWORD_PAGE === $this->sBrowseUrl) {
- $sLoadDynamicUrl = BX_DOL_URL_ROOT . 'searchKeywordContent.php?searchMode=ajax§ion[]=' . $this->aCurrent['name'] . ($this->_sCategoryObject ? '&cat=' . $this->_sCategoryObject : '');
- $sLoadDynamicUrl = $this->addAdditionalUrlParams($sLoadDynamicUrl, $aAdditionalParams, $bReplacePagesParams);
- $sKeyword = bx_get('keyword');
- if ($sKeyword !== false && mb_strlen($sKeyword) > 0)
- $sLoadDynamicUrl = bx_append_url_params($sLoadDynamicUrl, 'keyword=' . rawurlencode($sKeyword));
- return "return !loadDynamicBlockAuto(this, '{$sLoadDynamicUrl}');";
- } else {
-
- return "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . (empty($aAdditionalParams) ? 'undefined' : "'" . trim($this->addAdditionalUrlParams('', $aAdditionalParams, false, false), '&?') . "'") . ");";
- }
- }
- protected function addAdditionalUrlParams($sUrl, $aAdditionalParams, $bReplacePagesParams, $bAddPaginateParams = true)
- {
- if ($bAddPaginateParams) { // add pages params
- $sUrl = bx_append_url_params($sUrl, array (
- 'type' => $this->_sMetaType,
- 'start' => $bReplacePagesParams ? (int)$this->aCurrent['paginate']['start'] : '{start}',
- 'per_page' => $bReplacePagesParams ? (int)$this->aCurrent['paginate']['perPage'] : '{per_page}',
- ));
- }
- foreach ($this->aGetParams as $sGetParam) {
- $sValue = false;
- if (isset($aAdditionalParams[$sGetParam]))
- $sValue = $aAdditionalParams[$sGetParam];
- elseif (false !== bx_get($sGetParam))
- $sValue = bx_get($sGetParam);
- if (false !== $sValue)
- $sUrl = bx_append_url_params($sUrl, $sGetParam . '=' . rawurlencode($sValue));
- }
- return $sUrl;
- }
- function clearFilters ($aPassParams = array(), $aPassJoins = array())
- {
- //clear sorting
- $this->aCurrent['sorting'] = 'last';
- //clear restrictions
- foreach ($this->aCurrent['restriction'] as $sKey => $aValue) {
- if (!in_array($sKey, $aPassParams))
- $this->aCurrent['restriction'][$sKey]['value'] = '';
- }
- //clear unnecessary joins (remains only profile join)
- $aPassJoins[] = 'profile';
- $aTemp = array();
- foreach ($aPassJoins as $sValue) {
- if (isset($this->aCurrent['join'][$sValue]) && is_array($this->aCurrent['join'][$sValue]))
- $aTemp[$sValue] = $this->aCurrent['join'][$sValue];
- }
- $this->aCurrent['join'] = $aTemp;
- }
- function fillFilters ($aParams)
- {
- // transform all given values to fields values
- if (is_array($aParams)) {
- foreach ($aParams as $sKey => $mixedValue) {
- if (isset($this->aCurrent['restriction'][$sKey]))
- $this->aCurrent['restriction'][$sKey]['value'] = $mixedValue;
- }
- }
- }
- /**
- * Set design box template id to use to wrap search results in
- */
- function setDesignBoxTemplateId ($i)
- {
- $this->iDesignBoxTemplate = $i;
- }
- /**
- * Set unit class selector for content centering
- */
- function setCenterContentUnitSelector ($s)
- {
- $this->sCenterContentUnitSelector = $s;
- }
- /**
- * Add class to search result container
- * @param $mixed CSS class name string or array of classes
- */
- function addContainerClass ($mixed)
- {
- if (!is_array($mixed))
- $mixed = array($mixed);
- foreach ($mixed as $s)
- if (false === array_search($s, $this->aContainerClasses))
- $this->aContainerClasses[] = $s;
- }
- /**
- * Remove class from search result container
- * @param $mixed CSS class name string or array of classes
- */
- function removeContainerClass ($mixed)
- {
- if (!is_array($mixed))
- $mixed = array($mixed);
- foreach ($mixed as $s)
- if (false !== ($i = array_search($s, $this->aContainerClasses)))
- unset($this->aContainerClasses[$i]);
- }
- /**
- * Add attribute(s) to search result container
- * @param $aAttributes an array of Key -> Value pair(s).
- */
- function addContainerAttribute ($aAttributes)
- {
- if(empty($aAttributes) || !is_array($aAttributes))
- return;
- $this->aContainerAttrs = array_merge($this->aContainerAttrs, $aAttributes);
- }
- /**
- * Remove attribute(s) from search result container
- * @param $mixedName attribute name or an array of names
- */
- function removeContainerAttribute ($mixedName)
- {
- if(!is_array($mixedName))
- $mixedName = array($mixedName);
- $this->aContainerAttrs = array_diff_assoc($this->aContainerAttrs, array_flip($mixedName));
- }
- public function setUnitParams ($aParamsAdd = array(), $aParamsRemove = array())
- {
- if ($aParamsAdd)
- $this->aUnitParams = array_merge($this->aUnitParams, $aParamsAdd);
- if ($aParamsRemove)
- $this->aUnitParams = array_diff_key($this->aUnitParams, $aParamsRemove);
- }
- }
- /** @} */
|