eZ Publish  [trunk]
eZContentUpload Class Reference

Handles simple creation of content objects by uploading files. More...

List of all members.

Public Member Functions

 attribute ($attributeName)
 attributes ()
 eZContentUpload ($params=false)
 fetchHTTPFile ($httpFileIdentifier, &$errors, &$file, &$mimeData)
 Fetches the HTTP-File into $file and fills in MIME-Type information into $mimeData.
 findHandler (&$result, $mimeInfo)
 handleLocalFile (&$result, $filePath, $location, $existingNode, $nameString= '', $localeCode=false)
 Fetches the local file, figures out its MIME-type and creates the proper content object out of it.
 handleUpload (&$result, $httpFileIdentifier, $location, $existingNode, $nameString= '', $localeCode=false)
 Fetches the uploaded file, figures out its MIME-type and creates the proper content object out of it.
 hasAttribute ($attributeName)
 objectFileInfo ($contentObject)
 setResult ($result)

Static Public Member Functions

static cleanup ($actionName)
 cleanupAll ()
 nodeAliasID ($nodeName)
static result ($actionName, $cleanup=true)
static upload ($parameters=array(), $module)

Public Attributes

 $Parameters = false
 The upload parameters.
const STATUS_PERMISSION_DENIED = 1

Private Member Functions

 detectLocations ($classIdentifier, $class, $location, &$parentNodes, &$parentMainNode)
 publishObject (&$result, &$errors, &$notices, $object, $publishVersion, $class, $parentNodes, $parentMainNode)

Static Private Member Functions

 checkAccess ($nodeID, $class)
 detectClassIdentifier ($mime)
 findHTTPFileAttribute ($dataMap, $fileAttribute)
 findRegularFileAttribute ($dataMap, $fileAttribute)
 findStringAttribute ($dataMap, $nameAttribute)
 processNamePattern ($variables, $namePattern)

Detailed Description

Handles simple creation of content objects by uploading files.

This class makes it easy to use the start a new file upload and let it be created as a content object.

Using it is simply to call the upload function with some parameters.

eZContentUpload::upload( array( 'action_name' => 'MyActionName' ), $module );

It requires the module objects as the second parameter to redirect and the first define how the upload page should behave. Normally you just want to set action_name and define the behaviour of that action in settings/upload.ini.

Fetching the result afterwards is done by calling the result() method, it will return the resulting node ID or object ID depending on the configuration of the upload action.

eZContentUpload::result( 'MyActionName' );

It is also possible to use this class to upload a given file (HTTP or regular) as an object. The correct class and location can be determined automatically.

Simply create an instance and then call handleUpload() or handleLocalFile().

$upload = new eZContentUpload();
$upload->handleUpload( $result, 'UploadFile', 'auto', false );

$upload->handleLocalFile( $result, 'a_yellow_flower.jpg', 'auto' );

Definition at line 48 of file ezcontentupload.php.


Member Function Documentation

eZContentUpload::attribute ( attributeName)
Returns:
the attribute value of the attribute named $attributeName or null if no such attribute.

Definition at line 91 of file ezcontentupload.php.

Referenced by detectLocations().

Returns:
an array with attribute names.

Definition at line 75 of file ezcontentupload.php.

eZContentUpload::checkAccess ( nodeID,
class 
) [static, private]

Definition at line 1126 of file ezcontentupload.php.

Referenced by detectLocations().

static eZContentUpload::cleanup ( actionName) [static]

Cleans up the persistent data and result for action named $actionName

Definition at line 1291 of file ezcontentupload.php.

Referenced by result().

Similar to cleanup() but removes persistent data from all actions.

Definition at line 1301 of file ezcontentupload.php.

eZContentUpload::detectClassIdentifier ( mime) [static, private]

Figures out the class which should be used for file with MIME-Type $mime and returns the class identifier.

Parameters:
$mimeA string defining the MIME-Type, will be used to determine class identifier.

Definition at line 964 of file ezcontentupload.php.

Referenced by handleLocalFile(), and handleUpload().

eZContentUpload::detectLocations ( classIdentifier,
class,
location,
&$  parentNodes,
&$  parentMainNode 
) [private]

Figures out the location(s) in which the class with the identifier $classIdentifier should be placed. The returned locations will either be a node ID or an identifier for a node (e.g. content).

Returns:
true if a location was found or false if no location could be determined
Parameters:
$classIdentifierIdentifier of class, is used to determine location
$locationThe wanted location, either use 'auto' for automatic placement or number to determine to parent node ID.
[out]$parentNodesWill contain an array with node IDs or identifiers if a location could be detected.
[out]$parentMainNodeWill contain the ID of the main node if a location could be detected.

Definition at line 1001 of file ezcontentupload.php.

Referenced by handleLocalFile(), and handleUpload().

Initializes the object with the session data if they are found. If $params is supplied it used instead.

Definition at line 57 of file ezcontentupload.php.

Referenced by result().

eZContentUpload::fetchHTTPFile ( httpFileIdentifier,
&$  errors,
&$  file,
&$  mimeData 
)

Fetches the HTTP-File into $file and fills in MIME-Type information into $mimeData.

Returns:
bool false if something went wrong.

Definition at line 822 of file ezcontentupload.php.

Referenced by handleUpload().

eZContentUpload::findHandler ( &$  result,
mimeInfo 
)

Finds the correct upload handler for the file specified in $mimeInfo. If no handler is found it will return the default attribute based handler eZContentUpload, this means that the file is passed to one suitable attribute and handled from there.

Returns:
An object with the interface eZContentUploadHandler or false if an error occured. Will return true if there is no handler configured for this type.

Definition at line 1314 of file ezcontentupload.php.

Referenced by handleLocalFile(), and handleUpload().

eZContentUpload::findHTTPFileAttribute ( dataMap,
fileAttribute 
) [static, private]

Checks if the attribute with the identifier $fileAttribute in $dataMap supports HTTP file uploading. If not it will go trough all attributes and find the first that has this support.

Returns:
The identifier of the matched attribute or false if none were found.
Parameters:
$dataMapAssociative array with class attributes, the key is attribute identifier
$fileAttributeThe identifier of the attribute that is expected to have the file datatype.

Definition at line 869 of file ezcontentupload.php.

Referenced by handleUpload().

eZContentUpload::findRegularFileAttribute ( dataMap,
fileAttribute 
) [static, private]

Checks if the attribute with the identifier $fileAttribute in $dataMap supports file uploading. If not it will go trough all attributes and find the first that has this support.

Returns:
The identifier of the matched attribute or false if none were found.
Parameters:
$dataMapAssociative array with class attributes, the key is attribute identifier
$fileAttributeThe identifier of the attribute that is expected to have the file datatype.

Definition at line 902 of file ezcontentupload.php.

Referenced by handleLocalFile(), and objectFileInfo().

eZContentUpload::findStringAttribute ( dataMap,
nameAttribute 
) [static, private]

Checks if the attribute with the identifier $nameAttribute in $dataMap supports string insertion. If not it will go trough all attributes and find the first that has this support.

Returns:
The identifier of the matched attribute or false if none were found.
Parameters:
$dataMapAssociative array with class attributes, the key is attribute identifier
$nameAttributeThe identifier of the attribute that is expected to have the string datatype.

Definition at line 935 of file ezcontentupload.php.

Referenced by handleLocalFile(), and handleUpload().

eZContentUpload::handleLocalFile ( &$  result,
filePath,
location,
existingNode,
nameString = '',
localeCode = false 
)

Fetches the local file, figures out its MIME-type and creates the proper content object out of it.

Parameters:
array$resultResult data, will be filled with information which the client can examine, contains: errors An array with errors, each element is an array with a 'description' entry containing the text
string$filePathPath to file which should be stored
mixed$locationThe node ID which the new object will be placed or the string 'auto' for automatic placement of type.
eZContentObjectTreeNode | false$existingNodePass a contentobjecttreenode object to let the uploading be done to an existing object, if not it will create one from scratch.
string$nameStringThe name of the new object/new version
string | false$localeCodeLocale code (eg eng-GB, fre-FR, ...) to use when creating the object or the version.
Returns:
boolean

Definition at line 217 of file ezcontentupload.php.

eZContentUpload::handleUpload ( &$  result,
httpFileIdentifier,
location,
existingNode,
nameString = '',
localeCode = false 
)

Fetches the uploaded file, figures out its MIME-type and creates the proper content object out of it.

Parameters:
array$resultResult data, will be filled with information which the client can examine, contains: errors An array with errors, each element is an array with a 'description' entry containing the text
string$httpFileIdentifierThe HTTP identifier of the uploaded file, this must match the name of the input tag.
mixed$locationThe node ID which the new object will be placed or the string 'auto' for automatic placement of type.
eZContentObjectTreeNode | false$existingNodePass a contentobjecttreenode object to let the uploading be done to an existing object, if not it will create one from scratch.
string$nameStringThe name of the new object/new version
string | false$localeCodeLocale code (eg eng-GB, fre-FR, ...) to use when creating the object or the version.
Returns:
boolean

Definition at line 457 of file ezcontentupload.php.

eZContentUpload::hasAttribute ( attributeName)
Returns:
true if the attribute name $attributeName is among the upload parameters.

Definition at line 83 of file ezcontentupload.php.

Referenced by detectLocations().

eZContentUpload::nodeAliasID ( nodeName) [static]
Returns:
the node ID for the node alias $nodeName or false if no ID could be found.

Definition at line 1209 of file ezcontentupload.php.

Referenced by detectLocations(), and upload().

eZContentUpload::objectFileInfo ( contentObject)

Finds the file attribute for object $contentObject and tries to extract file information using eZDataType::storedFileInformation().

Returns:
The information structure or false if it fails somehow.

Definition at line 787 of file ezcontentupload.php.

eZContentUpload::processNamePattern ( variables,
namePattern 
) [static, private]

Parses the name pattern $namePattern and replaces any variables found in $variables with the variable value.

Returns:
The resulting string with all tags replaced.
Parameters:
$variablesAn associative array where the key is variable name and element the variable value.
$namePatternA string containing of plain text or tags, each tag is enclosed in < and > and defines name of the variable to lookup.
     $vars = array( 'name' => 'A name',
                    'filename' => 'myfile.txt' );
     $name = $this->parseNamePattern( $vars, '<name> - <filename>' );
     print( $name ); // Will output 'A name - myfile.txt'

Definition at line 1158 of file ezcontentupload.php.

Referenced by handleLocalFile(), and handleUpload().

eZContentUpload::publishObject ( &$  result,
&$  errors,
&$  notices,
object,
publishVersion,
class,
parentNodes,
parentMainNode 
) [private]

Publishes the object to the selected locations.

Returns:
true if everything was OK, false if something failed.

Definition at line 712 of file ezcontentupload.php.

Referenced by handleLocalFile(), and handleUpload().

static eZContentUpload::result ( actionName,
cleanup = true 
) [static]
Returns:
the result of the previous upload operation or false if no result was found. It uses the action name $actionName to determine which result to look for.
Parameters:
$cleanupIf true it the persisten data is cleaned up by calling cleanup().

Definition at line 1267 of file ezcontentupload.php.

Referenced by checkRelationAssignments().

Sets the result array to $result and stores the session variable.

Definition at line 1254 of file ezcontentupload.php.

Referenced by publishObject().

static eZContentUpload::upload ( parameters = array(),
module 
) [static]

Sets some session data taken from $parameters and start the upload module by redirecting to it using $module. Most data will be automatically derived from the action_name value taken from settings/upload.ini, other values will override default values.

Definition at line 108 of file ezcontentupload.php.

Referenced by checkRelationActions().


Member Data Documentation

eZContentUpload::$Parameters = false

The upload parameters.

Definition at line 1371 of file ezcontentupload.php.


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