Пример #1
0
 public function removeFromHomeScreen()
 {
     $config = Kurogo::getSiteConfig('navigation', 'site');
     $config->removeSection($this->configModule);
     Kurogo::sharedInstance()->saveConfig($config);
 }
Пример #2
0
 public function themeConfig()
 {
     if (!$this->themeConfig) {
         $this->themeConfig = new ConfigGroup('theme', 'site');
         if ($config = Kurogo::getSiteConfig('theme')) {
             $this->themeConfig->addConfig($config);
         }
         if ($this->configModule) {
             if ($config = Kurogo::getModuleConfig('theme', $this->module, Config::OPTION_DO_NOT_CREATE)) {
                 $this->themeConfig->addConfig($config);
             }
         }
     }
     return $this->themeConfig;
 }
Пример #3
0
 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 'buildNativeWebTemplates':
             $moduleID = $this->getArg('module', '');
             $platform = $this->getArg('platform', '');
             $module = WebModule::factory($moduleID);
             $module->buildNativeWebTemplatesForPlatform($platform);
             $this->setResponse(true);
             $this->setResponseVersion(1);
             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(__LINE__ . ": 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(__LINE__ . ": 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;
                 default:
                     throw new KurogoConfigurationException(__LINE__ . ": Invalid config type {$type}");
             }
             $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(__LINE__ . ": 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(__LINE__ . ": 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(__LINE__ . ": Invalid property {$key} for module {$module}");
                                 }
                                 $this->setConfigVar($module, 'general', $subsection, $key, $value);
                             }
                         }
                         foreach ($this->changedConfigs as $config) {
                             Kurogo::sharedInstance()->saveConfig($config);
                         }
                         $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(__LINE__ . ": 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'], Config::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) {
                 Kurogo::sharedInstance()->saveConfig($config);
             }
             $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 = Kurogo::getSiteConfig($sectionData['config'], 'site');
                     break;
                 case 'module':
                     $moduleID = $this->getArg('module', '');
                     $module = WebModule::factory($moduleID);
                     $sectionData = $this->getAdminData($module, $section);
                     $config = Kurogo::getModuleConfig($sectionData['config'], $moduleID);
                     $subsection = $moduleID;
                     break;
                 default:
                     throw new KurogoConfigurationException(__LINE__ . ": Invalid type {$type}");
             }
             if (!isset($sectionData['sections']) || (!isset($sectionData['sectiondelete']) || !$sectionData['sectiondelete'])) {
                 throw new KurogoConfigurationException(__LINE__ . ": Section '{$section}' does not permit removal of items");
             }
             if (!isset($sectionData['sections'][$key])) {
                 throw new KurogoConfigurationException(__LINE__ . ": Section {$key} not found in config '{$section}' of {$type} {$subsection}");
             }
             Kurogo::log(LOG_NOTICE, "Removing section {$key} from {$type} {$section} {$subsection}", 'admin');
             if (!($result = $config->removeSection($key))) {
                 throw new KurogoException(__LINE__ . ": Error removing item {$key} from config '" . $sectionData['config'] . "'");
             } else {
                 Kurogo::sharedInstance()->saveConfig($config);
             }
             $this->setResponse(true);
             $this->setResponseVersion(1);
             break;
         case 'addNewModule':
             $moduleData = $this->getArg('newModule');
             $module = $this->addNewModule($moduleData);
             $this->setResponseVersion(1);
             $this->setResponse(true);
             break;
         case 'removeModule':
             $moduleID = $this->getArg('configModule');
             try {
                 $module = WebModule::factory($moduleID);
             } catch (KurogoException $e) {
                 throw new KurogoException($this->getLocalizedString('ERROR_MODULE_NOT_FOUND', $moduleID));
             }
             $module->removeModule(true);
             $this->setResponseVersion(1);
             $this->setResponse(true);
             break;
         case 'setmodulelayout':
             Kurogo::log(LOG_NOTICE, "Updating module layout", 'admin');
             $data = $this->getArg('data', array());
             if (!isset($data['primary_modules'])) {
                 $data['primary_modules'] = array();
             }
             if (!isset($data['secondary_modules'])) {
                 $data['secondary_modules'] = array();
             }
             $config = Kurogo::getSiteConfig('navigation', 'site');
             $sections = array();
             foreach ($data['primary_modules'] as $moduleID => $title) {
                 $sections[$moduleID] = array('title' => $title);
             }
             foreach ($data['secondary_modules'] as $moduleID => $title) {
                 $sections[$moduleID] = array('type' => 'secondary', 'title' => $title);
             }
             $config->setSectionVars($sections);
             $result = Kurogo::sharedInstance()->saveConfig($config);
             $this->setResponse($result);
             $this->setResponseVersion(1);
             break;
         default:
             $this->invalidCommand();
             break;
     }
 }