1 | <?php
|
---|
2 | $mydirname = basename( dirname(dirname( __FILE__ ) ) );
|
---|
3 |
|
---|
4 | eval( '
|
---|
5 |
|
---|
6 | function '.$mydirname.'_global_search( $keywords , $andor , $limit , $offset , $userid )
|
---|
7 | {
|
---|
8 | return xpress_global_search_base( "'.$mydirname.'" , $keywords , $andor , $limit , $offset , $userid ) ;
|
---|
9 | }
|
---|
10 |
|
---|
11 | ' ) ;
|
---|
12 |
|
---|
13 |
|
---|
14 | if( ! function_exists( 'xpress_global_search_base' ) ) {
|
---|
15 |
|
---|
16 | function xpress_global_search_base( $mydirname , $queryarray , $andor , $limit , $offset , $userid )
|
---|
17 | {
|
---|
18 | global $xoopsDB, $myts;
|
---|
19 |
|
---|
20 | $myts =& MyTextSanitizer::getInstance();
|
---|
21 |
|
---|
22 | $time_difference = get_time_difference($mydirname);
|
---|
23 | $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
|
---|
24 | $where = "(post_status = 'publish') AND (post_date <= '".$now."')";
|
---|
25 |
|
---|
26 | if ( is_array($queryarray) && $count = count($queryarray) ) {
|
---|
27 | $str_query = array();
|
---|
28 | for($i=0;$i<$count;$i++){
|
---|
29 | $str_query[] = "(post_title LIKE '%".$queryarray[$i]."%' OR post_content LIKE '%".$queryarray[$i]."%')";
|
---|
30 | }
|
---|
31 | $where .= " AND ".implode(" $andor ", $str_query);
|
---|
32 | }
|
---|
33 | if ($userid) {
|
---|
34 | $userid = intval($userid);
|
---|
35 | $where .= " AND (post_author=".$userid.")";
|
---|
36 | }
|
---|
37 |
|
---|
38 | $xp_prefix = $mydirname;
|
---|
39 | if ($xp_prefix == 'wordpress'){
|
---|
40 | $xp_prefix = 'wp';
|
---|
41 | }
|
---|
42 | $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_posts' ;
|
---|
43 |
|
---|
44 | $request = "SELECT * FROM " . $views_table ." WHERE ".$where;
|
---|
45 | $request .= " ORDER BY post_date DESC";
|
---|
46 | $result = $xoopsDB->query($request,$limit,$offset);
|
---|
47 |
|
---|
48 | $ret = array();
|
---|
49 | $i = 0;
|
---|
50 | while($myrow = $xoopsDB->fetchArray($result)){
|
---|
51 |
|
---|
52 |
|
---|
53 | // $ret[$i]['link'] = str_replace(get_settings('home')."/","",get_permalink(($myrow['ID'])));
|
---|
54 | switch ($myrow['post_type']) {
|
---|
55 | case 'page':
|
---|
56 | $ret[$i]['link'] = '?page_id=' . $myrow['ID'];
|
---|
57 | break;
|
---|
58 | case 'post':
|
---|
59 | case '':
|
---|
60 | $ret[$i]['link'] = '?p=' . $myrow['ID'];
|
---|
61 | }
|
---|
62 |
|
---|
63 | $ret[$i]['title'] = $myts->htmlSpecialChars($myrow['post_title']);
|
---|
64 | $date_str = $myrow['post_date'];
|
---|
65 | $yyyy = substr($date_str,0,4);
|
---|
66 | $mm = substr($date_str,5,2);
|
---|
67 | $dd = substr($date_str,8,2);
|
---|
68 | $hh = substr($date_str,11,2);
|
---|
69 | $nn = substr($date_str,14,2);
|
---|
70 | $ss = substr($date_str,17,2);
|
---|
71 | $ret[$i]['time'] = mktime( $hh,$nn,$ss,$mm,$dd,$yyyy);
|
---|
72 | $ret[$i]['uid'] = $myrow['post_author'];
|
---|
73 | // $ret[$i]['page'] = $myts->htmlSpecialChars($myrow['post_title']);
|
---|
74 |
|
---|
75 | $context = '' ;
|
---|
76 | $text =$myrow['post_content'];
|
---|
77 | // get context for module "search"
|
---|
78 | $showcontext = empty( $_GET['showcontext'] ) ? 0 : 1 ;
|
---|
79 | if( function_exists( 'search_make_context' ) && $showcontext ) {
|
---|
80 | if( function_exists( 'easiestml' ) ) $text = easiestml( $text ) ;
|
---|
81 | $full_context = strip_tags($text) ;
|
---|
82 | $context = search_make_context( $full_context , $queryarray ) ;
|
---|
83 | }
|
---|
84 | $ret[$i]['context']=$context;
|
---|
85 |
|
---|
86 |
|
---|
87 | $i++;
|
---|
88 | }
|
---|
89 | return $ret;
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 | }
|
---|
94 |
|
---|
95 | if( ! function_exists( 'get_time_difference' ) ) {
|
---|
96 | function get_time_difference($mydirname){
|
---|
97 | $xoopsDB =& Database::getInstance();
|
---|
98 |
|
---|
99 | $xp_prefix = $mydirname;
|
---|
100 | if ($xp_prefix == 'wordpress'){
|
---|
101 | $xp_prefix = 'wp';
|
---|
102 | }
|
---|
103 | $option_tbl = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_options' ;
|
---|
104 |
|
---|
105 | $sql = "SELECT option_value FROM $option_tbl WHERE option_name = 'gmt_offset'";
|
---|
106 |
|
---|
107 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
108 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
109 | $row = $xoopsDB->fetchArray($result);
|
---|
110 | return $row['option_value'];
|
---|
111 | }
|
---|
112 | return 0;
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | ?> |
---|