@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | * @param array $headers additional key value based headers |
47 | 47 | * @since 8.1.0 |
48 | 48 | */ |
49 | - public function __construct($data='', $statusCode=Http::STATUS_OK, |
|
50 | - $headers=[]) { |
|
49 | + public function __construct($data = '', $statusCode = Http::STATUS_OK, |
|
50 | + $headers = []) { |
|
51 | 51 | $this->data = $data; |
52 | 52 | $this->setStatus($statusCode); |
53 | 53 | $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @return DataDisplayResponse Reference to this object |
71 | 71 | * @since 8.1.0 |
72 | 72 | */ |
73 | - public function setData($data){ |
|
73 | + public function setData($data) { |
|
74 | 74 | $this->data = $data; |
75 | 75 | |
76 | 76 | return $this; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @return string the data |
83 | 83 | * @since 8.1.0 |
84 | 84 | */ |
85 | - public function getData(){ |
|
85 | + public function getData() { |
|
86 | 86 | return $this->data; |
87 | 87 | } |
88 | 88 |
@@ -33,57 +33,57 @@ |
||
33 | 33 | */ |
34 | 34 | class DataDisplayResponse extends Response { |
35 | 35 | |
36 | - /** |
|
37 | - * response data |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected $data; |
|
36 | + /** |
|
37 | + * response data |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected $data; |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * @param string $data the data to display |
|
45 | - * @param int $statusCode the Http status code, defaults to 200 |
|
46 | - * @param array $headers additional key value based headers |
|
47 | - * @since 8.1.0 |
|
48 | - */ |
|
49 | - public function __construct($data='', $statusCode=Http::STATUS_OK, |
|
50 | - $headers=[]) { |
|
51 | - $this->data = $data; |
|
52 | - $this->setStatus($statusCode); |
|
53 | - $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
|
54 | - $this->addHeader('Content-Disposition', 'inline; filename=""'); |
|
55 | - } |
|
43 | + /** |
|
44 | + * @param string $data the data to display |
|
45 | + * @param int $statusCode the Http status code, defaults to 200 |
|
46 | + * @param array $headers additional key value based headers |
|
47 | + * @since 8.1.0 |
|
48 | + */ |
|
49 | + public function __construct($data='', $statusCode=Http::STATUS_OK, |
|
50 | + $headers=[]) { |
|
51 | + $this->data = $data; |
|
52 | + $this->setStatus($statusCode); |
|
53 | + $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
|
54 | + $this->addHeader('Content-Disposition', 'inline; filename=""'); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Outputs data. No processing is done. |
|
59 | - * @return string |
|
60 | - * @since 8.1.0 |
|
61 | - */ |
|
62 | - public function render() { |
|
63 | - return $this->data; |
|
64 | - } |
|
57 | + /** |
|
58 | + * Outputs data. No processing is done. |
|
59 | + * @return string |
|
60 | + * @since 8.1.0 |
|
61 | + */ |
|
62 | + public function render() { |
|
63 | + return $this->data; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * Sets values in the data |
|
69 | - * @param string $data the data to display |
|
70 | - * @return DataDisplayResponse Reference to this object |
|
71 | - * @since 8.1.0 |
|
72 | - */ |
|
73 | - public function setData($data){ |
|
74 | - $this->data = $data; |
|
67 | + /** |
|
68 | + * Sets values in the data |
|
69 | + * @param string $data the data to display |
|
70 | + * @return DataDisplayResponse Reference to this object |
|
71 | + * @since 8.1.0 |
|
72 | + */ |
|
73 | + public function setData($data){ |
|
74 | + $this->data = $data; |
|
75 | 75 | |
76 | - return $this; |
|
77 | - } |
|
76 | + return $this; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * Used to get the set parameters |
|
82 | - * @return string the data |
|
83 | - * @since 8.1.0 |
|
84 | - */ |
|
85 | - public function getData(){ |
|
86 | - return $this->data; |
|
87 | - } |
|
80 | + /** |
|
81 | + * Used to get the set parameters |
|
82 | + * @return string the data |
|
83 | + * @since 8.1.0 |
|
84 | + */ |
|
85 | + public function getData(){ |
|
86 | + return $this->data; |
|
87 | + } |
|
88 | 88 | |
89 | 89 | } |
@@ -52,119 +52,119 @@ |
||
52 | 52 | */ |
53 | 53 | interface IManager { |
54 | 54 | |
55 | - /** |
|
56 | - * This function is used to search and find contacts within the users address books. |
|
57 | - * In case $pattern is empty all contacts will be returned. |
|
58 | - * |
|
59 | - * Example: |
|
60 | - * Following function shows how to search for contacts for the name and the email address. |
|
61 | - * |
|
62 | - * public static function getMatchingRecipient($term) { |
|
63 | - * $cm = \OC::$server->getContactsManager(); |
|
64 | - * // The API is not active -> nothing to do |
|
65 | - * if (!$cm->isEnabled()) { |
|
66 | - * return array(); |
|
67 | - * } |
|
68 | - * |
|
69 | - * $result = $cm->search($term, array('FN', 'EMAIL')); |
|
70 | - * $receivers = array(); |
|
71 | - * foreach ($result as $r) { |
|
72 | - * $id = $r['id']; |
|
73 | - * $fn = $r['FN']; |
|
74 | - * $email = $r['EMAIL']; |
|
75 | - * if (!is_array($email)) { |
|
76 | - * $email = array($email); |
|
77 | - * } |
|
78 | - * |
|
79 | - * // loop through all email addresses of this contact |
|
80 | - * foreach ($email as $e) { |
|
81 | - * $displayName = $fn . " <$e>"; |
|
82 | - * $receivers[] = array( |
|
83 | - * 'id' => $id, |
|
84 | - * 'label' => $displayName, |
|
85 | - * 'value' => $displayName); |
|
86 | - * } |
|
87 | - * } |
|
88 | - * |
|
89 | - * return $receivers; |
|
90 | - * } |
|
91 | - * |
|
92 | - * |
|
93 | - * @param string $pattern which should match within the $searchProperties |
|
94 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
95 | - * @param array $options - for future use. One should always have options! |
|
96 | - * @return array an array of contacts which are arrays of key-value-pairs |
|
97 | - * @since 6.0.0 |
|
98 | - */ |
|
99 | - public function search($pattern, $searchProperties = array(), $options = array()); |
|
55 | + /** |
|
56 | + * This function is used to search and find contacts within the users address books. |
|
57 | + * In case $pattern is empty all contacts will be returned. |
|
58 | + * |
|
59 | + * Example: |
|
60 | + * Following function shows how to search for contacts for the name and the email address. |
|
61 | + * |
|
62 | + * public static function getMatchingRecipient($term) { |
|
63 | + * $cm = \OC::$server->getContactsManager(); |
|
64 | + * // The API is not active -> nothing to do |
|
65 | + * if (!$cm->isEnabled()) { |
|
66 | + * return array(); |
|
67 | + * } |
|
68 | + * |
|
69 | + * $result = $cm->search($term, array('FN', 'EMAIL')); |
|
70 | + * $receivers = array(); |
|
71 | + * foreach ($result as $r) { |
|
72 | + * $id = $r['id']; |
|
73 | + * $fn = $r['FN']; |
|
74 | + * $email = $r['EMAIL']; |
|
75 | + * if (!is_array($email)) { |
|
76 | + * $email = array($email); |
|
77 | + * } |
|
78 | + * |
|
79 | + * // loop through all email addresses of this contact |
|
80 | + * foreach ($email as $e) { |
|
81 | + * $displayName = $fn . " <$e>"; |
|
82 | + * $receivers[] = array( |
|
83 | + * 'id' => $id, |
|
84 | + * 'label' => $displayName, |
|
85 | + * 'value' => $displayName); |
|
86 | + * } |
|
87 | + * } |
|
88 | + * |
|
89 | + * return $receivers; |
|
90 | + * } |
|
91 | + * |
|
92 | + * |
|
93 | + * @param string $pattern which should match within the $searchProperties |
|
94 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
95 | + * @param array $options - for future use. One should always have options! |
|
96 | + * @return array an array of contacts which are arrays of key-value-pairs |
|
97 | + * @since 6.0.0 |
|
98 | + */ |
|
99 | + public function search($pattern, $searchProperties = array(), $options = array()); |
|
100 | 100 | |
101 | - /** |
|
102 | - * This function can be used to delete the contact identified by the given id |
|
103 | - * |
|
104 | - * @param object $id the unique identifier to a contact |
|
105 | - * @param string $address_book_key identifier of the address book in which the contact shall be deleted |
|
106 | - * @return bool successful or not |
|
107 | - * @since 6.0.0 |
|
108 | - */ |
|
109 | - public function delete($id, $address_book_key); |
|
101 | + /** |
|
102 | + * This function can be used to delete the contact identified by the given id |
|
103 | + * |
|
104 | + * @param object $id the unique identifier to a contact |
|
105 | + * @param string $address_book_key identifier of the address book in which the contact shall be deleted |
|
106 | + * @return bool successful or not |
|
107 | + * @since 6.0.0 |
|
108 | + */ |
|
109 | + public function delete($id, $address_book_key); |
|
110 | 110 | |
111 | - /** |
|
112 | - * This function is used to create a new contact if 'id' is not given or not present. |
|
113 | - * Otherwise the contact will be updated by replacing the entire data set. |
|
114 | - * |
|
115 | - * @param array $properties this array if key-value-pairs defines a contact |
|
116 | - * @param string $address_book_key identifier of the address book in which the contact shall be created or updated |
|
117 | - * @return array an array representing the contact just created or updated |
|
118 | - * @since 6.0.0 |
|
119 | - */ |
|
120 | - public function createOrUpdate($properties, $address_book_key); |
|
111 | + /** |
|
112 | + * This function is used to create a new contact if 'id' is not given or not present. |
|
113 | + * Otherwise the contact will be updated by replacing the entire data set. |
|
114 | + * |
|
115 | + * @param array $properties this array if key-value-pairs defines a contact |
|
116 | + * @param string $address_book_key identifier of the address book in which the contact shall be created or updated |
|
117 | + * @return array an array representing the contact just created or updated |
|
118 | + * @since 6.0.0 |
|
119 | + */ |
|
120 | + public function createOrUpdate($properties, $address_book_key); |
|
121 | 121 | |
122 | - /** |
|
123 | - * Check if contacts are available (e.g. contacts app enabled) |
|
124 | - * |
|
125 | - * @return bool true if enabled, false if not |
|
126 | - * @since 6.0.0 |
|
127 | - */ |
|
128 | - public function isEnabled(); |
|
122 | + /** |
|
123 | + * Check if contacts are available (e.g. contacts app enabled) |
|
124 | + * |
|
125 | + * @return bool true if enabled, false if not |
|
126 | + * @since 6.0.0 |
|
127 | + */ |
|
128 | + public function isEnabled(); |
|
129 | 129 | |
130 | - /** |
|
131 | - * Registers an address book |
|
132 | - * |
|
133 | - * @param \OCP\IAddressBook $address_book |
|
134 | - * @return void |
|
135 | - * @since 6.0.0 |
|
136 | - */ |
|
137 | - public function registerAddressBook(\OCP\IAddressBook $address_book); |
|
130 | + /** |
|
131 | + * Registers an address book |
|
132 | + * |
|
133 | + * @param \OCP\IAddressBook $address_book |
|
134 | + * @return void |
|
135 | + * @since 6.0.0 |
|
136 | + */ |
|
137 | + public function registerAddressBook(\OCP\IAddressBook $address_book); |
|
138 | 138 | |
139 | - /** |
|
140 | - * Unregisters an address book |
|
141 | - * |
|
142 | - * @param \OCP\IAddressBook $address_book |
|
143 | - * @return void |
|
144 | - * @since 6.0.0 |
|
145 | - */ |
|
146 | - public function unregisterAddressBook(\OCP\IAddressBook $address_book); |
|
139 | + /** |
|
140 | + * Unregisters an address book |
|
141 | + * |
|
142 | + * @param \OCP\IAddressBook $address_book |
|
143 | + * @return void |
|
144 | + * @since 6.0.0 |
|
145 | + */ |
|
146 | + public function unregisterAddressBook(\OCP\IAddressBook $address_book); |
|
147 | 147 | |
148 | - /** |
|
149 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
150 | - * address books are actually requested |
|
151 | - * |
|
152 | - * @param \Closure $callable |
|
153 | - * @return void |
|
154 | - * @since 6.0.0 |
|
155 | - */ |
|
156 | - public function register(\Closure $callable); |
|
148 | + /** |
|
149 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
150 | + * address books are actually requested |
|
151 | + * |
|
152 | + * @param \Closure $callable |
|
153 | + * @return void |
|
154 | + * @since 6.0.0 |
|
155 | + */ |
|
156 | + public function register(\Closure $callable); |
|
157 | 157 | |
158 | - /** |
|
159 | - * @return array |
|
160 | - * @since 6.0.0 |
|
161 | - */ |
|
162 | - public function getAddressBooks(); |
|
158 | + /** |
|
159 | + * @return array |
|
160 | + * @since 6.0.0 |
|
161 | + */ |
|
162 | + public function getAddressBooks(); |
|
163 | 163 | |
164 | - /** |
|
165 | - * removes all registered address book instances |
|
166 | - * @return void |
|
167 | - * @since 6.0.0 |
|
168 | - */ |
|
169 | - public function clear(); |
|
164 | + /** |
|
165 | + * removes all registered address book instances |
|
166 | + * @return void |
|
167 | + * @since 6.0.0 |
|
168 | + */ |
|
169 | + public function clear(); |
|
170 | 170 | } |
@@ -370,6 +370,7 @@ |
||
370 | 370 | |
371 | 371 | /** |
372 | 372 | * write back temporary files |
373 | + * @param string $path |
|
373 | 374 | */ |
374 | 375 | public function writeBack($tmpFile, $path) { |
375 | 376 | $this->addFile($path, $tmpFile); |
@@ -35,350 +35,350 @@ |
||
35 | 35 | use Icewind\Streams\CallbackWrapper; |
36 | 36 | |
37 | 37 | class TAR extends Archive { |
38 | - const PLAIN = 0; |
|
39 | - const GZIP = 1; |
|
40 | - const BZIP = 2; |
|
38 | + const PLAIN = 0; |
|
39 | + const GZIP = 1; |
|
40 | + const BZIP = 2; |
|
41 | 41 | |
42 | - private $fileList; |
|
43 | - private $cachedHeaders; |
|
42 | + private $fileList; |
|
43 | + private $cachedHeaders; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @var \Archive_Tar tar |
|
47 | - */ |
|
48 | - private $tar = null; |
|
49 | - private $path; |
|
45 | + /** |
|
46 | + * @var \Archive_Tar tar |
|
47 | + */ |
|
48 | + private $tar = null; |
|
49 | + private $path; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $source |
|
53 | - */ |
|
54 | - public function __construct($source) { |
|
55 | - $types = array(null, 'gz', 'bz2'); |
|
56 | - $this->path = $source; |
|
57 | - $this->tar = new \Archive_Tar($source, $types[self::getTarType($source)]); |
|
58 | - } |
|
51 | + /** |
|
52 | + * @param string $source |
|
53 | + */ |
|
54 | + public function __construct($source) { |
|
55 | + $types = array(null, 'gz', 'bz2'); |
|
56 | + $this->path = $source; |
|
57 | + $this->tar = new \Archive_Tar($source, $types[self::getTarType($source)]); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * try to detect the type of tar compression |
|
62 | - * |
|
63 | - * @param string $file |
|
64 | - * @return integer |
|
65 | - */ |
|
66 | - static public function getTarType($file) { |
|
67 | - if (strpos($file, '.')) { |
|
68 | - $extension = substr($file, strrpos($file, '.')); |
|
69 | - switch ($extension) { |
|
70 | - case '.gz': |
|
71 | - case '.tgz': |
|
72 | - return self::GZIP; |
|
73 | - case '.bz': |
|
74 | - case '.bz2': |
|
75 | - return self::BZIP; |
|
76 | - case '.tar': |
|
77 | - return self::PLAIN; |
|
78 | - default: |
|
79 | - return self::PLAIN; |
|
80 | - } |
|
81 | - } else { |
|
82 | - return self::PLAIN; |
|
83 | - } |
|
84 | - } |
|
60 | + /** |
|
61 | + * try to detect the type of tar compression |
|
62 | + * |
|
63 | + * @param string $file |
|
64 | + * @return integer |
|
65 | + */ |
|
66 | + static public function getTarType($file) { |
|
67 | + if (strpos($file, '.')) { |
|
68 | + $extension = substr($file, strrpos($file, '.')); |
|
69 | + switch ($extension) { |
|
70 | + case '.gz': |
|
71 | + case '.tgz': |
|
72 | + return self::GZIP; |
|
73 | + case '.bz': |
|
74 | + case '.bz2': |
|
75 | + return self::BZIP; |
|
76 | + case '.tar': |
|
77 | + return self::PLAIN; |
|
78 | + default: |
|
79 | + return self::PLAIN; |
|
80 | + } |
|
81 | + } else { |
|
82 | + return self::PLAIN; |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * add an empty folder to the archive |
|
88 | - * |
|
89 | - * @param string $path |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function addFolder($path) { |
|
93 | - $tmpBase = \OC::$server->getTempManager()->getTemporaryFolder(); |
|
94 | - $path = rtrim($path, '/') . '/'; |
|
95 | - if ($this->fileExists($path)) { |
|
96 | - return false; |
|
97 | - } |
|
98 | - $parts = explode('/', $path); |
|
99 | - $folder = $tmpBase; |
|
100 | - foreach ($parts as $part) { |
|
101 | - $folder .= '/' . $part; |
|
102 | - if (!is_dir($folder)) { |
|
103 | - mkdir($folder); |
|
104 | - } |
|
105 | - } |
|
106 | - $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase); |
|
107 | - rmdir($tmpBase . $path); |
|
108 | - $this->fileList = false; |
|
109 | - $this->cachedHeaders = false; |
|
110 | - return $result; |
|
111 | - } |
|
86 | + /** |
|
87 | + * add an empty folder to the archive |
|
88 | + * |
|
89 | + * @param string $path |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function addFolder($path) { |
|
93 | + $tmpBase = \OC::$server->getTempManager()->getTemporaryFolder(); |
|
94 | + $path = rtrim($path, '/') . '/'; |
|
95 | + if ($this->fileExists($path)) { |
|
96 | + return false; |
|
97 | + } |
|
98 | + $parts = explode('/', $path); |
|
99 | + $folder = $tmpBase; |
|
100 | + foreach ($parts as $part) { |
|
101 | + $folder .= '/' . $part; |
|
102 | + if (!is_dir($folder)) { |
|
103 | + mkdir($folder); |
|
104 | + } |
|
105 | + } |
|
106 | + $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase); |
|
107 | + rmdir($tmpBase . $path); |
|
108 | + $this->fileList = false; |
|
109 | + $this->cachedHeaders = false; |
|
110 | + return $result; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * add a file to the archive |
|
115 | - * |
|
116 | - * @param string $path |
|
117 | - * @param string $source either a local file or string data |
|
118 | - * @return bool |
|
119 | - */ |
|
120 | - public function addFile($path, $source = '') { |
|
121 | - if ($this->fileExists($path)) { |
|
122 | - $this->remove($path); |
|
123 | - } |
|
124 | - if ($source and $source[0] == '/' and file_exists($source)) { |
|
125 | - $source = file_get_contents($source); |
|
126 | - } |
|
127 | - $result = $this->tar->addString($path, $source); |
|
128 | - $this->fileList = false; |
|
129 | - $this->cachedHeaders = false; |
|
130 | - return $result; |
|
131 | - } |
|
113 | + /** |
|
114 | + * add a file to the archive |
|
115 | + * |
|
116 | + * @param string $path |
|
117 | + * @param string $source either a local file or string data |
|
118 | + * @return bool |
|
119 | + */ |
|
120 | + public function addFile($path, $source = '') { |
|
121 | + if ($this->fileExists($path)) { |
|
122 | + $this->remove($path); |
|
123 | + } |
|
124 | + if ($source and $source[0] == '/' and file_exists($source)) { |
|
125 | + $source = file_get_contents($source); |
|
126 | + } |
|
127 | + $result = $this->tar->addString($path, $source); |
|
128 | + $this->fileList = false; |
|
129 | + $this->cachedHeaders = false; |
|
130 | + return $result; |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * rename a file or folder in the archive |
|
135 | - * |
|
136 | - * @param string $source |
|
137 | - * @param string $dest |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - public function rename($source, $dest) { |
|
141 | - //no proper way to delete, rename entire archive, rename file and remake archive |
|
142 | - $tmp = \OC::$server->getTempManager()->getTemporaryFolder(); |
|
143 | - $this->tar->extract($tmp); |
|
144 | - rename($tmp . $source, $tmp . $dest); |
|
145 | - $this->tar = null; |
|
146 | - unlink($this->path); |
|
147 | - $types = array(null, 'gz', 'bz'); |
|
148 | - $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
|
149 | - $this->tar->createModify(array($tmp), '', $tmp . '/'); |
|
150 | - $this->fileList = false; |
|
151 | - $this->cachedHeaders = false; |
|
152 | - return true; |
|
153 | - } |
|
133 | + /** |
|
134 | + * rename a file or folder in the archive |
|
135 | + * |
|
136 | + * @param string $source |
|
137 | + * @param string $dest |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + public function rename($source, $dest) { |
|
141 | + //no proper way to delete, rename entire archive, rename file and remake archive |
|
142 | + $tmp = \OC::$server->getTempManager()->getTemporaryFolder(); |
|
143 | + $this->tar->extract($tmp); |
|
144 | + rename($tmp . $source, $tmp . $dest); |
|
145 | + $this->tar = null; |
|
146 | + unlink($this->path); |
|
147 | + $types = array(null, 'gz', 'bz'); |
|
148 | + $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
|
149 | + $this->tar->createModify(array($tmp), '', $tmp . '/'); |
|
150 | + $this->fileList = false; |
|
151 | + $this->cachedHeaders = false; |
|
152 | + return true; |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * @param string $file |
|
157 | - */ |
|
158 | - private function getHeader($file) { |
|
159 | - if (!$this->cachedHeaders) { |
|
160 | - $this->cachedHeaders = $this->tar->listContent(); |
|
161 | - } |
|
162 | - foreach ($this->cachedHeaders as $header) { |
|
163 | - if ($file == $header['filename'] |
|
164 | - or $file . '/' == $header['filename'] |
|
165 | - or '/' . $file . '/' == $header['filename'] |
|
166 | - or '/' . $file == $header['filename'] |
|
167 | - ) { |
|
168 | - return $header; |
|
169 | - } |
|
170 | - } |
|
171 | - return null; |
|
172 | - } |
|
155 | + /** |
|
156 | + * @param string $file |
|
157 | + */ |
|
158 | + private function getHeader($file) { |
|
159 | + if (!$this->cachedHeaders) { |
|
160 | + $this->cachedHeaders = $this->tar->listContent(); |
|
161 | + } |
|
162 | + foreach ($this->cachedHeaders as $header) { |
|
163 | + if ($file == $header['filename'] |
|
164 | + or $file . '/' == $header['filename'] |
|
165 | + or '/' . $file . '/' == $header['filename'] |
|
166 | + or '/' . $file == $header['filename'] |
|
167 | + ) { |
|
168 | + return $header; |
|
169 | + } |
|
170 | + } |
|
171 | + return null; |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * get the uncompressed size of a file in the archive |
|
176 | - * |
|
177 | - * @param string $path |
|
178 | - * @return int |
|
179 | - */ |
|
180 | - public function filesize($path) { |
|
181 | - $stat = $this->getHeader($path); |
|
182 | - return $stat['size']; |
|
183 | - } |
|
174 | + /** |
|
175 | + * get the uncompressed size of a file in the archive |
|
176 | + * |
|
177 | + * @param string $path |
|
178 | + * @return int |
|
179 | + */ |
|
180 | + public function filesize($path) { |
|
181 | + $stat = $this->getHeader($path); |
|
182 | + return $stat['size']; |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * get the last modified time of a file in the archive |
|
187 | - * |
|
188 | - * @param string $path |
|
189 | - * @return int |
|
190 | - */ |
|
191 | - public function mtime($path) { |
|
192 | - $stat = $this->getHeader($path); |
|
193 | - return $stat['mtime']; |
|
194 | - } |
|
185 | + /** |
|
186 | + * get the last modified time of a file in the archive |
|
187 | + * |
|
188 | + * @param string $path |
|
189 | + * @return int |
|
190 | + */ |
|
191 | + public function mtime($path) { |
|
192 | + $stat = $this->getHeader($path); |
|
193 | + return $stat['mtime']; |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * get the files in a folder |
|
198 | - * |
|
199 | - * @param string $path |
|
200 | - * @return array |
|
201 | - */ |
|
202 | - public function getFolder($path) { |
|
203 | - $files = $this->getFiles(); |
|
204 | - $folderContent = array(); |
|
205 | - $pathLength = strlen($path); |
|
206 | - foreach ($files as $file) { |
|
207 | - if ($file[0] == '/') { |
|
208 | - $file = substr($file, 1); |
|
209 | - } |
|
210 | - if (substr($file, 0, $pathLength) == $path and $file != $path) { |
|
211 | - $result = substr($file, $pathLength); |
|
212 | - if ($pos = strpos($result, '/')) { |
|
213 | - $result = substr($result, 0, $pos + 1); |
|
214 | - } |
|
215 | - if (array_search($result, $folderContent) === false) { |
|
216 | - $folderContent[] = $result; |
|
217 | - } |
|
218 | - } |
|
219 | - } |
|
220 | - return $folderContent; |
|
221 | - } |
|
196 | + /** |
|
197 | + * get the files in a folder |
|
198 | + * |
|
199 | + * @param string $path |
|
200 | + * @return array |
|
201 | + */ |
|
202 | + public function getFolder($path) { |
|
203 | + $files = $this->getFiles(); |
|
204 | + $folderContent = array(); |
|
205 | + $pathLength = strlen($path); |
|
206 | + foreach ($files as $file) { |
|
207 | + if ($file[0] == '/') { |
|
208 | + $file = substr($file, 1); |
|
209 | + } |
|
210 | + if (substr($file, 0, $pathLength) == $path and $file != $path) { |
|
211 | + $result = substr($file, $pathLength); |
|
212 | + if ($pos = strpos($result, '/')) { |
|
213 | + $result = substr($result, 0, $pos + 1); |
|
214 | + } |
|
215 | + if (array_search($result, $folderContent) === false) { |
|
216 | + $folderContent[] = $result; |
|
217 | + } |
|
218 | + } |
|
219 | + } |
|
220 | + return $folderContent; |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * get all files in the archive |
|
225 | - * |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - public function getFiles() { |
|
229 | - if ($this->fileList) { |
|
230 | - return $this->fileList; |
|
231 | - } |
|
232 | - if (!$this->cachedHeaders) { |
|
233 | - $this->cachedHeaders = $this->tar->listContent(); |
|
234 | - } |
|
235 | - $files = array(); |
|
236 | - foreach ($this->cachedHeaders as $header) { |
|
237 | - $files[] = $header['filename']; |
|
238 | - } |
|
239 | - $this->fileList = $files; |
|
240 | - return $files; |
|
241 | - } |
|
223 | + /** |
|
224 | + * get all files in the archive |
|
225 | + * |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + public function getFiles() { |
|
229 | + if ($this->fileList) { |
|
230 | + return $this->fileList; |
|
231 | + } |
|
232 | + if (!$this->cachedHeaders) { |
|
233 | + $this->cachedHeaders = $this->tar->listContent(); |
|
234 | + } |
|
235 | + $files = array(); |
|
236 | + foreach ($this->cachedHeaders as $header) { |
|
237 | + $files[] = $header['filename']; |
|
238 | + } |
|
239 | + $this->fileList = $files; |
|
240 | + return $files; |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * get the content of a file |
|
245 | - * |
|
246 | - * @param string $path |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - public function getFile($path) { |
|
250 | - return $this->tar->extractInString($path); |
|
251 | - } |
|
243 | + /** |
|
244 | + * get the content of a file |
|
245 | + * |
|
246 | + * @param string $path |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + public function getFile($path) { |
|
250 | + return $this->tar->extractInString($path); |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * extract a single file from the archive |
|
255 | - * |
|
256 | - * @param string $path |
|
257 | - * @param string $dest |
|
258 | - * @return bool |
|
259 | - */ |
|
260 | - public function extractFile($path, $dest) { |
|
261 | - $tmp = \OC::$server->getTempManager()->getTemporaryFolder(); |
|
262 | - if (!$this->fileExists($path)) { |
|
263 | - return false; |
|
264 | - } |
|
265 | - if ($this->fileExists('/' . $path)) { |
|
266 | - $success = $this->tar->extractList(array('/' . $path), $tmp); |
|
267 | - } else { |
|
268 | - $success = $this->tar->extractList(array($path), $tmp); |
|
269 | - } |
|
270 | - if ($success) { |
|
271 | - rename($tmp . $path, $dest); |
|
272 | - } |
|
273 | - \OCP\Files::rmdirr($tmp); |
|
274 | - return $success; |
|
275 | - } |
|
253 | + /** |
|
254 | + * extract a single file from the archive |
|
255 | + * |
|
256 | + * @param string $path |
|
257 | + * @param string $dest |
|
258 | + * @return bool |
|
259 | + */ |
|
260 | + public function extractFile($path, $dest) { |
|
261 | + $tmp = \OC::$server->getTempManager()->getTemporaryFolder(); |
|
262 | + if (!$this->fileExists($path)) { |
|
263 | + return false; |
|
264 | + } |
|
265 | + if ($this->fileExists('/' . $path)) { |
|
266 | + $success = $this->tar->extractList(array('/' . $path), $tmp); |
|
267 | + } else { |
|
268 | + $success = $this->tar->extractList(array($path), $tmp); |
|
269 | + } |
|
270 | + if ($success) { |
|
271 | + rename($tmp . $path, $dest); |
|
272 | + } |
|
273 | + \OCP\Files::rmdirr($tmp); |
|
274 | + return $success; |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * extract the archive |
|
279 | - * |
|
280 | - * @param string $dest |
|
281 | - * @return bool |
|
282 | - */ |
|
283 | - public function extract($dest) { |
|
284 | - return $this->tar->extract($dest); |
|
285 | - } |
|
277 | + /** |
|
278 | + * extract the archive |
|
279 | + * |
|
280 | + * @param string $dest |
|
281 | + * @return bool |
|
282 | + */ |
|
283 | + public function extract($dest) { |
|
284 | + return $this->tar->extract($dest); |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * check if a file or folder exists in the archive |
|
289 | - * |
|
290 | - * @param string $path |
|
291 | - * @return bool |
|
292 | - */ |
|
293 | - public function fileExists($path) { |
|
294 | - $files = $this->getFiles(); |
|
295 | - if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) { |
|
296 | - return true; |
|
297 | - } else { |
|
298 | - $folderPath = rtrim($path, '/') . '/'; |
|
299 | - $pathLength = strlen($folderPath); |
|
300 | - foreach ($files as $file) { |
|
301 | - if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) { |
|
302 | - return true; |
|
303 | - } |
|
304 | - } |
|
305 | - } |
|
306 | - if ($path[0] != '/') { //not all programs agree on the use of a leading / |
|
307 | - return $this->fileExists('/' . $path); |
|
308 | - } else { |
|
309 | - return false; |
|
310 | - } |
|
311 | - } |
|
287 | + /** |
|
288 | + * check if a file or folder exists in the archive |
|
289 | + * |
|
290 | + * @param string $path |
|
291 | + * @return bool |
|
292 | + */ |
|
293 | + public function fileExists($path) { |
|
294 | + $files = $this->getFiles(); |
|
295 | + if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) { |
|
296 | + return true; |
|
297 | + } else { |
|
298 | + $folderPath = rtrim($path, '/') . '/'; |
|
299 | + $pathLength = strlen($folderPath); |
|
300 | + foreach ($files as $file) { |
|
301 | + if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) { |
|
302 | + return true; |
|
303 | + } |
|
304 | + } |
|
305 | + } |
|
306 | + if ($path[0] != '/') { //not all programs agree on the use of a leading / |
|
307 | + return $this->fileExists('/' . $path); |
|
308 | + } else { |
|
309 | + return false; |
|
310 | + } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
314 | - * remove a file or folder from the archive |
|
315 | - * |
|
316 | - * @param string $path |
|
317 | - * @return bool |
|
318 | - */ |
|
319 | - public function remove($path) { |
|
320 | - if (!$this->fileExists($path)) { |
|
321 | - return false; |
|
322 | - } |
|
323 | - $this->fileList = false; |
|
324 | - $this->cachedHeaders = false; |
|
325 | - //no proper way to delete, extract entire archive, delete file and remake archive |
|
326 | - $tmp = \OC::$server->getTempManager()->getTemporaryFolder(); |
|
327 | - $this->tar->extract($tmp); |
|
328 | - \OCP\Files::rmdirr($tmp . $path); |
|
329 | - $this->tar = null; |
|
330 | - unlink($this->path); |
|
331 | - $this->reopen(); |
|
332 | - $this->tar->createModify(array($tmp), '', $tmp); |
|
333 | - return true; |
|
334 | - } |
|
313 | + /** |
|
314 | + * remove a file or folder from the archive |
|
315 | + * |
|
316 | + * @param string $path |
|
317 | + * @return bool |
|
318 | + */ |
|
319 | + public function remove($path) { |
|
320 | + if (!$this->fileExists($path)) { |
|
321 | + return false; |
|
322 | + } |
|
323 | + $this->fileList = false; |
|
324 | + $this->cachedHeaders = false; |
|
325 | + //no proper way to delete, extract entire archive, delete file and remake archive |
|
326 | + $tmp = \OC::$server->getTempManager()->getTemporaryFolder(); |
|
327 | + $this->tar->extract($tmp); |
|
328 | + \OCP\Files::rmdirr($tmp . $path); |
|
329 | + $this->tar = null; |
|
330 | + unlink($this->path); |
|
331 | + $this->reopen(); |
|
332 | + $this->tar->createModify(array($tmp), '', $tmp); |
|
333 | + return true; |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * get a file handler |
|
338 | - * |
|
339 | - * @param string $path |
|
340 | - * @param string $mode |
|
341 | - * @return resource |
|
342 | - */ |
|
343 | - public function getStream($path, $mode) { |
|
344 | - if (strrpos($path, '.') !== false) { |
|
345 | - $ext = substr($path, strrpos($path, '.')); |
|
346 | - } else { |
|
347 | - $ext = ''; |
|
348 | - } |
|
349 | - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); |
|
350 | - if ($this->fileExists($path)) { |
|
351 | - $this->extractFile($path, $tmpFile); |
|
352 | - } elseif ($mode == 'r' or $mode == 'rb') { |
|
353 | - return false; |
|
354 | - } |
|
355 | - if ($mode == 'r' or $mode == 'rb') { |
|
356 | - return fopen($tmpFile, $mode); |
|
357 | - } else { |
|
358 | - $handle = fopen($tmpFile, $mode); |
|
359 | - return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) { |
|
360 | - $this->writeBack($tmpFile, $path); |
|
361 | - }); |
|
362 | - } |
|
363 | - } |
|
336 | + /** |
|
337 | + * get a file handler |
|
338 | + * |
|
339 | + * @param string $path |
|
340 | + * @param string $mode |
|
341 | + * @return resource |
|
342 | + */ |
|
343 | + public function getStream($path, $mode) { |
|
344 | + if (strrpos($path, '.') !== false) { |
|
345 | + $ext = substr($path, strrpos($path, '.')); |
|
346 | + } else { |
|
347 | + $ext = ''; |
|
348 | + } |
|
349 | + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); |
|
350 | + if ($this->fileExists($path)) { |
|
351 | + $this->extractFile($path, $tmpFile); |
|
352 | + } elseif ($mode == 'r' or $mode == 'rb') { |
|
353 | + return false; |
|
354 | + } |
|
355 | + if ($mode == 'r' or $mode == 'rb') { |
|
356 | + return fopen($tmpFile, $mode); |
|
357 | + } else { |
|
358 | + $handle = fopen($tmpFile, $mode); |
|
359 | + return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) { |
|
360 | + $this->writeBack($tmpFile, $path); |
|
361 | + }); |
|
362 | + } |
|
363 | + } |
|
364 | 364 | |
365 | - /** |
|
366 | - * write back temporary files |
|
367 | - */ |
|
368 | - public function writeBack($tmpFile, $path) { |
|
369 | - $this->addFile($path, $tmpFile); |
|
370 | - unlink($tmpFile); |
|
371 | - } |
|
365 | + /** |
|
366 | + * write back temporary files |
|
367 | + */ |
|
368 | + public function writeBack($tmpFile, $path) { |
|
369 | + $this->addFile($path, $tmpFile); |
|
370 | + unlink($tmpFile); |
|
371 | + } |
|
372 | 372 | |
373 | - /** |
|
374 | - * reopen the archive to ensure everything is written |
|
375 | - */ |
|
376 | - private function reopen() { |
|
377 | - if ($this->tar) { |
|
378 | - $this->tar->_close(); |
|
379 | - $this->tar = null; |
|
380 | - } |
|
381 | - $types = array(null, 'gz', 'bz'); |
|
382 | - $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
|
383 | - } |
|
373 | + /** |
|
374 | + * reopen the archive to ensure everything is written |
|
375 | + */ |
|
376 | + private function reopen() { |
|
377 | + if ($this->tar) { |
|
378 | + $this->tar->_close(); |
|
379 | + $this->tar = null; |
|
380 | + } |
|
381 | + $types = array(null, 'gz', 'bz'); |
|
382 | + $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
|
383 | + } |
|
384 | 384 | } |
@@ -91,20 +91,20 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function addFolder($path) { |
93 | 93 | $tmpBase = \OC::$server->getTempManager()->getTemporaryFolder(); |
94 | - $path = rtrim($path, '/') . '/'; |
|
94 | + $path = rtrim($path, '/').'/'; |
|
95 | 95 | if ($this->fileExists($path)) { |
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | $parts = explode('/', $path); |
99 | 99 | $folder = $tmpBase; |
100 | 100 | foreach ($parts as $part) { |
101 | - $folder .= '/' . $part; |
|
101 | + $folder .= '/'.$part; |
|
102 | 102 | if (!is_dir($folder)) { |
103 | 103 | mkdir($folder); |
104 | 104 | } |
105 | 105 | } |
106 | - $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase); |
|
107 | - rmdir($tmpBase . $path); |
|
106 | + $result = $this->tar->addModify(array($tmpBase.$path), '', $tmpBase); |
|
107 | + rmdir($tmpBase.$path); |
|
108 | 108 | $this->fileList = false; |
109 | 109 | $this->cachedHeaders = false; |
110 | 110 | return $result; |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | //no proper way to delete, rename entire archive, rename file and remake archive |
142 | 142 | $tmp = \OC::$server->getTempManager()->getTemporaryFolder(); |
143 | 143 | $this->tar->extract($tmp); |
144 | - rename($tmp . $source, $tmp . $dest); |
|
144 | + rename($tmp.$source, $tmp.$dest); |
|
145 | 145 | $this->tar = null; |
146 | 146 | unlink($this->path); |
147 | 147 | $types = array(null, 'gz', 'bz'); |
148 | 148 | $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
149 | - $this->tar->createModify(array($tmp), '', $tmp . '/'); |
|
149 | + $this->tar->createModify(array($tmp), '', $tmp.'/'); |
|
150 | 150 | $this->fileList = false; |
151 | 151 | $this->cachedHeaders = false; |
152 | 152 | return true; |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | } |
162 | 162 | foreach ($this->cachedHeaders as $header) { |
163 | 163 | if ($file == $header['filename'] |
164 | - or $file . '/' == $header['filename'] |
|
165 | - or '/' . $file . '/' == $header['filename'] |
|
166 | - or '/' . $file == $header['filename'] |
|
164 | + or $file.'/' == $header['filename'] |
|
165 | + or '/'.$file.'/' == $header['filename'] |
|
166 | + or '/'.$file == $header['filename'] |
|
167 | 167 | ) { |
168 | 168 | return $header; |
169 | 169 | } |
@@ -262,13 +262,13 @@ discard block |
||
262 | 262 | if (!$this->fileExists($path)) { |
263 | 263 | return false; |
264 | 264 | } |
265 | - if ($this->fileExists('/' . $path)) { |
|
266 | - $success = $this->tar->extractList(array('/' . $path), $tmp); |
|
265 | + if ($this->fileExists('/'.$path)) { |
|
266 | + $success = $this->tar->extractList(array('/'.$path), $tmp); |
|
267 | 267 | } else { |
268 | 268 | $success = $this->tar->extractList(array($path), $tmp); |
269 | 269 | } |
270 | 270 | if ($success) { |
271 | - rename($tmp . $path, $dest); |
|
271 | + rename($tmp.$path, $dest); |
|
272 | 272 | } |
273 | 273 | \OCP\Files::rmdirr($tmp); |
274 | 274 | return $success; |
@@ -292,10 +292,10 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public function fileExists($path) { |
294 | 294 | $files = $this->getFiles(); |
295 | - if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) { |
|
295 | + if ((array_search($path, $files) !== false) or (array_search($path.'/', $files) !== false)) { |
|
296 | 296 | return true; |
297 | 297 | } else { |
298 | - $folderPath = rtrim($path, '/') . '/'; |
|
298 | + $folderPath = rtrim($path, '/').'/'; |
|
299 | 299 | $pathLength = strlen($folderPath); |
300 | 300 | foreach ($files as $file) { |
301 | 301 | if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) { |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | } |
305 | 305 | } |
306 | 306 | if ($path[0] != '/') { //not all programs agree on the use of a leading / |
307 | - return $this->fileExists('/' . $path); |
|
307 | + return $this->fileExists('/'.$path); |
|
308 | 308 | } else { |
309 | 309 | return false; |
310 | 310 | } |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | //no proper way to delete, extract entire archive, delete file and remake archive |
326 | 326 | $tmp = \OC::$server->getTempManager()->getTemporaryFolder(); |
327 | 327 | $this->tar->extract($tmp); |
328 | - \OCP\Files::rmdirr($tmp . $path); |
|
328 | + \OCP\Files::rmdirr($tmp.$path); |
|
329 | 329 | $this->tar = null; |
330 | 330 | unlink($this->path); |
331 | 331 | $this->reopen(); |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | return fopen($tmpFile, $mode); |
357 | 357 | } else { |
358 | 358 | $handle = fopen($tmpFile, $mode); |
359 | - return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) { |
|
359 | + return CallbackWrapper::wrap($handle, null, null, function() use ($path, $tmpFile) { |
|
360 | 360 | $this->writeBack($tmpFile, $path); |
361 | 361 | }); |
362 | 362 | } |
@@ -32,68 +32,68 @@ |
||
32 | 32 | * @package OC\Security |
33 | 33 | */ |
34 | 34 | class TrustedDomainHelper { |
35 | - /** @var IConfig */ |
|
36 | - private $config; |
|
35 | + /** @var IConfig */ |
|
36 | + private $config; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param IConfig $config |
|
40 | - */ |
|
41 | - public function __construct(IConfig $config) { |
|
42 | - $this->config = $config; |
|
43 | - } |
|
38 | + /** |
|
39 | + * @param IConfig $config |
|
40 | + */ |
|
41 | + public function __construct(IConfig $config) { |
|
42 | + $this->config = $config; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Strips a potential port from a domain (in format domain:port) |
|
47 | - * @param string $host |
|
48 | - * @return string $host without appended port |
|
49 | - */ |
|
50 | - private function getDomainWithoutPort($host) { |
|
51 | - $pos = strrpos($host, ':'); |
|
52 | - if ($pos !== false) { |
|
53 | - $port = substr($host, $pos + 1); |
|
54 | - if (is_numeric($port)) { |
|
55 | - $host = substr($host, 0, $pos); |
|
56 | - } |
|
57 | - } |
|
58 | - return $host; |
|
59 | - } |
|
45 | + /** |
|
46 | + * Strips a potential port from a domain (in format domain:port) |
|
47 | + * @param string $host |
|
48 | + * @return string $host without appended port |
|
49 | + */ |
|
50 | + private function getDomainWithoutPort($host) { |
|
51 | + $pos = strrpos($host, ':'); |
|
52 | + if ($pos !== false) { |
|
53 | + $port = substr($host, $pos + 1); |
|
54 | + if (is_numeric($port)) { |
|
55 | + $host = substr($host, 0, $pos); |
|
56 | + } |
|
57 | + } |
|
58 | + return $host; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Checks whether a domain is considered as trusted from the list |
|
63 | - * of trusted domains. If no trusted domains have been configured, returns |
|
64 | - * true. |
|
65 | - * This is used to prevent Host Header Poisoning. |
|
66 | - * @param string $domainWithPort |
|
67 | - * @return bool true if the given domain is trusted or if no trusted domains |
|
68 | - * have been configured |
|
69 | - */ |
|
70 | - public function isTrustedDomain($domainWithPort) { |
|
71 | - $domain = $this->getDomainWithoutPort($domainWithPort); |
|
61 | + /** |
|
62 | + * Checks whether a domain is considered as trusted from the list |
|
63 | + * of trusted domains. If no trusted domains have been configured, returns |
|
64 | + * true. |
|
65 | + * This is used to prevent Host Header Poisoning. |
|
66 | + * @param string $domainWithPort |
|
67 | + * @return bool true if the given domain is trusted or if no trusted domains |
|
68 | + * have been configured |
|
69 | + */ |
|
70 | + public function isTrustedDomain($domainWithPort) { |
|
71 | + $domain = $this->getDomainWithoutPort($domainWithPort); |
|
72 | 72 | |
73 | - // Read trusted domains from config |
|
74 | - $trustedList = $this->config->getSystemValue('trusted_domains', []); |
|
75 | - if (!is_array($trustedList)) { |
|
76 | - return false; |
|
77 | - } |
|
73 | + // Read trusted domains from config |
|
74 | + $trustedList = $this->config->getSystemValue('trusted_domains', []); |
|
75 | + if (!is_array($trustedList)) { |
|
76 | + return false; |
|
77 | + } |
|
78 | 78 | |
79 | - // Always allow access from localhost |
|
80 | - if (preg_match(Request::REGEX_LOCALHOST, $domain) === 1) { |
|
81 | - return true; |
|
82 | - } |
|
83 | - // Reject misformed domains in any case |
|
84 | - if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) { |
|
85 | - return false; |
|
86 | - } |
|
87 | - // Match, allowing for * wildcards |
|
88 | - foreach ($trustedList as $trusted) { |
|
89 | - if (gettype($trusted) !== 'string') { |
|
90 | - break; |
|
91 | - } |
|
92 | - $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/'; |
|
93 | - if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) { |
|
94 | - return true; |
|
95 | - } |
|
96 | - } |
|
97 | - return false; |
|
98 | - } |
|
79 | + // Always allow access from localhost |
|
80 | + if (preg_match(Request::REGEX_LOCALHOST, $domain) === 1) { |
|
81 | + return true; |
|
82 | + } |
|
83 | + // Reject misformed domains in any case |
|
84 | + if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) { |
|
85 | + return false; |
|
86 | + } |
|
87 | + // Match, allowing for * wildcards |
|
88 | + foreach ($trustedList as $trusted) { |
|
89 | + if (gettype($trusted) !== 'string') { |
|
90 | + break; |
|
91 | + } |
|
92 | + $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/'; |
|
93 | + if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) { |
|
94 | + return true; |
|
95 | + } |
|
96 | + } |
|
97 | + return false; |
|
98 | + } |
|
99 | 99 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | return true; |
82 | 82 | } |
83 | 83 | // Reject misformed domains in any case |
84 | - if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) { |
|
84 | + if (strpos($domain, '-') === 0 || strpos($domain, '..') !== false) { |
|
85 | 85 | return false; |
86 | 86 | } |
87 | 87 | // Match, allowing for * wildcards |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | if (gettype($trusted) !== 'string') { |
90 | 90 | break; |
91 | 91 | } |
92 | - $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/'; |
|
92 | + $regex = '/^'.implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))).'$/'; |
|
93 | 93 | if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) { |
94 | 94 | return true; |
95 | 95 | } |
@@ -35,102 +35,102 @@ |
||
35 | 35 | * functions etc. |
36 | 36 | */ |
37 | 37 | class XCache extends Cache implements IMemcache { |
38 | - use CASTrait; |
|
38 | + use CASTrait; |
|
39 | 39 | |
40 | - use CADTrait; |
|
40 | + use CADTrait; |
|
41 | 41 | |
42 | - /** |
|
43 | - * entries in XCache gets namespaced to prevent collisions between ownCloud instances and users |
|
44 | - */ |
|
45 | - protected function getNameSpace() { |
|
46 | - return $this->prefix; |
|
47 | - } |
|
42 | + /** |
|
43 | + * entries in XCache gets namespaced to prevent collisions between ownCloud instances and users |
|
44 | + */ |
|
45 | + protected function getNameSpace() { |
|
46 | + return $this->prefix; |
|
47 | + } |
|
48 | 48 | |
49 | - public function get($key) { |
|
50 | - return xcache_get($this->getNameSpace() . $key); |
|
51 | - } |
|
49 | + public function get($key) { |
|
50 | + return xcache_get($this->getNameSpace() . $key); |
|
51 | + } |
|
52 | 52 | |
53 | - public function set($key, $value, $ttl = 0) { |
|
54 | - if ($ttl > 0) { |
|
55 | - return xcache_set($this->getNameSpace() . $key, $value, $ttl); |
|
56 | - } else { |
|
57 | - return xcache_set($this->getNameSpace() . $key, $value); |
|
58 | - } |
|
59 | - } |
|
53 | + public function set($key, $value, $ttl = 0) { |
|
54 | + if ($ttl > 0) { |
|
55 | + return xcache_set($this->getNameSpace() . $key, $value, $ttl); |
|
56 | + } else { |
|
57 | + return xcache_set($this->getNameSpace() . $key, $value); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - public function hasKey($key) { |
|
62 | - return xcache_isset($this->getNameSpace() . $key); |
|
63 | - } |
|
61 | + public function hasKey($key) { |
|
62 | + return xcache_isset($this->getNameSpace() . $key); |
|
63 | + } |
|
64 | 64 | |
65 | - public function remove($key) { |
|
66 | - return xcache_unset($this->getNameSpace() . $key); |
|
67 | - } |
|
65 | + public function remove($key) { |
|
66 | + return xcache_unset($this->getNameSpace() . $key); |
|
67 | + } |
|
68 | 68 | |
69 | - public function clear($prefix = '') { |
|
70 | - if (function_exists('xcache_unset_by_prefix')) { |
|
71 | - return xcache_unset_by_prefix($this->getNameSpace() . $prefix); |
|
72 | - } else { |
|
73 | - // Since we can not clear by prefix, we just clear the whole cache. |
|
74 | - xcache_clear_cache(\XC_TYPE_VAR, 0); |
|
75 | - } |
|
76 | - return true; |
|
77 | - } |
|
69 | + public function clear($prefix = '') { |
|
70 | + if (function_exists('xcache_unset_by_prefix')) { |
|
71 | + return xcache_unset_by_prefix($this->getNameSpace() . $prefix); |
|
72 | + } else { |
|
73 | + // Since we can not clear by prefix, we just clear the whole cache. |
|
74 | + xcache_clear_cache(\XC_TYPE_VAR, 0); |
|
75 | + } |
|
76 | + return true; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Set a value in the cache if it's not already stored |
|
81 | - * |
|
82 | - * @param string $key |
|
83 | - * @param mixed $value |
|
84 | - * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
85 | - * @return bool |
|
86 | - */ |
|
87 | - public function add($key, $value, $ttl = 0) { |
|
88 | - if ($this->hasKey($key)) { |
|
89 | - return false; |
|
90 | - } else { |
|
91 | - return $this->set($key, $value, $ttl); |
|
92 | - } |
|
93 | - } |
|
79 | + /** |
|
80 | + * Set a value in the cache if it's not already stored |
|
81 | + * |
|
82 | + * @param string $key |
|
83 | + * @param mixed $value |
|
84 | + * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
85 | + * @return bool |
|
86 | + */ |
|
87 | + public function add($key, $value, $ttl = 0) { |
|
88 | + if ($this->hasKey($key)) { |
|
89 | + return false; |
|
90 | + } else { |
|
91 | + return $this->set($key, $value, $ttl); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Increase a stored number |
|
97 | - * |
|
98 | - * @param string $key |
|
99 | - * @param int $step |
|
100 | - * @return int | bool |
|
101 | - */ |
|
102 | - public function inc($key, $step = 1) { |
|
103 | - return xcache_inc($this->getPrefix() . $key, $step); |
|
104 | - } |
|
95 | + /** |
|
96 | + * Increase a stored number |
|
97 | + * |
|
98 | + * @param string $key |
|
99 | + * @param int $step |
|
100 | + * @return int | bool |
|
101 | + */ |
|
102 | + public function inc($key, $step = 1) { |
|
103 | + return xcache_inc($this->getPrefix() . $key, $step); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Decrease a stored number |
|
108 | - * |
|
109 | - * @param string $key |
|
110 | - * @param int $step |
|
111 | - * @return int | bool |
|
112 | - */ |
|
113 | - public function dec($key, $step = 1) { |
|
114 | - return xcache_dec($this->getPrefix() . $key, $step); |
|
115 | - } |
|
106 | + /** |
|
107 | + * Decrease a stored number |
|
108 | + * |
|
109 | + * @param string $key |
|
110 | + * @param int $step |
|
111 | + * @return int | bool |
|
112 | + */ |
|
113 | + public function dec($key, $step = 1) { |
|
114 | + return xcache_dec($this->getPrefix() . $key, $step); |
|
115 | + } |
|
116 | 116 | |
117 | - static public function isAvailable() { |
|
118 | - if (!extension_loaded('xcache')) { |
|
119 | - return false; |
|
120 | - } |
|
121 | - if (\OC::$CLI && !getenv('XCACHE_TEST')) { |
|
122 | - return false; |
|
123 | - } |
|
124 | - if (!function_exists('xcache_unset_by_prefix') && \OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
125 | - // We do not want to use XCache if we can not clear it without |
|
126 | - // using the administration function xcache_clear_cache() |
|
127 | - // AND administration functions are password-protected. |
|
128 | - return false; |
|
129 | - } |
|
130 | - $var_size = \OC::$server->getIniWrapper()->getBytes('xcache.var_size'); |
|
131 | - if (!$var_size) { |
|
132 | - return false; |
|
133 | - } |
|
134 | - return true; |
|
135 | - } |
|
117 | + static public function isAvailable() { |
|
118 | + if (!extension_loaded('xcache')) { |
|
119 | + return false; |
|
120 | + } |
|
121 | + if (\OC::$CLI && !getenv('XCACHE_TEST')) { |
|
122 | + return false; |
|
123 | + } |
|
124 | + if (!function_exists('xcache_unset_by_prefix') && \OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
125 | + // We do not want to use XCache if we can not clear it without |
|
126 | + // using the administration function xcache_clear_cache() |
|
127 | + // AND administration functions are password-protected. |
|
128 | + return false; |
|
129 | + } |
|
130 | + $var_size = \OC::$server->getIniWrapper()->getBytes('xcache.var_size'); |
|
131 | + if (!$var_size) { |
|
132 | + return false; |
|
133 | + } |
|
134 | + return true; |
|
135 | + } |
|
136 | 136 | } |
@@ -47,28 +47,28 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | public function get($key) { |
50 | - return xcache_get($this->getNameSpace() . $key); |
|
50 | + return xcache_get($this->getNameSpace().$key); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | public function set($key, $value, $ttl = 0) { |
54 | 54 | if ($ttl > 0) { |
55 | - return xcache_set($this->getNameSpace() . $key, $value, $ttl); |
|
55 | + return xcache_set($this->getNameSpace().$key, $value, $ttl); |
|
56 | 56 | } else { |
57 | - return xcache_set($this->getNameSpace() . $key, $value); |
|
57 | + return xcache_set($this->getNameSpace().$key, $value); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | 61 | public function hasKey($key) { |
62 | - return xcache_isset($this->getNameSpace() . $key); |
|
62 | + return xcache_isset($this->getNameSpace().$key); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | public function remove($key) { |
66 | - return xcache_unset($this->getNameSpace() . $key); |
|
66 | + return xcache_unset($this->getNameSpace().$key); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | public function clear($prefix = '') { |
70 | 70 | if (function_exists('xcache_unset_by_prefix')) { |
71 | - return xcache_unset_by_prefix($this->getNameSpace() . $prefix); |
|
71 | + return xcache_unset_by_prefix($this->getNameSpace().$prefix); |
|
72 | 72 | } else { |
73 | 73 | // Since we can not clear by prefix, we just clear the whole cache. |
74 | 74 | xcache_clear_cache(\XC_TYPE_VAR, 0); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @return int | bool |
101 | 101 | */ |
102 | 102 | public function inc($key, $step = 1) { |
103 | - return xcache_inc($this->getPrefix() . $key, $step); |
|
103 | + return xcache_inc($this->getPrefix().$key, $step); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return int | bool |
112 | 112 | */ |
113 | 113 | public function dec($key, $step = 1) { |
114 | - return xcache_dec($this->getPrefix() . $key, $step); |
|
114 | + return xcache_dec($this->getPrefix().$key, $step); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | static public function isAvailable() { |
@@ -34,147 +34,147 @@ |
||
34 | 34 | */ |
35 | 35 | class CleanupRemoteStorages extends Command { |
36 | 36 | |
37 | - /** |
|
38 | - * @var IDBConnection |
|
39 | - */ |
|
40 | - protected $connection; |
|
41 | - |
|
42 | - public function __construct(IDBConnection $connection) { |
|
43 | - $this->connection = $connection; |
|
44 | - parent::__construct(); |
|
45 | - } |
|
46 | - |
|
47 | - protected function configure() { |
|
48 | - $this |
|
49 | - ->setName('sharing:cleanup-remote-storages') |
|
50 | - ->setDescription('Cleanup shared storage entries that have no matching entry in the shares_external table') |
|
51 | - ->addOption( |
|
52 | - 'dry-run', |
|
53 | - null, |
|
54 | - InputOption::VALUE_NONE, |
|
55 | - 'only show which storages would be deleted' |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - public function execute(InputInterface $input, OutputInterface $output) { |
|
60 | - |
|
61 | - $remoteStorages = $this->getRemoteStorages(); |
|
62 | - |
|
63 | - $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked'); |
|
64 | - |
|
65 | - $remoteShareIds = $this->getRemoteShareIds(); |
|
66 | - |
|
67 | - $output->writeln(count($remoteShareIds) . ' remote share(s) exist'); |
|
68 | - |
|
69 | - foreach ($remoteShareIds as $id => $remoteShareId) { |
|
70 | - if (isset($remoteStorages[$remoteShareId])) { |
|
71 | - if ($input->getOption('dry-run') || $output->isVerbose()) { |
|
72 | - $output->writeln("<info>$remoteShareId belongs to remote share $id</info>"); |
|
73 | - } |
|
74 | - |
|
75 | - unset($remoteStorages[$remoteShareId]); |
|
76 | - } else { |
|
77 | - $output->writeln("<comment>$remoteShareId for share $id has no matching storage, yet</comment>"); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - if (empty($remoteStorages)) { |
|
82 | - $output->writeln('<info>no storages deleted</info>'); |
|
83 | - } else { |
|
84 | - $dryRun = $input->getOption('dry-run'); |
|
85 | - foreach ($remoteStorages as $id => $numericId) { |
|
86 | - if ($dryRun) { |
|
87 | - $output->writeln("<error>$id [$numericId] can be deleted</error>"); |
|
88 | - $this->countFiles($numericId, $output); |
|
89 | - } else { |
|
90 | - $this->deleteStorage($id, $numericId, $output); |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - public function countFiles($numericId, OutputInterface $output) { |
|
97 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
98 | - $queryBuilder->select($queryBuilder->createFunction('count(fileid)')) |
|
99 | - ->from('filecache') |
|
100 | - ->where($queryBuilder->expr()->eq( |
|
101 | - 'storage', |
|
102 | - $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
103 | - IQueryBuilder::PARAM_STR) |
|
104 | - ); |
|
105 | - $result = $queryBuilder->execute(); |
|
106 | - $count = $result->fetchColumn(); |
|
107 | - $output->writeln("$count files can be deleted for storage $numericId"); |
|
108 | - } |
|
109 | - |
|
110 | - public function deleteStorage($id, $numericId, OutputInterface $output) { |
|
111 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
112 | - $queryBuilder->delete('storages') |
|
113 | - ->where($queryBuilder->expr()->eq( |
|
114 | - 'id', |
|
115 | - $queryBuilder->createNamedParameter($id, IQueryBuilder::PARAM_STR), |
|
116 | - IQueryBuilder::PARAM_STR) |
|
117 | - ); |
|
118 | - $output->write("deleting $id [$numericId] ... "); |
|
119 | - $count = $queryBuilder->execute(); |
|
120 | - $output->writeln("deleted $count storage"); |
|
121 | - $this->deleteFiles($numericId, $output); |
|
122 | - } |
|
123 | - |
|
124 | - public function deleteFiles($numericId, OutputInterface $output) { |
|
125 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
126 | - $queryBuilder->delete('filecache') |
|
127 | - ->where($queryBuilder->expr()->eq( |
|
128 | - 'storage', |
|
129 | - $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
130 | - IQueryBuilder::PARAM_STR) |
|
131 | - ); |
|
132 | - $output->write("deleting files for storage $numericId ... "); |
|
133 | - $count = $queryBuilder->execute(); |
|
134 | - $output->writeln("deleted $count files"); |
|
135 | - } |
|
136 | - |
|
137 | - public function getRemoteStorages() { |
|
138 | - |
|
139 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
140 | - $queryBuilder->select(['id', 'numeric_id']) |
|
141 | - ->from('storages') |
|
142 | - ->where($queryBuilder->expr()->like( |
|
143 | - 'id', |
|
144 | - // match all 'shared::' + 32 characters storages |
|
145 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)), |
|
146 | - IQueryBuilder::PARAM_STR) |
|
147 | - ) |
|
148 | - ->andWhere($queryBuilder->expr()->notLike( |
|
149 | - 'id', |
|
150 | - // but not the ones starting with a '/', they are for normal shares |
|
151 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'), |
|
152 | - IQueryBuilder::PARAM_STR) |
|
153 | - )->orderBy('numeric_id'); |
|
154 | - $query = $queryBuilder->execute(); |
|
155 | - |
|
156 | - $remoteStorages = []; |
|
157 | - |
|
158 | - while ($row = $query->fetch()) { |
|
159 | - $remoteStorages[$row['id']] = $row['numeric_id']; |
|
160 | - } |
|
161 | - |
|
162 | - return $remoteStorages; |
|
163 | - } |
|
164 | - |
|
165 | - public function getRemoteShareIds() { |
|
166 | - |
|
167 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
168 | - $queryBuilder->select(['id', 'share_token', 'remote']) |
|
169 | - ->from('share_external'); |
|
170 | - $query = $queryBuilder->execute(); |
|
171 | - |
|
172 | - $remoteShareIds = []; |
|
173 | - |
|
174 | - while ($row = $query->fetch()) { |
|
175 | - $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']); |
|
176 | - } |
|
177 | - |
|
178 | - return $remoteShareIds; |
|
179 | - } |
|
37 | + /** |
|
38 | + * @var IDBConnection |
|
39 | + */ |
|
40 | + protected $connection; |
|
41 | + |
|
42 | + public function __construct(IDBConnection $connection) { |
|
43 | + $this->connection = $connection; |
|
44 | + parent::__construct(); |
|
45 | + } |
|
46 | + |
|
47 | + protected function configure() { |
|
48 | + $this |
|
49 | + ->setName('sharing:cleanup-remote-storages') |
|
50 | + ->setDescription('Cleanup shared storage entries that have no matching entry in the shares_external table') |
|
51 | + ->addOption( |
|
52 | + 'dry-run', |
|
53 | + null, |
|
54 | + InputOption::VALUE_NONE, |
|
55 | + 'only show which storages would be deleted' |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + public function execute(InputInterface $input, OutputInterface $output) { |
|
60 | + |
|
61 | + $remoteStorages = $this->getRemoteStorages(); |
|
62 | + |
|
63 | + $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked'); |
|
64 | + |
|
65 | + $remoteShareIds = $this->getRemoteShareIds(); |
|
66 | + |
|
67 | + $output->writeln(count($remoteShareIds) . ' remote share(s) exist'); |
|
68 | + |
|
69 | + foreach ($remoteShareIds as $id => $remoteShareId) { |
|
70 | + if (isset($remoteStorages[$remoteShareId])) { |
|
71 | + if ($input->getOption('dry-run') || $output->isVerbose()) { |
|
72 | + $output->writeln("<info>$remoteShareId belongs to remote share $id</info>"); |
|
73 | + } |
|
74 | + |
|
75 | + unset($remoteStorages[$remoteShareId]); |
|
76 | + } else { |
|
77 | + $output->writeln("<comment>$remoteShareId for share $id has no matching storage, yet</comment>"); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + if (empty($remoteStorages)) { |
|
82 | + $output->writeln('<info>no storages deleted</info>'); |
|
83 | + } else { |
|
84 | + $dryRun = $input->getOption('dry-run'); |
|
85 | + foreach ($remoteStorages as $id => $numericId) { |
|
86 | + if ($dryRun) { |
|
87 | + $output->writeln("<error>$id [$numericId] can be deleted</error>"); |
|
88 | + $this->countFiles($numericId, $output); |
|
89 | + } else { |
|
90 | + $this->deleteStorage($id, $numericId, $output); |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + public function countFiles($numericId, OutputInterface $output) { |
|
97 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
98 | + $queryBuilder->select($queryBuilder->createFunction('count(fileid)')) |
|
99 | + ->from('filecache') |
|
100 | + ->where($queryBuilder->expr()->eq( |
|
101 | + 'storage', |
|
102 | + $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
103 | + IQueryBuilder::PARAM_STR) |
|
104 | + ); |
|
105 | + $result = $queryBuilder->execute(); |
|
106 | + $count = $result->fetchColumn(); |
|
107 | + $output->writeln("$count files can be deleted for storage $numericId"); |
|
108 | + } |
|
109 | + |
|
110 | + public function deleteStorage($id, $numericId, OutputInterface $output) { |
|
111 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
112 | + $queryBuilder->delete('storages') |
|
113 | + ->where($queryBuilder->expr()->eq( |
|
114 | + 'id', |
|
115 | + $queryBuilder->createNamedParameter($id, IQueryBuilder::PARAM_STR), |
|
116 | + IQueryBuilder::PARAM_STR) |
|
117 | + ); |
|
118 | + $output->write("deleting $id [$numericId] ... "); |
|
119 | + $count = $queryBuilder->execute(); |
|
120 | + $output->writeln("deleted $count storage"); |
|
121 | + $this->deleteFiles($numericId, $output); |
|
122 | + } |
|
123 | + |
|
124 | + public function deleteFiles($numericId, OutputInterface $output) { |
|
125 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
126 | + $queryBuilder->delete('filecache') |
|
127 | + ->where($queryBuilder->expr()->eq( |
|
128 | + 'storage', |
|
129 | + $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
130 | + IQueryBuilder::PARAM_STR) |
|
131 | + ); |
|
132 | + $output->write("deleting files for storage $numericId ... "); |
|
133 | + $count = $queryBuilder->execute(); |
|
134 | + $output->writeln("deleted $count files"); |
|
135 | + } |
|
136 | + |
|
137 | + public function getRemoteStorages() { |
|
138 | + |
|
139 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
140 | + $queryBuilder->select(['id', 'numeric_id']) |
|
141 | + ->from('storages') |
|
142 | + ->where($queryBuilder->expr()->like( |
|
143 | + 'id', |
|
144 | + // match all 'shared::' + 32 characters storages |
|
145 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)), |
|
146 | + IQueryBuilder::PARAM_STR) |
|
147 | + ) |
|
148 | + ->andWhere($queryBuilder->expr()->notLike( |
|
149 | + 'id', |
|
150 | + // but not the ones starting with a '/', they are for normal shares |
|
151 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'), |
|
152 | + IQueryBuilder::PARAM_STR) |
|
153 | + )->orderBy('numeric_id'); |
|
154 | + $query = $queryBuilder->execute(); |
|
155 | + |
|
156 | + $remoteStorages = []; |
|
157 | + |
|
158 | + while ($row = $query->fetch()) { |
|
159 | + $remoteStorages[$row['id']] = $row['numeric_id']; |
|
160 | + } |
|
161 | + |
|
162 | + return $remoteStorages; |
|
163 | + } |
|
164 | + |
|
165 | + public function getRemoteShareIds() { |
|
166 | + |
|
167 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
168 | + $queryBuilder->select(['id', 'share_token', 'remote']) |
|
169 | + ->from('share_external'); |
|
170 | + $query = $queryBuilder->execute(); |
|
171 | + |
|
172 | + $remoteShareIds = []; |
|
173 | + |
|
174 | + while ($row = $query->fetch()) { |
|
175 | + $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']); |
|
176 | + } |
|
177 | + |
|
178 | + return $remoteShareIds; |
|
179 | + } |
|
180 | 180 | } |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | |
61 | 61 | $remoteStorages = $this->getRemoteStorages(); |
62 | 62 | |
63 | - $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked'); |
|
63 | + $output->writeln(count($remoteStorages).' remote storage(s) need(s) to be checked'); |
|
64 | 64 | |
65 | 65 | $remoteShareIds = $this->getRemoteShareIds(); |
66 | 66 | |
67 | - $output->writeln(count($remoteShareIds) . ' remote share(s) exist'); |
|
67 | + $output->writeln(count($remoteShareIds).' remote share(s) exist'); |
|
68 | 68 | |
69 | 69 | foreach ($remoteShareIds as $id => $remoteShareId) { |
70 | 70 | if (isset($remoteStorages[$remoteShareId])) { |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | ->where($queryBuilder->expr()->like( |
143 | 143 | 'id', |
144 | 144 | // match all 'shared::' + 32 characters storages |
145 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)), |
|
145 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::').str_repeat('_', 32)), |
|
146 | 146 | IQueryBuilder::PARAM_STR) |
147 | 147 | ) |
148 | 148 | ->andWhere($queryBuilder->expr()->notLike( |
149 | 149 | 'id', |
150 | 150 | // but not the ones starting with a '/', they are for normal shares |
151 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'), |
|
151 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/').'%'), |
|
152 | 152 | IQueryBuilder::PARAM_STR) |
153 | 153 | )->orderBy('numeric_id'); |
154 | 154 | $query = $queryBuilder->execute(); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $remoteShareIds = []; |
173 | 173 | |
174 | 174 | while ($row = $query->fetch()) { |
175 | - $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']); |
|
175 | + $remoteShareIds[$row['id']] = 'shared::'.md5($row['share_token'].'@'.$row['remote']); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | return $remoteShareIds; |
@@ -106,7 +106,7 @@ |
||
106 | 106 | /** |
107 | 107 | * Prints an unsanitized string - usage of this function may result into XSS. |
108 | 108 | * Consider using p() instead. |
109 | - * @param string|array $string the string which will be printed as it is |
|
109 | + * @param string $string the string which will be printed as it is |
|
110 | 110 | */ |
111 | 111 | function print_unescaped($string) { |
112 | 112 | print($string); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param string $string the string which will be escaped and printed |
37 | 37 | */ |
38 | 38 | function p($string) { |
39 | - print(\OCP\Util::sanitizeHTML($string)); |
|
39 | + print(\OCP\Util::sanitizeHTML($string)); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
@@ -46,14 +46,14 @@ discard block |
||
46 | 46 | * @param string $opts, additional optional options |
47 | 47 | */ |
48 | 48 | function emit_css_tag($href, $opts = '') { |
49 | - $s='<link rel="stylesheet"'; |
|
50 | - if (!empty($href)) { |
|
51 | - $s.=' href="' . $href .'"'; |
|
52 | - } |
|
53 | - if (!empty($opts)) { |
|
54 | - $s.=' '.$opts; |
|
55 | - } |
|
56 | - print_unescaped($s.">\n"); |
|
49 | + $s='<link rel="stylesheet"'; |
|
50 | + if (!empty($href)) { |
|
51 | + $s.=' href="' . $href .'"'; |
|
52 | + } |
|
53 | + if (!empty($opts)) { |
|
54 | + $s.=' '.$opts; |
|
55 | + } |
|
56 | + print_unescaped($s.">\n"); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -61,12 +61,12 @@ discard block |
||
61 | 61 | * @param array $obj all the script information from template |
62 | 62 | */ |
63 | 63 | function emit_css_loading_tags($obj) { |
64 | - foreach($obj['cssfiles'] as $css) { |
|
65 | - emit_css_tag($css); |
|
66 | - } |
|
67 | - foreach($obj['printcssfiles'] as $css) { |
|
68 | - emit_css_tag($css, 'media="print"'); |
|
69 | - } |
|
64 | + foreach($obj['cssfiles'] as $css) { |
|
65 | + emit_css_tag($css); |
|
66 | + } |
|
67 | + foreach($obj['printcssfiles'] as $css) { |
|
68 | + emit_css_tag($css, 'media="print"'); |
|
69 | + } |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -75,20 +75,20 @@ discard block |
||
75 | 75 | * @param string $script_content the inline script content, ignored when empty |
76 | 76 | */ |
77 | 77 | function emit_script_tag($src, $script_content='') { |
78 | - $defer_str=' defer'; |
|
79 | - $s='<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"'; |
|
80 | - if (!empty($src)) { |
|
81 | - // emit script tag for deferred loading from $src |
|
82 | - $s.=$defer_str.' src="' . $src .'">'; |
|
83 | - } else if (!empty($script_content)) { |
|
84 | - // emit script tag for inline script from $script_content without defer (see MDN) |
|
85 | - $s.=">\n".$script_content."\n"; |
|
86 | - } else { |
|
87 | - // no $src nor $src_content, really useless empty tag |
|
88 | - $s.='>'; |
|
89 | - } |
|
90 | - $s.='</script>'; |
|
91 | - print_unescaped($s."\n"); |
|
78 | + $defer_str=' defer'; |
|
79 | + $s='<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"'; |
|
80 | + if (!empty($src)) { |
|
81 | + // emit script tag for deferred loading from $src |
|
82 | + $s.=$defer_str.' src="' . $src .'">'; |
|
83 | + } else if (!empty($script_content)) { |
|
84 | + // emit script tag for inline script from $script_content without defer (see MDN) |
|
85 | + $s.=">\n".$script_content."\n"; |
|
86 | + } else { |
|
87 | + // no $src nor $src_content, really useless empty tag |
|
88 | + $s.='>'; |
|
89 | + } |
|
90 | + $s.='</script>'; |
|
91 | + print_unescaped($s."\n"); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -96,12 +96,12 @@ discard block |
||
96 | 96 | * @param array $obj all the script information from template |
97 | 97 | */ |
98 | 98 | function emit_script_loading_tags($obj) { |
99 | - foreach($obj['jsfiles'] as $jsfile) { |
|
100 | - emit_script_tag($jsfile, ''); |
|
101 | - } |
|
102 | - if (!empty($obj['inline_ocjs'])) { |
|
103 | - emit_script_tag('', $obj['inline_ocjs']); |
|
104 | - } |
|
99 | + foreach($obj['jsfiles'] as $jsfile) { |
|
100 | + emit_script_tag($jsfile, ''); |
|
101 | + } |
|
102 | + if (!empty($obj['inline_ocjs'])) { |
|
103 | + emit_script_tag('', $obj['inline_ocjs']); |
|
104 | + } |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param string|array $string the string which will be printed as it is |
111 | 111 | */ |
112 | 112 | function print_unescaped($string) { |
113 | - print($string); |
|
113 | + print($string); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | * if an array is given it will add all scripts |
121 | 121 | */ |
122 | 122 | function script($app, $file = null) { |
123 | - if(is_array($file)) { |
|
124 | - foreach($file as $f) { |
|
125 | - OC_Util::addScript($app, $f); |
|
126 | - } |
|
127 | - } else { |
|
128 | - OC_Util::addScript($app, $file); |
|
129 | - } |
|
123 | + if(is_array($file)) { |
|
124 | + foreach($file as $f) { |
|
125 | + OC_Util::addScript($app, $f); |
|
126 | + } |
|
127 | + } else { |
|
128 | + OC_Util::addScript($app, $file); |
|
129 | + } |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | * if an array is given it will add all scripts |
137 | 137 | */ |
138 | 138 | function vendor_script($app, $file = null) { |
139 | - if(is_array($file)) { |
|
140 | - foreach($file as $f) { |
|
141 | - OC_Util::addVendorScript($app, $f); |
|
142 | - } |
|
143 | - } else { |
|
144 | - OC_Util::addVendorScript($app, $file); |
|
145 | - } |
|
139 | + if(is_array($file)) { |
|
140 | + foreach($file as $f) { |
|
141 | + OC_Util::addVendorScript($app, $f); |
|
142 | + } |
|
143 | + } else { |
|
144 | + OC_Util::addVendorScript($app, $file); |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -152,13 +152,13 @@ discard block |
||
152 | 152 | * if an array is given it will add all styles |
153 | 153 | */ |
154 | 154 | function style($app, $file = null) { |
155 | - if(is_array($file)) { |
|
156 | - foreach($file as $f) { |
|
157 | - OC_Util::addStyle($app, $f); |
|
158 | - } |
|
159 | - } else { |
|
160 | - OC_Util::addStyle($app, $file); |
|
161 | - } |
|
155 | + if(is_array($file)) { |
|
156 | + foreach($file as $f) { |
|
157 | + OC_Util::addStyle($app, $f); |
|
158 | + } |
|
159 | + } else { |
|
160 | + OC_Util::addStyle($app, $file); |
|
161 | + } |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -168,13 +168,13 @@ discard block |
||
168 | 168 | * if an array is given it will add all styles |
169 | 169 | */ |
170 | 170 | function vendor_style($app, $file = null) { |
171 | - if(is_array($file)) { |
|
172 | - foreach($file as $f) { |
|
173 | - OC_Util::addVendorStyle($app, $f); |
|
174 | - } |
|
175 | - } else { |
|
176 | - OC_Util::addVendorStyle($app, $file); |
|
177 | - } |
|
171 | + if(is_array($file)) { |
|
172 | + foreach($file as $f) { |
|
173 | + OC_Util::addVendorStyle($app, $f); |
|
174 | + } |
|
175 | + } else { |
|
176 | + OC_Util::addVendorStyle($app, $file); |
|
177 | + } |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * if an array is given it will add all styles |
184 | 184 | */ |
185 | 185 | function translation($app) { |
186 | - OC_Util::addTranslations($app); |
|
186 | + OC_Util::addTranslations($app); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | * if an array is given it will add all components |
194 | 194 | */ |
195 | 195 | function component($app, $file) { |
196 | - if(is_array($file)) { |
|
197 | - foreach($file as $f) { |
|
198 | - $url = link_to($app, 'component/' . $f . '.html'); |
|
199 | - OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url)); |
|
200 | - } |
|
201 | - } else { |
|
202 | - $url = link_to($app, 'component/' . $file . '.html'); |
|
203 | - OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url)); |
|
204 | - } |
|
196 | + if(is_array($file)) { |
|
197 | + foreach($file as $f) { |
|
198 | + $url = link_to($app, 'component/' . $f . '.html'); |
|
199 | + OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url)); |
|
200 | + } |
|
201 | + } else { |
|
202 | + $url = link_to($app, 'component/' . $file . '.html'); |
|
203 | + OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url)); |
|
204 | + } |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * For further information have a look at \OCP\IURLGenerator::linkTo |
215 | 215 | */ |
216 | 216 | function link_to( $app, $file, $args = array() ) { |
217 | - return \OC::$server->getURLGenerator()->linkTo($app, $file, $args); |
|
217 | + return \OC::$server->getURLGenerator()->linkTo($app, $file, $args); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * @return string url to the online documentation |
223 | 223 | */ |
224 | 224 | function link_to_docs($key) { |
225 | - return \OC::$server->getURLGenerator()->linkToDocs($key); |
|
225 | + return \OC::$server->getURLGenerator()->linkToDocs($key); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * For further information have a look at \OCP\IURLGenerator::imagePath |
235 | 235 | */ |
236 | 236 | function image_path( $app, $image ) { |
237 | - return \OC::$server->getURLGenerator()->imagePath( $app, $image ); |
|
237 | + return \OC::$server->getURLGenerator()->imagePath( $app, $image ); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @return string link to the image |
244 | 244 | */ |
245 | 245 | function mimetype_icon( $mimetype ) { |
246 | - return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype ); |
|
246 | + return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype ); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @return string link to the preview |
254 | 254 | */ |
255 | 255 | function preview_icon( $path ) { |
256 | - return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]); |
|
256 | + return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @return string |
263 | 263 | */ |
264 | 264 | function publicPreview_icon ( $path, $token ) { |
265 | - return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 'token' => $token]); |
|
265 | + return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 'token' => $token]); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * For further information have a look at OC_Helper::humanFileSize |
274 | 274 | */ |
275 | 275 | function human_file_size( $bytes ) { |
276 | - return OC_Helper::humanFileSize( $bytes ); |
|
276 | + return OC_Helper::humanFileSize( $bytes ); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -282,9 +282,9 @@ discard block |
||
282 | 282 | * @return int timestamp without time value |
283 | 283 | */ |
284 | 284 | function strip_time($timestamp){ |
285 | - $date = new \DateTime("@{$timestamp}"); |
|
286 | - $date->setTime(0, 0, 0); |
|
287 | - return (int)$date->format('U'); |
|
285 | + $date = new \DateTime("@{$timestamp}"); |
|
286 | + $date->setTime(0, 0, 0); |
|
287 | + return (int)$date->format('U'); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -296,39 +296,39 @@ discard block |
||
296 | 296 | * @return string timestamp |
297 | 297 | */ |
298 | 298 | function relative_modified_date($timestamp, $fromTime = null, $dateOnly = false) { |
299 | - /** @var \OC\DateTimeFormatter $formatter */ |
|
300 | - $formatter = \OC::$server->query('DateTimeFormatter'); |
|
299 | + /** @var \OC\DateTimeFormatter $formatter */ |
|
300 | + $formatter = \OC::$server->query('DateTimeFormatter'); |
|
301 | 301 | |
302 | - if ($dateOnly){ |
|
303 | - return $formatter->formatDateSpan($timestamp, $fromTime); |
|
304 | - } |
|
305 | - return $formatter->formatTimeSpan($timestamp, $fromTime); |
|
302 | + if ($dateOnly){ |
|
303 | + return $formatter->formatDateSpan($timestamp, $fromTime); |
|
304 | + } |
|
305 | + return $formatter->formatTimeSpan($timestamp, $fromTime); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | function html_select_options($options, $selected, $params=array()) { |
309 | - if (!is_array($selected)) { |
|
310 | - $selected=array($selected); |
|
311 | - } |
|
312 | - if (isset($params['combine']) && $params['combine']) { |
|
313 | - $options = array_combine($options, $options); |
|
314 | - } |
|
315 | - $value_name = $label_name = false; |
|
316 | - if (isset($params['value'])) { |
|
317 | - $value_name = $params['value']; |
|
318 | - } |
|
319 | - if (isset($params['label'])) { |
|
320 | - $label_name = $params['label']; |
|
321 | - } |
|
322 | - $html = ''; |
|
323 | - foreach($options as $value => $label) { |
|
324 | - if ($value_name && is_array($label)) { |
|
325 | - $value = $label[$value_name]; |
|
326 | - } |
|
327 | - if ($label_name && is_array($label)) { |
|
328 | - $label = $label[$label_name]; |
|
329 | - } |
|
330 | - $select = in_array($value, $selected) ? ' selected="selected"' : ''; |
|
331 | - $html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n"; |
|
332 | - } |
|
333 | - return $html; |
|
309 | + if (!is_array($selected)) { |
|
310 | + $selected=array($selected); |
|
311 | + } |
|
312 | + if (isset($params['combine']) && $params['combine']) { |
|
313 | + $options = array_combine($options, $options); |
|
314 | + } |
|
315 | + $value_name = $label_name = false; |
|
316 | + if (isset($params['value'])) { |
|
317 | + $value_name = $params['value']; |
|
318 | + } |
|
319 | + if (isset($params['label'])) { |
|
320 | + $label_name = $params['label']; |
|
321 | + } |
|
322 | + $html = ''; |
|
323 | + foreach($options as $value => $label) { |
|
324 | + if ($value_name && is_array($label)) { |
|
325 | + $value = $label[$value_name]; |
|
326 | + } |
|
327 | + if ($label_name && is_array($label)) { |
|
328 | + $label = $label[$label_name]; |
|
329 | + } |
|
330 | + $select = in_array($value, $selected) ? ' selected="selected"' : ''; |
|
331 | + $html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n"; |
|
332 | + } |
|
333 | + return $html; |
|
334 | 334 | } |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | * @param string $opts, additional optional options |
47 | 47 | */ |
48 | 48 | function emit_css_tag($href, $opts = '') { |
49 | - $s='<link rel="stylesheet"'; |
|
49 | + $s = '<link rel="stylesheet"'; |
|
50 | 50 | if (!empty($href)) { |
51 | - $s.=' href="' . $href .'"'; |
|
51 | + $s .= ' href="'.$href.'"'; |
|
52 | 52 | } |
53 | 53 | if (!empty($opts)) { |
54 | - $s.=' '.$opts; |
|
54 | + $s .= ' '.$opts; |
|
55 | 55 | } |
56 | 56 | print_unescaped($s.">\n"); |
57 | 57 | } |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * @param array $obj all the script information from template |
62 | 62 | */ |
63 | 63 | function emit_css_loading_tags($obj) { |
64 | - foreach($obj['cssfiles'] as $css) { |
|
64 | + foreach ($obj['cssfiles'] as $css) { |
|
65 | 65 | emit_css_tag($css); |
66 | 66 | } |
67 | - foreach($obj['printcssfiles'] as $css) { |
|
67 | + foreach ($obj['printcssfiles'] as $css) { |
|
68 | 68 | emit_css_tag($css, 'media="print"'); |
69 | 69 | } |
70 | 70 | } |
@@ -74,20 +74,20 @@ discard block |
||
74 | 74 | * @param string $src the source URL, ignored when empty |
75 | 75 | * @param string $script_content the inline script content, ignored when empty |
76 | 76 | */ |
77 | -function emit_script_tag($src, $script_content='') { |
|
78 | - $defer_str=' defer'; |
|
79 | - $s='<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"'; |
|
77 | +function emit_script_tag($src, $script_content = '') { |
|
78 | + $defer_str = ' defer'; |
|
79 | + $s = '<script nonce="'.\OC::$server->getContentSecurityPolicyNonceManager()->getNonce().'"'; |
|
80 | 80 | if (!empty($src)) { |
81 | 81 | // emit script tag for deferred loading from $src |
82 | - $s.=$defer_str.' src="' . $src .'">'; |
|
82 | + $s .= $defer_str.' src="'.$src.'">'; |
|
83 | 83 | } else if (!empty($script_content)) { |
84 | 84 | // emit script tag for inline script from $script_content without defer (see MDN) |
85 | - $s.=">\n".$script_content."\n"; |
|
85 | + $s .= ">\n".$script_content."\n"; |
|
86 | 86 | } else { |
87 | 87 | // no $src nor $src_content, really useless empty tag |
88 | - $s.='>'; |
|
88 | + $s .= '>'; |
|
89 | 89 | } |
90 | - $s.='</script>'; |
|
90 | + $s .= '</script>'; |
|
91 | 91 | print_unescaped($s."\n"); |
92 | 92 | } |
93 | 93 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @param array $obj all the script information from template |
97 | 97 | */ |
98 | 98 | function emit_script_loading_tags($obj) { |
99 | - foreach($obj['jsfiles'] as $jsfile) { |
|
99 | + foreach ($obj['jsfiles'] as $jsfile) { |
|
100 | 100 | emit_script_tag($jsfile, ''); |
101 | 101 | } |
102 | 102 | if (!empty($obj['inline_ocjs'])) { |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * if an array is given it will add all scripts |
121 | 121 | */ |
122 | 122 | function script($app, $file = null) { |
123 | - if(is_array($file)) { |
|
124 | - foreach($file as $f) { |
|
123 | + if (is_array($file)) { |
|
124 | + foreach ($file as $f) { |
|
125 | 125 | OC_Util::addScript($app, $f); |
126 | 126 | } |
127 | 127 | } else { |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * if an array is given it will add all scripts |
137 | 137 | */ |
138 | 138 | function vendor_script($app, $file = null) { |
139 | - if(is_array($file)) { |
|
140 | - foreach($file as $f) { |
|
139 | + if (is_array($file)) { |
|
140 | + foreach ($file as $f) { |
|
141 | 141 | OC_Util::addVendorScript($app, $f); |
142 | 142 | } |
143 | 143 | } else { |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | * if an array is given it will add all styles |
153 | 153 | */ |
154 | 154 | function style($app, $file = null) { |
155 | - if(is_array($file)) { |
|
156 | - foreach($file as $f) { |
|
155 | + if (is_array($file)) { |
|
156 | + foreach ($file as $f) { |
|
157 | 157 | OC_Util::addStyle($app, $f); |
158 | 158 | } |
159 | 159 | } else { |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | * if an array is given it will add all styles |
169 | 169 | */ |
170 | 170 | function vendor_style($app, $file = null) { |
171 | - if(is_array($file)) { |
|
172 | - foreach($file as $f) { |
|
171 | + if (is_array($file)) { |
|
172 | + foreach ($file as $f) { |
|
173 | 173 | OC_Util::addVendorStyle($app, $f); |
174 | 174 | } |
175 | 175 | } else { |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | * if an array is given it will add all components |
194 | 194 | */ |
195 | 195 | function component($app, $file) { |
196 | - if(is_array($file)) { |
|
197 | - foreach($file as $f) { |
|
198 | - $url = link_to($app, 'component/' . $f . '.html'); |
|
196 | + if (is_array($file)) { |
|
197 | + foreach ($file as $f) { |
|
198 | + $url = link_to($app, 'component/'.$f.'.html'); |
|
199 | 199 | OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url)); |
200 | 200 | } |
201 | 201 | } else { |
202 | - $url = link_to($app, 'component/' . $file . '.html'); |
|
202 | + $url = link_to($app, 'component/'.$file.'.html'); |
|
203 | 203 | OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url)); |
204 | 204 | } |
205 | 205 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * |
214 | 214 | * For further information have a look at \OCP\IURLGenerator::linkTo |
215 | 215 | */ |
216 | -function link_to( $app, $file, $args = array() ) { |
|
216 | +function link_to($app, $file, $args = array()) { |
|
217 | 217 | return \OC::$server->getURLGenerator()->linkTo($app, $file, $args); |
218 | 218 | } |
219 | 219 | |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * |
234 | 234 | * For further information have a look at \OCP\IURLGenerator::imagePath |
235 | 235 | */ |
236 | -function image_path( $app, $image ) { |
|
237 | - return \OC::$server->getURLGenerator()->imagePath( $app, $image ); |
|
236 | +function image_path($app, $image) { |
|
237 | + return \OC::$server->getURLGenerator()->imagePath($app, $image); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | * @param string $mimetype mimetype |
243 | 243 | * @return string link to the image |
244 | 244 | */ |
245 | -function mimetype_icon( $mimetype ) { |
|
246 | - return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype ); |
|
245 | +function mimetype_icon($mimetype) { |
|
246 | + return \OC::$server->getMimeTypeDetector()->mimeTypeIcon($mimetype); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param string $path path of file |
253 | 253 | * @return string link to the preview |
254 | 254 | */ |
255 | -function preview_icon( $path ) { |
|
255 | +function preview_icon($path) { |
|
256 | 256 | return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]); |
257 | 257 | } |
258 | 258 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * @param string $token |
262 | 262 | * @return string |
263 | 263 | */ |
264 | -function publicPreview_icon ( $path, $token ) { |
|
264 | +function publicPreview_icon($path, $token) { |
|
265 | 265 | return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 'token' => $token]); |
266 | 266 | } |
267 | 267 | |
@@ -272,8 +272,8 @@ discard block |
||
272 | 272 | * |
273 | 273 | * For further information have a look at OC_Helper::humanFileSize |
274 | 274 | */ |
275 | -function human_file_size( $bytes ) { |
|
276 | - return OC_Helper::humanFileSize( $bytes ); |
|
275 | +function human_file_size($bytes) { |
|
276 | + return OC_Helper::humanFileSize($bytes); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -281,10 +281,10 @@ discard block |
||
281 | 281 | * @param int $timestamp UNIX timestamp to strip |
282 | 282 | * @return int timestamp without time value |
283 | 283 | */ |
284 | -function strip_time($timestamp){ |
|
284 | +function strip_time($timestamp) { |
|
285 | 285 | $date = new \DateTime("@{$timestamp}"); |
286 | 286 | $date->setTime(0, 0, 0); |
287 | - return (int)$date->format('U'); |
|
287 | + return (int) $date->format('U'); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -299,15 +299,15 @@ discard block |
||
299 | 299 | /** @var \OC\DateTimeFormatter $formatter */ |
300 | 300 | $formatter = \OC::$server->query('DateTimeFormatter'); |
301 | 301 | |
302 | - if ($dateOnly){ |
|
302 | + if ($dateOnly) { |
|
303 | 303 | return $formatter->formatDateSpan($timestamp, $fromTime); |
304 | 304 | } |
305 | 305 | return $formatter->formatTimeSpan($timestamp, $fromTime); |
306 | 306 | } |
307 | 307 | |
308 | -function html_select_options($options, $selected, $params=array()) { |
|
308 | +function html_select_options($options, $selected, $params = array()) { |
|
309 | 309 | if (!is_array($selected)) { |
310 | - $selected=array($selected); |
|
310 | + $selected = array($selected); |
|
311 | 311 | } |
312 | 312 | if (isset($params['combine']) && $params['combine']) { |
313 | 313 | $options = array_combine($options, $options); |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | $label_name = $params['label']; |
321 | 321 | } |
322 | 322 | $html = ''; |
323 | - foreach($options as $value => $label) { |
|
323 | + foreach ($options as $value => $label) { |
|
324 | 324 | if ($value_name && is_array($label)) { |
325 | 325 | $value = $label[$value_name]; |
326 | 326 | } |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | $label = $label[$label_name]; |
329 | 329 | } |
330 | 330 | $select = in_array($value, $selected) ? ' selected="selected"' : ''; |
331 | - $html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n"; |
|
331 | + $html .= '<option value="'.\OCP\Util::sanitizeHTML($value).'"'.$select.'>'.\OCP\Util::sanitizeHTML($label).'</option>'."\n"; |
|
332 | 332 | } |
333 | 333 | return $html; |
334 | 334 | } |
@@ -261,7 +261,7 @@ |
||
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Get the currently used Content-Security-Policy |
264 | - * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
264 | + * @return ContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
265 | 265 | * none specified. |
266 | 266 | * @since 8.1.0 |
267 | 267 | */ |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | * @since 6.0.0 - return value was added in 7.0.0 |
97 | 97 | */ |
98 | 98 | public function cacheFor(int $cacheSeconds) { |
99 | - if($cacheSeconds > 0) { |
|
100 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
99 | + if ($cacheSeconds > 0) { |
|
100 | + $this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate'); |
|
101 | 101 | |
102 | 102 | // Old scool prama caching |
103 | 103 | $this->addHeader('Pragma', 'public'); |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @since 8.0.0 |
162 | 162 | */ |
163 | 163 | public function invalidateCookies(array $cookieNames) { |
164 | - foreach($cookieNames as $cookieName) { |
|
164 | + foreach ($cookieNames as $cookieName) { |
|
165 | 165 | $this->invalidateCookie($cookieName); |
166 | 166 | } |
167 | 167 | return $this; |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | * @since 6.0.0 - return value was added in 7.0.0 |
186 | 186 | */ |
187 | 187 | public function addHeader($name, $value) { |
188 | - $name = trim($name); // always remove leading and trailing whitespace |
|
188 | + $name = trim($name); // always remove leading and trailing whitespace |
|
189 | 189 | // to be able to reliably check for security |
190 | 190 | // headers |
191 | 191 | |
192 | - if(is_null($value)) { |
|
192 | + if (is_null($value)) { |
|
193 | 193 | unset($this->headers[$name]); |
194 | 194 | } else { |
195 | 195 | $this->headers[$name] = $value; |
@@ -220,19 +220,19 @@ discard block |
||
220 | 220 | public function getHeaders() { |
221 | 221 | $mergeWith = []; |
222 | 222 | |
223 | - if($this->lastModified) { |
|
223 | + if ($this->lastModified) { |
|
224 | 224 | $mergeWith['Last-Modified'] = |
225 | 225 | $this->lastModified->format(\DateTime::RFC2822); |
226 | 226 | } |
227 | 227 | |
228 | 228 | // Build Content-Security-Policy and use default if none has been specified |
229 | - if(is_null($this->contentSecurityPolicy)) { |
|
229 | + if (is_null($this->contentSecurityPolicy)) { |
|
230 | 230 | $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
231 | 231 | } |
232 | 232 | $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
233 | 233 | |
234 | - if($this->ETag) { |
|
235 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
234 | + if ($this->ETag) { |
|
235 | + $mergeWith['ETag'] = '"'.$this->ETag.'"'; |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | return array_merge($mergeWith, $this->headers); |
@@ -45,329 +45,329 @@ |
||
45 | 45 | */ |
46 | 46 | class Response { |
47 | 47 | |
48 | - /** |
|
49 | - * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
50 | - * @var array |
|
51 | - */ |
|
52 | - private $headers = array( |
|
53 | - 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
54 | - ); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Cookies that will be need to be constructed as header |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - private $cookies = array(); |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * HTTP status code - defaults to STATUS OK |
|
66 | - * @var int |
|
67 | - */ |
|
68 | - private $status = Http::STATUS_OK; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Last modified date |
|
73 | - * @var \DateTime |
|
74 | - */ |
|
75 | - private $lastModified; |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * ETag |
|
80 | - * @var string |
|
81 | - */ |
|
82 | - private $ETag; |
|
83 | - |
|
84 | - /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
85 | - private $contentSecurityPolicy = null; |
|
86 | - |
|
87 | - /** @var bool */ |
|
88 | - private $throttled = false; |
|
89 | - /** @var array */ |
|
90 | - private $throttleMetadata = []; |
|
91 | - |
|
92 | - /** |
|
93 | - * Caches the response |
|
94 | - * @param int $cacheSeconds the amount of seconds that should be cached |
|
95 | - * if 0 then caching will be disabled |
|
96 | - * @return $this |
|
97 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
98 | - */ |
|
99 | - public function cacheFor(int $cacheSeconds) { |
|
100 | - if($cacheSeconds > 0) { |
|
101 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
102 | - |
|
103 | - // Old scool prama caching |
|
104 | - $this->addHeader('Pragma', 'public'); |
|
105 | - |
|
106 | - // Set expires header |
|
107 | - $expires = new \DateTime(); |
|
108 | - /** @var ITimeFactory $time */ |
|
109 | - $time = \OC::$server->query(ITimeFactory::class); |
|
110 | - $expires->setTimestamp($time->getTime()); |
|
111 | - $expires->add(new \DateInterval('PT'.$cacheSeconds.'S')); |
|
112 | - $this->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
113 | - } else { |
|
114 | - $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
115 | - unset($this->headers['Expires'], $this->headers['Pragma']); |
|
116 | - } |
|
117 | - |
|
118 | - return $this; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Adds a new cookie to the response |
|
123 | - * @param string $name The name of the cookie |
|
124 | - * @param string $value The value of the cookie |
|
125 | - * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
126 | - * to null cookie will be considered as session |
|
127 | - * cookie. |
|
128 | - * @return $this |
|
129 | - * @since 8.0.0 |
|
130 | - */ |
|
131 | - public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
132 | - $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
133 | - return $this; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Set the specified cookies |
|
139 | - * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
140 | - * @return $this |
|
141 | - * @since 8.0.0 |
|
142 | - */ |
|
143 | - public function setCookies(array $cookies) { |
|
144 | - $this->cookies = $cookies; |
|
145 | - return $this; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * Invalidates the specified cookie |
|
151 | - * @param string $name |
|
152 | - * @return $this |
|
153 | - * @since 8.0.0 |
|
154 | - */ |
|
155 | - public function invalidateCookie($name) { |
|
156 | - $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
157 | - return $this; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Invalidates the specified cookies |
|
162 | - * @param array $cookieNames array('foo', 'bar') |
|
163 | - * @return $this |
|
164 | - * @since 8.0.0 |
|
165 | - */ |
|
166 | - public function invalidateCookies(array $cookieNames) { |
|
167 | - foreach($cookieNames as $cookieName) { |
|
168 | - $this->invalidateCookie($cookieName); |
|
169 | - } |
|
170 | - return $this; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Returns the cookies |
|
175 | - * @return array |
|
176 | - * @since 8.0.0 |
|
177 | - */ |
|
178 | - public function getCookies() { |
|
179 | - return $this->cookies; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Adds a new header to the response that will be called before the render |
|
184 | - * function |
|
185 | - * @param string $name The name of the HTTP header |
|
186 | - * @param string $value The value, null will delete it |
|
187 | - * @return $this |
|
188 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
189 | - */ |
|
190 | - public function addHeader($name, $value) { |
|
191 | - $name = trim($name); // always remove leading and trailing whitespace |
|
192 | - // to be able to reliably check for security |
|
193 | - // headers |
|
194 | - |
|
195 | - if(is_null($value)) { |
|
196 | - unset($this->headers[$name]); |
|
197 | - } else { |
|
198 | - $this->headers[$name] = $value; |
|
199 | - } |
|
200 | - |
|
201 | - return $this; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * Set the headers |
|
207 | - * @param array $headers value header pairs |
|
208 | - * @return $this |
|
209 | - * @since 8.0.0 |
|
210 | - */ |
|
211 | - public function setHeaders(array $headers) { |
|
212 | - $this->headers = $headers; |
|
213 | - |
|
214 | - return $this; |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * Returns the set headers |
|
220 | - * @return array the headers |
|
221 | - * @since 6.0.0 |
|
222 | - */ |
|
223 | - public function getHeaders() { |
|
224 | - $mergeWith = []; |
|
225 | - |
|
226 | - if($this->lastModified) { |
|
227 | - $mergeWith['Last-Modified'] = |
|
228 | - $this->lastModified->format(\DateTime::RFC2822); |
|
229 | - } |
|
230 | - |
|
231 | - // Build Content-Security-Policy and use default if none has been specified |
|
232 | - if(is_null($this->contentSecurityPolicy)) { |
|
233 | - $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
234 | - } |
|
235 | - $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
236 | - |
|
237 | - if($this->ETag) { |
|
238 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
239 | - } |
|
240 | - |
|
241 | - return array_merge($mergeWith, $this->headers); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * By default renders no output |
|
247 | - * @return string |
|
248 | - * @since 6.0.0 |
|
249 | - */ |
|
250 | - public function render() { |
|
251 | - return ''; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * Set response status |
|
257 | - * @param int $status a HTTP status code, see also the STATUS constants |
|
258 | - * @return Response Reference to this object |
|
259 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
260 | - */ |
|
261 | - public function setStatus($status) { |
|
262 | - $this->status = $status; |
|
263 | - |
|
264 | - return $this; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Set a Content-Security-Policy |
|
269 | - * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
270 | - * @return $this |
|
271 | - * @since 8.1.0 |
|
272 | - */ |
|
273 | - public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
274 | - $this->contentSecurityPolicy = $csp; |
|
275 | - return $this; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Get the currently used Content-Security-Policy |
|
280 | - * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
281 | - * none specified. |
|
282 | - * @since 8.1.0 |
|
283 | - */ |
|
284 | - public function getContentSecurityPolicy() { |
|
285 | - return $this->contentSecurityPolicy; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * Get response status |
|
291 | - * @since 6.0.0 |
|
292 | - */ |
|
293 | - public function getStatus() { |
|
294 | - return $this->status; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * Get the ETag |
|
300 | - * @return string the etag |
|
301 | - * @since 6.0.0 |
|
302 | - */ |
|
303 | - public function getETag() { |
|
304 | - return $this->ETag; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * Get "last modified" date |
|
310 | - * @return \DateTime RFC2822 formatted last modified date |
|
311 | - * @since 6.0.0 |
|
312 | - */ |
|
313 | - public function getLastModified() { |
|
314 | - return $this->lastModified; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Set the ETag |
|
320 | - * @param string $ETag |
|
321 | - * @return Response Reference to this object |
|
322 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
323 | - */ |
|
324 | - public function setETag($ETag) { |
|
325 | - $this->ETag = $ETag; |
|
326 | - |
|
327 | - return $this; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * Set "last modified" date |
|
333 | - * @param \DateTime $lastModified |
|
334 | - * @return Response Reference to this object |
|
335 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
336 | - */ |
|
337 | - public function setLastModified($lastModified) { |
|
338 | - $this->lastModified = $lastModified; |
|
339 | - |
|
340 | - return $this; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Marks the response as to throttle. Will be throttled when the |
|
345 | - * @BruteForceProtection annotation is added. |
|
346 | - * |
|
347 | - * @param array $metadata |
|
348 | - * @since 12.0.0 |
|
349 | - */ |
|
350 | - public function throttle(array $metadata = []) { |
|
351 | - $this->throttled = true; |
|
352 | - $this->throttleMetadata = $metadata; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Returns the throttle metadata, defaults to empty array |
|
357 | - * |
|
358 | - * @return array |
|
359 | - * @since 13.0.0 |
|
360 | - */ |
|
361 | - public function getThrottleMetadata() { |
|
362 | - return $this->throttleMetadata; |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Whether the current response is throttled. |
|
367 | - * |
|
368 | - * @since 12.0.0 |
|
369 | - */ |
|
370 | - public function isThrottled() { |
|
371 | - return $this->throttled; |
|
372 | - } |
|
48 | + /** |
|
49 | + * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
50 | + * @var array |
|
51 | + */ |
|
52 | + private $headers = array( |
|
53 | + 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
54 | + ); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Cookies that will be need to be constructed as header |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + private $cookies = array(); |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * HTTP status code - defaults to STATUS OK |
|
66 | + * @var int |
|
67 | + */ |
|
68 | + private $status = Http::STATUS_OK; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Last modified date |
|
73 | + * @var \DateTime |
|
74 | + */ |
|
75 | + private $lastModified; |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * ETag |
|
80 | + * @var string |
|
81 | + */ |
|
82 | + private $ETag; |
|
83 | + |
|
84 | + /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
85 | + private $contentSecurityPolicy = null; |
|
86 | + |
|
87 | + /** @var bool */ |
|
88 | + private $throttled = false; |
|
89 | + /** @var array */ |
|
90 | + private $throttleMetadata = []; |
|
91 | + |
|
92 | + /** |
|
93 | + * Caches the response |
|
94 | + * @param int $cacheSeconds the amount of seconds that should be cached |
|
95 | + * if 0 then caching will be disabled |
|
96 | + * @return $this |
|
97 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
98 | + */ |
|
99 | + public function cacheFor(int $cacheSeconds) { |
|
100 | + if($cacheSeconds > 0) { |
|
101 | + $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
102 | + |
|
103 | + // Old scool prama caching |
|
104 | + $this->addHeader('Pragma', 'public'); |
|
105 | + |
|
106 | + // Set expires header |
|
107 | + $expires = new \DateTime(); |
|
108 | + /** @var ITimeFactory $time */ |
|
109 | + $time = \OC::$server->query(ITimeFactory::class); |
|
110 | + $expires->setTimestamp($time->getTime()); |
|
111 | + $expires->add(new \DateInterval('PT'.$cacheSeconds.'S')); |
|
112 | + $this->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
113 | + } else { |
|
114 | + $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
115 | + unset($this->headers['Expires'], $this->headers['Pragma']); |
|
116 | + } |
|
117 | + |
|
118 | + return $this; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Adds a new cookie to the response |
|
123 | + * @param string $name The name of the cookie |
|
124 | + * @param string $value The value of the cookie |
|
125 | + * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
126 | + * to null cookie will be considered as session |
|
127 | + * cookie. |
|
128 | + * @return $this |
|
129 | + * @since 8.0.0 |
|
130 | + */ |
|
131 | + public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
132 | + $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
133 | + return $this; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Set the specified cookies |
|
139 | + * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
140 | + * @return $this |
|
141 | + * @since 8.0.0 |
|
142 | + */ |
|
143 | + public function setCookies(array $cookies) { |
|
144 | + $this->cookies = $cookies; |
|
145 | + return $this; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * Invalidates the specified cookie |
|
151 | + * @param string $name |
|
152 | + * @return $this |
|
153 | + * @since 8.0.0 |
|
154 | + */ |
|
155 | + public function invalidateCookie($name) { |
|
156 | + $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
157 | + return $this; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Invalidates the specified cookies |
|
162 | + * @param array $cookieNames array('foo', 'bar') |
|
163 | + * @return $this |
|
164 | + * @since 8.0.0 |
|
165 | + */ |
|
166 | + public function invalidateCookies(array $cookieNames) { |
|
167 | + foreach($cookieNames as $cookieName) { |
|
168 | + $this->invalidateCookie($cookieName); |
|
169 | + } |
|
170 | + return $this; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Returns the cookies |
|
175 | + * @return array |
|
176 | + * @since 8.0.0 |
|
177 | + */ |
|
178 | + public function getCookies() { |
|
179 | + return $this->cookies; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Adds a new header to the response that will be called before the render |
|
184 | + * function |
|
185 | + * @param string $name The name of the HTTP header |
|
186 | + * @param string $value The value, null will delete it |
|
187 | + * @return $this |
|
188 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
189 | + */ |
|
190 | + public function addHeader($name, $value) { |
|
191 | + $name = trim($name); // always remove leading and trailing whitespace |
|
192 | + // to be able to reliably check for security |
|
193 | + // headers |
|
194 | + |
|
195 | + if(is_null($value)) { |
|
196 | + unset($this->headers[$name]); |
|
197 | + } else { |
|
198 | + $this->headers[$name] = $value; |
|
199 | + } |
|
200 | + |
|
201 | + return $this; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * Set the headers |
|
207 | + * @param array $headers value header pairs |
|
208 | + * @return $this |
|
209 | + * @since 8.0.0 |
|
210 | + */ |
|
211 | + public function setHeaders(array $headers) { |
|
212 | + $this->headers = $headers; |
|
213 | + |
|
214 | + return $this; |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * Returns the set headers |
|
220 | + * @return array the headers |
|
221 | + * @since 6.0.0 |
|
222 | + */ |
|
223 | + public function getHeaders() { |
|
224 | + $mergeWith = []; |
|
225 | + |
|
226 | + if($this->lastModified) { |
|
227 | + $mergeWith['Last-Modified'] = |
|
228 | + $this->lastModified->format(\DateTime::RFC2822); |
|
229 | + } |
|
230 | + |
|
231 | + // Build Content-Security-Policy and use default if none has been specified |
|
232 | + if(is_null($this->contentSecurityPolicy)) { |
|
233 | + $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
234 | + } |
|
235 | + $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
236 | + |
|
237 | + if($this->ETag) { |
|
238 | + $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
239 | + } |
|
240 | + |
|
241 | + return array_merge($mergeWith, $this->headers); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * By default renders no output |
|
247 | + * @return string |
|
248 | + * @since 6.0.0 |
|
249 | + */ |
|
250 | + public function render() { |
|
251 | + return ''; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * Set response status |
|
257 | + * @param int $status a HTTP status code, see also the STATUS constants |
|
258 | + * @return Response Reference to this object |
|
259 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
260 | + */ |
|
261 | + public function setStatus($status) { |
|
262 | + $this->status = $status; |
|
263 | + |
|
264 | + return $this; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Set a Content-Security-Policy |
|
269 | + * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
270 | + * @return $this |
|
271 | + * @since 8.1.0 |
|
272 | + */ |
|
273 | + public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
274 | + $this->contentSecurityPolicy = $csp; |
|
275 | + return $this; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Get the currently used Content-Security-Policy |
|
280 | + * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
281 | + * none specified. |
|
282 | + * @since 8.1.0 |
|
283 | + */ |
|
284 | + public function getContentSecurityPolicy() { |
|
285 | + return $this->contentSecurityPolicy; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * Get response status |
|
291 | + * @since 6.0.0 |
|
292 | + */ |
|
293 | + public function getStatus() { |
|
294 | + return $this->status; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * Get the ETag |
|
300 | + * @return string the etag |
|
301 | + * @since 6.0.0 |
|
302 | + */ |
|
303 | + public function getETag() { |
|
304 | + return $this->ETag; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * Get "last modified" date |
|
310 | + * @return \DateTime RFC2822 formatted last modified date |
|
311 | + * @since 6.0.0 |
|
312 | + */ |
|
313 | + public function getLastModified() { |
|
314 | + return $this->lastModified; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Set the ETag |
|
320 | + * @param string $ETag |
|
321 | + * @return Response Reference to this object |
|
322 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
323 | + */ |
|
324 | + public function setETag($ETag) { |
|
325 | + $this->ETag = $ETag; |
|
326 | + |
|
327 | + return $this; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * Set "last modified" date |
|
333 | + * @param \DateTime $lastModified |
|
334 | + * @return Response Reference to this object |
|
335 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
336 | + */ |
|
337 | + public function setLastModified($lastModified) { |
|
338 | + $this->lastModified = $lastModified; |
|
339 | + |
|
340 | + return $this; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Marks the response as to throttle. Will be throttled when the |
|
345 | + * @BruteForceProtection annotation is added. |
|
346 | + * |
|
347 | + * @param array $metadata |
|
348 | + * @since 12.0.0 |
|
349 | + */ |
|
350 | + public function throttle(array $metadata = []) { |
|
351 | + $this->throttled = true; |
|
352 | + $this->throttleMetadata = $metadata; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Returns the throttle metadata, defaults to empty array |
|
357 | + * |
|
358 | + * @return array |
|
359 | + * @since 13.0.0 |
|
360 | + */ |
|
361 | + public function getThrottleMetadata() { |
|
362 | + return $this->throttleMetadata; |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Whether the current response is throttled. |
|
367 | + * |
|
368 | + * @since 12.0.0 |
|
369 | + */ |
|
370 | + public function isThrottled() { |
|
371 | + return $this->throttled; |
|
372 | + } |
|
373 | 373 | } |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * pass all other function directly to the \Doctrine\DBAL\Driver\Statement |
56 | 56 | */ |
57 | - public function __call($name,$arguments) { |
|
58 | - return call_user_func_array(array($this->statement,$name), $arguments); |
|
57 | + public function __call($name, $arguments) { |
|
58 | + return call_user_func_array(array($this->statement, $name), $arguments); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @param array $input |
65 | 65 | * @return \OC_DB_StatementWrapper|int|bool |
66 | 66 | */ |
67 | - public function execute($input= []) { |
|
67 | + public function execute($input = []) { |
|
68 | 68 | $this->lastArguments = $input; |
69 | 69 | if (count($input) > 0) { |
70 | 70 | $result = $this->statement->execute($input); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param integer|null $length max length when using an OUT bind |
114 | 114 | * @return boolean |
115 | 115 | */ |
116 | - public function bindParam($column, &$variable, $type = null, $length = null){ |
|
116 | + public function bindParam($column, &$variable, $type = null, $length = null) { |
|
117 | 117 | return $this->statement->bindParam($column, $variable, $type, $length); |
118 | 118 | } |
119 | 119 | } |
@@ -37,83 +37,83 @@ |
||
37 | 37 | * @method array fetchAll(integer $fetchMode = null); |
38 | 38 | */ |
39 | 39 | class OC_DB_StatementWrapper { |
40 | - /** |
|
41 | - * @var \Doctrine\DBAL\Driver\Statement |
|
42 | - */ |
|
43 | - private $statement = null; |
|
44 | - private $isManipulation = false; |
|
45 | - private $lastArguments = array(); |
|
40 | + /** |
|
41 | + * @var \Doctrine\DBAL\Driver\Statement |
|
42 | + */ |
|
43 | + private $statement = null; |
|
44 | + private $isManipulation = false; |
|
45 | + private $lastArguments = array(); |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param boolean $isManipulation |
|
49 | - */ |
|
50 | - public function __construct($statement, $isManipulation) { |
|
51 | - $this->statement = $statement; |
|
52 | - $this->isManipulation = $isManipulation; |
|
53 | - } |
|
47 | + /** |
|
48 | + * @param boolean $isManipulation |
|
49 | + */ |
|
50 | + public function __construct($statement, $isManipulation) { |
|
51 | + $this->statement = $statement; |
|
52 | + $this->isManipulation = $isManipulation; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * pass all other function directly to the \Doctrine\DBAL\Driver\Statement |
|
57 | - */ |
|
58 | - public function __call($name,$arguments) { |
|
59 | - return call_user_func_array(array($this->statement,$name), $arguments); |
|
60 | - } |
|
55 | + /** |
|
56 | + * pass all other function directly to the \Doctrine\DBAL\Driver\Statement |
|
57 | + */ |
|
58 | + public function __call($name,$arguments) { |
|
59 | + return call_user_func_array(array($this->statement,$name), $arguments); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * make execute return the result instead of a bool |
|
64 | - * |
|
65 | - * @param array $input |
|
66 | - * @return \OC_DB_StatementWrapper|int|bool |
|
67 | - */ |
|
68 | - public function execute($input= []) { |
|
69 | - $this->lastArguments = $input; |
|
70 | - if (count($input) > 0) { |
|
71 | - $result = $this->statement->execute($input); |
|
72 | - } else { |
|
73 | - $result = $this->statement->execute(); |
|
74 | - } |
|
62 | + /** |
|
63 | + * make execute return the result instead of a bool |
|
64 | + * |
|
65 | + * @param array $input |
|
66 | + * @return \OC_DB_StatementWrapper|int|bool |
|
67 | + */ |
|
68 | + public function execute($input= []) { |
|
69 | + $this->lastArguments = $input; |
|
70 | + if (count($input) > 0) { |
|
71 | + $result = $this->statement->execute($input); |
|
72 | + } else { |
|
73 | + $result = $this->statement->execute(); |
|
74 | + } |
|
75 | 75 | |
76 | - if ($result === false) { |
|
77 | - return false; |
|
78 | - } |
|
79 | - if ($this->isManipulation) { |
|
80 | - return $this->statement->rowCount(); |
|
81 | - } else { |
|
82 | - return $this; |
|
83 | - } |
|
84 | - } |
|
76 | + if ($result === false) { |
|
77 | + return false; |
|
78 | + } |
|
79 | + if ($this->isManipulation) { |
|
80 | + return $this->statement->rowCount(); |
|
81 | + } else { |
|
82 | + return $this; |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * provide an alias for fetch |
|
88 | - * |
|
89 | - * @return mixed |
|
90 | - */ |
|
91 | - public function fetchRow() { |
|
92 | - return $this->statement->fetch(); |
|
93 | - } |
|
86 | + /** |
|
87 | + * provide an alias for fetch |
|
88 | + * |
|
89 | + * @return mixed |
|
90 | + */ |
|
91 | + public function fetchRow() { |
|
92 | + return $this->statement->fetch(); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Provide a simple fetchOne. |
|
97 | - * |
|
98 | - * fetch single column from the next row |
|
99 | - * @param int $column the column number to fetch |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function fetchOne($column = 0) { |
|
103 | - return $this->statement->fetchColumn($column); |
|
104 | - } |
|
95 | + /** |
|
96 | + * Provide a simple fetchOne. |
|
97 | + * |
|
98 | + * fetch single column from the next row |
|
99 | + * @param int $column the column number to fetch |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function fetchOne($column = 0) { |
|
103 | + return $this->statement->fetchColumn($column); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Binds a PHP variable to a corresponding named or question mark placeholder in the |
|
108 | - * SQL statement that was use to prepare the statement. |
|
109 | - * |
|
110 | - * @param mixed $column Either the placeholder name or the 1-indexed placeholder index |
|
111 | - * @param mixed $variable The variable to bind |
|
112 | - * @param integer|null $type one of the PDO::PARAM_* constants |
|
113 | - * @param integer|null $length max length when using an OUT bind |
|
114 | - * @return boolean |
|
115 | - */ |
|
116 | - public function bindParam($column, &$variable, $type = null, $length = null){ |
|
117 | - return $this->statement->bindParam($column, $variable, $type, $length); |
|
118 | - } |
|
106 | + /** |
|
107 | + * Binds a PHP variable to a corresponding named or question mark placeholder in the |
|
108 | + * SQL statement that was use to prepare the statement. |
|
109 | + * |
|
110 | + * @param mixed $column Either the placeholder name or the 1-indexed placeholder index |
|
111 | + * @param mixed $variable The variable to bind |
|
112 | + * @param integer|null $type one of the PDO::PARAM_* constants |
|
113 | + * @param integer|null $length max length when using an OUT bind |
|
114 | + * @return boolean |
|
115 | + */ |
|
116 | + public function bindParam($column, &$variable, $type = null, $length = null){ |
|
117 | + return $this->statement->bindParam($column, $variable, $type, $length); |
|
118 | + } |
|
119 | 119 | } |