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