\midcom_helper_misc

Miscellaneous helper functions

Summary

Methods
Properties
Constants
random_string()
parse_config()
get_snippet_content_graceful()
get_snippet_content()
include_snippet_php()
preparse()
include_element()
get_mime_icon()
filesize_to_string()
fix_serialization()
find_node_by_component()
get_element_content()
check_page_exists()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

random_string()

random_string(integer  $length, string  $characters) : string

Parameters

integer $length
string $characters

Throws

\InvalidArgumentException

Returns

string

parse_config()

parse_config(string  $data) : array

Turn midcom config files into PHP arrays

Parameters

string $data

The data to parse

Throws

\midcom_error

Returns

array —

The config in array format

get_snippet_content_graceful()

get_snippet_content_graceful(string  $path) : string

This helper function searches for a snippet either in the Filesystem or in the database and returns its content or code-field, respectively.

Prefix the snippet Path with 'file:' for retrieval of a file relative to MIDCOM_ROOT; omit it to get the code field of a Snippet.

Any error (files not found) will return null. If you want to trigger an error, look for midcom_helper_misc::get_snippet_content.

Parameters

string $path

The URL to the snippet.

Returns

string —

The content of the snippet/file.

get_snippet_content()

get_snippet_content(string  $path) : string

This helper function searches for a snippet either in the Filesystem or in the database and returns its content or code-field, respectively.

Prefix the snippet Path with 'file:' for retrieval of a file relative to MIDCOM_ROOT; omit it to get the code field of a Snippet.

Any error (files not found) will raise a MidCOM Error. If you want a more graceful behavior, look for midcom_helper_misc::get_snippet_content_graceful

Parameters

string $path

The URL to the snippet.

Returns

string —

The content of the snippet/file.

include_snippet_php()

include_snippet_php(string  $path) : boolean

Preparse and include snippet

Parameters

string $path

The path of the snippet that should be included.

Returns

boolean —

Returns false if the snippet could not be loaded or true, if it was evaluated successfully.

preparse()

preparse(string  $code) : string

This is a bit of a hack to allow &(); tags

Parameters

string $code

The unprocessed code

Returns

string —

The processed code

include_element()

include_element(  $name) 

Include a theme element

Parameters

$name

get_mime_icon()

get_mime_icon(string  $mimetype) : string

Find MIME type image for a document

Used in midcom.helper.imagepopup, midgard.admin.asgard and org.openpsa.documents.

Parameters

string $mimetype

Document MIME type

Returns

string —

Path to the icon

filesize_to_string()

filesize_to_string(integer  $size) : string

Pretty print file sizes

Parameters

integer $size

File size in bytes

Returns

string —

Prettified file size

fix_serialization()

fix_serialization(string  $data) : string

Fix newline etc encoding issues in serialized data

Parameters

string $data

The data to fix.

Returns

string —

$data with serializations fixed.

find_node_by_component()

find_node_by_component(string  $component, integer  $node_id = null, \midcom_helper_nav  $nap = null) : array

Returns the first instance of a given component on the site.

Parameters

string $component

The component name

integer $node_id

Node ID of parent topic

\midcom_helper_nav $nap

Returns

array —

NAP array of the first component instance found

get_element_content()

get_element_content(string  $element_name, string  $theme_root = OPENPSA2_THEME_ROOT) 

Get the content of the element by the passed element name.

Tries to resolve path according to theme-name & page

Parameters

string $element_name
string $theme_root

check_page_exists()

check_page_exists(string  $page_name, string  $theme_root = OPENPSA2_THEME_ROOT) 

Iterate through possible page directories in style-tree and check if the page exists (as a folder).

Parameters

string $page_name
string $theme_root