SnapExternalFile Class Reference

This class represents a file that exists in the /media directory. More...

Inheritance diagram for SnapExternalFile:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 __construct ($version, $array="")
 Create a new SnapExternalFile attached to a version.
 copy ($newName="")
 Creates a copy of this file.
 create ($tmpFile, $originalName, $name="")
 Creates an actual file on the file system.
 delete ()
 Destroy this file.
 getArray ()
 Retrieves "serialized" representation of the file.
 getName ()
 Retrieves the real name of the file this object represents.
 getPath ()
 Retrieves path on the server where file is located.
 getURL ()
 Retrieves URL to file.
 load ($array)
 Loads file information from serialized array generated by getArray().
 setAcceptable ($fileTypes)
 For directories: sets which file types are allowed to be contained in the directory.
 unzip ($callIt)
 If this is a zipfile, unzips it into a new directory.
 update ($tmpFile, $originalName, $name="")
 Modifies existing file or changes its name.
 updateDB ()
 updates or inserts the file's path and id /*
 weedFiles ($directory= 'default')
 For directories: weeds out files that do not belong to list of acceptable file types.

Private Member Functions

 generateFilePaths ($fileName, $origFileName)
 Generates URL and full paths to file/directory.
 generateRelPath ($fileName, $origFileName)
 Generates base path using md5 hasing.


Detailed Description

This class represents a file that exists in the /media directory.

There are several things we may want to do with it.

Definition at line 14 of file SnapExternalFile.php5.


Constructor & Destructor Documentation

SnapExternalFile::__construct ( version,
array = "" 
)

Create a new SnapExternalFile attached to a version.

Parameters:
$version [SnapVersion]: version that this external file is associated with
$array [array]: array of information representing a file to be loaded (array comes from getArray())

Definition at line 28 of file SnapExternalFile.php5.

References load().


Member Function Documentation

SnapExternalFile::copy ( newName = ""  ) 

Creates a copy of this file.

The copy can have a different name if given as the sole parameter, otherwise, the old name is used.

Parameters:
$newName [string]: optional new name for copy
Returns:
[SnapExternalFile]: external file object representing copy of this file

Definition at line 292 of file SnapExternalFile.php5.

Referenced by create(), and unzip().

SnapExternalFile::create ( tmpFile,
originalName,
name = "" 
)

Creates an actual file on the file system.

Merely creating a SnapExternalFile object is not enough to create a file. You must either call load() to load in an existing file, or call create() to create a new file/directory.

Parameters:
$tmpFile [string]: path to source file to upload
$originalName [string]: basename of the file (as, e.g., uploaded by the user)
$name [string]: alternate name for the file to be stored for future use
Returns:
[boolean]: success or failure INSERT BRIEF DESCRIPTION HERE INSERT FULL DESCRIPTION HERE
Parameters:
$tmpFile [TYPE]: DESCRIPTION
$originalName [TYPE]: DESCRIPTION
$name [TYPE]: DESCRIPTION
Returns:
[TYPE]: RETURN DESCRIPTION

Definition at line 216 of file SnapExternalFile.php5.

References copy(), generateFilePaths(), and SObject::setError().

SnapExternalFile::delete (  ) 

Destroy this file.

Destroy the file on the filesystem.

Returns:
[boolean]: success or failure

Definition at line 313 of file SnapExternalFile.php5.

SnapExternalFile::generateFilePaths ( fileName,
origFileName 
) [private]

Generates URL and full paths to file/directory.

The URL is essentially "/media" plus the base path from generateRelPath(). The Path is essentially /var/www/html/media" plus the base path from generateRelPath(). The prefixes are derived from the Snap2 configuration.

Parameters:
$fileName [string]: path to source file on filesystem
$origFileName [string]: original name of file if different from what's in the path
Returns:
[array]: first element is URL and second element is filesystem path

Definition at line 391 of file SnapExternalFile.php5.

References generateRelPath().

Referenced by create().

SnapExternalFile::generateRelPath ( fileName,
origFileName 
) [private]

Generates base path using md5 hasing.

For internal use only.

Basically, the contents of the file (or listing of files in the directory) are combined with the current time, the name of the file and the original file name and hashed using MD5, which is then base64-encoded into a 32 character string. The first three characters are used as names in a hierarchy of directories and the remaining 29 characters form the filename, to which is appended the original suffix of the filename. All of this is used when uploading the files to the media directory. They need a hashed filename.

Parameters:
$fileName [string]: path to source file on filesystem
$origFileName [string]: original file name, should it differ from the actual filename given in $fileName
Returns:
[string]: base path to file

Definition at line 357 of file SnapExternalFile.php5.

References SObject::setError().

Referenced by generateFilePaths().

SnapExternalFile::getArray (  ) 

Retrieves "serialized" representation of the file.

The array returned from here is to be treated as opaque. It can be stored in Snap content, to be used to initialize a SnapExternalFile object in the future.

Returns:
[array]: representation of the file

Definition at line 126 of file SnapExternalFile.php5.

SnapExternalFile::getName (  ) 

Retrieves the real name of the file this object represents.

External files have a hashed named which is meaningless. The original name is stored so that it can be used later after it would otherwise be lost.

Returns:
[string]: original name

Definition at line 115 of file SnapExternalFile.php5.

SnapExternalFile::getPath (  ) 

Retrieves path on the server where file is located.

Returns:
[string]: server path to file

Definition at line 40 of file SnapExternalFile.php5.

SnapExternalFile::getURL (  ) 

Retrieves URL to file.

Returns:
[string]: URL to file

Definition at line 49 of file SnapExternalFile.php5.

SnapExternalFile::load ( array  ) 

Loads file information from serialized array generated by getArray().

Parameters:
$array [array]: representation of the file
Returns:
[boolean]: success or failure

Definition at line 135 of file SnapExternalFile.php5.

References SObject::setError().

Referenced by __construct().

SnapExternalFile::setAcceptable ( fileTypes  ) 

For directories: sets which file types are allowed to be contained in the directory.

This is useful for zipfiles, where we want to filter out invalid files in the zip (see weedFiles())

Parameters:
$fileTypes [array]: list of file suffixes that are acceptable
Returns:
[boolean]: success or failure

Definition at line 157 of file SnapExternalFile.php5.

References SObject::setError().

SnapExternalFile::unzip ( callIt  ) 

If this is a zipfile, unzips it into a new directory.

The new directory is represented by a SnapExternalFile, which is returned from this method. The original zipfile is not deleted.

Returns:
[SnapExternalFile]: external file object representing directory containing contents of unzipped file

Definition at line 60 of file SnapExternalFile.php5.

References copy().

SnapExternalFile::update ( tmpFile,
originalName,
name = "" 
)

Modifies existing file or changes its name.

Updating does not create new files, it just changes information about an existing file or changes the file itself, in place.

Parameters:
$tmpFile [string]: path to source file, or empty string if the file is not to be modified
$originalName [string]: original name of file, if that is to be modified
$name [string]: no idea why we even need this...
Returns:
[boolean]: success or failure

Definition at line 269 of file SnapExternalFile.php5.

SnapExternalFile::updateDB (  ) 

updates or inserts the file's path and id /*

For internal use only.

/*

Returns:
TRUE on success, FALSE on failure.

Definition at line 335 of file SnapExternalFile.php5.

SnapExternalFile::weedFiles ( directory = 'default'  ) 

For directories: weeds out files that do not belong to list of acceptable file types.

You can set the list of acceptable files types in setAcceptable().

Parameters:
$directory [string]: which directory to search for invalid files; defaults to directory represented by this SnapExternalFile object
Returns:
[boolean]: success or failure

Definition at line 174 of file SnapExternalFile.php5.


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 02:06:26 2010 for Common by  doxygen 1.5.6