Class GBFilePicker

Description

Main class of the GBFilePicker Module

  • author: Georg Busch (NaN)
  • version: 1.3
  • copyright: 2010 Georg Busch (NaN)
  • license: GPL

Located in /GBFilePicker.module.php (line 33)

CMSModule
   |
   --GBFilePicker
Method Summary
array CleanArray (array $array)
string CleanPath (string $path, [string $full_path = true])
string CleanURL (string $url, [string $full_url = true])
boolean ContainsIllegalChars (string $filename)
string CreateFileDropdown (string $id, string $name, [string $dir = ''], [string $selected = ''], [array|string $excl_prefix = ''], [array|string $incl_prefix = ''], [array|string $excl_sufix = ''], [array|string $incl_sufix = ''], [array|string $file_ext = ''], [string $media_type = ''], [boolean $allow_none = true], [string $add_txt = ''])
string CreateFilePickerInput (object &$module, string $id, string $name, [string $value = ''], [array $params = array()], [integer $returnid = ''])
string CreateThumbnail (string $path)
string GetActionIcon (string $action)
string GetFileIcon ([string $ext = ''], [bool $is_dir = false], [bool $is_image = false])
array &GetFiles ([string $dir = ''], [array|string $excl_prefix = ''], [array|string $incl_prefix = ''], [array|string $excl_sufix = ''], [array|string $incl_sufix = ''], [array|string $file_ext = ''], [string $media_type = 'image'], [boolean $excl_dirs = false], [boolean $show_thumbfiles = false], [boolean $create_thumbs = true])
string GetFileType (string $file, [string $use_mime = false])
array &GetInputFiles (string $id, string $name, string $dir)
array GetThemesList ()
string GetThumbnail (string $path, [string $create_thumb = true], [string $urlonly = false])
array GetThumbnailSize (string $path)
void HandleFileResizing (string $source, string $output, integer $new_width, integer $new_height, [boolean $keep_aspectratio = true], [boolean $allow_upscaling = false], [integer $quality = 100], [boolean $clean_path = true])
boolean IsDirEmpty (string $dir)
bool IsFalse (mixed $value)
bool IsTrue (mixed $value)
boolean IsVarEmpty (mixed &$var, [boolean $trim = true], [boolean $unset_empty_indexes = false])
bool Loaded ()
void SetParameters ()
integer SortFiles (object $file1, object $file2)
Methods
CleanArray (line 1852)

Removes empty elements from an array.
(can be useful when using function explode to create the array from a csv)

  • return: - an array without empty elements or an empty array
  • since: 1.0
  • access: public
array CleanArray (array $array)
  • array $array: - the array to clean up
CleanPath (line 1265)

Replaces all multiple DIRECTORY_SEPARATOR, dots and (multiple) slashes with one single DIRECTORY_SEPARATOR to make a clean secure path parameter

  • return: - the clean path
  • since: 1.0
  • access: public
string CleanPath (string $path, [string $full_path = true])
  • string $path: - the path to clean
  • string $full_path: - true to prepend uploads path on return, false to return only the cleaned $path
CleanURL (line 1292)

Replaces all multiple slashes, dots and (multiple) backslashes with one single slash to make a clean secure url parameter

  • return: - the clean url
  • since: 1.0
  • access: public
string CleanURL (string $url, [string $full_url = true])
  • string $url: - the url to clean
  • string $full_url: - true to prepend uploads url on return, false to return only the cleaned $url
ContainsIllegalChars (line 1787)

Checks if a filename contains illegal chars
Taken from TinyMCE Module.

  • since: 1.0
  • access: public
boolean ContainsIllegalChars (string $filename)
  • string $filename: - the filename to check
CreateFileDropdown (line 978)

Create a dropdown form element containing a list of files that match certain conditions

  • return: - the HTML output of a select element with options
  • since: 1.0
  • access: public
string CreateFileDropdown (string $id, string $name, [string $dir = ''], [string $selected = ''], [array|string $excl_prefix = ''], [array|string $incl_prefix = ''], [array|string $excl_sufix = ''], [array|string $incl_sufix = ''], [array|string $file_ext = ''], [string $media_type = ''], [boolean $allow_none = true], [string $add_txt = ''])
  • string $id: - the id of the moduleinstance that creates the filepicker input
  • string $name: - the name of the input field
  • string $dir: - the directory to list the files of (may be relative to uploads dir or absolute path)
  • string $selected: - the preselected value
  • array|string $excl_prefix: - fileprefixes to exclude (array('foo','bar',...) or csv)
  • array|string $incl_prefix: - fileprefixes to include (array('foo','bar',...) or csv)
  • array|string $excl_sufix: - filesufixes to exclude (array('foo','bar',...) or csv)
  • array|string $incl_sufix: - filesufixes to include (array('foo','bar',...) or csv)
  • array|string $file_ext: - filesufixes to include (array('foo','bar',...) or csv)
  • string $media_type: - file or image
  • boolean $allow_none: - set to false to hide the option 'none'
  • string $add_txt: - any additional text that will be added to the html input when tag is rendered
CreateFilePickerInput (line 400)

Creates the filepicker input.

  • return: - the HTML output of the filepicker
  • since: 1.0
  • access: public
string CreateFilePickerInput (object &$module, string $id, string $name, [string $value = ''], [array $params = array()], [integer $returnid = ''])
  • object &$module: - the module instance that calls the filepicker (this is only needed if you want to process own templates; pass the filepicker instance itself or leave it empty if you don't need this)
  • string $id: - the id of the moduleinstance that creates the filepicker input
  • string $name: - the name of the input field
  • string $value: - the preselected value
  • array $params: - the input params (param_name => param_value):
    • (string) 'feu_access' => a csv of group ids of the frontend users module,
    • (boolean) 'restrict_users_diraccess' => set to true if user may only access a dir of his username (notice: this has no effect if you are admin; in frontend this will always be true),
    • (string) 'header_template' => specify wich template should be used to create the html output that will be placed in the <head> section (default is header.tpl of the selected theme of GBFilePickers preferences),
    • (string) 'input_template' => specify wich template should be used to create the input elements (default is input.tpl of the selected theme of GBFilePickers preferences),
    • (string) 'upload_template' => specify wich template should be used to create the upload form of mode dropdown (default is upload.tpl of the selected theme of GBFilePickers preferences),
    • (string) 'filebrowser_template' => specify wich template should be used to create the filebrowser output (default is fileBrowser.tpl of the selected theme of GBFilePickers preferences),
    • (string) 'prompt' => the prompt of the input field,
    • (string) 'media_type' => the media type (at the moment only image / file are supported),
    • (mixed) 'file_extensions' => an array or a csv of allowed file extensions,
    • (mixed) 'exclude_prefix' => an array or a csv of file prefixes that will be excluded,
    • (mixed) 'exclude_sufix' => an array or a csv of file suffixes that will be excluded,
    • (mixed) 'include_prefix' => an array or a csv of file prefixes that will be included,
    • (mixed) 'include_sufix' => an array or a csv of file suffixes that will be included,
    • (boolean) 'show_subdirs' => set to true if user may browse subdirs (notice: this has no effect if you are admin)
    • (string) 'mode' => dropdown/browser,
    • (boolean) 'allow_none' => set to false if the option "none" should not be shown (notice: this has no effect if you are admin),
    • (boolean) 'lock_input' => set to false if user may enter the path in the inputfield ('mode'=>'browser', 'media_type' => 'file') (notice: this has no effect if you are admin),
    • (boolean) 'upload' => set to true if user may upload files (notice: this has no effect if you are admin or have permission to modify files),
    • (boolean) 'delete' => set to true if user may delete files/dirs (notice: this has no effect if you are admin or have permission to modify files),
    • (boolean) 'create_dirs' => set to true if user may create dirs (notice: this has no effect if you are admin or have permission to modify files),
    • (string) 'add_txt' => any additional text that will be added to the html input when tag is rendered,
    • (integer) 'size' => the size of the textinput ('mode' => 'browser', 'media_type' => 'file' only),
    • (integer) 'maxlength' => the max length of the textinput ('mode' => 'browser', 'media_type' => 'file' only),
    • (integer) 'scaling_width' => the default width of images when allow_scaling is true,
    • (integer) 'scaling_height' => the default height of images when allow_scaling is true,
    • (boolean) 'show_thumbfiles' => set to true if thumbs should also be shown as regular files,
    • (boolean) 'allow_scaling' => set to false if user may not scale the images on upload,
    • (boolean) 'create_thumbs' => set to false if the module may not create thumbs for the input,
    • (boolean) 'allow_upscaling' => set to true if user may enlarge the images
    • (boolean) 'force_scaling' => set to true to force resizing of image to a given size if user may not resize images
    • (boolean) 'keep_aspectratio' => set to false to change aspect ratio to that one of the scaling size on resizing images
  • integer $returnid: - the page id to return to and to print out the result after module has finished its task;
    usually this has nothing to say but is required for frontend usage (must be an existing content id)
CreateThumbnail (line 1363)

Creates the thumbnail of a given image file.

  • return: - absolute path of the thumbnail
  • since: 1.2.9
  • access: public
string CreateThumbnail (string $path)
  • string $path: - the path of the file to create a thumbnail from (can be relative to the uploads dir or absolute)
GetActionIcon (line 1428)

Gets the icon for the file operation.
If FileManager is installed it uses FileManager icons.
Otherwise it uses own icons

  • return: - the HTML ouput of an image
  • since: 1.0
  • access: public
string GetActionIcon (string $action)
  • string $action: - the file operation (e.g. 'delete')
GetFileIcon (line 1398)

Gets the icon for a file.
If FileManager is installed it uses FileManager icons.
Otherwise it uses own icons.

  • return: - the HTML ouput of an image
  • since: 1.0
  • access: public
string GetFileIcon ([string $ext = ''], [bool $is_dir = false], [bool $is_image = false])
  • string $ext: - the file extension
  • bool $is_dir
  • bool $is_image
GetFiles (line 1063)

Return an array containing a list of files in a directory.
Performs a non recursive search.

  • since: 1.0
  • access: public
array &GetFiles ([string $dir = ''], [array|string $excl_prefix = ''], [array|string $incl_prefix = ''], [array|string $excl_sufix = ''], [array|string $incl_sufix = ''], [array|string $file_ext = ''], [string $media_type = 'image'], [boolean $excl_dirs = false], [boolean $show_thumbfiles = false], [boolean $create_thumbs = true])
  • string $dir: - the directory to list the files of (may be relative to uploads dir or absolute path)
  • array|string $excl_prefix: - fileprefixes to exclude (array('foo','bar',...) or csv)
  • array|string $incl_prefix: - fileprefixes to include (array('foo','bar',...) or csv)
  • array|string $excl_sufix: - filesufixes to exclude (array('foo','bar',...) or csv)
  • array|string $incl_sufix: - filesufixes to include (array('foo','bar',...) or csv)
  • array|string $file_ext: - filesufixes to include (array('foo','bar',...) or csv)
  • string $media_type: - file or image
  • boolean $excl_dirs: - set to true to exclude directories
  • boolean $show_thumbfiles
  • boolean $create_thumbs: = true
GetFileType (line 929)

Gets the file type of a file.

  • return: - the mime-type or file extension
  • since: 1.0
  • access: public
string GetFileType (string $file, [string $use_mime = false])
  • string $file: - the path to a file
  • string $use_mime: - set to true to detect file type by mime type
GetInputFiles (line 1032)

Return an array containing a list of files in a directory related to a certain input.
Performs a non recursive search.

  • since: 1.1
  • access: public
array &GetInputFiles (string $id, string $name, string $dir)
  • string $id: - the id of the moduleinstance that creates the filepicker input
  • string $name: - the name of the input field
  • string $dir: - the directory to list the files of (may be relative to uploads dir or absolute path)
GetThemesList (line 2011)

Returns a list of available themes

  • return: - the themes
  • since: 1.2.9
  • access: public
array GetThemesList ()
GetThumbnail (line 1320)

Returns the thumbnail of a given image file.

  • return: - HTML img element or url
  • since: 1.0
  • access: public
string GetThumbnail (string $path, [string $create_thumb = true], [string $urlonly = false])
  • string $path: - the path of the file to create a thumbnail of (can be relative to the uploads dir or absolute)
  • string $create_thumb: - set to false if thumbnail may not be created if not exists
  • string $urlonly: - set to true to get only the url to the thumbnail
GetThumbnailSize (line 1694)

returns the calculated size of the thumbnail

  • return: - array(width,height)
  • since: 1.2
  • access: public
array GetThumbnailSize (string $path)
  • string $path: - the source path of the image
HandleFileResizing (line 1504)

resizes images
Adapted from TinyMCE filepicker.

  • todo: enable format change?
  • since: 1.0
  • access: public
void HandleFileResizing (string $source, string $output, integer $new_width, integer $new_height, [boolean $keep_aspectratio = true], [boolean $allow_upscaling = false], [integer $quality = 100], [boolean $clean_path = true])
  • string $source: - the source path of the image
  • string $output: - the destination path of the resized image
  • integer $new_width: - the new wdth to scale the image to (if $keep_aspectratio is set to true this will be just some kind of max value)
  • integer $new_height: - the new height to scale the image to (if $keep_aspectratio is set to true this will be just some kind of max value)
  • boolean $keep_aspectratio: - set to false if image aspect ratio may be changed
  • boolean $allow_upscaling: - set to true if user may enlarge the image
  • integer $quality: - the quality of the new image (jpg only)
  • boolean $clean_path: - set to false if source is the upload_tmp_dir
IsDirEmpty (line 1450)

Checks if a directory is empty
Taken from TinyMCE Module (extracted from filepicker).

  • since: 1.0
  • access: public
boolean IsDirEmpty (string $dir)
  • string $dir: - the path to a directory
IsFalse (line 1910)

Checks if a value is really meant to be "false".
Can be usefull when checking smarty params for the value false

  • since: 1.0
  • access: public
bool IsFalse (mixed $value)
  • mixed $value: - the value to check
IsTrue (line 1894)

Checks if a value is really meant to be "true".
Can be usefull when checking smarty params for the value true

  • since: 1.0
  • access: public
bool IsTrue (mixed $value)
  • mixed $value: - the value to check
IsVarEmpty (line 1812)

Checks if a var is empty.
If $var is an array it recursivley checks all elements.

  • return: - true if empty, false if not
  • since: 1.0
  • access: public
boolean IsVarEmpty (mixed &$var, [boolean $trim = true], [boolean $unset_empty_indexes = false])
  • mixed &$var: - the var to check for empty value(s)
  • boolean $trim: - true to trim off spaces
  • boolean $unset_empty_indexes: - true to delete empty elements from array
Loaded (line 1925)

Indicates if GBFilePicker output is already done
can be useful to avoid ouput of javascript and css twice

  • return: - true if output done; false if not
  • since: 1.1
  • access: public
bool Loaded ()
SetParameters (line 292)
void SetParameters ()
SortFiles (line 1479)

Sorts the files by filename; shows directories first
this function is meant to be called from the php usort() function: usort($array,array($this,'SortFiles')
Taken from TinyMCE filepicker.

  • return: -1 or 1
  • since: 1.0
  • access: public
integer SortFiles (object $file1, object $file2)
  • object $file1: - one file to compare
    a php stdClass with properties (boolean) $is_dir - a flag that specifys if it is a dir or a file;
    (string) $basename - the basename of the file;
  • object $file2: - the other file to compare
    a php stdClass with properties (boolean) $is_dir - a flag that specifys if it is a dir or a file;
    (string) $basename - the basename of the file;

Documentation generated on Wed, 23 Feb 2011 21:38:09 +0100 by phpDocumentor 1.4.0a2