本文整理汇总了PHP中eZNodeAssignment::create方法的典型用法代码示例。如果您正苦于以下问题:PHP eZNodeAssignment::create方法的具体用法?PHP eZNodeAssignment::create怎么用?PHP eZNodeAssignment::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZNodeAssignment
的用法示例。
在下文中一共展示了eZNodeAssignment::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createUser
/**
* Creates a user with provided auth data
*
* @param array $authResult
*
* @return bool|eZUser
*/
public static function createUser($authResult)
{
$ngConnectINI = eZINI::instance('ngconnect.ini');
$siteINI = eZINI::instance('site.ini');
$defaultUserPlacement = $ngConnectINI->variable('LoginMethod_' . $authResult['login_method'], 'DefaultUserPlacement');
$placementNode = eZContentObjectTreeNode::fetch($defaultUserPlacement);
if (!$placementNode instanceof eZContentObjectTreeNode) {
$defaultUserPlacement = $siteINI->variable('UserSettings', 'DefaultUserPlacement');
$placementNode = eZContentObjectTreeNode::fetch($defaultUserPlacement);
if (!$placementNode instanceof eZContentObjectTreeNode) {
return false;
}
}
$contentClass = eZContentClass::fetch($siteINI->variable('UserSettings', 'UserClassID'));
$userCreatorID = $siteINI->variable('UserSettings', 'UserCreatorID');
$defaultSectionID = $siteINI->variable('UserSettings', 'DefaultSectionID');
$db = eZDB::instance();
$db->begin();
$contentObject = $contentClass->instantiate($userCreatorID, $defaultSectionID);
$contentObject->store();
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObject->attribute('id'), 'contentobject_version' => 1, 'parent_node' => $placementNode->attribute('node_id'), 'is_main' => 1));
$nodeAssignment->store();
$currentTimeStamp = eZDateTime::currentTimeStamp();
/** @var eZContentObjectVersion $version */
$version = $contentObject->currentVersion();
$version->setAttribute('modified', $currentTimeStamp);
$version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
$version->store();
$dataMap = $version->dataMap();
self::fillUserObject($version->dataMap(), $authResult);
if (!isset($dataMap['user_account'])) {
$db->rollback();
return false;
}
$userLogin = 'ngconnect_' . $authResult['login_method'] . '_' . $authResult['id'];
$userPassword = (string) rand() . 'ngconnect_' . $authResult['login_method'] . '_' . $authResult['id'] . (string) rand();
$userExists = false;
if (eZUser::requireUniqueEmail()) {
$userExists = eZUser::fetchByEmail($authResult['email']) instanceof eZUser;
}
if (empty($authResult['email']) || $userExists) {
$email = md5('ngconnect_' . $authResult['login_method'] . '_' . $authResult['id']) . '@localhost.local';
} else {
$email = $authResult['email'];
}
$user = new eZUser(array('contentobject_id' => $contentObject->attribute('id'), 'email' => $email, 'login' => $userLogin, 'password_hash' => md5("{$userLogin}\n{$userPassword}"), 'password_hash_type' => 1));
$user->store();
$userSetting = new eZUserSetting(array('is_enabled' => true, 'max_login' => 0, 'user_id' => $contentObject->attribute('id')));
$userSetting->store();
$dataMap['user_account']->setContent($user);
$dataMap['user_account']->store();
$operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObject->attribute('id'), 'version' => $version->attribute('version')));
if (array_key_exists('status', $operationResult) && $operationResult['status'] == eZModuleOperationInfo::STATUS_CONTINUE) {
$db->commit();
return $user;
}
$db->rollback();
return false;
}
示例2: create
public function create($parentNodeId, $classIdentifier, $dataSet)
{
$result = array("result" => false);
$parentNode = eZContentObjectTreeNode::fetch($parentNodeId);
if (!is_object($parentNode)) {
throw new Exception("createObject::create(): Failed to locate parent node. id='" . $parentNodeId . "'");
}
$contentClass = eZContentClass::fetchByIdentifier($classIdentifier);
if (!$contentClass) {
throw new Exception("Failed to instantiate content class [" . $classIdentifier . "]");
}
// take care over clustered setups
$db = eZDB::instance();
$db->begin();
$contentObject = $contentClass->instantiate(false, 0, false);
$dataMap = $contentObject->attribute('data_map');
foreach ($dataSet as $key => $value) {
// attributes are lower case
$key = strtolower($key);
// if the field exists in the object, write to it
if (isset($dataMap[$key])) {
$dataMap[$key]->fromString($value);
$dataMap[$key]->store();
}
}
$contentObject->store();
$result["objectid"] = $contentObject->attribute('id');
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObject->attribute('id'), 'contentobject_version' => 1, 'parent_node' => $parentNodeId, 'is_main' => 1));
if (!$nodeAssignment) {
throw new Exception("createObject::create(): Failed to create matching node for object of class '" . $classIdentifier . "'");
}
$nodeAssignment->store();
$obj_version = $contentObject->currentVersion();
$publish = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObject->attribute('id'), 'version' => $obj_version->attribute('version')));
$db->commit();
$result["publish"] = $publish;
$result["parentnodeid"] = $parentNodeId;
$result["mainnodeid"] = $contentObject->mainNodeID();
$result["contentclass"] = $classIdentifier;
$result["contentobjectid"] = $contentObject->attribute('id');
$result["result"] = true;
return $result;
}
示例3: copyObject
function copyObject($Module, $object, $allVersions, $newParentNodeID)
{
if (!$newParentNodeID) {
return $Module->redirectToView('view', array('full', 2));
}
// check if we can create node under the specified parent node
if (($newParentNode = eZContentObjectTreeNode::fetch($newParentNodeID)) === null) {
return $Module->redirectToView('view', array('full', 2));
}
$classID = $object->attribute('contentclass_id');
if (!$newParentNode->checkAccess('create', $classID)) {
$objectID = $object->attribute('id');
eZDebug::writeError("Cannot copy object {$objectID} to node {$newParentNodeID}, " . "the current user does not have create permission for class ID {$classID}", 'content/copy');
return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
}
$db = eZDB::instance();
$db->begin();
$newObject = $object->copy($allVersions);
// We should reset section that will be updated in updateSectionID().
// If sectionID is 0 then the object has been newly created
$newObject->setAttribute('section_id', 0);
$newObject->store();
$curVersion = $newObject->attribute('current_version');
$curVersionObject = $newObject->attribute('current');
$newObjAssignments = $curVersionObject->attribute('node_assignments');
unset($curVersionObject);
// remove old node assignments
foreach ($newObjAssignments as $assignment) {
$assignment->purge();
}
// and create a new one
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $newObject->attribute('id'), 'contentobject_version' => $curVersion, 'parent_node' => $newParentNodeID, 'is_main' => 1));
$nodeAssignment->store();
// publish the newly created object
eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $curVersion));
// Update "is_invisible" attribute for the newly created node.
$newNode = $newObject->attribute('main_node');
eZContentObjectTreeNode::updateNodeVisibility($newNode, $newParentNode);
$db->commit();
return $Module->redirectToView('view', array('full', $newParentNodeID));
}
示例4: createObject
function createObject($classIdentifier, $parentNodeID, $name)
{
$user = eZUser::currentUser();
$Class = eZContentClass::fetchByIdentifier($classIdentifier);
if (!$Class) {
eZDebug::writeError("No class with identifier {$classIdentifier}", "classCreation");
return false;
}
$contentObject = $Class->instantiate($user->attribute('contentobject_id'));
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObject->attribute('id'), 'contentobject_version' => $contentObject->attribute('current_version'), 'parent_node' => $parentNodeID, 'is_main' => 1));
$nodeAssignment->store();
$version = $contentObject->version(1);
$version->setAttribute('modified', eZDateTime::currentTimeStamp());
$version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
$version->store();
$contentObjectID = $contentObject->attribute('id');
$attributes = $contentObject->attribute('contentobject_attributes');
$attributes[0]->fromString($name);
$attributes[0]->store();
$operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1));
return true;
}
示例5: onPublish
function onPublish($contentObjectAttribute, $contentObject, $publishedNodes)
{
$content = $contentObjectAttribute->content();
foreach ($content['relation_browse'] as $key => $relationItem) {
if ($relationItem['is_modified']) {
$subObjectID = $relationItem['contentobject_id'];
$subObjectVersion = $relationItem['contentobject_version'];
$object = eZContentObject::fetch($subObjectID);
if ($object) {
$class = $object->contentClass();
$time = time();
// Make the previous version archived
$currentVersion = $object->currentVersion();
$currentVersion->setAttribute('status', eZContentObjectVersion::STATUS_ARCHIVED);
$currentVersion->setAttribute('modified', $time);
$currentVersion->store();
$version = eZContentObjectVersion::fetchVersion($subObjectVersion, $subObjectID);
$version->setAttribute('modified', $time);
$version->setAttribute('status', eZContentObjectVersion::STATUS_PUBLISHED);
$version->store();
$object->setAttribute('status', eZContentObject::STATUS_PUBLISHED);
if (!$object->attribute('published')) {
$object->setAttribute('published', $time);
}
$object->setAttribute('modified', $time);
$object->setAttribute('current_version', $version->attribute('version'));
$object->setAttribute('is_published', true);
$objectName = $class->contentObjectName($object, $version->attribute('version'));
$object->setName($objectName, $version->attribute('version'));
$object->store();
}
if ($relationItem['parent_node_id'] > 0) {
if (!eZNodeAssignment::fetch($object->attribute('id'), $object->attribute('current_version'), $relationItem['parent_node_id'], false)) {
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $relationItem['parent_node_id'], 'sort_field' => 2, 'sort_order' => 0, 'is_main' => 1));
$nodeAssignment->store();
}
$operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $object->attribute('id'), 'version' => $object->attribute('current_version')));
$objectNodeID = $object->attribute('main_node_id');
$content['relation_browse'][$key]['node_id'] = $objectNodeID;
} else {
if (!eZNodeAssignment::fetch($object->attribute('id'), $object->attribute('current_version'), $contentObject->attribute('main_node_id'), false)) {
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $contentObject->attribute('main_node_id'), 'sort_field' => 2, 'sort_order' => 0, 'is_main' => 1));
$nodeAssignment->store();
}
}
$content['relation_browse'][$key]['is_modified'] = false;
}
}
eZObjectRelationBrowseType::storeObjectAttributeContent($contentObjectAttribute, $content);
$contentObjectAttribute->setContent($content);
$contentObjectAttribute->store();
}
示例6: handleNodeTemplate
function handleNodeTemplate( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $tpl )
{
// When the object has been published we will use the nodes as
// node-assignments by faking the list, this is required since new
// version of the object does not have node-assignments/
// When the object is a draft we use the normal node-assignment list
$assignedNodeArray = array();
$versionedAssignedNodeArray = $version->attribute( 'parent_nodes' );
$parentNodeIDMap = array();
$nodes = $object->assignedNodes();
$i = 0;
foreach ( $nodes as $node )
{
$data = array( 'id' => null,
'contentobject_id' => $object->attribute( 'id' ),
'contentobject_version' => $version->attribute( 'version' ),
'parent_node' => $node->attribute( 'parent_node_id' ),
'sort_field' => $node->attribute( 'sort_field' ),
'sort_order' => $node->attribute( 'sort_order' ),
'is_main' => ( $node->attribute( 'main_node_id' ) == $node->attribute( 'node_id' ) ? 1 : 0 ),
'parent_remote_id' => $node->attribute( 'remote_id' ),
'op_code' => eZNodeAssignment::OP_CODE_NOP );
$assignment = eZNodeAssignment::create( $data );
$assignedNodeArray[$i] = $assignment;
$parentNodeIDMap[$node->attribute( 'parent_node_id' )] = $i;
++$i;
}
foreach ( $versionedAssignedNodeArray as $nodeAssignment )
{
$opCode = $nodeAssignment->attribute( 'op_code' );
if ( ( $opCode & 1 ) == eZNodeAssignment::OP_CODE_NOP ) // If the execute bit is not set it will be ignored.
{
continue;
}
// Only add assignments whose parent is not present in the published nodes.
if ( isset( $parentNodeIDMap[$nodeAssignment->attribute( 'parent_node' )] ) )
{
if ( $opCode == eZNodeAssignment::OP_CODE_CREATE ) // CREATE entries are just skipped
{
continue;
}
// Or if they have an op_code (move,remove) set, in which case they overwrite the entry
$index = $parentNodeIDMap[$nodeAssignment->attribute( 'parent_node' )];
$assignedNodeArray[$index]->setAttribute( 'id', $nodeAssignment->attribute( 'id' ) );
$assignedNodeArray[$index]->setAttribute( 'from_node_id', $nodeAssignment->attribute( 'from_node_id' ) );
$assignedNodeArray[$index]->setAttribute( 'remote_id', $nodeAssignment->attribute( 'remote_id' ) );
$assignedNodeArray[$index]->setAttribute( 'op_code', $nodeAssignment->attribute( 'op_code' ) );
continue;
}
if ( $opCode == eZNodeAssignment::OP_CODE_REMOVE ||
$opCode == eZNodeAssignment::OP_CODE_MOVE )
{
// The node-assignment has a remove/move operation but the node does not exist.
// We will not show it in this case.
continue;
}
$assignedNodeArray[$i] = $nodeAssignment;
++$i;
}
eZDebugSetting::writeDebug( 'kernel-content-edit', $assignedNodeArray, "assigned nodes array" );
$remoteMap = array();
$db = eZDB::instance();
$db->begin();
foreach ( $assignedNodeArray as $assignedNodeKey => $assignedNode )
{
$node = $assignedNode->getParentNode();
if ( $node !== null )
{
$remoteID = $assignedNode->attribute( 'remote_id' );
if ( $remoteID > 0 )
{
if ( isset( $remoteMap[$remoteID] ) )
{
if ( is_array( $remoteMap[$remoteID] ) )
{
$remoteMap[$remoteID][] = $assignedNode;
}
else
{
$currentRemote = $remoteMap[$remoteID];
unset( $remoteMap[$remoteID] );
$remoteMap[$remoteID] = array();
$remoteMap[$remoteID][] = $currentRemote;
$remoteMap[$remoteID][] = $assignedNode;
}
}
else
{
$remoteMap[$remoteID] = $assignedNode;
}
}
}
else
{
$assignedNode->purge();
if( isset( $assignedNodeArray[$assignedNodeKey] ) )
unset( $assignedNodeArray[$assignedNodeKey] );
}
}
//.........这里部分代码省略.........
示例7: setupAssignments
function setupAssignments( $parameters )
{
$parameters = array_merge( array( 'group-name' => false,
'default-variable-name' => false,
'specific-variable-name' => false,
'fallback-node-id' => false,
'section-id-wanted' => false ),
$parameters );
if ( !$parameters['group-name'] and
!$parameters['default-variable-name'] and
!$parameters['specific-variable-name'] )
return false;
$contentINI = eZINI::instance( 'content.ini' );
$defaultAssignment = $contentINI->variable( $parameters['group-name'], $parameters['default-variable-name'] );
$specificAssignments = $contentINI->variable( $parameters['group-name'], $parameters['specific-variable-name'] );
$hasAssignment = false;
$assignments = false;
$sectionIDWanted = $parameters['section-id-wanted'];
$sectionID = 0;
$contentClass = $this->CurrentObject->attribute( 'content_class' );
$contentClassIdentifier = $contentClass->attribute( 'identifier' );
$contentClassID = $contentClass->attribute( 'id' );
foreach ( $specificAssignments as $specificAssignment )
{
$assignmentRules = explode( ';', $specificAssignment );
$classMatches = $assignmentRules[0];
$assignments = $assignmentRules[1];
$mainID = false;
if ( isset( $assignmentRules[2] ) )
$mainID = $assignmentRules[2];
$classMatchArray = explode( ',', $classMatches );
foreach ( $classMatchArray as $classMatch )
{
$classMatch = trim( $classMatch );
if ( preg_match( "#^group_([0-9]+)$#", $classMatch, $matches ) )
{
$classGroupID = $matches[1];
if ( $contentClass->inGroup( $classGroupID ) )
{
$hasAssignment = true;
break;
}
}
else if ( $classMatch == $contentClassIdentifier )
{
$hasAssignment = true;
break;
}
else if ( $classMatch == $contentClassID )
{
$hasAssignment = true;
break;
}
}
if ( $hasAssignment )
break;
}
if ( !$hasAssignment )
{
$assignmentRules = explode( ';', $defaultAssignment );
$assignments = $assignmentRules[0];
$mainID = false;
if ( isset( $assignmentRules[1] ) )
$mainID = $assignmentRules[1];
}
eZDebug::writeDebug( $assignments, 'assignments' );
if ( $assignments )
{
if ( $mainID )
$mainID = $this->nodeID( $mainID );
$nodeList = $this->nodeIDList( $assignments );
eZDebug::writeDebug( $nodeList, 'nodeList' );
$assignmentCount = 0;
eZDebug::writeDebug( $this->CurrentObject->attribute( 'id' ), 'current object' );
eZDebug::writeDebug( $this->CurrentVersion->attribute( 'version' ), 'current version' );
foreach ( $nodeList as $nodeID )
{
$node = eZContentObjectTreeNode::fetch( $nodeID );
if ( !$node )
continue;
$parentContentObject = $node->attribute( 'object' );
eZDebug::writeDebug( "Checking for '$nodeID'" );
if ( $parentContentObject->checkAccess( 'create',
$contentClassID,
$parentContentObject->attribute( 'contentclass_id' ) ) == '1' )
{
eZDebug::writeDebug( "Adding to '$nodeID' and main = '$mainID'" );
if ( $mainID === false )
{
$isMain = ( $assignmentCount == 0 );
}
else
$isMain = ( $mainID == $nodeID );
/* Here we figure out the section ID in case it is needed
* to assign a newly created object to. */
if ( $sectionIDWanted and $isMain )
{
$db = eZDB::instance();
//.........这里部分代码省略.........
示例8: onPublish
function onPublish($contentObjectAttribute, $contentObject, $publishedNodes)
{
$content = $contentObjectAttribute->content();
foreach ($content['relation_list'] as $key => $relationItem) {
if ($relationItem['is_modified']) {
$subObjectID = $relationItem['contentobject_id'];
$subObjectVersion = $relationItem['contentobject_version'];
$object = eZContentObject::fetch($subObjectID);
$time = time();
$version = eZContentObjectVersion::fetchVersion($subObjectVersion, $subObjectID);
$version->setAttribute('modified', $time);
$version->store();
if ($relationItem['parent_node_id'] > 0) {
// action 1: edit a normal object
if (!eZNodeAssignment::fetch($object->attribute('id'), $object->attribute('current_version'), $relationItem['parent_node_id'], false)) {
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $relationItem['parent_node_id'], 'sort_field' => eZContentObjectTreeNode::SORT_FIELD_PUBLISHED, 'sort_order' => eZContentObjectTreeNode::SORT_ORDER_DESC, 'is_main' => 1));
$nodeAssignment->store();
}
$operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $object->attribute('id'), 'version' => $subObjectVersion));
$objectNodeID = $object->attribute('main_node_id');
$content['relation_list'][$key]['node_id'] = $objectNodeID;
} else {
// action 2: edit a nodeless object (or creating a new node
// Make the previous version archived
$currentVersion = $object->currentVersion();
$currentVersion->setAttribute('status', eZContentObjectVersion::STATUS_ARCHIVED);
$currentVersion->setAttribute('modified', $time);
$currentVersion->store();
$version->setAttribute('status', eZContentObjectVersion::STATUS_PUBLISHED);
$version->store();
$object->setAttribute('status', eZContentObject::STATUS_PUBLISHED);
if (!$object->attribute('published')) {
$object->setAttribute('published', $time);
}
$object->setAttribute('modified', $time);
$object->setAttribute('current_version', $subObjectVersion);
$class = $object->contentClass();
$objectName = $class->contentObjectName($object, $version->attribute('version'));
$object->setName($objectName, $version->attribute('version'));
$object->store();
if (!eZNodeAssignment::fetch($object->attribute('id'), $object->attribute('current_version'), $contentObject->attribute('main_node_id'), false)) {
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $contentObject->attribute('main_node_id'), 'sort_field' => eZContentObjectTreeNode::SORT_FIELD_PUBLISHED, 'sort_order' => eZContentObjectTreeNode::SORT_ORDER_DESC, 'is_main' => 1));
$nodeAssignment->store();
}
}
$content['relation_list'][$key]['is_modified'] = false;
}
}
$this->storeObjectAttributeContent($contentObjectAttribute, $content);
$contentObjectAttribute->setContent($content);
$contentObjectAttribute->store();
}
示例9: copyObjectSameDirectory
/**
* Copies the specified object to the same folder, with optional $destinationName.
*
* @param eZContentObject $object
* @param eZContentObject $newParentNode
* @param string $destinationName
* @return bool
*/
protected function copyObjectSameDirectory($object, $newParentNode, $destinationName = null)
{
$object = $object->ContentObject;
$newParentNodeID = $newParentNode->attribute('node_id');
$classID = $object->attribute('contentclass_id');
if (!$newParentNode->checkAccess('create', $classID)) {
$objectID = $object->attribute('id');
return false;
}
$db = eZDB::instance();
$db->begin();
$newObject = $object->copy(true);
// We should reset section that will be updated in updateSectionID().
// If sectionID is 0 than the object has been newly created
$newObject->setAttribute('section_id', 0);
// @as 2009-01-08 - Added check for destination name the same as the source name
// (this was causing problems with nodes disappearing after renaming)
$newName = $destinationName;
if ($destinationName === null || strtolower($destinationName) === strtolower($object->attribute('name'))) {
$newName = 'Copy of ' . $object->attribute('name');
}
// @todo @as avoid using [0] (could be another index in some classes)
$contentObjectAttributes = $newObject->contentObjectAttributes();
$contentObjectAttributes[0]->setAttribute('data_text', $newName);
$contentObjectAttributes[0]->store();
$newObject->store();
$curVersion = $newObject->attribute('current_version');
$curVersionObject = $newObject->attribute('current');
$newObjAssignments = $curVersionObject->attribute('node_assignments');
unset($curVersionObject);
// remove old node assignments
foreach ($newObjAssignments as $assignment) {
$assignment->purge();
}
// and create a new one
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $newObject->attribute('id'), 'contentobject_version' => $curVersion, 'parent_node' => $newParentNodeID, 'is_main' => 1));
$nodeAssignment->store();
// publish the newly created object
eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $curVersion));
// Update "is_invisible" attribute for the newly created node.
$newNode = $newObject->attribute('main_node');
eZContentObjectTreeNode::updateNodeVisibility($newNode, $newParentNode);
$db->commit();
return true;
}
示例10: loginUser
static function loginUser($login, $password, $authenticationMatch = false)
{
$http = eZHTTPTool::instance();
$db = eZDB::instance();
if ($authenticationMatch === false) {
$authenticationMatch = eZUser::authenticationMatch();
}
$loginEscaped = $db->escapeString($login);
$passwordEscaped = $db->escapeString($password);
$loginArray = array();
if ($authenticationMatch & eZUser::AUTHENTICATE_LOGIN) {
$loginArray[] = "login='{$loginEscaped}'";
}
if ($authenticationMatch & eZUser::AUTHENTICATE_EMAIL) {
$loginArray[] = "email='{$loginEscaped}'";
}
if (count($loginArray) == 0) {
$loginArray[] = "login='{$loginEscaped}'";
}
$loginText = implode(' OR ', $loginArray);
$contentObjectStatus = eZContentObject::STATUS_PUBLISHED;
$ini = eZINI::instance();
$textFileIni = eZINI::instance('textfile.ini');
$databaseName = $db->databaseName();
// if mysql
if ($databaseName === 'mysql') {
$query = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n FROM ezuser, ezcontentobject\n WHERE ( {$loginText} ) AND\n ezcontentobject.status='{$contentObjectStatus}' AND\n ( ezcontentobject.id=contentobject_id OR ( password_hash_type=4 AND ( {$loginText} ) AND password_hash=PASSWORD('{$passwordEscaped}') ) )";
} else {
$query = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n FROM ezuser, ezcontentobject\n WHERE ( {$loginText} ) AND\n ezcontentobject.status='{$contentObjectStatus}' AND\n ezcontentobject.id=contentobject_id";
}
$users = $db->arrayQuery($query);
$exists = false;
if (count($users) >= 1) {
foreach ($users as $userRow) {
$userID = $userRow['contentobject_id'];
$hashType = $userRow['password_hash_type'];
$hash = $userRow['password_hash'];
$exists = eZUser::authenticateHash($userRow['login'], $password, eZUser::site(), $hashType, $hash);
// If hash type is MySql
if ($hashType == eZUser::PASSWORD_HASH_MYSQL and $databaseName === 'mysql') {
$queryMysqlUser = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n FROM ezuser, ezcontentobject\n WHERE ezcontentobject.status='{$contentObjectStatus}' AND\n password_hash_type=4 AND ( {$loginText} ) AND password_hash=PASSWORD('{$passwordEscaped}') ";
$mysqlUsers = $db->arrayQuery($queryMysqlUser);
if (count($mysqlUsers) >= 1) {
$exists = true;
}
}
eZDebugSetting::writeDebug('kernel-user', eZUser::createHash($userRow['login'], $password, eZUser::site(), $hashType), "check hash");
eZDebugSetting::writeDebug('kernel-user', $hash, "stored hash");
// If current user has been disabled after a few failed login attempts.
$canLogin = eZUser::isEnabledAfterFailedLogin($userID);
if ($exists) {
// We should store userID for warning message.
$GLOBALS['eZFailedLoginAttemptUserID'] = $userID;
$userSetting = eZUserSetting::fetch($userID);
$isEnabled = $userSetting->attribute("is_enabled");
if ($hashType != eZUser::hashType() and strtolower($ini->variable('UserSettings', 'UpdateHash')) == 'true') {
$hashType = eZUser::hashType();
$hash = eZUser::createHash($login, $password, eZUser::site(), $hashType);
$db->query("UPDATE ezuser SET password_hash='{$hash}', password_hash_type='{$hashType}' WHERE contentobject_id='{$userID}'");
}
break;
}
}
}
if ($exists and $isEnabled and $canLogin) {
eZDebugSetting::writeDebug('kernel-user', $userRow, 'user row');
$user = new eZUser($userRow);
eZDebugSetting::writeDebug('kernel-user', $user, 'user');
$userID = $user->attribute('contentobject_id');
eZUser::updateLastVisit($userID);
eZUser::setCurrentlyLoggedInUser($user, $userID);
// Reset number of failed login attempts
eZUser::setFailedLoginAttempts($userID, 0);
return $user;
} else {
if ($textFileIni->variable('TextFileSettings', 'TextFileEnabled') == "true") {
$fileName = $textFileIni->variable('TextFileSettings', 'FileName');
$filePath = $textFileIni->variable('TextFileSettings', 'FilePath');
$defaultUserPlacement = $ini->variable("UserSettings", "DefaultUserPlacement");
$separator = $textFileIni->variable("TextFileSettings", "FileFieldSeparator");
$loginColumnNr = $textFileIni->variable("TextFileSettings", "LoginAttribute");
$passwordColumnNr = $textFileIni->variable("TextFileSettings", "PasswordAttribute");
$emailColumnNr = $textFileIni->variable("TextFileSettings", "EmailAttribute");
$lastNameColumnNr = $textFileIni->variable("TextFileSettings", "LastNameAttribute");
$firstNameColumnNr = $textFileIni->variable("TextFileSettings", "FirstNameAttribute");
if ($textFileIni->hasVariable('TextFileSettings', 'DefaultUserGroupType')) {
$UserGroupType = $textFileIni->variable('TextFileSettings', 'DefaultUserGroupType');
$UserGroup = $textFileIni->variable('TextFileSettings', 'DefaultUserGroup');
}
if ($UserGroupType != null) {
if ($UserGroupType == "name") {
$groupName = $UserGroup;
$groupQuery = "SELECT ezcontentobject_tree.node_id\n FROM ezcontentobject, ezcontentobject_tree\n WHERE ezcontentobject.name='{$groupName}'\n AND ezcontentobject.id=ezcontentobject_tree.contentobject_id";
$groupObject = $db->arrayQuery($groupQuery);
if (count($groupObject) > 0) {
$defaultUserPlacement = $groupObject[0]['node_id'];
}
} else {
if ($UserGroupType == "id") {
$groupID = $UserGroup;
//.........这里部分代码省略.........
示例11: createCopy
/**
* Creates a copy of $sourceObject
* @param eZContentObject $sourceObject
* @return eZContentObject
*/
protected function createCopy(eZContentObject $sourceObject)
{
$db = eZDB::instance();
$db->begin();
$newObject = $sourceObject->copy();
$newObject->setAttribute('section_id', 0);
$newObject->store();
$curVersion = $newObject->attribute('current_version');
$curVersionObject = $newObject->attribute('current');
$newObjAssignments = $curVersionObject->attribute('node_assignments');
// remove old node assignments
foreach ($newObjAssignments as $assignment) {
$assignment->purge();
}
// and create a new one
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $newObject->attribute('id'), 'contentobject_version' => $curVersion, 'parent_node' => 2, 'is_main' => 1));
$nodeAssignment->store();
// publish the newly created object
eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $curVersion));
$db->commit();
return $this->forceFetchContentObject($newObject->attribute('id'));
}
示例12: array
static function &loginUser($login, $password, $authenticationMatch = false)
{
#read configuration
$SERVERS = array();
$ini =& eZINI::instance('imapuser.ini');
$blocks = $ini->groups();
foreach ($blocks as $key => $variables) {
if (preg_match('/SERVER:(?P<server>.*)/', $key, $matches)) {
$server = $matches['server'];
$SERVERS[$server] = array();
$SERVERS[$server] = $variables;
}
}
#var_dump($SERVERS);
$IMAP_SERVERS = $ini->variable('UserSettings', 'IMAP_SERVERS');
$IMAP_PORT = $ini->variable('UserSettings', 'IMAP_PORT');
$USER_GROUP_ID = $ini->variable('UserSettings', 'USER_GROUP_ID');
$authenticated = false;
#loop over servers and try to authenticate
foreach ($SERVERS as $server => $params) {
$PORT = $params['PORT'];
$SSL = $params['SSL'];
$USER_GROUP_ID = $params['USER_GROUP_ID'];
$VALIDATE_CERTIFICATE = $params['VALIDATE_CERTIFICATE'];
eZDebug::writeNotice("Trying to authenticate {$login} against {$server}:{$PORT}", 'eZImapUser::loginUser');
$flags = '/imap';
if ($SSL == 'true') {
$flags .= '/ssl';
}
if ($VALIDATE_CERTIFICATE == 'false') {
$flags .= '/novalidate-cert';
}
$identifier = '{' . $server . ':' . $PORT . $flags . '}';
#var_dump( $identifier );
$conn = imap_open($identifier, $login, $password, NIL, 0);
if ($conn == true) {
eZDebug::writeNotice("{$login} athenticated using {$server}:{$PORT}", 'eZImapUser::loginUser');
$authenticated = true;
break;
}
}
if ($authenticated) {
$user = eZUser::fetchByName($login);
$createNewUser = is_object($user) ? false : true;
if ($createNewUser) {
#create user
$ini = eZINI::instance();
$userClassID = $ini->variable("UserSettings", "UserClassID");
$userCreatorID = $ini->variable("UserSettings", "UserCreatorID");
$defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID");
$class = eZContentClass::fetch($userClassID);
$contentObject = $class->instantiate($userCreatorID, $defaultSectionID);
$contentObject->store();
$userID = $contentObjectID = $contentObject->attribute('id');
$version = $contentObject->version(1);
$version->setAttribute('modified', time());
$version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
$version->store();
$user = eZImapUser::create($userID);
$user->setAttribute('login', $login);
$user->setAttribute('email', $login . '@' . $server);
#set unusable password
$user->setAttribute('password_hash', "");
$user->setAttribute('password_hash_type', 0);
$user->store();
#set group
$newNodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $USER_GROUP_ID, 'is_main' => 1));
$newNodeAssignment->store();
$operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1));
#overwrite default name, which is generated based on first name and second name which we don't have here
$contentObject->setName($login);
$contentObject->setAttribute('published', time());
$contentObject->setAttribute('modified', time());
$contentObject->store();
}
eZUser::setCurrentlyLoggedInUser($user, $user->attribute('contentobject_id'));
return $user;
} else {
return false;
}
}
示例13: time
$user = eZUser::currentUser();
$userID = $user->attribute('contentobject_id');
$sectionID = $parentContentObject->attribute('section_id');
$db = eZDB::instance();
$db->begin();
$object = $class->instantiate($userID, $sectionID);
$ObjectID = $object->attribute('id');
$version = $object->currentVersion();
$EditVersion = $version->attribute('version');
$EditLanguage = false;
$time = time();
$version->setAttribute('created', $time);
$version->setAttribute('modified', $time);
$object->setAttribute('modified', $time);
$dataMap = $version->dataMap();
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $node->attribute('node_id'), 'sort_field' => $class->attribute('sort_field'), 'sort_order' => $class->attribute('sort_order'), 'is_main' => 1));
if ($http->hasPostVariable('AssignmentRemoteID')) {
$nodeAssignment->setAttribute('remote_id', $http->postVariable('AssignmentRemoteID'));
}
$nodeAssignment->store();
/*
handle attribute values
conversion scheme:
powercontent_[attributeidentifier]_[normalpostvariablename]
where the attribute id in normalpostvariablename has been replaced with 'pcattributeid'
*/
$postVariables = $_POST;
$usedAttributes = array();
foreach ($postVariables as $postName => $postValue) {
示例14: updateObject
/**
* Updates content object
*
* @param $params array(
* 'object' => eZContentObject Content object
* 'attributes' => array( Content object`s attributes
* string identifier => string stringValue
* ),
* 'parentNode' => eZContentObjectTreeNode Parent node object, not necessary
* 'parentNodeID' => int Content object`s parent node ID, not necessary
* 'additionalParentNodeIDs' => array additionalParentNodeIDs, Additional parent node ids
* 'visibility' => bool Nodes visibility
* )
* @return bool true if object was updated, otherwise false
*/
public function updateObject($params)
{
$this->db->begin();
$object = $params['object'];
if ($object instanceof eZContentObject === false) {
$this->error('Content object is empty');
$this->db->rollback();
return false;
}
$this->debug('Starting update "' . $object->attribute('name') . '" object (class: ' . $object->attribute('class_name') . ') with remote ID ' . $object->attribute('remote_id'));
$visibility = isset($params['visibility']) ? (bool) $params['visibility'] : true;
$parentNode = false;
if (isset($params['parentNode'])) {
$parentNode = $params['parentNode'];
} elseif (isset($params['parentNodeID'])) {
$parentNode = eZContentObjectTreeNode::fetch($params['parentNodeID']);
}
if ($parentNode instanceof eZContentObjectTreeNode && $object->attribute('main_node') instanceof eZContentObjectTreeNode) {
if ($parentNode->attribute('node_id') != $object->attribute('main_node')->attribute('parent_node_id')) {
eZContentOperationCollection::moveNode($object->attribute('main_node_id'), $object->attribute('id'), $parentNode->attribute('node_id'));
}
}
$additionalParentNodeIDs = isset($params['additionalParentNodeIDs']) ? (array) $params['additionalParentNodeIDs'] : array();
$additionalParentNodes = array();
foreach ($additionalParentNodeIDs as $nodeID) {
$additionalParentNode = eZContentObjectTreeNode::fetch($nodeID);
if ($additionalParentNode instanceof eZContentObjectTreeNode) {
if ($parentNode instanceof eZContentObjectTreeNode && $nodeID != $parentNode->attribute('node_id')) {
$additionalParentNodes[] = $additionalParentNode;
}
} else {
$this->error('Can`t fetch additional parent node by ID: ' . $nodeID);
}
}
if (count($additionalParentNodes) > 0) {
$nodeAssigments = eZPersistentObject::fetchObjectList(eZNodeAssignment::definition(), null, array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'is_main' => 0), null, null, true);
$removeNodeIDs = array();
foreach ($nodeAssigments as $assigment) {
$node = $assigment->attribute('node');
if ($node instanceof eZContentObjectTreeNode) {
if (in_array($node->attribute('parent_node_id'), $additionalParentNodeIDs) === false) {
$removeNodeIDs[] = $node->attribute('node_id');
$assigment->purge();
}
}
}
if (count($removeNodeIDs) > 0) {
$info = eZContentObjectTreeNode::subtreeRemovalInformation($removeNodeIDs);
foreach ($info['delete_list'] as $deleteItem) {
$node = $deleteItem['node'];
if ($node === null) {
continue;
}
if ($deleteItem['can_remove']) {
eZContentObjectTreeNode::removeSubtrees(array($node->attribute('node_id')), false);
$this->debug('[Removed additional location] "' . $node->attribute('name') . '"', array('red'));
}
}
}
foreach ($additionalParentNodes as $node) {
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $node->attribute('node_id'), 'is_main' => 0));
$nodeAssignment->store();
}
}
$this->setObjectAttributes($object, $params['attributes']);
$object->commitInputRelations($object->attribute('current_version'));
$object->resetInputRelationList();
eZOperationHandler::execute('content', 'publish', array('object_id' => $object->attribute('id'), 'version' => $object->attribute('current_version')));
$this->db->commit();
$this->updateVisibility($object, $visibility);
$this->debug('[Updated] "' . $object->attribute('name') . '"', array('yellow'));
return true;
}
示例15: Exception
throw new Exception();
}
} catch (Exception $e) {
eZDebug::writeError("Invalid XML input data.", 'view_newslettertype');
$input = "";
}
} else {
$input = $newsletterType->attribute($typeSource);
}
$attribute->setAttribute('data_text', $input);
$attribute->store();
}
}
$contentObject->store();
}
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObject->attribute('id'), 'contentobject_version' => $contentObject->attribute('current_version'), 'parent_node' => $parentNode->attribute('node_id'), 'is_main' => 1));
$nodeAssignment->store();
$newsletter = eZNewsletter::create('New "' . $class->attribute('name') . '" newsletter.', $userID, $newsletterType->attribute('id'));
$newsletter->setAttribute('contentobject_id', $contentObject->attribute('id'));
$newsletter->setAttribute('contentobject_version', $contentObject->attribute('current_version'));
$newsletter->setAttribute('design_to_use', strtok($newsletterType->attribute('allowed_designs'), ','));
$newsletter->store();
$db->commit();
return $Module->redirectTo('content/edit/' . $contentObject->attribute('id') . '/' . $contentObject->attribute('current_version'));
}
$userParameters = $Params['UserParameters'];
$offset = isset($userParameters['offset']) ? $userParameters['offset'] : 0;
$limitKey = isset($userParameters['limit']) ? $userParameters['limit'] : '1';
$limitList = array('1' => 10, '2' => 25, '3' => 50);
$limit = $limitList[(string) $limitKey];
$viewParameters = array('offset' => $offset, 'limitkey' => isset($userParameters['limitkey']) ? $userParameters['limitkey'] : 1);