@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * actions that user backends can define |
39 | 39 | */ |
40 | - const CREATE_USER = 1; // 1 << 0 |
|
41 | - const SET_PASSWORD = 16; // 1 << 4 |
|
42 | - const CHECK_PASSWORD = 256; // 1 << 8 |
|
43 | - const GET_HOME = 4096; // 1 << 12 |
|
44 | - const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
45 | - const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
46 | - const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
47 | - const COUNT_USERS = 268435456; // 1 << 28 |
|
40 | + const CREATE_USER = 1; // 1 << 0 |
|
41 | + const SET_PASSWORD = 16; // 1 << 4 |
|
42 | + const CHECK_PASSWORD = 256; // 1 << 8 |
|
43 | + const GET_HOME = 4096; // 1 << 12 |
|
44 | + const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
45 | + const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
46 | + const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
47 | + const COUNT_USERS = 268435456; // 1 << 28 |
|
48 | 48 | |
49 | 49 | protected $possibleActions = array( |
50 | 50 | self::CREATE_USER => 'createUser', |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function getSupportedActions() { |
68 | 68 | $actions = 0; |
69 | - foreach($this->possibleActions AS $action => $methodName) { |
|
70 | - if(method_exists($this, $methodName)) { |
|
69 | + foreach ($this->possibleActions AS $action => $methodName) { |
|
70 | + if (method_exists($this, $methodName)) { |
|
71 | 71 | $actions |= $action; |
72 | 72 | } |
73 | 73 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * compared with self::CREATE_USER etc. |
85 | 85 | */ |
86 | 86 | public function implementsActions($actions) { |
87 | - return (bool)($this->getSupportedActions() & $actions); |
|
87 | + return (bool) ($this->getSupportedActions() & $actions); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * Deletes a user |
96 | 96 | */ |
97 | - public function deleteUser( $uid ) { |
|
97 | + public function deleteUser($uid) { |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
149 | 149 | $displayNames = array(); |
150 | 150 | $users = $this->getUsers($search, $limit, $offset); |
151 | - foreach ( $users as $user) { |
|
151 | + foreach ($users as $user) { |
|
152 | 152 | $displayNames[$user] = $user; |
153 | 153 | } |
154 | 154 | return $displayNames; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | try { |
65 | 65 | return new \DateTimeZone($timeZone); |
66 | 66 | } catch (\Exception $e) { |
67 | - \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG); |
|
67 | + \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "'.$timeZone."'", \OCP\Util::DEBUG); |
|
68 | 68 | return new \DateTimeZone($this->getDefaultTimeZone()); |
69 | 69 | } |
70 | 70 | } |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | // so a positive offset means negative timeZone |
86 | 86 | // and the other way around. |
87 | 87 | if ($offset > 0) { |
88 | - $timeZone = 'Etc/GMT-' . $offset; |
|
88 | + $timeZone = 'Etc/GMT-'.$offset; |
|
89 | 89 | } else { |
90 | - $timeZone = 'Etc/GMT+' . abs($offset); |
|
90 | + $timeZone = 'Etc/GMT+'.abs($offset); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return new \DateTimeZone($timeZone); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | // No timezone found, fallback to UTC |
112 | - \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG); |
|
112 | + \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "'.$offset."'", \OCP\Util::DEBUG); |
|
113 | 113 | return new \DateTimeZone($this->getDefaultTimeZone()); |
114 | 114 | } |
115 | 115 | } |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | * @return array An array of Tag objects. |
51 | 51 | */ |
52 | 52 | public function loadTags($owners, $type) { |
53 | - if(!is_array($owners)) { |
|
53 | + if (!is_array($owners)) { |
|
54 | 54 | $owners = array($owners); |
55 | 55 | } |
56 | 56 | |
57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
58 | + . 'WHERE `uid` IN ('.str_repeat('?,', count($owners) - 1).'?) AND `type` = ? ORDER BY `category`'; |
|
59 | 59 | return $this->findEntities($sql, array_merge($owners, array($type))); |
60 | 60 | } |
61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return bool |
67 | 67 | */ |
68 | 68 | public function tagExists($tag) { |
69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
70 | 70 | . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
71 | 71 | try { |
72 | 72 | $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @todo migrate existing database columns to the correct names |
63 | 63 | * to be able to drop this direct mapping |
64 | 64 | */ |
65 | - public function columnToProperty($columnName){ |
|
65 | + public function columnToProperty($columnName) { |
|
66 | 66 | if ($columnName === 'category') { |
67 | 67 | return 'name'; |
68 | 68 | } elseif ($columnName === 'uid') { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param string $property the name of the property |
79 | 79 | * @return string the column name |
80 | 80 | */ |
81 | - public function propertyToColumn($property){ |
|
81 | + public function propertyToColumn($property) { |
|
82 | 82 | if ($property === 'name') { |
83 | 83 | return 'category'; |
84 | 84 | } elseif ($property === 'owner') { |
@@ -52,7 +52,7 @@ |
||
52 | 52 | */ |
53 | 53 | public function generate($name, $parameters = array(), $absolute = false) { |
54 | 54 | asort($parameters); |
55 | - $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
55 | + $key = $this->context->getHost().'#'.$this->context->getBaseUrl().$name.sha1(json_encode($parameters)).intval($absolute); |
|
56 | 56 | $cachedKey = $this->cache->get($key); |
57 | 57 | if ($cachedKey) { |
58 | 58 | return $cachedKey; |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | public function search($pattern, $searchProperties = array(), $options = array()) { |
42 | 42 | $this->loadAddressBooks(); |
43 | 43 | $result = array(); |
44 | - foreach($this->addressBooks as $addressBook) { |
|
44 | + foreach ($this->addressBooks as $addressBook) { |
|
45 | 45 | $r = $addressBook->search($pattern, $searchProperties, $options); |
46 | 46 | $contacts = array(); |
47 | - foreach($r as $c){ |
|
47 | + foreach ($r as $c) { |
|
48 | 48 | $c['addressbook-key'] = $addressBook->getKey(); |
49 | 49 | $contacts[] = $c; |
50 | 50 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | public function getAddressBooks() { |
125 | 125 | $this->loadAddressBooks(); |
126 | 126 | $result = array(); |
127 | - foreach($this->addressBooks as $addressBook) { |
|
127 | + foreach ($this->addressBooks as $addressBook) { |
|
128 | 128 | $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
129 | 129 | } |
130 | 130 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | protected function loadAddressBooks() |
183 | 183 | { |
184 | - foreach($this->addressBookLoaders as $callable) { |
|
184 | + foreach ($this->addressBookLoaders as $callable) { |
|
185 | 185 | $callable($this); |
186 | 186 | } |
187 | 187 | $this->addressBookLoaders = array(); |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | $parts = explode('/', $path); |
102 | 102 | $folder = $tmpBase; |
103 | 103 | foreach ($parts as $part) { |
104 | - $folder .= '/' . $part; |
|
104 | + $folder .= '/'.$part; |
|
105 | 105 | if (!is_dir($folder)) { |
106 | 106 | mkdir($folder); |
107 | 107 | } |
108 | 108 | } |
109 | - $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase); |
|
110 | - rmdir($tmpBase . $path); |
|
109 | + $result = $this->tar->addModify(array($tmpBase.$path), '', $tmpBase); |
|
110 | + rmdir($tmpBase.$path); |
|
111 | 111 | $this->fileList = false; |
112 | 112 | $this->cachedHeaders = false; |
113 | 113 | return $result; |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | //no proper way to delete, rename entire archive, rename file and remake archive |
145 | 145 | $tmp = \OCP\Files::tmpFolder(); |
146 | 146 | $this->tar->extract($tmp); |
147 | - rename($tmp . $source, $tmp . $dest); |
|
147 | + rename($tmp.$source, $tmp.$dest); |
|
148 | 148 | $this->tar = null; |
149 | 149 | unlink($this->path); |
150 | 150 | $types = array(null, 'gz', 'bz'); |
151 | 151 | $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
152 | - $this->tar->createModify(array($tmp), '', $tmp . '/'); |
|
152 | + $this->tar->createModify(array($tmp), '', $tmp.'/'); |
|
153 | 153 | $this->fileList = false; |
154 | 154 | $this->cachedHeaders = false; |
155 | 155 | return true; |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | } |
165 | 165 | foreach ($this->cachedHeaders as $header) { |
166 | 166 | if ($file == $header['filename'] |
167 | - or $file . '/' == $header['filename'] |
|
168 | - or '/' . $file . '/' == $header['filename'] |
|
169 | - or '/' . $file == $header['filename'] |
|
167 | + or $file.'/' == $header['filename'] |
|
168 | + or '/'.$file.'/' == $header['filename'] |
|
169 | + or '/'.$file == $header['filename'] |
|
170 | 170 | ) { |
171 | 171 | return $header; |
172 | 172 | } |
@@ -265,13 +265,13 @@ discard block |
||
265 | 265 | if (!$this->fileExists($path)) { |
266 | 266 | return false; |
267 | 267 | } |
268 | - if ($this->fileExists('/' . $path)) { |
|
269 | - $success = $this->tar->extractList(array('/' . $path), $tmp); |
|
268 | + if ($this->fileExists('/'.$path)) { |
|
269 | + $success = $this->tar->extractList(array('/'.$path), $tmp); |
|
270 | 270 | } else { |
271 | 271 | $success = $this->tar->extractList(array($path), $tmp); |
272 | 272 | } |
273 | 273 | if ($success) { |
274 | - rename($tmp . $path, $dest); |
|
274 | + rename($tmp.$path, $dest); |
|
275 | 275 | } |
276 | 276 | \OCP\Files::rmdirr($tmp); |
277 | 277 | return $success; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | */ |
296 | 296 | function fileExists($path) { |
297 | 297 | $files = $this->getFiles(); |
298 | - if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) { |
|
298 | + if ((array_search($path, $files) !== false) or (array_search($path.'/', $files) !== false)) { |
|
299 | 299 | return true; |
300 | 300 | } else { |
301 | 301 | $folderPath = $path; |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | } |
311 | 311 | } |
312 | 312 | if ($path[0] != '/') { //not all programs agree on the use of a leading / |
313 | - return $this->fileExists('/' . $path); |
|
313 | + return $this->fileExists('/'.$path); |
|
314 | 314 | } else { |
315 | 315 | return false; |
316 | 316 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | //no proper way to delete, extract entire archive, delete file and remake archive |
332 | 332 | $tmp = \OCP\Files::tmpFolder(); |
333 | 333 | $this->tar->extract($tmp); |
334 | - \OCP\Files::rmdirr($tmp . $path); |
|
334 | + \OCP\Files::rmdirr($tmp.$path); |
|
335 | 335 | $this->tar = null; |
336 | 336 | unlink($this->path); |
337 | 337 | $this->reopen(); |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | return fopen($tmpFile, $mode); |
363 | 363 | } else { |
364 | 364 | $handle = fopen($tmpFile, $mode); |
365 | - return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) { |
|
365 | + return CallbackWrapper::wrap($handle, null, null, function() use ($path, $tmpFile) { |
|
366 | 366 | $this->writeBack($tmpFile, $path); |
367 | 367 | }); |
368 | 368 | } |
@@ -33,21 +33,21 @@ discard block |
||
33 | 33 | |
34 | 34 | use Icewind\Streams\CallbackWrapper; |
35 | 35 | |
36 | -class ZIP extends Archive{ |
|
36 | +class ZIP extends Archive { |
|
37 | 37 | /** |
38 | 38 | * @var \ZipArchive zip |
39 | 39 | */ |
40 | - private $zip=null; |
|
40 | + private $zip = null; |
|
41 | 41 | private $path; |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @param string $source |
45 | 45 | */ |
46 | 46 | function __construct($source) { |
47 | - $this->path=$source; |
|
48 | - $this->zip=new \ZipArchive(); |
|
49 | - if($this->zip->open($source, \ZipArchive::CREATE)) { |
|
50 | - }else{ |
|
47 | + $this->path = $source; |
|
48 | + $this->zip = new \ZipArchive(); |
|
49 | + if ($this->zip->open($source, \ZipArchive::CREATE)) { |
|
50 | + } else { |
|
51 | 51 | \OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, \OCP\Util::WARN); |
52 | 52 | } |
53 | 53 | } |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | * @param string $source either a local file or string data |
66 | 66 | * @return bool |
67 | 67 | */ |
68 | - function addFile($path, $source='') { |
|
69 | - if($source and $source[0]=='/' and file_exists($source)) { |
|
70 | - $result=$this->zip->addFile($source, $path); |
|
71 | - }else{ |
|
72 | - $result=$this->zip->addFromString($path, $source); |
|
68 | + function addFile($path, $source = '') { |
|
69 | + if ($source and $source[0] == '/' and file_exists($source)) { |
|
70 | + $result = $this->zip->addFile($source, $path); |
|
71 | + } else { |
|
72 | + $result = $this->zip->addFromString($path, $source); |
|
73 | 73 | } |
74 | - if($result) { |
|
75 | - $this->zip->close();//close and reopen to save the zip |
|
74 | + if ($result) { |
|
75 | + $this->zip->close(); //close and reopen to save the zip |
|
76 | 76 | $this->zip->open($this->path); |
77 | 77 | } |
78 | 78 | return $result; |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * @return boolean|null |
85 | 85 | */ |
86 | 86 | function rename($source, $dest) { |
87 | - $source=$this->stripPath($source); |
|
88 | - $dest=$this->stripPath($dest); |
|
87 | + $source = $this->stripPath($source); |
|
88 | + $dest = $this->stripPath($dest); |
|
89 | 89 | $this->zip->renameName($source, $dest); |
90 | 90 | } |
91 | 91 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return int |
95 | 95 | */ |
96 | 96 | function filesize($path) { |
97 | - $stat=$this->zip->statName($path); |
|
97 | + $stat = $this->zip->statName($path); |
|
98 | 98 | return $stat['size']; |
99 | 99 | } |
100 | 100 | /** |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | * @return array |
112 | 112 | */ |
113 | 113 | function getFolder($path) { |
114 | - $files=$this->getFiles(); |
|
115 | - $folderContent=array(); |
|
116 | - $pathLength=strlen($path); |
|
117 | - foreach($files as $file) { |
|
118 | - if(substr($file, 0, $pathLength)==$path and $file!=$path) { |
|
119 | - if(strrpos(substr($file, 0, -1), '/')<=$pathLength) { |
|
120 | - $folderContent[]=substr($file, $pathLength); |
|
114 | + $files = $this->getFiles(); |
|
115 | + $folderContent = array(); |
|
116 | + $pathLength = strlen($path); |
|
117 | + foreach ($files as $file) { |
|
118 | + if (substr($file, 0, $pathLength) == $path and $file != $path) { |
|
119 | + if (strrpos(substr($file, 0, -1), '/') <= $pathLength) { |
|
120 | + $folderContent[] = substr($file, $pathLength); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | } |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | * @return array |
129 | 129 | */ |
130 | 130 | function getFiles() { |
131 | - $fileCount=$this->zip->numFiles; |
|
132 | - $files=array(); |
|
133 | - for($i=0;$i<$fileCount;$i++) { |
|
134 | - $files[]=$this->zip->getNameIndex($i); |
|
131 | + $fileCount = $this->zip->numFiles; |
|
132 | + $files = array(); |
|
133 | + for ($i = 0; $i < $fileCount; $i++) { |
|
134 | + $files[] = $this->zip->getNameIndex($i); |
|
135 | 135 | } |
136 | 136 | return $files; |
137 | 137 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @return bool |
168 | 168 | */ |
169 | 169 | function fileExists($path) { |
170 | - return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false); |
|
170 | + return ($this->zip->locateName($path) !== false) or ($this->zip->locateName($path.'/') !== false); |
|
171 | 171 | } |
172 | 172 | /** |
173 | 173 | * remove a file or folder from the archive |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | * @return bool |
176 | 176 | */ |
177 | 177 | function remove($path) { |
178 | - if($this->fileExists($path.'/')) { |
|
178 | + if ($this->fileExists($path.'/')) { |
|
179 | 179 | return $this->zip->deleteName($path.'/'); |
180 | - }else{ |
|
180 | + } else { |
|
181 | 181 | return $this->zip->deleteName($path); |
182 | 182 | } |
183 | 183 | } |
@@ -188,23 +188,23 @@ discard block |
||
188 | 188 | * @return resource |
189 | 189 | */ |
190 | 190 | function getStream($path, $mode) { |
191 | - if($mode=='r' or $mode=='rb') { |
|
191 | + if ($mode == 'r' or $mode == 'rb') { |
|
192 | 192 | return $this->zip->getStream($path); |
193 | 193 | } else { |
194 | 194 | //since we can't directly get a writable stream, |
195 | 195 | //make a temp copy of the file and put it back |
196 | 196 | //in the archive when the stream is closed |
197 | - if(strrpos($path, '.')!==false) { |
|
198 | - $ext=substr($path, strrpos($path, '.')); |
|
199 | - }else{ |
|
200 | - $ext=''; |
|
197 | + if (strrpos($path, '.') !== false) { |
|
198 | + $ext = substr($path, strrpos($path, '.')); |
|
199 | + } else { |
|
200 | + $ext = ''; |
|
201 | 201 | } |
202 | - $tmpFile=\OCP\Files::tmpFile($ext); |
|
203 | - if($this->fileExists($path)) { |
|
202 | + $tmpFile = \OCP\Files::tmpFile($ext); |
|
203 | + if ($this->fileExists($path)) { |
|
204 | 204 | $this->extractFile($path, $tmpFile); |
205 | 205 | } |
206 | 206 | $handle = fopen($tmpFile, $mode); |
207 | - return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) { |
|
207 | + return CallbackWrapper::wrap($handle, null, null, function() use ($path, $tmpFile) { |
|
208 | 208 | $this->writeBack($tmpFile, $path); |
209 | 209 | }); |
210 | 210 | } |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | * @return string |
224 | 224 | */ |
225 | 225 | private function stripPath($path) { |
226 | - if(!$path || $path[0]=='/') { |
|
226 | + if (!$path || $path[0] == '/') { |
|
227 | 227 | return substr($path, 1); |
228 | - }else{ |
|
228 | + } else { |
|
229 | 229 | return $path; |
230 | 230 | } |
231 | 231 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param string $source either a local file or string data |
50 | 50 | * @return bool |
51 | 51 | */ |
52 | - abstract function addFile($path, $source=''); |
|
52 | + abstract function addFile($path, $source = ''); |
|
53 | 53 | /** |
54 | 54 | * rename a file or folder in the archive |
55 | 55 | * @param string $source |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | */ |
127 | 127 | function addRecursive($path, $source) { |
128 | 128 | $dh = opendir($source); |
129 | - if(is_resource($dh)) { |
|
129 | + if (is_resource($dh)) { |
|
130 | 130 | $this->addFolder($path); |
131 | 131 | while (($file = readdir($dh)) !== false) { |
132 | - if($file=='.' or $file=='..') { |
|
132 | + if ($file == '.' or $file == '..') { |
|
133 | 133 | continue; |
134 | 134 | } |
135 | - if(is_dir($source.'/'.$file)) { |
|
135 | + if (is_dir($source.'/'.$file)) { |
|
136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
137 | - }else{ |
|
137 | + } else { |
|
138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
139 | 139 | } |
140 | 140 | } |