plugin updates
This commit is contained in:
@@ -284,7 +284,7 @@ function relevanssi_populate_array( $matches, $blog_id = -1 ) {
|
||||
foreach ( $posts as $post ) {
|
||||
$cache_id = $blog_id . '|' . $post->ID;
|
||||
|
||||
$relevanssi_post_array[ $cache_id ] = $post;
|
||||
$relevanssi_post_array[ $cache_id ] = new WP_Post( $post );
|
||||
}
|
||||
}
|
||||
} while ( $ids );
|
||||
|
||||
@@ -73,14 +73,14 @@ function relevanssi_seoframework_form() {
|
||||
?>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for='relevanssi_seo_noindex'><?php esc_html_e( 'Use SEO Framework noindex', 'relevanssi' ); ?></label>
|
||||
<label for='relevanssi_seo_noindex'><?php esc_html_e( 'Use SEO Framework local search exclude', 'relevanssi' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<label for='relevanssi_seo_noindex'>
|
||||
<input type='checkbox' name='relevanssi_seo_noindex' id='relevanssi_seo_noindex' <?php echo esc_attr( $seo_noindex ); ?> />
|
||||
<?php esc_html_e( 'Use SEO Framework noindex.', 'relevanssi' ); ?>
|
||||
<?php esc_html_e( 'Use SEO Framework local search exclude.', 'relevanssi' ); ?>
|
||||
</label>
|
||||
<p class="description"><?php esc_html_e( 'If checked, Relevanssi will not index posts marked as "No index" in SEO Framework settings.', 'relevanssi' ); ?></p>
|
||||
<p class="description"><?php esc_html_e( 'If checked, Relevanssi will not index posts marked as "Exclude this page from all search queries on this site" in SEO Framework settings.', 'relevanssi' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
@@ -616,6 +616,39 @@ function relevanssi_index_doc( $index_post, $remove_first = false, $custom_field
|
||||
$post = $previous_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the number of queries returned.
|
||||
*
|
||||
* Added for potential TranslatePress support.
|
||||
*
|
||||
* @param string|int $n Number of insert queries run, or
|
||||
* -1 if the indexing fails, or 'hide' in case the post is hidden or
|
||||
* 'donotindex' if a filter blocks this.
|
||||
* @param object|int $index_post The post to index, either post
|
||||
* object or post ID.
|
||||
* @param boolean $remove_first If true, remove the post from the
|
||||
* index before indexing. Default false.
|
||||
* @param array $custom_fields The custom fields that are indexed
|
||||
* for the post. Default an empty string.
|
||||
* @param boolean $bypass_global_post If true, do not use the global
|
||||
* $post object. Default false.
|
||||
* @param boolean $debug If true, echo out debugging
|
||||
* information. Default false.
|
||||
*
|
||||
* @return string|int Number of insert queries run, or -1 if the indexing
|
||||
* fails, or 'hide' in case the post is hidden or 'donotindex' if a filter
|
||||
* blocks this.
|
||||
*/
|
||||
$n = apply_filters(
|
||||
'relevanssi_after_index_doc_n',
|
||||
$n,
|
||||
$index_post,
|
||||
$remove_first,
|
||||
$custom_fields,
|
||||
$bypass_global_post,
|
||||
$debug
|
||||
);
|
||||
|
||||
return $n;
|
||||
}
|
||||
|
||||
@@ -1049,7 +1082,13 @@ function relevanssi_get_comments( $post_id ) {
|
||||
function relevanssi_truncate_index() {
|
||||
global $wpdb, $relevanssi_variables;
|
||||
$relevanssi_table = $relevanssi_variables['relevanssi_table'];
|
||||
return $wpdb->query( "TRUNCATE TABLE $relevanssi_table" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
|
||||
/**
|
||||
* Filters the TRUNCATE TABLE query for truncating the index.
|
||||
*
|
||||
* @param string The MySQL query.
|
||||
*/
|
||||
return $wpdb->query( apply_filters( 'relevanssi_truncate_index', "TRUNCATE TABLE $relevanssi_table" ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1477,6 +1516,8 @@ function relevanssi_index_content( &$insert_data, $post_object, $min_word_length
|
||||
/**
|
||||
* If this filter returns false, post content is not indexed at all.
|
||||
*
|
||||
* Also used in /premium/pinning.php.
|
||||
*
|
||||
* @param boolean Return false to prevent post content from being indexed.
|
||||
* Default true.
|
||||
* @param object $post_object The post object.
|
||||
|
||||
@@ -321,8 +321,8 @@ function relevanssi_create_database_tables( $relevanssi_db_version ) {
|
||||
customfield mediumint(9) NOT NULL DEFAULT '0',
|
||||
mysqlcolumn mediumint(9) NOT NULL DEFAULT '0',
|
||||
taxonomy_detail longtext NOT NULL,
|
||||
customfield_detail longtext NOT NULL DEFAULT '',
|
||||
mysqlcolumn_detail longtext NOT NULL DEFAULT '',
|
||||
customfield_detail longtext NOT NULL,
|
||||
mysqlcolumn_detail longtext NOT NULL,
|
||||
type varchar(210) NOT NULL DEFAULT 'post',
|
||||
item bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY doctermitem (doc, term, item)) $charset_collate";
|
||||
@@ -392,6 +392,7 @@ function relevanssi_create_database_tables( $relevanssi_db_version ) {
|
||||
user_id bigint(20) NOT NULL DEFAULT '0',
|
||||
ip varchar(40) NOT NULL DEFAULT '',
|
||||
session_id varchar(32) NOT NULL DEFAULT '',
|
||||
source varchar(32) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY id (id)) $charset_collate;";
|
||||
|
||||
dbDelta( $sql );
|
||||
@@ -524,10 +525,11 @@ function relevanssi_load_compatibility_code() {
|
||||
defined( 'GROUPS_CORE_VERSION' ) && require_once 'compatibility/groups.php';
|
||||
defined( 'NINJA_TABLES_VERSION' ) && require_once 'compatibility/ninjatables.php';
|
||||
defined( 'PRLI_PLUGIN_NAME' ) && require_once 'compatibility/pretty-links.php';
|
||||
defined( 'WPM_PRODUCT_GTIN_WC_VERSION' ) && require_once 'compatibility/product-gtin-ean-upc-isbn-for-woocommerce.php';
|
||||
defined( 'SEOPRESS_VERSION' ) && require_once 'compatibility/seopress.php';
|
||||
defined( 'SIMPLE_WP_MEMBERSHIP_VER' ) && require_once 'compatibility/simplemembership.php';
|
||||
defined( 'THE_SEO_FRAMEWORK_VERSION' ) && require_once 'compatibility/seoframework.php';
|
||||
defined( 'WPFD_VERSION' ) && require_once 'compatibility/wp-file-download.php';
|
||||
defined( 'WPM_PRODUCT_GTIN_WC_VERSION' ) && require_once 'compatibility/product-gtin-ean-upc-isbn-for-woocommerce.php';
|
||||
defined( 'WPMEM_VERSION' ) && require_once 'compatibility/wp-members.php';
|
||||
defined( 'WPSEO_FILE' ) && require_once 'compatibility/yoast-seo.php';
|
||||
function_exists( 'do_blocks' ) && require_once 'compatibility/gutenberg.php';
|
||||
@@ -535,7 +537,6 @@ function relevanssi_load_compatibility_code() {
|
||||
function_exists( 'members_content_permissions_enabled' ) && require_once 'compatibility/members.php';
|
||||
function_exists( 'pmpro_has_membership_access' ) && require_once 'compatibility/paidmembershippro.php';
|
||||
function_exists( 'rcp_user_can_access' ) && require_once 'compatibility/restrictcontentpro.php';
|
||||
function_exists( 'seopress_get_toggle_titles_option' ) && '1' === seopress_get_toggle_titles_option() && require_once 'compatibility/seopress.php';
|
||||
function_exists( 'wp_jv_prg_user_can_see_a_post' ) && require_once 'compatibility/wpjvpostreadinggroups.php';
|
||||
|
||||
// phpcs:disable WordPress.NamingConventions.ValidVariableName
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
* @global object $wpdb The WordPress database interface.
|
||||
* @global array $relevanssi_variables The global Relevanssi variables, used for database table names.
|
||||
*
|
||||
* @param string $query The search query.
|
||||
* @param int $hits The number of hits found.
|
||||
* @param string $query The search query.
|
||||
* @param int $hits The number of hits found.
|
||||
* @param string $source The search source identifier, default ''.
|
||||
*
|
||||
* @return boolean True if logged, false if not logged.
|
||||
*/
|
||||
function relevanssi_update_log( $query, $hits ) {
|
||||
function relevanssi_update_log( $query, $hits, $source = '' ) {
|
||||
if ( empty( $query ) ) {
|
||||
return false;
|
||||
}
|
||||
@@ -58,6 +59,10 @@ function relevanssi_update_log( $query, $hits ) {
|
||||
$ip = apply_filters( 'relevanssi_remote_addr', $_SERVER['REMOTE_ADDR'] );
|
||||
}
|
||||
|
||||
if ( $source && function_exists( 'relevanssi_validate_source' ) ) {
|
||||
$source = relevanssi_validate_source( $source );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters whether a query should be logged or not.
|
||||
*
|
||||
@@ -68,8 +73,9 @@ function relevanssi_update_log( $query, $hits ) {
|
||||
* @param int $hits The number of hits found.
|
||||
* @param string $user_agent The user agent that made the search.
|
||||
* @param string $ip The IP address the search came from (or empty).
|
||||
* @param string $source The search source identifier.
|
||||
*/
|
||||
$ok_to_log = apply_filters( 'relevanssi_ok_to_log', true, $query, $hits, $user_agent, $ip );
|
||||
$ok_to_log = apply_filters( 'relevanssi_ok_to_log', true, $query, $hits, $user_agent, $ip, $source );
|
||||
if ( $ok_to_log ) {
|
||||
global $wpdb, $relevanssi_variables;
|
||||
|
||||
@@ -83,12 +89,13 @@ function relevanssi_update_log( $query, $hits ) {
|
||||
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
'INSERT INTO ' . $relevanssi_variables['log_table'] . ' (query, hits, user_id, ip, time, session_id) VALUES (%s, %d, %d, %s, NOW(), %s)', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
'INSERT INTO ' . $relevanssi_variables['log_table'] . ' (query, hits, user_id, ip, time, session_id, source) VALUES (%s, %d, %d, %s, NOW(), %s, %s)', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$query,
|
||||
intval( $hits ),
|
||||
$user->ID,
|
||||
$ip,
|
||||
$session_id
|
||||
$session_id,
|
||||
$source
|
||||
)
|
||||
);
|
||||
|
||||
@@ -399,7 +406,7 @@ function relevanssi_delete_query_from_log( string $query ) {
|
||||
$deleted = $wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$relevanssi_variables['log_table']} WHERE query = %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared
|
||||
stripslashes( $query )
|
||||
stripslashes( wp_encode_emoji( $query ) )
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -661,7 +661,8 @@ function relevanssi_do_query( &$query ) {
|
||||
$q,
|
||||
$query
|
||||
);
|
||||
relevanssi_update_log( $query_string, $hits_count );
|
||||
$source = $query->query_vars['rlv_source'] ?? '';
|
||||
relevanssi_update_log( $query_string, $hits_count, $source );
|
||||
}
|
||||
|
||||
$make_excerpts = 'on' === get_option( 'relevanssi_excerpts' ) ? true : false;
|
||||
@@ -1752,15 +1753,15 @@ function relevanssi_compile_common_args( $query ) {
|
||||
$date_query = relevanssi_wp_date_query_from_query_vars( $query );
|
||||
|
||||
$post_type = false;
|
||||
if ( isset( $query->query_vars['post_type'] ) && is_array( $query->query_vars['post_type'] ) ) {
|
||||
$query->query_vars['post_type'] = implode( ',', $query->query_vars['post_type'] );
|
||||
}
|
||||
if ( isset( $query->query_vars['post_type'] ) && 'any' !== $query->query_vars['post_type'] ) {
|
||||
$post_type = $query->query_vars['post_type'];
|
||||
}
|
||||
if ( isset( $query->query_vars['post_types'] ) && 'any' !== $query->query_vars['post_types'] ) {
|
||||
$post_type = $query->query_vars['post_types'];
|
||||
}
|
||||
if ( is_array( $post_type ) ) {
|
||||
$post_type = implode( ',', $post_type );
|
||||
}
|
||||
|
||||
$post_status = false;
|
||||
if ( isset( $query->query_vars['post_status'] ) && 'any' !== $query->query_vars['post_status'] ) {
|
||||
|
||||
@@ -242,7 +242,10 @@ function relevanssi_update_stopwords( $stopwords ) {
|
||||
function relevanssi_delete_term_from_all_posts( $term ) {
|
||||
global $wpdb, $relevanssi_variables;
|
||||
|
||||
if ( function_exists( 'pll_languages_list' ) ) {
|
||||
if ( function_exists( 'pll_languages_list' )
|
||||
&& function_exists( 'relevanssi_get_language_term_taxonomy_id' ) ) {
|
||||
// The Relevanssi function does not exist when this function is run as
|
||||
// part of the Relevanssi install process.
|
||||
$term_id = relevanssi_get_language_term_taxonomy_id(
|
||||
relevanssi_get_current_language()
|
||||
);
|
||||
|
||||
@@ -104,7 +104,7 @@ function relevanssi_indexing_tab() {
|
||||
}
|
||||
|
||||
$this_page = '?page=' . plugin_basename( $relevanssi_variables['file'] );
|
||||
$update_url = wp_nonce_url( $this_page . '&tab=indexing&update_counts=1', 'update_counts' );
|
||||
$update_url = wp_nonce_url( $this_page . '&rlv_tab=indexing&update_counts=1', 'update_counts' );
|
||||
|
||||
?>
|
||||
<div id="indexing_tab">
|
||||
|
||||
@@ -53,11 +53,19 @@ function relevanssi_search_stats() {
|
||||
*/
|
||||
function relevanssi_query_log() {
|
||||
global $wpdb, $relevanssi_variables;
|
||||
$data = $wpdb->get_results(
|
||||
'SELECT LEFT( `time`, 10 ) as `day`, count(*) as `count` ' .
|
||||
"FROM {$relevanssi_variables['log_table']} " . // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared
|
||||
'GROUP BY LEFT( `time`, 10 )'
|
||||
);
|
||||
|
||||
$source = '';
|
||||
if ( function_exists( 'relevanssi_validate_source' ) ) {
|
||||
$source = relevanssi_validate_source( $_REQUEST['source'] ?? '' );
|
||||
}
|
||||
|
||||
$data_query = 'SELECT LEFT( `time`, 10 ) as `day`, count(*) as `count` ' .
|
||||
"FROM {$relevanssi_variables['log_table']} ";
|
||||
if ( $source ) {
|
||||
$data_query .= "WHERE source = '$source' ";
|
||||
}
|
||||
$data_query .= 'GROUP BY LEFT( `time`, 10 )';
|
||||
$data = $wpdb->get_results( $data_query ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared
|
||||
|
||||
$labels = array();
|
||||
$values = array();
|
||||
@@ -81,6 +89,10 @@ function relevanssi_query_log() {
|
||||
}
|
||||
}
|
||||
|
||||
$source_select = '';
|
||||
if ( function_exists( 'relevanssi_generate_source_select' ) ) {
|
||||
$source_select = relevanssi_generate_source_select( $source );
|
||||
}
|
||||
?>
|
||||
<form method="post" style="background: white; padding: 10px; margin-top: 20px;">
|
||||
<?php
|
||||
@@ -91,6 +103,8 @@ function relevanssi_query_log() {
|
||||
<?php echo esc_html__( 'From:', 'relevanssi' ); ?> <input type="date" name="from" value="<?php echo esc_attr( $from ); ?>" />
|
||||
<?php echo esc_html__( 'To:', 'relevanssi' ); ?> <input type="date" name="to" value="<?php echo esc_attr( $to ); ?>" />
|
||||
<input type="submit" value="<?php echo esc_attr( __( 'Filter', 'relevanssi' ) ); ?>" /></p>
|
||||
|
||||
<?php echo $source_select; ?>
|
||||
</div>
|
||||
<div>
|
||||
<input type="submit" value="<?php echo esc_attr( __( 'Year so far', 'relevanssi' ) ); ?>" name="this_year" style="margin-bottom: 10px" />
|
||||
@@ -113,7 +127,7 @@ function relevanssi_query_log() {
|
||||
)
|
||||
);
|
||||
|
||||
$total_queries = relevanssi_total_queries( $from, $to );
|
||||
$total_queries = relevanssi_total_queries( $from, $to, $source );
|
||||
?>
|
||||
<div style="background: white; padding: 10px; display: grid; grid-template-columns: 1fr 2fr 2fr; grid-gap: 20px; margin-top: 20px">
|
||||
<div>
|
||||
@@ -124,12 +138,12 @@ function relevanssi_query_log() {
|
||||
</div>
|
||||
<div style="margin-bottom: 20px"><?php esc_html_e( 'Searches that found nothing', 'relevanssi' ); ?>
|
||||
<span style="display: block; font-size: 42px; font-weight: bolder; line-height: 50px">
|
||||
<?php echo intval( relevanssi_nothing_found_queries( $from, $to ) ); ?>
|
||||
<?php echo intval( relevanssi_nothing_found_queries( $from, $to, $source ) ); ?>
|
||||
</span>
|
||||
</div>
|
||||
<?php
|
||||
if ( function_exists( 'relevanssi_user_searches_clicks' ) ) {
|
||||
relevanssi_user_searches_clicks( $from, $to, $total_queries );
|
||||
relevanssi_user_searches_clicks( $from, $to, $total_queries, $source );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
@@ -146,13 +160,13 @@ function relevanssi_query_log() {
|
||||
<p><?php esc_html_e( 'In order to see the clicks, you need to enable click tracking. Click tracking is not currently enabled, and you\'re not collecting new clicks.', 'relevanssi' ); ?></p>
|
||||
<?php
|
||||
}
|
||||
relevanssi_date_queries( $from, $to, 'good' );
|
||||
relevanssi_date_queries( $from, $to, 'good', $source );
|
||||
?>
|
||||
</div>
|
||||
<div>
|
||||
<h3><?php esc_html_e( 'Unsuccessful searches', 'relevanssi' ); ?></h3>
|
||||
<p><?php esc_html_e( 'These queries have found no results.', 'relevanssi' ); ?></p>
|
||||
<?php relevanssi_date_queries( $from, $to, 'bad' ); ?>
|
||||
<?php relevanssi_date_queries( $from, $to, 'bad', $source ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
@@ -196,24 +210,37 @@ function relevanssi_query_log() {
|
||||
* @global object $wpdb The WP database interface.
|
||||
* @global array $relevanssi_variables The global Relevanssi variables array.
|
||||
*
|
||||
* @param string $from The start date.
|
||||
* @param string $to The end date.
|
||||
* @param string $from The start date.
|
||||
* @param string $to The end date.
|
||||
* @param string $source The search source.
|
||||
*
|
||||
* @return int The number of searches.
|
||||
*/
|
||||
function relevanssi_total_queries( string $from, string $to ) {
|
||||
function relevanssi_total_queries( string $from, string $to, string $source ) {
|
||||
global $wpdb, $relevanssi_variables;
|
||||
$log_table = $relevanssi_variables['log_table'];
|
||||
|
||||
$count = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
if ( ! $source ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(id) FROM $log_table " // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
. 'WHERE time >= %s
|
||||
AND time <= %s',
|
||||
$from . ' 00:00:00',
|
||||
$to . ' 23:59:59'
|
||||
)
|
||||
);
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(id) FROM $log_table " // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
. 'WHERE time >= %s
|
||||
AND time <= %s
|
||||
AND source = %s',
|
||||
$from . ' 00:00:00',
|
||||
$to . ' 23:59:59',
|
||||
$source
|
||||
);
|
||||
}
|
||||
|
||||
$count = $wpdb->get_var( $query );
|
||||
|
||||
return $count;
|
||||
}
|
||||
@@ -224,23 +251,37 @@ function relevanssi_total_queries( string $from, string $to ) {
|
||||
* @global object $wpdb The WP database interface.
|
||||
* @global array $relevanssi_variables The global Relevanssi variables array.
|
||||
*
|
||||
* @param string $from The start date.
|
||||
* @param string $to The end date.
|
||||
* @param string $from The start date.
|
||||
* @param string $to The end date.
|
||||
* @param string $source The search source.
|
||||
*/
|
||||
function relevanssi_nothing_found_queries( string $from, string $to ) {
|
||||
function relevanssi_nothing_found_queries( string $from, string $to, string $source ) {
|
||||
global $wpdb, $relevanssi_variables;
|
||||
$log_table = $relevanssi_variables['log_table'];
|
||||
|
||||
$count = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
if ( ! $source ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(id) FROM $log_table " // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
. 'WHERE time >= %s
|
||||
AND time <= %s
|
||||
AND hits = 0',
|
||||
$from . ' 00:00:00',
|
||||
$to . ' 23:59:59'
|
||||
)
|
||||
);
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(id) FROM $log_table " // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
. 'WHERE time >= %s
|
||||
AND time <= %s
|
||||
AND hits = 0
|
||||
AND source = %s',
|
||||
$from . ' 00:00:00',
|
||||
$to . ' 23:59:59',
|
||||
$source
|
||||
);
|
||||
}
|
||||
|
||||
$count = $wpdb->get_var( $query );
|
||||
|
||||
return $count;
|
||||
}
|
||||
@@ -255,8 +296,9 @@ function relevanssi_nothing_found_queries( string $from, string $to ) {
|
||||
* @param string $to The ending date.
|
||||
* @param string $version If 'good', show the searches that found something; if
|
||||
* 'bad', show the searches that didn't find anything. Default 'good'.
|
||||
* @param string $source The source identifier, default ''.
|
||||
*/
|
||||
function relevanssi_date_queries( string $from, string $to, string $version = 'good' ) {
|
||||
function relevanssi_date_queries( string $from, string $to, string $version = 'good', string $source = '' ) {
|
||||
global $wpdb, $relevanssi_variables;
|
||||
$log_table = $relevanssi_variables['log_table'];
|
||||
|
||||
@@ -268,8 +310,8 @@ function relevanssi_date_queries( string $from, string $to, string $version = 'g
|
||||
$limit = apply_filters( 'relevanssi_user_searches_limit', 100 );
|
||||
|
||||
if ( 'good' === $version ) {
|
||||
$queries = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
if ( ! $source ) {
|
||||
$query = $wpdb->prepare(
|
||||
'SELECT COUNT(DISTINCT(id)) as cnt, query, AVG(hits) AS hits ' .
|
||||
"FROM $log_table " . // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
'WHERE time >= %s
|
||||
@@ -281,13 +323,30 @@ function relevanssi_date_queries( string $from, string $to, string $version = 'g
|
||||
$from . ' 00:00:00',
|
||||
$to . ' 23:59:59',
|
||||
$limit
|
||||
)
|
||||
);
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
'SELECT COUNT(DISTINCT(id)) as cnt, query, AVG(hits) AS hits ' .
|
||||
"FROM $log_table " . // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
'WHERE time >= %s
|
||||
AND time <= %s
|
||||
AND hits > 0
|
||||
AND source = %s
|
||||
GROUP BY query
|
||||
ORDER BY cnt DESC
|
||||
LIMIT %d',
|
||||
$from . ' 00:00:00',
|
||||
$to . ' 23:59:59',
|
||||
$source,
|
||||
$limit
|
||||
);
|
||||
}
|
||||
$queries = $wpdb->get_results( $query );
|
||||
}
|
||||
|
||||
if ( 'bad' === $version ) {
|
||||
$queries = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
if ( ! $source ) {
|
||||
$query = $wpdb->prepare(
|
||||
'SELECT COUNT(DISTINCT(id)) as cnt, query, hits ' .
|
||||
"FROM $log_table " . // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
'WHERE time >= %s
|
||||
@@ -299,8 +358,25 @@ function relevanssi_date_queries( string $from, string $to, string $version = 'g
|
||||
$from . ' 00:00:00',
|
||||
$to . ' 23:59:59',
|
||||
$limit
|
||||
)
|
||||
);
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
'SELECT COUNT(DISTINCT(id)) as cnt, query, hits ' .
|
||||
"FROM $log_table " . // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
'WHERE time >= %s
|
||||
AND time <= %s
|
||||
AND hits = 0
|
||||
AND source = %s
|
||||
GROUP BY query
|
||||
ORDER BY cnt DESC
|
||||
LIMIT %d',
|
||||
$from . ' 00:00:00',
|
||||
$to . ' 23:59:59',
|
||||
$source,
|
||||
$limit
|
||||
);
|
||||
}
|
||||
$queries = $wpdb->get_results( $query );
|
||||
}
|
||||
|
||||
if ( count( $queries ) > 0 ) {
|
||||
|
||||
@@ -793,7 +793,14 @@ function relevanssi_is_multiple_words( string $str ): bool {
|
||||
if ( empty( $str ) ) {
|
||||
return false;
|
||||
}
|
||||
$punctuation = get_option( 'relevanssi_punctuation' );
|
||||
$punctuation = get_option(
|
||||
'relevanssi_punctuation',
|
||||
array(
|
||||
'quotes' => 'replace',
|
||||
'hyphens' => 'replace',
|
||||
'ampersands' => 'replace',
|
||||
)
|
||||
);
|
||||
if ( 'replace' === $punctuation['hyphens'] ) {
|
||||
$str = str_replace(
|
||||
array(
|
||||
|
||||
Reference in New Issue
Block a user