/** * Display a list of the emails within the current conference. */ function emails() { $this->validate(); $this->setupTemplate(true); $conference =& Request::getConference(); $rangeInfo = Handler::getRangeInfo('emails', array()); $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO'); $emailTemplatesArray =& $emailTemplateDao->getEmailTemplates(AppLocale::getLocale(), $conference->getId()); import('core.ArrayItemIterator'); if ($rangeInfo && $rangeInfo->isValid()) { while (true) { $emailTemplates = new ArrayItemIterator($emailTemplatesArray, $rangeInfo->getPage(), $rangeInfo->getCount()); if ($emailTemplates->isInBounds()) { break; } unset($rangeInfo); $rangeInfo =& $emailTemplates->getLastPageRangeInfo(); unset($emailTemplates); } } else { $emailTemplates = new ArrayItemIterator($emailTemplatesArray); } $templateMgr =& TemplateManager::getManager(); // The bread crumbs depends on whether we're doing scheduled conference or conference // management. FIXME: this is going to be a common situation, and this isn't // an elegant way of testing for it. if (Request::getRequestedPage() === 'manager') { $templateMgr->assign('pageHierarchy', array(array(Request::url(null, 'index', 'manager'), 'manager.conferenceSiteManagement'))); } else { $templateMgr->assign('pageHierarchy', array(array(Request::url(null, null, 'manager'), 'manager.schedConfManagement'))); } $templateMgr->assign_by_ref('emailTemplates', $emailTemplates); $templateMgr->assign('helpTopicId', 'conference.generalManagement.emails'); $templateMgr->display('manager/emails/emails.tpl'); }
/** * Retrieve announcement type name by ID. * @param $typeId int * @return string */ function getAnnouncementTypeName($typeId) { $result = $this->retrieve('SELECT COALESCE(l.setting_value, p.setting_value) FROM announcement_type_settings p LEFT JOIN announcement_type_settings l ON (l.type_id = ? AND l.setting_name = ? AND l.locale = ?) WHERE p.type_id = ? AND p.setting_name = ? AND p.locale = ?', array((int) $typeId, 'name', AppLocale::getLocale(), (int) $typeId, 'name', AppLocale::getPrimaryLocale())); $returner = isset($result->fields[0]) ? $result->fields[0] : false; $result->Close(); return $returner; }
function initialize(&$request) { parent::initialize($request); // Basic grid configuration $this->setId('preparedEmailsGrid'); AppLocale::requireComponents(LOCALE_COMPONENT_PKP_MANAGER); // Set the grid title. $this->setTitle('grid.preparedEmails.title'); $this->setInstructions('grid.preparedEmails.description'); // Elements to be displayed in the grid $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */ $emailTemplates =& $emailTemplateDao->getEmailTemplates(AppLocale::getLocale(), $this->getContextId($request)); $rowData = array(); foreach ($emailTemplates as $emailTemplate) { $rowData[$emailTemplate->getEmailKey()] = $emailTemplate; } $this->setGridDataElements($rowData); // Grid actions import('lib.pkp.controllers.grid.settings.preparedEmails.linkAction.EditEmailLinkAction'); $addEmailLinkAction = new EditEmailLinkAction($request); $this->addAction($addEmailLinkAction); import('lib.pkp.classes.linkAction.LinkAction'); import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal'); $router =& $request->getRouter(); $this->addAction(new LinkAction('resetAll', new RemoteActionConfirmationModal(__('manager.emails.resetAll.message'), null, $router->url($request, null, 'grid.settings.preparedEmails.PreparedEmailsGridHandler', 'resetAllEmails')), __('manager.emails.resetAll'), 'reset_default')); // Columns import('lib.pkp.controllers.grid.settings.preparedEmails.PreparedEmailsGridCellProvider'); $cellProvider = new PreparedEmailsGridCellProvider(); $this->addColumn(new GridColumn('name', 'common.name', null, 'controllers/grid/gridCell.tpl', $cellProvider, array('width' => 40))); $this->addColumn(new GridColumn('sender', 'email.sender', null, 'controllers/grid/gridCell.tpl', $cellProvider, array('width' => 10))); $this->addColumn(new GridColumn('recipient', 'email.recipient', null, 'controllers/grid/gridCell.tpl', $cellProvider)); $this->addColumn(new GridColumn('subject', 'common.subject', null, 'controllers/grid/gridCell.tpl', $cellProvider)); $this->addColumn(new GridColumn('enabled', 'common.enabled', null, 'controllers/grid/common/cell/selectStatusCell.tpl', $cellProvider, array('width' => 5))); }
/** * @see PaymentPlugin::displayPaymentForm */ function displayPaymentForm($queuedPaymentId, &$queuedPayment, &$request) { if (!$this->isConfigured()) { return false; } $schedConf =& $request->getSchedConf(); $user =& $request->getUser(); $params = array('charset' => Config::getVar('i18n', 'client_charset'), 'business' => $this->getSetting($schedConf->getConferenceId(), $schedConf->getId(), 'selleraccount'), 'item_name' => $queuedPayment->getDescription(), 'amount' => sprintf('%.2F', $queuedPayment->getAmount()), 'quantity' => 1, 'no_note' => 1, 'no_shipping' => 1, 'currency_code' => $queuedPayment->getCurrencyCode(), 'lc' => String::substr(AppLocale::getLocale(), 3), 'custom' => $queuedPaymentId, 'notify_url' => $request->url(null, null, 'payment', 'plugin', array($this->getName(), 'ipn')), 'return' => $queuedPayment->getRequestUrl(), 'cancel_return' => $request->url(null, null, 'payment', 'plugin', array($this->getName(), 'cancel')), 'first_name' => $user ? $user->getFirstName() : '', 'last_name' => $user ? $user->getLastname() : '', 'item_number' => 1, 'cmd' => '_xclick'); $templateMgr =& TemplateManager::getManager(); switch ($queuedPayment->getType()) { case QUEUED_PAYMENT_TYPE_REGISTRATION: // Provide registration-specific details to template. $registrationDao = DAORegistry::getDAO('RegistrationDAO'); $registrationOptionDao = DAORegistry::getDAO('RegistrationOptionDAO'); $registrationTypeDao = DAORegistry::getDAO('RegistrationTypeDAO'); $registration =& $registrationDao->getRegistration($queuedPayment->getAssocId()); if (!$registration || $registration->getUserId() != $queuedPayment->getUserId() || $registration->getSchedConfId() != $queuedPayment->getSchedConfId()) { break; } $registrationOptionIterator =& $registrationOptionDao->getRegistrationOptionsBySchedConfId($schedConf->getId()); $registrationOptionCosts = $registrationTypeDao->getRegistrationOptionCosts($registration->getTypeId()); $registrationOptionIds = $registrationOptionDao->getRegistrationOptions($registration->getRegistrationId()); $templateMgr->assign('registration', $registration); $templateMgr->assign('registrationType', $registrationTypeDao->getRegistrationType($registration->getTypeId())); $templateMgr->assign('registrationOptions', $registrationOptionIterator->toArray()); $templateMgr->assign('registrationOptionCosts', $registrationOptionCosts); $templateMgr->assign('registrationOptionIds', $registrationOptionIds); } $templateMgr->assign('params', $params); $templateMgr->assign('paypalFormUrl', $this->getSetting($schedConf->getConferenceId(), $schedConf->getId(), 'paypalurl')); $templateMgr->display($this->getTemplatePath() . 'paymentForm.tpl'); return true; }
/** * Extracts variables for a given column from a data element * so that they may be assigned to template before rendering. * @param $element mixed * @param $columnId string * @return array */ function getTemplateVarsFromRowColumn($row, $column) { $element =& $row->getData(); $columnId = $column->getId(); assert(is_a($element, 'DataObject') && !empty($columnId)); $roleDao = DAORegistry::getDAO('RoleDAO'); /* @var $roleDao RoleDAO */ switch ($columnId) { case 'name': $label = $element->getEmailKey(); return array('label' => ucwords(strtolower(str_replace('_', ' ', $label)))); case 'sender': $roleId = $element->getFromRoleId(); $label = $roleDao->getRoleNames(false, array($roleId)); return array('label' => __(array_shift($label))); case 'recipient': $roleId = $element->getToRoleId(); $label = $roleDao->getRoleNames(false, array($roleId)); return array('label' => __(array_shift($label))); case 'subject': $locale = AppLocale::getLocale(); $label = $element->getSubject(); return array('label' => $label); case 'enabled': $selectDisabled = $element->getCanDisable() ? false : true; return array('selected' => $element->getEnabled(), 'disabled' => $selectDisabled); } }
function _cacheMiss(&$cache, $id) { $allCodelistItems =& Registry::get('all' . $this->getListName() . 'CodelistItems', true, null); if ($allCodelistItems === null) { // Add a locale load to the debug notes. $notes =& Registry::get('system.debug.notes'); $locale = $cache->cacheId; if ($locale == null) { $locale = AppLocale::getLocale(); } $filename = $this->getFilename($locale); $notes[] = array('debug.notes.codelistItemListLoad', array('filename' => $filename)); // Reload locale registry file $xmlDao = new XMLDAO(); $listName = $this->getListName(); // i.e., 'List30' import('lib.pkp.classes.codelist.ONIXParserDOMHandler'); $handler = new ONIXParserDOMHandler($listName); import('lib.pkp.classes.xslt.XSLTransformer'); import('lib.pkp.classes.file.FileManager'); import('classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $fileManager = new FileManager(); // Ensure that the temporary file dir exists $tmpDir = $temporaryFileManager->getBasePath(); if (!file_exists($tmpDir)) { mkdir($tmpDir); } $tmpName = tempnam($tmpDir, 'ONX'); $xslTransformer = new XSLTransformer(); $xslTransformer->setParameters(array('listName' => $listName)); $xslTransformer->setRegisterPHPFunctions(true); $xslFile = 'lib/pkp/xml/onixFilter.xsl'; $filteredXml = $xslTransformer->transform($filename, XSL_TRANSFORMER_DOCTYPE_FILE, $xslFile, XSL_TRANSFORMER_DOCTYPE_FILE, XSL_TRANSFORMER_DOCTYPE_STRING); if (!$filteredXml) { assert(false); } $data = null; if (is_writeable($tmpName)) { $fp = fopen($tmpName, 'wb'); fwrite($fp, $filteredXml); fclose($fp); $data = $xmlDao->parseWithHandler($tmpName, $handler); $fileManager->deleteFile($tmpName); } else { fatalError('misconfigured directory permissions on: ' . $tmpDir); } // Build array with ($charKey => array(stuff)) if (isset($data[$listName])) { foreach ($data[$listName] as $code => $codelistData) { $allCodelistItems[$code] = $codelistData; } } if (is_array($allCodelistItems)) { asort($allCodelistItems); } $cache->setEntireCache($allCodelistItems); } return null; }
/** * Public view book for review details. */ function viewBookForReview($args = array(), &$request) { $this->setupTemplate(true); $journal =& $request->getJournal(); $journalId = $journal->getId(); $bfrPlugin =& PluginRegistry::getPlugin('generic', BOOKS_FOR_REVIEW_PLUGIN_NAME); $bookId = !isset($args) || empty($args) ? null : (int) $args[0]; $bfrDao =& DAORegistry::getDAO('BookForReviewDAO'); // Ensure book for review is valid and for this journal if ($bfrDao->getBookForReviewJournalId($bookId) == $journalId) { $book =& $bfrDao->getBookForReview($bookId); $bfrPlugin->import('classes.BookForReview'); // Ensure book is still available if ($book->getStatus() == BFR_STATUS_AVAILABLE) { $isAuthor = Validation::isAuthor(); import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $coverPagePath = $request->getBaseUrl() . '/'; $coverPagePath .= $publicFileManager->getJournalFilesPath($journalId) . '/'; $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('coverPagePath', $coverPagePath); $templateMgr->assign('locale', AppLocale::getLocale()); $templateMgr->assign_by_ref('bookForReview', $book); $templateMgr->assign('isAuthor', $isAuthor); $templateMgr->display($bfrPlugin->getTemplatePath() . 'bookForReview.tpl'); } } $request->redirect(null, 'booksForReview'); }
/** * Handle a cache miss * @param $cache GenericCache * @param $id mixed ID that wasn't found in the cache * @return null */ function _cacheMiss($cache, $id) { $allCodelistItems =& Registry::get('all' . $this->getName() . 'CodelistItems', true, null); if ($allCodelistItems === null) { // Add a locale load to the debug notes. $notes =& Registry::get('system.debug.notes'); $locale = $cache->cacheId; if ($locale == null) { $locale = AppLocale::getLocale(); } $filename = $this->getFilename($locale); $notes[] = array('debug.notes.codelistItemListLoad', array('filename' => $filename)); // Reload locale registry file $xmlDao = new XMLDAO(); $nodeName = $this->getName(); // i.e., subject $data = $xmlDao->parseStruct($filename, array($nodeName)); // Build array with ($charKey => array(stuff)) if (isset($data[$nodeName])) { foreach ($data[$nodeName] as $codelistData) { $allCodelistItems[$codelistData['attributes']['code']] = array($codelistData['attributes']['text']); } } if (is_array($allCodelistItems)) { asort($allCodelistItems); } $cache->setEntireCache($allCodelistItems); } return null; }
/** * @see Filter::process() * @param $input MetadataDescription NLM citation description * @return string formatted citation output */ function &process(&$input) { // Initialize view $locale = AppLocale::getLocale(); $templateMgr =& TemplateManager::getManager($this->_request); // Add the filter's directory as additional template dir so that // citation output format templates can include sub-templates in // the same folder. $templateMgr->template_dir[] = $this->getBasePath(); // Loop over the statements in the schema and add them // to the template $propertyNames =& $input->getPropertyNames(); foreach ($propertyNames as $propertyName) { $templateVariable = $input->getNamespacedPropertyId($propertyName); if ($input->hasProperty($propertyName)) { $propertyLocale = $input->getProperty($propertyName)->getTranslated() ? $locale : null; $templateMgr->assign_by_ref($templateVariable, $input->getStatement($propertyName, $propertyLocale)); } else { // Delete potential leftovers from previous calls $templateMgr->clear_assign($templateVariable); } } // Let the template engine render the citation $templateName = $this->_getCitationTemplate(); $output = $templateMgr->fetch($templateName); // Remove the additional template dir array_pop($templateMgr->template_dir); return $output; }
function register($category, $path) { if (parent::register($category, $path)) { if ($this->getEnabled()) { // Add custom locale data for already registered locale files. $locale = AppLocale::getLocale(); $localeFiles = AppLocale::getLocaleFiles($locale); $journal = Request::getJournal(); $journalId = $journal->getId(); $publicFilesDir = Config::getVar('files', 'public_files_dir'); $customLocalePathBase = $publicFilesDir . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR; import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); foreach ($localeFiles as $localeFile) { $customLocalePath = $customLocalePathBase . $localeFile->getFilename(); if ($fileManager->fileExists($customLocalePath)) { AppLocale::registerLocaleFile($locale, $customLocalePath, true); } } // Add custom locale data for all locale files registered after this plugin HookRegistry::register('PKPLocale::registerLocaleFile', array(&$this, 'addCustomLocale')); } return true; } return false; }
/** * Display this galley in some manner. * * @param $publishedMonograph PublishedMonograph * @param $submissionFile SubmissionFile */ function displaySubmissionFile($publishedMonograph, $publicationFormat, $submissionFile) { $templateMgr = TemplateManager::getManager($this->getRequest()); $templateFilename = $this->getTemplateFilename(); if ($templateFilename === null) { return ''; } // Set up the viewable file template variables. $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); $chapterDao = DAORegistry::getDAO('ChapterDAO'); $genreDao = DAORegistry::getDAO('GenreDAO'); // Find a good candidate for a publication date $publicationDateDao = DAORegistry::getDAO('PublicationDateDAO'); $publicationDates = $publicationDateDao->getByPublicationFormatId($publicationFormat->getId()); $bestPublicationDate = null; while ($publicationDate = $publicationDates->next()) { // 11: Date of first publication; 01: Publication date if ($publicationDate->getRole() != '11' && $publicationDate->getRole() != '01') { continue; } if ($bestPublicationDate) { $bestPublicationDate = min($bestPublicationDate, $publicationDate->getUnixTime()); } else { $bestPublicationDate = $publicationDate->getUnixTime(); } } $templateMgr->assign(array('submissionKeywords' => $submissionKeywordDao->getKeywords($publishedMonograph->getId(), array_merge(array(AppLocale::getLocale()), array_keys(AppLocale::getSupportedLocales()))), 'publishedMonograph' => $publishedMonograph, 'publicationFormat' => $publicationFormat, 'submissionFile' => $submissionFile, 'chapter' => $chapterDao->getChapter($submissionFile->getData('chapterId')), 'genre' => $genreDao->getById($submissionFile->getGenreId()), 'bestPublicationDate' => $bestPublicationDate)); // Fetch the viewable file template render. $templateMgr->assign('viewableFileContent', $templateMgr->fetch($this->getTemplatePath() . $templateFilename)); // Show the front-end. $templateMgr->display('frontend/pages/viewFile.tpl'); }
/** * Save the new image file. * @param $request Request. */ function execute($request) { $temporaryFile = $this->fetchTemporaryFile($request); import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); if (is_a($temporaryFile, 'TemporaryFile')) { $type = $temporaryFile->getFileType(); $extension = $publicFileManager->getImageExtension($type); if (!$extension) { return false; } $locale = AppLocale::getLocale(); $uploadName = $this->getFileSettingName() . '_' . $locale . $extension; if ($publicFileManager->copyFile($temporaryFile->getFilePath(), $publicFileManager->getSiteFilesPath() . '/' . $uploadName)) { // Get image dimensions $filePath = $publicFileManager->getSiteFilesPath(); list($width, $height) = getimagesize($filePath . '/' . $uploadName); $site = $request->getSite(); $siteDao = DAORegistry::getDAO('SiteDAO'); $value = $site->getSetting($this->getFileSettingName()); $imageAltText = $this->getData('imageAltText'); $value[$locale] = array('originalFilename' => $temporaryFile->getOriginalFileName(), 'uploadName' => $uploadName, 'width' => $width, 'height' => $height, 'dateUploaded' => Core::getCurrentDate(), 'altText' => $imageAltText[$locale]); $site->updateSetting($this->getFileSettingName(), $value, 'object', true); // Clean up the temporary file $this->removeTemporaryFile($request); return true; } } return false; }
/** * Internal function to assign information for the Counter part of a report */ function _assignTemplateCounterXML($templateManager, $begin, $end = '') { $journal =& Request::getJournal(); $counterReportDao =& DAORegistry::getDAO('CounterReportDAO'); $journalDao =& DAORegistry::getDAO('JournalDAO'); $journalIds = $counterReportDao->getJournalIds(); if ($end == '') { $end = $begin; } $i = 0; foreach ($journalIds as $journalId) { $journal =& $journalDao->getById($journalId); if (!$journal) { continue; } $entries = $counterReportDao->getMonthlyLogRange($journalId, $begin, $end); $journalsArray[$i]['entries'] = $this->_arrangeEntries($entries, $begin, $end); $journalsArray[$i]['journalTitle'] = $journal->getLocalizedTitle(); $journalsArray[$i]['publisherInstitution'] = $journal->getSetting('publisherInstitution'); $journalsArray[$i]['printIssn'] = $journal->getSetting('printIssn'); $journalsArray[$i]['onlineIssn'] = $journal->getSetting('onlineIssn'); $i++; } $siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO'); $siteTitle = $siteSettingsDao->getSetting('title', AppLocale::getLocale()); $base_url =& Config::getVar('general', 'base_url'); $reqUser =& Request::getUser(); $templateManager->assign_by_ref('reqUser', $reqUser); $templateManager->assign_by_ref('journalsArray', $journalsArray); $templateManager->assign('siteTitle', $siteTitle); $templateManager->assign('base_url', $base_url); }
/** * @see Filter::process() */ function &process(&$input) { // Initialize view $locale = AppLocale::getLocale(); $application = PKPApplication::getApplication(); $request = $application->getRequest(); $templateMgr = TemplateManager::getManager($request); // Add the filter's directory as additional template dir so that // templates can include sub-templates in the same folder. array_unshift($templateMgr->template_dir, $this->getBasePath()); // Give sub-filters a chance to add their variables // to the template. $this->addTemplateVars($templateMgr, $input, $request, $locale); // Use a base path hash as compile id to make sure that we don't // get namespace problems if several filters use the same // template names. $previousCompileId = $templateMgr->compile_id; $templateMgr->compile_id = md5($this->getBasePath()); // Let the template engine render the citation. $output = $templateMgr->fetch($this->getTemplateName()); // Remove the additional template dir array_shift($templateMgr->template_dir); // Restore the compile id. $templateMgr->compile_id = $previousCompileId; return $output; }
/** * Retrieve subscription type name by ID. * @param $typeId int * @return string */ function getSubscriptionTypeName($typeId) { $result = $this->retrieve('SELECT COALESCE(l.setting_value, p.setting_value) FROM subscription_type_settings l LEFT JOIN subscription_type_settings p ON (p.type_id = ? AND p.setting_name = ? AND p.locale = ?) WHERE l.type_id = ? AND l.setting_name = ? AND l.locale = ?', array($typeId, 'name', AppLocale::getLocale(), $typeId, 'name', AppLocale::getPrimaryLocale())); $returner = isset($result->fields[0]) ? $result->fields[0] : false; $result->Close(); return $returner; }
/** * Get the HTML contents for this block. * @param $templateMgr object * @return $string */ function getContents(&$templateMgr) { $journal =& Request::getJournal(); $cacheManager =& CacheManager::getManager(); $cache =& $cacheManager->getFileCache('keywords_' . AppLocale::getLocale(), $journal->getId(), array(&$this, '_cacheMiss')); // If the cache is older than a couple of days, regenerate it if (time() - $cache->getCacheTime() > 60 * 60 * 24 * KEYWORD_BLOCK_CACHE_DAYS) { $cache->flush(); } $keywords =& $cache->getContents(); if (empty($keywords)) { return ''; } // Get the max occurrences for all keywords $maxOccurs = array_shift(array_values($keywords)); // Now sort the array alphabetically ksort($keywords); $page = Request::getRequestedPage(); $op = Request::getRequestedOp(); $templateMgr->assign_by_ref('cloudKeywords', $keywords); $templateMgr->assign_by_ref('maxOccurs', $maxOccurs); if ($page == 'index' && $op == 'index' || $page == 'issue' || $page == 'search') { return parent::getContents($templateMgr); } else { return ''; } }
function _cacheMiss($cache, $id) { $allLanguages =& Registry::get('allLanguages-' . $cache->cacheId, true, null); if ($allLanguages === null) { // Add a locale load to the debug notes. $notes =& Registry::get('system.debug.notes'); $locale = $cache->cacheId; if ($locale == null) { $locale = AppLocale::getLocale(); } $filename = $this->getLanguageFilename($locale); $notes[] = array('debug.notes.languageListLoad', array('filename' => $filename)); // Reload locale registry file $xmlDao = new XMLDAO(); $data = $xmlDao->parseStruct($filename, array('language')); // Build array with ($charKey => array(stuff)) if (isset($data['language'])) { foreach ($data['language'] as $languageData) { $allLanguages[$languageData['attributes']['code']] = array($languageData['attributes']['name']); } } if (is_array($allLanguages)) { asort($allLanguages); } $cache->setEntireCache($allLanguages); } if (isset($allLanguages[$id])) { return $allLanguages[$id]; } else { return null; } }
/** * Iterate through the localized params for a notification's locale key. * For each parameter, return (in preferred order) a value for the user's current locale, * a param for the journal's default locale, or the first value (in case the value * is not localized) * @param $params array * @return array */ public function getParamsForCurrentLocale($params) { $locale = AppLocale::getLocale(); $primaryLocale = AppLocale::getPrimaryLocale(); $localizedParams = array(); foreach ($params as $name => $value) { if (!is_array($value)) { // Non-localized text $localizedParams[$name] = $value; } elseif (isset($value[$locale])) { // Check if the parameter is in the user's current locale $localizedParams[$name] = $value[$locale]; } elseif (isset($value[$primaryLocale])) { // Check if the parameter is in the default site locale $localizedParams[$name] = $value[$primaryLocale]; } else { // Otherwise, iterate over all supported locales and return the first match $locales = AppLocale::getSupportedLocales(); foreach ($locales as $localeKey) { if (isset($value[$localeKey])) { $localizedParams[$name] = $value[$localeKey]; } } } } return $localizedParams; }
/** * Get a piece of data for this object, localized to the current * locale if possible. * @param $key string * @param $preferredLocale string * @return mixed */ function &getLocalizedData($key, $preferredLocale = null) { if (is_null($preferredLocale)) { $preferredLocale = AppLocale::getLocale(); } $localePrecedence = array($preferredLocale, $this->getLocale()); foreach ($localePrecedence as $locale) { if (empty($locale)) { continue; } $value =& $this->getData($key, $locale); if (!empty($value)) { return $value; } unset($value); } // Fallback: Get the first available piece of data. $data =& $this->getData($key, null); if (!empty($data)) { return $data[array_shift(array_keys($data))]; } // No data available; return null. unset($data); $data = null; return $data; }
/** * Retrieve registration option name by ID. * @param $optionId int * @return string */ function getRegistrationOptionName($optionId) { $result =& $this->retrieve('SELECT COALESCE(l.setting_value, p.setting_value) FROM registration_option_settings l LEFT JOIN registration_option_settings p ON (p.option_id = ? AND p.setting_name = ? AND p.locale = ?) WHERE l.option_id = ? AND l.setting_name = ? AND l.locale = ?', array($optionId, 'name', AppLocale::getLocale(), $optionId, 'name', AppLocale::getPrimaryLocale())); $returner = isset($result->fields[0]) ? $result->fields[0] : false; $result->Close(); unset($result); return $returner; }
/** * Get the locale to display help files in. * If help isn't available for the current locale, * defaults to en_US. */ function getLocale() { $locale = AppLocale::getLocale(); if (!file_exists("help/{$locale}/.")) { return 'en_US'; } return $locale; }
/** * Get the localized value of the galley label. * @return $string */ function getGalleyLabel() { $label = $this->getLabel(); if ($this->getLocale() != AppLocale::getLocale()) { $locales = AppLocale::getAllLocales(); $label .= ' (' . $locales[$this->getLocale()] . ')'; } return $label; }
/** * Get localized favicon * @return string */ function getLocalizedFavicon() { $faviconArray = $this->getSetting('journalFavicon'); foreach (array(AppLocale::getLocale(), AppLocale::getPrimaryLocale()) as $locale) { if (isset($faviconArray[$locale])) { return $faviconArray[$locale]; } } return null; }
/** * Get "localized" press page logo (if applicable). * @return string */ function getPageHeaderLogo() { $logoArray = $this->getSetting('pageHeaderLogoImage'); foreach (array(AppLocale::getLocale(), AppLocale::getPrimaryLocale()) as $locale) { if (isset($logoArray[$locale])) { return $logoArray[$locale]; } } return null; }
/** * determine the correct language for the sharing button. Attempt to use the user's local * setting if it is one that AddThis supports. If not, use the language the administrator * has chosen. * * @return string * @param $default string */ function sharingLocale($default) { // getLocale() returns a string like 'en_US'. $locale = AppLocale::getLocale(); $lang = substr($locale, 0, 2); $languages = SharingRT::getLanguages(); if (isset($languages[$lang])) { return $lang; } return $default; }
/** * @see GridHandler::loadData() */ protected function loadData($request, $filter) { // Elements to be displayed in the grid $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */ $context = $request->getContext(); $emailTemplates = $emailTemplateDao->getEmailTemplates(AppLocale::getLocale(), $context->getId()); foreach ($emailTemplates as $emailTemplate) { $rowData[$emailTemplate->getEmailKey()] = $emailTemplate; } return $rowData; }
/** * Constructor. * @param $emailKey string unique identifier for the template * @param $locale string locale of the template * @param $includeSignature boolean optional */ function MailTemplate($emailKey = null, $locale = null, $context = null, $includeSignature = true) { parent::Mail(); $this->emailKey = isset($emailKey) ? $emailKey : null; // If a context wasn't specified, use the current request. $application = PKPApplication::getApplication(); $request = $application->getRequest(); if ($context === null) { $context = $request->getContext(); } $this->includeSignature = $includeSignature; // Use current user's locale if none specified $this->locale = isset($locale) ? $locale : AppLocale::getLocale(); // Record whether or not to BCC the sender when sending message $this->bccSender = $request->getUserVar('bccSender'); $this->addressFieldsEnabled = true; if (isset($this->emailKey)) { $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); $emailTemplate = $emailTemplateDao->getEmailTemplate($this->emailKey, $this->locale, $context == null ? 0 : $context->getId()); } $userSig = ''; $user = defined('SESSION_DISABLE_INIT') ? null : $request->getUser(); if ($user && $this->includeSignature) { $userSig = $user->getLocalizedSignature(); if (!empty($userSig)) { $userSig = "<br/>" . $userSig; } } if (isset($emailTemplate)) { $this->setSubject($emailTemplate->getSubject()); $this->setBody($emailTemplate->getBody() . $userSig); $this->enabled = $emailTemplate->getEnabled(); } else { $this->setBody($userSig); $this->enabled = true; } // Default "From" to user if available, otherwise site/context principal contact $this->emailHeader = ''; if ($user) { $this->setFrom($user->getEmail(), $user->getFullName()); } elseif (is_null($context) || is_null($context->getSetting('contactEmail'))) { $site = $request->getSite(); $this->setFrom($site->getLocalizedContactEmail(), $site->getLocalizedContactName()); } else { $this->setFrom($context->getSetting('contactEmail'), $context->getSetting('contactName')); $this->emailHeader = $context->getSetting('emailHeader'); } if ($context) { $this->setSubject('[' . $context->getLocalizedAcronym() . '] ' . $this->getSubject()); } $this->context = $context; $this->params = array(); }
/** * Get the localized location for citations in this journal * @param $journal Journal * @return string */ function getLocalizedLocation($journal) { $settings = $this->getSetting($journal->getId(), 'location'); if ($settings === null) { return null; } $location = $settings[AppLocale::getLocale()]; if (empty($location)) { $location = $settings[AppLocale::getPrimaryLocale()]; } return $location; }
function displayPaymentForm($queuedPaymentId, &$queuedPayment) { if (!$this->isConfigured()) { return false; } $schedConf =& Request::getSchedConf(); $user =& Request::getUser(); $params = array('charset' => Config::getVar('i18n', 'client_charset'), 'business' => $this->getSetting($schedConf->getConferenceId(), $schedConf->getId(), 'selleraccount'), 'item_name' => $queuedPayment->getDescription(), 'amount' => $queuedPayment->getAmount(), 'quantity' => 1, 'no_note' => 1, 'no_shipping' => 1, 'currency_code' => $queuedPayment->getCurrencyCode(), 'lc' => String::substr(AppLocale::getLocale(), 3), 'custom' => $queuedPaymentId, 'notify_url' => Request::url(null, null, 'payment', 'plugin', array($this->getName(), 'ipn')), 'return' => $queuedPayment->getRequestUrl(), 'cancel_return' => Request::url(null, null, 'payment', 'plugin', array($this->getName(), 'cancel')), 'first_name' => $user ? $user->getFirstName() : '', 'last_name' => $user ? $user->getLastname() : '', 'item_number' => 1, 'cmd' => '_xclick'); $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('params', $params); $templateMgr->assign('paypalFormUrl', $this->getSetting($schedConf->getConferenceId(), $schedConf->getId(), 'paypalurl')); $templateMgr->display($this->getTemplatePath() . 'paymentForm.tpl'); }
/** * Initialize form data. */ function initData() { $docRoot = dirname($_SERVER['DOCUMENT_ROOT']); if (Core::isWindows()) { // Replace backslashes with slashes for the default files directory. $docRoot = str_replace('\\', '/', $docRoot); } // Add a trailing slash for paths that aren't filesystem root if ($docRoot !== '/') { $docRoot .= '/'; } $this->_data = array('locale' => AppLocale::getLocale(), 'additionalLocales' => array(), 'clientCharset' => 'utf-8', 'connectionCharset' => '', 'databaseCharset' => '', 'filesDir' => $docRoot . 'files', 'databaseDriver' => 'mysql', 'databaseHost' => 'localhost', 'databaseUsername' => Application::getName(), 'databasePassword' => '', 'databaseName' => Application::getName(), 'createDatabase' => 1, 'oaiRepositoryId' => Application::getName() . '.' . $this->_request->getServerHost(), 'enableBeacon' => true); }