Bp_Search_Folders:: sql (search_term美元,only_totalrow_count美元=假)
描述
源
文件:bp-search /类/ class-bp-search-folders.php
Public function sql($search_term, $only_totalrow_count = false) {global $wpdb, $bp;数组$ query_placeholder = ();数组$ user_groups = ();if (bp_is_active('groups')){//获取公共组。$public_groups = group_get_groups (array('fields' => 'ids', 'status' => 'public', 'per_page' => - 1,));如果(!$public_groups = $public_groups['groups']; / / public groups = $public_groups['groups']} else {$public_groups = array();} $user_groups = array();If (is_user_logged_in()) {$groups = group_get_user_groups (bp_loggedin_user_id()); if ( ! empty( $groups['groups'] ) ) { $user_groups = $groups['groups']; } else { $user_groups = array(); } } $user_groups = array_unique( array_merge( $user_groups, $public_groups ) ); } $friends = array(); if ( bp_is_active( 'friends' ) && is_user_logged_in() ) { // Determine friends of user. $friends = friends_get_friend_user_ids( bp_loggedin_user_id() ); if ( empty( $friends ) ) { $friends = array( 0 ); } array_push( $friends, bp_loggedin_user_id() ); } $sql = ' SELECT '; if ( $only_totalrow_count ) { $sql .= ' COUNT( DISTINCT f.id ) '; } else { $sql .= $wpdb->prepare(" DISTINCT f.id, 'folders' as type, f.title LIKE %s AS relevance, f.date_created as entry_date ", '%' . $wpdb->esc_like( $search_term ) . '%' ); } $privacy = array( 'public' ); if( is_user_logged_in() ) { $privacy[] = 'loggedin'; } $sql .= $wpdb->prepare( " FROM {$bp->document->table_name_folder} f WHERE ( f.title LIKE %s AND ( f.privacy IN ( '" . implode( "','", $privacy ) . "' ) " . ( isset( $user_groups ) && ! empty( $user_groups ) ? " OR ( f.group_id IN ( '" . implode( "','", $user_groups ) . "' ) AND f.privacy = 'grouponly' )" : '' ) . ( bp_is_active( 'friends' ) && ! empty( $friends ) ? " OR ( f.user_id IN ( '" . implode( "','", $friends ) . "' ) AND f.privacy = 'friends' )" : '' ) . ( is_user_logged_in() ? " OR ( f.user_id = '" . bp_loggedin_user_id() . "' AND f.privacy = 'onlyme' )" : '' ) . ") )", '%' . $wpdb->esc_like( $search_term ) . '%' ); return apply_filters( 'bp_search_folders_sql', $sql, array( 'search_term' => $search_term, 'only_totalrow_count' => $only_totalrow_count, ) ); }