Recent

Helpersclass

Helpers

Static utility helpers used throughout Better Search.

Namespace: WebberZone\Better_Search\Util
Since: 3.3.0
Source: includes/util/class-helpers.php line 21

Methods

__construct()

Constructor class.

Since: 3.3.0
Line: 28

public function __construct(  );

get_bsearch_table() static

Function to delete all rows in the posts table.

Since: 3.3.0
Line: 38

static public function get_bsearch_table( $daily = ... );
Type Name Description
bool $daily Daily flag.

clean_terms() static

Clean search string from XSS exploits.

Since: 3.3.0
Line: 56

static public function clean_terms( $val ): string;
Type Name Description
string $val Potentially unclean string.

Returns: string — Cleaned string if successful or empty string on use of banned word

rand_censor() static

Generates a random string.

Since: 3.3.0
Line: 149

static public function rand_censor( $chars, $len ): string;
Type Name Description
string $chars Chars that can be used.
int $len Length of the output string.

Returns: string — Random string

censor_string() static

Apply censorship to $message, replacing $badwords with $censor_char.

Since: 3.3.0
Line: 172

static public function censor_string( $message, $badwords, $censor_char = ..., $whole_words = ... ): array;
Type Name Description
string $message String to be censored.
array $badwords Array of badwords. Use * to match any run of letters or digits.
string $censor_char String which replaces bad words. If it’s more than 1-char long, a random string will be generated from these chars. Default: ‘*’.
bool $whole_words Filter whole worlds only.

Returns: array — Array containing the original string at orig and the censored string at clean.

html2rgb() static

Convert Hexadecimal colour code to RGB.

Since: 3.3.0
Line: 255

static public function html2rgb( $color ): array|bool;
Type Name Description
string $color Hexadecimal colour.

Returns: array|bool — Array containing RGB colour code or false if error.

rgb2html() static

Function to convert RGB color code to Hexadecimal.

Since: 1.3.4
Line: 296

static public function rgb2html( $r, $g = ..., $b = ..., $padhash = ... ): string;
Type Name Description
int|string|array $r Red colour or array of RGB values.
int|string $g (default: -1) Green colour.
int|string $b (default: -1) Blue colour.
bool $padhash Pad # when returning.

Returns: string — HEX color code

get_from_date() static

Retrieve the from date for the query

Since: 3.3.0
Line: 330

static public function get_from_date( $time = ..., $daily_range = ... ): string;
Type Name Description
string $time A date/time string.
int $daily_range Daily range.

Returns: string — From date

number_format_i18n() static

Convert float number to format based on the locale if number_format_count is true.

Since: 3.3.0
Line: 360

static public function number_format_i18n( $number, $decimals = ... ): string;
Type Name Description
float $number The number to convert based on locale.
int $decimals Optional. Precision of the number of decimal places. Default 0.

Returns: string — Converted number in string format.

str_putcsv() static

Convert a string to CSV.

Since: 3.3.0
Line: 391

static public function str_putcsv( $input_array, $delimiter = ..., $enclosure = ..., $terminator = ... ): string;
Type Name Description
array $input_array Input string.
string $delimiter Delimiter.
string $enclosure Enclosure.
string $terminator Terminating string.

Returns: string — CSV string.

Get the link to Better Search homepage.

Since: 3.3.0
Line: 444

static public function get_credit_link(  ): string;

Returns: string — HTML markup.

highlight() static

Highlights search terms in HTML content without affecting tags or attributes.

Since: 3.3.0
Line: 468

static public function highlight( $content, $terms ): string;
Type Name Description
string $content The HTML content to process.
string|array $terms Single term, phrase, or array of terms/phrases to highlight.

Returns: string — The content with highlighted search terms.

score2percent() static

Function to convert the mySQL score to percentage.

Since: 3.3.0
Line: 610

static public function score2percent( $score, $topscore ): string;
Type Name Description
float $score Score for the search result.
float $topscore Score for the most relevant search result.

Returns: string — Score converted to percentage

extract_locations() static

Find the locations of each of the words within the text.

Since: 3.3.0
Line: 640

static public function extract_locations( $words, $fulltext ): array;
Type Name Description
array|string $words Array of words whose location needs to be extracted, or a single word.
string $fulltext Text to search the words in.

Returns: array

extract_start_position() static

Extract the start position of the relevant portion to display.

This is done by looping over each match and finding the smallest distance between two found strings. The idea being that the closer the terms are the better match the snippet would be. When checking for matches we only change the location if there is a better match. The only exception is where we have only two matches in which case we just take the first as will be equally distant.

Since: 3.3.0
Line: 688

static public function extract_start_position( $locations, $padding_before ): int;
Type Name Description
array $locations Array of locations.
int $padding_before Number of characters to include before the first match.

Returns: int — Starting position of the relevant extract.

extract_relevant_excerpt() static

Extract the relevant excerpt for a set of words.

Since: 3.3.0
Line: 727

static public function extract_relevant_excerpt( $words, $fulltext, $excerpt_more = ..., $excerpt_length = ..., $padding_before = ... ): string;
Type Name Description
array|string $words Array of words used to determine the relevant excerpt, or a single word.
string $fulltext Full text to search for the extract.
string $excerpt_more What to append if $text needs to be trimmed. Default ‘…’.
int $excerpt_length Excerpt length in characters.
int $padding_before Number of characters to include before the first match.

Returns: string — Excerpt containing the relevant portion of of the text.

get_wp_search_stopwords() static

Get WordPress’s search stopwords, translated for the site’s locale.

Since: 4.5.0
Line: 764

static public function get_wp_search_stopwords(  ): array;

Returns: array — Stopwords.

strip_stopwords() static

Strip stopwords from text.

Since: 4.2.0
Line: 784

static public function strip_stopwords( $subject = ..., $search = ..., $replace = ... ): string;
Type Name Description
string|array $subject The string or an array with strings to search and replace.
string|array $search Optional. The pattern to search for. It can be either a string or an array with strings.
string|array $replace Optional. The string to replace with. Default empty string.

Returns: string — Processed text with stopwords removed.

parse_wp_query_arguments() static

Parse WP_Query variables to parse comma separated list of IDs and convert them to arrays as needed by WP_Query.

Since: 4.0.0
Line: 830

static public function parse_wp_query_arguments( $query_vars ): array;
Type Name Description
array $query_vars Defined query variables.

Returns: array — Complete query variables with undefined ones filled in empty.

sanitize_args() static

Sanitize args.

Since: 4.1.1
Line: 867

static public function sanitize_args( $args ): array;
Type Name Description
array $args Array of arguments.

Returns: array — Sanitized array of arguments.

get_primary_term() static

Get the primary term for a given post.

Since: 4.2.0
Line: 899

static public function get_primary_term( $post, $term = ..., $return_all = ..., $return_first = ... ): array;
Type Name Description
int|\WP_Post $post Post ID or WP_Post object.
string $term Term name.
bool $return_all Whether to return all terms.
bool $return_first Whether to return the first term.

Returns: array — Primary term object at primary and array of term

is_sqlite() static

Check if the site runs on SQLite rather than MySQL/MariaDB.

Since: 4.5.0
Line: 978

static public function is_sqlite(  ): bool;

Returns: bool — True when the database layer is SQLite.

get_database_compatibility_message() static

Get a message about MySQL/MariaDB compatibility issues.

Since: 4.2.0
Line: 995

static public function get_database_compatibility_message(  ): string;

Returns: string — Message about compatibility or empty string if compatible.