PHP Class ImageManager

Mostra file Open project: sourcefabric/newscoop Class Usage Examples

Public Properties

Property Type Description
$config Configuration array.
$dirs Array of directory information.

Public Methods

Method Description
ImageManager ( array $config ) Constructor. Create a new Image Manager instance.
_delDir ( string $relative ) : boolean Delete directories recursively.
_delFile ( string $relative ) : boolean Delete the relative file, and any thumbnails.
_dirs ( string $base, string $path ) : array Recursively travese the directories to get a list of accessable directories.
_processFiles ( string $relative, array $file ) : boolean Process upload files. The file must be an uploaded file. If 'validate_images' is set to true, only images will be processed. Any duplicate file will be renamed. See Files::copyFile for details on renaming.
countFiles ( $path ) Count the number of files and directories in a given folder minus the thumbnail folders and thumbnails.
deleteDirs ( ) : boolean Delete and specified directories.
deleteFiles ( ) : boolean Delete and specified files.
getBaseDir ( ) : string Get the base directory.
getBaseURL ( ) : string Get the base URL.
getDefaultThumb ( ) : string Get the default thumbnail.
getDirs ( ) : array Get the sub directories in the base dir.
getFileURL ( string $relative ) : string Get the URL of the relative file.
getFiles ( string $path, $articleId ) : array Get all the files and directories of a relative path.
getFullPath ( string $relative ) : string Get the fullpath to a relative file.
getImageByNumber ( $articleId, $imageNumber )
getImageInfo ( string $file ) : array Get image size information.
getThumbName ( string $fullpathfile ) : string For a given image file, get the respective thumbnail filename no file existence check is done.
getThumbURL ( string $relative ) : string Similar to getThumbName, but returns the URL, base on the given base_url in config.inc.php
getThumbnail ( string $relative ) : string Get the thumbnail url to be displayed.
getTmpPrefix ( ) : string Get the tmp file prefix.
isThumb ( string $file ) : true Check if the file contains the thumbnail prefix.
isThumbDir ( string $entry ) : true Check if the given directory is a thumbnail directory.
isTmpFile ( string $file ) : boolean Check if the given file is a tmp file.
isValidBase ( )
processNewDir ( ) : boolean Create new directories.
processUploads ( ) : null Process uploaded files, assumes the file is in $_FILES['upload'] and $_POST['dir'] is set.
validRelativePath ( string $path ) : boolean Check if the given path is part of the subdirectories under the base_dir.

Method Details

ImageManager() public method

Constructor. Create a new Image Manager instance.
public ImageManager ( array $config )
$config array configuration array, see config.inc.php

_delDir() public method

Delete directories recursively.
public _delDir ( string $relative ) : boolean
$relative string the relative path to be deleted.
return boolean true if deleted, false otherwise.

_delFile() public method

Delete the relative file, and any thumbnails.
public _delFile ( string $relative ) : boolean
$relative string the relative file.
return boolean true if deleted, false otherwise.

_dirs() public method

Recursively travese the directories to get a list of accessable directories.
public _dirs ( string $base, string $path ) : array
$base string the full path to the current directory
$path string the relative path name
return array of accessiable sub-directories array('path name' => 'full directory path', ...)

_processFiles() public method

Process upload files. The file must be an uploaded file. If 'validate_images' is set to true, only images will be processed. Any duplicate file will be renamed. See Files::copyFile for details on renaming.
public _processFiles ( string $relative, array $file ) : boolean
$relative string the relative path where the file should be copied to.
$file array the uploaded file from $_FILES
return boolean true if the file was processed successfully, false otherwise

countFiles() public method

Count the number of files and directories in a given folder minus the thumbnail folders and thumbnails.
public countFiles ( $path )

deleteDirs() public method

Delete and specified directories.
public deleteDirs ( ) : boolean
return boolean true if delete, false otherwise

deleteFiles() public method

Delete and specified files.
public deleteFiles ( ) : boolean
return boolean true if delete, false otherwise

getBaseDir() public method

Get the base directory.
public getBaseDir ( ) : string
return string base dir, see config.inc.php

getBaseURL() public method

Get the base URL.
public getBaseURL ( ) : string
return string base url, see config.inc.php

getDefaultThumb() public method

Get the default thumbnail.
public getDefaultThumb ( ) : string
return string default thumbnail, empty string if the thumbnail doesn't exist.

getDirs() public method

Each array element contain the relative path (relative to the base dir) as key and the full path as value.
public getDirs ( ) : array
return array of sub directries array('path name' => 'full directory path', ...)

getFileURL() public method

basically appends the relative file to the base_url given in config.inc.php
public getFileURL ( string $relative ) : string
$relative string a file the relative to the base_dir
return string the URL of the relative file.

getFiles() public method

Get all the files and directories of a relative path.
public getFiles ( string $path, $articleId ) : array
$path string relative path to be base path.
return array of file and path information. array(0 => array('relative'=>'fullpath',...), 1 => array('filename'=>fileinfo array(),...) fileinfo array: array('url'=>'full url', 'relative'=>'relative to base', 'fullpath'=>'full file path', 'image'=>imageInfo array() false if not image, 'stat' => filestat)

getFullPath() public method

Get the fullpath to a relative file.
public getFullPath ( string $relative ) : string
$relative string the relative file.
return string the full path, .ie. the base_dir + relative.

getImageByNumber() public method

public getImageByNumber ( $articleId, $imageNumber )

getImageInfo() public method

Get image size information.
public getImageInfo ( string $file ) : array
$file string the image file
return array of getImageSize information, false if the file is not an image.

getThumbName() public method

For a given image file, get the respective thumbnail filename no file existence check is done.
public getThumbName ( string $fullpathfile ) : string
$fullpathfile string the full path to the image file
return string of the thumbnail file

getThumbURL() public method

Similar to getThumbName, but returns the URL, base on the given base_url in config.inc.php
public getThumbURL ( string $relative ) : string
$relative string the relative image file name, relative to the base_dir path
return string the url of the thumbnail

getThumbnail() public method

If the thumbnail exists, and it is up-to-date the thumbnail url will be returns. If the file is not an image, a default image will be returned. If it is an image file, and no thumbnail exists or the thumbnail is out-of-date (i.e. the thumbnail modified time is less than the original file) then a thumbs.php?img=filename.jpg is returned. The thumbs.php url will generate a new thumbnail on the fly. If the image is less than the dimensions of the thumbnails, the image will be display instead.
public getThumbnail ( string $relative ) : string
$relative string the relative image file.
return string the url of the thumbnail, be it actually thumbnail or a script to generate the thumbnail on the fly.

getTmpPrefix() public method

Get the tmp file prefix.
public getTmpPrefix ( ) : string
return string tmp file prefix.

isThumb() public method

Check if the file contains the thumbnail prefix.
public isThumb ( string $file ) : true
$file string filename to be checked
return true if the file contains the thumbnail prefix, false otherwise.

isThumbDir() public method

Check if the given directory is a thumbnail directory.
public isThumbDir ( string $entry ) : true
$entry string directory name
return true if it is a thumbnail directory, false otherwise

isTmpFile() public method

Check if the given file is a tmp file.
public isTmpFile ( string $file ) : boolean
$file string file name
return boolean true if it is a tmp file, false otherwise

isValidBase() public method

public isValidBase ( )

processNewDir() public method

If in safe_mode, nothing happens.
public processNewDir ( ) : boolean
return boolean true if created, false otherwise.

processUploads() public method

The dir must be relative to the base_dir and exists. If 'validate_images' is set to true, only file with image dimensions will be accepted.
public processUploads ( ) : null
return null

validRelativePath() public method

Check if the given path is part of the subdirectories under the base_dir.
public validRelativePath ( string $path ) : boolean
$path string the relative path to be checked
return boolean true if the path exists, false otherwise

Property Details

$config public_oe property

Configuration array.
public $config

$dirs public_oe property

Array of directory information.
public $dirs