Esempio n. 1
0
 private function setPageVariables()
 {
     $this->loadTemplateEngineIfNeeded();
     $this->loadPageConfig();
     // Set variables common to all modules
     $this->assign('moduleID', $this->id);
     $this->assign('configModule', $this->configModule);
     $this->assign('templateModule', $this->templateModule);
     $this->assign('moduleName', $this->moduleName);
     $this->assign('navImageID', $this->getModuleIcon());
     $this->assign('page', $this->page);
     $this->assign('isModuleHome', $this->page == 'index');
     $this->assign('request_uri', $_SERVER['REQUEST_URI']);
     $this->assign('hideFooterLinks', $this->hideFooterLinks);
     $this->assign('ajaxContentLoad', $this->ajaxContentLoad);
     $this->assign('charset', Kurogo::getCharset());
     $this->assign('http_protocol', HTTP_PROTOCOL);
     $this->assign('webBridgeAjaxContentLoad', KurogoWebBridge::isAjaxContentLoad());
     // Font size for template
     $this->assign('fontsizes', $this->fontsizes);
     $this->assign('fontsize', $this->fontsize);
     $this->assign('fontsizeCSS', $this->getFontSizeCSS());
     $this->assign('fontSizeURLs', $this->getFontSizeURLs());
     // Minify URLs
     $this->assign('minify', $this->getMinifyUrls());
     // Google Analytics. This probably needs to be moved
     if ($gaID = Kurogo::getOptionalSiteVar('GOOGLE_ANALYTICS_ID')) {
         $this->assign('GOOGLE_ANALYTICS_ID', $gaID);
         $this->assign('GOOGLE_ANALYTICS_DOMAIN', Kurogo::getOptionalSiteVar('GOOGLE_ANALYTICS_DOMAIN'));
         $this->assign('gaImageURL', $this->googleAnalyticsGetImageUrl($gaID));
     }
     // Breadcrumbs
     $this->loadBreadcrumbs();
     // Tablet iScroll
     if ($this->pagetype == 'tablet') {
         $this->addInternalJavascript('/common/javascript/lib/iscroll-4.2.js');
         // Module nav list
         if ($this->shouldShowNavigation()) {
             $this->assign('navigationModules', $this->getModuleNavlist());
             $allowCustomize = Kurogo::getOptionalModuleVar('ALLOW_CUSTOMIZE', true, $this->getHomeModuleID());
             $this->assignUserContexts($allowCustomize);
         }
     }
     if ($this->page == self::WEB_BRIDGE_BUILD_TEMPLATES_PAGE) {
         $title = 'Error!';
         $message = '';
         try {
             if (!Kurogo::isLocalhost()) {
                 throw new KurogoException("{$this->page} command can only be run from localhost");
             }
             $platforms = array_filter(array_map('trim', explode(',', $this->getArg('platform', ''))));
             if (!$platforms) {
                 throw new KurogoException("No platforms specified");
             }
             foreach ($platforms as $platform) {
                 $this->buildNativeWebTemplatesForPlatform($platform);
             }
             $title = 'Success!';
             $message = 'Generated native web templates for ' . implode(' and ', $platforms);
         } catch (Exception $e) {
             $message = $e->getMessage();
         }
         $this->assign('contentTitle', $title);
         $this->assign('contentBody', $message);
     } else {
         if (KurogoWebBridge::useNativeTemplatePageInitializer()) {
             Kurogo::log(LOG_DEBUG, "Calling initializeForNativeTemplatePage for {$this->configModule} - {$this->page}", 'module');
             $this->initializeForNativeTemplatePage();
             //subclass behavior
             Kurogo::log(LOG_DEBUG, "Returned from initializeForNativeTemplatePage for {$this->configModule} - {$this->page}", 'module');
         } else {
             Kurogo::log(LOG_DEBUG, "Calling initializeForPage for {$this->configModule} - {$this->page}", 'module');
             $this->initializeForPage();
             //subclass behavior
             Kurogo::log(LOG_DEBUG, "Returned from initializeForPage for {$this->configModule} - {$this->page}", 'module');
         }
     }
     // Set variables for each page
     $this->assign('pageTitle', $this->pageTitle);
     // Variables which may have been modified by the module subclass
     $this->assign('inlineCSSBlocks', $this->inlineCSSBlocks);
     $this->assign('cssURLs', $this->cssURLs);
     $this->assign('inlineJavascriptBlocks', $this->inlineJavascriptBlocks);
     $this->assign('onOrientationChangeBlocks', $this->onOrientationChangeBlocks);
     $this->assign('onLoadBlocks', $this->onLoadBlocks);
     $this->assign('inlineJavascriptFooterBlocks', $this->inlineJavascriptFooterBlocks);
     $this->assign('javascriptURLs', $this->javascriptURLs);
     $this->assign('breadcrumbs', $this->breadcrumbs);
     $this->assign('breadcrumbArgs', $this->getBreadcrumbArgs());
     $this->assign('breadcrumbSamePageArgs', $this->getBreadcrumbArgs(false));
     $this->assign('breadcrumbsShowAll', $this->getOptionalThemeVar('breadcrumbs_show', true));
     if (Kurogo::getSiteVar('MODULE_DEBUG')) {
         $this->addModuleDebugString('Config Mode', implode(', ', Kurogo::sharedInstance()->getConfigModes()));
         $this->addModuleDebugString('Version', KUROGO_VERSION);
         if (SITE_VERSION) {
             $this->addModuleDebugString('Site Version', SITE_VERSION);
         }
         if (SITE_BUILD) {
             $this->addModuleDebugString('Site Build', SITE_BUILD);
         }
         if ($contexts = Kurogo::sharedInstance()->getActiveContexts()) {
             $this->addModuleDebugString('Context(s)', implode(', ', $contexts));
         }
         $this->assign('moduleDebugStrings', $this->moduleDebugStrings);
     }
     $this->assign('webBridgeOnPageLoadParams', KurogoWebBridge::getOnPageLoadParams($this->pageTitle, $this->breadcrumbTitle, $this->hasWebBridgePageRefresh, $this->hasWebBridgeAutoRefresh));
     $this->assign('webBridgeOnPageLoadConfig', KurogoWebBridge::getOnPageLoadConfig());
     $this->assign('webBridgeConfig', KurogoWebBridge::getServerConfig($this->configModule, $this->page, $this->args));
     $moduleStrings = $this->getOptionalModuleSection('strings');
     $this->assign('moduleStrings', $moduleStrings);
     $this->assign('homeLink', $this->buildURLForModule($this->getHomeModuleID(), '', array()));
     $this->assign('homeModuleID', $this->getHomeModuleID());
     $this->assignLocalizedStrings();
     if ($this->page == 'help') {
         // Module Help
         $this->assign('hasHelp', false);
         $template = 'common/templates/' . $this->page;
     } else {
         if ($this->page == self::WEB_BRIDGE_BUILD_TEMPLATES_PAGE) {
             $template = 'common/templates/staticContent';
         } else {
             if (KurogoWebBridge::useWrapperPageTemplate()) {
                 // Web bridge page wrapper
                 $template = 'common/templates/webBridge';
                 $this->assign('webBridgeJSLocalizedStrings', json_encode(Kurogo::getLocalizedStrings()));
             } else {
                 $this->assign('hasHelp', isset($moduleStrings['help']));
                 $this->assign('helpLink', $this->buildBreadcrumbURL('help', array()));
                 $this->assign('helpLinkText', $this->getLocalizedString('HELP_TEXT', $this->getModuleName()));
                 $template = 'modules/' . $this->templateModule . '/templates/' . $this->templatePage;
             }
         }
     }
     Kurogo::log(LOG_DEBUG, "Template file is {$template}", 'module');
     // Pager support
     if (isset($this->htmlPager)) {
         $this->assign('pager', $this->getPager());
     }
     // Tab support
     if (isset($this->tabbedView)) {
         $this->assign('tabbedView', $this->tabbedView);
     }
     $this->assign('imageExt', $this->imageExt);
     $this->assign(Kurogo::getThemeVars());
     // Access Key Start
     $accessKeyStart = count($this->breadcrumbs);
     if ($this->configModule != $this->getHomeModuleID()) {
         $accessKeyStart++;
         // Home link
     }
     $this->assign('accessKeyStart', $accessKeyStart);
     if (Kurogo::getSiteVar('AUTHENTICATION_ENABLED')) {
         Kurogo::includePackage('Authentication');
         $this->setCacheMaxAge(0);
         $session = $this->getSession();
         $this->assign('session', $session);
         $this->assign('session_isLoggedIn', $this->isLoggedIn());
         $this->assign('showLogin', Kurogo::getSiteVar('AUTHENTICATION_ENABLED') && $this->showLogin());
         if ($this->isLoggedIn()) {
             $user = $session->getUser();
             $authority = $user->getAuthenticationAuthority();
             $this->assign('session_userID', $user->getUserID());
             $this->assign('session_fullName', $user->getFullname());
             if (count($session->getUsers()) == 1) {
                 $this->assign('session_logout_url', $this->buildURLForModule($this->getLoginModuleID(), 'logout', array('authority' => $user->getAuthenticationAuthorityIndex())));
                 $this->assign('footerLoginLink', $this->buildURLForModule($this->getLoginModuleID(), '', array()));
                 $this->assign('footerLoginText', $this->getLocalizedString('SIGNED_IN_SINGLE', $authority->getAuthorityTitle(), $user->getFullName()));
                 $this->assign('footerLoginClass', $authority->getAuthorityClass());
             } else {
                 $this->assign('footerLoginClass', 'login_multiple');
                 $this->assign('session_logout_url', $this->buildURLForModule($this->getLoginModuleID(), 'logout', array()));
                 $this->assign('footerLoginLink', $this->buildURLForModule($this->getLoginModuleID(), 'logout', array()));
                 $this->assign('footerLoginText', $this->getLocalizedString('SIGNED_IN_MULTIPLE'));
             }
             if ($session_max_idle = intval(Kurogo::getOptionalSiteVar('AUTHENTICATION_IDLE_TIMEOUT', 0))) {
                 $this->setRefresh($session_max_idle + 60);
             }
         } else {
             $this->assign('footerLoginClass', 'noauth');
             $this->assign('footerLoginLink', $this->buildURLForModule($this->getLoginModuleID(), '', array()));
             $this->assign('footerLoginText', $this->getLocalizedString('SIGN_IN_SITE', Kurogo::getSiteString('SITE_NAME')));
         }
     }
     /* set cache age. Modules that present content that rarely changes can set this value
        to something higher */
     header(sprintf("Cache-Control: max-age=%d", $this->cacheMaxAge));
     /*
      * Date is set by apache (or your webserver of choice).  Under apache, and possibly other
      * webservers, it is impossible to either manually set this header or read the value of it.
      * Here, we want to set the Expires header such that disable caching.  One method of doing
      * this is to set Expires to the same value as Date.
      * Because of execution time up to this point, very occasionally these two values are off by
      * 1 second.  The net result is that with a $this->cacheMaxAge of 0, the Date and Expires
      * headers are different by 1 second.  Combined with Pragma: no-cache and
      * Cache-Control: no-cache, you get conflicting behavior which can (in theory) be exploited.
      * It also causes security tools to complain about the difference.
      *
      * The only reliable thing to do when explicitly attempting to avoid caching is to set
      * Expires to a time in the past. The best way to do that is to set it to Unix epoch.
      */
     if ($this->cacheMaxAge > 0) {
         header("Expires: " . gmdate('D, d M Y H:i:s', time() + $this->cacheMaxAge) . ' GMT');
     } else {
         header("Expires: " . gmdate('D, d M Y H:i:s', 0) . ' GMT');
     }
     return $template;
 }
Esempio n. 2
0
 protected function getOptionalThemeVar($var, $default = '')
 {
     $vars = Kurogo::getThemeVars();
     return isset($vars[$var]) ? $vars[$var] : $default;
 }
Esempio n. 3
0
function minifyPostProcess($content, $type)
{
    if ($type === Minify::TYPE_CSS) {
        $urlPrefix = URL_PREFIX;
        if (Kurogo::getSiteVar('DEVICE_DEBUG') && URL_PREFIX == URL_BASE) {
            // if device debugging is on, always append device classification
            $urlPrefix .= 'device/' . Kurogo::deviceClassifier()->getDevice() . '/';
        }
        // Theme variable replacement
        $themeVars = Kurogo::getThemeVars();
        if ($themeVars) {
            $content = preg_replace_callback(';@@@([^@]+)@@@;', 'minifyThemeVarReplace', $content);
        }
        $content = "/* Adding url prefix '" . $urlPrefix . "' */\n\n" . preg_replace(';url\\("?\'?/([^"\'\\)]+)"?\'?\\);', 'url("' . $urlPrefix . '\\1")', $content);
    }
    return $content;
}