[ class tree: functions ] [ index: functions ] [ all elements ]

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]
[ Top ]

require ("zp-config.php") [line 32]
[ Top ]

require_once ('lib-gettext/gettext.inc') [line 18]
[ Top ]

require_once ("lib-utf8.php") [line 39]
[ Top ]

require_once ('functions-i18n.php') [line 97]
[ Top ]

require_once ('functions-db.php') [line 37]
[ Top ]

require_once ('lib-encryption.php') [line 38]
[ Top ]


Constants
ADMIN_RIGHTS  [line 2048]

ADMIN_RIGHTS = 65536

[ Top ]

ALBUMFOLDER  [line 83]

ALBUMFOLDER = '/albums/'

[ Top ]

ALL_ALBUMS_RIGHTS  [line 2044]

ALL_ALBUMS_RIGHTS = 512

[ Top ]

ALL_RIGHTS  [line 2049]

ALL_RIGHTS = 07777777777

[ Top ]

CACHEFOLDER  [line 74]

CACHEFOLDER = '/cache/'

[ Top ]

CAPTCHA_LENGTH  [line 11]

CAPTCHA_LENGTH = 5

[ Top ]

CHMOD_VALUE  [line 13]

CHMOD_VALUE = 0777

[ Top ]

COMMENT_RIGHTS  [line 2042]

COMMENT_RIGHTS = 64

[ Top ]

DEBUG_ERROR  [line 9]

DEBUG_ERROR = false

[ Top ]

DEBUG_LOGIN  [line 8]

DEBUG_LOGIN = false

[ Top ]

EDIT_RIGHTS  [line 2043]

EDIT_RIGHTS = 256

[ Top ]

FULLWEBPATH  [line 72]

FULLWEBPATH = PROTOCOL."://".$_SERVER['HTTP_HOST'].WEBPATH

[ Top ]

MAIN_RIGHTS  [line 2039]

MAIN_RIGHTS = 4

[ Top ]

NO_RIGHTS  [line 2038]

NO_RIGHTS = 2

[ Top ]

OFFSET_PATH  [line 15]

OFFSET_PATH = 0

[ Top ]

OPTIONS_RIGHTS  [line 2046]

OPTIONS_RIGHTS = 8192

[ Top ]

PLUGIN_FOLDER  [line 84]

PLUGIN_FOLDER = '/plugins/'

[ Top ]

PROTOCOL  [line 71]

PROTOCOL = getOption('server_protocol')

[ Top ]

SAFE_GLOB  [line 10]

SAFE_GLOB = false

[ Top ]

SAFE_MODE_ALBUM_SEP  [line 73]

SAFE_MODE_ALBUM_SEP = '__'

[ Top ]

SERVERCACHE  [line 75]

SERVERCACHE = SERVERPATH.substr(CACHEFOLDER,0,-1)

[ Top ]

SERVERPATH  [line 70]

SERVERPATH = str_replace("\\",'/',dirname(dirname(__FILE__)))

[ Top ]

THEMEFOLDER  [line 85]

THEMEFOLDER = 'themes'

[ Top ]

THEMES_RIGHTS  [line 2045]

THEMES_RIGHTS = 1024

[ Top ]

UPLOAD_RIGHTS  [line 2041]

UPLOAD_RIGHTS = 16

[ Top ]

VIEWALL_RIGHTS  [line 2040]

VIEWALL_RIGHTS = 8

[ Top ]

WEBPATH  [line 69]

WEBPATH = $const_webpath

[ Top ]

ZENFOLDER  [line 14]

ZENFOLDER = 'zp-core'

[ Top ]

ZENPAGE_RIGHTS  [line 2047]

ZENPAGE_RIGHTS = 2048

[ Top ]


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  )

[ Top ]
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  )

[ Top ]
albumSortKey  [line 468]

Returns the DB sort key for an album sort type

Parameters:
string   $sorttype:  The sort type option


string albumSortKey( string $sorttype  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
checkAuthorization  [line 2167]

Retuns the administration rights of a saved authorization code

Parameters:
string   $authCode:  the md5 code to check


bit checkAuthorization( string $authCode  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
createAlbumZip  [line 1391]

Creates a zip file of the album

Parameters:
string   $album:  album folder


void createAlbumZip( string $album  )

[ Top ]
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]  )

[ Top ]
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  )

[ Top ]
debugLogBacktrace  [line 1906]

Logs the calling stack

@ param string $message Message to prefix the backtrace

Parameters:
   $message: 


void debugLogBacktrace( $message  )

[ Top ]
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  )

[ Top ]
dirsize  [line 1051]

Get the size of a directory.

From: http://aidan.dotgeek.org/lib/

Parameters:
string   $directory:  Path to directory

Information Tags:
Author:  Aidan Lister <aidan@php.net>
Version:  1.0.0

void dirsize( string $directory  )

[ Top ]
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   $tags: 


array filterTags( array $tags  )

[ Top ]
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  )

[ Top ]
galleryAlbumsPerPage  [line 2354]

Returns the number of album thumbs that go on a gallery page


int galleryAlbumsPerPage( )

[ Top ]
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:
   &$image: 


string; generateCaptcha( &$image  )

[ Top ]
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]  )

[ Top ]
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]  )

[ Top ]
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]  )

[ Top ]
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( )

[ Top ]
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]  )

[ Top ]
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]  )

[ Top ]
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 = '']  )

[ Top ]
getAllTagsCount  [line 2566]

Returns an array indexed by 'tag' with the element value the count of the tag


array getAllTagsCount( )

[ Top ]
getAllTagsUnique  [line 2544]

Returns an array of unique tag names


unknown getAllTagsUnique( )

[ Top ]
getEnabledPlugins  [line 1502]

Returns an array of the currently enabled plugins


array getEnabledPlugins( )

[ Top ]
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  )

[ Top ]
getImageCachePostfix  [line 621]

Returns the crop/sizing string to postfix to a cache image

Parameters:
array   $args:  cropping arguments


string getImageCachePostfix( array $args  )

[ Top ]
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  )

[ Top ]
getImageParameters  [line 636]

Validates and edits image size/cropping parameters

Parameters:
array   $args:  cropping arguments


array getImageParameters( array $args  )

[ Top ]
getIPTCTag  [line 1523]

For internal use--fetches a single tag from IPTC data

Parameters:
string   $tag:  the metadata tag sought


string getIPTCTag( string $tag  )

[ Top ]
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  )

[ Top ]
getManagedAlbumList  [line 2252]

Populates and returns the $_zp_admin_album_list array


array getManagedAlbumList( )

[ Top ]
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]  )

[ Top ]
getOptionList  [line 260]

Retuns the option array


array getOptionList( )

[ Top ]
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  )

[ Top ]
getUrAlbum  [line 453]

Returns the oldest ancestor of an alubm;

Parameters:
string   $album:  an album object


object getUrAlbum( string $album  )

[ Top ]
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 = '']  )

[ Top ]
hasDyanmicAlbumSuffix  [line 2407]

Returns true if the file has the dynamic album suffix

Parameters:
string   $path: 


bool hasDyanmicAlbumSuffix( string $path  )

[ Top ]
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  )

[ Top ]
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]  )

[ Top ]
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  )

[ Top ]
isValidURL  [line 1680]

Checks to see if a URL is valid

Parameters:
string   $url:  the URL being checked


bool isValidURL( string $url  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
is_valid_other_type  [line 2486]

Returns true if the file is handled by a plugin object

Parameters:
string   $filename: 


bool is_valid_other_type( string $filename  )

[ Top ]
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  )

[ Top ]
js_encode  [line 137]

encodes a pre-sanitized string to be used in a Javascript alert box

Parameters:
string   $this_string: 


string js_encode( string $this_string  )

[ Top ]
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]  )

[ Top ]
myts_date  [line 996]

Simple mySQL timestamp formatting function.

Parameters:
string   $format:  formatting template
int   $mytimestamp:  timestamp


string myts_date( string $format, int $mytimestamp  )

[ Top ]
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  )

[ Top ]
pageError  [line 1290]

Emits a page error. Used for attempts to bypass password protection

Parameters:
   $err: 
   $text: 


void pageError( $err, $text  )

[ Top ]
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:
Since:  1.1.3

array parseAllowedTags( string &$source  )

[ Top ]
parseThemeDef  [line 1119]

Parses and sanitizes Theme definition text

Parameters:
file   $file:  theme file


string parseThemeDef( file $file  )

[ Top ]
parse_size  [line 2821]

Parses a byte size from a size value (eg: 100M) for comparison.

Parameters:
   $size: 


void parse_size( $size  )

[ Top ]
pathurlencode  [line 1039]

rawurlencode function that is path-safe (does not encode /)

Parameters:
string   $path:  URL


string pathurlencode( string $path  )

[ Top ]
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  )

[ Top ]
prepIPTCString  [line 1554]
Parameters:
   $iptcstring: 


void prepIPTCString( $iptcstring  )

[ Top ]
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]  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
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]  )

[ Top ]
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.
  1. - Basic sanitation. Only strips null bytes. Not recommended for submitted form data.
  2. - User specified. (User defined code is allowed. Used for descriptions and comments.)
  3. - Text style/formatting. (Text style codes allowed. Used for titles.)
  4. - 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]  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
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  )

[ Top ]
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]  )

[ Top ]
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  )

[ Top ]
setupTheme  [line 2363]

Returns the theme folder If there is an album theme, loads the theme options.


string setupTheme( )

[ Top ]
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:
Author:  Aidan Lister <aidan@php.net>