/** * @copydoc SetupListbuilderHandler::initialize() */ function initialize($request) { parent::initialize($request); $context = $request->getContext(); $this->setTitle('plugins.generic.translator.localeFileContents'); $this->setInstructions('plugins.generic.translator.localeFileContentsDescription'); // Get and validate the locale and filename parameters $this->locale = $request->getUserVar('locale'); if (!AppLocale::isLocaleValid($this->locale)) { fatalError('Invalid locale.'); } $this->filename = $request->getUserVar('filename'); if (!in_array($this->filename, TranslatorAction::getLocaleFiles($this->locale))) { fatalError('Invalid locale file specified!'); } // Basic configuration $this->setSourceType(LISTBUILDER_SOURCE_TYPE_TEXT); $this->setSaveType(LISTBUILDER_SAVE_TYPE_EXTERNAL); $this->setSaveFieldName('localeKeys'); self::$plugin->import('controllers.listbuilder.LocaleFileListbuilderGridCellProvider'); $cellProvider = new LocaleFileListbuilderGridCellProvider($this->locale); // Key column $this->addColumn(new ListbuilderGridColumn($this, 'key', 'plugins.generic.translator.localeKey', null, self::$plugin->getTemplatePath() . 'localeFileKeyGridCell.tpl', $cellProvider, array('tabIndex' => 1))); // Value column (custom template displays English text) $this->addColumn(new ListbuilderGridColumn($this, 'value', 'plugins.generic.translator.localeKeyValue', null, self::$plugin->getTemplatePath() . 'localeFileValueGridCell.tpl', $cellProvider, array('tabIndex' => 2, 'width' => 70, 'alignment' => COLUMN_ALIGNMENT_LEFT))); }
/** * Get the filename of the qualifier database * @param $locale string * @return string */ function getFilename($locale) { if (!AppLocale::isLocaleValid($locale)) { $locale = AppLocale::MASTER_LOCALE; } return "lib/pkp/locale/{$locale}/bic21qualifiers.xml"; }
/** * Display upgrade form. */ function upgrade() { $this->validate(); $this->setupTemplate(); if (($setLocale = PKPRequest::getUserVar('setLocale')) != null && AppLocale::isLocaleValid($setLocale)) { PKPRequest::setCookieVar('currentLocale', $setLocale); } $installForm = new UpgradeForm(); $installForm->initData(); $installForm->display(); }
/** * @copydoc Gridhandler::initialize() */ function initialize($request, $args = null) { parent::initialize($request); $this->tabsSelector = $request->getUserVar('tabsSelector'); $this->locale = $request->getUserVar('locale'); if (!AppLocale::isLocaleValid($this->locale)) { fatalError('Invalid locale.'); } $this->addColumns(); if ($this->locale != MASTER_LOCALE) { $this->addColumn(new GridColumn('status', 'common.status', null, 'controllers/grid/gridCell.tpl', null, array('html' => true, 'alignment' => COLUMN_ALIGNMENT_LEFT))); } }
/** * Reload the default localized settings for this conference * @param $args array * @param $request object */ function reloadLocalizedDefaultSettings($args, &$request) { // make sure the locale is valid $locale = $request->getUserVar('localeToLoad'); if (!AppLocale::isLocaleValid($locale)) { $request->redirect(null, null, null, 'languages'); } $this->validate(); $this->setupTemplate(true); $conference =& $request->getConference(); $conferenceSettingsDao =& DAORegistry::getDAO('ConferenceSettingsDAO'); $conferenceSettingsDao->reloadLocalizedDefaultSettings($conference->getId(), 'registry/conferenceSettings.xml', array('indexUrl' => $request->getIndexUrl(), 'conferencePath' => $conference->getData('path'), 'primaryLocale' => $conference->getPrimaryLocale(), 'conferenceName' => $conference->getTitle($conference->getPrimaryLocale())), $locale); $templateMgr =& TemplateManager::getManager(); $templateMgr->assign(array('currentUrl' => $request->url(null, null, null, 'languages'), 'pageTitle' => 'common.languages', 'message' => 'common.changesSaved', 'backLink' => $request->url(null, null, $request->getRequestedPage()), 'backLinkLabel' => 'manager.conferenceSiteManagement')); $templateMgr->display('common/message.tpl'); }
/** * Change the locale for the current user. * @param $args array first parameter is the new locale */ function setLocale($args, &$request) { $setLocale = isset($args[0]) ? $args[0] : null; $site =& $request->getSite(); if (AppLocale::isLocaleValid($setLocale) && in_array($setLocale, $site->getSupportedLocales())) { $session =& $request->getSession(); $session->setSessionVar('currentLocale', $setLocale); } if (isset($_SERVER['HTTP_REFERER'])) { $request->redirectUrl($_SERVER['HTTP_REFERER']); } $source = $request->getUserVar('source'); if (isset($source) && !empty($source)) { $request->redirectUrl($request->getProtocol() . '://' . $request->getServerHost() . $source, false); } $request->redirect('index'); }
/** * Change the locale for the current user. * @param $args array first parameter is the new locale */ function setLocale($args, $request) { $setLocale = array_shift($args); $site = $request->getSite(); $context = $request->getContext(); if ($context != null) { $contextSupportedLocales = (array) $context->getSupportedLocales(); } if (AppLocale::isLocaleValid($setLocale) && (!isset($contextSupportedLocales) || in_array($setLocale, $contextSupportedLocales)) && in_array($setLocale, $site->getSupportedLocales())) { $session = $request->getSession(); $session->setSessionVar('currentLocale', $setLocale); } if (isset($_SERVER['HTTP_REFERER'])) { $request->redirectUrl($_SERVER['HTTP_REFERER']); } $request->redirect(null, 'index'); }
function getLocaleFiles($locale) { if (!AppLocale::isLocaleValid($locale)) { return null; } $localeFiles = AppLocale::getFilenameComponentMap($locale); $plugins =& PluginRegistry::loadAllPlugins(); foreach (array_keys($plugins) as $key) { $plugin =& $plugins[$key]; $localeFile = $plugin->getLocaleFilename($locale); if (!empty($localeFile)) { $localeFiles[] = $localeFile; } unset($plugin); } return $localeFiles; }
/** * Reload the default localized settings for the journal. * @param $args array * @param $request object */ function reloadLocalizedDefaultSettings($args, &$request) { // make sure the locale is valid $locale = $request->getUserVar('localeToLoad'); if (!AppLocale::isLocaleValid($locale)) { $request->redirect(null, null, 'languages'); } $this->validate(); $this->setupTemplate(true); $journal =& $request->getJournal(); $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO'); $journalSettingsDao->reloadLocalizedDefaultSettings($journal->getId(), 'registry/journalSettings.xml', array('indexUrl' => $request->getIndexUrl(), 'journalPath' => $journal->getData('path'), 'primaryLocale' => $journal->getPrimaryLocale(), 'journalName' => $journal->getTitle($journal->getPrimaryLocale())), $locale); // Display a notification import('lib.pkp.classes.notification.NotificationManager'); $notificationManager = new NotificationManager(); $notificationManager->createTrivialNotification('notification.notification', 'common.changesSaved'); $request->redirect(null, null, 'languages'); }
/** * Save contact settings. * @param $request PKPRequest */ function execute($request) { $user = $this->getUser(); $user->setCountry($this->getData('country')); $user->setEmail($this->getData('email')); $user->setPhone($this->getData('phone')); $user->setMailingAddress($this->getData('mailingAddress')); $user->setAffiliation($this->getData('affiliation'), null); // Localized $site = $request->getSite(); $availableLocales = $site->getSupportedLocales(); $locales = array(); foreach ($this->getData('userLocales') as $locale) { if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) { array_push($locales, $locale); } } $user->setLocales($locales); parent::execute($request, $user); }
/** * @copydoc Form::execute() */ function execute($request) { $site = $request->getSite(); $localesToInstall = $this->getData('localesToInstall'); if (isset($localesToInstall) && is_array($localesToInstall)) { $installedLocales = $site->getInstalledLocales(); $supportedLocales = $site->getSupportedLocales(); foreach ($localesToInstall as $locale) { if (AppLocale::isLocaleValid($locale) && !in_array($locale, $installedLocales)) { array_push($installedLocales, $locale); // Activate/support by default. if (!in_array($locale, $supportedLocales)) { array_push($supportedLocales, $locale); } AppLocale::installLocale($locale); } } $site->setInstalledLocales($installedLocales); $site->setSupportedLocales($supportedLocales); $siteDao = DAORegistry::getDAO('SiteDAO'); $siteDao->updateObject($site); } }
/** * Pre-installation. * @return boolean */ function preInstall() { if (!isset($this->currentVersion)) { $this->currentVersion = Version::fromString(''); } $this->locale = $this->getParam('locale'); $this->installedLocales = $this->getParam('additionalLocales'); if (!isset($this->installedLocales) || !is_array($this->installedLocales)) { $this->installedLocales = array(); } if (!in_array($this->locale, $this->installedLocales) && AppLocale::isLocaleValid($this->locale)) { array_push($this->installedLocales, $this->locale); } // Connect to database $conn = new DBConnection($this->getParam('databaseDriver'), $this->getParam('databaseHost'), $this->getParam('databaseUsername'), $this->getParam('databasePassword'), $this->getParam('createDatabase') ? null : $this->getParam('databaseName'), false, $this->getParam('connectionCharset') == '' ? false : $this->getParam('connectionCharset')); $this->dbconn =& $conn->getDBConn(); if (!$conn->isConnected()) { $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg()); return false; } DBConnection::getInstance($conn); return parent::preInstall(); }
/** * Try to translate an ISO language code to an OJS locale. * @param $language string 2- or 3-letter ISO language code * @return string|null An OJS locale or null if no matching * locale could be found. */ function translateLanguageToLocale($language) { $locale = null; if (strlen($language) == 2) { $language = AppLocale::get3LetterFrom2LetterIsoLanguage($language); } if (strlen($language) == 3) { $language = AppLocale::getLocaleFrom3LetterIso($language); } if (AppLocale::isLocaleValid($language)) { $locale = $language; } return $locale; }
/** * Create or update a user. * @param $args array * @param $request PKPRequest */ function &execute($args, $request) { parent::execute($request); $userDao = DAORegistry::getDAO('UserDAO'); $context = $request->getContext(); if (isset($this->userId)) { $userId = $this->userId; $user = $userDao->getById($userId); } if (!isset($user)) { $user = $userDao->newDataObject(); $user->setInlineHelp(1); // default new users to having inline help visible } $user->setSalutation($this->getData('salutation')); $user->setFirstName($this->getData('firstName')); $user->setMiddleName($this->getData('middleName')); $user->setLastName($this->getData('lastName')); $user->setSuffix($this->getData('suffix')); $user->setInitials($this->getData('initials')); $user->setGender($this->getData('gender')); $user->setAffiliation($this->getData('affiliation'), null); // Localized $user->setSignature($this->getData('signature'), null); // Localized $user->setEmail($this->getData('email')); $user->setUrl($this->getData('userUrl')); $user->setPhone($this->getData('phone')); $user->setOrcid($this->getData('orcid')); $user->setMailingAddress($this->getData('mailingAddress')); $user->setCountry($this->getData('country')); $user->setBiography($this->getData('biography'), null); // Localized $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0); $user->setAuthId((int) $this->getData('authId')); $site = $request->getSite(); $availableLocales = $site->getSupportedLocales(); $locales = array(); foreach ($this->getData('userLocales') as $locale) { if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) { array_push($locales, $locale); } } $user->setLocales($locales); if ($user->getAuthId()) { $authDao = DAORegistry::getDAO('AuthSourceDAO'); $auth =& $authDao->getPlugin($user->getAuthId()); } if ($user->getId() != null) { if ($this->getData('password') !== '') { if (isset($auth)) { $auth->doSetUserPassword($user->getUsername(), $this->getData('password')); $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only } else { $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password'))); } } if (isset($auth)) { // FIXME Should try to create user here too? $auth->doSetUserInfo($user); } $userDao->updateObject($user); } else { $user->setUsername($this->getData('username')); if ($this->getData('generatePassword')) { $password = Validation::generatePassword(); $sendNotify = true; } else { $password = $this->getData('password'); $sendNotify = $this->getData('sendNotify'); } if (isset($auth)) { $user->setPassword($password); // FIXME Check result and handle failures $auth->doCreateUser($user); $user->setAuthId($auth->authId); $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only } else { $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password)); } $user->setDateRegistered(Core::getCurrentDate()); $userId = $userDao->insertObject($user); if ($sendNotify) { // Send welcome email to user import('lib.pkp.classes.mail.MailTemplate'); $mail = new MailTemplate('USER_REGISTER'); $mail->setReplyTo($context->getSetting('contactEmail'), $context->getSetting('contactName')); $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName())); $mail->addRecipient($user->getEmail(), $user->getFullName()); $mail->send(); } } import('lib.pkp.classes.user.InterestManager'); $interestManager = new InterestManager(); $interestManager->setInterestsForUser($user, $this->getData('interests')); return $user; }
/** * Remove book for review cover page image. */ function removeBookForReviewCoverPage($args = array(), &$request) { $this->setupTemplate(); if (empty($args) || count($args) < 2) { $request->redirect(null, 'editor'); } $bookId = (int) $args[0]; $formLocale = $args[1]; if (!AppLocale::isLocaleValid($formLocale)) { $request->redirect(null, 'editor'); } $bfrPlugin =& PluginRegistry::getPlugin('generic', BOOKS_FOR_REVIEW_PLUGIN_NAME); $returnPage = $request->getUserVar('returnPage'); if ($returnPage != null) { $validPages =& $this->getValidReturnPages(); if (!in_array($returnPage, $validPages)) { $returnPage = null; } } $journal =& $request->getJournal(); $journalId = $journal->getId(); $bfrDao =& DAORegistry::getDAO('BookForReviewDAO'); // Ensure book for review is for this journal if ($bfrDao->getBookForReviewJournalId($bookId) == $journalId) { $bfrDao->removeCoverPage($bookId, $formLocale); $request->redirect(null, 'editor', 'editBookForReview', $bookId, array('returnPage' => $returnPage)); } $request->redirect(null, 'editor', 'booksForReview', $returnPage); }
/** * Remove cover page from article * @param $args array * @param $request PKPRequest */ function removeArticleCoverPage($args, &$request) { $articleId = (int) array_shift($args); $this->validate($request, $articleId); $formLocale = array_shift($args); if (!AppLocale::isLocaleValid($formLocale)) { $request->redirect(null, null, 'viewMetadata', $articleId); } import('classes.submission.sectionEditor.SectionEditorAction'); if (SectionEditorAction::removeArticleCoverPage($this->submission, $formLocale)) { $request->redirect(null, null, 'viewMetadata', $articleId); } }
/** * Retrieve the primary locale of the current context. * @return string */ function getPrimaryLocale() { static $locale; if ($locale) { return $locale; } if (defined('SESSION_DISABLE_INIT') || !Config::getVar('general', 'installed')) { return $locale = LOCALE_DEFAULT; } $journal =& Request::getJournal(); if (isset($journal)) { $locale = $journal->getPrimaryLocale(); } if (!isset($locale)) { $site =& Request::getSite(); $locale = $site->getPrimaryLocale(); } if (!isset($locale) || !AppLocale::isLocaleValid($locale)) { $locale = LOCALE_DEFAULT; } return $locale; }
/** * Change the locale for the current user. * @param $args array first parameter is the new locale */ function setLocale($args, $request) { $setLocale = array_shift($args); $site =& $request->getSite(); $journal =& $request->getJournal(); if ($journal != null) { $journalSupportedLocales = $journal->getSetting('supportedLocales'); if (!is_array($journalSupportedLocales)) { $journalSupportedLocales = array(); } } if (AppLocale::isLocaleValid($setLocale) && (!isset($journalSupportedLocales) || in_array($setLocale, $journalSupportedLocales)) && in_array($setLocale, $site->getSupportedLocales())) { $session =& $request->getSession(); $session->setSessionVar('currentLocale', $setLocale); } if (isset($_SERVER['HTTP_REFERER'])) { $request->redirectUrl($_SERVER['HTTP_REFERER']); } $source = $request->getUserVar('source'); if (isset($source) && !empty($source)) { $request->redirectUrl($request->getProtocol() . '://' . $request->getServerHost() . $source, false); } $request->redirect(null, 'index'); }
/** * Register a new user. * @return $userId int */ function execute() { $userDao =& DAORegistry::getDAO('UserDAO'); $user = new User(); $user->setSalutation($this->getData('salutation')); $user->setFirstName($this->getData('firstName')); $user->setMiddleName($this->getData('middleName')); $user->setLastName($this->getData('lastName')); $user->setGender($this->getData('gender')); $user->setInitials($this->getData('initials')); $user->setAffiliation($this->getData('affiliation')); $user->setEmail($this->getData('email')); $user->setUrl($this->getData('userUrl')); $user->setPhone($this->getData('phone')); $user->setFax($this->getData('fax')); $user->setMailingAddress($this->getData('mailingAddress')); $user->setCountry($this->getData('country')); $user->setBiography($this->getData('biography'), null); // Localized $user->setInterests($this->getData('interests'), null); // Localized $user->setGossip($this->getData('gossip'), null); // Localized $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0); $authDao =& DAORegistry::getDAO('AuthSourceDAO'); $auth =& $authDao->getDefaultPlugin(); $user->setAuthId($auth ? $auth->getAuthId() : 0); $site =& Request::getSite(); $availableLocales = $site->getSupportedLocales(); $locales = array(); foreach ($this->getData('userLocales') as $locale) { if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) { array_push($locales, $locale); } } $user->setLocales($locales); $user->setUsername($this->getData('username')); $password = Validation::generatePassword(); $sendNotify = $this->getData('sendNotify'); if (isset($auth)) { $user->setPassword($password); // FIXME Check result and handle failures $auth->doCreateUser($user); $user->setAuthId($auth->authId); $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only } else { $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password)); } $user->setDateRegistered(Core::getCurrentDate()); $userId = $userDao->insertUser($user); $roleDao =& DAORegistry::getDAO('RoleDAO'); $schedConf =& Request::getSchedConf(); $role = new Role(); $role->setConferenceId($schedConf->getConferenceId()); $role->setSchedConfId($schedConf->getId()); $role->setUserId($userId); $role->setRoleId(ROLE_ID_REVIEWER); $roleDao->insertRole($role); if ($sendNotify) { // Send welcome email to user import('mail.MailTemplate'); $mail = new MailTemplate('USER_REGISTER'); $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName')); $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password)); $mail->addRecipient($user->getEmail(), $user->getFullName()); $mail->send(); } return $userId; }
function importUsers() { assert($this->xml->name == 'users'); import('lib.pkp.classes.user.InterestManager'); $interestManager = new InterestManager(); $roleDao =& DAORegistry::getDAO('RoleDAO'); $userDAO =& DAORegistry::getDAO('UserDAO'); $publicFileManager =& new PublicFileManager(); $site =& Request::getSite(); $siteSupportedLocales = $site->getSupportedLocales(); $this->nextElement(); while ($this->xml->name == 'user') { $userXML = $this->getCurrentElementAsDom(); $username = (string) $userXML->username; $email = (string) $userXML->email; $userByEmail = $userDAO->getUserByEmail($email); $user = null; if (!empty($userByEmail)) { $user = $userByEmail; } else { $user = new User(); $user->setUsername((string) $userXML->username); $user->setPassword((string) $userXML->password); $user->setSalutation((string) $userXML->salutation); $user->setFirstName((string) $userXML->firstName); $user->setMiddleName((string) $userXML->middleName); $user->setInitials((string) $userXML->initials); $user->setLastName((string) $userXML->lastName); $user->setSuffix((string) $userXML->suffix); $user->setGender((string) $userXML->gender); $user->setEmail((string) $userXML->email); $user->setUrl((string) $userXML->url); $user->setPhone((string) $userXML->phone); $user->setFax((string) $userXML->fax); $user->setMailingAddress((string) $userXML->mailingAddress); $user->setBillingAddress((string) $userXML->billingAddress); $user->setCountry((string) $userXML->country); $locales = array(); foreach (explode(':', (string) $userXML->locales) as $locale) { if (AppLocale::isLocaleValid($locale) && in_array($locale, $siteSupportedLocales)) { array_push($locales, $locale); } } $user->setLocales($locales); $user->setDateLastEmail((string) $userXML->dateLastEmail); $user->setDateRegistered((string) $userXML->dateRegistered); $user->setDateValidated((string) $userXML->dateValidated); $user->setDateLastLogin((string) $userXML->dateLastLogin); $user->setMustChangePassword((int) $userXML->mustChangePassword); $user->setDisabled((int) $userXML->disabled); $user->setDisabledReason((string) $userXML->disabledReason); $user->setAuthId((int) $userXML->authId); $user->setAuthStr((string) $userXML->authStr); $user->setInlineHelp((int) $userXML->inlineHelp); $this->generateUsername($user); $userDAO->insertUser($user); $this->restoreDataObjectSettings($userDAO, $userXML->settings, 'user_settings', 'user_id', $user->getId()); $user = $userDAO->getById($user->getId()); $profileImage =& $user->getSetting('profileImage'); if ($profileImage) { $oldProfileImage = $profileImage['uploadName']; $extension = $publicFileManager->getExtension($oldProfileImage); $newProfileImage = 'profileImage-' . $user->getId() . "." . $extension; $sourceFile = $this->siteFolderPath . '/' . $oldProfileImage; $publicFileManager->copyFile($sourceFile, $publicFileManager->getSiteFilesPath() . "/" . $newProfileImage); unlink($sourceFile); $profileImage['uploadName'] = $newProfileImage; $user->updateSetting('profileImage', $profileImage); } $interests = array(); foreach ($userXML->interest as $interest) { $interests[] = (string) $interest; } $interestManager->setInterestsForUser($user, $interests); } $this->idTranslationTable->register(INTERNAL_TRANSFER_OBJECT_USER, (int) $userXML->oldId, $user->getId()); foreach ($userXML->role as $roleXML) { $role = new Role(); $role->setRoleId((int) $roleXML); $role->setUserId($user->getId()); $role->setJournalId($this->journal->getId()); $roleDao->insertRole($role); } $this->nextElement(); } }
/** * 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': $newUser->setTemporaryInterests($attrib->getValue()); 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; }
function saveEmail($args, $request) { $this->validate(); $plugin =& $this->plugin; $this->setupTemplate($request); $locale = array_shift($args); if (!AppLocale::isLocaleValid($locale)) { $request->redirect(null, null, 'index'); } $emails = TranslatorAction::getEmailTemplates($locale); $referenceEmails = TranslatorAction::getEmailTemplates(MASTER_LOCALE); $emailKey = array_shift($args); $targetFilename = str_replace(MASTER_LOCALE, $locale, $referenceEmails[$emailKey]['templateDataFile']); // FIXME: Ugly. if (!in_array($emailKey, array_keys($emails))) { // If it's not a reference or translation email, bail. if (!in_array($emailKey, array_keys($referenceEmails))) { $request->redirect(null, null, 'index'); } // If it's a reference email but not a translated one, // create a blank file. FIXME: This is ugly. if (!file_exists($targetFilename)) { $dir = dirname($targetFilename); if (!file_exists($dir)) { mkdir($dir); } file_put_contents($targetFilename, '<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE email_texts SYSTEM "../../../../../lib/pkp/dtd/emailTemplateData.dtd"> <!-- * emailTemplateData.xml * * Copyright (c) 2003-2013 John Willinsky * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING. * * Localized email templates XML file. * --> <email_texts locale="' . $locale . '"> </email_texts>'); } } import('lib.pkp.classes.file.EditableEmailFile'); $file = new EditableEmailFile($locale, $targetFilename); $subject = $this->correctCr($request->getUserVar('subject')); $body = $this->correctCr($request->getUserVar('body')); $description = $this->correctCr($request->getUserVar('description')); if (!$file->update($emailKey, $subject, $body, $description)) { $file->insert($emailKey, $subject, $body, $description); } $file->write(); if ($request->getUserVar('returnToCheck') == 1) { $request->redirect(null, null, 'check', $locale); } else { $request->redirect(null, null, 'edit', $locale); } }
/** * Register a new user. */ function execute() { $userDao =& DAORegistry::getDAO('UserDAO'); $journal =& Request::getJournal(); if (isset($this->userId)) { $user =& $userDao->getById($this->userId); } if (!isset($user)) { $user = new User(); } $user->setSalutation($this->getData('salutation')); $user->setFirstName($this->getData('firstName')); $user->setMiddleName($this->getData('middleName')); $user->setLastName($this->getData('lastName')); $user->setInitials($this->getData('initials')); $user->setGender($this->getData('gender')); $user->setAffiliation($this->getData('affiliation'), null); // Localized $user->setSignature($this->getData('signature'), null); // Localized $user->setEmail($this->getData('email')); $user->setData('orcid', $this->getData('orcid')); $user->setUrl($this->getData('userUrl')); $user->setPhone($this->getData('phone')); $user->setFax($this->getData('fax')); $user->setMailingAddress($this->getData('mailingAddress')); $user->setCountry($this->getData('country')); $user->setBiography($this->getData('biography'), null); // Localized $user->setGossip($this->getData('gossip'), null); // Localized $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0); $user->setAuthId((int) $this->getData('authId')); $site =& Request::getSite(); $availableLocales = $site->getSupportedLocales(); $locales = array(); foreach ($this->getData('userLocales') as $locale) { if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) { array_push($locales, $locale); } } $user->setLocales($locales); if ($user->getAuthId()) { $authDao =& DAORegistry::getDAO('AuthSourceDAO'); $auth =& $authDao->getPlugin($user->getAuthId()); } if ($user->getId() != null) { $userId = $user->getId(); if ($this->getData('password') !== '') { if (isset($auth)) { $auth->doSetUserPassword($user->getUsername(), $this->getData('password')); $user->setPassword(Validation::encryptCredentials($userId, Validation::generatePassword())); // Used for PW reset hash only } else { $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password'))); } } if (isset($auth)) { // FIXME Should try to create user here too? $auth->doSetUserInfo($user); } $userDao->updateObject($user); } else { $user->setUsername($this->getData('username')); if ($this->getData('generatePassword')) { $password = Validation::generatePassword(); $sendNotify = true; } else { $password = $this->getData('password'); $sendNotify = $this->getData('sendNotify'); } if (isset($auth)) { $user->setPassword($password); // FIXME Check result and handle failures $auth->doCreateUser($user); $user->setAuthId($auth->authId); $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only } else { $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password)); } $user->setDateRegistered(Core::getCurrentDate()); $userId = $userDao->insertUser($user); $isManager = Validation::isJournalManager(); if (!empty($this->_data['enrollAs'])) { foreach ($this->getData('enrollAs') as $roleName) { // Enroll new user into an initial role $roleDao =& DAORegistry::getDAO('RoleDAO'); $roleId = $roleDao->getRoleIdFromPath($roleName); if (!$isManager && $roleId != ROLE_ID_READER) { continue; } if ($roleId != null) { $role = new Role(); $role->setJournalId($journal->getId()); $role->setUserId($userId); $role->setRoleId($roleId); $roleDao->insertRole($role); } } } if ($sendNotify) { // Send welcome email to user import('classes.mail.MailTemplate'); $mail = new MailTemplate('USER_REGISTER'); $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName')); $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName())); $mail->addRecipient($user->getEmail(), $user->getFullName()); $mail->send(); } } // Insert the user interests $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly'); import('lib.pkp.classes.user.InterestManager'); $interestManager = new InterestManager(); $interestManager->setInterestsForUser($user, $interests); }
/** * Update the locale support state (enabled or disabled). * @param $request Request * @param $rowId string The locale row id. * @param $enable boolean Enable locale flag. */ function _updateLocaleSupportState($request, $rowId, $enable) { $newSupportedLocales = array(); $gridData = $this->getGridDataElements($request); foreach ($gridData as $locale => $data) { if ($data['supported']) { array_push($newSupportedLocales, $locale); } } if (AppLocale::isLocaleValid($rowId)) { if ($enable) { array_push($newSupportedLocales, $rowId); } else { $key = array_search($rowId, $newSupportedLocales); if ($key !== false) { unset($newSupportedLocales[$key]); } } } $site = $request->getSite(); $site->setSupportedLocales($newSupportedLocales); $siteDao = DAORegistry::getDAO('SiteDAO'); $siteDao->updateObject($site); $this->_updateContextLocaleSettings($request); }
/** * Set context primary locale. * @param $args array * @param $request Request * @return JSONMessage JSON object */ function setContextPrimaryLocale($args, $request) { $locale = (string) $request->getUserVar('rowId'); $context = $request->getContext(); $availableLocales = $this->getGridDataElements($request); if (AppLocale::isLocaleValid($locale) && array_key_exists($locale, $availableLocales)) { // Make sure at least the primary locale is chosen as available foreach (array('supportedLocales', 'supportedSubmissionLocales', 'supportedFormLocales') as $name) { ${$name} = $context->getSetting($name); if (!in_array($locale, ${$name})) { array_push(${$name}, $locale); $context->updateSetting($name, ${$name}); } } $context->setPrimaryLocale($locale); $contextDao = $context->getDAO(); $contextDao->updateObject($context); $notificationManager = new NotificationManager(); $user = $request->getUser(); $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.localeSettingsSaved'))); } return DAO::getDataChangedEvent(); }
/** * Reload the default localized settings for the journal * @param $args array * @param $request object */ function reloadLocalizedDefaultSettings($args, $request) { // make sure the locale is valid $locale = $request->getUserVar('localeToLoad'); if (!AppLocale::isLocaleValid($locale)) { $json = new JSONMessage(false); return $json->getString(); } $journal = $request->getJournal(); $journalSettingsDao = DAORegistry::getDAO('JournalSettingsDAO'); $journalSettingsDao->reloadLocalizedDefaultSettings($journal->getId(), 'registry/journalSettings.xml', array('indexUrl' => $request->getIndexUrl(), 'journalPath' => $journal->getData('path'), 'primaryLocale' => $journal->getPrimaryLocale(), 'journalName' => $journal->getName($journal->getPrimaryLocale())), $locale); // also reload the user group localizable data $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); $userGroupDao->installLocale($locale, $journal->getId()); return DAO::getDataChangedEvent(); }
/** * Create the journal issue element. * * @param $issue Issue * * @return XMLNode|DOMImplementation */ function &_journalIssueElement(&$issue) { $journalIssueElement =& XMLCustomWriter::createElement($this->getDoc(), 'JournalIssue'); // Volume $volume = $issue->getVolume(); if (!empty($volume)) { XMLCustomWriter::createChildWithText($this->getDoc(), $journalIssueElement, 'JournalVolumeNumber', $volume); } // Number $number = $issue->getNumber(); if (!empty($number)) { XMLCustomWriter::createChildWithText($this->getDoc(), $journalIssueElement, 'JournalIssueNumber', $number); } // Identification $identification = $issue->getIssueIdentification(); if (!empty($identification)) { XMLCustomWriter::createChildWithText($this->getDoc(), $journalIssueElement, 'JournalIssueDesignation', $identification); } assert(!(empty($number) && empty($identification))); // Nominal Year $year = (string) $issue->getYear(); $yearlen = strlen($year); if (!empty($year) && ($yearlen == 2 || $yearlen == 4)) { $issueDate =& XMLCustomWriter::createElement($this->getDoc(), 'JournalIssueDate'); XMLCustomWriter::createChildWithText($this->getDoc(), $issueDate, 'DateFormat', O4DOI_DATE_FORMAT_YYYY); // Try to extend the year if necessary. if ($yearlen == 2) { // Assume that the issue date will never be // more than one year in the future. if ((int) $year <= (int) date('y') + 1) { $year = '20' . $year; } else { $year = '19' . $year; } } XMLCustomWriter::createChildWithText($this->getDoc(), $issueDate, 'Date', $year); XMLCustomWriter::appendChild($journalIssueElement, $issueDate); } if ($this->_getObjectType() == 'Issue') { // Publication Date $datePublished = $issue->getDatePublished(); if (!empty($datePublished)) { XMLCustomWriter::appendChild($journalIssueElement, $this->_publicationDateElement($datePublished)); } // Issue Title (mandatory) $journal =& $this->getJournal(); $locale = $journal->getPrimaryLocale(); assert(AppLocale::isLocaleValid($locale)); $localizedTitle = $issue->getTitle($locale); if (empty($localizedTitle)) { $localizedTitle = $journal->getTitle($locale); assert(!empty($localizedTitle)); // Hack to make sure that no untranslated title appears: $showTitle = $issue->getShowTitle(); $issue->setShowTitle(0); $localizedTitle = $localizedTitle . ', ' . $issue->getIssueIdentification(); $issue->setShowTitle($showTitle); } XMLCustomWriter::appendChild($journalIssueElement, $this->_titleElement($locale, $localizedTitle, O4DOI_TITLE_TYPE_ISSUE)); // Extent (for issues-as-manifestation only) if (!$this->_exportIssuesAsWork()) { $issueGalleyDao =& DAORegistry::getDAO('IssueGalleyDAO'); /* @var $issueGalleyDao IssueGalleyDAO */ $issueGalleys =& $issueGalleyDao->getGalleysByIssue($issue->getId()); if (!empty($issueGalleys)) { foreach ($issueGalleys as $issueGalley) { XMLCustomWriter::appendChild($journalIssueElement, $this->_extentElement($issueGalley)); } } } } return $journalIssueElement; }
/** * Export the locale files to the browser as a tarball. * Requires tar (configured in config.inc.php) for operation. * @param $args array Parameters. * @param $request PKPRequest Request object. */ function export($args, $request) { $locale = $request->getUserVar('locale'); if (!AppLocale::isLocaleValid($locale)) { fatalError('Invalid locale.'); } // Construct the tar command $tarBinary = Config::getVar('cli', 'tar'); if (empty($tarBinary) || !file_exists($tarBinary)) { fatalError('cli.tar binary not properly configured.'); } $command = $tarBinary . ' cz'; $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); $localeFilesList = array_merge(TranslatorAction::getLocaleFiles($locale), TranslatorAction::getMiscLocaleFiles($locale), array($emailTemplateDao->getMainEmailTemplateDataFilename($locale)), array_values(TranslatorAction::getEmailFileMap($locale))); // Include locale files (main file and plugin files) foreach ($localeFilesList as $file) { if (file_exists($file)) { $command .= ' ' . escapeshellarg($file); } } header('Content-Type: application/x-gtar'); header("Content-Disposition: attachment; filename=\"{$locale}.tar.gz\""); header('Cache-Control: private'); // Workarounds for IE weirdness passthru($command); }
/** * Change the locale for the current user. * @param $args array first parameter is the new locale */ function setLocale($args) { $setLocale = isset($args[0]) ? $args[0] : null; $site =& Request::getSite(); $conference =& Request::getConference(); if ($conference != null) { $conferenceSupportedLocales = $conference->getSetting('supportedLocales'); if (!is_array($conferenceSupportedLocales)) { $conferenceSupportedLocales = array(); } } if (AppLocale::isLocaleValid($setLocale) && (!isset($conferenceSupportedLocales) || in_array($setLocale, $conferenceSupportedLocales)) && in_array($setLocale, $site->getSupportedLocales())) { $session =& Request::getSession(); $session->setSessionVar('currentLocale', $setLocale); } if (isset($_SERVER['HTTP_REFERER'])) { Request::redirectUrl($_SERVER['HTTP_REFERER']); } $source = Request::getUserVar('source'); if (isset($source) && !empty($source)) { Request::redirectUrl(Request::getProtocol() . '://' . Request::getServerHost() . $source, false); } Request::redirect(null, null, 'index'); }
/** * Remove cover page from issue */ function removeIssueCoverPage($args, $request) { $issueId = (int) array_shift($args); $this->validate($issueId, true); $formLocale = array_shift($args); if (!AppLocale::isLocaleValid($formLocale)) { $request->redirect(null, null, 'issueData', $issueId); } $journal =& $request->getJournal(); $issue =& $this->issue; import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $publicFileManager->removeJournalFile($journal->getId(), $issue->getFileName($formLocale)); $issue->setFileName('', $formLocale); $issue->setOriginalFileName('', $formLocale); $issue->setWidth('', $formLocale); $issue->setHeight('', $formLocale); $issueDao =& DAORegistry::getDAO('IssueDAO'); $issueDao->updateIssue($issue); $request->redirect(null, null, 'issueData', $issueId); }