PHP Class Jetpack_RelatedPosts, jetpack

Mostra file Open project: automattic/jetpack Class Usage Examples

Protected Properties

Property Type Description
$_allow_feature_toggle
$_blog_charset
$_blog_id_local
$_blog_id_wpcom
$_convert_charset
$_found_shortcode
$_options
$_previous_post_id

Public Methods

Method Description
__construct ( integer $blog_id_local, integer $blog_id_wpcom ) : null Constructor for Jetpack_RelatedPosts.
action_admin_init ( ) : null Add a checkbox field to Settings > Reading for enabling related posts.
action_frontend_init ( ) Load related posts assets if it's a elegiable front end page or execute search and return JSON if it's an endpoint request.
filter_add_target_to_dom ( string $content ) Adds a target to the post content to load related posts into if a shortcode for it did not already exist.
get_for_post_id ( integer $post_id, array $args ) : array Gets an array of related posts that match the given post_id.
get_options ( ) : array Gets options set for Jetpack_RelatedPosts and merge with defaults.
get_target_html ( ) Returns the HTML for the related posts section.
get_target_html_unsupported ( ) Returns the HTML for the related posts section if it's running in the loop or other instances where we don't support related posts.
init ( ) : Jetpack_RelatedPosts Creates and returns a static instance of Jetpack_RelatedPosts.
init_raw ( ) : Jetpack_RelatedPosts Creates and returns a static instance of Jetpack_RelatedPosts_Raw.
parse_options ( array $input ) : array Parses input and returnes normalized options array.
print_setting_head ( ) Head JS/CSS for admin settings page.
print_setting_html ( ) HTML for admin settings page.
rest_get_related_posts ( array $object, string $field_name, WP_REST_Request $request ) : array Build an array of Related Posts.
rest_register_related_posts ( ) : null Add Related Posts to the REST API Post response.
test_for_shortcode ( string $content ) Looks for our shortcode on the unfiltered content, this has to execute early.

Protected Methods

Method Description
_action_frontend_init_ajax ( array $excludes ) : null Generate and output ajax response for related posts API call.
_action_frontend_init_page ( ) : null Adds filters and enqueues assets.
_allow_feature_toggle ( )
_enabled_for_request ( ) : boolean Determines if the current post is able to use related posts.
_enqueue_assets ( $script, $style ) : null Enqueues assets needed to do async loading of related posts.
_filter_non_public_posts ( array $related_posts ) : array Filter out any hits that are not public anymore.
_generate_related_post_context ( integer $post_id ) : string Generates a context for the related content (second line in related post output).
_generate_related_post_image_params ( integer $post_id ) : string Generates the thumbnail image to be used for the post. Uses the image as returned by Jetpack_PostImages::get_image()
_get_coalesced_range ( array $date_range ) : array Takes a range and coalesces it into a month interval bracketed by a time as determined by the blog_id to enhance caching.
_get_es_filters_from_args ( integer $post_id, array $args ) : array Creates an array of ElasticSearch filters based on the post_id and args.
_get_excerpt ( string $post_excerpt, string $post_content ) : string Returns a plain text post excerpt for title attribute of links.
_get_related_post_data_for_post ( integer $post_id, integer $position, integer $origin ) : array Returns a UTF-8 encoded array of post information for the given post_id
_get_related_post_ids ( integer $post_id, integer $size, array $filters ) : array Get array of related posts matched by ElasticSearch.
_get_related_posts ( integer $post_id, integer $size, array $filters ) : array Workhorse method to return array of related posts matched by ElasticSearch.
_get_title ( string $post_title, string $post_content ) : string Returns either the title or a small excerpt to use as title for post.
_log_click ( $post_id, $to_post_id, $link_position ) : null Logs clicks for clickthrough analysis and related result tuning.
_setup_shortcode ( ) : null Sets up the shortcode processing.
_to_utf8 ( string $text ) : string Returns the string UTF-8 encoded

Method Details

__construct() public method

Constructor for Jetpack_RelatedPosts.
public __construct ( integer $blog_id_local, integer $blog_id_wpcom ) : null
$blog_id_local integer
$blog_id_wpcom integer
return null

_action_frontend_init_ajax() protected method

NOTE: Calls exit() to end all further processing after payload has been outputed.
protected _action_frontend_init_ajax ( array $excludes ) : null
$excludes array array of post_ids to exclude
return null

_action_frontend_init_page() protected method

Adds filters and enqueues assets.
protected _action_frontend_init_page ( ) : null
return null

_allow_feature_toggle() protected method

protected _allow_feature_toggle ( )

_enabled_for_request() protected method

Determines if the current post is able to use related posts.
protected _enabled_for_request ( ) : boolean
return boolean

_enqueue_assets() protected method

Enqueues assets needed to do async loading of related posts.
protected _enqueue_assets ( $script, $style ) : null
return null

_filter_non_public_posts() protected method

Filter out any hits that are not public anymore.
protected _filter_non_public_posts ( array $related_posts ) : array
$related_posts array
return array

_generate_related_post_context() protected method

Order of importance: - First category (Not 'Uncategorized') - First post tag - Number of comments
protected _generate_related_post_context ( integer $post_id ) : string
$post_id integer
return string

_generate_related_post_image_params() protected method

Generates the thumbnail image to be used for the post. Uses the image as returned by Jetpack_PostImages::get_image()
protected _generate_related_post_image_params ( integer $post_id ) : string
$post_id integer
return string

_get_coalesced_range() protected method

Takes a range and coalesces it into a month interval bracketed by a time as determined by the blog_id to enhance caching.
protected _get_coalesced_range ( array $date_range ) : array
$date_range array
return array

_get_es_filters_from_args() protected method

Creates an array of ElasticSearch filters based on the post_id and args.
protected _get_es_filters_from_args ( integer $post_id, array $args ) : array
$post_id integer
$args array
return array

_get_excerpt() protected method

Returns a plain text post excerpt for title attribute of links.
protected _get_excerpt ( string $post_excerpt, string $post_content ) : string
$post_excerpt string
$post_content string
return string

_get_related_post_data_for_post() protected method

Returns a UTF-8 encoded array of post information for the given post_id
protected _get_related_post_data_for_post ( integer $post_id, integer $position, integer $origin ) : array
$post_id integer
$position integer
$origin integer The post id that this is related to
return array

_get_related_post_ids() protected method

Get array of related posts matched by ElasticSearch.
protected _get_related_post_ids ( integer $post_id, integer $size, array $filters ) : array
$post_id integer
$size integer
$filters array
return array

_get_title() protected method

Returns either the title or a small excerpt to use as title for post.
protected _get_title ( string $post_title, string $post_content ) : string
$post_title string
$post_content string
return string

_log_click() protected method

Logs clicks for clickthrough analysis and related result tuning.
protected _log_click ( $post_id, $to_post_id, $link_position ) : null
return null

_setup_shortcode() protected method

Sets up the shortcode processing.
protected _setup_shortcode ( ) : null
return null

_to_utf8() protected method

Returns the string UTF-8 encoded
protected _to_utf8 ( string $text ) : string
$text string
return string

action_admin_init() public method

Add a checkbox field to Settings > Reading for enabling related posts.
public action_admin_init ( ) : null
return null

action_frontend_init() public method

Load related posts assets if it's a elegiable front end page or execute search and return JSON if it's an endpoint request.

filter_add_target_to_dom() public method

Adds a target to the post content to load related posts into if a shortcode for it did not already exist.
public filter_add_target_to_dom ( string $content )
$content string

get_for_post_id() public method

Gets an array of related posts that match the given post_id.
public get_for_post_id ( integer $post_id, array $args ) : array
$post_id integer
$args array - params to use when building ElasticSearch filters to narrow down the search domain.
return array

get_options() public method

Gets options set for Jetpack_RelatedPosts and merge with defaults.
public get_options ( ) : array
return array

get_target_html() public method

Returns the HTML for the related posts section.
public get_target_html ( )

get_target_html_unsupported() public method

Returns the HTML for the related posts section if it's running in the loop or other instances where we don't support related posts.

init() public static method

Creates and returns a static instance of Jetpack_RelatedPosts.
public static init ( ) : Jetpack_RelatedPosts
return Jetpack_RelatedPosts

init_raw() public static method

Creates and returns a static instance of Jetpack_RelatedPosts_Raw.
public static init_raw ( ) : Jetpack_RelatedPosts
return Jetpack_RelatedPosts

parse_options() public method

Parses input and returnes normalized options array.
public parse_options ( array $input ) : array
$input array
return array

print_setting_head() public method

Head JS/CSS for admin settings page.
public print_setting_head ( )

print_setting_html() public method

HTML for admin settings page.
public print_setting_html ( )

test_for_shortcode() public method

Looks for our shortcode on the unfiltered content, this has to execute early.
public test_for_shortcode ( string $content )
$content string

Property Details

$_allow_feature_toggle protected_oe property

protected $_allow_feature_toggle

$_blog_charset protected_oe property

protected $_blog_charset

$_blog_id_local protected_oe property

protected $_blog_id_local

$_blog_id_wpcom protected_oe property

protected $_blog_id_wpcom

$_convert_charset protected_oe property

protected $_convert_charset

$_found_shortcode protected_oe property

protected $_found_shortcode

$_options protected_oe property

protected $_options

$_previous_post_id protected_oe property

protected $_previous_post_id