PHP Class Hookr, hookr-plugin

Inheritance: extends Hookr_Plugin
Mostrar archivo Open project: explodybits/hookr-plugin

Protected Properties

Property Type Description
$abort
$actions
$buffer
$comments
$context
$error
$hooks
$scripts
$settings
$visible

Public Methods

Method Description
abort ( mixed $mixed ) : mixed Abort hook callback.
activate ( ) : void Activate hook callback.
ajax ( ) Ajax entrypoint
buffer ( string $buffer ) : string Output buffer callback.
error ( mixed $mixed ) : mixed Error callback.
get_file ( ) : string Returns the plugin entry-point.
get_render ( string $tpl, array $data = [] ) : string Renders & returns a template file.
init ( ) : object Plugin init.
load ( ) : void Load hook callback.
loaded ( ) : void Loaded hook callback.
post_filter_buffer ( string $buffer ) : string Post-filter buffer for any last-chance changes.
register_actions ( $actions ) : void Registers the plugin actions.
register_menu ( object $wp_admin_bar ) : void Registers the admin bar menu.
register_page ( ) : void Registers the admin options page.
register_scripts ( ) : void Registers the JS assets.
register_settings ( ) : void Registers the plugin settings.
register_styles ( ) : void Registers the CSS assets.
set_context_footer ( ) : void Sets the runtime context to "footer"
set_context_header ( ) : void Sets the runtime context to "header"
set_context_limbo ( ) : void Sets the runtime context to "middle" (eventually)
set_context_middle ( $mixed = null ) : void Sets the runtime context to "middle"
settings_fields ( ) : string Renders the fields for use on the plugin options page.
settings_page ( ) : void. Renders the plugin options page.
settings_validate ( array $args ) : array Validates the settings posted from the plugin options page.
track_hook ( ) : void Echos (if applicable) the hook's tag & stores instance.

Protected Methods

Method Description
__construct ( )
_filter_wildcard ( array $array ) : array Utility method to filter wildcard tags.
ajax_detail ( ) : string Ajax callback for hook details.
ajax_enable ( ) : string Ajax callback for enabling/disabling
clear_cache ( $force = false ) : void Clears the cache.
create_hook ( string $tag, array $args = [] ) : stdClass Creates a generic hook instance.
create_key ( integer $index, char $char = 'h' ) : string Converts index key to '__h00001' (raw) format.
create_node ( DOMNode | string $node, string $value = '' ) : DOMElement Creates a new DOMElement.
decode_keys ( string $keys ) : array Decodes string of keys into array.
encode_keys ( array $keys ) : string Encodes an array of keys into a string.
filter_buffer ( string $buffer ) : string Filters buffer by converting raw keys to inline annotations.
filter_ignore ( DOMDocument $dom, string $buffer ) : string Filters the raw keys from nodes that are not rendered/off-canvas.
filter_keys ( DOMNode $node, integer $type = self::KEY_IGNORE ) : array Returns a list of keys in a specific node.
filter_node ( DOMNode $node ) : void Filters element nodes for actions/filters.
filter_nodes ( DOMNode $node ) Filters nodes for actions/filters.
filter_text ( DOMDocument $dom, string $buffer ) : string Filters the raw keys from text nodes.
get_cache ( null | string $key = null ) : null | json Returns value of the cache.
get_cache_file ( string | null $key = null ) : string Returns the cache filename.
get_child_node ( DOMNode $node, DOMXPath $xpath = null ) : DOMNode Returns the child node to be annotated.
get_hook ( string $key ) : object Returns a hook by key.
get_node_tag ( DOMNode $node ) : string For a parent node, return the child's tag name.
get_request_key ( null | string $key = null ) : string Returns a generic cache key.
get_setting ( string $key, string $val = '' ) : mixed Return a specific setting from the plugin settings object.
get_settings ( ) : object Returns the filters/runtime plugin settings object.
get_settings_default ( ) : object Returns the plugin's default settings.
get_settings_empty ( ) : object Returns an "empty" settings object.
get_settings_raw ( ) : array Returns the "raw" plugin options (unmodified).
get_target_node ( DOMNode $node ) : DOMNode Find the target node to be annotated.
has_key ( string $chunk ) : boolean Returns whether or not a chunk of html/text contains a raw key.
ignore_node ( string $tag ) : boolean Ignore the specific tag?
is_abort ( ) : boolean Should the plugin abort?
is_enabled ( ) : boolean Is the plugin enabled?
is_tag_ignore ( string $tag ) : boolean Should the tag be ignored?
is_tag_watch ( string $tag ) : boolean Is the tag being watched?
is_tools_page ( ) : boolean Is the current request for the plugin options page?
is_update_page ( ) : boolean Is the current request for the update page?
node_add_class ( DOMNode $node, string $class ) : void Add a CSS class to the given node.
node_has_class ( DOMNode $node, string $class ) : boolean Does the given node have CSS class?
parse_key ( string $key ) : integer Converts raw string key into it's index.
parse_keys ( string $chunk ) : array Returns the list of raw keys from a chunk of html/text.
post_filter_body ( DOMDocument $dom ) : void Post-filters with various runtime attributes/element creation.
post_filter_comments ( string $buffer ) : string Post-filters comments within buffer.
post_filter_html ( DOMDocument $dom ) : void Post-filters with various runtime attributes.
post_filter_scripts ( string $buffer ) : string Post-filters scripts within buffer.
pre_filter_body ( string $buffer ) : string Pre-filters raw keys between to .
pre_filter_buffer ( string $buffer ) : string Pre-filter buffer - calls self::pre_filter_* methods.
pre_filter_comments ( string $buffer ) : string Pre-filters comments within buffer.
pre_filter_html ( string $buffer ) : string Pre-filters raw keys from begining of document to .
pre_filter_nodes ( string $buffer ) : string Pre-filters the nodes containing raw keys.
pre_filter_offcanvas ( string $buffer, string $chunk ) : string Pre-filters raw keys from given chunk of html/text.
pre_filter_scripts ( string $buffer ) : string Pre-filters scripts within buffer.
register_hooks ( ) : void Registers the hooks.
set_cache ( mixed $val, null | string $key = null ) : boolean Write a value to the cache.
set_node_attrs ( DOMNode $node, array $attrs = [] ) : void Sets the attributes on a given DOMNode.
strip_keys ( string $buffer ) : string Strip keys
track_visible ( string $tag ) Sets the runtime visibility for the hooks.
unique_keys ( array $keys ) : array Returns a unique raw key list.
unregister_hooks ( ) : void Unregisters the hooks.

Method Details

__construct() protected method

protected __construct ( )

_filter_wildcard() protected method

Utility method to filter wildcard tags.
protected _filter_wildcard ( array $array ) : array
$array array
return array

abort() public method

Abort hook callback.
public abort ( mixed $mixed ) : mixed
$mixed mixed
return mixed

activate() public method

Activate hook callback.
public activate ( ) : void
return void

ajax() public method

Ajax entrypoint
public ajax ( )

ajax_detail() protected method

Ajax callback for hook details.
protected ajax_detail ( ) : string
return string

ajax_enable() protected method

Ajax callback for enabling/disabling
protected ajax_enable ( ) : string
return string

buffer() public method

Output buffer callback.
public buffer ( string $buffer ) : string
$buffer string
return string

clear_cache() protected method

Clears the cache.
protected clear_cache ( $force = false ) : void
return void

create_hook() protected method

Creates a generic hook instance.
protected create_hook ( string $tag, array $args = [] ) : stdClass
$tag string
$args array
return stdClass

create_key() protected method

Converts index key to '__h00001' (raw) format.
protected create_key ( integer $index, char $char = 'h' ) : string
$index integer
$char char
return string

create_node() protected method

Creates a new DOMElement.
protected create_node ( DOMNode | string $node, string $value = '' ) : DOMElement
$node DOMNode | string
$value string
return DOMElement

decode_keys() protected method

Decodes string of keys into array.
protected decode_keys ( string $keys ) : array
$keys string
return array

encode_keys() protected method

Encodes an array of keys into a string.
protected encode_keys ( array $keys ) : string
$keys array
return string

error() public method

Something bad happened... mmmkay?
public error ( mixed $mixed ) : mixed
$mixed mixed
return mixed

filter_buffer() protected method

Filters buffer by converting raw keys to inline annotations.
protected filter_buffer ( string $buffer ) : string
$buffer string
return string

filter_ignore() protected method

Filters the raw keys from nodes that are not rendered/off-canvas.
protected filter_ignore ( DOMDocument $dom, string $buffer ) : string
$dom DOMDocument
$buffer string
return string

filter_keys() protected method

Returns a list of keys in a specific node.
protected filter_keys ( DOMNode $node, integer $type = self::KEY_IGNORE ) : array
$node DOMNode
$type integer
return array List of keys.

filter_node() protected method

Filters element nodes for actions/filters.
protected filter_node ( DOMNode $node ) : void
$node DOMNode
return void

filter_nodes() protected method

Filters nodes for actions/filters.
protected filter_nodes ( DOMNode $node )
$node DOMNode

filter_text() protected method

Filters the raw keys from text nodes.
protected filter_text ( DOMDocument $dom, string $buffer ) : string
$dom DOMDocument
$buffer string
return string

get_cache() protected method

Returns value of the cache.
protected get_cache ( null | string $key = null ) : null | json
$key null | string
return null | json

get_cache_file() protected method

Returns the cache filename.
protected get_cache_file ( string | null $key = null ) : string
$key string | null
return string

get_child_node() protected method

Returns the child node to be annotated.
protected get_child_node ( DOMNode $node, DOMXPath $xpath = null ) : DOMNode
$node DOMNode
$xpath DOMXPath
return DOMNode

get_file() public method

Returns the plugin entry-point.
public get_file ( ) : string
return string

get_hook() protected method

Returns a hook by key.
protected get_hook ( string $key ) : object
$key string
return object

get_node_tag() protected method

For a parent node, return the child's tag name.
protected get_node_tag ( DOMNode $node ) : string
$node DOMNode
return string

get_render() public method

Renders & returns a template file.
public get_render ( string $tpl, array $data = [] ) : string
$tpl string
$data array
return string

get_request_key() protected method

Returns a generic cache key.
protected get_request_key ( null | string $key = null ) : string
$key null | string
return string

get_setting() protected method

Return a specific setting from the plugin settings object.
protected get_setting ( string $key, string $val = '' ) : mixed
$key string
$val string
return mixed The value of the specified key

get_settings() protected method

Returns the filters/runtime plugin settings object.
protected get_settings ( ) : object
return object The plugin settings object.

get_settings_default() protected method

Returns the plugin's default settings.
protected get_settings_default ( ) : object
return object

get_settings_empty() protected method

Returns an "empty" settings object.
protected get_settings_empty ( ) : object
return object The settigs object with empty values.

get_settings_raw() protected method

Returns the "raw" plugin options (unmodified).
protected get_settings_raw ( ) : array
return array Plugin settings

get_target_node() protected method

Find the target node to be annotated.
protected get_target_node ( DOMNode $node ) : DOMNode
$node DOMNode
return DOMNode

has_key() protected method

Returns whether or not a chunk of html/text contains a raw key.
protected has_key ( string $chunk ) : boolean
$chunk string
return boolean

ignore_node() protected method

Ignore the specific tag?
protected ignore_node ( string $tag ) : boolean
$tag string
return boolean

init() static public method

Plugin init.
static public init ( ) : object
return object

is_abort() protected method

Should the plugin abort?
protected is_abort ( ) : boolean
return boolean

is_enabled() protected method

Is the plugin enabled?
protected is_enabled ( ) : boolean
return boolean

is_tag_ignore() protected method

Should the tag be ignored?
protected is_tag_ignore ( string $tag ) : boolean
$tag string
return boolean

is_tag_watch() protected method

Is the tag being watched?
protected is_tag_watch ( string $tag ) : boolean
$tag string
return boolean

is_tools_page() protected method

Is the current request for the plugin options page?
protected is_tools_page ( ) : boolean
return boolean

is_update_page() protected method

Is the current request for the update page?
protected is_update_page ( ) : boolean
return boolean

load() public method

Load hook callback.
public load ( ) : void
return void

loaded() public method

Loaded hook callback.
public loaded ( ) : void
return void

node_add_class() protected method

Add a CSS class to the given node.
protected node_add_class ( DOMNode $node, string $class ) : void
$node DOMNode
$class string
return void

node_has_class() protected method

Does the given node have CSS class?
protected node_has_class ( DOMNode $node, string $class ) : boolean
$node DOMNode
$class string
return boolean

parse_key() protected method

Converts raw string key into it's index.
protected parse_key ( string $key ) : integer
$key string
return integer

parse_keys() protected method

Returns the list of raw keys from a chunk of html/text.
protected parse_keys ( string $chunk ) : array
$chunk string
return array

post_filter_body() protected method

Post-filters with various runtime attributes/element creation.
protected post_filter_body ( DOMDocument $dom ) : void
$dom DOMDocument
return void

post_filter_buffer() public method

Post-filter buffer for any last-chance changes.
public post_filter_buffer ( string $buffer ) : string
$buffer string
return string

post_filter_comments() protected method

Converts raw keys to their original values.
protected post_filter_comments ( string $buffer ) : string
$buffer string
return string

post_filter_html() protected method

Post-filters with various runtime attributes.
protected post_filter_html ( DOMDocument $dom ) : void
$dom DOMDocument
return void

post_filter_scripts() protected method

Converts raw keys to their original values.
protected post_filter_scripts ( string $buffer ) : string
$buffer string
return string

pre_filter_body() protected method

Pre-filters raw keys between to .
protected pre_filter_body ( string $buffer ) : string
$buffer string
return string

pre_filter_buffer() protected method

Pre-filter buffer - calls self::pre_filter_* methods.
See also: pre_filter_html
See also: pre_filter_body
protected pre_filter_buffer ( string $buffer ) : string
$buffer string
return string

pre_filter_comments() protected method

Converts comments to raw key, for later replacement. This is needed because of various conditional comments that will corrupt the output of $dom->saveHTML().
protected pre_filter_comments ( string $buffer ) : string
$buffer string
return string

pre_filter_html() protected method

This is needed to prevent the DOMDocument parser from vomitting. Since Hookr doens't know what context it render's it's keys, pre-filtering is required to prevent corrupted output.
protected pre_filter_html ( string $buffer ) : string
$buffer string
return string

pre_filter_nodes() protected method

Pre-filters the nodes containing raw keys.
protected pre_filter_nodes ( string $buffer ) : string
$buffer string
return string

pre_filter_offcanvas() protected method

Pre-filters raw keys from given chunk of html/text.
See also: pre_filter_html
See also: pre_filter_body
protected pre_filter_offcanvas ( string $buffer, string $chunk ) : string
$buffer string
$chunk string
return string

pre_filter_scripts() protected method

For whatever reason, the DOMDocument object has absolutely terrible performance when it comes to large inline-scripts. To prevent Hookr from lagging too much on the admin side, the "ginormous" scripts have to be removed.
protected pre_filter_scripts ( string $buffer ) : string
$buffer string
return string

register_actions() public method

Registers the plugin actions.
public register_actions ( $actions ) : void
return void

register_hooks() protected method

Registers the hooks.
protected register_hooks ( ) : void
return void

register_menu() public method

Registers the admin bar menu.
public register_menu ( object $wp_admin_bar ) : void
$wp_admin_bar object
return void

register_page() public method

Registers the admin options page.
public register_page ( ) : void
return void

register_scripts() public method

Registers the JS assets.
public register_scripts ( ) : void
return void

register_settings() public method

Registers the plugin settings.
public register_settings ( ) : void
return void

register_styles() public method

Registers the CSS assets.
public register_styles ( ) : void
return void

set_cache() protected method

Write a value to the cache.
protected set_cache ( mixed $val, null | string $key = null ) : boolean
$val mixed
$key null | string
return boolean

set_context_header() public method

Sets the runtime context to "header"
public set_context_header ( ) : void
return void

set_context_limbo() public method

Sets the runtime context to "middle" (eventually)
public set_context_limbo ( ) : void
return void

set_context_middle() public method

Sets the runtime context to "middle"
public set_context_middle ( $mixed = null ) : void
return void

set_node_attrs() protected method

Sets the attributes on a given DOMNode.
protected set_node_attrs ( DOMNode $node, array $attrs = [] ) : void
$node DOMNode
$attrs array
return void

settings_fields() public method

Renders the fields for use on the plugin options page.
See also: self::settings_page()
public settings_fields ( ) : string
return string The pre-rendered markup.

settings_page() public method

Renders the plugin options page.
public settings_page ( ) : void.
return void.

settings_validate() public method

Validates the settings posted from the plugin options page.
public settings_validate ( array $args ) : array
$args array The plugin settings.
return array

strip_keys() protected method

Strip keys
protected strip_keys ( string $buffer ) : string
$buffer string
return string

track_hook() public method

This is really where the magic happens... just sayin'
public track_hook ( ) : void
return void

track_visible() protected method

First, this is an expensive function; it attempts to correctly render hooks based on whether or not they are within the element.
protected track_visible ( string $tag )
$tag string

unique_keys() protected method

Returns a unique raw key list.
protected unique_keys ( array $keys ) : array
$keys array
return array

unregister_hooks() protected method

Unregisters the hooks.
protected unregister_hooks ( ) : void
return void

Property Details

$abort protected_oe property

protected $abort

$actions protected_oe property

protected $actions

$buffer protected_oe property

protected $buffer

$comments protected_oe property

protected $comments

$context protected_oe property

protected $context

$error protected_oe property

protected $error

$hooks protected_oe property

protected $hooks

$scripts protected_oe property

protected $scripts

$settings protected_oe property

protected $settings

$visible protected_oe property

protected $visible