Logo Search packages:      
Sourcecode: nagvis version File versions  Download package

GlobalMainCfg::readConfig ( printErr = 1  )  [inherited]

Reads the config file specified in $this->configFile

Parameters:
Boolean $printErr
Returns:
Boolean Is Successful?
Author:
Lars Michelsen <lars@vertical-visions.de>

Definition at line 320 of file GlobalMainCfg.php.

References GlobalMainCfg::checkMainConfigIsValid(), GlobalMainCfg::checkNagVisConfigExists(), and GlobalMainCfg::checkNagVisConfigReadable().

Referenced by GlobalMainCfg::GlobalMainCfg().

                                       {
            if (DEBUG&&DEBUGLEVEL&1) debug('Start method GlobalMainCfg::readConfig('.$printErr.')');
            $numComments = 0;
            $sec = '';
            
            // Check for config file and read permissions
            if($this->checkNagVisConfigExists($printErr) && $this->checkNagVisConfigReadable($printErr)) {
                  // read thx config file line by line in array $file
                  $file = @file($this->configFile);
                  
                  // loop trough array
                  for ($i = 0; $i < @count($file); $i++) {
                        // cut spaces from beginning and end
                        $line = @trim($file[$i]);
                        
                        // don't read empty lines
                        if(isset($line) && $line != '') {
                              // get first char of actual line
                              $firstChar = @substr($line,0,1);
                              
                              // check what's in this line
                              if($firstChar == ';') {
                                    // comment...
                                    $key = 'comment_'.($numComments++);
                                    $val = @trim($line);
                                    
                                    if(isset($sec) && $sec != '') {
                                          $this->config[$sec][$key] = $val;
                                    } else {
                                          $this->config[$key] = $val;
                                    }
                              } elseif ((@substr($line, 0, 1) == '[') && (@substr($line, -1, 1)) == ']') {
                                    // section
                                    $sec = @strtolower(@trim(@substr($line, 1, @strlen($line)-2)));
                                    
                                    // write to array
                                    if(preg_match('/^backend_/i', $sec)) {
                                          $this->config[$sec] = Array();
                                          $this->config[$sec]['backendid'] = str_replace('backend_','',$sec);
                                    } elseif(preg_match('/^rotation_/i', $sec)) {
                                          $this->config[$sec] = Array();
                                          $this->config[$sec]['rotationid'] = str_replace('rotation_','',$sec);
                                    } else {
                                          $this->config[$sec] = Array();
                                    }
                              } else {
                                    // parameter...
                                    
                                    // seperate string in an array
                                    $arr = @explode('=',$line);
                                    // read key from array and delete it
                                    $key = @strtolower(@trim($arr[0]));
                                    unset($arr[0]);
                                    // build string from rest of array
                                    $val = @trim(@implode('=', $arr));
                                    
                                    // remove " at beginign and at the end of the string
                                    if ((@substr($val,0,1) == '"') && (@substr($val,-1,1)=='"')) {
                                          $val = @substr($val,1,@strlen($val)-2);
                                    }
                                    
                                    // Special options (Arrays)
                                    if($sec == 'wui' && $key == 'allowedforconfig') {
                                          $val = explode(',', str_replace(' ','',$val));
                                    }
                                    
                                    // write in config array
                                    if(isset($sec)) {
                                          $this->config[$sec][$key] = $val;
                                    } else {
                                          $this->config[$key] = $val;
                                    }
                              }
                        } else {
                              $sec = '';
                              $this->config['comment_'.($numComments++)] = '';
                        }
                  }
                  
                  if($this->checkMainConfigIsValid(1)) {
                        if (DEBUG&&DEBUGLEVEL&1) debug('End method GlobalMainCfg::readConfig(): TRUE');
                        return TRUE;
                  } else {
                        if (DEBUG&&DEBUGLEVEL&1) debug('End method GlobalMainCfg::readConfig(): FALSE');
                        return FALSE;
                  }
            } else {
                  if (DEBUG&&DEBUGLEVEL&1) debug('End method GlobalMainCfg::readConfig(): FALSE');
                  return FALSE;
            }
      }


Generated by  Doxygen 1.6.0   Back to index