Example #1
0
	public function results() {
		require_once KPATH_SITE . '/lib/kunena.link.class.php';

		$model = $this->getModel('Search');
		$this->app->redirect ( CKunenaLink::GetSearchURL('advsearch', $model->getState('searchwords'),
			$model->getState('list.start'), $model->getState('list.limit'), $model->getUrlParams(), false) );
	}
Example #2
0
 /**
  * Search constructor
  * @param limitstart First shown item
  * @param limit Limit
  */
 function CKunenaSearch()
 {
     global $kunena_my;
     $app =& JFactory::getApplication();
     $kunena_db =& JFactory::getDBO();
     $fbConfig =& CKunenaConfig::getInstance();
     // TODO: started_by
     // TODO: active_in
     // Default values for checkboxes depends on function
     $this->func = strtolower(JRequest::getCmd('func'));
     if ($this->func == 'search') {
         $this->defaults['exactname'] = $this->defaults['childforums'] = 1;
     } else {
         $this->defaults['exactname'] = $this->defaults['childforums'] = 0;
     }
     $q = JRequest::getVar('q', '');
     // Search words
     // Backwards compability for old templates
     if (empty($q) && isset($_REQUEST['searchword'])) {
         $q = JRequest::getVar('searchword', '');
     }
     $q = stripslashes($q);
     $this->params['titleonly'] = JRequest::getInt('titleonly', $this->defaults['titleonly']);
     $this->params['searchuser'] = stripslashes(JRequest::getVar('searchuser', $this->defaults['searchuser']));
     $this->params['starteronly'] = JRequest::getInt('starteronly', $this->defaults['starteronly']);
     $this->params['exactname'] = JRequest::getInt('exactname', $this->defaults['exactname']);
     $this->params['replyless'] = JRequest::getInt('replyless', $this->defaults['replyless']);
     $this->params['replylimit'] = JRequest::getInt('replylimit', $this->defaults['replylimit']);
     $this->params['searchdate'] = JRequest::getVar('searchdate', $this->defaults['searchdate']);
     $this->params['beforeafter'] = JRequest::getVar('beforeafter', $this->defaults['beforeafter']);
     $this->params['sortby'] = JRequest::getVar('sortby', $this->defaults['sortby']);
     $this->params['order'] = JRequest::getVar('order', $this->defaults['order']);
     $this->params['childforums'] = JRequest::getInt('childforums', $this->defaults['childforums']);
     $this->params['catids'] = strtr(JRequest::getVar('catids', '0', 'get'), KUNENA_URL_LIST_SEPARATOR, ',');
     $limitstart = $this->limitstart = JRequest::getInt('limitstart', 0);
     $limit = $this->limit = JRequest::getInt('limit', $fbConfig->messages_per_page_search);
     extract($this->params);
     if ($limit < 1 || $limit > 40) {
         $limit = $this->limit = $fbConfig->messages_per_page_search;
     }
     if (isset($_POST['q']) || isset($_POST['searchword'])) {
         $this->params['catids'] = implode(',', JRequest::getVar('catids', array(0), 'post', 'array'));
         $url = CKunenaLink::GetSearchURL($fbConfig, $this->func, $q, $limitstart, $limit, $this->getUrlParams());
         header("HTTP/1.1 303 See Other");
         header("Location: " . htmlspecialchars_decode($url));
         $app->close();
     }
     if ($q == _GEN_SEARCH_BOX) {
         $q = '';
     }
     $this->searchword = $q;
     $arr_searchwords = split(' ', $q);
     $do_search = FALSE;
     $this->arr_kunena_searchstrings = array();
     foreach ($arr_searchwords as $q) {
         $q = trim($q);
         if (strlen($q) > 2) {
             $do_search = TRUE;
         }
         $this->arr_kunena_searchstrings[] = $q;
     }
     if (strlen($searchuser) > 0) {
         $do_search = TRUE;
     }
     $arr_searchwords = $this->arr_kunena_searchstrings;
     $this->str_kunena_username = $searchuser;
     if ($do_search != TRUE) {
         $this->int_kunena_errornr = 1;
         $this->str_kunena_errormsg = _KUNENA_SEARCH_ERR_SHORTKEYWORD;
         return;
     }
     $search_forums = $this->get_search_forums($catids, $childforums);
     /* if there are no forums to search in, set error and return */
     if (empty($search_forums)) {
         $this->int_kunena_errornr = 2;
         $this->str_kunena_errormsg = _KUNENA_SEARCH_NOFORUM;
         return;
     }
     for ($x = 0; $x < count($arr_searchwords); $x++) {
         $searchword = $arr_searchwords[$x];
         $searchword = $kunena_db->getEscaped(addslashes(trim(strtolower($searchword))));
         if (empty($searchword)) {
             continue;
         }
         $matches = array();
         $not = '';
         $operator = ' OR ';
         if (strstr($searchword, '-') == $searchword) {
             $not = 'NOT';
             $operator = 'AND';
             $searchword = substr($searchword, 1);
         }
         if ($titleonly == '0') {
             $querystrings[] = "(t.message {$not} LIKE '%{$searchword}%' {$operator} m.subject {$not} LIKE '%{$searchword}%')";
         } else {
             $querystrings[] = "(m.subject {$not} LIKE '%{$searchword}%')";
         }
     }
     //User searching
     if (strlen($searchuser) > 0) {
         if ($exactname == '1') {
             $querystrings[] = "m.name LIKE '" . $kunena_db->getEscaped(addslashes($searchuser)) . "'";
         } else {
             $querystrings[] = "m.name LIKE '%" . $kunena_db->getEscaped(addslashes($searchuser)) . "%'";
         }
     }
     $time = 0;
     switch ($searchdate) {
         case 'lastvisit':
             $kunena_db->setQuery("SELECT lasttime FROM #__fb_sessions WHERE userid='{$kunena_my->id}'");
             $time = $kunena_db->loadResult();
             break;
         case 'all':
             break;
         case '1':
         case '7':
         case '14':
         case '30':
         case '90':
         case '180':
         case '365':
             $time = time() - 86400 * intval($searchdate);
             //24*3600
             break;
         default:
             $time = time() - 86400 * 365;
             $searchdate = '365';
     }
     if ($time) {
         if ($beforeafter == 'after') {
             $querystrings[] = "m.time > '{$time}'";
         } else {
             $querystrings[] = "m.time <= '{$time}'";
         }
     }
     /* build query */
     $querystrings[] = "m.moved='0'";
     $querystrings[] = "m.hold='0'";
     $querystrings[] = "m.catid IN ({$search_forums})";
     $where = implode(' AND ', $querystrings);
     $groupby = array();
     if ($order == 'dec') {
         $order1 = 'DESC';
     } else {
         $order1 = 'ASC';
     }
     switch ($sortby) {
         case 'title':
             $orderby = "m.subject {$order1}, m.time {$order1}";
             break;
         case 'views':
             $orderby = "m.hits {$order1}, m.time {$order1}";
             break;
             /*
                     case 'threadstart':
             		$orderby = "m.time {$order1}, m.ordering {$order1}, m.hits {$order1}";
                     break;
             */
         /*
                 case 'threadstart':
         		$orderby = "m.time {$order1}, m.ordering {$order1}, m.hits {$order1}";
                 break;
         */
         case 'forum':
             $orderby = "m.catid {$order1}, m.time {$order1}, m.ordering {$order1}";
             break;
             /*
                     case 'replycount':
                     case 'postusername':
             */
         /*
                 case 'replycount':
                 case 'postusername':
         */
         case 'lastpost':
         default:
             $orderby = "m.time {$order1}, m.ordering {$order1}, m.catid {$order1}";
     }
     if (count($groupby) > 0) {
         $groupby = ' GROUP BY ' . implode(',', $groupby);
     } else {
         $groupby = '';
     }
     /* get total */
     $kunena_db->setQuery("SELECT COUNT(*) FROM #__fb_messages AS m JOIN #__fb_messages_text AS t ON m.id=t.mesid WHERE {$where} {$groupby}");
     $this->total = $kunena_db->loadResult();
     check_dberror("Unable to count messages.");
     /* if there are no forums to search in, set error and return */
     if ($this->total == 0) {
         $this->int_kunena_errornr = 3;
         $this->str_kunena_errormsg = _KUNENA_SEARCH_ERR_NOPOSTS;
         return;
     }
     if ($this->total < $this->limitstart) {
         $this->limitstart = $limitstart = (int) ($this->total / $this->limit);
     }
     /* get results */
     $sql = "SELECT m.id, m.subject, m.catid, m.thread, m.name, m.time, t.mesid, t.message FROM #__fb_messages_text AS t JOIN #__fb_messages AS m ON m.id=t.mesid WHERE {$where} {$groupby} ORDER BY {$orderby}";
     $kunena_db->setQuery($sql, $limitstart, $limit);
     $rows = $kunena_db->loadObjectList();
     check_dberror("Unable to load messages.");
     $this->str_kunena_errormsg = $sql . '<br />' . $kunena_db->getErrorMsg();
     if (count($rows) > 0) {
         $this->arr_kunena_results = $rows;
     } else {
         $this->arr_kunena_results = array();
     }
     return;
 }
 /**
  * Search constructor
  * @param limitstart First shown item
  * @param limit Limit
  */
 function CKunenaSearch()
 {
     $this->my = JFactory::getUser();
     $this->app = JFactory::getApplication();
     $this->doc = JFactory::getDocument();
     $this->db = JFactory::getDBO();
     $this->config = KunenaFactory::getConfig();
     $this->session = KunenaFactory::getSession();
     // TODO: started_by
     // TODO: active_in
     // Default values for checkboxes depends on function
     $this->func = JString::strtolower(JRequest::getCmd('func'));
     if ($this->func == 'search') {
         $this->defaults['exactname'] = $this->defaults['childforums'] = 1;
     } else {
         $this->defaults['exactname'] = $this->defaults['childforums'] = 0;
     }
     $q = JRequest::getVar('q', '');
     // Search words
     // Backwards compability for old templates
     if (empty($q) && isset($_REQUEST['searchword'])) {
         $q = JRequest::getVar('searchword', '');
     }
     $q = JString::trim($q);
     $this->params['titleonly'] = JRequest::getInt('titleonly', $this->defaults['titleonly']);
     $this->params['searchuser'] = JRequest::getVar('searchuser', $this->defaults['searchuser']);
     $this->params['starteronly'] = JRequest::getInt('starteronly', $this->defaults['starteronly']);
     $this->params['exactname'] = JRequest::getInt('exactname', $this->defaults['exactname']);
     $this->params['replyless'] = JRequest::getInt('replyless', $this->defaults['replyless']);
     $this->params['replylimit'] = JRequest::getInt('replylimit', $this->defaults['replylimit']);
     $this->params['searchdate'] = JRequest::getVar('searchdate', $this->defaults['searchdate']);
     $this->params['beforeafter'] = JRequest::getVar('beforeafter', $this->defaults['beforeafter']);
     $this->params['sortby'] = JRequest::getVar('sortby', $this->defaults['sortby']);
     $this->params['order'] = JRequest::getVar('order', $this->defaults['order']);
     $this->params['childforums'] = JRequest::getInt('childforums', $this->defaults['childforums']);
     $this->params['catids'] = strtr(JRequest::getVar('catids', '0', 'get'), KUNENA_URL_LIST_SEPARATOR, ',');
     $this->params['show'] = JRequest::getInt('show', $this->defaults['show']);
     $this->limitstart = JRequest::getInt('limitstart', 0);
     $this->limit = JRequest::getInt('limit', $this->config->messages_per_page_search);
     extract($this->params);
     if ($this->limit < 1 || $this->limit > 40) {
         $this->limit = $this->limit = $this->config->messages_per_page_search;
     }
     if (isset($_POST['q']) || isset($_POST['searchword'])) {
         $catids = JRequest::getVar('catids', array(0), 'post', 'array');
         JArrayHelper::toInteger($catids);
         $this->params['catids'] = implode(',', $catids);
         $url = CKunenaLink::GetSearchURL($this->func, $q, $this->limitstart, $this->limit, $this->getUrlParams());
         header("HTTP/1.1 303 See Other");
         header("Location: " . htmlspecialchars_decode($url));
         $this->app->close();
     }
     $catids = explode(',', $this->params['catids']);
     JArrayHelper::toInteger($catids);
     $this->params['catids'] = implode(',', $catids);
     if ($q == JText::_('COM_KUNENA_GEN_SEARCH_BOX')) {
         $q = '';
     }
     $this->q = $q;
     $arr_searchwords = preg_split('/[\\s,]*\'([^\']+)\'[\\s,]*|[\\s,]*"([^"]+)"[\\s,]*|[\\s,]+/u', $q, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
     $do_search = FALSE;
     $this->arr_kunena_searchstrings = array();
     foreach ($arr_searchwords as $q) {
         $q = JString::trim($q);
         if (JString::strlen($q) > 1) {
             $do_search = TRUE;
         }
         $this->arr_kunena_searchstrings[] = $q;
     }
     if (JString::strlen($this->params['searchuser']) > 0) {
         $do_search = TRUE;
     }
     $arr_searchwords = $this->arr_kunena_searchstrings;
     $this->str_kunena_username = $this->params['searchuser'];
     if ($do_search != TRUE) {
         $this->int_kunena_errornr = 1;
         $this->str_kunena_errormsg = JText::_('COM_KUNENA_SEARCH_ERR_SHORTKEYWORD');
         return;
     }
     $search_forums = $this->get_search_forums($this->params['catids'], $this->params['childforums']);
     /* if there are no forums to search in, set error and return */
     if (empty($search_forums)) {
         $this->int_kunena_errornr = 2;
         $this->str_kunena_errormsg = JText::_('COM_KUNENA_SEARCH_NOFORUM');
         return;
     }
     for ($x = 0; $x < count($arr_searchwords); $x++) {
         $searchword = $arr_searchwords[$x];
         $searchword = $this->db->getEscaped(JString::trim($searchword));
         if (empty($searchword)) {
             continue;
         }
         $matches = array();
         $not = '';
         $operator = ' OR ';
         if (substr($searchword, 0, 1) == '-' && strlen($searchword) > 1) {
             $not = 'NOT';
             $operator = 'AND';
             $searchword = JString::substr($searchword, 1);
         }
         if ($this->params['titleonly'] == '0') {
             $querystrings[] = "(t.message {$not} LIKE '%{$searchword}%' {$operator} m.subject {$not} LIKE '%{$searchword}%')";
         } else {
             $querystrings[] = "(m.subject {$not} LIKE '%{$searchword}%')";
         }
     }
     //User searching
     if (JString::strlen($this->params['searchuser']) > 0) {
         if ($this->params['exactname'] == '1') {
             $querystrings[] = "m.name LIKE '" . $this->db->getEscaped($this->params['searchuser']) . "'";
         } else {
             $querystrings[] = "m.name LIKE '%" . $this->db->getEscaped($this->params['searchuser']) . "%'";
         }
     }
     $time = 0;
     switch ($this->params['searchdate']) {
         case 'lastvisit':
             $this->db->setQuery("SELECT lasttime FROM #__kunena_sessions WHERE userid={$this->db->Quote($this->my->id)}");
             $time = $this->db->loadResult();
             break;
         case 'all':
             break;
         case '1':
         case '7':
         case '14':
         case '30':
         case '90':
         case '180':
         case '365':
             $time = time() - 86400 * intval($this->params['searchdate']);
             //24*3600
             break;
         default:
             $time = time() - 86400 * 365;
             $searchdate = '365';
     }
     if ($time) {
         if ($this->params['beforeafter'] == 'after') {
             $querystrings[] = "m.time > '{$time}'";
         } else {
             $querystrings[] = "m.time <= '{$time}'";
         }
     }
     /* build query */
     $querystrings[] = "m.moved='0'";
     //Search also unapproved, trash
     $this->show = array();
     if (CKunenaTools::isModerator($this->my->id) && $this->params['show'] > 0) {
         $search_forums_array = explode(',', $search_forums);
         $search_forums = array();
         foreach ($search_forums_array as $currforum) {
             if (CKunenaTools::isModerator($this->my->id, $currforum)) {
                 $search_forums[] = $currforum;
             }
         }
         if (empty($search_forums)) {
             return;
         }
         $search_forums = implode(',', $search_forums);
         $querystrings[] = "m.hold='" . (int) $this->params['show'] . "'";
     } else {
         $querystrings[] = "m.hold='0'";
     }
     $querystrings[] = "m.catid IN ({$search_forums})";
     $where = implode(' AND ', $querystrings);
     $groupby = array();
     if ($this->params['order'] == 'dec') {
         $order1 = 'DESC';
     } else {
         $order1 = 'ASC';
     }
     switch ($this->params['sortby']) {
         case 'title':
             $orderby = "m.subject {$order1}, m.time {$order1}";
             break;
         case 'views':
             $orderby = "m.hits {$order1}, m.time {$order1}";
             break;
             /*
                     case 'threadstart':
             		$orderby = "m.time {$order1}, m.ordering {$order1}, m.hits {$order1}";
                     break;
             */
         /*
                 case 'threadstart':
         		$orderby = "m.time {$order1}, m.ordering {$order1}, m.hits {$order1}";
                 break;
         */
         case 'forum':
             $orderby = "m.catid {$order1}, m.time {$order1}, m.ordering {$order1}";
             break;
             /*
                     case 'replycount':
                     case 'postusername':
             */
         /*
                 case 'replycount':
                 case 'postusername':
         */
         case 'lastpost':
         default:
             $orderby = "m.time {$order1}, m.ordering {$order1}, m.catid {$order1}";
     }
     if (count($groupby) > 0) {
         $groupby = ' GROUP BY ' . implode(',', $groupby);
     } else {
         $groupby = '';
     }
     /* get total */
     $this->db->setQuery("SELECT COUNT(*) FROM #__kunena_messages AS m JOIN #__kunena_messages_text AS t ON m.id=t.mesid WHERE {$where} {$groupby}");
     $this->total = $this->db->loadResult();
     KunenaError::checkDatabaseError();
     /* if there are no forums to search in, set error and return */
     if ($this->total == 0) {
         $this->int_kunena_errornr = 3;
         $this->str_kunena_errormsg = JText::_('COM_KUNENA_SEARCH_ERR_NOPOSTS');
         return;
     }
     if ($this->total < $this->limitstart) {
         $this->limitstart = (int) ($this->total / $this->limit);
     }
     /* get results */
     $sql = "SELECT m.id, m.subject, m.catid, m.thread, m.name, m.time, t.mesid, t.message,\n\t\t\t\t\t\tc.name AS catname, c.class_sfx\n        \t\tFROM #__kunena_messages_text AS t JOIN #__kunena_messages AS m ON m.id=t.mesid\n        \t\tJOIN #__kunena_categories AS c ON m.catid = c.id\n        \t\tWHERE {$where} {$groupby} ORDER BY {$orderby}";
     $this->db->setQuery($sql, $this->limitstart, $this->limit);
     $rows = $this->db->loadObjectList();
     KunenaError::checkDatabaseError();
     $this->str_kunena_errormsg = $sql . '<br />' . $this->db->getErrorMsg();
     if (count($rows) > 0) {
         $this->arr_kunena_results = $rows;
     } else {
         $this->arr_kunena_results = array();
     }
     return;
 }
Example #4
0
		<span class="ktoggler"><a class="ktoggler <?php 
echo $advsearch_class;
?>
" title="<?php 
echo $advsearch_title;
?>
" rel="advsearch"></a></span>
		<h2><span><?php 
echo JText::_('COM_KUNENA_SEARCH_ADVSEARCH');
?>
</span></h2>
	</div>
	<div class="kcontainer">
		<div class="kbody">
<form action="<?php 
echo CKunenaLink::GetSearchURL('advsearch');
?>
" method="post" id="searchform" name="adminForm">
	<table id="kforumsearch">
		<tbody id="advsearch"<?php 
echo $advsearch_style;
?>
>
			<tr class="krow1">
				<td class="kcol-first">
					<fieldset class="fieldset">
						<legend><?php 
echo JText::_('COM_KUNENA_SEARCH_SEARCHBY_KEYWORD');
?>
</legend>
						<label class="searchlabel" for="keywords"><?php 
Example #5
0
 * @package Kunena.Template.Default20
 * @subpackage Common
 *
 * @copyright (C) 2008 - 2011 Kunena Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @link http://www.kunena.org
 **/
defined ( '_JEXEC' ) or die ();
		$q = JRequest::getVar ( 'q', '' ); // Search words
		$searchuser = JRequest::getVar ( 'searchuser', '' ); // Search user
		// Backwards compability for old templates
		if (empty ( $q ) && isset ( $_REQUEST ['searchword'] )) {
			$q = JRequest::getVar ( 'searchword', '' );
		}
		if (empty ( $searchuser ) && isset ( $_REQUEST ['searchword'] )) {
			$searchuser = JRequest::getVar ( 'searchword', '' );
		}
?>
<div id="mb_search" style="display:none;">
	<div class="tk-mb-header-search" style="display:none; margin-bottom:10px;">
		<span class="tk-mb-first"><?php echo JText::_('COM_KUNENA_TEMPLATE_SEARCH_IN_FORUM'); ?></span>
	</div>
	<form action="<?php echo CKunenaLink::GetSearchURL('advsearch'); ?>" method="post" id="searchform" name="adminForm">
		<input id="keywords" class="tk-searchbox" type="text" name="q" value="<?php echo $this->escape($q); ?>" />
		<?php /*?><input id="kusername" class="tk-searchbox" type="text" name="searchuser" value="<?php echo $this->escape($searchuser); ?>" /><?php */?>
		<input class="tk-search-button" type="submit" value="<?php echo JText::_('COM_KUNENA_SEARCH_SEND'); ?>" />
	</form>
	<div>
		<a class="tk-mb-advsearchlink" href="<?php JURI::base() ?>index.php?option=com_kunena&view=search"><?php echo JText::_('COM_KUNENA_SEARCH_ADVSEARCH'); ?></a>
	</div>
</div>