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