Miscellaneous helper functions

package midcom.helper

 Methods

filesize_to_string (int $size)

Helper function for pretty printing file sizes Original from http://www.theukwebdesigncompany.com/articles/php-file-manager.php
Static

Parameters

$size

intFile size in bytes

Returns

stringPrettified file size

find_node_by_component ($component, $node_id, $nap)

This helper function returns the first instance of a given component on the MidCOM site.
Static

Parameters

$component

$node_id

$nap

Returns

arrayNAP array of the first component instance found

fix_serialization (string $data)

Fixes newline etc encoding issues in serialized data
Static

Parameters

$data

stringThe data to fix.

Returns

string$data with serializations fixed.

get_mime_icon (string $mimetype, $fallback)

Helper function for finding MIME type image for a document
Static

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

Parameters

$mimetype

stringDocument MIME type

$fallback

Returns

stringPath to the icon

get_mimetype (string $filename)

Helper function, determines the mime-type of the specified file.
Static

The call uses the "file" utility which must be present for this type to work.

Parameters

$filename

stringThe file to scan

Returns

stringThe autodetected mime-type

get_snippet_content (string $path)

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

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

$path

stringThe URL to the snippet.

Returns

stringThe content of the snippet/file.

get_snippet_content_graceful (string $path)

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

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

$path

stringThe URL to the snippet.

Returns

stringThe content of the snippet/file.

include_element ($name)

Include a theme element
Static

Parameters

$name

include_snippet_php (string $path)

PHP-level implementation of the Midgard Preparser language construct mgd_include_snippet.
Static

Same semantics, but probably a little bit slower.

This function is there as a backup in case you are not running within the Midgard Parser; it will run the snippet code through preparse manually.

Parameters

$path

stringThe path of the snippet that should be included.

Returns

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

parse_config (string $data)

Helper function to turn typical midcom config files into PHP arrays
Static

Parameters

$data

stringThe data to parse

Exceptions

\midcom_error

Returns

arrayThe config in array format

preparse (string $code)

Preparse a string to handle element inclusion and variable
Static

Parameters

$code

stringThe unprocessed code

Returns

stringThe processed code