HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/includes/pages/search.php
<?php

/**
 * This file contains the iwp_page_search class
 *
 * @version $Id$
 * 
 *
 * @package IWP
 * @subpackage IWP_FrontEnd
 */

/**
 * IWP Frontend Search Class
 * This class extends the iwp_engine abstract class.
 * This class handles the actions for searching content on the frontend
 *
 * @package IWP
 * @subpackage IWP_FrontEnd
 */

class iwp_page_search extends iwp_engine {

	protected $searchQuery = '';
	protected $searchFields = null;
	protected $paging = null;
	protected $perPage = 10;

	/**
	 * Calls the parent constructor
	 *
	 * @return void Doesn't return anything
	 */

	public function __construct(){
		parent::__construct();
	}

	/**
	 * This function tells the controller to loads the advanced search page
	 *
	 * @return void Doesn't return anything
	 */
	public function ShowPage(){

		// load page essentials

		// page css
		$this->template->AddRequiredCSS(IWP_BASE_URI . '/lib/imodal/imodal.css');
		$this->template->AddRequiredCSS(IWP_BASE_URI . '/lib/iselector/iselector.css');
		$this->template->AddRequiredCSS(IWP_TPL_URI . '/styles/datepicker.css');

		// page javascript
		$this->template->AddRequiredJS(IWP_BASE_URI . '/javascript/jquery.ui.frontend.js');
		$this->template->AddRequiredJS(IWP_BASE_URI . '/lib/iselector/iselector.js');
		$this->template->AddRequiredJS(IWP_BASE_URI . '/javascript/search.js');
		$this->template->AddRequiredJS(IWP_BASE_URI . '/lib/imodal/imodal.js');

		// check if there is a search term in the url
		$sections = $this->urls->GetCurrentMatches();
		if(isset($sections['searchterm'])){
			$sections['searchterm'] = trim(urldecode(str_replace('+', ' ', $sections['searchterm'])));
		}

		// load the list of content types that can be searched
		$selectedTypes = $searchableTypes = array();

		if(isset($_GET['search_contenttypes']) && is_array($_GET['search_contenttypes'])){
			$selectedTypes = $_GET['search_contenttypes'];
		}

		$resource = $this->db->Query('select typeid, name from ' . IWP_TABLE_CONTENTTYPES .' where searchable=1');
		while($cType = $this->db->Fetch($resource)){
			$searchableTypes[$cType['typeid']] = $cType['name'];
		}

		$this->template->Assign('searchableContentTypesOptions', $this->output->ArrayToOptions($searchableTypes, $selectedTypes), false);

		// load the list of categories that can be searched
		$searchableCategories = $selectedCategories = array();

		if(isset($_GET['search_categories']) && is_array($_GET['search_categories'])){
			$selectedCategories = $_GET['search_categories'];
		}

		// add the first two options then the rest
		$searchableCategories[-1] = '('.$this->lang->Get('Uncategorized').')';
		$searchableCategories[0] = '('.$this->lang->Get('AllCategories').')';
		$searchableCategories = $searchableCategories + iwp_categories::getInstance()->GetCategoriesList();

		$this->template->Assign('searchableCategoriesOptions', $this->output->ArrayToOptions($searchableCategories, $selectedCategories), false);

		// the action for the form should be the static search url
		$this->template->Assign('searchAction', $this->urls->GetStaticURL('search'), false);

		// default form options
		$this->searchFields = array('content', 'title');

		$this->template->Assign('searchAuthorChecked', false);
		$this->template->Assign('searchAuthorChecked', true);
		$this->template->Assign('searchTitleChecked', true);
		//$this->template->Assign('searchStartDate', date('d/m/Y', strtotime('-30 days')));
		//$this->template->Assign('searchEndDate', date('d/m/Y'));
		$this->template->Assign('searchStartDate', '');
		$this->template->Assign('searchEndDate', '');



		// do we have a search term? If so, lets search!
		if(isset($_GET['search_Query']) && !iwp_validation::IsBlank($_GET['search_Query'])){
			$this->PerformSearch();
		}elseif(Isset($sections['searchterm']) && strlen($sections['searchterm']) > 0){
			$this->PerformSearch($sections['searchterm']);
		}

		if(iwp_validation::IsBlank($this->searchQuery)){
			$this->template->Assign('searchAdvanced', true);
		}else{
			$this->template->Assign('searchAdvanced', (@$_GET['searchadvanced'] == '1'));
		}

		// if we have a valid search query, lets show the title for it
		if(iwp_validation::IsBlank($this->searchQuery)){
			$this->template->AddOnLoadJS('setTimeout(\'$("#search_Query").focus();\',50);');
		}

		// output the page
		$this->controller->SetContent($this->template->ParseSection('advancedsearch_standard'));
		$this->controller->ShowTemplate('search');
	}

	private function PerformSearch($searchTerm=''){
		if(iwp_validation::IsBlank($searchTerm) && iwp_validation::IsBlank($_GET['search_Query'])){
			return;
		}

		if(isset($_GET['search_Query']) && strlen($_GET['search_Query']) > 0){
			$this->searchQuery = $_GET['search_Query'];
		}

		if(!iwp_validation::IsBlank($searchTerm)){
			$this->searchQuery = $searchTerm;
		}

		$allcats = $allTypes = false;
		$uncategorized = false;
		$categories = array('0', '-1');
		$contentTypes = null;

		$search = new iwp_search();
		$search->searchQuery = $this->searchQuery;

		// set up the searching categories
		if(isset($_GET['search_categories'])){
			$categories = $_GET['search_categories'];
		}

		if(in_array('0', $categories)){
			$allcats = true;
		}

		if(in_array('-1', $categories)){
			$uncategorized = true;
		}

		$categories = array_filter($categories, 'iwp_IsId');

		if($allcats){
			$categories[] = '0';
		}

		if($uncategorized){
			$categories[] = '-1';
		}

		$search->categories = $categories;

		// set up the searching content types
		if(isset($_GET['search_contenttypes'])){
			$contentTypes = $_GET['search_contenttypes'];

			if(in_array('0', $contentTypes)){
				$allTypes = true;
			}

			$contentTypes = array_filter($contentTypes, 'iwp_IsId');

			if($allTypes){
				$contentTypes[] = '0';
			}
		}

		if(sizeof($contentTypes) > 0){
			$search->contentTypes = $contentTypes;
		}

		// determine which fields should be searched
		$searchFields = array('title', 'content');

		if(isset($_GET['searchfields'])){
			$searchFields = array();

			if(in_array('content', $_GET['searchfields'])){
				$searchFields[] = 'content';
			}

			if(in_array('title', $_GET['searchfields'])){
				$searchFields[] = 'title';
			}

			if(in_array('author', $_GET['searchfields'])){
				$searchFields[] = 'author';
			}

			if(sizeof($searchFields) < 1){
				$searchFields = array('title', 'content');
			}
		}

		$this->searchFields = $searchFields;


		if(isset($_GET['search_startdate']) && isset($_GET['search_enddate']) && !($_GET['search_startdate'] == $_GET['search_enddate'] && ($_GET['search_enddate'] == date('d/m/Y')))){
			// do start date
			if(isset($_GET['search_startdate']) && !iwp_validation::IsBlank($_GET['search_startdate'])){
				preg_match_all('#([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})#ism', $_GET['search_startdate'], $matches);
				$time = strtotime((int)@$matches[3][0].'-'.(int)@$matches[2][0].'-'.(int)@$matches[1][0]);
				$search->startDate = $time;
			}

			// end date
			if(isset($_GET['search_enddate']) && !iwp_validation::IsBlank($_GET['search_enddate'])){
				preg_match_all('#([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})#ism', $_GET['search_enddate'], $matches);
				$time = strtotime((int)@$matches[3][0].'-'.(int)@$matches[2][0].'-'.(int)@$matches[1][0]);
				$search->endDate = $time;
			}

			if($search->startDate > $search->endDate && $search->endDate != null){
				$this->template->Assign('searchMessage', $this->lang->Get('errorStartDateAfterEndDate'));
				return;
			}
		}

		if(in_array('author', $this->searchFields)){
			$this->template->Assign('searchAuthorChecked', true);
		}else{
			$this->template->Assign('searchAuthorChecked', false);
		}

		if(in_array('content', $this->searchFields)){
			$this->template->Assign('searchContentChecked', true);
		}else{
			$this->template->Assign('searchContentChecked', false);
		}

		if(in_array('title', $this->searchFields)){
			$this->template->Assign('searchTitleChecked', true);
		}else{
			$this->template->Assign('searchTitleChecked', false);
		}

		if(isset($_GET['search_enddate']) && preg_match('#^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})$#', trim($_GET['search_enddate'])) > 0){
			$this->template->Assign('searchEndDate', $_GET['search_enddate']);
		}

		if(isset($_GET['search_startdate']) && preg_match('#^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})$#', trim($_GET['search_startdate'])) > 0){
			$this->template->Assign('searchStartDate', $_GET['search_startdate']);
		}

		$this->template->Assign('searchQuery', $this->searchQuery);

		$queryStringParts = array();

		$queryStringParts[] = 'search_Query='.urlencode($this->searchQuery);

		foreach($searchFields as $field){
			$queryStringParts[] = 'searchfields[]='. $field;
		}

		if(isset($_GET['search_contenttypes'])){
			foreach($_GET['search_contenttypes'] as $type){
				$queryStringParts[] = 'search_contenttypes[]='. (int)$type;
			}
		}

		if(isset($_GET['search_categories'])){
			foreach($_GET['search_categories'] as $cat){
				$queryStringParts[] = 'search_categories[]='. (int)$cat;
			}
		}

		if(isset($_GET['search_startdate'])){
			$queryStringParts[] = 'search_startdate='. urlencode($_GET['search_startdate']);
		}

		if(isset($_GET['search_enddate'])){
			$queryStringParts[] = 'search_enddate='. urlencode($_GET['search_enddate']);
		}

		$queryString = implode('&', $queryStringParts);

		$search->fields = $searchFields;

		// start paging
		$currentPage = max((int)@$_GET['page'], 1);

		iwp_event::listenerRegister('iwp_event_lists_dynamicoutput', array(&$this, 'ModifySearchResultRows'), '{%IWP_BASE_PATH%}/includes/pages/search.php',  50, true);

		$lists = new iwp_lists;
		$lists->ignoreCache = true;

		$search->perPage = $this->perPage;
		$search->pageNum = $currentPage;

		$sql = $search->Search();

		$searchResultList = $lists->OutputListByQuery($sql);

		iwp_event::listenerUnregister('iwp_event_lists_dynamicoutput', array(&$this, 'ModifySearchResultRows'), '{%IWP_BASE_PATH%}/includes/pages/search.php', 50, true);

		if(strlen($searchResultList) > 0){
			$this->template->Assign('searchResults', $searchResultList, false);
		}else{
			$this->template->Assign('searchResults', GetLang('searchNoResults'), false);
		}

		if(!iwp_validation::IsBlank($this->searchQuery)){
			$this->lang->Set('SearchResultTitle', $lists->foundRows . ' ' . sprintf($this->lang->Get('SearchResultTitle'), iwp_htmlentities($this->searchQuery)));
		}

		if($lists->foundRows > $this->perPage){
			$this->paging = new iwp_paging();

			$this->paging->ReplaceToken = '{pagenum}';
			$this->paging->SetPaging($lists->foundRows, $this->perPage, $currentPage, '?page={pagenum}&' . $queryString, 5);

			$paging = array();
			$paging['PageCount']	= $this->paging->PageCount;
			$paging['currentPage']	= $this->paging->CurrentPage;
			$paging['prevPageLink']	= $_SERVER['REQUEST_URI'] . $this->paging->PreviousURL;
			$paging['nextPageLink']	= $_SERVER['REQUEST_URI'] . $this->paging->NextURL;
			$paging['links']		= $this->paging->PageList;
			$paging['firstPageLink']= $_SERVER['REQUEST_URI'] . $this->paging->FirstURL;
			$paging['lastPageLink']	= $_SERVER['REQUEST_URI'] . $this->paging->LastURL;

			$this->template->Assign('paging', $paging);
			$pagingHTML = $this->template->ParseSection('paginglinks_standard');
			$this->template->Assign('searchPaging', $pagingHTML, false);
		}
	}

	public function ModifySearchResultRows($resultRow){
		$resultRow->listRowArray['Summary']     = strip_tags($resultRow->listRowArray['Summary'], '<br>');
		$resultRow->listRowArray['loadModules'] = false;
	}
}