fix #8131 - chinese translations
[Pman.Core] / Config.php
1 <?php
2
3 // default framework settings for release
4
5 class Pman_Core_Config {
6     
7     
8     var $memory_limit = 0;
9     
10     var $defaults = array(  ); // override... 
11     
12     
13     // note if other extended 'config's require more, then you porbably need to include these first.
14     var $required_extensions = array(
15         'json',        
16         'curl',
17         'gd',
18         'mbstring',
19         'http'
20     );
21     
22     function init($ff, $cfg)
23     {
24         
25         
26         
27         $cfg = $this->overlayDefaults($cfg);
28         
29         if (!empty($this->memory_limit)) {
30             $mem = ini_get('memory_limit');
31             if (php_sapi_name() != 'cli' && $this->to_bytes($mem) < $this->to_bytes($this->memory_limit)) {
32                 trigger_error("increase the memory limit settings to 2048M or more", E_USER_ERROR);
33             }
34         
35         }
36         
37         $this->verifyExtensions();
38         
39         
40         if (!isset($cfg['Pman']['timezone'])) {
41             trigger_error("timezone needs setting in Pman[timezone]", E_USER_ERROR);
42         }
43         if ($cfg['Pman']['timezone'] != ini_get('date.timezone')) {
44             trigger_error("timezone needs setting in php.ini date.timezone = " . $cfg['Pman']['timezone'], E_USER_ERROR);
45         }
46         
47         
48         return $cfg;
49     }
50     
51     function to_bytes($val) {
52         $val = trim($val);
53         $last = strtolower($val[strlen($val)-1]);
54         switch($last) {
55             // The 'G' modifier is available since PHP 5.1.0
56             case 'g':
57                 $val = substr($val, 0, -1);
58                 $val *= 1024;
59             case 'm':
60                 $val = substr($val, 0, -1);
61                 $val *= 1024;
62                 $val = substr($val, 0, -1);
63             case 'k':
64                 $val *= 1024;
65         }
66     
67         return $val;
68     }
69     function overlayDefaults($cfg)
70     {
71         if (isset($this->defaults['disable']) && is_array($this->defaults['disable']) ) {
72             $this->defaults['disable'] = implode(',', $this->defaults['disable']);
73         }
74         foreach($this->defaults as $k=>$v) {
75             if (is_array($v)) {
76                 
77                 if (!isset($cfg[$k])) {
78                     $cfg[$k] = $v;
79                     continue;
80                 }
81                 
82                 foreach($v as $kk=>$vv) {
83                     if (isset($cfg[$k][$kk])) {
84                         continue;
85                     }
86                     
87                     $cfg[$k][$kk] = $vv;
88                 }
89             }
90             
91             if (!isset($cfg[$k])) {
92                 $cfg[$k] = $v;
93             }
94         }
95         
96         return $cfg;
97     }
98     function verifyExtensions()
99     {
100         $error = array();
101         
102         foreach ($this->required_extensions as $e){
103             
104             if(empty($e) || extension_loaded($e)) {
105                 continue;
106             }
107             
108             $error[] = "Error: Please install php extension: {$e}";
109         }
110         
111         if(empty($error)){
112            return true; 
113         }
114         trigger_error("Missing Extensions: \n" . implode('\n', $error), E_USER_ERROR);
115     }
116
117 }