core.php

The Pepperminty Wiki core

Classes

ids Provides an interface to interact with page ids.
page_renderer Renders the HTML page that is sent to the client.

Functions

url_origin()

url_origin(array  $s = false, boolean  $use_forwarded_host = false) : string

Get the actual absolute origin of the request sent by the user.

Parameters

array $s

The $_SERVER variable contents. Defaults to $_SERVER.

boolean $use_forwarded_host

Whether to utilise the X-Forwarded-Host header when calculating the actual origin.

Returns

string —

The actual origin of the user's request.

full_url()

full_url(array  $s = false, boolean  $use_forwarded_host = false) : string

Get the full url, as requested by the client.

Parameters

array $s

The $_SERVER variable. Defaults to $_SERVER.

boolean $use_forwarded_host

Whether to take the X-Forwarded-Host header into account.

Returns

string —

The full url, as requested by the client.

human_filesize()

human_filesize(\number  $bytes, \number  $decimals = 2) : string

Converts a filesize into a human-readable string.

Parameters

\number $bytes

The number of bytes to convert.

\number $decimals

The number of decimal places to preserve.

Returns

string —

A human-readable filesize.

human_time_since()

human_time_since(integer  $time) : string

Calculates the time since a particular timestamp and returns a human-readable result.

Parameters

integer $time

The timestamp to convert.

Returns

string —

The time since the given timestamp as a human-readable string.

human_time()

human_time(integer  $seconds) : string

Renders a given number of seconds as something that humans can understand more easily.

Parameters

integer $seconds

The number of seconds to render.

Returns

string —

The rendered time.

glob_recursive()

glob_recursive(string  $pattern, integer  $flags) : array

A recursive glob() function.

Parameters

string $pattern

The glob pattern to use to find filenames.

integer $flags

The glob flags to use when finding filenames.

Returns

array —

An array of the filepaths that match the given glob.

get_page_parent()

get_page_parent(string  $pagename) : string|boolean

Gets the name of the parent page to the specified page.

Parameters

string $pagename

The child page to get the parent page name for.

Returns

string|boolean

get_subpages()

get_subpages(object  $pageindex, string  $pagename) : object

Gets a list of all the sub pages of the current page.

Parameters

object $pageindex

The pageindex to use to search.

string $pagename

The name of the page to list the sub pages of.

Returns

object —

An object containing all the subpages and their respective distances from the given page name in the pageindex tree.

check_subpage_parents()

check_subpage_parents(  $pagename) 

Makes sure that a subpage's parents exist.

Note this doesn't check the pagename itself.

Parameters

$pagename

The pagename to check.

makepathsafe()

makepathsafe(string  $string) : string

Makes a path safe.

Paths may only contain alphanumeric characters, spaces, underscores, and dashes.

Parameters

string $string

The string to make safe.

Returns

string —

A safe version of the given string.

hide_email()

hide_email(string  $str) : string

Hides an email address from bots by adding random html entities.

Parameters

string $str

The original email address

Returns

string —

The mangled email address.

starts_with()

starts_with(string  $haystack, string  $needle) : boolean

Checks to see if $haystack starts with $needle.

Parameters

string $haystack

The string to search.

string $needle

The string to search for at the beginning of $haystack.

Returns

boolean —

Whether $needle can be found at the beginning of $haystack.

mb_stripos_all()

mb_stripos_all(string  $haystack, string  $needle) : array|false

Case-insensitively finds all occurrences of $needle in $haystack. Handles UTF-8 characters correctly.

Parameters

string $haystack

The string to search.

string $needle

The string to find.

Returns

array|false —

An array of match indices, or false if nothing was found.

startsWith()

startsWith(string  $haystack, string  $needle) : boolean

Tests whether a string starts with a specified substring.

Parameters

string $haystack

The string to check against.

string $needle

The substring to look for.

Returns

boolean —

Whether the string starts with the specified substring.

endsWith()

endsWith(string  $whole, string  $end) : boolean

Tests whether a string ends with a given substring.

Parameters

string $whole

The string to test against.

string $end

The substring test for.

Returns

boolean —

Whether $whole ends in $end.

str_replace_once()

str_replace_once(string  $find, string  $replace, string  $subject) : string

Replaces the first occurrence of $find with $replace.

Parameters

string $find

The string to search for.

string $replace

The string to replace the search string with.

string $subject

The string ot perform the search and replace on.

Returns

string —

The source string after the find and replace has been performed.

system_mime_type_extensions()

system_mime_type_extensions() : array

Returns the system's mime type mappings, considering the first extension listed to be cacnonical.

Returns

array —

An array of mime type mappings.

system_mime_type_extension()

system_mime_type_extension(string  $type) : string

Converts a given mime type to it's associated file extension.

Parameters

string $type

The mime type to convert.

Returns

string —

The extension for the given mime type.

system_extension_mime_types()

system_extension_mime_types() : array

Returns the system MIME type mapping of extensions to MIME types.

Returns

array —

An array mapping file extensions to their associated mime types.

system_extension_mime_type()

system_extension_mime_type(string  $ext) : string

Converts a given file extension to it's associated mime type.

Parameters

string $ext

The extension to convert.

Returns

string —

The mime type associated with the given extension.

accept_contains_mime()

accept_contains_mime(string  $accept_header, string  $mime_type) : boolean

Figures out whether a given http accepts header contains a specified mime type.

Parameters

string $accept_header

The accept header to search.

string $mime_type

The mime type to search for.

Returns

boolean —

Whether the specified mime type was found in the specified accepts header.

stack_trace()

stack_trace(boolean  $log_trace = true, boolean  $full = false) : string

Generates a stack trace.

Parameters

boolean $log_trace

Whether to send the stack trace to the error log.

boolean $full

Whether to output a full description of all the variables involved.

Returns

string —

A string prepresentation of a stack trace.

var_dump_ret()

var_dump_ret(mixed  $var) : string

Calls var_dump() and returns the output.

Parameters

mixed $var

The thing to pass to var_dump().

Returns

string —

The output captured from var_dump().

var_dump_short()

var_dump_short(mixed  $var) : string

Calls var_dump(), shortening the output for various types.

Parameters

mixed $var

The thing to pass to var_dump().

Returns

string —

A shortened version of the var_dump() output.

getallheaders()

getallheaders() 

Polyfill for PHP's native getallheaders() function on platforms that don't have it.

render_timestamp()

render_timestamp(integer  $timestamp) : string

Renders a timestamp in HTML.

Parameters

integer $timestamp

The timestamp to render.

Returns

string —

HTML representing the given timestamp.

render_pagename()

render_pagename(object  $rchange) : string

Renders a page name in HTML.

Parameters

object $rchange

The recent change to render as a page name

Returns

string —

HTML representing the name of the given page.

render_editor()

render_editor(string  $editorName) : string

Renders an editor's or a group of editors name(s) in HTML.

Parameters

string $editorName

The name of the editor to render.

Returns

string —

HTML representing the given editor's name.

save_userdata()

save_userdata() : boolean

Saves the currently logged in uesr's data back to peppermint.json.

Returns

boolean —

Whether the user's data was saved successfully. Returns false if the user isn't logged in.

get_user_pagename()

get_user_pagename(string  $username) : string

Figures out the path to the user page for a given username.

Does not check to make sure the user acutally exists.

Parameters

string $username

The username to get the path to their user page for.

Returns

string —

The path to the given user's page.

extract_user_from_userpage()

extract_user_from_userpage(string  $userPagename) : string

Extracts a username from a user page path.

Parameters

string $userPagename

The suer page path to extract from.

Returns

string —

The name of the user that the user page belongs to.

email_user()

email_user(string  $username, string  $subject, string  $body) : boolean

Sends a plain text email to a user, replacing {username} with the specified username.

Parameters

string $username

The username to send the email to.

string $subject

The subject of the email.

string $body

The body of the email.

Returns

boolean —

Whether the email was sent successfully or not. Currently, this may fail if the user doesn't have a registered email address.

email_users()

email_users(array<mixed,string>  $usernames, string  $subject, string  $body) : integer

Sends a plain text email to a list of users, replacing {username} with each user's name.

Parameters

array<mixed,string> $usernames

A list of usernames to email.

string $subject

The subject of the email.

string $body

The body of the email.

Returns

integer —

The number of emails sent successfully.

register_module()

register_module(array  $moduledata) 

Registers a module.

Parameters

array $moduledata

The module data to register.

module_exists()

module_exists(string  $id) : boolean

Checks to see whether a module with the given id exists.

Parameters

string $id

The id to search for.

Returns

boolean —

Whether a module is currently loaded with the given id.

add_action()

add_action(string  $action_name, \function  $func) 

Registers a new action handler.

Parameters

string $action_name

The action to register.

\function $func

The function to call when the specified action is requested.

has_action()

has_action(string  $action_name) : boolean

Figures out whether a given action is currently registered.

Only guaranteed to be accurate in inside an existing action function

Parameters

string $action_name

The name of the action to search for

Returns

boolean —

Whether an action with the specified name exists.

add_parser()

add_parser(string  $name, \function  $parser_code) 

Registers a new parser.

Parameters

string $name

The name of the new parser to register.

\function $parser_code

The function to register as a new parser.

parse_page_source()

parse_page_source(string  $source) : string

Parses the specified page source using the parser specified in the settings into HTML.

The specified parser may (though it's unilkely) render it to other things.

Parameters

string $source

The source to render.

Returns

string —

The source rendered to HTML.

register_save_preprocessor()

register_save_preprocessor(\function  $func) 

Register a new proprocessor that will be executed just before an edit is saved.

Parameters

\function $func

The function to register.

add_help_section()

add_help_section(string  $index, string  $title, string  $content) 

Adds a new help section to the help page.

Parameters

string $index

The string to index the new section under.

string $title

The title to display above the section.

string $content

The content to display.

statistic_add()

statistic_add(array  $stat_data) 

Registers a statistic calculator against the system.

Parameters

array $stat_data

The statistic object to register.

has_statistic()

has_statistic(string  $stat_id) : boolean

Checks whether a specified statistic has been registered.

Parameters

string $stat_id

The id of the statistic to check the existence of.

Returns

boolean —

Whether the specified statistic has been registered.