function __construct() { // Load main configuration file $config = ConfigFile::factory('kurogo', 'project', ConfigFile::OPTION_IGNORE_MODE | ConfigFile::OPTION_IGNORE_LOCAL); $this->addConfig($config); define('CONFIG_MODE', $config->getVar('CONFIG_MODE')); define('CONFIG_IGNORE_LOCAL', $config->getVar('CONFIG_IGNORE_LOCAL')); //make sure active site is set if (!$site = $this->getVar('ACTIVE_SITE')) { die("FATAL ERROR: ACTIVE_SITE not set"); } //make sure site_dir is set and is a valid path if (!($siteDir = $this->getVar('SITE_DIR')) || !($siteDir = realpath_exists($siteDir))) { die("FATAL ERROR: Site Directory ". $this->getVar('SITE_DIR') . " not found for site " . $site); } // Set up defines relative to SITE_DIR define('SITE_DIR', $siteDir); define('SITE_KEY', md5($siteDir)); define('SITE_LIB_DIR', SITE_DIR.'/lib'); define('SITE_APP_DIR', SITE_DIR.'/app'); define('SITE_MODULES_DIR', SITE_DIR.'/app/modules'); define('DATA_DIR', SITE_DIR.'/data'); define('CACHE_DIR', SITE_DIR.'/cache'); define('LOG_DIR', SITE_DIR.'/logs'); define('SITE_CONFIG_DIR', SITE_DIR.'/config'); //load in the site config file (required); $config = ConfigFile::factory('site', 'site'); $this->addConfig($config); // Set up theme define if (!$theme = $this->getVar('ACTIVE_THEME')) { die("FATAL ERROR: ACTIVE_THEME not set"); } define('THEME_DIR', SITE_DIR.'/themes/'.$theme); }
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 getSiteAccessControlLists() { $config = ConfigFile::factory('acls', 'site', ConfigFile::OPTION_CREATE_EMPTY); $acls = array(); foreach ($config->getSectionVars() as $aclArray) { if ($acl = AccessControlList::createFromArray($aclArray)) { $acls[] = $acl; } } return $acls; }
/** * Returns the authentication config file * @return ConfigFile */ private static function getAuthorityConfigFile() { return ConfigFile::factory('authentication', 'site'); }
protected function loadSiteConfigFile($name, $opts = 0) { $config = ConfigFile::factory($name, 'site', $opts); Kurogo::siteConfig()->addConfig($config); return $config->getSectionVars(true); }
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 loadSiteConfigFile($name, $keyName = null, $opts = 0) { $config = ConfigFile::factory($name, 'site', $opts); Kurogo::siteConfig()->addConfig($config); if ($keyName === null) { $keyName = $name; } return $this->loadConfigFile($config, $keyName); }
function minifyGetThemeVars() { static $themeVars = null; if (!isset($themeVars)) { $config = ConfigFile::factory('config', 'theme', ConfigFile::OPTION_CREATE_EMPTY); $pagetype = Kurogo::deviceClassifier()->getPagetype(); $platform = Kurogo::deviceClassifier()->getPlatform(); $sections = array('common', $pagetype, $pagetype . '-' . $platform); $themeVars = array(); foreach ($sections as $section) { if ($sectionVars = $config->getOptionalSection($section)) { $themeVars = array_merge($themeVars, $sectionVars); } } } return $themeVars; }
} $result['title'] = $feature->getTitle(); } return $result; } function htmlColorForColorString($colorString) { return substr($colorString, strlen($colorString) - 6); } function isValidURL($urlString) { // There is a bug in some versions of filter_var where it can't handle hyphens in hostnames return filter_var(strtr($urlString, '-', '.'), FILTER_VALIDATE_URL); } class MapsAdmin { public static function getMapControllerClasses() { return array('MapDataController' => 'default', 'MapDBDataController' => 'database'); } public static function getStaticMapClasses() { return array('GoogleStaticMap' => 'Google', 'ArcGISStaticMap' => 'ArcGIS', 'WMSStaticMap' => 'WMS'); } public static function getDynamicControllerClasses() { return array('GoogleJSMap' => 'Google', 'ArcGISJSMap' => 'ArcGIS'); } } $config = ConfigFile::factory('maps', 'site'); Kurogo::siteConfig()->addConfig($config);
protected function getPageConfig($name, $opts) { $config = ConfigFile::factory($this->id, "page-$name", $opts); $GLOBALS['siteConfig']->addConfig($config); return $config; }
protected function getConfig($name, $type, $opts=0) { $config = ConfigFile::factory($name, $type, $opts); $GLOBALS['siteConfig']->addConfig($config); return $config; }
function __construct(&$path) { // Load main configuration file $config = ConfigFile::factory('kurogo', 'project', ConfigFile::OPTION_IGNORE_MODE | ConfigFile::OPTION_IGNORE_LOCAL); $this->addConfig($config); define('CONFIG_MODE', $config->getVar('CONFIG_MODE', 'kurogo')); Kurogo::log(LOG_DEBUG, "Setting config mode to " . (CONFIG_MODE ? CONFIG_MODE : '<empty>'), 'config'); define('CONFIG_IGNORE_LOCAL', $config->getVar('CONFIG_IGNORE_LOCAL', 'kurogo')); //multi site currently only works with a url base of root "/" if ($this->getOptionalVar('MULTI_SITE', false, 'kurogo')) { // in scripts you can pass the site name to Kurogo::initialize() if (PHP_SAPI == 'cli') { $site = strlen($path) > 0 ? $path : $this->getVar('DEFAULT_SITE'); $siteDir = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site)); if (!file_exists(realpath($siteDir))) { die("FATAL ERROR: Site Directory {$siteDir} not found for site {$path}"); } } else { $paths = explode("/", $path); // this is url $sites = array(); $siteDir = ''; if (count($paths) > 1) { $site = $paths[1]; if ($sites = $this->getOptionalVar('ACTIVE_SITES', array(), 'kurogo')) { //see if the site is in the list of available sites if (in_array($site, $sites)) { $testPath = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site)); if (($siteDir = realpath($testPath)) && file_exists($siteDir)) { $urlBase = '/' . $site . '/'; // this is a url } } } elseif ($this->isValidSiteName($site)) { $testPath = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site)); if (($siteDir = realpath($testPath)) && file_exists($siteDir)) { $urlBase = '/' . $site . '/'; // this is a url } } } if (!$siteDir) { $site = $this->getVar('DEFAULT_SITE'); array_splice($paths, 1, 1, array($site, $paths[1])); $url = implode("/", $paths); header("Location: {$url}"); die; } } } else { //make sure active site is set if (!($site = $this->getVar('ACTIVE_SITE'))) { die("FATAL ERROR: ACTIVE_SITE not set"); } // make sure site_dir is set and is a valid path // Do not call realpath_exists here because until SITE_DIR define is set // it will not allow files and directories outside ROOT_DIR if (!($siteDir = $this->getVar('SITE_DIR')) || !(($siteDir = realpath($siteDir)) && file_exists($siteDir))) { die("FATAL ERROR: Site Directory " . $this->getVar('SITE_DIR') . " not found for site " . $site); } if (PHP_SAPI != 'cli') { // // Get URL base // if ($urlBase = $config->getOptionalVar('URL_BASE', '', 'kurogo')) { $urlBase = rtrim($urlBase, '/') . '/'; } else { //extract the path parts from the url $pathParts = array_values(array_filter(explode("/", $_SERVER['REQUEST_URI']))); $testPath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR; $urlBase = '/'; //once the path equals the WEBROOT_DIR we've found the base. This only works with symlinks if (realpath($testPath) != WEBROOT_DIR) { foreach ($pathParts as $dir) { $test = $testPath . $dir . DIRECTORY_SEPARATOR; if (realpath_exists($test)) { $testPath = $test; $urlBase .= $dir . '/'; if (realpath($test) == WEBROOT_DIR) { break; } } } } } } } define('SITE_NAME', $site); if (PHP_SAPI == 'cli') { define('URL_BASE', null); } else { if (!isset($urlBase)) { throw new KurogoConfigurationException("URL base not set. Please report the configuration to see why this happened"); } define('URL_BASE', $urlBase); Kurogo::log(LOG_DEBUG, "Setting site to {$site} with a base of {$urlBase}", 'kurogo'); // Strips out the leading part of the url for sites where // the base is not located at the document root, ie.. /mobile or /m // Also strips off the leading slash (needed by device debug below) if (isset($path)) { // Strip the URL_BASE off the path $baseLen = strlen(URL_BASE); if ($baseLen && strpos($path, URL_BASE) === 0) { $path = substr($path, $baseLen); } } } // Set up defines relative to SITE_DIR define('SITE_DIR', $siteDir); //already been realpath'd define('SITE_KEY', md5($siteDir)); define('SITE_LIB_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'lib'); define('SITE_APP_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'app'); define('SITE_MODULES_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'modules'); define('DATA_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'data'); define('CACHE_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'cache'); define('LOG_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'logs'); define('SITE_CONFIG_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'config'); //load in the site config file (required); $config = ConfigFile::factory('site', 'site'); $this->addConfig($config); if ($config->getOptionalVar('SITE_DISABLED')) { die("FATAL ERROR: Site disabled"); } // Set up theme define if (!($theme = $this->getVar('ACTIVE_THEME'))) { die("FATAL ERROR: ACTIVE_THEME not set"); } Kurogo::log(LOG_DEBUG, "Setting theme to {$theme}", 'kurogo'); define('THEME_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme); }
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; } }