static function create($contentclassAttributeID, $contentobjectID, $version = 1, $languageCode = false) { if ($languageCode == false) { $languageCode = eZContentObject::defaultLanguage(); } $languageID = eZContentLanguage::idByLocale($languageCode); $row = array("id" => null, "contentobject_id" => $contentobjectID, "version" => $version, "language_code" => $languageCode, 'language_id' => $languageID, "contentclassattribute_id" => $contentclassAttributeID, 'data_text' => '', 'data_int' => null, 'data_float' => 0.0); return new eZContentObjectAttribute($row); }
function instantiate($userID = false, $sectionID = 0, $versionNumber = false, $languageCode = false, $versionStatus = eZContentObjectVersion::STATUS_INTERNAL_DRAFT) { $attributes = $this->fetchAttributes(); if ($userID === false) { $user = eZUser::currentUser(); $userID = $user->attribute('contentobject_id'); } if ($languageCode == false) { $languageCode = eZContentObject::defaultLanguage(); } $object = eZContentObject::create(ezpI18n::tr("kernel/contentclass", "New %1", null, array($this->name($languageCode))), $this->attribute("id"), $userID, $sectionID, 1, $languageCode); if ($this->attribute('always_available')) { $object->setAttribute('language_mask', (int) $object->attribute('language_mask') | 1); } $db = eZDB::instance(); $db->begin(); $object->store(); $object->assignDefaultStates(); $object->setName(ezpI18n::tr("kernel/contentclass", "New %1", null, array($this->name($languageCode))), false, $languageCode); if (!$versionNumber) { $version = $object->createInitialVersion($userID, $languageCode); } else { $version = eZContentObjectVersion::create($object->attribute("id"), $userID, $versionNumber, $languageCode); } if ($versionStatus !== false) { $version->setAttribute('status', $versionStatus); } $version->store(); foreach ($attributes as $attribute) { $attribute->instantiate($object->attribute('id'), $languageCode); } if (isset($user) && $user instanceof eZUser && $user->isAnonymous()) { $createdObjectIDList = eZPreferences::value('ObjectCreationIDList'); if (!$createdObjectIDList) { $createdObjectIDList = array($object->attribute('id')); } else { $createdObjectIDList = unserialize($createdObjectIDList); $createdObjectIDList[] = $object->attribute('id'); } eZPreferences::setValue('ObjectCreationIDList', serialize($createdObjectIDList)); } $db->commit(); return $object; }
function createFolder( $parentNode, $target ) { // Grab settings from the ini file: $webdavINI = eZINI::instance( eZWebDAVContentServer::WEBDAV_INI_FILE ); $folderClassID = $webdavINI->variable( 'FolderSettings', 'FolderClass' ); $languageCode = eZContentObject::defaultLanguage(); $contentObject = eZContentObject::createWithNodeAssignment( $parentNode, $folderClassID, $languageCode ); if ( $contentObject ) { $db = eZDB::instance(); $db->begin(); $version = $contentObject->version( 1 ); $version->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT ); $version->store(); $contentObjectID = $contentObject->attribute( 'id' ); $contentObjectAttributes = $version->contentObjectAttributes(); $contentObjectAttributes[0]->setAttribute( 'data_text', basename( $target ) ); $contentObjectAttributes[0]->store(); $db->commit(); $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID, 'version' => 1 ) ); return eZWebDAVServer::OK_CREATED; } else { $this->appendLogEntry( "Not allowed", 'CS:createFolder' ); return eZWebDAVServer::FAILED_FORBIDDEN; } }
/** * Creates a new folder under the given $target path. * * @param eZContentObject $parentNode * @param string $target Eg. 'Folder1' * @return bool */ protected function createFolder($parentNode, $target) { // Grab settings from the ini file: $webdavINI = eZINI::instance(self::WEBDAV_INI_FILE); $folderClassID = $webdavINI->variable('FolderSettings', 'FolderClass'); $languageCode = eZContentObject::defaultLanguage(); $contentObject = eZContentObject::createWithNodeAssignment($parentNode, $folderClassID, $languageCode); if ($contentObject) { $db = eZDB::instance(); $db->begin(); $version = $contentObject->version(1); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $contentObjectID = $contentObject->attribute('id'); $contentObjectAttributes = $version->contentObjectAttributes(); // @todo @as avoid using [0] (could be another index in some classes) $contentObjectAttributes[0]->setAttribute('data_text', basename($target)); $contentObjectAttributes[0]->store(); $db->commit(); $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1)); return true; // @as self::OK_CREATED; } else { return false; // @as self::FAILED_FORBIDDEN; } }
/** * Creates a new content object instance and stores it. * * @param string $name * @param int $contentclassID * @param int $userID * @param int $sectionID * @param int $version * @param string|bool $languageCode * @return eZContentObject */ static function create( $name, $contentclassID, $userID, $sectionID = 1, $version = 1, $languageCode = false ) { if ( $languageCode == false ) { $languageCode = eZContentObject::defaultLanguage(); } $languageID = eZContentLanguage::idByLocale( $languageCode ); $row = array( "name" => $name, "current_version" => $version, 'initial_language_id' => $languageID, 'language_mask' => $languageID, "contentclass_id" => $contentclassID, "permission_id" => 1, "parent_id" => 0, "main_node_id" => 0, "owner_id" => $userID, "section_id" => $sectionID, 'remote_id' => eZRemoteIdUtility::generate( 'object' ) ); return new eZContentObject( $row ); }
/** * Fetches the uploaded file, figures out its MIME-type and creates the * proper content object out of it. * * @param array $result * Result 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 * @param string $httpFileIdentifier * The HTTP identifier of the uploaded file, this must match the * name of the input tag. * @param mixed $location * The node ID which the new object will be placed or the string * 'auto' for automatic placement of type. * @param eZContentObjectTreeNode|false $existingNode * Pass a contentobjecttreenode object to let the uploading be done * to an existing object, if not it will create one from scratch. * @param string $nameString * The name of the new object/new version * @param string|false $localeCode * Locale code (eg eng-GB, fre-FR, ...) to use when creating the * object or the version. * @param boolean $publish whether to publish the new created content object * * @return boolean */ function handleUpload(&$result, $httpFileIdentifier, $location, $existingNode, $nameString = '', $localeCode = false, $publish = true) { $result = array('errors' => array(), 'notices' => array(), 'result' => false, 'redirect_url' => false); $this->fetchHTTPFile($httpFileIdentifier, $result['errors'], $file, $mimeData); if (!$file) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'No HTTP file found, cannot fetch uploaded file.')); return false; } $mime = $mimeData['name']; if ($mime == '') { $mime = $file->attribute("mime_type"); } $handler = $this->findHandler($result, $mimeData); if ($handler === false) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'There was an error trying to instantiate content upload handler.')); return false; } // If this is an object we have a special handler for the file // The handler will be responsible for the rest of the execution. if (is_object($handler)) { $filePath = $file->attribute("filename"); $originalFilename = $file->attribute("original_filename"); $handlerResult = $handler->handleFile($this, $result, $filePath, $originalFilename, $mimeData, $location, $existingNode); if (is_object($result['contentobject'])) { return $handlerResult; } } $object = false; $class = false; // Figure out class identifier from an existing node // if not we will have to detect it from the mimetype if (is_object($existingNode)) { $object = $existingNode->object(); $class = $object->contentClass(); $classIdentifier = $class->attribute('identifier'); } else { $classIdentifier = $this->detectClassIdentifier($mime); } if (!$classIdentifier) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'No matching class identifier found.')); return false; } if (!is_object($class)) { $class = eZContentClass::fetchByIdentifier($classIdentifier); } if (!$class) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'The class %class_identifier does not exist.', null, array('%class_identifier' => $classIdentifier))); return false; } $parentNodes = false; $parentMainNode = false; // If do not have an existing node we need to figure // out the locations from $location and $classIdentifier if (!is_object($existingNode)) { $locationOK = $this->detectLocations($classIdentifier, $class, $location, $parentNodes, $parentMainNode); if ($locationOK === false) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'Was not able to figure out placement of object.')); return false; } elseif ($locationOK === null) { $result['status'] = eZContentUpload::STATUS_PERMISSION_DENIED; $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'Permission denied')); return false; } } $uploadINI = eZINI::instance('upload.ini'); $iniGroup = $classIdentifier . '_ClassSettings'; if (!$uploadINI->hasGroup($iniGroup)) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'No configuration group in upload.ini for class identifier %class_identifier.', null, array('%class_identifier' => $classIdentifier))); return false; } $fileAttribute = $uploadINI->variable($iniGroup, 'FileAttribute'); $dataMap = $class->dataMap(); if ($classIdentifier == 'image') { $classAttribute = $dataMap['image']; $maxSize = 1024 * 1024 * $classAttribute->attribute('data_int1'); if ($maxSize != 0 && $file->attribute('filesize') > $maxSize) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'The size of the uploaded file exceeds the limit set for this site: %1 bytes.', null, array($maxSize))); return false; } } $fileAttribute = $this->findHTTPFileAttribute($dataMap, $fileAttribute); if (!$fileAttribute) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'No matching file attribute found, cannot create content object without this.')); return false; } $nameAttribute = $uploadINI->variable($iniGroup, 'NameAttribute'); if (!$nameAttribute) { $nameAttribute = $this->findStringAttribute($dataMap, $nameAttribute); } if (!$nameAttribute) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'No matching name attribute found, cannot create content object without this.')); return false; } $variables = array('original_filename' => $file->attribute('original_filename'), 'mime_type' => $mime); $variables['original_filename_base'] = $mimeData['basename']; $variables['original_filename_suffix'] = $mimeData['suffix']; if (!$nameString) { $namePattern = $uploadINI->variable($iniGroup, 'NamePattern'); $nameString = $this->processNamePattern($variables, $namePattern); } $db = eZDB::instance(); $db->begin(); // If we have an existing node we need to create // a new version in it. // If we don't we have to make a new object if (is_object($existingNode)) { if ($existingNode->canEdit() != '1') { $result['status'] = eZContentUpload::STATUS_PERMISSION_DENIED; $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'Permission denied')); $db->commit(); return false; } $version = $object->createNewVersion(false, true, $localeCode); unset($dataMap); $dataMap = $version->dataMap(); $publishVersion = $version->attribute('version'); } else { $object = $class->instantiateIn($localeCode); unset($dataMap); $dataMap = $object->dataMap(); $publishVersion = $object->attribute('current_version'); } unset($dataMap); $dataMap = $object->dataMap(); if ($localeCode === false) { $localeCode = eZContentObject::defaultLanguage(); } $status = $dataMap[$fileAttribute]->insertHTTPFile($object, $publishVersion, $localeCode, $file, $mimeData, $storeResult); if ($status === null) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'The attribute %class_identifier does not support HTTP file storage.', null, array('%class_identifier' => $classIdentifier))); $db->commit(); return false; } else { if (!$status) { $result['errors'] = array_merge($result['errors'], $storeResult['errors']); $db->commit(); return false; } } if ($storeResult['require_storage']) { $dataMap[$fileAttribute]->store(); } $status = $dataMap[$nameAttribute]->insertSimpleString($object, $publishVersion, $localeCode, $nameString, $storeResult); if ($status === null) { $result['errors'][] = array('description' => ezpI18n::tr('kernel/content/upload', 'The attribute %class_identifier does not support simple string storage.', null, array('%class_identifier' => $classIdentifier))); $db->commit(); return false; } else { if (!$status) { $result['errors'] = array_merge($result['errors'], $storeResult['errors']); $db->commit(); return false; } } if ($storeResult['require_storage']) { $dataMap[$nameAttribute]->store(); } if (is_array($parentNodes)) { foreach ($parentNodes as $key => $parentNode) { $object->createNodeAssignment($parentNode, $parentNode == $parentMainNode); } } $object->setName($class->contentObjectName($object)); $object->store(); if ($publish) { $tmpresult = $this->publishObject($result, $result['errors'], $result['notices'], $object, $publishVersion, $class, $parentNodes, $parentMainNode); } else { $tmpresult = $result; $tmpresult['contentobject'] = $object; $tmpresult['contentobject_id'] = $object->attribute('id'); $tmpresult['contentobject_version'] = $publishVersion; $tmpresult['contentobject_main_node'] = false; $tmpresult['contentobject_main_node_id'] = false; $this->setResult(array('node_id' => 0, 'object_id' => $object->attribute('id'), 'object_version' => $publishVersion)); } $db->commit(); return $tmpresult; }
public function __construct(array $options = array()) { // Define some default values $this->properties = array('remote_id' => null, 'section_id' => 0, 'creator_id' => false, 'language' => eZContentObject::defaultLanguage(), 'class_identifier' => null); parent::__construct($options); }
static function create( $contentobjectID, $userID = false, $version = 1, $initialLanguageCode = false ) { if ( $userID === false ) { $user = eZUser::currentUser(); $userID = $user->attribute( 'contentobject_id' ); } $time = time(); if ( $initialLanguageCode == false ) { $initialLanguageCode = eZContentObject::defaultLanguage(); } $initialLanguageID = eZContentLanguage::idByLocale( $initialLanguageCode ); $row = array( "contentobject_id" => $contentobjectID, 'initial_language_id' => $initialLanguageID, 'language_mask' => $initialLanguageID, "version" => $version, "created" => $time, "modified" => $time, 'creator_id' => $userID ); return new eZContentObjectVersion( $row ); }
/** * Initializes a content fieldset holder from eZContentObject * @param eZContentObject $object * @return SQLIContentFieldsetHolder */ public static function fromContentObject(eZContentObject $object) { eZDebug::accumulatorStart('fieldset_holder_create', 'sqlicontent'); $setHolder = new self(); $languages = $object->allLanguages(); $setHolder->contentObject = $object; foreach ($languages as $lang) { $locale = $lang->attribute('locale'); $set = SQLIContentFieldset::fromDataMap($object->fetchDataMap(false, $locale)); $set->setLanguage($locale); $setHolder->fieldsets[$locale] = $set; } // Set default language $setHolder->setActiveLanguage(eZContentObject::defaultLanguage()); // Init internal iterator $setHolder->initIterator(); eZDebug::accumulatorStop('fieldset_holder_create'); return $setHolder; }