[5341] | 1 | <?php |
---|
| 2 | |
---|
[6528] | 3 | namespace prototype\api; |
---|
| 4 | |
---|
[5341] | 5 | class Config |
---|
| 6 | { |
---|
[6528] | 7 | static $register; |
---|
| 8 | static $sessionStarted; |
---|
[5341] | 9 | |
---|
[6528] | 10 | static function module($config , $module = false) |
---|
| 11 | { |
---|
| 12 | //Todo: registrar na nova api o currentapp |
---|
| 13 | if(!$module) |
---|
| 14 | $module = $_SESSION['flags']['currentapp']; |
---|
[5399] | 15 | |
---|
[6528] | 16 | if( !isset( $_SESSION['config'][$module] ) || !isset( $_SESSION['config'][$module][$config] )) |
---|
| 17 | $_SESSION['config'][$module] = parse_ini_file( ROOTPATH."/config/$module.ini", true ); |
---|
[5341] | 18 | |
---|
[6528] | 19 | return isset($_SESSION['config'][$module][$config]) ? $_SESSION['config'][$module][$config] : false; |
---|
[5341] | 20 | |
---|
[6528] | 21 | } |
---|
[5341] | 22 | |
---|
[6528] | 23 | static function me($config) |
---|
| 24 | { |
---|
[5399] | 25 | |
---|
[6528] | 26 | return isset($_SESSION['wallet']['user'][$config]) ? $_SESSION['wallet']['user'][$config] : false; |
---|
| 27 | } |
---|
[5399] | 28 | |
---|
[6528] | 29 | static function service( $service , $config ) |
---|
| 30 | { |
---|
| 31 | if( !isset( $_SESSION['wallet'][$service] ) || !isset( $_SESSION['wallet'][$service][$config] )) |
---|
| 32 | $_SESSION['wallet'][$service] = parse_ini_file( ROOTPATH."/config/$service.srv", true ); |
---|
[5415] | 33 | |
---|
[6528] | 34 | return (isset($_SESSION['wallet'][$service][$config])) ? $_SESSION['wallet'][$service][$config] : false; |
---|
| 35 | } |
---|
[5399] | 36 | |
---|
[6528] | 37 | static function get( $concept , $config = false , $module = false ) |
---|
| 38 | { |
---|
| 39 | $load = parse_ini_file( ROOTPATH."/config/$concept.ini", true ); |
---|
[5437] | 40 | |
---|
[6528] | 41 | if($config === false) return $load; |
---|
[5437] | 42 | |
---|
[6528] | 43 | return (isset($load[$config])) ? $load[$config] : false; |
---|
| 44 | } |
---|
[5437] | 45 | |
---|
[6528] | 46 | static function regSet( $name , $value) |
---|
| 47 | { |
---|
| 48 | self::$register[$name] = $value; |
---|
| 49 | } |
---|
| 50 | static function regGet ($name ) |
---|
| 51 | { |
---|
| 52 | return (isset(self::$register[$name]) ? self::$register[$name] : false ); |
---|
| 53 | } |
---|
[5341] | 54 | |
---|
[6528] | 55 | static function init( ) |
---|
| 56 | { |
---|
| 57 | |
---|
| 58 | if( !defined( 'ROOTPATH' ) ) |
---|
| 59 | define( 'ROOTPATH', dirname(__FILE__).'/..' ); |
---|
[5399] | 60 | |
---|
[6528] | 61 | if ( isset( $_COOKIE[ 'sessionid' ] ) ) |
---|
| 62 | { |
---|
| 63 | session_id( $_COOKIE[ 'sessionid' ] ); |
---|
| 64 | $GLOBALS['phpgw']->session->sessionid = $_COOKIE[ 'sessionid' ]; |
---|
| 65 | } |
---|
[5399] | 66 | |
---|
| 67 | if( !self::$sessionStarted ) |
---|
[6528] | 68 | self::$sessionStarted = session_start(); |
---|
[5399] | 69 | |
---|
[6528] | 70 | } |
---|
| 71 | |
---|
| 72 | public static function writeIniFile($assoc_arr, $path, $has_sections) |
---|
| 73 | { |
---|
| 74 | $content = ''; |
---|
| 75 | self::_writeIniFile($content, $assoc_arr, $has_sections); |
---|
| 76 | if( file_put_contents($path, $content) === false) |
---|
| 77 | { |
---|
| 78 | trigger_error("Permission failure when trying to write in the file: $path ", E_USER_WARNING); |
---|
| 79 | return false; |
---|
| 80 | } |
---|
| 81 | return true; |
---|
| 82 | } |
---|
[5399] | 83 | |
---|
[6528] | 84 | private static function _writeIniFile(&$content, $assoc_arr, $has_sections) |
---|
| 85 | { |
---|
| 86 | foreach ($assoc_arr as $key => $val) |
---|
| 87 | { |
---|
| 88 | if (is_array($val)) |
---|
| 89 | { |
---|
| 90 | if($has_sections) |
---|
| 91 | { |
---|
| 92 | $content .= "[$key]\n"; |
---|
| 93 | self::_writeIniFile(&$content, $val, false); |
---|
| 94 | } |
---|
| 95 | else |
---|
| 96 | foreach($val as $iKey => $iVal) |
---|
| 97 | { |
---|
| 98 | if (is_int($iKey)) |
---|
| 99 | $content .= $key ."[] = $iVal\n"; |
---|
| 100 | else |
---|
| 101 | $content .= $key ."[$iKey] = $iVal\n"; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | else |
---|
| 105 | $content .= "$key = $val\n"; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
[5341] | 109 | } |
---|
| 110 | |
---|
[6528] | 111 | Config::init(); |
---|
[5399] | 112 | |
---|
| 113 | |
---|
[5341] | 114 | ?> |
---|