PageRenderTime 22ms CodeModel.GetById 7ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/include/search.inc.php

https://gitlab.com/VoyaTrax/vtforum
PHP | 52 lines | 39 code | 10 blank | 3 comment | 6 complexity | fb823ba1bb370879b6abf6e98b2ea8bb MD5 | raw file
 1<?php
 2
 3function vtforum_search( $keywords , $andor , $limit , $offset , $userid )
 4{
 5	$db =& Database::getInstance() ;
 6	$myts =& MyTextSanitizer::getInstance() ;
 7
 8	$andor = strtoupper( $andor ) ;
 9	$userid = intval( $userid ) ;
10
11	// XOOPS Search module
12	$showcontext = empty( $_GET['showcontext'] ) ? 0 : 1 ;
13	$select4con = $showcontext ? "t.post_text" : "'' AS post_text" ;
14
15	require_once dirname(__FILE__).'/perm_functions.php' ;
16	$whr_forum = "p.forum_id IN (".implode(",",vtforum_get_forums_can_read()).")" ;
17
18	$whr_uid = $userid > 0 ? "p.uid=$userid" : "1" ;
19
20	$whr_query = $andor == 'OR' ? '0' : '1' ;
21	if( is_array( $keywords ) ) foreach( $keywords as $word ) {
22		// I know this is not a right escaping, but I can't believe $keywords :-)
23		$word4sql = addslashes( stripslashes( $word ) ) ;
24		$whr_query .= $andor == 'EXACT' ? ' AND' : ' '.$andor ;
25		$whr_query .= " (p.subject LIKE '%$word4sql%' OR t.post_text LIKE '%$word4sql%')" ;
26	}
27
28	$sql = "SELECT p.post_id,p.topic_id,p.post_time,p.uid,p.subject,$select4con FROM ".$db->prefix("vtforum_posts")." p LEFT JOIN ".$db->prefix("vtforum_posts_text")." t ON t.post_id=p.post_id LEFT JOIN ".$db->prefix("vtforum_forums")." f ON f.forum_id=p.forum_id WHERE ($whr_forum) AND ($whr_uid) AND ($whr_query) ORDER BY p.post_time DESC" ;
29
30	$result = $db->query( $sql , $limit , $offset ) ;
31	$ret = array() ;
32	$context = '' ;
33 	while( list( $post_id , $topic_id , $post_time , $uid , $subject , $text ) = $db->fetchRow( $result ) ) {
34
35		// get context for module "search"
36		if( function_exists( 'search_make_context' ) && $showcontext ) {
37			if( function_exists( 'easiestml' ) ) $text = easiestml( $text ) ;
38			$full_context = strip_tags( $myts->displayTarea( $text , 1 , 1 , 1 , 1 , 1 ) ) ;
39			$context = search_make_context( $full_context , $keywords ) ;
40		}
41
42		$ret[] = array(
43			'link' => "viewtopic.php?topic_id=$topic_id&post_id=$post_id#forumpost$post_id" ,
44			'title' => $subject ,
45			'time' => $post_time ,
46			'uid' => $uid ,
47			"context" => $context ,
48		) ;
49	}
50	return $ret;
51}
52?>