private function getAdminData($type, $section, $subsection = null) { if ($type == 'site') { $configData = $this->getSiteAdminConfig(); $module = $this; } elseif ($type instanceof Module) { $configData = $type->getModuleAdminConfig(); $module = $type; } else { throw new KurogoConfigurationException("Invalid type {$type}"); } if (!isset($configData[$section])) { throw new KurogoConfigurationException("Invalid section {$section}"); } $sectionData = $configData[$section]; if ($subsection) { if (!isset($configData[$section]['sections'][$subsection])) { throw new KurogoConfigurationException("Invalid subsection {$subsection} for section {$section}"); } $sectionData = $configData[$section]['sections'][$subsection]; } $sectionData['section'] = $section; if (isset($sectionData['titleKey'])) { $sectionData['title'] = $module->getLocalizedString($sectionData['titleKey']); unset($sectionData['titleKey']); } if (isset($sectionData['descriptionKey'])) { $sectionData['description'] = $module->getLocalizedString($sectionData['descriptionKey']); unset($sectionData['descriptionKey']); } if (isset($sectionData['fieldgroups'])) { foreach ($sectionData['fieldgroups'] as $fieldgroup => &$fieldgroupData) { if (isset($fieldgroupData['labelKey'])) { $fieldgroupData['label'] = $module->getLocalizedString($fieldgroupData['labelKey']); unset($fieldgroupData['labelKey']); } if (isset($fieldgroupData['descriptionKey'])) { $fieldgroupData['description'] = $module->getLocalizedString($fieldgroupData['descriptionKey']); unset($fieldgroupData['descriptionKey']); } } } switch ($sectionData['sectiontype']) { case 'fields': foreach ($sectionData['fields'] as $key => &$field) { if (isset($field['labelKey'])) { $field['label'] = $module->getLocalizedString($field['labelKey']); unset($field['labelKey']); } if (isset($field['descriptionKey'])) { $field['description'] = $module->getLocalizedString($field['descriptionKey']); unset($field['descriptionKey']); } if (isset($field['valueMethod'])) { $field['value'] = call_user_func(array($module, $field['valueMethod'])); unset($field['valueMethod']); } elseif (isset($field['valueKey'])) { $field['value'] = $module->getLocalizedString($field['valueKey']); unset($field['valueKey']); } elseif ($type == 'site') { if (isset($field['config'])) { switch ($field['config']) { case 'site': $field['value'] = Kurogo::getOptionalSiteVar($key, '', $field['section']); break; case 'strings': $field['value'] = Kurogo::getOptionalSiteString($key); break; default: throw new KurogoConfigurationException("Unknown config " . $field['config']); break; } } } elseif (isset($field['config'], $field['section'])) { $field['value'] = $module->getOptionalModuleVar($key, isset($field['default']) ? $field['default'] : '', $field['section'], $field['config']); } switch ($field['type']) { case 'paragraph': if (is_array($field['value'])) { $field['value'] = implode("\n\n", $field['value']); } break; case 'select': if (isset($field['optionsMethod'])) { if (is_array($field['optionsMethod'])) { $field['options'] = call_user_func($field['optionsMethod']); } else { $field['options'] = $module->{$field}['optionsMethod'](); } unset($field['optionsMethod']); } if (isset($field['optionsFirst'])) { $field['options'] = array_merge(array('' => $field['optionsFirst']), $field['options']); unset($field['optionsFirst']); } } if (isset($field['value'])) { $value = $this->getUnconstantedValue($field['value'], $constant); if ($constant) { $field['value'] = $value; $field['constant'] = $constant; } } } break; case 'section': if (isset($sectionData['sectionsmethod'])) { if (is_array($sectionData['sectionsmethod'])) { $sectionData['sections'] = call_user_func($sectionData['sectionsmethod']); } else { $sectionData['sections'] = $module->{$sectionData}['sectionsmethod'](); } unset($sectionData['sectionsmethod']); } elseif ($type == 'site') { throw new KurogoConfigurationException("Getting sections for site is not written yet"); } else { $configMode = isset($sectionData['configMode']) ? $sectionData['configMode'] : 0; $sectionData['sections'] = $module->getModuleSections($sectionData['config'], Config::NO_EXPAND_VALUE, $configMode); } if (isset($sectionData['sectionsnoneKey'])) { $sectionData['sectionsnone'] = $module->getLocalizedString($sectionData['sectionsnoneKey']); unset($sectionData['sectionsnoneKey']); } if (isset($sectionData['sectionaddpromptkey'])) { $sectionData['sectionaddprompt'] = $module->getLocalizedString($sectionData['sectionaddpromptkey']); unset($sectionData['sectionaddpromptkey']); } foreach ($sectionData['fields'] as $key => &$field) { if (isset($field['labelKey'])) { $field['label'] = $module->getLocalizedString($field['labelKey']); unset($field['labelKey']); } if (isset($field['descriptionKey'])) { $field['description'] = $module->getLocalizedString($field['descriptionKey']); unset($field['descriptionKey']); } if (isset($field['valueKey'])) { $field['value'] = $module->getLocalizedString($field['valueKey']); unset($field['valueKey']); } switch ($field['type']) { case 'select': if (isset($field['optionsMethod'])) { if (is_array($field['optionsMethod'])) { $field['options'] = call_user_func($field['optionsMethod']); } else { $field['options'] = $module->{$field}['optionsMethod'](); } unset($field['optionsMethod']); } if (isset($field['optionsFirst'])) { $field['options'] = array_merge(array('' => $field['optionsFirst']), $field['options']); unset($field['optionsFirst']); } } } foreach ($sectionData['sections'] as $section => &$sectionFields) { foreach ($sectionFields as $key => &$value) { if (isset($sectionData['fields'][$key]['type']) && $sectionData['fields'][$key]['type'] == 'paragraph') { $value = implode("\n\n", $value); } $v = $this->getUnconstantedValue($value, $constant); if ($constant) { $value = array($constant, $v, $value); } } } break; case 'sections': foreach ($sectionData['sections'] as $subsection => &$_sectionData) { $subsectionData = $this->getAdminData($type, $section, $subsection); if (isset($subsectionData['showIfSiteVar'])) { if (Kurogo::getOptionalSiteVar($subsectionData['showIfSiteVar'][0], '') != $subsectionData['showIfSiteVar'][1]) { unset($sectionData['sections'][$subsection]); continue; } } if (isset($subsectionData['showIfModuleVar'])) { if ($type->getOptionalModuleVar($subsectionData['showIfModuleVar'][0], '') != $subsectionData['showIfModuleVar'][1]) { unset($sectionData['sections'][$subsection]); continue; } } $sectionData['sections'][$subsection] = $subsectionData; } break; default: throw new KurogoConfigurationException("Section type " . $sectionData['sectiontype'] . " not understood for section {$section}"); } return $sectionData; }
private function assignLocalizedStrings() { $this->assign('footerKurogo', $this->getLocalizedString('FOOTER_KUROGO')); $this->assign('footerBackToTop', $this->getLocalizedString('FOOTER_BACK_TO_TOP')); $this->assign('homeLinkText', $this->getLocalizedString('HOME_LINK', Kurogo::getOptionalSiteString('SITE_NAME'))); $this->assign('moduleHomeLinkText', $this->getLocalizedString('HOME_LINK', $this->getModuleName())); }
private function getAdminData($type, $section, $subsection = null) { if (in_array($type, array('site'))) { $configData = $this->getSiteAdminConfig($type); $module = $this; if (is_null($section)) { $section = key($configData); } } elseif ($type instanceof Module) { $configData = $type->getModuleAdminConfig(); $module = $type; } else { throw new KurogoConfigurationException(__LINE__ . ": Invalid type {$type}"); } if (!isset($configData[$section])) { throw new KurogoConfigurationException(__LINE__ . ": Invalid section {$section}"); } $sectionData = $configData[$section]; if ($subsection) { if (!isset($configData[$section]['sections'][$subsection])) { throw new KurogoConfigurationException(__LINE__ . ": Invalid subsection {$subsection} for section {$section}"); } $sectionData = $configData[$section]['sections'][$subsection]; } $sectionData['section'] = $section; if (isset($sectionData['titleKey'])) { $sectionData['title'] = $module->getLocalizedString($sectionData['titleKey']); unset($sectionData['titleKey']); } if (isset($sectionData['descriptionKey'])) { $sectionData['description'] = $module->getLocalizedString($sectionData['descriptionKey']); unset($sectionData['descriptionKey']); } if (isset($sectionData['fieldgroups'])) { foreach ($sectionData['fieldgroups'] as $fieldgroup => &$fieldgroupData) { if (isset($fieldgroupData['labelKey'])) { $fieldgroupData['label'] = $module->getLocalizedString($fieldgroupData['labelKey']); unset($fieldgroupData['labelKey']); } if (isset($fieldgroupData['descriptionKey'])) { $fieldgroupData['description'] = $module->getLocalizedString($fieldgroupData['descriptionKey']); unset($fieldgroupData['descriptionKey']); } } } switch ($sectionData['sectiontype']) { case 'fields': foreach ($sectionData['fields'] as $key => &$field) { $_key = isset($field['key']) ? $field['key'] : $key; if (isset($field['labelKey'])) { $field['label'] = $module->getLocalizedString($field['labelKey']); unset($field['labelKey']); } if (isset($field['descriptionKey'])) { $field['description'] = $module->getLocalizedString($field['descriptionKey']); unset($field['descriptionKey']); } if (isset($field['value'])) { // value is set. used typically for hidden fields } elseif (isset($field['valueMethod'])) { if (is_array($field['valueMethod'])) { $method = array_shift($field['valueMethod']); $field['value'] = call_user_func_array(array($module, $method), $field['valueMethod']); } else { $field['value'] = call_user_func(array($module, $field['valueMethod'])); } if (is_null($field['value']) && isset($field['default'])) { $field['value'] = $field['default']; } unset($field['valueMethod']); } elseif (isset($field['valueKey'])) { $field['value'] = $module->getLocalizedString($field['valueKey']); unset($field['valueKey']); } elseif (in_array($type, array('site'))) { if (isset($field['config'])) { switch ($field['config']) { case 'site': case 'kurogo': $field['value'] = Kurogo::getOptionalSiteVar($_key, '', $field['section']); break; case 'strings': $field['value'] = Kurogo::getOptionalSiteString($_key); break; default: throw new KurogoConfigurationException(__LINE__ . ": Unknown config " . $field['config']); break; } } } elseif (isset($field['config'], $field['section'])) { $field['value'] = $module->getOptionalModuleVar($_key, isset($field['default']) ? $field['default'] : '', $field['section'], $field['config']); } switch ($field['type']) { case 'paragraph': if (is_array($field['value'])) { $field['value'] = implode("\n\n", $field['value']); } break; case 'select': if (isset($field['optionsMethod'])) { if (is_array($field['optionsMethod'])) { $field['options'] = call_user_func($field['optionsMethod']); } else { $field['options'] = $module->{$field}['optionsMethod'](); } unset($field['optionsMethod']); } if (isset($field['optionsFirst'])) { $field['options'] = array_merge(array('' => $field['optionsFirst']), $field['options']); unset($field['optionsFirst']); } } if (isset($field['value'])) { $useConstant = isset($field['useConstant']) ? $field['useConstant'] : true; if ($useConstant) { $value = $this->getUnconstantedValue($field['value'], $constant); if ($constant) { $field['value'] = $value; $field['constant'] = $constant; } } } if (isset($field['enabledMethod'])) { if (is_array($field['enabledMethod'])) { $field['enabled'] = call_user_func($field['enabledMethod']); } else { $field['enabled'] = $module->{$field}['enabledMethod'](); } unset($field['enabledMethod']); } } break; case 'section': if (isset($sectionData['sectionsmethod'])) { if (is_array($sectionData['sectionsmethod'])) { $sectionData['sections'] = call_user_func($sectionData['sectionsmethod']); } else { $sectionData['sections'] = $module->{$sectionData}['sectionsmethod'](); } $sectionindex = isset($sectionData['sectionindex']) ? $sectionData['sectionindex'] : null; if ($sectionindex == 'numeric') { $sectionData['sections'] = array_values($sectionData['sections']); } unset($sectionData['sectionsmethod']); } elseif (in_array($type, array('site'))) { throw new KurogoConfigurationException(__LINE__ . ": Getting sections for {$type} is not written yet"); } else { $configMode = isset($sectionData['configMode']) ? $sectionData['configMode'] : 0; $sectionData['sections'] = $module->getModuleSections($sectionData['config']); } if (isset($sectionData['sectionsnoneKey'])) { $sectionData['sectionsnone'] = $module->getLocalizedString($sectionData['sectionsnoneKey']); unset($sectionData['sectionsnoneKey']); } if (isset($sectionData['sectionaddpromptkey'])) { $sectionData['sectionaddprompt'] = $module->getLocalizedString($sectionData['sectionaddpromptkey']); unset($sectionData['sectionaddpromptkey']); } foreach ($sectionData['fields'] as $key => &$field) { if (isset($field['labelKey'])) { $field['label'] = $module->getLocalizedString($field['labelKey']); unset($field['labelKey']); } if (isset($field['descriptionKey'])) { $field['description'] = $module->getLocalizedString($field['descriptionKey']); unset($field['descriptionKey']); } if (isset($field['valueKey'])) { $field['value'] = $module->getLocalizedString($field['valueKey']); unset($field['valueKey']); } switch ($field['type']) { case 'select': if (isset($field['optionsMethod'])) { if (is_array($field['optionsMethod'])) { $field['options'] = call_user_func($field['optionsMethod']); } else { $field['options'] = $module->{$field}['optionsMethod'](); } unset($field['optionsMethod']); } if (isset($field['optionsFirst'])) { $field['options'] = array_merge(array('' => $field['optionsFirst']), $field['options']); unset($field['optionsFirst']); } } } foreach ($sectionData['sections'] as $section => &$sectionFields) { foreach ($sectionFields as $key => &$value) { if (isset($sectionData['fields'][$key]['type']) && $sectionData['fields'][$key]['type'] == 'paragraph') { $value = implode("\n\n", $value); } $v = $this->getUnconstantedValue($value, $constant); if ($constant) { $value = array($constant, $v, $value); } } } break; case 'sections': foreach ($sectionData['sections'] as $subsection => &$_sectionData) { $subsectionData = $this->getAdminData($type, $section, $subsection); if (isset($subsectionData['showIfSiteVar'])) { if (Kurogo::getOptionalSiteVar($subsectionData['showIfSiteVar'][0], '') != $subsectionData['showIfSiteVar'][1]) { unset($sectionData['sections'][$subsection]); continue; } } if (isset($subsectionData['showIfModuleVar'])) { if ($type->getOptionalModuleVar($subsectionData['showIfModuleVar'][0], '') != $subsectionData['showIfModuleVar'][1]) { unset($sectionData['sections'][$subsection]); continue; } } $sectionData['sections'][$subsection] = $subsectionData; } break; default: throw new KurogoConfigurationException(__LINE__ . ": Section type " . $sectionData['sectiontype'] . " not understood for section {$section}"); } return $sectionData; }
protected function initializeForPage() { switch ($this->page) { case 'help': break; case 'index': $this->setPageTitle($this->getOptionalModuleVar('pageTitle', Kurogo::getOptionalSiteString('SITE_NAME'), 'index', 'pages')); if ($this->pagetype == 'tablet') { $modulePanes = $this->getTabletModulePanes(); $this->assign('modulePanes', $modulePanes); $this->addInlineJavascript('var homePortlets = {};'); $this->addOnLoad('loadModulePages(' . json_encode($modulePanes) . ');'); $this->addOnOrientationChange('moduleHandleWindowResize();'); } else { $this->assign('modules', $this->getAllModuleNavigationData(self::EXCLUDE_HIDDEN_MODULES)); $this->assign('hideImages', $this->getOptionalModuleVar('HIDE_IMAGES', false)); } if ($this->getOptionalModuleVar('BANNER_ALERT', false, 'notice')) { $noticeData = $this->getOptionalModuleSection('notice'); if ($noticeData) { $bannerNotice = null; // notice can either take a module or data model class or retriever class. The section is passed on. It must implement the HomeAlertInterface interface if (isset($noticeData['BANNER_ALERT_MODULE'])) { $moduleID = $noticeData['BANNER_ALERT_MODULE']; $controller = WebModule::factory($moduleID); $string = "Module {$moduleID}"; } elseif (isset($noticeData['BANNER_ALERT_MODEL_CLASS'])) { $controller = DataModel::factory($noticeData['BANNER_ALERT_MODEL_CLASS'], $noticeData); $string = $noticeData['BANNER_ALERT_MODEL_CLASS']; } elseif (isset($noticeData['BANNER_ALERT_RETRIEVER_CLASS'])) { $controller = DataRetriever::factory($noticeData['BANNER_ALERT_RETRIEVER_CLASS'], $noticeData); $string = $noticeData['BANNER_ALERT_RETRIEVER_CLASS']; } else { throw new KurogoConfigurationException("Banner alert not properly configured"); } if (!$controller instanceof HomeAlertInterface) { throw new KurogoConfigurationException("{$string} does not implement HomeAlertModule interface"); } $bannerNotice = $controller->getHomeScreenAlert(); if ($bannerNotice) { $this->assign('bannerNotice', $bannerNotice); // is this necessary? $bannerModule = $this->getOptionalModuleVar('BANNER_ALERT_MODULE_LINK', false, 'notice'); if ($bannerModule) { $this->assign('bannerURL', $this->buildURLForModule($moduleID, 'index')); } } } } if ($this->getOptionalModuleVar('SHOW_FEDERATED_SEARCH', true)) { $this->assign('showFederatedSearch', true); $this->assign('placeholder', $this->getLocalizedString("SEARCH_PLACEHOLDER", Kurogo::getOptionalSiteString('SITE_NAME'))); } if ($this->getPlatform() == 'iphone' && $this->getOptionalModuleVar('ADD_TO_HOME', false)) { $this->addInternalJavascript('/common/javascript/lib/add2homeConfig.js'); $this->addInternalJavascript('/common/javascript/lib/add2home.js'); $this->addInternalCSS('/common/css/add2home.css'); } $this->assignUserContexts($this->getOptionalModuleVar('ALLOW_CUSTOMIZE', true)); $this->assignSites(); $this->assign('SHOW_DOWNLOAD_TEXT', Kurogo::getOptionalSiteVar('downloadText', '', $this->platform, 'apps')); $homeModuleID = $this->getHomeModuleID(); if ($iconSet = $this->getOptionalThemeVar('navigation_icon_set')) { $iconSetSize = $this->getOptionalThemeVar('navigation_icon_size'); $downloadImgPrefix = "/common/images/iconsets/{$iconSet}/{$iconSetSize}/download"; } else { $downloadImgPrefix = "/modules/{$homeModuleID}/images/download"; } $this->assign('downloadImgPrefix', $downloadImgPrefix); $this->assign('displayType', $this->getModuleVar('display_type')); $this->addOnLoad('addFormNotEmptyValidator()'); break; case 'search': $searchTerms = $this->getArg('filter'); //return home if a blank search was provided. //client side form validation is in place, but this will work //for basic devices, as well as those which have javascript disabled. if (trim($searchTerms) == "") { $this->redirectTo('index', array()); return; } $useAjax = $this->pagetype != 'basic'; $searchModules = array(); if ($this->getOptionalModuleVar('SHOW_FEDERATED_SEARCH', true)) { $this->assign('showFederatedSearch', true); foreach ($this->getAllModuleNavigationData(self::EXCLUDE_HIDDEN_MODULES) as $type => $modules) { foreach ($modules as $id => $info) { if ($id == 'customize') { continue; } $module = self::factory($id); if ($module->getOptionalModuleVar('search', false, 'module')) { $searchModule = array('id' => $id, 'elementId' => 'federatedSearchModule_' . $id, 'title' => $info['title']); if ($useAjax) { $searchModule['ajaxURL'] = FULL_URL_PREFIX . ltrim($this->buildURL('searchResult', array('id' => $id, 'filter' => $searchTerms)), '/'); } else { $searchModule['results'] = $this->runFederatedSearchForModule($module, $searchTerms); } $searchModules[] = $searchModule; } } } if ($useAjax) { $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js'); $this->addInlineJavascript('var federatedSearchModules = ' . json_encode($searchModules) . ";\n"); $this->addOnLoad('runFederatedSearch(federatedSearchModules);'); } } $this->assign('federatedSearchModules', $searchModules); $this->assign('searchTerms', $searchTerms); $this->setLogData($searchTerms); $this->addOnLoad('addFormNotEmptyValidator()'); break; case 'modules': $configModule = $this->getArg('configModule', $this->configModule); $this->assign('modules', $this->getAllModuleNavigationData(self::EXCLUDE_HIDDEN_MODULES)); $this->assign('hideImages', $this->getOptionalModuleVar('HIDE_IMAGES', false)); $this->assign('displayType', $this->getModuleVar('display_type')); if ($configModule == $this->configModule && $this->getOptionalModuleVar('SHOW_FEDERATED_SEARCH', true)) { $this->assign('showFederatedSearch', true); $this->assign('placeholder', $this->getLocalizedString("SEARCH_PLACEHOLDER", Kurogo::getOptionalSiteString('SITE_NAME'))); } $this->assignUserContexts($this->getOptionalModuleVar('ALLOW_CUSTOMIZE', true)); break; case 'searchResult': $moduleID = $this->getArg('id'); $searchTerms = $this->getArg('filter'); $this->setLogData($searchTerms); $module = self::factory($moduleID); $this->assign('federatedSearchResults', $this->runFederatedSearchForModule($module, $searchTerms)); break; case 'pane': // This wrapper exists so we can catch module errors and prevent redirection to the error page $moduleID = $this->getArg('id'); try { $module = self::factory($moduleID, 'pane', array(self::AJAX_PARAMETER => 1)); $content = $module->fetchPage(); } catch (Exception $e) { Kurogo::log(LOG_WARNING, $e->getMessage(), "home", $e->getTrace()); $content = '<p class="nonfocal">' . $this->getLocalizedString('ERROR_MODULE_PANE') . '</p>'; } $this->assign('content', $content); break; case 'customize': $allowCustomize = $this->getOptionalModuleVar('ALLOW_CUSTOMIZE', true); $this->assign('allowCustomize', $allowCustomize); if (!$allowCustomize) { break; } $this->handleCustomizeRequest($this->args); $modules = $this->getModuleCustomizeList(); $moduleIDs = array_keys($modules); switch ($this->pagetype) { case 'compliant': case 'tablet': $this->addInlineJavascript('var MODULE_NAV_COOKIE = "' . self::MODULE_NAV_COOKIE . '";' . 'var MODULE_NAV_COOKIE_LIFESPAN = ' . Kurogo::getSiteVar('MODULE_NAV_COOKIE_LIFESPAN') . ';' . 'var COOKIE_PATH = "' . COOKIE_PATH . '";'); $this->addInlineJavascriptFooter('init();'); break; case 'basic': foreach ($moduleIDs as $index => $id) { $modules[$id]['toggleVisibleURL'] = $this->buildBreadcrumbURL('index', array('action' => $modules[$id]['visible'] ? 'off' : 'on', 'module' => $id), false); if ($index > 0) { $modules[$id]['swapUpURL'] = $this->buildBreadcrumbURL('index', array('action' => 'swap', 'module1' => $id, 'module2' => $moduleIDs[$index - 1]), false); } if ($index < count($moduleIDs) - 1) { $modules[$id]['swapDownURL'] = $this->buildBreadcrumbURL('index', array('action' => 'swap', 'module1' => $id, 'module2' => $moduleIDs[$index + 1]), false); } } break; default: break; } // show user selectable context switching if ($contexts = Kurogo::sharedInstance()->getContexts()) { $userContextList = $this->getUserContextListData('customizemodules', false); $this->assign('customizeUserContextListDescription', $this->getLocalizedString('USER_CONTEXT_LIST_DESCRIPTION')); if ($this->platform == 'iphone') { $this->assign('customizeUserContextListDescriptionFooter', $this->getLocalizedString('USER_CONTEXT_LIST_DESCRIPTION_FOOTER_DRAG')); } else { $this->assign('customizeUserContextListDescriptionFooter', $this->getLocalizedString('USER_CONTEXT_LIST_DESCRIPTION_FOOTER')); } $this->assign('customizeUserContextList', $userContextList); } else { $key = 'CUSTOMIZE_INSTRUCTIONS'; if ($this->pagetype == 'compliant' || $this->pagetype == 'tablet') { $key = 'CUSTOMIZE_INSTRUCTIONS_' . strtoupper($this->pagetype); if ($this->platform == 'iphone') { $key .= '_DRAG'; } } $this->assign('customizeInstructions', $this->getLocalizedString($key)); } $this->assign('modules', $modules); break; case 'customizemodules': $modules = $this->getModuleCustomizeList(); $this->assign('modules', $modules); break; } }