示例#1
0
 public static function factory($id, $type, $options=0) {
     $config = new ModuleConfigFile();
     
     if (!$result = $config->loadFileType($id, $type, $options)) {
         die("FATAL ERROR: cannot load $type configuration file: " . self::getfileByType($id, $type));
     }
 
     return $config;
 }
 public static function factory($id, $type = 'file', $options = 0)
 {
     $config = new ModuleConfigFile();
     if (!($options & self::OPTION_DO_NOT_CREATE)) {
         $options = $options | self::OPTION_CREATE_WITH_DEFAULT;
     }
     if (!($result = $config->loadFileType($id, $type, $options))) {
         if ($options & self::OPTION_DO_NOT_CREATE) {
             return false;
         }
         throw new KurogoConfigurationException("FATAL ERROR: cannot load {$type} configuration file for module {$id}: " . self::getfileByType($id, $type));
     }
     return $config;
 }
示例#3
0
 public static function factory($configModule, $type = 'file', $options = 0)
 {
     $args = func_get_args();
     $module = isset($args[3]) ? $args[3] : null;
     $config = new ModuleConfigFile();
     if ($module) {
         $config->setModule($module);
     }
     if (!($options & self::OPTION_DO_NOT_CREATE)) {
         $options = $options | self::OPTION_CREATE_WITH_DEFAULT;
     }
     if (!($result = $config->loadFileType($configModule, $type, $options))) {
         if ($options & self::OPTION_DO_NOT_CREATE) {
             return false;
         }
         throw new KurogoConfigurationException("FATAL ERROR: cannot load {$type} configuration file for module {$configModule}");
     }
     return $config;
 }
示例#4
0
 public static function appDownloadText($platform)
 {
     if ($config = ModuleConfigFile::factory('download', 'apps')) {
         return $config->getOptionalVar('downloadText', null, $platform);
     }
 }
 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;
     }
 }
示例#6
0
 protected function getAPIConfig($name, $opts = 0)
 {
     $opts = $opts | ConfigFile::OPTION_CREATE_WITH_DEFAULT;
     $config = ModuleConfigFile::factory($this->configModule, "api-{$name}", $opts);
     return $config;
 }
示例#7
0
文件: Module.php 项目: nncsang/Kurogo
 protected function getModuleNavigationConfig()
 {
     static $moduleNavConfig;
     if (!$moduleNavConfig) {
         $moduleNavConfig = ModuleConfigFile::factory($this->getHomeModuleID(), 'module');
     }
     return $moduleNavConfig;
 }
 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;
 }
示例#9
0
 /**
   * Returns a config file
   * @param string $id the module id
   * @param string $type the config file type (module, feeds, pages, etc)
   * @param int $opts bitfield of ConfigFile options
   * @return ConfigFile object
   */
 protected function getConfig($type, $opts=0) {
     if ($config = ModuleConfigFile::factory($this->configModule, $type, $opts)) {
         Kurogo::siteConfig()->addConfig($config);
     }
     return $config;
 }
示例#10
0
 protected function getPageConfig($name, $opts=0) {
   $config = ModuleConfigFile::factory($this->configModule, "page-$name", $opts);
   Kurogo::siteConfig()->addConfig($config);
   return $config;
 }
示例#11
0
 protected function getPageConfig($name, $opts) {
   $config = ModuleConfigFile::factory($this->configModule, "page-$name", $opts);
   $GLOBALS['siteConfig']->addConfig($config);
   return $config;
 }
示例#12
0
 protected function getModuleNavigationConfig()
 {
     static $moduleNavConfig;
     if (!$moduleNavConfig) {
         $moduleNavConfig = ModuleConfigFile::factory('home', 'module');
     }
     return $moduleNavConfig;
 }
    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;
        }
    }
示例#14
0
 /**
   * Returns a config file
   * @param string $id the module id
   * @param string $type the config file type (module, feeds, pages, etc)
   * @param int $opts bitfield of ConfigFile options
   * @return ConfigFile object
   */
 protected function getConfig($id, $type, $opts=0) {
     $opts = $opts | ModuleConfigFile::OPTION_CREATE_WITH_DEFAULT;
     $config = ModuleConfigFile::factory($id, $type, $opts); 
     $GLOBALS['siteConfig']->addConfig($config);
     return $config;
 }