", esc_html__( 'Clearing the logs failed.', 'relevanssi' ) );
}
}
return $result;
}
/**
* Shows the query log with the most common queries
*
* Uses relevanssi_total_queries() and relevanssi_date_queries() to fetch the data.
*/
function relevanssi_query_log() {
/**
* Adjusts the number of days to show the logs in User searches page.
*
* @param int Number of days, default 1.
*/
$days1 = apply_filters( 'relevanssi_1day', 1 );
/**
* Adjusts the number of days to show the logs in User searches page.
*
* @param int Number of days, default 7.
*/
$days7 = apply_filters( 'relevanssi_7days', 7 );
/**
* Adjusts the number of days to show the logs in User searches page.
*
* @param int Number of days, default 30.
*/
$days30 = apply_filters( 'relevanssi_30days', 30 );
printf( '
', esc_html__( 'Common Queries', 'relevanssi' ) );
/**
* Filters the number of rows to show.
*
* @param int Number of top results to show, default 20.
*/
$limit = apply_filters( 'relevanssi_user_searches_limit', 20 );
// Translators: %d is the number of queries to show.
printf( '
%s
', esc_html( sprintf( __( 'Here you can see the %d most common user search queries, how many times those queries were made and how many results were found for those queries.', 'relevanssi' ), $limit ) ) );
echo "
";
if ( 1 === $days1 ) {
relevanssi_date_queries( $days1, __( 'Today and yesterday', 'relevanssi' ) );
} else {
// Translators: number of days to show.
relevanssi_date_queries( $days1, sprintf( __( 'Last %d days', 'relevanssi' ), $days1 ) );
}
echo '
';
echo "
";
// Translators: number of days to show.
relevanssi_date_queries( $days7, sprintf( __( 'Last %d days', 'relevanssi' ), $days7 ) );
echo '
';
echo "
";
// Translators: number of days to show.
relevanssi_date_queries( $days30, sprintf( __( 'Last %d days', 'relevanssi' ), $days30 ) );
echo '
', esc_html__( 'Reset Logs', 'relevanssi' ) );
print( "',
// Translators: do not translate "reset".
esc_html__(
'To reset the logs, type "reset" into the box here and click the Reset button',
'relevanssi'
),
esc_html__( 'Reset', 'relevanssi' )
);
}
echo '
';
}
/**
* Shows the total number of searches on 'User searches' page.
*
* @global object $wpdb The WP database interface.
* @global array $relevanssi_variables The global Relevanssi variables array.
*
* @param string $title The title that is printed out on top of the results.
*/
function relevanssi_total_queries( $title ) {
global $wpdb, $relevanssi_variables;
$log_table = $relevanssi_variables['log_table'];
$count = array();
$titles = array();
$titles[0] = __( 'Today and yesterday', 'relevanssi' );
$titles[1] = __( 'Last 7 days', 'relevanssi' );
$titles[2] = __( 'Last 30 days', 'relevanssi' );
$titles[3] = __( 'Forever', 'relevanssi' );
$count[0] = $wpdb->get_var( "SELECT COUNT(id) FROM $log_table WHERE TIMESTAMPDIFF(DAY, time, NOW()) <= 1;" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$count[1] = $wpdb->get_var( "SELECT COUNT(id) FROM $log_table WHERE TIMESTAMPDIFF(DAY, time, NOW()) <= 7;" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$count[2] = $wpdb->get_var( "SELECT COUNT(id) FROM $log_table WHERE TIMESTAMPDIFF(DAY, time, NOW()) <= 30;" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$count[3] = $wpdb->get_var( "SELECT COUNT(id) FROM $log_table;" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
printf(
'
';
}
/**
* Shows the most common search queries on different time periods.
*
* @global object $wpdb The WP database interface.
* @global array $relevanssi_variables The global Relevanssi variables array.
*
* @param int $days The number of days to show.
* @param string $title The title that is printed out on top of the results.
* @param string $version If 'good', show the searches that found something; if
* 'bad', show the searches that didn't find anything. Default 'good'.
*/
function relevanssi_date_queries( $days, $title, $version = 'good' ) {
global $wpdb, $relevanssi_variables;
$log_table = $relevanssi_variables['log_table'];
/** Documented in lib/interface.php. */
$limit = apply_filters( 'relevanssi_user_searches_limit', 20 );
if ( 'good' === $version ) {
$queries = $wpdb->get_results(
$wpdb->prepare(
'SELECT COUNT(DISTINCT(id)) as cnt, query, hits ' .
"FROM $log_table " . // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
'WHERE TIMESTAMPDIFF(DAY, time, NOW()) <= %d
GROUP BY query
ORDER BY cnt DESC
LIMIT %d',
$days,
$limit
)
);
}
if ( 'bad' === $version ) {
$queries = $wpdb->get_results(
$wpdb->prepare(
'SELECT COUNT(DISTINCT(id)) as cnt, query, hits ' .
"FROM $log_table " . // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
'WHERE TIMESTAMPDIFF(DAY, time, NOW()) <= %d AND hits = 0
GROUP BY query
ORDER BY cnt DESC
LIMIT %d',
$days,
$limit
)
); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
}
if ( count( $queries ) > 0 ) {
printf(
"
';
}
}
/**
* Returns 'checked' if the option is enabled.
*
* @param string $option Value to check.
*
* @return string If the option is 'on', returns 'checked', otherwise returns an
* empty string.
*/
function relevanssi_check( $option ) {
$checked = '';
if ( 'on' === $option ) {
$checked = 'checked';
}
return $checked;
}
/**
* Returns 'selected' if the option matches a value.
*
* @param string $option Value to check.
* @param string $value The 'selected' value.
*
* @return string If the option matches the value, returns 'selected', otherwise
* returns an empty string.
*/
function relevanssi_select( $option, $value ) {
$selected = '';
if ( $option === $value ) {
$selected = 'selected';
}
return $selected;
}
/**
* Prints out the Relevanssi options form.
*
* @global object $wpdb The WP database interface.
* @global array $relevanssi_variables The global Relevanssi variables array.
*/
function relevanssi_options_form() {
global $relevanssi_variables, $wpdb;
wp_enqueue_style( 'dashboard' );
wp_print_styles( 'dashboard' );
wp_enqueue_script( 'dashboard' );
wp_print_scripts( 'dashboard' );
echo "
";
echo "
__( 'Click OK to copy Relevanssi options to all subsites', 'relevanssi' ),
'confirm_stopwords' => __( 'Are you sure you want to remove all stopwords?', 'relevanssi' ),
'truncating_index' => __( 'Wiping out the index...', 'relevanssi' ),
'done' => __( 'Done.', 'relevanssi' ),
'indexing_users' => __( 'Indexing users...', 'relevanssi' ),
'indexing_taxonomies' => __( 'Indexing the following taxonomies:', 'relevanssi' ),
'indexing_attachments' => __( 'Indexing attachments...', 'relevanssi' ),
'counting_posts' => __( 'Counting posts...', 'relevanssi' ),
'counting_terms' => __( 'Counting taxonomy terms...', 'relevanssi' ),
'counting_users' => __( 'Counting users...', 'relevanssi' ),
'counting_attachments' => __( 'Counting attachments...', 'relevanssi' ),
'posts_found' => __( 'posts found.', 'relevanssi' ),
'terms_found' => __( 'taxonomy terms found.', 'relevanssi' ),
'users_found' => __( 'users found.', 'relevanssi' ),
'attachments_found' => __( 'attachments found.', 'relevanssi' ),
'taxonomy_disabled' => __( 'Taxonomy term indexing is disabled.', 'relevanssi' ),
'user_disabled' => __( 'User indexing is disabled.', 'relevanssi' ),
'indexing_complete' => __( 'Indexing complete.', 'relevanssi' ),
'excluded_posts' => __( 'posts excluded.', 'relevanssi' ),
'options_changed' => __( 'Settings have changed, please save the options before indexing.', 'relevanssi' ),
'reload_state' => __( 'Reload the page to refresh the state of the index.', 'relevanssi' ),
'pdf_reset_confirm' => __( 'Are you sure you want to delete all attachment content from the index?', 'relevanssi' ),
'pdf_reset_done' => __( 'Relevanssi attachment data wiped clean.', 'relevanssi' ),
'pdf_reset_problems' => __( 'There were problems wiping the Relevanssi attachment data clean.', 'relevanssi' ),
'hour' => __( 'hour', 'relevanssi' ),
'hours' => __( 'hours', 'relevanssi' ),
'about' => __( 'about', 'relevanssi' ),
'sixty_min' => __( 'about an hour', 'relevanssi' ),
'ninety_min' => __( 'about an hour and a half', 'relevanssi' ),
'minute' => __( 'minute', 'relevanssi' ),
'minutes' => __( 'minutes', 'relevanssi' ),
'underminute' => __( 'less than a minute', 'relevanssi' ),
'notimeremaining' => __( "we're done!", 'relevanssi' ),
);
wp_localize_script( 'relevanssi_admin_js', 'relevanssi', $localizations );
$nonce = array(
'indexing_nonce' => wp_create_nonce( 'relevanssi_indexing_nonce' ),
'searching_nonce' => wp_create_nonce( 'relevanssi_admin_search_nonce' ),
);
if ( ! RELEVANSSI_PREMIUM ) {
wp_localize_script( 'relevanssi_admin_js', 'nonce', $nonce );
}
/**
* Sets the indexing limit, ie. how many posts are indexed at once.
*
* Relevanssi starts by indexing this many posts at once. If the process
* goes fast enough, Relevanssi will then increase the limit and if the
* process is slow, the limit will be decreased. If necessary, you can
* use the relevanssi_indexing_adjust filter hook to disable that
* adjustment.
*
* @param int The indexing limit, default 10.
*/
$indexing_limit = apply_filters( 'relevanssi_indexing_limit', 10 );
/**
* Sets the indexing adjustment.
*
* Relevanssi will adjust the number of posts indexed at once to speed
* up the process if it goes fast and to slow down, if the posts are
* slow to index. You can use this filter to stop that behaviour, making
* Relevanssi index posts at constant pace. That's generally slower, but
* more reliable.
*
* @param boolean Should the limit be adjusted, default true.
*/
$indexing_adjust = apply_filters( 'relevanssi_indexing_adjust', true );
wp_localize_script(
'relevanssi_admin_js',
'relevanssi_params',
array(
'indexing_limit' => $indexing_limit,
'indexing_adjust' => $indexing_adjust,
)
);
}
/**
* Prints out the form fields for tag and category weights.
*/
function relevanssi_form_tag_weight() {
$taxonomy_weights = get_option( 'relevanssi_post_type_weights' );
$tag_value = 1;
if ( isset( $taxonomy_weights['post_tag'] ) ) {
$tag_value = $taxonomy_weights['post_tag'];
}
$category_value = 1;
if ( isset( $taxonomy_weights['category'] ) ) {
$category_value = $taxonomy_weights['category'];
}
?>