@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @param string $name name of the config-value |
119 | 119 | * @param mixed $value content, empty or null values are not saved, but deleted |
120 | 120 | * @param string $app app-name (depreacted to use default of $this->appname set via the constructor!) |
121 | - * @param boolean $update_cache=true update instance cache and for phpgwapi invalidate session-cache |
|
121 | + * @param boolean $update_cache update instance cache and for phpgwapi invalidate session-cache |
|
122 | 122 | * @throws egw_exception_wrong_parameter if no $app parameter given for static call |
123 | 123 | * @return boolean|int true if no change, else number of affected rows |
124 | 124 | */ |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | /** |
196 | 196 | * sets a single value in the repositry, you need to call save_repository after |
197 | 197 | * |
198 | - * @param $variable_name string name of the config |
|
198 | + * @param string $variable_name string name of the config |
|
199 | 199 | * @param $variable_data mixed the content |
200 | 200 | */ |
201 | 201 | function value($variable_name,$variable_data) |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | * get customfield array of an application |
225 | 225 | * |
226 | 226 | * @param string $app |
227 | - * @param boolean $all_private_too=false should all the private fields be returned too, default no |
|
228 | - * @param string $only_type2=null if given only return fields of type2 == $only_type2 |
|
227 | + * @param boolean $all_private_too should all the private fields be returned too, default no |
|
228 | + * @param string $only_type2 if given only return fields of type2 == $only_type2 |
|
229 | 229 | * @deprecated use egw_customfields::get() |
230 | 230 | * @return array with customfields |
231 | 231 | */ |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | if (is_array($this->config_data)) |
86 | 86 | { |
87 | 87 | self::$db->lock(array(config::TABLE)); |
88 | - foreach($this->config_data as $name => $value) |
|
88 | + foreach ($this->config_data as $name => $value) |
|
89 | 89 | { |
90 | 90 | self::save_value($name, $value, $this->appname, false); |
91 | 91 | } |
92 | - foreach(self::$configs[$this->appname] as $name => $value) |
|
92 | + foreach (self::$configs[$this->appname] as $name => $value) |
|
93 | 93 | { |
94 | 94 | if (!isset($this->config_data[$name])) // has been deleted |
95 | 95 | { |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | } |
100 | 100 | self::$db->unlock(); |
101 | 101 | |
102 | - if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
102 | + if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
103 | 103 | { |
104 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
104 | + $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
105 | 105 | } |
106 | 106 | self::$configs[$this->appname] = $this->config_data; |
107 | 107 | |
@@ -122,14 +122,14 @@ discard block |
||
122 | 122 | * @throws egw_exception_wrong_parameter if no $app parameter given for static call |
123 | 123 | * @return boolean|int true if no change, else number of affected rows |
124 | 124 | */ |
125 | - static function save_value($name, $value, $app, $update_cache=true) |
|
125 | + static function save_value($name, $value, $app, $update_cache = true) |
|
126 | 126 | { |
127 | - if (!$app && (!isset($this) || !is_a($this,__CLASS__))) |
|
127 | + if (!$app && (!isset($this) || !is_a($this, __CLASS__))) |
|
128 | 128 | { |
129 | 129 | throw new egw_exception_wrong_parameter('$app parameter required for static call of config::save_value($name,$value,$app)!'); |
130 | 130 | } |
131 | 131 | //echo "<p>config::save_value('$name','".print_r($value,True)."','$app')</p>\n"; |
132 | - if (!$app || isset($this) && is_a($this,__CLASS__) && $app == $this->appname) |
|
132 | + if (!$app || isset($this) && is_a($this, __CLASS__) && $app == $this->appname) |
|
133 | 133 | { |
134 | 134 | $app = $this->appname; |
135 | 135 | $this->config_data[$name] = $value; |
@@ -141,25 +141,25 @@ discard block |
||
141 | 141 | //echo "<p>config::save_value('$name','".print_r($value,True)."','$app')</p>\n"; |
142 | 142 | if (isset(self::$configs[$app][$name]) && self::$configs[$app][$name] === $value) |
143 | 143 | { |
144 | - return True; // no change ==> exit |
|
144 | + return True; // no change ==> exit |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | if (!isset($value) || $value === '') |
148 | 148 | { |
149 | 149 | if (isset(self::$configs[$app])) unset(self::$configs[$app][$name]); |
150 | - self::$db->delete(config::TABLE,array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
|
150 | + self::$db->delete(config::TABLE, array('config_app'=>$app, 'config_name'=>$name), __LINE__, __FILE__); |
|
151 | 151 | } |
152 | 152 | else |
153 | 153 | { |
154 | 154 | self::$configs[$app][$name] = $value; |
155 | - if(is_array($value)) $value = json_encode($value); |
|
156 | - self::$db->insert(config::TABLE,array('config_value'=>$value),array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
|
155 | + if (is_array($value)) $value = json_encode($value); |
|
156 | + self::$db->insert(config::TABLE, array('config_value'=>$value), array('config_app'=>$app, 'config_name'=>$name), __LINE__, __FILE__); |
|
157 | 157 | } |
158 | 158 | if ($update_cache) |
159 | 159 | { |
160 | - if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
160 | + if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
161 | 161 | { |
162 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
162 | + $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
163 | 163 | } |
164 | 164 | egw_cache::setInstance(__CLASS__, 'configs', self::$configs); |
165 | 165 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | { |
177 | 177 | self::init_static(); |
178 | 178 | } |
179 | - self::$db->delete(config::TABLE,array('config_app' => $this->appname),__LINE__,__FILE__); |
|
179 | + self::$db->delete(config::TABLE, array('config_app' => $this->appname), __LINE__, __FILE__); |
|
180 | 180 | |
181 | 181 | unset(self::$configs[$this->appname]); |
182 | 182 | egw_cache::setInstance(__CLASS__, 'configs', self::$configs); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @param $variable_name string name of the config |
199 | 199 | * @param $variable_data mixed the content |
200 | 200 | */ |
201 | - function value($variable_name,$variable_data) |
|
201 | + function value($variable_name, $variable_data) |
|
202 | 202 | { |
203 | 203 | $this->config_data[$variable_name] = $variable_data; |
204 | 204 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @deprecated use egw_customfields::get() |
230 | 230 | * @return array with customfields |
231 | 231 | */ |
232 | - static function get_customfields($app, $all_private_too=false, $only_type2=null) |
|
232 | + static function get_customfields($app, $all_private_too = false, $only_type2 = null) |
|
233 | 233 | { |
234 | 234 | //error_log(__METHOD__."('$app', $all_private_too, $only_type2) deprecated, use egw_customfields::get() in ". function_backtrace()); |
235 | 235 | return egw_customfields::get($app, $all_private_too, $only_type2); |
@@ -259,12 +259,12 @@ discard block |
||
259 | 259 | { |
260 | 260 | static $white_list = array( |
261 | 261 | 'all' => array('customfields', 'types'), |
262 | - 'phpgwapi' => array('webserver_url','server_timezone','enforce_ssl','system_charset', |
|
263 | - 'checkfornewversion','checkappversions','email_address_format', // admin >> site config |
|
264 | - 'site_title','login_logo_file','login_logo_url','login_logo_title','favicon_file', |
|
265 | - 'markuntranslated','link_list_thumbnail','enabled_spellcheck','debug_minify', |
|
266 | - 'call_link','call_popup', // addressbook |
|
267 | - 'hide_birthdays','egw_tutorial_disable'), // calendar |
|
262 | + 'phpgwapi' => array('webserver_url', 'server_timezone', 'enforce_ssl', 'system_charset', |
|
263 | + 'checkfornewversion', 'checkappversions', 'email_address_format', // admin >> site config |
|
264 | + 'site_title', 'login_logo_file', 'login_logo_url', 'login_logo_title', 'favicon_file', |
|
265 | + 'markuntranslated', 'link_list_thumbnail', 'enabled_spellcheck', 'debug_minify', |
|
266 | + 'call_link', 'call_popup', // addressbook |
|
267 | + 'hide_birthdays', 'egw_tutorial_disable'), // calendar |
|
268 | 268 | 'projectmanager' => array('hours_per_workday', 'duration_units'), |
269 | 269 | 'manual' => array('manual_remote_egw_url'), |
270 | 270 | 'infolog' => array('status'), |
@@ -275,9 +275,9 @@ discard block |
||
275 | 275 | self::init_static(); |
276 | 276 | } |
277 | 277 | $client_config = array(); |
278 | - foreach(self::$configs as $app => $config) |
|
278 | + foreach (self::$configs as $app => $config) |
|
279 | 279 | { |
280 | - foreach($config as $name => $value) |
|
280 | + foreach ($config as $name => $value) |
|
281 | 281 | { |
282 | 282 | if (strpos($name, 'pass') !== false) continue; |
283 | 283 | |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | } |
316 | 316 | // handling of old PHP serialized config values |
317 | 317 | $data = php_safe_unserialize($str); |
318 | - if($data === false) |
|
318 | + if ($data === false) |
|
319 | 319 | { |
320 | 320 | // manually retrieve the string lengths of the serialized array if unserialize failed (iso / utf-8 conversation) |
321 | 321 | $data = php_safe_unserialize(preg_replace_callback('!s:(\d+):"(.*?)";!s', function($matches) |
322 | 322 | { |
323 | - return 's:'.mb_strlen($matches[2],'8bit').':"'.$matches[2].'";'; |
|
323 | + return 's:'.mb_strlen($matches[2], '8bit').':"'.$matches[2].'";'; |
|
324 | 324 | }, $str)); |
325 | 325 | } |
326 | 326 | // returning original string, if unserialize failed, eg. for "a:hello" |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | if (!(self::$configs = egw_cache::getInstance(__CLASS__, 'configs')) || !is_array(self::$configs['phpgwapi'])) |
346 | 346 | { |
347 | 347 | self::$configs = array(); |
348 | - foreach(self::$db->select(config::TABLE,'*',false,__LINE__,__FILE__) as $row) |
|
348 | + foreach (self::$db->select(config::TABLE, '*', false, __LINE__, __FILE__) as $row) |
|
349 | 349 | { |
350 | 350 | self::$configs[$row['config_app']][$row['config_name']] = self::unserialize($row['config_value']); |
351 | 351 | //error_log(__METHOD__."() configs[$row[config_app]][$row[config_name]]=".array2string(self::$configs[$row['config_app']][$row['config_name']])); |
@@ -92,16 +92,23 @@ discard block |
||
92 | 92 | } |
93 | 93 | foreach(self::$configs[$this->appname] as $name => $value) |
94 | 94 | { |
95 | - if (!isset($this->config_data[$name])) // has been deleted |
|
95 | + if (!isset($this->config_data[$name])) |
|
96 | + { |
|
97 | + // has been deleted |
|
96 | 98 | { |
97 | 99 | self::save_value($name, null, $this->appname, false); |
100 | + } |
|
98 | 101 | //self::$db->delete(self::TABLE,array('config_app'=>$this->appname,'config_name'=>$name),__LINE__,__FILE__); |
99 | 102 | } |
100 | 103 | } |
101 | 104 | |
102 | - if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
105 | + if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
106 | + { |
|
107 | + // egw object in setup is limited |
|
103 | 108 | { |
104 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
109 | + $GLOBALS['egw']->invalidate_session_cache(); |
|
110 | + } |
|
111 | + // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
105 | 112 | } |
106 | 113 | self::$configs[$this->appname] = $this->config_data; |
107 | 114 | |
@@ -145,20 +152,30 @@ discard block |
||
145 | 152 | |
146 | 153 | if (!isset($value) || $value === '') |
147 | 154 | { |
148 | - if (isset(self::$configs[$app])) unset(self::$configs[$app][$name]); |
|
155 | + if (isset(self::$configs[$app])) |
|
156 | + { |
|
157 | + unset(self::$configs[$app][$name]); |
|
158 | + } |
|
149 | 159 | self::$db->delete(self::TABLE,array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
150 | 160 | } |
151 | 161 | else |
152 | 162 | { |
153 | 163 | self::$configs[$app][$name] = $value; |
154 | - if(is_array($value)) $value = json_encode($value); |
|
164 | + if(is_array($value)) |
|
165 | + { |
|
166 | + $value = json_encode($value); |
|
167 | + } |
|
155 | 168 | self::$db->insert(self::TABLE,array('config_value'=>$value),array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
156 | 169 | } |
157 | 170 | if ($update_cache) |
158 | 171 | { |
159 | - if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
172 | + if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
173 | + { |
|
174 | + // egw object in setup is limited |
|
160 | 175 | { |
161 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
176 | + $GLOBALS['egw']->invalidate_session_cache(); |
|
177 | + } |
|
178 | + // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
162 | 179 | } |
163 | 180 | Cache::setInstance(__CLASS__, 'configs', self::$configs); |
164 | 181 | } |
@@ -278,7 +295,10 @@ discard block |
||
278 | 295 | { |
279 | 296 | foreach($config as $name => $value) |
280 | 297 | { |
281 | - if (strpos($name, 'pass') !== false) continue; |
|
298 | + if (strpos($name, 'pass') !== false) |
|
299 | + { |
|
300 | + continue; |
|
301 | + } |
|
282 | 302 | |
283 | 303 | if (in_array($name, $white_list['all']) || isset($white_list[$app]) && in_array($name, $white_list[$app])) |
284 | 304 | { |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | * This method was named read in eGW 1.0 and 1.2 |
68 | 68 | * |
69 | 69 | * @deprecated since 1.3 use search() instead |
70 | - * @param int $start=0 starting number of the range, if $limit != 0 |
|
71 | - * @param int $limit=0 max. number of entries to return, 0=all |
|
72 | - * @param array $fields=null fields to return or null for all stock fields, fields are either in the keys or values |
|
70 | + * @param int $start starting number of the range, if $limit != 0 |
|
71 | + * @param int $limit max. number of entries to return, 0=all |
|
72 | + * @param array $fields fields to return or null for all stock fields, fields are either in the keys or values |
|
73 | 73 | * @param string $query='' search pattern or '' for none |
74 | 74 | * @param string $filter='' filters with syntax like <name>=<value>,<name2>=<value2>,<name3>=!'' for not empty |
75 | 75 | * @param string $sort='' sorting: ASC or DESC |
76 | 76 | * @param string $order='' column to order, default ('') n_family,n_given,email ASC |
77 | - * @param int $lastmod=-1 return only values modified after given timestamp, default (-1) return all |
|
77 | + * @param int $lastmod return only values modified after given timestamp, default (-1) return all |
|
78 | 78 | * @param string $cquery='' return only entries starting with given character, default ('') all |
79 | 79 | * @return array of contacts |
80 | 80 | */ |
@@ -182,9 +182,8 @@ discard block |
||
182 | 182 | * @deprecated since 1.3 use save() instead |
183 | 183 | * @param int $owner owner of the entry |
184 | 184 | * @param array $fields contains access, cat_id and tif if their param is null |
185 | - * @param string $access=null 'private' or 'public' |
|
186 | - * @param int $cat_id=null |
|
187 | - * @param string $tid=null 'n' |
|
185 | + * @param string $access 'private' or 'public' |
|
186 | + * @param int $cat_id |
|
188 | 187 | * @return array/boolean contact or false on failure |
189 | 188 | */ |
190 | 189 | function add($owner,$fields,$access=NULL,$cat_id=NULL,$tid=NULL) |
@@ -214,9 +213,8 @@ discard block |
||
214 | 213 | * @param int $id id of the entry |
215 | 214 | * @param int $owner owner of the entry |
216 | 215 | * @param array $fields contains access, cat_id and tif if their param is null |
217 | - * @param string $access=null 'private' or 'public' |
|
218 | - * @param int $cat_id=null |
|
219 | - * @param string $tid=null 'n' |
|
216 | + * @param string $access 'private' or 'public' |
|
217 | + * @param int $cat_id |
|
220 | 218 | * @return array/boolean contact or false on failure |
221 | 219 | */ |
222 | 220 | function update($id,$owner,$fields,$access=NULL,$cat_id=NULL,$tid=NULL) |
@@ -38,13 +38,13 @@ |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | - * reads contacts matched by key and puts all cols in the data array |
|
42 | - * |
|
43 | - * reimplemented from bocontacts to call the old read function, if more then one param |
|
44 | - * |
|
45 | - * @param int/string $contact_id |
|
46 | - * @return array/boolean contact data or false on error |
|
47 | - */ |
|
41 | + * reads contacts matched by key and puts all cols in the data array |
|
42 | + * |
|
43 | + * reimplemented from bocontacts to call the old read function, if more then one param |
|
44 | + * |
|
45 | + * @param int/string $contact_id |
|
46 | + * @return array/boolean contact data or false on error |
|
47 | + */ |
|
48 | 48 | function read($contact_id) |
49 | 49 | { |
50 | 50 | if (func_num_args() > 1) // calling the old / depricated read function |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * constructor calling the constructor of the extended class |
31 | 31 | */ |
32 | - function __construct($contact_app='addressbook') |
|
32 | + function __construct($contact_app = 'addressbook') |
|
33 | 33 | { |
34 | 34 | parent::__construct($contact_app); |
35 | 35 | |
36 | - $this->total_records =& $this->total; |
|
36 | + $this->total_records = & $this->total; |
|
37 | 37 | $this->stock_contact_fields = array_keys($this->contact_fields); |
38 | 38 | } |
39 | 39 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | if (func_num_args() > 1) // calling the old / depricated read function |
51 | 51 | { |
52 | 52 | $args = func_get_args(); |
53 | - return call_user_func_array(array(&$this,'old_read'),$args); |
|
53 | + return call_user_func_array(array(&$this, 'old_read'), $args); |
|
54 | 54 | } |
55 | 55 | return parent::read($contact_id); |
56 | 56 | } |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | * @param string $cquery='' return only entries starting with given character, default ('') all |
79 | 79 | * @return array of contacts |
80 | 80 | */ |
81 | - function old_read($start=0,$limit=0,$fields=null,$query='',$filter='',$sort='',$order='', $lastmod=-1,$cquery='') |
|
81 | + function old_read($start = 0, $limit = 0, $fields = null, $query = '', $filter = '', $sort = '', $order = '', $lastmod = -1, $cquery = '') |
|
82 | 82 | { |
83 | 83 | //error_log("contacts::old_read($start,$limit,".print_r($fields,true).",$query,'$filter','$sort','$order',$lastmod,$cquery)"); |
84 | 84 | //echo "<p>contacts::old_read($start,$limit,".print_r($fields,true).",$query,'$filter','$sort','$order',$lastmod,$cquery)</p>\n"; |
85 | 85 | $sfilter = array(); |
86 | 86 | if ($filter) |
87 | 87 | { |
88 | - foreach(explode(',',$filter) as $expr) |
|
88 | + foreach (explode(',', $filter) as $expr) |
|
89 | 89 | { |
90 | - list($col,$value) = explode('=',$expr); |
|
90 | + list($col, $value) = explode('=', $expr); |
|
91 | 91 | |
92 | 92 | if ($col == 'access') // text field access is renamed to private and using boolean 0/1 |
93 | 93 | { |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | { |
102 | 102 | $sfilter[] = 'contact_modified > '.(int)$lastmod; |
103 | 103 | } |
104 | - static $old2new = array('fn' => 'n_fn','bday' => 'bday'); |
|
104 | + static $old2new = array('fn' => 'n_fn', 'bday' => 'bday'); |
|
105 | 105 | |
106 | 106 | if (is_array($fields)) |
107 | 107 | { |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | $fields = $fields2[0] === true || $fields2[0] === 1 ? array_keys($fields) : $fields2; |
111 | 111 | |
112 | 112 | |
113 | - foreach($old2new as $old => $new) |
|
113 | + foreach ($old2new as $old => $new) |
|
114 | 114 | { |
115 | - if (($key = array_search($old,$fields)) !== false) |
|
115 | + if (($key = array_search($old, $fields)) !== false) |
|
116 | 116 | { |
117 | 117 | $fields[$key] = $new; |
118 | 118 | } |
@@ -120,41 +120,41 @@ discard block |
||
120 | 120 | } |
121 | 121 | elseif (is_string($fields)) |
122 | 122 | { |
123 | - $fields = explode(',',$fields); |
|
123 | + $fields = explode(',', $fields); |
|
124 | 124 | } |
125 | 125 | if (!$order) $order = $fields ? $fields[0] : 'org_name,n_family,n_given'; |
126 | - if ($order && strpos($order,'_') === false) $order = 'contact_'.$order; |
|
126 | + if ($order && strpos($order, '_') === false) $order = 'contact_'.$order; |
|
127 | 127 | |
128 | 128 | //echo '<p>contacts::search('.($cquery ? $cquery.'*' : $query).','.print_r($fields,true).",'$order $sort','','".($cquery ? '' : '%')."',false,'OR',".(!$limit ? 'false' : "array($start,$limit)").",".print_r($sfilter,true).");</p>\n"; |
129 | - $rows =& $this->search($cquery ? $cquery.'*' : $query,$fields,$order.($sort ? ' '.$sort : ''),'', |
|
130 | - $cquery ? '' : '%',false,'OR',!$limit ? false : array((int)$start,(int)$limit),$sfilter); |
|
129 | + $rows = & $this->search($cquery ? $cquery.'*' : $query, $fields, $order.($sort ? ' '.$sort : ''), '', |
|
130 | + $cquery ? '' : '%', false, 'OR', !$limit ? false : array((int)$start, (int)$limit), $sfilter); |
|
131 | 131 | |
132 | 132 | // return the old birthday format |
133 | - if ($rows && (is_null($fields) || array_intersect($old2new,$fields))) |
|
133 | + if ($rows && (is_null($fields) || array_intersect($old2new, $fields))) |
|
134 | 134 | { |
135 | - foreach($rows as $n => $row) |
|
135 | + foreach ($rows as $n => $row) |
|
136 | 136 | { |
137 | - foreach($old2new as $old => $new) |
|
137 | + foreach ($old2new as $old => $new) |
|
138 | 138 | { |
139 | 139 | if (isset($row[$new])) $rows[$n][$old] = $row[$new]; |
140 | 140 | |
141 | 141 | if (isset($row['bday']) || isset($row['contact_bday'])) |
142 | 142 | { |
143 | - $bdayset=true; |
|
144 | - if (isset($row['bday']) && ($row['bday']=='0000-00-00 0' || $row['bday']=='0000-00-00' || $row['bday']=='0.0.00')) |
|
143 | + $bdayset = true; |
|
144 | + if (isset($row['bday']) && ($row['bday'] == '0000-00-00 0' || $row['bday'] == '0000-00-00' || $row['bday'] == '0.0.00')) |
|
145 | 145 | { |
146 | - $rows[$n]['bday'] = $row['bday']=null; |
|
147 | - $bdayset=false; |
|
146 | + $rows[$n]['bday'] = $row['bday'] = null; |
|
147 | + $bdayset = false; |
|
148 | 148 | } |
149 | - if (isset($row['contact_bday']) && ($row['contact_bday']=='0000-00-00 0' || $row['contact_bday']=='0000-00-00' || $row['contact_bday']=='0.0.00')) |
|
149 | + if (isset($row['contact_bday']) && ($row['contact_bday'] == '0000-00-00 0' || $row['contact_bday'] == '0000-00-00' || $row['contact_bday'] == '0.0.00')) |
|
150 | 150 | { |
151 | - $rows[$n]['contact_bday'] = $row['contact_bday']=null; |
|
152 | - $bdayset=false; |
|
151 | + $rows[$n]['contact_bday'] = $row['contact_bday'] = null; |
|
152 | + $bdayset = false; |
|
153 | 153 | } |
154 | - if ($bdayset==false) continue; // dont try to make a date out of that |
|
155 | - $row['bday'] = egw_time::to((isset($row['bday'])?$row['bday']:$row['contact_bday']),"Y-m-d"); |
|
156 | - list($y,$m,$d) = explode('-',$row['bday']); |
|
157 | - $rows[$n]['bday'] = sprintf('%d/%d/%04d',$m,$d,$y); |
|
154 | + if ($bdayset == false) continue; // dont try to make a date out of that |
|
155 | + $row['bday'] = egw_time::to((isset($row['bday']) ? $row['bday'] : $row['contact_bday']), "Y-m-d"); |
|
156 | + list($y, $m, $d) = explode('-', $row['bday']); |
|
157 | + $rows[$n]['bday'] = sprintf('%d/%d/%04d', $m, $d, $y); |
|
158 | 158 | |
159 | 159 | } |
160 | 160 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @param string $fields='' we always return all fields now |
172 | 172 | * @return array/boolean contact or false on failure |
173 | 173 | */ |
174 | - function read_single_entry($id,$fields='') |
|
174 | + function read_single_entry($id, $fields = '') |
|
175 | 175 | { |
176 | 176 | return $this->read($id); |
177 | 177 | } |
@@ -187,22 +187,22 @@ discard block |
||
187 | 187 | * @param string $tid=null 'n' |
188 | 188 | * @return array/boolean contact or false on failure |
189 | 189 | */ |
190 | - function add($owner,$fields,$access=NULL,$cat_id=NULL,$tid=NULL) |
|
190 | + function add($owner, $fields, $access = NULL, $cat_id = NULL, $tid = NULL) |
|
191 | 191 | { |
192 | 192 | // access, cat_id and tid can be in $fields now or as extra params |
193 | - foreach(array('access','cat_id','tid') as $extra) |
|
193 | + foreach (array('access', 'cat_id', 'tid') as $extra) |
|
194 | 194 | { |
195 | 195 | if (!is_null($$extra)) |
196 | 196 | { |
197 | 197 | $fields[$extra] = $$extra; |
198 | 198 | } |
199 | 199 | } |
200 | - if(empty($fields['tid'])) |
|
200 | + if (empty($fields['tid'])) |
|
201 | 201 | { |
202 | 202 | $fields['tid'] = 'n'; |
203 | 203 | } |
204 | - $fields['private'] = (int) $fields['access'] == 'private'; |
|
205 | - unset($fields['id']); // in case it's set |
|
204 | + $fields['private'] = (int)$fields['access'] == 'private'; |
|
205 | + unset($fields['id']); // in case it's set |
|
206 | 206 | |
207 | 207 | return !$this->save($fields) ? $fields['id'] : false; |
208 | 208 | } |
@@ -219,21 +219,21 @@ discard block |
||
219 | 219 | * @param string $tid=null 'n' |
220 | 220 | * @return array/boolean contact or false on failure |
221 | 221 | */ |
222 | - function update($id,$owner,$fields,$access=NULL,$cat_id=NULL,$tid=NULL) |
|
222 | + function update($id, $owner, $fields, $access = NULL, $cat_id = NULL, $tid = NULL) |
|
223 | 223 | { |
224 | 224 | // access, cat_id and tid can be in $fields now or as extra params |
225 | - foreach(array('access','cat_id','tid') as $extra) |
|
225 | + foreach (array('access', 'cat_id', 'tid') as $extra) |
|
226 | 226 | { |
227 | 227 | if (!is_null($$extra)) |
228 | 228 | { |
229 | 229 | $fields[$extra] = $$extra; |
230 | 230 | } |
231 | 231 | } |
232 | - if(empty($fields['tid'])) |
|
232 | + if (empty($fields['tid'])) |
|
233 | 233 | { |
234 | 234 | $fields['tid'] = 'n'; |
235 | 235 | } |
236 | - $fields['private'] = (int) $fields['access'] == 'private'; |
|
236 | + $fields['private'] = (int)$fields['access'] == 'private'; |
|
237 | 237 | $fields['id'] = $id; |
238 | 238 | |
239 | 239 | return $id && !$this->save($fields); |
@@ -47,9 +47,12 @@ discard block |
||
47 | 47 | */ |
48 | 48 | function read($contact_id) |
49 | 49 | { |
50 | - if (func_num_args() > 1) // calling the old / depricated read function |
|
50 | + if (func_num_args() > 1) |
|
51 | + { |
|
52 | + // calling the old / depricated read function |
|
51 | 53 | { |
52 | 54 | $args = func_get_args(); |
55 | + } |
|
53 | 56 | return call_user_func_array(array(&$this,'old_read'),$args); |
54 | 57 | } |
55 | 58 | return parent::read($contact_id); |
@@ -89,9 +92,12 @@ discard block |
||
89 | 92 | { |
90 | 93 | list($col,$value) = explode('=',$expr); |
91 | 94 | |
92 | - if ($col == 'access') // text field access is renamed to private and using boolean 0/1 |
|
95 | + if ($col == 'access') |
|
96 | + { |
|
97 | + // text field access is renamed to private and using boolean 0/1 |
|
93 | 98 | { |
94 | 99 | $col = 'private'; |
100 | + } |
|
95 | 101 | $value = $value == 'private'; |
96 | 102 | } |
97 | 103 | $sfilter[$col] = $value; |
@@ -122,8 +128,14 @@ discard block |
||
122 | 128 | { |
123 | 129 | $fields = explode(',',$fields); |
124 | 130 | } |
125 | - if (!$order) $order = $fields ? $fields[0] : 'org_name,n_family,n_given'; |
|
126 | - if ($order && strpos($order,'_') === false) $order = 'contact_'.$order; |
|
131 | + if (!$order) |
|
132 | + { |
|
133 | + $order = $fields ? $fields[0] : 'org_name,n_family,n_given'; |
|
134 | + } |
|
135 | + if ($order && strpos($order,'_') === false) |
|
136 | + { |
|
137 | + $order = 'contact_'.$order; |
|
138 | + } |
|
127 | 139 | |
128 | 140 | //echo '<p>contacts::search('.($cquery ? $cquery.'*' : $query).','.print_r($fields,true).",'$order $sort','','".($cquery ? '' : '%')."',false,'OR',".(!$limit ? 'false' : "array($start,$limit)").",".print_r($sfilter,true).");</p>\n"; |
129 | 141 | $rows =& $this->search($cquery ? $cquery.'*' : $query,$fields,$order.($sort ? ' '.$sort : ''),'', |
@@ -136,7 +148,10 @@ discard block |
||
136 | 148 | { |
137 | 149 | foreach($old2new as $old => $new) |
138 | 150 | { |
139 | - if (isset($row[$new])) $rows[$n][$old] = $row[$new]; |
|
151 | + if (isset($row[$new])) |
|
152 | + { |
|
153 | + $rows[$n][$old] = $row[$new]; |
|
154 | + } |
|
140 | 155 | |
141 | 156 | if (isset($row['bday']) || isset($row['contact_bday'])) |
142 | 157 | { |
@@ -151,7 +166,11 @@ discard block |
||
151 | 166 | $rows[$n]['contact_bday'] = $row['contact_bday']=null; |
152 | 167 | $bdayset=false; |
153 | 168 | } |
154 | - if ($bdayset==false) continue; // dont try to make a date out of that |
|
169 | + if ($bdayset==false) |
|
170 | + { |
|
171 | + continue; |
|
172 | + } |
|
173 | + // dont try to make a date out of that |
|
155 | 174 | $row['bday'] = egw_time::to((isset($row['bday'])?$row['bday']:$row['contact_bday']),"Y-m-d"); |
156 | 175 | list($y,$m,$d) = explode('-',$row['bday']); |
157 | 176 | $rows[$n]['bday'] = sprintf('%d/%d/%04d',$m,$d,$y); |
@@ -350,8 +350,6 @@ discard block |
||
350 | 350 | * Selectbox for country-selection |
351 | 351 | * |
352 | 352 | * @deprecated use html::select with country_array |
353 | - * @param string $selected 2-letter iso country-code |
|
354 | - * @param string $name='country' |
|
355 | 353 | * @return string |
356 | 354 | */ |
357 | 355 | function form_select($code,$name='country') |
@@ -362,8 +360,7 @@ discard block |
||
362 | 360 | /** |
363 | 361 | * Get country-name from the 2-letter iso code |
364 | 362 | * |
365 | - * @param string $selected 2-letter iso country-code |
|
366 | - * @param boolean $translated=true use translated name or english |
|
363 | + * @param boolean $translated use translated name or english |
|
367 | 364 | * @return string |
368 | 365 | */ |
369 | 366 | function get_full_name($code,$translated=true) |
@@ -424,7 +421,7 @@ discard block |
||
424 | 421 | /** |
425 | 422 | * Get list of country names |
426 | 423 | * |
427 | - * @param boolean $translated=true use translated names or english |
|
424 | + * @param boolean $translated use translated names or english |
|
428 | 425 | * @return array with 2-letter code => name pairs |
429 | 426 | */ |
430 | 427 | function countries($translated=true) |
@@ -354,9 +354,9 @@ discard block |
||
354 | 354 | * @param string $name='country' |
355 | 355 | * @return string |
356 | 356 | */ |
357 | - function form_select($code,$name='country') |
|
357 | + function form_select($code, $name = 'country') |
|
358 | 358 | { |
359 | - return html::select($name,strtoupper($code),$this->country_array); |
|
359 | + return html::select($name, strtoupper($code), $this->country_array); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @param boolean $translated=true use translated name or english |
367 | 367 | * @return string |
368 | 368 | */ |
369 | - function get_full_name($code,$translated=true) |
|
369 | + function get_full_name($code, $translated = true) |
|
370 | 370 | { |
371 | 371 | if ($translated) |
372 | 372 | { |
@@ -385,36 +385,36 @@ discard block |
||
385 | 385 | */ |
386 | 386 | function country_code($name) |
387 | 387 | { |
388 | - if (!$name) return ''; // nothing to do |
|
388 | + if (!$name) return ''; // nothing to do |
|
389 | 389 | |
390 | 390 | if (strlen($name) == 2 && isset($this->country_array[$name])) |
391 | 391 | { |
392 | - return $name; // $name is already a country-code |
|
392 | + return $name; // $name is already a country-code |
|
393 | 393 | } |
394 | 394 | |
395 | - if (($code = array_search(strtoupper($name),$this->country_array)) !== false) |
|
395 | + if (($code = array_search(strtoupper($name), $this->country_array)) !== false) |
|
396 | 396 | { |
397 | 397 | return $code; |
398 | 398 | } |
399 | 399 | if (!$this->countries_translated) $this->_translate_countries(); |
400 | 400 | |
401 | - if (($code = array_search(strtoupper($name),$this->countries_translated)) !== false || |
|
402 | - ($code = array_search($name,$this->countries_translated)) !== false) |
|
401 | + if (($code = array_search(strtoupper($name), $this->countries_translated)) !== false || |
|
402 | + ($code = array_search($name, $this->countries_translated)) !== false) |
|
403 | 403 | { |
404 | 404 | return $code; |
405 | 405 | } |
406 | 406 | // search case-insensitive all translations for the english phrase of given country $name |
407 | 407 | // we do that to catch all possible cases of translations |
408 | - static $en_names = array(); // we do some caching to minimize db-accesses |
|
408 | + static $en_names = array(); // we do some caching to minimize db-accesses |
|
409 | 409 | if (isset($en_names[$name])) |
410 | 410 | { |
411 | 411 | $name = $en_names[$name]; |
412 | 412 | } |
413 | - elseif (($name_en = $GLOBALS['egw']->translation->get_message_id($name,'common'))) |
|
413 | + elseif (($name_en = $GLOBALS['egw']->translation->get_message_id($name, 'common'))) |
|
414 | 414 | { |
415 | 415 | $name = $en_names[$name] = strtoupper($name_en); |
416 | 416 | } |
417 | - if (($code = array_search(strtoupper($name),$this->country_array)) !== false) |
|
417 | + if (($code = array_search(strtoupper($name), $this->country_array)) !== false) |
|
418 | 418 | { |
419 | 419 | return $code; |
420 | 420 | } |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | * @param boolean $translated=true use translated names or english |
428 | 428 | * @return array with 2-letter code => name pairs |
429 | 429 | */ |
430 | - function countries($translated=true) |
|
430 | + function countries($translated = true) |
|
431 | 431 | { |
432 | 432 | if ($translated) |
433 | 433 | { |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | |
450 | 450 | $this->countries_translated = $this->country_array; |
451 | 451 | // try to translate them and sort alphabetic |
452 | - foreach($this->countries_translated as $k => $name) |
|
452 | + foreach ($this->countries_translated as $k => $name) |
|
453 | 453 | { |
454 | 454 | if (($translated = lang($name)) != $name.'*') |
455 | 455 | { |
@@ -370,7 +370,10 @@ discard block |
||
370 | 370 | { |
371 | 371 | if ($translated) |
372 | 372 | { |
373 | - if (!$this->countries_translated) $this->_translate_countries(); |
|
373 | + if (!$this->countries_translated) |
|
374 | + { |
|
375 | + $this->_translate_countries(); |
|
376 | + } |
|
374 | 377 | |
375 | 378 | return $this->countries_translated[strtoupper($code)]; |
376 | 379 | } |
@@ -385,7 +388,11 @@ discard block |
||
385 | 388 | */ |
386 | 389 | function country_code($name) |
387 | 390 | { |
388 | - if (!$name) return ''; // nothing to do |
|
391 | + if (!$name) |
|
392 | + { |
|
393 | + return ''; |
|
394 | + } |
|
395 | + // nothing to do |
|
389 | 396 | |
390 | 397 | if (strlen($name) == 2 && isset($this->country_array[$name])) |
391 | 398 | { |
@@ -396,7 +403,10 @@ discard block |
||
396 | 403 | { |
397 | 404 | return $code; |
398 | 405 | } |
399 | - if (!$this->countries_translated) $this->_translate_countries(); |
|
406 | + if (!$this->countries_translated) |
|
407 | + { |
|
408 | + $this->_translate_countries(); |
|
409 | + } |
|
400 | 410 | |
401 | 411 | if (($code = array_search(strtoupper($name),$this->countries_translated)) !== false || |
402 | 412 | ($code = array_search($name,$this->countries_translated)) !== false) |
@@ -445,7 +455,10 @@ discard block |
||
445 | 455 | */ |
446 | 456 | function _translate_countries() |
447 | 457 | { |
448 | - if ($this->countries_translated) return; |
|
458 | + if ($this->countries_translated) |
|
459 | + { |
|
460 | + return; |
|
461 | + } |
|
449 | 462 | |
450 | 463 | $this->countries_translated = $this->country_array; |
451 | 464 | // try to translate them and sort alphabetic |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | * Restore data from a (compressed) csv file |
497 | 497 | * |
498 | 498 | * @param resource $f file opened with fopen for reading |
499 | - * @param int|string $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert |
|
499 | + * @param integer $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert |
|
500 | 500 | * @returns int number of rows read from csv file |
501 | 501 | */ |
502 | 502 | function db_restore($f, $insert_n_rows=10) |
@@ -1044,7 +1044,7 @@ discard block |
||
1044 | 1044 | /** |
1045 | 1045 | * Backup all schemas in the form of a setup/tables_current.inc.php file |
1046 | 1046 | * |
1047 | - * @param resource|boolean $f |
|
1047 | + * @param resource $f |
|
1048 | 1048 | */ |
1049 | 1049 | function schema_backup($f=False) |
1050 | 1050 | { |
@@ -1089,6 +1089,7 @@ discard block |
||
1089 | 1089 | * Dump an array as php source |
1090 | 1090 | * |
1091 | 1091 | * copied from etemplate/inc/class.db_tools.inc.php |
1092 | + * @param integer $depth |
|
1092 | 1093 | */ |
1093 | 1094 | private static function write_array($arr,$depth,$parent='') |
1094 | 1095 | { |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | $zip = NULL; |
382 | 382 | $_f = NULL; |
383 | 383 | if($type == 'zip') |
384 | - { |
|
384 | + { |
|
385 | 385 | // has already been verified to be available in fopen_backup |
386 | 386 | $zip = new ZipArchive; |
387 | 387 | if(($zip->open($filename)) !== TRUE) |
@@ -719,9 +719,9 @@ discard block |
||
719 | 719 | while($file = $list[0]) |
720 | 720 | { |
721 | 721 | if(is_dir($file) && $file != '.' && $file != '..') |
722 | - self::remove_dir_content($dir.'/'.$file); |
|
722 | + self::remove_dir_content($dir.'/'.$file); |
|
723 | 723 | if(is_file($file) && $file != '.' && $file != '..') |
724 | - unlink($dir.'/'.$file); |
|
724 | + unlink($dir.'/'.$file); |
|
725 | 725 | array_shift($list); |
726 | 726 | } |
727 | 727 | //rmdir($dir); // dont remove own dir |
@@ -967,8 +967,8 @@ discard block |
||
967 | 967 | echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>'; |
968 | 968 | } |
969 | 969 | |
970 | - fclose($f); |
|
971 | - if (file_exists($name)) unlink($name); |
|
970 | + fclose($f); |
|
971 | + if (file_exists($name)) unlink($name); |
|
972 | 972 | return TRUE; |
973 | 973 | } |
974 | 974 | // save files .... |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * @var array |
47 | 47 | */ |
48 | 48 | var $exclude_tables = array( |
49 | - 'egw_sessions','egw_app_sessions','phpgw_sessions','phpgw_app_sessions', // eGW's session-tables |
|
50 | - 'phpgw_anglemail', // email's cache |
|
51 | - 'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus', // felamimail's cache |
|
49 | + 'egw_sessions', 'egw_app_sessions', 'phpgw_sessions', 'phpgw_app_sessions', // eGW's session-tables |
|
50 | + 'phpgw_anglemail', // email's cache |
|
51 | + 'egw_felamimail_cache', 'egw_felamimail_folderstatus', 'phpgw_felamimail_cache', 'phpgw_felamimail_folderstatus', // felamimail's cache |
|
52 | 52 | 'egw_phpfreechat', // as of the fieldnames of the table a restore would fail within egroupware, and chatcontent is of no particular intrest |
53 | 53 | ); |
54 | 54 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @var boolean |
82 | 82 | */ |
83 | - var $backup_files = false ; |
|
83 | + var $backup_files = false; |
|
84 | 84 | /** |
85 | 85 | * Reference to schema_proc's egw_db object |
86 | 86 | * |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | { |
96 | 96 | if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']) && !isset($GLOBALS['egw_setup']->db)) |
97 | 97 | { |
98 | - $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
|
98 | + $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
|
99 | 99 | } |
100 | 100 | if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc)) // schema_proc already instanciated, use it |
101 | 101 | { |
@@ -113,37 +113,37 @@ discard block |
||
113 | 113 | { |
114 | 114 | if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table))) |
115 | 115 | { |
116 | - $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'",__LINE__,__FILE__); |
|
116 | + $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'", __LINE__, __FILE__); |
|
117 | 117 | $this->db->next_record(); |
118 | 118 | if (!($this->backup_dir = $this->db->f(0))) |
119 | 119 | { |
120 | - $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'",__LINE__,__FILE__); |
|
120 | + $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'", __LINE__, __FILE__); |
|
121 | 121 | $this->db->next_record(); |
122 | 122 | $this->backup_dir = $this->db->f(0).'/db_backup'; |
123 | 123 | } |
124 | - $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'",__LINE__,__FILE__); |
|
124 | + $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'", __LINE__, __FILE__); |
|
125 | 125 | $this->db->next_record(); |
126 | 126 | if (!($this->files_dir = $this->db->f(0))) |
127 | 127 | { |
128 | 128 | error_log(__METHOD__."->"."No files Directory set/found"); |
129 | 129 | } |
130 | - $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='system_charset'",__LINE__,__FILE__); |
|
130 | + $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='system_charset'", __LINE__, __FILE__); |
|
131 | 131 | $this->db->next_record(); |
132 | 132 | $this->charset = $this->db->f(0); |
133 | 133 | if (!$this->charset) |
134 | 134 | { |
135 | - $this->db->query("SELECT content FROM {$GLOBALS['egw_setup']->lang_table} WHERE message_id='charset' AND app_name='common' AND lang!='en'",__LINE__,__FILE__); |
|
135 | + $this->db->query("SELECT content FROM {$GLOBALS['egw_setup']->lang_table} WHERE message_id='charset' AND app_name='common' AND lang!='en'", __LINE__, __FILE__); |
|
136 | 136 | $this->db->next_record(); |
137 | 137 | $this->charset = $this->db->f(0); |
138 | 138 | } |
139 | - $this->db->select($GLOBALS['egw_setup']->applications_table,'app_version',array('app_name'=>'phpgwapi'),__LINE__,__FILE__); |
|
139 | + $this->db->select($GLOBALS['egw_setup']->applications_table, 'app_version', array('app_name'=>'phpgwapi'), __LINE__, __FILE__); |
|
140 | 140 | $this->api_version = $this->db->next_record() ? $this->db->f(0) : false; |
141 | 141 | /* Backup settings */ |
142 | - $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_mincount'",__LINE__,__FILE__); |
|
142 | + $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_mincount'", __LINE__, __FILE__); |
|
143 | 143 | $this->db->next_record(); |
144 | 144 | $this->backup_mincount = $this->db->f(0); |
145 | 145 | // backup files too |
146 | - $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'",__LINE__,__FILE__); |
|
146 | + $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'", __LINE__, __FILE__); |
|
147 | 147 | $this->db->next_record(); |
148 | 148 | $this->backup_files = (bool)$this->db->f(0); |
149 | 149 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | { |
178 | 178 | mkdir($this->backup_dir); |
179 | 179 | } |
180 | - switch($this->db->Type) |
|
180 | + switch ($this->db->Type) |
|
181 | 181 | { |
182 | 182 | case 'sapdb': |
183 | 183 | case 'maxdb': |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * @param $reading =false opening for reading ('rb') or writing ('wb') |
195 | 195 | * @return string/resource/zip error-msg of file-handle |
196 | 196 | */ |
197 | - function fopen_backup($name=false,$reading=false) |
|
197 | + function fopen_backup($name = false, $reading = false) |
|
198 | 198 | { |
199 | 199 | //echo "function fopen_backup($name,$reading)<br>"; // ! |
200 | 200 | if (!$name) |
@@ -203,27 +203,27 @@ discard block |
||
203 | 203 | if (!$this->backup_dir || !is_writable($this->backup_dir)) |
204 | 204 | { |
205 | 205 | //echo ' -> !$this->backup_dir || !is_writable($this->backup_dir)<br>'; // ! |
206 | - return lang("backupdir '%1' is not writeable by the webserver",$this->backup_dir); |
|
206 | + return lang("backupdir '%1' is not writeable by the webserver", $this->backup_dir); |
|
207 | 207 | } |
208 | 208 | $name = $this->backup_dir.'/db_backup-'.date('YmdHi'); |
209 | 209 | } |
210 | 210 | else // remove the extension, to use the correct wrapper based on the extension |
211 | 211 | { |
212 | 212 | //echo '-> else<br>'; // ! |
213 | - $name = preg_replace('/\.(bz2|gz)$/i','',$name); |
|
213 | + $name = preg_replace('/\.(bz2|gz)$/i', '', $name); |
|
214 | 214 | } |
215 | 215 | $mode = $reading ? 'rb' : 'wb'; |
216 | - list( , $type) = explode('.', basename($name)); |
|
217 | - if($type == 'zip' && $reading && $this->backup_files) |
|
216 | + list(, $type) = explode('.', basename($name)); |
|
217 | + if ($type == 'zip' && $reading && $this->backup_files) |
|
218 | 218 | { |
219 | 219 | //echo '-> $type == "zip" && $reading<br>'; // ! |
220 | - if(!class_exists('ZipArchive', false)) |
|
220 | + if (!class_exists('ZipArchive', false)) |
|
221 | 221 | { |
222 | 222 | $this->backup_files = false; |
223 | 223 | //echo ' -> (new ZipArchive) == NULL<br>'; // ! |
224 | 224 | return lang("Cant open %1, needs ZipArchive", $name)."<br>\n"; |
225 | 225 | } |
226 | - if(!($f = fopen($name, $mode))) |
|
226 | + if (!($f = fopen($name, $mode))) |
|
227 | 227 | { |
228 | 228 | //echo ' -> !($f = fopen($name, $mode))<br>'; // ! |
229 | 229 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
@@ -231,10 +231,10 @@ discard block |
||
231 | 231 | } |
232 | 232 | return $f; |
233 | 233 | } |
234 | - if(class_exists('ZipArchive', false) && !$reading && $this->backup_files) |
|
234 | + if (class_exists('ZipArchive', false) && !$reading && $this->backup_files) |
|
235 | 235 | { |
236 | 236 | //echo '-> (new ZipArchive) != NULL && !$reading; '.$name.'<br>'; // ! |
237 | - if(!($f = fopen($name, $mode))) |
|
237 | + if (!($f = fopen($name, $mode))) |
|
238 | 238 | { |
239 | 239 | //echo ' -> !($f = fopen($name, $mode))<br>'; // ! |
240 | 240 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | } |
243 | 243 | return $f; |
244 | 244 | } |
245 | - if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
|
246 | - !($f = fopen("compress.zlib://$name.gz",$mode)) && |
|
247 | - !($f = fopen($name,$mode)) |
|
245 | + if (!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
|
246 | + !($f = fopen("compress.zlib://$name.gz", $mode)) && |
|
247 | + !($f = fopen($name, $mode)) |
|
248 | 248 | ) |
249 | 249 | { |
250 | 250 | //echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>'; // ! |
@@ -271,13 +271,13 @@ discard block |
||
271 | 271 | /* Search the backup directory for matching files. */ |
272 | 272 | $handle = @opendir($this->backup_dir); |
273 | 273 | $files = array(); |
274 | - while($handle && ($file = readdir($handle))) |
|
274 | + while ($handle && ($file = readdir($handle))) |
|
275 | 275 | { |
276 | 276 | /* Filter for only the files with the regular name (un-renamed). |
277 | 277 | * Leave special backup files (renamed) in place. |
278 | 278 | * Note that this also excludes "." and "..". |
279 | 279 | */ |
280 | - if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/",$file)) |
|
280 | + if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/", $file)) |
|
281 | 281 | { |
282 | 282 | $files[filectime($this->backup_dir.'/'.$file)] = $file; |
283 | 283 | } |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | /* Sort the files by ctime. */ |
288 | 288 | krsort($files); |
289 | 289 | $count = 0; |
290 | - foreach($files as $file) |
|
290 | + foreach ($files as $file) |
|
291 | 291 | { |
292 | 292 | if ($count >= $this->backup_mincount)// |
293 | 293 | { |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | array_push($files_return, $file); |
298 | 298 | } |
299 | 299 | } |
300 | - $count ++; |
|
300 | + $count++; |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
@@ -307,13 +307,13 @@ discard block |
||
307 | 307 | * @param int $minCount Minimum number of backups to keep. |
308 | 308 | * @param boolean $backupFiles include files in backup or not, default dont change! |
309 | 309 | */ |
310 | - function saveConfig($minCount,$backupFiles=null) |
|
310 | + function saveConfig($minCount, $backupFiles = null) |
|
311 | 311 | { |
312 | - config::save_value('backup_mincount',$this->backup_mincount=(int)$minCount,'phpgwapi'); |
|
312 | + config::save_value('backup_mincount', $this->backup_mincount = (int)$minCount, 'phpgwapi'); |
|
313 | 313 | |
314 | 314 | if (!is_null($backupFiles)) |
315 | 315 | { |
316 | - config::save_value('backup_files',$this->backup_files=(boolean)$backupFiles,'phpgwapi'); |
|
316 | + config::save_value('backup_files', $this->backup_files = (boolean)$backupFiles, 'phpgwapi'); |
|
317 | 317 | } |
318 | 318 | } |
319 | 319 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | 'httpproxy_server_password', |
337 | 337 | 'system_charset', |
338 | 338 | 'usecookies', |
339 | - 'install_id', // do not restore install_id, as that would give two systems with identical install_id |
|
339 | + 'install_id', // do not restore install_id, as that would give two systems with identical install_id |
|
340 | 340 | ); |
341 | 341 | |
342 | 342 | /** |
@@ -350,38 +350,38 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @returns An empty string or an error message in case of failure. |
352 | 352 | */ |
353 | - function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true, $insert_n_rows=10) |
|
353 | + function restore($f, $convert_to_system_charset = true, $filename = '', $protect_system_config = true, $insert_n_rows = 10) |
|
354 | 354 | { |
355 | 355 | @set_time_limit(0); |
356 | - ini_set('auto_detect_line_endings',true); |
|
356 | + ini_set('auto_detect_line_endings', true); |
|
357 | 357 | |
358 | - if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
358 | + if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
359 | 359 | |
360 | 360 | if ($protect_system_config) |
361 | 361 | { |
362 | 362 | $system_config = array(); |
363 | - foreach($this->db->select(self::TABLE,'*',array( |
|
363 | + foreach ($this->db->select(self::TABLE, '*', array( |
|
364 | 364 | 'config_app' => 'phpgwapi', |
365 | 365 | 'config_name' => self::$system_config, |
366 | - ),__LINE__,__FILE__) as $row) |
|
366 | + ), __LINE__, __FILE__) as $row) |
|
367 | 367 | { |
368 | 368 | $system_config[] = $row; |
369 | 369 | } |
370 | 370 | } |
371 | - if (substr($this->db->Type,0,5) != 'mysql') $this->db->transaction_begin(); |
|
371 | + if (substr($this->db->Type, 0, 5) != 'mysql') $this->db->transaction_begin(); |
|
372 | 372 | |
373 | 373 | // drop all existing tables |
374 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
374 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
375 | 375 | { |
376 | - if ($this->system_tables && preg_match($this->system_tables,$table) || |
|
377 | - $this->egw_tables && !preg_match($this->egw_tables,$table)) |
|
376 | + if ($this->system_tables && preg_match($this->system_tables, $table) || |
|
377 | + $this->egw_tables && !preg_match($this->egw_tables, $table)) |
|
378 | 378 | { |
379 | 379 | continue; |
380 | 380 | } |
381 | 381 | $this->schema_proc->DropTable($table); |
382 | 382 | } |
383 | 383 | // it could be an old backup |
384 | - list( , $type) = explode('.', basename($filename)); |
|
384 | + list(, $type) = explode('.', basename($filename)); |
|
385 | 385 | $dir = $this->files_dir; // $GLOBALS['egw_info']['server']['files_dir']; |
386 | 386 | // we may have to clean up old backup - left overs |
387 | 387 | if (is_dir($dir.'/database_backup')) |
@@ -394,20 +394,20 @@ discard block |
||
394 | 394 | $name = ""; |
395 | 395 | $zip = NULL; |
396 | 396 | $_f = NULL; |
397 | - if($type == 'zip') |
|
397 | + if ($type == 'zip') |
|
398 | 398 | { |
399 | 399 | // has already been verified to be available in fopen_backup |
400 | 400 | $zip = new ZipArchive; |
401 | - if(($zip->open($filename)) !== TRUE) |
|
401 | + if (($zip->open($filename)) !== TRUE) |
|
402 | 402 | { |
403 | 403 | return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n"; |
404 | 404 | } |
405 | - self::remove_dir_content($dir); // removes the files-dir |
|
405 | + self::remove_dir_content($dir); // removes the files-dir |
|
406 | 406 | $zip->extractTo($dir); |
407 | 407 | $_f = $f; |
408 | 408 | $list = $this->get_file_list($dir.'/database_backup/'); |
409 | 409 | $name = $dir.'/database_backup/'.basename($list[0]); |
410 | - if(!($f = fopen($name, 'rb'))) |
|
410 | + if (!($f = fopen($name, 'rb'))) |
|
411 | 411 | { |
412 | 412 | return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n"; |
413 | 413 | } |
@@ -424,46 +424,46 @@ discard block |
||
424 | 424 | { |
425 | 425 | $this->db->insert(config::TABLE, array( |
426 | 426 | 'config_value' => $this->schema_proc->system_charset, |
427 | - ),array( |
|
427 | + ), array( |
|
428 | 428 | 'config_app' => 'phpgwapi', |
429 | 429 | 'config_name' => 'system_charset', |
430 | - ),__LINE__,__FILE__); |
|
430 | + ), __LINE__, __FILE__); |
|
431 | 431 | } |
432 | 432 | // restore protected system config |
433 | 433 | if ($protect_system_config) |
434 | 434 | { |
435 | - foreach($system_config as $row) |
|
435 | + foreach ($system_config as $row) |
|
436 | 436 | { |
437 | - $this->db->insert(self::TABLE,array('config_value'=>$row['config_value']),array( |
|
437 | + $this->db->insert(self::TABLE, array('config_value'=>$row['config_value']), array( |
|
438 | 438 | 'config_name' => $row['config_name'], |
439 | 439 | 'config_app' => $row['config_app'], |
440 | - ),__LINE__,__FILE__); |
|
440 | + ), __LINE__, __FILE__); |
|
441 | 441 | } |
442 | 442 | // check and reset cookie configuration, if it does not match current enviroment |
443 | 443 | // if $_SERVER[HTTP_HOST] does not end with cookiedomain --> delete cookiedomain |
444 | - if (($cookiedomain = $this->db->select(self::TABLE,'config_value',array( |
|
444 | + if (($cookiedomain = $this->db->select(self::TABLE, 'config_value', array( |
|
445 | 445 | 'config_app' => 'phpgwapi', |
446 | 446 | 'config_name' => 'cookiedomain', |
447 | - ),__LINE__,__FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) && |
|
448 | - (list($hostname) = explode(':',$_SERVER['HTTP_HOST'])) && |
|
449 | - substr($hostname,-strlen($cookiedomain) !== $cookiedomain)) |
|
447 | + ), __LINE__, __FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) && |
|
448 | + (list($hostname) = explode(':', $_SERVER['HTTP_HOST'])) && |
|
449 | + substr($hostname, -strlen($cookiedomain) !== $cookiedomain)) |
|
450 | 450 | { |
451 | - $this->db->delete(self::TABLE,array( |
|
451 | + $this->db->delete(self::TABLE, array( |
|
452 | 452 | 'config_app' => 'phpgwapi', |
453 | 453 | 'config_name' => 'cookiedomain', |
454 | - ),__LINE__,__FILE__); |
|
454 | + ), __LINE__, __FILE__); |
|
455 | 455 | } |
456 | 456 | // if configured webserver_url does NOT start with cookiepath --> delete cookiepath |
457 | - if (($cookiepath = $this->db->select(self::TABLE,'config_value',array( |
|
457 | + if (($cookiepath = $this->db->select(self::TABLE, 'config_value', array( |
|
458 | 458 | 'config_app' => 'phpgwapi', |
459 | 459 | 'config_name' => 'cookiepath', |
460 | - ),__LINE__,__FILE__)->fetchColumn()) && |
|
461 | - substr(parse_url($system_config['webserver_url'], PHP_URL_PATH),0,strlen($cookiepath) !== $cookiepath)) |
|
460 | + ), __LINE__, __FILE__)->fetchColumn()) && |
|
461 | + substr(parse_url($system_config['webserver_url'], PHP_URL_PATH), 0, strlen($cookiepath) !== $cookiepath)) |
|
462 | 462 | { |
463 | - $this->db->delete(self::TABLE,array( |
|
463 | + $this->db->delete(self::TABLE, array( |
|
464 | 464 | 'config_app' => 'phpgwapi', |
465 | 465 | 'config_name' => 'cookiepath', |
466 | - ),__LINE__,__FILE__); |
|
466 | + ), __LINE__, __FILE__); |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | // restore original Halt_On_Error state (if changed) |
@@ -472,13 +472,13 @@ discard block |
||
472 | 472 | $this->db->Halt_On_Error = $backup_db_halt_on_error; |
473 | 473 | } |
474 | 474 | // zip? |
475 | - if($type == 'zip') |
|
475 | + if ($type == 'zip') |
|
476 | 476 | { |
477 | 477 | fclose($f); |
478 | 478 | unlink($name); |
479 | 479 | rmdir($dir.'/database_backup'); |
480 | 480 | } |
481 | - if (substr($this->db->Type,0,5) != 'mysql') |
|
481 | + if (substr($this->db->Type, 0, 5) != 'mysql') |
|
482 | 482 | { |
483 | 483 | if (!$this->db->transaction_commit()) |
484 | 484 | { |
@@ -513,26 +513,26 @@ discard block |
||
513 | 513 | * @param int|string $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert |
514 | 514 | * @returns int number of rows read from csv file |
515 | 515 | */ |
516 | - function db_restore($f, $insert_n_rows=10) |
|
516 | + function db_restore($f, $insert_n_rows = 10) |
|
517 | 517 | { |
518 | 518 | $convert_to_system_charset = true; |
519 | 519 | $table = False; |
520 | 520 | $n = 0; |
521 | 521 | $rows = array(); |
522 | - while(!feof($f)) |
|
522 | + while (!feof($f)) |
|
523 | 523 | { |
524 | 524 | $line = trim(fgets($f)); ++$n; |
525 | 525 | |
526 | 526 | if (empty($line)) continue; |
527 | 527 | |
528 | - if (substr($line,0,9) == 'version: ') |
|
528 | + if (substr($line, 0, 9) == 'version: ') |
|
529 | 529 | { |
530 | - $api_version = trim(substr($line,9)); |
|
530 | + $api_version = trim(substr($line, 9)); |
|
531 | 531 | continue; |
532 | 532 | } |
533 | - if (substr($line,0,9) == 'charset: ') |
|
533 | + if (substr($line, 0, 9) == 'charset: ') |
|
534 | 534 | { |
535 | - $charset = trim(substr($line,9)); |
|
535 | + $charset = trim(substr($line, 9)); |
|
536 | 536 | // needed if mbstring.func_overload > 0, else eg. substr does not work with non ascii chars |
537 | 537 | $ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset'; |
538 | 538 | @ini_set($ini_default_charset, $charset); |
@@ -540,29 +540,29 @@ discard block |
||
540 | 540 | // check if we really need to convert the charset, as it's not perfect and can do some damage |
541 | 541 | if ($convert_to_system_charset && !strcasecmp($this->schema_proc->system_charset, $charset)) |
542 | 542 | { |
543 | - $convert_to_system_charset = false; // no conversation necessary |
|
543 | + $convert_to_system_charset = false; // no conversation necessary |
|
544 | 544 | } |
545 | 545 | // set the DB's client encoding (for mysql only if api_version >= 1.0.1.019) |
546 | 546 | if ((!$convert_to_system_charset || $this->db->capabilities['client_encoding']) && |
547 | - (substr($this->db->Type,0,5) != 'mysql' || !is_object($GLOBALS['egw_setup']) || |
|
548 | - $api_version && !$GLOBALS['egw_setup']->alessthanb($api_version,'1.0.1.019'))) |
|
547 | + (substr($this->db->Type, 0, 5) != 'mysql' || !is_object($GLOBALS['egw_setup']) || |
|
548 | + $api_version && !$GLOBALS['egw_setup']->alessthanb($api_version, '1.0.1.019'))) |
|
549 | 549 | { |
550 | 550 | $this->db->Link_ID->SetCharSet($charset); |
551 | 551 | if (!$convert_to_system_charset) |
552 | 552 | { |
553 | - $this->schema_proc->system_charset = $charset; // so schema_proc uses it for the creation of the tables |
|
553 | + $this->schema_proc->system_charset = $charset; // so schema_proc uses it for the creation of the tables |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | continue; |
557 | 557 | } |
558 | - if (substr($line,0,8) == 'schema: ') |
|
558 | + if (substr($line, 0, 8) == 'schema: ') |
|
559 | 559 | { |
560 | 560 | // create the tables in the backup set |
561 | - $this->schemas = json_php_unserialize(trim(substr($line,8))); |
|
562 | - foreach($this->schemas as $table_name => $schema) |
|
561 | + $this->schemas = json_php_unserialize(trim(substr($line, 8))); |
|
562 | + foreach ($this->schemas as $table_name => $schema) |
|
563 | 563 | { |
564 | 564 | // if column is longtext in current schema, convert text to longtext, in case user already updated column |
565 | - foreach($schema['fd'] as $col => &$def) |
|
565 | + foreach ($schema['fd'] as $col => &$def) |
|
566 | 566 | { |
567 | 567 | if ($def['type'] == 'text' && $this->db->get_column_attribute($col, $table_name, true, 'type') == 'longtext') |
568 | 568 | { |
@@ -574,27 +574,27 @@ discard block |
||
574 | 574 | } |
575 | 575 | continue; |
576 | 576 | } |
577 | - if (substr($line,0,7) == 'table: ') |
|
577 | + if (substr($line, 0, 7) == 'table: ') |
|
578 | 578 | { |
579 | 579 | if ($rows) // flush pending rows of last table |
580 | 580 | { |
581 | 581 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
582 | 582 | } |
583 | 583 | $rows = array(); |
584 | - $table = substr($line,7); |
|
584 | + $table = substr($line, 7); |
|
585 | 585 | if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
586 | 586 | $auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null; |
587 | 587 | |
588 | - $cols = self::csv_split($line=fgets($f)); ++$n; |
|
588 | + $cols = self::csv_split($line = fgets($f)); ++$n; |
|
589 | 589 | $blobs = array(); |
590 | - foreach($this->schemas[$table]['fd'] as $col => $data) |
|
590 | + foreach ($this->schemas[$table]['fd'] as $col => $data) |
|
591 | 591 | { |
592 | 592 | if ($data['type'] == 'blob') $blobs[] = $col; |
593 | 593 | } |
594 | 594 | // check if we have an old PostgreSQL backup useing 't'/'f' for bool values |
595 | 595 | // --> convert them to MySQL and our new PostgreSQL format of 1/0 |
596 | 596 | $bools = array(); |
597 | - foreach($this->schemas[$table]['fd'] as $col => $def) |
|
597 | + foreach ($this->schemas[$table]['fd'] as $col => $def) |
|
598 | 598 | { |
599 | 599 | if ($def['type'] === 'bool') $bools[] = $col; |
600 | 600 | } |
@@ -618,15 +618,15 @@ discard block |
||
618 | 618 | $import = true; |
619 | 619 | $data = self::csv_split($line, $cols, $blobs, $bools); |
620 | 620 | |
621 | - if ($table == 'egw_async' && in_array('##last-check-run##',$data)) |
|
621 | + if ($table == 'egw_async' && in_array('##last-check-run##', $data)) |
|
622 | 622 | { |
623 | 623 | //echo '<p>'.lang("Line %1: '%2'<br><b>csv data does contain ##last-check-run## of table %3 ==> ignored</b>",$n,$line,$table)."</p>\n"; |
624 | 624 | //echo 'data=<pre>'.print_r($data,true)."</pre>\n"; |
625 | 625 | $import = false; |
626 | 626 | } |
627 | - if (in_array($table,$this->exclude_tables)) |
|
627 | + if (in_array($table, $this->exclude_tables)) |
|
628 | 628 | { |
629 | - echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.",$table)."</b></p>\n"; |
|
629 | + echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.", $table)."</b></p>\n"; |
|
630 | 630 | $import = false; // dont restore data of excluded tables |
631 | 631 | } |
632 | 632 | if ($import) |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | { |
636 | 636 | if ($convert_to_system_charset && !$this->db->capabilities['client_encoding']) |
637 | 637 | { |
638 | - $data = translation::convert($data,$charset); |
|
638 | + $data = translation::convert($data, $charset); |
|
639 | 639 | } |
640 | 640 | if ($insert_n_rows > 1) |
641 | 641 | { |
@@ -647,27 +647,27 @@ discard block |
||
647 | 647 | } |
648 | 648 | } |
649 | 649 | // update existing table using given unique key in $insert_n_rows (also removing auto-id/sequence) |
650 | - elseif(!is_numeric($insert_n_rows)) |
|
650 | + elseif (!is_numeric($insert_n_rows)) |
|
651 | 651 | { |
652 | 652 | $where = array($insert_n_rows => $data[$insert_n_rows]); |
653 | 653 | unset($data[$insert_n_rows]); |
654 | 654 | if ($auto_id) unset($data[$auto_id]); |
655 | - $this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
|
655 | + $this->db->insert($table, $data, $where, __LINE__, __FILE__, false, false, $this->schemas[$table]); |
|
656 | 656 | } |
657 | 657 | else |
658 | 658 | { |
659 | 659 | try { |
660 | - $this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
|
660 | + $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $this->schemas[$table]); |
|
661 | 661 | } |
662 | - catch(egw_exception_db_invalid_sql $e) { |
|
662 | + catch (egw_exception_db_invalid_sql $e) { |
|
663 | 663 | echo "<p>".$e->getMessage()."</p>\n"; |
664 | 664 | } |
665 | 665 | } |
666 | 666 | } |
667 | 667 | else |
668 | 668 | { |
669 | - echo '<p>'.lang("Line %1: '%2'<br><b>csv data does not match column-count of table %3 ==> ignored</b>",$n,$line,$table)."</p>\n"; |
|
670 | - echo 'data=<pre>'.print_r($data,true)."</pre>\n"; |
|
669 | + echo '<p>'.lang("Line %1: '%2'<br><b>csv data does not match column-count of table %3 ==> ignored</b>", $n, $line, $table)."</p>\n"; |
|
670 | + echo 'data=<pre>'.print_r($data, true)."</pre>\n"; |
|
671 | 671 | } |
672 | 672 | } |
673 | 673 | } |
@@ -677,14 +677,14 @@ discard block |
||
677 | 677 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
678 | 678 | } |
679 | 679 | // updated the sequences, if the DB uses them |
680 | - foreach($this->schemas as $table => $schema) |
|
680 | + foreach ($this->schemas as $table => $schema) |
|
681 | 681 | { |
682 | - foreach($schema['fd'] as $column => $definition) |
|
682 | + foreach ($schema['fd'] as $column => $definition) |
|
683 | 683 | { |
684 | 684 | if ($definition['type'] == 'auto') |
685 | 685 | { |
686 | - $this->schema_proc->UpdateSequence($table,$column); |
|
687 | - break; // max. one per table |
|
686 | + $this->schema_proc->UpdateSequence($table, $column); |
|
687 | + break; // max. one per table |
|
688 | 688 | } |
689 | 689 | } |
690 | 690 | } |
@@ -707,15 +707,15 @@ discard block |
||
707 | 707 | try { |
708 | 708 | $this->db->insert($table, $rows, False, __LINE__, __FILE__, false, false, $schema); |
709 | 709 | } |
710 | - catch(egw_exception_db_invalid_sql $e) |
|
710 | + catch (egw_exception_db_invalid_sql $e) |
|
711 | 711 | { |
712 | 712 | // try inserting them one by one, ignoring doublicates |
713 | - foreach($rows as $data) |
|
713 | + foreach ($rows as $data) |
|
714 | 714 | { |
715 | 715 | try { |
716 | 716 | $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema); |
717 | 717 | } |
718 | - catch(egw_exception_db_invalid_sql $e) { |
|
718 | + catch (egw_exception_db_invalid_sql $e) { |
|
719 | 719 | echo "<p>".$e->getMessage()."</p>\n"; |
720 | 720 | } |
721 | 721 | } |
@@ -730,11 +730,11 @@ discard block |
||
730 | 730 | private static function remove_dir_content($dir) |
731 | 731 | { |
732 | 732 | $list = scandir($dir); |
733 | - while($file = $list[0]) |
|
733 | + while ($file = $list[0]) |
|
734 | 734 | { |
735 | - if(is_dir($file) && $file != '.' && $file != '..') |
|
735 | + if (is_dir($file) && $file != '.' && $file != '..') |
|
736 | 736 | self::remove_dir_content($dir.'/'.$file); |
737 | - if(is_file($file) && $file != '.' && $file != '..') |
|
737 | + if (is_file($file) && $file != '.' && $file != '..') |
|
738 | 738 | unlink($dir.'/'.$file); |
739 | 739 | array_shift($list); |
740 | 740 | } |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | * @param array $bools =array() bool columns, values might be 't'/'f' for old PostgreSQL backups |
760 | 760 | * @return array |
761 | 761 | */ |
762 | - public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) |
|
762 | + public static function csv_split($line, $keys = null, $blobs = array(), $bools = array()) |
|
763 | 763 | { |
764 | 764 | if (function_exists('str_getcsv')) // php5.3+ |
765 | 765 | { |
@@ -772,9 +772,9 @@ discard block |
||
772 | 772 | '\\n' => "\n", |
773 | 773 | '\\r' => "\r")), ',', '"', '\0'); |
774 | 774 | // replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash |
775 | - foreach($fields as &$field) |
|
775 | + foreach ($fields as &$field) |
|
776 | 776 | { |
777 | - switch($field) |
|
777 | + switch ($field) |
|
778 | 778 | { |
779 | 779 | case self::NULL_TOKEN: |
780 | 780 | $field = 'NULL'; |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | { |
792 | 792 | $fields = array_combine($keys, $fields); |
793 | 793 | // base64-decode blob columns, if they are base64 encoded |
794 | - foreach($blobs as $key) |
|
794 | + foreach ($blobs as $key) |
|
795 | 795 | { |
796 | 796 | if (!is_null($fields[$key]) && ($tmp = base64_decode($fields[$key], true)) !== false) |
797 | 797 | { |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | } |
800 | 800 | } |
801 | 801 | // decode bool columns, they might be 't'/'f' for old PostgreSQL backups |
802 | - foreach($bools as $key) |
|
802 | + foreach ($bools as $key) |
|
803 | 803 | { |
804 | 804 | $fields[$key] = egw_db::from_bool($fields[$key]); |
805 | 805 | } |
@@ -807,11 +807,11 @@ discard block |
||
807 | 807 | return $fields; |
808 | 808 | } |
809 | 809 | // pre 5.3 implementation |
810 | - $fields = explode(',',trim($line)); |
|
810 | + $fields = explode(',', trim($line)); |
|
811 | 811 | |
812 | 812 | $str_pending = False; |
813 | 813 | $n = 0; |
814 | - foreach($fields as $field) |
|
814 | + foreach ($fields as $field) |
|
815 | 815 | { |
816 | 816 | if ($str_pending !== False) |
817 | 817 | { |
@@ -822,12 +822,12 @@ discard block |
||
822 | 822 | |
823 | 823 | if ($field[0] == '"') |
824 | 824 | { |
825 | - if (substr($field,-1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/',$field)) |
|
825 | + if (substr($field, -1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/', $field)) |
|
826 | 826 | { |
827 | 827 | $str_pending = $field; |
828 | 828 | continue; |
829 | 829 | } |
830 | - $arr[$key] = str_replace(self::BACKSLASH_TOKEN,'\\',str_replace(array('\\\\','\\n','\\r','\\"'),array(self::BACKSLASH_TOKEN,"\n","\r",'"'),substr($field,1,-1))); |
|
830 | + $arr[$key] = str_replace(self::BACKSLASH_TOKEN, '\\', str_replace(array('\\\\', '\\n', '\\r', '\\"'), array(self::BACKSLASH_TOKEN, "\n", "\r", '"'), substr($field, 1, -1))); |
|
831 | 831 | } |
832 | 832 | elseif ($keys && strlen($field) > 26) |
833 | 833 | { |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | /** |
850 | 850 | * escape data for csv |
851 | 851 | */ |
852 | - public static function escape_data(&$data,$col,$defs) |
|
852 | + public static function escape_data(&$data, $col, $defs) |
|
853 | 853 | { |
854 | 854 | if (is_null($data)) |
855 | 855 | { |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | } |
858 | 858 | else |
859 | 859 | { |
860 | - switch($defs[$col]['type']) |
|
860 | + switch ($defs[$col]['type']) |
|
861 | 861 | { |
862 | 862 | case 'int': |
863 | 863 | case 'auto': |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | $data = (int)egw_db::from_bool($data); |
873 | 873 | break; |
874 | 874 | default: |
875 | - $data = '"'.str_replace(array('\\',"\n","\r",'"'),array('\\\\','\\n','\\r','\\"'),$data).'"'; |
|
875 | + $data = '"'.str_replace(array('\\', "\n", "\r", '"'), array('\\\\', '\\n', '\\r', '\\"'), $data).'"'; |
|
876 | 876 | break; |
877 | 877 | } |
878 | 878 | } |
@@ -904,15 +904,15 @@ discard block |
||
904 | 904 | $name = $this->backup_dir.'/db_backup-'.date('YmdHi'); |
905 | 905 | $filename = $name.'.zip'; |
906 | 906 | $zippresent = false; |
907 | - if(class_exists('ZipArchive') && $this->backup_files) |
|
907 | + if (class_exists('ZipArchive') && $this->backup_files) |
|
908 | 908 | { |
909 | 909 | $zip = new ZipArchive; |
910 | - if(is_object($zip)) |
|
910 | + if (is_object($zip)) |
|
911 | 911 | { |
912 | 912 | $zippresent = true; |
913 | 913 | //echo '-> is_object($zip); '.$filename.'<br>'; // ! |
914 | 914 | $res = $zip->open($filename, ZIPARCHIVE::CREATE); |
915 | - if($res !== TRUE) |
|
915 | + if ($res !== TRUE) |
|
916 | 916 | { |
917 | 917 | //echo ' -> !$res<br>'; // ! |
918 | 918 | return lang("Cant open '%1' for %2", $filename, lang("writing"))."<br>\n"; |
@@ -920,19 +920,19 @@ discard block |
||
920 | 920 | $file_list = $this->get_file_list($dir); |
921 | 921 | } |
922 | 922 | } |
923 | - fwrite($f,"EGroupware backup from ".date('Y-m-d H:i:s')."\n\n"); |
|
923 | + fwrite($f, "EGroupware backup from ".date('Y-m-d H:i:s')."\n\n"); |
|
924 | 924 | |
925 | - fwrite($f,"version: $this->api_version\n\n"); |
|
925 | + fwrite($f, "version: $this->api_version\n\n"); |
|
926 | 926 | |
927 | - fwrite($f,"charset: $this->charset\n\n"); |
|
927 | + fwrite($f, "charset: $this->charset\n\n"); |
|
928 | 928 | |
929 | - $this->schema_backup($f); // add the schema in a human readable form too |
|
929 | + $this->schema_backup($f); // add the schema in a human readable form too |
|
930 | 930 | |
931 | - fwrite($f,"\nschema: ".json_encode($this->schemas)."\n"); |
|
931 | + fwrite($f, "\nschema: ".json_encode($this->schemas)."\n"); |
|
932 | 932 | |
933 | - foreach($this->schemas as $table => $schema) |
|
933 | + foreach ($this->schemas as $table => $schema) |
|
934 | 934 | { |
935 | - if (in_array($table,$this->exclude_tables)) continue; // dont backup |
|
935 | + if (in_array($table, $this->exclude_tables)) continue; // dont backup |
|
936 | 936 | |
937 | 937 | // do we have a primary key? |
938 | 938 | // --> use it to order and limit rows, to kope with rows being added during backup |
@@ -944,26 +944,26 @@ discard block |
||
944 | 944 | do { |
945 | 945 | $num_rows = 0; |
946 | 946 | // querying only chunks for 10000 rows, to not run into memory limit on huge tables |
947 | - foreach($this->db->select($table, '*', |
|
947 | + foreach ($this->db->select($table, '*', |
|
948 | 948 | // limit by maximum primary key already received |
949 | 949 | empty($pk) || !$max ? false : $pk.' > '.$this->db->quote($max, $schema['fd'][$pk]['type']), |
950 | 950 | __LINE__, __FILE__, |
951 | - empty($pk) ? false : 0, // if no primary key, query all rows |
|
952 | - empty($pk) ? '' : 'ORDER BY '.$this->db->name_quote($pk).' ASC', // order by primary key |
|
951 | + empty($pk) ? false : 0, // if no primary key, query all rows |
|
952 | + empty($pk) ? '' : 'ORDER BY '.$this->db->name_quote($pk).' ASC', // order by primary key |
|
953 | 953 | false, self::ROW_CHUNK) as $row) |
954 | 954 | { |
955 | 955 | if (!empty($pk)) $max = $row[$pk]; |
956 | - if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
956 | + if ($total === 0) fwrite($f, "\ntable: $table\n".implode(',', array_keys($row))."\n"); |
|
957 | 957 | |
958 | - array_walk($row,array('db_backup','escape_data'),$schema['fd']); |
|
959 | - fwrite($f,implode(',',$row)."\n"); |
|
958 | + array_walk($row, array('db_backup', 'escape_data'), $schema['fd']); |
|
959 | + fwrite($f, implode(',', $row)."\n"); |
|
960 | 960 | ++$total; |
961 | 961 | ++$num_rows; |
962 | 962 | } |
963 | 963 | } |
964 | - while(!empty($pk) && !($total % self::ROW_CHUNK) && $num_rows); |
|
964 | + while (!empty($pk) && !($total % self::ROW_CHUNK) && $num_rows); |
|
965 | 965 | } |
966 | - if(!$zippresent) // save without files |
|
966 | + if (!$zippresent) // save without files |
|
967 | 967 | { |
968 | 968 | if ($this->backup_files) |
969 | 969 | { |
@@ -978,16 +978,16 @@ discard block |
||
978 | 978 | //echo $name.'<br>'; |
979 | 979 | $zip->addFile($name, 'database_backup/'.basename($name)); |
980 | 980 | $count = 1; |
981 | - foreach($file_list as $file) |
|
981 | + foreach ($file_list as $file) |
|
982 | 982 | { |
983 | 983 | //echo substr($file,strlen($dir)+1).'<br>'; |
984 | 984 | //echo $file.'<br>'; |
985 | - $zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file); |
|
986 | - if(($count++) == 100) { // the file descriptor limit |
|
985 | + $zip->addFile($file, substr($file, strlen($dir) + 1)); //,substr($file); |
|
986 | + if (($count++) == 100) { // the file descriptor limit |
|
987 | 987 | $zip->close(); |
988 | - if(($zip = new ZipArchive())) { |
|
988 | + if (($zip = new ZipArchive())) { |
|
989 | 989 | $zip->open($filename); |
990 | - $count =0; |
|
990 | + $count = 0; |
|
991 | 991 | } |
992 | 992 | } |
993 | 993 | } |
@@ -1010,17 +1010,17 @@ discard block |
||
1010 | 1010 | { |
1011 | 1011 | //chdir($f); |
1012 | 1012 | //echo "Processing $f <br>"; |
1013 | - if ($path_name =='') $path_name = $f; |
|
1013 | + if ($path_name == '') $path_name = $f; |
|
1014 | 1014 | $tlist = scandir($f); |
1015 | 1015 | $list = array(); |
1016 | 1016 | $i = $cnt; |
1017 | - while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
1017 | + while ($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
1018 | 1018 | { |
1019 | - if($file == '.' || $file == '..') |
|
1019 | + if ($file == '.' || $file == '..') |
|
1020 | 1020 | { |
1021 | 1021 | array_shift($tlist); |
1022 | 1022 | } |
1023 | - elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false) |
|
1023 | + elseif ($file == 'debug.txt' && stripos($f, 'activesync') !== false) |
|
1024 | 1024 | { |
1025 | 1025 | // skip activesync debug.txt on backupFiles |
1026 | 1026 | //error_log(__METHOD__.__LINE__.'->'.$f.'/'.$file); |
@@ -1028,7 +1028,7 @@ discard block |
||
1028 | 1028 | } |
1029 | 1029 | else |
1030 | 1030 | { |
1031 | - if(is_dir($f.'/'.$file)) |
|
1031 | + if (is_dir($f.'/'.$file)) |
|
1032 | 1032 | { |
1033 | 1033 | $nlist = $this->get_file_list($f.'/'.$file, $i); |
1034 | 1034 | $list += $nlist; |
@@ -1049,12 +1049,12 @@ discard block |
||
1049 | 1049 | * |
1050 | 1050 | * @param resource|boolean $f |
1051 | 1051 | */ |
1052 | - function schema_backup($f=False) |
|
1052 | + function schema_backup($f = False) |
|
1053 | 1053 | { |
1054 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
1054 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
1055 | 1055 | { |
1056 | - if ($this->system_tables && preg_match($this->system_tables,$table) || |
|
1057 | - $this->egw_tables && !preg_match($this->egw_tables,$table)) |
|
1056 | + if ($this->system_tables && preg_match($this->system_tables, $table) || |
|
1057 | + $this->egw_tables && !preg_match($this->egw_tables, $table)) |
|
1058 | 1058 | { |
1059 | 1059 | continue; |
1060 | 1060 | } |
@@ -1073,17 +1073,17 @@ discard block |
||
1073 | 1073 | } |
1074 | 1074 | } |
1075 | 1075 | $def = "\t\$phpgw_baseline = "; |
1076 | - $def .= self::write_array($this->schemas,1); |
|
1076 | + $def .= self::write_array($this->schemas, 1); |
|
1077 | 1077 | $def .= ";\n"; |
1078 | 1078 | |
1079 | 1079 | if ($f) |
1080 | 1080 | { |
1081 | - fwrite($f,$def); |
|
1081 | + fwrite($f, $def); |
|
1082 | 1082 | } |
1083 | 1083 | else |
1084 | 1084 | { |
1085 | 1085 | $def = "<?php\n\t/* EGroupware schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def; |
1086 | - html::content_header('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def)); |
|
1086 | + html::content_header('schema-backup-'.date('YmdHi').'.inc.php', 'text/plain', bytes($def)); |
|
1087 | 1087 | echo $def; |
1088 | 1088 | } |
1089 | 1089 | } |
@@ -1093,9 +1093,9 @@ discard block |
||
1093 | 1093 | * |
1094 | 1094 | * copied from etemplate/inc/class.db_tools.inc.php |
1095 | 1095 | */ |
1096 | - private static function write_array($arr,$depth,$parent='') |
|
1096 | + private static function write_array($arr, $depth, $parent = '') |
|
1097 | 1097 | { |
1098 | - if (in_array($parent,array('pk','fk','ix','uc'))) |
|
1098 | + if (in_array($parent, array('pk', 'fk', 'ix', 'uc'))) |
|
1099 | 1099 | { |
1100 | 1100 | $depth = 0; |
1101 | 1101 | } |
@@ -1111,7 +1111,7 @@ discard block |
||
1111 | 1111 | $def = "array($tabs".($tabs ? "\t" : ''); |
1112 | 1112 | |
1113 | 1113 | $n = 0; |
1114 | - foreach($arr as $key => $val) |
|
1114 | + foreach ($arr as $key => $val) |
|
1115 | 1115 | { |
1116 | 1116 | if (!is_int($key)) |
1117 | 1117 | { |
@@ -1119,7 +1119,7 @@ discard block |
||
1119 | 1119 | } |
1120 | 1120 | if (is_array($val)) |
1121 | 1121 | { |
1122 | - $def .= self::write_array($val,$parent == 'fd' ? 0 : $depth,$key); |
|
1122 | + $def .= self::write_array($val, $parent == 'fd' ? 0 : $depth, $key); |
|
1123 | 1123 | } |
1124 | 1124 | else |
1125 | 1125 | { |
@@ -1132,7 +1132,7 @@ discard block |
||
1132 | 1132 | $def .= "'$val'"; |
1133 | 1133 | } |
1134 | 1134 | } |
1135 | - if ($n < count($arr)-1) |
|
1135 | + if ($n < count($arr) - 1) |
|
1136 | 1136 | { |
1137 | 1137 | $def .= ",$tabs".($tabs ? "\t" : ''); |
1138 | 1138 | } |
@@ -97,23 +97,32 @@ discard block |
||
97 | 97 | { |
98 | 98 | $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
99 | 99 | } |
100 | - if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc)) // schema_proc already instanciated, use it |
|
100 | + if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc)) |
|
101 | + { |
|
102 | + // schema_proc already instanciated, use it |
|
101 | 103 | { |
102 | 104 | $this->schema_proc = $GLOBALS['egw_setup']->oProc; |
103 | 105 | } |
106 | + } |
|
104 | 107 | else |
105 | 108 | { |
106 | 109 | $this->schema_proc = new schema_proc(); |
107 | 110 | } |
108 | 111 | |
109 | 112 | $this->db = $this->schema_proc->m_odb; |
110 | - if (!$this->db->Link_ID) $this->db->connect(); |
|
113 | + if (!$this->db->Link_ID) |
|
114 | + { |
|
115 | + $this->db->connect(); |
|
116 | + } |
|
111 | 117 | $this->adodb = $this->db->Link_ID; |
112 | - if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup'])) // called from setup |
|
118 | + if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup'])) |
|
119 | + { |
|
120 | + // called from setup |
|
113 | 121 | { |
114 | 122 | if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table))) |
115 | 123 | { |
116 | 124 | $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'",__LINE__,__FILE__); |
125 | + } |
|
117 | 126 | $this->db->next_record(); |
118 | 127 | if (!($this->backup_dir = $this->db->f(0))) |
119 | 128 | { |
@@ -147,7 +156,10 @@ discard block |
||
147 | 156 | $this->db->next_record(); |
148 | 157 | $this->backup_files = (bool)$this->db->f(0); |
149 | 158 | } |
150 | - if (!$this->charset) $this->charset = 'iso-8859-1'; |
|
159 | + if (!$this->charset) |
|
160 | + { |
|
161 | + $this->charset = 'iso-8859-1'; |
|
162 | + } |
|
151 | 163 | } |
152 | 164 | else // called from eGW |
153 | 165 | { |
@@ -245,8 +257,7 @@ discard block |
||
245 | 257 | if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
246 | 258 | !($f = fopen("compress.zlib://$name.gz",$mode)) && |
247 | 259 | !($f = fopen($name,$mode)) |
248 | - ) |
|
249 | - { |
|
260 | + ) { |
|
250 | 261 | //echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>'; // ! |
251 | 262 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
252 | 263 | return lang("Cant open '%1' for %2", $name, $lang_mode)."<br>"; |
@@ -282,16 +293,22 @@ discard block |
||
282 | 293 | $files[filectime($this->backup_dir.'/'.$file)] = $file; |
283 | 294 | } |
284 | 295 | } |
285 | - if ($handle) closedir($handle); |
|
296 | + if ($handle) |
|
297 | + { |
|
298 | + closedir($handle); |
|
299 | + } |
|
286 | 300 | |
287 | 301 | /* Sort the files by ctime. */ |
288 | 302 | krsort($files); |
289 | 303 | $count = 0; |
290 | 304 | foreach($files as $file) |
291 | 305 | { |
292 | - if ($count >= $this->backup_mincount)// |
|
306 | + if ($count >= $this->backup_mincount) |
|
307 | + { |
|
308 | + // |
|
293 | 309 | { |
294 | 310 | $ret = unlink($this->backup_dir.'/'.$file); |
311 | + } |
|
295 | 312 | if (($ret) && (is_array($files_return))) |
296 | 313 | { |
297 | 314 | array_push($files_return, $file); |
@@ -355,7 +372,11 @@ discard block |
||
355 | 372 | @set_time_limit(0); |
356 | 373 | ini_set('auto_detect_line_endings',true); |
357 | 374 | |
358 | - if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
375 | + if (true) |
|
376 | + { |
|
377 | + $convert_to_system_charset = true; |
|
378 | + } |
|
379 | + // enforce now utf-8 as system charset restores of old backups |
|
359 | 380 | |
360 | 381 | if ($protect_system_config) |
361 | 382 | { |
@@ -368,7 +389,10 @@ discard block |
||
368 | 389 | $system_config[] = $row; |
369 | 390 | } |
370 | 391 | } |
371 | - if (substr($this->db->Type,0,5) != 'mysql') $this->db->transaction_begin(); |
|
392 | + if (substr($this->db->Type,0,5) != 'mysql') |
|
393 | + { |
|
394 | + $this->db->transaction_begin(); |
|
395 | + } |
|
372 | 396 | |
373 | 397 | // drop all existing tables |
374 | 398 | foreach($this->adodb->MetaTables('TABLES') as $table) |
@@ -395,7 +419,7 @@ discard block |
||
395 | 419 | $zip = NULL; |
396 | 420 | $_f = NULL; |
397 | 421 | if($type == 'zip') |
398 | - { |
|
422 | + { |
|
399 | 423 | // has already been verified to be available in fopen_backup |
400 | 424 | $zip = new ZipArchive; |
401 | 425 | if(($zip->open($filename)) !== TRUE) |
@@ -420,7 +444,9 @@ discard block |
||
420 | 444 | } |
421 | 445 | $this->db_restore($f, $insert_n_rows); |
422 | 446 | |
423 | - if ($convert_to_system_charset) // store the changed charset |
|
447 | + if ($convert_to_system_charset) |
|
448 | + { |
|
449 | + // store the changed charset |
|
424 | 450 | { |
425 | 451 | $this->db->insert(config::TABLE, array( |
426 | 452 | 'config_value' => $this->schema_proc->system_charset, |
@@ -429,6 +455,7 @@ discard block |
||
429 | 455 | 'config_name' => 'system_charset', |
430 | 456 | ),__LINE__,__FILE__); |
431 | 457 | } |
458 | + } |
|
432 | 459 | // restore protected system config |
433 | 460 | if ($protect_system_config) |
434 | 461 | { |
@@ -523,7 +550,10 @@ discard block |
||
523 | 550 | { |
524 | 551 | $line = trim(fgets($f)); ++$n; |
525 | 552 | |
526 | - if (empty($line)) continue; |
|
553 | + if (empty($line)) |
|
554 | + { |
|
555 | + continue; |
|
556 | + } |
|
527 | 557 | |
528 | 558 | if (substr($line,0,9) == 'version: ') |
529 | 559 | { |
@@ -576,31 +606,49 @@ discard block |
||
576 | 606 | } |
577 | 607 | if (substr($line,0,7) == 'table: ') |
578 | 608 | { |
579 | - if ($rows) // flush pending rows of last table |
|
609 | + if ($rows) |
|
610 | + { |
|
611 | + // flush pending rows of last table |
|
580 | 612 | { |
581 | 613 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
582 | 614 | } |
615 | + } |
|
583 | 616 | $rows = array(); |
584 | 617 | $table = substr($line,7); |
585 | - if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
|
618 | + if (!isset($this->schemas[$table])) |
|
619 | + { |
|
620 | + $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
|
621 | + } |
|
586 | 622 | $auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null; |
587 | 623 | |
588 | 624 | $cols = self::csv_split($line=fgets($f)); ++$n; |
589 | 625 | $blobs = array(); |
590 | 626 | foreach($this->schemas[$table]['fd'] as $col => $data) |
591 | 627 | { |
592 | - if ($data['type'] == 'blob') $blobs[] = $col; |
|
628 | + if ($data['type'] == 'blob') |
|
629 | + { |
|
630 | + $blobs[] = $col; |
|
631 | + } |
|
593 | 632 | } |
594 | 633 | // check if we have an old PostgreSQL backup useing 't'/'f' for bool values |
595 | 634 | // --> convert them to MySQL and our new PostgreSQL format of 1/0 |
596 | 635 | $bools = array(); |
597 | 636 | foreach($this->schemas[$table]['fd'] as $col => $def) |
598 | 637 | { |
599 | - if ($def['type'] === 'bool') $bools[] = $col; |
|
638 | + if ($def['type'] === 'bool') |
|
639 | + { |
|
640 | + $bools[] = $col; |
|
641 | + } |
|
642 | + } |
|
643 | + if ($table == 'egw_cal_dates') |
|
644 | + { |
|
645 | + error_log(__METHOD__."() $table: bools=".array2string($bools).", schema[fd]=".array2string($this->schemas[$table]['fd'])); |
|
600 | 646 | } |
601 | - if ($table == 'egw_cal_dates') error_log(__METHOD__."() $table: bools=".array2string($bools).", schema[fd]=".array2string($this->schemas[$table]['fd'])); |
|
602 | 647 | |
603 | - if (feof($f)) break; |
|
648 | + if (feof($f)) |
|
649 | + { |
|
650 | + break; |
|
651 | + } |
|
604 | 652 | continue; |
605 | 653 | } |
606 | 654 | if ($convert_to_system_charset && !$this->db->capabilities['client_encoding']) |
@@ -613,9 +661,12 @@ discard block |
||
613 | 661 | } |
614 | 662 | } |
615 | 663 | } |
616 | - if ($table) // do we already reached the data part |
|
664 | + if ($table) |
|
665 | + { |
|
666 | + // do we already reached the data part |
|
617 | 667 | { |
618 | 668 | $import = true; |
669 | + } |
|
619 | 670 | $data = self::csv_split($line, $cols, $blobs, $bools); |
620 | 671 | |
621 | 672 | if ($table == 'egw_async' && in_array('##last-check-run##',$data)) |
@@ -651,7 +702,10 @@ discard block |
||
651 | 702 | { |
652 | 703 | $where = array($insert_n_rows => $data[$insert_n_rows]); |
653 | 704 | unset($data[$insert_n_rows]); |
654 | - if ($auto_id) unset($data[$auto_id]); |
|
705 | + if ($auto_id) |
|
706 | + { |
|
707 | + unset($data[$auto_id]); |
|
708 | + } |
|
655 | 709 | $this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
656 | 710 | } |
657 | 711 | else |
@@ -672,10 +726,13 @@ discard block |
||
672 | 726 | } |
673 | 727 | } |
674 | 728 | } |
675 | - if ($rows) // flush pending rows |
|
729 | + if ($rows) |
|
730 | + { |
|
731 | + // flush pending rows |
|
676 | 732 | { |
677 | 733 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
678 | 734 | } |
735 | + } |
|
679 | 736 | // updated the sequences, if the DB uses them |
680 | 737 | foreach($this->schemas as $table => $schema) |
681 | 738 | { |
@@ -733,9 +790,13 @@ discard block |
||
733 | 790 | while($file = $list[0]) |
734 | 791 | { |
735 | 792 | if(is_dir($file) && $file != '.' && $file != '..') |
736 | - self::remove_dir_content($dir.'/'.$file); |
|
793 | + { |
|
794 | + self::remove_dir_content($dir.'/'.$file); |
|
795 | + } |
|
737 | 796 | if(is_file($file) && $file != '.' && $file != '..') |
738 | - unlink($dir.'/'.$file); |
|
797 | + { |
|
798 | + unlink($dir.'/'.$file); |
|
799 | + } |
|
739 | 800 | array_shift($list); |
740 | 801 | } |
741 | 802 | //rmdir($dir); // dont remove own dir |
@@ -761,7 +822,9 @@ discard block |
||
761 | 822 | */ |
762 | 823 | public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) |
763 | 824 | { |
764 | - if (function_exists('str_getcsv')) // php5.3+ |
|
825 | + if (function_exists('str_getcsv')) |
|
826 | + { |
|
827 | + // php5.3+ |
|
765 | 828 | { |
766 | 829 | // we need to take care of literal "NULL" values, replacing them we a special token as str_getcsv removes enclosures around strings |
767 | 830 | // str_getcsv uses '""' for '"' instead of '\\"' and does not unescape '\\n', '\\r' or '\\\\' (two backslashes) |
@@ -771,6 +834,7 @@ discard block |
||
771 | 834 | '\\"' => '""', |
772 | 835 | '\\n' => "\n", |
773 | 836 | '\\r' => "\r")), ',', '"', '\0'); |
837 | + } |
|
774 | 838 | // replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash |
775 | 839 | foreach($fields as &$field) |
776 | 840 | { |
@@ -787,9 +851,12 @@ discard block |
||
787 | 851 | break; |
788 | 852 | } |
789 | 853 | } |
790 | - if ($keys) // if string keys are to be used --> combine keys and values |
|
854 | + if ($keys) |
|
855 | + { |
|
856 | + // if string keys are to be used --> combine keys and values |
|
791 | 857 | { |
792 | 858 | $fields = array_combine($keys, $fields); |
859 | + } |
|
793 | 860 | // base64-decode blob columns, if they are base64 encoded |
794 | 861 | foreach($blobs as $key) |
795 | 862 | { |
@@ -932,7 +999,11 @@ discard block |
||
932 | 999 | |
933 | 1000 | foreach($this->schemas as $table => $schema) |
934 | 1001 | { |
935 | - if (in_array($table,$this->exclude_tables)) continue; // dont backup |
|
1002 | + if (in_array($table,$this->exclude_tables)) |
|
1003 | + { |
|
1004 | + continue; |
|
1005 | + } |
|
1006 | + // dont backup |
|
936 | 1007 | |
937 | 1008 | // do we have a primary key? |
938 | 1009 | // --> use it to order and limit rows, to kope with rows being added during backup |
@@ -952,8 +1023,14 @@ discard block |
||
952 | 1023 | empty($pk) ? '' : 'ORDER BY '.$this->db->name_quote($pk).' ASC', // order by primary key |
953 | 1024 | false, self::ROW_CHUNK) as $row) |
954 | 1025 | { |
955 | - if (!empty($pk)) $max = $row[$pk]; |
|
956 | - if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
1026 | + if (!empty($pk)) |
|
1027 | + { |
|
1028 | + $max = $row[$pk]; |
|
1029 | + } |
|
1030 | + if ($total === 0) |
|
1031 | + { |
|
1032 | + fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
1033 | + } |
|
957 | 1034 | |
958 | 1035 | array_walk($row,array('db_backup','escape_data'),$schema['fd']); |
959 | 1036 | fwrite($f,implode(',',$row)."\n"); |
@@ -963,15 +1040,21 @@ discard block |
||
963 | 1040 | } |
964 | 1041 | while(!empty($pk) && !($total % self::ROW_CHUNK) && $num_rows); |
965 | 1042 | } |
966 | - if(!$zippresent) // save without files |
|
1043 | + if(!$zippresent) |
|
1044 | + { |
|
1045 | + // save without files |
|
967 | 1046 | { |
968 | 1047 | if ($this->backup_files) |
969 | 1048 | { |
970 | 1049 | echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>'; |
1050 | + } |
|
971 | 1051 | } |
972 | 1052 | |
973 | 1053 | fclose($f); |
974 | - if (file_exists($name)) unlink($name); |
|
1054 | + if (file_exists($name)) |
|
1055 | + { |
|
1056 | + unlink($name); |
|
1057 | + } |
|
975 | 1058 | return TRUE; |
976 | 1059 | } |
977 | 1060 | // save files .... |
@@ -983,9 +1066,12 @@ discard block |
||
983 | 1066 | //echo substr($file,strlen($dir)+1).'<br>'; |
984 | 1067 | //echo $file.'<br>'; |
985 | 1068 | $zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file); |
986 | - if(($count++) == 100) { // the file descriptor limit |
|
1069 | + if(($count++) == 100) |
|
1070 | + { |
|
1071 | +// the file descriptor limit |
|
987 | 1072 | $zip->close(); |
988 | - if(($zip = new ZipArchive())) { |
|
1073 | + if(($zip = new ZipArchive())) |
|
1074 | + { |
|
989 | 1075 | $zip->open($filename); |
990 | 1076 | $count =0; |
991 | 1077 | } |
@@ -1010,15 +1096,21 @@ discard block |
||
1010 | 1096 | { |
1011 | 1097 | //chdir($f); |
1012 | 1098 | //echo "Processing $f <br>"; |
1013 | - if ($path_name =='') $path_name = $f; |
|
1099 | + if ($path_name =='') |
|
1100 | + { |
|
1101 | + $path_name = $f; |
|
1102 | + } |
|
1014 | 1103 | $tlist = scandir($f); |
1015 | 1104 | $list = array(); |
1016 | 1105 | $i = $cnt; |
1017 | - while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
1106 | + while($file = $tlist[0]) |
|
1107 | + { |
|
1108 | + // remove all '.' and '..' and transfer to $list |
|
1018 | 1109 | { |
1019 | 1110 | if($file == '.' || $file == '..') |
1020 | 1111 | { |
1021 | 1112 | array_shift($tlist); |
1113 | + } |
|
1022 | 1114 | } |
1023 | 1115 | elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false) |
1024 | 1116 | { |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param string $app application storing data |
104 | 104 | * @param string $location location name for data |
105 | 105 | * @param mixed $data |
106 | - * @param int $expiration=0 expiration time in seconds, default 0 = never |
|
106 | + * @param int $expiration expiration time in seconds, default 0 = never |
|
107 | 107 | * @return boolean true if data could be stored, false otherwise |
108 | 108 | */ |
109 | 109 | static public function setCache($level,$app,$location,$data,$expiration=0) |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | * @param string $level use egw_cache::(TREE|INSTANCE|SESSION|REQUEST) |
139 | 139 | * @param string $app application storing data |
140 | 140 | * @param string|array $location location(s) name for data |
141 | - * @param callback $callback=null callback to get/create the value, if it's not cache |
|
141 | + * @param callback $callback callback to get/create the value, if it's not cache |
|
142 | 142 | * @param array $callback_params=array() array with parameters for the callback |
143 | - * @param int $expiration=0 expiration time in seconds, default 0 = never |
|
143 | + * @param int $expiration expiration time in seconds, default 0 = never |
|
144 | 144 | * @return mixed NULL if data not found in cache (and no callback specified) or |
145 | 145 | * if $location is an array: location => data pairs for existing location-data, non-existing is not returned |
146 | 146 | */ |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @param string $app application storing data |
243 | 243 | * @param string $location location name for data |
244 | 244 | * @param mixed $data |
245 | - * @param int $expiration=0 expiration time in seconds, default 0 = never |
|
245 | + * @param int $expiration expiration time in seconds, default 0 = never |
|
246 | 246 | * @return boolean true if data could be stored, false otherwise |
247 | 247 | */ |
248 | 248 | static public function setTree($app,$location,$data,$expiration=0) |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @param string $app application storing data |
258 | 258 | * @param string $location location name for data |
259 | - * @param callback $callback=null callback to get/create the value, if it's not cache |
|
259 | + * @param callback $callback callback to get/create the value, if it's not cache |
|
260 | 260 | * @param array $callback_params=array() array with parameters for the callback |
261 | - * @param int $expiration=0 expiration time in seconds, default 0 = never |
|
261 | + * @param int $expiration expiration time in seconds, default 0 = never |
|
262 | 262 | * @return mixed NULL if data not found in cache (and no callback specified) |
263 | 263 | */ |
264 | 264 | static public function getTree($app,$location,$callback=null,array $callback_params=array(),$expiration=0) |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | * @param string $app application storing data |
285 | 285 | * @param string $location location name for data |
286 | 286 | * @param mixed $data |
287 | - * @param int $expiration=0 expiration time in seconds, default 0 = never |
|
287 | + * @param int $expiration expiration time in seconds, default 0 = never |
|
288 | 288 | * @return boolean true if data could be stored, false otherwise |
289 | 289 | */ |
290 | 290 | static public function setInstance($app,$location,$data,$expiration=0) |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | * |
298 | 298 | * @param string $app application storing data |
299 | 299 | * @param string $location location name for data |
300 | - * @param callback $callback=null callback to get/create the value, if it's not cache |
|
300 | + * @param string[] $callback callback to get/create the value, if it's not cache |
|
301 | 301 | * @param array $callback_params=array() array with parameters for the callback |
302 | - * @param int $expiration=0 expiration time in seconds, default 0 = never |
|
302 | + * @param int $expiration expiration time in seconds, default 0 = never |
|
303 | 303 | * @return mixed NULL if data not found in cache (and no callback specified) |
304 | 304 | */ |
305 | 305 | static public function getInstance($app,$location,$callback=null,array $callback_params=array(),$expiration=0) |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param string $app application storing data |
326 | 326 | * @param string $location location name for data |
327 | 327 | * @param mixed $data |
328 | - * @param int $expiration=0 expiration time in seconds, default 0 = never |
|
328 | + * @param int $expiration expiration time in seconds, default 0 = never |
|
329 | 329 | * @return boolean true if data could be stored, false otherwise |
330 | 330 | */ |
331 | 331 | static public function setSession($app,$location,$data,$expiration=0) |
@@ -348,9 +348,9 @@ discard block |
||
348 | 348 | * |
349 | 349 | * @param string $app application storing data |
350 | 350 | * @param string $location location name for data |
351 | - * @param callback $callback=null callback to get/create the value, if it's not cache |
|
351 | + * @param callback $callback callback to get/create the value, if it's not cache |
|
352 | 352 | * @param array $callback_params=array() array with parameters for the callback |
353 | - * @param int $expiration=0 expiration time in seconds, default 0 = never |
|
353 | + * @param int $expiration expiration time in seconds, default 0 = never |
|
354 | 354 | * @return mixed NULL if data not found in cache (and no callback specified) |
355 | 355 | */ |
356 | 356 | static public function &getSession($app,$location,$callback=null,array $callback_params=array(),$expiration=0) |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | * @param string $app application storing data |
405 | 405 | * @param string $location location name for data |
406 | 406 | * @param mixed $data |
407 | - * @param int $expiration=0 expiration time is NOT used for REQUEST! |
|
407 | + * @param int $expiration expiration time is NOT used for REQUEST! |
|
408 | 408 | * @return boolean true if data could be stored, false otherwise |
409 | 409 | */ |
410 | 410 | static public function setRequest($app,$location,$data,$expiration=0) |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @param string $app application storing data |
422 | 422 | * @param string $location location name for data |
423 | - * @param callback $callback=null callback to get/create the value, if it's not cache |
|
423 | + * @param callback $callback callback to get/create the value, if it's not cache |
|
424 | 424 | * @param array $callback_params=array() array with parameters for the callback |
425 | - * @param int $expiration=0 expiration time is NOT used for REQUEST! |
|
425 | + * @param int $expiration expiration time is NOT used for REQUEST! |
|
426 | 426 | * @return mixed NULL if data not found in cache (and no callback specified) |
427 | 427 | */ |
428 | 428 | static public function getRequest($app,$location,$callback=null,array $callback_params=array(),$expiration=0) |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | * The returned provider already has an opened connection |
460 | 460 | * |
461 | 461 | * @param string $level egw_cache::(TREE|INSTANCE) or install_id |
462 | - * @param boolean $log_not_found=true false do not log if no provider found, used eg. to supress error via unsetCache during installation |
|
462 | + * @param boolean $log_not_found false do not log if no provider found, used eg. to supress error via unsetCache during installation |
|
463 | 463 | * @return egw_cache_provider |
464 | 464 | */ |
465 | 465 | static protected function get_provider($level, $log_not_found=true) |
@@ -525,7 +525,6 @@ discard block |
||
525 | 525 | * Get a system configuration, even if in setup and it's not read |
526 | 526 | * |
527 | 527 | * @param string $name |
528 | - * @param boolean $throw=true throw an exception, if we can't retriev the value |
|
529 | 528 | * @return string|boolean string with config or false if not found and !$throw |
530 | 529 | */ |
531 | 530 | static public function get_system_config($name,$throw=true) |
@@ -565,8 +564,7 @@ discard block |
||
565 | 564 | /** |
566 | 565 | * Flush (delete) whole (instance) cache or application/class specific part of it |
567 | 566 | * |
568 | - * @param $string $level=self::INSTANCE |
|
569 | - * @param string $app=null |
|
567 | + * @param string $app |
|
570 | 568 | */ |
571 | 569 | static public function flush($level=self::INSTANCE, $app=null) |
572 | 570 | { |
@@ -612,7 +610,7 @@ discard block |
||
612 | 610 | /** |
613 | 611 | * Generate a new instance key and by doing so effectivly flushes whole instance cache |
614 | 612 | * |
615 | - * @param string $install_id=null default use install_id of current instance |
|
613 | + * @param string $install_id default use install_id of current instance |
|
616 | 614 | * @return string new key also stored in self::$instance_key |
617 | 615 | */ |
618 | 616 | static public function generate_instance_key($install_id=null) |
@@ -633,8 +631,7 @@ discard block |
||
633 | 631 | * Get keys array from $level, $app and $location |
634 | 632 | * |
635 | 633 | * @param string $level egw_cache::(TREE|INSTANCE) or instance_id |
636 | - * @param string $app=null |
|
637 | - * @param string $location=null |
|
634 | + * @param string $location |
|
638 | 635 | * @return array |
639 | 636 | */ |
640 | 637 | static public function keys($level, $app=null, $location=null) |
@@ -714,7 +711,7 @@ discard block |
||
714 | 711 | * |
715 | 712 | * @param array $keys eg. array($level,$app,$location) |
716 | 713 | * @param mixed $data |
717 | - * @param int $expiration=0 |
|
714 | + * @param int $expiration |
|
718 | 715 | * @return boolean true on success, false on error |
719 | 716 | */ |
720 | 717 | function set(array $keys,$data,$expiration=0); |
@@ -769,7 +766,7 @@ discard block |
||
769 | 766 | /** |
770 | 767 | * Run several checks on a caching provider |
771 | 768 | * |
772 | - * @param boolean $verbose=false true: echo failed checks |
|
769 | + * @param boolean $verbose true: echo failed checks |
|
773 | 770 | * @return int number of failed checks |
774 | 771 | */ |
775 | 772 | function check($verbose=false) |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @var array |
82 | 82 | */ |
83 | - static $default_provider; // = array('egw_cache_files');// array('egw_cache_memcache','localhost'); |
|
83 | + static $default_provider; // = array('egw_cache_files');// array('egw_cache_memcache','localhost'); |
|
84 | 84 | |
85 | 85 | /** |
86 | 86 | * Maximum expiration time, if set unlimited expiration (=0) or bigger expiration times are replaced with that time |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | * @param int $expiration=0 expiration time in seconds, default 0 = never |
107 | 107 | * @return boolean true if data could be stored, false otherwise |
108 | 108 | */ |
109 | - static public function setCache($level,$app,$location,$data,$expiration=0) |
|
109 | + static public function setCache($level, $app, $location, $data, $expiration = 0) |
|
110 | 110 | { |
111 | 111 | //error_log(__METHOD__."('$level','$app','$location',".array2string($data).",$expiration)"); |
112 | - switch($level) |
|
112 | + switch ($level) |
|
113 | 113 | { |
114 | 114 | case self::SESSION: |
115 | 115 | case self::REQUEST: |
116 | - return call_user_func(array(__CLASS__,'set'.$level),$app,$location,$data,$expiration); |
|
116 | + return call_user_func(array(__CLASS__, 'set'.$level), $app, $location, $data, $expiration); |
|
117 | 117 | |
118 | 118 | case self::INSTANCE: |
119 | 119 | case self::TREE: |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | $expiration = self::$max_expiration; |
129 | 129 | } |
130 | - return $provider->set(self::keys($level,$app,$location),$data,$expiration); |
|
130 | + return $provider->set(self::keys($level, $app, $location), $data, $expiration); |
|
131 | 131 | } |
132 | 132 | throw new egw_exception_wrong_parameter(__METHOD__."() unknown level '$level'!"); |
133 | 133 | } |
@@ -144,15 +144,15 @@ discard block |
||
144 | 144 | * @return mixed NULL if data not found in cache (and no callback specified) or |
145 | 145 | * if $location is an array: location => data pairs for existing location-data, non-existing is not returned |
146 | 146 | */ |
147 | - static public function getCache($level,$app,$location,$callback=null,array $callback_params=array(),$expiration=0) |
|
147 | + static public function getCache($level, $app, $location, $callback = null, array $callback_params = array(), $expiration = 0) |
|
148 | 148 | { |
149 | - switch($level) |
|
149 | + switch ($level) |
|
150 | 150 | { |
151 | 151 | case self::SESSION: |
152 | 152 | case self::REQUEST: |
153 | - foreach((array)$location as $l) |
|
153 | + foreach ((array)$location as $l) |
|
154 | 154 | { |
155 | - $data[$l] = call_user_func(array(__CLASS__,'get'.$level),$app,$l,$callback,$callback_params,$expiration); |
|
155 | + $data[$l] = call_user_func(array(__CLASS__, 'get'.$level), $app, $l, $callback, $callback_params, $expiration); |
|
156 | 156 | } |
157 | 157 | return is_array($location) ? $data : $data[$l]; |
158 | 158 | |
@@ -172,34 +172,34 @@ discard block |
||
172 | 172 | } |
173 | 173 | if (is_a($provider, 'egw_cache_provider_multiple')) |
174 | 174 | { |
175 | - $data = $provider->mget($keys=self::keys($level,$app,$location)); |
|
175 | + $data = $provider->mget($keys = self::keys($level, $app, $location)); |
|
176 | 176 | } |
177 | 177 | else // default implementation calls get multiple times |
178 | 178 | { |
179 | 179 | $data = array(); |
180 | - foreach($location as $l) |
|
180 | + foreach ($location as $l) |
|
181 | 181 | { |
182 | - $data[$l] = $provider->get($keys=self::keys($level,$app,$l)); |
|
182 | + $data[$l] = $provider->get($keys = self::keys($level, $app, $l)); |
|
183 | 183 | if (!isset($data[$l])) unset($data[$l]); |
184 | 184 | } |
185 | 185 | } |
186 | 186 | } |
187 | 187 | else |
188 | 188 | { |
189 | - $data = $provider->get($keys=self::keys($level,$app,$location)); |
|
189 | + $data = $provider->get($keys = self::keys($level, $app, $location)); |
|
190 | 190 | if (is_null($data) && !is_null($callback)) |
191 | 191 | { |
192 | - $data = call_user_func_array($callback,$callback_params); |
|
192 | + $data = call_user_func_array($callback, $callback_params); |
|
193 | 193 | // limit expiration to configured maximum time |
194 | 194 | if (isset(self::$max_expiration) && (!$expiration || $expiration > self::$max_expiration)) |
195 | 195 | { |
196 | 196 | $expiration = self::$max_expiration; |
197 | 197 | } |
198 | - $provider->set($keys,$data,$expiration); |
|
198 | + $provider->set($keys, $data, $expiration); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | } |
202 | - catch(Exception $e) { |
|
202 | + catch (Exception $e) { |
|
203 | 203 | unset($e); |
204 | 204 | $data = null; |
205 | 205 | } |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | * @param string $location location name for data |
217 | 217 | * @return boolean true if data was set, false if not (like isset()) |
218 | 218 | */ |
219 | - static public function unsetCache($level,$app,$location) |
|
219 | + static public function unsetCache($level, $app, $location) |
|
220 | 220 | { |
221 | - switch($level) |
|
221 | + switch ($level) |
|
222 | 222 | { |
223 | 223 | case self::SESSION: |
224 | 224 | case self::REQUEST: |
225 | - return call_user_func(array(__CLASS__,'unset'.$level),$app,$location); |
|
225 | + return call_user_func(array(__CLASS__, 'unset'.$level), $app, $location); |
|
226 | 226 | |
227 | 227 | case self::INSTANCE: |
228 | 228 | case self::TREE: |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | { |
232 | 232 | return false; |
233 | 233 | } |
234 | - return $provider->delete(self::keys($level,$app,$location)); |
|
234 | + return $provider->delete(self::keys($level, $app, $location)); |
|
235 | 235 | } |
236 | 236 | throw new egw_exception_wrong_parameter(__METHOD__."() unknown level '$level'!"); |
237 | 237 | } |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | * @param int $expiration=0 expiration time in seconds, default 0 = never |
246 | 246 | * @return boolean true if data could be stored, false otherwise |
247 | 247 | */ |
248 | - static public function setTree($app,$location,$data,$expiration=0) |
|
248 | + static public function setTree($app, $location, $data, $expiration = 0) |
|
249 | 249 | { |
250 | 250 | //error_log(__METHOD__."('$app','$location',".array2string($data).",$expiration)"); |
251 | - return self::setCache(self::TREE,$app,$location,$data,$expiration); |
|
251 | + return self::setCache(self::TREE, $app, $location, $data, $expiration); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -261,9 +261,9 @@ discard block |
||
261 | 261 | * @param int $expiration=0 expiration time in seconds, default 0 = never |
262 | 262 | * @return mixed NULL if data not found in cache (and no callback specified) |
263 | 263 | */ |
264 | - static public function getTree($app,$location,$callback=null,array $callback_params=array(),$expiration=0) |
|
264 | + static public function getTree($app, $location, $callback = null, array $callback_params = array(), $expiration = 0) |
|
265 | 265 | { |
266 | - return self::getCache(self::TREE,$app,$location,$callback,$callback_params,$expiration); |
|
266 | + return self::getCache(self::TREE, $app, $location, $callback, $callback_params, $expiration); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -273,9 +273,9 @@ discard block |
||
273 | 273 | * @param string $location location name for data |
274 | 274 | * @return boolean true if data was set, false if not (like isset()) |
275 | 275 | */ |
276 | - static public function unsetTree($app,$location) |
|
276 | + static public function unsetTree($app, $location) |
|
277 | 277 | { |
278 | - return self::unsetCache(self::TREE,$app,$location); |
|
278 | + return self::unsetCache(self::TREE, $app, $location); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | * @param int $expiration=0 expiration time in seconds, default 0 = never |
288 | 288 | * @return boolean true if data could be stored, false otherwise |
289 | 289 | */ |
290 | - static public function setInstance($app,$location,$data,$expiration=0) |
|
290 | + static public function setInstance($app, $location, $data, $expiration = 0) |
|
291 | 291 | { |
292 | - return self::setCache(self::INSTANCE,$app,$location,$data,$expiration); |
|
292 | + return self::setCache(self::INSTANCE, $app, $location, $data, $expiration); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | * @param int $expiration=0 expiration time in seconds, default 0 = never |
303 | 303 | * @return mixed NULL if data not found in cache (and no callback specified) |
304 | 304 | */ |
305 | - static public function getInstance($app,$location,$callback=null,array $callback_params=array(),$expiration=0) |
|
305 | + static public function getInstance($app, $location, $callback = null, array $callback_params = array(), $expiration = 0) |
|
306 | 306 | { |
307 | - return self::getCache(self::INSTANCE,$app,$location,$callback,$callback_params,$expiration); |
|
307 | + return self::getCache(self::INSTANCE, $app, $location, $callback, $callback_params, $expiration); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -314,9 +314,9 @@ discard block |
||
314 | 314 | * @param string $location location name for data |
315 | 315 | * @return boolean true if data was set, false if not (like isset()) |
316 | 316 | */ |
317 | - static public function unsetInstance($app,$location) |
|
317 | + static public function unsetInstance($app, $location) |
|
318 | 318 | { |
319 | - return self::unsetCache(self::INSTANCE,$app,$location); |
|
319 | + return self::unsetCache(self::INSTANCE, $app, $location); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -328,13 +328,13 @@ discard block |
||
328 | 328 | * @param int $expiration=0 expiration time in seconds, default 0 = never |
329 | 329 | * @return boolean true if data could be stored, false otherwise |
330 | 330 | */ |
331 | - static public function setSession($app,$location,$data,$expiration=0) |
|
331 | + static public function setSession($app, $location, $data, $expiration = 0) |
|
332 | 332 | { |
333 | - unset($expiration); // not used, but required by function signature |
|
333 | + unset($expiration); // not used, but required by function signature |
|
334 | 334 | if (isset($_SESSION[egw_session::EGW_SESSION_ENCRYPTED])) |
335 | 335 | { |
336 | 336 | if (egw_session::ERROR_LOG_DEBUG) error_log(__METHOD__.' called after session was encrypted --> ignored!'); |
337 | - return false; // can no longer store something in the session, eg. because commit_session() was called |
|
337 | + return false; // can no longer store something in the session, eg. because commit_session() was called |
|
338 | 338 | } |
339 | 339 | $_SESSION[egw_session::EGW_APPSESSION_VAR][$app][$location] = $data; |
340 | 340 | |
@@ -353,17 +353,17 @@ discard block |
||
353 | 353 | * @param int $expiration=0 expiration time in seconds, default 0 = never |
354 | 354 | * @return mixed NULL if data not found in cache (and no callback specified) |
355 | 355 | */ |
356 | - static public function &getSession($app,$location,$callback=null,array $callback_params=array(),$expiration=0) |
|
356 | + static public function &getSession($app, $location, $callback = null, array $callback_params = array(), $expiration = 0) |
|
357 | 357 | { |
358 | - unset($expiration); // not used, but required by function signature |
|
358 | + unset($expiration); // not used, but required by function signature |
|
359 | 359 | if (isset($_SESSION[egw_session::EGW_SESSION_ENCRYPTED])) |
360 | 360 | { |
361 | 361 | if (egw_session::ERROR_LOG_DEBUG) error_log(__METHOD__.' called after session was encrypted --> ignored!'); |
362 | - return null; // can no longer store something in the session, eg. because commit_session() was called |
|
362 | + return null; // can no longer store something in the session, eg. because commit_session() was called |
|
363 | 363 | } |
364 | 364 | if (!isset($_SESSION[egw_session::EGW_APPSESSION_VAR][$app][$location]) && !is_null($callback)) |
365 | 365 | { |
366 | - $_SESSION[egw_session::EGW_APPSESSION_VAR][$app][$location] = call_user_func_array($callback,$callback_params); |
|
366 | + $_SESSION[egw_session::EGW_APPSESSION_VAR][$app][$location] = call_user_func_array($callback, $callback_params); |
|
367 | 367 | } |
368 | 368 | return $_SESSION[egw_session::EGW_APPSESSION_VAR][$app][$location]; |
369 | 369 | } |
@@ -375,12 +375,12 @@ discard block |
||
375 | 375 | * @param string $location location name for data |
376 | 376 | * @return boolean true if data was set, false if not (like isset()) |
377 | 377 | */ |
378 | - static public function unsetSession($app,$location) |
|
378 | + static public function unsetSession($app, $location) |
|
379 | 379 | { |
380 | 380 | if (isset($_SESSION[egw_session::EGW_SESSION_ENCRYPTED])) |
381 | 381 | { |
382 | 382 | if (egw_session::ERROR_LOG_DEBUG) error_log(__METHOD__.' called after session was encrypted --> ignored!'); |
383 | - return false; // can no longer store something in the session, eg. because commit_session() was called |
|
383 | + return false; // can no longer store something in the session, eg. because commit_session() was called |
|
384 | 384 | } |
385 | 385 | if (!isset($_SESSION[egw_session::EGW_APPSESSION_VAR][$app][$location])) |
386 | 386 | { |
@@ -407,9 +407,9 @@ discard block |
||
407 | 407 | * @param int $expiration=0 expiration time is NOT used for REQUEST! |
408 | 408 | * @return boolean true if data could be stored, false otherwise |
409 | 409 | */ |
410 | - static public function setRequest($app,$location,$data,$expiration=0) |
|
410 | + static public function setRequest($app, $location, $data, $expiration = 0) |
|
411 | 411 | { |
412 | - unset($expiration); // not used, but required by function signature |
|
412 | + unset($expiration); // not used, but required by function signature |
|
413 | 413 | self::$request_cache[$app][$location] = $data; |
414 | 414 | |
415 | 415 | return true; |
@@ -425,12 +425,12 @@ discard block |
||
425 | 425 | * @param int $expiration=0 expiration time is NOT used for REQUEST! |
426 | 426 | * @return mixed NULL if data not found in cache (and no callback specified) |
427 | 427 | */ |
428 | - static public function getRequest($app,$location,$callback=null,array $callback_params=array(),$expiration=0) |
|
428 | + static public function getRequest($app, $location, $callback = null, array $callback_params = array(), $expiration = 0) |
|
429 | 429 | { |
430 | - unset($expiration); // not used, but required by function signature |
|
430 | + unset($expiration); // not used, but required by function signature |
|
431 | 431 | if (!isset(self::$request_cache[$app][$location]) && !is_null($callback)) |
432 | 432 | { |
433 | - self::$request_cache[$app][$location] = call_user_func_array($callback,$callback_params); |
|
433 | + self::$request_cache[$app][$location] = call_user_func_array($callback, $callback_params); |
|
434 | 434 | } |
435 | 435 | return self::$request_cache[$app][$location]; |
436 | 436 | } |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | * @param string $location location name for data |
443 | 443 | * @return boolean true if data was set, false if not (like isset()) |
444 | 444 | */ |
445 | - static public function unsetRequest($app,$location) |
|
445 | + static public function unsetRequest($app, $location) |
|
446 | 446 | { |
447 | 447 | if (!isset(self::$request_cache[$app][$location])) |
448 | 448 | { |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | * @param boolean $log_not_found=true false do not log if no provider found, used eg. to supress error via unsetCache during installation |
463 | 463 | * @return egw_cache_provider |
464 | 464 | */ |
465 | - static protected function get_provider($level, $log_not_found=true) |
|
465 | + static protected function get_provider($level, $log_not_found = true) |
|
466 | 466 | { |
467 | 467 | static $providers = array(); |
468 | 468 | |
@@ -483,13 +483,13 @@ discard block |
||
483 | 483 | } |
484 | 484 | else |
485 | 485 | { |
486 | - $providers[$level] = false; // no provider specified |
|
486 | + $providers[$level] = false; // no provider specified |
|
487 | 487 | $reason = 'no provider specified'; |
488 | 488 | } |
489 | 489 | } |
490 | 490 | elseif (!$params) |
491 | 491 | { |
492 | - $providers[$level] = false; // cache for $level disabled |
|
492 | + $providers[$level] = false; // cache for $level disabled |
|
493 | 493 | $reason = "cache for $level disabled"; |
494 | 494 | } |
495 | 495 | else |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | $class = array_shift($params); |
500 | 500 | if (!class_exists($class)) |
501 | 501 | { |
502 | - $providers[$level] = false; // provider class not found |
|
502 | + $providers[$level] = false; // provider class not found |
|
503 | 503 | $reason = "provider $class not found"; |
504 | 504 | } |
505 | 505 | else |
@@ -508,9 +508,9 @@ discard block |
||
508 | 508 | { |
509 | 509 | $providers[$level] = new $class($params); |
510 | 510 | } |
511 | - catch(Exception $e) |
|
511 | + catch (Exception $e) |
|
512 | 512 | { |
513 | - $providers[$level] = false; // eg. could not open connection to backend |
|
513 | + $providers[$level] = false; // eg. could not open connection to backend |
|
514 | 514 | $reason = "error instanciating provider $class: ".$e->getMessage(); |
515 | 515 | } |
516 | 516 | } |
@@ -528,35 +528,35 @@ discard block |
||
528 | 528 | * @param boolean $throw=true throw an exception, if we can't retriev the value |
529 | 529 | * @return string|boolean string with config or false if not found and !$throw |
530 | 530 | */ |
531 | - static public function get_system_config($name,$throw=true) |
|
531 | + static public function get_system_config($name, $throw = true) |
|
532 | 532 | { |
533 | - if(!isset($GLOBALS['egw_info']['server'][$name])) |
|
533 | + if (!isset($GLOBALS['egw_info']['server'][$name])) |
|
534 | 534 | { |
535 | 535 | if (isset($GLOBALS['egw_setup']) && isset($GLOBALS['egw_setup']->db) || $GLOBALS['egw']->db) |
536 | 536 | { |
537 | 537 | $db = $GLOBALS['egw']->db ? $GLOBALS['egw']->db : $GLOBALS['egw_setup']->db; |
538 | 538 | |
539 | 539 | try { |
540 | - if (($rs = $db->select(config::TABLE,'config_value',array( |
|
540 | + if (($rs = $db->select(config::TABLE, 'config_value', array( |
|
541 | 541 | 'config_app' => 'phpgwapi', |
542 | 542 | 'config_name' => $name, |
543 | - ),__LINE__,__FILE__))) |
|
543 | + ), __LINE__, __FILE__))) |
|
544 | 544 | { |
545 | 545 | $GLOBALS['egw_info']['server'][$name] = $rs->fetchColumn(); |
546 | 546 | } |
547 | 547 | else |
548 | 548 | { |
549 | - error_log(__METHOD__."('$name', $throw) config value NOT found!");//.function_backtrace()); |
|
549 | + error_log(__METHOD__."('$name', $throw) config value NOT found!"); //.function_backtrace()); |
|
550 | 550 | } |
551 | 551 | } |
552 | - catch(egw_exception_db $e) |
|
552 | + catch (egw_exception_db $e) |
|
553 | 553 | { |
554 | - if ($throw) error_log(__METHOD__."('$name', $throw) cound NOT query value: ".$e->getMessage());//.function_backtrace()); |
|
554 | + if ($throw) error_log(__METHOD__."('$name', $throw) cound NOT query value: ".$e->getMessage()); //.function_backtrace()); |
|
555 | 555 | } |
556 | 556 | } |
557 | 557 | if (!$GLOBALS['egw_info']['server'][$name] && $throw) |
558 | 558 | { |
559 | - throw new Exception (__METHOD__."($name) \$GLOBALS['egw_info']['server']['$name'] is NOT set!"); |
|
559 | + throw new Exception(__METHOD__."($name) \$GLOBALS['egw_info']['server']['$name'] is NOT set!"); |
|
560 | 560 | } |
561 | 561 | } |
562 | 562 | return $GLOBALS['egw_info']['server'][$name]; |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | * @param $string $level=self::INSTANCE |
569 | 569 | * @param string $app=null |
570 | 570 | */ |
571 | - static public function flush($level=self::INSTANCE, $app=null) |
|
571 | + static public function flush($level = self::INSTANCE, $app = null) |
|
572 | 572 | { |
573 | 573 | $ret = true; |
574 | 574 | if (!($provider = self::get_provider($level))) |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | * @param string $install_id=null default use install_id of current instance |
616 | 616 | * @return string new key also stored in self::$instance_key |
617 | 617 | */ |
618 | - static public function generate_instance_key($install_id=null) |
|
618 | + static public function generate_instance_key($install_id = null) |
|
619 | 619 | { |
620 | 620 | if (!isset($install_id)) |
621 | 621 | { |
@@ -637,18 +637,18 @@ discard block |
||
637 | 637 | * @param string $location=null |
638 | 638 | * @return array |
639 | 639 | */ |
640 | - static public function keys($level, $app=null, $location=null) |
|
640 | + static public function keys($level, $app = null, $location = null) |
|
641 | 641 | { |
642 | 642 | static $tree_key = null; |
643 | 643 | |
644 | - switch($level) |
|
644 | + switch ($level) |
|
645 | 645 | { |
646 | 646 | case self::TREE: |
647 | 647 | if (!isset($tree_key)) |
648 | 648 | { |
649 | - $tree_key = $level.'-'.str_replace(array(':','/','\\'),'-', self::$egw_server_root); |
|
649 | + $tree_key = $level.'-'.str_replace(array(':', '/', '\\'), '-', self::$egw_server_root); |
|
650 | 650 | // add charset to key, if not utf-8 (as everything we store depends on charset!) |
651 | - if (($charset = self::get_system_config('system_charset',false)) && $charset != 'utf-8') |
|
651 | + if (($charset = self::get_system_config('system_charset', false)) && $charset != 'utf-8') |
|
652 | 652 | { |
653 | 653 | $tree_key .= '-'.$charset; |
654 | 654 | } |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | * @param int $expiration=0 |
718 | 718 | * @return boolean true on success, false on error |
719 | 719 | */ |
720 | - function set(array $keys,$data,$expiration=0); |
|
720 | + function set(array $keys, $data, $expiration = 0); |
|
721 | 721 | |
722 | 722 | /** |
723 | 723 | * Get some data from the cache |
@@ -772,34 +772,34 @@ discard block |
||
772 | 772 | * @param boolean $verbose=false true: echo failed checks |
773 | 773 | * @return int number of failed checks |
774 | 774 | */ |
775 | - function check($verbose=false) |
|
775 | + function check($verbose = false) |
|
776 | 776 | { |
777 | 777 | // set us up as provider for egw_cache class |
778 | 778 | $GLOBALS['egw_info']['server']['install_id'] = md5(microtime(true)); |
779 | 779 | egw_cache::$default_provider = $this; |
780 | 780 | |
781 | 781 | $failed = 0; |
782 | - foreach(array( |
|
782 | + foreach (array( |
|
783 | 783 | egw_cache::TREE => 'tree', |
784 | 784 | egw_cache::INSTANCE => 'instance', |
785 | 785 | ) as $level => $label) |
786 | 786 | { |
787 | 787 | $locations = array(); |
788 | - foreach(array('string',123,true,false,null,array(),array(1,2,3)) as $data) |
|
788 | + foreach (array('string', 123, true, false, null, array(), array(1, 2, 3)) as $data) |
|
789 | 789 | { |
790 | 790 | $location = md5(microtime(true).$label.serialize($data)); |
791 | - $get_before_set = $this->get(array($level,__CLASS__,$location)); |
|
791 | + $get_before_set = $this->get(array($level, __CLASS__, $location)); |
|
792 | 792 | if (!is_null($get_before_set)) |
793 | 793 | { |
794 | 794 | if ($verbose) echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
795 | 795 | ++$failed; |
796 | 796 | } |
797 | - if (($set = $this->set(array($level,__CLASS__,$location), $data, 10)) !== true) |
|
797 | + if (($set = $this->set(array($level, __CLASS__, $location), $data, 10)) !== true) |
|
798 | 798 | { |
799 | 799 | if ($verbose) echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
800 | 800 | ++$failed; |
801 | 801 | } |
802 | - $get_after_set = $this->get(array($level,__CLASS__,$location)); |
|
802 | + $get_after_set = $this->get(array($level, __CLASS__, $location)); |
|
803 | 803 | if ($get_after_set !== $data) |
804 | 804 | { |
805 | 805 | if ($verbose) echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
@@ -807,19 +807,19 @@ discard block |
||
807 | 807 | } |
808 | 808 | if (is_a($this, 'egw_cache_provider_multiple')) |
809 | 809 | { |
810 | - $mget_after_set = $this->mget(array($level,__CLASS__,array($location))); |
|
810 | + $mget_after_set = $this->mget(array($level, __CLASS__, array($location))); |
|
811 | 811 | if ($mget_after_set[$location] !== $data) |
812 | 812 | { |
813 | 813 | if ($verbose) echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
814 | 814 | ++$failed; |
815 | 815 | } |
816 | 816 | } |
817 | - if (($delete = $this->delete(array($level,__CLASS__,$location))) !== true) |
|
817 | + if (($delete = $this->delete(array($level, __CLASS__, $location))) !== true) |
|
818 | 818 | { |
819 | 819 | if ($verbose) echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
820 | 820 | ++$failed; |
821 | 821 | } |
822 | - $get_after_delete = $this->get(array($level,__CLASS__,$location)); |
|
822 | + $get_after_delete = $this->get(array($level, __CLASS__, $location)); |
|
823 | 823 | if (!is_null($get_after_delete)) |
824 | 824 | { |
825 | 825 | if ($verbose) echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
@@ -829,13 +829,13 @@ discard block |
||
829 | 829 | if (is_a($this, 'egw_cache_provider_multiple')) |
830 | 830 | { |
831 | 831 | $locations[$location] = $data; |
832 | - $mget_after_delete = $this->mget(array($level,__CLASS__,array($location))); |
|
832 | + $mget_after_delete = $this->mget(array($level, __CLASS__, array($location))); |
|
833 | 833 | if (isset($mget_after_delete[$location])) |
834 | 834 | { |
835 | 835 | if ($verbose) echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
836 | 836 | ++$failed; |
837 | 837 | } |
838 | - $this->set(array($level,__CLASS__,$location), $data, 10); |
|
838 | + $this->set(array($level, __CLASS__, $location), $data, 10); |
|
839 | 839 | } |
840 | 840 | elseif (!is_null($data)) // emulation can NOT distinquish between null and not set |
841 | 841 | { |
@@ -845,11 +845,11 @@ discard block |
||
845 | 845 | } |
846 | 846 | // get all above in one request |
847 | 847 | $keys = array_keys($locations); |
848 | - $keys_bogus = array_merge(array('not-set'),array_keys($locations),array('not-set-too')); |
|
848 | + $keys_bogus = array_merge(array('not-set'), array_keys($locations), array('not-set-too')); |
|
849 | 849 | if (is_a($this, 'egw_cache_provider_multiple')) |
850 | 850 | { |
851 | - $mget = $this->mget(array($level,__CLASS__,$keys)); |
|
852 | - $mget_bogus = $this->mget(array($level,__CLASS__,$keys_bogus)); |
|
851 | + $mget = $this->mget(array($level, __CLASS__, $keys)); |
|
852 | + $mget_bogus = $this->mget(array($level, __CLASS__, $keys_bogus)); |
|
853 | 853 | } |
854 | 854 | else |
855 | 855 | { |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | */ |
882 | 882 | function flush(array $keys) |
883 | 883 | { |
884 | - unset($keys); // required by function signature |
|
884 | + unset($keys); // required by function signature |
|
885 | 885 | return false; |
886 | 886 | } |
887 | 887 | } |
@@ -180,7 +180,10 @@ discard block |
||
180 | 180 | foreach($location as $l) |
181 | 181 | { |
182 | 182 | $data[$l] = $provider->get($keys=self::keys($level,$app,$l)); |
183 | - if (!isset($data[$l])) unset($data[$l]); |
|
183 | + if (!isset($data[$l])) |
|
184 | + { |
|
185 | + unset($data[$l]); |
|
186 | + } |
|
184 | 187 | } |
185 | 188 | } |
186 | 189 | } |
@@ -333,7 +336,10 @@ discard block |
||
333 | 336 | unset($expiration); // not used, but required by function signature |
334 | 337 | if (isset($_SESSION[egw_session::EGW_SESSION_ENCRYPTED])) |
335 | 338 | { |
336 | - if (egw_session::ERROR_LOG_DEBUG) error_log(__METHOD__.' called after session was encrypted --> ignored!'); |
|
339 | + if (egw_session::ERROR_LOG_DEBUG) |
|
340 | + { |
|
341 | + error_log(__METHOD__.' called after session was encrypted --> ignored!'); |
|
342 | + } |
|
337 | 343 | return false; // can no longer store something in the session, eg. because commit_session() was called |
338 | 344 | } |
339 | 345 | $_SESSION[egw_session::EGW_APPSESSION_VAR][$app][$location] = $data; |
@@ -358,7 +364,10 @@ discard block |
||
358 | 364 | unset($expiration); // not used, but required by function signature |
359 | 365 | if (isset($_SESSION[egw_session::EGW_SESSION_ENCRYPTED])) |
360 | 366 | { |
361 | - if (egw_session::ERROR_LOG_DEBUG) error_log(__METHOD__.' called after session was encrypted --> ignored!'); |
|
367 | + if (egw_session::ERROR_LOG_DEBUG) |
|
368 | + { |
|
369 | + error_log(__METHOD__.' called after session was encrypted --> ignored!'); |
|
370 | + } |
|
362 | 371 | return null; // can no longer store something in the session, eg. because commit_session() was called |
363 | 372 | } |
364 | 373 | if (!isset($_SESSION[egw_session::EGW_APPSESSION_VAR][$app][$location]) && !is_null($callback)) |
@@ -379,7 +388,10 @@ discard block |
||
379 | 388 | { |
380 | 389 | if (isset($_SESSION[egw_session::EGW_SESSION_ENCRYPTED])) |
381 | 390 | { |
382 | - if (egw_session::ERROR_LOG_DEBUG) error_log(__METHOD__.' called after session was encrypted --> ignored!'); |
|
391 | + if (egw_session::ERROR_LOG_DEBUG) |
|
392 | + { |
|
393 | + error_log(__METHOD__.' called after session was encrypted --> ignored!'); |
|
394 | + } |
|
383 | 395 | return false; // can no longer store something in the session, eg. because commit_session() was called |
384 | 396 | } |
385 | 397 | if (!isset($_SESSION[egw_session::EGW_APPSESSION_VAR][$app][$location])) |
@@ -466,7 +478,10 @@ discard block |
||
466 | 478 | { |
467 | 479 | static $providers = array(); |
468 | 480 | |
469 | - if ($level != self::TREE) $level = self::INSTANCE; |
|
481 | + if ($level != self::TREE) |
|
482 | + { |
|
483 | + $level = self::INSTANCE; |
|
484 | + } |
|
470 | 485 | |
471 | 486 | if (!isset($providers[$level])) |
472 | 487 | { |
@@ -477,10 +492,13 @@ discard block |
||
477 | 492 | } |
478 | 493 | if (!isset($params)) |
479 | 494 | { |
480 | - if ($level == self::TREE) // if no tree level provider use the instance level one |
|
495 | + if ($level == self::TREE) |
|
496 | + { |
|
497 | + // if no tree level provider use the instance level one |
|
481 | 498 | { |
482 | 499 | $providers[$level] = self::get_provider(self::INSTANCE); |
483 | 500 | } |
501 | + } |
|
484 | 502 | else |
485 | 503 | { |
486 | 504 | $providers[$level] = false; // no provider specified |
@@ -494,7 +512,10 @@ discard block |
||
494 | 512 | } |
495 | 513 | else |
496 | 514 | { |
497 | - if (!is_array($params)) $params = (array)$params; |
|
515 | + if (!is_array($params)) |
|
516 | + { |
|
517 | + $params = (array)$params; |
|
518 | + } |
|
498 | 519 | |
499 | 520 | $class = array_shift($params); |
500 | 521 | if (!class_exists($class)) |
@@ -515,7 +536,10 @@ discard block |
||
515 | 536 | } |
516 | 537 | } |
517 | 538 | } |
518 | - if (!$providers[$level] && $log_not_found) error_log(__METHOD__."($level) no provider found ($reason)!".function_backtrace()); |
|
539 | + if (!$providers[$level] && $log_not_found) |
|
540 | + { |
|
541 | + error_log(__METHOD__."($level) no provider found ($reason)!".function_backtrace()); |
|
542 | + } |
|
519 | 543 | } |
520 | 544 | //error_log(__METHOD__."($level) = ".array2string($providers[$level]).', cache_provider='.array2string($GLOBALS['egw_info']['server']['cache_provider_'.strtolower($level)])); |
521 | 545 | return $providers[$level]; |
@@ -551,7 +575,11 @@ discard block |
||
551 | 575 | } |
552 | 576 | catch(egw_exception_db $e) |
553 | 577 | { |
554 | - if ($throw) error_log(__METHOD__."('$name', $throw) cound NOT query value: ".$e->getMessage());//.function_backtrace()); |
|
578 | + if ($throw) |
|
579 | + { |
|
580 | + error_log(__METHOD__."('$name', $throw) cound NOT query value: ".$e->getMessage()); |
|
581 | + } |
|
582 | + //.function_backtrace()); |
|
555 | 583 | } |
556 | 584 | } |
557 | 585 | if (!$GLOBALS['egw_info']['server'][$name] && $throw) |
@@ -659,7 +687,10 @@ discard block |
||
659 | 687 | if ($level !== $GLOBALS['egw_info']['server']['install_id']) |
660 | 688 | { |
661 | 689 | $level_key = self::getTree(__CLASS__, $level); |
662 | - if (!isset($level_key)) $level_key = self::generate_instance_key($level); |
|
690 | + if (!isset($level_key)) |
|
691 | + { |
|
692 | + $level_key = self::generate_instance_key($level); |
|
693 | + } |
|
663 | 694 | break; |
664 | 695 | } |
665 | 696 | // fall-through for current instance |
@@ -668,7 +699,10 @@ discard block |
||
668 | 699 | { |
669 | 700 | self::$instance_key = self::getTree(__CLASS__, self::get_system_config('install_id')); |
670 | 701 | //error_log(__METHOD__."('$level',...) instance_key read from tree-cache=".array2string(self::$instance_key)); |
671 | - if (!isset(self::$instance_key)) self::$instance_key = self::generate_instance_key(); |
|
702 | + if (!isset(self::$instance_key)) |
|
703 | + { |
|
704 | + self::$instance_key = self::generate_instance_key(); |
|
705 | + } |
|
672 | 706 | } |
673 | 707 | $level_key = self::$instance_key; |
674 | 708 | break; |
@@ -677,7 +711,10 @@ discard block |
||
677 | 711 | if (isset($app)) |
678 | 712 | { |
679 | 713 | $keys[] = $app; |
680 | - if (isset($location)) $keys[] = $location; |
|
714 | + if (isset($location)) |
|
715 | + { |
|
716 | + $keys[] = $location; |
|
717 | + } |
|
681 | 718 | } |
682 | 719 | return $keys; |
683 | 720 | } |
@@ -791,18 +828,27 @@ discard block |
||
791 | 828 | $get_before_set = $this->get(array($level,__CLASS__,$location)); |
792 | 829 | if (!is_null($get_before_set)) |
793 | 830 | { |
794 | - if ($verbose) echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
|
831 | + if ($verbose) |
|
832 | + { |
|
833 | + echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
|
834 | + } |
|
795 | 835 | ++$failed; |
796 | 836 | } |
797 | 837 | if (($set = $this->set(array($level,__CLASS__,$location), $data, 10)) !== true) |
798 | 838 | { |
799 | - if ($verbose) echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
|
839 | + if ($verbose) |
|
840 | + { |
|
841 | + echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
|
842 | + } |
|
800 | 843 | ++$failed; |
801 | 844 | } |
802 | 845 | $get_after_set = $this->get(array($level,__CLASS__,$location)); |
803 | 846 | if ($get_after_set !== $data) |
804 | 847 | { |
805 | - if ($verbose) echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
|
848 | + if ($verbose) |
|
849 | + { |
|
850 | + echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
|
851 | + } |
|
806 | 852 | ++$failed; |
807 | 853 | } |
808 | 854 | if (is_a($this, 'egw_cache_provider_multiple')) |
@@ -810,19 +856,28 @@ discard block |
||
810 | 856 | $mget_after_set = $this->mget(array($level,__CLASS__,array($location))); |
811 | 857 | if ($mget_after_set[$location] !== $data) |
812 | 858 | { |
813 | - if ($verbose) echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
|
859 | + if ($verbose) |
|
860 | + { |
|
861 | + echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
|
862 | + } |
|
814 | 863 | ++$failed; |
815 | 864 | } |
816 | 865 | } |
817 | 866 | if (($delete = $this->delete(array($level,__CLASS__,$location))) !== true) |
818 | 867 | { |
819 | - if ($verbose) echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
|
868 | + if ($verbose) |
|
869 | + { |
|
870 | + echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
|
871 | + } |
|
820 | 872 | ++$failed; |
821 | 873 | } |
822 | 874 | $get_after_delete = $this->get(array($level,__CLASS__,$location)); |
823 | 875 | if (!is_null($get_after_delete)) |
824 | 876 | { |
825 | - if ($verbose) echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
|
877 | + if ($verbose) |
|
878 | + { |
|
879 | + echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
|
880 | + } |
|
826 | 881 | ++$failed; |
827 | 882 | } |
828 | 883 | // prepare for mget of everything |
@@ -832,14 +887,20 @@ discard block |
||
832 | 887 | $mget_after_delete = $this->mget(array($level,__CLASS__,array($location))); |
833 | 888 | if (isset($mget_after_delete[$location])) |
834 | 889 | { |
835 | - if ($verbose) echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
|
890 | + if ($verbose) |
|
891 | + { |
|
892 | + echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
|
893 | + } |
|
836 | 894 | ++$failed; |
837 | 895 | } |
838 | 896 | $this->set(array($level,__CLASS__,$location), $data, 10); |
839 | 897 | } |
840 | - elseif (!is_null($data)) // emulation can NOT distinquish between null and not set |
|
898 | + elseif (!is_null($data)) |
|
899 | + { |
|
900 | + // emulation can NOT distinquish between null and not set |
|
841 | 901 | { |
842 | 902 | $locations[$location] = $data; |
903 | + } |
|
843 | 904 | egw_cache::setCache($level, __CLASS__, $location, $data); |
844 | 905 | } |
845 | 906 | } |
@@ -858,12 +919,18 @@ discard block |
||
858 | 919 | } |
859 | 920 | if ($mget !== $locations) |
860 | 921 | { |
861 | - if ($verbose) echo "$label: mget=<br/>".array2string($mget)." !==<br/>".array2string($locations)."\n"; |
|
922 | + if ($verbose) |
|
923 | + { |
|
924 | + echo "$label: mget=<br/>".array2string($mget)." !==<br/>".array2string($locations)."\n"; |
|
925 | + } |
|
862 | 926 | ++$failed; |
863 | 927 | } |
864 | 928 | if ($mget_bogus !== $locations) |
865 | 929 | { |
866 | - if ($verbose) echo "$label: mget(".array2string($keys_bogus).")=<br/>".array2string($mget_bogus)." !==<br/>".array2string($locations)."\n"; |
|
930 | + if ($verbose) |
|
931 | + { |
|
932 | + echo "$label: mget(".array2string($keys_bogus).")=<br/>".array2string($mget_bogus)." !==<br/>".array2string($locations)."\n"; |
|
933 | + } |
|
867 | 934 | ++$failed; |
868 | 935 | } |
869 | 936 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @param array $keys eg. array($level,$app,$location) |
61 | 61 | * @param mixed $data |
62 | - * @param int $expiration=0 |
|
62 | + * @param int $expiration |
|
63 | 63 | * @return boolean true on success, false on error |
64 | 64 | */ |
65 | 65 | function set(array $keys,$data,$expiration=0) |
@@ -162,7 +162,6 @@ discard block |
||
162 | 162 | * Create a path from $keys and $basepath |
163 | 163 | * |
164 | 164 | * @param array $keys |
165 | - * @param boolean $mkdir=false should we create the directory |
|
166 | 165 | * @return string |
167 | 166 | */ |
168 | 167 | function filename(array $keys,$mkdir=false) |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | $this->base_path = egw_cache::get_system_config('temp_dir', false); |
49 | 49 | if (isset($this->base_path)) $this->base_path .= '/egw_cache'; |
50 | 50 | } |
51 | - if (!isset($this->base_path) || !file_exists($this->base_path) && !mkdir($this->base_path,0700,true)) |
|
51 | + if (!isset($this->base_path) || !file_exists($this->base_path) && !mkdir($this->base_path, 0700, true)) |
|
52 | 52 | { |
53 | - throw new Exception (__METHOD__."() can't create basepath $this->base_path!"); |
|
53 | + throw new Exception(__METHOD__."() can't create basepath $this->base_path!"); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | * @param int $expiration=0 |
63 | 63 | * @return boolean true on success, false on error |
64 | 64 | */ |
65 | - function set(array $keys,$data,$expiration=0) |
|
65 | + function set(array $keys, $data, $expiration = 0) |
|
66 | 66 | { |
67 | - if (($ret = @file_put_contents($fname=$this->filename($keys,true),serialize($data),LOCK_EX) > 0)) |
|
67 | + if (($ret = @file_put_contents($fname = $this->filename($keys, true), serialize($data), LOCK_EX) > 0)) |
|
68 | 68 | { |
69 | - if ((int)$expiration > 0) file_put_contents($fname.self::EXPIRATION_EXTENSION,(string)$expiration); |
|
69 | + if ((int)$expiration > 0) file_put_contents($fname.self::EXPIRATION_EXTENSION, (string)$expiration); |
|
70 | 70 | } |
71 | 71 | return $ret; |
72 | 72 | } |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | { |
84 | 84 | return null; |
85 | 85 | } |
86 | - if (file_exists($fname_expiration=$fname.self::EXPIRATION_EXTENSION) && |
|
86 | + if (file_exists($fname_expiration = $fname.self::EXPIRATION_EXTENSION) && |
|
87 | 87 | ($expiration = (int)file_get_contents($fname_expiration)) && |
88 | - filemtime($fname) < time()-$expiration) |
|
88 | + filemtime($fname) < time() - $expiration) |
|
89 | 89 | { |
90 | 90 | unlink($fname); |
91 | 91 | unlink($fname_expiration); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | //error_log(__METHOD__.'('.array2string($keys).") file_exists('$fname') == FALSE!"); |
108 | 108 | return false; |
109 | 109 | } |
110 | - if (file_exists($fname_expiration=$fname.self::EXPIRATION_EXTENSION)) |
|
110 | + if (file_exists($fname_expiration = $fname.self::EXPIRATION_EXTENSION)) |
|
111 | 111 | { |
112 | 112 | unlink($fname_expiration); |
113 | 113 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | { |
141 | 141 | return unlink($path); |
142 | 142 | } |
143 | - foreach(scandir($path) as $file) |
|
143 | + foreach (scandir($path) as $file) |
|
144 | 144 | { |
145 | 145 | if ($file == '.' || $file == '..') continue; |
146 | 146 | |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | * @param boolean $mkdir=false should we create the directory |
166 | 166 | * @return string |
167 | 167 | */ |
168 | - function filename(array $keys,$mkdir=false) |
|
168 | + function filename(array $keys, $mkdir = false) |
|
169 | 169 | { |
170 | - $fname = $this->base_path.'/'.str_replace(array(':','*'),'-',implode('/',$keys)); |
|
170 | + $fname = $this->base_path.'/'.str_replace(array(':', '*'), '-', implode('/', $keys)); |
|
171 | 171 | |
172 | - if ($mkdir && !file_exists($dirname=dirname($fname))) |
|
172 | + if ($mkdir && !file_exists($dirname = dirname($fname))) |
|
173 | 173 | { |
174 | - @mkdir($dirname,0700,true); |
|
174 | + @mkdir($dirname, 0700, true); |
|
175 | 175 | } |
176 | 176 | return $fname; |
177 | 177 | } |
@@ -46,7 +46,10 @@ discard block |
||
46 | 46 | else |
47 | 47 | { |
48 | 48 | $this->base_path = egw_cache::get_system_config('temp_dir', false); |
49 | - if (isset($this->base_path)) $this->base_path .= '/egw_cache'; |
|
49 | + if (isset($this->base_path)) |
|
50 | + { |
|
51 | + $this->base_path .= '/egw_cache'; |
|
52 | + } |
|
50 | 53 | } |
51 | 54 | if (!isset($this->base_path) || !file_exists($this->base_path) && !mkdir($this->base_path,0700,true)) |
52 | 55 | { |
@@ -66,7 +69,10 @@ discard block |
||
66 | 69 | { |
67 | 70 | if (($ret = @file_put_contents($fname=$this->filename($keys,true),serialize($data),LOCK_EX) > 0)) |
68 | 71 | { |
69 | - if ((int)$expiration > 0) file_put_contents($fname.self::EXPIRATION_EXTENSION,(string)$expiration); |
|
72 | + if ((int)$expiration > 0) |
|
73 | + { |
|
74 | + file_put_contents($fname.self::EXPIRATION_EXTENSION,(string)$expiration); |
|
75 | + } |
|
70 | 76 | } |
71 | 77 | return $ret; |
72 | 78 | } |
@@ -142,17 +148,26 @@ discard block |
||
142 | 148 | } |
143 | 149 | foreach(scandir($path) as $file) |
144 | 150 | { |
145 | - if ($file == '.' || $file == '..') continue; |
|
151 | + if ($file == '.' || $file == '..') |
|
152 | + { |
|
153 | + continue; |
|
154 | + } |
|
146 | 155 | |
147 | 156 | $file = $path.'/'.$file; |
148 | 157 | |
149 | 158 | if (is_dir($file)) |
150 | 159 | { |
151 | - if (!self::rm_recursive($file)) return false; |
|
160 | + if (!self::rm_recursive($file)) |
|
161 | + { |
|
162 | + return false; |
|
163 | + } |
|
152 | 164 | } |
153 | 165 | else |
154 | 166 | { |
155 | - if (!unlink($file)) return false; |
|
167 | + if (!unlink($file)) |
|
168 | + { |
|
169 | + return false; |
|
170 | + } |
|
156 | 171 | } |
157 | 172 | } |
158 | 173 | return rmdir($path); |
@@ -70,7 +70,7 @@ |
||
70 | 70 | * |
71 | 71 | * @param array $keys eg. array($level,$app,$location) |
72 | 72 | * @param mixed $data |
73 | - * @param int $expiration=0 |
|
73 | + * @param int $expiration |
|
74 | 74 | * @return boolean true on success, false on error |
75 | 75 | */ |
76 | 76 | function set(array $keys,$data,$expiration=0) |
@@ -45,23 +45,23 @@ discard block |
||
45 | 45 | */ |
46 | 46 | function __construct(array $params) |
47 | 47 | { |
48 | - check_load_extension('memcache',true); |
|
48 | + check_load_extension('memcache', true); |
|
49 | 49 | $this->memcache = new Memcache(); |
50 | 50 | |
51 | - if (!$params) $params = array('localhost'); // some reasonable default |
|
51 | + if (!$params) $params = array('localhost'); // some reasonable default |
|
52 | 52 | |
53 | 53 | $ok = false; |
54 | - foreach($params as $host_port) |
|
54 | + foreach ($params as $host_port) |
|
55 | 55 | { |
56 | - list($host,$port) = explode(':',$host_port); |
|
57 | - if (!$port) $port = 11211; // default port |
|
56 | + list($host, $port) = explode(':', $host_port); |
|
57 | + if (!$port) $port = 11211; // default port |
|
58 | 58 | |
59 | - $ok = $this->memcache->addServer($host,$port) || $ok; |
|
59 | + $ok = $this->memcache->addServer($host, $port) || $ok; |
|
60 | 60 | //error_log(__METHOD__."(".array2string($params).") memcache->addServer('$host',$port) = ".(int)$ok); |
61 | 61 | } |
62 | 62 | if (!$ok) |
63 | 63 | { |
64 | - throw new Exception (__METHOD__.'('.array2string($params).") Can't open connection to any memcached server!"); |
|
64 | + throw new Exception(__METHOD__.'('.array2string($params).") Can't open connection to any memcached server!"); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | * @param int $expiration=0 |
74 | 74 | * @return boolean true on success, false on error |
75 | 75 | */ |
76 | - function set(array $keys,$data,$expiration=0) |
|
76 | + function set(array $keys, $data, $expiration = 0) |
|
77 | 77 | { |
78 | - return $this->memcache->set(self::key($keys),serialize($data),self::STORE_FLAGS,$expiration); |
|
78 | + return $this->memcache->set(self::key($keys), serialize($data), self::STORE_FLAGS, $expiration); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | function get(array $keys) |
88 | 88 | { |
89 | - if (($data = $this->memcache->get($key=self::key($keys))) === false) |
|
89 | + if (($data = $this->memcache->get($key = self::key($keys))) === false) |
|
90 | 90 | { |
91 | 91 | //error_log(__METHOD__."(".array2string($keys).") key='$key' NOT found!"); |
92 | 92 | return null; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | { |
106 | 106 | $locations = array_pop($keys); |
107 | 107 | $prefix = self::key($keys); |
108 | - foreach($locations as &$location) |
|
108 | + foreach ($locations as &$location) |
|
109 | 109 | { |
110 | 110 | $location = $prefix.'::'.$location; |
111 | 111 | } |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | return array(); |
115 | 115 | } |
116 | 116 | $ret = array(); |
117 | - $prefix_len = strlen($prefix)+2; |
|
118 | - foreach($multiple as $location => $data) |
|
117 | + $prefix_len = strlen($prefix) + 2; |
|
118 | + foreach ($multiple as $location => $data) |
|
119 | 119 | { |
120 | - $key = substr($location,$prefix_len); |
|
120 | + $key = substr($location, $prefix_len); |
|
121 | 121 | //error_log(__METHOD__."(".array2string($locations).") key='$key' found ".bytes($data)." bytes)."); |
122 | 122 | $ret[$key] = unserialize($data); |
123 | 123 | } |
@@ -145,6 +145,6 @@ discard block |
||
145 | 145 | */ |
146 | 146 | private function key(array $keys) |
147 | 147 | { |
148 | - return implode('::',$keys); |
|
148 | + return implode('::', $keys); |
|
149 | 149 | } |
150 | 150 | } |
@@ -48,13 +48,21 @@ |
||
48 | 48 | check_load_extension('memcache',true); |
49 | 49 | $this->memcache = new Memcache(); |
50 | 50 | |
51 | - if (!$params) $params = array('localhost'); // some reasonable default |
|
51 | + if (!$params) |
|
52 | + { |
|
53 | + $params = array('localhost'); |
|
54 | + } |
|
55 | + // some reasonable default |
|
52 | 56 | |
53 | 57 | $ok = false; |
54 | 58 | foreach($params as $host_port) |
55 | 59 | { |
56 | 60 | list($host,$port) = explode(':',$host_port); |
57 | - if (!$port) $port = 11211; // default port |
|
61 | + if (!$port) |
|
62 | + { |
|
63 | + $port = 11211; |
|
64 | + } |
|
65 | + // default port |
|
58 | 66 | |
59 | 67 | $ok = $this->memcache->addServer($host,$port) || $ok; |
60 | 68 | //error_log(__METHOD__."(".array2string($params).") memcache->addServer('$host',$port) = ".(int)$ok); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * Only return skins existing in filesystem, as we disable / remove them if not compatible with supported browsers. |
67 | 67 | * |
68 | - * @return array skin => label pairs alphabetical sorted with default moono first |
|
68 | + * @return string skin => label pairs alphabetical sorted with default moono first |
|
69 | 69 | */ |
70 | 70 | public static function getAvailableCKEditorSkins() |
71 | 71 | { |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * Adds all "easy to write" options to the configuration |
260 | 260 | * |
261 | 261 | * @param array& $config array were config get's added to |
262 | - * @param int|string $height integer height in pixel or string with css unit |
|
262 | + * @param integer $height integer height in pixel or string with css unit |
|
263 | 263 | * @param boolean|string $expanded_toolbar show toolbar expanded, boolean value, string "false", or string casted to boolean |
264 | 264 | * @param string $start_path start path for file browser |
265 | 265 | */ |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | /** |
452 | 452 | * Adds extra |
453 | 453 | * @param array $config |
454 | - * @param array $plugins plugins name which needs to be appended into extraPlugins |
|
454 | + * @param string[] $plugins plugins name which needs to be appended into extraPlugins |
|
455 | 455 | */ |
456 | 456 | public static function append_extraPlugins_config_array (&$config, $plugins) |
457 | 457 | { |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | ); |
72 | 72 | $skins = array(); |
73 | 73 | |
74 | - foreach(scandir(EGW_SERVER_ROOT.'/phpgwapi/js/ckeditor/skins') as $skin) |
|
74 | + foreach (scandir(EGW_SERVER_ROOT.'/phpgwapi/js/ckeditor/skins') as $skin) |
|
75 | 75 | { |
76 | 76 | if ($skin[0] == '.') continue; |
77 | 77 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | uasort($skins, 'strcasecmp'); |
88 | 88 | |
89 | 89 | // return our default "moono" first |
90 | - return isset($skins['moono']) ? array('moono' => $skins['moono'])+$skins : $skins; |
|
90 | + return isset($skins['moono']) ? array('moono' => $skins['moono']) + $skins : $skins; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param string &$unit =null on return just unit |
99 | 99 | * @return string font-size including unit |
100 | 100 | */ |
101 | - public static function font_size_from_prefs(array $prefs=null, &$size=null, &$unit=null) |
|
101 | + public static function font_size_from_prefs(array $prefs = null, &$size = null, &$unit = null) |
|
102 | 102 | { |
103 | 103 | if (is_null($prefs)) $prefs = $GLOBALS['egw_info']['user']['preferences']; |
104 | 104 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $unit = 'px'; |
110 | 110 | $size = (string)(int)$size; |
111 | 111 | } |
112 | - return $size.($size?$unit:''); |
|
112 | + return $size.($size ? $unit : ''); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -120,12 +120,11 @@ discard block |
||
120 | 120 | { |
121 | 121 | //use the lang and country information to construct a possible lang info for CKEditor UI and scayt_slang |
122 | 122 | self::$lang = ($GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'] ? |
123 | - $GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang']: |
|
124 | - $GLOBALS['egw_info']['user']['preferences']['common']['lang']); |
|
123 | + $GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'] : $GLOBALS['egw_info']['user']['preferences']['common']['lang']); |
|
125 | 124 | |
126 | 125 | self::$country = $GLOBALS['egw_info']['user']['preferences']['common']['country']; |
127 | 126 | |
128 | - if (!(strpos(self::$lang, '-')===false)) |
|
127 | + if (!(strpos(self::$lang, '-') === false)) |
|
129 | 128 | list(self::$lang, self::$country) = explode('-', self::$lang); |
130 | 129 | } |
131 | 130 | |
@@ -270,8 +269,7 @@ discard block |
||
270 | 269 | $config['removePlugins'] = 'elementspath'; |
271 | 270 | |
272 | 271 | $config['toolbarCanCollapse'] = true; |
273 | - $config['toolbarStartupExpanded'] = is_bool($expanded_toolbar) ? $expanded_toolbar : |
|
274 | - ($expanded_toolbar === 'false' ? false : (boolean)$expanded_toolbar); |
|
272 | + $config['toolbarStartupExpanded'] = is_bool($expanded_toolbar) ? $expanded_toolbar : ($expanded_toolbar === 'false' ? false : (boolean)$expanded_toolbar); |
|
275 | 273 | |
276 | 274 | $config['filebrowserBrowseUrl'] = self::get_filebrowserBrowseUrl($start_path); |
277 | 275 | $config['filebrowserWindowHeight'] = 640; |
@@ -284,7 +282,7 @@ discard block |
||
284 | 282 | $config['fontSize_sizes'] = ''; |
285 | 283 | $unit = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font_unit']; |
286 | 284 | if (empty($unit)) $unit = 'px'; |
287 | - foreach(self::$font_size_options as $k => $v) |
|
285 | + foreach (self::$font_size_options as $k => $v) |
|
288 | 286 | { |
289 | 287 | $config['fontSize_sizes'] .= $v.$unit.'/'.$k.$unit.';'; |
290 | 288 | } |
@@ -302,22 +300,22 @@ discard block |
||
302 | 300 | // enable browsers native spellchecker as default, if e.g.: aspell fails |
303 | 301 | // to use browsers native spellchecker, you have to hold CMD/CTRL button on rightclick to |
304 | 302 | // access the browsers spell correction options |
305 | - if ($GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesNoSCAYT') $config['disableNativeSpellChecker'] = false; |
|
303 | + if ($GLOBALS['egw_info']['server']['enabled_spellcheck'] != 'YesNoSCAYT') $config['disableNativeSpellChecker'] = false; |
|
306 | 304 | |
307 | 305 | if (!empty($GLOBALS['egw_info']['server']['aspell_path']) && |
308 | 306 | is_executable($GLOBALS['egw_info']['server']['aspell_path']) && |
309 | - ($GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesUseWebSpellCheck' && |
|
310 | - $GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesBrowserBased') |
|
307 | + ($GLOBALS['egw_info']['server']['enabled_spellcheck'] != 'YesUseWebSpellCheck' && |
|
308 | + $GLOBALS['egw_info']['server']['enabled_spellcheck'] != 'YesBrowserBased') |
|
311 | 309 | ) |
312 | 310 | { |
313 | 311 | $spellchecker_button = 'SpellCheck'; |
314 | 312 | self::append_extraPlugins_config_array($config, array("aspell")); |
315 | 313 | } |
316 | - if ($GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesNoSCAYT' && |
|
317 | - $GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesBrowserBased' |
|
314 | + if ($GLOBALS['egw_info']['server']['enabled_spellcheck'] != 'YesNoSCAYT' && |
|
315 | + $GLOBALS['egw_info']['server']['enabled_spellcheck'] != 'YesBrowserBased' |
|
318 | 316 | ) |
319 | 317 | { |
320 | - $scayt_button='Scayt'; |
|
318 | + $scayt_button = 'Scayt'; |
|
321 | 319 | $config['scayt_autoStartup'] = true; |
322 | 320 | $config['scayt_sLang'] = self::get_lang().'_'.self::get_country(); |
323 | 321 | $config['disableNativeSpellChecker'] = true; // only one spell as you type |
@@ -333,48 +331,48 @@ discard block |
||
333 | 331 | * Writes the toolbar configuration to the options which depends on the chosen |
334 | 332 | * mode and the spellchecker_button written by the add_spellchecker_options button |
335 | 333 | */ |
336 | - private static function add_toolbar_options(&$config, $mode, $spellchecker_button, $scayt_button=false) |
|
334 | + private static function add_toolbar_options(&$config, $mode, $spellchecker_button, $scayt_button = false) |
|
337 | 335 | { |
338 | 336 | $config['toolbar'] = array(); |
339 | 337 | switch ($mode) |
340 | 338 | { |
341 | 339 | case 'advanced': |
342 | - $config['toolbar'][] = array('name' => 'document', 'items' => array('Source','DocProps','-','Preview','-','Templates')); |
|
343 | - $config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Print')); |
|
344 | - if ($spellchecker_button||$scayt_button) |
|
340 | + $config['toolbar'][] = array('name' => 'document', 'items' => array('Source', 'DocProps', '-', 'Preview', '-', 'Templates')); |
|
341 | + $config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print')); |
|
342 | + if ($spellchecker_button || $scayt_button) |
|
345 | 343 | { |
346 | 344 | $configArray = array(); |
347 | 345 | if ($spellchecker_button) $configArray[] = $spellchecker_button; |
348 | 346 | if ($scayt_button) $configArray[] = $scayt_button; |
349 | 347 | $config['toolbar'][] = array('name' => 'tools', 'items' => $configArray); |
350 | 348 | } |
351 | - $config['toolbar'][] = array('name' => 'edit', 'items' => array('Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat')); |
|
349 | + $config['toolbar'][] = array('name' => 'edit', 'items' => array('Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat')); |
|
352 | 350 | |
353 | 351 | $config['toolbar'][] = '/'; |
354 | 352 | |
355 | - $config['toolbar'][] = array('name' => 'basicstyles', 'items' => array('Bold','Italic','Underline','Strike','-','Subscript','Superscript')); |
|
356 | - $config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock')); |
|
357 | - $config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList','NumberedList','-','Outdent','Indent')); |
|
358 | - $config['toolbar'][] = array('name' => 'links', 'items' => array('Link','Unlink','Anchor')); |
|
359 | - $config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize','Image','Table','HorizontalRule','SpecialChar'/*,'Smiley'*/)); |
|
353 | + $config['toolbar'][] = array('name' => 'basicstyles', 'items' => array('Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript')); |
|
354 | + $config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock')); |
|
355 | + $config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList', 'NumberedList', '-', 'Outdent', 'Indent')); |
|
356 | + $config['toolbar'][] = array('name' => 'links', 'items' => array('Link', 'Unlink', 'Anchor')); |
|
357 | + $config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize', 'Image', 'Table', 'HorizontalRule', 'SpecialChar'/*,'Smiley'*/)); |
|
360 | 358 | |
361 | 359 | $config['toolbar'][] = '/'; |
362 | 360 | |
363 | - $config['toolbar'][] = array('name' => 'styles', 'items' => array('Style','Format','Font','FontSize')); |
|
364 | - $config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor')); |
|
365 | - $config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About')); |
|
361 | + $config['toolbar'][] = array('name' => 'styles', 'items' => array('Style', 'Format', 'Font', 'FontSize')); |
|
362 | + $config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor', 'BGColor')); |
|
363 | + $config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks', '-', 'About')); |
|
366 | 364 | break; |
367 | 365 | |
368 | 366 | case 'extended': default: |
369 | - $config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Bold','Italic','Underline')); |
|
370 | - $config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock')); |
|
371 | - $config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList','NumberedList'/*,'Smiley'*/,'Outdent','Indent','Undo','Redo')); |
|
372 | - $config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Print')); |
|
367 | + $config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Bold', 'Italic', 'Underline')); |
|
368 | + $config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock')); |
|
369 | + $config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList', 'NumberedList'/*,'Smiley'*/, 'Outdent', 'Indent', 'Undo', 'Redo')); |
|
370 | + $config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print')); |
|
373 | 371 | |
374 | 372 | if ($mode == 'extended') |
375 | 373 | { |
376 | - $config['toolbar'][] = array('name' => 'insert', 'items' => array('Image','Link','Unlink','Anchor')); |
|
377 | - if ($spellchecker_button||$scayt_button) |
|
374 | + $config['toolbar'][] = array('name' => 'insert', 'items' => array('Image', 'Link', 'Unlink', 'Anchor')); |
|
375 | + if ($spellchecker_button || $scayt_button) |
|
378 | 376 | { |
379 | 377 | $configArray = array('Maximize'); |
380 | 378 | if ($spellchecker_button) $configArray[] = $spellchecker_button; |
@@ -382,13 +380,13 @@ discard block |
||
382 | 380 | $config['toolbar'][] = array('name' => 'tools', 'items' => $configArray); |
383 | 381 | } |
384 | 382 | else |
385 | - $config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize'));//, 'Image', 'Table'); |
|
383 | + $config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize')); //, 'Image', 'Table'); |
|
386 | 384 | |
387 | 385 | $config['toolbar'][count($config['toolbar']) - 1][] = array('name' => 'insert', 'items' => array('Image', 'Table')); |
388 | 386 | } |
389 | 387 | else |
390 | 388 | { |
391 | - if ($spellchecker_button||$scayt_button) |
|
389 | + if ($spellchecker_button || $scayt_button) |
|
392 | 390 | { |
393 | 391 | $configArray = array('Maximize'); |
394 | 392 | if ($spellchecker_button) $configArray[] = $spellchecker_button; |
@@ -400,11 +398,11 @@ discard block |
||
400 | 398 | } |
401 | 399 | |
402 | 400 | $config['toolbar'][] = '/'; |
403 | - $config['toolbar'][] = array('name' => 'edit', 'items' => array('Find','Replace','-','SelectAll','RemoveFormat')); |
|
404 | - if ($mode == 'simple-withimage') $config['toolbar'][] = array('name' => 'links', 'items' => array('Image','Link','Unlink')); |
|
405 | - $config['toolbar'][] = array('name' => 'styles', 'items' => array('Format','Font','FontSize')); |
|
406 | - $config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor')); |
|
407 | - $config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About')); |
|
401 | + $config['toolbar'][] = array('name' => 'edit', 'items' => array('Find', 'Replace', '-', 'SelectAll', 'RemoveFormat')); |
|
402 | + if ($mode == 'simple-withimage') $config['toolbar'][] = array('name' => 'links', 'items' => array('Image', 'Link', 'Unlink')); |
|
403 | + $config['toolbar'][] = array('name' => 'styles', 'items' => array('Format', 'Font', 'FontSize')); |
|
404 | + $config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor', 'BGColor')); |
|
405 | + $config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks', '-', 'About')); |
|
408 | 406 | } |
409 | 407 | } |
410 | 408 | |
@@ -417,7 +415,7 @@ discard block |
||
417 | 415 | self::set_csp_script_src_attrs(); |
418 | 416 | |
419 | 417 | // If not explicitly set, use preference for toolbar mode |
420 | - if(!$mode || trim($mode) == '') $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features']; |
|
418 | + if (!$mode || trim($mode) == '') $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features']; |
|
421 | 419 | $config = array(); |
422 | 420 | $spellchecker_button = null; |
423 | 421 | |
@@ -427,7 +425,7 @@ discard block |
||
427 | 425 | self::add_toolbar_options($config, $mode, $spellchecker_button, $scayt_button); |
428 | 426 | //error_log(__METHOD__."('$mode', $height, ".array2string($expanded_toolbar).") returning ".array2string($config)); |
429 | 427 | // Add extra plugins |
430 | - self::append_extraPlugins_config_array($config, array('uploadimage','uploadwidget','widget','notification','notificationaggregator','lineutils')); |
|
428 | + self::append_extraPlugins_config_array($config, array('uploadimage', 'uploadwidget', 'widget', 'notification', 'notificationaggregator', 'lineutils')); |
|
431 | 429 | return $config; |
432 | 430 | } |
433 | 431 | |
@@ -436,7 +434,7 @@ discard block |
||
436 | 434 | * @param array $config |
437 | 435 | * @param array $plugins plugins name which needs to be appended into extraPlugins |
438 | 436 | */ |
439 | - public static function append_extraPlugins_config_array (&$config, $plugins) |
|
437 | + public static function append_extraPlugins_config_array(&$config, $plugins) |
|
440 | 438 | { |
441 | 439 | if (is_array($plugins)) |
442 | 440 | { |
@@ -444,7 +442,7 @@ discard block |
||
444 | 442 | { |
445 | 443 | if (!empty($config['extraPlugins']) && $config['extraPlugins'] !== '') |
446 | 444 | { |
447 | - $config['extraPlugins'] .= ',' . $plugin; |
|
445 | + $config['extraPlugins'] .= ','.$plugin; |
|
448 | 446 | } |
449 | 447 | else |
450 | 448 | { |
@@ -73,7 +73,10 @@ discard block |
||
73 | 73 | |
74 | 74 | foreach(scandir(EGW_SERVER_ROOT.'/phpgwapi/js/ckeditor/skins') as $skin) |
75 | 75 | { |
76 | - if ($skin[0] == '.') continue; |
|
76 | + if ($skin[0] == '.') |
|
77 | + { |
|
78 | + continue; |
|
79 | + } |
|
77 | 80 | |
78 | 81 | if (isset($labels[$skin])) |
79 | 82 | { |
@@ -100,7 +103,10 @@ discard block |
||
100 | 103 | */ |
101 | 104 | public static function font_size_from_prefs(array $prefs=null, &$size=null, &$unit=null) |
102 | 105 | { |
103 | - if (is_null($prefs)) $prefs = $GLOBALS['egw_info']['user']['preferences']; |
|
106 | + if (is_null($prefs)) |
|
107 | + { |
|
108 | + $prefs = $GLOBALS['egw_info']['user']['preferences']; |
|
109 | + } |
|
104 | 110 | |
105 | 111 | $size = $prefs['common']['rte_font_size']; |
106 | 112 | $unit = $prefs['common']['rte_font_unit']; |
@@ -126,7 +132,9 @@ discard block |
||
126 | 132 | self::$country = $GLOBALS['egw_info']['user']['preferences']['common']['country']; |
127 | 133 | |
128 | 134 | if (!(strpos(self::$lang, '-')===false)) |
129 | - list(self::$lang, self::$country) = explode('-', self::$lang); |
|
135 | + { |
|
136 | + list(self::$lang, self::$country) = explode('-', self::$lang); |
|
137 | + } |
|
130 | 138 | } |
131 | 139 | |
132 | 140 | /** |
@@ -135,7 +143,9 @@ discard block |
||
135 | 143 | private static function get_lang() |
136 | 144 | { |
137 | 145 | if (self::$lang == null || self::$country == null) |
138 | - self::read_lang_country(); |
|
146 | + { |
|
147 | + self::read_lang_country(); |
|
148 | + } |
|
139 | 149 | |
140 | 150 | return self::$lang; |
141 | 151 | } |
@@ -146,7 +156,9 @@ discard block |
||
146 | 156 | private static function get_country() |
147 | 157 | { |
148 | 158 | if (self::$lang == null || self::$country == null) |
149 | - self::read_lang_country(); |
|
159 | + { |
|
160 | + self::read_lang_country(); |
|
161 | + } |
|
150 | 162 | |
151 | 163 | return strtoupper(self::$country); |
152 | 164 | } |
@@ -283,7 +295,10 @@ discard block |
||
283 | 295 | |
284 | 296 | $config['fontSize_sizes'] = ''; |
285 | 297 | $unit = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font_unit']; |
286 | - if (empty($unit)) $unit = 'px'; |
|
298 | + if (empty($unit)) |
|
299 | + { |
|
300 | + $unit = 'px'; |
|
301 | + } |
|
287 | 302 | foreach(self::$font_size_options as $k => $v) |
288 | 303 | { |
289 | 304 | $config['fontSize_sizes'] .= $v.$unit.'/'.$k.$unit.';'; |
@@ -302,21 +317,22 @@ discard block |
||
302 | 317 | // enable browsers native spellchecker as default, if e.g.: aspell fails |
303 | 318 | // to use browsers native spellchecker, you have to hold CMD/CTRL button on rightclick to |
304 | 319 | // access the browsers spell correction options |
305 | - if ($GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesNoSCAYT') $config['disableNativeSpellChecker'] = false; |
|
320 | + if ($GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesNoSCAYT') |
|
321 | + { |
|
322 | + $config['disableNativeSpellChecker'] = false; |
|
323 | + } |
|
306 | 324 | |
307 | 325 | if (!empty($GLOBALS['egw_info']['server']['aspell_path']) && |
308 | 326 | is_executable($GLOBALS['egw_info']['server']['aspell_path']) && |
309 | 327 | ($GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesUseWebSpellCheck' && |
310 | 328 | $GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesBrowserBased') |
311 | - ) |
|
312 | - { |
|
329 | + ) { |
|
313 | 330 | $spellchecker_button = 'SpellCheck'; |
314 | 331 | self::append_extraPlugins_config_array($config, array("aspell")); |
315 | 332 | } |
316 | 333 | if ($GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesNoSCAYT' && |
317 | 334 | $GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesBrowserBased' |
318 | - ) |
|
319 | - { |
|
335 | + ) { |
|
320 | 336 | $scayt_button='Scayt'; |
321 | 337 | $config['scayt_autoStartup'] = true; |
322 | 338 | $config['scayt_sLang'] = self::get_lang().'_'.self::get_country(); |
@@ -344,8 +360,14 @@ discard block |
||
344 | 360 | if ($spellchecker_button||$scayt_button) |
345 | 361 | { |
346 | 362 | $configArray = array(); |
347 | - if ($spellchecker_button) $configArray[] = $spellchecker_button; |
|
348 | - if ($scayt_button) $configArray[] = $scayt_button; |
|
363 | + if ($spellchecker_button) |
|
364 | + { |
|
365 | + $configArray[] = $spellchecker_button; |
|
366 | + } |
|
367 | + if ($scayt_button) |
|
368 | + { |
|
369 | + $configArray[] = $scayt_button; |
|
370 | + } |
|
349 | 371 | $config['toolbar'][] = array('name' => 'tools', 'items' => $configArray); |
350 | 372 | } |
351 | 373 | $config['toolbar'][] = array('name' => 'edit', 'items' => array('Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat')); |
@@ -377,12 +399,20 @@ discard block |
||
377 | 399 | if ($spellchecker_button||$scayt_button) |
378 | 400 | { |
379 | 401 | $configArray = array('Maximize'); |
380 | - if ($spellchecker_button) $configArray[] = $spellchecker_button; |
|
381 | - if ($scayt_button) $configArray[] = $scayt_button; |
|
402 | + if ($spellchecker_button) |
|
403 | + { |
|
404 | + $configArray[] = $spellchecker_button; |
|
405 | + } |
|
406 | + if ($scayt_button) |
|
407 | + { |
|
408 | + $configArray[] = $scayt_button; |
|
409 | + } |
|
382 | 410 | $config['toolbar'][] = array('name' => 'tools', 'items' => $configArray); |
383 | 411 | } |
384 | - else |
|
385 | - $config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize'));//, 'Image', 'Table'); |
|
412 | + else { |
|
413 | + $config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize')); |
|
414 | + } |
|
415 | + //, 'Image', 'Table'); |
|
386 | 416 | |
387 | 417 | $config['toolbar'][count($config['toolbar']) - 1][] = array('name' => 'insert', 'items' => array('Image', 'Table')); |
388 | 418 | } |
@@ -391,17 +421,27 @@ discard block |
||
391 | 421 | if ($spellchecker_button||$scayt_button) |
392 | 422 | { |
393 | 423 | $configArray = array('Maximize'); |
394 | - if ($spellchecker_button) $configArray[] = $spellchecker_button; |
|
395 | - if ($scayt_button) $configArray[] = $scayt_button; |
|
424 | + if ($spellchecker_button) |
|
425 | + { |
|
426 | + $configArray[] = $spellchecker_button; |
|
427 | + } |
|
428 | + if ($scayt_button) |
|
429 | + { |
|
430 | + $configArray[] = $scayt_button; |
|
431 | + } |
|
396 | 432 | $config['toolbar'][] = array('name' => 'tools', 'items' => $configArray); |
397 | 433 | } |
398 | - else |
|
399 | - $config['toolbar'][] = array('name' => 'tools', 'items' => array('Maximize')); |
|
434 | + else { |
|
435 | + $config['toolbar'][] = array('name' => 'tools', 'items' => array('Maximize')); |
|
436 | + } |
|
400 | 437 | } |
401 | 438 | |
402 | 439 | $config['toolbar'][] = '/'; |
403 | 440 | $config['toolbar'][] = array('name' => 'edit', 'items' => array('Find','Replace','-','SelectAll','RemoveFormat')); |
404 | - if ($mode == 'simple-withimage') $config['toolbar'][] = array('name' => 'links', 'items' => array('Image','Link','Unlink')); |
|
441 | + if ($mode == 'simple-withimage') |
|
442 | + { |
|
443 | + $config['toolbar'][] = array('name' => 'links', 'items' => array('Image','Link','Unlink')); |
|
444 | + } |
|
405 | 445 | $config['toolbar'][] = array('name' => 'styles', 'items' => array('Format','Font','FontSize')); |
406 | 446 | $config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor')); |
407 | 447 | $config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About')); |
@@ -417,7 +457,10 @@ discard block |
||
417 | 457 | self::set_csp_script_src_attrs(); |
418 | 458 | |
419 | 459 | // If not explicitly set, use preference for toolbar mode |
420 | - if(!$mode || trim($mode) == '') $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features']; |
|
460 | + if(!$mode || trim($mode) == '') |
|
461 | + { |
|
462 | + $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features']; |
|
463 | + } |
|
421 | 464 | $config = array(); |
422 | 465 | $spellchecker_button = null; |
423 | 466 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * Get a CSRF token for an optional $purpose, which can be validated |
29 | 29 | * |
30 | - * @param mixed $_purpose=true if given it need to be used in validate too! (It must NOT be NULL) |
|
30 | + * @param mixed $_purpose if given it need to be used in validate too! (It must NOT be NULL) |
|
31 | 31 | * @return string CSRF token |
32 | 32 | */ |
33 | 33 | public static function token($_purpose=true) |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * Validate a CSRF token or teminate the request |
52 | 52 | * |
53 | 53 | * @param string $_token CSRF token generated with egw_csfr::token() |
54 | - * @param string $_purpose=true optional purpose string passed to token method |
|
55 | - * @param boolean $_delete_token=true true if token should be deleted after validation, it will validate no second time |
|
54 | + * @param string $_purpose optional purpose string passed to token method |
|
55 | + * @param boolean $_delete_token true if token should be deleted after validation, it will validate no second time |
|
56 | 56 | */ |
57 | 57 | public static function validate($_token, $_purpose=true, $_delete_token=true) |
58 | 58 | { |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param mixed $_purpose=true if given it need to be used in validate too! (It must NOT be NULL) |
31 | 31 | * @return string CSRF token |
32 | 32 | */ |
33 | - public static function token($_purpose=true) |
|
33 | + public static function token($_purpose = true) |
|
34 | 34 | { |
35 | 35 | if (is_null($_purpose)) |
36 | 36 | { |
@@ -38,8 +38,7 @@ discard block |
||
38 | 38 | } |
39 | 39 | // generate random token (using oppenssl if available otherwise mt_rand based auth::randomstring) |
40 | 40 | $token = function_exists('openssl_random_pseudo_bytes') ? |
41 | - base64_encode(openssl_random_pseudo_bytes(64)) : |
|
42 | - auth::randomstring(64); |
|
41 | + base64_encode(openssl_random_pseudo_bytes(64)) : auth::randomstring(64); |
|
43 | 42 | |
44 | 43 | // store it in session for later validation |
45 | 44 | egw_cache::setSession(__CLASS__, $token, $_purpose); |
@@ -54,7 +53,7 @@ discard block |
||
54 | 53 | * @param string $_purpose=true optional purpose string passed to token method |
55 | 54 | * @param boolean $_delete_token=true true if token should be deleted after validation, it will validate no second time |
56 | 55 | */ |
57 | - public static function validate($_token, $_purpose=true, $_delete_token=true) |
|
56 | + public static function validate($_token, $_purpose = true, $_delete_token = true) |
|
58 | 57 | { |
59 | 58 | $stored_purpose = egw_cache::getSession(__CLASS__, $_token); |
60 | 59 | |
@@ -66,6 +65,6 @@ discard block |
||
66 | 65 | // we are not throwing an exception here, but die, to not allow catching it! |
67 | 66 | die("CSRF detected, request terminated!"); |
68 | 67 | } |
69 | - if ($_delete_token) egw_cache::unsetTree (__CLASS__, $_token); |
|
68 | + if ($_delete_token) egw_cache::unsetTree(__CLASS__, $_token); |
|
70 | 69 | } |
71 | 70 | } |
72 | 71 | \ No newline at end of file |
@@ -62,10 +62,16 @@ |
||
62 | 62 | if (!isset($stored_purpose) || $stored_purpose !== $_purpose) |
63 | 63 | { |
64 | 64 | error_log('CSRF detected from IP '.$_SERVER['REMOTE_ADDR'].' to '.$_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI']); |
65 | - if ($_POST) error_log(array2string($_POST)); |
|
65 | + if ($_POST) |
|
66 | + { |
|
67 | + error_log(array2string($_POST)); |
|
68 | + } |
|
66 | 69 | // we are not throwing an exception here, but die, to not allow catching it! |
67 | 70 | die("CSRF detected, request terminated!"); |
68 | 71 | } |
69 | - if ($_delete_token) egw_cache::unsetTree (__CLASS__, $_token); |
|
72 | + if ($_delete_token) |
|
73 | + { |
|
74 | + egw_cache::unsetTree (__CLASS__, $_token); |
|
75 | + } |
|
70 | 76 | } |
71 | 77 | } |
72 | 78 | \ No newline at end of file |