ZenMagick 0.9.6


org.zenmagick.misc.ZMTools

Class ZMTools

ZMTools

public class ZMTools

(System) Tools.

Author:
DerManoMann
Version:
$Id: ZMTools.php 2231 2009-05-21 04:57:23Z DerManoMann $

Field Summary
final mixed

RANDOM_CHARS

final mixed

RANDOM_DIGITS

final mixed

RANDOM_HEX

final mixed

RANDOM_MIXED

Method Summary
static boolean

asBoolean(mixed value)

Evaluate a string value as boolean.

static boolean

compareStoreUrl(string url1, string url2)

Compare URLs.

static boolean

endsWith(string s, string end)

Check if the given string ends with the provided string.

void

fmod_round(mixed x, mixed y)

fmod variant that can handle values < 1.

static void

ifModifiedSince(string timestamp, boolean true)

Helper for conditional get support.

static boolean

inArray(string value, mixed array)

Check if the given value exists in the array or comma separated list.

static boolean

isEmpty(mixed value)

Check if a given value or array is empty.

static string

mkRssDate(mixed date)

Convert date to RSS date format.

static string

mkUnique(var arg)

Create a unique key from all given parameters.

static boolean

mkdir(string dir, int perms, boolean recursive)

Make directory.

static boolean

move(string src, string target)

Move files and folders.

static string

normalizeFilename(string filename)

Normalize filename.

static array

parseDateString(string s, string format, array defaults)

Parse a date according to the given format.

static float

parseMoney(mixed money, string amount)

Parse a money amount.

static array

parseRange(string range)

Convert a numeric range definition into an array of single values.

static array

parseRssDate(string date)

Parse RSS date.

static string

random(int length, string type)

Generate a random value.

static void

resolveZCClass(string clazz)

Resolve the given zen-cart class.

static boolean

rmdir(string dir, boolean recursive)

Remove a directory (tree).

static mixed

sanitize(mixed value)

Sanitize the given value.

static void

setFilePerms(mixed files, boolean recursive, array perms)

Apply user/group settings to file(s) that should allow ftp users to modify/delete them.

static boolean

startsWith(string s, string start)

Check if the given string starts with the provided string.

static array

toArray(mixed value)

Convert values to array where reasonable.

static string

translateDateString(string s, string from, string to)

Convert a (UI) date from one format to another.

static boolean

unzip(string filename, string target)

Unzip a file into the given directory.

Field Detail

RANDOM_CHARS

public final mixed RANDOM_CHARS = 'chars'

RANDOM_DIGITS

public final mixed RANDOM_DIGITS = 'digits'

RANDOM_HEX

public final mixed RANDOM_HEX = 'hex'

RANDOM_MIXED

public final mixed RANDOM_MIXED = 'mixed'

Method Detail

asBoolean

public static boolean asBoolean(mixed value)

Evaluate a string value as boolean.

Parameters:
value - The value.
Returns:
The boolean value.

compareStoreUrl

public static boolean compareStoreUrl(string url1, string url2)

Compare URLs.

This is defined only for URLs within the store.

NOTE: This function may not work with SEO solutions.

Parameters:
url1 - The first URL to compare.
url2 - Optional second URL; default is null to compare to the current URL.
Returns:
true if URLs are considered equal (based on various URL parameters).

endsWith

public static boolean endsWith(string s, string end)

Check if the given string ends with the provided string.

Parameters:
s - The haystack.
end - The needle.
Returns:
true if $s ends with $start, * false if not.

fmod_round

public void fmod_round(mixed x, mixed y)

fmod variant that can handle values < 1. /


ifModifiedSince

public static void ifModifiedSince(string timestamp, boolean true)

Helper for conditional get support.

Parameters:
timestamp - The last change date of whatever resource this is about.
true - if a body should be returned, * false if the resource changed.

inArray

public static boolean inArray(string value, mixed array)

Check if the given value exists in the array or comma separated list.

Parameters:
value - The value to search for.
array - Either an array or a string containing a comma separated list.
Returns:
true if the given value exists in the array, false if not.

isEmpty

public static boolean isEmpty(mixed value)

Check if a given value or array is empty.

Parameters:
value - The value or array to check.
Returns:
true if the value is empty or null, false if not.

mkRssDate

public static string mkRssDate(mixed date)

Convert date to RSS date format.

Parameters:
date - The date string, timestamp (long) or null to use the current date.
Returns:
A date string formatted according to RSS date rules.

mkUnique

public static string mkUnique(var arg)

Create a unique key from all given parameters.

Parameters:
arg - Arguments.
Returns:
a unique key based on the arguments.

mkdir

public static boolean mkdir(string dir, int perms, boolean recursive)

Make directory.

Parameters:
dir - The folder name.
perms - The file permisssions (octal); default: null to use the value of setting * fs.permissions.defaults.folder.
recursive - Optional recursive flag; (default: true)
Returns:
true on success.

move

public static boolean move(string src, string target)

Move files and folders.

Parameters:
src - The source (file or folder).
target - The target (file or folder).
Returns:
true on success.

normalizeFilename

public static string normalizeFilename(string filename)

Normalize filename.

Parameters:
filename - The filename.
Returns:
The normalized filename.

parseDateString

public static array parseDateString(string s, string format, array defaults)

Parse a date according to the given format.

This function supports the following format token:

  • hh - hours
  • ii - minutes
  • ss - seconds
  • dd - day
  • mm - month
  • cc - century
  • yy - year
  • yyyy - full year (if found both cc and yy will be populated accordingly

Parameters:
s - A date; usually either provided by the user or a database date.
format - The date format
defaults - Optional defaults for components; default is null for none.
Returns:
The individual date components as map using the token as keys.

parseMoney

public static float parseMoney(mixed money, string amount)

Parse a money amount.

Parameters:
amount - The amount probably formatted according to the sessions currency setting.
Returns:
The amount.

parseRange

public static array parseRange(string range)

Convert a numeric range definition into an array of single values.

A range might be a single value, a range; for example 3-8 or a list of both.

Valid examples of ranges are:

  • 3
  • 3,4,8
  • 3,4-6,8
  • 1,3-5,9,13,100-302

Parameters:
range - The range value.
Returns:
List of numeric (int) values.

parseRssDate

public static array parseRssDate(string date)

Parse RSS date.

Parameters:
date - The date.
Returns:
An array with 3 elements in the order [day] [month] [year].

random

public static string random(int length, string type)

Generate a random value.

Parameters:
length - The length of the random value.
type - Optional type; predefined values are: mixed, chars, digits or hex; default is mixed. * Any other value will be used as the valid character range.
Returns:
The random string.

resolveZCClass

public static void resolveZCClass(string clazz)

Resolve the given zen-cart class.

This function ensures that the given class is loaded.

Parameters:
clazz - The class name.

rmdir

public static boolean rmdir(string dir, boolean recursive)

Remove a directory (tree).

Parameters:
dir - The directory name.
recursive - Optional flag to enable/disable recursive deletion; (default is true)
Returns:
true on success.

sanitize

public static mixed sanitize(mixed value)

Sanitize the given value.

Parameters:
value - A string or array.
Returns:
A sanitized version.

setFilePerms

public static void setFilePerms(mixed files, boolean recursive, array perms)

Apply user/group settings to file(s) that should allow ftp users to modify/delete them.

The file group attribute is only going to be changed if the $perms parameter is not empty.

This method may be disabled by setting fs.permissions.fix to false.

Parameters:
files - Either a single filename or list of files.
recursive - Optional flag to recursively process all files/folders in a given directory; default is false.
perms - Optional file permissions; defaults are taken from the settings fs.permissions.defaults.folder for folder, * fs.permissions.defaults.file for files.

startsWith

public static boolean startsWith(string s, string start)

Check if the given string starts with the provided string.

Parameters:
s - The haystack.
start - The needle.
Returns:
true if $s starts with $start, * false if not.

toArray

public static array toArray(mixed value)

Convert values to array where reasonable.

Parameters:
value - The value to convert; either already an array or a URL query form string.
Returns:
The value as array.

translateDateString

public static string translateDateString(string s, string from, string to)

Convert a (UI) date from one format to another.

Parameters:
s - The date as received via the UI.
from - The current format of the date string.
to - The target format.
Returns:
The formatted date string or '' (if $s is empty).

unzip

public static boolean unzip(string filename, string target)

Unzip a file into the given directory.

Parameters:
filename - The zip filename.
target - The target directory.
Returns:
true on success.

ZenMagick 0.9.6