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