/** * Parse an XML users file into a set of users to import. * @param $file string path to the XML file to parse * @return array ImportedUsers the collection of users read from the file */ function &parseData($file) { $roleDao =& DAORegistry::getDAO('RoleDAO'); $success = true; $this->usersToImport = array(); $tree = $this->parser->parse($file); $journalDao =& DAORegistry::getDAO('JournalDAO'); $journal =& $journalDao->getById($this->journalId); $journalPrimaryLocale = AppLocale::getPrimaryLocale(); $site =& Request::getSite(); $siteSupportedLocales = $site->getSupportedLocales(); if ($tree !== false) { foreach ($tree->getChildren() as $user) { if ($user->getName() == 'user') { // Match user element $newUser = new ImportedUser(); foreach ($user->getChildren() as $attrib) { switch ($attrib->getName()) { case 'username': // Usernames must be lowercase $newUser->setUsername(strtolower_codesafe($attrib->getValue())); break; case 'password': $newUser->setMustChangePassword($attrib->getAttribute('change') == 'true' ? 1 : 0); $encrypted = $attrib->getAttribute('encrypted'); if (isset($encrypted) && $encrypted !== 'plaintext') { $ojsEncryptionScheme = Config::getVar('security', 'encryption'); if ($encrypted != $ojsEncryptionScheme) { $this->errors[] = __('plugins.importexport.users.import.encryptionMismatch', array('importHash' => $encrypted, 'ojsHash' => $ojsEncryptionScheme)); } $newUser->setPassword($attrib->getValue()); } else { $newUser->setUnencryptedPassword($attrib->getValue()); } break; case 'salutation': $newUser->setSalutation($attrib->getValue()); break; case 'first_name': $newUser->setFirstName($attrib->getValue()); break; case 'middle_name': $newUser->setMiddleName($attrib->getValue()); break; case 'last_name': $newUser->setLastName($attrib->getValue()); break; case 'initials': $newUser->setInitials($attrib->getValue()); break; case 'gender': $newUser->setGender($attrib->getValue()); break; case 'affiliation': $locale = $attrib->getAttribute('locale'); if (empty($locale)) { $locale = $journalPrimaryLocale; } $newUser->setAffiliation($attrib->getValue(), $locale); break; case 'email': $newUser->setEmail($attrib->getValue()); break; case 'url': $newUser->setUrl($attrib->getValue()); break; case 'phone': $newUser->setPhone($attrib->getValue()); break; case 'fax': $newUser->setFax($attrib->getValue()); break; case 'mailing_address': $newUser->setMailingAddress($attrib->getValue()); break; case 'country': $newUser->setCountry($attrib->getValue()); break; case 'signature': $locale = $attrib->getAttribute('locale'); if (empty($locale)) { $locale = $journalPrimaryLocale; } $newUser->setSignature($attrib->getValue(), $locale); break; case 'interests': $interests = $attrib->getValue(); // Bug #9054 $oldInterests = $newUser->getTemporaryInterests(); if ($oldInterests) { $interests = $oldInterests . ',' . $interests; } $newUser->setTemporaryInterests($interests); break; case 'gossip': $locale = $attrib->getAttribute('locale'); if (empty($locale)) { $locale = $journalPrimaryLocale; } $newUser->setGossip($attrib->getValue(), $locale); break; case 'biography': $locale = $attrib->getAttribute('locale'); if (empty($locale)) { $locale = $journalPrimaryLocale; } $newUser->setBiography($attrib->getValue(), $locale); break; case 'locales': $locales = array(); foreach (explode(':', $attrib->getValue()) as $locale) { if (AppLocale::isLocaleValid($locale) && in_array($locale, $siteSupportedLocales)) { array_push($locales, $locale); } } $newUser->setLocales($locales); break; case 'role': $roleType = $attrib->getAttribute('type'); if ($this->validRole($roleType)) { $role = new Role(); $role->setRoleId($roleDao->getRoleIdFromPath($roleType)); $newUser->addRole($role); } break; } } array_push($this->usersToImport, $newUser); } } } return $this->usersToImport; }