\

Classes

Als Core plugin class
Als_Activator Fired during plugin activation.
Als_Admin_Settings Als_Admin_Settings.
Als_Deactivator Fired during plugin deactivation
Als_General_Settings The main class that displays the general settings tab
Als_i18n Define the internationalization functionality
Als_Loader Register all actions and filters for the plugin.
Als_Search The main search class
Als_Settings_Page Als_Settings_Page.
Als_Settings_results Main class to display the Results page settings tab
Als_Settings_searching Used to display the searching tab of our settings page
PorterStemmer PHP5 Implementation of the Porter Stemmer algorithm. Certain elements were borrowed from the (broken) implementation by Jon Abernathy.
PorterStemmer2 Main class used to stem a word
StringBuilder Builds a standard string from the given word

Constants

ALS__CACHE_DIR

ALS__CACHE_DIR

ALS__PLUGIN_DIR

ALS__PLUGIN_DIR

ALS_SEARCH_RESULTS

ALS_SEARCH_RESULTS

Functions

activate_als()

activate_als() 

The code that runs during plugin activation.

This action is documented in includes/class-als-activator.php

als_add_listings_columns()

als_add_listings_columns(  $columns) : boolean

Filter to add more columns on listings overview page

Parameters

$columns

Returns

boolean

als_add_meta_box()

als_add_meta_box() 

Creates the url meta box

als_admin_scripts()

als_admin_scripts(  $page) : null

Registers js and css that is used on the admin page And localises our js with search statistics info

Parameters

$page

This is the name of the current page being displayed

Returns

null

als_ajax_results()

als_ajax_results() 

Handles ajax requests for live search and ajax search First checks if there is a cached version before fetching the results

als_clean()

als_clean(string|array  $var) : string|array

Clean variables using sanitize_text_field.

Parameters

string|array $var

text to be cleaned

Returns

string|array

als_crawl_results()

als_crawl_results(  $q = false) : null

Crawls the homepage for results

Parameters

$q

The query to crawl for

Returns

null

als_custom_columns()

als_custom_columns(  $column,   $post_id) 

Runs on the sponsored listings overview page Basically, we just output a new field to show the link of each sponsored result

Parameters

$column

the column being displayed, in this case 'url'

$post_id

id of the post being displayed

als_custom_post_types()

als_custom_post_types() 

Registers a new post type named sponsored results

als_database_suggest()

als_database_suggest(  $q = '',   $count = 5) : array

Fetch query suggestions from the database

Parameters

$q

the user query that should be used to fetch suggestions

$count

the number of suggestions to fetch

Returns

array

als_date_diff()

als_date_diff(  $past,   $current = false) : array

Returns how many seconds/mins/hours/days/weeks/months ago

Parameters

$past

an earlier date

$current

the later date, defaults to now()

Returns

array

als_delete_dir_files()

als_delete_dir_files(  $dir) 

Helper function to recursively delete a directory and it's children

Parameters

$dir

the directory to delete

als_dummy_data()

als_dummy_data() : null

Fills the searches log table with dummy data

Returns

null

als_fetch_posts()

als_fetch_posts(  $post_types,   $limit = 1000000,   $none_indexed = false) 

Fetches all published posts Returns an array of fetched posts ids

Parameters

$post_types

an array of post types to fetch

$limit

maximum number of posts to fetch and an optional integer

$none_indexed

Whether or not to limit the posts to non-indexed posts

als_form_filter()

als_form_filter(  $form) : string

Callback to the get_search_form filter, allows us to edit search forms generated using get_search_form()

Parameters

$form

string The generated markup for the search form

Returns

string —

Markup for the search form

als_frontend_scripts()

als_frontend_scripts() 

Registers js and css that is used on the admin page And localises our js with user options for ajax and live search

als_general_index_more()

als_general_index_more() 

Displays the index more details

als_get_search_results()

als_get_search_results(  $q) : array

Searches for posts matching the current request

Parameters

$q

the user query that should be used to fetch results

Returns

array

als_get_suggestions()

als_get_suggestions() 

Handles the ajax requests for search suggestions

als_get_terms()

als_get_terms(  $content,   $weight = 1.5,   $tokens = array(),   $count = false) : array

Converts a string into an array of words

Parameters

$content

string to be converted

$weight

the weight to assign each word

$tokens

an optional array of existing tokens that should be added to the extracted terms

$count

the total count of words used when calculating tf, df and idf

Returns

array —

of words ... array['example']=array('tf','relevance'); where tf = term frequence = no. of appearence / total no of terms relevance is calculated using the option weight parameter, tf and appearance position in the document

relevance = log(zoneX weight tf)

als_google_suggest()

als_google_suggest(  $q = '',   $count = 5) : array

Fetch query suggestions from the google api

Parameters

$q

the user query that should be used to fetch suggestions

$count

the number of suggestions to fetch

Returns

array

als_has_authors()

als_has_authors(  $s = false) : \array/false

Checks if their is any user matching the current search term

Parameters

$s

the search term defaults to $_GET['s'];

Returns

\array/false

als_has_cache()

als_has_cache() 

Returns true if the user has enabled caching And the current request has been cached before

als_help_tip()

als_help_tip(string  $tip, boolean  $allow_html = false) : string

Display an als help tip.

Parameters

string $tip

Help tip text

boolean $allow_html

Allow sanitized HTML if true or escape

Returns

string

als_index_new()

als_index_new() 

Indexes 100 non indexed posts

als_index_post_types()

als_index_post_types(  $types) : array

Filters indexable post types

Parameters

$types

an array of current post types

Returns

array

als_indexed_count()

als_indexed_count() 

returns the number of total indexable posts

als_post_types()

als_post_types(  $array = false) : \array/string

Fetches the registered post types with the exclusion of sponsored_results

Parameters

$array

whether to return an array or string. Set true to return an array

Returns

\array/string

als_pre_get_posts()

als_pre_get_posts(  $query) 

Runs before the WP_Query class fetches posts First we check if its the main query of a search page Then fetch the posts containing the query And pass their ids to WP_Query

Parameters

$query

the query that is currently being accessed

als_publish_post()

als_publish_post(  $id,   $post) 

Runs whenever a post is published If it's an aautosave request or the post is not published, Or it's not in one of the indexable post types, we do nothing Otherwise, we add it to the index and then clear the cache

Parameters

$id

The id of the post being saved

$post

The global post object of the current post

als_remove_post()

als_remove_post(  $id) : \$id

Removes a single post from the index

Parameters

$id

int id of the post to eliminate

Returns

\$id —

int id of removed post

als_remove_punct()

als_remove_punct(  $a,   $preserve_basics = false) : \modified

Removes all punctuations from a string

Parameters

$a
$preserve_basics

whether or not to preserve basic punctuations like fullstops and comas

Returns

\modified —

string

als_results_vs_no_results()

als_results_vs_no_results() : array

Fetches details of searches that have/lack results

Returns

array

als_save_meta_box()

als_save_meta_box(  $post_id) 

An action hook that runs every time a new post is being saved

We do a couple of security checks then save the url field in the posts meta table

Parameters

$post_id

The post id of the post being saved

als_search_conditions()

als_search_conditions(  $conditions) : array

Filter to add extra search conditions

Parameters

$conditions

array An array of existing conditions

Returns

array —

an array of the modified conditions

als_search_template()

als_search_template(  $search_template) : string

Filter to change the search page template

Parameters

$search_template

string The path to the original template

Returns

string —

The path to our custom template

als_searches_per_month()

als_searches_per_month() : array

Fetches details of searches from the last 30 days

Returns

array

als_searches_this_week()

als_searches_this_week() : array

Fetches details of searches from the last 7 days

Returns

array

als_searches_today()

als_searches_today() : array

Fetches a list of searches that have been made today

Returns

array

als_should_cache()

als_should_cache() 

Returns true if the user has enabled caching

als_show_authors()

als_show_authors(  $users = false) : \null/bool

outputs the users provided by the $users param

Parameters

$users

an array of user objects

Returns

\null/bool

als_show_cache()

als_show_cache(  $echo = true) 

Echoes or returns a cached version of the current request

Parameters

$echo

whether to echo or return the cache

als_show_meta_box()

als_show_meta_box(  $post) 

Runs when the user is adding a sponsored result It outputs a text box that allows him/her to add a url for the sponsored result

Parameters

$post

The post object of a specific post being displayed

als_single_index()

als_single_index(  $id,   $delete = true) 

Indexes the post containing the published id

Parameters

$id

id of the post to index

$delete

whether or not to remove it from the index first before indexing it again

als_snippet()

als_snippet(  $content,   $s = false) : array

Returns the snippet that is shown in the search results page with optional highliting

Parameters

$content

the text to use for generating the snippet

$s

the search string to highlight

Returns

array

als_sponsored_posts()

als_sponsored_posts(  $s = false) : boolean

Fetches sponsored posts that match the current request

Parameters

$s

The query to crawl for

Returns

boolean

als_total_indexable()

als_total_indexable() 

returns the number of total indexable posts

als_use_custom_search()

als_use_custom_search(  $allow) : boolean

Filter to allow or deny the use of our inbuilt search function

Parameters

$allow

bool

Returns

boolean

als_wp_query()

als_wp_query(  $ids) : \$wpdb

Excutes a query

Parameters

$ids

an array of id's to fetch

Returns

\$wpdb —

object

als_youtube_suggest()

als_youtube_suggest(  $q = '',   $count = 5) : array

Fetch query suggestions from the google->youtube api

Parameters

$q

the user query that should be used to fetch suggestions

$count

the number of suggestions to fetch

Returns

array

deactivate_als()

deactivate_als() 

The code that runs during plugin deactivation.

This action is documented in includes/class-als-deactivator.php

run_als()

run_als() 

Begins execution of the plugin.

Since everything within the plugin is registered via hooks, then kicking off the plugin from this point in the file does not affect the page life cycle.