Util

Util is a plugin for blaze which is based on the idea to have a little helper for simple but annoying tasks. It provides you with currently 24 methods to help you out when you are in a hurry.

Like any plugin, blaze makes the plugin available by its name. If you have installed and activated the plugin, you would be able to use the following methods:

Dump

    $blaze->util->dump($variable);

->dump() is a better alternative to var_dump(). It puts out a cool and clean overview over the provided $variable, placed within <pre> tags. You may input whatever you want to.

Array Functions

    $blaze->util->arrayFirst($array);

This method will return the first element of $array.

    $blaze->util->arrayFirstKey($array);

This method will return the key of the first element of $array.

    $blaze->util->arrayLast($array);

This method will return the last element of $array.

    $blaze->util->arrayLastKey($array);

This method will return the key of the last element of $array.

String functions

    $blaze->util->linkify($string);

->linkify() will search for any urls that might be hidden in $string and turn them into clickable hyperlinks.

Returns $string with clickable links.

    $blaze->util->slugify($string);

Generates a string safe for use in URLs from any given string by replacing anything that could cause problems.

Returns the safe $string.

    $blaze->util->makeQuerySafe($variable);

A wrapper for mysql_real_escape_string() with the ability to pass arrays to it. It will make all values safe to use in MySQL queries and return the cleaned $variable.

    $blaze->util->truncateChars(string $string, $maxlength, $replace = '...', $tolerance = 3);

Advanced truncating function with some options. It tries to truncate a string after a number of chars while searching for possible breakpoints nearby. This way, you should not see any badly broken word. If you do not provide $replace and/or $tolerance, the function will use the defaults you see above. Returns the truncated $string.

Try to play around with $tolerance if you don't like your results.

    $blaze->util->truncateWords($string, $maxwords, $replace = '...');

Another truncating function. This one will look for a number of words you provide, and truncate the string after those. If the string is shorter, there will not be of course any truncating.

Returns the truncated $string.

    $blaze->util->generatePassword($length);

This method generates a random string with password characteristics (No 0 and O, no 1 and I) with a given $length.

Web functions

    $blaze->util->validateEmail($email);

Returns a boolean true if $email is a valid email address. Else it will return false.

    $blaze->util->callUrl($url);

This method tries to call $url via curl. You may get an error if curl is not installed.

It should return the response of that request as string.

    $blaze->util->callJSON($url);

Tries to call $url via curl and will return the JSON decoded result if possible.

false if the response wasn't proper JSON.

    $blaze->util->callXML($url);

Tries to call $url via curl and will return the decoded XML result as object if possible.

false if the response wasn't proper XML.

    $blaze->util->getGravatar($email, $size = 32);

->getGravatar()will return the gravatar for $email. If you provide a $size, it will be that big. If not, it will be 32 pixels in width and height.

Returns the web path to the gravatar which could then be used as value for the src attribute.

    $blaze->util->getTweets($url = null);

Returns tweet count from Twitter api for the specified $url (called via curl). If no url is provided, the currently visited one will be assumed.

    $blaze->util->getFacebookStats($url = null);

Returns Facebook stats for the specified $url (called via curl). If no url is provided, the currently visited one will be assumed.

Special functions

    $blaze->util->calculateDistance($lat1, $long1, $lat2, $long2);

Calculates the distance between two points on earth. It needs four parameters, all four must be float values: $lat1 and $long1 should be latitude and longitude for point 1, $lat2 and $long2 the same for point 2.

The method will return an array holding the distance in miles, feet, yards, kilometers and meters.

System functions

    $blaze->util->sendMailToAdmin($body, $subject = '');

Allows you to send an email to the system admin whitch has been setup in blaze's main configuration. It needs $body as string, $subject is omissible but also string.

    $blaze->util->getCalledPath();

Returns the currently requested path without the domain as string.

    $blaze->util->getCurrentDomain();

Returns the currently requested host (domain) as string.

    $blaze->util->getCurrentDomainWithProtocol();

Returns the currently requested domain with protocol and path as string.