PHP Class SimpleHistory

Mostra file Open project: bonny/wordpress-simple-history Class Usage Examples

Public Properties

Property Type Description
$gettextLatestTranslations Used to store latest translations used by __() Required to automagically determine orginal text and text domain for calls like this SimpleLogger()->log( __("My translated message") );

Public Methods

Method Description
__construct ( )
addWelcomeLogMessage ( ) Greet users to version 2! Is only called after database has been upgraded, so only on first install (or upgrade).
add_admin_bar_menu_item ( $wp_admin_bar ) Adds a "View history" item/shortcut to the admin bar
add_admin_bar_network_menu_item ( $wp_admin_bar ) Adds a "View history" item/shortcut to the network admin, on blogs where Simple History is installed
add_admin_pages ( ) Add pages (history page and settings page)
add_dashboard_widget ( ) Maybe add a dashboard widget, requires current user to have view history capability and a setting to show dashboard to be set
add_default_settings_tabs ( ) Adds default tabs to settings
add_js_templates ( $hook ) Output JS templated into footer
add_settings ( ) * Add setting sections and settings for the settings page Also maybe save some settings before outputing them
api ( ) Base url is: wp-admin/admin-ajax.php?action=simple_history_api
check_for_upgrade ( ) Check if plugin version have changed, i.e. has been upgraded If upgrade is detected then maybe modify database and so on for that version
clear_log ( ) Removes all items from the log
dashboard_widget_output ( ) Output html for the dashboard widget
does_database_have_data ( ) : boolean Check if the database has data/rows
ends_with ( string $haystack, string $needle ) Returns true if $haystack ends with $needle
enqueue_admin_scripts ( $hook ) Enqueue styles and scripts for Simple History but only to our own pages.
filter_gettext ( $translated_text, $untranslated_text, $domain ) During the load of info for a logger we want to get a reference to the untranslated text too, because that's the version we want to store in the database.
filter_gettext_storeLatestTranslations ( $translation, $text, $domain )
filter_gettext_with_context ( $translated_text, $untranslated_text, $context, $domain ) Store messages with context
filter_option_page_capability ( $capability )
getInstantiatedDropins ( )
getInstantiatedLoggerBySlug ( $slug = "" )
getInstantiatedLoggers ( )
getLogLevelTranslated ( string $loglevel ) : string Return translated loglevel
getLogRowDetailsOutput ( $row )
getLogRowHTMLOutput ( array $oneLogRow, $args ) : string Returns the HTML output for a log row, to be used in the GUI/Activity Feed
getLogRowHeaderOutput ( array $row ) : string Return header output for a log row Uses the getLogRowHeaderOutput of the logger that logged the row with fallback to SimpleLogger if logger is not available
getLogRowPlainTextOutput ( array $row ) : string Return plain text output for a log row Uses the getLogRowPlainTextOutput of the logger that logged the row with fallback to SimpleLogger if logger is not available
getLoggersThatUserCanRead ( integer $user_id = "", string $format = "array" ) : array Check which loggers a user has the right to read and return an array with all loggers they are allowed to read
getSettingsTabs ( )
get_avatar ( string $email, integer $size = '96', string $default = '', string $alt = false ) : string Retrieve the avatar for a user who provided a user ID or email address.
get_cache_incrementor ( $refresh = false ) : string https://www.tollmanz.com/invalidation-schemes/
get_clear_history_interval ( ) : integer How old log entried are allowed to be.
get_instance ( ) : SimpleHistory Get singleton intance
get_num_events_last_n_days ( $period_days = 28 ) Number of rows the last n days
get_num_events_per_day_last_n_days ( $period_days = 28 ) get_num_events_last_n_days
get_pager_size ( ) : integer Gets the pager size, i.e. the number of items to show on each page in the history
get_pager_size_dashboard ( ) : integer Gets the pager size, i.e. the number of items to show on each page in the history
get_unique_events_for_days ( $days = 7 ) Number of unique events the last n days
get_view_history_capability ( ) : string Return capability required to view history = for who will the History page be added
get_view_settings_capability ( ) : string Return capability required to view settings
history_page_output ( ) Output for page with the history
init ( )
is_on_our_own_pages ( $hook = "" )
json_encode ( $value ) Works like json_encode, but adds JSON_PRETTY_PRINT if the current php version supports it i.e. PHP is 5.4.0 or greated
load_dropins ( ) Load built in dropins from all files in /dropins and instantiates them
load_loggers ( ) Load built in loggers from all files in /loggers and instantiates them
load_plugin_textdomain ( ) Load language files.
maybe_purge_db ( ) Runs the purge_db() method sometimes We don't want to call it each time because it performs SQL queries
onAdminFooter ( )
onAdminHead ( )
on_filter_simple_history_log ( $message = null, array $context = null, string $level = "info" ) Log a message
output_quick_stats ( ) Quick stats above the log Uses filter "simple_history/history_page/before_gui" to output its contents
plugin_action_links ( $actions, $b, $c, $d ) Show a link to our settings page on the Plugins -> Installed Plugins screen
purge_db ( ) Removes old entries from the db
registerSettingsTab ( $arr_tab_settings )
register_dropin ( $dropinClassName ) Register an external dropin so Simple History knows about it.
register_logger ( $loggerClassName ) Register an external logger so Simple History knows about it.
setting_show_as_page ( ) : boolean Should simple history be shown as a page Defaults to true
setting_show_on_dashboard ( ) : boolean Get setting if plugin should be visible on dasboard.
settings_field_clear_log ( ) Settings section to clear database
settings_field_number_of_items ( ) Settings field for how many rows/items to show in log on the log page
settings_field_number_of_items_dashboard ( ) Settings field for how many rows/items to show in log on the dashboard
settings_field_where_to_show ( ) Settings field for where to show the log, page or dashboard
settings_output_general ( )
settings_output_log ( )
settings_output_styles_example ( )
settings_page_output ( ) Output HTML for the settings page Called from add_options_page
settings_section_output ( ) Content for section intro. Leave it be, even if empty.
setup_cron ( )
setup_variables ( ) Setup variables and things
testlog_old ( )

Private Methods

Method Description
add_admin_actions ( )
getLogRowSenderImageOutput ( array $row ) : string

Method Details

__construct() public method

public __construct ( )

addWelcomeLogMessage() public method

Not called after only plugin activation.

add_admin_bar_menu_item() public method

Useful because Simple History is something at least the author of this plugin often use on a site :)
Since: 2.7.1
public add_admin_bar_menu_item ( $wp_admin_bar )

add_admin_bar_network_menu_item() public method

Useful because Simple History is something at least the author of this plugin often use on a site :)
Since: 2.7.1
public add_admin_bar_network_menu_item ( $wp_admin_bar )

add_admin_pages() public method

Add pages (history page and settings page)
public add_admin_pages ( )

add_dashboard_widget() public method

Maybe add a dashboard widget, requires current user to have view history capability and a setting to show dashboard to be set

add_default_settings_tabs() public method

Adds default tabs to settings

add_js_templates() public method

Output JS templated into footer
public add_js_templates ( $hook )

add_settings() public method

* Add setting sections and settings for the settings page Also maybe save some settings before outputing them
public add_settings ( )

api() public method

Examples: http://playground-root.ep/wp-admin/admin-ajax.php?action=simple_history_api&posts_per_page=5&paged=1&format=html
public api ( )

check_for_upgrade() public method

Check if plugin version have changed, i.e. has been upgraded If upgrade is detected then maybe modify database and so on for that version
public check_for_upgrade ( )

clear_log() public method

Removes all items from the log
public clear_log ( )

dashboard_widget_output() public method

Output html for the dashboard widget

does_database_have_data() public method

Check if the database has data/rows
Since: 2.1.6
public does_database_have_data ( ) : boolean
return boolean True if database is not empty, false if database is empty = contains no data

ends_with() public static method

Returns true if $haystack ends with $needle
public static ends_with ( string $haystack, string $needle )
$haystack string
$needle string

enqueue_admin_scripts() public method

Only adds scripts to pages where the log is shown or the settings page.
public enqueue_admin_scripts ( $hook )

filter_gettext() public method

During the load of info for a logger we want to get a reference to the untranslated text too, because that's the version we want to store in the database.
public filter_gettext ( $translated_text, $untranslated_text, $domain )

filter_gettext_storeLatestTranslations() public method

public filter_gettext_storeLatestTranslations ( $translation, $text, $domain )

filter_gettext_with_context() public method

Store messages with context
public filter_gettext_with_context ( $translated_text, $untranslated_text, $context, $domain )

filter_option_page_capability() public method

public filter_option_page_capability ( $capability )

getInstantiatedDropins() public method

getInstantiatedLoggerBySlug() public method

public getInstantiatedLoggerBySlug ( $slug = "" )

getInstantiatedLoggers() public method

getLogLevelTranslated() public method

Return translated loglevel
Since: 2.0.14
public getLogLevelTranslated ( string $loglevel ) : string
$loglevel string
return string translated loglevel

getLogRowDetailsOutput() public method

public getLogRowDetailsOutput ( $row )

getLogRowHTMLOutput() public method

Returns the HTML output for a log row, to be used in the GUI/Activity Feed
public getLogRowHTMLOutput ( array $oneLogRow, $args ) : string
$oneLogRow array SimpleHistoryLogQuery array with data from SimpleHistoryLogQuery
return string

getLogRowHeaderOutput() public method

Loggers are discouraged to override this in the loggers, because the output should be the same for all items in the gui
public getLogRowHeaderOutput ( array $row ) : string
$row array
return string

getLogRowPlainTextOutput() public method

Return plain text output for a log row Uses the getLogRowPlainTextOutput of the logger that logged the row with fallback to SimpleLogger if logger is not available
public getLogRowPlainTextOutput ( array $row ) : string
$row array
return string

getLoggersThatUserCanRead() public method

Check which loggers a user has the right to read and return an array with all loggers they are allowed to read
public getLoggersThatUserCanRead ( integer $user_id = "", string $format = "array" ) : array
$user_id integer Id of user to get loggers for. Defaults to current user id.
$format string format to return loggers in. Default is array. Can also be "sql"
return array

getSettingsTabs() public method

public getSettingsTabs ( )

get_avatar() public method

A modified version of the function that comes with WordPress, but we want to allow/show gravatars even if they are disabled in discussion settings
Since: 2.0
public get_avatar ( string $email, integer $size = '96', string $default = '', string $alt = false ) : string
$email string email address
$size integer Size of the avatar image
$default string URL to a default image to use if no avatar is available
$alt string Alternative text to use in image tag. Defaults to blank
return string tag for the user's avatar

get_cache_incrementor() public static method

https://www.tollmanz.com/invalidation-schemes/
public static get_cache_incrementor ( $refresh = false ) : string
$refresh bool
return string

get_clear_history_interval() public method

0 = don't delete old entries.
public get_clear_history_interval ( ) : integer
return integer Number of days.

get_instance() public static method

Get singleton intance
public static get_instance ( ) : SimpleHistory
return SimpleHistory instance

get_num_events_last_n_days() public method

Number of rows the last n days
public get_num_events_last_n_days ( $period_days = 28 )

get_num_events_per_day_last_n_days() public method

get_num_events_last_n_days
public get_num_events_per_day_last_n_days ( $period_days = 28 )

get_pager_size() public method

Gets the pager size, i.e. the number of items to show on each page in the history
public get_pager_size ( ) : integer
return integer

get_pager_size_dashboard() public method

Gets the pager size, i.e. the number of items to show on each page in the history
Since: 2.12

get_unique_events_for_days() public method

Number of unique events the last n days
public get_unique_events_for_days ( $days = 7 )

get_view_history_capability() public method

Return capability required to view history = for who will the History page be added
Since: 2.1.5
public get_view_history_capability ( ) : string
return string capability

get_view_settings_capability() public method

Return capability required to view settings
Since: 2.1.5
public get_view_settings_capability ( ) : string
return string capability

history_page_output() public method

Output for page with the history
public history_page_output ( )

init() public method

Since: 2.5.2
public init ( )

is_on_our_own_pages() public method

public is_on_our_own_pages ( $hook = "" )

json_encode() public static method

Works like json_encode, but adds JSON_PRETTY_PRINT if the current php version supports it i.e. PHP is 5.4.0 or greated
public static json_encode ( $value )
$value array|object|string|whatever that is json_encode'able

load_dropins() public method

Load built in dropins from all files in /dropins and instantiates them
public load_dropins ( )

load_loggers() public method

Load built in loggers from all files in /loggers and instantiates them
public load_loggers ( )

load_plugin_textdomain() public method

Uses the method described here: http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
Since: 2.0

maybe_purge_db() public method

Runs the purge_db() method sometimes We don't want to call it each time because it performs SQL queries
Since: 2.0.17
public maybe_purge_db ( )

onAdminFooter() public method

public onAdminFooter ( )

onAdminHead() public method

public onAdminHead ( )

on_filter_simple_history_log() public method

Function called when running filter "simple_history_log"
Since: 2.13
public on_filter_simple_history_log ( $message = null, array $context = null, string $level = "info" )
$context array Optional context to add to the logged data
$level string The loglevel. Must be one of the existing ones. Defaults to "info".

output_quick_stats() public method

Quick stats above the log Uses filter "simple_history/history_page/before_gui" to output its contents
public output_quick_stats ( )

purge_db() public method

Removes old entries from the db
public purge_db ( )

registerSettingsTab() public method

public registerSettingsTab ( $arr_tab_settings )

register_dropin() public method

Does not load the dropin, so file with dropin class must be loaded already. See example-dropin.php for an example on how to use this.
Since: 2.1
public register_dropin ( $dropinClassName )

register_logger() public method

Does not load the logger, so file with logger class must be loaded already. See example-logger.php for an example on how to use this.
Since: 2.1
public register_logger ( $loggerClassName )

setting_show_as_page() public method

Should simple history be shown as a page Defaults to true
public setting_show_as_page ( ) : boolean
return boolean

setting_show_on_dashboard() public method

Defaults to true

settings_field_clear_log() public method

Settings section to clear database

settings_field_number_of_items() public method

Settings field for how many rows/items to show in log on the log page

settings_field_number_of_items_dashboard() public method

Settings field for how many rows/items to show in log on the dashboard

settings_field_where_to_show() public method

Settings field for where to show the log, page or dashboard

settings_output_general() public method

settings_output_log() public method

public settings_output_log ( )

settings_output_styles_example() public method

settings_page_output() public method

Output HTML for the settings page Called from add_options_page

settings_section_output() public method

Called from add_sections_setting.

setup_cron() public method

public setup_cron ( )

setup_variables() public method

Setup variables and things
public setup_variables ( )

testlog_old() public method

public testlog_old ( )

Property Details

$gettextLatestTranslations public_oe property

Used to store latest translations used by __() Required to automagically determine orginal text and text domain for calls like this SimpleLogger()->log( __("My translated message") );
public $gettextLatestTranslations