public function initializeForCommand() { switch ($this->command) { case 'notice': $response = null; $responseVersion = 1; if ($this->getOptionalModuleVar('BANNER_ALERT', false, 'notice')) { $noticeData = $this->getOptionalModuleSection('notice'); if ($noticeData) { $response = array('notice' => '', 'moduleID' => null, 'link' => $this->getOptionalModuleVar('BANNER_ALERT_MODULE_LINK', false, 'notice')); // 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); $response['moduleID'] = $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"); } $response['notice'] = $controller->getHomeScreenAlert(); } } $this->setResponse($response); $this->setResponseVersion($responseVersion); break; case 'modules': if ($setcontext = $this->getArg('setcontext')) { Kurogo::sharedInstance()->setUserContext($setcontext); } $responseVersion = 2; $response = array('primary' => array(), 'secondary' => array(), 'customize' => $this->getOptionalModuleVar('ALLOW_CUSTOMIZE', true), 'displayType' => $this->getOptionalModuleVar('display_type', 'springboard')); $allmodules = $this->getAllModules(); $navModules = Kurogo::getSiteSections('navigation', Config::APPLY_CONTEXTS_NAVIGATION); foreach ($navModules as $moduleID => $moduleData) { if ($module = Kurogo::arrayVal($allmodules, $moduleID)) { $title = Kurogo::arrayVal($moduleData, 'title', $module->getModuleVar('title')); $type = Kurogo::arrayVal($moduleData, 'type', 'primary'); $visible = Kurogo::arrayVal($moduleData, 'visible', 1); $response[$type][] = array('tag' => $moduleID, 'title' => $title, 'visible' => (bool) $visible); } } $this->setResponse($response); $this->setResponseVersion($responseVersion); break; default: $this->invalidCommand(); } }
protected function getCreditsHTML() { //get original device $device = Kurogo::deviceClassifier()->getDevice(); //set browser to unknown so we don't get AppQ HTML Kurogo::deviceClassifier()->setBrowser('unknown'); $module = WebModule::factory($this->configModule, 'credits_html'); $html = $module->fetchPage(); //restore device Kurogo::deviceClassifier()->setDevice($device); return $html; }
public function initializeForCommand() { switch ($this->command) { case 'notice': $response = null; $responseVersion = 1; if ($this->getOptionalModuleVar('BANNER_ALERT', false, 'notice')) { $noticeData = $this->getOptionalModuleSection('notice'); if ($noticeData) { $response = array('notice' => '', 'moduleID' => null, 'link' => $this->getOptionalModuleVar('BANNER_ALERT_MODULE_LINK', false, 'notice')); // 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); $response['moduleID'] = $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"); } $response['notice'] = $controller->getHomeScreenAlert(); } } $this->setResponse($response); $this->setResponseVersion($responseVersion); break; default: $this->invalidCommand(); } }
public static function searchItems($moduleID, $searchTerms, $limit = null, $options = null) { $module = WebModule::factory($moduleID); return $module->searchItems($searchTerms, $limit, $options); }
$parts[0] = $url_redirects[$id]; $url = URL_PREFIX . implode("/", $parts); } header("Location: " . $url); exit; } } // find the page part if (isset($parts[1])) { if (strlen($parts[1])) { $page = basename($parts[1], '.php'); } } else { // redirect with trailing slash for completeness header("Location: ./$id/"); exit; } if ($module = WebModule::factory($id, $page, $args)) { /* log this page view */ PageViews::increment($id, Kurogo::deviceClassifier()->getPlatform()); $module->displayPage(); } else { throw new Exception("Module $id cannot be loaded"); } } exit;
public function initializeForCommand() { $this->requiresAdmin(); switch ($this->command) { case 'checkversion': $current = Kurogo::sharedInstance()->checkCurrentVersion(); Kurogo::log(LOG_INFO, sprintf("Checking version. This site: %s Current Kurogo Version: %s", $current, KUROGO_VERSION), 'admin'); $uptodate = version_compare(KUROGO_VERSION, $current, ">="); $messageKey = $uptodate ? 'KUROGO_VERSION_MESSAGE_UPTODATE' : 'KUROGO_VERSION_MESSAGE_NOTUPDATED'; $data = array('current' => $current, 'local' => KUROGO_VERSION, 'uptodate' => $uptodate, 'message' => $this->getLocalizedString($messageKey, $current, KUROGO_VERSION)); $this->setResponse($data); $this->setResponseVersion(1); break; case 'getlocalizedstring': $key = $this->getArg('key'); $data = array(); if (is_array($key)) { foreach ($key as $k) { $data[$k] = $this->getLocalizedString($k); } } else { $data[$key] = $this->getLocalizedString($key); } $this->setResponse($data); $this->setResponseVersion(1); break; case 'clearcaches': Kurogo::log(LOG_NOTICE, "Clearing Site Caches", 'admin'); $result = Kurogo::sharedInstance()->clearCaches(); if ($result === 0) { $this->setResponse(true); $this->setResponseVersion(1); } else { $this->throwError(new KurogoError(1, "Error clearing caches", "There was an error ({$result}) clearing the caches")); } break; case 'upload': $type = $this->getArg('type'); $section = $this->getArg('section', ''); $subsection = null; switch ($type) { case 'module': $moduleID = $this->getArg('module', ''); $module = WebModule::factory($moduleID); $type = $module; break; case 'site': break; default: throw new KurogoConfigurationException("Invalid type {$type}"); } if (count($_FILES) == 0) { throw new KurogoException("No files uploaded"); } foreach ($_FILES as $key => $uploadData) { $this->uploadFile($type, $section, $subsection, $key, $uploadData); } $this->setResponseVersion(1); $this->setResponse(true); break; case 'getconfigsections': $type = $this->getArg('type'); switch ($type) { case 'module': $moduleID = $this->getArg('module', ''); $module = WebModule::factory($moduleID); $sections = $module->getModuleAdminSections(); break; case 'site': throw new KurogoConfigurationException("getconfigsections for site not handled yet"); } $this->setResponse($sections); $this->setResponseVersion(1); break; case 'getconfigdata': $type = $this->getArg('type'); $section = $this->getArg('section', ''); switch ($type) { case 'module': $moduleID = $this->getArg('module', ''); $module = WebModule::factory($moduleID); $adminData = $this->getAdminData($module, $section); break; case 'site': $adminData = $this->getAdminData('site', $section); break; } $this->setResponse($adminData); $this->setResponseVersion(1); break; case 'setconfigdata': $type = $this->getArg('type'); $data = $this->getArg('data', array()); $section = $this->getArg('section', ''); $subsection = null; if (empty($data)) { $data = array(); } elseif (!is_array($data)) { throw new KurogoConfigurationException("Invalid data for {$type} {$section}"); } switch ($type) { case 'module': if ($section == 'overview') { foreach ($data as $moduleID => $props) { $module = WebModule::factory($moduleID); if (!is_array($props)) { throw new KurogoConfigurationException("Invalid properties for {$type} {$section}"); } $valid_props = array('protected', 'secure', 'disabled', 'search'); foreach ($props as $key => $value) { if (!in_array($key, $valid_props)) { throw new KurogoConfigurationException("Invalid property {$key} for module {$module}"); } $this->setConfigVar($module, 'general', $subsection, $key, $value); } } foreach ($this->changedConfigs as $config) { $config->saveFile(); } $this->setResponse(true); $this->setResponseVersion(1); break 2; } else { $moduleID = $this->getArg('module', ''); $module = WebModule::factory($moduleID); $type = $module; } break; case 'site': break; default: throw new KurogoConfigurationException("Invalid type {$type}"); } foreach ($data as $section => $fields) { $adminData = $this->getAdminData($type, $section); if ($adminData['sectiontype'] == 'sections') { $subsection = key($fields); $fields = current($fields); $adminData = $this->getAdminData($type, $section, $subsection); } $fields = is_array($fields) ? $fields : array(); foreach ($fields as $key => $value) { if ($adminData['sectiontype'] == 'section' && isset($adminData['sectionclearvalues']) && $adminData['sectionclearvalues']) { if ($config = $this->getAdminConfig($type, $adminData['config'], ConfigFile::OPTION_DO_NOT_CREATE)) { $config->removeSection($key); } } // ignore prefix values. We'll put it back together later if (preg_match("/^(.*?)_prefix\$/", $key, $bits)) { continue; } $prefix = isset($fields[$key . '_prefix']) ? $fields[$key . '_prefix'] : ''; if ($prefix && defined($prefix)) { $value = constant($prefix) . '/' . $value; } $this->setConfigVar($type, $section, $subsection, $key, $value); } } if ($sectionorder = $this->getArg('sectionorder')) { foreach ($sectionorder as $section => $order) { $this->setSectionOrder($type, $section, $subsection, $order); } } foreach ($this->changedConfigs as $config) { $config->saveFile(); } $this->setResponse(true); $this->setResponseVersion(1); break; case 'removeconfigsection': $type = $this->getArg('type'); $section = $this->getArg('section', ''); $key = $this->getArg('key', null); switch ($type) { case 'site': $subsection = $this->getArg('subsection', null); $sectionData = $this->getAdminData($type, $section, $subsection); $config = ConfigFile::factory($sectionData['config'], 'site'); break; case 'module': $moduleID = $this->getArg('module', ''); $module = WebModule::factory($moduleID); $sectionData = $this->getAdminData($module, $section); $config = $module->getConfig($sectionData['config']); break; default: throw new KurogoConfigurationException("Invalid type {$type}"); } if (!isset($sectionData['sections']) || (!isset($sectionData['sectiondelete']) || !$sectionData['sectiondelete'])) { throw new KurogoConfigurationException("Config '{$section}' of module '{$moduleID}' does not permit removal of items"); } if (!isset($sectionData['sections'][$key])) { throw new KurogoConfigurationException("Section {$key} not found in config '{$section}' of module '{$moduleID}'"); } Kurogo::log(LOG_NOTICE, "Removing section {$section} from " . $this->getTypeStr($type) . " {$subsection}", 'admin'); if (!($result = $config->removeSection($key))) { throw new KurogoException("Error removing item {$key} from config '" . $sectionData['config'] . "'"); } else { $config->saveFile(); } $this->setResponse(true); $this->setResponseVersion(1); break; case 'setmodulelayout': Kurogo::log(LOG_NOTICE, "Updating module layout", 'admin'); $data = $this->getArg('data', array()); $config = ModuleConfigFile::factory('home', 'module'); if (!isset($data['primary_modules'])) { $data['primary_modules'] = array(); } $config->setSection('primary_modules', $data['primary_modules']); if (!isset($data['secondary_modules'])) { $data['secondary_modules'] = array(); } $config->setSection('secondary_modules', $data['secondary_modules']); $config->saveFile(); $this->setResponse(true); $this->setResponseVersion(1); break; default: $this->invalidCommand(); break; } }
protected function initializeForPage() { //make sure that only desktop/tablet devices can use the module $deviceClassifier = Kurogo::deviceClassifier(); if ($this->page != 'index' && !($deviceClassifier->isComputer() || $deviceClassifier->isTablet())) { $this->redirectTo('index'); } $navSections = $this->getNavSections(); $section = ''; $this->assign('navSections', $navSections); $this->addJQuery(); $this->addJQueryUI(); switch ($this->page) { case 'modules': $subNavSections = $this->getSubNavSections($this->page); $this->assign('subNavSections', $subNavSections); $defaultSubNavSection = key($subNavSections); $section = $this->getArg('section', $defaultSubNavSection); $moduleID = $this->getArg('module'); if ($moduleID) { $this->setTemplatePage('module'); try { if ($module = WebModule::factory($moduleID)) { $this->assign('moduleName', $module->getModuleName()); $this->assign('moduleID', $module->getConfigModule()); $this->assign('moduleIcon', $module->getOptionalModuleVar('icon', $module->getConfigModule(), 'module')); $section = $moduleID; $moduleSection = $this->getArg('section', 'general'); $this->assign('moduleSection', $moduleSection); } } catch (KurogoException $e) { $this->redirectTo($this->page, array()); } } elseif ($section == $defaultSubNavSection) { $moduleClasses = WebModule::getAllModuleClasses(); $this->assign('moduleClasses', $moduleClasses); $this->setTemplatePage($section); } elseif ($section == 'homescreen') { $this->setTemplatePage($section); $modules = $this->getModules(); $this->assign('modules', $modules); } else { $this->redirectTo($this->page, array()); } break; case 'site': $subNavSections = $this->getSubNavSections($this->page); $this->assign('subNavSections', $subNavSections); $defaultSubNavSection = key($subNavSections); $section = $this->getArg('section', $defaultSubNavSection); if (!isset($subNavSections[$section])) { $this->redirectTo($this->page, array()); } break; case 'credits': $section = $this->getArg('section', 'credits'); $subNavSections = array('credits' => array('id' => 'credits', 'title' => $this->getLocalizedString("ADMIN_CREDITS_CREDITS_TITLE"), 'url' => $this->buildURL($this->page, array('section' => 'credits'))), 'license' => array('id' => 'license', 'title' => $this->getLocalizedString("ADMIN_CREDITS_LICENSE_TITLE"), 'url' => $this->buildURL($this->page, array('section' => 'license')))); $this->assign('subNavSections', $subNavSections); if (isset($subNavSections[$section])) { switch ($section) { case 'license': $licenseFile = ROOT_DIR . "/LICENSE"; if (is_file($licenseFile)) { $this->assign('license', file_get_contents($licenseFile)); } else { die($licenseFile); throw new KurogoException("Unable to load LICENSE file, you may have a compromised Kurogo Installation"); } } $this->setTemplatePage($section); } else { $this->redirectTo('section', array()); } break; case 'index': //redirect desktop devices to the "default page" $deviceClassifier = Kurogo::deviceClassifier(); if ($deviceClassifier->isComputer() || $deviceClassifier->isTablet()) { $defaultSection = current($navSections); $this->redirectTo($defaultSection['id'], array()); } break; default: $this->redirectTo('index', array()); break; } $this->assign('section', $section); }
protected function getAllModuleNavigationData($includeDisabled = self::INCLUDE_DISABLED_MODULES) { $moduleConfig = $this->getModuleNavigationIDs($includeDisabled); $homeModuleID = $this->getHomeModuleID(); $modules = array('home' => array(), 'primary' => array(), 'secondary' => array()); $disabledIDs = $this->getUserDisabledModuleIDs(); foreach ($moduleConfig as $type => $modulesOfType) { foreach ($modulesOfType as $moduleID => $title) { $shortTitle = $title; $moduleConfig = ModuleConfigFile::factory($moduleID, 'module', ModuleConfigFile::OPTION_DO_NOT_CREATE); if ($moduleConfig) { $shortTitle = $moduleConfig->getOptionalVar('shortTitle', $title); } $selected = $this->configModule == $moduleID; $primary = $type == 'primary'; $classes = array(); if ($selected) { $classes[] = 'selected'; } if (!$primary) { $classes[] = 'utility'; } $imgSuffix = $this->pagetype == 'tablet' && $selected ? '-selected' : ''; //this is fixed for now $modulesThatCannotBeDisabled = array('customize'); $moduleNavData = array('type' => $type, 'selected' => $selected, 'title' => $title, 'shortTitle' => $shortTitle, 'url' => "/{$moduleID}/", 'disableable' => !in_array($moduleID, $modulesThatCannotBeDisabled), 'disabled' => $includeDisabled && in_array($moduleID, $disabledIDs), 'img' => "/modules/{$homeModuleID}/images/{$moduleID}{$imgSuffix}" . $this->imageExt, 'class' => implode(' ', $classes)); if (Kurogo::getOptionalSiteVar('DYNAMIC_MODULE_NAV_DATA', false)) { $module = WebModule::factory($moduleID, false, array(), false); // do not initialize if ($moduleNavData = $module->getModuleNavigationData($moduleNavData)) { $modules[$moduleNavData['type']][$moduleID] = $moduleNavData; } } else { $modules[$type][$moduleID] = $moduleNavData; } } } $modules = $this->getUserSortedModules($modules); //error_log('$modules(): '.print_r(array_keys($modules), true)); return $modules; }
protected function initializeForPage() { //make sure that only desktop devices can use the module if (!Kurogo::deviceClassifier()->isComputer() && $this->page !='index') { $this->redirectTo('index'); } $navSections = $this->getNavSections(); $section = ''; $this->assign('navSections', $navSections); $this->addJQuery(); $this->addJQueryUI(); switch ($this->page) { case 'modules': $subNavSections = $this->getSubNavSections($this->page); $this->assign('subNavSections', $subNavSections); $defaultSubNavSection = key($subNavSections); $section = $this->getArg('section', $defaultSubNavSection); $moduleID = $this->getArg('module'); if ($moduleID) { $this->setTemplatePage('module'); try { if ($module = WebModule::factory($moduleID)) { $this->assign('moduleName', $module->getModuleName()); $this->assign('moduleID', $module->getConfigModule()); $section = $moduleID; $moduleSection = $this->getArg('section','general'); $this->assign('moduleSection',$moduleSection); } } catch (Exception $e) { $this->redirectTo($this->page, array()); } } elseif ($section == $defaultSubNavSection) { $this->setTemplatePage($section); } elseif ($section == 'homescreen') { $this->setTemplatePage($section); $homeModule = WebModule::factory('home'); $modules = $this->getModules(); $this->assign('modules', $modules); } else { $this->redirectTo($this->page, array()); } break; case 'site': $subNavSections = $this->getSubNavSections($this->page); $this->assign('subNavSections', $subNavSections); $defaultSubNavSection = key($subNavSections); $section = $this->getArg('section', $defaultSubNavSection); if (!isset($subNavSections[$section])) { $this->redirectTo($this->page, array()); } break; case 'credits': $section = $this->getArg('section', 'credits'); $subNavSections = array( 'credits'=>array( 'id'=>'credits', 'title'=>'Credits', 'url'=>$this->buildURL($this->page, array('section'=>'credits')) ), 'license'=>array( 'id'=>'license', 'title'=>'License', 'url'=>$this->buildURL($this->page, array('section'=>'license')) ) ); $this->assign('subNavSections', $subNavSections); if (isset($subNavSections[$section])) { $this->setTemplatePage($section); } else { $this->redirectTo('section', array()); } break; case 'index': //redirect desktop devices to the "default page" if (Kurogo::deviceClassifier()->isComputer()) { $defaultSection = current($navSections); $this->redirectTo($defaultSection['id'], array()); } break; default: $this->redirectTo('index', array()); break; } $this->assign('section', $section); }
protected function initializeForPage() { switch ($this->page) { case 'help': break; case 'index': $this->setPageTitle($this->getOptionalModuleVar('pageTitle', Kurogo::getSiteString('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::getSiteString('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->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')); break; case 'search': $searchTerms = $this->getArg('filter'); $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); 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::getSiteString('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; } }
protected function getAllModuleNavigationData($includeHidden = self::INCLUDE_HIDDEN_MODULES, $iconSetType = 'navigation') { $modules = $moduleNavData = array('primary' => array(), 'secondary' => array()); $navModules = Kurogo::getSiteSections('navigation', Config::APPLY_CONTEXTS_NAVIGATION); foreach ($navModules as $moduleID => $moduleData) { $type = Kurogo::arrayVal($moduleData, 'type', 'primary'); $moduleNavData[$type][$moduleID] = $moduleData; } if ($iconSet = $this->getOptionalThemeVar($iconSetType . '_icon_set')) { $iconSetSize = $this->getOptionalThemeVar($iconSetType . '_icon_size'); $imgPrefix = "/common/images/iconsets/{$iconSet}/{$iconSetSize}/"; } else { $homeModuleID = $this->getHomeModuleID(); $imgPrefix = "/modules/{$homeModuleID}/images/"; } //this is fixed for now $modulesThatCannotBeHidden = array('customize'); $allModuleData = array(); $userNavData = $this->getUserNavData(); foreach ($moduleNavData as $type => $modulesOfType) { foreach ($modulesOfType as $moduleID => $navData) { $icon = $moduleID; $selected = $this->configModule == $moduleID; $primary = $type == 'primary'; $classes = array(); if ($selected) { $classes[] = 'selected'; } if (!$primary) { $classes[] = 'utility'; } $hidable = !in_array($moduleID, $modulesThatCannotBeHidden); $imgSuffix = $this->pagetype == 'tablet' && $selected ? '' : ''; $linkTarget = Kurogo::arrayVal($navData, 'linkTarget'); // customize is implemented as a page on the home module if ($moduleID == 'customize') { $visible = true; $icon = $moduleID; $moduleData = array('type' => $type, 'selected' => $selected, 'title' => $this->getLocalizedString('CUSTOMIZE_TITLE'), 'shortTitle' => $this->getLocalizedString('CUSTOMIZE_SHORT_TITLE'), 'url' => "/" . $this->getHomeModuleID() . "/customize", 'hideable' => $hidable, 'visible' => true, 'img' => $imgPrefix . "{$icon}{$imgSuffix}" . $this->imageExt, 'class' => implode(' ', $classes), 'linkTarget' => $linkTarget); } else { //this will throw an exception if a module is not available, so watch out $moduleConfig = Kurogo::getModuleConfig('module', $moduleID); $title = Kurogo::arrayVal($navData, 'title', $moduleConfig->getVar('title')); $shortTitle = Kurogo::arrayVal($navData, 'shortTitle', $title); $icon = $moduleConfig->getOptionalVar('icon', $moduleID); $visible = Kurogo::arrayVal($userNavData, $moduleID, Kurogo::arrayVal($navData, 'visible', 1)); $moduleData = array('type' => $type, 'selected' => $selected, 'title' => $title, 'shortTitle' => $shortTitle, 'url' => "/{$moduleID}/", 'hideable' => $hidable, 'visible' => $visible, 'img' => $imgPrefix . "{$icon}{$imgSuffix}" . $this->imageExt, 'class' => implode(' ', $classes), 'linkTarget' => $linkTarget); if (Kurogo::getOptionalSiteVar('DYNAMIC_MODULE_NAV_DATA', false)) { $module = WebModule::factory($moduleID, false, array(), false); // do not initialize $moduleData = $module->getModuleNavigationData($moduleData); } } if ($visible || $includeHidden || $type == 'primary' && isset($userNavData['visible'])) { $modules[$type][$moduleID] = $moduleData; } } } if (isset($userNavData['visible'])) { $userModuleNavData = array(); foreach ($userNavData['visible'] as $moduleID => $visible) { if (isset($modules['primary'][$moduleID])) { if ($visible || $includeHidden) { $userModuleNavData[$moduleID] = $modules['primary'][$moduleID]; $userModuleNavData[$moduleID]['visible'] = $visible; } } } // make sure all primary modules are defined in userNavData // this ensures that new modules show up if a user has customized their layout $userModules = array_keys($userNavData['visible']); $navModules = array_keys($modules['primary']); if ($diff = array_diff($navModules, $userModules)) { foreach ($diff as $moduleID) { $userModuleNavData[$moduleID] = $modules['primary'][$moduleID]; } } $modules['primary'] = $userModuleNavData; } return $modules; }
protected function getAllModules() { $dirs = array(MODULES_DIR, SITE_MODULES_DIR); $modules = array(); foreach ($dirs as $dir) { if (is_dir($dir)) { $d = dir($dir); while (false !== ($entry = $d->read())) { if ($entry[0]!='.' && is_dir(sprintf("%s/%s", $dir, $entry))) { $module = WebModule::factory($entry); $modules[$entry] = $module; } } $d->close(); } } ksort($modules); return $modules; }
protected function initializeForPage() { switch ($this->page) { case 'help': break; case 'index': if ($this->pagetype == 'tablet') { $modulePanes = $this->getTabletModulePanes($this->getModuleSection('tablet_panes')); $this->assign('modulePanes', $modulePanes); $this->addOnLoad('loadModulePages(' . json_encode($modulePanes) . ');'); $this->addOnOrientationChange('moduleHandleWindowResize();'); } else { $this->assign('modules', $this->getModuleNavlist()); $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::getSiteString('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->assign('SHOW_DOWNLOAD_TEXT', DownloadWebModule::appDownloadText($this->platform)); $this->assign('displayType', $this->getModuleVar('display_type')); break; case 'search': $searchTerms = $this->getArg('filter'); $useAjax = $this->pagetype != 'basic' && $this->pagetype != 'touch'; $searchModules = array(); foreach ($this->getAllModuleNavigationData(self::EXCLUDE_DISABLED_MODULES) as $type => $modules) { foreach ($modules as $id => $info) { $module = self::factory($id); if ($module->getModuleVar('search')) { $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->addInlineJavascript('var federatedSearchModules = ' . json_encode($searchModules) . ";\n"); $this->addOnLoad('runFederatedSearch(federatedSearchModules);'); } $this->assign('federatedSearchModules', $searchModules); $this->assign('searchTerms', $searchTerms); $this->setLogData($searchTerms); break; case 'searchResult': $moduleID = $this->getArg('id'); $searchTerms = $this->getArg('filter'); $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('ajax' => 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; } }
protected function getCreditsHTML() { $module = WebModule::factory($this->configModule, 'credits_html'); return $module->fetchPage(); }
public function initializeForCommand() { $this->requiresAdmin(); switch ($this->command) { case 'checkversion': $data = array( 'current'=>Kurogo::sharedInstance()->checkCurrentVersion(), 'local' =>KUROGO_VERSION ); $this->setResponse($data); $this->setResponseVersion(1); break; case 'clearcaches': $result = Kurogo::sharedInstance()->clearCaches(); if ($result===0) { $this->setResponse(true); $this->setResponseVersion(1); } else { $this->throwError(KurogoError(1, "Error clearing caches", "There was an error ($result) clearing the caches")); } break; case 'getconfigsections': $type = $this->getArg('type'); switch ($type) { case 'module': $moduleID = $this->getArg('module',''); try { $module = WebModule::factory($moduleID); } catch (Exception $e) { throw new Exception('Module ' . $moduleID . ' not found'); } $sections = $module->getModuleAdminSections(); break; case 'site': throw new Exception("getconfigsections for site not handled yet"); } $this->setResponse($sections); $this->setResponseVersion(1); break; case 'getconfigdata': $type = $this->getArg('type'); $section = $this->getArg('section',''); switch ($type) { case 'module': $moduleID = $this->getArg('module',''); try { $module = WebModule::factory($moduleID); } catch (Exception $e) { throw new Exception('Module ' . $moduleID . ' not found'); } $adminData = $this->getAdminData($module, $section); break; case 'site': $adminData = $this->getAdminData('site', $section); break; } $this->setResponse($adminData); $this->setResponseVersion(1); break; case 'setconfigdata': $type = $this->getArg('type'); $data = $this->getArg('data', array()); $section = $this->getArg('section',''); $subsection = null; if (empty($data)) { $data = array(); } elseif (!is_array($data)) { throw new Exception("Invalid data for $type $section"); } switch ($type) { case 'module': if ($section == 'overview') { foreach ($data as $moduleID=>$props) { try { $module = WebModule::factory($moduleID); } catch (Exception $e) { throw new Exception('Module ' . $moduleID . ' not found'); } if (!is_array($props)) { throw new Exception("Invalid properties for $type $section"); } $valid_props = array('protected','secure','disabled','search'); foreach ($props as $key=>$value) { if (!in_array($key, $valid_props)) { throw new Exception("Invalid property $key for module $module"); } $this->setConfigVar($module, 'general', $subsection, $key, $value); } } foreach ($this->changedConfigs as $config) { $config->saveFile(); } $this->setResponse(true); $this->setResponseVersion(1); break 2; } else { $moduleID = $this->getArg('module',''); try { $module = WebModule::factory($moduleID); } catch (Exception $e) { throw new Exception('Module ' . $moduleID . ' not found'); } $type = $module; } break; case 'site': break; default: throw new Exception("Invalid type $type"); } foreach ($data as $section=>$fields) { $adminData = $this->getAdminData($type, $section); if ($adminData['sectiontype']=='sections') { $subsection = key($fields); $fields = current($fields); $adminData = $this->getAdminData($type, $section, $subsection); } $fields = is_array($fields) ? $fields : array(); foreach ($fields as $key=>$value) { if ($adminData['sectiontype']=='section' && isset($adminData['sectionclearvalues']) && $adminData['sectionclearvalues']) { if ($config = $this->getAdminConfig($type, $adminData['config'], ConfigFile::OPTION_DO_NOT_CREATE)) { $config->removeSection($key); } } // ignore prefix values. We'll put it back together later if (preg_match("/^(.*?)_prefix$/", $key,$bits)) { continue; } $prefix = isset($fields[$key . '_prefix']) ? $fields[$key . '_prefix'] : ''; if ($prefix && defined($prefix)) { $value = constant($prefix) . '/' . $value; } $this->setConfigVar($type, $section, $subsection, $key, $value); } } if ($sectionorder = $this->getArg('sectionorder')) { foreach ($sectionorder as $section=>$order) { $this->setSectionOrder($type, $section, $subsection, $order); } } foreach ($this->changedConfigs as $config) { $config->saveFile(); } $this->setResponse(true); $this->setResponseVersion(1); break; case 'removeconfigsection': $type = $this->getArg('type'); $section = $this->getArg('section',''); $key = $this->getArg('key', null); switch ($type) { case 'site': $subsection = $this->getArg('subsection',null); $sectionData = $this->getAdminData($type, $section, $subsection); $config = ConfigFile::factory($sectionData['config'],'site'); break; case 'module': $moduleID = $this->getArg('module',''); try { $module = WebModule::factory($moduleID); } catch (Exception $e) { throw new Exception('Module ' . $moduleID . ' not found'); } $sectionData = $this->getAdminData($module, $section); $config = $module->getConfig($sectionData['config']); break; default: throw new Exception("Invalid type $type"); } if (!isset($sectionData['sections']) || (!isset($sectionData['sectiondelete']) || !$sectionData['sectiondelete'])) { throw new Exception("Config '$section' of module '$moduleID' does not permit removal of items"); } if (!isset($sectionData['sections'][$key])) { throw new Exception("Section $key not found in config '$section' of module '$moduleID'"); } if (!$result = $config->removeSection($key)) { throw new Exception("Error removing item $key from config '" . $sectionData['config'] ."'"); } else { $config->saveFile(); } $this->setResponse(true); $this->setResponseVersion(1); break; case 'setmodulelayout': $data = $this->getArg('data', array()); $config = ModuleConfigFile::factory('home', 'module'); if (!isset($data['primary_modules'])) { $data['primary_modules'] = array(); } $config->setSection('primary_modules', $data['primary_modules']); if (!isset($data['secondary_modules'])) { $data['secondary_modules'] = array(); } $config->setSection('secondary_modules', $data['secondary_modules']); $config->saveFile(); $this->setResponse(true); $this->setResponseVersion(1); break; default: $this->invalidCommand(); break; } }
protected function createDefaultFile($file, $type) { switch ($type) { case 'site': $_file = $this->getFileByType($file, $type); $defaultFile = $this->getFileByType($file, $type.'-default'); if (file_exists($defaultFile)) { $this->createDirIfNotExists(dirname($_file)); return @copy($defaultFile, $_file); } return false; break; case 'module': //check to see if the module has a default config file first $_file = $this->getFileByType($file, $type); $defaultFile = $this->getFileByType($file, $type.'-default'); if (file_exists($defaultFile)) { $this->createDirIfNotExists(dirname($_file)); return @copy($defaultFile, $_file); } elseif ($module = WebModule::factory($file)) { return $module->createDefaultConfigFile(); } else { throw new Exception("Module $file not found"); } break; case 'file': $defaultFile = $this->getFileByType($file, $type.'-default'); if (file_exists($defaultFile)) { $this->createDirIfNotExists(dirname($file)); return @copy($defaultFile, $file); } return false; break; } }
protected function initializeForPage() { $this->addJQuery(); switch ($this->page) { case 'module': $moduleID = $this->getArg('moduleID'); if (empty($moduleID)) { $this->redirectTo('modules'); } $module = WebModule::factory($moduleID); $moduleData = $module->getModuleData(); $moduleSections = array(); if ($section = $this->getArg('section')) { if ($section=='feeds' && $module->hasFeeds()) { if (strlen($this->getArg('removeFeed'))>0) { $index = $this->getArg('removeFeed'); $module->removeFeed($index); } if ($this->getArg('addFeed')) { $feedData = $this->getArg('addFeedData'); if (!$module->addFeed($feedData, $error)) { $this->assign('errorMessage', $error); } } $moduleData['feeds'] = $module->loadFeedData(); if (!$moduleData['feeds']) { $moduleData['feeds'] = array(); } $this->assign('feedURL', $this->buildBreadcrumbURL('module', array( 'moduleID'=>$moduleID, 'section'=>$section),false )); $this->assign('feedFields', $module->getFeedFields()); } elseif (!isset($moduleData[$section])) { $this->redirectTo('module', array('moduleID'=>$moduleID), false); } } if ($this->getArg('submit')) { $merge = $this->getArg('merge', true); if ($merge) { $moduleData = $this->prepareSubmitData('moduleData'); $moduleData = array_merge($module->getModuleDefaultData(), $moduleData); } else { $moduleData = $this->prepareSubmitData('moduleData'); } if ($section) { $moduleData = array($section=>$moduleData[$section]); } else { /* only include the scalar values since array values come from sections */ $_data = array(); foreach ($moduleData as $var=>$val) { if (is_scalar($val)) { $_data[$var] = $val; } $moduleData = $_data; } } $module->saveConfig($moduleData, $section); if ($section) { $this->redirectTo('module', array('moduleID'=>$moduleID), false); } else { $this->redirectTo('modules', false, false); } } $this->setPageTitle(sprintf("Administering %s module", $moduleData['title'])); $this->setBreadcrumbTitle($moduleData['title']); $this->setBreadcrumbLongTitle($moduleData['title']); $formListItems = array(); if ($section) { $moduleData = $moduleData[$section]; } else { $formListItems[] = $this->getModuleItemForKey('id', $moduleID); } foreach ($moduleData as $key=>$value) { if (is_scalar($value)) { $formListItems[] = $module->getModuleItemForKey($key, $value); } else { $moduleSections[$key] = $module->getSectionTitleForKey($key); } } if (!$section) { foreach ($moduleSections as $key=>$title) { $formListItems[] = array( 'type'=>'url', 'name'=>$title, 'value'=>$this->buildBreadcrumbURL('module', array( 'moduleID'=>$moduleID, 'section'=>$key) ) ); } if ($module->hasFeeds()) { $formListItems[] = array( 'type'=>'url', 'name'=>'Data Configuration', 'value'=>$this->buildBreadcrumbURL('module', array( 'moduleID'=>$moduleID, 'section'=>'feeds') ) ); } $formListItems[] = array( 'type'=>'url', 'name'=>'Page Data', 'value'=>$this->buildBreadcrumbURL('pageData', array( 'moduleID'=>$moduleID ) ) ); } $_module = array( 'id'=>$moduleID ); $this->assign('formListItems', $formListItems); $this->assign('module' , $_module); $this->assign('section' , $section); if ($section) { $module->prepareAdminForSection($section, $this); } break; case 'modules': $allModules = $this->getAllModules(); $moduleList = array(); foreach ($allModules as $moduleID=>$moduleData) { try { $moduleList[] = array( 'img'=>"/modules/home/images/{$moduleID}.png", 'title'=>$moduleData->getModuleName(), 'url'=>$this->buildBreadcrumbURL('module', array( 'moduleID'=>$moduleID ) ) ); $this->assign('moduleList', $moduleList); } catch(Exception $e) {} } break; case 'pageData': $moduleID = $this->getArg('moduleID'); if (empty($moduleID)) { $this->redirectTo('modules'); } $module = WebModule::factory($moduleID); $pageData = $module->getPageData(); if ($this->getArg('submit')) { $pageData = $this->prepareSubmitData('pageData'); $module->saveConfig(array('nav'=>$pageData), 'nav'); } $this->setPageTitle(sprintf("Administering Page Data for %s", $module->getModuleName())); $pages = array(); foreach ($pageData as $page=>$_pageData) { $item = array(); $item[] = array( 'label'=>'Page', 'type'=>'label', 'value'=>$page ); $item[] = array( 'label'=>'Title', 'type'=>'text', 'name'=>"pageData[$page][pageTitle]", 'typename'=>"pageData][$page][pageTitle", 'value'=>isset($_pageData['pageTitle']) ? $_pageData['pageTitle'] : '' ); $item[] = array( 'label'=>'Breadcrumb Title', 'type'=>'text', 'name'=>"pageData[$page][breadcrumbTitle]", 'typename'=>"pageData][$page][breadcrumbTitle", 'value'=>isset($_pageData['breadcrumbTitle']) ? $_pageData['breadcrumbTitle'] : '' ); $item[] = array( 'label'=>'Breadcrumb Long Title', 'type'=>'text', 'name'=>"pageData[$page][breadcrumbLongTitle]", 'typename'=>"pageData][$page][breadcrumbLongTitle", 'value'=>isset($_pageData['breadcrumbLongTitle']) ? $_pageData['breadcrumbLongTitle'] : '' ); $pages[$page] = $item; } $_module = array( 'id'=>$moduleID ); $this->assign('pages' , $pages); $this->assign('module' , $_module); break; case 'strings': $configFile = ConfigFile::factory('strings', 'site', ConfigFile::OPTION_CREATE_WITH_DEFAULT | ConfigFile::OPTION_IGNORE_LOCAL); if ($this->getArg('submit')) { $strings = $this->prepareSubmitData('strings'); $configFile->addSectionVars($strings, false); $configFile->saveFile(); $this->redirectTo('index', false, false); } $strings = $configFile->getSectionVars(true); $formListItems = array(); foreach ($strings as $key=>$value) { if (is_scalar($value)) { $formListItems[] = array( 'label'=>implode(" ", array_map("ucfirst", explode("_", strtolower($key)))), 'name'=>"strings[$key]", 'typename'=>"strings][$key", 'value'=>$value, 'type'=>'text' ); } else { $formListItems[] = array( 'label'=>implode(" ", array_map("ucfirst", explode("_", strtolower($key)))), 'name'=>"strings[$key]", 'typename'=>"strings][$key", 'value'=>implode("\n\n", $value), 'type'=>'paragraph' ); } } $this->assign('localFile' , $configFile->localFile()); $this->assign('strings', $strings); $this->assign('formListItems', $formListItems); break; case 'site': $configFile = ConfigFile::factory('config', 'site', ConfigFile::OPTION_IGNORE_LOCAL); $siteVars = $configFile->getSectionVars(); if ($section = $this->getArg('section')) { if (!isset($siteVars[$section])) { $section = null; } } $formListItems = array(); if ($section) { if ($this->getArg('submit')) { $sectionVars = $this->prepareSubmitData('siteData'); $configFile->addSectionVars($sectionVars, true); $configFile->saveFile(); $this->redirectTo('site', false, false); } $formListItems = array(); $sectionVars = $configFile->getSection($section); foreach ($sectionVars as $key=>$value) { $formListItems[] = $this->getSiteItemForKey($section, $key, $value); } } else { foreach ($siteVars as $sectionName=>$sectionVars){ $formListItems[] = array( 'type'=>'url', 'name'=>$this->getSectionTitleForKey($sectionName), 'value'=>$this->buildBreadcrumbURL('site', array( 'section'=>$sectionName ) ) ); } } $this->assign('localFile' , $configFile->localFile()); $this->assign('section' , $section); $this->assign('formListItems', $formListItems); break; case 'sessions'; $session = $this->getSession(); if ($this->getArg('deleteSession')) { $sessionID = key($this->getArg('deleteSession')); // you can't delete your own session if ($sessionID != $session->getSessionID()) { $session->deleteSession($sessionID); } } $activeSessions = $session->getActiveSessions(); $sessions = array(); foreach ($activeSessions as $sessionID=>$sessionData) { $sessionItem = array( 'label'=>$sessionData['userID'] . " (" . $sessionData['auth'] . ")", 'subtitle'=>'Last Access: ' . date('m/d/y H:i:s', $sessionData['ping']) ); // you can't delete your own session if ($sessionID != $session->getSessionID()) { $sessionItem['name'] ='deleteSession[' . $sessionID . ']'; $sessionItem['type'] ='submit'; $sessionItem['confirm'] = true; $sessionItem['value'] = 'Delete'; } $sessions[] = $sessionItem; } $this->assign('sessions', $sessions); break; case 'index': $adminList = array(); $adminList[] = array( 'title'=>'Modules', 'url'=>$this->buildBreadcrumbURL('modules', array()), 'subtitle'=>'Manage module configuration and data' ); $adminList[] = array( 'title'=>'Site Configuration', 'url'=>$this->buildBreadcrumbURL('site', array()), 'subtitle'=>'Manage site-wide configuration' ); $adminList[] = array( 'title'=>'String Configuration', 'url'=>$this->buildBreadcrumbURL('strings', array()), 'subtitle'=>'Update textual strings used throughout the site' ); if ($this->getSiteVar('AUTHENTICATION_ENABLED')) { $adminList[] = array( 'title'=>'User Sessions', 'url'=>$this->buildBreadcrumbURL('sessions', array()), 'subtitle'=>'View and manage active user sessions' ); } $this->assign('adminList', $adminList); break; } }
public static function searchItems($moduleID, $searchTerms, $limit = null, $options = null) { $args = self::sharedInstance()->getArgs(); $module = WebModule::factory($moduleID, null, $args); return $module->searchItems($searchTerms, $limit, $options); }