Procedural File: functions.php
Source Location: /functions.php
Page Details
basic functions used by zenphoto core
Headers not sent yet!
Includes
include
('version.php')
[line 12]
require
("zp-config.php")
[line 32]
require_once
('lib-gettext/gettext.inc')
[line 18]
require_once
("lib-utf8.php")
[line 39]
require_once
('lib-encryption.php')
[line 38]
Constants
ALL_ALBUMS_RIGHTS [line 2044]
COMMENT_RIGHTS [line 2042]
FULLWEBPATH [line 72]
FULLWEBPATH = PROTOCOL."://".$_SERVER['HTTP_HOST'].WEBPATH
|
|
OPTIONS_RIGHTS [line 2046]
PLUGIN_FOLDER [line 84]
PLUGIN_FOLDER = '/plugins/'
|
|
PROTOCOL [line 71]
PROTOCOL = getOption('server_protocol')
|
|
SAFE_MODE_ALBUM_SEP [line 73]
SAFE_MODE_ALBUM_SEP = '__'
|
|
SERVERCACHE [line 75]
SERVERCACHE = SERVERPATH.substr(CACHEFOLDER,0,-1)
|
|
SERVERPATH [line 70]
SERVERPATH = str_replace("\\",'/',dirname(dirname(__FILE__)))
|
|
THEMES_RIGHTS [line 2045]
UPLOAD_RIGHTS [line 2041]
VIEWALL_RIGHTS [line 2040]
ZENPAGE_RIGHTS [line 2047]
Functions
addPluginScript [line 2463]
Allows plugins to add to the scripts output by zenJavascript()
Parameters:
|
string |
$script: |
the text to be added. |
void addPluginScript(
string $script
)
|
|
addPluginType [line 2475]
Registers a plugin as handler for a file extension
Parameters:
|
string |
$suffix: |
the file extension |
|
string |
$objectName: |
the name of the object that handles this extension |
void addPluginType(
string $suffix, string $objectName
)
|
|
albumSortKey [line 468]
Returns the DB sort key for an album sort type
Parameters:
|
string |
$sorttype: |
The sort type option |
string albumSortKey(
string $sorttype
)
|
|
assert_handler [line 337]
Emits an assertion error
Parameters:
|
string |
$file: |
the script file |
|
string |
$line: |
the line of the assertion |
|
string |
$code: |
the error message |
void assert_handler(
string $file, string $line, string $code
)
|
|
cbone [line 2420]
Count Binary Ones
Returns the number of bits set in $bits
Parameters:
|
bit |
$bits: |
the bit mask to count |
|
int |
$limit: |
the upper limit on the numer of bits; |
int cbone(
bit $bits, int $limit
)
|
|
checkAlbumPassword [line 1308]
Checks to see access is allowed to an album Returns true if access is allowed.
There is no password dialog--you must have already had authorization via a cookie.
Parameters:
|
string |
$albumname: |
the album |
|
string |
&$hint: |
becomes populated with the password hint. |
bool checkAlbumPassword(
string $albumname, string &$hint
)
|
|
checkAuthorization [line 2167]
Retuns the administration rights of a saved authorization code
Parameters:
|
string |
$authCode: |
the md5 code to check |
bit checkAuthorization(
string $authCode
)
|
|
checkLogon [line 2213]
Checks a logon user/password against the list of admins
Returns true if there is a match
Parameters:
|
string |
$user: |
|
|
string |
$pass: |
|
bool checkLogon(
string $user, string $pass
)
|
|
checkObjectsThumb [line 398]
Search for a thumbnail for the image
Parameters:
|
string |
$album: |
folder path of the album |
|
string |
$video: |
name of the target |
string checkObjectsThumb(
string $album, string $video
)
|
|
checkVideoOriginal [line 418]
Search for a high quality version of the video
Parameters:
|
string |
$album: |
folder path of the album |
|
string |
$video: |
name of the target |
string checkVideoOriginal(
string $album, string $video
)
|
|
createAlbumZip [line 1391]
Creates a zip file of the album
Parameters:
|
string |
$album: |
album folder |
void createAlbumZip(
string $album
)
|
|
debugLog [line 1867]
Write output to the debug log Use this for debugging when echo statements would come before headers are sent or would create havoc in the HTML.
Creates (or adds to) a file named debug_log.txt which is located in the zenphoto core folder
Parameters:
|
string |
$message: |
the debug information |
|
bool |
$reset: |
set to true to reset the log to zero before writing the message |
void debugLog(
string $message, [bool $reset = false]
)
|
|
debugLogArray [line 1880]
"print_r" equivalent for the debug log
Parameters:
|
string |
$name: |
the name (or message) to display for the array |
|
array |
$source: |
|
void debugLogArray(
string $name, array $source
)
|
|
debugLogBacktrace [line 1906]
Logs the calling stack
@ param string $message Message to prefix the backtrace
Parameters:
void debugLogBacktrace(
$message
)
|
|
dircopy [line 2776]
Copies a directory recursively
Parameters:
|
string |
$srcdir: |
the source directory. |
|
string |
$dstdir: |
the destination directory. |
API Tags:
| Return: | total number of files copied. |
the dircopy(
string $srcdir, string $dstdir
)
|
|
dirsize [line 1051]
Get the size of a directory.
From: http://aidan.dotgeek.org/lib/
Parameters:
|
string |
$directory: |
Path to directory |
Information Tags:
void dirsize(
string $directory
)
|
|
filterTags [line 2522]
Trims the tag values and eliminates duplicates.
Tags are case insensitive so only the first of 'Tag' and 'tag' will be preserved Returns the filtered tag array.
Parameters:
array filterTags(
array $tags
)
|
|
fnmatch [line 1980]
pattern match function in case it is not included in PHP
Parameters:
|
string |
$pattern: |
pattern |
|
string |
$string: |
haystack |
bool fnmatch(
string $pattern, string $string
)
|
|
galleryAlbumsPerPage [line 2354]
Returns the number of album thumbs that go on a gallery page
int galleryAlbumsPerPage(
)
|
|
generateCaptcha [line 2438]
generates a simple captcha for comments
Thanks to gregb34 who posted the original code Returns the captcha code string and image URL (via the $image parameter).
Parameters:
string; generateCaptcha(
&$image
)
|
|
generateListFromArray [line 2666]
Creates the body of a select list
Parameters:
|
array |
$currentValue: |
list of items to be flagged as checked |
|
array |
$list: |
the elements of the select list |
|
bool |
$descending: |
set true for a reverse order sort |
void generateListFromArray(
array $currentValue, array $list, [bool $descending = false]
)
|
|
generateListFromFiles [line 2702]
Generates a selection list from files found on disk
Parameters:
|
strig |
$currentValue: |
the current value of the selector |
|
string |
$root: |
directory path to search |
|
string |
$suffix: |
suffix to select for |
|
bool |
$descending: |
set true to get a reverse order sort |
void generateListFromFiles(
strig $currentValue, string $root, string $suffix, [bool $descending = false]
)
|
|
getAdminEmail [line 2232]
Returns the email addresses of the Admin with ADMIN_USERS rights
Parameters:
|
bit |
$rights: |
what kind of admins to retrieve |
array getAdminEmail(
[bit $rights = ADMIN_RIGHTS]
)
|
|
getAdministrators [line 2120]
Returns an array of admin users, indexed by the userid
The array contains the md5 password, user's name, email, and admin priviledges
array getAdministrators(
)
|
|
getAlbumArray [line 578]
getAlbumArray - returns an array of folder names corresponding to the given album string.
Parameters:
|
string |
$albumstring: |
is the path to the album as a string. Ex: album/subalbum/my-album |
|
string |
$includepaths: |
is a boolean whether or not to include the full path to the album in each item of the array. Ex: when $includepaths==false, the above array would be ['album', 'subalbum', 'my-album'], and with $includepaths==true, ['album', 'album/subalbum', 'album/subalbum/my-album'] |
array getAlbumArray(
string $albumstring, [string $includepaths = false]
)
|
|
getAlbumFolder [line 1437]
Returns the fully qualified path to the album folders
Parameters:
|
string |
$root: |
the base from whence the path dereives |
sting getAlbumFolder(
[string $root = SERVERPATH]
)
|
|
getAllSubAlbumIDs [line 2292]
Returns an array of album ids whose parent is the folder
Parameters:
|
string |
$albumfolder: |
folder name if you want a album different >>from the current album |
array getAllSubAlbumIDs(
[string $albumfolder = '']
)
|
|
getAllTagsCount [line 2566]
Returns an array indexed by 'tag' with the element value the count of the tag
getAllTagsUnique [line 2544]
Returns an array of unique tag names
unknown getAllTagsUnique(
)
|
|
getEnabledPlugins [line 1502]
Returns an array of the currently enabled plugins
array getEnabledPlugins(
)
|
|
getImageCacheFilename [line 599]
Returns the path of an image for uses in caching it
Parameters:
|
string |
$album: |
album folder |
|
string |
$image: |
image file name |
|
array |
$args: |
cropping arguments |
string getImageCacheFilename(
string $album, string $image, array $args
)
|
|
getImageCachePostfix [line 621]
Returns the crop/sizing string to postfix to a cache image
Parameters:
|
array |
$args: |
cropping arguments |
string getImageCachePostfix(
array $args
)
|
|
getImageMetadata [line 1570]
Parces IPTC data and returns those tags zenphoto is interested in folds multiple tags into single zp data items based on precedence.
Parameters:
|
string |
$imageName: |
the name of the image |
array getImageMetadata(
string $imageName
)
|
|
getImageParameters [line 636]
Validates and edits image size/cropping parameters
Parameters:
|
array |
$args: |
cropping arguments |
array getImageParameters(
array $args
)
|
|
getIPTCTag [line 1523]
For internal use--fetches a single tag from IPTC data
Parameters:
|
string |
$tag: |
the metadata tag sought |
string getIPTCTag(
string $tag
)
|
|
getIPTCTagArray [line 1545]
For internal use--fetches the IPTC array for a single tag.
Parameters:
|
string |
$tag: |
the metadata tag sought |
array getIPTCTagArray(
string $tag
)
|
|
getManagedAlbumList [line 2252]
Populates and returns the $_zp_admin_album_list array
array getManagedAlbumList(
)
|
|
getOption [line 148]
Get a option stored in the database.
This function reads the options only once, in order to improve performance.
Parameters:
|
string |
$key: |
the name of the option. |
|
bool |
$db: |
set to true to force retrieval from the database. |
void getOption(
string $key, [bool $db = false]
)
|
|
getPlugin [line 1481]
Returns the fully qualified "require" file name of the plugin file.
Parameters:
|
string |
$plugin: |
is the name of the plugin file, typically something.php |
|
bool |
$inTheme: |
tells where to find the plugin. true means look in the current theme false means look in the zp-core/plugins folder. |
string getPlugin(
string $plugin, bool $inTheme
)
|
|
getUrAlbum [line 453]
Returns the oldest ancestor of an alubm;
Parameters:
|
string |
$album: |
an album object |
object getUrAlbum(
string $album
)
|
|
handleSearchParms [line 2312]
recovers search parameters from stored cookie, clears the cookie
Parameters:
|
string |
$album: |
Name of the album |
|
string |
$image: |
Name of the image |
void handleSearchParms(
[string $album = ''], [string $image = '']
)
|
|
hasDyanmicAlbumSuffix [line 2407]
Returns true if the file has the dynamic album suffix
Parameters:
bool hasDyanmicAlbumSuffix(
string $path
)
|
|
htmlspecialchars_decode [line 110]
Decodes HTML Special Characters. Function for backwards compatability with PHP 4.1.
Parameters:
|
string |
$text: |
|
|
string |
$quote_style: |
|
|
|
$string: |
|
string htmlspecialchars_decode(
$string, [string $quote_style = ENT_COMPAT], string $text
)
|
|
html_encode [line 125]
encodes a pre-sanitized string to be used in an HTML text-only field (value, alt, title, etc.)
Parameters:
|
string |
$this_string: |
|
|
|
$striptags: |
|
string html_encode(
string $this_string, [ $striptags = true]
)
|
|
isMyAlbum [line 2270]
Checks to see if the loggedin Admin has rights to the album
Parameters:
|
string |
$albumfolder: |
the album to be checked |
|
|
$action: |
|
void isMyAlbum(
string $albumfolder, $action
)
|
|
isValidURL [line 1680]
Checks to see if a URL is valid
Parameters:
|
string |
$url: |
the URL being checked |
bool isValidURL(
string $url
)
|
|
is_objectsThumb [line 381]
Check if the image is a video thumb
Parameters:
|
string |
$album: |
folder path for the album |
|
string |
$filename: |
name of the target |
API Tags:
| Return: | Note: this function is inefficient and slows down the image file loop a lot. Don't use it in a loop! |
bool is_objectsThumb(
string $album, string $filename
)
|
|
is_valid_email_zp [line 1023]
Determines if the input is an e-mail address. Adapted from WordPress.
Name changed to avoid conflicts in WP integrations.
Parameters:
|
string |
$input_email: |
email address? |
bool is_valid_email_zp(
string $input_email
)
|
|
is_valid_image [line 351]
Returns true if the file is an image
Parameters:
|
string |
$filename: |
the name of the target |
bool is_valid_image(
string $filename
)
|
|
is_valid_other_type [line 2486]
Returns true if the file is handled by a plugin object
Parameters:
bool is_valid_other_type(
string $filename
)
|
|
is_valid_video [line 364]
Returns true fi the file is a video file
Parameters:
|
string |
$filename: |
the name of the target |
bool is_valid_video(
string $filename
)
|
|
js_encode [line 137]
encodes a pre-sanitized string to be used in a Javascript alert box
Parameters:
string js_encode(
string $this_string
)
|
|
mkdir_recursive [line 2811]
Makes directory recursively, returns TRUE if exists or was created sucessfuly.
Note: PHP5 includes a recursive parameter to mkdir, but PHP4 does not, so this is required to target PHP4.
Parameters:
|
string |
$pathname: |
The directory path to be created. |
|
|
$mode: |
|
API Tags:
| Return: | TRUE if exists or made or FALSE on failure. |
boolean mkdir_recursive(
string $pathname, [ $mode = 0777]
)
|
|
myts_date [line 996]
Simple mySQL timestamp formatting function.
Parameters:
|
string |
$format: |
formatting template |
|
int |
$mytimestamp: |
timestamp |
string myts_date(
string $format, int $mytimestamp
)
|
|
newImage [line 2503]
Returns a new "image" object based on the file extension
Parameters:
|
object |
$album: |
the owner album |
|
string |
$filename: |
the filename |
|
|
&$album: |
|
object newImage(
&$album, string $filename, object $album
)
|
|
pageError [line 1290]
Emits a page error. Used for attempts to bypass password protection
Parameters:
void pageError(
$err, $text
)
|
|
parseAllowedTags [line 273]
parses the allowed HTML tags for use by htmLawed
Parameters:
|
string |
&$source: |
by name, contains the string with the tag options |
API Tags:
| Return: | the allowed_tags array. |
Information Tags:
array parseAllowedTags(
string &$source
)
|
|
parseThemeDef [line 1119]
Parses and sanitizes Theme definition text
Parameters:
string parseThemeDef(
file $file
)
|
|
parse_size [line 2821]
Parses a byte size from a size value (eg: 100M) for comparison.
Parameters:
pathurlencode [line 1039]
rawurlencode function that is path-safe (does not encode /)
Parameters:
string pathurlencode(
string $path
)
|
|
postComment [line 1706]
Generic comment adding routine. Called by album objects or image objects to add comments.
Returns a code for the success of the comment add: 0: Bad entry 1: Marked for moderation 2: Successfully posted
Parameters:
|
string |
$name: |
Comment author name |
|
string |
$email: |
Comment author email |
|
string |
$website: |
Comment author website |
|
string |
$comment: |
body of the comment |
|
string |
$code: |
Captcha code entered |
|
string |
$code_ok: |
Captcha md5 expected |
|
string |
$type: |
'albums' if it is an album or 'images' if it is an image comment |
|
object |
$receiver: |
the object (image or album) to which to post the comment |
|
string |
$ip: |
the IP address of the comment poster |
|
bool |
$private: |
set to true if the comment is for the admin only |
|
bool |
$anon: |
set to true if the poster wishes to remain anonymous |
int postComment(
string $name, string $email, string $website, string $comment, string $code, string $code_ok, object $receiver, string $ip, bool $private, bool $anon, string $type
)
|
|
prepIPTCString [line 1554]
Parameters:
void prepIPTCString(
$iptcstring
)
|
|
printLink [line 2722]
General link printing function
Parameters:
|
string |
$url: |
The link URL |
|
string |
$text: |
The text to go with the link |
|
string |
$title: |
Text for the title tag |
|
string |
$class: |
optional class |
|
string |
$id: |
optional id |
void printLink(
string $url, string $text, [string $title = NULL], [string $class = NULL], [string $id = NULL]
)
|
|
readTags [line 2646]
Retrieves the tags for an album/image Returns them in an array
Parameters:
|
int |
$id: |
the record id of the album/image |
|
string |
$tbl: |
'albums' or 'images' |
unknown readTags(
int $id, string $tbl
)
|
|
rewrite_get_album_image [line 520]
rewrite_get_album_image - Fix special characters in the album and image names if mod_rewrite is on: This is redundant and hacky; we need to either make the rewriting completely internal, or fix the bugs in mod_rewrite. The former is probably a good idea.
Old explanation: rewrite_get_album_image() parses the album and image from the requested URL if mod_rewrite is on, and replaces the query variables with corrected ones. This is because of bugs in mod_rewrite that disallow certain characters.
Parameters:
|
string |
$albumvar: |
"$_GET" parameter for the album |
|
string |
$imagevar: |
"$_GET" parameter for the image |
void rewrite_get_album_image(
string $albumvar, string $imagevar
)
|
|
rewrite_path [line 960]
Returns either the rewrite path or the plain, non-mod_rewrite path based on the mod_rewrite option in zp-config.php.
The given paths can start /with or without a slash, it doesn't matter. IDEA: this function could be used to specially escape items in the rewrite chain, like the # character (a bug in mod_rewrite). This is here because it's used in both template-functions.php and in the classes.
Parameters:
|
string |
$rewrite: |
is the path to return if rewrite is enabled. (eg: "/myalbum") |
|
string |
$plain: |
is the path if rewrite is disabled (eg: "/?album=myalbum") |
string rewrite_path(
string $rewrite, string $plain
)
|
|
safe_glob [line 1938]
Provide an alternative to glob if the ISP has disabled it To enable the alternative, change the SAFE_GLOB define at the front to functions.php
Parameters:
|
string |
$pattern: |
the 'pattern' for matching files |
|
bit |
$flags: |
glob 'flags' |
void safe_glob(
string $pattern, [bit $flags = 0]
)
|
|
sanitize [line 717]
Make strings generally clean. Takes an input string and cleans out null-bytes, slashes (if magic_quotes_gpc is on), and optionally use KSES library to prevent XSS attacks and other malicious user input.
Parameters:
|
string |
$input_string: |
is a string that needs cleaning. |
|
string |
$sanitize_level: |
is a number between 0 and 3 that describes the type of sanitizing to perform on $input_string. - - Basic sanitation. Only strips null bytes. Not recommended for submitted form data.
- - User specified. (User defined code is allowed. Used for descriptions and comments.)
- - Text style/formatting. (Text style codes allowed. Used for titles.)
- - Full sanitation. (Default. No code allowed. Used for text only fields)
|
API Tags:
| Return: | the sanitized string. |
string sanitize(
string $input_string, [string $sanitize_level = 3]
)
|
|
sanitize_numeric [line 696]
Checks if the input is numeric, rounds if so, otherwise returns false.
Parameters:
|
mixed |
$num: |
the number to be sanitized |
int sanitize_numeric(
mixed $num
)
|
|
sanitize_path [line 906]
Takes user input meant to be used within a path to a file or folder and removes anything that could be insecure or malicious, or result in duplicate representations for the same physical file.
Returns the sanitized path
Parameters:
|
string |
$filename: |
is the path text to filter. |
string sanitize_path(
string $filename
)
|
|
sanitize_string [line 734]
returns a sanitized string for the sanitize function
Parameters:
|
string |
$input_string: |
|
|
string |
$sanitize_level: |
|
API Tags:
| Return: | the sanitized string. |
string sanitize_string(
string $input_string, string $sanitize_level
)
|
|
saveAdmin [line 2064]
Saves an admin user's settings
Parameters:
|
string |
$user: |
The username of the admin |
|
string |
$pass: |
The password associated with the user name (md5) |
|
string |
$name: |
The display name of the admin |
|
string |
$email: |
The email address of the admin |
|
bit |
$rights: |
The administrating rites for the admin |
|
array |
$albums: |
an array of albums that the admin can access. (If empty, access is to all albums) |
void saveAdmin(
string $user, string $pass, string $name, string $email, bit $rights, array $albums
)
|
|
setBoolOption [line 224]
Converts a boolean value to 1 or 0 and sets the option with it
Parameters:
|
string |
$key: |
the option |
|
bool |
$value: |
the value to be set |
void setBoolOption(
string $key, bool $value
)
|
|
setOption [line 188]
Stores an option value.
Parameters:
|
string |
$key: |
name of the option. |
|
mixed |
$value: |
new value of the option. |
|
bool |
$persistent: |
set to false if the option is stored in memory only otherwise it is preserved in the database |
void setOption(
string $key, mixed $value, [bool $persistent = true]
)
|
|
setOptionDefault [line 240]
Sets the default value of an option.
If the option has never been set it is set to the value passed
Parameters:
|
string |
$key: |
the option name |
|
mixed |
$default: |
the value to be used as the default |
void setOptionDefault(
string $key, mixed $default
)
|
|
setupTheme [line 2363]
Returns the theme folder If there is an album theme, loads the theme options.
size_readable [line 1086]
Return human readable sizes From: http://aidan.dotgeek.org/lib/
Parameters:
|
int |
$size: |
Size |
|
int |
$unit: |
The maximum unit |
|
int |
$retstring: |
The return string format |
Information Tags:
|
|