/** * @covers PKPLocale */ public function testGetLocaleStylesheet() { self::assertNull(Locale::getLocaleStyleSheet('en_US')); self::assertEquals('pt.css', Locale::getLocaleStyleSheet('pt_BR')); self::assertNull(Locale::getLocaleStyleSheet('xx_XX')); }
/** * Constructor. * Initialize template engine and assign basic template variables. * @param $request PKPRequest FIXME: is optional for backwards compatibility only - make mandatory */ function PKPTemplateManager($request = null) { // FIXME: for backwards compatibility only - remove if (!isset($request)) { if (Config::getVar('debug', 'deprecation_warnings')) { trigger_error('Deprecated function call.'); } $request =& Registry::get('request'); } assert(is_a($request, 'PKPRequest')); // Retrieve the router $router =& $request->getRouter(); assert(is_a($router, 'PKPRouter')); parent::Smarty(); // Set up Smarty configuration $baseDir = Core::getBaseDir(); $cachePath = CacheManager::getFileCachePath(); // Set the default template dir (app's template dir) $this->app_template_dir = $baseDir . DIRECTORY_SEPARATOR . 'templates'; // Set fallback template dir (core's template dir) $this->core_template_dir = $baseDir . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'templates'; $this->template_dir = array($this->app_template_dir, $this->core_template_dir); $this->compile_dir = $cachePath . DIRECTORY_SEPARATOR . 't_compile'; $this->config_dir = $cachePath . DIRECTORY_SEPARATOR . 't_config'; $this->cache_dir = $cachePath . DIRECTORY_SEPARATOR . 't_cache'; // Assign common variables $this->styleSheets = array(); $this->assign_by_ref('stylesheets', $this->styleSheets); $this->javaScripts = array(); $this->cacheability = CACHEABILITY_NO_STORE; // Safe default $this->assign('defaultCharset', Config::getVar('i18n', 'client_charset')); $this->assign('basePath', $request->getBasePath()); $this->assign('baseUrl', $request->getBaseUrl()); $this->assign('requiresFormRequest', $request->isPost()); if (is_a($router, 'PKPPageRouter')) { $this->assign('requestedPage', $router->getRequestedPage($request)); } $this->assign('currentUrl', $request->getCompleteUrl()); $this->assign('dateFormatTrunc', Config::getVar('general', 'date_format_trunc')); $this->assign('dateFormatShort', Config::getVar('general', 'date_format_short')); $this->assign('dateFormatLong', Config::getVar('general', 'date_format_long')); $this->assign('datetimeFormatShort', Config::getVar('general', 'datetime_format_short')); $this->assign('datetimeFormatLong', Config::getVar('general', 'datetime_format_long')); $this->assign('timeFormat', Config::getVar('general', 'time_format')); $this->assign('allowCDN', Config::getVar('general', 'enable_cdn')); $this->assign('useMinifiedJavaScript', Config::getVar('general', 'enable_minified')); $locale = Locale::getLocale(); $this->assign('currentLocale', $locale); // If there's a locale-specific stylesheet, add it. if (($localeStyleSheet = Locale::getLocaleStyleSheet($locale)) != null) { $this->addStyleSheet($request->getBaseUrl() . '/' . $localeStyleSheet); } $application =& PKPApplication::getApplication(); $this->assign('pageTitle', $application->getNameKey()); // Register custom functions $this->register_modifier('translate', array('Locale', 'translate')); $this->register_modifier('get_value', array(&$this, 'smartyGetValue')); $this->register_modifier('strip_unsafe_html', array('String', 'stripUnsafeHtml')); $this->register_modifier('String_substr', array('String', 'substr')); $this->register_modifier('to_array', array(&$this, 'smartyToArray')); $this->register_modifier('concat', array(&$this, 'smartyConcat')); $this->register_modifier('escape', array(&$this, 'smartyEscape')); $this->register_modifier('strtotime', array(&$this, 'smartyStrtotime')); $this->register_modifier('explode', array(&$this, 'smartyExplode')); $this->register_modifier('assign', array(&$this, 'smartyAssign')); $this->register_function('translate', array(&$this, 'smartyTranslate')); $this->register_function('flush', array(&$this, 'smartyFlush')); $this->register_function('call_hook', array(&$this, 'smartyCallHook')); $this->register_function('html_options_translate', array(&$this, 'smartyHtmlOptionsTranslate')); $this->register_block('iterate', array(&$this, 'smartyIterate')); $this->register_function('call_progress_function', array(&$this, 'smartyCallProgressFunction')); $this->register_function('page_links', array(&$this, 'smartyPageLinks')); $this->register_function('page_info', array(&$this, 'smartyPageInfo')); $this->register_function('get_help_id', array(&$this, 'smartyGetHelpId')); $this->register_function('icon', array(&$this, 'smartyIcon')); $this->register_function('help_topic', array(&$this, 'smartyHelpTopic')); $this->register_function('sort_heading', array(&$this, 'smartySortHeading')); $this->register_function('sort_search', array(&$this, 'smartySortSearch')); $this->register_function('get_debug_info', array(&$this, 'smartyGetDebugInfo')); $this->register_function('assign_mailto', array(&$this, 'smartyAssignMailto')); $this->register_function('display_template', array(&$this, 'smartyDisplayTemplate')); $this->register_modifier('truncate', array(&$this, 'smartyTruncate')); // JS UI components $this->register_function('modal', array(&$this, 'smartyModal')); $this->register_function('confirm', array(&$this, 'smartyConfirm')); $this->register_function('confirm_submit', array(&$this, 'smartyConfirmSubmit')); $this->register_function('init_tabs', array(&$this, 'smartyInitTabs')); $this->register_function('modal_title', array(&$this, 'smartyModalTitle')); // register the resource name "core" $this->register_resource("core", array(array(&$this, 'smartyResourceCoreGetTemplate'), array(&$this, 'smartyResourceCoreGetTimestamp'), array(&$this, 'smartyResourceCoreGetSecure'), array(&$this, 'smartyResourceCoreGetTrusted'))); $this->register_function('url', array(&$this, 'smartyUrl')); // ajax load into a div $this->register_function('load_url_in_div', array(&$this, 'smartyLoadUrlInDiv')); if (!defined('SESSION_DISABLE_INIT')) { /** * Kludge to make sure no code that tries to connect to * the database is executed (e.g., when loading * installer pages). */ $this->assign('isUserLoggedIn', Validation::isLoggedIn()); $application =& PKPApplication::getApplication(); $currentVersion =& $application->getCurrentVersion(); $this->assign('currentVersionString', $currentVersion->getVersionString()); $this->assign('itemsPerPage', Config::getVar('interface', 'items_per_page')); $this->assign('numPageLinks', Config::getVar('interface', 'page_links')); $user =& $request->getUser(); if ($user) { $notificationDao =& DAORegistry::getDAO('NotificationDAO'); $notifications =& $notificationDao->getNotificationsByUserId($user->getId(), NOTIFICATION_LEVEL_TRIVIAL); $notificationsArray =& $notifications->toArray(); unset($notifications); foreach ($notificationsArray as $notification) { $notificationDao->deleteNotificationById($notification->getId()); } $this->assign('systemNotifications', $notificationsArray); } } $this->initialized = false; }
/** * Constructor. * Initialize template engine and assign basic template variables. */ function TemplateManager() { parent::Smarty(); import('file.PublicFileManager'); import('cache.CacheManager'); // Set up Smarty configuration $baseDir = Core::getBaseDir(); $cachePath = CacheManager::getFileCachePath(); $this->template_dir = $baseDir . DIRECTORY_SEPARATOR . 'templates'; $this->compile_dir = $cachePath . DIRECTORY_SEPARATOR . 't_compile'; $this->config_dir = $cachePath . DIRECTORY_SEPARATOR . 't_config'; $this->cache_dir = $cachePath . DIRECTORY_SEPARATOR . 't_cache'; // Assign common variables $this->styleSheets = array(); $this->assign_by_ref('stylesheets', $this->styleSheets); $this->cacheability = CACHEABILITY_NO_STORE; // Safe default $this->assign('defaultCharset', Config::getVar('i18n', 'client_charset')); $this->assign('baseUrl', Request::getBaseUrl()); $this->assign('pageTitle', 'common.openJournalSystems'); $this->assign('requestedPage', Request::getRequestedPage()); $this->assign('currentUrl', Request::getCompleteUrl()); $this->assign('dateFormatTrunc', Config::getVar('general', 'date_format_trunc')); $this->assign('dateFormatShort', Config::getVar('general', 'date_format_short')); $this->assign('dateFormatLong', Config::getVar('general', 'date_format_long')); $this->assign('datetimeFormatShort', Config::getVar('general', 'datetime_format_short')); $this->assign('datetimeFormatLong', Config::getVar('general', 'datetime_format_long')); // Are we using implicit authentication? $this->assign('implicitAuth', Config::getVar('security', 'implicit_auth')); $locale = Locale::getLocale(); $this->assign('currentLocale', $locale); if (!defined('SESSION_DISABLE_INIT')) { /* Kludge to make sure no code that tries to connect to the database is executed * (e.g., when loading installer pages). */ $this->assign('isUserLoggedIn', Validation::isLoggedIn()); $journal =& Request::getJournal(); $site =& Request::getSite(); $versionDAO =& DAORegistry::getDAO('VersionDAO'); $currentVersion = $versionDAO->getCurrentVersion(); $this->assign('currentVersionString', $currentVersion->getVersionString()); $siteFilesDir = Request::getBaseUrl() . '/' . PublicFileManager::getSiteFilesPath(); $this->assign('sitePublicFilesDir', $siteFilesDir); $this->assign('publicFilesDir', $siteFilesDir); // May be overridden by journal $siteStyleFilename = PublicFileManager::getSiteFilesPath() . '/' . $site->getSiteStyleFilename(); if (file_exists($siteStyleFilename)) { $this->addStyleSheet(Request::getBaseUrl() . '/' . $siteStyleFilename); } if (isset($journal)) { $this->assign_by_ref('currentJournal', $journal); $journalTitle = $journal->getJournalTitle(); $this->assign('siteTitle', $journalTitle); $this->assign('publicFilesDir', Request::getBaseUrl() . '/' . PublicFileManager::getJournalFilesPath($journal->getJournalId())); $this->assign('primaryLocale', $journal->getPrimaryLocale()); $this->assign('alternateLocales', $journal->getSetting('alternateLocales')); // Assign additional navigation bar items $navMenuItems =& $journal->getLocalizedSetting('navItems'); $this->assign_by_ref('navMenuItems', $navMenuItems); // Assign journal page header $this->assign('displayPageHeaderTitle', $journal->getJournalPageHeaderTitle()); $this->assign('displayPageHeaderLogo', $journal->getJournalPageHeaderLogo()); $this->assign('alternatePageHeader', $journal->getLocalizedSetting('journalPageHeader')); $this->assign('metaSearchDescription', $journal->getLocalizedSetting('searchDescription')); $this->assign('metaSearchKeywords', $journal->getLocalizedSetting('searchKeywords')); $this->assign('metaCustomHeaders', $journal->getLocalizedSetting('customHeaders')); $this->assign('numPageLinks', $journal->getSetting('numPageLinks')); $this->assign('itemsPerPage', $journal->getSetting('itemsPerPage')); $this->assign('enableAnnouncements', $journal->getSetting('enableAnnouncements')); // Load and apply theme plugin, if chosen $themePluginPath = $journal->getSetting('journalTheme'); if (!empty($themePluginPath)) { // Load and activate the theme $themePlugin =& PluginRegistry::loadPlugin('themes', $themePluginPath); if ($themePlugin) { $themePlugin->activate($this); } } // Assign stylesheets and footer $journalStyleSheet = $journal->getSetting('journalStyleSheet'); if ($journalStyleSheet) { $this->addStyleSheet(Request::getBaseUrl() . '/' . PublicFileManager::getJournalFilesPath($journal->getJournalId()) . '/' . $journalStyleSheet['uploadName']); } import('payment.ojs.OJSPaymentManager'); $paymentManager =& OJSPaymentManager::getManager(); $this->assign('journalPaymentsEnabled', $paymentManager->isConfigured()); $this->assign('pageFooter', $journal->getLocalizedSetting('journalPageFooter')); } else { // Add the site-wide logo, if set for this locale or the primary locale $this->assign('displayPageHeaderTitle', $site->getSitePageHeaderTitle()); $this->assign('siteTitle', $site->getSiteTitle()); $this->assign('itemsPerPage', Config::getVar('interface', 'items_per_page')); $this->assign('numPageLinks', Config::getVar('interface', 'page_links')); } if (!$site->getJournalRedirect()) { $this->assign('hasOtherJournals', true); } } // If there's a locale-specific stylesheet, add it. if (($localeStyleSheet = Locale::getLocaleStyleSheet($locale)) != null) { $this->addStyleSheet(Request::getBaseUrl() . '/' . $localeStyleSheet); } // Register custom functions $this->register_modifier('translate', array('Locale', 'translate')); $this->register_modifier('strip_unsafe_html', array('String', 'stripUnsafeHtml')); $this->register_modifier('String_substr', array('String', 'substr')); $this->register_modifier('to_array', array(&$this, 'smartyToArray')); $this->register_modifier('escape', array(&$this, 'smartyEscape')); $this->register_modifier('explode', array(&$this, 'smartyExplode')); $this->register_modifier('assign', array(&$this, 'smartyAssign')); $this->register_function('translate', array(&$this, 'smartyTranslate')); $this->register_function('flush', array(&$this, 'smartyFlush')); $this->register_function('call_hook', array(&$this, 'smartyCallHook')); $this->register_function('html_options_translate', array(&$this, 'smartyHtmlOptionsTranslate')); $this->register_block('iterate', array(&$this, 'smartyIterate')); $this->register_function('call_progress_function', array(&$this, 'smartyCallProgressFunction')); $this->register_function('page_links', array(&$this, 'smartyPageLinks')); $this->register_function('page_info', array(&$this, 'smartyPageInfo')); $this->register_function('get_help_id', array(&$this, 'smartyGetHelpId')); $this->register_function('icon', array(&$this, 'smartyIcon')); $this->register_function('help_topic', array(&$this, 'smartyHelpTopic')); $this->register_function('get_debug_info', array(&$this, 'smartyGetDebugInfo')); $this->register_function('assign_mailto', array(&$this, 'smartyAssignMailto')); $this->register_function('display_template', array(&$this, 'smartyDisplayTemplate')); $this->register_function('url', array(&$this, 'smartyUrl')); $this->initialized = false; }