@@ -41,19 +41,19 @@ discard block |
||
41 | 41 | var $Query_ID = 0; |
42 | 42 | |
43 | 43 | /** |
44 | - * Execute a query |
|
45 | - * |
|
46 | - * @param string $Query_String the query to be executed |
|
47 | - * @param int $line the line method was called from - use __LINE__ |
|
48 | - * @param string $file the file method was called from - use __FILE__ |
|
49 | - * @param int $offset row to start from, default 0 |
|
50 | - * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
51 | - * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
52 | - * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
53 | - * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
54 | - * @return ADORecordSet or false, if the query fails |
|
55 | - * @throws EGroupware\Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
56 | - */ |
|
44 | + * Execute a query |
|
45 | + * |
|
46 | + * @param string $Query_String the query to be executed |
|
47 | + * @param int $line the line method was called from - use __LINE__ |
|
48 | + * @param string $file the file method was called from - use __FILE__ |
|
49 | + * @param int $offset row to start from, default 0 |
|
50 | + * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
51 | + * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
52 | + * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
53 | + * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
54 | + * @return ADORecordSet or false, if the query fails |
|
55 | + * @throws EGroupware\Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
56 | + */ |
|
57 | 57 | function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
58 | 58 | { |
59 | 59 | // New query, discard previous result. |
@@ -76,12 +76,12 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Escape strings before sending them to the database |
|
80 | - * |
|
81 | - * @deprecated use quote($value,$type='') instead |
|
82 | - * @param string $str the string to be escaped |
|
83 | - * @return string escaped sting |
|
84 | - */ |
|
79 | + * Escape strings before sending them to the database |
|
80 | + * |
|
81 | + * @deprecated use quote($value,$type='') instead |
|
82 | + * @param string $str the string to be escaped |
|
83 | + * @return string escaped sting |
|
84 | + */ |
|
85 | 85 | function db_addslashes($str) |
86 | 86 | { |
87 | 87 | if (!isset($str) || $str == '') |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | - * Move to the next row in the results set |
|
111 | - * |
|
112 | - * Specifying a fetch_mode only works for newly fetched rows, the first row always gets fetched by query!!! |
|
113 | - * |
|
114 | - * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object |
|
115 | - * @param int $fetch_mode self::FETCH_BOTH = numerical+assoc keys (eGW default), self::FETCH_ASSOC or self::FETCH_NUM |
|
116 | - * @return bool was another row found? |
|
117 | - */ |
|
110 | + * Move to the next row in the results set |
|
111 | + * |
|
112 | + * Specifying a fetch_mode only works for newly fetched rows, the first row always gets fetched by query!!! |
|
113 | + * |
|
114 | + * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object |
|
115 | + * @param int $fetch_mode self::FETCH_BOTH = numerical+assoc keys (eGW default), self::FETCH_ASSOC or self::FETCH_NUM |
|
116 | + * @return bool was another row found? |
|
117 | + */ |
|
118 | 118 | function next_record($fetch_mode=self::FETCH_BOTH) |
119 | 119 | { |
120 | 120 | if (!$this->Query_ID) |
@@ -164,12 +164,12 @@ discard block |
||
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
167 | - * Move to position in result set |
|
168 | - * |
|
169 | - * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
170 | - * @param int $pos required row (optional), default first row |
|
171 | - * @return boolean true if sucessful or false if not found |
|
172 | - */ |
|
167 | + * Move to position in result set |
|
168 | + * |
|
169 | + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
170 | + * @param int $pos required row (optional), default first row |
|
171 | + * @return boolean true if sucessful or false if not found |
|
172 | + */ |
|
173 | 173 | function seek($pos = 0) |
174 | 174 | { |
175 | 175 | if (!$this->Query_ID || !$this->Query_ID->Move($this->Row = $pos)) |
@@ -180,74 +180,74 @@ discard block |
||
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | - * Lock a table |
|
184 | - * |
|
185 | - * @deprecated not used anymore as it costs to much performance, use transactions if needed |
|
186 | - * @param string $table name of table to lock |
|
187 | - * @param string $mode type of lock required (optional), default write |
|
188 | - * @return bool True if sucessful, False if fails |
|
189 | - */ |
|
183 | + * Lock a table |
|
184 | + * |
|
185 | + * @deprecated not used anymore as it costs to much performance, use transactions if needed |
|
186 | + * @param string $table name of table to lock |
|
187 | + * @param string $mode type of lock required (optional), default write |
|
188 | + * @return bool True if sucessful, False if fails |
|
189 | + */ |
|
190 | 190 | function lock($table, $mode='write') |
191 | 191 | { |
192 | 192 | unset($table, $mode); // not used anymore |
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Unlock a table |
|
197 | - * |
|
198 | - * @deprecated not used anymore as it costs to much performance, use transactions if needed |
|
199 | - * @return bool True if sucessful, False if fails |
|
200 | - */ |
|
196 | + * Unlock a table |
|
197 | + * |
|
198 | + * @deprecated not used anymore as it costs to much performance, use transactions if needed |
|
199 | + * @return bool True if sucessful, False if fails |
|
200 | + */ |
|
201 | 201 | function unlock() |
202 | 202 | {} |
203 | 203 | |
204 | 204 | /** |
205 | - * Number of rows in current result set |
|
206 | - * |
|
207 | - * @deprecated use the result-object returned by query/select()->NumRows(), so you can use the global db-object and not a clone |
|
208 | - * @return int number of rows |
|
209 | - */ |
|
205 | + * Number of rows in current result set |
|
206 | + * |
|
207 | + * @deprecated use the result-object returned by query/select()->NumRows(), so you can use the global db-object and not a clone |
|
208 | + * @return int number of rows |
|
209 | + */ |
|
210 | 210 | function num_rows() |
211 | 211 | { |
212 | 212 | return $this->Query_ID ? $this->Query_ID->RecordCount() : False; |
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
216 | - * Number of fields in current row |
|
217 | - * |
|
218 | - * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
219 | - * @return int number of fields |
|
220 | - */ |
|
216 | + * Number of fields in current row |
|
217 | + * |
|
218 | + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
219 | + * @return int number of fields |
|
220 | + */ |
|
221 | 221 | function num_fields() |
222 | 222 | { |
223 | 223 | return $this->Query_ID ? $this->Query_ID->FieldCount() : False; |
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
227 | - * @deprecated use num_rows() |
|
228 | - */ |
|
227 | + * @deprecated use num_rows() |
|
228 | + */ |
|
229 | 229 | function nf() |
230 | 230 | { |
231 | 231 | return $this->num_rows(); |
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | - * @deprecated use print num_rows() |
|
236 | - */ |
|
235 | + * @deprecated use print num_rows() |
|
236 | + */ |
|
237 | 237 | function np() |
238 | 238 | { |
239 | 239 | print $this->num_rows(); |
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Return the value of a column |
|
244 | - * |
|
245 | - * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
246 | - * @param string|integer $Name name of field or positional index starting from 0 |
|
247 | - * @param bool $strip_slashes string escape chars from field(optional), default false |
|
248 | - * depricated param, as correctly quoted values dont need any stripslashes! |
|
249 | - * @return string the field value |
|
250 | - */ |
|
243 | + * Return the value of a column |
|
244 | + * |
|
245 | + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
246 | + * @param string|integer $Name name of field or positional index starting from 0 |
|
247 | + * @param bool $strip_slashes string escape chars from field(optional), default false |
|
248 | + * depricated param, as correctly quoted values dont need any stripslashes! |
|
249 | + * @return string the field value |
|
250 | + */ |
|
251 | 251 | function f($Name, $strip_slashes = False) |
252 | 252 | { |
253 | 253 | if ($strip_slashes) |
@@ -258,26 +258,26 @@ discard block |
||
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | - * Print the value of a field |
|
262 | - * |
|
263 | - * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
264 | - * @param string $Name name of field to print |
|
265 | - * @param bool $strip_slashes string escape chars from field(optional), default false |
|
266 | - * depricated param, as correctly quoted values dont need any stripslashes! |
|
267 | - */ |
|
261 | + * Print the value of a field |
|
262 | + * |
|
263 | + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
264 | + * @param string $Name name of field to print |
|
265 | + * @param bool $strip_slashes string escape chars from field(optional), default false |
|
266 | + * depricated param, as correctly quoted values dont need any stripslashes! |
|
267 | + */ |
|
268 | 268 | function p($Name, $strip_slashes = True) |
269 | 269 | { |
270 | 270 | print $this->f($Name, $strip_slashes); |
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
274 | - * Returns a query-result-row as an associative array (no numerical keys !!!) |
|
275 | - * |
|
276 | - * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object |
|
277 | - * @param bool $do_next_record should next_record() be called or not (default not) |
|
278 | - * @param string $strip ='' string to strip of the column-name, default '' |
|
279 | - * @return array/bool the associative array or False if no (more) result-row is availible |
|
280 | - */ |
|
274 | + * Returns a query-result-row as an associative array (no numerical keys !!!) |
|
275 | + * |
|
276 | + * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object |
|
277 | + * @param bool $do_next_record should next_record() be called or not (default not) |
|
278 | + * @param string $strip ='' string to strip of the column-name, default '' |
|
279 | + * @return array/bool the associative array or False if no (more) result-row is availible |
|
280 | + */ |
|
281 | 281 | function row($do_next_record=False,$strip='') |
282 | 282 | { |
283 | 283 | if ($do_next_record && !$this->next_record(self::FETCH_ASSOC) || !is_array($this->Record)) |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return ADORecordSet or false, if the query fails |
55 | 55 | * @throws EGroupware\Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
56 | 56 | */ |
57 | - function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
|
57 | + function query($Query_String, $line = '', $file = '', $offset = 0, $num_rows = -1, $inputarr = false, $fetchmode = self::FETCH_BOTH, $reconnect = true) |
|
58 | 58 | { |
59 | 59 | // New query, discard previous result. |
60 | 60 | if ($this->Query_ID) |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function free() |
104 | 104 | { |
105 | - unset($this->Query_ID); // else copying of the db-object does not work |
|
105 | + unset($this->Query_ID); // else copying of the db-object does not work |
|
106 | 106 | $this->Query_ID = 0; |
107 | 107 | } |
108 | 108 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @param int $fetch_mode self::FETCH_BOTH = numerical+assoc keys (eGW default), self::FETCH_ASSOC or self::FETCH_NUM |
116 | 116 | * @return bool was another row found? |
117 | 117 | */ |
118 | - function next_record($fetch_mode=self::FETCH_BOTH) |
|
118 | + function next_record($fetch_mode = self::FETCH_BOTH) |
|
119 | 119 | { |
120 | 120 | if (!$this->Query_ID) |
121 | 121 | { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | } |
136 | 136 | if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper') // maxdb, oracle, ... |
137 | 137 | { |
138 | - switch($fetch_mode) |
|
138 | + switch ($fetch_mode) |
|
139 | 139 | { |
140 | 140 | case self::FETCH_ASSOC: |
141 | 141 | $this->Record = array_change_key_case($this->Record); |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | */ |
173 | 173 | function seek($pos = 0) |
174 | 174 | { |
175 | - if (!$this->Query_ID || !$this->Query_ID->Move($this->Row = $pos)) |
|
175 | + if (!$this->Query_ID || !$this->Query_ID->Move($this->Row = $pos)) |
|
176 | 176 | { |
177 | - throw new Exception("seek($pos) failed: resultset has " . $this->num_rows() . " rows"); |
|
177 | + throw new Exception("seek($pos) failed: resultset has ".$this->num_rows()." rows"); |
|
178 | 178 | } |
179 | 179 | return True; |
180 | 180 | } |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | * @param string $mode type of lock required (optional), default write |
188 | 188 | * @return bool True if sucessful, False if fails |
189 | 189 | */ |
190 | - function lock($table, $mode='write') |
|
190 | + function lock($table, $mode = 'write') |
|
191 | 191 | { |
192 | - unset($table, $mode); // not used anymore |
|
192 | + unset($table, $mode); // not used anymore |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -278,18 +278,18 @@ discard block |
||
278 | 278 | * @param string $strip ='' string to strip of the column-name, default '' |
279 | 279 | * @return array/bool the associative array or False if no (more) result-row is availible |
280 | 280 | */ |
281 | - function row($do_next_record=False,$strip='') |
|
281 | + function row($do_next_record = False, $strip = '') |
|
282 | 282 | { |
283 | 283 | if ($do_next_record && !$this->next_record(self::FETCH_ASSOC) || !is_array($this->Record)) |
284 | 284 | { |
285 | 285 | return False; |
286 | 286 | } |
287 | 287 | $result = array(); |
288 | - foreach($this->Record as $column => $value) |
|
288 | + foreach ($this->Record as $column => $value) |
|
289 | 289 | { |
290 | 290 | if (!is_numeric($column)) |
291 | 291 | { |
292 | - if ($strip) $column = str_replace($strip,'',$column); |
|
292 | + if ($strip) $column = str_replace($strip, '', $column); |
|
293 | 293 | |
294 | 294 | $result[$column] = $value; |
295 | 295 | } |
@@ -121,10 +121,13 @@ discard block |
||
121 | 121 | { |
122 | 122 | throw new Exception('next_record called with no query pending.'); |
123 | 123 | } |
124 | - if ($this->Row) // first row is already fetched |
|
124 | + if ($this->Row) |
|
125 | + { |
|
126 | + // first row is already fetched |
|
125 | 127 | { |
126 | 128 | $this->Query_ID->MoveNext(); |
127 | 129 | } |
130 | + } |
|
128 | 131 | ++$this->Row; |
129 | 132 | |
130 | 133 | $this->Record = $this->Query_ID->fields; |
@@ -133,12 +136,15 @@ discard block |
||
133 | 136 | { |
134 | 137 | return False; |
135 | 138 | } |
136 | - if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper') // maxdb, oracle, ... |
|
139 | + if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper') |
|
140 | + { |
|
141 | + // maxdb, oracle, ... |
|
137 | 142 | { |
138 | 143 | switch($fetch_mode) |
139 | 144 | { |
140 | 145 | case self::FETCH_ASSOC: |
141 | 146 | $this->Record = array_change_key_case($this->Record); |
147 | + } |
|
142 | 148 | break; |
143 | 149 | case self::FETCH_NUM: |
144 | 150 | $this->Record = array_values($this->Record); |
@@ -199,7 +205,8 @@ discard block |
||
199 | 205 | * @return bool True if sucessful, False if fails |
200 | 206 | */ |
201 | 207 | function unlock() |
202 | - {} |
|
208 | + { |
|
209 | +} |
|
203 | 210 | |
204 | 211 | /** |
205 | 212 | * Number of rows in current result set |
@@ -289,7 +296,10 @@ discard block |
||
289 | 296 | { |
290 | 297 | if (!is_numeric($column)) |
291 | 298 | { |
292 | - if ($strip) $column = str_replace($strip,'',$column); |
|
299 | + if ($strip) |
|
300 | + { |
|
301 | + $column = str_replace($strip,'',$column); |
|
302 | + } |
|
293 | 303 | |
294 | 304 | $result[$column] = $value; |
295 | 305 | } |
@@ -301,4 +311,6 @@ discard block |
||
301 | 311 | /** |
302 | 312 | * @deprecated use EGroupware\Api\Db\CallbackIterator |
303 | 313 | */ |
304 | -class egw_db_callback_iterator extends Api\Db\CallbackIterator {} |
|
314 | +class egw_db_callback_iterator extends Api\Db\CallbackIterator |
|
315 | +{ |
|
316 | +} |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | */ |
65 | 65 | static $sub_objects = array( |
66 | 66 | 'log' => 'errorlog', |
67 | - 'link' => 'bolink', // depricated use static egw_link methods |
|
67 | + 'link' => 'bolink', // depricated use static egw_link methods |
|
68 | 68 | 'datetime' => 'egw_datetime', |
69 | 69 | // classes moved to new api dir |
70 | 70 | 'template' => true, |
71 | 71 | 'applications' => 'EGroupware\\Api\\Egw\\Applications', |
72 | - 'framework' => true, // special handling in __get() |
|
72 | + 'framework' => true, // special handling in __get() |
|
73 | 73 | 'ldap' => true, |
74 | 74 | ); |
75 | 75 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | { |
96 | 96 | //error_log(__METHOD__."($name)".function_backtrace()); |
97 | 97 | |
98 | - if ($name == 'js') $name = 'framework'; // javascript class is integrated now into framework |
|
98 | + if ($name == 'js') $name = 'framework'; // javascript class is integrated now into framework |
|
99 | 99 | |
100 | 100 | if (isset($this->$name)) |
101 | 101 | { |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | if ($name != 'ADOdb') error_log(__METHOD__.": There's NO $name object! ".function_backtrace()); |
108 | 108 | return null; |
109 | 109 | } |
110 | - switch($name) |
|
110 | + switch ($name) |
|
111 | 111 | { |
112 | 112 | case 'framework': |
113 | 113 | return $this->framework = Api\Framework::factory(); |
@@ -95,7 +95,11 @@ discard block |
||
95 | 95 | { |
96 | 96 | //error_log(__METHOD__."($name)".function_backtrace()); |
97 | 97 | |
98 | - if ($name == 'js') $name = 'framework'; // javascript class is integrated now into framework |
|
98 | + if ($name == 'js') |
|
99 | + { |
|
100 | + $name = 'framework'; |
|
101 | + } |
|
102 | + // javascript class is integrated now into framework |
|
99 | 103 | |
100 | 104 | if (isset($this->$name)) |
101 | 105 | { |
@@ -104,7 +108,10 @@ discard block |
||
104 | 108 | |
105 | 109 | if (!isset(self::$sub_objects[$name]) && !class_exists('EGroupware\\Api\\'.ucfirst($name)) && !class_exists($name)) |
106 | 110 | { |
107 | - if ($name != 'ADOdb') error_log(__METHOD__.": There's NO $name object! ".function_backtrace()); |
|
111 | + if ($name != 'ADOdb') |
|
112 | + { |
|
113 | + error_log(__METHOD__.": There's NO $name object! ".function_backtrace()); |
|
114 | + } |
|
108 | 115 | return null; |
109 | 116 | } |
110 | 117 | switch($name) |
@@ -121,7 +128,10 @@ discard block |
||
121 | 128 | return $this->ldap = Api\Ldap::factory(false); |
122 | 129 | default: |
123 | 130 | $class = isset(self::$sub_objects[$name]) ? self::$sub_objects[$name] : 'EGroupware\\Api\\'.ucfirst($name); |
124 | - if (!class_exists($class)) $class = $name; |
|
131 | + if (!class_exists($class)) |
|
132 | + { |
|
133 | + $class = $name; |
|
134 | + } |
|
125 | 135 | break; |
126 | 136 | } |
127 | 137 | return $this->$name = new $class(); |
@@ -170,7 +170,7 @@ |
||
170 | 170 | * |
171 | 171 | * @param string/array $_contact_id contact_id or array with values for id or account_id |
172 | 172 | * @return array/boolean data if row could be retrived else False |
173 | - */ |
|
173 | + */ |
|
174 | 174 | function read($_contact_id) |
175 | 175 | { |
176 | 176 | if (is_array($_contact_id) && isset($_contact_id['account_id']) || |
@@ -84,7 +84,11 @@ discard block |
||
84 | 84 | */ |
85 | 85 | function __construct(array $ldap_config=null, $ds=null) |
86 | 86 | { |
87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
87 | + if (false) |
|
88 | + { |
|
89 | + parent::__construct (); |
|
90 | + } |
|
91 | + // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
88 | 92 | |
89 | 93 | $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
90 | 94 | |
@@ -202,10 +206,16 @@ discard block |
||
202 | 206 | $contact['id'] = $contact['uid'] = $this->accounts_ads->objectguid2str($data['objectguid']); |
203 | 207 | |
204 | 208 | // ignore system accounts |
205 | - if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) return false; |
|
209 | + if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) |
|
210 | + { |
|
211 | + return false; |
|
212 | + } |
|
206 | 213 | |
207 | 214 | // ignore deactivated or expired accounts |
208 | - if (!$this->accounts_ads->user_active($data)) return false; |
|
215 | + if (!$this->accounts_ads->user_active($data)) |
|
216 | + { |
|
217 | + return false; |
|
218 | + } |
|
209 | 219 | |
210 | 220 | $this->_inetorgperson2egw($contact, $data, 'displayname'); |
211 | 221 | } |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * minimum: $this->columns_to_search = array('n_family','n_given','org_name','email'); |
36 | 36 | */ |
37 | 37 | var $search_attributes = array( |
38 | - 'n_family','n_middle','n_given','org_name','org_unit', |
|
39 | - 'adr_one_location','note','email','samaccountname', |
|
38 | + 'n_family', 'n_middle', 'n_given', 'org_name', 'org_unit', |
|
39 | + 'adr_one_location', 'note', 'email', 'samaccountname', |
|
40 | 40 | ); |
41 | 41 | |
42 | 42 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @var string |
52 | 52 | */ |
53 | - var $dn_attribute='cn'; |
|
53 | + var $dn_attribute = 'cn'; |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Do NOT attempt to change DN (dn-attribute can NOT be part of schemas used in addressbook!) |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | * @param array $ldap_config =null default use from $GLOBALS['egw_info']['server'] |
83 | 83 | * @param resource $ds =null ldap connection to use |
84 | 84 | */ |
85 | - function __construct(array $ldap_config=null, $ds=null) |
|
85 | + function __construct(array $ldap_config = null, $ds = null) |
|
86 | 86 | { |
87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
87 | + if (false) parent::__construct(); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
88 | 88 | |
89 | - $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
89 | + $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
90 | 90 | |
91 | 91 | if ($ldap_config) |
92 | 92 | { |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | else |
96 | 96 | { |
97 | - $this->ldap_config =& $GLOBALS['egw_info']['server']; |
|
97 | + $this->ldap_config = & $GLOBALS['egw_info']['server']; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | $this->accounts_ads = $GLOBALS['egw']->accounts->backend; |
@@ -119,15 +119,15 @@ discard block |
||
119 | 119 | 'account_id' => 'objectsid', |
120 | 120 | 'id' => 'objectguid', |
121 | 121 | 'uid' => 'objectguid', |
122 | - 'n_fn' => 'displayname', // leave CN used in DN untouched |
|
123 | - 'accountexpires', 'useraccountcontrol', // needed to exclude deactivated or expired accounts |
|
122 | + 'n_fn' => 'displayname', // leave CN used in DN untouched |
|
123 | + 'accountexpires', 'useraccountcontrol', // needed to exclude deactivated or expired accounts |
|
124 | 124 | )); |
125 | 125 | unset($this->schema2egw['user']['n_fileas']); |
126 | 126 | unset($this->schema2egw['inetorgperson']); |
127 | 127 | |
128 | - foreach($this->schema2egw as $attributes) |
|
128 | + foreach ($this->schema2egw as $attributes) |
|
129 | 129 | { |
130 | - $this->all_attributes = array_merge($this->all_attributes,array_values($attributes)); |
|
130 | + $this->all_attributes = array_merge($this->all_attributes, array_values($attributes)); |
|
131 | 131 | } |
132 | 132 | $this->all_attributes = array_values(array_unique($this->all_attributes)); |
133 | 133 | |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param boolean $admin =false true (re-)connect with admin not user credentials, eg. to modify accounts |
141 | 141 | */ |
142 | - function connect($admin=false) |
|
142 | + function connect($admin = false) |
|
143 | 143 | { |
144 | - unset($admin); // not used, but required by function signature |
|
144 | + unset($admin); // not used, but required by function signature |
|
145 | 145 | |
146 | 146 | $this->ds = $this->accounts_ads->ldap_connection(); |
147 | 147 | } |
@@ -174,18 +174,17 @@ discard block |
||
174 | 174 | function read($_contact_id) |
175 | 175 | { |
176 | 176 | if (is_array($_contact_id) && isset($_contact_id['account_id']) || |
177 | - !is_array($_contact_id) && substr($_contact_id,0,8) == 'account:') |
|
177 | + !is_array($_contact_id) && substr($_contact_id, 0, 8) == 'account:') |
|
178 | 178 | { |
179 | - $account_id = (int)(is_array($_contact_id) ? $_contact_id['account_id'] : substr($_contact_id,8)); |
|
179 | + $account_id = (int)(is_array($_contact_id) ? $_contact_id['account_id'] : substr($_contact_id, 8)); |
|
180 | 180 | if ($account_id < 0 || !($_contact_id = $GLOBALS['egw']->accounts->id2name($account_id, 'person_id'))) |
181 | 181 | { |
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | } |
185 | - $contact_id = !is_array($_contact_id) ? $_contact_id : |
|
186 | - (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); |
|
185 | + $contact_id = !is_array($_contact_id) ? $_contact_id : (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); |
|
187 | 186 | |
188 | - $rows = $this->_searchLDAP($this->allContactsDN, $filter=$this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); |
|
187 | + $rows = $this->_searchLDAP($this->allContactsDN, $filter = $this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); |
|
189 | 188 | //error_log(__METHOD__."('$contact_id') _searchLDAP($this->allContactsDN, '$filter',...)=".array2string($rows)); |
190 | 189 | return $rows ? $rows[0] : false; |
191 | 190 | } |
@@ -35,7 +35,7 @@ |
||
35 | 35 | * @param array $keys if given $keys are copied to data before saveing => allows a save as |
36 | 36 | * @return int 0 on success and errno != 0 else |
37 | 37 | */ |
38 | - function save($keys=null) |
|
38 | + function save($keys = null) |
|
39 | 39 | { |
40 | 40 | // UCS lowercases email when storing |
41 | 41 | $keys['email'] = strtolower(!empty($keys['email']) ? $keys['email'] : $this->data['email']); |
@@ -41,33 +41,33 @@ discard block |
||
41 | 41 | var $contacts_id='id'; |
42 | 42 | |
43 | 43 | /** |
44 | - * @var string $accountName holds the accountname of the current user |
|
45 | - */ |
|
44 | + * @var string $accountName holds the accountname of the current user |
|
45 | + */ |
|
46 | 46 | var $accountName; |
47 | 47 | |
48 | 48 | /** |
49 | - * @var object $ldapServerInfo holds the information about the current used ldap server |
|
50 | - */ |
|
49 | + * @var object $ldapServerInfo holds the information about the current used ldap server |
|
50 | + */ |
|
51 | 51 | var $ldapServerInfo; |
52 | 52 | |
53 | 53 | /** |
54 | - * @var int $ldapLimit how many rows to fetch from ldap server |
|
55 | - */ |
|
54 | + * @var int $ldapLimit how many rows to fetch from ldap server |
|
55 | + */ |
|
56 | 56 | var $ldapLimit = 2000; |
57 | 57 | |
58 | 58 | /** |
59 | - * @var string $personalContactsDN holds the base DN for the personal addressbooks |
|
60 | - */ |
|
59 | + * @var string $personalContactsDN holds the base DN for the personal addressbooks |
|
60 | + */ |
|
61 | 61 | var $personalContactsDN; |
62 | 62 | |
63 | 63 | /** |
64 | - * @var string $sharedContactsDN holds the base DN for the shared addressbooks |
|
65 | - */ |
|
64 | + * @var string $sharedContactsDN holds the base DN for the shared addressbooks |
|
65 | + */ |
|
66 | 66 | var $sharedContactsDN; |
67 | 67 | |
68 | 68 | /** |
69 | - * @var string $accountContactsDN holds the base DN for accounts addressbook |
|
70 | - */ |
|
69 | + * @var string $accountContactsDN holds the base DN for accounts addressbook |
|
70 | + */ |
|
71 | 71 | var $accountContactsDN; |
72 | 72 | |
73 | 73 | /** |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | var $accountsFilter = '(objectclass=posixaccount)'; |
78 | 78 | |
79 | 79 | /** |
80 | - * @var string $allContactsDN holds the base DN of all addressbook |
|
81 | - */ |
|
80 | + * @var string $allContactsDN holds the base DN of all addressbook |
|
81 | + */ |
|
82 | 82 | var $allContactsDN; |
83 | 83 | |
84 | 84 | /** |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | var $never_change_dn = false; |
97 | 97 | |
98 | 98 | /** |
99 | - * @var int $total holds the total count of found rows |
|
100 | - */ |
|
99 | + * @var int $total holds the total count of found rows |
|
100 | + */ |
|
101 | 101 | var $total; |
102 | 102 | |
103 | 103 | /** |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * |
404 | 404 | * @param string|array $contact_id contact_id or array with values for id or account_id |
405 | 405 | * @return array/boolean data if row could be retrived else False |
406 | - */ |
|
406 | + */ |
|
407 | 407 | function read($contact_id) |
408 | 408 | { |
409 | 409 | if (is_array($contact_id) && isset($contact_id['account_id']) || |
@@ -327,9 +327,12 @@ discard block |
||
327 | 327 | $this->ds = Api\Ldap::factory(); |
328 | 328 | } |
329 | 329 | // if ldap is NOT the contact repository, we only do accounts and need to use the account-data |
330 | - elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap') // not (ldap or sql-ldap) |
|
330 | + elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap') |
|
331 | + { |
|
332 | + // not (ldap or sql-ldap) |
|
331 | 333 | { |
332 | 334 | $this->ldap_config['ldap_contact_host'] = $this->ldap_config['ldap_host']; |
335 | + } |
|
333 | 336 | $this->allContactsDN = $this->ldap_config['ldap_context']; |
334 | 337 | $this->ds = Api\Ldap::factory(); |
335 | 338 | } |
@@ -413,7 +416,10 @@ discard block |
||
413 | 416 | } |
414 | 417 | else |
415 | 418 | { |
416 | - if (is_array($contact_id)) $contact_id = isset ($contact_id['id']) ? $contact_id['id'] : $contact_id['uid']; |
|
419 | + if (is_array($contact_id)) |
|
420 | + { |
|
421 | + $contact_id = isset ($contact_id['id']) ? $contact_id['id'] : $contact_id['uid']; |
|
422 | + } |
|
417 | 423 | $filter = $this->id_filter($contact_id); |
418 | 424 | } |
419 | 425 | $rows = $this->_searchLDAP($this->allContactsDN, |
@@ -517,7 +523,10 @@ discard block |
||
517 | 523 | // add for all supported objectclasses the objectclass and it's attributes |
518 | 524 | foreach($this->schema2egw as $objectclass => $mapping) |
519 | 525 | { |
520 | - if(!$this->ldapServerInfo->supportsObjectClass($objectclass)) continue; |
|
526 | + if(!$this->ldapServerInfo->supportsObjectClass($objectclass)) |
|
527 | + { |
|
528 | + continue; |
|
529 | + } |
|
521 | 530 | |
522 | 531 | if($objectclass != 'posixaccount' && !in_array($objectclass, $oldObjectclasses)) |
523 | 532 | { |
@@ -535,7 +544,10 @@ discard block |
||
535 | 544 | } |
536 | 545 | foreach($mapping as $egwFieldName => $ldapFieldName) |
537 | 546 | { |
538 | - if (is_int($egwFieldName)) continue; |
|
547 | + if (is_int($egwFieldName)) |
|
548 | + { |
|
549 | + continue; |
|
550 | + } |
|
539 | 551 | if(!empty($data[$egwFieldName])) |
540 | 552 | { |
541 | 553 | // dont convert the (binary) jpegPhoto! |
@@ -671,7 +683,10 @@ discard block |
||
671 | 683 | function delete($keys=null) |
672 | 684 | { |
673 | 685 | // single entry |
674 | - if($keys[$this->contacts_id]) $keys = array( 0 => $keys); |
|
686 | + if($keys[$this->contacts_id]) |
|
687 | + { |
|
688 | + $keys = array( 0 => $keys); |
|
689 | + } |
|
675 | 690 | |
676 | 691 | if(!is_array($keys)) |
677 | 692 | { |
@@ -760,7 +775,10 @@ discard block |
||
760 | 775 | |
761 | 776 | if((int)$filter['owner']) |
762 | 777 | { |
763 | - if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner']))) return false; |
|
778 | + if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner']))) |
|
779 | + { |
|
780 | + return false; |
|
781 | + } |
|
764 | 782 | |
765 | 783 | $searchDN = 'cn='. Api\Ldap::quote(strtolower($accountName)) .','; |
766 | 784 | |
@@ -856,7 +874,10 @@ discard block |
||
856 | 874 | $sort = 'ASC'; |
857 | 875 | foreach(explode(',',$order_by) as $o) |
858 | 876 | { |
859 | - if (substr($o,0,8) == 'contact_') $o = substr($o,8); |
|
877 | + if (substr($o,0,8) == 'contact_') |
|
878 | + { |
|
879 | + $o = substr($o,8); |
|
880 | + } |
|
860 | 881 | if (substr($o,-4) == ' ASC') |
861 | 882 | { |
862 | 883 | $sort = 'ASC'; |
@@ -884,7 +905,10 @@ discard block |
||
884 | 905 | { |
885 | 906 | $strc = strcmp($b[$f], $a[$f]); |
886 | 907 | } |
887 | - if ($strc) return $strc; |
|
908 | + if ($strc) |
|
909 | + { |
|
910 | + return $strc; |
|
911 | + } |
|
888 | 912 | } |
889 | 913 | return 0; |
890 | 914 | }); |
@@ -913,12 +937,18 @@ discard block |
||
913 | 937 | */ |
914 | 938 | function _colFilter($filter) |
915 | 939 | { |
916 | - if (!is_array($filter)) return ''; |
|
940 | + if (!is_array($filter)) |
|
941 | + { |
|
942 | + return ''; |
|
943 | + } |
|
917 | 944 | |
918 | 945 | $filters = ''; |
919 | 946 | foreach($filter as $key => $value) |
920 | 947 | { |
921 | - if ($key != 'cat_id' && $key != 'account_id' && !$value) continue; |
|
948 | + if ($key != 'cat_id' && $key != 'account_id' && !$value) |
|
949 | + { |
|
950 | + continue; |
|
951 | + } |
|
922 | 952 | |
923 | 953 | switch((string) $key) |
924 | 954 | { |
@@ -933,12 +963,18 @@ discard block |
||
933 | 963 | } |
934 | 964 | elseif ($value) |
935 | 965 | { |
936 | - if (is_array($value)) $filters .= '(|'; |
|
966 | + if (is_array($value)) |
|
967 | + { |
|
968 | + $filters .= '(|'; |
|
969 | + } |
|
937 | 970 | foreach((array)$value as $value) |
938 | 971 | { |
939 | 972 | $filters .= '(uidNumber='.(int)$value.')'; |
940 | 973 | } |
941 | - if (is_array($value)) $filters .= ')'; |
|
974 | + if (is_array($value)) |
|
975 | + { |
|
976 | + $filters .= ')'; |
|
977 | + } |
|
942 | 978 | } |
943 | 979 | break; |
944 | 980 | |
@@ -954,19 +990,28 @@ discard block |
||
954 | 990 | $GLOBALS['egw']->categories = new Api\Categories(); |
955 | 991 | } |
956 | 992 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$value); |
957 | - if (count($cats) > 1) $filters .= '(|'; |
|
993 | + if (count($cats) > 1) |
|
994 | + { |
|
995 | + $filters .= '(|'; |
|
996 | + } |
|
958 | 997 | foreach($cats as $cat) |
959 | 998 | { |
960 | 999 | $catName = Api\Translation::convert( |
961 | 1000 | $GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8'); |
962 | 1001 | $filters .= '(category='.Api\Ldap::quote($catName).')'; |
963 | 1002 | } |
964 | - if (count($cats) > 1) $filters .= ')'; |
|
1003 | + if (count($cats) > 1) |
|
1004 | + { |
|
1005 | + $filters .= ')'; |
|
1006 | + } |
|
965 | 1007 | } |
966 | 1008 | break; |
967 | 1009 | |
968 | 1010 | case 'carddav_name': |
969 | - if (!is_array($value)) $value = array($value); |
|
1011 | + if (!is_array($value)) |
|
1012 | + { |
|
1013 | + $value = array($value); |
|
1014 | + } |
|
970 | 1015 | foreach($value as &$v) |
971 | 1016 | { |
972 | 1017 | $v = basename($v, '.vcf'); |
@@ -1000,7 +1045,10 @@ discard block |
||
1000 | 1045 | elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches)) |
1001 | 1046 | { |
1002 | 1047 | list(,$name,$value) = $matches; |
1003 | - if (strpos($name,'.') !== false) list(,$name) = explode('.',$name); |
|
1048 | + if (strpos($name,'.') !== false) |
|
1049 | + { |
|
1050 | + list(,$name) = explode('.',$name); |
|
1051 | + } |
|
1004 | 1052 | foreach($this->schema2egw as $mapping) |
1005 | 1053 | { |
1006 | 1054 | if (isset($mapping[$name])) |
@@ -1073,13 +1121,20 @@ discard block |
||
1073 | 1121 | { |
1074 | 1122 | $result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1075 | 1123 | } |
1076 | - if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1124 | + if(!$result || !$entries = ldap_get_entries($this->ds, $result)) |
|
1125 | + { |
|
1126 | + return array(); |
|
1127 | + } |
|
1077 | 1128 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]"); |
1078 | 1129 | |
1079 | 1130 | $this->total = $entries['count']; |
1080 | 1131 | foreach($entries as $i => $entry) |
1081 | 1132 | { |
1082 | - if (!is_int($i)) continue; // eg. count |
|
1133 | + if (!is_int($i)) |
|
1134 | + { |
|
1135 | + continue; |
|
1136 | + } |
|
1137 | + // eg. count |
|
1083 | 1138 | |
1084 | 1139 | $contact = array( |
1085 | 1140 | 'id' => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0], |
@@ -1211,7 +1266,10 @@ discard block |
||
1211 | 1266 | $var => $val, |
1212 | 1267 | ); |
1213 | 1268 | // create a admin connection to add the needed DN |
1214 | - if (!isset($adminDS)) $adminDS = Api\Ldap::factory(); |
|
1269 | + if (!isset($adminDS)) |
|
1270 | + { |
|
1271 | + $adminDS = Api\Ldap::factory(); |
|
1272 | + } |
|
1215 | 1273 | if(!@ldap_add($adminDS, $dn, $data)) |
1216 | 1274 | { |
1217 | 1275 | //echo "<p>ldap_add($adminDS,'$dn',".print_r($data,true).")</p>\n"; |
@@ -1297,11 +1355,17 @@ discard block |
||
1297 | 1355 | $contact['cat_id'] = array(); |
1298 | 1356 | foreach($data['category'] as $iii => $cat) |
1299 | 1357 | { |
1300 | - if (!is_int($iii)) continue; |
|
1358 | + if (!is_int($iii)) |
|
1359 | + { |
|
1360 | + continue; |
|
1361 | + } |
|
1301 | 1362 | |
1302 | 1363 | $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat); |
1303 | 1364 | } |
1304 | - if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1365 | + if ($contact['cat_id']) |
|
1366 | + { |
|
1367 | + $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1368 | + } |
|
1305 | 1369 | } |
1306 | 1370 | if ($data['primaryphone']) |
1307 | 1371 | { |
@@ -1356,7 +1420,10 @@ discard block |
||
1356 | 1420 | { |
1357 | 1421 | unset($contact); // not used, but required by function signature |
1358 | 1422 | static $shadowExpireNow=null; |
1359 | - if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1423 | + if (!isset($shadowExpireNow)) |
|
1424 | + { |
|
1425 | + $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1426 | + } |
|
1360 | 1427 | |
1361 | 1428 | // exclude expired or deactivated accounts |
1362 | 1429 | if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow) |
@@ -1401,9 +1468,13 @@ discard block |
||
1401 | 1468 | elseif ($data['adr_one_countryname']) |
1402 | 1469 | { |
1403 | 1470 | $ldapContact['c'] = Api\Country::country_code($data['adr_one_countryname']); |
1404 | - if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
|
1471 | + if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) |
|
1405 | 1472 | { |
1406 | - $ldapContact['c'] = array(); // should return error... |
|
1473 | + // Bad countryname when "custom" selected! |
|
1474 | + { |
|
1475 | + $ldapContact['c'] = array(); |
|
1476 | + } |
|
1477 | + // should return error... |
|
1407 | 1478 | } |
1408 | 1479 | } |
1409 | 1480 | elseif ($isUpdate) |
@@ -1442,14 +1513,21 @@ discard block |
||
1442 | 1513 | if ($data['adr_one_countrycode']) |
1443 | 1514 | { |
1444 | 1515 | $ldapContact['c'] = $data['adr_one_countrycode']; |
1445 | - if ($isUpdate) $ldapContact['co'] = array(); |
|
1516 | + if ($isUpdate) |
|
1517 | + { |
|
1518 | + $ldapContact['co'] = array(); |
|
1519 | + } |
|
1446 | 1520 | } |
1447 | 1521 | elseif ($data['adr_one_countryname']) |
1448 | 1522 | { |
1449 | 1523 | $ldapContact['c'] = Api\Country::country_code($data['adr_one_countryname']); |
1450 | - if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
|
1524 | + if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) |
|
1525 | + { |
|
1526 | + // Bad countryname when "custom" selected! |
|
1451 | 1527 | { |
1452 | - $ldapContact['c'] = array(); // should return error... |
|
1528 | + $ldapContact['c'] = array(); |
|
1529 | + } |
|
1530 | + // should return error... |
|
1453 | 1531 | } |
1454 | 1532 | } |
1455 | 1533 | elseif ($isUpdate) |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @var string |
40 | 40 | */ |
41 | - var $contacts_id='id'; |
|
41 | + var $contacts_id = 'id'; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @var string $accountName holds the accountname of the current user |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @var string |
88 | 88 | */ |
89 | - var $dn_attribute='uid'; |
|
89 | + var $dn_attribute = 'uid'; |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Do NOT attempt to change DN (dn-attribute can NOT be part of schemas used in addressbook!) |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * minimum: $this->columns_to_search = array('n_family','n_given','org_name','email'); |
114 | 114 | */ |
115 | 115 | var $search_attributes = array( |
116 | - 'n_family','n_middle','n_given','org_name','org_unit', |
|
117 | - 'adr_one_locality','adr_two_locality','note', |
|
118 | - 'email','mozillasecondemail','uidnumber', |
|
116 | + 'n_family', 'n_middle', 'n_given', 'org_name', 'org_unit', |
|
117 | + 'adr_one_locality', 'adr_two_locality', 'note', |
|
118 | + 'email', 'mozillasecondemail', 'uidnumber', |
|
119 | 119 | ); |
120 | 120 | |
121 | 121 | /** |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | #postOfficeBox |
172 | 172 | 'mozillaabpersonalpha' => array( |
173 | 173 | 'adr_one_street2' => 'mozillaworkstreet2', |
174 | - 'adr_one_countryname' => 'c', // 2 letter country code |
|
175 | - 'adr_one_countrycode' => 'c', // 2 letter country code |
|
174 | + 'adr_one_countryname' => 'c', // 2 letter country code |
|
175 | + 'adr_one_countrycode' => 'c', // 2 letter country code |
|
176 | 176 | 'adr_two_street' => 'mozillahomestreet', |
177 | 177 | 'adr_two_street2' => 'mozillahomestreet2', |
178 | 178 | 'adr_two_locality' => 'mozillahomelocalityname', |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | // similar to the newer mozillaAbPerson, but uses mozillaPostalAddress2 instead of mozillaStreet2 |
187 | 187 | 'mozillaorgperson' => array( |
188 | 188 | 'adr_one_street2' => 'mozillapostaladdress2', |
189 | - 'adr_one_countrycode' => 'c', // 2 letter country code |
|
190 | - 'adr_one_countryname' => 'co', // human readable country name, must be after 'c' to take precedence on read! |
|
189 | + 'adr_one_countrycode' => 'c', // 2 letter country code |
|
190 | + 'adr_one_countryname' => 'co', // human readable country name, must be after 'c' to take precedence on read! |
|
191 | 191 | 'adr_two_street' => 'mozillahomestreet', |
192 | 192 | 'adr_two_street2' => 'mozillahomepostaladdress2', |
193 | 193 | 'adr_two_locality' => 'mozillahomelocalityname', |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | 'note' => 'note', |
214 | 214 | 'tel_car' => 'carphone', |
215 | 215 | 'tel_prefer' => 'primaryphone', |
216 | - 'cat_id' => 'category', // special handling in _egw2evolutionperson method |
|
216 | + 'cat_id' => 'category', // special handling in _egw2evolutionperson method |
|
217 | 217 | 'role' => 'businessrole', |
218 | 218 | 'tel_assistent' => 'assistantphone', |
219 | 219 | 'assistent' => 'assistantname', |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | 'freebusy_uri' => 'freeBusyuri', |
223 | 223 | 'calendar_uri' => 'calendaruri', |
224 | 224 | 'tel_other' => 'otherphone', |
225 | - 'tel_cell_private' => 'callbackphone', // not the best choice, but better then nothing |
|
225 | + 'tel_cell_private' => 'callbackphone', // not the best choice, but better then nothing |
|
226 | 226 | ), |
227 | 227 | // additional schema can be added here, including special functions |
228 | 228 | |
@@ -270,10 +270,10 @@ discard block |
||
270 | 270 | * @param array $ldap_config =null default use from $GLOBALS['egw_info']['server'] |
271 | 271 | * @param resource $ds =null ldap connection to use |
272 | 272 | */ |
273 | - function __construct(array $ldap_config=null, $ds=null) |
|
273 | + function __construct(array $ldap_config = null, $ds = null) |
|
274 | 274 | { |
275 | 275 | //$this->db_data_cols = $this->stock_contact_fields + $this->non_contact_fields; |
276 | - $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
276 | + $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
277 | 277 | |
278 | 278 | if ($ldap_config) |
279 | 279 | { |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | } |
282 | 282 | else |
283 | 283 | { |
284 | - $this->ldap_config =& $GLOBALS['egw_info']['server']; |
|
284 | + $this->ldap_config = & $GLOBALS['egw_info']['server']; |
|
285 | 285 | } |
286 | 286 | $this->accountContactsDN = $this->ldap_config['ldap_context']; |
287 | - $this->allContactsDN = $this->ldap_config['ldap_contact_context']; |
|
288 | - $this->personalContactsDN = 'ou=personal,ou=contacts,'. $this->allContactsDN; |
|
289 | - $this->sharedContactsDN = 'ou=shared,ou=contacts,'. $this->allContactsDN; |
|
287 | + $this->allContactsDN = $this->ldap_config['ldap_contact_context']; |
|
288 | + $this->personalContactsDN = 'ou=personal,ou=contacts,'.$this->allContactsDN; |
|
289 | + $this->sharedContactsDN = 'ou=shared,ou=contacts,'.$this->allContactsDN; |
|
290 | 290 | |
291 | 291 | if ($ds) |
292 | 292 | { |
@@ -298,9 +298,9 @@ discard block |
||
298 | 298 | } |
299 | 299 | $this->ldapServerInfo = $GLOBALS['egw']->ldap->getLDAPServerInfo($this->ldap_config['ldap_contact_host']); |
300 | 300 | |
301 | - foreach($this->schema2egw as $attributes) |
|
301 | + foreach ($this->schema2egw as $attributes) |
|
302 | 302 | { |
303 | - $this->all_attributes = array_merge($this->all_attributes,array_values($attributes)); |
|
303 | + $this->all_attributes = array_merge($this->all_attributes, array_values($attributes)); |
|
304 | 304 | } |
305 | 305 | $this->all_attributes = array_values(array_unique($this->all_attributes)); |
306 | 306 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | $this->ds = Api\Ldap::factory(); |
328 | 328 | } |
329 | 329 | // if ldap is NOT the contact repository, we only do accounts and need to use the account-data |
330 | - elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap') // not (ldap or sql-ldap) |
|
330 | + elseif (substr($GLOBALS['egw_info']['server']['contact_repository'], -4) != 'ldap') // not (ldap or sql-ldap) |
|
331 | 331 | { |
332 | 332 | $this->ldap_config['ldap_contact_host'] = $this->ldap_config['ldap_host']; |
333 | 333 | $this->allContactsDN = $this->ldap_config['ldap_context']; |
@@ -351,17 +351,17 @@ discard block |
||
351 | 351 | function supported_fields() |
352 | 352 | { |
353 | 353 | $fields = array( |
354 | - 'id','tid','owner', |
|
355 | - 'n_middle','n_prefix','n_suffix', // stored in the cn |
|
356 | - 'created','modified', // automatic timestamps |
|
357 | - 'creator','modifier', // automatic for non accounts |
|
358 | - 'private', // true for personal addressbooks, false otherwise |
|
354 | + 'id', 'tid', 'owner', |
|
355 | + 'n_middle', 'n_prefix', 'n_suffix', // stored in the cn |
|
356 | + 'created', 'modified', // automatic timestamps |
|
357 | + 'creator', 'modifier', // automatic for non accounts |
|
358 | + 'private', // true for personal addressbooks, false otherwise |
|
359 | 359 | ); |
360 | - foreach($this->schema2egw as $objectclass => $mapping) |
|
360 | + foreach ($this->schema2egw as $objectclass => $mapping) |
|
361 | 361 | { |
362 | - if($this->ldapServerInfo->supportsObjectClass($objectclass)) |
|
362 | + if ($this->ldapServerInfo->supportsObjectClass($objectclass)) |
|
363 | 363 | { |
364 | - $fields = array_merge($fields,array_keys($mapping)); |
|
364 | + $fields = array_merge($fields, array_keys($mapping)); |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | return array_values(array_unique($fields)); |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | return $this->id_filter(is_array($ids) ? array_shift($ids) : $ids); |
393 | 393 | } |
394 | 394 | $filter = array(); |
395 | - foreach($ids as $id) |
|
395 | + foreach ($ids as $id) |
|
396 | 396 | { |
397 | 397 | $filter[] = $this->id_filter($id); |
398 | 398 | } |
@@ -408,9 +408,9 @@ discard block |
||
408 | 408 | function read($contact_id) |
409 | 409 | { |
410 | 410 | if (is_array($contact_id) && isset($contact_id['account_id']) || |
411 | - !is_array($contact_id) && substr($contact_id,0,8) == 'account:') |
|
411 | + !is_array($contact_id) && substr($contact_id, 0, 8) == 'account:') |
|
412 | 412 | { |
413 | - $filter = 'uidNumber='.(int)(is_array($contact_id) ? $contact_id['account_id'] : substr($contact_id,8)); |
|
413 | + $filter = 'uidNumber='.(int)(is_array($contact_id) ? $contact_id['account_id'] : substr($contact_id, 8)); |
|
414 | 414 | } |
415 | 415 | else |
416 | 416 | { |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | // never allow to change the uidNumber (account_id) on update, as it could be misused by eg. xmlrpc or syncml |
434 | 434 | unset($ldapContact['uidnumber']); |
435 | 435 | |
436 | - unset($ldapContact['entryuuid']); // not allowed to modify that, no need either |
|
436 | + unset($ldapContact['entryuuid']); // not allowed to modify that, no need either |
|
437 | 437 | |
438 | 438 | unset($ldapContact['objectClass']); |
439 | 439 | } |
@@ -444,28 +444,28 @@ discard block |
||
444 | 444 | * @param array $keys if given $keys are copied to data before saveing => allows a save as |
445 | 445 | * @return int 0 on success and errno != 0 else |
446 | 446 | */ |
447 | - function save($keys=null) |
|
447 | + function save($keys = null) |
|
448 | 448 | { |
449 | 449 | //error_log(__METHOD__."(".array2string($keys).") this->data=".array2string($this->data)); |
450 | - if(is_array($keys)) |
|
450 | + if (is_array($keys)) |
|
451 | 451 | { |
452 | - $this->data = is_array($this->data) ? array_merge($this->data,$keys) : $keys; |
|
452 | + $this->data = is_array($this->data) ? array_merge($this->data, $keys) : $keys; |
|
453 | 453 | } |
454 | 454 | |
455 | - $data =& $this->data; |
|
455 | + $data = & $this->data; |
|
456 | 456 | $isUpdate = false; |
457 | 457 | $ldapContact = array(); |
458 | 458 | |
459 | 459 | // generate addressbook dn |
460 | - if((int)$data['owner']) |
|
460 | + if ((int)$data['owner']) |
|
461 | 461 | { |
462 | 462 | // group address book |
463 | - if(!($cn = strtolower($GLOBALS['egw']->accounts->id2name((int)$data['owner'])))) |
|
463 | + if (!($cn = strtolower($GLOBALS['egw']->accounts->id2name((int)$data['owner'])))) |
|
464 | 464 | { |
465 | 465 | error_log('Unknown owner'); |
466 | 466 | return true; |
467 | 467 | } |
468 | - $baseDN = 'cn='. $cn .','.($data['owner'] < 0 ? $this->sharedContactsDN : $this->personalContactsDN); |
|
468 | + $baseDN = 'cn='.$cn.','.($data['owner'] < 0 ? $this->sharedContactsDN : $this->personalContactsDN); |
|
469 | 469 | } |
470 | 470 | // only an admin or the user itself is allowed to change the data of an account |
471 | 471 | elseif ($data['account_id'] && ($GLOBALS['egw_info']['user']['apps']['admin'] || |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | { |
474 | 474 | // account |
475 | 475 | $baseDN = $this->accountContactsDN; |
476 | - $cn = false; |
|
476 | + $cn = false; |
|
477 | 477 | // we need an admin connection |
478 | 478 | $this->connect(true); |
479 | 479 | |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | else |
487 | 487 | { |
488 | 488 | error_log("Permission denied, to write: data[owner]=$data[owner], data[account_id]=$data[account_id], account_id=".$GLOBALS['egw_info']['user']['account_id']); |
489 | - return lang('Permission denied !!!'); // only admin or the user itself is allowd to write accounts! |
|
489 | + return lang('Permission denied !!!'); // only admin or the user itself is allowd to write accounts! |
|
490 | 490 | } |
491 | 491 | // check if $baseDN exists. If not create it |
492 | 492 | if (($err = $this->_check_create_dn($baseDN))) |
@@ -495,55 +495,54 @@ discard block |
||
495 | 495 | } |
496 | 496 | // check the existing objectclasses of an entry, none = array() for new ones |
497 | 497 | $oldObjectclasses = array(); |
498 | - $attributes = array('dn','cn','objectClass',$this->dn_attribute,'mail'); |
|
498 | + $attributes = array('dn', 'cn', 'objectClass', $this->dn_attribute, 'mail'); |
|
499 | 499 | |
500 | 500 | $contactUID = $this->data[$this->contacts_id]; |
501 | 501 | if (!empty($contactUID) && |
502 | - ($result = ldap_search($this->ds, $base=$this->allContactsDN, $this->id_filter($contactUID), $attributes)) && |
|
502 | + ($result = ldap_search($this->ds, $base = $this->allContactsDN, $this->id_filter($contactUID), $attributes)) && |
|
503 | 503 | ($oldContactInfo = ldap_get_entries($this->ds, $result)) && $oldContactInfo['count']) |
504 | 504 | { |
505 | 505 | unset($oldContactInfo[0]['objectclass']['count']); |
506 | - foreach($oldContactInfo[0]['objectclass'] as $objectclass) |
|
506 | + foreach ($oldContactInfo[0]['objectclass'] as $objectclass) |
|
507 | 507 | { |
508 | - $oldObjectclasses[] = strtolower($objectclass); |
|
508 | + $oldObjectclasses[] = strtolower($objectclass); |
|
509 | 509 | } |
510 | 510 | $isUpdate = true; |
511 | 511 | } |
512 | 512 | |
513 | - if(empty($contactUID)) |
|
513 | + if (empty($contactUID)) |
|
514 | 514 | { |
515 | 515 | $ldapContact[$this->dn_attribute] = $this->data[$this->contacts_id] = $contactUID = md5(Api\Auth::randomstring(15)); |
516 | 516 | } |
517 | 517 | //error_log(__METHOD__."() contactUID='$contactUID', isUpdate=".array2string($isUpdate).", oldContactInfo=".array2string($oldContactInfo)); |
518 | 518 | // add for all supported objectclasses the objectclass and it's attributes |
519 | - foreach($this->schema2egw as $objectclass => $mapping) |
|
519 | + foreach ($this->schema2egw as $objectclass => $mapping) |
|
520 | 520 | { |
521 | - if(!$this->ldapServerInfo->supportsObjectClass($objectclass)) continue; |
|
521 | + if (!$this->ldapServerInfo->supportsObjectClass($objectclass)) continue; |
|
522 | 522 | |
523 | - if($objectclass != 'posixaccount' && !in_array($objectclass, $oldObjectclasses)) |
|
523 | + if ($objectclass != 'posixaccount' && !in_array($objectclass, $oldObjectclasses)) |
|
524 | 524 | { |
525 | 525 | $ldapContact['objectClass'][] = $objectclass; |
526 | 526 | } |
527 | 527 | if (isset($this->required_subs[$objectclass])) |
528 | 528 | { |
529 | - foreach($this->required_subs[$objectclass] as $sub) |
|
529 | + foreach ($this->required_subs[$objectclass] as $sub) |
|
530 | 530 | { |
531 | - if(!in_array($sub, $oldObjectclasses)) |
|
531 | + if (!in_array($sub, $oldObjectclasses)) |
|
532 | 532 | { |
533 | 533 | $ldapContact['objectClass'][] = $sub; |
534 | 534 | } |
535 | 535 | } |
536 | 536 | } |
537 | - foreach($mapping as $egwFieldName => $ldapFieldName) |
|
537 | + foreach ($mapping as $egwFieldName => $ldapFieldName) |
|
538 | 538 | { |
539 | 539 | if (is_int($egwFieldName)) continue; |
540 | - if(!empty($data[$egwFieldName])) |
|
540 | + if (!empty($data[$egwFieldName])) |
|
541 | 541 | { |
542 | 542 | // dont convert the (binary) jpegPhoto! |
543 | - $ldapContact[$ldapFieldName] = $ldapFieldName == 'jpegphoto' ? $data[$egwFieldName] : |
|
544 | - Api\Translation::convert(trim($data[$egwFieldName]),$this->charset,'utf-8'); |
|
543 | + $ldapContact[$ldapFieldName] = $ldapFieldName == 'jpegphoto' ? $data[$egwFieldName] : Api\Translation::convert(trim($data[$egwFieldName]), $this->charset, 'utf-8'); |
|
545 | 544 | } |
546 | - elseif($isUpdate && isset($data[$egwFieldName])) |
|
545 | + elseif ($isUpdate && isset($data[$egwFieldName])) |
|
547 | 546 | { |
548 | 547 | $ldapContact[$ldapFieldName] = array(); |
549 | 548 | } |
@@ -551,9 +550,9 @@ discard block |
||
551 | 550 | } |
552 | 551 | // handling of special attributes, like cat_id in evolutionPerson |
553 | 552 | $egw2objectclass = '_egw2'.$objectclass; |
554 | - if (method_exists($this,$egw2objectclass)) |
|
553 | + if (method_exists($this, $egw2objectclass)) |
|
555 | 554 | { |
556 | - $this->$egw2objectclass($ldapContact,$data,$isUpdate); |
|
555 | + $this->$egw2objectclass($ldapContact, $data, $isUpdate); |
|
557 | 556 | } |
558 | 557 | } |
559 | 558 | if ($isUpdate) |
@@ -571,11 +570,11 @@ discard block |
||
571 | 570 | $needRecreation = false; |
572 | 571 | |
573 | 572 | // add missing objectclasses |
574 | - if($ldapContact['objectClass'] && ($missing=array_diff($ldapContact['objectClass'],$oldObjectclasses))) |
|
573 | + if ($ldapContact['objectClass'] && ($missing = array_diff($ldapContact['objectClass'], $oldObjectclasses))) |
|
575 | 574 | { |
576 | 575 | if (!@ldap_mod_add($this->ds, $dn, array('objectClass' => $ldapContact['objectClass']))) |
577 | 576 | { |
578 | - if(in_array(ldap_errno($this->ds),array(69,20))) |
|
577 | + if (in_array(ldap_errno($this->ds), array(69, 20))) |
|
579 | 578 | { |
580 | 579 | // need to modify structural objectclass |
581 | 580 | $needRecreation = true; |
@@ -584,15 +583,15 @@ discard block |
||
584 | 583 | else |
585 | 584 | { |
586 | 585 | //echo "<p>ldap_mod_add($this->ds,'$dn',array(objectClass =>".print_r($ldapContact['objectClass'],true)."))</p>\n"; |
587 | - error_log(__METHOD__.'() '.__LINE__.' update of '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .')'); |
|
586 | + error_log(__METHOD__.'() '.__LINE__.' update of '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).')'); |
|
588 | 587 | return $this->_error(__LINE__); |
589 | 588 | } |
590 | 589 | } |
591 | 590 | } |
592 | 591 | |
593 | 592 | // check if we need to rename the DN or need to recreate the contact |
594 | - $newRDN = $this->dn_attribute.'='. $ldapContact[$this->dn_attribute]; |
|
595 | - $newDN = $newRDN .','. $baseDN; |
|
593 | + $newRDN = $this->dn_attribute.'='.$ldapContact[$this->dn_attribute]; |
|
594 | + $newDN = $newRDN.','.$baseDN; |
|
596 | 595 | if ($needRecreation) |
597 | 596 | { |
598 | 597 | $result = ldap_read($this->ds, $dn, 'objectclass=*'); |
@@ -603,20 +602,20 @@ discard block |
||
603 | 602 | $newContact = $oldContact; |
604 | 603 | $newContact[$this->dn_attribute] = $ldapContact[$this->dn_attribute]; |
605 | 604 | |
606 | - if(is_array($ldapContact['objectClass']) && count($ldapContact['objectClass']) > 0) |
|
605 | + if (is_array($ldapContact['objectClass']) && count($ldapContact['objectClass']) > 0) |
|
607 | 606 | { |
608 | - $newContact['objectclass'] = array_unique(array_map('strtolower', // objectclasses my have different case |
|
607 | + $newContact['objectclass'] = array_unique(array_map('strtolower', // objectclasses my have different case |
|
609 | 608 | array_merge($newContact['objectclass'], $ldapContact['objectClass']))); |
610 | 609 | } |
611 | 610 | |
612 | - if(!ldap_delete($this->ds, $dn)) |
|
611 | + if (!ldap_delete($this->ds, $dn)) |
|
613 | 612 | { |
614 | - error_log(__METHOD__.'() '.__LINE__.' delete of old '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .')'); |
|
613 | + error_log(__METHOD__.'() '.__LINE__.' delete of old '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).')'); |
|
615 | 614 | return $this->_error(__LINE__); |
616 | 615 | } |
617 | - if(!@ldap_add($this->ds, $newDN, $newContact)) |
|
616 | + if (!@ldap_add($this->ds, $newDN, $newContact)) |
|
618 | 617 | { |
619 | - error_log(__METHOD__.'() '.__LINE__.' re-create contact as '. $newDN .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .') newContact='.array2string($newContact)); |
|
618 | + error_log(__METHOD__.'() '.__LINE__.' re-create contact as '.$newDN.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).') newContact='.array2string($newContact)); |
|
620 | 619 | // if adding with new objectclass or dn fails, re-add deleted contact |
621 | 620 | @ldap_add($this->ds, $dn, $oldContact); |
622 | 621 | return $this->_error(__LINE__); |
@@ -645,22 +644,22 @@ discard block |
||
645 | 644 | |
646 | 645 | if (!@ldap_modify($this->ds, $dn, $ldapContact)) |
647 | 646 | { |
648 | - error_log(__METHOD__.'() '.__LINE__.' update of '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .') ldapContact='.array2string($ldapContact)); |
|
647 | + error_log(__METHOD__.'() '.__LINE__.' update of '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).') ldapContact='.array2string($ldapContact)); |
|
649 | 648 | return $this->_error(__LINE__); |
650 | 649 | } |
651 | 650 | } |
652 | 651 | else |
653 | 652 | { |
654 | - $dn = $this->dn_attribute.'='. $ldapContact[$this->dn_attribute] .','. $baseDN; |
|
655 | - unset($ldapContact['entryuuid']); // trying to write it, gives an error |
|
653 | + $dn = $this->dn_attribute.'='.$ldapContact[$this->dn_attribute].','.$baseDN; |
|
654 | + unset($ldapContact['entryuuid']); // trying to write it, gives an error |
|
656 | 655 | |
657 | 656 | if (!@ldap_add($this->ds, $dn, $ldapContact)) |
658 | 657 | { |
659 | - error_log(__METHOD__.'() '.__LINE__.' add of '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .') ldapContact='.array2string($ldapContact)); |
|
658 | + error_log(__METHOD__.'() '.__LINE__.' add of '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).') ldapContact='.array2string($ldapContact)); |
|
660 | 659 | return $this->_error(__LINE__); |
661 | 660 | } |
662 | 661 | } |
663 | - return 0; // Ok, no error |
|
662 | + return 0; // Ok, no error |
|
664 | 663 | } |
665 | 664 | |
666 | 665 | /** |
@@ -669,28 +668,28 @@ discard block |
||
669 | 668 | * @param array $keys if given array with col => value pairs to characterise the rows to delete |
670 | 669 | * @return int affected rows, should be 1 if ok, 0 if an error |
671 | 670 | */ |
672 | - function delete($keys=null) |
|
671 | + function delete($keys = null) |
|
673 | 672 | { |
674 | 673 | // single entry |
675 | - if($keys[$this->contacts_id]) $keys = array( 0 => $keys); |
|
674 | + if ($keys[$this->contacts_id]) $keys = array(0 => $keys); |
|
676 | 675 | |
677 | - if(!is_array($keys)) |
|
676 | + if (!is_array($keys)) |
|
678 | 677 | { |
679 | - $keys = array( $keys); |
|
678 | + $keys = array($keys); |
|
680 | 679 | } |
681 | 680 | |
682 | 681 | $ret = 0; |
683 | 682 | |
684 | 683 | $attributes = array('dn'); |
685 | 684 | |
686 | - foreach($keys as $entry) |
|
685 | + foreach ($keys as $entry) |
|
687 | 686 | { |
688 | 687 | $entry = Api\Ldap::quote(is_array($entry) ? $entry['id'] : $entry); |
689 | - if(($result = ldap_search($this->ds, $this->allContactsDN, |
|
688 | + if (($result = ldap_search($this->ds, $this->allContactsDN, |
|
690 | 689 | "(|(entryUUID=$entry)(uid=$entry))", $attributes))) |
691 | 690 | { |
692 | 691 | $contactInfo = ldap_get_entries($this->ds, $result); |
693 | - if(@ldap_delete($this->ds, $contactInfo[0]['dn'])) |
|
692 | + if (@ldap_delete($this->ds, $contactInfo[0]['dn'])) |
|
694 | 693 | { |
695 | 694 | $ret++; |
696 | 695 | } |
@@ -718,10 +717,10 @@ discard block |
||
718 | 717 | * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false |
719 | 718 | * @return array of matching rows (the row is an array of the cols) or False |
720 | 719 | */ |
721 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) |
|
720 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false) |
|
722 | 721 | { |
723 | 722 | //error_log(__METHOD__."(".array2string($criteria).", ".array2string($only_keys).", '$order_by', ".array2string($extra_cols).", '$wildcard', '$empty', '$op', ".array2string($start).", ".array2string($filter).")"); |
724 | - unset($only_keys, $extra_cols, $empty, $join, $need_full_no_count); // not used, but required by function signature |
|
723 | + unset($only_keys, $extra_cols, $empty, $join, $need_full_no_count); // not used, but required by function signature |
|
725 | 724 | |
726 | 725 | if (is_array($filter['owner'])) |
727 | 726 | { |
@@ -743,7 +742,7 @@ discard block |
||
743 | 742 | 'created' => 'createtimestamp', |
744 | 743 | 'modified' => 'modifytimestamp', |
745 | 744 | ); |
746 | - foreach($filter as $key => $value) |
|
745 | + foreach ($filter as $key => $value) |
|
747 | 746 | { |
748 | 747 | $matches = null; |
749 | 748 | if (is_int($key) && preg_match('/^(contact_)?(modified|created)([<=>]+)([0-9]+)$/', $value, $matches)) |
@@ -759,11 +758,11 @@ discard block |
||
759 | 758 | } |
760 | 759 | } |
761 | 760 | |
762 | - if((int)$filter['owner']) |
|
761 | + if ((int)$filter['owner']) |
|
763 | 762 | { |
764 | 763 | if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner']))) return false; |
765 | 764 | |
766 | - $searchDN = 'cn='. Api\Ldap::quote(strtolower($accountName)) .','; |
|
765 | + $searchDN = 'cn='.Api\Ldap::quote(strtolower($accountName)).','; |
|
767 | 766 | |
768 | 767 | if ($filter['owner'] < 0) |
769 | 768 | { |
@@ -787,7 +786,7 @@ discard block |
||
787 | 786 | $addressbookType = self::ACCOUNTS; |
788 | 787 | } |
789 | 788 | // create the search filter |
790 | - switch($addressbookType) |
|
789 | + switch ($addressbookType) |
|
791 | 790 | { |
792 | 791 | case self::ACCOUNTS: |
793 | 792 | $objectFilter = $this->accountsFilter; |
@@ -802,42 +801,42 @@ discard block |
||
802 | 801 | // shadowExpire>= does NOT work, as shadow schema only specifies integerMatch and not integerOrderingMatch :-( |
803 | 802 | |
804 | 803 | $searchFilter = ''; |
805 | - if(is_array($criteria) && count($criteria) > 0) |
|
804 | + if (is_array($criteria) && count($criteria) > 0) |
|
806 | 805 | { |
807 | 806 | $wildcard = $wildcard === '%' ? '*' : ''; |
808 | 807 | $searchFilter = ''; |
809 | - foreach($criteria as $egwSearchKey => $searchValue) |
|
808 | + foreach ($criteria as $egwSearchKey => $searchValue) |
|
810 | 809 | { |
811 | - if (in_array($egwSearchKey, array('id','contact_id'))) |
|
810 | + if (in_array($egwSearchKey, array('id', 'contact_id'))) |
|
812 | 811 | { |
813 | 812 | try { |
814 | 813 | $searchFilter .= $this->ids_filter($searchValue); |
815 | 814 | } |
816 | 815 | // catch and ignore exception caused by id not being a valid GUID |
817 | - catch(Api\Exception\AssertionFailed $e) { |
|
816 | + catch (Api\Exception\AssertionFailed $e) { |
|
818 | 817 | unset($e); |
819 | 818 | } |
820 | 819 | continue; |
821 | 820 | } |
822 | - foreach($this->schema2egw as $mapping) |
|
821 | + foreach ($this->schema2egw as $mapping) |
|
823 | 822 | { |
824 | 823 | $matches = null; |
825 | 824 | if (preg_match('/^(egw_addressbook\.)?(contact_)?(.*)$/', $egwSearchKey, $matches)) |
826 | 825 | { |
827 | 826 | $egwSearchKey = $matches[3]; |
828 | 827 | } |
829 | - if(($ldapSearchKey = $mapping[$egwSearchKey])) |
|
828 | + if (($ldapSearchKey = $mapping[$egwSearchKey])) |
|
830 | 829 | { |
831 | - foreach((array)$searchValue as $val) |
|
830 | + foreach ((array)$searchValue as $val) |
|
832 | 831 | { |
833 | - $searchString = Api\Translation::convert($val, $this->charset,'utf-8'); |
|
832 | + $searchString = Api\Translation::convert($val, $this->charset, 'utf-8'); |
|
834 | 833 | $searchFilter .= '('.$ldapSearchKey.'='.$wildcard.Api\Ldap::quote($searchString).$wildcard.')'; |
835 | 834 | } |
836 | 835 | break; |
837 | 836 | } |
838 | 837 | } |
839 | 838 | } |
840 | - if($op == 'AND') |
|
839 | + if ($op == 'AND') |
|
841 | 840 | { |
842 | 841 | $searchFilter = "(&$searchFilter)"; |
843 | 842 | } |
@@ -856,9 +855,9 @@ discard block |
||
856 | 855 | // only return certain owners --> unset not matching ones |
857 | 856 | if ($owner_filter) |
858 | 857 | { |
859 | - foreach($rows as $k => $row) |
|
858 | + foreach ($rows as $k => $row) |
|
860 | 859 | { |
861 | - if (!in_array($row['owner'],$owner_filter)) |
|
860 | + if (!in_array($row['owner'], $owner_filter)) |
|
862 | 861 | { |
863 | 862 | unset($rows[$k]); |
864 | 863 | --$this->total; |
@@ -869,18 +868,18 @@ discard block |
||
869 | 868 | { |
870 | 869 | $order = array(); |
871 | 870 | $sort = 'ASC'; |
872 | - foreach(explode(',',$order_by) as $o) |
|
871 | + foreach (explode(',', $order_by) as $o) |
|
873 | 872 | { |
874 | - if (substr($o,0,8) == 'contact_') $o = substr($o,8); |
|
875 | - if (substr($o,-4) == ' ASC') |
|
873 | + if (substr($o, 0, 8) == 'contact_') $o = substr($o, 8); |
|
874 | + if (substr($o, -4) == ' ASC') |
|
876 | 875 | { |
877 | 876 | $sort = 'ASC'; |
878 | - $order[] = substr($o,0,-4); |
|
877 | + $order[] = substr($o, 0, -4); |
|
879 | 878 | } |
880 | - elseif (substr($o,-5) == ' DESC') |
|
879 | + elseif (substr($o, -5) == ' DESC') |
|
881 | 880 | { |
882 | 881 | $sort = 'DESC'; |
883 | - $order[] = substr($o,0,-5); |
|
882 | + $order[] = substr($o, 0, -5); |
|
884 | 883 | } |
885 | 884 | elseif ($o) |
886 | 885 | { |
@@ -889,9 +888,9 @@ discard block |
||
889 | 888 | } |
890 | 889 | usort($rows, function($a, $b) use ($order, $sort) |
891 | 890 | { |
892 | - foreach($order as $f) |
|
891 | + foreach ($order as $f) |
|
893 | 892 | { |
894 | - if($sort == 'ASC') |
|
893 | + if ($sort == 'ASC') |
|
895 | 894 | { |
896 | 895 | $strc = strcmp($a[$f], $b[$f]); |
897 | 896 | } |
@@ -907,13 +906,13 @@ discard block |
||
907 | 906 | // if requested ($start !== false) return only limited resultset |
908 | 907 | if (is_array($start)) |
909 | 908 | { |
910 | - list($start,$offset) = $start; |
|
909 | + list($start, $offset) = $start; |
|
911 | 910 | } |
912 | - if(is_numeric($start) && is_numeric($offset) && $offset >= 0) |
|
911 | + if (is_numeric($start) && is_numeric($offset) && $offset >= 0) |
|
913 | 912 | { |
914 | 913 | return array_slice($rows, $start, $offset); |
915 | 914 | } |
916 | - elseif(is_numeric($start)) |
|
915 | + elseif (is_numeric($start)) |
|
917 | 916 | { |
918 | 917 | return array_slice($rows, $start, $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']); |
919 | 918 | } |
@@ -931,11 +930,11 @@ discard block |
||
931 | 930 | if (!is_array($filter)) return ''; |
932 | 931 | |
933 | 932 | $filters = ''; |
934 | - foreach($filter as $key => $value) |
|
933 | + foreach ($filter as $key => $value) |
|
935 | 934 | { |
936 | 935 | if ($key != 'cat_id' && $key != 'account_id' && !$value) continue; |
937 | 936 | |
938 | - switch((string) $key) |
|
937 | + switch ((string)$key) |
|
939 | 938 | { |
940 | 939 | case 'owner': // already handled |
941 | 940 | case 'tid': // ignored |
@@ -949,7 +948,7 @@ discard block |
||
949 | 948 | elseif ($value) |
950 | 949 | { |
951 | 950 | if (is_array($value)) $filters .= '(|'; |
952 | - foreach((array)$value as $value) |
|
951 | + foreach ((array)$value as $value) |
|
953 | 952 | { |
954 | 953 | $filters .= '(uidNumber='.(int)$value.')'; |
955 | 954 | } |
@@ -962,7 +961,7 @@ discard block |
||
962 | 961 | { |
963 | 962 | $filters .= '(!(category=*))'; |
964 | 963 | } |
965 | - elseif((int)$value) |
|
964 | + elseif ((int)$value) |
|
966 | 965 | { |
967 | 966 | if (!is_object($GLOBALS['egw']->categories)) |
968 | 967 | { |
@@ -970,10 +969,10 @@ discard block |
||
970 | 969 | } |
971 | 970 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$value); |
972 | 971 | if (count($cats) > 1) $filters .= '(|'; |
973 | - foreach($cats as $cat) |
|
972 | + foreach ($cats as $cat) |
|
974 | 973 | { |
975 | 974 | $catName = Api\Translation::convert( |
976 | - $GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8'); |
|
975 | + $GLOBALS['egw']->categories->id2name($cat), $this->charset, 'utf-8'); |
|
977 | 976 | $filters .= '(category='.Api\Ldap::quote($catName).')'; |
978 | 977 | } |
979 | 978 | if (count($cats) > 1) $filters .= ')'; |
@@ -982,7 +981,7 @@ discard block |
||
982 | 981 | |
983 | 982 | case 'carddav_name': |
984 | 983 | if (!is_array($value)) $value = array($value); |
985 | - foreach($value as &$v) |
|
984 | + foreach ($value as &$v) |
|
986 | 985 | { |
987 | 986 | $v = basename($v, '.vcf'); |
988 | 987 | } |
@@ -1000,28 +999,27 @@ discard block |
||
1000 | 999 | $matches = null; |
1001 | 1000 | if (!is_int($key)) |
1002 | 1001 | { |
1003 | - foreach($this->schema2egw as $mapping) |
|
1002 | + foreach ($this->schema2egw as $mapping) |
|
1004 | 1003 | { |
1005 | 1004 | if (isset($mapping[$key])) |
1006 | 1005 | { |
1007 | 1006 | // todo: value = "!''" |
1008 | - $filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : |
|
1009 | - Api\Ldap::quote(Api\Translation::convert($value,$this->charset,'utf-8'))).')'; |
|
1007 | + $filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : Api\Ldap::quote(Api\Translation::convert($value, $this->charset, 'utf-8'))).')'; |
|
1010 | 1008 | break; |
1011 | 1009 | } |
1012 | 1010 | } |
1013 | 1011 | } |
1014 | 1012 | // filter for letter-search |
1015 | - elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches)) |
|
1013 | + elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/", $value, $matches)) |
|
1016 | 1014 | { |
1017 | - list(,$name,$value) = $matches; |
|
1018 | - if (strpos($name,'.') !== false) list(,$name) = explode('.',$name); |
|
1019 | - foreach($this->schema2egw as $mapping) |
|
1015 | + list(,$name, $value) = $matches; |
|
1016 | + if (strpos($name, '.') !== false) list(,$name) = explode('.', $name); |
|
1017 | + foreach ($this->schema2egw as $mapping) |
|
1020 | 1018 | { |
1021 | 1019 | if (isset($mapping[$name])) |
1022 | 1020 | { |
1023 | 1021 | $filters .= '('.$mapping[$name].'='.Api\Ldap::quote( |
1024 | - Api\Translation::convert($value,$this->charset,'utf-8')).'*)'; |
|
1022 | + Api\Translation::convert($value, $this->charset, 'utf-8')).'*)'; |
|
1025 | 1023 | break; |
1026 | 1024 | } |
1027 | 1025 | } |
@@ -1045,7 +1043,7 @@ discard block |
||
1045 | 1043 | { |
1046 | 1044 | $filter .= '(|'; |
1047 | 1045 | // unfortunately we have no group-membership attribute in LDAP, like in AD |
1048 | - foreach($GLOBALS['egw']->accounts->members($gid, true) as $account_id) |
|
1046 | + foreach ($GLOBALS['egw']->accounts->members($gid, true) as $account_id) |
|
1049 | 1047 | { |
1050 | 1048 | $filter .= '(uidNumber='.(int)$account_id.')'; |
1051 | 1049 | } |
@@ -1067,7 +1065,7 @@ discard block |
||
1067 | 1065 | * @param array $_skipPlugins =null schema-plugins to skip |
1068 | 1066 | * @return array/boolean with eGW contacts or false on error |
1069 | 1067 | */ |
1070 | - function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins=null) |
|
1068 | + function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins = null) |
|
1071 | 1069 | { |
1072 | 1070 | $this->total = 0; |
1073 | 1071 | |
@@ -1080,7 +1078,7 @@ discard block |
||
1080 | 1078 | |
1081 | 1079 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype)"); |
1082 | 1080 | |
1083 | - if($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN) |
|
1081 | + if ($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN) |
|
1084 | 1082 | { |
1085 | 1083 | $result = ldap_search($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1086 | 1084 | } |
@@ -1088,36 +1086,36 @@ discard block |
||
1088 | 1086 | { |
1089 | 1087 | $result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1090 | 1088 | } |
1091 | - if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1089 | + if (!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1092 | 1090 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]"); |
1093 | 1091 | |
1094 | 1092 | $this->total = $entries['count']; |
1095 | - foreach($entries as $i => $entry) |
|
1093 | + foreach ($entries as $i => $entry) |
|
1096 | 1094 | { |
1097 | - if (!is_int($i)) continue; // eg. count |
|
1095 | + if (!is_int($i)) continue; // eg. count |
|
1098 | 1096 | |
1099 | 1097 | $contact = array( |
1100 | 1098 | 'id' => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0], |
1101 | - 'tid' => 'n', // the type id for the addressbook |
|
1099 | + 'tid' => 'n', // the type id for the addressbook |
|
1102 | 1100 | ); |
1103 | - foreach($entry['objectclass'] as $ii => $objectclass) |
|
1101 | + foreach ($entry['objectclass'] as $ii => $objectclass) |
|
1104 | 1102 | { |
1105 | 1103 | $objectclass = strtolower($objectclass); |
1106 | 1104 | if (!is_int($ii) || !isset($this->schema2egw[$objectclass])) |
1107 | 1105 | { |
1108 | - continue; // eg. count or unsupported objectclass |
|
1106 | + continue; // eg. count or unsupported objectclass |
|
1109 | 1107 | } |
1110 | - foreach($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName) |
|
1108 | + foreach ($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName) |
|
1111 | 1109 | { |
1112 | - if(!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName])) |
|
1110 | + if (!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName])) |
|
1113 | 1111 | { |
1114 | - $contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0],'utf-8'); |
|
1112 | + $contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0], 'utf-8'); |
|
1115 | 1113 | } |
1116 | 1114 | } |
1117 | 1115 | $objectclass2egw = '_'.$objectclass.'2egw'; |
1118 | - if (!in_array($objectclass2egw, (array)$_skipPlugins) &&method_exists($this,$objectclass2egw)) |
|
1116 | + if (!in_array($objectclass2egw, (array)$_skipPlugins) && method_exists($this, $objectclass2egw)) |
|
1119 | 1117 | { |
1120 | - if (($ret=$this->$objectclass2egw($contact,$entry)) === false) |
|
1118 | + if (($ret = $this->$objectclass2egw($contact, $entry)) === false) |
|
1121 | 1119 | { |
1122 | 1120 | --$this->total; |
1123 | 1121 | continue 2; |
@@ -1127,20 +1125,20 @@ discard block |
||
1127 | 1125 | // read binary jpegphoto only for one result == call by read |
1128 | 1126 | if ($this->total == 1 && isset($entry['jpegphoto'][0])) |
1129 | 1127 | { |
1130 | - $bin = ldap_get_values_len($this->ds,ldap_first_entry($this->ds,$result),'jpegphoto'); |
|
1128 | + $bin = ldap_get_values_len($this->ds, ldap_first_entry($this->ds, $result), 'jpegphoto'); |
|
1131 | 1129 | $contact['jpegphoto'] = $bin[0]; |
1132 | 1130 | } |
1133 | 1131 | $matches = null; |
1134 | - if(preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN,'/').'$/i',$entry['dn'],$matches)) |
|
1132 | + if (preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN, '/').'$/i', $entry['dn'], $matches)) |
|
1135 | 1133 | { |
1136 | 1134 | // personal addressbook |
1137 | - $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','u'); |
|
1135 | + $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'u'); |
|
1138 | 1136 | $contact['private'] = 0; |
1139 | 1137 | } |
1140 | - elseif(preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN,'/').'$/i',$entry['dn'],$matches)) |
|
1138 | + elseif (preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN, '/').'$/i', $entry['dn'], $matches)) |
|
1141 | 1139 | { |
1142 | 1140 | // group addressbook |
1143 | - $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','g'); |
|
1141 | + $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'g'); |
|
1144 | 1142 | $contact['private'] = 0; |
1145 | 1143 | } |
1146 | 1144 | else |
@@ -1149,12 +1147,12 @@ discard block |
||
1149 | 1147 | $contact['owner'] = 0; |
1150 | 1148 | $contact['private'] = 0; |
1151 | 1149 | } |
1152 | - foreach(array( |
|
1150 | + foreach (array( |
|
1153 | 1151 | 'createtimestamp' => 'created', |
1154 | 1152 | 'modifytimestamp' => 'modified', |
1155 | 1153 | ) as $ldapFieldName => $egwFieldName) |
1156 | 1154 | { |
1157 | - if(!empty($entry[$ldapFieldName][0])) |
|
1155 | + if (!empty($entry[$ldapFieldName][0])) |
|
1158 | 1156 | { |
1159 | 1157 | $contact[$egwFieldName] = $this->_ldap2ts($entry[$ldapFieldName][0]); |
1160 | 1158 | } |
@@ -1173,8 +1171,8 @@ discard block |
||
1173 | 1171 | */ |
1174 | 1172 | static function _ldap2ts($date) |
1175 | 1173 | { |
1176 | - return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2), |
|
1177 | - substr($date,4,2),substr($date,6,2),substr($date,0,4)); |
|
1174 | + return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2), |
|
1175 | + substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4)); |
|
1178 | 1176 | } |
1179 | 1177 | |
1180 | 1178 | /** |
@@ -1197,20 +1195,20 @@ discard block |
||
1197 | 1195 | function _check_create_dn($baseDN) |
1198 | 1196 | { |
1199 | 1197 | // check if $baseDN exists. If not create new one |
1200 | - if(@ldap_read($this->ds, $baseDN, 'objectclass=*')) |
|
1198 | + if (@ldap_read($this->ds, $baseDN, 'objectclass=*')) |
|
1201 | 1199 | { |
1202 | 1200 | return false; |
1203 | 1201 | } |
1204 | 1202 | //error_log(__METHOD__."('$baseDN') !ldap_read({$this->ds}, '$baseDN', 'objectclass=*') ldap_errno()=".ldap_errno($this->ds).', ldap_error()='.ldap_error($this->ds).get_class($this)); |
1205 | - if(ldap_errno($this->ds) != 32 || substr($baseDN,0,3) != 'cn=') |
|
1203 | + if (ldap_errno($this->ds) != 32 || substr($baseDN, 0, 3) != 'cn=') |
|
1206 | 1204 | { |
1207 | 1205 | error_log(__METHOD__."('$baseDN') baseDN does NOT exist and we cant/wont create it! ldap_errno()=".ldap_errno($this->ds).', ldap_error()='.ldap_error($this->ds)); |
1208 | - return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it |
|
1206 | + return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it |
|
1209 | 1207 | } |
1210 | 1208 | |
1211 | - list(,$ou) = explode(',',$baseDN); |
|
1209 | + list(,$ou) = explode(',', $baseDN); |
|
1212 | 1210 | $adminDS = null; |
1213 | - foreach(array( |
|
1211 | + foreach (array( |
|
1214 | 1212 | 'ou=contacts,'.$this->allContactsDN, |
1215 | 1213 | $ou.',ou=contacts,'.$this->allContactsDN, |
1216 | 1214 | $baseDN, |
@@ -1219,18 +1217,18 @@ discard block |
||
1219 | 1217 | if (!@ldap_read($this->ds, $dn, 'objectclass=*') && ldap_errno($this->ds) == 32) |
1220 | 1218 | { |
1221 | 1219 | // entry does not exist, lets try to create it |
1222 | - list($top) = explode(',',$dn); |
|
1223 | - list($var,$val) = explode('=',$top); |
|
1220 | + list($top) = explode(',', $dn); |
|
1221 | + list($var, $val) = explode('=', $top); |
|
1224 | 1222 | $data = array( |
1225 | 1223 | 'objectClass' => $var == 'cn' ? 'organizationalRole' : 'organizationalUnit', |
1226 | 1224 | $var => $val, |
1227 | 1225 | ); |
1228 | 1226 | // create a admin connection to add the needed DN |
1229 | 1227 | if (!isset($adminDS)) $adminDS = Api\Ldap::factory(); |
1230 | - if(!@ldap_add($adminDS, $dn, $data)) |
|
1228 | + if (!@ldap_add($adminDS, $dn, $data)) |
|
1231 | 1229 | { |
1232 | 1230 | //echo "<p>ldap_add($adminDS,'$dn',".print_r($data,true).")</p>\n"; |
1233 | - $err = lang("Can't create dn %1",$dn).': '.$this->_error(__LINE__,$adminDS); |
|
1231 | + $err = lang("Can't create dn %1", $dn).': '.$this->_error(__LINE__, $adminDS); |
|
1234 | 1232 | return $err; |
1235 | 1233 | } |
1236 | 1234 | } |
@@ -1245,7 +1243,7 @@ discard block |
||
1245 | 1243 | * @param int $line |
1246 | 1244 | * @return string |
1247 | 1245 | */ |
1248 | - function _error($line,$ds=null) |
|
1246 | + function _error($line, $ds = null) |
|
1249 | 1247 | { |
1250 | 1248 | return ldap_error($ds ? $ds : $this->ds).': '.__CLASS__.': '.$line; |
1251 | 1249 | } |
@@ -1260,27 +1258,27 @@ discard block |
||
1260 | 1258 | * @param array $data eGW contact data |
1261 | 1259 | * @param boolean $isUpdate |
1262 | 1260 | */ |
1263 | - function _egw2evolutionperson(&$ldapContact,$data,$isUpdate) |
|
1261 | + function _egw2evolutionperson(&$ldapContact, $data, $isUpdate) |
|
1264 | 1262 | { |
1265 | - if(!empty($data['cat_id'])) |
|
1263 | + if (!empty($data['cat_id'])) |
|
1266 | 1264 | { |
1267 | 1265 | $ldapContact['category'] = array(); |
1268 | - foreach(is_array($data['cat_id']) ? $data['cat_id'] : explode(',',$data['cat_id']) as $cat) |
|
1266 | + foreach (is_array($data['cat_id']) ? $data['cat_id'] : explode(',', $data['cat_id']) as $cat) |
|
1269 | 1267 | { |
1270 | 1268 | $ldapContact['category'][] = Api\Translation::convert( |
1271 | - Api\Categories::id2name($cat),$this->charset,'utf-8'); |
|
1269 | + Api\Categories::id2name($cat), $this->charset, 'utf-8'); |
|
1272 | 1270 | } |
1273 | 1271 | } |
1274 | - foreach(array( |
|
1275 | - 'postaladdress' => $data['adr_one_street'] .'$'. $data['adr_one_locality'] .', '. $data['adr_one_region'] .'$'. $data['adr_one_postalcode'] .'$$'. $data['adr_one_countryname'], |
|
1276 | - 'homepostaladdress' => $data['adr_two_street'] .'$'. $data['adr_two_locality'] .', '. $data['adr_two_region'] .'$'. $data['adr_two_postalcode'] .'$$'. $data['adr_two_countryname'], |
|
1272 | + foreach (array( |
|
1273 | + 'postaladdress' => $data['adr_one_street'].'$'.$data['adr_one_locality'].', '.$data['adr_one_region'].'$'.$data['adr_one_postalcode'].'$$'.$data['adr_one_countryname'], |
|
1274 | + 'homepostaladdress' => $data['adr_two_street'].'$'.$data['adr_two_locality'].', '.$data['adr_two_region'].'$'.$data['adr_two_postalcode'].'$$'.$data['adr_two_countryname'], |
|
1277 | 1275 | ) as $attr => $value) |
1278 | 1276 | { |
1279 | - if($value != '$, $$$') |
|
1277 | + if ($value != '$, $$$') |
|
1280 | 1278 | { |
1281 | - $ldapContact[$attr] = Api\Translation::convert($value,$this->charset,'utf-8'); |
|
1279 | + $ldapContact[$attr] = Api\Translation::convert($value, $this->charset, 'utf-8'); |
|
1282 | 1280 | } |
1283 | - elseif($isUpdate) |
|
1281 | + elseif ($isUpdate) |
|
1284 | 1282 | { |
1285 | 1283 | $ldapContact[$attr] = array(); |
1286 | 1284 | } |
@@ -1290,7 +1288,7 @@ discard block |
||
1290 | 1288 | { |
1291 | 1289 | $ldapContact['primaryphone'] = $data[$data['tel_prefer']]; |
1292 | 1290 | } |
1293 | - elseif($isUpdate) |
|
1291 | + elseif ($isUpdate) |
|
1294 | 1292 | { |
1295 | 1293 | $ldapContact['primaryphone'] = array(); |
1296 | 1294 | } |
@@ -1305,23 +1303,23 @@ discard block |
||
1305 | 1303 | * @param array &$contact already copied fields according to the mapping |
1306 | 1304 | * @param array $data eGW contact data |
1307 | 1305 | */ |
1308 | - function _evolutionperson2egw(&$contact,$data) |
|
1306 | + function _evolutionperson2egw(&$contact, $data) |
|
1309 | 1307 | { |
1310 | 1308 | if ($data['category'] && is_array($data['category'])) |
1311 | 1309 | { |
1312 | 1310 | $contact['cat_id'] = array(); |
1313 | - foreach($data['category'] as $iii => $cat) |
|
1311 | + foreach ($data['category'] as $iii => $cat) |
|
1314 | 1312 | { |
1315 | 1313 | if (!is_int($iii)) continue; |
1316 | 1314 | |
1317 | 1315 | $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat); |
1318 | 1316 | } |
1319 | - if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1317 | + if ($contact['cat_id']) $contact['cat_id'] = implode(',', $contact['cat_id']); |
|
1320 | 1318 | } |
1321 | 1319 | if ($data['primaryphone']) |
1322 | 1320 | { |
1323 | - unset($contact['tel_prefer']); // to not find itself |
|
1324 | - $contact['tel_prefer'] = array_search($data['primaryphone'][0],$contact); |
|
1321 | + unset($contact['tel_prefer']); // to not find itself |
|
1322 | + $contact['tel_prefer'] = array_search($data['primaryphone'][0], $contact); |
|
1325 | 1323 | } |
1326 | 1324 | } |
1327 | 1325 | |
@@ -1334,10 +1332,10 @@ discard block |
||
1334 | 1332 | * @param array &$contact already copied fields according to the mapping |
1335 | 1333 | * @param array $data eGW contact data |
1336 | 1334 | */ |
1337 | - function _inetorgperson2egw(&$contact, $data, $cn='cn') |
|
1335 | + function _inetorgperson2egw(&$contact, $data, $cn = 'cn') |
|
1338 | 1336 | { |
1339 | 1337 | $matches = null; |
1340 | - if(empty($data['givenname'][0])) |
|
1338 | + if (empty($data['givenname'][0])) |
|
1341 | 1339 | { |
1342 | 1340 | $parts = explode($data['sn'][0], $data[$cn][0]); |
1343 | 1341 | $contact['n_prefix'] = trim($parts[0]); |
@@ -1345,8 +1343,8 @@ discard block |
||
1345 | 1343 | } |
1346 | 1344 | // iOS addressbook either use "givenname surname" or "surname givenname" depending on contact preference display-order |
1347 | 1345 | // in full name, so we need to check for both when trying to parse prefix, middle name and suffix form full name |
1348 | - elseif (preg_match($preg='/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) || |
|
1349 | - preg_match($preg='/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches)) |
|
1346 | + elseif (preg_match($preg = '/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) || |
|
1347 | + preg_match($preg = '/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches)) |
|
1350 | 1348 | { |
1351 | 1349 | list(,$contact['n_prefix'], $contact['n_middle'], $contact['n_suffix']) = $matches; |
1352 | 1350 | //error_log(__METHOD__."() preg_match('$preg', '{$data[$cn][0]}') = ".array2string($matches)); |
@@ -1367,11 +1365,11 @@ discard block |
||
1367 | 1365 | * @param array &$contact already copied fields according to the mapping |
1368 | 1366 | * @param array $data eGW contact data |
1369 | 1367 | */ |
1370 | - function _posixaccount2egw(&$contact,$data) |
|
1368 | + function _posixaccount2egw(&$contact, $data) |
|
1371 | 1369 | { |
1372 | - unset($contact); // not used, but required by function signature |
|
1373 | - static $shadowExpireNow=null; |
|
1374 | - if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1370 | + unset($contact); // not used, but required by function signature |
|
1371 | + static $shadowExpireNow = null; |
|
1372 | + if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time() - date('Z')) / 86400); |
|
1375 | 1373 | |
1376 | 1374 | // exclude expired or deactivated accounts |
1377 | 1375 | if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow) |
@@ -1389,7 +1387,7 @@ discard block |
||
1389 | 1387 | * @param array &$contact already copied fields according to the mapping |
1390 | 1388 | * @param array $data eGW contact data |
1391 | 1389 | */ |
1392 | - function _mozillaabpersonalpha2egw(&$contact,$data) |
|
1390 | + function _mozillaabpersonalpha2egw(&$contact, $data) |
|
1393 | 1391 | { |
1394 | 1392 | if ($data['c']) |
1395 | 1393 | { |
@@ -1407,7 +1405,7 @@ discard block |
||
1407 | 1405 | * @param array $data eGW contact data |
1408 | 1406 | * @param boolean $isUpdate |
1409 | 1407 | */ |
1410 | - function _egw2mozillaabpersonalpha(&$ldapContact,$data,$isUpdate) |
|
1408 | + function _egw2mozillaabpersonalpha(&$ldapContact, $data, $isUpdate) |
|
1411 | 1409 | { |
1412 | 1410 | if ($data['adr_one_countrycode']) |
1413 | 1411 | { |
@@ -1436,9 +1434,9 @@ discard block |
||
1436 | 1434 | * @param array &$contact already copied fields according to the mapping |
1437 | 1435 | * @param array $data eGW contact data |
1438 | 1436 | */ |
1439 | - function _mozillaorgperson2egw(&$contact,$data) |
|
1437 | + function _mozillaorgperson2egw(&$contact, $data) |
|
1440 | 1438 | { |
1441 | - unset($contact, $data); // not used, but required by function signature |
|
1439 | + unset($contact, $data); // not used, but required by function signature |
|
1442 | 1440 | // no special handling necessary, as it supports two distinct attributes: c, cn |
1443 | 1441 | } |
1444 | 1442 | |
@@ -1452,7 +1450,7 @@ discard block |
||
1452 | 1450 | * @param array $data eGW contact data |
1453 | 1451 | * @param boolean $isUpdate |
1454 | 1452 | */ |
1455 | - function _egw2mozillaorgperson(&$ldapContact,$data,$isUpdate) |
|
1453 | + function _egw2mozillaorgperson(&$ldapContact, $data, $isUpdate) |
|
1456 | 1454 | { |
1457 | 1455 | if ($data['adr_one_countrycode']) |
1458 | 1456 | { |
@@ -1480,7 +1478,7 @@ discard block |
||
1480 | 1478 | * @param int $account_id account-id of the old owner |
1481 | 1479 | * @param int $new_owner account-id of the new owner |
1482 | 1480 | */ |
1483 | - function change_owner($account_id,$new_owner) |
|
1481 | + function change_owner($account_id, $new_owner) |
|
1484 | 1482 | { |
1485 | 1483 | error_log(__METHOD__."($account_id,$new_owner) not yet implemented"); |
1486 | 1484 | } |
@@ -858,9 +858,9 @@ |
||
858 | 858 | } |
859 | 859 | |
860 | 860 | /** |
861 | - * Deletes custom field data |
|
862 | - * Implemented to deal with LDAP backend, which saves CFs in SQL, but the account record is in LDAP |
|
863 | - */ |
|
861 | + * Deletes custom field data |
|
862 | + * Implemented to deal with LDAP backend, which saves CFs in SQL, but the account record is in LDAP |
|
863 | + */ |
|
864 | 864 | function delete_customfields($data) |
865 | 865 | { |
866 | 866 | $this->db->delete($this->extra_table,$data,__LINE__,__FILE__); |
@@ -336,18 +336,18 @@ discard block |
||
336 | 336 | $match_count = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] ? |
337 | 337 | $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] : 3; |
338 | 338 | |
339 | - $columns = Array(); |
|
340 | - $extra = Array(); |
|
339 | + $columns = array(); |
|
340 | + $extra = array(); |
|
341 | 341 | $order = in_array($param['order'], $group) ? $param['order'] : $group[0]; |
342 | 342 | $join .= $this->table_name .'.contact_id != a2.contact_id AND ('; |
343 | - $join_fields = Array(); |
|
343 | + $join_fields = array(); |
|
344 | 344 | foreach($group as $field) |
345 | 345 | { |
346 | 346 | $extra[] = "IF({$this->table_name}.$field = a2.$field, 1, 0)"; |
347 | 347 | $join_fields[] = $this->table_name . ".$field = a2.$field"; |
348 | 348 | $columns[] = "IF({$this->table_name}.$field = a2.$field, {$this->table_name}.$field, '') AS $field"; |
349 | 349 | } |
350 | - $extra = Array( |
|
350 | + $extra = array( |
|
351 | 351 | implode('+', $extra) . ' AS match_count' |
352 | 352 | ); |
353 | 353 | $join .= $this->db->column_data_implode(' OR ',$join_fields) . ')'; |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | } |
383 | 383 | |
384 | 384 | $rows = $this->db->query( |
385 | - "SELECT $mysql_calc_rows " . $columns. ', COUNT(contact_id) AS group_count' . |
|
385 | + "select $mysql_calc_rows " . $columns. ', COUNT(contact_id) AS group_count' . |
|
386 | 386 | ' FROM (' . $sub_query . ') AS matches GROUP BY ' . implode(',',$group) . |
387 | 387 | ' HAVING group_count > 1 ORDER BY ' . $order, |
388 | 388 | __LINE__, __FILE__, (int)$param['start'],$mysql_calc_rows ? (int)$param['num_rows'] : -1 |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr", |
721 | 721 | $this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))), |
722 | 722 | __LINE__,__FILE__,false,$member_attr=='contact_id' ? '' : |
723 | - '',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
723 | + '',false,0,"join $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
724 | 724 | { |
725 | 725 | $lists[$row['list_id']]['members'][] = $row[$member_attr]; |
726 | 726 | } |
@@ -112,11 +112,20 @@ discard block |
||
112 | 112 | $filter = is_array($param['col_filter']) ? $param['col_filter'] : array(); |
113 | 113 | $join = ''; |
114 | 114 | $op = 'OR'; |
115 | - if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
|
115 | + if (isset($param['op']) && !empty($param['op'])) |
|
116 | + { |
|
117 | + $op = $param['op']; |
|
118 | + } |
|
116 | 119 | $advanced_search = false; |
117 | - if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
|
120 | + if (isset($param['advanced_search']) && !empty($param['advanced_search'])) |
|
121 | + { |
|
122 | + $advanced_search = true; |
|
123 | + } |
|
118 | 124 | $wildcard ='%'; |
119 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
125 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) |
|
126 | + { |
|
127 | + $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
128 | + } |
|
120 | 129 | |
121 | 130 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
122 | 131 | if ($filter['cat_id']) |
@@ -134,7 +143,11 @@ discard block |
||
134 | 143 | // we have no private grants in addressbook at the moment, they have then to be added here too |
135 | 144 | if ($param['owner']) |
136 | 145 | { |
137 | - if (!$this->grants[(int) $filter['owner']]) return false; // we have no access to that addressbook |
|
146 | + if (!$this->grants[(int) $filter['owner']]) |
|
147 | + { |
|
148 | + return false; |
|
149 | + } |
|
150 | + // we have no access to that addressbook |
|
138 | 151 | |
139 | 152 | $filter['owner'] = $param['owner']; |
140 | 153 | $filter['private'] = 0; |
@@ -223,7 +236,10 @@ discard block |
||
223 | 236 | $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, |
224 | 237 | array($param['start'],$param['num_rows']),$filter,$join); |
225 | 238 | |
226 | - if (!$rows) return false; |
|
239 | + if (!$rows) |
|
240 | + { |
|
241 | + return false; |
|
242 | + } |
|
227 | 243 | |
228 | 244 | // query the values for *_count == 1, to display them instead |
229 | 245 | $filter['org_name'] = $orgs = array(); |
@@ -298,11 +314,20 @@ discard block |
||
298 | 314 | $join = 'JOIN ' . $this->table_name . ' AS a2 ON '; |
299 | 315 | $filter = $param['col_filter']; |
300 | 316 | $op = 'OR'; |
301 | - if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
|
317 | + if (isset($param['op']) && !empty($param['op'])) |
|
318 | + { |
|
319 | + $op = $param['op']; |
|
320 | + } |
|
302 | 321 | $advanced_search = false; |
303 | - if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
|
322 | + if (isset($param['advanced_search']) && !empty($param['advanced_search'])) |
|
323 | + { |
|
324 | + $advanced_search = true; |
|
325 | + } |
|
304 | 326 | $wildcard ='%'; |
305 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
327 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) |
|
328 | + { |
|
329 | + $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
330 | + } |
|
306 | 331 | |
307 | 332 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
308 | 333 | if ($param['cat_id']) |
@@ -333,7 +358,11 @@ discard block |
||
333 | 358 | // we have no private grants in addressbook at the moment, they have then to be added here too |
334 | 359 | if (array_key_exists('owner', $param)) |
335 | 360 | { |
336 | - if (!$this->grants[(int) $param['owner']]) return false; // we have no access to that addressbook |
|
361 | + if (!$this->grants[(int) $param['owner']]) |
|
362 | + { |
|
363 | + return false; |
|
364 | + } |
|
365 | + // we have no access to that addressbook |
|
337 | 366 | |
338 | 367 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
339 | 368 | $filter[$this->table_name.'.private'] = 0; |
@@ -473,7 +502,10 @@ discard block |
||
473 | 502 | */ |
474 | 503 | function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false, $ignore_acl=false) |
475 | 504 | { |
476 | - if ((int) $this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
505 | + if ((int) $this->debug >= 4) |
|
506 | + { |
|
507 | + echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
508 | + } |
|
477 | 509 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
478 | 510 | |
479 | 511 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -522,7 +554,10 @@ discard block |
||
522 | 554 | // no grants for selected owner/addressbook |
523 | 555 | if (!array_intersect((array)$filter['owner'],array_keys($this->grants))) |
524 | 556 | { |
525 | - if (!isset($groupmember_sql)) return false; |
|
557 | + if (!isset($groupmember_sql)) |
|
558 | + { |
|
559 | + return false; |
|
560 | + } |
|
526 | 561 | $filter[] = substr($groupmember_sql,4); |
527 | 562 | unset($filter['owner']); |
528 | 563 | } |
@@ -574,13 +609,16 @@ discard block |
||
574 | 609 | $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
575 | 610 | } |
576 | 611 | } |
577 | - if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
|
612 | + if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) |
|
613 | + { |
|
614 | + // search also adds a join for custom fields! |
|
578 | 615 | { |
579 | 616 | switch(gettype($only_keys)) |
580 | 617 | { |
581 | 618 | case 'boolean': |
582 | 619 | // Correctly handled by parent class |
583 | 620 | break; |
621 | + } |
|
584 | 622 | case 'string': |
585 | 623 | $only_keys = explode(',',$only_keys); |
586 | 624 | // fall through |
@@ -590,13 +628,23 @@ discard block |
||
590 | 628 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
591 | 629 | $order_by, $all_matches, PREG_SET_ORDER)) |
592 | 630 | { |
593 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
631 | + if (!is_array($extra_cols)) |
|
632 | + { |
|
633 | + $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
634 | + } |
|
594 | 635 | foreach($all_matches as $matches) |
595 | 636 | { |
596 | 637 | $table = ''; |
597 | 638 | $column = $matches[1]; |
598 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
599 | - if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
|
639 | + if ($column[0] == '#') |
|
640 | + { |
|
641 | + continue; |
|
642 | + } |
|
643 | + // order by custom field is handeled in so_sql_cf anyway |
|
644 | + if (($key = array_search($column, $this->db_cols)) !== false) |
|
645 | + { |
|
646 | + $column = $key; |
|
647 | + } |
|
600 | 648 | if (strpos($column,'.') === false) |
601 | 649 | { |
602 | 650 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
@@ -611,10 +659,13 @@ discard block |
||
611 | 659 | } |
612 | 660 | $extra_cols[] = $table.$column.' '.$matches[2]; |
613 | 661 | //_debug_array($matches); |
614 | - if (!empty($order_by) && $table) // postgres requires explizit order by |
|
662 | + if (!empty($order_by) && $table) |
|
663 | + { |
|
664 | + // postgres requires explizit order by |
|
615 | 665 | { |
616 | 666 | $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
617 | 667 | } |
668 | + } |
|
618 | 669 | } |
619 | 670 | //_debug_array($order_by); _debug_array($extra_cols); |
620 | 671 | } |
@@ -640,7 +691,11 @@ discard block |
||
640 | 691 | } |
641 | 692 | $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
642 | 693 | |
643 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
694 | + if ($start === false) |
|
695 | + { |
|
696 | + $this->total = is_array($rows) ? count($rows) : 0; |
|
697 | + } |
|
698 | + // so_sql sets total only for $start !== false! |
|
644 | 699 | |
645 | 700 | return $rows; |
646 | 701 | } |
@@ -682,7 +737,10 @@ discard block |
||
682 | 737 | $cat_filter = array(); |
683 | 738 | foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
684 | 739 | { |
685 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
740 | + if (is_numeric($cat)) |
|
741 | + { |
|
742 | + $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
743 | + } |
|
686 | 744 | } |
687 | 745 | return $cat_filter; |
688 | 746 | } |
@@ -695,10 +753,13 @@ discard block |
||
695 | 753 | */ |
696 | 754 | function change_owner($account_id,$new_owner) |
697 | 755 | { |
698 | - if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
|
756 | + if (!$new_owner) |
|
757 | + { |
|
758 | + // otherwise we would create an account (contact_owner==0) |
|
699 | 759 | { |
700 | 760 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
701 | 761 | } |
762 | + } |
|
702 | 763 | // contacts |
703 | 764 | $this->db->update($this->table_name,array( |
704 | 765 | 'contact_owner' => $new_owner, |
@@ -743,7 +804,10 @@ discard block |
||
743 | 804 | foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
744 | 805 | false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
745 | 806 | { |
746 | - if ($member_attr) $row['members'] = array(); |
|
807 | + if ($member_attr) |
|
808 | + { |
|
809 | + $row['members'] = array(); |
|
810 | + } |
|
747 | 811 | $lists[$row['list_id']] = $row; |
748 | 812 | } |
749 | 813 | if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
@@ -806,9 +870,15 @@ discard block |
||
806 | 870 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
807 | 871 | { |
808 | 872 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
809 | - if (!$keys && !$data || !(int)$owner) return false; |
|
873 | + if (!$keys && !$data || !(int)$owner) |
|
874 | + { |
|
875 | + return false; |
|
876 | + } |
|
810 | 877 | |
811 | - if ($keys && !is_array($keys)) $keys = array('list_name' => $keys); |
|
878 | + if ($keys && !is_array($keys)) |
|
879 | + { |
|
880 | + $keys = array('list_name' => $keys); |
|
881 | + } |
|
812 | 882 | if ($keys) |
813 | 883 | { |
814 | 884 | $keys['list_owner'] = $owner; |
@@ -828,9 +898,15 @@ discard block |
||
828 | 898 | } |
829 | 899 | $data['list_modified'] = time(); |
830 | 900 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
831 | - if (!$data['list_id']) unset($data['list_id']); |
|
901 | + if (!$data['list_id']) |
|
902 | + { |
|
903 | + unset($data['list_id']); |
|
904 | + } |
|
832 | 905 | |
833 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
906 | + if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) |
|
907 | + { |
|
908 | + return false; |
|
909 | + } |
|
834 | 910 | |
835 | 911 | if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
836 | 912 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
@@ -848,7 +924,10 @@ discard block |
||
848 | 924 | |
849 | 925 | $this->add2list($list_id,$contacts,array()); |
850 | 926 | } |
851 | - if ($keys) $data += $keys; |
|
927 | + if ($keys) |
|
928 | + { |
|
929 | + $data += $keys; |
|
930 | + } |
|
852 | 931 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
853 | 932 | return $list_id; |
854 | 933 | } |
@@ -863,7 +942,10 @@ discard block |
||
863 | 942 | */ |
864 | 943 | function add2list($contact,$list,array $existing=null) |
865 | 944 | { |
866 | - if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
|
945 | + if (!(int)$list || !is_array($contact) && !(int)$contact) |
|
946 | + { |
|
947 | + return false; |
|
948 | + } |
|
867 | 949 | |
868 | 950 | if (!is_array($existing)) |
869 | 951 | { |
@@ -905,7 +987,10 @@ discard block |
||
905 | 987 | */ |
906 | 988 | function remove_from_list($contact,$list=null) |
907 | 989 | { |
908 | - if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
|
990 | + if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) |
|
991 | + { |
|
992 | + return false; |
|
993 | + } |
|
909 | 994 | |
910 | 995 | $where = array( |
911 | 996 | 'contact_id' => $contact, |
@@ -947,7 +1032,10 @@ discard block |
||
947 | 1032 | */ |
948 | 1033 | function delete_list($list) |
949 | 1034 | { |
950 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
1035 | + if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) |
|
1036 | + { |
|
1037 | + return false; |
|
1038 | + } |
|
951 | 1039 | |
952 | 1040 | $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
953 | 1041 | |
@@ -962,7 +1050,10 @@ discard block |
||
962 | 1050 | */ |
963 | 1051 | function lists_ctag($owner=null) |
964 | 1052 | { |
965 | - if (is_null($owner)) $owner = array_keys($this->grants); |
|
1053 | + if (is_null($owner)) |
|
1054 | + { |
|
1055 | + $owner = array_keys($this->grants); |
|
1056 | + } |
|
966 | 1057 | |
967 | 1058 | if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
968 | 1059 | __LINE__,__FILE__)->fetchColumn())) |
@@ -982,9 +1073,12 @@ discard block |
||
982 | 1073 | */ |
983 | 1074 | function read($keys,$extra_cols='',$join='') |
984 | 1075 | { |
985 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
1076 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
1077 | + { |
|
986 | 1078 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
987 | - } else { |
|
1079 | + } |
|
1080 | + else |
|
1081 | + { |
|
988 | 1082 | $minimum_uid_length = 8; |
989 | 1083 | } |
990 | 1084 | |
@@ -1004,7 +1098,8 @@ discard block |
||
1004 | 1098 | |
1005 | 1099 | // enforce a minium uid strength |
1006 | 1100 | if (is_array($contact) && (!isset($contact['uid']) |
1007 | - || strlen($contact['uid']) < $minimum_uid_length)) { |
|
1101 | + || strlen($contact['uid']) < $minimum_uid_length)) |
|
1102 | + { |
|
1008 | 1103 | parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
1009 | 1104 | } |
1010 | 1105 | return $contact; |
@@ -1021,19 +1116,28 @@ discard block |
||
1021 | 1116 | { |
1022 | 1117 | unset($extra_where); // not used, but required by function signature |
1023 | 1118 | |
1024 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
1119 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
1120 | + { |
|
1025 | 1121 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
1026 | - } else { |
|
1122 | + } |
|
1123 | + else |
|
1124 | + { |
|
1027 | 1125 | $minimum_uid_length = 8; |
1028 | 1126 | } |
1029 | 1127 | |
1030 | - if (is_array($keys) && count($keys)) $this->data_merge($keys); |
|
1128 | + if (is_array($keys) && count($keys)) |
|
1129 | + { |
|
1130 | + $this->data_merge($keys); |
|
1131 | + } |
|
1031 | 1132 | |
1032 | 1133 | $new_entry = !$this->data['id']; |
1033 | 1134 | |
1034 | - if (isset($this->data['etag'])) // do we have an etag in the data to write |
|
1135 | + if (isset($this->data['etag'])) |
|
1136 | + { |
|
1137 | + // do we have an etag in the data to write |
|
1035 | 1138 | { |
1036 | 1139 | $etag = $this->data['etag']; |
1140 | + } |
|
1037 | 1141 | unset($this->data['etag']); |
1038 | 1142 | if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
1039 | 1143 | { |
@@ -1105,7 +1209,10 @@ discard block |
||
1105 | 1209 | */ |
1106 | 1210 | function read_list($list) |
1107 | 1211 | { |
1108 | - if (!$list) return false; |
|
1212 | + if (!$list) |
|
1213 | + { |
|
1214 | + return false; |
|
1215 | + } |
|
1109 | 1216 | |
1110 | 1217 | return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
1111 | 1218 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @var string |
46 | 46 | */ |
47 | - var $contacts_id='id'; |
|
47 | + var $contacts_id = 'id'; |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * Name of the table for distribution lists |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param Api\Db $db =null |
69 | 69 | */ |
70 | - function __construct(Api\Db $db=null) |
|
70 | + function __construct(Api\Db $db = null) |
|
71 | 71 | { |
72 | 72 | parent::__construct('api', 'egw_addressbook', self::EXTRA_TABLE, |
73 | 73 | 'contact_', '_name', '_value', '_id', $db); |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
116 | 116 | $advanced_search = false; |
117 | 117 | if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
118 | - $wildcard ='%'; |
|
119 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
118 | + $wildcard = '%'; |
|
119 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard'] ? $param['wildcard'] : ''); |
|
120 | 120 | |
121 | 121 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
122 | 122 | if ($filter['cat_id']) |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | // we have no private grants in addressbook at the moment, they have then to be added here too |
135 | 135 | if ($param['owner']) |
136 | 136 | { |
137 | - if (!$this->grants[(int) $filter['owner']]) return false; // we have no access to that addressbook |
|
137 | + if (!$this->grants[(int)$filter['owner']]) return false; // we have no access to that addressbook |
|
138 | 138 | |
139 | 139 | $filter['owner'] = $param['owner']; |
140 | 140 | $filter['private'] = 0; |
@@ -143,19 +143,18 @@ discard block |
||
143 | 143 | { |
144 | 144 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
145 | 145 | { |
146 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
146 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
147 | 147 | } |
148 | 148 | $filter[] = "(".$this->table_name.".contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
149 | - (!$this->grants ? ')' : |
|
150 | - " OR contact_private=0 AND ".$this->table_name.".contact_owner IN (". |
|
151 | - implode(',',array_keys($this->grants))."))"); |
|
149 | + (!$this->grants ? ')' : " OR contact_private=0 AND ".$this->table_name.".contact_owner IN (". |
|
150 | + implode(',', array_keys($this->grants))."))"); |
|
152 | 151 | } |
153 | 152 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== 'none') |
154 | 153 | { |
155 | 154 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
156 | 155 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
157 | 156 | { |
158 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
|
157 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER); |
|
159 | 158 | } |
160 | 159 | else |
161 | 160 | { |
@@ -169,7 +168,7 @@ discard block |
||
169 | 168 | } |
170 | 169 | else |
171 | 170 | { |
172 | - $filter[] = "org_name != ''";// AND org_name IS NOT NULL"; |
|
171 | + $filter[] = "org_name != ''"; // AND org_name IS NOT NULL"; |
|
173 | 172 | } |
174 | 173 | if (isset($filter['list'])) |
175 | 174 | { |
@@ -187,7 +186,7 @@ discard block |
||
187 | 186 | } |
188 | 187 | $sort = $param['sort'] == 'DESC' ? 'DESC' : 'ASC'; |
189 | 188 | |
190 | - list(,$by) = explode(',',$param['org_view']); |
|
189 | + list(,$by) = explode(',', $param['org_view']); |
|
191 | 190 | if (!$by) |
192 | 191 | { |
193 | 192 | $extra = array( |
@@ -200,41 +199,40 @@ discard block |
||
200 | 199 | else // by adr_one_location or org_unit |
201 | 200 | { |
202 | 201 | // org total for more then one $by |
203 | - $by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" : |
|
204 | - "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)"; |
|
205 | - parent::search($param['search'],array('org_name'), |
|
202 | + $by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" : "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)"; |
|
203 | + parent::search($param['search'], array('org_name'), |
|
206 | 204 | "GROUP BY org_name HAVING $by_expr > 1 ORDER BY org_name $sort", array( |
207 | 205 | "NULL AS $by", |
208 | 206 | '1 AS is_main', |
209 | 207 | 'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count', |
210 | 208 | "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count", |
211 | 209 | "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count", |
212 | - ),$wildcard,false,$op/*'OR'*/,'UNION',$filter,$join); |
|
210 | + ), $wildcard, false, $op/*'OR'*/, 'UNION', $filter, $join); |
|
213 | 211 | // org by location |
214 | - parent::search($param['search'],array('org_name'), |
|
212 | + parent::search($param['search'], array('org_name'), |
|
215 | 213 | "GROUP BY org_name,$by ORDER BY org_name $sort,$by $sort", array( |
216 | 214 | "CASE WHEN $by IS NULL THEN '' ELSE $by END AS $by", |
217 | 215 | '0 AS is_main', |
218 | 216 | 'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count', |
219 | 217 | "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count", |
220 | 218 | "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count", |
221 | - ),$wildcard,false,$op/*'OR'*/,'UNION',$filter,$join); |
|
219 | + ), $wildcard, false, $op/*'OR'*/, 'UNION', $filter, $join); |
|
222 | 220 | $append = "ORDER BY org_name $sort,is_main DESC,$by $sort"; |
223 | 221 | } |
224 | - $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, |
|
225 | - array($param['start'],$param['num_rows']),$filter,$join); |
|
222 | + $rows = parent::search($param['search'], array('org_name'), $append, $extra, $wildcard, false, $op/*'OR'*/, |
|
223 | + array($param['start'], $param['num_rows']), $filter, $join); |
|
226 | 224 | |
227 | 225 | if (!$rows) return false; |
228 | 226 | |
229 | 227 | // query the values for *_count == 1, to display them instead |
230 | 228 | $filter['org_name'] = $orgs = array(); |
231 | - foreach($rows as $row) |
|
229 | + foreach ($rows as $row) |
|
232 | 230 | { |
233 | 231 | if ($row['org_unit_count'] == 1 || $row['adr_one_locality_count'] == 1) |
234 | 232 | { |
235 | - $filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once |
|
233 | + $filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once |
|
236 | 234 | } |
237 | - $org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count']==1 ? $row[$by] : '|||') : ''); |
|
235 | + $org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count'] == 1 ? $row[$by] : '|||') : ''); |
|
238 | 236 | $row['group_count'] = $row['org_count']; |
239 | 237 | $orgs[$org_key] = $row; |
240 | 238 | } |
@@ -242,9 +240,9 @@ discard block |
||
242 | 240 | |
243 | 241 | if (count($filter['org_name'])) |
244 | 242 | { |
245 | - foreach((array) parent::search(null, array('org_name','org_unit','adr_one_locality'), |
|
243 | + foreach ((array)parent::search(null, array('org_name', 'org_unit', 'adr_one_locality'), |
|
246 | 244 | 'GROUP BY org_name,org_unit,adr_one_locality', |
247 | - '',$wildcard,false,$op/*'AND'*/,false,$filter,$join) as $row) |
|
245 | + '', $wildcard, false, $op/*'AND'*/, false, $filter, $join) as $row) |
|
248 | 246 | { |
249 | 247 | $org_key = $row['org_name'].($by ? '|||'.$row[$by] : ''); |
250 | 248 | if ($orgs[$org_key]['org_unit_count'] == 1) |
@@ -296,27 +294,27 @@ discard block |
||
296 | 294 | */ |
297 | 295 | function duplicates($param) |
298 | 296 | { |
299 | - $join = 'JOIN ' . $this->table_name . ' AS a2 ON '; |
|
297 | + $join = 'JOIN '.$this->table_name.' AS a2 ON '; |
|
300 | 298 | $filter = $param['col_filter']; |
301 | 299 | $op = 'OR'; |
302 | 300 | if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
303 | 301 | $advanced_search = false; |
304 | 302 | if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
305 | - $wildcard ='%'; |
|
306 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
303 | + $wildcard = '%'; |
|
304 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard'] ? $param['wildcard'] : ''); |
|
307 | 305 | |
308 | 306 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
309 | 307 | if ($param['cat_id']) |
310 | 308 | { |
311 | 309 | $cat_filter = $this->_cat_filter($filter['cat_id']); |
312 | - $filter[] = str_replace('cat_id', $this->table_name . '.cat_id', $cat_filter); |
|
313 | - $join .= str_replace('cat_id', 'a2.cat_id', $cat_filter) . ' AND '; |
|
310 | + $filter[] = str_replace('cat_id', $this->table_name.'.cat_id', $cat_filter); |
|
311 | + $join .= str_replace('cat_id', 'a2.cat_id', $cat_filter).' AND '; |
|
314 | 312 | unset($filter['cat_id']); |
315 | 313 | } |
316 | 314 | if ($filter['tid']) |
317 | 315 | { |
318 | - $filter[$this->table_name . '.contact_tid'] = $param['col_filter']['tid']; |
|
319 | - $join .= 'a2.contact_tid = ' . $this->db->quote($filter['tid']) . ' AND '; |
|
316 | + $filter[$this->table_name.'.contact_tid'] = $param['col_filter']['tid']; |
|
317 | + $join .= 'a2.contact_tid = '.$this->db->quote($filter['tid']).' AND '; |
|
320 | 318 | unset($filter['tid']); |
321 | 319 | } |
322 | 320 | else |
@@ -324,33 +322,33 @@ discard block |
||
324 | 322 | $join .= 'a2.contact_tid != \'D\' AND '; |
325 | 323 | } |
326 | 324 | // add filter for read ACL in sql, if user is NOT the owner of the addressbook |
327 | - if (array_key_exists('owner',$param) && $param['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
|
325 | + if (array_key_exists('owner', $param) && $param['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
|
328 | 326 | { |
329 | 327 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
330 | - $join .= 'a2.contact_owner = ' . $this->db->quote($param['owner']) . ' AND '; |
|
328 | + $join .= 'a2.contact_owner = '.$this->db->quote($param['owner']).' AND '; |
|
331 | 329 | } |
332 | 330 | else |
333 | 331 | { |
334 | 332 | // we have no private grants in addressbook at the moment, they have then to be added here too |
335 | 333 | if (array_key_exists('owner', $param)) |
336 | 334 | { |
337 | - if (!$this->grants[(int) $param['owner']]) return false; // we have no access to that addressbook |
|
335 | + if (!$this->grants[(int)$param['owner']]) return false; // we have no access to that addressbook |
|
338 | 336 | |
339 | 337 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
340 | 338 | $filter[$this->table_name.'.private'] = 0; |
341 | - $join .= 'a2.contact_owner = ' . $this->db->quote($param['owner']) . ' AND '; |
|
342 | - $join .= 'a2.contact_private = ' . $this->db->quote($filter['private']) . ' AND '; |
|
339 | + $join .= 'a2.contact_owner = '.$this->db->quote($param['owner']).' AND '; |
|
340 | + $join .= 'a2.contact_private = '.$this->db->quote($filter['private']).' AND '; |
|
343 | 341 | } |
344 | 342 | else // search all addressbooks, incl. accounts |
345 | 343 | { |
346 | 344 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
347 | 345 | { |
348 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
346 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
349 | 347 | } |
350 | 348 | $filter[] = $access = "(".$this->table_name.".contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
351 | 349 | " OR {$this->table_name}.contact_private=0 AND ".$this->table_name.".contact_owner IN (". |
352 | - implode(',',array_keys($this->grants))."))"; |
|
353 | - $join .= str_replace($this->table_name, 'a2', $access) . ' AND '; |
|
350 | + implode(',', array_keys($this->grants))."))"; |
|
351 | + $join .= str_replace($this->table_name, 'a2', $access).' AND '; |
|
354 | 352 | } |
355 | 353 | } |
356 | 354 | if ($param['searchletter']) |
@@ -359,34 +357,33 @@ discard block |
||
359 | 357 | } |
360 | 358 | $sort = $param['sort'] == 'DESC' ? 'DESC' : 'ASC'; |
361 | 359 | $group = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields'] ? |
362 | - explode(',',$GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields']): |
|
363 | - array('n_family', 'org_name', 'contact_email'); |
|
360 | + explode(',', $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields']) : array('n_family', 'org_name', 'contact_email'); |
|
364 | 361 | $match_count = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] ? |
365 | 362 | $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] : 3; |
366 | 363 | |
367 | 364 | $columns = Array(); |
368 | 365 | $extra = Array(); |
369 | 366 | $order = in_array($param['order'], $group) ? $param['order'] : $group[0]; |
370 | - $join .= $this->table_name .'.contact_id != a2.contact_id AND ('; |
|
367 | + $join .= $this->table_name.'.contact_id != a2.contact_id AND ('; |
|
371 | 368 | $join_fields = Array(); |
372 | - foreach($group as $field) |
|
369 | + foreach ($group as $field) |
|
373 | 370 | { |
374 | 371 | $extra[] = "IF({$this->table_name}.$field = a2.$field, 1, 0)"; |
375 | - $join_fields[] = $this->table_name . ".$field = a2.$field"; |
|
372 | + $join_fields[] = $this->table_name.".$field = a2.$field"; |
|
376 | 373 | $columns[] = "IF({$this->table_name}.$field = a2.$field, {$this->table_name}.$field, '') AS $field"; |
377 | 374 | } |
378 | 375 | $extra = Array( |
379 | - implode('+', $extra) . ' AS match_count' |
|
376 | + implode('+', $extra).' AS match_count' |
|
380 | 377 | ); |
381 | - $join .= $this->db->column_data_implode(' OR ',$join_fields) . ')'; |
|
378 | + $join .= $this->db->column_data_implode(' OR ', $join_fields).')'; |
|
382 | 379 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== 'none') |
383 | 380 | { |
384 | 381 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
385 | 382 | { |
386 | - $join .=' LEFT JOIN egw_accounts AS account_1 ON egw_addressbook.account_id=account_1.account_id '; |
|
387 | - $join .=' LEFT JOIN egw_accounts AS account_2 ON egw_addressbook.account_id=account_2.account_id '; |
|
388 | - $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'),array(time(),'account_1.account_'),self::ACOUNT_ACTIVE_FILTER); |
|
389 | - $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'),array(time(),'account_2.account_'),self::ACOUNT_ACTIVE_FILTER); |
|
383 | + $join .= ' LEFT JOIN egw_accounts AS account_1 ON egw_addressbook.account_id=account_1.account_id '; |
|
384 | + $join .= ' LEFT JOIN egw_accounts AS account_2 ON egw_addressbook.account_id=account_2.account_id '; |
|
385 | + $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'), array(time(), 'account_1.account_'), self::ACOUNT_ACTIVE_FILTER); |
|
386 | + $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'), array(time(), 'account_2.account_'), self::ACOUNT_ACTIVE_FILTER); |
|
390 | 387 | } |
391 | 388 | else |
392 | 389 | { |
@@ -400,17 +397,17 @@ discard block |
||
400 | 397 | if ($param['search'] && !is_array($param['search'])) |
401 | 398 | { |
402 | 399 | $search_cols = array(); |
403 | - foreach($group as $col) |
|
400 | + foreach ($group as $col) |
|
404 | 401 | { |
405 | - $search_cols[] = $this->table_name . '.' . $col; |
|
402 | + $search_cols[] = $this->table_name.'.'.$col; |
|
406 | 403 | } |
407 | - $search = $this->search2criteria($param['search'],$wildcard,$op, null, $search_cols); |
|
404 | + $search = $this->search2criteria($param['search'], $wildcard, $op, null, $search_cols); |
|
408 | 405 | $criteria = array($search); |
409 | 406 | } |
410 | 407 | $query = $this->parse_search(array_merge($criteria, $filter), $wildcard, false, ' AND '); |
411 | 408 | |
412 | 409 | $sub_query = $this->db->select($this->table_name, |
413 | - 'DISTINCT ' . implode(', ',array_merge($columns, $extra)), |
|
410 | + 'DISTINCT '.implode(', ', array_merge($columns, $extra)), |
|
414 | 411 | $query, |
415 | 412 | False, False, 0, $append, False, -1, |
416 | 413 | $join |
@@ -423,15 +420,15 @@ discard block |
||
423 | 420 | } |
424 | 421 | |
425 | 422 | $rows = $this->db->query( |
426 | - "SELECT $mysql_calc_rows " . $columns. ', COUNT(contact_id) AS group_count' . |
|
427 | - ' FROM (' . $sub_query . ') AS matches GROUP BY ' . implode(',',$group) . |
|
428 | - ' HAVING group_count > 1 ORDER BY ' . $order, |
|
429 | - __LINE__, __FILE__, (int)$param['start'],$mysql_calc_rows ? (int)$param['num_rows'] : -1 |
|
423 | + "SELECT $mysql_calc_rows ".$columns.', COUNT(contact_id) AS group_count'. |
|
424 | + ' FROM ('.$sub_query.') AS matches GROUP BY '.implode(',', $group). |
|
425 | + ' HAVING group_count > 1 ORDER BY '.$order, |
|
426 | + __LINE__, __FILE__, (int)$param['start'], $mysql_calc_rows ? (int)$param['num_rows'] : -1 |
|
430 | 427 | ); |
431 | 428 | |
432 | 429 | // Go through rows and only return one for each pair/triplet/etc. of matches |
433 | 430 | $dupes = array(); |
434 | - foreach($rows as $key => $row) |
|
431 | + foreach ($rows as $key => $row) |
|
435 | 432 | { |
436 | 433 | $row['email'] = $row['contact_email']; |
437 | 434 | $row['email_home'] = $row['contact_email_home']; |
@@ -472,9 +469,9 @@ discard block |
||
472 | 469 | * @param boolean $ignore_acl =false true: no acl check |
473 | 470 | * @return boolean/array of matching rows (the row is an array of the cols) or False |
474 | 471 | */ |
475 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false, $ignore_acl=false) |
|
472 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false, $ignore_acl = false) |
|
476 | 473 | { |
477 | - if ((int) $this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
474 | + if ((int)$this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
478 | 475 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
479 | 476 | |
480 | 477 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -490,10 +487,10 @@ discard block |
||
490 | 487 | { |
491 | 488 | if ($filter['cat_id'][0] == '!') |
492 | 489 | { |
493 | - $filter['cat_id'] = substr($filter['cat_id'],1); |
|
490 | + $filter['cat_id'] = substr($filter['cat_id'], 1); |
|
494 | 491 | $not = 'NOT'; |
495 | 492 | } |
496 | - $filter[] = $this->_cat_filter($filter['cat_id'],$not); |
|
493 | + $filter[] = $this->_cat_filter($filter['cat_id'], $not); |
|
497 | 494 | unset($filter['cat_id']); |
498 | 495 | } |
499 | 496 | |
@@ -503,17 +500,17 @@ discard block |
||
503 | 500 | { |
504 | 501 | // add read ACL for groupmembers (they have no |
505 | 502 | if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' && |
506 | - (!isset($filter['owner']) || in_array('0',(array)$filter['owner']))) |
|
503 | + (!isset($filter['owner']) || in_array('0', (array)$filter['owner']))) |
|
507 | 504 | { |
508 | 505 | $groupmembers = array(); |
509 | - foreach($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $group_id) |
|
506 | + foreach ($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $group_id) |
|
510 | 507 | { |
511 | - if (($members = $GLOBALS['egw']->accounts->members($group_id,true))) |
|
508 | + if (($members = $GLOBALS['egw']->accounts->members($group_id, true))) |
|
512 | 509 | { |
513 | - $groupmembers = array_merge($groupmembers,$members); |
|
510 | + $groupmembers = array_merge($groupmembers, $members); |
|
514 | 511 | } |
515 | 512 | } |
516 | - $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.',array( |
|
513 | + $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.', array( |
|
517 | 514 | 'account_id' => array_unique($groupmembers), |
518 | 515 | )); |
519 | 516 | } |
@@ -521,10 +518,10 @@ discard block |
||
521 | 518 | if (isset($filter['owner'])) |
522 | 519 | { |
523 | 520 | // no grants for selected owner/addressbook |
524 | - if (!array_intersect((array)$filter['owner'],array_keys($this->grants))) |
|
521 | + if (!array_intersect((array)$filter['owner'], array_keys($this->grants))) |
|
525 | 522 | { |
526 | 523 | if (!isset($groupmember_sql)) return false; |
527 | - $filter[] = substr($groupmember_sql,4); |
|
524 | + $filter[] = substr($groupmember_sql, 4); |
|
528 | 525 | unset($filter['owner']); |
529 | 526 | } |
530 | 527 | // for an owner filter, which does NOT include current user, filter out private entries |
@@ -533,22 +530,22 @@ discard block |
||
533 | 530 | $filter['private'] = 0; |
534 | 531 | } |
535 | 532 | // if multiple addressbooks (incl. current owner) are searched, we need full acl filter |
536 | - elseif(is_array($filter['owner']) && count($filter['owner']) > 1) |
|
533 | + elseif (is_array($filter['owner']) && count($filter['owner']) > 1) |
|
537 | 534 | { |
538 | 535 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
539 | 536 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
540 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
537 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
541 | 538 | } |
542 | 539 | } |
543 | 540 | else // search all addressbooks, incl. accounts |
544 | 541 | { |
545 | 542 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
546 | 543 | { |
547 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
544 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
548 | 545 | } |
549 | 546 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
550 | 547 | ($this->grants ? " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
551 | - implode(',',array_keys($this->grants)).")" : ''). |
|
548 | + implode(',', array_keys($this->grants)).")" : ''). |
|
552 | 549 | $groupmember_sql." OR $this->table_name.contact_owner IS NULL)"; |
553 | 550 | } |
554 | 551 | } |
@@ -567,24 +564,24 @@ discard block |
||
567 | 564 | unset($filter['list']); |
568 | 565 | } |
569 | 566 | // add join to show only active accounts (only if accounts are shown and in sql and we not already join the accounts table, eg. used by admin) |
570 | - if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository,0,3) == 'sql' && |
|
571 | - strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter)) |
|
567 | + if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository, 0, 3) == 'sql' && |
|
568 | + strpos($join, $GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id', $filter)) |
|
572 | 569 | { |
573 | 570 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
574 | 571 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
575 | 572 | { |
576 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
|
573 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER); |
|
577 | 574 | } |
578 | 575 | } |
579 | 576 | if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
580 | 577 | { |
581 | - switch(gettype($only_keys)) |
|
578 | + switch (gettype($only_keys)) |
|
582 | 579 | { |
583 | 580 | case 'boolean': |
584 | 581 | // Correctly handled by parent class |
585 | 582 | break; |
586 | 583 | case 'string': |
587 | - $only_keys = explode(',',$only_keys); |
|
584 | + $only_keys = explode(',', $only_keys); |
|
588 | 585 | // fall through |
589 | 586 | } |
590 | 587 | // postgres requires that expressions in order by appear in the columns of a distinct select |
@@ -592,14 +589,14 @@ discard block |
||
592 | 589 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
593 | 590 | $order_by, $all_matches, PREG_SET_ORDER)) |
594 | 591 | { |
595 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
596 | - foreach($all_matches as $matches) |
|
592 | + if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',', $extra_cols) : array(); |
|
593 | + foreach ($all_matches as $matches) |
|
597 | 594 | { |
598 | 595 | $table = ''; |
599 | 596 | $column = $matches[1]; |
600 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
597 | + if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
601 | 598 | if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
602 | - if (strpos($column,'.') === false) |
|
599 | + if (strpos($column, '.') === false) |
|
603 | 600 | { |
604 | 601 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
605 | 602 | if (isset($this->db_cols[$column])) |
@@ -615,34 +612,34 @@ discard block |
||
615 | 612 | //_debug_array($matches); |
616 | 613 | if (!empty($order_by) && $table) // postgres requires explizit order by |
617 | 614 | { |
618 | - $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
|
615 | + $order_by = str_replace($matches[0], $table.$column.' '.$matches[2].' '.$matches[3].$matches[4], $order_by); |
|
619 | 616 | } |
620 | 617 | } |
621 | 618 | //_debug_array($order_by); _debug_array($extra_cols); |
622 | 619 | } |
623 | 620 | |
624 | 621 | // Understand search by date with wildcard (????.10.??) according to user date preference |
625 | - if(is_string($criteria) && strpos($criteria, '?') !== false) |
|
622 | + if (is_string($criteria) && strpos($criteria, '?') !== false) |
|
626 | 623 | { |
627 | 624 | // First, check for a 'date', with wildcards, in the user's format |
628 | - $date_regex = str_replace('Q','d', |
|
629 | - str_replace(array('Y','m','d','.','-'), |
|
630 | - array('(?P<Y>(?:\?|\Q){4})','(?P<m>(?:\?|\Q){2})','(?P<d>(?:\?|\Q){2})','\.','\-'), |
|
625 | + $date_regex = str_replace('Q', 'd', |
|
626 | + str_replace(array('Y', 'm', 'd', '.', '-'), |
|
627 | + array('(?P<Y>(?:\?|\Q){4})', '(?P<m>(?:\?|\Q){2})', '(?P<d>(?:\?|\Q){2})', '\.', '\-'), |
|
631 | 628 | $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])); |
632 | 629 | |
633 | - if(preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
630 | + if (preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
634 | 631 | { |
635 | - foreach($matches[0] as $m_id => $match) |
|
632 | + foreach ($matches[0] as $m_id => $match) |
|
636 | 633 | { |
637 | 634 | // Birthday is Y-m-d |
638 | - $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*",$criteria); |
|
635 | + $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*", $criteria); |
|
639 | 636 | } |
640 | 637 | } |
641 | 638 | } |
642 | 639 | } |
643 | - $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
640 | + $rows = & parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
644 | 641 | |
645 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
642 | + if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
646 | 643 | |
647 | 644 | return $rows; |
648 | 645 | } |
@@ -654,18 +651,18 @@ discard block |
||
654 | 651 | * @param int|array $cat_id |
655 | 652 | * @return string sql to filter by given cat |
656 | 653 | */ |
657 | - function _cat_filter($cat_id, $not='') |
|
654 | + function _cat_filter($cat_id, $not = '') |
|
658 | 655 | { |
659 | 656 | if (!is_object($GLOBALS['egw']->categories)) |
660 | 657 | { |
661 | 658 | $GLOBALS['egw']->categories = new Api\Categories; |
662 | 659 | } |
663 | - foreach($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
660 | + foreach ($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
664 | 661 | { |
665 | 662 | $cat_filter[] = $this->db->concat("','", 'cat_id', "','")." $not LIKE '%,$cat,%'"; |
666 | 663 | } |
667 | - $cfilter = '('.implode(' OR ',$cat_filter).')'; |
|
668 | - if(!empty($not)) |
|
664 | + $cfilter = '('.implode(' OR ', $cat_filter).')'; |
|
665 | + if (!empty($not)) |
|
669 | 666 | { |
670 | 667 | $cfilter = "( $cfilter OR cat_id IS NULL )"; |
671 | 668 | } |
@@ -682,9 +679,9 @@ discard block |
||
682 | 679 | function _cat_search($cats) |
683 | 680 | { |
684 | 681 | $cat_filter = array(); |
685 | - foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
|
682 | + foreach (is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',', $cats)) as $cat) |
|
686 | 683 | { |
687 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
684 | + if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','", cat_id, "','")." LIKE '%,$cat,%'"; |
|
688 | 685 | } |
689 | 686 | return $cat_filter; |
690 | 687 | } |
@@ -695,32 +692,32 @@ discard block |
||
695 | 692 | * @param int $account_id account-id of the old owner |
696 | 693 | * @param int $new_owner account-id of the new owner |
697 | 694 | */ |
698 | - function change_owner($account_id,$new_owner) |
|
695 | + function change_owner($account_id, $new_owner) |
|
699 | 696 | { |
700 | 697 | if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
701 | 698 | { |
702 | 699 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
703 | 700 | } |
704 | 701 | // contacts |
705 | - $this->db->update($this->table_name,array( |
|
702 | + $this->db->update($this->table_name, array( |
|
706 | 703 | 'contact_owner' => $new_owner, |
707 | - ),array( |
|
704 | + ), array( |
|
708 | 705 | 'contact_owner' => $account_id, |
709 | - ),__LINE__,__FILE__); |
|
706 | + ), __LINE__, __FILE__); |
|
710 | 707 | |
711 | 708 | // cfs |
712 | 709 | $this->db->update(self::EXTRA_TABLE, array( |
713 | 710 | 'contact_owner' => $new_owner |
714 | - ),array( |
|
711 | + ), array( |
|
715 | 712 | 'contact_owner' => $account_id |
716 | 713 | ), __LINE__, __FILE__); |
717 | 714 | |
718 | 715 | // lists |
719 | 716 | $this->db->update($this->lists_table, array( |
720 | 717 | 'list_owner' => $new_owner, |
721 | - ),array( |
|
718 | + ), array( |
|
722 | 719 | 'list_owner' => $account_id, |
723 | - ),__LINE__,__FILE__); |
|
720 | + ), __LINE__, __FILE__); |
|
724 | 721 | } |
725 | 722 | |
726 | 723 | /** |
@@ -734,21 +731,21 @@ discard block |
||
734 | 731 | * if int|array only return members from the given owners addressbook(s) |
735 | 732 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
736 | 733 | */ |
737 | - function get_lists($uids,$uid_column='list_owner',$member_attr=null,$limit_in_ab=false) |
|
734 | + function get_lists($uids, $uid_column = 'list_owner', $member_attr = null, $limit_in_ab = false) |
|
738 | 735 | { |
739 | 736 | if (is_array($uids) && array_key_exists('list_id', $uids)) |
740 | 737 | { |
741 | - $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.',array('list_id' => $uids['list_id'])); |
|
738 | + $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.', array('list_id' => $uids['list_id'])); |
|
742 | 739 | unset($uids['list_id']); |
743 | 740 | } |
744 | 741 | $lists = array(); |
745 | - foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
|
746 | - false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
742 | + foreach ($this->db->select($this->lists_table, '*', $uid_column ? array($uid_column=>$uids) : $uids, __LINE__, __FILE__, |
|
743 | + false, 'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
747 | 744 | { |
748 | 745 | if ($member_attr) $row['members'] = array(); |
749 | 746 | $lists[$row['list_id']] = $row; |
750 | 747 | } |
751 | - if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
|
748 | + if ($lists && $member_attr && in_array($member_attr, array('contact_id', 'contact_uid', 'caldav_name'))) |
|
752 | 749 | { |
753 | 750 | if ($limit_in_ab) |
754 | 751 | { |
@@ -762,10 +759,9 @@ discard block |
||
762 | 759 | $in_ab_join .= "list_owner=$this->table_name.contact_owner"; |
763 | 760 | } |
764 | 761 | } |
765 | - foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
762 | + foreach ($this->db->select($this->ab2list_table, "$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
766 | 763 | $this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))), |
767 | - __LINE__,__FILE__,false,$member_attr=='contact_id' ? '' : |
|
768 | - '',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
764 | + __LINE__, __FILE__, false, $member_attr == 'contact_id' ? '' : '', false, 0, "JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
769 | 765 | { |
770 | 766 | $lists[$row['list_id']]['members'][] = $row[$member_attr]; |
771 | 767 | } |
@@ -805,7 +801,7 @@ discard block |
||
805 | 801 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
806 | 802 | * @return int|boolean integer list_id or false on error |
807 | 803 | */ |
808 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
804 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
809 | 805 | { |
810 | 806 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
811 | 807 | if (!$keys && !$data || !(int)$owner) return false; |
@@ -819,7 +815,7 @@ discard block |
||
819 | 815 | { |
820 | 816 | $data['list_owner'] = $owner; |
821 | 817 | } |
822 | - if (!$keys || !($list_id = $this->db->select($this->lists_table,'list_id',$keys,__LINE__,__FILE__)->fetchColumn())) |
|
818 | + if (!$keys || !($list_id = $this->db->select($this->lists_table, 'list_id', $keys, __LINE__, __FILE__)->fetchColumn())) |
|
823 | 819 | { |
824 | 820 | $data['list_created'] = time(); |
825 | 821 | $data['list_creator'] = $GLOBALS['egw_info']['user']['account_id']; |
@@ -832,9 +828,9 @@ discard block |
||
832 | 828 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
833 | 829 | if (!$data['list_id']) unset($data['list_id']); |
834 | 830 | |
835 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
831 | + if (!$this->db->insert($this->lists_table, $data, $keys, __LINE__, __FILE__)) return false; |
|
836 | 832 | |
837 | - if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
|
833 | + if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table, 'list_id')) && |
|
838 | 834 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
839 | 835 | { |
840 | 836 | $update = array(); |
@@ -846,9 +842,9 @@ discard block |
||
846 | 842 | { |
847 | 843 | $update['list_carddav_name'] = $data['list_carddav_name'] = $data['list_uid'].'.vcf'; |
848 | 844 | } |
849 | - $this->db->update($this->lists_table,$update,array('list_id'=>$list_id),__LINE__,__FILE__); |
|
845 | + $this->db->update($this->lists_table, $update, array('list_id'=>$list_id), __LINE__, __FILE__); |
|
850 | 846 | |
851 | - $this->add2list($list_id,$contacts,array()); |
|
847 | + $this->add2list($list_id, $contacts, array()); |
|
852 | 848 | } |
853 | 849 | if ($keys) $data += $keys; |
854 | 850 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
@@ -863,39 +859,39 @@ discard block |
||
863 | 859 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
864 | 860 | * @return false on error |
865 | 861 | */ |
866 | - function add2list($contact,$list,array $existing=null) |
|
862 | + function add2list($contact, $list, array $existing = null) |
|
867 | 863 | { |
868 | 864 | if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
869 | 865 | |
870 | 866 | if (!is_array($existing)) |
871 | 867 | { |
872 | 868 | $existing = array(); |
873 | - foreach($this->db->select($this->ab2list_table,'contact_id',array('list_id'=>$list),__LINE__,__FILE__) as $row) |
|
869 | + foreach ($this->db->select($this->ab2list_table, 'contact_id', array('list_id'=>$list), __LINE__, __FILE__) as $row) |
|
874 | 870 | { |
875 | 871 | $existing[] = $row['contact_id']; |
876 | 872 | } |
877 | 873 | } |
878 | - if (!($to_add = array_diff((array)$contact,$existing))) |
|
874 | + if (!($to_add = array_diff((array)$contact, $existing))) |
|
879 | 875 | { |
880 | - return true; // no need to insert it, would give sql error |
|
876 | + return true; // no need to insert it, would give sql error |
|
881 | 877 | } |
882 | - foreach($to_add as $contact) |
|
878 | + foreach ($to_add as $contact) |
|
883 | 879 | { |
884 | - $this->db->insert($this->ab2list_table,array( |
|
880 | + $this->db->insert($this->ab2list_table, array( |
|
885 | 881 | 'contact_id' => $contact, |
886 | 882 | 'list_id' => $list, |
887 | 883 | 'list_added' => time(), |
888 | 884 | 'list_added_by' => $GLOBALS['egw_info']['user']['account_id'], |
889 | - ),array(),__LINE__,__FILE__); |
|
885 | + ), array(), __LINE__, __FILE__); |
|
890 | 886 | } |
891 | 887 | // update etag |
892 | - return $this->db->update($this->lists_table,array( |
|
888 | + return $this->db->update($this->lists_table, array( |
|
893 | 889 | 'list_etag=list_etag+1', |
894 | 890 | 'list_modified' => time(), |
895 | 891 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
896 | - ),array( |
|
892 | + ), array( |
|
897 | 893 | 'list_id' => $list, |
898 | - ),__LINE__,__FILE__); |
|
894 | + ), __LINE__, __FILE__); |
|
899 | 895 | } |
900 | 896 | |
901 | 897 | /** |
@@ -905,7 +901,7 @@ discard block |
||
905 | 901 | * @param int $list =null list-id or null to remove from all lists |
906 | 902 | * @return false on error |
907 | 903 | */ |
908 | - function remove_from_list($contact,$list=null) |
|
904 | + function remove_from_list($contact, $list = null) |
|
909 | 905 | { |
910 | 906 | if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
911 | 907 | |
@@ -919,24 +915,24 @@ discard block |
||
919 | 915 | else |
920 | 916 | { |
921 | 917 | $list = array(); |
922 | - foreach($this->db->select($this->ab2list_table,'list_id',$where,__LINE__,__FILE__) as $row) |
|
918 | + foreach ($this->db->select($this->ab2list_table, 'list_id', $where, __LINE__, __FILE__) as $row) |
|
923 | 919 | { |
924 | 920 | $list[] = $row['list_id']; |
925 | 921 | } |
926 | 922 | } |
927 | - if (!$this->db->delete($this->ab2list_table,$where,__LINE__,__FILE__)) |
|
923 | + if (!$this->db->delete($this->ab2list_table, $where, __LINE__, __FILE__)) |
|
928 | 924 | { |
929 | 925 | return false; |
930 | 926 | } |
931 | - foreach((array)$list as $list_id) |
|
927 | + foreach ((array)$list as $list_id) |
|
932 | 928 | { |
933 | - $this->db->update($this->lists_table,array( |
|
929 | + $this->db->update($this->lists_table, array( |
|
934 | 930 | 'list_etag=list_etag+1', |
935 | 931 | 'list_modified' => time(), |
936 | 932 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
937 | - ),array( |
|
933 | + ), array( |
|
938 | 934 | 'list_id' => $list_id, |
939 | - ),__LINE__,__FILE__); |
|
935 | + ), __LINE__, __FILE__); |
|
940 | 936 | } |
941 | 937 | return true; |
942 | 938 | } |
@@ -949,9 +945,9 @@ discard block |
||
949 | 945 | */ |
950 | 946 | function delete_list($list) |
951 | 947 | { |
952 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
948 | + if (!$this->db->delete($this->lists_table, array('list_id' => $list), __LINE__, __FILE__)) return false; |
|
953 | 949 | |
954 | - $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
|
950 | + $this->db->delete($this->ab2list_table, array('list_id' => $list), __LINE__, __FILE__); |
|
955 | 951 | |
956 | 952 | return $this->db->affected_rows(); |
957 | 953 | } |
@@ -962,12 +958,12 @@ discard block |
||
962 | 958 | * @param int|array $owner =null null for all lists user has access too |
963 | 959 | * @return int |
964 | 960 | */ |
965 | - function lists_ctag($owner=null) |
|
961 | + function lists_ctag($owner = null) |
|
966 | 962 | { |
967 | 963 | if (is_null($owner)) $owner = array_keys($this->grants); |
968 | 964 | |
969 | - if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
|
970 | - __LINE__,__FILE__)->fetchColumn())) |
|
965 | + if (!($modified = $this->db->select($this->lists_table, 'MAX(list_modified)', array('list_owner'=>$owner), |
|
966 | + __LINE__, __FILE__)->fetchColumn())) |
|
971 | 967 | { |
972 | 968 | return 0; |
973 | 969 | } |
@@ -982,7 +978,7 @@ discard block |
||
982 | 978 | * @param string $join |
983 | 979 | * @return array|boolean |
984 | 980 | */ |
985 | - function read($keys,$extra_cols='',$join='') |
|
981 | + function read($keys, $extra_cols = '', $join = '') |
|
986 | 982 | { |
987 | 983 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
988 | 984 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -995,11 +991,11 @@ discard block |
||
995 | 991 | $keys = array('uid' => $keys); |
996 | 992 | } |
997 | 993 | try { |
998 | - $contact = parent::read($keys,$extra_cols,$join); |
|
994 | + $contact = parent::read($keys, $extra_cols, $join); |
|
999 | 995 | } |
1000 | 996 | // catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267) |
1001 | 997 | // caused by non-ascii chars compared with ascii field uid |
1002 | - catch(Api\Db\Exception $e) { |
|
998 | + catch (Api\Db\Exception $e) { |
|
1003 | 999 | _egw_log_exception($e); |
1004 | 1000 | return false; |
1005 | 1001 | } |
@@ -1007,7 +1003,7 @@ discard block |
||
1007 | 1003 | // enforce a minium uid strength |
1008 | 1004 | if (is_array($contact) && (!isset($contact['uid']) |
1009 | 1005 | || strlen($contact['uid']) < $minimum_uid_length)) { |
1010 | - parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
|
1006 | + parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook', $contact['id']))); |
|
1011 | 1007 | } |
1012 | 1008 | return $contact; |
1013 | 1009 | } |
@@ -1021,7 +1017,7 @@ discard block |
||
1021 | 1017 | */ |
1022 | 1018 | function save($keys = NULL, $extra_where = NULL) |
1023 | 1019 | { |
1024 | - unset($extra_where); // not used, but required by function signature |
|
1020 | + unset($extra_where); // not used, but required by function signature |
|
1025 | 1021 | |
1026 | 1022 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
1027 | 1023 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -1037,9 +1033,9 @@ discard block |
||
1037 | 1033 | { |
1038 | 1034 | $etag = $this->data['etag']; |
1039 | 1035 | unset($this->data['etag']); |
1040 | - if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
|
1036 | + if (!($err = parent::save(array('contact_etag=contact_etag+1'), array('contact_etag' => $etag)))) |
|
1041 | 1037 | { |
1042 | - $this->data['etag'] = $etag+1; |
|
1038 | + $this->data['etag'] = $etag + 1; |
|
1043 | 1039 | } |
1044 | 1040 | else |
1045 | 1041 | { |
@@ -1059,7 +1055,7 @@ discard block |
||
1059 | 1055 | // enforce a minium uid strength |
1060 | 1056 | if (!isset($this->data['uid']) || strlen($this->data['uid']) < $minimum_uid_length) |
1061 | 1057 | { |
1062 | - $update['uid'] = Api\CalDAV::generate_uid('addressbook',$this->data['id']); |
|
1058 | + $update['uid'] = Api\CalDAV::generate_uid('addressbook', $this->data['id']); |
|
1063 | 1059 | //echo "<p>set uid={$this->data['uid']}, etag={$this->data['etag']}</p>"; |
1064 | 1060 | } |
1065 | 1061 | // set carddav_name, if not given by caller |
@@ -1077,17 +1073,17 @@ discard block |
||
1077 | 1073 | 'contact_id' => $this->data['id'], |
1078 | 1074 | ), __LINE__, __FILE__)->fetchColumn(); |
1079 | 1075 | } |
1080 | - $path = Api\Link::vfs_path('addressbook', $this->data['id'], Api\Contacts::FILES_PHOTO); |
|
1076 | + $path = Api\Link::vfs_path('addressbook', $this->data['id'], Api\Contacts::FILES_PHOTO); |
|
1081 | 1077 | $backup = Api\Vfs::$is_root; Api\Vfs::$is_root = true; |
1082 | 1078 | if (empty($this->data['jpegphoto'])) |
1083 | 1079 | { |
1084 | 1080 | unlink($path); |
1085 | - $update['files'] = $this->data['files'] & ~Api\Contacts::FILES_BIT_PHOTO; |
|
1081 | + $update['files'] = $this->data['files']&~Api\Contacts::FILES_BIT_PHOTO; |
|
1086 | 1082 | } |
1087 | 1083 | else |
1088 | 1084 | { |
1089 | 1085 | file_put_contents($path, $this->data['jpegphoto']); |
1090 | - $update['files'] = $this->data['files'] | Api\Contacts::FILES_BIT_PHOTO; |
|
1086 | + $update['files'] = $this->data['files']|Api\Contacts::FILES_BIT_PHOTO; |
|
1091 | 1087 | } |
1092 | 1088 | Api\Vfs::$is_root = $backup; |
1093 | 1089 | } |
@@ -1109,7 +1105,7 @@ discard block |
||
1109 | 1105 | { |
1110 | 1106 | if (!$list) return false; |
1111 | 1107 | |
1112 | - return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
|
1108 | + return $this->db->select($this->lists_table, '*', array('list_id'=>$list), __LINE__, __FILE__)->fetch(); |
|
1113 | 1109 | } |
1114 | 1110 | |
1115 | 1111 | /** |
@@ -1120,9 +1116,9 @@ discard block |
||
1120 | 1116 | * @param array $extra_cols =array() extra-data to be saved |
1121 | 1117 | * @return bool false on success, errornumber on failure |
1122 | 1118 | */ |
1123 | - function save_customfields(&$data, array $extra_cols=array()) |
|
1119 | + function save_customfields(&$data, array $extra_cols = array()) |
|
1124 | 1120 | { |
1125 | - return parent::save_customfields($data, array('contact_owner' => $data['owner'])+$extra_cols); |
|
1121 | + return parent::save_customfields($data, array('contact_owner' => $data['owner']) + $extra_cols); |
|
1126 | 1122 | } |
1127 | 1123 | |
1128 | 1124 | /** |
@@ -1131,6 +1127,6 @@ discard block |
||
1131 | 1127 | */ |
1132 | 1128 | function delete_customfields($data) |
1133 | 1129 | { |
1134 | - $this->db->delete($this->extra_table,$data,__LINE__,__FILE__); |
|
1130 | + $this->db->delete($this->extra_table, $data, __LINE__, __FILE__); |
|
1135 | 1131 | } |
1136 | 1132 | } |
@@ -447,10 +447,10 @@ discard block |
||
447 | 447 | * Important: PHP 5.0 introduced a bug that wasn't fixed until 5.1: the return value has to be the oposite! |
448 | 448 | * |
449 | 449 | * if(version_compare(PHP_VERSION,'5.0','>=') && version_compare(PHP_VERSION,'5.1','<')) |
450 | - * { |
|
450 | + * { |
|
451 | 451 | * $eof = !$eof; |
452 | 452 | * } |
453 | - * |
|
453 | + * |
|
454 | 454 | * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise |
455 | 455 | */ |
456 | 456 | function stream_eof ( ) |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | * See fseek() for more information about these parameters. |
486 | 486 | * |
487 | 487 | * @param integer $offset |
488 | - * @param integer $whence SEEK_SET - 0 - Set position equal to offset bytes |
|
488 | + * @param integer $whence SEEK_SET - 0 - Set position equal to offset bytes |
|
489 | 489 | * SEEK_CUR - 1 - Set position to current location plus offset. |
490 | 490 | * SEEK_END - 2 - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.) |
491 | 491 | * @return boolean TRUE if the position was updated, FALSE otherwise. |
@@ -681,8 +681,8 @@ discard block |
||
681 | 681 | $maxdepth=10; |
682 | 682 | $depth2propagate = (int)$depth + 1; |
683 | 683 | if ($depth2propagate > $maxdepth) return is_dir($pathname); |
684 | - is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate); |
|
685 | - return is_dir($pathname) || @mkdir($pathname, $mode); |
|
684 | + is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate); |
|
685 | + return is_dir($pathname) || @mkdir($pathname, $mode); |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | /** |
68 | 68 | * mode-bits, which have to be set for directories |
69 | 69 | */ |
70 | - const MODE_DIR = 040000; |
|
70 | + const MODE_DIR = 040000; |
|
71 | 71 | /** |
72 | 72 | * mode-bits, which have to be set for links |
73 | 73 | */ |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | * |
170 | 170 | * @param string $path ='/' |
171 | 171 | */ |
172 | - public static function clearstatcache($path='/') |
|
172 | + public static function clearstatcache($path = '/') |
|
173 | 173 | { |
174 | 174 | //error_log(__METHOD__."('$path')"); |
175 | - unset($path); // not used |
|
175 | + unset($path); // not used |
|
176 | 176 | |
177 | 177 | self::$stat_cache = array(); |
178 | 178 | |
@@ -191,32 +191,32 @@ discard block |
||
191 | 191 | * @param string &$opened_path full path of the file/resource, if the open was successfull and STREAM_USE_PATH was set |
192 | 192 | * @return boolean true if the ressource was opened successful, otherwise false |
193 | 193 | */ |
194 | - function stream_open ($url, $mode, $options, &$opened_path) |
|
194 | + function stream_open($url, $mode, $options, &$opened_path) |
|
195 | 195 | { |
196 | 196 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)"); |
197 | 197 | |
198 | - $path = Vfs::parse_url($url,PHP_URL_PATH); |
|
198 | + $path = Vfs::parse_url($url, PHP_URL_PATH); |
|
199 | 199 | $this->operation = self::url2operation($url); |
200 | 200 | $dir = Vfs::dirname($url); |
201 | 201 | |
202 | 202 | $this->opened_path = $opened_path = $path; |
203 | - $this->opened_mode = $mode = str_replace('b','',$mode); // we are always binary, like every Linux system |
|
203 | + $this->opened_mode = $mode = str_replace('b', '', $mode); // we are always binary, like every Linux system |
|
204 | 204 | $this->opened_stream = null; |
205 | 205 | |
206 | 206 | parse_str(parse_url($url, PHP_URL_QUERY), $this->dir_url_params); |
207 | 207 | |
208 | - if (!is_null($this->overwrite_new) || !($stat = $this->url_stat($path,STREAM_URL_STAT_QUIET)) || $mode[0] == 'x') // file not found or file should NOT exist |
|
208 | + if (!is_null($this->overwrite_new) || !($stat = $this->url_stat($path, STREAM_URL_STAT_QUIET)) || $mode[0] == 'x') // file not found or file should NOT exist |
|
209 | 209 | { |
210 | - if (!$dir || $mode[0] == 'r' || // does $mode require the file to exist (r,r+) |
|
211 | - $mode[0] == 'x' && $stat || // or file should not exist, but does |
|
212 | - !($dir_stat=$this->url_stat($dir,STREAM_URL_STAT_QUIET)) || // or parent dir does not exist create it |
|
213 | - !Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat)) // or we are not allowed to create it |
|
210 | + if (!$dir || $mode[0] == 'r' || // does $mode require the file to exist (r,r+) |
|
211 | + $mode[0] == 'x' && $stat || // or file should not exist, but does |
|
212 | + !($dir_stat = $this->url_stat($dir, STREAM_URL_STAT_QUIET)) || // or parent dir does not exist create it |
|
213 | + !Vfs::check_access($dir, Vfs::WRITABLE, $dir_stat)) // or we are not allowed to create it |
|
214 | 214 | { |
215 | 215 | self::_remove_password($url); |
216 | 216 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!"); |
217 | - if (($options & STREAM_REPORT_ERRORS)) |
|
217 | + if (($options&STREAM_REPORT_ERRORS)) |
|
218 | 218 | { |
219 | - trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING); |
|
219 | + trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!", E_USER_WARNING); |
|
220 | 220 | } |
221 | 221 | $this->opened_stream = $this->opened_path = $this->opened_mode = null; |
222 | 222 | return false; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | 'fs_name' => self::limit_filename(Vfs::basename($path)), |
232 | 232 | 'fs_dir' => $dir_stat['ino'], |
233 | 233 | // we use the mode of the dir, so files in group dirs stay accessible by all members |
234 | - 'fs_mode' => $dir_stat['mode'] & 0666, |
|
234 | + 'fs_mode' => $dir_stat['mode']&0666, |
|
235 | 235 | // for the uid we use the uid of the dir if not 0=root or the current user otherwise |
236 | 236 | 'fs_uid' => $dir_stat['uid'] ? $dir_stat['uid'] : Vfs::$user, |
237 | 237 | // we allways use the group of the dir |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | 'fs_created' => self::_pdo_timestamp(time()), |
240 | 240 | 'fs_modified' => self::_pdo_timestamp(time()), |
241 | 241 | 'fs_creator' => Vfs::$user, |
242 | - 'fs_mime' => 'application/octet-stream', // required NOT NULL! |
|
242 | + 'fs_mime' => 'application/octet-stream', // required NOT NULL! |
|
243 | 243 | 'fs_size' => 0, |
244 | 244 | 'fs_active' => self::_pdo_boolean(true), |
245 | 245 | ); |
@@ -256,35 +256,35 @@ discard block |
||
256 | 256 | $this->opened_stream = tmpfile(); |
257 | 257 | } |
258 | 258 | // create the hash-dirs, if they not yet exist |
259 | - elseif(!file_exists($fs_dir=Vfs::dirname(self::_fs_path($this->opened_fs_id)))) |
|
259 | + elseif (!file_exists($fs_dir = Vfs::dirname(self::_fs_path($this->opened_fs_id)))) |
|
260 | 260 | { |
261 | 261 | $umaskbefore = umask(); |
262 | 262 | if (self::LOG_LEVEL > 1) error_log(__METHOD__." about to call mkdir for $fs_dir # Present UMASK:".decoct($umaskbefore)." called from:".function_backtrace()); |
263 | - self::mkdir_recursive($fs_dir,0700,true); |
|
263 | + self::mkdir_recursive($fs_dir, 0700, true); |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | // check if opend file is a directory |
267 | - elseif($stat && ($stat['mode'] & self::MODE_DIR) == self::MODE_DIR) |
|
267 | + elseif ($stat && ($stat['mode']&self::MODE_DIR) == self::MODE_DIR) |
|
268 | 268 | { |
269 | 269 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) Is a directory!"); |
270 | - if (($options & STREAM_REPORT_ERRORS)) |
|
270 | + if (($options&STREAM_REPORT_ERRORS)) |
|
271 | 271 | { |
272 | - trigger_error(__METHOD__."($url,$mode,$options) Is a directory!",E_USER_WARNING); |
|
272 | + trigger_error(__METHOD__."($url,$mode,$options) Is a directory!", E_USER_WARNING); |
|
273 | 273 | } |
274 | 274 | $this->opened_stream = $this->opened_path = $this->opened_mode = null; |
275 | 275 | return false; |
276 | 276 | } |
277 | 277 | else |
278 | 278 | { |
279 | - if ($mode == 'r' && !Vfs::check_access($url,Vfs::READABLE ,$stat) ||// we are not allowed to read |
|
280 | - $mode != 'r' && !Vfs::check_access($url,Vfs::WRITABLE,$stat)) // or edit it |
|
279 | + if ($mode == 'r' && !Vfs::check_access($url, Vfs::READABLE, $stat) || // we are not allowed to read |
|
280 | + $mode != 'r' && !Vfs::check_access($url, Vfs::WRITABLE, $stat)) // or edit it |
|
281 | 281 | { |
282 | 282 | self::_remove_password($url); |
283 | 283 | $op = $mode == 'r' ? 'read' : 'edited'; |
284 | 284 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be $op!"); |
285 | - if (($options & STREAM_REPORT_ERRORS)) |
|
285 | + if (($options&STREAM_REPORT_ERRORS)) |
|
286 | 286 | { |
287 | - trigger_error(__METHOD__."($url,$mode,$options) file can not be $op!",E_USER_WARNING); |
|
287 | + trigger_error(__METHOD__."($url,$mode,$options) file can not be $op!", E_USER_WARNING); |
|
288 | 288 | } |
289 | 289 | $this->opened_stream = $this->opened_path = $this->opened_mode = null; |
290 | 290 | return false; |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | |
294 | 294 | if ($this->operation == self::STORE2DB) |
295 | 295 | { |
296 | - $stmt = self::$pdo->prepare($sql='SELECT fs_content FROM '.self::TABLE.' WHERE fs_id=?'); |
|
296 | + $stmt = self::$pdo->prepare($sql = 'SELECT fs_content FROM '.self::TABLE.' WHERE fs_id=?'); |
|
297 | 297 | $stmt->execute(array($stat['ino'])); |
298 | - $stmt->bindColumn(1,$this->opened_stream,\PDO::PARAM_LOB); |
|
298 | + $stmt->bindColumn(1, $this->opened_stream, \PDO::PARAM_LOB); |
|
299 | 299 | $stmt->fetch(\PDO::FETCH_BOUND); |
300 | 300 | // hack to work around a current php bug (http://bugs.php.net/bug.php?id=40913) |
301 | 301 | // PDOStatement::bindColumn(,,\PDO::PARAM_LOB) is not working for MySQL, content is returned as string :-( |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | if ($this->operation == self::STORE2FS) |
315 | 315 | { |
316 | 316 | if (self::LOG_LEVEL > 1) error_log(__METHOD__." fopen (may create a directory? mkdir) ($this->opened_fs_id,$mode,$options)"); |
317 | - if (!($this->opened_stream = fopen(self::_fs_path($this->opened_fs_id),$mode)) && $new_file) |
|
317 | + if (!($this->opened_stream = fopen(self::_fs_path($this->opened_fs_id), $mode)) && $new_file) |
|
318 | 318 | { |
319 | 319 | // delete db entry again, if we are not able to open a new(!) file |
320 | 320 | unset($stmt); |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | } |
325 | 325 | if ($mode[0] == 'a') // append modes: a, a+ |
326 | 326 | { |
327 | - $this->stream_seek(0,SEEK_END); |
|
327 | + $this->stream_seek(0, SEEK_END); |
|
328 | 328 | } |
329 | 329 | if (!is_resource($this->opened_stream)) error_log(__METHOD__."($url,$mode,$options) NO stream, returning false!"); |
330 | 330 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * |
337 | 337 | * You must release any resources that were locked or allocated by the stream. |
338 | 338 | */ |
339 | - function stream_close ( ) |
|
339 | + function stream_close( ) |
|
340 | 340 | { |
341 | 341 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."()"); |
342 | 342 | |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | |
348 | 348 | if ($this->opened_mode != 'r') |
349 | 349 | { |
350 | - $this->stream_seek(0,SEEK_END); |
|
350 | + $this->stream_seek(0, SEEK_END); |
|
351 | 351 | |
352 | 352 | // we need to update the mime-type, size and content (if STORE2DB) |
353 | 353 | $values = array( |
@@ -370,10 +370,10 @@ discard block |
||
370 | 370 | else |
371 | 371 | { |
372 | 372 | $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_size=:fs_size,fs_mime=:fs_mime,fs_modifier=:fs_modifier,fs_modified=:fs_modified,fs_content=:fs_content WHERE fs_id=:fs_id'); |
373 | - $this->stream_seek(0,SEEK_SET); // rewind to the start |
|
374 | - foreach($values as $name => &$value) |
|
373 | + $this->stream_seek(0, SEEK_SET); // rewind to the start |
|
374 | + foreach ($values as $name => &$value) |
|
375 | 375 | { |
376 | - $stmt->bindParam($name,$value); |
|
376 | + $stmt->bindParam($name, $value); |
|
377 | 377 | } |
378 | 378 | $stmt->bindParam('fs_content', $this->opened_stream, \PDO::PARAM_LOB); |
379 | 379 | if (!($ret = $stmt->execute())) |
@@ -406,13 +406,13 @@ discard block |
||
406 | 406 | * @param int $count |
407 | 407 | * @return string/false up to count bytes read or false on EOF |
408 | 408 | */ |
409 | - function stream_read ( $count ) |
|
409 | + function stream_read($count) |
|
410 | 410 | { |
411 | 411 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($count) pos=$this->opened_pos"); |
412 | 412 | |
413 | 413 | if (is_resource($this->opened_stream)) |
414 | 414 | { |
415 | - return fread($this->opened_stream,$count); |
|
415 | + return fread($this->opened_stream, $count); |
|
416 | 416 | } |
417 | 417 | return false; |
418 | 418 | } |
@@ -428,13 +428,13 @@ discard block |
||
428 | 428 | * @param string $data |
429 | 429 | * @return integer |
430 | 430 | */ |
431 | - function stream_write ( $data ) |
|
431 | + function stream_write($data) |
|
432 | 432 | { |
433 | 433 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($data)"); |
434 | 434 | |
435 | 435 | if (is_resource($this->opened_stream)) |
436 | 436 | { |
437 | - return fwrite($this->opened_stream,$data); |
|
437 | + return fwrite($this->opened_stream, $data); |
|
438 | 438 | } |
439 | 439 | return false; |
440 | 440 | } |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | * |
452 | 452 | * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise |
453 | 453 | */ |
454 | - function stream_eof ( ) |
|
454 | + function stream_eof( ) |
|
455 | 455 | { |
456 | 456 | if (is_resource($this->opened_stream)) |
457 | 457 | { |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | * |
466 | 466 | * @return integer current read/write position of the stream |
467 | 467 | */ |
468 | - function stream_tell ( ) |
|
468 | + function stream_tell( ) |
|
469 | 469 | { |
470 | 470 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."()"); |
471 | 471 | |
@@ -488,13 +488,13 @@ discard block |
||
488 | 488 | * SEEK_END - 2 - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.) |
489 | 489 | * @return boolean TRUE if the position was updated, FALSE otherwise. |
490 | 490 | */ |
491 | - function stream_seek ( $offset, $whence ) |
|
491 | + function stream_seek($offset, $whence) |
|
492 | 492 | { |
493 | 493 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($offset,$whence)"); |
494 | 494 | |
495 | 495 | if (is_resource($this->opened_stream)) |
496 | 496 | { |
497 | - return !fseek($this->opened_stream,$offset,$whence); // fseek returns 0 on success and -1 on failure |
|
497 | + return !fseek($this->opened_stream, $offset, $whence); // fseek returns 0 on success and -1 on failure |
|
498 | 498 | } |
499 | 499 | return false; |
500 | 500 | } |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | * |
507 | 507 | * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored. |
508 | 508 | */ |
509 | - function stream_flush ( ) |
|
509 | + function stream_flush( ) |
|
510 | 510 | { |
511 | 511 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."()"); |
512 | 512 | |
@@ -531,11 +531,11 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @return array containing the same values as appropriate for the stream. |
533 | 533 | */ |
534 | - function stream_stat ( ) |
|
534 | + function stream_stat( ) |
|
535 | 535 | { |
536 | 536 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($this->opened_path)"); |
537 | 537 | |
538 | - return $this->url_stat($this->opened_path,0); |
|
538 | + return $this->url_stat($this->opened_path, 0); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
@@ -547,28 +547,28 @@ discard block |
||
547 | 547 | * @param string $url |
548 | 548 | * @return boolean TRUE on success or FALSE on failure |
549 | 549 | */ |
550 | - function unlink ( $url ) |
|
550 | + function unlink($url) |
|
551 | 551 | { |
552 | 552 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)"); |
553 | 553 | |
554 | - $path = Vfs::parse_url($url,PHP_URL_PATH); |
|
554 | + $path = Vfs::parse_url($url, PHP_URL_PATH); |
|
555 | 555 | |
556 | 556 | // need to get parent stat from Sqlfs, not Vfs |
557 | 557 | $parent_stat = !($dir = Vfs::dirname($path)) ? false : |
558 | 558 | $this->url_stat($dir, STREAM_URL_STAT_LINK); |
559 | 559 | |
560 | - if (!$parent_stat || !($stat = $this->url_stat($path,STREAM_URL_STAT_LINK)) || |
|
560 | + if (!$parent_stat || !($stat = $this->url_stat($path, STREAM_URL_STAT_LINK)) || |
|
561 | 561 | !$dir || !Vfs::check_access($dir, Vfs::WRITABLE, $parent_stat)) |
562 | 562 | { |
563 | 563 | self::_remove_password($url); |
564 | 564 | if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!"); |
565 | - return false; // no permission or file does not exist |
|
565 | + return false; // no permission or file does not exist |
|
566 | 566 | } |
567 | 567 | if ($stat['mime'] == self::DIR_MIME_TYPE) |
568 | 568 | { |
569 | 569 | self::_remove_password($url); |
570 | 570 | if (self::LOG_LEVEL) error_log(__METHOD__."($url) is NO file!"); |
571 | - return false; // no permission or file does not exist |
|
571 | + return false; // no permission or file does not exist |
|
572 | 572 | } |
573 | 573 | $stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=:fs_id'); |
574 | 574 | unset(self::$stat_cache[$path]); |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | if (($ret = $stmt->execute(array('fs_id' => $stat['ino'])))) |
577 | 577 | { |
578 | 578 | if (self::url2operation($url) == self::STORE2FS && |
579 | - ($stat['mode'] & self::MODE_LINK) != self::MODE_LINK) |
|
579 | + ($stat['mode']&self::MODE_LINK) != self::MODE_LINK) |
|
580 | 580 | { |
581 | 581 | unlink(self::_fs_path($stat['ino'])); |
582 | 582 | } |
@@ -600,13 +600,13 @@ discard block |
||
600 | 600 | * @param string $url_to |
601 | 601 | * @return boolean TRUE on success or FALSE on failure |
602 | 602 | */ |
603 | - function rename ( $url_from, $url_to) |
|
603 | + function rename($url_from, $url_to) |
|
604 | 604 | { |
605 | 605 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url_from,$url_to)"); |
606 | 606 | |
607 | - $path_from = Vfs::parse_url($url_from,PHP_URL_PATH); |
|
607 | + $path_from = Vfs::parse_url($url_from, PHP_URL_PATH); |
|
608 | 608 | $from_dir = Vfs::dirname($path_from); |
609 | - $path_to = Vfs::parse_url($url_to,PHP_URL_PATH); |
|
609 | + $path_to = Vfs::parse_url($url_to, PHP_URL_PATH); |
|
610 | 610 | $to_dir = Vfs::dirname($path_to); |
611 | 611 | |
612 | 612 | if (!($from_stat = $this->url_stat($path_from, 0)) || !$from_dir || |
@@ -615,14 +615,14 @@ discard block |
||
615 | 615 | self::_remove_password($url_from); |
616 | 616 | self::_remove_password($url_to); |
617 | 617 | if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_from permission denied!"); |
618 | - return false; // no permission or file does not exist |
|
618 | + return false; // no permission or file does not exist |
|
619 | 619 | } |
620 | 620 | if (!$to_dir || !Vfs::check_access($to_dir, Vfs::WRITABLE, $to_dir_stat = $this->url_stat($to_dir, 0))) |
621 | 621 | { |
622 | 622 | self::_remove_password($url_from); |
623 | 623 | self::_remove_password($url_to); |
624 | 624 | if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_to permission denied!"); |
625 | - return false; // no permission or parent-dir does not exist |
|
625 | + return false; // no permission or parent-dir does not exist |
|
626 | 626 | } |
627 | 627 | // the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems |
628 | 628 | // for our vfs too, we abort here with an error, like the filesystem one does |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | self::_remove_password($url_to); |
634 | 634 | $is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no'; |
635 | 635 | if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $path_to is $is_dir directory!"); |
636 | - return false; // no permission or file does not exist |
|
636 | + return false; // no permission or file does not exist |
|
637 | 637 | } |
638 | 638 | // if destination file already exists, delete it |
639 | 639 | if ($to_stat && !$this->unlink($url_to)) |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | |
658 | 658 | // check if extension changed and update mime-type in that case (as we currently determine mime-type by it's extension!) |
659 | 659 | // fixes eg. problems with MsWord storing file with .tmp extension and then renaming to .doc |
660 | - if ($ok && ($new_mime = Vfs::mime_content_type($url_to,true)) != Vfs::mime_content_type($url_to)) |
|
660 | + if ($ok && ($new_mime = Vfs::mime_content_type($url_to, true)) != Vfs::mime_content_type($url_to)) |
|
661 | 661 | { |
662 | 662 | //echo "<p>Vfs::nime_content_type($url_to,true) = $new_mime</p>\n"; |
663 | 663 | $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_mime=:fs_mime WHERE fs_id=:fs_id'); |
@@ -673,9 +673,9 @@ discard block |
||
673 | 673 | /** |
674 | 674 | * due to problems with recursive directory creation, we have our own here |
675 | 675 | */ |
676 | - protected static function mkdir_recursive($pathname, $mode, $depth=0) |
|
676 | + protected static function mkdir_recursive($pathname, $mode, $depth = 0) |
|
677 | 677 | { |
678 | - $maxdepth=10; |
|
678 | + $maxdepth = 10; |
|
679 | 679 | $depth2propagate = (int)$depth + 1; |
680 | 680 | if ($depth2propagate > $maxdepth) return is_dir($pathname); |
681 | 681 | is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate); |
@@ -693,19 +693,19 @@ discard block |
||
693 | 693 | * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE |
694 | 694 | * @return boolean TRUE on success or FALSE on failure |
695 | 695 | */ |
696 | - function mkdir ( $url, $mode, $options ) |
|
696 | + function mkdir($url, $mode, $options) |
|
697 | 697 | { |
698 | 698 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)"); |
699 | 699 | if (self::LOG_LEVEL > 1) error_log(__METHOD__." called from:".function_backtrace()); |
700 | - $path = Vfs::parse_url($url,PHP_URL_PATH); |
|
700 | + $path = Vfs::parse_url($url, PHP_URL_PATH); |
|
701 | 701 | |
702 | - if ($this->url_stat($path,STREAM_URL_STAT_QUIET)) |
|
702 | + if ($this->url_stat($path, STREAM_URL_STAT_QUIET)) |
|
703 | 703 | { |
704 | 704 | self::_remove_password($url); |
705 | 705 | if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) already exist!"); |
706 | - if (!($options & STREAM_REPORT_ERRORS)) |
|
706 | + if (!($options&STREAM_REPORT_ERRORS)) |
|
707 | 707 | { |
708 | - trigger_error(__METHOD__."('$url',$mode,$options) already exist!",E_USER_WARNING); |
|
708 | + trigger_error(__METHOD__."('$url',$mode,$options) already exist!", E_USER_WARNING); |
|
709 | 709 | } |
710 | 710 | return false; |
711 | 711 | } |
@@ -713,35 +713,35 @@ discard block |
||
713 | 713 | { |
714 | 714 | self::_remove_password($url); |
715 | 715 | if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) dirname('$path')===false!"); |
716 | - if (!($options & STREAM_REPORT_ERRORS)) |
|
716 | + if (!($options&STREAM_REPORT_ERRORS)) |
|
717 | 717 | { |
718 | 718 | trigger_error(__METHOD__."('$url',$mode,$options) dirname('$path')===false!", E_USER_WARNING); |
719 | 719 | } |
720 | 720 | return false; |
721 | 721 | } |
722 | - if (($query = Vfs::parse_url($url,PHP_URL_QUERY))) $parent_path .= '?'.$query; |
|
723 | - $parent = $this->url_stat($parent_path,STREAM_URL_STAT_QUIET); |
|
722 | + if (($query = Vfs::parse_url($url, PHP_URL_QUERY))) $parent_path .= '?'.$query; |
|
723 | + $parent = $this->url_stat($parent_path, STREAM_URL_STAT_QUIET); |
|
724 | 724 | |
725 | 725 | // check if we should also create all non-existing path components and our parent does not exist, |
726 | 726 | // if yes call ourself recursive with the parent directory |
727 | - if (($options & STREAM_MKDIR_RECURSIVE) && $parent_path != '/' && !$parent) |
|
727 | + if (($options&STREAM_MKDIR_RECURSIVE) && $parent_path != '/' && !$parent) |
|
728 | 728 | { |
729 | 729 | if (self::LOG_LEVEL > 1) error_log(__METHOD__." creating parents: $parent_path, $mode"); |
730 | - if (!$this->mkdir($parent_path,$mode,$options)) |
|
730 | + if (!$this->mkdir($parent_path, $mode, $options)) |
|
731 | 731 | { |
732 | 732 | return false; |
733 | 733 | } |
734 | - $parent = $this->url_stat($parent_path,0); |
|
734 | + $parent = $this->url_stat($parent_path, 0); |
|
735 | 735 | } |
736 | - if (!$parent || !Vfs::check_access($parent_path,Vfs::WRITABLE,$parent)) |
|
736 | + if (!$parent || !Vfs::check_access($parent_path, Vfs::WRITABLE, $parent)) |
|
737 | 737 | { |
738 | 738 | self::_remove_password($url); |
739 | 739 | if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) permission denied!"); |
740 | - if (!($options & STREAM_REPORT_ERRORS)) |
|
740 | + if (!($options&STREAM_REPORT_ERRORS)) |
|
741 | 741 | { |
742 | - trigger_error(__METHOD__."('$url',$mode,$options) permission denied!",E_USER_WARNING); |
|
742 | + trigger_error(__METHOD__."('$url',$mode,$options) permission denied!", E_USER_WARNING); |
|
743 | 743 | } |
744 | - return false; // no permission or file does not exist |
|
744 | + return false; // no permission or file does not exist |
|
745 | 745 | } |
746 | 746 | unset(self::$stat_cache[$path]); |
747 | 747 | $stmt = self::$pdo->prepare('INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_size,fs_mime,fs_created,fs_modified,fs_creator'. |
@@ -762,9 +762,9 @@ discard block |
||
762 | 762 | // check if some other process created the directory parallel to us (sqlfs would gives SQL errors later!) |
763 | 763 | $new_fs_id = self::$pdo->lastInsertId('egw_sqlfs_fs_id_seq'); |
764 | 764 | |
765 | - unset($stmt); // free statement object, on some installs a new prepare fails otherwise! |
|
765 | + unset($stmt); // free statement object, on some installs a new prepare fails otherwise! |
|
766 | 766 | |
767 | - $stmt = self::$pdo->prepare($q='SELECT COUNT(*) FROM '.self::TABLE. |
|
767 | + $stmt = self::$pdo->prepare($q = 'SELECT COUNT(*) FROM '.self::TABLE. |
|
768 | 768 | ' WHERE fs_dir=:fs_dir AND fs_active=:fs_active AND fs_name'.self::$case_sensitive_equal.':fs_name'); |
769 | 769 | if ($stmt->execute(array( |
770 | 770 | 'fs_dir' => $parent['ino'], |
@@ -788,25 +788,24 @@ discard block |
||
788 | 788 | * @param int $options Possible values include STREAM_REPORT_ERRORS. |
789 | 789 | * @return boolean TRUE on success or FALSE on failure. |
790 | 790 | */ |
791 | - function rmdir ( $url, $options ) |
|
791 | + function rmdir($url, $options) |
|
792 | 792 | { |
793 | 793 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)"); |
794 | 794 | |
795 | - $path = Vfs::parse_url($url,PHP_URL_PATH); |
|
795 | + $path = Vfs::parse_url($url, PHP_URL_PATH); |
|
796 | 796 | |
797 | 797 | if (!($parent = Vfs::dirname($path)) || |
798 | 798 | !($stat = $this->url_stat($path, 0)) || $stat['mime'] != self::DIR_MIME_TYPE || |
799 | - !Vfs::check_access($parent, Vfs::WRITABLE, $this->url_stat($parent,0))) |
|
799 | + !Vfs::check_access($parent, Vfs::WRITABLE, $this->url_stat($parent, 0))) |
|
800 | 800 | { |
801 | 801 | self::_remove_password($url); |
802 | - $err_msg = __METHOD__."($url,$options) ".(!$stat ? 'not found!' : |
|
803 | - ($stat['mime'] != self::DIR_MIME_TYPE ? 'not a directory!' : 'permission denied!')); |
|
802 | + $err_msg = __METHOD__."($url,$options) ".(!$stat ? 'not found!' : ($stat['mime'] != self::DIR_MIME_TYPE ? 'not a directory!' : 'permission denied!')); |
|
804 | 803 | if (self::LOG_LEVEL) error_log($err_msg); |
805 | - if (!($options & STREAM_REPORT_ERRORS)) |
|
804 | + if (!($options&STREAM_REPORT_ERRORS)) |
|
806 | 805 | { |
807 | - trigger_error($err_msg,E_USER_WARNING); |
|
806 | + trigger_error($err_msg, E_USER_WARNING); |
|
808 | 807 | } |
809 | - return false; // no permission or file does not exist |
|
808 | + return false; // no permission or file does not exist |
|
810 | 809 | } |
811 | 810 | $stmt = self::$pdo->prepare('SELECT COUNT(*) FROM '.self::TABLE.' WHERE fs_dir=?'); |
812 | 811 | $stmt->execute(array($stat['ino'])); |
@@ -814,19 +813,19 @@ discard block |
||
814 | 813 | { |
815 | 814 | self::_remove_password($url); |
816 | 815 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$options) dir is not empty!"); |
817 | - if (!($options & STREAM_REPORT_ERRORS)) |
|
816 | + if (!($options&STREAM_REPORT_ERRORS)) |
|
818 | 817 | { |
819 | - trigger_error(__METHOD__."('$url',$options) dir is not empty!",E_USER_WARNING); |
|
818 | + trigger_error(__METHOD__."('$url',$options) dir is not empty!", E_USER_WARNING); |
|
820 | 819 | } |
821 | 820 | return false; |
822 | 821 | } |
823 | 822 | unset(self::$stat_cache[$path]); |
824 | - unset($stmt); // free statement object, on some installs a new prepare fails otherwise! |
|
823 | + unset($stmt); // free statement object, on some installs a new prepare fails otherwise! |
|
825 | 824 | |
826 | 825 | $del_stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=?'); |
827 | 826 | if (($ret = $del_stmt->execute(array($stat['ino'])))) |
828 | 827 | { |
829 | - self::eacl($path,null,false,$stat['ino']); // remove all (=false) evtl. existing extended acl for that dir |
|
828 | + self::eacl($path, null, false, $stat['ino']); // remove all (=false) evtl. existing extended acl for that dir |
|
830 | 829 | // delete props |
831 | 830 | unset($del_stmt); |
832 | 831 | $del_stmt = self::$pdo->prepare('DELETE FROM '.self::PROPS_TABLE.' WHERE fs_id=?'); |
@@ -853,10 +852,10 @@ discard block |
||
853 | 852 | { |
854 | 853 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path, $option, ".array2string($value).")"); |
855 | 854 | |
856 | - switch($option) |
|
855 | + switch ($option) |
|
857 | 856 | { |
858 | 857 | case STREAM_META_TOUCH: |
859 | - return $this->touch($path, $value[0]); // atime is not supported |
|
858 | + return $this->touch($path, $value[0]); // atime is not supported |
|
860 | 859 | |
861 | 860 | case STREAM_META_ACCESS: |
862 | 861 | return $this->chmod($path, $value); |
@@ -885,26 +884,26 @@ discard block |
||
885 | 884 | * @param int $time =null modification time (unix timestamp), default null = current time |
886 | 885 | * @param int $atime =null access time (unix timestamp), default null = current time, not implemented in the vfs! |
887 | 886 | */ |
888 | - protected function touch($url,$time=null,$atime=null) |
|
887 | + protected function touch($url, $time = null, $atime = null) |
|
889 | 888 | { |
890 | - unset($atime); // not used |
|
889 | + unset($atime); // not used |
|
891 | 890 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $time)"); |
892 | 891 | |
893 | - $path = Vfs::parse_url($url,PHP_URL_PATH); |
|
892 | + $path = Vfs::parse_url($url, PHP_URL_PATH); |
|
894 | 893 | |
895 | 894 | $vfs = new self(); |
896 | - if (!($stat = $vfs->url_stat($path,STREAM_URL_STAT_QUIET))) |
|
895 | + if (!($stat = $vfs->url_stat($path, STREAM_URL_STAT_QUIET))) |
|
897 | 896 | { |
898 | 897 | // file does not exist --> create an empty one |
899 | - if (!($f = fopen(self::SCHEME.'://default'.$path,'w')) || !fclose($f)) |
|
898 | + if (!($f = fopen(self::SCHEME.'://default'.$path, 'w')) || !fclose($f)) |
|
900 | 899 | { |
901 | 900 | return false; |
902 | 901 | } |
903 | 902 | if (!$time) |
904 | 903 | { |
905 | - return true; // new (empty) file created with current mod time |
|
904 | + return true; // new (empty) file created with current mod time |
|
906 | 905 | } |
907 | - $stat = $vfs->url_stat($path,0); |
|
906 | + $stat = $vfs->url_stat($path, 0); |
|
908 | 907 | } |
909 | 908 | unset(self::$stat_cache[$path]); |
910 | 909 | $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_modified=:fs_modified,fs_modifier=:fs_modifier WHERE fs_id=:fs_id'); |
@@ -923,40 +922,40 @@ discard block |
||
923 | 922 | * @param int $owner |
924 | 923 | * @return boolean |
925 | 924 | */ |
926 | - protected function chown($url,$owner) |
|
925 | + protected function chown($url, $owner) |
|
927 | 926 | { |
928 | 927 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)"); |
929 | 928 | |
930 | - $path = Vfs::parse_url($url,PHP_URL_PATH); |
|
929 | + $path = Vfs::parse_url($url, PHP_URL_PATH); |
|
931 | 930 | |
932 | 931 | $vfs = new self(); |
933 | - if (!($stat = $vfs->url_stat($path,0))) |
|
932 | + if (!($stat = $vfs->url_stat($path, 0))) |
|
934 | 933 | { |
935 | 934 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!"); |
936 | - trigger_error("No such file or directory $url !",E_USER_WARNING); |
|
935 | + trigger_error("No such file or directory $url !", E_USER_WARNING); |
|
937 | 936 | return false; |
938 | 937 | } |
939 | 938 | if (!Vfs::$is_root) |
940 | 939 | { |
941 | 940 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only root can do that!"); |
942 | - trigger_error("Only root can do that!",E_USER_WARNING); |
|
941 | + trigger_error("Only root can do that!", E_USER_WARNING); |
|
943 | 942 | return false; |
944 | 943 | } |
945 | 944 | if ($owner < 0 || $owner && !$GLOBALS['egw']->accounts->id2name($owner)) // not a user (0 == root) |
946 | 945 | { |
947 | 946 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) user id!"); |
948 | - trigger_error(__METHOD__."($url,$owner) Unknown (numeric) user id!",E_USER_WARNING); |
|
947 | + trigger_error(__METHOD__."($url,$owner) Unknown (numeric) user id!", E_USER_WARNING); |
|
949 | 948 | //throw new Exception(__METHOD__."($url,$owner) Unknown (numeric) user id!"); |
950 | 949 | return false; |
951 | 950 | } |
952 | 951 | $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_uid=:fs_uid WHERE fs_id=:fs_id'); |
953 | 952 | |
954 | 953 | // update stat-cache |
955 | - if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1); |
|
954 | + if ($path != '/' && substr($path, -1) == '/') $path = substr($path, 0, -1); |
|
956 | 955 | self::$stat_cache[$path]['fs_uid'] = $owner; |
957 | 956 | |
958 | 957 | return $stmt->execute(array( |
959 | - 'fs_uid' => (int) $owner, |
|
958 | + 'fs_uid' => (int)$owner, |
|
960 | 959 | 'fs_id' => $stat['ino'], |
961 | 960 | )); |
962 | 961 | } |
@@ -968,37 +967,37 @@ discard block |
||
968 | 967 | * @param int $owner |
969 | 968 | * @return boolean |
970 | 969 | */ |
971 | - protected function chgrp($url,$owner) |
|
970 | + protected function chgrp($url, $owner) |
|
972 | 971 | { |
973 | 972 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)"); |
974 | 973 | |
975 | - $path = Vfs::parse_url($url,PHP_URL_PATH); |
|
974 | + $path = Vfs::parse_url($url, PHP_URL_PATH); |
|
976 | 975 | |
977 | 976 | $vfs = new self(); |
978 | - if (!($stat = $vfs->url_stat($path,0))) |
|
977 | + if (!($stat = $vfs->url_stat($path, 0))) |
|
979 | 978 | { |
980 | 979 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!"); |
981 | - trigger_error("No such file or directory $url !",E_USER_WARNING); |
|
980 | + trigger_error("No such file or directory $url !", E_USER_WARNING); |
|
982 | 981 | return false; |
983 | 982 | } |
984 | - if (!Vfs::has_owner_rights($path,$stat)) |
|
983 | + if (!Vfs::has_owner_rights($path, $stat)) |
|
985 | 984 | { |
986 | 985 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only owner or root can do that!"); |
987 | - trigger_error("Only owner or root can do that!",E_USER_WARNING); |
|
986 | + trigger_error("Only owner or root can do that!", E_USER_WARNING); |
|
988 | 987 | return false; |
989 | 988 | } |
990 | - if ($owner < 0) $owner = -$owner; // sqlfs uses a positiv group id's! |
|
989 | + if ($owner < 0) $owner = -$owner; // sqlfs uses a positiv group id's! |
|
991 | 990 | |
992 | 991 | if ($owner && !$GLOBALS['egw']->accounts->id2name(-$owner)) // not a group |
993 | 992 | { |
994 | 993 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) group id!"); |
995 | - trigger_error("Unknown (numeric) group id!",E_USER_WARNING); |
|
994 | + trigger_error("Unknown (numeric) group id!", E_USER_WARNING); |
|
996 | 995 | return false; |
997 | 996 | } |
998 | 997 | $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_gid=:fs_gid WHERE fs_id=:fs_id'); |
999 | 998 | |
1000 | 999 | // update stat-cache |
1001 | - if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1); |
|
1000 | + if ($path != '/' && substr($path, -1) == '/') $path = substr($path, 0, -1); |
|
1002 | 1001 | self::$stat_cache[$path]['fs_gid'] = $owner; |
1003 | 1002 | |
1004 | 1003 | return $stmt->execute(array( |
@@ -1014,39 +1013,39 @@ discard block |
||
1014 | 1013 | * @param int $mode |
1015 | 1014 | * @return boolean |
1016 | 1015 | */ |
1017 | - protected function chmod($url,$mode) |
|
1016 | + protected function chmod($url, $mode) |
|
1018 | 1017 | { |
1019 | 1018 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $mode)"); |
1020 | 1019 | |
1021 | - $path = Vfs::parse_url($url,PHP_URL_PATH); |
|
1020 | + $path = Vfs::parse_url($url, PHP_URL_PATH); |
|
1022 | 1021 | |
1023 | 1022 | $vfs = new self(); |
1024 | - if (!($stat = $vfs->url_stat($path,0))) |
|
1023 | + if (!($stat = $vfs->url_stat($path, 0))) |
|
1025 | 1024 | { |
1026 | 1025 | if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no such file or directory!"); |
1027 | - trigger_error("No such file or directory $url !",E_USER_WARNING); |
|
1026 | + trigger_error("No such file or directory $url !", E_USER_WARNING); |
|
1028 | 1027 | return false; |
1029 | 1028 | } |
1030 | - if (!Vfs::has_owner_rights($path,$stat)) |
|
1029 | + if (!Vfs::has_owner_rights($path, $stat)) |
|
1031 | 1030 | { |
1032 | 1031 | if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) only owner or root can do that!"); |
1033 | - trigger_error("Only owner or root can do that!",E_USER_WARNING); |
|
1032 | + trigger_error("Only owner or root can do that!", E_USER_WARNING); |
|
1034 | 1033 | return false; |
1035 | 1034 | } |
1036 | 1035 | if (!is_numeric($mode)) // not a mode |
1037 | 1036 | { |
1038 | 1037 | if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no (numeric) mode!"); |
1039 | - trigger_error("No (numeric) mode!",E_USER_WARNING); |
|
1038 | + trigger_error("No (numeric) mode!", E_USER_WARNING); |
|
1040 | 1039 | return false; |
1041 | 1040 | } |
1042 | 1041 | $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_mode=:fs_mode WHERE fs_id=:fs_id'); |
1043 | 1042 | |
1044 | 1043 | // update stat cache |
1045 | - if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1); |
|
1046 | - self::$stat_cache[$path]['fs_mode'] = ((int) $mode) & 0777; |
|
1044 | + if ($path != '/' && substr($path, -1) == '/') $path = substr($path, 0, -1); |
|
1045 | + self::$stat_cache[$path]['fs_mode'] = ((int)$mode)&0777; |
|
1047 | 1046 | |
1048 | 1047 | return $stmt->execute(array( |
1049 | - 'fs_mode' => ((int) $mode) & 0777, // we dont store the file and dir bits, give int overflow! |
|
1048 | + 'fs_mode' => ((int)$mode)&0777, // we dont store the file and dir bits, give int overflow! |
|
1050 | 1049 | 'fs_id' => $stat['ino'], |
1051 | 1050 | )); |
1052 | 1051 | } |
@@ -1059,18 +1058,18 @@ discard block |
||
1059 | 1058 | * @param int $options |
1060 | 1059 | * @return booelan |
1061 | 1060 | */ |
1062 | - function dir_opendir ( $url, $options ) |
|
1061 | + function dir_opendir($url, $options) |
|
1063 | 1062 | { |
1064 | 1063 | $this->opened_dir = null; |
1065 | 1064 | |
1066 | - $path = Vfs::parse_url($url,PHP_URL_PATH); |
|
1065 | + $path = Vfs::parse_url($url, PHP_URL_PATH); |
|
1067 | 1066 | |
1068 | - if (!($stat = $this->url_stat($url,0)) || // dir not found |
|
1069 | - !($stat['mode'] & self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE || // no dir |
|
1070 | - !Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat)) // no access |
|
1067 | + if (!($stat = $this->url_stat($url, 0)) || // dir not found |
|
1068 | + !($stat['mode']&self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE || // no dir |
|
1069 | + !Vfs::check_access($url, Vfs::EXECUTABLE|Vfs::READABLE, $stat)) // no access |
|
1071 | 1070 | { |
1072 | 1071 | self::_remove_password($url); |
1073 | - $msg = !($stat['mode'] & self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE ? |
|
1072 | + $msg = !($stat['mode']&self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE ? |
|
1074 | 1073 | "$url is no directory" : 'permission denied'; |
1075 | 1074 | if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$options) $msg!"); |
1076 | 1075 | $this->opened_dir = null; |
@@ -1087,13 +1086,13 @@ discard block |
||
1087 | 1086 | $stmt->setFetchMode(\PDO::FETCH_ASSOC); |
1088 | 1087 | if ($stmt->execute(array($stat['ino']))) |
1089 | 1088 | { |
1090 | - foreach($stmt as $file) |
|
1089 | + foreach ($stmt as $file) |
|
1091 | 1090 | { |
1092 | 1091 | $this->opened_dir[] = $file['fs_name']; |
1093 | - self::$stat_cache[Vfs::concat($path,$file['fs_name'])] = $file; |
|
1092 | + self::$stat_cache[Vfs::concat($path, $file['fs_name'])] = $file; |
|
1094 | 1093 | } |
1095 | 1094 | } |
1096 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options): ".implode(', ',$this->opened_dir)); |
|
1095 | + if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options): ".implode(', ', $this->opened_dir)); |
|
1097 | 1096 | reset($this->opened_dir); |
1098 | 1097 | |
1099 | 1098 | return true; |
@@ -1125,26 +1124,26 @@ discard block |
||
1125 | 1124 | * stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper! |
1126 | 1125 | * @return array |
1127 | 1126 | */ |
1128 | - function url_stat ( $url, $flags ) |
|
1127 | + function url_stat($url, $flags) |
|
1129 | 1128 | { |
1130 | - static $max_subquery_depth=null; |
|
1129 | + static $max_subquery_depth = null; |
|
1131 | 1130 | if (is_null($max_subquery_depth)) |
1132 | 1131 | { |
1133 | 1132 | $max_subquery_depth = $GLOBALS['egw_info']['server']['max_subquery_depth']; |
1134 | - if (!$max_subquery_depth) $max_subquery_depth = 7; // setting current default of 7, if nothing set |
|
1133 | + if (!$max_subquery_depth) $max_subquery_depth = 7; // setting current default of 7, if nothing set |
|
1135 | 1134 | } |
1136 | 1135 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$flags)"); |
1137 | 1136 | |
1138 | - $path = Vfs::parse_url($url,PHP_URL_PATH); |
|
1137 | + $path = Vfs::parse_url($url, PHP_URL_PATH); |
|
1139 | 1138 | |
1140 | 1139 | // webdav adds a trailing slash to dirs, which causes url_stat to NOT find the file otherwise |
1141 | - if ($path != '/' && substr($path,-1) == '/') |
|
1140 | + if ($path != '/' && substr($path, -1) == '/') |
|
1142 | 1141 | { |
1143 | - $path = substr($path,0,-1); |
|
1142 | + $path = substr($path, 0, -1); |
|
1144 | 1143 | } |
1145 | 1144 | if (empty($path)) |
1146 | 1145 | { |
1147 | - return false; // is invalid and gives sql error |
|
1146 | + return false; // is invalid and gives sql error |
|
1148 | 1147 | } |
1149 | 1148 | // check if we already have the info from the last dir_open call, as the old vfs reads it anyway from the db |
1150 | 1149 | if (self::$stat_cache && isset(self::$stat_cache[$path]) && self::$stat_cache[$path] !== false) |
@@ -1159,25 +1158,25 @@ discard block |
||
1159 | 1158 | $base_query = 'SELECT fs_id,fs_name,fs_mode,fs_uid,fs_gid,fs_size,fs_mime,fs_created,fs_modified'.self::$extra_columns. |
1160 | 1159 | ' FROM '.self::TABLE.' WHERE fs_active='.self::_pdo_boolean(true). |
1161 | 1160 | ' AND fs_name'.self::$case_sensitive_equal.'? AND fs_dir='; |
1162 | - $parts = explode('/',$path); |
|
1161 | + $parts = explode('/', $path); |
|
1163 | 1162 | |
1164 | 1163 | // if we have extended acl access to the url, we dont need and can NOT include the sql for the readable check |
1165 | - $eacl_access = static::check_extended_acl($path,Vfs::READABLE); |
|
1164 | + $eacl_access = static::check_extended_acl($path, Vfs::READABLE); |
|
1166 | 1165 | |
1167 | 1166 | try { |
1168 | - foreach($parts as $n => $name) |
|
1167 | + foreach ($parts as $n => $name) |
|
1169 | 1168 | { |
1170 | 1169 | if ($n == 0) |
1171 | 1170 | { |
1172 | - $query = (int) ($path != '/'); // / always has fs_id == 1, no need to query it ($path=='/' needs fs_dir=0!) |
|
1171 | + $query = (int)($path != '/'); // / always has fs_id == 1, no need to query it ($path=='/' needs fs_dir=0!) |
|
1173 | 1172 | } |
1174 | - elseif ($n < count($parts)-1) |
|
1173 | + elseif ($n < count($parts) - 1) |
|
1175 | 1174 | { |
1176 | 1175 | // MySQL 5.0 has a nesting limit for subqueries |
1177 | 1176 | // --> we replace the so far cumulated subqueries with their result |
1178 | 1177 | // no idea about the other DBMS, but this does NOT hurt ... |
1179 | 1178 | // --> depth limit of subqueries is now dynamicly decremented in catch |
1180 | - if ($n > 1 && !(($n-1) % $max_subquery_depth) && !($query = self::$pdo->query($query)->fetchColumn())) |
|
1179 | + if ($n > 1 && !(($n - 1) % $max_subquery_depth) && !($query = self::$pdo->query($query)->fetchColumn())) |
|
1181 | 1180 | { |
1182 | 1181 | if (self::LOG_LEVEL > 1) |
1183 | 1182 | { |
@@ -1204,7 +1203,7 @@ discard block |
||
1204 | 1203 | } |
1205 | 1204 | else |
1206 | 1205 | { |
1207 | - $query = str_replace('fs_name'.self::$case_sensitive_equal.'?','fs_name'.self::$case_sensitive_equal.self::$pdo->quote($name),$base_query).'('.$query.')'; |
|
1206 | + $query = str_replace('fs_name'.self::$case_sensitive_equal.'?', 'fs_name'.self::$case_sensitive_equal.self::$pdo->quote($name), $base_query).'('.$query.')'; |
|
1208 | 1207 | } |
1209 | 1208 | } |
1210 | 1209 | if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__."($url,$flags) eacl_access=$eacl_access".' */ '.$query; |
@@ -1230,7 +1229,7 @@ discard block |
||
1230 | 1229 | $GLOBALS['egw_info']['server']['max_subquery_depth'] = --$max_subquery_depth; |
1231 | 1230 | error_log(__METHOD__."() decremented max_subquery_depth to $max_subquery_depth"); |
1232 | 1231 | Api\Config::save_value('max_subquery_depth', $max_subquery_depth, 'phpgwapi'); |
1233 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache(); |
|
1232 | + if (method_exists($GLOBALS['egw'], 'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache(); |
|
1234 | 1233 | return $this->url_stat($url, $flags); |
1235 | 1234 | } |
1236 | 1235 | self::$stat_cache[$path] = $info; |
@@ -1246,18 +1245,18 @@ discard block |
||
1246 | 1245 | */ |
1247 | 1246 | protected static function _sql_readable() |
1248 | 1247 | { |
1249 | - static $sql_read_acl=null; |
|
1248 | + static $sql_read_acl = null; |
|
1250 | 1249 | |
1251 | 1250 | if (is_null($sql_read_acl)) |
1252 | 1251 | { |
1253 | - foreach($GLOBALS['egw']->accounts->memberships(Vfs::$user,true) as $gid) |
|
1252 | + foreach ($GLOBALS['egw']->accounts->memberships(Vfs::$user, true) as $gid) |
|
1254 | 1253 | { |
1255 | - $memberships[] = abs($gid); // sqlfs stores the gid's positiv |
|
1254 | + $memberships[] = abs($gid); // sqlfs stores the gid's positiv |
|
1256 | 1255 | } |
1257 | 1256 | // using octal numbers with mysql leads to funny results (select 384 & 0400 --> 384 not 256=0400) |
1258 | 1257 | // 256 = 0400, 32 = 040 |
1259 | 1258 | $sql_read_acl = '((fs_mode & 4)=4 OR (fs_mode & 256)=256 AND fs_uid='.(int)Vfs::$user. |
1260 | - ($memberships ? ' OR (fs_mode & 32)=32 AND fs_gid IN('.implode(',',$memberships).')' : '').')'; |
|
1259 | + ($memberships ? ' OR (fs_mode & 32)=32 AND fs_gid IN('.implode(',', $memberships).')' : '').')'; |
|
1261 | 1260 | //error_log(__METHOD__."() Vfs::\$user=".array2string(Vfs::$user).' --> memberships='.array2string($memberships).' --> '.$sql_read_acl.($memberships?'':': '.function_backtrace())); |
1262 | 1261 | } |
1263 | 1262 | return $sql_read_acl; |
@@ -1270,7 +1269,7 @@ discard block |
||
1270 | 1269 | * |
1271 | 1270 | * @return string |
1272 | 1271 | */ |
1273 | - function dir_readdir ( ) |
|
1272 | + function dir_readdir( ) |
|
1274 | 1273 | { |
1275 | 1274 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )"); |
1276 | 1275 | |
@@ -1289,7 +1288,7 @@ discard block |
||
1289 | 1288 | * |
1290 | 1289 | * @return boolean |
1291 | 1290 | */ |
1292 | - function dir_rewinddir ( ) |
|
1291 | + function dir_rewinddir( ) |
|
1293 | 1292 | { |
1294 | 1293 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )"); |
1295 | 1294 | |
@@ -1307,7 +1306,7 @@ discard block |
||
1307 | 1306 | * |
1308 | 1307 | * @return boolean |
1309 | 1308 | */ |
1310 | - function dir_closedir ( ) |
|
1309 | + function dir_closedir( ) |
|
1311 | 1310 | { |
1312 | 1311 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )"); |
1313 | 1312 | |
@@ -1329,7 +1328,7 @@ discard block |
||
1329 | 1328 | static function readlink($path) |
1330 | 1329 | { |
1331 | 1330 | $vfs = new self(); |
1332 | - $link = !($lstat = $vfs->url_stat($path,STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink']; |
|
1331 | + $link = !($lstat = $vfs->url_stat($path, STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink']; |
|
1333 | 1332 | |
1334 | 1333 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = $link"); |
1335 | 1334 | |
@@ -1343,32 +1342,32 @@ discard block |
||
1343 | 1342 | * @param string $link |
1344 | 1343 | * @return boolean true on success false on error |
1345 | 1344 | */ |
1346 | - static function symlink($target,$link) |
|
1345 | + static function symlink($target, $link) |
|
1347 | 1346 | { |
1348 | 1347 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$target','$link')"); |
1349 | 1348 | |
1350 | 1349 | $inst = new static(); |
1351 | - if ($inst->url_stat($link,0)) |
|
1350 | + if ($inst->url_stat($link, 0)) |
|
1352 | 1351 | { |
1353 | 1352 | if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') $link exists, returning false!"); |
1354 | - return false; // $link already exists |
|
1353 | + return false; // $link already exists |
|
1355 | 1354 | } |
1356 | 1355 | if (!($dir = Vfs::dirname($link)) || |
1357 | - !Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=$inst->url_stat($dir,0))) |
|
1356 | + !Vfs::check_access($dir, Vfs::WRITABLE, $dir_stat = $inst->url_stat($dir, 0))) |
|
1358 | 1357 | { |
1359 | 1358 | if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') returning false! (!is_writable('$dir'), dir_stat=".array2string($dir_stat).")"); |
1360 | - return false; // parent dir does not exist or is not writable |
|
1359 | + return false; // parent dir does not exist or is not writable |
|
1361 | 1360 | } |
1362 | 1361 | $query = 'INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_created,fs_modified,fs_creator,fs_mime,fs_size,fs_link'. |
1363 | 1362 | ') VALUES (:fs_name,:fs_dir,:fs_mode,:fs_uid,:fs_gid,:fs_created,:fs_modified,:fs_creator,:fs_mime,:fs_size,:fs_link)'; |
1364 | 1363 | if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
1365 | 1364 | $stmt = self::$pdo->prepare($query); |
1366 | - unset(self::$stat_cache[Vfs::parse_url($link,PHP_URL_PATH)]); |
|
1365 | + unset(self::$stat_cache[Vfs::parse_url($link, PHP_URL_PATH)]); |
|
1367 | 1366 | |
1368 | 1367 | return !!$stmt->execute(array( |
1369 | 1368 | 'fs_name' => self::limit_filename(Vfs::basename($link)), |
1370 | 1369 | 'fs_dir' => $dir_stat['ino'], |
1371 | - 'fs_mode' => ($dir_stat['mode'] & 0666), |
|
1370 | + 'fs_mode' => ($dir_stat['mode']&0666), |
|
1372 | 1371 | 'fs_uid' => $dir_stat['uid'] ? $dir_stat['uid'] : Vfs::$user, |
1373 | 1372 | 'fs_gid' => $dir_stat['gid'], |
1374 | 1373 | 'fs_created' => self::_pdo_timestamp(time()), |
@@ -1392,24 +1391,24 @@ discard block |
||
1392 | 1391 | * @param int $check mode to check: one or more or'ed together of: 4 = read, 2 = write, 1 = executable |
1393 | 1392 | * @return boolean |
1394 | 1393 | */ |
1395 | - static function check_extended_acl($url,$check) |
|
1394 | + static function check_extended_acl($url, $check) |
|
1396 | 1395 | { |
1397 | - $url_path = Vfs::parse_url($url,PHP_URL_PATH); |
|
1396 | + $url_path = Vfs::parse_url($url, PHP_URL_PATH); |
|
1398 | 1397 | |
1399 | 1398 | if (is_null(self::$extended_acl)) |
1400 | 1399 | { |
1401 | 1400 | self::_read_extended_acl(); |
1402 | 1401 | } |
1403 | 1402 | $access = false; |
1404 | - foreach(self::$extended_acl as $path => $rights) |
|
1403 | + foreach (self::$extended_acl as $path => $rights) |
|
1405 | 1404 | { |
1406 | - if ($path == $url_path || substr($url_path,0,strlen($path)+1) == $path.'/') |
|
1405 | + if ($path == $url_path || substr($url_path, 0, strlen($path) + 1) == $path.'/') |
|
1407 | 1406 | { |
1408 | - $access = ($rights & $check) == $check; |
|
1407 | + $access = ($rights&$check) == $check; |
|
1409 | 1408 | break; |
1410 | 1409 | } |
1411 | 1410 | } |
1412 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$check) ".($access?"access granted by $path=$rights":'no access!!!')); |
|
1411 | + if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$check) ".($access ? "access granted by $path=$rights" : 'no access!!!')); |
|
1413 | 1412 | return $access; |
1414 | 1413 | } |
1415 | 1414 | |
@@ -1421,14 +1420,14 @@ discard block |
||
1421 | 1420 | { |
1422 | 1421 | if ((self::$extended_acl = Api\Cache::getSession(self::EACL_APPNAME, 'extended_acl'))) |
1423 | 1422 | { |
1424 | - return; // ext. ACL read from session. |
|
1423 | + return; // ext. ACL read from session. |
|
1425 | 1424 | } |
1426 | 1425 | self::$extended_acl = array(); |
1427 | - if (($rights = $GLOBALS['egw']->acl->get_all_location_rights(Vfs::$user,self::EACL_APPNAME))) |
|
1426 | + if (($rights = $GLOBALS['egw']->acl->get_all_location_rights(Vfs::$user, self::EACL_APPNAME))) |
|
1428 | 1427 | { |
1429 | 1428 | $pathes = self::id2path(array_keys($rights)); |
1430 | 1429 | } |
1431 | - foreach($rights as $fs_id => $right) |
|
1430 | + foreach ($rights as $fs_id => $right) |
|
1432 | 1431 | { |
1433 | 1432 | $path = $pathes[$fs_id]; |
1434 | 1433 | if (isset($path)) |
@@ -1437,8 +1436,8 @@ discard block |
||
1437 | 1436 | } |
1438 | 1437 | } |
1439 | 1438 | // sort by length descending, to allow more specific pathes to have precedence |
1440 | - uksort(self::$extended_acl, function($a,$b) { |
|
1441 | - return strlen($b)-strlen($a); |
|
1439 | + uksort(self::$extended_acl, function($a, $b) { |
|
1440 | + return strlen($b) - strlen($a); |
|
1442 | 1441 | }); |
1443 | 1442 | Api\Cache::setSession(self::EACL_APPNAME, 'extended_acl', self::$extended_acl); |
1444 | 1443 | if (self::LOG_LEVEL > 1) error_log(__METHOD__.'() '.array2string(self::$extended_acl)); |
@@ -1460,24 +1459,24 @@ discard block |
||
1460 | 1459 | * @param int $fs_id =null fs_id to use, to not query it again (eg. because it's already deleted) |
1461 | 1460 | * @return boolean true if acl is set/deleted, false on error |
1462 | 1461 | */ |
1463 | - static function eacl($path,$rights=null,$owner=null,$fs_id=null) |
|
1462 | + static function eacl($path, $rights = null, $owner = null, $fs_id = null) |
|
1464 | 1463 | { |
1465 | 1464 | if ($path[0] != '/') |
1466 | 1465 | { |
1467 | - $path = Vfs::parse_url($path,PHP_URL_PATH); |
|
1466 | + $path = Vfs::parse_url($path, PHP_URL_PATH); |
|
1468 | 1467 | } |
1469 | 1468 | if (is_null($fs_id)) |
1470 | 1469 | { |
1471 | 1470 | $vfs = new self(); |
1472 | - if (!($stat = $vfs->url_stat($path,0))) |
|
1471 | + if (!($stat = $vfs->url_stat($path, 0))) |
|
1473 | 1472 | { |
1474 | 1473 | if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!"); |
1475 | - return false; // $path not found |
|
1474 | + return false; // $path not found |
|
1476 | 1475 | } |
1477 | - if (!Vfs::has_owner_rights($path,$stat)) // not group dir and user is eGW admin |
|
1476 | + if (!Vfs::has_owner_rights($path, $stat)) // not group dir and user is eGW admin |
|
1478 | 1477 | { |
1479 | 1478 | if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) permission denied!"); |
1480 | - return false; // permission denied |
|
1479 | + return false; // permission denied |
|
1481 | 1480 | } |
1482 | 1481 | $fs_id = $stat['ino']; |
1483 | 1482 | } |
@@ -1489,16 +1488,16 @@ discard block |
||
1489 | 1488 | { |
1490 | 1489 | // delete eacl |
1491 | 1490 | if (is_null($owner) || $owner == Vfs::$user || |
1492 | - $owner < 0 && Vfs::$user && in_array($owner,$GLOBALS['egw']->accounts->memberships(Vfs::$user,true))) |
|
1491 | + $owner < 0 && Vfs::$user && in_array($owner, $GLOBALS['egw']->accounts->memberships(Vfs::$user, true))) |
|
1493 | 1492 | { |
1494 | - self::$extended_acl = null; // force new read of eACL, as there could be multiple eACL for that path |
|
1493 | + self::$extended_acl = null; // force new read of eACL, as there could be multiple eACL for that path |
|
1495 | 1494 | } |
1496 | 1495 | $ret = $GLOBALS['egw']->acl->delete_repository(self::EACL_APPNAME, $fs_id, (int)$owner, false); |
1497 | 1496 | } |
1498 | 1497 | else |
1499 | 1498 | { |
1500 | 1499 | if (isset(self::$extended_acl) && ($owner == Vfs::$user || |
1501 | - $owner < 0 && Vfs::$user && in_array($owner,$GLOBALS['egw']->accounts->memberships(Vfs::$user,true)))) |
|
1500 | + $owner < 0 && Vfs::$user && in_array($owner, $GLOBALS['egw']->accounts->memberships(Vfs::$user, true)))) |
|
1502 | 1501 | { |
1503 | 1502 | // set rights for this class, if applicable |
1504 | 1503 | self::$extended_acl[$path] |= $rights; |
@@ -1527,10 +1526,10 @@ discard block |
||
1527 | 1526 | if (!($stat = $inst->url_stat($path, STREAM_URL_STAT_QUIET))) |
1528 | 1527 | { |
1529 | 1528 | error_log(__METHOD__.__LINE__.' '.array2string($path).' not found!'); |
1530 | - return false; // not found |
|
1529 | + return false; // not found |
|
1531 | 1530 | } |
1532 | 1531 | $eacls = array(); |
1533 | - foreach($GLOBALS['egw']->acl->get_all_rights($stat['ino'],self::EACL_APPNAME) as $owner => $rights) |
|
1532 | + foreach ($GLOBALS['egw']->acl->get_all_rights($stat['ino'], self::EACL_APPNAME) as $owner => $rights) |
|
1534 | 1533 | { |
1535 | 1534 | $eacls[] = array( |
1536 | 1535 | 'path' => $path, |
@@ -1541,7 +1540,7 @@ discard block |
||
1541 | 1540 | } |
1542 | 1541 | if (($path = Vfs::dirname($path))) |
1543 | 1542 | { |
1544 | - $eacls = array_merge((array)self::get_eacl($path),$eacls); |
|
1543 | + $eacls = array_merge((array)self::get_eacl($path), $eacls); |
|
1545 | 1544 | } |
1546 | 1545 | // sort by length descending, to show precedence |
1547 | 1546 | usort($eacls, function($a, $b) { |
@@ -1560,7 +1559,7 @@ discard block |
||
1560 | 1559 | static function get_minimum_file_id($path) |
1561 | 1560 | { |
1562 | 1561 | $vfs = new self(); |
1563 | - $stat = $vfs->url_stat($path,0); |
|
1562 | + $stat = $vfs->url_stat($path, 0); |
|
1564 | 1563 | if ($stat['readlink']) |
1565 | 1564 | { |
1566 | 1565 | $stat = $vfs->url_stat($stat['readlink'], 0); |
@@ -1600,7 +1599,7 @@ discard block |
||
1600 | 1599 | * @param int $recursion_count =0 internally used to break infinit recursions |
1601 | 1600 | * @return false|string|array path or array or pathes indexed by fs_id, or false on error |
1602 | 1601 | */ |
1603 | - static function id2path($fs_ids, $recursion_count=0) |
|
1602 | + static function id2path($fs_ids, $recursion_count = 0) |
|
1604 | 1603 | { |
1605 | 1604 | if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')'); |
1606 | 1605 | if ($recursion_count > self::MAX_ID2PATH_RECURSION) |
@@ -1611,9 +1610,9 @@ discard block |
||
1611 | 1610 | $ids = (array)$fs_ids; |
1612 | 1611 | $pathes = array(); |
1613 | 1612 | // first check our stat-cache for the ids |
1614 | - foreach(self::$stat_cache as $path => $stat) |
|
1613 | + foreach (self::$stat_cache as $path => $stat) |
|
1615 | 1614 | { |
1616 | - if (($key = array_search($stat['fs_id'],$ids)) !== false) |
|
1615 | + if (($key = array_search($stat['fs_id'], $ids)) !== false) |
|
1617 | 1616 | { |
1618 | 1617 | $pathes[$stat['fs_id']] = $path; |
1619 | 1618 | unset($ids[$key]); |
@@ -1627,7 +1626,7 @@ discard block |
||
1627 | 1626 | // now search via the database |
1628 | 1627 | if (count($ids) > 1) $ids = array_map(function($v) { return (int)$v; }, $ids); |
1629 | 1628 | $query = 'SELECT fs_id,fs_dir,fs_name FROM '.self::TABLE.' WHERE fs_id'. |
1630 | - (count($ids) == 1 ? '='.(int)$ids[0] : ' IN ('.implode(',',$ids).')'); |
|
1629 | + (count($ids) == 1 ? '='.(int)$ids[0] : ' IN ('.implode(',', $ids).')'); |
|
1631 | 1630 | if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
1632 | 1631 | |
1633 | 1632 | if (!is_object(self::$pdo)) |
@@ -1638,12 +1637,12 @@ discard block |
||
1638 | 1637 | $stmt->setFetchMode(\PDO::FETCH_ASSOC); |
1639 | 1638 | if (!$stmt->execute()) |
1640 | 1639 | { |
1641 | - return false; // not found |
|
1640 | + return false; // not found |
|
1642 | 1641 | } |
1643 | 1642 | $parents = array(); |
1644 | - foreach($stmt as $row) |
|
1643 | + foreach ($stmt as $row) |
|
1645 | 1644 | { |
1646 | - if ($row['fs_dir'] > 1 && !in_array($row['fs_dir'],$parents)) |
|
1645 | + if ($row['fs_dir'] > 1 && !in_array($row['fs_dir'], $parents)) |
|
1647 | 1646 | { |
1648 | 1647 | $parents[] = $row['fs_dir']; |
1649 | 1648 | } |
@@ -1651,16 +1650,16 @@ discard block |
||
1651 | 1650 | } |
1652 | 1651 | unset($stmt); |
1653 | 1652 | |
1654 | - if ($parents && !($parents = self::id2path($parents, $recursion_count+1))) |
|
1653 | + if ($parents && !($parents = self::id2path($parents, $recursion_count + 1))) |
|
1655 | 1654 | { |
1656 | - return false; // parent not found, should never happen ... |
|
1655 | + return false; // parent not found, should never happen ... |
|
1657 | 1656 | } |
1658 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__." trying foreach with:".print_r($rows,true)."#"); |
|
1659 | - foreach((array)$rows as $fs_id => $row) |
|
1657 | + if (self::LOG_LEVEL > 1) error_log(__METHOD__." trying foreach with:".print_r($rows, true)."#"); |
|
1658 | + foreach ((array)$rows as $fs_id => $row) |
|
1660 | 1659 | { |
1661 | 1660 | $parent = $row['fs_dir'] > 1 ? $parents[$row['fs_dir']] : ''; |
1662 | 1661 | |
1663 | - $pathes[$fs_id] = $parent . '/' . $row['fs_name']; |
|
1662 | + $pathes[$fs_id] = $parent.'/'.$row['fs_name']; |
|
1664 | 1663 | } |
1665 | 1664 | if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes)); |
1666 | 1665 | return is_array($fs_ids) ? $pathes : array_shift($pathes); |
@@ -1684,7 +1683,7 @@ discard block |
||
1684 | 1683 | $parts = explode('.', $name); |
1685 | 1684 | if ($parts > 1 && mb_strlen($extension = '.'.array_pop($parts)) <= $fs_name_precision) |
1686 | 1685 | { |
1687 | - $name = mb_substr(implode('.', $parts), 0, $fs_name_precision-mb_strlen($extension)).$extension; |
|
1686 | + $name = mb_substr(implode('.', $parts), 0, $fs_name_precision - mb_strlen($extension)).$extension; |
|
1688 | 1687 | } |
1689 | 1688 | else |
1690 | 1689 | { |
@@ -1705,9 +1704,8 @@ discard block |
||
1705 | 1704 | $stat = array( |
1706 | 1705 | 'ino' => $info['fs_id'], |
1707 | 1706 | 'name' => $info['fs_name'], |
1708 | - 'mode' => $info['fs_mode'] | |
|
1709 | - ($info['fs_mime'] == self::DIR_MIME_TYPE ? self::MODE_DIR : |
|
1710 | - ($info['fs_mime'] == self::SYMLINK_MIME_TYPE ? self::MODE_LINK : self::MODE_FILE)), // required by the stream wrapper |
|
1707 | + 'mode' => $info['fs_mode']| |
|
1708 | + ($info['fs_mime'] == self::DIR_MIME_TYPE ? self::MODE_DIR : ($info['fs_mime'] == self::SYMLINK_MIME_TYPE ? self::MODE_LINK : self::MODE_FILE)), // required by the stream wrapper |
|
1711 | 1709 | 'size' => $info['fs_size'], |
1712 | 1710 | 'uid' => $info['fs_uid'], |
1713 | 1711 | 'gid' => $info['fs_gid'], |
@@ -1752,10 +1750,10 @@ discard block |
||
1752 | 1750 | { |
1753 | 1751 | if (is_object($GLOBALS['egw_setup']->db)) // if we run under setup, query the db for the files dir |
1754 | 1752 | { |
1755 | - $GLOBALS['egw_info']['server']['files_dir'] = $GLOBALS['egw_setup']->db->select('egw_config','config_value',array( |
|
1753 | + $GLOBALS['egw_info']['server']['files_dir'] = $GLOBALS['egw_setup']->db->select('egw_config', 'config_value', array( |
|
1756 | 1754 | 'config_name' => 'files_dir', |
1757 | 1755 | 'config_app' => 'phpgwapi', |
1758 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
1756 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
1759 | 1757 | } |
1760 | 1758 | } |
1761 | 1759 | if (!$GLOBALS['egw_info']['server']['files_dir']) |
@@ -1764,14 +1762,14 @@ discard block |
||
1764 | 1762 | } |
1765 | 1763 | $hash = array(); |
1766 | 1764 | $n = $id; |
1767 | - while(($n = (int) ($n / self::HASH_MAX))) |
|
1765 | + while (($n = (int)($n / self::HASH_MAX))) |
|
1768 | 1766 | { |
1769 | - $hash[] = sprintf('%02d',$n % self::HASH_MAX); |
|
1767 | + $hash[] = sprintf('%02d', $n % self::HASH_MAX); |
|
1770 | 1768 | } |
1771 | - if (!$hash) $hash[] = '00'; // we need at least one directory, to not conflict with the dir-names |
|
1772 | - array_unshift($hash,$id); |
|
1769 | + if (!$hash) $hash[] = '00'; // we need at least one directory, to not conflict with the dir-names |
|
1770 | + array_unshift($hash, $id); |
|
1773 | 1771 | |
1774 | - $path = '/sqlfs/'.implode('/',array_reverse($hash)); |
|
1772 | + $path = '/sqlfs/'.implode('/', array_reverse($hash)); |
|
1775 | 1773 | //error_log(__METHOD__."($id) = '$path'"); |
1776 | 1774 | return $GLOBALS['egw_info']['server']['files_dir'].$path; |
1777 | 1775 | } |
@@ -1787,7 +1785,7 @@ discard block |
||
1787 | 1785 | |
1788 | 1786 | if ($parts['pass'] || $parts['scheme']) |
1789 | 1787 | { |
1790 | - $url = $parts['scheme'].'://'.($parts['user'] ? $parts['user'].($parts['pass']?':...':'').'@' : ''). |
|
1788 | + $url = $parts['scheme'].'://'.($parts['user'] ? $parts['user'].($parts['pass'] ? ':...' : '').'@' : ''). |
|
1791 | 1789 | $parts['host'].$parts['path']; |
1792 | 1790 | } |
1793 | 1791 | } |
@@ -1802,10 +1800,10 @@ discard block |
||
1802 | 1800 | { |
1803 | 1801 | $operation = self::DEFAULT_OPERATION; |
1804 | 1802 | |
1805 | - if (strpos(is_array($url) ? $url['query'] : $url,'storage=') !== false) |
|
1803 | + if (strpos(is_array($url) ? $url['query'] : $url, 'storage=') !== false) |
|
1806 | 1804 | { |
1807 | 1805 | $query = null; |
1808 | - parse_str(is_array($url) ? $url['query'] : Vfs::parse_url($url,PHP_URL_QUERY), $query); |
|
1806 | + parse_str(is_array($url) ? $url['query'] : Vfs::parse_url($url, PHP_URL_QUERY), $query); |
|
1809 | 1807 | switch ($query['storage']) |
1810 | 1808 | { |
1811 | 1809 | case 'db': |
@@ -1828,29 +1826,29 @@ discard block |
||
1828 | 1826 | * @param array $props array of array with values for keys 'name', 'ns', 'val' (null to delete the prop) |
1829 | 1827 | * @return boolean true if props are updated, false otherwise (eg. ressource not found) |
1830 | 1828 | */ |
1831 | - static function proppatch($path,array $props) |
|
1829 | + static function proppatch($path, array $props) |
|
1832 | 1830 | { |
1833 | 1831 | static $inst = null; |
1834 | 1832 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."(".array2string($path).','.array2string($props)); |
1835 | 1833 | if (!is_numeric($path)) |
1836 | 1834 | { |
1837 | 1835 | if (!isset($inst)) $inst = new self(); |
1838 | - if (!($stat = $inst->url_stat($path,0))) |
|
1836 | + if (!($stat = $inst->url_stat($path, 0))) |
|
1839 | 1837 | { |
1840 | 1838 | return false; |
1841 | 1839 | } |
1842 | 1840 | $id = $stat['ino']; |
1843 | 1841 | } |
1844 | - elseif(!($path = self::id2path($id=$path))) |
|
1842 | + elseif (!($path = self::id2path($id = $path))) |
|
1845 | 1843 | { |
1846 | 1844 | return false; |
1847 | 1845 | } |
1848 | - if (!Vfs::check_access($path,Api\Acl::EDIT,$stat)) |
|
1846 | + if (!Vfs::check_access($path, Api\Acl::EDIT, $stat)) |
|
1849 | 1847 | { |
1850 | - return false; // permission denied |
|
1848 | + return false; // permission denied |
|
1851 | 1849 | } |
1852 | 1850 | $ins_stmt = $del_stmt = null; |
1853 | - foreach($props as &$prop) |
|
1851 | + foreach ($props as &$prop) |
|
1854 | 1852 | { |
1855 | 1853 | if (!isset($prop['ns'])) $prop['ns'] = Vfs::DEFAULT_PROP_NAMESPACE; |
1856 | 1854 | |
@@ -1895,17 +1893,17 @@ discard block |
||
1895 | 1893 | * @return array|boolean false on error ($path_ids does not exist), array with props (values for keys 'name', 'ns', 'value'), or |
1896 | 1894 | * fs_id/path => array of props for $depth==1 or is_array($path_ids) |
1897 | 1895 | */ |
1898 | - static function propfind($path_ids,$ns=Vfs::DEFAULT_PROP_NAMESPACE) |
|
1896 | + static function propfind($path_ids, $ns = Vfs::DEFAULT_PROP_NAMESPACE) |
|
1899 | 1897 | { |
1900 | 1898 | static $inst = null; |
1901 | 1899 | |
1902 | 1900 | $ids = is_array($path_ids) ? $path_ids : array($path_ids); |
1903 | - foreach($ids as &$id) |
|
1901 | + foreach ($ids as &$id) |
|
1904 | 1902 | { |
1905 | 1903 | if (!is_numeric($id)) |
1906 | 1904 | { |
1907 | 1905 | if (!isset($inst)) $inst = new self(); |
1908 | - if (!($stat = $inst->url_stat($id,0))) |
|
1906 | + if (!($stat = $inst->url_stat($id, 0))) |
|
1909 | 1907 | { |
1910 | 1908 | if (self::LOG_LEVEL) error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!"); |
1911 | 1909 | return false; |
@@ -1915,7 +1913,7 @@ discard block |
||
1915 | 1913 | } |
1916 | 1914 | if (count($ids) >= 1) $ids = array_map(function($v) { return (int)$v; }, $ids); |
1917 | 1915 | $query = 'SELECT * FROM '.self::PROPS_TABLE.' WHERE (fs_id'. |
1918 | - (count($ids) == 1 ? '='.(int)implode('',$ids) : ' IN ('.implode(',',$ids).')').')'. |
|
1916 | + (count($ids) == 1 ? '='.(int)implode('', $ids) : ' IN ('.implode(',', $ids).')').')'. |
|
1919 | 1917 | (!is_null($ns) ? ' AND prop_namespace=?' : ''); |
1920 | 1918 | if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
1921 | 1919 | |
@@ -1924,7 +1922,7 @@ discard block |
||
1924 | 1922 | $stmt->execute(!is_null($ns) ? array($ns) : array()); |
1925 | 1923 | |
1926 | 1924 | $props = array(); |
1927 | - foreach($stmt as $row) |
|
1925 | + foreach ($stmt as $row) |
|
1928 | 1926 | { |
1929 | 1927 | $props[$row['fs_id']][] = array( |
1930 | 1928 | 'val' => $row['prop_value'], |
@@ -1934,19 +1932,19 @@ discard block |
||
1934 | 1932 | } |
1935 | 1933 | if (!is_array($path_ids)) |
1936 | 1934 | { |
1937 | - $props = $props[$row['fs_id']] ? $props[$row['fs_id']] : array(); // return empty array for no props |
|
1935 | + $props = $props[$row['fs_id']] ? $props[$row['fs_id']] : array(); // return empty array for no props |
|
1938 | 1936 | } |
1939 | 1937 | elseif ($props && isset($stat) && is_array($id2path = self::id2path(array_keys($props)))) // need to map fs_id's to pathes |
1940 | 1938 | { |
1941 | - foreach($id2path as $id => $path) |
|
1939 | + foreach ($id2path as $id => $path) |
|
1942 | 1940 | { |
1943 | - $props[$path] =& $props[$id]; |
|
1941 | + $props[$path] = & $props[$id]; |
|
1944 | 1942 | unset($props[$id]); |
1945 | 1943 | } |
1946 | 1944 | } |
1947 | 1945 | if (self::LOG_LEVEL > 1) |
1948 | 1946 | { |
1949 | - foreach((array)$props as $k => $v) |
|
1947 | + foreach ((array)$props as $k => $v) |
|
1950 | 1948 | { |
1951 | 1949 | error_log(__METHOD__."($path_ids,$ns) $k => ".array2string($v)); |
1952 | 1950 | } |
@@ -193,7 +193,10 @@ discard block |
||
193 | 193 | */ |
194 | 194 | function stream_open ($url, $mode, $options, &$opened_path) |
195 | 195 | { |
196 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)"); |
|
196 | + if (self::LOG_LEVEL > 1) |
|
197 | + { |
|
198 | + error_log(__METHOD__."($url,$mode,$options)"); |
|
199 | + } |
|
197 | 200 | |
198 | 201 | $path = Vfs::parse_url($url,PHP_URL_PATH); |
199 | 202 | $this->operation = self::url2operation($url); |
@@ -205,7 +208,9 @@ discard block |
||
205 | 208 | |
206 | 209 | parse_str(parse_url($url, PHP_URL_QUERY), $this->dir_url_params); |
207 | 210 | |
208 | - if (!is_null($this->overwrite_new) || !($stat = $this->url_stat($path,STREAM_URL_STAT_QUIET)) || $mode[0] == 'x') // file not found or file should NOT exist |
|
211 | + if (!is_null($this->overwrite_new) || !($stat = $this->url_stat($path,STREAM_URL_STAT_QUIET)) || $mode[0] == 'x') |
|
212 | + { |
|
213 | + // file not found or file should NOT exist |
|
209 | 214 | { |
210 | 215 | if (!$dir || $mode[0] == 'r' || // does $mode require the file to exist (r,r+) |
211 | 216 | $mode[0] == 'x' && $stat || // or file should not exist, but does |
@@ -213,7 +218,11 @@ discard block |
||
213 | 218 | !Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat)) // or we are not allowed to create it |
214 | 219 | { |
215 | 220 | self::_remove_password($url); |
216 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!"); |
|
221 | + } |
|
222 | + if (self::LOG_LEVEL) |
|
223 | + { |
|
224 | + error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!"); |
|
225 | + } |
|
217 | 226 | if (($options & STREAM_REPORT_ERRORS)) |
218 | 227 | { |
219 | 228 | trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING); |
@@ -225,7 +234,10 @@ discard block |
||
225 | 234 | $new_file = true; |
226 | 235 | $query = 'INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_created,fs_modified,fs_creator,fs_mime,fs_size,fs_active'. |
227 | 236 | ') VALUES (:fs_name,:fs_dir,:fs_mode,:fs_uid,:fs_gid,:fs_created,:fs_modified,:fs_creator,:fs_mime,:fs_size,:fs_active)'; |
228 | - if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
|
237 | + if (self::LOG_LEVEL > 2) |
|
238 | + { |
|
239 | + $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
|
240 | + } |
|
229 | 241 | $stmt = self::$pdo->prepare($query); |
230 | 242 | $values = array( |
231 | 243 | 'fs_name' => self::limit_filename(Vfs::basename($path)), |
@@ -243,11 +255,17 @@ discard block |
||
243 | 255 | 'fs_size' => 0, |
244 | 256 | 'fs_active' => self::_pdo_boolean(true), |
245 | 257 | ); |
246 | - if ($this->overwrite_new) $values = array_merge($values, $this->overwrite_new); |
|
258 | + if ($this->overwrite_new) |
|
259 | + { |
|
260 | + $values = array_merge($values, $this->overwrite_new); |
|
261 | + } |
|
247 | 262 | if (!$stmt->execute($values) || !($this->opened_fs_id = self::$pdo->lastInsertId('egw_sqlfs_fs_id_seq'))) |
248 | 263 | { |
249 | 264 | $this->opened_stream = $this->opened_path = $this->opened_mode = null; |
250 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) execute() failed: ".self::$pdo->errorInfo()); |
|
265 | + if (self::LOG_LEVEL) |
|
266 | + { |
|
267 | + error_log(__METHOD__."($url,$mode,$options) execute() failed: ".self::$pdo->errorInfo()); |
|
268 | + } |
|
251 | 269 | return false; |
252 | 270 | } |
253 | 271 | if ($this->operation == self::STORE2DB) |
@@ -259,14 +277,20 @@ discard block |
||
259 | 277 | elseif(!file_exists($fs_dir=Vfs::dirname(self::_fs_path($this->opened_fs_id)))) |
260 | 278 | { |
261 | 279 | $umaskbefore = umask(); |
262 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__." about to call mkdir for $fs_dir # Present UMASK:".decoct($umaskbefore)." called from:".function_backtrace()); |
|
280 | + if (self::LOG_LEVEL > 1) |
|
281 | + { |
|
282 | + error_log(__METHOD__." about to call mkdir for $fs_dir # Present UMASK:".decoct($umaskbefore)." called from:".function_backtrace()); |
|
283 | + } |
|
263 | 284 | self::mkdir_recursive($fs_dir,0700,true); |
264 | 285 | } |
265 | 286 | } |
266 | 287 | // check if opend file is a directory |
267 | 288 | elseif($stat && ($stat['mode'] & self::MODE_DIR) == self::MODE_DIR) |
268 | 289 | { |
269 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) Is a directory!"); |
|
290 | + if (self::LOG_LEVEL) |
|
291 | + { |
|
292 | + error_log(__METHOD__."($url,$mode,$options) Is a directory!"); |
|
293 | + } |
|
270 | 294 | if (($options & STREAM_REPORT_ERRORS)) |
271 | 295 | { |
272 | 296 | trigger_error(__METHOD__."($url,$mode,$options) Is a directory!",E_USER_WARNING); |
@@ -277,11 +301,17 @@ discard block |
||
277 | 301 | else |
278 | 302 | { |
279 | 303 | if ($mode == 'r' && !Vfs::check_access($url,Vfs::READABLE ,$stat) ||// we are not allowed to read |
280 | - $mode != 'r' && !Vfs::check_access($url,Vfs::WRITABLE,$stat)) // or edit it |
|
304 | + $mode != 'r' && !Vfs::check_access($url,Vfs::WRITABLE,$stat)) |
|
305 | + { |
|
306 | + // or edit it |
|
281 | 307 | { |
282 | 308 | self::_remove_password($url); |
309 | + } |
|
283 | 310 | $op = $mode == 'r' ? 'read' : 'edited'; |
284 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be $op!"); |
|
311 | + if (self::LOG_LEVEL) |
|
312 | + { |
|
313 | + error_log(__METHOD__."($url,$mode,$options) file can not be $op!"); |
|
314 | + } |
|
285 | 315 | if (($options & STREAM_REPORT_ERRORS)) |
286 | 316 | { |
287 | 317 | trigger_error(__METHOD__."($url,$mode,$options) file can not be $op!",E_USER_WARNING); |
@@ -313,7 +343,10 @@ discard block |
||
313 | 343 | // do we operate directly on the filesystem --> open file from there |
314 | 344 | if ($this->operation == self::STORE2FS) |
315 | 345 | { |
316 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__." fopen (may create a directory? mkdir) ($this->opened_fs_id,$mode,$options)"); |
|
346 | + if (self::LOG_LEVEL > 1) |
|
347 | + { |
|
348 | + error_log(__METHOD__." fopen (may create a directory? mkdir) ($this->opened_fs_id,$mode,$options)"); |
|
349 | + } |
|
317 | 350 | if (!($this->opened_stream = fopen(self::_fs_path($this->opened_fs_id),$mode)) && $new_file) |
318 | 351 | { |
319 | 352 | // delete db entry again, if we are not able to open a new(!) file |
@@ -322,11 +355,17 @@ discard block |
||
322 | 355 | $stmt->execute(array('fs_id' => $this->opened_fs_id)); |
323 | 356 | } |
324 | 357 | } |
325 | - if ($mode[0] == 'a') // append modes: a, a+ |
|
358 | + if ($mode[0] == 'a') |
|
359 | + { |
|
360 | + // append modes: a, a+ |
|
326 | 361 | { |
327 | 362 | $this->stream_seek(0,SEEK_END); |
328 | 363 | } |
329 | - if (!is_resource($this->opened_stream)) error_log(__METHOD__."($url,$mode,$options) NO stream, returning false!"); |
|
364 | + } |
|
365 | + if (!is_resource($this->opened_stream)) |
|
366 | + { |
|
367 | + error_log(__METHOD__."($url,$mode,$options) NO stream, returning false!"); |
|
368 | + } |
|
330 | 369 | |
331 | 370 | return is_resource($this->opened_stream); |
332 | 371 | } |
@@ -338,7 +377,10 @@ discard block |
||
338 | 377 | */ |
339 | 378 | function stream_close ( ) |
340 | 379 | { |
341 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."()"); |
|
380 | + if (self::LOG_LEVEL > 1) |
|
381 | + { |
|
382 | + error_log(__METHOD__."()"); |
|
383 | + } |
|
342 | 384 | |
343 | 385 | if (is_null($this->opened_path) || !is_resource($this->opened_stream) || !$this->opened_fs_id) |
344 | 386 | { |
@@ -408,7 +450,10 @@ discard block |
||
408 | 450 | */ |
409 | 451 | function stream_read ( $count ) |
410 | 452 | { |
411 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($count) pos=$this->opened_pos"); |
|
453 | + if (self::LOG_LEVEL > 1) |
|
454 | + { |
|
455 | + error_log(__METHOD__."($count) pos=$this->opened_pos"); |
|
456 | + } |
|
412 | 457 | |
413 | 458 | if (is_resource($this->opened_stream)) |
414 | 459 | { |
@@ -430,7 +475,10 @@ discard block |
||
430 | 475 | */ |
431 | 476 | function stream_write ( $data ) |
432 | 477 | { |
433 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($data)"); |
|
478 | + if (self::LOG_LEVEL > 1) |
|
479 | + { |
|
480 | + error_log(__METHOD__."($data)"); |
|
481 | + } |
|
434 | 482 | |
435 | 483 | if (is_resource($this->opened_stream)) |
436 | 484 | { |
@@ -467,7 +515,10 @@ discard block |
||
467 | 515 | */ |
468 | 516 | function stream_tell ( ) |
469 | 517 | { |
470 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."()"); |
|
518 | + if (self::LOG_LEVEL > 1) |
|
519 | + { |
|
520 | + error_log(__METHOD__."()"); |
|
521 | + } |
|
471 | 522 | |
472 | 523 | if (is_resource($this->opened_stream)) |
473 | 524 | { |
@@ -490,7 +541,10 @@ discard block |
||
490 | 541 | */ |
491 | 542 | function stream_seek ( $offset, $whence ) |
492 | 543 | { |
493 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($offset,$whence)"); |
|
544 | + if (self::LOG_LEVEL > 1) |
|
545 | + { |
|
546 | + error_log(__METHOD__."($offset,$whence)"); |
|
547 | + } |
|
494 | 548 | |
495 | 549 | if (is_resource($this->opened_stream)) |
496 | 550 | { |
@@ -508,7 +562,10 @@ discard block |
||
508 | 562 | */ |
509 | 563 | function stream_flush ( ) |
510 | 564 | { |
511 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."()"); |
|
565 | + if (self::LOG_LEVEL > 1) |
|
566 | + { |
|
567 | + error_log(__METHOD__."()"); |
|
568 | + } |
|
512 | 569 | |
513 | 570 | if (is_resource($this->opened_stream)) |
514 | 571 | { |
@@ -533,7 +590,10 @@ discard block |
||
533 | 590 | */ |
534 | 591 | function stream_stat ( ) |
535 | 592 | { |
536 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($this->opened_path)"); |
|
593 | + if (self::LOG_LEVEL > 1) |
|
594 | + { |
|
595 | + error_log(__METHOD__."($this->opened_path)"); |
|
596 | + } |
|
537 | 597 | |
538 | 598 | return $this->url_stat($this->opened_path,0); |
539 | 599 | } |
@@ -549,7 +609,10 @@ discard block |
||
549 | 609 | */ |
550 | 610 | function unlink ( $url ) |
551 | 611 | { |
552 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)"); |
|
612 | + if (self::LOG_LEVEL > 1) |
|
613 | + { |
|
614 | + error_log(__METHOD__."($url)"); |
|
615 | + } |
|
553 | 616 | |
554 | 617 | $path = Vfs::parse_url($url,PHP_URL_PATH); |
555 | 618 | |
@@ -561,13 +624,19 @@ discard block |
||
561 | 624 | !$dir || !Vfs::check_access($dir, Vfs::WRITABLE, $parent_stat)) |
562 | 625 | { |
563 | 626 | self::_remove_password($url); |
564 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!"); |
|
627 | + if (self::LOG_LEVEL) |
|
628 | + { |
|
629 | + error_log(__METHOD__."($url) permission denied!"); |
|
630 | + } |
|
565 | 631 | return false; // no permission or file does not exist |
566 | 632 | } |
567 | 633 | if ($stat['mime'] == self::DIR_MIME_TYPE) |
568 | 634 | { |
569 | 635 | self::_remove_password($url); |
570 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url) is NO file!"); |
|
636 | + if (self::LOG_LEVEL) |
|
637 | + { |
|
638 | + error_log(__METHOD__."($url) is NO file!"); |
|
639 | + } |
|
571 | 640 | return false; // no permission or file does not exist |
572 | 641 | } |
573 | 642 | $stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=:fs_id'); |
@@ -602,7 +671,10 @@ discard block |
||
602 | 671 | */ |
603 | 672 | function rename ( $url_from, $url_to) |
604 | 673 | { |
605 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url_from,$url_to)"); |
|
674 | + if (self::LOG_LEVEL > 1) |
|
675 | + { |
|
676 | + error_log(__METHOD__."($url_from,$url_to)"); |
|
677 | + } |
|
606 | 678 | |
607 | 679 | $path_from = Vfs::parse_url($url_from,PHP_URL_PATH); |
608 | 680 | $from_dir = Vfs::dirname($path_from); |
@@ -614,14 +686,20 @@ discard block |
||
614 | 686 | { |
615 | 687 | self::_remove_password($url_from); |
616 | 688 | self::_remove_password($url_to); |
617 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_from permission denied!"); |
|
689 | + if (self::LOG_LEVEL) |
|
690 | + { |
|
691 | + error_log(__METHOD__."($url_from,$url_to): $path_from permission denied!"); |
|
692 | + } |
|
618 | 693 | return false; // no permission or file does not exist |
619 | 694 | } |
620 | 695 | if (!$to_dir || !Vfs::check_access($to_dir, Vfs::WRITABLE, $to_dir_stat = $this->url_stat($to_dir, 0))) |
621 | 696 | { |
622 | 697 | self::_remove_password($url_from); |
623 | 698 | self::_remove_password($url_to); |
624 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_to permission denied!"); |
|
699 | + if (self::LOG_LEVEL) |
|
700 | + { |
|
701 | + error_log(__METHOD__."($url_from,$url_to): $path_to permission denied!"); |
|
702 | + } |
|
625 | 703 | return false; // no permission or parent-dir does not exist |
626 | 704 | } |
627 | 705 | // the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems |
@@ -632,14 +710,20 @@ discard block |
||
632 | 710 | self::_remove_password($url_from); |
633 | 711 | self::_remove_password($url_to); |
634 | 712 | $is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no'; |
635 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $path_to is $is_dir directory!"); |
|
713 | + if (self::LOG_LEVEL) |
|
714 | + { |
|
715 | + error_log(__METHOD__."($url_to,$url_from) $path_to is $is_dir directory!"); |
|
716 | + } |
|
636 | 717 | return false; // no permission or file does not exist |
637 | 718 | } |
638 | 719 | // if destination file already exists, delete it |
639 | 720 | if ($to_stat && !$this->unlink($url_to)) |
640 | 721 | { |
641 | 722 | self::_remove_password($url_to); |
642 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!"); |
|
723 | + if (self::LOG_LEVEL) |
|
724 | + { |
|
725 | + error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!"); |
|
726 | + } |
|
643 | 727 | return false; |
644 | 728 | } |
645 | 729 | unset(self::$stat_cache[$path_from]); |
@@ -677,7 +761,10 @@ discard block |
||
677 | 761 | { |
678 | 762 | $maxdepth=10; |
679 | 763 | $depth2propagate = (int)$depth + 1; |
680 | - if ($depth2propagate > $maxdepth) return is_dir($pathname); |
|
764 | + if ($depth2propagate > $maxdepth) |
|
765 | + { |
|
766 | + return is_dir($pathname); |
|
767 | + } |
|
681 | 768 | is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate); |
682 | 769 | return is_dir($pathname) || @mkdir($pathname, $mode); |
683 | 770 | } |
@@ -695,14 +782,23 @@ discard block |
||
695 | 782 | */ |
696 | 783 | function mkdir ( $url, $mode, $options ) |
697 | 784 | { |
698 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)"); |
|
699 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__." called from:".function_backtrace()); |
|
785 | + if (self::LOG_LEVEL > 1) |
|
786 | + { |
|
787 | + error_log(__METHOD__."($url,$mode,$options)"); |
|
788 | + } |
|
789 | + if (self::LOG_LEVEL > 1) |
|
790 | + { |
|
791 | + error_log(__METHOD__." called from:".function_backtrace()); |
|
792 | + } |
|
700 | 793 | $path = Vfs::parse_url($url,PHP_URL_PATH); |
701 | 794 | |
702 | 795 | if ($this->url_stat($path,STREAM_URL_STAT_QUIET)) |
703 | 796 | { |
704 | 797 | self::_remove_password($url); |
705 | - if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) already exist!"); |
|
798 | + if (self::LOG_LEVEL) |
|
799 | + { |
|
800 | + error_log(__METHOD__."('$url',$mode,$options) already exist!"); |
|
801 | + } |
|
706 | 802 | if (!($options & STREAM_REPORT_ERRORS)) |
707 | 803 | { |
708 | 804 | trigger_error(__METHOD__."('$url',$mode,$options) already exist!",E_USER_WARNING); |
@@ -712,21 +808,30 @@ discard block |
||
712 | 808 | if (!($parent_path = Vfs::dirname($path))) |
713 | 809 | { |
714 | 810 | self::_remove_password($url); |
715 | - if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) dirname('$path')===false!"); |
|
811 | + if (self::LOG_LEVEL) |
|
812 | + { |
|
813 | + error_log(__METHOD__."('$url',$mode,$options) dirname('$path')===false!"); |
|
814 | + } |
|
716 | 815 | if (!($options & STREAM_REPORT_ERRORS)) |
717 | 816 | { |
718 | 817 | trigger_error(__METHOD__."('$url',$mode,$options) dirname('$path')===false!", E_USER_WARNING); |
719 | 818 | } |
720 | 819 | return false; |
721 | 820 | } |
722 | - if (($query = Vfs::parse_url($url,PHP_URL_QUERY))) $parent_path .= '?'.$query; |
|
821 | + if (($query = Vfs::parse_url($url,PHP_URL_QUERY))) |
|
822 | + { |
|
823 | + $parent_path .= '?'.$query; |
|
824 | + } |
|
723 | 825 | $parent = $this->url_stat($parent_path,STREAM_URL_STAT_QUIET); |
724 | 826 | |
725 | 827 | // check if we should also create all non-existing path components and our parent does not exist, |
726 | 828 | // if yes call ourself recursive with the parent directory |
727 | 829 | if (($options & STREAM_MKDIR_RECURSIVE) && $parent_path != '/' && !$parent) |
728 | 830 | { |
729 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__." creating parents: $parent_path, $mode"); |
|
831 | + if (self::LOG_LEVEL > 1) |
|
832 | + { |
|
833 | + error_log(__METHOD__." creating parents: $parent_path, $mode"); |
|
834 | + } |
|
730 | 835 | if (!$this->mkdir($parent_path,$mode,$options)) |
731 | 836 | { |
732 | 837 | return false; |
@@ -736,7 +841,10 @@ discard block |
||
736 | 841 | if (!$parent || !Vfs::check_access($parent_path,Vfs::WRITABLE,$parent)) |
737 | 842 | { |
738 | 843 | self::_remove_password($url); |
739 | - if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) permission denied!"); |
|
844 | + if (self::LOG_LEVEL) |
|
845 | + { |
|
846 | + error_log(__METHOD__."('$url',$mode,$options) permission denied!"); |
|
847 | + } |
|
740 | 848 | if (!($options & STREAM_REPORT_ERRORS)) |
741 | 849 | { |
742 | 850 | trigger_error(__METHOD__."('$url',$mode,$options) permission denied!",E_USER_WARNING); |
@@ -770,10 +878,13 @@ discard block |
||
770 | 878 | 'fs_dir' => $parent['ino'], |
771 | 879 | 'fs_active' => self::_pdo_boolean(true), |
772 | 880 | 'fs_name' => self::limit_filename(Vfs::basename($path)), |
773 | - )) && $stmt->fetchColumn() > 1) // if there's more then one --> remove our new dir |
|
881 | + )) && $stmt->fetchColumn() > 1) |
|
882 | + { |
|
883 | + // if there's more then one --> remove our new dir |
|
774 | 884 | { |
775 | 885 | self::$pdo->query('DELETE FROM '.self::TABLE.' WHERE fs_id='.$new_fs_id); |
776 | 886 | } |
887 | + } |
|
777 | 888 | } |
778 | 889 | return $ok; |
779 | 890 | } |
@@ -790,7 +901,10 @@ discard block |
||
790 | 901 | */ |
791 | 902 | function rmdir ( $url, $options ) |
792 | 903 | { |
793 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)"); |
|
904 | + if (self::LOG_LEVEL > 1) |
|
905 | + { |
|
906 | + error_log(__METHOD__."($url)"); |
|
907 | + } |
|
794 | 908 | |
795 | 909 | $path = Vfs::parse_url($url,PHP_URL_PATH); |
796 | 910 | |
@@ -801,7 +915,10 @@ discard block |
||
801 | 915 | self::_remove_password($url); |
802 | 916 | $err_msg = __METHOD__."($url,$options) ".(!$stat ? 'not found!' : |
803 | 917 | ($stat['mime'] != self::DIR_MIME_TYPE ? 'not a directory!' : 'permission denied!')); |
804 | - if (self::LOG_LEVEL) error_log($err_msg); |
|
918 | + if (self::LOG_LEVEL) |
|
919 | + { |
|
920 | + error_log($err_msg); |
|
921 | + } |
|
805 | 922 | if (!($options & STREAM_REPORT_ERRORS)) |
806 | 923 | { |
807 | 924 | trigger_error($err_msg,E_USER_WARNING); |
@@ -813,7 +930,10 @@ discard block |
||
813 | 930 | if ($stmt->fetchColumn()) |
814 | 931 | { |
815 | 932 | self::_remove_password($url); |
816 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$options) dir is not empty!"); |
|
933 | + if (self::LOG_LEVEL) |
|
934 | + { |
|
935 | + error_log(__METHOD__."($url,$options) dir is not empty!"); |
|
936 | + } |
|
817 | 937 | if (!($options & STREAM_REPORT_ERRORS)) |
818 | 938 | { |
819 | 939 | trigger_error(__METHOD__."('$url',$options) dir is not empty!",E_USER_WARNING); |
@@ -851,7 +971,10 @@ discard block |
||
851 | 971 | */ |
852 | 972 | function stream_metadata($path, $option, $value) |
853 | 973 | { |
854 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path, $option, ".array2string($value).")"); |
|
974 | + if (self::LOG_LEVEL > 1) |
|
975 | + { |
|
976 | + error_log(__METHOD__."($path, $option, ".array2string($value).")"); |
|
977 | + } |
|
855 | 978 | |
856 | 979 | switch($option) |
857 | 980 | { |
@@ -863,14 +986,18 @@ discard block |
||
863 | 986 | |
864 | 987 | case STREAM_META_OWNER_NAME: |
865 | 988 | if (($value = $GLOBALS['egw']->accounts->name2id($value, 'account_lid', 'u')) === false) |
866 | - return false; |
|
989 | + { |
|
990 | + return false; |
|
991 | + } |
|
867 | 992 | // fall through |
868 | 993 | case STREAM_META_OWNER: |
869 | 994 | return $this->chown($path, $value); |
870 | 995 | |
871 | 996 | case STREAM_META_GROUP_NAME: |
872 | 997 | if (($value = $GLOBALS['egw']->accounts->name2id($value, 'account_lid', 'g')) === false) |
873 | - return false; |
|
998 | + { |
|
999 | + return false; |
|
1000 | + } |
|
874 | 1001 | // fall through |
875 | 1002 | case STREAM_META_GROUP: |
876 | 1003 | return $this->chgrp($path, $value); |
@@ -888,7 +1015,10 @@ discard block |
||
888 | 1015 | protected function touch($url,$time=null,$atime=null) |
889 | 1016 | { |
890 | 1017 | unset($atime); // not used |
891 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $time)"); |
|
1018 | + if (self::LOG_LEVEL > 1) |
|
1019 | + { |
|
1020 | + error_log(__METHOD__."($url, $time)"); |
|
1021 | + } |
|
892 | 1022 | |
893 | 1023 | $path = Vfs::parse_url($url,PHP_URL_PATH); |
894 | 1024 | |
@@ -925,26 +1055,38 @@ discard block |
||
925 | 1055 | */ |
926 | 1056 | protected function chown($url,$owner) |
927 | 1057 | { |
928 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)"); |
|
1058 | + if (self::LOG_LEVEL > 1) |
|
1059 | + { |
|
1060 | + error_log(__METHOD__."($url,$owner)"); |
|
1061 | + } |
|
929 | 1062 | |
930 | 1063 | $path = Vfs::parse_url($url,PHP_URL_PATH); |
931 | 1064 | |
932 | 1065 | $vfs = new self(); |
933 | 1066 | if (!($stat = $vfs->url_stat($path,0))) |
934 | 1067 | { |
935 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!"); |
|
1068 | + if (self::LOG_LEVEL) |
|
1069 | + { |
|
1070 | + error_log(__METHOD__."($url,$owner) no such file or directory!"); |
|
1071 | + } |
|
936 | 1072 | trigger_error("No such file or directory $url !",E_USER_WARNING); |
937 | 1073 | return false; |
938 | 1074 | } |
939 | 1075 | if (!Vfs::$is_root) |
940 | 1076 | { |
941 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only root can do that!"); |
|
1077 | + if (self::LOG_LEVEL) |
|
1078 | + { |
|
1079 | + error_log(__METHOD__."($url,$owner) only root can do that!"); |
|
1080 | + } |
|
942 | 1081 | trigger_error("Only root can do that!",E_USER_WARNING); |
943 | 1082 | return false; |
944 | 1083 | } |
945 | - if ($owner < 0 || $owner && !$GLOBALS['egw']->accounts->id2name($owner)) // not a user (0 == root) |
|
1084 | + if ($owner < 0 || $owner && !$GLOBALS['egw']->accounts->id2name($owner)) |
|
1085 | + { |
|
1086 | + // not a user (0 == root) |
|
946 | 1087 | { |
947 | 1088 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) user id!"); |
1089 | + } |
|
948 | 1090 | trigger_error(__METHOD__."($url,$owner) Unknown (numeric) user id!",E_USER_WARNING); |
949 | 1091 | //throw new Exception(__METHOD__."($url,$owner) Unknown (numeric) user id!"); |
950 | 1092 | return false; |
@@ -952,7 +1094,10 @@ discard block |
||
952 | 1094 | $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_uid=:fs_uid WHERE fs_id=:fs_id'); |
953 | 1095 | |
954 | 1096 | // update stat-cache |
955 | - if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1); |
|
1097 | + if ($path != '/' && substr($path,-1) == '/') |
|
1098 | + { |
|
1099 | + $path = substr($path, 0, -1); |
|
1100 | + } |
|
956 | 1101 | self::$stat_cache[$path]['fs_uid'] = $owner; |
957 | 1102 | |
958 | 1103 | return $stmt->execute(array( |
@@ -970,35 +1115,54 @@ discard block |
||
970 | 1115 | */ |
971 | 1116 | protected function chgrp($url,$owner) |
972 | 1117 | { |
973 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)"); |
|
1118 | + if (self::LOG_LEVEL > 1) |
|
1119 | + { |
|
1120 | + error_log(__METHOD__."($url,$owner)"); |
|
1121 | + } |
|
974 | 1122 | |
975 | 1123 | $path = Vfs::parse_url($url,PHP_URL_PATH); |
976 | 1124 | |
977 | 1125 | $vfs = new self(); |
978 | 1126 | if (!($stat = $vfs->url_stat($path,0))) |
979 | 1127 | { |
980 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!"); |
|
1128 | + if (self::LOG_LEVEL) |
|
1129 | + { |
|
1130 | + error_log(__METHOD__."($url,$owner) no such file or directory!"); |
|
1131 | + } |
|
981 | 1132 | trigger_error("No such file or directory $url !",E_USER_WARNING); |
982 | 1133 | return false; |
983 | 1134 | } |
984 | 1135 | if (!Vfs::has_owner_rights($path,$stat)) |
985 | 1136 | { |
986 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only owner or root can do that!"); |
|
1137 | + if (self::LOG_LEVEL) |
|
1138 | + { |
|
1139 | + error_log(__METHOD__."($url,$owner) only owner or root can do that!"); |
|
1140 | + } |
|
987 | 1141 | trigger_error("Only owner or root can do that!",E_USER_WARNING); |
988 | 1142 | return false; |
989 | 1143 | } |
990 | - if ($owner < 0) $owner = -$owner; // sqlfs uses a positiv group id's! |
|
1144 | + if ($owner < 0) |
|
1145 | + { |
|
1146 | + $owner = -$owner; |
|
1147 | + } |
|
1148 | + // sqlfs uses a positiv group id's! |
|
991 | 1149 | |
992 | - if ($owner && !$GLOBALS['egw']->accounts->id2name(-$owner)) // not a group |
|
1150 | + if ($owner && !$GLOBALS['egw']->accounts->id2name(-$owner)) |
|
1151 | + { |
|
1152 | + // not a group |
|
993 | 1153 | { |
994 | 1154 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) group id!"); |
1155 | + } |
|
995 | 1156 | trigger_error("Unknown (numeric) group id!",E_USER_WARNING); |
996 | 1157 | return false; |
997 | 1158 | } |
998 | 1159 | $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_gid=:fs_gid WHERE fs_id=:fs_id'); |
999 | 1160 | |
1000 | 1161 | // update stat-cache |
1001 | - if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1); |
|
1162 | + if ($path != '/' && substr($path,-1) == '/') |
|
1163 | + { |
|
1164 | + $path = substr($path, 0, -1); |
|
1165 | + } |
|
1002 | 1166 | self::$stat_cache[$path]['fs_gid'] = $owner; |
1003 | 1167 | |
1004 | 1168 | return $stmt->execute(array( |
@@ -1016,33 +1180,48 @@ discard block |
||
1016 | 1180 | */ |
1017 | 1181 | protected function chmod($url,$mode) |
1018 | 1182 | { |
1019 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $mode)"); |
|
1183 | + if (self::LOG_LEVEL > 1) |
|
1184 | + { |
|
1185 | + error_log(__METHOD__."($url, $mode)"); |
|
1186 | + } |
|
1020 | 1187 | |
1021 | 1188 | $path = Vfs::parse_url($url,PHP_URL_PATH); |
1022 | 1189 | |
1023 | 1190 | $vfs = new self(); |
1024 | 1191 | if (!($stat = $vfs->url_stat($path,0))) |
1025 | 1192 | { |
1026 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no such file or directory!"); |
|
1193 | + if (self::LOG_LEVEL) |
|
1194 | + { |
|
1195 | + error_log(__METHOD__."($url, $mode) no such file or directory!"); |
|
1196 | + } |
|
1027 | 1197 | trigger_error("No such file or directory $url !",E_USER_WARNING); |
1028 | 1198 | return false; |
1029 | 1199 | } |
1030 | 1200 | if (!Vfs::has_owner_rights($path,$stat)) |
1031 | 1201 | { |
1032 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) only owner or root can do that!"); |
|
1202 | + if (self::LOG_LEVEL) |
|
1203 | + { |
|
1204 | + error_log(__METHOD__."($url, $mode) only owner or root can do that!"); |
|
1205 | + } |
|
1033 | 1206 | trigger_error("Only owner or root can do that!",E_USER_WARNING); |
1034 | 1207 | return false; |
1035 | 1208 | } |
1036 | - if (!is_numeric($mode)) // not a mode |
|
1209 | + if (!is_numeric($mode)) |
|
1210 | + { |
|
1211 | + // not a mode |
|
1037 | 1212 | { |
1038 | 1213 | if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no (numeric) mode!"); |
1214 | + } |
|
1039 | 1215 | trigger_error("No (numeric) mode!",E_USER_WARNING); |
1040 | 1216 | return false; |
1041 | 1217 | } |
1042 | 1218 | $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_mode=:fs_mode WHERE fs_id=:fs_id'); |
1043 | 1219 | |
1044 | 1220 | // update stat cache |
1045 | - if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1); |
|
1221 | + if ($path != '/' && substr($path,-1) == '/') |
|
1222 | + { |
|
1223 | + $path = substr($path, 0, -1); |
|
1224 | + } |
|
1046 | 1225 | self::$stat_cache[$path]['fs_mode'] = ((int) $mode) & 0777; |
1047 | 1226 | |
1048 | 1227 | return $stmt->execute(array( |
@@ -1067,12 +1246,18 @@ discard block |
||
1067 | 1246 | |
1068 | 1247 | if (!($stat = $this->url_stat($url,0)) || // dir not found |
1069 | 1248 | !($stat['mode'] & self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE || // no dir |
1070 | - !Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat)) // no access |
|
1249 | + !Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat)) |
|
1250 | + { |
|
1251 | + // no access |
|
1071 | 1252 | { |
1072 | 1253 | self::_remove_password($url); |
1254 | + } |
|
1073 | 1255 | $msg = !($stat['mode'] & self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE ? |
1074 | 1256 | "$url is no directory" : 'permission denied'; |
1075 | - if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$options) $msg!"); |
|
1257 | + if (self::LOG_LEVEL) |
|
1258 | + { |
|
1259 | + error_log(__METHOD__."('$url',$options) $msg!"); |
|
1260 | + } |
|
1076 | 1261 | $this->opened_dir = null; |
1077 | 1262 | return false; |
1078 | 1263 | } |
@@ -1081,7 +1266,10 @@ discard block |
||
1081 | 1266 | ' FROM '.self::TABLE.' WHERE fs_dir=? AND fs_active='.self::_pdo_boolean(true). |
1082 | 1267 | " ORDER BY fs_mime='httpd/unix-directory' DESC, fs_name ASC"; |
1083 | 1268 | //if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
1084 | - if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__."($url,$options)".' */ '.$query; |
|
1269 | + if (self::LOG_LEVEL > 2) |
|
1270 | + { |
|
1271 | + $query = '/* '.__METHOD__."($url,$options)".' */ '.$query; |
|
1272 | + } |
|
1085 | 1273 | |
1086 | 1274 | $stmt = self::$pdo->prepare($query); |
1087 | 1275 | $stmt->setFetchMode(\PDO::FETCH_ASSOC); |
@@ -1093,7 +1281,10 @@ discard block |
||
1093 | 1281 | self::$stat_cache[Vfs::concat($path,$file['fs_name'])] = $file; |
1094 | 1282 | } |
1095 | 1283 | } |
1096 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options): ".implode(', ',$this->opened_dir)); |
|
1284 | + if (self::LOG_LEVEL > 1) |
|
1285 | + { |
|
1286 | + error_log(__METHOD__."($url,$options): ".implode(', ',$this->opened_dir)); |
|
1287 | + } |
|
1097 | 1288 | reset($this->opened_dir); |
1098 | 1289 | |
1099 | 1290 | return true; |
@@ -1131,9 +1322,16 @@ discard block |
||
1131 | 1322 | if (is_null($max_subquery_depth)) |
1132 | 1323 | { |
1133 | 1324 | $max_subquery_depth = $GLOBALS['egw_info']['server']['max_subquery_depth']; |
1134 | - if (!$max_subquery_depth) $max_subquery_depth = 7; // setting current default of 7, if nothing set |
|
1325 | + if (!$max_subquery_depth) |
|
1326 | + { |
|
1327 | + $max_subquery_depth = 7; |
|
1328 | + } |
|
1329 | + // setting current default of 7, if nothing set |
|
1330 | + } |
|
1331 | + if (self::LOG_LEVEL > 1) |
|
1332 | + { |
|
1333 | + error_log(__METHOD__."('$url',$flags)"); |
|
1135 | 1334 | } |
1136 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$flags)"); |
|
1137 | 1335 | |
1138 | 1336 | $path = Vfs::parse_url($url,PHP_URL_PATH); |
1139 | 1337 | |
@@ -1196,7 +1394,10 @@ discard block |
||
1196 | 1394 | if (!Vfs::$user) |
1197 | 1395 | { |
1198 | 1396 | self::_remove_password($url); |
1199 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$flags) permission denied, no user-id and not root!"); |
|
1397 | + if (self::LOG_LEVEL > 1) |
|
1398 | + { |
|
1399 | + error_log(__METHOD__."('$url',$flags) permission denied, no user-id and not root!"); |
|
1400 | + } |
|
1200 | 1401 | return false; |
1201 | 1402 | } |
1202 | 1403 | $query .= ' AND '.self::_sql_readable(); |
@@ -1207,7 +1408,10 @@ discard block |
||
1207 | 1408 | $query = str_replace('fs_name'.self::$case_sensitive_equal.'?','fs_name'.self::$case_sensitive_equal.self::$pdo->quote($name),$base_query).'('.$query.')'; |
1208 | 1409 | } |
1209 | 1410 | } |
1210 | - if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__."($url,$flags) eacl_access=$eacl_access".' */ '.$query; |
|
1411 | + if (self::LOG_LEVEL > 2) |
|
1412 | + { |
|
1413 | + $query = '/* '.__METHOD__."($url,$flags) eacl_access=$eacl_access".' */ '.$query; |
|
1414 | + } |
|
1211 | 1415 | //if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
1212 | 1416 | |
1213 | 1417 | if (!($result = self::$pdo->query($query)) || !($info = $result->fetch(\PDO::FETCH_ASSOC))) |
@@ -1230,12 +1434,18 @@ discard block |
||
1230 | 1434 | $GLOBALS['egw_info']['server']['max_subquery_depth'] = --$max_subquery_depth; |
1231 | 1435 | error_log(__METHOD__."() decremented max_subquery_depth to $max_subquery_depth"); |
1232 | 1436 | Api\Config::save_value('max_subquery_depth', $max_subquery_depth, 'phpgwapi'); |
1233 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache(); |
|
1437 | + if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
1438 | + { |
|
1439 | + $GLOBALS['egw']->invalidate_session_cache(); |
|
1440 | + } |
|
1234 | 1441 | return $this->url_stat($url, $flags); |
1235 | 1442 | } |
1236 | 1443 | self::$stat_cache[$path] = $info; |
1237 | 1444 | |
1238 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags)=".array2string($info)); |
|
1445 | + if (self::LOG_LEVEL > 1) |
|
1446 | + { |
|
1447 | + error_log(__METHOD__."($url,$flags)=".array2string($info)); |
|
1448 | + } |
|
1239 | 1449 | return self::_vfsinfo2stat($info); |
1240 | 1450 | } |
1241 | 1451 | |
@@ -1272,9 +1482,15 @@ discard block |
||
1272 | 1482 | */ |
1273 | 1483 | function dir_readdir ( ) |
1274 | 1484 | { |
1275 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )"); |
|
1485 | + if (self::LOG_LEVEL > 1) |
|
1486 | + { |
|
1487 | + error_log(__METHOD__."( )"); |
|
1488 | + } |
|
1276 | 1489 | |
1277 | - if (!is_array($this->opened_dir)) return false; |
|
1490 | + if (!is_array($this->opened_dir)) |
|
1491 | + { |
|
1492 | + return false; |
|
1493 | + } |
|
1278 | 1494 | |
1279 | 1495 | $file = current($this->opened_dir); next($this->opened_dir); |
1280 | 1496 | |
@@ -1291,9 +1507,15 @@ discard block |
||
1291 | 1507 | */ |
1292 | 1508 | function dir_rewinddir ( ) |
1293 | 1509 | { |
1294 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )"); |
|
1510 | + if (self::LOG_LEVEL > 1) |
|
1511 | + { |
|
1512 | + error_log(__METHOD__."( )"); |
|
1513 | + } |
|
1295 | 1514 | |
1296 | - if (!is_array($this->opened_dir)) return false; |
|
1515 | + if (!is_array($this->opened_dir)) |
|
1516 | + { |
|
1517 | + return false; |
|
1518 | + } |
|
1297 | 1519 | |
1298 | 1520 | reset($this->opened_dir); |
1299 | 1521 | |
@@ -1309,9 +1531,15 @@ discard block |
||
1309 | 1531 | */ |
1310 | 1532 | function dir_closedir ( ) |
1311 | 1533 | { |
1312 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )"); |
|
1534 | + if (self::LOG_LEVEL > 1) |
|
1535 | + { |
|
1536 | + error_log(__METHOD__."( )"); |
|
1537 | + } |
|
1313 | 1538 | |
1314 | - if (!is_array($this->opened_dir)) return false; |
|
1539 | + if (!is_array($this->opened_dir)) |
|
1540 | + { |
|
1541 | + return false; |
|
1542 | + } |
|
1315 | 1543 | |
1316 | 1544 | $this->opened_dir = null; |
1317 | 1545 | |
@@ -1331,7 +1559,10 @@ discard block |
||
1331 | 1559 | $vfs = new self(); |
1332 | 1560 | $link = !($lstat = $vfs->url_stat($path,STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink']; |
1333 | 1561 | |
1334 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = $link"); |
|
1562 | + if (self::LOG_LEVEL > 1) |
|
1563 | + { |
|
1564 | + error_log(__METHOD__."('$path') = $link"); |
|
1565 | + } |
|
1335 | 1566 | |
1336 | 1567 | return $link; |
1337 | 1568 | } |
@@ -1345,23 +1576,35 @@ discard block |
||
1345 | 1576 | */ |
1346 | 1577 | static function symlink($target,$link) |
1347 | 1578 | { |
1348 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$target','$link')"); |
|
1579 | + if (self::LOG_LEVEL > 1) |
|
1580 | + { |
|
1581 | + error_log(__METHOD__."('$target','$link')"); |
|
1582 | + } |
|
1349 | 1583 | |
1350 | 1584 | $inst = new static(); |
1351 | 1585 | if ($inst->url_stat($link,0)) |
1352 | 1586 | { |
1353 | - if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') $link exists, returning false!"); |
|
1587 | + if (self::LOG_LEVEL > 0) |
|
1588 | + { |
|
1589 | + error_log(__METHOD__."('$target','$link') $link exists, returning false!"); |
|
1590 | + } |
|
1354 | 1591 | return false; // $link already exists |
1355 | 1592 | } |
1356 | 1593 | if (!($dir = Vfs::dirname($link)) || |
1357 | 1594 | !Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=$inst->url_stat($dir,0))) |
1358 | 1595 | { |
1359 | - if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') returning false! (!is_writable('$dir'), dir_stat=".array2string($dir_stat).")"); |
|
1596 | + if (self::LOG_LEVEL > 0) |
|
1597 | + { |
|
1598 | + error_log(__METHOD__."('$target','$link') returning false! (!is_writable('$dir'), dir_stat=".array2string($dir_stat).")"); |
|
1599 | + } |
|
1360 | 1600 | return false; // parent dir does not exist or is not writable |
1361 | 1601 | } |
1362 | 1602 | $query = 'INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_created,fs_modified,fs_creator,fs_mime,fs_size,fs_link'. |
1363 | 1603 | ') VALUES (:fs_name,:fs_dir,:fs_mode,:fs_uid,:fs_gid,:fs_created,:fs_modified,:fs_creator,:fs_mime,:fs_size,:fs_link)'; |
1364 | - if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
|
1604 | + if (self::LOG_LEVEL > 2) |
|
1605 | + { |
|
1606 | + $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
|
1607 | + } |
|
1365 | 1608 | $stmt = self::$pdo->prepare($query); |
1366 | 1609 | unset(self::$stat_cache[Vfs::parse_url($link,PHP_URL_PATH)]); |
1367 | 1610 | |
@@ -1409,7 +1652,10 @@ discard block |
||
1409 | 1652 | break; |
1410 | 1653 | } |
1411 | 1654 | } |
1412 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$check) ".($access?"access granted by $path=$rights":'no access!!!')); |
|
1655 | + if (self::LOG_LEVEL > 1) |
|
1656 | + { |
|
1657 | + error_log(__METHOD__."($url,$check) ".($access?"access granted by $path=$rights":'no access!!!')); |
|
1658 | + } |
|
1413 | 1659 | return $access; |
1414 | 1660 | } |
1415 | 1661 | |
@@ -1437,11 +1683,15 @@ discard block |
||
1437 | 1683 | } |
1438 | 1684 | } |
1439 | 1685 | // sort by length descending, to allow more specific pathes to have precedence |
1440 | - uksort(self::$extended_acl, function($a,$b) { |
|
1686 | + uksort(self::$extended_acl, function($a,$b) |
|
1687 | + { |
|
1441 | 1688 | return strlen($b)-strlen($a); |
1442 | 1689 | }); |
1443 | 1690 | Api\Cache::setSession(self::EACL_APPNAME, 'extended_acl', self::$extended_acl); |
1444 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__.'() '.array2string(self::$extended_acl)); |
|
1691 | + if (self::LOG_LEVEL > 1) |
|
1692 | + { |
|
1693 | + error_log(__METHOD__.'() '.array2string(self::$extended_acl)); |
|
1694 | + } |
|
1445 | 1695 | } |
1446 | 1696 | |
1447 | 1697 | /** |
@@ -1471,12 +1721,18 @@ discard block |
||
1471 | 1721 | $vfs = new self(); |
1472 | 1722 | if (!($stat = $vfs->url_stat($path,0))) |
1473 | 1723 | { |
1474 | - if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!"); |
|
1724 | + if (self::LOG_LEVEL) |
|
1725 | + { |
|
1726 | + error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!"); |
|
1727 | + } |
|
1475 | 1728 | return false; // $path not found |
1476 | 1729 | } |
1477 | - if (!Vfs::has_owner_rights($path,$stat)) // not group dir and user is eGW admin |
|
1730 | + if (!Vfs::has_owner_rights($path,$stat)) |
|
1731 | + { |
|
1732 | + // not group dir and user is eGW admin |
|
1478 | 1733 | { |
1479 | 1734 | if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) permission denied!"); |
1735 | + } |
|
1480 | 1736 | return false; // permission denied |
1481 | 1737 | } |
1482 | 1738 | $fs_id = $stat['ino']; |
@@ -1509,7 +1765,10 @@ discard block |
||
1509 | 1765 | { |
1510 | 1766 | Api\Cache::setSession(self::EACL_APPNAME, 'extended_acl', self::$extended_acl); |
1511 | 1767 | } |
1512 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$rights,$owner,$fs_id)=".(int)$ret); |
|
1768 | + if (self::LOG_LEVEL > 1) |
|
1769 | + { |
|
1770 | + error_log(__METHOD__."($path,$rights,$owner,$fs_id)=".(int)$ret); |
|
1771 | + } |
|
1513 | 1772 | return $ret; |
1514 | 1773 | } |
1515 | 1774 | |
@@ -1544,7 +1803,8 @@ discard block |
||
1544 | 1803 | $eacls = array_merge((array)self::get_eacl($path),$eacls); |
1545 | 1804 | } |
1546 | 1805 | // sort by length descending, to show precedence |
1547 | - usort($eacls, function($a, $b) { |
|
1806 | + usort($eacls, function($a, $b) |
|
1807 | + { |
|
1548 | 1808 | return strlen($b['path']) - strlen($a['path']); |
1549 | 1809 | }); |
1550 | 1810 | //error_log(__METHOD__."('$_path') returning ".array2string($eacls)); |
@@ -1602,7 +1862,10 @@ discard block |
||
1602 | 1862 | */ |
1603 | 1863 | static function id2path($fs_ids, $recursion_count=0) |
1604 | 1864 | { |
1605 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')'); |
|
1865 | + if (self::LOG_LEVEL > 1) |
|
1866 | + { |
|
1867 | + error_log(__METHOD__.'('.array2string($fs_ids).')'); |
|
1868 | + } |
|
1606 | 1869 | if ($recursion_count > self::MAX_ID2PATH_RECURSION) |
1607 | 1870 | { |
1608 | 1871 | error_log(__METHOD__."(".array2string($fs_ids).", $recursion_count) max recursion depth reached, probably broken filesystem!"); |
@@ -1619,16 +1882,26 @@ discard block |
||
1619 | 1882 | unset($ids[$key]); |
1620 | 1883 | if (!$ids) |
1621 | 1884 | { |
1622 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes).' *from stat_cache*'); |
|
1885 | + if (self::LOG_LEVEL > 1) |
|
1886 | + { |
|
1887 | + error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes).' *from stat_cache*'); |
|
1888 | + } |
|
1623 | 1889 | return is_array($fs_ids) ? $pathes : array_shift($pathes); |
1624 | 1890 | } |
1625 | 1891 | } |
1626 | 1892 | } |
1627 | 1893 | // now search via the database |
1628 | - if (count($ids) > 1) $ids = array_map(function($v) { return (int)$v; }, $ids); |
|
1894 | + if (count($ids) > 1) |
|
1895 | + { |
|
1896 | + $ids = array_map(function($v) { return (int)$v; |
|
1897 | + } |
|
1898 | + }, $ids); |
|
1629 | 1899 | $query = 'SELECT fs_id,fs_dir,fs_name FROM '.self::TABLE.' WHERE fs_id'. |
1630 | 1900 | (count($ids) == 1 ? '='.(int)$ids[0] : ' IN ('.implode(',',$ids).')'); |
1631 | - if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
|
1901 | + if (self::LOG_LEVEL > 2) |
|
1902 | + { |
|
1903 | + $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
|
1904 | + } |
|
1632 | 1905 | |
1633 | 1906 | if (!is_object(self::$pdo)) |
1634 | 1907 | { |
@@ -1655,14 +1928,20 @@ discard block |
||
1655 | 1928 | { |
1656 | 1929 | return false; // parent not found, should never happen ... |
1657 | 1930 | } |
1658 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__." trying foreach with:".print_r($rows,true)."#"); |
|
1931 | + if (self::LOG_LEVEL > 1) |
|
1932 | + { |
|
1933 | + error_log(__METHOD__." trying foreach with:".print_r($rows,true)."#"); |
|
1934 | + } |
|
1659 | 1935 | foreach((array)$rows as $fs_id => $row) |
1660 | 1936 | { |
1661 | 1937 | $parent = $row['fs_dir'] > 1 ? $parents[$row['fs_dir']] : ''; |
1662 | 1938 | |
1663 | 1939 | $pathes[$fs_id] = $parent . '/' . $row['fs_name']; |
1664 | 1940 | } |
1665 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes)); |
|
1941 | + if (self::LOG_LEVEL > 1) |
|
1942 | + { |
|
1943 | + error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes)); |
|
1944 | + } |
|
1666 | 1945 | return is_array($fs_ids) ? $pathes : array_shift($pathes); |
1667 | 1946 | } |
1668 | 1947 | |
@@ -1718,7 +1997,10 @@ discard block |
||
1718 | 1997 | 'mime' => $info['fs_mime'], |
1719 | 1998 | 'readlink' => $info['fs_link'], |
1720 | 1999 | ); |
1721 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($info[name]) = ".array2string($stat)); |
|
2000 | + if (self::LOG_LEVEL > 1) |
|
2001 | + { |
|
2002 | + error_log(__METHOD__."($info[name]) = ".array2string($stat)); |
|
2003 | + } |
|
1722 | 2004 | return $stat; |
1723 | 2005 | } |
1724 | 2006 | |
@@ -1750,13 +2032,16 @@ discard block |
||
1750 | 2032 | } |
1751 | 2033 | if (!isset($GLOBALS['egw_info']['server']['files_dir'])) |
1752 | 2034 | { |
1753 | - if (is_object($GLOBALS['egw_setup']->db)) // if we run under setup, query the db for the files dir |
|
2035 | + if (is_object($GLOBALS['egw_setup']->db)) |
|
2036 | + { |
|
2037 | + // if we run under setup, query the db for the files dir |
|
1754 | 2038 | { |
1755 | 2039 | $GLOBALS['egw_info']['server']['files_dir'] = $GLOBALS['egw_setup']->db->select('egw_config','config_value',array( |
1756 | 2040 | 'config_name' => 'files_dir', |
1757 | 2041 | 'config_app' => 'phpgwapi', |
1758 | 2042 | ),__LINE__,__FILE__)->fetchColumn(); |
1759 | 2043 | } |
2044 | + } |
|
1760 | 2045 | } |
1761 | 2046 | if (!$GLOBALS['egw_info']['server']['files_dir']) |
1762 | 2047 | { |
@@ -1768,7 +2053,11 @@ discard block |
||
1768 | 2053 | { |
1769 | 2054 | $hash[] = sprintf('%02d',$n % self::HASH_MAX); |
1770 | 2055 | } |
1771 | - if (!$hash) $hash[] = '00'; // we need at least one directory, to not conflict with the dir-names |
|
2056 | + if (!$hash) |
|
2057 | + { |
|
2058 | + $hash[] = '00'; |
|
2059 | + } |
|
2060 | + // we need at least one directory, to not conflict with the dir-names |
|
1772 | 2061 | array_unshift($hash,$id); |
1773 | 2062 | |
1774 | 2063 | $path = '/sqlfs/'.implode('/',array_reverse($hash)); |
@@ -1831,10 +2120,16 @@ discard block |
||
1831 | 2120 | static function proppatch($path,array $props) |
1832 | 2121 | { |
1833 | 2122 | static $inst = null; |
1834 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."(".array2string($path).','.array2string($props)); |
|
2123 | + if (self::LOG_LEVEL > 1) |
|
2124 | + { |
|
2125 | + error_log(__METHOD__."(".array2string($path).','.array2string($props)); |
|
2126 | + } |
|
1835 | 2127 | if (!is_numeric($path)) |
1836 | 2128 | { |
1837 | - if (!isset($inst)) $inst = new self(); |
|
2129 | + if (!isset($inst)) |
|
2130 | + { |
|
2131 | + $inst = new self(); |
|
2132 | + } |
|
1838 | 2133 | if (!($stat = $inst->url_stat($path,0))) |
1839 | 2134 | { |
1840 | 2135 | return false; |
@@ -1852,13 +2147,19 @@ discard block |
||
1852 | 2147 | $ins_stmt = $del_stmt = null; |
1853 | 2148 | foreach($props as &$prop) |
1854 | 2149 | { |
1855 | - if (!isset($prop['ns'])) $prop['ns'] = Vfs::DEFAULT_PROP_NAMESPACE; |
|
2150 | + if (!isset($prop['ns'])) |
|
2151 | + { |
|
2152 | + $prop['ns'] = Vfs::DEFAULT_PROP_NAMESPACE; |
|
2153 | + } |
|
1856 | 2154 | |
1857 | - if (!isset($prop['val']) || self::$pdo_type != 'mysql') // for non mysql, we have to delete the prop anyway, as there's no REPLACE! |
|
2155 | + if (!isset($prop['val']) || self::$pdo_type != 'mysql') |
|
2156 | + { |
|
2157 | + // for non mysql, we have to delete the prop anyway, as there's no REPLACE! |
|
1858 | 2158 | { |
1859 | 2159 | if (!isset($del_stmt)) |
1860 | 2160 | { |
1861 | 2161 | $del_stmt = self::$pdo->prepare('DELETE FROM '.self::PROPS_TABLE.' WHERE fs_id=:fs_id AND prop_namespace=:prop_namespace AND prop_name=:prop_name'); |
2162 | + } |
|
1862 | 2163 | } |
1863 | 2164 | $del_stmt->execute(array( |
1864 | 2165 | 'fs_id' => $id, |
@@ -1904,20 +2205,33 @@ discard block |
||
1904 | 2205 | { |
1905 | 2206 | if (!is_numeric($id)) |
1906 | 2207 | { |
1907 | - if (!isset($inst)) $inst = new self(); |
|
2208 | + if (!isset($inst)) |
|
2209 | + { |
|
2210 | + $inst = new self(); |
|
2211 | + } |
|
1908 | 2212 | if (!($stat = $inst->url_stat($id,0))) |
1909 | 2213 | { |
1910 | - if (self::LOG_LEVEL) error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!"); |
|
2214 | + if (self::LOG_LEVEL) |
|
2215 | + { |
|
2216 | + error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!"); |
|
2217 | + } |
|
1911 | 2218 | return false; |
1912 | 2219 | } |
1913 | 2220 | $id = $stat['ino']; |
1914 | 2221 | } |
1915 | 2222 | } |
1916 | - if (count($ids) >= 1) $ids = array_map(function($v) { return (int)$v; }, $ids); |
|
2223 | + if (count($ids) >= 1) |
|
2224 | + { |
|
2225 | + $ids = array_map(function($v) { return (int)$v; |
|
2226 | + } |
|
2227 | + }, $ids); |
|
1917 | 2228 | $query = 'SELECT * FROM '.self::PROPS_TABLE.' WHERE (fs_id'. |
1918 | 2229 | (count($ids) == 1 ? '='.(int)implode('',$ids) : ' IN ('.implode(',',$ids).')').')'. |
1919 | 2230 | (!is_null($ns) ? ' AND prop_namespace=?' : ''); |
1920 | - if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
|
2231 | + if (self::LOG_LEVEL > 2) |
|
2232 | + { |
|
2233 | + $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query; |
|
2234 | + } |
|
1921 | 2235 | |
1922 | 2236 | $stmt = self::$pdo->prepare($query); |
1923 | 2237 | $stmt->setFetchMode(\PDO::FETCH_ASSOC); |
@@ -1936,11 +2250,14 @@ discard block |
||
1936 | 2250 | { |
1937 | 2251 | $props = $props[$row['fs_id']] ? $props[$row['fs_id']] : array(); // return empty array for no props |
1938 | 2252 | } |
1939 | - elseif ($props && isset($stat) && is_array($id2path = self::id2path(array_keys($props)))) // need to map fs_id's to pathes |
|
2253 | + elseif ($props && isset($stat) && is_array($id2path = self::id2path(array_keys($props)))) |
|
2254 | + { |
|
2255 | + // need to map fs_id's to pathes |
|
1940 | 2256 | { |
1941 | 2257 | foreach($id2path as $id => $path) |
1942 | 2258 | { |
1943 | 2259 | $props[$path] =& $props[$id]; |
2260 | + } |
|
1944 | 2261 | unset($props[$id]); |
1945 | 2262 | } |
1946 | 2263 | } |
@@ -171,16 +171,16 @@ |
||
171 | 171 | |
172 | 172 | if (is_dir($source)) { // resource is a collection |
173 | 173 | switch ($options["depth"]) { |
174 | - case "infinity": // valid |
|
175 | - break; |
|
176 | - case "0": // valid for COPY only |
|
177 | - if ($del) { // MOVE? |
|
178 | - return "400 Bad request"; |
|
179 | - } |
|
180 | - break; |
|
181 | - case "1": // invalid for both COPY and MOVE |
|
182 | - default: |
|
183 | - return "400 Bad request"; |
|
174 | + case "infinity": // valid |
|
175 | + break; |
|
176 | + case "0": // valid for COPY only |
|
177 | + if ($del) { // MOVE? |
|
178 | + return "400 Bad request"; |
|
179 | + } |
|
180 | + break; |
|
181 | + case "1": // invalid for both COPY and MOVE |
|
182 | + default: |
|
183 | + return "400 Bad request"; |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 |
@@ -52,13 +52,13 @@ discard block |
||
52 | 52 | var $debug = 0; |
53 | 53 | |
54 | 54 | /** |
55 | - * Serve a webdav request |
|
56 | - * |
|
57 | - * Reimplemented to not check our vfs base path with realpath and connect to mysql DB |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @param $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php |
|
61 | - */ |
|
55 | + * Serve a webdav request |
|
56 | + * |
|
57 | + * Reimplemented to not check our vfs base path with realpath and connect to mysql DB |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @param $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php |
|
61 | + */ |
|
62 | 62 | function ServeRequest($prefix=null) |
63 | 63 | { |
64 | 64 | // special treatment for litmus compliance test |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | - * DELETE method handler |
|
77 | - * |
|
78 | - * @param array general parameter passing array |
|
79 | - * @return bool true on success |
|
80 | - */ |
|
76 | + * DELETE method handler |
|
77 | + * |
|
78 | + * @param array general parameter passing array |
|
79 | + * @return bool true on success |
|
80 | + */ |
|
81 | 81 | function DELETE($options) |
82 | 82 | { |
83 | 83 | $path = $this->base . $options['path']; |
@@ -110,118 +110,118 @@ discard block |
||
110 | 110 | return '204 No Content'; |
111 | 111 | } |
112 | 112 | |
113 | - /** |
|
114 | - * MKCOL method handler |
|
115 | - * |
|
116 | - * Reimplemented to NOT use dirname/basename, which has problems with utf-8 chars |
|
117 | - * |
|
118 | - * @param array general parameter passing array |
|
119 | - * @return bool true on success |
|
120 | - */ |
|
121 | - function MKCOL($options) |
|
122 | - { |
|
123 | - $path = $this->_unslashify($this->base .$options["path"]); |
|
124 | - $parent = Vfs::dirname($path); |
|
125 | - |
|
126 | - if (!file_exists($parent)) { |
|
127 | - return "409 Conflict"; |
|
128 | - } |
|
129 | - |
|
130 | - if (!is_dir($parent)) { |
|
131 | - return "403 Forbidden"; |
|
132 | - } |
|
133 | - |
|
134 | - if ( file_exists($path) ) { |
|
135 | - return "405 Method not allowed"; |
|
136 | - } |
|
137 | - |
|
138 | - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
139 | - return "415 Unsupported media type"; |
|
140 | - } |
|
141 | - |
|
142 | - $stat = mkdir($path, 0777); |
|
143 | - if (!$stat) { |
|
144 | - return "403 Forbidden"; |
|
145 | - } |
|
146 | - |
|
147 | - return ("201 Created"); |
|
148 | - } |
|
113 | + /** |
|
114 | + * MKCOL method handler |
|
115 | + * |
|
116 | + * Reimplemented to NOT use dirname/basename, which has problems with utf-8 chars |
|
117 | + * |
|
118 | + * @param array general parameter passing array |
|
119 | + * @return bool true on success |
|
120 | + */ |
|
121 | + function MKCOL($options) |
|
122 | + { |
|
123 | + $path = $this->_unslashify($this->base .$options["path"]); |
|
124 | + $parent = Vfs::dirname($path); |
|
125 | + |
|
126 | + if (!file_exists($parent)) { |
|
127 | + return "409 Conflict"; |
|
128 | + } |
|
129 | + |
|
130 | + if (!is_dir($parent)) { |
|
131 | + return "403 Forbidden"; |
|
132 | + } |
|
133 | + |
|
134 | + if ( file_exists($path) ) { |
|
135 | + return "405 Method not allowed"; |
|
136 | + } |
|
137 | + |
|
138 | + if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
139 | + return "415 Unsupported media type"; |
|
140 | + } |
|
141 | + |
|
142 | + $stat = mkdir($path, 0777); |
|
143 | + if (!$stat) { |
|
144 | + return "403 Forbidden"; |
|
145 | + } |
|
146 | + |
|
147 | + return ("201 Created"); |
|
148 | + } |
|
149 | 149 | |
150 | 150 | /** |
151 | - * COPY method handler |
|
152 | - * |
|
153 | - * @param array general parameter passing array |
|
154 | - * @return bool true on success |
|
155 | - */ |
|
156 | - function COPY($options, $del=false) |
|
157 | - { |
|
158 | - // TODO Property updates still broken (Litmus should detect this?) |
|
159 | - |
|
160 | - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
161 | - return "415 Unsupported media type"; |
|
162 | - } |
|
163 | - |
|
164 | - // no copying to different WebDAV Servers yet |
|
165 | - if (isset($options["dest_url"])) { |
|
166 | - return "502 bad gateway"; |
|
167 | - } |
|
168 | - |
|
169 | - $source = $this->base .$options["path"]; |
|
170 | - if (!file_exists($source)) return "404 Not found"; |
|
171 | - |
|
172 | - if (is_dir($source)) { // resource is a collection |
|
173 | - switch ($options["depth"]) { |
|
174 | - case "infinity": // valid |
|
175 | - break; |
|
176 | - case "0": // valid for COPY only |
|
177 | - if ($del) { // MOVE? |
|
178 | - return "400 Bad request"; |
|
179 | - } |
|
180 | - break; |
|
181 | - case "1": // invalid for both COPY and MOVE |
|
182 | - default: |
|
183 | - return "400 Bad request"; |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - $dest = $this->base . $options["dest"]; |
|
188 | - $destdir = Vfs::dirname($dest); |
|
189 | - |
|
190 | - if (!file_exists($destdir) || !is_dir($destdir)) { |
|
151 | + * COPY method handler |
|
152 | + * |
|
153 | + * @param array general parameter passing array |
|
154 | + * @return bool true on success |
|
155 | + */ |
|
156 | + function COPY($options, $del=false) |
|
157 | + { |
|
158 | + // TODO Property updates still broken (Litmus should detect this?) |
|
159 | + |
|
160 | + if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
161 | + return "415 Unsupported media type"; |
|
162 | + } |
|
163 | + |
|
164 | + // no copying to different WebDAV Servers yet |
|
165 | + if (isset($options["dest_url"])) { |
|
166 | + return "502 bad gateway"; |
|
167 | + } |
|
168 | + |
|
169 | + $source = $this->base .$options["path"]; |
|
170 | + if (!file_exists($source)) return "404 Not found"; |
|
171 | + |
|
172 | + if (is_dir($source)) { // resource is a collection |
|
173 | + switch ($options["depth"]) { |
|
174 | + case "infinity": // valid |
|
175 | + break; |
|
176 | + case "0": // valid for COPY only |
|
177 | + if ($del) { // MOVE? |
|
178 | + return "400 Bad request"; |
|
179 | + } |
|
180 | + break; |
|
181 | + case "1": // invalid for both COPY and MOVE |
|
182 | + default: |
|
183 | + return "400 Bad request"; |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + $dest = $this->base . $options["dest"]; |
|
188 | + $destdir = Vfs::dirname($dest); |
|
189 | + |
|
190 | + if (!file_exists($destdir) || !is_dir($destdir)) { |
|
191 | 191 | //error_log(__METHOD__."(".array2string($options).", $del) file_exists('$destdir')=".array2string(file_exists($destdir)).", is_dir('$destdir')=".array2string(is_dir($destdir))); |
192 | - return "409 Conflict"; |
|
193 | - } |
|
194 | - |
|
195 | - $new = !file_exists($dest); |
|
196 | - $existing_col = false; |
|
197 | - |
|
198 | - if (!$new) { |
|
199 | - if ($del && is_dir($dest)) { |
|
200 | - if (!$options["overwrite"]) { |
|
201 | - return "412 precondition failed"; |
|
202 | - } |
|
203 | - $dest .= Vfs::basename($source); |
|
204 | - if (file_exists($dest)) { |
|
205 | - $options["dest"] .= Vfs::basename($source); |
|
206 | - } else { |
|
207 | - $new = true; |
|
208 | - $existing_col = true; |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - if (!$new) { |
|
214 | - if ($options["overwrite"]) { |
|
215 | - $stat = $this->DELETE(array("path" => $options["dest"])); |
|
216 | - if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { |
|
217 | - return $stat; |
|
218 | - } |
|
219 | - } else { |
|
220 | - return "412 precondition failed"; |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - if ($del) { |
|
192 | + return "409 Conflict"; |
|
193 | + } |
|
194 | + |
|
195 | + $new = !file_exists($dest); |
|
196 | + $existing_col = false; |
|
197 | + |
|
198 | + if (!$new) { |
|
199 | + if ($del && is_dir($dest)) { |
|
200 | + if (!$options["overwrite"]) { |
|
201 | + return "412 precondition failed"; |
|
202 | + } |
|
203 | + $dest .= Vfs::basename($source); |
|
204 | + if (file_exists($dest)) { |
|
205 | + $options["dest"] .= Vfs::basename($source); |
|
206 | + } else { |
|
207 | + $new = true; |
|
208 | + $existing_col = true; |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + if (!$new) { |
|
214 | + if ($options["overwrite"]) { |
|
215 | + $stat = $this->DELETE(array("path" => $options["dest"])); |
|
216 | + if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { |
|
217 | + return $stat; |
|
218 | + } |
|
219 | + } else { |
|
220 | + return "412 precondition failed"; |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + if ($del) { |
|
225 | 225 | try { |
226 | 226 | if (!rename($source, $dest)) { |
227 | 227 | return "500 Internal server error"; |
@@ -230,51 +230,51 @@ discard block |
||
230 | 230 | catch (Exception\ProtectedDirectory $e) { |
231 | 231 | return "403 Forbidden: ".$e->getMessage(); |
232 | 232 | } |
233 | - } else { |
|
234 | - if (is_dir($source) && $options['depth'] == 'infinity') { |
|
235 | - $files = Vfs::find($source,array('depth' => true,'url' => true)); // depth=true: return dirs first, url=true: allow urls! |
|
236 | - } else { |
|
237 | - $files = array($source); |
|
238 | - } |
|
239 | - |
|
240 | - if (!is_array($files) || empty($files)) { |
|
241 | - return "500 Internal server error"; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - foreach ($files as $file) { |
|
246 | - if (is_dir($file)) { |
|
247 | - $file = $this->_slashify($file); |
|
248 | - } |
|
249 | - |
|
250 | - $destfile = str_replace($source, $dest, $file); |
|
251 | - |
|
252 | - if (is_dir($file)) { |
|
253 | - if (!is_dir($destfile)) { |
|
254 | - // TODO "mkdir -p" here? (only natively supported by PHP 5) |
|
255 | - if (!@mkdir($destfile)) { |
|
256 | - return "409 Conflict"; |
|
257 | - } |
|
258 | - } |
|
259 | - } else { |
|
260 | - if (!@copy($file, $destfile)) { |
|
261 | - return "409 Conflict"; |
|
262 | - } |
|
263 | - } |
|
264 | - } |
|
265 | - } |
|
266 | - // adding Location header as shown in example in rfc2518 section 8.9.5 |
|
233 | + } else { |
|
234 | + if (is_dir($source) && $options['depth'] == 'infinity') { |
|
235 | + $files = Vfs::find($source,array('depth' => true,'url' => true)); // depth=true: return dirs first, url=true: allow urls! |
|
236 | + } else { |
|
237 | + $files = array($source); |
|
238 | + } |
|
239 | + |
|
240 | + if (!is_array($files) || empty($files)) { |
|
241 | + return "500 Internal server error"; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + foreach ($files as $file) { |
|
246 | + if (is_dir($file)) { |
|
247 | + $file = $this->_slashify($file); |
|
248 | + } |
|
249 | + |
|
250 | + $destfile = str_replace($source, $dest, $file); |
|
251 | + |
|
252 | + if (is_dir($file)) { |
|
253 | + if (!is_dir($destfile)) { |
|
254 | + // TODO "mkdir -p" here? (only natively supported by PHP 5) |
|
255 | + if (!@mkdir($destfile)) { |
|
256 | + return "409 Conflict"; |
|
257 | + } |
|
258 | + } |
|
259 | + } else { |
|
260 | + if (!@copy($file, $destfile)) { |
|
261 | + return "409 Conflict"; |
|
262 | + } |
|
263 | + } |
|
264 | + } |
|
265 | + } |
|
266 | + // adding Location header as shown in example in rfc2518 section 8.9.5 |
|
267 | 267 | header('Location: '.$this->base_uri.$options['dest']); |
268 | 268 | |
269 | - return ($new && !$existing_col) ? "201 Created" : "204 No Content"; |
|
270 | - } |
|
269 | + return ($new && !$existing_col) ? "201 Created" : "204 No Content"; |
|
270 | + } |
|
271 | 271 | |
272 | - /** |
|
273 | - * Get properties for a single file/resource |
|
274 | - * |
|
275 | - * @param string $_path resource path |
|
276 | - * @return array resource properties |
|
277 | - */ |
|
272 | + /** |
|
273 | + * Get properties for a single file/resource |
|
274 | + * |
|
275 | + * @param string $_path resource path |
|
276 | + * @return array resource properties |
|
277 | + */ |
|
278 | 278 | function fileinfo($_path) |
279 | 279 | { |
280 | 280 | // internally we require some url-encoding, as vfs_stream_wrapper uses URL's internally |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | $info['props'][] = self::mkprop ('creationdate', filectime($fspath)); |
303 | 303 | $info['props'][] = self::mkprop ('getlastmodified', filemtime($fspath)); |
304 | 304 | |
305 | - // Microsoft extensions: last access time and 'hidden' status |
|
306 | - $info["props"][] = self::mkprop("lastaccessed", fileatime($fspath)); |
|
307 | - $info["props"][] = self::mkprop("ishidden", Vfs::is_hidden($fspath)); |
|
305 | + // Microsoft extensions: last access time and 'hidden' status |
|
306 | + $info["props"][] = self::mkprop("lastaccessed", fileatime($fspath)); |
|
307 | + $info["props"][] = self::mkprop("ishidden", Vfs::is_hidden($fspath)); |
|
308 | 308 | |
309 | 309 | // type and size (caller already made sure that path exists) |
310 | 310 | if (is_dir($fspath)) { |
@@ -442,38 +442,38 @@ discard block |
||
442 | 442 | } |
443 | 443 | |
444 | 444 | /** |
445 | - * Used eg. by get |
|
446 | - * |
|
447 | - * @todo replace all calls to _mimetype with Vfs::mime_content_type() |
|
448 | - * @param string $path |
|
449 | - * @return string |
|
450 | - */ |
|
445 | + * Used eg. by get |
|
446 | + * |
|
447 | + * @todo replace all calls to _mimetype with Vfs::mime_content_type() |
|
448 | + * @param string $path |
|
449 | + * @return string |
|
450 | + */ |
|
451 | 451 | function _mimetype($path) |
452 | 452 | { |
453 | 453 | return Vfs::mime_content_type($path); |
454 | 454 | } |
455 | 455 | |
456 | - /** |
|
457 | - * Check if path is readable by current user |
|
458 | - * |
|
459 | - * @param string $fspath |
|
460 | - * @return boolean |
|
461 | - */ |
|
462 | - function _is_readable($fspath) |
|
463 | - { |
|
464 | - return Vfs::is_readable($fspath); |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Check if path is writable by current user |
|
469 | - * |
|
470 | - * @param string $fspath |
|
471 | - * @return boolean |
|
472 | - */ |
|
473 | - function _is_writable($fspath) |
|
474 | - { |
|
475 | - return Vfs::is_writable($fspath); |
|
476 | - } |
|
456 | + /** |
|
457 | + * Check if path is readable by current user |
|
458 | + * |
|
459 | + * @param string $fspath |
|
460 | + * @return boolean |
|
461 | + */ |
|
462 | + function _is_readable($fspath) |
|
463 | + { |
|
464 | + return Vfs::is_readable($fspath); |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Check if path is writable by current user |
|
469 | + * |
|
470 | + * @param string $fspath |
|
471 | + * @return boolean |
|
472 | + */ |
|
473 | + function _is_writable($fspath) |
|
474 | + { |
|
475 | + return Vfs::is_writable($fspath); |
|
476 | + } |
|
477 | 477 | |
478 | 478 | /** |
479 | 479 | * PROPPATCH method handler |
@@ -616,13 +616,13 @@ discard block |
||
616 | 616 | * @param string directory path |
617 | 617 | * @return void function has to handle HTTP response itself |
618 | 618 | */ |
619 | - function GetDir($fspath, &$options) |
|
620 | - { |
|
619 | + function GetDir($fspath, &$options) |
|
620 | + { |
|
621 | 621 | // add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv) |
622 | 622 | header('Content-type: text/html; charset='.Api\Translation::charset()); |
623 | 623 | |
624 | 624 | parent::GetDir($fspath, $options); |
625 | - } |
|
625 | + } |
|
626 | 626 | |
627 | 627 | private $force_download = false; |
628 | 628 |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @access public |
60 | 60 | * @param $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php |
61 | 61 | */ |
62 | - function ServeRequest($prefix=null) |
|
62 | + function ServeRequest($prefix = null) |
|
63 | 63 | { |
64 | 64 | // special treatment for litmus compliance test |
65 | 65 | // reply on its identifier header |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | function DELETE($options) |
82 | 82 | { |
83 | - $path = $this->base . $options['path']; |
|
83 | + $path = $this->base.$options['path']; |
|
84 | 84 | |
85 | 85 | if (!file_exists($path)) |
86 | 86 | { |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | function MKCOL($options) |
122 | 122 | { |
123 | - $path = $this->_unslashify($this->base .$options["path"]); |
|
123 | + $path = $this->_unslashify($this->base.$options["path"]); |
|
124 | 124 | $parent = Vfs::dirname($path); |
125 | 125 | |
126 | 126 | if (!file_exists($parent)) { |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | return "403 Forbidden"; |
132 | 132 | } |
133 | 133 | |
134 | - if ( file_exists($path) ) { |
|
134 | + if (file_exists($path)) { |
|
135 | 135 | return "405 Method not allowed"; |
136 | 136 | } |
137 | 137 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param array general parameter passing array |
154 | 154 | * @return bool true on success |
155 | 155 | */ |
156 | - function COPY($options, $del=false) |
|
156 | + function COPY($options, $del = false) |
|
157 | 157 | { |
158 | 158 | // TODO Property updates still broken (Litmus should detect this?) |
159 | 159 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | return "502 bad gateway"; |
167 | 167 | } |
168 | 168 | |
169 | - $source = $this->base .$options["path"]; |
|
169 | + $source = $this->base.$options["path"]; |
|
170 | 170 | if (!file_exists($source)) return "404 Not found"; |
171 | 171 | |
172 | 172 | if (is_dir($source)) { // resource is a collection |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
187 | - $dest = $this->base . $options["dest"]; |
|
187 | + $dest = $this->base.$options["dest"]; |
|
188 | 188 | $destdir = Vfs::dirname($dest); |
189 | 189 | |
190 | 190 | if (!file_exists($destdir) || !is_dir($destdir)) { |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | } |
233 | 233 | } else { |
234 | 234 | if (is_dir($source) && $options['depth'] == 'infinity') { |
235 | - $files = Vfs::find($source,array('depth' => true,'url' => true)); // depth=true: return dirs first, url=true: allow urls! |
|
235 | + $files = Vfs::find($source, array('depth' => true, 'url' => true)); // depth=true: return dirs first, url=true: allow urls! |
|
236 | 236 | } else { |
237 | 237 | $files = array($source); |
238 | 238 | } |
@@ -278,16 +278,16 @@ discard block |
||
278 | 278 | function fileinfo($_path) |
279 | 279 | { |
280 | 280 | // internally we require some url-encoding, as vfs_stream_wrapper uses URL's internally |
281 | - $path = str_replace(array('#','?'),array('%23','%3F'),$_path); |
|
281 | + $path = str_replace(array('#', '?'), array('%23', '%3F'), $_path); |
|
282 | 282 | |
283 | 283 | //error_log(__METHOD__."($path)"); |
284 | 284 | // map URI path to filesystem path |
285 | - $fspath = $this->base . $path; |
|
285 | + $fspath = $this->base.$path; |
|
286 | 286 | |
287 | 287 | // create result array |
288 | 288 | $info = array(); |
289 | 289 | // TODO remove slash append code when base class is able to do it itself |
290 | - $info['path'] = is_dir($fspath) ? $this->_slashify($path) : $path; |
|
290 | + $info['path'] = is_dir($fspath) ? $this->_slashify($path) : $path; |
|
291 | 291 | |
292 | 292 | // remove all urlencoding we need internally in EGw, HTTP_WebDAV_Server will add it's own! |
293 | 293 | // rawurldecode does NOT touch + |
@@ -296,32 +296,32 @@ discard block |
||
296 | 296 | $info['props'] = array(); |
297 | 297 | |
298 | 298 | // no special beautified displayname here ... |
299 | - $info['props'][] = self::mkprop ('displayname', Vfs::basename(self::_unslashify($info['path']))); |
|
299 | + $info['props'][] = self::mkprop('displayname', Vfs::basename(self::_unslashify($info['path']))); |
|
300 | 300 | |
301 | 301 | // creation and modification time |
302 | - $info['props'][] = self::mkprop ('creationdate', filectime($fspath)); |
|
303 | - $info['props'][] = self::mkprop ('getlastmodified', filemtime($fspath)); |
|
302 | + $info['props'][] = self::mkprop('creationdate', filectime($fspath)); |
|
303 | + $info['props'][] = self::mkprop('getlastmodified', filemtime($fspath)); |
|
304 | 304 | |
305 | 305 | // Microsoft extensions: last access time and 'hidden' status |
306 | - $info["props"][] = self::mkprop("lastaccessed", fileatime($fspath)); |
|
307 | - $info["props"][] = self::mkprop("ishidden", Vfs::is_hidden($fspath)); |
|
306 | + $info["props"][] = self::mkprop("lastaccessed", fileatime($fspath)); |
|
307 | + $info["props"][] = self::mkprop("ishidden", Vfs::is_hidden($fspath)); |
|
308 | 308 | |
309 | 309 | // type and size (caller already made sure that path exists) |
310 | 310 | if (is_dir($fspath)) { |
311 | 311 | // directory (WebDAV collection) |
312 | - $info['props'][] = self::mkprop ('resourcetype', array( |
|
312 | + $info['props'][] = self::mkprop('resourcetype', array( |
|
313 | 313 | self::mkprop('collection', ''))); |
314 | - $info['props'][] = self::mkprop ('getcontenttype', 'httpd/unix-directory'); |
|
314 | + $info['props'][] = self::mkprop('getcontenttype', 'httpd/unix-directory'); |
|
315 | 315 | } else { |
316 | 316 | // plain file (WebDAV resource) |
317 | - $info['props'][] = self::mkprop ('resourcetype', ''); |
|
317 | + $info['props'][] = self::mkprop('resourcetype', ''); |
|
318 | 318 | if (Vfs::is_readable($path)) { |
319 | - $info['props'][] = self::mkprop ('getcontenttype', Vfs::mime_content_type($path)); |
|
319 | + $info['props'][] = self::mkprop('getcontenttype', Vfs::mime_content_type($path)); |
|
320 | 320 | } else { |
321 | 321 | error_log(__METHOD__."($path) $fspath is not readable!"); |
322 | - $info['props'][] = self::mkprop ('getcontenttype', 'application/x-non-readable'); |
|
322 | + $info['props'][] = self::mkprop('getcontenttype', 'application/x-non-readable'); |
|
323 | 323 | } |
324 | - $info['props'][] = self::mkprop ('getcontentlength', filesize($fspath)); |
|
324 | + $info['props'][] = self::mkprop('getcontentlength', filesize($fspath)); |
|
325 | 325 | } |
326 | 326 | // generate etag from inode (sqlfs: fs_id), modification time and size |
327 | 327 | $stat = stat($fspath); |
@@ -375,21 +375,21 @@ discard block |
||
375 | 375 | */ |
376 | 376 | function PROPFIND(&$options, &$files) |
377 | 377 | { |
378 | - if (!parent::PROPFIND($options,$files)) |
|
378 | + if (!parent::PROPFIND($options, $files)) |
|
379 | 379 | { |
380 | 380 | return false; |
381 | 381 | } |
382 | 382 | $path2n = array(); |
383 | - foreach($files['files'] as $n => $info) |
|
383 | + foreach ($files['files'] as $n => $info) |
|
384 | 384 | { |
385 | 385 | // do NOT report /clientsync/.favorites/, as it fails |
386 | - if (strpos($info['path'],'/clientsync/.favorites/') === 0) |
|
386 | + if (strpos($info['path'], '/clientsync/.favorites/') === 0) |
|
387 | 387 | { |
388 | 388 | unset($files['files'][$n]); |
389 | 389 | continue; |
390 | 390 | } |
391 | 391 | $_path = $info['path']; |
392 | - if (!$n && $info['path'] != '/' && substr($info['path'],-1) == '/') $_path = substr($info['path'],0,-1); |
|
392 | + if (!$n && $info['path'] != '/' && substr($info['path'], -1) == '/') $_path = substr($info['path'], 0, -1); |
|
393 | 393 | |
394 | 394 | // need to encode path again, as $info['path'] is NOT encoded, but Vfs::(stat|propfind) require it |
395 | 395 | // otherwise pathes containing url special chars like ? or # will not stat |
@@ -399,21 +399,21 @@ discard block |
||
399 | 399 | // adding some properties used instead of regular DAV times |
400 | 400 | if (($stat = Vfs::stat($path))) |
401 | 401 | { |
402 | - $fileprops =& $files['files'][$path2n[$path]]['props']; |
|
403 | - foreach(self::$auto_props as $attr => $props) |
|
402 | + $fileprops = & $files['files'][$path2n[$path]]['props']; |
|
403 | + foreach (self::$auto_props as $attr => $props) |
|
404 | 404 | { |
405 | - switch($attr) |
|
405 | + switch ($attr) |
|
406 | 406 | { |
407 | 407 | case 'ctime': |
408 | 408 | case 'mtime': |
409 | 409 | case 'atime': |
410 | - $value = gmdate('D, d M Y H:i:s T',$stat[$attr]); |
|
410 | + $value = gmdate('D, d M Y H:i:s T', $stat[$attr]); |
|
411 | 411 | break; |
412 | 412 | |
413 | 413 | default: |
414 | 414 | continue 2; |
415 | 415 | } |
416 | - foreach($props as $prop) |
|
416 | + foreach ($props as $prop) |
|
417 | 417 | { |
418 | 418 | $prop['val'] = $value; |
419 | 419 | $fileprops[] = $prop; |
@@ -421,17 +421,17 @@ discard block |
||
421 | 421 | } |
422 | 422 | } |
423 | 423 | } |
424 | - if ($path2n && ($path2props = Vfs::propfind(array_keys($path2n),null))) |
|
424 | + if ($path2n && ($path2props = Vfs::propfind(array_keys($path2n), null))) |
|
425 | 425 | { |
426 | - foreach($path2props as $path => $props) |
|
426 | + foreach ($path2props as $path => $props) |
|
427 | 427 | { |
428 | - $fileprops =& $files['files'][$path2n[$path]]['props']; |
|
429 | - foreach($props as $prop) |
|
428 | + $fileprops = & $files['files'][$path2n[$path]]['props']; |
|
429 | + foreach ($props as $prop) |
|
430 | 430 | { |
431 | 431 | if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'][0] == '#') // eGW's customfields |
432 | 432 | { |
433 | 433 | $prop['ns'] .= 'customfields/'; |
434 | - $prop['name'] = substr($prop['name'],1); |
|
434 | + $prop['name'] = substr($prop['name'], 1); |
|
435 | 435 | } |
436 | 436 | $fileprops[] = $prop; |
437 | 437 | } |
@@ -487,36 +487,36 @@ discard block |
||
487 | 487 | */ |
488 | 488 | function PROPPATCH(&$options) |
489 | 489 | { |
490 | - $path = Api\Translation::convert($options['path'],'utf-8'); |
|
490 | + $path = Api\Translation::convert($options['path'], 'utf-8'); |
|
491 | 491 | |
492 | 492 | foreach ($options['props'] as $key => $prop) { |
493 | 493 | $attributes = array(); |
494 | - switch($prop['ns']) |
|
494 | + switch ($prop['ns']) |
|
495 | 495 | { |
496 | 496 | // allow Webdrive to set creation and modification time |
497 | 497 | case 'http://www.southrivertech.com/': |
498 | - switch($prop['name']) |
|
498 | + switch ($prop['name']) |
|
499 | 499 | { |
500 | 500 | case 'srt_modifiedtime': |
501 | 501 | case 'getlastmodified': |
502 | - Vfs::touch($path,strtotime($prop['val'])); |
|
502 | + Vfs::touch($path, strtotime($prop['val'])); |
|
503 | 503 | break; |
504 | 504 | //case 'srt_creationtime': |
505 | 505 | // no streamwrapper interface / php function to set the ctime currently |
506 | 506 | //$attributes['created'] = strtotime($prop['val']); |
507 | 507 | //break; |
508 | 508 | default: |
509 | - if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden'; |
|
509 | + if (!Vfs::proppatch($path, array($prop))) $options['props'][$key]['status'] = '403 Forbidden'; |
|
510 | 510 | break; |
511 | 511 | } |
512 | 512 | break; |
513 | 513 | |
514 | 514 | case 'DAV:': |
515 | - switch($prop['name']) |
|
515 | + switch ($prop['name']) |
|
516 | 516 | { |
517 | 517 | // allow netdrive to change the modification time |
518 | 518 | case 'getlastmodified': |
519 | - Vfs::touch($path,strtotime($prop['val'])); |
|
519 | + Vfs::touch($path, strtotime($prop['val'])); |
|
520 | 520 | break; |
521 | 521 | // not sure why, the filesystem example of the WebDAV class does it ... |
522 | 522 | default: |
@@ -526,16 +526,16 @@ discard block |
||
526 | 526 | break; |
527 | 527 | |
528 | 528 | case 'urn:schemas-microsoft-com:': |
529 | - switch($prop['name']) |
|
529 | + switch ($prop['name']) |
|
530 | 530 | { |
531 | 531 | case 'Win32LastModifiedTime': |
532 | - Vfs::touch($path,strtotime($prop['val'])); |
|
532 | + Vfs::touch($path, strtotime($prop['val'])); |
|
533 | 533 | break; |
534 | 534 | case 'Win32CreationTime': // eg. "Wed, 14 Sep 2011 15:48:26 GMT" |
535 | 535 | case 'Win32LastAccessTime': |
536 | 536 | case 'Win32FileAttributes': // not sure what that is, it was always "00000000" |
537 | 537 | default: |
538 | - if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden'; |
|
538 | + if (!Vfs::proppatch($path, array($prop))) $options['props'][$key]['status'] = '403 Forbidden'; |
|
539 | 539 | break; |
540 | 540 | } |
541 | 541 | break; |
@@ -545,18 +545,18 @@ discard block |
||
545 | 545 | $prop['name'] = '#'.$prop['name']; |
546 | 546 | // fall through |
547 | 547 | default: |
548 | - if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden'; |
|
548 | + if (!Vfs::proppatch($path, array($prop))) $options['props'][$key]['status'] = '403 Forbidden'; |
|
549 | 549 | break; |
550 | 550 | } |
551 | 551 | if ($this->debug) $props[] = '('.$prop['ns'].')'.$prop['name'].'='.$prop['val']; |
552 | 552 | } |
553 | 553 | if ($this->debug) |
554 | 554 | { |
555 | - error_log(__METHOD__.": path=$options[path], props=".implode(', ',$props)); |
|
556 | - if ($attributes) error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n",' ',print_r($attributes,true))); |
|
555 | + error_log(__METHOD__.": path=$options[path], props=".implode(', ', $props)); |
|
556 | + if ($attributes) error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n", ' ', print_r($attributes, true))); |
|
557 | 557 | } |
558 | 558 | |
559 | - return ''; // this is as the filesystem example handler does it, no true or false ... |
|
559 | + return ''; // this is as the filesystem example handler does it, no true or false ... |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | /** |
@@ -567,18 +567,18 @@ discard block |
||
567 | 567 | */ |
568 | 568 | function LOCK(&$options) |
569 | 569 | { |
570 | - if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')'); |
|
570 | + if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n", ' '), '', print_r($options, true)).')'); |
|
571 | 571 | // TODO recursive locks on directories not supported yet |
572 | - if (is_dir($this->base . $options['path']) && !empty($options['depth'])) |
|
572 | + if (is_dir($this->base.$options['path']) && !empty($options['depth'])) |
|
573 | 573 | { |
574 | 574 | return '409 Conflict'; |
575 | 575 | } |
576 | - $options['timeout'] = time()+300; // 5min. hardcoded |
|
576 | + $options['timeout'] = time() + 300; // 5min. hardcoded |
|
577 | 577 | |
578 | 578 | // dont know why, but HTTP_WebDAV_Server passes the owner in D:href tags, which get's passed unchanged to checkLock/PROPFIND |
579 | 579 | // that's wrong according to the standard and cadaver does not show it on discover --> strip_tags removes eventual tags |
580 | - if (($ret = Vfs::lock($options['path'],$options['locktoken'],$options['timeout'],strip_tags($options['owner']), |
|
581 | - $options['scope'],$options['type'],isset($options['update']))) && !isset($options['update'])) |
|
580 | + if (($ret = Vfs::lock($options['path'], $options['locktoken'], $options['timeout'], strip_tags($options['owner']), |
|
581 | + $options['scope'], $options['type'], isset($options['update']))) && !isset($options['update'])) |
|
582 | 582 | { |
583 | 583 | return $ret ? '200 OK' : '409 Conflict'; |
584 | 584 | } |
@@ -593,8 +593,8 @@ discard block |
||
593 | 593 | */ |
594 | 594 | function UNLOCK(&$options) |
595 | 595 | { |
596 | - if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')'); |
|
597 | - return Vfs::unlock($options['path'],$options['token']) ? '204 No Content' : '409 Conflict'; |
|
596 | + if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n", ' '), '', print_r($options, true)).')'); |
|
597 | + return Vfs::unlock($options['path'], $options['token']) ? '204 No Content' : '409 Conflict'; |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
@@ -633,9 +633,9 @@ discard block |
||
633 | 633 | */ |
634 | 634 | function __construct() |
635 | 635 | { |
636 | - if ($_SERVER['REQUEST_METHOD'] == 'GET' && (($this->force_download = strpos($_SERVER['REQUEST_URI'],'?download')) !== false)) |
|
636 | + if ($_SERVER['REQUEST_METHOD'] == 'GET' && (($this->force_download = strpos($_SERVER['REQUEST_URI'], '?download')) !== false)) |
|
637 | 637 | { |
638 | - $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'],0,$this->force_download); |
|
638 | + $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $this->force_download); |
|
639 | 639 | } |
640 | 640 | parent::__construct(); |
641 | 641 | } |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | */ |
651 | 651 | function GET(&$options) |
652 | 652 | { |
653 | - if (is_dir($this->base . $options["path"])) |
|
653 | + if (is_dir($this->base.$options["path"])) |
|
654 | 654 | { |
655 | 655 | return $this->autoindex($options); |
656 | 656 | } |
@@ -658,11 +658,11 @@ discard block |
||
658 | 658 | { |
659 | 659 | // mitigate risks of serving javascript or css from our domain |
660 | 660 | Api\Header\Content::safe($options['stream'], $options['path'], $options['mimetype'], $options['size'], false, |
661 | - $this->force_download, true); // true = do not send content-type and content-length header, but modify values |
|
661 | + $this->force_download, true); // true = do not send content-type and content-length header, but modify values |
|
662 | 662 | |
663 | 663 | if (!is_resource($options['stream'])) |
664 | 664 | { |
665 | - $options['data'] =& $options['stream']; |
|
665 | + $options['data'] = & $options['stream']; |
|
666 | 666 | unset($options['stream']); |
667 | 667 | } |
668 | 668 | } |
@@ -681,9 +681,9 @@ discard block |
||
681 | 681 | 'depth' => 1, |
682 | 682 | ); |
683 | 683 | $files = array(); |
684 | - if (($ret = $this->PROPFIND($propfind_options,$files)) !== true) |
|
684 | + if (($ret = $this->PROPFIND($propfind_options, $files)) !== true) |
|
685 | 685 | { |
686 | - return $ret; // no collection |
|
686 | + return $ret; // no collection |
|
687 | 687 | } |
688 | 688 | header('Content-type: text/html; charset='.Api\Translation::charset()); |
689 | 689 | echo "<html>\n<head>\n\t<title>".'EGroupware WebDAV server '.htmlspecialchars($options['path'])."</title>\n"; |
@@ -695,10 +695,10 @@ discard block |
||
695 | 695 | echo '<h1>WebDAV '; |
696 | 696 | list(,$base) = explode(parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH), $this->base_uri, 2); |
697 | 697 | $path = $base; |
698 | - foreach(explode('/',$this->_unslashify($options['path'])) as $n => $name) |
|
698 | + foreach (explode('/', $this->_unslashify($options['path'])) as $n => $name) |
|
699 | 699 | { |
700 | 700 | $path .= ($n != 1 ? '/' : '').$name; |
701 | - echo Api\Html::a_href(htmlspecialchars($name.'/'),$path); |
|
701 | + echo Api\Html::a_href(htmlspecialchars($name.'/'), $path); |
|
702 | 702 | } |
703 | 703 | echo "</h1>\n"; |
704 | 704 | |
@@ -715,18 +715,18 @@ discard block |
||
715 | 715 | ); |
716 | 716 | $n = 0; |
717 | 717 | $collection_props = null; |
718 | - foreach($files['files'] as $file) |
|
718 | + foreach ($files['files'] as $file) |
|
719 | 719 | { |
720 | 720 | if (!isset($collection_props)) |
721 | 721 | { |
722 | 722 | $collection_props = $this->props2array($file['props']); |
723 | 723 | echo '<h3>'.lang('Collection listing').': '.htmlspecialchars($collection_props['DAV:displayname'])."</h3>\n"; |
724 | - continue; // own entry --> displaying properies later |
|
724 | + continue; // own entry --> displaying properies later |
|
725 | 725 | } |
726 | - if(!$n++) |
|
726 | + if (!$n++) |
|
727 | 727 | { |
728 | 728 | echo "<table>\n\t<tr class='th'>\n\t\t<th>#</th>\n\t\t<th>".lang('Name')."</th>"; |
729 | - foreach($props2show as $label) |
|
729 | + foreach ($props2show as $label) |
|
730 | 730 | { |
731 | 731 | echo "\t\t<th>".lang($label)."</th>\n"; |
732 | 732 | } |
@@ -736,9 +736,9 @@ discard block |
||
736 | 736 | //echo $file['path']; _debug_array($props); |
737 | 737 | $class = $class == 'row_on' ? 'row_off' : 'row_on'; |
738 | 738 | |
739 | - if (substr($file['path'],-1) == '/') |
|
739 | + if (substr($file['path'], -1) == '/') |
|
740 | 740 | { |
741 | - $name = Vfs::basename(substr($file['path'],0,-1)).'/'; |
|
741 | + $name = Vfs::basename(substr($file['path'], 0, -1)).'/'; |
|
742 | 742 | } |
743 | 743 | else |
744 | 744 | { |
@@ -746,14 +746,14 @@ discard block |
||
746 | 746 | } |
747 | 747 | |
748 | 748 | echo "\t<tr class='$class'>\n\t\t<td>$n</td>\n\t\t<td>". |
749 | - Api\Html::a_href(htmlspecialchars($name),$base.strtr($file['path'], array( |
|
749 | + Api\Html::a_href(htmlspecialchars($name), $base.strtr($file['path'], array( |
|
750 | 750 | '%' => '%25', |
751 | 751 | '#' => '%23', |
752 | 752 | '?' => '%3F', |
753 | 753 | )))."</td>\n"; |
754 | - foreach($props2show as $prop => $label) |
|
754 | + foreach ($props2show as $prop => $label) |
|
755 | 755 | { |
756 | - echo "\t\t<td>".($prop=='DAV:getlastmodified'&&!empty($props[$prop])?date('Y-m-d H:i:s',$props[$prop]):$props[$prop])."</td>\n"; |
|
756 | + echo "\t\t<td>".($prop == 'DAV:getlastmodified' && !empty($props[$prop]) ?date('Y-m-d H:i:s', $props[$prop]) : $props[$prop])."</td>\n"; |
|
757 | 757 | } |
758 | 758 | echo "\t</tr>\n"; |
759 | 759 | } |
@@ -767,12 +767,12 @@ discard block |
||
767 | 767 | } |
768 | 768 | echo '<h3>'.lang('Properties')."</h3>\n"; |
769 | 769 | echo "<table>\n\t<tr class='th'><th>".lang('Namespace')."</th><th>".lang('Name')."</th><th>".lang('Value')."</th></tr>\n"; |
770 | - foreach($collection_props as $name => $value) |
|
770 | + foreach ($collection_props as $name => $value) |
|
771 | 771 | { |
772 | 772 | $class = $class == 'row_on' ? 'row_off' : 'row_on'; |
773 | - $parts = explode(':',$name); |
|
773 | + $parts = explode(':', $name); |
|
774 | 774 | $name = array_pop($parts); |
775 | - $ns = implode(':',$parts); |
|
775 | + $ns = implode(':', $parts); |
|
776 | 776 | echo "\t<tr class='$class'>\n\t\t<td>".htmlspecialchars($ns)."</td><td style='white-space: nowrap'>".htmlspecialchars($name)."</td>\n"; |
777 | 777 | echo "\t\t<td>".$value."</td>\n\t</tr>\n"; |
778 | 778 | } |
@@ -815,11 +815,11 @@ discard block |
||
815 | 815 | 'wrap' => 0, |
816 | 816 | )); |
817 | 817 | } |
818 | - if (($href=preg_match('/\<(D:)?href\>[^<]+\<\/(D:)?href\>/i',$value))) |
|
818 | + if (($href = preg_match('/\<(D:)?href\>[^<]+\<\/(D:)?href\>/i', $value))) |
|
819 | 819 | { |
820 | - $value = preg_replace('/\<(D:)?href\>('.preg_quote($this->base_uri.'/','/').')?([^<]+)\<\/(D:)?href\>/i','<\\1href><a href="\\2\\3">\\3</a></\\4href>',$value); |
|
820 | + $value = preg_replace('/\<(D:)?href\>('.preg_quote($this->base_uri.'/', '/').')?([^<]+)\<\/(D:)?href\>/i', '<\\1href><a href="\\2\\3">\\3</a></\\4href>', $value); |
|
821 | 821 | } |
822 | - $ret = $value[0] == '<' || strpos($value, "\n") !== false ? |
|
822 | + $ret = $value[0] == '<' || strpos($value, "\n") !== false ? |
|
823 | 823 | '<pre>'.htmlspecialchars($value).'</pre>' : htmlspecialchars($value); |
824 | 824 | |
825 | 825 | if ($href) |
@@ -839,10 +839,10 @@ discard block |
||
839 | 839 | protected function props2array(array $props) |
840 | 840 | { |
841 | 841 | $arr = array(); |
842 | - foreach($props as $prop) |
|
842 | + foreach ($props as $prop) |
|
843 | 843 | { |
844 | 844 | $ns_hash = array('DAV:' => 'D'); |
845 | - switch($prop['ns']) |
|
845 | + switch ($prop['ns']) |
|
846 | 846 | { |
847 | 847 | case 'DAV:'; |
848 | 848 | $ns = 'DAV'; |
@@ -852,10 +852,10 @@ discard block |
||
852 | 852 | } |
853 | 853 | if (is_array($prop['val'])) |
854 | 854 | { |
855 | - $prop['val'] = $this->_hierarchical_prop_encode($prop['val'], $prop['ns'], $ns_defs='', $ns_hash); |
|
855 | + $prop['val'] = $this->_hierarchical_prop_encode($prop['val'], $prop['ns'], $ns_defs = '', $ns_hash); |
|
856 | 856 | // hack to show real namespaces instead of not (visibly) defined shortcuts |
857 | 857 | unset($ns_hash['DAV:']); |
858 | - $value = strtr($v=$this->prop_value($prop['val']),array_flip($ns_hash)); |
|
858 | + $value = strtr($v = $this->prop_value($prop['val']), array_flip($ns_hash)); |
|
859 | 859 | } |
860 | 860 | else |
861 | 861 | { |
@@ -64,7 +64,8 @@ discard block |
||
64 | 64 | // special treatment for litmus compliance test |
65 | 65 | // reply on its identifier header |
66 | 66 | // not needed for the test itself but eases debugging |
67 | - if (isset($this->_SERVER['HTTP_X_LITMUS'])) { |
|
67 | + if (isset($this->_SERVER['HTTP_X_LITMUS'])) |
|
68 | + { |
|
68 | 69 | error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']); |
69 | 70 | header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']); |
70 | 71 | } |
@@ -123,24 +124,30 @@ discard block |
||
123 | 124 | $path = $this->_unslashify($this->base .$options["path"]); |
124 | 125 | $parent = Vfs::dirname($path); |
125 | 126 | |
126 | - if (!file_exists($parent)) { |
|
127 | + if (!file_exists($parent)) |
|
128 | + { |
|
127 | 129 | return "409 Conflict"; |
128 | 130 | } |
129 | 131 | |
130 | - if (!is_dir($parent)) { |
|
132 | + if (!is_dir($parent)) |
|
133 | + { |
|
131 | 134 | return "403 Forbidden"; |
132 | 135 | } |
133 | 136 | |
134 | - if ( file_exists($path) ) { |
|
137 | + if ( file_exists($path) ) |
|
138 | + { |
|
135 | 139 | return "405 Method not allowed"; |
136 | 140 | } |
137 | 141 | |
138 | - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
142 | + if (!empty($this->_SERVER["CONTENT_LENGTH"])) |
|
143 | + { |
|
144 | +// no body parsing yet |
|
139 | 145 | return "415 Unsupported media type"; |
140 | 146 | } |
141 | 147 | |
142 | 148 | $stat = mkdir($path, 0777); |
143 | - if (!$stat) { |
|
149 | + if (!$stat) |
|
150 | + { |
|
144 | 151 | return "403 Forbidden"; |
145 | 152 | } |
146 | 153 | |
@@ -157,24 +164,35 @@ discard block |
||
157 | 164 | { |
158 | 165 | // TODO Property updates still broken (Litmus should detect this?) |
159 | 166 | |
160 | - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
167 | + if (!empty($this->_SERVER["CONTENT_LENGTH"])) |
|
168 | + { |
|
169 | +// no body parsing yet |
|
161 | 170 | return "415 Unsupported media type"; |
162 | 171 | } |
163 | 172 | |
164 | 173 | // no copying to different WebDAV Servers yet |
165 | - if (isset($options["dest_url"])) { |
|
174 | + if (isset($options["dest_url"])) |
|
175 | + { |
|
166 | 176 | return "502 bad gateway"; |
167 | 177 | } |
168 | 178 | |
169 | 179 | $source = $this->base .$options["path"]; |
170 | - if (!file_exists($source)) return "404 Not found"; |
|
180 | + if (!file_exists($source)) |
|
181 | + { |
|
182 | + return "404 Not found"; |
|
183 | + } |
|
171 | 184 | |
172 | - if (is_dir($source)) { // resource is a collection |
|
173 | - switch ($options["depth"]) { |
|
185 | + if (is_dir($source)) |
|
186 | + { |
|
187 | +// resource is a collection |
|
188 | + switch ($options["depth"]) |
|
189 | + { |
|
174 | 190 | case "infinity": // valid |
175 | 191 | break; |
176 | 192 | case "0": // valid for COPY only |
177 | - if ($del) { // MOVE? |
|
193 | + if ($del) |
|
194 | + { |
|
195 | +// MOVE? |
|
178 | 196 | return "400 Bad request"; |
179 | 197 | } |
180 | 198 | break; |
@@ -187,7 +205,8 @@ discard block |
||
187 | 205 | $dest = $this->base . $options["dest"]; |
188 | 206 | $destdir = Vfs::dirname($dest); |
189 | 207 | |
190 | - if (!file_exists($destdir) || !is_dir($destdir)) { |
|
208 | + if (!file_exists($destdir) || !is_dir($destdir)) |
|
209 | + { |
|
191 | 210 | //error_log(__METHOD__."(".array2string($options).", $del) file_exists('$destdir')=".array2string(file_exists($destdir)).", is_dir('$destdir')=".array2string(is_dir($destdir))); |
192 | 211 | return "409 Conflict"; |
193 | 212 | } |
@@ -195,69 +214,96 @@ discard block |
||
195 | 214 | $new = !file_exists($dest); |
196 | 215 | $existing_col = false; |
197 | 216 | |
198 | - if (!$new) { |
|
199 | - if ($del && is_dir($dest)) { |
|
200 | - if (!$options["overwrite"]) { |
|
217 | + if (!$new) |
|
218 | + { |
|
219 | + if ($del && is_dir($dest)) |
|
220 | + { |
|
221 | + if (!$options["overwrite"]) |
|
222 | + { |
|
201 | 223 | return "412 precondition failed"; |
202 | 224 | } |
203 | 225 | $dest .= Vfs::basename($source); |
204 | - if (file_exists($dest)) { |
|
226 | + if (file_exists($dest)) |
|
227 | + { |
|
205 | 228 | $options["dest"] .= Vfs::basename($source); |
206 | - } else { |
|
229 | + } |
|
230 | + else |
|
231 | + { |
|
207 | 232 | $new = true; |
208 | 233 | $existing_col = true; |
209 | 234 | } |
210 | 235 | } |
211 | 236 | } |
212 | 237 | |
213 | - if (!$new) { |
|
214 | - if ($options["overwrite"]) { |
|
238 | + if (!$new) |
|
239 | + { |
|
240 | + if ($options["overwrite"]) |
|
241 | + { |
|
215 | 242 | $stat = $this->DELETE(array("path" => $options["dest"])); |
216 | - if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { |
|
243 | + if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) |
|
244 | + { |
|
217 | 245 | return $stat; |
218 | 246 | } |
219 | - } else { |
|
247 | + } |
|
248 | + else |
|
249 | + { |
|
220 | 250 | return "412 precondition failed"; |
221 | 251 | } |
222 | 252 | } |
223 | 253 | |
224 | - if ($del) { |
|
254 | + if ($del) |
|
255 | + { |
|
225 | 256 | try { |
226 | - if (!rename($source, $dest)) { |
|
257 | + if (!rename($source, $dest)) |
|
258 | + { |
|
227 | 259 | return "500 Internal server error"; |
228 | 260 | } |
229 | 261 | } |
230 | 262 | catch (Exception\ProtectedDirectory $e) { |
231 | 263 | return "403 Forbidden: ".$e->getMessage(); |
232 | 264 | } |
233 | - } else { |
|
234 | - if (is_dir($source) && $options['depth'] == 'infinity') { |
|
265 | + } |
|
266 | + else |
|
267 | + { |
|
268 | + if (is_dir($source) && $options['depth'] == 'infinity') |
|
269 | + { |
|
235 | 270 | $files = Vfs::find($source,array('depth' => true,'url' => true)); // depth=true: return dirs first, url=true: allow urls! |
236 | - } else { |
|
271 | + } |
|
272 | + else |
|
273 | + { |
|
237 | 274 | $files = array($source); |
238 | 275 | } |
239 | 276 | |
240 | - if (!is_array($files) || empty($files)) { |
|
277 | + if (!is_array($files) || empty($files)) |
|
278 | + { |
|
241 | 279 | return "500 Internal server error"; |
242 | 280 | } |
243 | 281 | |
244 | 282 | |
245 | - foreach ($files as $file) { |
|
246 | - if (is_dir($file)) { |
|
283 | + foreach ($files as $file) |
|
284 | + { |
|
285 | + if (is_dir($file)) |
|
286 | + { |
|
247 | 287 | $file = $this->_slashify($file); |
248 | 288 | } |
249 | 289 | |
250 | 290 | $destfile = str_replace($source, $dest, $file); |
251 | 291 | |
252 | - if (is_dir($file)) { |
|
253 | - if (!is_dir($destfile)) { |
|
292 | + if (is_dir($file)) |
|
293 | + { |
|
294 | + if (!is_dir($destfile)) |
|
295 | + { |
|
254 | 296 | // TODO "mkdir -p" here? (only natively supported by PHP 5) |
255 | - if (!@mkdir($destfile)) { |
|
297 | + if (!@mkdir($destfile)) |
|
298 | + { |
|
256 | 299 | return "409 Conflict"; |
257 | 300 | } |
258 | 301 | } |
259 | - } else { |
|
260 | - if (!@copy($file, $destfile)) { |
|
302 | + } |
|
303 | + else |
|
304 | + { |
|
305 | + if (!@copy($file, $destfile)) |
|
306 | + { |
|
261 | 307 | return "409 Conflict"; |
262 | 308 | } |
263 | 309 | } |
@@ -307,17 +353,23 @@ discard block |
||
307 | 353 | $info["props"][] = self::mkprop("ishidden", Vfs::is_hidden($fspath)); |
308 | 354 | |
309 | 355 | // type and size (caller already made sure that path exists) |
310 | - if (is_dir($fspath)) { |
|
356 | + if (is_dir($fspath)) |
|
357 | + { |
|
311 | 358 | // directory (WebDAV collection) |
312 | 359 | $info['props'][] = self::mkprop ('resourcetype', array( |
313 | 360 | self::mkprop('collection', ''))); |
314 | 361 | $info['props'][] = self::mkprop ('getcontenttype', 'httpd/unix-directory'); |
315 | - } else { |
|
362 | + } |
|
363 | + else |
|
364 | + { |
|
316 | 365 | // plain file (WebDAV resource) |
317 | 366 | $info['props'][] = self::mkprop ('resourcetype', ''); |
318 | - if (Vfs::is_readable($path)) { |
|
367 | + if (Vfs::is_readable($path)) |
|
368 | + { |
|
319 | 369 | $info['props'][] = self::mkprop ('getcontenttype', Vfs::mime_content_type($path)); |
320 | - } else { |
|
370 | + } |
|
371 | + else |
|
372 | + { |
|
321 | 373 | error_log(__METHOD__."($path) $fspath is not readable!"); |
322 | 374 | $info['props'][] = self::mkprop ('getcontenttype', 'application/x-non-readable'); |
323 | 375 | } |
@@ -389,7 +441,10 @@ discard block |
||
389 | 441 | continue; |
390 | 442 | } |
391 | 443 | $_path = $info['path']; |
392 | - if (!$n && $info['path'] != '/' && substr($info['path'],-1) == '/') $_path = substr($info['path'],0,-1); |
|
444 | + if (!$n && $info['path'] != '/' && substr($info['path'],-1) == '/') |
|
445 | + { |
|
446 | + $_path = substr($info['path'],0,-1); |
|
447 | + } |
|
393 | 448 | |
394 | 449 | // need to encode path again, as $info['path'] is NOT encoded, but Vfs::(stat|propfind) require it |
395 | 450 | // otherwise pathes containing url special chars like ? or # will not stat |
@@ -428,16 +483,22 @@ discard block |
||
428 | 483 | $fileprops =& $files['files'][$path2n[$path]]['props']; |
429 | 484 | foreach($props as $prop) |
430 | 485 | { |
431 | - if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'][0] == '#') // eGW's customfields |
|
486 | + if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'][0] == '#') |
|
487 | + { |
|
488 | + // eGW's customfields |
|
432 | 489 | { |
433 | 490 | $prop['ns'] .= 'customfields/'; |
491 | + } |
|
434 | 492 | $prop['name'] = substr($prop['name'],1); |
435 | 493 | } |
436 | 494 | $fileprops[] = $prop; |
437 | 495 | } |
438 | 496 | } |
439 | 497 | } |
440 | - if ($this->debug) error_log(__METHOD__."() props=".array2string($files['files'])); |
|
498 | + if ($this->debug) |
|
499 | + { |
|
500 | + error_log(__METHOD__."() props=".array2string($files['files'])); |
|
501 | + } |
|
441 | 502 | return true; |
442 | 503 | } |
443 | 504 | |
@@ -489,7 +550,8 @@ discard block |
||
489 | 550 | { |
490 | 551 | $path = Api\Translation::convert($options['path'],'utf-8'); |
491 | 552 | |
492 | - foreach ($options['props'] as $key => $prop) { |
|
553 | + foreach ($options['props'] as $key => $prop) |
|
554 | + { |
|
493 | 555 | $attributes = array(); |
494 | 556 | switch($prop['ns']) |
495 | 557 | { |
@@ -506,7 +568,10 @@ discard block |
||
506 | 568 | //$attributes['created'] = strtotime($prop['val']); |
507 | 569 | //break; |
508 | 570 | default: |
509 | - if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden'; |
|
571 | + if (!Vfs::proppatch($path,array($prop))) |
|
572 | + { |
|
573 | + $options['props'][$key]['status'] = '403 Forbidden'; |
|
574 | + } |
|
510 | 575 | break; |
511 | 576 | } |
512 | 577 | break; |
@@ -535,7 +600,10 @@ discard block |
||
535 | 600 | case 'Win32LastAccessTime': |
536 | 601 | case 'Win32FileAttributes': // not sure what that is, it was always "00000000" |
537 | 602 | default: |
538 | - if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden'; |
|
603 | + if (!Vfs::proppatch($path,array($prop))) |
|
604 | + { |
|
605 | + $options['props'][$key]['status'] = '403 Forbidden'; |
|
606 | + } |
|
539 | 607 | break; |
540 | 608 | } |
541 | 609 | break; |
@@ -545,15 +613,24 @@ discard block |
||
545 | 613 | $prop['name'] = '#'.$prop['name']; |
546 | 614 | // fall through |
547 | 615 | default: |
548 | - if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden'; |
|
616 | + if (!Vfs::proppatch($path,array($prop))) |
|
617 | + { |
|
618 | + $options['props'][$key]['status'] = '403 Forbidden'; |
|
619 | + } |
|
549 | 620 | break; |
550 | 621 | } |
551 | - if ($this->debug) $props[] = '('.$prop['ns'].')'.$prop['name'].'='.$prop['val']; |
|
622 | + if ($this->debug) |
|
623 | + { |
|
624 | + $props[] = '('.$prop['ns'].')'.$prop['name'].'='.$prop['val']; |
|
625 | + } |
|
552 | 626 | } |
553 | 627 | if ($this->debug) |
554 | 628 | { |
555 | 629 | error_log(__METHOD__.": path=$options[path], props=".implode(', ',$props)); |
556 | - if ($attributes) error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n",' ',print_r($attributes,true))); |
|
630 | + if ($attributes) |
|
631 | + { |
|
632 | + error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n",' ',print_r($attributes,true))); |
|
633 | + } |
|
557 | 634 | } |
558 | 635 | |
559 | 636 | return ''; // this is as the filesystem example handler does it, no true or false ... |
@@ -567,7 +644,10 @@ discard block |
||
567 | 644 | */ |
568 | 645 | function LOCK(&$options) |
569 | 646 | { |
570 | - if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')'); |
|
647 | + if ($this->debug) |
|
648 | + { |
|
649 | + error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')'); |
|
650 | + } |
|
571 | 651 | // TODO recursive locks on directories not supported yet |
572 | 652 | if (is_dir($this->base . $options['path']) && !empty($options['depth'])) |
573 | 653 | { |
@@ -593,7 +673,10 @@ discard block |
||
593 | 673 | */ |
594 | 674 | function UNLOCK(&$options) |
595 | 675 | { |
596 | - if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')'); |
|
676 | + if ($this->debug) |
|
677 | + { |
|
678 | + error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')'); |
|
679 | + } |
|
597 | 680 | return Vfs::unlock($options['path'],$options['token']) ? '204 No Content' : '409 Conflict'; |
598 | 681 | } |
599 | 682 |
@@ -228,10 +228,10 @@ |
||
228 | 228 | * Important: PHP 5.0 introduced a bug that wasn't fixed until 5.1: the return value has to be the oposite! |
229 | 229 | * |
230 | 230 | * if(version_compare(PHP_VERSION,'5.0','>=') && version_compare(PHP_VERSION,'5.1','<')) |
231 | - * { |
|
231 | + * { |
|
232 | 232 | * $eof = !$eof; |
233 | 233 | * } |
234 | - * |
|
234 | + * |
|
235 | 235 | * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise |
236 | 236 | */ |
237 | 237 | function stream_eof ( ) |
@@ -131,7 +131,9 @@ discard block |
||
131 | 131 | $read_only = str_replace('b','',$mode) == 'r'; |
132 | 132 | |
133 | 133 | // check access rights, based on the eGW mount perms |
134 | - if (!($stat = $this->url_stat($url,0)) || $mode[0] == 'x') // file not found or file should NOT exist |
|
134 | + if (!($stat = $this->url_stat($url,0)) || $mode[0] == 'x') |
|
135 | + { |
|
136 | + // file not found or file should NOT exist |
|
135 | 137 | { |
136 | 138 | if ($mode[0] == 'r' || // does $mode require the file to exist (r,r+) |
137 | 139 | $mode[0] == 'x' || // or file should not exist, but does |
@@ -139,6 +141,7 @@ discard block |
||
139 | 141 | !Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=$this->url_stat($dir,0))) // or we are not allowed to create it |
140 | 142 | { |
141 | 143 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!"); |
144 | + } |
|
142 | 145 | if (!($options & STREAM_URL_STAT_QUIET)) |
143 | 146 | { |
144 | 147 | trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING); |
@@ -146,9 +149,12 @@ discard block |
||
146 | 149 | return false; |
147 | 150 | } |
148 | 151 | } |
149 | - elseif (!$read_only && !Vfs::check_access($url,Vfs::WRITABLE,$stat)) // we are not allowed to edit it |
|
152 | + elseif (!$read_only && !Vfs::check_access($url,Vfs::WRITABLE,$stat)) |
|
153 | + { |
|
154 | + // we are not allowed to edit it |
|
150 | 155 | { |
151 | 156 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be edited!"); |
157 | + } |
|
152 | 158 | if (!($options & STREAM_URL_STAT_QUIET)) |
153 | 159 | { |
154 | 160 | trigger_error(__METHOD__."($url,$mode,$options) file can not be edited!",E_USER_WARNING); |
@@ -157,7 +163,10 @@ discard block |
||
157 | 163 | } |
158 | 164 | if (!$read_only && self::deny_script($url)) |
159 | 165 | { |
160 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) permission denied, file is a script!"); |
|
166 | + if (self::LOG_LEVEL) |
|
167 | + { |
|
168 | + error_log(__METHOD__."($url,$mode,$options) permission denied, file is a script!"); |
|
169 | + } |
|
161 | 170 | if (!($options & STREAM_URL_STAT_QUIET)) |
162 | 171 | { |
163 | 172 | trigger_error(__METHOD__."($url,$mode,$options) permission denied, file is a script!",E_USER_WARNING); |
@@ -168,7 +177,10 @@ discard block |
||
168 | 177 | // open the "real" file |
169 | 178 | if (!($this->opened_stream = fopen($path=Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH)),$mode,$options))) |
170 | 179 | { |
171 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) fopen('$path','$mode',$options) returned false!"); |
|
180 | + if (self::LOG_LEVEL) |
|
181 | + { |
|
182 | + error_log(__METHOD__."($url,$mode,$options) fopen('$path','$mode',$options) returned false!"); |
|
183 | + } |
|
172 | 184 | return false; |
173 | 185 | } |
174 | 186 | $this->opened_stream_url = $url; |
@@ -313,7 +325,10 @@ discard block |
||
313 | 325 | // check access rights (file need to exist and directory need to be writable |
314 | 326 | if (!file_exists($path) || is_dir($path) || !($dir = Vfs::dirname($url)) || !Vfs::check_access($dir,Vfs::WRITABLE)) |
315 | 327 | { |
316 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!"); |
|
328 | + if (self::LOG_LEVEL) |
|
329 | + { |
|
330 | + error_log(__METHOD__."($url) permission denied!"); |
|
331 | + } |
|
317 | 332 | return false; // no permission or file does not exist |
318 | 333 | } |
319 | 334 | return unlink($path); |
@@ -339,17 +354,26 @@ discard block |
||
339 | 354 | // check access rights |
340 | 355 | if (!($from_stat = $this->url_stat($url_from,0)) || !($dir = Vfs::dirname($url_from)) || !Vfs::check_access($dir,Vfs::WRITABLE)) |
341 | 356 | { |
342 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $from[path] permission denied!"); |
|
357 | + if (self::LOG_LEVEL) |
|
358 | + { |
|
359 | + error_log(__METHOD__."($url_from,$url_to): $from[path] permission denied!"); |
|
360 | + } |
|
343 | 361 | return false; // no permission or file does not exist |
344 | 362 | } |
345 | 363 | if (!($to_dir = Vfs::dirname($url_to)) || !Vfs::check_access($to_dir,Vfs::WRITABLE,$to_dir_stat = $this->url_stat($to_dir,0))) |
346 | 364 | { |
347 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $to_dir permission denied!"); |
|
365 | + if (self::LOG_LEVEL) |
|
366 | + { |
|
367 | + error_log(__METHOD__."($url_from,$url_to): $to_dir permission denied!"); |
|
368 | + } |
|
348 | 369 | return false; // no permission or parent-dir does not exist |
349 | 370 | } |
350 | 371 | if (self::deny_script($url_to)) |
351 | 372 | { |
352 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to) permission denied, file is a script!"); |
|
373 | + if (self::LOG_LEVEL) |
|
374 | + { |
|
375 | + error_log(__METHOD__."($url_from,$url_to) permission denied, file is a script!"); |
|
376 | + } |
|
353 | 377 | return false; |
354 | 378 | } |
355 | 379 | // the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems |
@@ -358,13 +382,19 @@ discard block |
||
358 | 382 | ($to_stat['mime'] === self::DIR_MIME_TYPE) !== ($from_stat['mime'] === self::DIR_MIME_TYPE)) |
359 | 383 | { |
360 | 384 | $is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no'; |
361 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $to[path] is $is_dir directory!"); |
|
385 | + if (self::LOG_LEVEL) |
|
386 | + { |
|
387 | + error_log(__METHOD__."($url_to,$url_from) $to[path] is $is_dir directory!"); |
|
388 | + } |
|
362 | 389 | return false; // no permission or file does not exist |
363 | 390 | } |
364 | 391 | // if destination file already exists, delete it |
365 | 392 | if ($to_stat && !self::unlink($url_to)) |
366 | 393 | { |
367 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!"); |
|
394 | + if (self::LOG_LEVEL) |
|
395 | + { |
|
396 | + error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!"); |
|
397 | + } |
|
368 | 398 | return false; |
369 | 399 | } |
370 | 400 | return rename(Vfs::decodePath($from['path']),Vfs::decodePath($to['path'])); |
@@ -399,7 +429,10 @@ discard block |
||
399 | 429 | // check access rights (in real filesystem AND by mount perms) |
400 | 430 | if (!$parent_url || file_exists($path) || !file_exists($parent) || !is_writable($parent) || !Vfs::check_access($parent_url,Vfs::WRITABLE)) |
401 | 431 | { |
402 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!"); |
|
432 | + if (self::LOG_LEVEL) |
|
433 | + { |
|
434 | + error_log(__METHOD__."($url) permission denied!"); |
|
435 | + } |
|
403 | 436 | return false; |
404 | 437 | } |
405 | 438 | return mkdir($path, 0700, $recursive); // setting mode 0700 allows (only) apache to write into the dir |
@@ -425,7 +458,10 @@ discard block |
||
425 | 458 | // check access rights (in real filesystem AND by mount perms) |
426 | 459 | if (!file_exists($path) || !is_writable($parent) || !($dir = Vfs::dirname($url)) || !Vfs::check_access($dir, Vfs::WRITABLE)) |
427 | 460 | { |
428 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!"); |
|
461 | + if (self::LOG_LEVEL) |
|
462 | + { |
|
463 | + error_log(__METHOD__."($url) permission denied!"); |
|
464 | + } |
|
429 | 465 | return false; |
430 | 466 | } |
431 | 467 | return rmdir($path); |
@@ -448,7 +484,7 @@ discard block |
||
448 | 484 | function stream_metadata($url, $option, $value) |
449 | 485 | { |
450 | 486 | if ($option != STREAM_META_TOUCH) |
451 | - { |
|
487 | + { |
|
452 | 488 | return false; // not implemented / supported |
453 | 489 | } |
454 | 490 | |
@@ -458,7 +494,10 @@ discard block |
||
458 | 494 | // check access rights (in real filesystem AND by mount perms) |
459 | 495 | if (!file_exists($path) || !is_writable($parent) || !($dir = Vfs::dirname($url)) || !Vfs::check_access($dir, Vfs::WRITABLE)) |
460 | 496 | { |
461 | - if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!"); |
|
497 | + if (self::LOG_LEVEL) |
|
498 | + { |
|
499 | + error_log(__METHOD__."($url) permission denied!"); |
|
500 | + } |
|
462 | 501 | return false; |
463 | 502 | } |
464 | 503 | |
@@ -475,7 +514,10 @@ discard block |
||
475 | 514 | */ |
476 | 515 | function dir_opendir ( $url, $options ) |
477 | 516 | { |
478 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options)"); |
|
517 | + if (self::LOG_LEVEL > 1) |
|
518 | + { |
|
519 | + error_log(__METHOD__."($url,$options)"); |
|
520 | + } |
|
479 | 521 | |
480 | 522 | $this->opened_dir = null; |
481 | 523 | |
@@ -485,7 +527,10 @@ discard block |
||
485 | 527 | |
486 | 528 | if (!($this->opened_dir = opendir($path))) |
487 | 529 | { |
488 | - if (self::LOG_LEVEL > 0) error_log(__METHOD__."($url,$options) opendir('$path') failed!"); |
|
530 | + if (self::LOG_LEVEL > 0) |
|
531 | + { |
|
532 | + error_log(__METHOD__."($url,$options) opendir('$path') failed!"); |
|
533 | + } |
|
489 | 534 | return false; |
490 | 535 | } |
491 | 536 | return true; |
@@ -541,7 +586,10 @@ discard block |
||
541 | 586 | $stat['mode'] = $stat[2] = $stat['mode'] & ~0222; |
542 | 587 | } |
543 | 588 | } |
544 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags) path=$path, mount_mode=".sprintf('0%o',$mode).", mode=".sprintf('0%o',$stat['mode']).'='.Vfs::int2mode($stat['mode'])); |
|
589 | + if (self::LOG_LEVEL > 1) |
|
590 | + { |
|
591 | + error_log(__METHOD__."($url,$flags) path=$path, mount_mode=".sprintf('0%o',$mode).", mode=".sprintf('0%o',$stat['mode']).'='.Vfs::int2mode($stat['mode'])); |
|
592 | + } |
|
545 | 593 | return $stat; |
546 | 594 | } |
547 | 595 | |
@@ -562,14 +610,23 @@ discard block |
||
562 | 610 | |
563 | 611 | $ignore = !($file === false || // stop if no more dirs or |
564 | 612 | ($file != '.' && $file != '..' )); // file not . or .. |
565 | - if (self::LOG_LEVEL > 1 && $ignore) error_log(__METHOD__.'() ignoring '.array2string($file)); |
|
613 | + if (self::LOG_LEVEL > 1 && $ignore) |
|
614 | + { |
|
615 | + error_log(__METHOD__.'() ignoring '.array2string($file)); |
|
616 | + } |
|
566 | 617 | } |
567 | 618 | while ($ignore); |
568 | 619 | |
569 | 620 | // encode special chars messing up url's |
570 | - if ($file !== false) $file = Vfs::encodePathComponent($file); |
|
621 | + if ($file !== false) |
|
622 | + { |
|
623 | + $file = Vfs::encodePathComponent($file); |
|
624 | + } |
|
571 | 625 | |
572 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__.'() returning '.array2string($file)); |
|
626 | + if (self::LOG_LEVEL > 1) |
|
627 | + { |
|
628 | + error_log(__METHOD__.'() returning '.array2string($file)); |
|
629 | + } |
|
573 | 630 | |
574 | 631 | return $file; |
575 | 632 | } |
@@ -724,9 +781,17 @@ discard block |
||
724 | 781 | list($url,$query) = explode('?',$_url,2); |
725 | 782 | $get = null; |
726 | 783 | parse_str($query,$get); |
727 | - if (empty($get['url'])) return false; // no download url given for this mount-point |
|
784 | + if (empty($get['url'])) |
|
785 | + { |
|
786 | + return false; |
|
787 | + } |
|
788 | + // no download url given for this mount-point |
|
728 | 789 | |
729 | - if (!($mount_url = Vfs::mount_url($_url))) return false; // no mount url found, should not happen |
|
790 | + if (!($mount_url = Vfs::mount_url($_url))) |
|
791 | + { |
|
792 | + return false; |
|
793 | + } |
|
794 | + // no mount url found, should not happen |
|
730 | 795 | list($mount_url) = explode('?',$mount_url); |
731 | 796 | |
732 | 797 | $relpath = substr($url,strlen($mount_url)); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * Mime type of directories, the old vfs used 'Directory', while eg. WebDAV uses 'httpd/unix-directory' |
54 | 54 | */ |
55 | - const DIR_MIME_TYPE = Vfs::DIR_MIME_TYPE ; |
|
55 | + const DIR_MIME_TYPE = Vfs::DIR_MIME_TYPE; |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * mode-bits, which have to be set for files |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * mode-bits, which have to be set for directories |
63 | 63 | */ |
64 | - const MODE_DIR = 040000; |
|
64 | + const MODE_DIR = 040000; |
|
65 | 65 | |
66 | 66 | /** |
67 | 67 | * optional context param when opening the stream, null if no context passed |
@@ -124,50 +124,50 @@ discard block |
||
124 | 124 | * @param string $opened_path full path of the file/resource, if the open was successfull and STREAM_USE_PATH was set |
125 | 125 | * @return boolean true if the ressource was opened successful, otherwise false |
126 | 126 | */ |
127 | - function stream_open ( $url, $mode, $options, &$opened_path ) |
|
127 | + function stream_open($url, $mode, $options, &$opened_path) |
|
128 | 128 | { |
129 | - unset($opened_path); // not used, but required by interface |
|
129 | + unset($opened_path); // not used, but required by interface |
|
130 | 130 | |
131 | 131 | $this->opened_stream = $this->opened_stream_url = null; |
132 | - $read_only = str_replace('b','',$mode) == 'r'; |
|
132 | + $read_only = str_replace('b', '', $mode) == 'r'; |
|
133 | 133 | |
134 | 134 | // check access rights, based on the eGW mount perms |
135 | - if (!($stat = $this->url_stat($url,0)) || $mode[0] == 'x') // file not found or file should NOT exist |
|
135 | + if (!($stat = $this->url_stat($url, 0)) || $mode[0] == 'x') // file not found or file should NOT exist |
|
136 | 136 | { |
137 | - if ($mode[0] == 'r' || // does $mode require the file to exist (r,r+) |
|
138 | - $mode[0] == 'x' || // or file should not exist, but does |
|
137 | + if ($mode[0] == 'r' || // does $mode require the file to exist (r,r+) |
|
138 | + $mode[0] == 'x' || // or file should not exist, but does |
|
139 | 139 | !($dir = Vfs::dirname($url)) || |
140 | - !Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=$this->url_stat($dir,0))) // or we are not allowed to create it |
|
140 | + !Vfs::check_access($dir, Vfs::WRITABLE, $dir_stat = $this->url_stat($dir, 0))) // or we are not allowed to create it |
|
141 | 141 | { |
142 | 142 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!"); |
143 | - if (!($options & STREAM_URL_STAT_QUIET)) |
|
143 | + if (!($options&STREAM_URL_STAT_QUIET)) |
|
144 | 144 | { |
145 | - trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING); |
|
145 | + trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!", E_USER_WARNING); |
|
146 | 146 | } |
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | } |
150 | - elseif (!$read_only && !Vfs::check_access($url,Vfs::WRITABLE,$stat)) // we are not allowed to edit it |
|
150 | + elseif (!$read_only && !Vfs::check_access($url, Vfs::WRITABLE, $stat)) // we are not allowed to edit it |
|
151 | 151 | { |
152 | 152 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be edited!"); |
153 | - if (!($options & STREAM_URL_STAT_QUIET)) |
|
153 | + if (!($options&STREAM_URL_STAT_QUIET)) |
|
154 | 154 | { |
155 | - trigger_error(__METHOD__."($url,$mode,$options) file can not be edited!",E_USER_WARNING); |
|
155 | + trigger_error(__METHOD__."($url,$mode,$options) file can not be edited!", E_USER_WARNING); |
|
156 | 156 | } |
157 | 157 | return false; |
158 | 158 | } |
159 | 159 | if (!$read_only && self::deny_script($url)) |
160 | 160 | { |
161 | 161 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) permission denied, file is a script!"); |
162 | - if (!($options & STREAM_URL_STAT_QUIET)) |
|
162 | + if (!($options&STREAM_URL_STAT_QUIET)) |
|
163 | 163 | { |
164 | - trigger_error(__METHOD__."($url,$mode,$options) permission denied, file is a script!",E_USER_WARNING); |
|
164 | + trigger_error(__METHOD__."($url,$mode,$options) permission denied, file is a script!", E_USER_WARNING); |
|
165 | 165 | } |
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | |
169 | 169 | // open the "real" file |
170 | - if (!($this->opened_stream = fopen($path=Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH)),$mode,$options))) |
|
170 | + if (!($this->opened_stream = fopen($path = Vfs::decodePath(Vfs::parse_url($url, PHP_URL_PATH)), $mode, $options))) |
|
171 | 171 | { |
172 | 172 | if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) fopen('$path','$mode',$options) returned false!"); |
173 | 173 | return false; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * |
183 | 183 | * You must release any resources that were locked or allocated by the stream. |
184 | 184 | */ |
185 | - function stream_close ( ) |
|
185 | + function stream_close( ) |
|
186 | 186 | { |
187 | 187 | $ret = fclose($this->opened_stream); |
188 | 188 | |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | * @param int $count |
203 | 203 | * @return string/false up to count bytes read or false on EOF |
204 | 204 | */ |
205 | - function stream_read ( $count ) |
|
205 | + function stream_read($count) |
|
206 | 206 | { |
207 | - return fread($this->opened_stream,$count); |
|
207 | + return fread($this->opened_stream, $count); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | * @param string $data |
219 | 219 | * @return integer |
220 | 220 | */ |
221 | - function stream_write ( $data ) |
|
221 | + function stream_write($data) |
|
222 | 222 | { |
223 | - return fwrite($this->opened_stream,$data); |
|
223 | + return fwrite($this->opened_stream, $data); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise |
237 | 237 | */ |
238 | - function stream_eof ( ) |
|
238 | + function stream_eof( ) |
|
239 | 239 | { |
240 | 240 | return feof($this->opened_stream); |
241 | 241 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * |
246 | 246 | * @return integer current read/write position of the stream |
247 | 247 | */ |
248 | - function stream_tell ( ) |
|
248 | + function stream_tell( ) |
|
249 | 249 | { |
250 | 250 | return ftell($this->opened_stream); |
251 | 251 | } |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | * SEEK_END - 2 - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.) |
263 | 263 | * @return boolean TRUE if the position was updated, FALSE otherwise. |
264 | 264 | */ |
265 | - function stream_seek ( $offset, $whence ) |
|
265 | + function stream_seek($offset, $whence) |
|
266 | 266 | { |
267 | - return !fseek($this->opened_stream,$offset,$whence); // fseek returns 0 on success and -1 on failure |
|
267 | + return !fseek($this->opened_stream, $offset, $whence); // fseek returns 0 on success and -1 on failure |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored. |
276 | 276 | */ |
277 | - function stream_flush ( ) |
|
277 | + function stream_flush( ) |
|
278 | 278 | { |
279 | 279 | return fflush($this->opened_stream); |
280 | 280 | } |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | * |
294 | 294 | * @return array containing the same values as appropriate for the stream. |
295 | 295 | */ |
296 | - function stream_stat ( ) |
|
296 | + function stream_stat( ) |
|
297 | 297 | { |
298 | - return $this->url_stat($this->opened_stream_url,0); |
|
298 | + return $this->url_stat($this->opened_stream_url, 0); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -307,15 +307,15 @@ discard block |
||
307 | 307 | * @param string $url |
308 | 308 | * @return boolean TRUE on success or FALSE on failure |
309 | 309 | */ |
310 | - function unlink ( $url ) |
|
310 | + function unlink($url) |
|
311 | 311 | { |
312 | - $path = Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH)); |
|
312 | + $path = Vfs::decodePath(Vfs::parse_url($url, PHP_URL_PATH)); |
|
313 | 313 | |
314 | 314 | // check access rights (file need to exist and directory need to be writable |
315 | - if (!file_exists($path) || is_dir($path) || !($dir = Vfs::dirname($url)) || !Vfs::check_access($dir,Vfs::WRITABLE)) |
|
315 | + if (!file_exists($path) || is_dir($path) || !($dir = Vfs::dirname($url)) || !Vfs::check_access($dir, Vfs::WRITABLE)) |
|
316 | 316 | { |
317 | 317 | if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!"); |
318 | - return false; // no permission or file does not exist |
|
318 | + return false; // no permission or file does not exist |
|
319 | 319 | } |
320 | 320 | return unlink($path); |
321 | 321 | } |
@@ -332,21 +332,21 @@ discard block |
||
332 | 332 | * @param string $url_to |
333 | 333 | * @return boolean TRUE on success or FALSE on failure |
334 | 334 | */ |
335 | - function rename ( $url_from, $url_to ) |
|
335 | + function rename($url_from, $url_to) |
|
336 | 336 | { |
337 | 337 | $from = Vfs::parse_url($url_from); |
338 | 338 | $to = Vfs::parse_url($url_to); |
339 | 339 | |
340 | 340 | // check access rights |
341 | - if (!($from_stat = $this->url_stat($url_from,0)) || !($dir = Vfs::dirname($url_from)) || !Vfs::check_access($dir,Vfs::WRITABLE)) |
|
341 | + if (!($from_stat = $this->url_stat($url_from, 0)) || !($dir = Vfs::dirname($url_from)) || !Vfs::check_access($dir, Vfs::WRITABLE)) |
|
342 | 342 | { |
343 | 343 | if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $from[path] permission denied!"); |
344 | - return false; // no permission or file does not exist |
|
344 | + return false; // no permission or file does not exist |
|
345 | 345 | } |
346 | - if (!($to_dir = Vfs::dirname($url_to)) || !Vfs::check_access($to_dir,Vfs::WRITABLE,$to_dir_stat = $this->url_stat($to_dir,0))) |
|
346 | + if (!($to_dir = Vfs::dirname($url_to)) || !Vfs::check_access($to_dir, Vfs::WRITABLE, $to_dir_stat = $this->url_stat($to_dir, 0))) |
|
347 | 347 | { |
348 | 348 | if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $to_dir permission denied!"); |
349 | - return false; // no permission or parent-dir does not exist |
|
349 | + return false; // no permission or parent-dir does not exist |
|
350 | 350 | } |
351 | 351 | if (self::deny_script($url_to)) |
352 | 352 | { |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | } |
356 | 356 | // the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems |
357 | 357 | // for our vfs too, we abort here with an error, like the filesystem one does |
358 | - if (($to_stat = $this->url_stat($to['path'],0)) && |
|
358 | + if (($to_stat = $this->url_stat($to['path'], 0)) && |
|
359 | 359 | ($to_stat['mime'] === self::DIR_MIME_TYPE) !== ($from_stat['mime'] === self::DIR_MIME_TYPE)) |
360 | 360 | { |
361 | 361 | $is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no'; |
362 | 362 | if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $to[path] is $is_dir directory!"); |
363 | - return false; // no permission or file does not exist |
|
363 | + return false; // no permission or file does not exist |
|
364 | 364 | } |
365 | 365 | // if destination file already exists, delete it |
366 | 366 | if ($to_stat && !self::unlink($url_to)) |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!"); |
369 | 369 | return false; |
370 | 370 | } |
371 | - return rename(Vfs::decodePath($from['path']),Vfs::decodePath($to['path'])); |
|
371 | + return rename(Vfs::decodePath($from['path']), Vfs::decodePath($to['path'])); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -382,12 +382,12 @@ discard block |
||
382 | 382 | * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE |
383 | 383 | * @return boolean TRUE on success or FALSE on failure |
384 | 384 | */ |
385 | - function mkdir ( $url, $mode, $options ) |
|
385 | + function mkdir($url, $mode, $options) |
|
386 | 386 | { |
387 | - unset($mode); // not used, but required by interface |
|
387 | + unset($mode); // not used, but required by interface |
|
388 | 388 | |
389 | - $path = Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH)); |
|
390 | - $recursive = (bool)($options & STREAM_MKDIR_RECURSIVE); |
|
389 | + $path = Vfs::decodePath(Vfs::parse_url($url, PHP_URL_PATH)); |
|
390 | + $recursive = (bool)($options&STREAM_MKDIR_RECURSIVE); |
|
391 | 391 | |
392 | 392 | // find the real parent (might be more then one level if $recursive!) |
393 | 393 | do { |
@@ -398,12 +398,12 @@ discard block |
||
398 | 398 | //echo __METHOD__."($url,$mode,$options) path=$path, recursive=$recursive, parent=$parent, Vfs::check_access(parent_url=$parent_url,Vfs::WRITABLE)=".(int)Vfs::check_access($parent_url,Vfs::WRITABLE)."\n"; |
399 | 399 | |
400 | 400 | // check access rights (in real filesystem AND by mount perms) |
401 | - if (!$parent_url || file_exists($path) || !file_exists($parent) || !is_writable($parent) || !Vfs::check_access($parent_url,Vfs::WRITABLE)) |
|
401 | + if (!$parent_url || file_exists($path) || !file_exists($parent) || !is_writable($parent) || !Vfs::check_access($parent_url, Vfs::WRITABLE)) |
|
402 | 402 | { |
403 | 403 | if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!"); |
404 | 404 | return false; |
405 | 405 | } |
406 | - return mkdir($path, 0700, $recursive); // setting mode 0700 allows (only) apache to write into the dir |
|
406 | + return mkdir($path, 0700, $recursive); // setting mode 0700 allows (only) apache to write into the dir |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -416,11 +416,11 @@ discard block |
||
416 | 416 | * @param int $options Possible values include STREAM_REPORT_ERRORS. |
417 | 417 | * @return boolean TRUE on success or FALSE on failure. |
418 | 418 | */ |
419 | - function rmdir ( $url, $options ) |
|
419 | + function rmdir($url, $options) |
|
420 | 420 | { |
421 | - unset($options); // not used, but required by interface |
|
421 | + unset($options); // not used, but required by interface |
|
422 | 422 | |
423 | - $path = Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH)); |
|
423 | + $path = Vfs::decodePath(Vfs::parse_url($url, PHP_URL_PATH)); |
|
424 | 424 | $parent = dirname($path); |
425 | 425 | |
426 | 426 | // check access rights (in real filesystem AND by mount perms) |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | { |
451 | 451 | if ($option != STREAM_META_TOUCH) |
452 | 452 | { |
453 | - return false; // not implemented / supported |
|
453 | + return false; // not implemented / supported |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | $path = Vfs::decodePath(Vfs::parse_url($url, PHP_URL_PATH)); |
@@ -474,13 +474,13 @@ discard block |
||
474 | 474 | * @param int $options |
475 | 475 | * @return booelan |
476 | 476 | */ |
477 | - function dir_opendir ( $url, $options ) |
|
477 | + function dir_opendir($url, $options) |
|
478 | 478 | { |
479 | 479 | if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options)"); |
480 | 480 | |
481 | 481 | $this->opened_dir = null; |
482 | 482 | |
483 | - $path = Vfs::decodePath(Vfs::parse_url($this->opened_dir_url = $url,PHP_URL_PATH)); |
|
483 | + $path = Vfs::decodePath(Vfs::parse_url($this->opened_dir_url = $url, PHP_URL_PATH)); |
|
484 | 484 | |
485 | 485 | // ToDo: check access rights |
486 | 486 | |
@@ -518,31 +518,31 @@ discard block |
||
518 | 518 | * stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper! |
519 | 519 | * @return array |
520 | 520 | */ |
521 | - function url_stat ( $url, $flags ) |
|
521 | + function url_stat($url, $flags) |
|
522 | 522 | { |
523 | 523 | $parts = Vfs::parse_url($url); |
524 | 524 | $path = Vfs::decodePath($parts['path']); |
525 | 525 | |
526 | - $stat = @stat($path); // suppressed the stat failed warnings |
|
526 | + $stat = @stat($path); // suppressed the stat failed warnings |
|
527 | 527 | |
528 | 528 | if ($stat) |
529 | 529 | { |
530 | 530 | // set owner, group and mode from mount options |
531 | 531 | $uid = $gid = $mode = null; |
532 | - if (!self::parse_query($parts['query'],$uid,$gid,$mode)) |
|
532 | + if (!self::parse_query($parts['query'], $uid, $gid, $mode)) |
|
533 | 533 | { |
534 | 534 | return false; |
535 | 535 | } |
536 | 536 | $stat['uid'] = $stat[4] = $uid; |
537 | 537 | $stat['gid'] = $stat[5] = $gid; |
538 | - $stat['mode'] = $stat[2] = $stat['mode'] & self::MODE_DIR ? self::MODE_DIR | $mode : self::MODE_FILE | ($mode & ~0111); |
|
538 | + $stat['mode'] = $stat[2] = $stat['mode']&self::MODE_DIR ? self::MODE_DIR|$mode : self::MODE_FILE|($mode&~0111); |
|
539 | 539 | // write rights also depend on the write rights of the webserver |
540 | 540 | if (!is_writable($path)) |
541 | 541 | { |
542 | - $stat['mode'] = $stat[2] = $stat['mode'] & ~0222; |
|
542 | + $stat['mode'] = $stat[2] = $stat['mode']&~0222; |
|
543 | 543 | } |
544 | 544 | } |
545 | - if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags) path=$path, mount_mode=".sprintf('0%o',$mode).", mode=".sprintf('0%o',$stat['mode']).'='.Vfs::int2mode($stat['mode'])); |
|
545 | + if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags) path=$path, mount_mode=".sprintf('0%o', $mode).", mode=".sprintf('0%o', $stat['mode']).'='.Vfs::int2mode($stat['mode'])); |
|
546 | 546 | return $stat; |
547 | 547 | } |
548 | 548 | |
@@ -556,13 +556,13 @@ discard block |
||
556 | 556 | * |
557 | 557 | * @return string |
558 | 558 | */ |
559 | - function dir_readdir ( ) |
|
559 | + function dir_readdir( ) |
|
560 | 560 | { |
561 | 561 | do { |
562 | 562 | $file = readdir($this->opened_dir); |
563 | 563 | |
564 | - $ignore = !($file === false || // stop if no more dirs or |
|
565 | - ($file != '.' && $file != '..' )); // file not . or .. |
|
564 | + $ignore = !($file === false || // stop if no more dirs or |
|
565 | + ($file != '.' && $file != '..')); // file not . or .. |
|
566 | 566 | if (self::LOG_LEVEL > 1 && $ignore) error_log(__METHOD__.'() ignoring '.array2string($file)); |
567 | 567 | } |
568 | 568 | while ($ignore); |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | * |
584 | 584 | * @return boolean |
585 | 585 | */ |
586 | - function dir_rewinddir ( ) |
|
586 | + function dir_rewinddir( ) |
|
587 | 587 | { |
588 | 588 | return rewinddir($this->opened_dir); |
589 | 589 | } |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | * |
596 | 596 | * @return boolean |
597 | 597 | */ |
598 | - function dir_closedir ( ) |
|
598 | + function dir_closedir( ) |
|
599 | 599 | { |
600 | 600 | closedir($this->opened_dir); |
601 | 601 | |
@@ -613,18 +613,18 @@ discard block |
||
613 | 613 | * @param int &$mode default if not set is 05 r-x for others |
614 | 614 | * @return boolean true on successfull parse, false on error |
615 | 615 | */ |
616 | - static function parse_query($query,&$uid,&$gid,&$mode) |
|
616 | + static function parse_query($query, &$uid, &$gid, &$mode) |
|
617 | 617 | { |
618 | 618 | $params = null; |
619 | - parse_str(is_array($query) ? $query['query'] : $query,$params); |
|
619 | + parse_str(is_array($query) ? $query['query'] : $query, $params); |
|
620 | 620 | |
621 | 621 | // setting the default perms root.root r-x for other |
622 | 622 | $uid = $gid = 0; |
623 | 623 | $mode = 05; |
624 | 624 | |
625 | - foreach($params as $name => $value) |
|
625 | + foreach ($params as $name => $value) |
|
626 | 626 | { |
627 | - switch($name) |
|
627 | + switch ($name) |
|
628 | 628 | { |
629 | 629 | case 'user': |
630 | 630 | if (!is_numeric($value)) |
@@ -633,10 +633,10 @@ discard block |
||
633 | 633 | { |
634 | 634 | $value = 0; |
635 | 635 | } |
636 | - elseif (($value = $GLOBALS['egw']->accounts->name2id($value,'account_lid','u')) === false) |
|
636 | + elseif (($value = $GLOBALS['egw']->accounts->name2id($value, 'account_lid', 'u')) === false) |
|
637 | 637 | { |
638 | 638 | error_log(__METHOD__."('$query') unknown user-name '$value'!"); |
639 | - return false; // wrong user-name |
|
639 | + return false; // wrong user-name |
|
640 | 640 | } |
641 | 641 | } |
642 | 642 | // fall-through |
@@ -655,12 +655,12 @@ discard block |
||
655 | 655 | { |
656 | 656 | $value = 0; |
657 | 657 | } |
658 | - elseif (($value = $GLOBALS['egw']->accounts->name2id($value,'account_lid','g')) === false) |
|
658 | + elseif (($value = $GLOBALS['egw']->accounts->name2id($value, 'account_lid', 'g')) === false) |
|
659 | 659 | { |
660 | 660 | error_log(__METHOD__."('$query') unknown group-name '$value'!"); |
661 | - return false; // wrong group-name |
|
661 | + return false; // wrong group-name |
|
662 | 662 | } |
663 | - $value = -$value; // vfs uses positiv gid's! |
|
663 | + $value = -$value; // vfs uses positiv gid's! |
|
664 | 664 | } |
665 | 665 | // fall-through |
666 | 666 | case 'gid': |
@@ -699,9 +699,9 @@ discard block |
||
699 | 699 | { |
700 | 700 | $parts = Vfs::parse_url($url); |
701 | 701 | $get = null; |
702 | - parse_str($parts['query'],$get); |
|
702 | + parse_str($parts['query'], $get); |
|
703 | 703 | |
704 | - $deny = !$get['exec'] && preg_match(self::SCRIPT_EXTENSIONS_PREG,$parts['path']); |
|
704 | + $deny = !$get['exec'] && preg_match(self::SCRIPT_EXTENSIONS_PREG, $parts['path']); |
|
705 | 705 | |
706 | 706 | if (self::LOG_LEVEL > 1 || self::LOG_LEVEL > 0 && $deny) |
707 | 707 | { |
@@ -721,21 +721,21 @@ discard block |
||
721 | 721 | * @todo get $force_download working through webdav |
722 | 722 | * @return string|false string with full download url or false to use default webdav.php url |
723 | 723 | */ |
724 | - static function download_url($_url,$force_download=false) |
|
724 | + static function download_url($_url, $force_download = false) |
|
725 | 725 | { |
726 | - unset($force_download); // not used, but required by interface |
|
726 | + unset($force_download); // not used, but required by interface |
|
727 | 727 | |
728 | - list($url,$query) = explode('?',$_url,2); |
|
728 | + list($url, $query) = explode('?', $_url, 2); |
|
729 | 729 | $get = null; |
730 | - parse_str($query,$get); |
|
731 | - if (empty($get['url'])) return false; // no download url given for this mount-point |
|
730 | + parse_str($query, $get); |
|
731 | + if (empty($get['url'])) return false; // no download url given for this mount-point |
|
732 | 732 | |
733 | - if (!($mount_url = Vfs::mount_url($_url))) return false; // no mount url found, should not happen |
|
734 | - list($mount_url) = explode('?',$mount_url); |
|
733 | + if (!($mount_url = Vfs::mount_url($_url))) return false; // no mount url found, should not happen |
|
734 | + list($mount_url) = explode('?', $mount_url); |
|
735 | 735 | |
736 | - $relpath = substr($url,strlen($mount_url)); |
|
736 | + $relpath = substr($url, strlen($mount_url)); |
|
737 | 737 | |
738 | - return Api\Framework::getUrl(Vfs::concat($get['url'],$relpath)); |
|
738 | + return Api\Framework::getUrl(Vfs::concat($get['url'], $relpath)); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | /** |