eZPublish  4.4
eZContentUpload Class Reference

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

Public Member Functions

 attribute ($attributeName)
 
 attributes ()
 
 eZContentUpload ($params=false)
 
 findHandler (&$result, $mimeInfo)
 
 handleLocalFile (&$result, $filePath, $location, $existingNode, $nameString= '')
 
 handleUpload (&$result, $httpFileIdentifier, $location, $existingNode, $nameString= '')
 
 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. More...
 
const STATUS_PERMISSION_DENIED = 1
 

Private Member Functions

 detectLocations ($classIdentifier, $class, $location, &$parentNodes, &$parentMainNode)
 
 fetchHTTPFile ($httpFileIdentifier, &$errors, &$file, &$mimeData)
 
 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->handleUpload( $result, 'UploadFile', 'auto', false );
$upload->handleLocalFile( $result, 'a_yellow_flower.jpg', 'auto' );

Member Function Documentation

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

Referenced by detectLocations().

eZContentUpload::attributes ( )
Returns
an array with attribute names.
eZContentUpload::checkAccess (   $nodeID,
  $class 
)
staticprivate

Referenced by detectLocations().

static eZContentUpload::cleanup (   $actionName)
static

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

Referenced by result().

eZContentUpload::cleanupAll ( )
static

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

eZContentUpload::detectClassIdentifier (   $mime)
staticprivate

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.

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.

Referenced by handleLocalFile(), and handleUpload().

eZContentUpload::eZContentUpload (   $params = false)

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

Referenced by result().

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

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

Returns
false if something went wrong.

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.

Referenced by handleLocalFile(), and handleUpload().

eZContentUpload::findHTTPFileAttribute (   $dataMap,
  $fileAttribute 
)
staticprivate

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.

Referenced by handleUpload().

eZContentUpload::findRegularFileAttribute (   $dataMap,
  $fileAttribute 
)
staticprivate

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.

Referenced by handleLocalFile(), and objectFileInfo().

eZContentUpload::findStringAttribute (   $dataMap,
  $nameAttribute 
)
staticprivate

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.

Referenced by handleLocalFile(), and handleUpload().

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

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

Parameters
$filePathPath to file which should be stored.
$resultResult data, will be filled with information which the client can examine, contains:
  • errors - An array with errors, each element is an array with 'description' containing the text
$locationThe node ID which the new object will be placed or the string 'auto' for automatic placement of type.
$existingNodePass a contentobjecttreenode object to let the uploading be done to an existing object, if not it will create one from scratch.
Returns
false if something failed or true if succesful.
Note
Transaction unsafe. If you call several transaction unsafe methods you must enclose the calls within a db transaction; thus within db->begin and db->commit.
eZContentUpload::handleUpload ( $result,
  $httpFileIdentifier,
  $location,
  $existingNode,
  $nameString = '' 
)

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

Parameters
$httpFileIdentifierThe HTTP identifier of the uploaded file, this must match the name of your input tag.
$resultResult data, will be filled with information which the client can examine, contains:
  • errors - An array with errors, each element is an array with 'description' containing the text
$locationThe node ID which the new object will be placed or the string 'auto' for automatic placement of type.
$existingNodePass a contentobjecttreenode object to let the uploading be done to an existing object, if not it will create one from scratch.
Returns
false if something failed or true if succesful.
Note
Transaction unsafe. If you call several transaction unsafe methods you must enclose the calls within a db transaction; thus within db->begin and db->commit.
eZContentUpload::hasAttribute (   $attributeName)
Returns
true if the attribute name $attributeName is among the upload parameters.

Referenced by detectLocations().

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

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.
eZContentUpload::processNamePattern (   $variables,
  $namePattern 
)
staticprivate

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'

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.

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().

Referenced by checkRelationAssignments().

eZContentUpload::setResult (   $result)

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

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.

Referenced by checkRelationActions().

Member Data Documentation

eZContentUpload::$Parameters = false

The upload parameters.

const eZContentUpload::STATUS_PERMISSION_DENIED = 1

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