ZenMagick 0.9.8


org.zenmagick.store.utils.ZMTools
\store\utils\ZMTools.php at line 35

Class ZMTools

ZMTools

public class ZMTools

(System) Tools.

Author:
DerManoMann
Version:
$Id: ZMTools.php 2711 2009-12-11 03:27:54Z dermanomann $

Field Summary
final str

RANDOM_CHARS

final str

RANDOM_DIGITS

final str

RANDOM_HEX

final str

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.

static 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 currencyCode, 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

\store\utils\ZMTools.php at line 37

RANDOM_CHARS

public final str RANDOM_CHARS = 'chars'

\store\utils\ZMTools.php at line 36

RANDOM_DIGITS

public final str RANDOM_DIGITS = 'digits'

\store\utils\ZMTools.php at line 39

RANDOM_HEX

public final str RANDOM_HEX = 'hex'

\store\utils\ZMTools.php at line 38

RANDOM_MIXED

public final str RANDOM_MIXED = 'mixed'

Method Detail

\store\utils\ZMTools.php at line 203

asBoolean

public static boolean asBoolean(mixed value)

Evaluate a string value as boolean.

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

\store\utils\ZMTools.php at line 426

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).

\store\utils\ZMTools.php at line 144

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.

\store\utils\ZMTools.php at line 727

fmod_round

public static void fmod_round(mixed x, mixed y)

fmod variant that can handle values < 1.


\store\utils\ZMTools.php at line 231

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.

\store\utils\ZMTools.php at line 156

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.

\store\utils\ZMTools.php at line 119

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.

\store\utils\ZMTools.php at line 381

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.

\store\utils\ZMTools.php at line 399

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.

\store\utils\ZMTools.php at line 83

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.

\store\utils\ZMTools.php at line 634

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.

\store\utils\ZMTools.php at line 557

normalizeFilename

public static string normalizeFilename(string filename)

Normalize filename.

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

\store\utils\ZMTools.php at line 325

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.

\store\utils\ZMTools.php at line 217

parseMoney

public static float parseMoney(mixed money, string currencyCode, string amount)

Parse a money amount.

Parameters:
amount - The amount.
currencyCode - The currency.
Returns:
The amount.

\store\utils\ZMTools.php at line 178

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.

\store\utils\ZMTools.php at line 368

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].

\store\utils\ZMTools.php at line 591

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.

\store\utils\ZMTools.php at line 621

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.

\store\utils\ZMTools.php at line 53

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.

\store\utils\ZMTools.php at line 267

sanitize

public static mixed sanitize(mixed value)

Sanitize the given value.

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

\store\utils\ZMTools.php at line 505

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.

\store\utils\ZMTools.php at line 131

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.

\store\utils\ZMTools.php at line 572

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.

\store\utils\ZMTools.php at line 294

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).

\store\utils\ZMTools.php at line 695

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.8