コード例 #1
0
    private function createNeweZUser()
    {
        $user = eZUser::create( $this->userObject->attribute( 'id' ) );

        $user->setAttribute( 'login', $this->userLogin );
        $user->setAttribute( 'email', $this->userEmail );
        $user->setAttribute( 'password_hash', self::USER_PASSWORD_HASH );
        $user->setAttribute( 'password_hash_type', eZUser::passwordHashTypeID( self::USER_PASSWORD_HASH_ID ) );
        $user->store();

        if( !$user instanceof eZUser )
        {
            die( 'FAIL : not an eZUser' );
        }
    }
コード例 #2
0
 function unserializeContentObjectAttribute($package, $objectAttribute, $attributeNode)
 {
     $userNode = $attributeNode->getElementsByTagName('account')->item(0);
     if (is_object($userNode)) {
         $userID = $objectAttribute->attribute('contentobject_id');
         $user = eZUser::fetch($userID);
         if (!is_object($user)) {
             $user = eZUser::create($userID);
         }
         $user->setAttribute('login', $userNode->getAttribute('login'));
         $user->setAttribute('email', $userNode->getAttribute('email'));
         $user->setAttribute('password_hash', $userNode->getAttribute('password_hash'));
         $user->setAttribute('password_hash_type', eZUser::passwordHashTypeID($userNode->getAttribute('password_hash_type')));
         $user->store();
     }
 }
コード例 #3
0
    function createContentObject( $objectInformation )
    {
        $db = eZDB::instance();
        $contentObjectVersion = false;
        if ( $objectInformation['ownerID'] )
        {
            $userID = $objectInformation['ownerID'];
        }
        else
        {
            $user = eZUser::currentUser();
            $userID = $user->attribute( 'contentobject_id' );
        }
        if ( $objectInformation['remoteID'] )
        {
            $contentObject = eZContentObject::fetchByRemoteId( $objectInformation['remoteID'] );
            if (  $contentObject )
            {
                $this->writeMessage( "\t[".$objectInformation['remoteID']."] Object exists: " . $contentObject->attribute("name") . ". Creating new version.", 'notice' );
                $contentObjectVersion = $contentObject->createNewVersion();
            }
        }
        elseif ( $objectInformation['objectID'] )
        {
            $contentObject = eZContentObject::fetch( $objectInformation['objectID'] );
            if (  $contentObject )
            {
                $this->writeMessage( "\t[".$objectInformation['remoteID']."] Object exists: " . $contentObject->attribute("name") . ". Creating new version.", 'notice' );
                $contentObjectVersion = $contentObject->createNewVersion();
            }
        }

        if ( !$contentObjectVersion )
        {
            if ( is_numeric( $objectInformation['classID'] ) )
            {
                $contentClass = eZContentClass::fetch( $objectInformation['classID'] );
            }
            elseif ( is_string( $objectInformation['classID'] ) && $objectInformation['classID'] != "" )
            {
                $contentClass = eZContentClass::fetchByIdentifier( $objectInformation['classID'] );
            }
            else
            {
                $this->writeMessage( "\tNo class defined. Using class article.", 'warning' );
                $contentClass = eZContentClass::fetchByIdentifier( 'article' );
            }
            if ( !$contentClass )
            {
                $this->writeMessage( "\tCannot instantiate class '". $objectInformation['classID'] ."'." , 'error' );
                return false;
            }
            $contentObject = $contentClass->instantiate( $userID );
            $contentObject->setAttribute( 'remote_id',  $objectInformation['remoteID'] );
            if ( $contentObject )
            {
                $contentObjectVersion = $contentObject->currentVersion();
            }
        }
        if ( $contentObjectVersion )
        {
            $db->begin();
            $versionNumber  = $contentObjectVersion->attribute( 'version' );

            $sortField = intval( eZContentObjectTreeNode::sortFieldID( $objectInformation['sort_field'] ) );
            $sortOrder = strtolower( $objectInformation['sort_order'] ) == 'desc' ? eZContentObjectTreeNode::SORT_ORDER_DESC : eZContentObjectTreeNode::SORT_ORDER_ASC;

            $nodeAssignment = eZNodeAssignment::create(
                    array(  'contentobject_id'      => $contentObject->attribute( 'id' ),
                            'contentobject_version' => $versionNumber,
                            'parent_node'           => $objectInformation['parentNode'],
                            'is_main'               => 1,
                            'sort_field'			=> $sortField,
                            'sort_order'			=> $sortOrder,
                            )
            );
            $nodeAssignment->store();
            $dataMap = $contentObjectVersion->dataMap();
            foreach ( $objectInformation['attributes'] as $attributeName => $attributesContent )
            {
                if ( array_key_exists( $attributeName, $dataMap ) )
                {
                    $attribute = $dataMap[$attributeName];
                    $classAttributeID = $attribute->attribute( 'contentclassattribute_id' );
                    $dataType = $attribute->attribute( 'data_type_string' );
                    switch ( $dataType )
                    {
                        case 'ezstring':
                        case 'eztext':
                        case 'ezselection':
                        case 'ezemail':
                        {
                            if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" )
                            {
                                $attribute->setAttribute( 'data_text', $this->parseAndReplaceStringReferences( $attributesContent['content'] ) );
                            }
                            else
                            {
                                $attribute->setAttribute( 'data_text', $attributesContent['content'] );
                            }
                        } break;

                        case 'ezboolean':
                        case 'ezinteger':
                        {
                            $attribute->setAttribute( 'data_int', (int)$attributesContent['content'] );
                        } break;

                        case 'ezxmltext':
                        {
                            if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" )
                            {
                                $attributesContent['content'] = $this->parseAndReplaceStringReferences( $attributesContent['content'] );
                            }
                            if ( array_key_exists( 'htmlDecode', $attributesContent ) && $attributesContent['htmlDecode'] == "true" )
                            {
                                $content = html_entity_decode( $attributesContent['content'] );
                            }
                            else
                            {
                                $content = $attributesContent['content'];
                            }

                            if( array_key_exists( 'fullxml', $attributesContent ) && $attributesContent['fullxml'] == "true" )
                            {
                                $xml = $content;
                            }
                            else
                            {
                                $xml = '<?xml version="1.0" encoding="utf-8"?>'."\n".
                                        '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"'."\n".
                                        '         xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"'."\n".
                                        '         xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">'."\n".
                                        '  <section>'."\n";
                                $xml .= '    <paragraph>' . $content . "</paragraph>\n";
                                $xml .= "  </section>\n</section>\n";
                            }

                            $attribute->setAttribute( 'data_text', $xml );
                        } break;

                        case 'ezprice':
                        case 'ezfloat':
                        {
                            $attribute->setAttribute( 'data_float', (float)$attributesContent['content'] );
                        } break;
                        case 'ezimage':
                        {
                            $imagePath = $this->setting( 'data_source' ) . '/' . $attributesContent['src'];
                            $imageName = $attributesContent['title'];
                            $path = realpath( $imagePath );
                            if ( file_exists( $path ) )
                            {
                                $content = $attribute->content();
                                $content->initializeFromFile( $path, $imageName, basename( $attributesContent['src'] ) );
                                $content->store( $attribute );
                            }
                            else
                            {
                                $this->writeMessage( "\tFile " . $path . " not found.", 'warning' );
                            }
                        } break;
                        case 'ezobjectrelation':
                        {
                            $relationContent = trim( $attributesContent['content'] );
                            if ( $relationContent != '' )
                            {
                                $objectID = $this->getReferenceID( $attributesContent['content'] );
                                if ( $objectID )
                                {
                                    $attribute->setAttribute( 'data_int', $objectID );
                                    eZContentObject::fetch( $objectID )->addContentObjectRelation( $objectID, $versionNumber, $contentObject->attribute( 'id' ), $attribute->attribute( 'contentclassattribute_id' ),    eZContentObject::RELATION_ATTRIBUTE );
                                }
                                else
                                {
                                    $this->writeMessage( "\tReference " . $attributesContent['content'] . " not set.", 'warning' );
                                }
                            }
                        } break;
                        case 'ezurl':
                        {
                            $url = '';
                            $title = '';
                            if (  array_key_exists( 'url', $attributesContent ) )
                                $url   = $attributesContent['url'];
                            if (  array_key_exists( 'title', $attributesContent ) )
                                $title   = $attributesContent['title'];

                            if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" )
                            {
                                $title = $this->parseAndReplaceStringReferences( $title );
                                $url   = $this->parseAndReplaceStringReferences( $url );
                            }

                            $attribute->setAttribute( 'data_text', $title );
                            $attribute->setContent( $url );
                        } break;
                        case 'ezuser':
                        {
                            $login    = '';
                            $email    = '';
                            $password = '';
                            if (  array_key_exists( 'login', $attributesContent ) )
                                $login    = $attributesContent['login'];
                            if (  array_key_exists( 'email', $attributesContent ) )
                                $email    = $attributesContent['email'];
                            if (  array_key_exists( 'password', $attributesContent ) )
                                $password = $attributesContent['password'];

                            $contentObjectID = $attribute->attribute( "contentobject_id" );

                            $user =& $attribute->content();
                            if ( $user === null )
                            {
                                $user = eZUser::create( $contentObjectID );
                            }

                            $ini =& eZINI::instance();
                            $generatePasswordIfEmpty = $ini->variable( "UserSettings", "GeneratePasswordIfEmpty" );
                            if (  $password == "" )
                            {
                                if ( $generatePasswordIfEmpty == 'true' )
                                {
                                    $passwordLength = $ini->variable( "UserSettings", "GeneratePasswordLength" );
                                    $password = $user->createPassword( $passwordLength );
                                }
                                else
                                {
                                    $password = null;
                                }
                            }

                            if ( $password == "_ezpassword" )
                            {
                                $password = false;
                                $passwordConfirm = false;
                            }

                            $user->setInformation( $contentObjectID, $login, $email, $password, $password );
                            $attribute->setContent( $user );
                        } break;
                        case 'ezkeyword':
                        {
                            $keyword = new eZKeyword();
                            $keyword->initializeKeyword( $attributesContent['content'] );
                            $attribute->setContent( $keyword );
                        } break;
                        case 'ezmatrix':
                        {
                            if ( is_array( $attributesContent ) )
                            {
                                $matrix = $attribute->attribute( 'content' );
                                $cells = array();
                                $matrix->Matrix['rows']['sequential'] = array();
                                $matrix->NumRows = 0;
                                foreach( $attributesContent as $key => $value )
                                {
                                    $cells = array_merge( $cells, $value );
                                    $newRow['columns'] = $value;
                                    $newRow['identifier'] =  'row_' . ( $matrix->NumRows + 1 );
                                    $newRow['name'] = 'Row_' . ( $matrix->NumRows + 1 );
                                    $matrix->NumRows++;
                                    $matrix->Matrix['rows']['sequential'][] = $newRow;
                                }
                                $matrix->Cells = $cells;
                                $attribute->setAttribute( 'data_text', $matrix->xmlString() );
                                $matrix->decodeXML( $attribute->attribute( 'data_text' ) );
                                $attribute->setContent( $matrix );
                            }
                        } break;

                        case 'ezobjectrelationlist':
                        {
                            $relationContent = explode( ',', $attributesContent['content'] );
                            if ( count( $relationContent ) )
                            {
                                $objectIDs = array();
                                foreach( $relationContent as $relation )
                                {
                                    $objectIDs[] = $this->getReferenceID( trim ( $relation ) );
                                }
                                $attribute->fromString( implode( '-', $objectIDs ) );
                            }
                            else
                            {
                                eZDebug::writeWarning( $attributesContent['content'], "No relation declared" );
                            }
                        } break;


                        case 'ezauthor':
                        case 'ezbinaryfile':
                        case 'ezcountry':
                        case 'ezdate':
                        case 'ezdatetime':
                        case 'ezenum':
                        case 'ezidentifier':
                        case 'ezinisetting':
                        case 'ezisbn':
                        case 'ezmedia':
                        case 'ezmultioption':
                        case 'ezmultiprice':
                        case 'ezoption':
                        case 'ezpackage':
                        case 'ezproductcategory':
                        case 'ezrangeoption':
                        case 'ezsubtreesubscription':
                        case 'eztime':
                        default:
                        {
                            try
                            {
                                $attribute->fromString($attributesContent['content']);
                            }
                            catch ( Exception $e )
                            {
                                $this->writeMessage( "\tDatatype " . $dataType . " fromString function rejected value " . $attributesContent['content'], 'warning' );
                            }
                        } break;

                    }
                    $attribute->store();
                }
            }
            if ( isset($objectInformation['sectionID']) && $objectInformation['sectionID'] != '' && $objectInformation['sectionID'] != 0 )
            {
                $contentObject->setAttribute( 'section_id',  $objectInformation['sectionID'] );
            }

            if ( isset($objectInformation['creatorID']) && $objectInformation['creatorID'] != '' && $objectInformation['creatorID'] != 0 )
            {
                $contentObjectVersion->setAttribute( 'creator_id',  $objectInformation['creatorID'] );
            }

            if ( isset($objectInformation['ownerID']) && $objectInformation['ownerID'] != '' && $objectInformation['ownerID'] != 0 )
            {
                $contentObject->setAttribute( 'owner_id',  $objectInformation['ownerID'] );
            }

            if( isset( $objectInformation['relations'] ) && is_array( $objectInformation['relations'] ) )
            {
                foreach( $objectInformation['relations'] as $toObjectID )
                {
                    $contentObject->addContentObjectRelation( $toObjectID );
                }
            }

            $contentObjectVersion->store();
            $contentObject->store();
            $db->commit();

            eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ), 'version'   => $versionNumber ) );

            $newNodeArray = eZContentObjectTreeNode::fetchByContentObjectID( $contentObject->attribute( 'id' ) );
            $refArray = false;
            if ( $newNodeArray && count($newNodeArray) >= 1 )
            {
                $newNode = $newNodeArray[0];
                if ( $newNode )
                {
                    $refArray = array( "node_id"   => $newNode->attribute( 'node_id' ),
                                       "name"      => $contentObjectVersion->attribute( 'name' ),
                                       "object_id" => $contentObject->attribute( 'id' ) );

                    if( $objectInformation['priority'] )
                    {
                        $this->updateNodePriority( $refArray['node_id'], $objectInformation['priority'] );
                    }
                }
            }
            unset($contentObjectVersion);
            unset($contentObject);
            return $refArray;
        }
    return false;
    }
コード例 #4
0
 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='******'";
     }
     if ($authenticationMatch & eZUser::AUTHENTICATE_EMAIL) {
         $loginArray[] = "email='{$loginEscaped}'";
     }
     if (count($loginArray) == 0) {
         $loginArray[] = "login='******'";
     }
     $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 = "******";
                 $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;
                         $groupQuery = "SELECT ezcontentobject_tree.node_id\n                                           FROM ezcontentobject, ezcontentobject_tree\n                                           WHERE ezcontentobject.id='{$groupID}'\n                                           AND ezcontentobject.id=ezcontentobject_tree.contentobject_id";
                         $groupObject = $db->arrayQuery($groupQuery);
                         if (count($groupObject) > 0) {
                             $defaultUserPlacement = $groupObject[0]['node_id'];
                         }
                     }
                 }
             }
             if ($filePath != "root" and $filePath != null) {
                 $fileName = $filePath . "/" . $fileName;
             }
             if (file_exists($fileName)) {
                 $handle = fopen($fileName, "r");
             } else {
                 // Increase number of failed login attempts.
                 if (isset($userID)) {
                     eZUser::setFailedLoginAttempts($userID);
                 }
                 return false;
             }
             while (!feof($handle)) {
                 $line = trim(fgets($handle, 4096));
                 if ($line === '') {
                     continue;
                 }
                 if ($separator == "tab") {
                     $userArray = explode("\t", $line);
                 } else {
                     $userArray = explode($separator, $line);
                 }
                 $uid = $userArray[$loginColumnNr - 1];
                 $email = $userArray[$emailColumnNr - 1];
                 $pass = $userArray[$passwordColumnNr - 1];
                 $firstName = $userArray[$firstNameColumnNr - 1];
                 $lastName = $userArray[$lastNameColumnNr - 1];
                 if ($login == $uid) {
                     if (trim($pass) == $password) {
                         $createNewUser = true;
                         $existUser = eZUser::fetchByName($login);
                         if ($existUser != null) {
                             $createNewUser = false;
                         }
                         if ($createNewUser) {
                             $userClassID = $ini->variable("UserSettings", "UserClassID");
                             $userCreatorID = $ini->variable("UserSettings", "UserCreatorID");
                             $defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID");
                             $remoteID = "TextFile_" . $login;
                             $db->begin();
                             // The content object may already exist if this process has failed once before, before the eZUser object was created.
                             // Therefore we try to fetch the eZContentObject before instantiating it.
                             $contentObject = eZContentObject::fetchByRemoteID($remoteID);
                             if (!is_object($contentObject)) {
                                 $class = eZContentClass::fetch($userClassID);
                                 $contentObject = $class->instantiate($userCreatorID, $defaultSectionID);
                             }
                             $contentObject->setAttribute('remote_id', $remoteID);
                             $contentObject->store();
                             $contentObjectID = $contentObject->attribute('id');
                             $userID = $contentObjectID;
                             $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $defaultUserPlacement, 'is_main' => 1));
                             $nodeAssignment->store();
                             $version = $contentObject->version(1);
                             $version->setAttribute('modified', time());
                             $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
                             $version->store();
                             $contentObjectID = $contentObject->attribute('id');
                             $contentObjectAttributes = $version->contentObjectAttributes();
                             $contentObjectAttributes[0]->setAttribute('data_text', $firstName);
                             $contentObjectAttributes[0]->store();
                             $contentObjectAttributes[1]->setAttribute('data_text', $lastName);
                             $contentObjectAttributes[1]->store();
                             $user = eZUser::create($userID);
                             $user->setAttribute('login', $login);
                             $user->setAttribute('email', $email);
                             $user->setAttribute('password_hash', "");
                             $user->setAttribute('password_hash_type', 0);
                             $user->store();
                             eZUser::updateLastVisit($userID);
                             eZUser::setCurrentlyLoggedInUser($user, $userID);
                             // Reset number of failed login attempts
                             eZUser::setFailedLoginAttempts($userID, 0);
                             $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1));
                             $db->commit();
                             return $user;
                         } else {
                             $db->begin();
                             // Update user information
                             $userID = $existUser->attribute('contentobject_id');
                             $contentObject = eZContentObject::fetch($userID);
                             $parentNodeID = $contentObject->attribute('main_parent_node_id');
                             $currentVersion = $contentObject->attribute('current_version');
                             $version = $contentObject->attribute('current');
                             $contentObjectAttributes = $version->contentObjectAttributes();
                             $contentObjectAttributes[0]->setAttribute('data_text', $firstName);
                             $contentObjectAttributes[0]->store();
                             $contentObjectAttributes[1]->setAttribute('data_text', $lastName);
                             $contentObjectAttributes[1]->store();
                             $existUser = eZUser::fetch($userID);
                             $existUser->setAttribute('email', $email);
                             $existUser->setAttribute('password_hash', "");
                             $existUser->setAttribute('password_hash_type', 0);
                             $existUser->store();
                             if ($defaultUserPlacement != $parentNodeID) {
                                 $newVersion = $contentObject->createNewVersion();
                                 $newVersion->assignToNode($defaultUserPlacement, 1);
                                 $newVersion->removeAssignment($parentNodeID);
                                 $newVersionNr = $newVersion->attribute('version');
                                 $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $userID, 'version' => $newVersionNr));
                             }
                             eZUser::updateLastVisit($userID);
                             eZUser::setCurrentlyLoggedInUser($existUser, $userID);
                             // Reset number of failed login attempts
                             eZUser::setFailedLoginAttempts($userID, 0);
                             $db->commit();
                             return $existUser;
                         }
                     } else {
                         // Increase number of failed login attempts.
                         if (isset($userID)) {
                             eZUser::setFailedLoginAttempts($userID);
                         }
                         return false;
                     }
                 }
             }
             fclose($handle);
         }
     }
     // Increase number of failed login attempts.
     if (isset($userID)) {
         eZUser::setFailedLoginAttempts($userID);
     }
     return false;
 }
コード例 #5
0
ファイル: ezsiteinstaller.php プロジェクト: nottavi/ezpublish
    function updateContentObjectAttributes( $params )
    {
        $objectID = $params['object_id'];
        $attributesData = $params['attributes_data'];

        $contentObject = eZContentObject::fetch( $objectID );
        if( !is_object( $contentObject ) )
        {
            $this->reportError( "Content object with id '$objectID' doesn't exist." , 'eZSiteInstaller::updateContentObjectAttributes' );
            return;
        }

        $dataMap = $contentObject->dataMap();
        foreach( $attributesData as $attrIdentifier => $attrData )
        {
            $attribute = $dataMap[$attrIdentifier];
            if( !is_object( $attribute ) )
            {
                $this->reportError( "Warning: could not acquire attribute with identifier '$attrIdentifier'.",
                                    'eZSiteInstaller::updateContentObjectAttributes',
                                    eZSiteInstaller::ERR_CONTINUE );
                continue;
            }

            //get datatype name
            $datatypeString = $attribute->attribute( 'data_type_string' );

            switch( $datatypeString )
            {
                case 'ezstring':
                {
                    $attribute->setAttribute( "data_text", $attrData['DataText']);
                } break;

                case 'ezxmltext':
                {
                    $xml = '<?xml version="1.0" encoding="utf-8"?>'."\n".
                           '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"'."\n".
                           '         xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"'."\n".
                           '         xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">'."\n".
                           '  <section>'."\n";
                    {
                        $xml .= '    <paragraph>';
                        $numSentences = mt_rand( ( int ) $attributeParameters['min_sentences'], ( int ) $attributeParameters['max_sentences'] );
                        for( $sentence = 0; $sentence < $numSentences; $sentence++ )
                        {
                            if( $sentence != 0 )
                            {
                                $xml .= ' ';
                            }
                        }
                        $xml .= "</paragraph>\n";
                    }
                    $xml .= "  </section>\n</section>\n";

                    $attribute->setAttribute( 'data_text', $xml );
                } break;

                case 'eztext':
                {
                    $attribute->setAttribute( 'data_text', $attrData['DataText'] );
                } break;

                case 'ezmatrix':
                {
                    $columnsCount = count( $attrData["MatrixDefinition"]->attribute( 'columns' ) );
                    if( $columnsCount > 0 )
                    {
                        $rowsCount = count( $attrData["MatrixCells"] ) / $columnsCount;

                        $tempMatrix = new eZMatrix( $attrData["MatrixTitle"], $rowsCount, $attrData["MatrixDefinition"] );
                        $tempMatrix->Cells = $attrData["MatrixCells"];

                        $attribute->setAttribute( 'data_text', $tempMatrix->xmlString() );
                        $tempMatrix->decodeXML( $attribute->attribute( 'data_text' ) );

                        $attribute->setContent( $tempMatrix );
                    }
                    else
                    {
                        $this->reportError( "Number of columns in 'ezmatrix' should be greater then zero",
                                            'eZSiteInstaller::updateContentObjectAttributes',
                                            eZSiteInstaller::ERR_CONTINUE );
                    }

                } break;

                case 'ezboolean':
                {
                    $attribute->setAttribute( 'data_int', $attrData['DataInt'] );
                } break;

                case 'ezinteger':
                {
                    $attribute->setAttribute( 'data_int', $attrData['DataInt'] );
                } break;

                case 'ezfloat':
                {
                    $power = 100;
                    $float = mt_rand( $power * ( int ) $attrData['Min'], $power * ( int ) $attrData['Max'] );
                    $float = $float / $power;
                    $attribute->setAttribute( 'data_float', $float );
                } break;

                case 'ezprice':
                {
                    $power = 10;
                    $price = mt_rand( $power * ( int ) $attrData['Min'], $power * ( int ) $attrData['Max'] );
                    $price = $price / $power;
                    $attribute->setAttribute( 'data_float', $price );
                } break;

                case 'ezurl':
                {
                    $attribute->setContent( $attrData['Content'] );
                    $attribute->setAttribute( "data_text", $attrData['DataText']);
                } break;

                case 'ezuser':
                {
                    $user = $attribute->content();
                    if( $user === null )
                    {
                        $user = eZUser::create( $objectID );
                    }

                    $user->setInformation( $objectID,
                                           md5( time() . '-' . mt_rand() ),
                                           md5( time() . '-' . mt_rand() ) . '@ez.no',
                                           'publish',
                                           'publish' );
                    $user->store();
                } break;
            }
            $attribute->store();
        }

        $contentObject->store();
    }
コード例 #6
0
    function editContentObject( $objectInformation )
    {
        $db = eZDB::instance();
        $contentObjectVersion = false;
        $contentObject = $objectInformation['object'];

        if ( $objectInformation['ownerID'] )
        {
            $userID = $objectInformation['ownerID'];
        }
        else
        {
            $userID = $contentObject->attribute( 'owner_id' );
        }

        if (  $contentObject )
        {
            $contentObjectVersion = $contentObject->createNewVersion();
        }

        if ( $contentObjectVersion )
        {
            $db->begin();
            $versionNumber  = $contentObjectVersion->attribute( 'version' );

            $dataMap = $contentObjectVersion->dataMap();
            foreach ( $objectInformation['attributes'] as $attributeName => $attributesContent )
            {
                if ( array_key_exists( $attributeName, $dataMap ) )
                {
                    $attribute = $dataMap[$attributeName];
                    $classAttributeID = $attribute->attribute( 'contentclassattribute_id' );
                    $dataType = $attribute->attribute( 'data_type_string' );
                    switch ( $dataType )
                    {
                        case 'ezstring':
                        case 'eztext':
                        case 'ezselection':
                        case 'ezemail':
                        {
                            if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" )
                            {
                                $attribute->setAttribute( 'data_text', $this->parseAndReplaceStringReferences( $attributesContent['content'] ) );
                            }
                            else
                            {
                                $attribute->setAttribute( 'data_text', $attributesContent['content'] );
                            }
                        } break;

                        case 'ezboolean':
                        case 'ezinteger':
                        {
                            $attribute->setAttribute( 'data_int', (int)$attributesContent['content'] );
                        } break;

                        case 'ezxmltext':
                        {
                            if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" )
                            {
                                $attributesContent['content'] = $this->parseAndReplaceStringReferences( $attributesContent['content'] );
                            }
                            if ( array_key_exists( 'htmlDecode', $attributesContent ) && $attributesContent['htmlDecode'] == "true" )
                            {
                                $content = html_entity_decode( $attributesContent['content'] );
                            }
                            else
                            {
                                $content = $attributesContent['content'];
                            }
                            $xml = '<?xml version="1.0" encoding="utf-8"?>'."\n".
                                    '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"'."\n".
                                    '         xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"'."\n".
                                    '         xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">'."\n".
                                    '  <section>'."\n";
                            $xml .= '    <paragraph>' . $content . "</paragraph>\n";
                            $xml .= "  </section>\n</section>\n";

                            $attribute->setAttribute( 'data_text', $xml );
                        } break;

                        case 'ezprice':
                        case 'ezfloat':
                        {
                            $attribute->setAttribute( 'data_float', (float)$attributesContent['content'] );
                        } break;
                        case 'ezimage':
                        {
                            $imagePath = $this->setting( 'data_source' ) . '/' . $attributesContent['src'];
                            $imageName = $attributesContent['title'];
                            $path = realpath( $imagePath );
                            if ( file_exists( $path ) )
                            {
                                $content = $attribute->content();
                                $content->initializeFromFile( $path, $imageName, basename( $attributesContent['src'] ) );
                                $content->store( $attribute );
                            }
                            else
                            {
                                $this->writeMessage( "\tFile " . $path . " not found.", 'warning' );
                            }
                        } break;
                        case 'ezobjectrelation':
                        {
                            $objectID = $this->getReferenceID( $attributesContent['content'] );
                            if ( $objectID )
                            {
                                $attribute->setAttribute( 'data_int', $objectID );
                                eZContentObject::fetch( $objectID )->addContentObjectRelation( $objectID, $versionNumber, $contentObject->attribute( 'id' ), $attribute->attribute( 'contentclassattribute_id' ),    eZContentObject::RELATION_ATTRIBUTE );
                            }
                            else
                            {
                                $this->writeMessage( "\tReference " . $attributesContent['content'] . " not set.", 'warning' );
                            }
                        } break;
                        case 'ezurl':
                        {
                            $url = '';
                            $title = '';
                            if (  array_key_exists( 'url', $attributesContent ) )
                                $url   = $attributesContent['url'];
                            if (  array_key_exists( 'title', $attributesContent ) )
                                $title   = $attributesContent['title'];

                            if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" )
                            {
                                $title = $this->parseAndReplaceStringReferences( $title );
                                $url   = $this->parseAndReplaceStringReferences( $url );
                            }

                            $attribute->setAttribute( 'data_text', $title );
                            $attribute->setContent( $url );
                        } break;
                        case 'ezuser':
                        {
                            $login    = '';
                            $email    = '';
                            $password = '';
                            if (  array_key_exists( 'login', $attributesContent ) )
                                $login    = $attributesContent['login'];
                            if (  array_key_exists( 'email', $attributesContent ) )
                                $email    = $attributesContent['email'];
                            if (  array_key_exists( 'password', $attributesContent ) )
                                $password = $attributesContent['password'];

                            $contentObjectID = $attribute->attribute( "contentobject_id" );

                            $user =& $attribute->content();
                            if ( $user === null )
                            {
                                $user = eZUser::create( $contentObjectID );
                            }

                            $ini =& eZINI::instance();
                            $generatePasswordIfEmpty = $ini->variable( "UserSettings", "GeneratePasswordIfEmpty" );
                            if (  $password == "" )
                            {
                                if ( $generatePasswordIfEmpty == 'true' )
                                {
                                    $passwordLength = $ini->variable( "UserSettings", "GeneratePasswordLength" );
                                    $password = $user->createPassword( $passwordLength );
                                }
                                else
                                {
                                    $password = null;
                                }
                            }

                            if ( $password == "_ezpassword" )
                            {
                                $password = false;
                                $passwordConfirm = false;
                            }

                            $user->setInformation( $contentObjectID, $login, $email, $password, $password );
                            $attribute->setContent( $user );
                        } break;
                        case 'ezkeyword':
                        {
                            $keyword = new eZKeyword();
                            $keyword->initializeKeyword( $attributesContent['content'] );
                            $attribute->setContent( $keyword );
                        } break;
                        case 'ezmatrix':
                        {
                            if ( is_array( $attributesContent ) )
                            {
                                $matrix = $attribute->attribute( 'content' );
                                $cells = array();
                                $matrix->Matrix['rows']['sequential'] = array();
                                $matrix->NumRows = 0;
                                foreach( $attributesContent as $key => $value )
                                {
                                    $cells = array_merge( $cells, $value );
                                    $newRow['columns'] = $value;
                                    $newRow['identifier'] =  'row_' . ( $matrix->NumRows + 1 );
                                    $newRow['name'] = 'Row_' . ( $matrix->NumRows + 1 );
                                    $matrix->NumRows++;
                                    $matrix->Matrix['rows']['sequential'][] = $newRow;
                                }
                                $matrix->Cells = $cells;
                                $attribute->setAttribute( 'data_text', $matrix->xmlString() );
                                $matrix->decodeXML( $attribute->attribute( 'data_text' ) );
                                $attribute->setContent( $matrix );
                            }
                        } break;


                        case 'ezauthor':
                        case 'ezbinaryfile':
                        case 'ezcountry':
                        case 'ezdate':
                        case 'ezdatetime':
                        case 'ezenum':
                        case 'ezidentifier':
                        case 'ezinisetting':
                        case 'ezisbn':
                        case 'ezmedia':
                        case 'ezmultioption':
                        case 'ezmultiprice':
                        case 'ezobjectrelationlist':
                        case 'ezoption':
                        case 'ezpackage':
                        case 'ezproductcategory':
                        case 'ezrangeoption':
                        case 'ezsubtreesubscription':
                        case 'eztime':
                        {
                            $this->writeMessage( "\tDatatype " . $dataType . " not supported yet.", 'warning' );
                        } break;

                    }
                    $attribute->store();
                }
            }
            if ( isset($objectInformation['sectionID']) && $objectInformation['sectionID'] != '' && $objectInformation['sectionID'] != 0 )
            {
                $contentObject->setAttribute( 'section_id',  $objectInformation['sectionID'] );
            }

            if ( isset($objectInformation['creatorID']) && $objectInformation['creatorID'] != '' && $objectInformation['creatorID'] != 0 )
            {
                $contentObjectVersion->setAttribute( 'creator_id',  $objectInformation['creatorID'] );
            }

            if ( isset($objectInformation['ownerID']) && $objectInformation['ownerID'] != '' && $objectInformation['ownerID'] != 0 )
            {
                $contentObject->setAttribute( 'owner_id',  $objectInformation['ownerID'] );
            }

            $contentObjectVersion->store();
            $contentObject->store();
            $db->commit();

            eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ), 'version'   => $versionNumber ) );

            // set chosen hidden/invisible attributes for object nodes
            $http          = eZHTTPTool::instance();
            $assignedNodes = $contentObject->assignedNodes( true );
            foreach ( $assignedNodes as $node )
            {
                $nodeID               = $node->attribute( 'node_id' );
                $parentNodeID         = $node->attribute( 'parent_node_id' );

                $db = eZDB::instance();
                $db->begin();
                $parentNode = eZContentObjectTreeNode::fetch( $parentNodeID );
                eZContentObjectTreeNode::updateNodeVisibility( $node, $parentNode, /* $recursive = */ false );
                $db->commit();
                unset( $node, $parentNode );
            }
            unset( $assignedNodes );




            eZContentCacheManager::clearObjectViewCacheIfNeeded( $contentObject->attribute( 'id' ) );

            $newNodeArray = eZContentObjectTreeNode::fetchByContentObjectID( $contentObject->attribute( 'id' ) );
            $refArray = false;
            if ( $newNodeArray && count($newNodeArray) >= 1 )
            {
                $newNode = $newNodeArray[0];
                if ( $newNode )
                {
                    $refArray = array( "node_id"   => $newNode->attribute( 'node_id' ),
                                       "name"      => $contentObject->attribute( 'name' ),
                                       "object_id" => $contentObject->attribute( 'id' ) );
                }
            }
            unset($contentObjectVersion);
            unset($contentObject);
            return $refArray;
        }
        return false;
    }