PHP Class ImageManager

Afficher le fichier Open project: sourcefabric/newscoop Class Usage Examples

Méthodes publiques

Свойство Type Description
$config Configuration array.
$dirs Array of directory information.

Méthodes publiques

Méthode 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 méthode

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

_delDir() public méthode

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

_delFile() public méthode

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

_dirs() public méthode

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
Résultat array of accessiable sub-directories array('path name' => 'full directory path', ...)

_processFiles() public méthode

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
Résultat boolean true if the file was processed successfully, false otherwise

countFiles() public méthode

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

deleteDirs() public méthode

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

deleteFiles() public méthode

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

getBaseDir() public méthode

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

getBaseURL() public méthode

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

getDefaultThumb() public méthode

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

getDirs() public méthode

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

getFileURL() public méthode

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
Résultat string the URL of the relative file.

getFiles() public méthode

Get all the files and directories of a relative path.
public getFiles ( string $path, $articleId ) : array
$path string relative path to be base path.
Résultat 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 méthode

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

getImageByNumber() public méthode

public getImageByNumber ( $articleId, $imageNumber )

getImageInfo() public méthode

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

getThumbName() public méthode

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
Résultat string of the thumbnail file

getThumbURL() public méthode

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
Résultat string the url of the thumbnail

getThumbnail() public méthode

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.
Résultat string the url of the thumbnail, be it actually thumbnail or a script to generate the thumbnail on the fly.

getTmpPrefix() public méthode

Get the tmp file prefix.
public getTmpPrefix ( ) : string
Résultat string tmp file prefix.

isThumb() public méthode

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

isThumbDir() public méthode

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

isTmpFile() public méthode

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

isValidBase() public méthode

public isValidBase ( )

processNewDir() public méthode

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

processUploads() public méthode

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
Résultat null

validRelativePath() public méthode

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
Résultat 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