public function getJSONOutput() { $contexts = Kurogo::sharedInstance()->getActiveContexts(); $this->contexts = array_keys($contexts); if (is_null($this->version)) { throw new KurogoException('APIResponse version must be set before display'); } return json_encode($this); }
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(); } }
public function initializeForCommand() { switch ($this->command) { case 'version': $this->out(KUROGO_VERSION); return 0; break; case 'clearCaches': $result = Kurogo::sharedInstance()->clearCaches(); return 0; break; case 'fetchAllData': $allModules = $this->getAllModules(); $time = 0; $this->out("Fetching data for site: " . SITE_NAME); $start = microtime(true); foreach ($allModules as $moduleID => $module) { if ($module->isEnabled() && $module->getOptionalModuleVar('PREFETCH_DATA')) { $module->setDispatcher($this->Dispatcher()); try { $module->init('fetchAllData'); $module->executeCommand(); } catch (KurogoException $e) { $this->out("Error: " . $e->getMessage()); } } } $end = microtime(true); $diff = $end - $start; $time += $diff; $this->out("Total: " . sprintf("%.2f", $end - $start) . " seconds."); return 0; break; case 'deployPostFlight': $this->verbose = $this->getArg('v'); $this->out('Running KurogoShell kurogo deployPostFlight'); $postFlightFilePath = SITE_SCRIPTS_DIR . DIRECTORY_SEPARATOR . 'deployPostFlight.sh'; if (!file_exists($postFlightFilePath)) { $this->out("{$postFlightFilePath} does not exist, skipping execution"); return 0; } elseif (!is_executable($postFlightFilePath)) { $this->out("{$postFlightFilePath} exists, but is not executable. This must be fixed"); return 126; } $outputLines = array(); exec(sprintf("%s %s %s", escapeshellcmd($postFlightFilePath), escapeshellarg(ROOT_DIR), escapeshellarg(SITE_DIR)), $outputLines, $returnValue); foreach ($outputLines as $lineNumber => $line) { $this->out($line); } return $returnValue; break; default: $this->invalidCommand(); break; } }
protected function applyContexts($sectionVars, $area, $type, $applyContexts) { if (!$this->activeContexts) { $this->activeContexts = Kurogo::sharedInstance()->getActiveContexts(); } $contextData = array(); $deny = array(); if ($type instanceof Module) { $type = $type->getConfigModule(); } foreach ($this->activeContexts as $context) { if ($context->getID() == UserContext::CONTEXT_DEFAULT) { continue; } Kurogo::log(LOG_DEBUG, "Apply context {$context} to {$area} {$type}", 'context'); if ($contextData) { throw new KurogoException("Multiple contexts not yet completed"); } if ($contextData = $this->getContextData($context->getID(), $area, $type)) { switch ($applyContexts) { case Config::APPLY_CONTEXTS_NAVIGATION: $_sectionData = array(); $deny = array(); foreach ($contextData as $field => $sections) { foreach ($sections as $section => $value) { switch ($field) { case 'visible': if (isset($sectionVars[$section])) { $_sectionData[$section] = $sectionVars[$section]; } $_sectionData[$section][$field] = $value; break; case 'deny': if ($value) { $deny[] = $section; } } } } $sectionVars = $_sectionData; foreach ($deny as $section) { unset($sectionVars[$section]); } break; default: throw new KurogoException("Invalid apply context value {$applyContexts}"); } } } return $sectionVars; }
public function getLocalizedString($key) { if (!preg_match("/^[a-z0-9_]+\$/i", $key)) { throw new KurogoConfigurationException("Invalid string key {$key}"); } Kurogo::log(LOG_DEBUG, "Retrieving localized string for {$key}", 'module'); // use any number of args past the first as options $args = func_get_args(); array_shift($args); if (count($args) == 0 || is_null($args[0])) { $args = null; } $languages = Kurogo::sharedInstance()->getLanguages(); foreach ($languages as $language) { $val = $this->getStringForLanguage($key, $language, $args); if ($val !== null) { Kurogo::log(LOG_INFO, "Found localized string \"{$val}\" for {$key} in {$language}", 'module'); return Kurogo::getOptionalSiteVar('LOCALIZATION_DEBUG') ? $key : $val; } } throw new KurogoConfigurationException("Unable to find string {$key} for Module {$this->id}"); }
/** * export the stats data to the database */ public static function exportStatsData($startTimestamp = null) { $site = Kurogo::sharedInstance()->getSite(); $baseLogDir = $site->getBaseLogDir(); $logDir = $site->getLogDir(); $statsLogFileName = Kurogo::getOptionalSiteVar('KUROGO_STATS_LOG_FILENAME', 'kurogo_stats_log_v1'); //if the base dir is different then the log dir then get all files with the log file name if ($baseLogDir != $logDir) { $logFiles = glob($baseLogDir . DIRECTORY_SEPARATOR . "*" . DIRECTORY_SEPARATOR . $statsLogFileName); } else { $logFiles = array($logDir . DIRECTORY_SEPARATOR . $statsLogFileName); } //cycle through all log files foreach ($logFiles as $statsLogFile) { if (!file_exists($statsLogFile)) { continue; } $today = date('Ymd', time()); //copy the log file $tempLogFolder = Kurogo::tempDirectory(); $statsLogFileCopy = rtrim($tempLogFolder, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . "stats_log_copy.{$today}"; if (!is_writable($tempLogFolder)) { throw new Exception("Unable to write to Temporary Directory {$tempLogFolder}"); } if (!rename($statsLogFile, $statsLogFileCopy)) { Kurogo::log(LOG_DEBUG, "Failed to rename {$statsLogFile} to {$statsLogFileCopy}", 'kurogostats'); return; } $handle = fopen($statsLogFileCopy, 'r'); $startDate = ''; while (!feof($handle)) { $line = trim(fgets($handle, 1024)); $value = explode("\t", $line); if (count($value) != count(self::validFields()) || !isset($value[0]) || intval($value[0]) <= 0) { continue; } if (!$startDate) { $startTimestamp = $value[0]; $startDate = date('Y-m-d', $startTimestamp); // If startTimestamp is during today // Set startTimestamp to the beginning of today if ($startDate == date('Y-m-d')) { list($year, $month, $day) = explode('-', $startDate); $startTimestamp = mktime(0, 0, 0, $month, $day, $year); } } //insert the raw data to the database $logData = array_combine(self::validFields(), $value); self::insertStatsToMainTable($logData); } fclose($handle); unlink($statsLogFileCopy); self::updateSummaryFromShards($startTimestamp); } }
public static function popErrorReporting() { return Kurogo::sharedInstance()->_popErrorReporting(); }
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 getMemoryCache() { if ($this->useMemoryCache) { return Kurogo::sharedInstance()->cacher(); } return false; }
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; } }
public static function getLocalizedString($key, $opts = null) { return Kurogo::sharedInstance()->localizedString($key, $opts); }
function getMinifyGroupsConfig() { $minifyConfig = array(); $key = $_GET['g']; // javascript and css search directory order $dirs = array(APP_DIR, SHARED_APP_DIR, SITE_APP_DIR, SHARED_THEME_DIR, THEME_DIR); // // Check for specific file request // if (strpos($key, MIN_FILE_PREFIX) === 0) { // file path relative to either templates or the theme (check theme first) $path = substr($key, strlen(MIN_FILE_PREFIX)); $files = array(); foreach ($dirs as $dir) { if ($dir) { $files[] = $dir . $path; } } $config = array('include' => 'all', 'files' => $files); return array($key => buildFileList($config)); } // // Page request // $pageOnly = isset($_GET['pageOnly']) && $_GET['pageOnly']; $noCommon = $pageOnly || isset($_GET['noCommon']) && $_GET['noCommon']; // if this is a copied module also pull in files from that module $configModule = isset($_GET['config']) ? $_GET['config'] : ''; list($ext, $module, $page, $pagetype, $platform, $browser, $pathHash) = explode('-', $key); $cache = new DiskCache(CACHE_DIR . '/minify', Kurogo::getOptionalSiteVar('MINIFY_CACHE_TIMEOUT', 30), true); $cacheName = "group_{$key}"; $Kurogo = Kurogo::sharedInstance(); $Kurogo->setCurrentModuleID($module); if ($configModule) { $Kurogo->setCurrentConfigModule($configModule); $cacheName .= "-{$configModule}"; } if ($pageOnly) { $cacheName .= "-pageOnly"; } if ($cache->isFresh($cacheName)) { $minifyConfig = $cache->read($cacheName); } else { if ($noCommon) { // Info module does not inherit from common files $subDirs = array('/modules/' . $module); } else { $subDirs = array('/common', '/modules/' . $module); } if ($configModule && $configModule !== $module) { $subDirs[] = '/modules/' . $configModule; } $checkFiles = array('css' => getFileConfigForDirs('css', 'css', $page, $pagetype, $platform, $browser, $dirs, $subDirs, $pageOnly), 'js' => getFileConfigForDirs('js', 'javascript', $page, $pagetype, $platform, $browser, $dirs, $subDirs, $pageOnly)); //error_log(print_r($checkFiles, true)); $minifyConfig[$key] = buildFileList($checkFiles[$ext]); //error_log(__FUNCTION__."($pagetype-$platform-$browser) scanned filesystem for $key"); $cache->write($minifyConfig, $cacheName); } // Add minify source object for the theme config if ($ext == 'css') { $themeConfig = Kurogo::getThemeConfig(); if ($themeConfig) { $minifyConfig[$key][] = new Minify_Source(array('id' => 'themeConfigModTimeChecker', 'getContentFunc' => 'minifyThemeConfigModTimeCheckerContent', 'minifier' => '', 'contentType' => Minify::TYPE_CSS, 'lastModified' => $themeConfig->getLastModified())); } } //error_log(__FUNCTION__."($pagetype-$platform-$browser) returning: ".print_r($minifyConfig, true)); return $minifyConfig; }
public function initializeForCommand() { switch ($this->command) { case 'hello': $allmodules = $this->getAllModules(); if ($this->requestedVersion >= 3) { $version = 3; } else { $version = 2; $homeModuleData = $this->getAllModuleNavigationData(); $homeModules = array('primary' => array_keys($homeModuleData['primary']), 'secondary' => array_keys($homeModuleData['secondary'])); } $platform = $this->clientPlatform; if ($this->clientPagetype == 'tablet') { $platform .= '-tablet'; } foreach ($allmodules as $moduleID => $module) { if ($module->isEnabled()) { //home is deprecated in lieu of using the "modules" command of the home module $home = false; if ($version < 3) { if (($key = array_search($moduleID, $homeModules['primary'])) !== FALSE) { if (Kurogo::arrayVal($homeModuleData['primary'][$moduleID], 'visible', true)) { $title = Kurogo::arrayVal($homeModuleData['primary'][$moduleID], 'title', $module->getModuleVar('title')); $home = array('type' => 'primary', 'order' => $key, 'title' => $title); } } elseif (($key = array_search($moduleID, $homeModules['secondary'])) !== FALSE) { if (Kurogo::arrayVal($homeModuleData['secondary'][$moduleID], 'visible', true)) { $title = Kurogo::arrayVal($homeModuleData['secondary'][$moduleID], 'title', $module->getModuleVar('title')); $home = array('type' => 'secondary', 'order' => $key, 'title' => $title); } } } $moduleResponse = array('id' => $module->getID(), 'tag' => $module->getConfigModule(), 'icon' => $module->getOptionalModuleVar('icon', $module->getConfigModule(), 'module'), 'title' => $module->getModuleVar('title', 'module'), 'access' => $module->getAccess(AccessControlList::RULE_TYPE_ACCESS), 'payload' => $module->getPayload(), 'bridge' => $module->getWebBridgeConfig($platform), 'vmin' => $module->getVmin(), 'vmax' => $module->getVmax()); if ($version < 3) { $moduleResponse['home'] = $home; } $modules[] = $moduleResponse; } } $contexts = array(); foreach (Kurogo::sharedInstance()->getContexts() as $context) { if ($context->isManual()) { $contexts[] = array('id' => $context->getID(), 'title' => $context->getTitle(), 'description' => $context->getDescription()); } } $response = array('timezone' => Kurogo::getSiteVar('LOCAL_TIMEZONE'), 'site' => Kurogo::getSiteString('SITE_NAME'), 'organization' => Kurogo::getSiteString('ORGANIZATION_NAME'), 'version' => KUROGO_VERSION, 'modules' => $modules, 'default' => Kurogo::defaultModule(), 'home' => $this->getHomeModuleID(), 'contexts' => $contexts, 'contextsDisplay' => array('home' => Kurogo::getSiteVar('USER_CONTEXT_LIST_STYLE_NATIVE', 'contexts'), 'customize' => Kurogo::getSiteVar('USER_CONTEXT_LIST_STYLE_CUSTOMIZE', 'contexts'))); if ($appData = Kurogo::getAppData($this->clientPlatform)) { if ($version = Kurogo::arrayVal($appData, 'version')) { if (version_compare($this->clientVersion, $version) < 0) { $response['appdata'] = array('url' => Kurogo::arrayVal($appData, 'url'), 'version' => Kurogo::arrayVal($appData, 'version')); } } } $this->setResponse($response); $this->setResponseVersion($version); break; case 'setcontext': $context = $this->getArg('context'); $response = Kurogo::sharedInstance()->setUserContext($context); $this->setResponse($response); $this->setResponseVersion(1); break; case 'classify': $userAgent = $this->getArg('useragent'); if (!$userAgent) { throw new KurogoException("useragent parameter not specified"); } $response = Kurogo::deviceClassifier()->classifyUserAgent($userAgent); $this->setResponse($response); $this->setResponseVersion(1); break; default: $this->invalidCommand(); break; } }
public static function deviceClassifier() { return Kurogo::sharedInstance()->getDeviceClassifier(); }
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 dispatch() { if (isset($this->args[0])) { $shell = $this->args[0]; $command = ''; $this->shell = $shell; $this->shiftArgs(); if (isset($this->args[0]) && $this->args[0]) { $command = $this->args[0]; } $this->shellCommand = $command; $args = $this->getParams(); $Kurogo = Kurogo::sharedInstance(); $Kurogo->setRequest($shell, $command, $args); try { if ($module = ShellModule::factory($shell, $command, $args, $this)) { if (!$command) { $this->stop(ShellModule::SHELL_COMMAND_EMPTY); } $Kurogo->setCurrentModule($module); return $module->executeCommand(); } } catch (KurogoModuleNotFound $e) { $this->stop(ShellModule::SHELL_MODULE_NOT_FOUND); } } $this->stop(ShellModule::SHELL_NO_MODULE); /* $this->stderr(PHP_EOL . "Kurogo Console: "); $this->stderr(PHP_EOL . "Not found the shell module"); $this->stop(); */ }
protected function getUserContextListData($reloadPage = 'modules', $includeCustom = true) { // show user selectable context switching if ($contexts = Kurogo::sharedInstance()->getContexts()) { $userContextList = array(); $ajaxURLPrefix = Kurogo::getSiteVar('DEVICE_DEBUG') ? rtrim(URL_PREFIX, '/') : ''; $activeCount = 0; $homeModuleID = $this->getHomeModuleID(); $userCustomized = (bool) $this->getUserNavData(); foreach ($contexts as $context) { if ($context->isManual()) { $args = array_merge($context->getContextArgs(), array('resetUserNavData' => 1)); if ($this->pagetype == 'compliant' || $this->pagetype == 'tablet') { $ajax = true; $url = $ajaxURLPrefix . self::buildURLForModule($homeModuleID, $reloadPage, $args); } else { $ajax = false; $url = self::buildURLForModule($homeModuleID, 'index', $args); } $userContextList[] = array('active' => $context->isActive() && !$userCustomized, 'context' => $context->getID(), 'ajax' => $ajax, 'title' => $context->getTitle(), 'url' => $url); } } if ($includeCustom && $userCustomized) { $userContextList[] = array('title' => Kurogo::getSiteString("USER_CONTEXT_CUSTOM"), 'active' => true, 'url' => $this->buildURLForModule($homeModuleID, 'customize'), 'ajax' => false); } return $userContextList; } }
<?php /** * @package Minify */ /** */ if (!isset($Kurogo)) { require_once realpath(dirname(__FILE__) . '/../../lib/Kurogo.php'); $Kurogo = Kurogo::sharedInstance(); // Configure web application $path = $_SERVER['REQUEST_URI']; $Kurogo->initialize($path); } // Minify cache ids for groups contain the list of source files, not the group id. // However Minify's cache ids do contain a serialized copy of the 'minifierOptions' field. // Use this to make sure there is a unique cache entry for each device class // allowing us to put device-specific content inside javascript and css files $min_serveOptions['minifierOptions']['kurogo']['device'] = Kurogo::deviceClassifier()->getDevice(); require_once LIB_DIR . '/minify.php'; /** * Configuration for default Minify application * @package Minify */ /** * In 'debug' mode, Minify can combine files with no minification and * add comments to indicate line #s of the original files. * * To allow debugging, set this option to true and add "&debug=1" to * a URI. E.g. /min/?f=script1.js,script2.js&debug=1 */
protected function assignSites() { $sites = Kurogo::sharedInstance()->getSites(); if (count($sites) > 1) { $currentSite = Kurogo::sharedInstance()->getSite(); $siteLinks = array(); foreach ($sites as $site) { if ($site->isEnabled()) { $siteLinks[] = array('name' => $site->getName(), 'title' => $site->getTitle(), 'active' => $site->getName() == $currentSite->getName(), 'url' => $site->getURL()); } } if ($this->pagetype == 'tablet') { $this->assign('siteLinksDescription', Kurogo::getSiteString('SITE_LINKS_DESCRIPTION_TABLET')); $siteLinksStyle = Kurogo::getSiteVar('SITES_LIST_STYLE_TABLET', 'sites'); } else { $this->assign('siteLinksDescription', Kurogo::getSiteString('SITE_LINKS_DESCRIPTION_COMPLIANT')); $siteLinksStyle = Kurogo::getSiteVar('SITES_LIST_STYLE_COMPLIANT', 'sites'); } $this->assign('siteLinks', $siteLinks); $this->assign('siteLinksStyle', $siteLinksStyle); } }