TemplateManager::__construct PHP Method

__construct() public method

Initialize template engine and assign basic template variables.
public __construct ( $request )
$request PKPRequest
    function __construct($request)
    {
        parent::__construct($request);
        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).
             */
            $context = $request->getContext();
            $site = $request->getSite();
            $publicFileManager = new PublicFileManager();
            $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('siteStylesheet', $request->getBaseUrl() . '/' . $siteStyleFilename, array('priority' => STYLE_SEQUENCE_LATE));
            }
            // Pass app-specific details to template
            $this->assign(array('brandImage' => 'templates/images/ojs_brand.png', 'packageKey' => 'common.openJournalSystems', 'pkpLink' => 'http://pkp.sfu.ca/ojs'));
            // Get a count of unread tasks.
            if ($user = $request->getUser()) {
                $notificationDao = DAORegistry::getDAO('NotificationDAO');
                // Exclude certain tasks, defined in the notifications grid handler
                import('lib.pkp.controllers.grid.notifications.TaskNotificationsGridHandler');
                $this->assign('unreadNotificationCount', $notificationDao->getNotificationCount(false, $user->getId(), null, NOTIFICATION_LEVEL_TASK));
            }
            if (isset($context)) {
                $this->assign(array('currentJournal' => $context, 'siteTitle' => $context->getLocalizedName(), 'publicFilesDir' => $request->getBaseUrl() . '/' . $publicFileManager->getJournalFilesPath($context->getId()), 'primaryLocale' => $context->getPrimaryLocale(), 'supportedLocales' => $context->getSupportedLocaleNames(), 'displayPageHeaderTitle' => $context->getLocalizedPageHeaderTitle(), 'displayPageHeaderLogo' => $context->getLocalizedPageHeaderLogo(), 'displayPageHeaderLogoAltText' => $context->getLocalizedSetting('pageHeaderLogoImageAltText'), 'numPageLinks' => $context->getSetting('numPageLinks'), 'itemsPerPage' => $context->getSetting('itemsPerPage'), 'enableAnnouncements' => $context->getSetting('enableAnnouncements'), 'contextSettings' => $context->getSettingsDAO()->getSettings($context->getId()), 'disableUserReg' => $context->getSetting('disableUserReg')));
                // Assign meta tags
                $favicon = $context->getLocalizedFavicon();
                if (!empty($favicon)) {
                    $faviconDir = $request->getBaseUrl() . '/' . $publicFileManager->getJournalFilesPath($context->getId());
                    $this->addHeader('favicon', '<link rel="icon" href="' . $faviconDir . '/' . $favicon['uploadName'] . '">');
                }
                // Assign stylesheets and footer
                $contextStyleSheet = $context->getSetting('styleSheet');
                if ($contextStyleSheet) {
                    $this->addStyleSheet('contextStylesheet', $request->getBaseUrl() . '/' . $publicFileManager->getJournalFilesPath($context->getId()) . '/' . $contextStyleSheet['uploadName'], array('priority' => STYLE_SEQUENCE_LATE));
                }
                // Get a link to the settings page for the current context.
                // This allows us to reduce template duplication by using this
                // variable in templates/common/header.tpl, instead of
                // reproducing a lot of OMP/OJS-specific logic there.
                $dispatcher = $request->getDispatcher();
                $this->assign('contextSettingsUrl', $dispatcher->url($request, ROUTE_PAGE, null, 'management', 'settings', 'journal'));
                import('classes.payment.ojs.OJSPaymentManager');
                $paymentManager = new OJSPaymentManager($request);
                $this->assign('journalPaymentsEnabled', $paymentManager->isConfigured());
                $this->assign('pageFooter', $context->getLocalizedSetting('pageFooter'));
            } else {
                // Check if registration is open for any contexts
                $contextDao = Application::getContextDAO();
                $contexts = $contextDao->getAll(true)->toArray();
                $contextsForRegistration = array();
                foreach ($contexts as $context) {
                    if (!$context->getSetting('disableUserReg')) {
                        $contextsForRegistration[] = $context;
                    }
                }
                $this->assign(array('contexts' => $contextsForRegistration, 'disableUserReg' => empty($contextsForRegistration), 'displayPageHeaderTitle' => $site->getLocalizedPageHeaderTitle(), 'displayPageHeaderLogo' => $site->getLocalizedSetting('pageHeaderTitleImage'), 'siteTitle' => $site->getLocalizedTitle(), 'primaryLocale' => $site->getPrimaryLocale(), 'supportedLocales' => $site->getSupportedLocaleNames(), 'pageFooter' => $site->getLocalizedSetting('pageFooter')));
            }
        }
    }

Usage Example

コード例 #1
0
ファイル: fbvVisualResults.php プロジェクト: NateWr/omp
 function __construct()
 {
     parent::__construct();
     $this->caching = 0;
     // look for templates in the test directory
     $baseDir = Core::getBaseDir();
     $test_template_dir = $baseDir . DIRECTORY_SEPARATOR . PKP_LIB_PATH . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'ui' . DIRECTORY_SEPARATOR . 'fbv';
     $this->template_dir[] = $test_template_dir;
     // $baseUrl has to be reset to properly reference the javascript files and stylesheets
     $baseUrl = '';
     $uriComponents = explode('/', $_SERVER['REQUEST_URI']);
     for ($i = 0, $count = count($uriComponents); $i < $count; $i++) {
         if ($uriComponents[$i] == 'tools' && $uriComponents[$i + 1] == 'fbvVisualResults.php') {
             break;
         } else {
             if (empty($uriComponents[$i])) {
                 continue;
             } else {
                 $baseUrl .= '/' . $uriComponents[$i];
             }
         }
     }
     $this->assign('baseUrl', $baseUrl);
 }
TemplateManager