@@ -42,186 +42,186 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class Defaults { |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * \OC_Defaults instance to retrieve the defaults |
|
| 47 | - * @since 6.0.0 |
|
| 48 | - */ |
|
| 49 | - private $defaults; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * creates a \OC_Defaults instance which is used in all methods to retrieve the |
|
| 53 | - * actual defaults |
|
| 54 | - * @since 6.0.0 |
|
| 55 | - */ |
|
| 56 | - public function __construct(\OC_Defaults $defaults = null) { |
|
| 57 | - if ($defaults === null) { |
|
| 58 | - $defaults = \OC::$server->getThemingDefaults(); |
|
| 59 | - } |
|
| 60 | - $this->defaults = $defaults; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * get base URL for the organisation behind your ownCloud instance |
|
| 65 | - * @return string |
|
| 66 | - * @since 6.0.0 |
|
| 67 | - */ |
|
| 68 | - public function getBaseUrl() { |
|
| 69 | - return $this->defaults->getBaseUrl(); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * link to the desktop sync client |
|
| 74 | - * @return string |
|
| 75 | - * @since 6.0.0 |
|
| 76 | - */ |
|
| 77 | - public function getSyncClientUrl() { |
|
| 78 | - return $this->defaults->getSyncClientUrl(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * link to the iOS client |
|
| 83 | - * @return string |
|
| 84 | - * @since 8.0.0 |
|
| 85 | - */ |
|
| 86 | - public function getiOSClientUrl() { |
|
| 87 | - return $this->defaults->getiOSClientUrl(); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * link to the Android client |
|
| 92 | - * @return string |
|
| 93 | - * @since 8.0.0 |
|
| 94 | - */ |
|
| 95 | - public function getAndroidClientUrl() { |
|
| 96 | - return $this->defaults->getAndroidClientUrl(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * base URL to the documentation of your ownCloud instance |
|
| 101 | - * @return string |
|
| 102 | - * @since 6.0.0 |
|
| 103 | - */ |
|
| 104 | - public function getDocBaseUrl() { |
|
| 105 | - return $this->defaults->getDocBaseUrl(); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * name of your ownCloud instance |
|
| 110 | - * @return string |
|
| 111 | - * @since 6.0.0 |
|
| 112 | - */ |
|
| 113 | - public function getName() { |
|
| 114 | - return $this->defaults->getName(); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * name of your ownCloud instance containing HTML styles |
|
| 119 | - * @return string |
|
| 120 | - * @since 8.0.0 |
|
| 121 | - */ |
|
| 122 | - public function getHTMLName() { |
|
| 123 | - return $this->defaults->getHTMLName(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Entity behind your onwCloud instance |
|
| 128 | - * @return string |
|
| 129 | - * @since 6.0.0 |
|
| 130 | - */ |
|
| 131 | - public function getEntity() { |
|
| 132 | - return $this->defaults->getEntity(); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * ownCloud slogan |
|
| 137 | - * @return string |
|
| 138 | - * @since 6.0.0 |
|
| 139 | - */ |
|
| 140 | - public function getSlogan(?string $lang = null) { |
|
| 141 | - return $this->defaults->getSlogan($lang); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * logo claim |
|
| 146 | - * @return string |
|
| 147 | - * @since 6.0.0 |
|
| 148 | - * @deprecated 13.0.0 |
|
| 149 | - */ |
|
| 150 | - public function getLogoClaim() { |
|
| 151 | - return ''; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * footer, short version |
|
| 156 | - * @return string |
|
| 157 | - * @since 6.0.0 |
|
| 158 | - */ |
|
| 159 | - public function getShortFooter() { |
|
| 160 | - return $this->defaults->getShortFooter(); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * footer, long version |
|
| 165 | - * @return string |
|
| 166 | - * @since 6.0.0 |
|
| 167 | - */ |
|
| 168 | - public function getLongFooter() { |
|
| 169 | - return $this->defaults->getLongFooter(); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Returns the AppId for the App Store for the iOS Client |
|
| 174 | - * @return string AppId |
|
| 175 | - * @since 8.0.0 |
|
| 176 | - */ |
|
| 177 | - public function getiTunesAppId() { |
|
| 178 | - return $this->defaults->getiTunesAppId(); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Themed logo url |
|
| 183 | - * |
|
| 184 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 185 | - * @return string |
|
| 186 | - * @since 12.0.0 |
|
| 187 | - */ |
|
| 188 | - public function getLogo($useSvg = true) { |
|
| 189 | - return $this->defaults->getLogo($useSvg); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Returns primary color |
|
| 194 | - * @return string |
|
| 195 | - * @since 12.0.0 |
|
| 196 | - */ |
|
| 197 | - public function getColorPrimary() { |
|
| 198 | - return $this->defaults->getColorPrimary(); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @param string $key |
|
| 203 | - * @return string URL to doc with key |
|
| 204 | - * @since 12.0.0 |
|
| 205 | - */ |
|
| 206 | - public function buildDocLinkToKey($key) { |
|
| 207 | - return $this->defaults->buildDocLinkToKey($key); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Returns the title |
|
| 212 | - * @return string title |
|
| 213 | - * @since 12.0.0 |
|
| 214 | - */ |
|
| 215 | - public function getTitle() { |
|
| 216 | - return $this->defaults->getTitle(); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Returns primary color |
|
| 221 | - * @return string |
|
| 222 | - * @since 13.0.0 |
|
| 223 | - */ |
|
| 224 | - public function getTextColorPrimary() { |
|
| 225 | - return $this->defaults->getTextColorPrimary(); |
|
| 226 | - } |
|
| 45 | + /** |
|
| 46 | + * \OC_Defaults instance to retrieve the defaults |
|
| 47 | + * @since 6.0.0 |
|
| 48 | + */ |
|
| 49 | + private $defaults; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * creates a \OC_Defaults instance which is used in all methods to retrieve the |
|
| 53 | + * actual defaults |
|
| 54 | + * @since 6.0.0 |
|
| 55 | + */ |
|
| 56 | + public function __construct(\OC_Defaults $defaults = null) { |
|
| 57 | + if ($defaults === null) { |
|
| 58 | + $defaults = \OC::$server->getThemingDefaults(); |
|
| 59 | + } |
|
| 60 | + $this->defaults = $defaults; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * get base URL for the organisation behind your ownCloud instance |
|
| 65 | + * @return string |
|
| 66 | + * @since 6.0.0 |
|
| 67 | + */ |
|
| 68 | + public function getBaseUrl() { |
|
| 69 | + return $this->defaults->getBaseUrl(); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * link to the desktop sync client |
|
| 74 | + * @return string |
|
| 75 | + * @since 6.0.0 |
|
| 76 | + */ |
|
| 77 | + public function getSyncClientUrl() { |
|
| 78 | + return $this->defaults->getSyncClientUrl(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * link to the iOS client |
|
| 83 | + * @return string |
|
| 84 | + * @since 8.0.0 |
|
| 85 | + */ |
|
| 86 | + public function getiOSClientUrl() { |
|
| 87 | + return $this->defaults->getiOSClientUrl(); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * link to the Android client |
|
| 92 | + * @return string |
|
| 93 | + * @since 8.0.0 |
|
| 94 | + */ |
|
| 95 | + public function getAndroidClientUrl() { |
|
| 96 | + return $this->defaults->getAndroidClientUrl(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * base URL to the documentation of your ownCloud instance |
|
| 101 | + * @return string |
|
| 102 | + * @since 6.0.0 |
|
| 103 | + */ |
|
| 104 | + public function getDocBaseUrl() { |
|
| 105 | + return $this->defaults->getDocBaseUrl(); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * name of your ownCloud instance |
|
| 110 | + * @return string |
|
| 111 | + * @since 6.0.0 |
|
| 112 | + */ |
|
| 113 | + public function getName() { |
|
| 114 | + return $this->defaults->getName(); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * name of your ownCloud instance containing HTML styles |
|
| 119 | + * @return string |
|
| 120 | + * @since 8.0.0 |
|
| 121 | + */ |
|
| 122 | + public function getHTMLName() { |
|
| 123 | + return $this->defaults->getHTMLName(); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Entity behind your onwCloud instance |
|
| 128 | + * @return string |
|
| 129 | + * @since 6.0.0 |
|
| 130 | + */ |
|
| 131 | + public function getEntity() { |
|
| 132 | + return $this->defaults->getEntity(); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * ownCloud slogan |
|
| 137 | + * @return string |
|
| 138 | + * @since 6.0.0 |
|
| 139 | + */ |
|
| 140 | + public function getSlogan(?string $lang = null) { |
|
| 141 | + return $this->defaults->getSlogan($lang); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * logo claim |
|
| 146 | + * @return string |
|
| 147 | + * @since 6.0.0 |
|
| 148 | + * @deprecated 13.0.0 |
|
| 149 | + */ |
|
| 150 | + public function getLogoClaim() { |
|
| 151 | + return ''; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * footer, short version |
|
| 156 | + * @return string |
|
| 157 | + * @since 6.0.0 |
|
| 158 | + */ |
|
| 159 | + public function getShortFooter() { |
|
| 160 | + return $this->defaults->getShortFooter(); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * footer, long version |
|
| 165 | + * @return string |
|
| 166 | + * @since 6.0.0 |
|
| 167 | + */ |
|
| 168 | + public function getLongFooter() { |
|
| 169 | + return $this->defaults->getLongFooter(); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Returns the AppId for the App Store for the iOS Client |
|
| 174 | + * @return string AppId |
|
| 175 | + * @since 8.0.0 |
|
| 176 | + */ |
|
| 177 | + public function getiTunesAppId() { |
|
| 178 | + return $this->defaults->getiTunesAppId(); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Themed logo url |
|
| 183 | + * |
|
| 184 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 185 | + * @return string |
|
| 186 | + * @since 12.0.0 |
|
| 187 | + */ |
|
| 188 | + public function getLogo($useSvg = true) { |
|
| 189 | + return $this->defaults->getLogo($useSvg); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Returns primary color |
|
| 194 | + * @return string |
|
| 195 | + * @since 12.0.0 |
|
| 196 | + */ |
|
| 197 | + public function getColorPrimary() { |
|
| 198 | + return $this->defaults->getColorPrimary(); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @param string $key |
|
| 203 | + * @return string URL to doc with key |
|
| 204 | + * @since 12.0.0 |
|
| 205 | + */ |
|
| 206 | + public function buildDocLinkToKey($key) { |
|
| 207 | + return $this->defaults->buildDocLinkToKey($key); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Returns the title |
|
| 212 | + * @return string title |
|
| 213 | + * @since 12.0.0 |
|
| 214 | + */ |
|
| 215 | + public function getTitle() { |
|
| 216 | + return $this->defaults->getTitle(); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Returns primary color |
|
| 221 | + * @return string |
|
| 222 | + * @since 13.0.0 |
|
| 223 | + */ |
|
| 224 | + public function getTextColorPrimary() { |
|
| 225 | + return $this->defaults->getTextColorPrimary(); |
|
| 226 | + } |
|
| 227 | 227 | } |
@@ -58,118 +58,118 @@ |
||
| 58 | 58 | */ |
| 59 | 59 | interface IEMailTemplate { |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Sets the subject of the email |
|
| 63 | - * |
|
| 64 | - * @param string $subject |
|
| 65 | - * |
|
| 66 | - * @since 13.0.0 |
|
| 67 | - */ |
|
| 68 | - public function setSubject(string $subject); |
|
| 61 | + /** |
|
| 62 | + * Sets the subject of the email |
|
| 63 | + * |
|
| 64 | + * @param string $subject |
|
| 65 | + * |
|
| 66 | + * @since 13.0.0 |
|
| 67 | + */ |
|
| 68 | + public function setSubject(string $subject); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Adds a header to the email |
|
| 72 | - * |
|
| 73 | - * @since 12.0.0 |
|
| 74 | - */ |
|
| 75 | - public function addHeader(); |
|
| 70 | + /** |
|
| 71 | + * Adds a header to the email |
|
| 72 | + * |
|
| 73 | + * @since 12.0.0 |
|
| 74 | + */ |
|
| 75 | + public function addHeader(); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Adds a heading to the email |
|
| 79 | - * |
|
| 80 | - * @param string $title |
|
| 81 | - * @param string|bool $plainTitle Title that is used in the plain text email |
|
| 82 | - * if empty the $title is used, if false none will be used |
|
| 83 | - * |
|
| 84 | - * @since 12.0.0 |
|
| 85 | - */ |
|
| 86 | - public function addHeading(string $title, $plainTitle = ''); |
|
| 77 | + /** |
|
| 78 | + * Adds a heading to the email |
|
| 79 | + * |
|
| 80 | + * @param string $title |
|
| 81 | + * @param string|bool $plainTitle Title that is used in the plain text email |
|
| 82 | + * if empty the $title is used, if false none will be used |
|
| 83 | + * |
|
| 84 | + * @since 12.0.0 |
|
| 85 | + */ |
|
| 86 | + public function addHeading(string $title, $plainTitle = ''); |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Adds a paragraph to the body of the email |
|
| 90 | - * |
|
| 91 | - * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 92 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 93 | - * if empty the $text is used, if false none will be used |
|
| 94 | - * |
|
| 95 | - * @since 12.0.0 |
|
| 96 | - */ |
|
| 97 | - public function addBodyText(string $text, $plainText = ''); |
|
| 88 | + /** |
|
| 89 | + * Adds a paragraph to the body of the email |
|
| 90 | + * |
|
| 91 | + * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 92 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 93 | + * if empty the $text is used, if false none will be used |
|
| 94 | + * |
|
| 95 | + * @since 12.0.0 |
|
| 96 | + */ |
|
| 97 | + public function addBodyText(string $text, $plainText = ''); |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Adds a list item to the body of the email |
|
| 101 | - * |
|
| 102 | - * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 103 | - * @param string $metaInfo; Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
| 104 | - * @param string $icon Absolute path, must be 16*16 pixels |
|
| 105 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 106 | - * if empty the $text is used, if false none will be used |
|
| 107 | - * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
| 108 | - * if empty the $metaInfo is used, if false none will be used |
|
| 109 | - * @since 12.0.0 |
|
| 110 | - */ |
|
| 111 | - public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = ''); |
|
| 99 | + /** |
|
| 100 | + * Adds a list item to the body of the email |
|
| 101 | + * |
|
| 102 | + * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 103 | + * @param string $metaInfo; Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
| 104 | + * @param string $icon Absolute path, must be 16*16 pixels |
|
| 105 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 106 | + * if empty the $text is used, if false none will be used |
|
| 107 | + * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
| 108 | + * if empty the $metaInfo is used, if false none will be used |
|
| 109 | + * @since 12.0.0 |
|
| 110 | + */ |
|
| 111 | + public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = ''); |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Adds a button group of two buttons to the body of the email |
|
| 115 | - * |
|
| 116 | - * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
| 117 | - * @param string $urlLeft URL of left button |
|
| 118 | - * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
| 119 | - * @param string $urlRight URL of right button |
|
| 120 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used |
|
| 121 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
|
| 122 | - * |
|
| 123 | - * @since 12.0.0 |
|
| 124 | - */ |
|
| 125 | - public function addBodyButtonGroup(string $textLeft, string $urlLeft, string $textRight, string $urlRight, string $plainTextLeft = '', string $plainTextRight = ''); |
|
| 113 | + /** |
|
| 114 | + * Adds a button group of two buttons to the body of the email |
|
| 115 | + * |
|
| 116 | + * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
| 117 | + * @param string $urlLeft URL of left button |
|
| 118 | + * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
| 119 | + * @param string $urlRight URL of right button |
|
| 120 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used |
|
| 121 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
|
| 122 | + * |
|
| 123 | + * @since 12.0.0 |
|
| 124 | + */ |
|
| 125 | + public function addBodyButtonGroup(string $textLeft, string $urlLeft, string $textRight, string $urlRight, string $plainTextLeft = '', string $plainTextRight = ''); |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Adds a button to the body of the email |
|
| 129 | - * |
|
| 130 | - * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 131 | - * @param string $url URL of button |
|
| 132 | - * @param string $plainText Text of button in plain text version |
|
| 133 | - * if empty the $text is used, if false none will be used |
|
| 134 | - * |
|
| 135 | - * @since 12.0.0 |
|
| 136 | - */ |
|
| 137 | - public function addBodyButton(string $text, string $url, $plainText = ''); |
|
| 127 | + /** |
|
| 128 | + * Adds a button to the body of the email |
|
| 129 | + * |
|
| 130 | + * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 131 | + * @param string $url URL of button |
|
| 132 | + * @param string $plainText Text of button in plain text version |
|
| 133 | + * if empty the $text is used, if false none will be used |
|
| 134 | + * |
|
| 135 | + * @since 12.0.0 |
|
| 136 | + */ |
|
| 137 | + public function addBodyButton(string $text, string $url, $plainText = ''); |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 141 | - * |
|
| 142 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
| 143 | - * @param string $lang Optional language to set the default footer in |
|
| 144 | - * |
|
| 145 | - * @since 12.0.0 |
|
| 146 | - */ |
|
| 147 | - public function addFooter(string $text = '', ?string $lang = null); |
|
| 139 | + /** |
|
| 140 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 141 | + * |
|
| 142 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
| 143 | + * @param string $lang Optional language to set the default footer in |
|
| 144 | + * |
|
| 145 | + * @since 12.0.0 |
|
| 146 | + */ |
|
| 147 | + public function addFooter(string $text = '', ?string $lang = null); |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Returns the rendered email subject as string |
|
| 151 | - * |
|
| 152 | - * @return string |
|
| 153 | - * |
|
| 154 | - * @since 13.0.0 |
|
| 155 | - */ |
|
| 156 | - public function renderSubject(): string; |
|
| 149 | + /** |
|
| 150 | + * Returns the rendered email subject as string |
|
| 151 | + * |
|
| 152 | + * @return string |
|
| 153 | + * |
|
| 154 | + * @since 13.0.0 |
|
| 155 | + */ |
|
| 156 | + public function renderSubject(): string; |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Returns the rendered HTML email as string |
|
| 160 | - * |
|
| 161 | - * @return string |
|
| 162 | - * |
|
| 163 | - * @since 12.0.0 |
|
| 164 | - */ |
|
| 165 | - public function renderHtml(): string; |
|
| 158 | + /** |
|
| 159 | + * Returns the rendered HTML email as string |
|
| 160 | + * |
|
| 161 | + * @return string |
|
| 162 | + * |
|
| 163 | + * @since 12.0.0 |
|
| 164 | + */ |
|
| 165 | + public function renderHtml(): string; |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Returns the rendered plain text email as string |
|
| 169 | - * |
|
| 170 | - * @return string |
|
| 171 | - * |
|
| 172 | - * @since 12.0.0 |
|
| 173 | - */ |
|
| 174 | - public function renderText(): string; |
|
| 167 | + /** |
|
| 168 | + * Returns the rendered plain text email as string |
|
| 169 | + * |
|
| 170 | + * @return string |
|
| 171 | + * |
|
| 172 | + * @since 12.0.0 |
|
| 173 | + */ |
|
| 174 | + public function renderText(): string; |
|
| 175 | 175 | } |
@@ -67,256 +67,256 @@ |
||
| 67 | 67 | * @package OC\Mail |
| 68 | 68 | */ |
| 69 | 69 | class Mailer implements IMailer { |
| 70 | - /** @var \Swift_Mailer Cached mailer */ |
|
| 71 | - private $instance = null; |
|
| 72 | - /** @var IConfig */ |
|
| 73 | - private $config; |
|
| 74 | - /** @var ILogger */ |
|
| 75 | - private $logger; |
|
| 76 | - /** @var Defaults */ |
|
| 77 | - private $defaults; |
|
| 78 | - /** @var IURLGenerator */ |
|
| 79 | - private $urlGenerator; |
|
| 80 | - /** @var IL10N */ |
|
| 81 | - private $l10n; |
|
| 82 | - /** @var IEventDispatcher */ |
|
| 83 | - private $dispatcher; |
|
| 84 | - /** @var IFactory */ |
|
| 85 | - private $l10nFactory; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param IConfig $config |
|
| 89 | - * @param ILogger $logger |
|
| 90 | - * @param Defaults $defaults |
|
| 91 | - * @param IURLGenerator $urlGenerator |
|
| 92 | - * @param IL10N $l10n |
|
| 93 | - * @param IEventDispatcher $dispatcher |
|
| 94 | - */ |
|
| 95 | - public function __construct(IConfig $config, |
|
| 96 | - ILogger $logger, |
|
| 97 | - Defaults $defaults, |
|
| 98 | - IURLGenerator $urlGenerator, |
|
| 99 | - IL10N $l10n, |
|
| 100 | - IEventDispatcher $dispatcher, |
|
| 101 | - IFactory $l10nFactory) { |
|
| 102 | - $this->config = $config; |
|
| 103 | - $this->logger = $logger; |
|
| 104 | - $this->defaults = $defaults; |
|
| 105 | - $this->urlGenerator = $urlGenerator; |
|
| 106 | - $this->l10n = $l10n; |
|
| 107 | - $this->dispatcher = $dispatcher; |
|
| 108 | - $this->l10nFactory = $l10nFactory; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Creates a new message object that can be passed to send() |
|
| 113 | - * |
|
| 114 | - * @return IMessage |
|
| 115 | - */ |
|
| 116 | - public function createMessage(): IMessage { |
|
| 117 | - $plainTextOnly = $this->config->getSystemValue('mail_send_plaintext_only', false); |
|
| 118 | - return new Message(new \Swift_Message(), $plainTextOnly); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param string|null $data |
|
| 123 | - * @param string|null $filename |
|
| 124 | - * @param string|null $contentType |
|
| 125 | - * @return IAttachment |
|
| 126 | - * @since 13.0.0 |
|
| 127 | - */ |
|
| 128 | - public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment { |
|
| 129 | - return new Attachment(new \Swift_Attachment($data, $filename, $contentType)); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @param string $path |
|
| 134 | - * @param string|null $contentType |
|
| 135 | - * @return IAttachment |
|
| 136 | - * @since 13.0.0 |
|
| 137 | - */ |
|
| 138 | - public function createAttachmentFromPath(string $path, $contentType = null): IAttachment { |
|
| 139 | - return new Attachment(\Swift_Attachment::fromPath($path, $contentType)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Creates a new email template object |
|
| 144 | - * |
|
| 145 | - * @param string $emailId |
|
| 146 | - * @param array $data |
|
| 147 | - * @return IEMailTemplate |
|
| 148 | - * @since 12.0.0 |
|
| 149 | - */ |
|
| 150 | - public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate { |
|
| 151 | - $class = $this->config->getSystemValue('mail_template_class', ''); |
|
| 152 | - |
|
| 153 | - if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) { |
|
| 154 | - return new $class( |
|
| 155 | - $this->defaults, |
|
| 156 | - $this->urlGenerator, |
|
| 157 | - $this->l10n, |
|
| 158 | - $emailId, |
|
| 159 | - $data |
|
| 160 | - ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return new EMailTemplate( |
|
| 164 | - $this->defaults, |
|
| 165 | - $this->urlGenerator, |
|
| 166 | - $this->l10nFactory, |
|
| 167 | - $emailId, |
|
| 168 | - $data |
|
| 169 | - ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Send the specified message. Also sets the from address to the value defined in config.php |
|
| 174 | - * if no-one has been passed. |
|
| 175 | - * |
|
| 176 | - * @param IMessage|Message $message Message to send |
|
| 177 | - * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
| 178 | - * therefore should be considered |
|
| 179 | - * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
| 180 | - * has been supplied.) |
|
| 181 | - */ |
|
| 182 | - public function send(IMessage $message): array { |
|
| 183 | - $debugMode = $this->config->getSystemValue('mail_smtpdebug', false); |
|
| 184 | - |
|
| 185 | - if (empty($message->getFrom())) { |
|
| 186 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress('no-reply') => $this->defaults->getName()]); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $failedRecipients = []; |
|
| 190 | - |
|
| 191 | - $mailer = $this->getInstance(); |
|
| 192 | - |
|
| 193 | - // Enable logger if debug mode is enabled |
|
| 194 | - if ($debugMode) { |
|
| 195 | - $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); |
|
| 196 | - $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - $this->dispatcher->dispatchTyped(new BeforeMessageSent($message)); |
|
| 201 | - |
|
| 202 | - $mailer->send($message->getSwiftMessage(), $failedRecipients); |
|
| 203 | - |
|
| 204 | - // Debugging logging |
|
| 205 | - $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); |
|
| 206 | - $this->logger->debug($logMessage, ['app' => 'core']); |
|
| 207 | - if ($debugMode && isset($mailLogger)) { |
|
| 208 | - $this->logger->debug($mailLogger->dump(), ['app' => 'core']); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return $failedRecipients; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Checks if an e-mail address is valid |
|
| 216 | - * |
|
| 217 | - * @param string $email Email address to be validated |
|
| 218 | - * @return bool True if the mail address is valid, false otherwise |
|
| 219 | - */ |
|
| 220 | - public function validateMailAddress(string $email): bool { |
|
| 221 | - $validator = new EmailValidator(); |
|
| 222 | - $validation = new RFCValidation(); |
|
| 223 | - |
|
| 224 | - return $validator->isValid($this->convertEmail($email), $validation); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
|
| 229 | - * |
|
| 230 | - * FIXME: Remove this once SwiftMailer supports IDN |
|
| 231 | - * |
|
| 232 | - * @param string $email |
|
| 233 | - * @return string Converted mail address if `idn_to_ascii` exists |
|
| 234 | - */ |
|
| 235 | - protected function convertEmail(string $email): string { |
|
| 236 | - if (!function_exists('idn_to_ascii') || !defined('INTL_IDNA_VARIANT_UTS46') || strpos($email, '@') === false) { |
|
| 237 | - return $email; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - list($name, $domain) = explode('@', $email, 2); |
|
| 241 | - $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); |
|
| 242 | - return $name.'@'.$domain; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - protected function getInstance(): \Swift_Mailer { |
|
| 246 | - if (!is_null($this->instance)) { |
|
| 247 | - return $this->instance; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $transport = null; |
|
| 251 | - |
|
| 252 | - switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { |
|
| 253 | - case 'sendmail': |
|
| 254 | - $transport = $this->getSendMailInstance(); |
|
| 255 | - break; |
|
| 256 | - case 'smtp': |
|
| 257 | - default: |
|
| 258 | - $transport = $this->getSmtpInstance(); |
|
| 259 | - break; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - return new \Swift_Mailer($transport); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Returns the SMTP transport |
|
| 267 | - * |
|
| 268 | - * @return \Swift_SmtpTransport |
|
| 269 | - */ |
|
| 270 | - protected function getSmtpInstance(): \Swift_SmtpTransport { |
|
| 271 | - $transport = new \Swift_SmtpTransport(); |
|
| 272 | - $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); |
|
| 273 | - $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1')); |
|
| 274 | - $transport->setPort($this->config->getSystemValue('mail_smtpport', 25)); |
|
| 275 | - if ($this->config->getSystemValue('mail_smtpauth', false)) { |
|
| 276 | - $transport->setUsername($this->config->getSystemValue('mail_smtpname', '')); |
|
| 277 | - $transport->setPassword($this->config->getSystemValue('mail_smtppassword', '')); |
|
| 278 | - $transport->setAuthMode($this->config->getSystemValue('mail_smtpauthtype', 'LOGIN')); |
|
| 279 | - } |
|
| 280 | - $smtpSecurity = $this->config->getSystemValue('mail_smtpsecure', ''); |
|
| 281 | - if (!empty($smtpSecurity)) { |
|
| 282 | - $transport->setEncryption($smtpSecurity); |
|
| 283 | - } |
|
| 284 | - $streamingOptions = $this->config->getSystemValue('mail_smtpstreamoptions', []); |
|
| 285 | - if (is_array($streamingOptions) && !empty($streamingOptions)) { |
|
| 286 | - $transport->setStreamOptions($streamingOptions); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - return $transport; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Returns the sendmail transport |
|
| 294 | - * |
|
| 295 | - * @return \Swift_SendmailTransport |
|
| 296 | - */ |
|
| 297 | - protected function getSendMailInstance(): \Swift_SendmailTransport { |
|
| 298 | - switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { |
|
| 299 | - case 'qmail': |
|
| 300 | - $binaryPath = '/var/qmail/bin/sendmail'; |
|
| 301 | - break; |
|
| 302 | - default: |
|
| 303 | - $sendmail = \OC_Helper::findBinaryPath('sendmail'); |
|
| 304 | - if ($sendmail === null) { |
|
| 305 | - $sendmail = '/usr/sbin/sendmail'; |
|
| 306 | - } |
|
| 307 | - $binaryPath = $sendmail; |
|
| 308 | - break; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - switch ($this->config->getSystemValue('mail_sendmailmode', 'smtp')) { |
|
| 312 | - case 'pipe': |
|
| 313 | - $binaryParam = ' -t'; |
|
| 314 | - break; |
|
| 315 | - default: |
|
| 316 | - $binaryParam = ' -bs'; |
|
| 317 | - break; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - return new \Swift_SendmailTransport($binaryPath . $binaryParam); |
|
| 321 | - } |
|
| 70 | + /** @var \Swift_Mailer Cached mailer */ |
|
| 71 | + private $instance = null; |
|
| 72 | + /** @var IConfig */ |
|
| 73 | + private $config; |
|
| 74 | + /** @var ILogger */ |
|
| 75 | + private $logger; |
|
| 76 | + /** @var Defaults */ |
|
| 77 | + private $defaults; |
|
| 78 | + /** @var IURLGenerator */ |
|
| 79 | + private $urlGenerator; |
|
| 80 | + /** @var IL10N */ |
|
| 81 | + private $l10n; |
|
| 82 | + /** @var IEventDispatcher */ |
|
| 83 | + private $dispatcher; |
|
| 84 | + /** @var IFactory */ |
|
| 85 | + private $l10nFactory; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param IConfig $config |
|
| 89 | + * @param ILogger $logger |
|
| 90 | + * @param Defaults $defaults |
|
| 91 | + * @param IURLGenerator $urlGenerator |
|
| 92 | + * @param IL10N $l10n |
|
| 93 | + * @param IEventDispatcher $dispatcher |
|
| 94 | + */ |
|
| 95 | + public function __construct(IConfig $config, |
|
| 96 | + ILogger $logger, |
|
| 97 | + Defaults $defaults, |
|
| 98 | + IURLGenerator $urlGenerator, |
|
| 99 | + IL10N $l10n, |
|
| 100 | + IEventDispatcher $dispatcher, |
|
| 101 | + IFactory $l10nFactory) { |
|
| 102 | + $this->config = $config; |
|
| 103 | + $this->logger = $logger; |
|
| 104 | + $this->defaults = $defaults; |
|
| 105 | + $this->urlGenerator = $urlGenerator; |
|
| 106 | + $this->l10n = $l10n; |
|
| 107 | + $this->dispatcher = $dispatcher; |
|
| 108 | + $this->l10nFactory = $l10nFactory; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Creates a new message object that can be passed to send() |
|
| 113 | + * |
|
| 114 | + * @return IMessage |
|
| 115 | + */ |
|
| 116 | + public function createMessage(): IMessage { |
|
| 117 | + $plainTextOnly = $this->config->getSystemValue('mail_send_plaintext_only', false); |
|
| 118 | + return new Message(new \Swift_Message(), $plainTextOnly); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param string|null $data |
|
| 123 | + * @param string|null $filename |
|
| 124 | + * @param string|null $contentType |
|
| 125 | + * @return IAttachment |
|
| 126 | + * @since 13.0.0 |
|
| 127 | + */ |
|
| 128 | + public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment { |
|
| 129 | + return new Attachment(new \Swift_Attachment($data, $filename, $contentType)); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @param string $path |
|
| 134 | + * @param string|null $contentType |
|
| 135 | + * @return IAttachment |
|
| 136 | + * @since 13.0.0 |
|
| 137 | + */ |
|
| 138 | + public function createAttachmentFromPath(string $path, $contentType = null): IAttachment { |
|
| 139 | + return new Attachment(\Swift_Attachment::fromPath($path, $contentType)); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Creates a new email template object |
|
| 144 | + * |
|
| 145 | + * @param string $emailId |
|
| 146 | + * @param array $data |
|
| 147 | + * @return IEMailTemplate |
|
| 148 | + * @since 12.0.0 |
|
| 149 | + */ |
|
| 150 | + public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate { |
|
| 151 | + $class = $this->config->getSystemValue('mail_template_class', ''); |
|
| 152 | + |
|
| 153 | + if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) { |
|
| 154 | + return new $class( |
|
| 155 | + $this->defaults, |
|
| 156 | + $this->urlGenerator, |
|
| 157 | + $this->l10n, |
|
| 158 | + $emailId, |
|
| 159 | + $data |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return new EMailTemplate( |
|
| 164 | + $this->defaults, |
|
| 165 | + $this->urlGenerator, |
|
| 166 | + $this->l10nFactory, |
|
| 167 | + $emailId, |
|
| 168 | + $data |
|
| 169 | + ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Send the specified message. Also sets the from address to the value defined in config.php |
|
| 174 | + * if no-one has been passed. |
|
| 175 | + * |
|
| 176 | + * @param IMessage|Message $message Message to send |
|
| 177 | + * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
| 178 | + * therefore should be considered |
|
| 179 | + * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
| 180 | + * has been supplied.) |
|
| 181 | + */ |
|
| 182 | + public function send(IMessage $message): array { |
|
| 183 | + $debugMode = $this->config->getSystemValue('mail_smtpdebug', false); |
|
| 184 | + |
|
| 185 | + if (empty($message->getFrom())) { |
|
| 186 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress('no-reply') => $this->defaults->getName()]); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $failedRecipients = []; |
|
| 190 | + |
|
| 191 | + $mailer = $this->getInstance(); |
|
| 192 | + |
|
| 193 | + // Enable logger if debug mode is enabled |
|
| 194 | + if ($debugMode) { |
|
| 195 | + $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); |
|
| 196 | + $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + $this->dispatcher->dispatchTyped(new BeforeMessageSent($message)); |
|
| 201 | + |
|
| 202 | + $mailer->send($message->getSwiftMessage(), $failedRecipients); |
|
| 203 | + |
|
| 204 | + // Debugging logging |
|
| 205 | + $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); |
|
| 206 | + $this->logger->debug($logMessage, ['app' => 'core']); |
|
| 207 | + if ($debugMode && isset($mailLogger)) { |
|
| 208 | + $this->logger->debug($mailLogger->dump(), ['app' => 'core']); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return $failedRecipients; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Checks if an e-mail address is valid |
|
| 216 | + * |
|
| 217 | + * @param string $email Email address to be validated |
|
| 218 | + * @return bool True if the mail address is valid, false otherwise |
|
| 219 | + */ |
|
| 220 | + public function validateMailAddress(string $email): bool { |
|
| 221 | + $validator = new EmailValidator(); |
|
| 222 | + $validation = new RFCValidation(); |
|
| 223 | + |
|
| 224 | + return $validator->isValid($this->convertEmail($email), $validation); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
|
| 229 | + * |
|
| 230 | + * FIXME: Remove this once SwiftMailer supports IDN |
|
| 231 | + * |
|
| 232 | + * @param string $email |
|
| 233 | + * @return string Converted mail address if `idn_to_ascii` exists |
|
| 234 | + */ |
|
| 235 | + protected function convertEmail(string $email): string { |
|
| 236 | + if (!function_exists('idn_to_ascii') || !defined('INTL_IDNA_VARIANT_UTS46') || strpos($email, '@') === false) { |
|
| 237 | + return $email; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + list($name, $domain) = explode('@', $email, 2); |
|
| 241 | + $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); |
|
| 242 | + return $name.'@'.$domain; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + protected function getInstance(): \Swift_Mailer { |
|
| 246 | + if (!is_null($this->instance)) { |
|
| 247 | + return $this->instance; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $transport = null; |
|
| 251 | + |
|
| 252 | + switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { |
|
| 253 | + case 'sendmail': |
|
| 254 | + $transport = $this->getSendMailInstance(); |
|
| 255 | + break; |
|
| 256 | + case 'smtp': |
|
| 257 | + default: |
|
| 258 | + $transport = $this->getSmtpInstance(); |
|
| 259 | + break; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + return new \Swift_Mailer($transport); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Returns the SMTP transport |
|
| 267 | + * |
|
| 268 | + * @return \Swift_SmtpTransport |
|
| 269 | + */ |
|
| 270 | + protected function getSmtpInstance(): \Swift_SmtpTransport { |
|
| 271 | + $transport = new \Swift_SmtpTransport(); |
|
| 272 | + $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); |
|
| 273 | + $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1')); |
|
| 274 | + $transport->setPort($this->config->getSystemValue('mail_smtpport', 25)); |
|
| 275 | + if ($this->config->getSystemValue('mail_smtpauth', false)) { |
|
| 276 | + $transport->setUsername($this->config->getSystemValue('mail_smtpname', '')); |
|
| 277 | + $transport->setPassword($this->config->getSystemValue('mail_smtppassword', '')); |
|
| 278 | + $transport->setAuthMode($this->config->getSystemValue('mail_smtpauthtype', 'LOGIN')); |
|
| 279 | + } |
|
| 280 | + $smtpSecurity = $this->config->getSystemValue('mail_smtpsecure', ''); |
|
| 281 | + if (!empty($smtpSecurity)) { |
|
| 282 | + $transport->setEncryption($smtpSecurity); |
|
| 283 | + } |
|
| 284 | + $streamingOptions = $this->config->getSystemValue('mail_smtpstreamoptions', []); |
|
| 285 | + if (is_array($streamingOptions) && !empty($streamingOptions)) { |
|
| 286 | + $transport->setStreamOptions($streamingOptions); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + return $transport; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Returns the sendmail transport |
|
| 294 | + * |
|
| 295 | + * @return \Swift_SendmailTransport |
|
| 296 | + */ |
|
| 297 | + protected function getSendMailInstance(): \Swift_SendmailTransport { |
|
| 298 | + switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { |
|
| 299 | + case 'qmail': |
|
| 300 | + $binaryPath = '/var/qmail/bin/sendmail'; |
|
| 301 | + break; |
|
| 302 | + default: |
|
| 303 | + $sendmail = \OC_Helper::findBinaryPath('sendmail'); |
|
| 304 | + if ($sendmail === null) { |
|
| 305 | + $sendmail = '/usr/sbin/sendmail'; |
|
| 306 | + } |
|
| 307 | + $binaryPath = $sendmail; |
|
| 308 | + break; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + switch ($this->config->getSystemValue('mail_sendmailmode', 'smtp')) { |
|
| 312 | + case 'pipe': |
|
| 313 | + $binaryParam = ' -t'; |
|
| 314 | + break; |
|
| 315 | + default: |
|
| 316 | + $binaryParam = ' -bs'; |
|
| 317 | + break; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + return new \Swift_SendmailTransport($binaryPath . $binaryParam); |
|
| 321 | + } |
|
| 322 | 322 | } |
@@ -48,33 +48,33 @@ discard block |
||
| 48 | 48 | * @package OC\Mail |
| 49 | 49 | */ |
| 50 | 50 | class EMailTemplate implements IEMailTemplate { |
| 51 | - /** @var Defaults */ |
|
| 52 | - protected $themingDefaults; |
|
| 53 | - /** @var IURLGenerator */ |
|
| 54 | - protected $urlGenerator; |
|
| 55 | - /** @var IFactory */ |
|
| 56 | - protected $l10nFactory; |
|
| 57 | - /** @var string */ |
|
| 58 | - protected $emailId; |
|
| 59 | - /** @var array */ |
|
| 60 | - protected $data; |
|
| 61 | - |
|
| 62 | - /** @var string */ |
|
| 63 | - protected $subject = ''; |
|
| 64 | - /** @var string */ |
|
| 65 | - protected $htmlBody = ''; |
|
| 66 | - /** @var string */ |
|
| 67 | - protected $plainBody = ''; |
|
| 68 | - /** @var bool indicated if the footer is added */ |
|
| 69 | - protected $headerAdded = false; |
|
| 70 | - /** @var bool indicated if the body is already opened */ |
|
| 71 | - protected $bodyOpened = false; |
|
| 72 | - /** @var bool indicated if there is a list open in the body */ |
|
| 73 | - protected $bodyListOpened = false; |
|
| 74 | - /** @var bool indicated if the footer is added */ |
|
| 75 | - protected $footerAdded = false; |
|
| 76 | - |
|
| 77 | - protected $head = <<<EOF |
|
| 51 | + /** @var Defaults */ |
|
| 52 | + protected $themingDefaults; |
|
| 53 | + /** @var IURLGenerator */ |
|
| 54 | + protected $urlGenerator; |
|
| 55 | + /** @var IFactory */ |
|
| 56 | + protected $l10nFactory; |
|
| 57 | + /** @var string */ |
|
| 58 | + protected $emailId; |
|
| 59 | + /** @var array */ |
|
| 60 | + protected $data; |
|
| 61 | + |
|
| 62 | + /** @var string */ |
|
| 63 | + protected $subject = ''; |
|
| 64 | + /** @var string */ |
|
| 65 | + protected $htmlBody = ''; |
|
| 66 | + /** @var string */ |
|
| 67 | + protected $plainBody = ''; |
|
| 68 | + /** @var bool indicated if the footer is added */ |
|
| 69 | + protected $headerAdded = false; |
|
| 70 | + /** @var bool indicated if the body is already opened */ |
|
| 71 | + protected $bodyOpened = false; |
|
| 72 | + /** @var bool indicated if there is a list open in the body */ |
|
| 73 | + protected $bodyListOpened = false; |
|
| 74 | + /** @var bool indicated if the footer is added */ |
|
| 75 | + protected $footerAdded = false; |
|
| 76 | + |
|
| 77 | + protected $head = <<<EOF |
|
| 78 | 78 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 79 | 79 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important"> |
| 80 | 80 | <head> |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | <center data-parsed="" style="min-width:580px;width:100%"> |
| 93 | 93 | EOF; |
| 94 | 94 | |
| 95 | - protected $tail = <<<EOF |
|
| 95 | + protected $tail = <<<EOF |
|
| 96 | 96 | </center> |
| 97 | 97 | </td> |
| 98 | 98 | </tr> |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | </html> |
| 104 | 104 | EOF; |
| 105 | 105 | |
| 106 | - protected $header = <<<EOF |
|
| 106 | + protected $header = <<<EOF |
|
| 107 | 107 | <table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:%s;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
| 108 | 108 | <tr style="padding:0;text-align:left;vertical-align:top"> |
| 109 | 109 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | </table> |
| 137 | 137 | EOF; |
| 138 | 138 | |
| 139 | - protected $heading = <<<EOF |
|
| 139 | + protected $heading = <<<EOF |
|
| 140 | 140 | <table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px"> |
| 141 | 141 | <tbody> |
| 142 | 142 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | </table> |
| 156 | 156 | EOF; |
| 157 | 157 | |
| 158 | - protected $bodyBegin = <<<EOF |
|
| 158 | + protected $bodyBegin = <<<EOF |
|
| 159 | 159 | <table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%"> |
| 160 | 160 | <tr style="padding:0;text-align:left;vertical-align:top"> |
| 161 | 161 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | </table> |
| 173 | 173 | EOF; |
| 174 | 174 | |
| 175 | - protected $bodyText = <<<EOF |
|
| 175 | + protected $bodyText = <<<EOF |
|
| 176 | 176 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%"> |
| 177 | 177 | <tbody> |
| 178 | 178 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -191,8 +191,8 @@ discard block |
||
| 191 | 191 | </table> |
| 192 | 192 | EOF; |
| 193 | 193 | |
| 194 | - // note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151) |
|
| 195 | - protected $listBegin = <<<EOF |
|
| 194 | + // note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151) |
|
| 195 | + protected $listBegin = <<<EOF |
|
| 196 | 196 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%"> |
| 197 | 197 | <tbody> |
| 198 | 198 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%"> |
| 201 | 201 | EOF; |
| 202 | 202 | |
| 203 | - protected $listItem = <<<EOF |
|
| 203 | + protected $listItem = <<<EOF |
|
| 204 | 204 | <tr style="padding:0;text-align:left;vertical-align:top"> |
| 205 | 205 | <td style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;width:15px;"> |
| 206 | 206 | <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;padding-left:10px;text-align:left">%s</p> |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | </tr> |
| 213 | 213 | EOF; |
| 214 | 214 | |
| 215 | - protected $listEnd = <<<EOF |
|
| 215 | + protected $listEnd = <<<EOF |
|
| 216 | 216 | </table> |
| 217 | 217 | </th> |
| 218 | 218 | </tr> |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | </table> |
| 221 | 221 | EOF; |
| 222 | 222 | |
| 223 | - protected $buttonGroup = <<<EOF |
|
| 223 | + protected $buttonGroup = <<<EOF |
|
| 224 | 224 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
| 225 | 225 | <tbody> |
| 226 | 226 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | </table> |
| 274 | 274 | EOF; |
| 275 | 275 | |
| 276 | - protected $button = <<<EOF |
|
| 276 | + protected $button = <<<EOF |
|
| 277 | 277 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
| 278 | 278 | <tbody> |
| 279 | 279 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | </table> |
| 314 | 314 | EOF; |
| 315 | 315 | |
| 316 | - protected $bodyEnd = <<<EOF |
|
| 316 | + protected $bodyEnd = <<<EOF |
|
| 317 | 317 | |
| 318 | 318 | </td> |
| 319 | 319 | </tr> |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | </table> |
| 325 | 325 | EOF; |
| 326 | 326 | |
| 327 | - protected $footer = <<<EOF |
|
| 327 | + protected $footer = <<<EOF |
|
| 328 | 328 | <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
| 329 | 329 | <tbody> |
| 330 | 330 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -350,307 +350,307 @@ discard block |
||
| 350 | 350 | </table> |
| 351 | 351 | EOF; |
| 352 | 352 | |
| 353 | - public function __construct(Defaults $themingDefaults, |
|
| 354 | - IURLGenerator $urlGenerator, |
|
| 355 | - IFactory $l10nFactory, |
|
| 356 | - $emailId, |
|
| 357 | - array $data) { |
|
| 358 | - $this->themingDefaults = $themingDefaults; |
|
| 359 | - $this->urlGenerator = $urlGenerator; |
|
| 360 | - $this->l10nFactory = $l10nFactory; |
|
| 361 | - $this->htmlBody .= $this->head; |
|
| 362 | - $this->emailId = $emailId; |
|
| 363 | - $this->data = $data; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Sets the subject of the email |
|
| 368 | - * |
|
| 369 | - * @param string $subject |
|
| 370 | - */ |
|
| 371 | - public function setSubject(string $subject) { |
|
| 372 | - $this->subject = $subject; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Adds a header to the email |
|
| 377 | - */ |
|
| 378 | - public function addHeader() { |
|
| 379 | - if ($this->headerAdded) { |
|
| 380 | - return; |
|
| 381 | - } |
|
| 382 | - $this->headerAdded = true; |
|
| 383 | - |
|
| 384 | - $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); |
|
| 385 | - $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Adds a heading to the email |
|
| 390 | - * |
|
| 391 | - * @param string $title |
|
| 392 | - * @param string|bool $plainTitle Title that is used in the plain text email |
|
| 393 | - * if empty the $title is used, if false none will be used |
|
| 394 | - */ |
|
| 395 | - public function addHeading(string $title, $plainTitle = '') { |
|
| 396 | - if ($this->footerAdded) { |
|
| 397 | - return; |
|
| 398 | - } |
|
| 399 | - if ($plainTitle === '') { |
|
| 400 | - $plainTitle = $title; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
| 404 | - if ($plainTitle !== false) { |
|
| 405 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Open the HTML body when it is not already |
|
| 411 | - */ |
|
| 412 | - protected function ensureBodyIsOpened() { |
|
| 413 | - if ($this->bodyOpened) { |
|
| 414 | - return; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $this->htmlBody .= $this->bodyBegin; |
|
| 418 | - $this->bodyOpened = true; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Adds a paragraph to the body of the email |
|
| 423 | - * |
|
| 424 | - * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 425 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 426 | - * if empty the $text is used, if false none will be used |
|
| 427 | - */ |
|
| 428 | - public function addBodyText(string $text, $plainText = '') { |
|
| 429 | - if ($this->footerAdded) { |
|
| 430 | - return; |
|
| 431 | - } |
|
| 432 | - if ($plainText === '') { |
|
| 433 | - $plainText = $text; |
|
| 434 | - $text = htmlspecialchars($text); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $this->ensureBodyListClosed(); |
|
| 438 | - $this->ensureBodyIsOpened(); |
|
| 439 | - |
|
| 440 | - $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
|
| 441 | - if ($plainText !== false) { |
|
| 442 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * Adds a list item to the body of the email |
|
| 448 | - * |
|
| 449 | - * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 450 | - * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
| 451 | - * @param string $icon Absolute path, must be 16*16 pixels |
|
| 452 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 453 | - * if empty the $text is used, if false none will be used |
|
| 454 | - * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
| 455 | - * if empty the $metaInfo is used, if false none will be used |
|
| 456 | - * @since 12.0.0 |
|
| 457 | - */ |
|
| 458 | - public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '') { |
|
| 459 | - $this->ensureBodyListOpened(); |
|
| 460 | - |
|
| 461 | - if ($plainText === '') { |
|
| 462 | - $plainText = $text; |
|
| 463 | - $text = htmlspecialchars($text); |
|
| 464 | - } |
|
| 465 | - if ($plainMetaInfo === '') { |
|
| 466 | - $plainMetaInfo = $metaInfo; |
|
| 467 | - $metaInfo = htmlspecialchars($metaInfo); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $htmlText = $text; |
|
| 471 | - if ($metaInfo) { |
|
| 472 | - $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText; |
|
| 473 | - } |
|
| 474 | - if ($icon !== '') { |
|
| 475 | - $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
| 476 | - } else { |
|
| 477 | - $icon = '•'; |
|
| 478 | - } |
|
| 479 | - $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
|
| 480 | - if ($plainText !== false) { |
|
| 481 | - $this->plainBody .= ' * ' . $plainText; |
|
| 482 | - if ($plainMetaInfo !== false) { |
|
| 483 | - $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
| 484 | - } |
|
| 485 | - $this->plainBody .= PHP_EOL; |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - protected function ensureBodyListOpened() { |
|
| 490 | - if ($this->bodyListOpened) { |
|
| 491 | - return; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - $this->ensureBodyIsOpened(); |
|
| 495 | - $this->bodyListOpened = true; |
|
| 496 | - $this->htmlBody .= $this->listBegin; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - protected function ensureBodyListClosed() { |
|
| 500 | - if (!$this->bodyListOpened) { |
|
| 501 | - return; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - $this->bodyListOpened = false; |
|
| 505 | - $this->htmlBody .= $this->listEnd; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Adds a button group of two buttons to the body of the email |
|
| 510 | - * |
|
| 511 | - * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
| 512 | - * @param string $urlLeft URL of left button |
|
| 513 | - * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
| 514 | - * @param string $urlRight URL of right button |
|
| 515 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
| 516 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
| 517 | - */ |
|
| 518 | - public function addBodyButtonGroup(string $textLeft, |
|
| 519 | - string $urlLeft, |
|
| 520 | - string $textRight, |
|
| 521 | - string $urlRight, |
|
| 522 | - string $plainTextLeft = '', |
|
| 523 | - string $plainTextRight = '') { |
|
| 524 | - if ($this->footerAdded) { |
|
| 525 | - return; |
|
| 526 | - } |
|
| 527 | - if ($plainTextLeft === '') { |
|
| 528 | - $plainTextLeft = $textLeft; |
|
| 529 | - $textLeft = htmlspecialchars($textLeft); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - if ($plainTextRight === '') { |
|
| 533 | - $plainTextRight = $textRight; |
|
| 534 | - $textRight = htmlspecialchars($textRight); |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - $this->ensureBodyIsOpened(); |
|
| 538 | - $this->ensureBodyListClosed(); |
|
| 539 | - |
|
| 540 | - $color = $this->themingDefaults->getColorPrimary(); |
|
| 541 | - $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 542 | - |
|
| 543 | - $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); |
|
| 544 | - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 545 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Adds a button to the body of the email |
|
| 550 | - * |
|
| 551 | - * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 552 | - * @param string $url URL of button |
|
| 553 | - * @param string $plainText Text of button in plain text version |
|
| 554 | - * if empty the $text is used, if false none will be used |
|
| 555 | - * |
|
| 556 | - * @since 12.0.0 |
|
| 557 | - */ |
|
| 558 | - public function addBodyButton(string $text, string $url, $plainText = '') { |
|
| 559 | - if ($this->footerAdded) { |
|
| 560 | - return; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - $this->ensureBodyIsOpened(); |
|
| 564 | - $this->ensureBodyListClosed(); |
|
| 565 | - |
|
| 566 | - if ($plainText === '') { |
|
| 567 | - $plainText = $text; |
|
| 568 | - $text = htmlspecialchars($text); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - $color = $this->themingDefaults->getColorPrimary(); |
|
| 572 | - $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 573 | - $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]); |
|
| 574 | - |
|
| 575 | - if ($plainText !== false) { |
|
| 576 | - $this->plainBody .= $plainText . ': '; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - $this->plainBody .= $url . PHP_EOL; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * Close the HTML body when it is open |
|
| 584 | - */ |
|
| 585 | - protected function ensureBodyIsClosed() { |
|
| 586 | - if (!$this->bodyOpened) { |
|
| 587 | - return; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - $this->ensureBodyListClosed(); |
|
| 591 | - |
|
| 592 | - $this->htmlBody .= $this->bodyEnd; |
|
| 593 | - $this->bodyOpened = false; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 598 | - * |
|
| 599 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
| 600 | - */ |
|
| 601 | - public function addFooter(string $text = '', ?string $lang = null) { |
|
| 602 | - if ($text === '') { |
|
| 603 | - $l10n = $this->l10nFactory->get('lib', $lang); |
|
| 604 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.'); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - if ($this->footerAdded) { |
|
| 608 | - return; |
|
| 609 | - } |
|
| 610 | - $this->footerAdded = true; |
|
| 611 | - |
|
| 612 | - $this->ensureBodyIsClosed(); |
|
| 613 | - |
|
| 614 | - $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
| 615 | - $this->htmlBody .= $this->tail; |
|
| 616 | - $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 617 | - $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Returns the rendered email subject as string |
|
| 622 | - * |
|
| 623 | - * @return string |
|
| 624 | - */ |
|
| 625 | - public function renderSubject(): string { |
|
| 626 | - return $this->subject; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Returns the rendered HTML email as string |
|
| 631 | - * |
|
| 632 | - * @return string |
|
| 633 | - */ |
|
| 634 | - public function renderHtml(): string { |
|
| 635 | - if (!$this->footerAdded) { |
|
| 636 | - $this->footerAdded = true; |
|
| 637 | - $this->ensureBodyIsClosed(); |
|
| 638 | - $this->htmlBody .= $this->tail; |
|
| 639 | - } |
|
| 640 | - return $this->htmlBody; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * Returns the rendered plain text email as string |
|
| 645 | - * |
|
| 646 | - * @return string |
|
| 647 | - */ |
|
| 648 | - public function renderText(): string { |
|
| 649 | - if (!$this->footerAdded) { |
|
| 650 | - $this->footerAdded = true; |
|
| 651 | - $this->ensureBodyIsClosed(); |
|
| 652 | - $this->htmlBody .= $this->tail; |
|
| 653 | - } |
|
| 654 | - return $this->plainBody; |
|
| 655 | - } |
|
| 353 | + public function __construct(Defaults $themingDefaults, |
|
| 354 | + IURLGenerator $urlGenerator, |
|
| 355 | + IFactory $l10nFactory, |
|
| 356 | + $emailId, |
|
| 357 | + array $data) { |
|
| 358 | + $this->themingDefaults = $themingDefaults; |
|
| 359 | + $this->urlGenerator = $urlGenerator; |
|
| 360 | + $this->l10nFactory = $l10nFactory; |
|
| 361 | + $this->htmlBody .= $this->head; |
|
| 362 | + $this->emailId = $emailId; |
|
| 363 | + $this->data = $data; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Sets the subject of the email |
|
| 368 | + * |
|
| 369 | + * @param string $subject |
|
| 370 | + */ |
|
| 371 | + public function setSubject(string $subject) { |
|
| 372 | + $this->subject = $subject; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Adds a header to the email |
|
| 377 | + */ |
|
| 378 | + public function addHeader() { |
|
| 379 | + if ($this->headerAdded) { |
|
| 380 | + return; |
|
| 381 | + } |
|
| 382 | + $this->headerAdded = true; |
|
| 383 | + |
|
| 384 | + $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); |
|
| 385 | + $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Adds a heading to the email |
|
| 390 | + * |
|
| 391 | + * @param string $title |
|
| 392 | + * @param string|bool $plainTitle Title that is used in the plain text email |
|
| 393 | + * if empty the $title is used, if false none will be used |
|
| 394 | + */ |
|
| 395 | + public function addHeading(string $title, $plainTitle = '') { |
|
| 396 | + if ($this->footerAdded) { |
|
| 397 | + return; |
|
| 398 | + } |
|
| 399 | + if ($plainTitle === '') { |
|
| 400 | + $plainTitle = $title; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
| 404 | + if ($plainTitle !== false) { |
|
| 405 | + $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Open the HTML body when it is not already |
|
| 411 | + */ |
|
| 412 | + protected function ensureBodyIsOpened() { |
|
| 413 | + if ($this->bodyOpened) { |
|
| 414 | + return; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $this->htmlBody .= $this->bodyBegin; |
|
| 418 | + $this->bodyOpened = true; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Adds a paragraph to the body of the email |
|
| 423 | + * |
|
| 424 | + * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 425 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 426 | + * if empty the $text is used, if false none will be used |
|
| 427 | + */ |
|
| 428 | + public function addBodyText(string $text, $plainText = '') { |
|
| 429 | + if ($this->footerAdded) { |
|
| 430 | + return; |
|
| 431 | + } |
|
| 432 | + if ($plainText === '') { |
|
| 433 | + $plainText = $text; |
|
| 434 | + $text = htmlspecialchars($text); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $this->ensureBodyListClosed(); |
|
| 438 | + $this->ensureBodyIsOpened(); |
|
| 439 | + |
|
| 440 | + $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
|
| 441 | + if ($plainText !== false) { |
|
| 442 | + $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * Adds a list item to the body of the email |
|
| 448 | + * |
|
| 449 | + * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 450 | + * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
| 451 | + * @param string $icon Absolute path, must be 16*16 pixels |
|
| 452 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 453 | + * if empty the $text is used, if false none will be used |
|
| 454 | + * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
| 455 | + * if empty the $metaInfo is used, if false none will be used |
|
| 456 | + * @since 12.0.0 |
|
| 457 | + */ |
|
| 458 | + public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '') { |
|
| 459 | + $this->ensureBodyListOpened(); |
|
| 460 | + |
|
| 461 | + if ($plainText === '') { |
|
| 462 | + $plainText = $text; |
|
| 463 | + $text = htmlspecialchars($text); |
|
| 464 | + } |
|
| 465 | + if ($plainMetaInfo === '') { |
|
| 466 | + $plainMetaInfo = $metaInfo; |
|
| 467 | + $metaInfo = htmlspecialchars($metaInfo); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $htmlText = $text; |
|
| 471 | + if ($metaInfo) { |
|
| 472 | + $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText; |
|
| 473 | + } |
|
| 474 | + if ($icon !== '') { |
|
| 475 | + $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
| 476 | + } else { |
|
| 477 | + $icon = '•'; |
|
| 478 | + } |
|
| 479 | + $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
|
| 480 | + if ($plainText !== false) { |
|
| 481 | + $this->plainBody .= ' * ' . $plainText; |
|
| 482 | + if ($plainMetaInfo !== false) { |
|
| 483 | + $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
| 484 | + } |
|
| 485 | + $this->plainBody .= PHP_EOL; |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + protected function ensureBodyListOpened() { |
|
| 490 | + if ($this->bodyListOpened) { |
|
| 491 | + return; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + $this->ensureBodyIsOpened(); |
|
| 495 | + $this->bodyListOpened = true; |
|
| 496 | + $this->htmlBody .= $this->listBegin; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + protected function ensureBodyListClosed() { |
|
| 500 | + if (!$this->bodyListOpened) { |
|
| 501 | + return; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + $this->bodyListOpened = false; |
|
| 505 | + $this->htmlBody .= $this->listEnd; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Adds a button group of two buttons to the body of the email |
|
| 510 | + * |
|
| 511 | + * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
| 512 | + * @param string $urlLeft URL of left button |
|
| 513 | + * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
| 514 | + * @param string $urlRight URL of right button |
|
| 515 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
| 516 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
| 517 | + */ |
|
| 518 | + public function addBodyButtonGroup(string $textLeft, |
|
| 519 | + string $urlLeft, |
|
| 520 | + string $textRight, |
|
| 521 | + string $urlRight, |
|
| 522 | + string $plainTextLeft = '', |
|
| 523 | + string $plainTextRight = '') { |
|
| 524 | + if ($this->footerAdded) { |
|
| 525 | + return; |
|
| 526 | + } |
|
| 527 | + if ($plainTextLeft === '') { |
|
| 528 | + $plainTextLeft = $textLeft; |
|
| 529 | + $textLeft = htmlspecialchars($textLeft); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + if ($plainTextRight === '') { |
|
| 533 | + $plainTextRight = $textRight; |
|
| 534 | + $textRight = htmlspecialchars($textRight); |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + $this->ensureBodyIsOpened(); |
|
| 538 | + $this->ensureBodyListClosed(); |
|
| 539 | + |
|
| 540 | + $color = $this->themingDefaults->getColorPrimary(); |
|
| 541 | + $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 542 | + |
|
| 543 | + $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); |
|
| 544 | + $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 545 | + $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Adds a button to the body of the email |
|
| 550 | + * |
|
| 551 | + * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 552 | + * @param string $url URL of button |
|
| 553 | + * @param string $plainText Text of button in plain text version |
|
| 554 | + * if empty the $text is used, if false none will be used |
|
| 555 | + * |
|
| 556 | + * @since 12.0.0 |
|
| 557 | + */ |
|
| 558 | + public function addBodyButton(string $text, string $url, $plainText = '') { |
|
| 559 | + if ($this->footerAdded) { |
|
| 560 | + return; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + $this->ensureBodyIsOpened(); |
|
| 564 | + $this->ensureBodyListClosed(); |
|
| 565 | + |
|
| 566 | + if ($plainText === '') { |
|
| 567 | + $plainText = $text; |
|
| 568 | + $text = htmlspecialchars($text); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + $color = $this->themingDefaults->getColorPrimary(); |
|
| 572 | + $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 573 | + $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]); |
|
| 574 | + |
|
| 575 | + if ($plainText !== false) { |
|
| 576 | + $this->plainBody .= $plainText . ': '; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + $this->plainBody .= $url . PHP_EOL; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * Close the HTML body when it is open |
|
| 584 | + */ |
|
| 585 | + protected function ensureBodyIsClosed() { |
|
| 586 | + if (!$this->bodyOpened) { |
|
| 587 | + return; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + $this->ensureBodyListClosed(); |
|
| 591 | + |
|
| 592 | + $this->htmlBody .= $this->bodyEnd; |
|
| 593 | + $this->bodyOpened = false; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 598 | + * |
|
| 599 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
| 600 | + */ |
|
| 601 | + public function addFooter(string $text = '', ?string $lang = null) { |
|
| 602 | + if ($text === '') { |
|
| 603 | + $l10n = $this->l10nFactory->get('lib', $lang); |
|
| 604 | + $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.'); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + if ($this->footerAdded) { |
|
| 608 | + return; |
|
| 609 | + } |
|
| 610 | + $this->footerAdded = true; |
|
| 611 | + |
|
| 612 | + $this->ensureBodyIsClosed(); |
|
| 613 | + |
|
| 614 | + $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
| 615 | + $this->htmlBody .= $this->tail; |
|
| 616 | + $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 617 | + $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Returns the rendered email subject as string |
|
| 622 | + * |
|
| 623 | + * @return string |
|
| 624 | + */ |
|
| 625 | + public function renderSubject(): string { |
|
| 626 | + return $this->subject; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Returns the rendered HTML email as string |
|
| 631 | + * |
|
| 632 | + * @return string |
|
| 633 | + */ |
|
| 634 | + public function renderHtml(): string { |
|
| 635 | + if (!$this->footerAdded) { |
|
| 636 | + $this->footerAdded = true; |
|
| 637 | + $this->ensureBodyIsClosed(); |
|
| 638 | + $this->htmlBody .= $this->tail; |
|
| 639 | + } |
|
| 640 | + return $this->htmlBody; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * Returns the rendered plain text email as string |
|
| 645 | + * |
|
| 646 | + * @return string |
|
| 647 | + */ |
|
| 648 | + public function renderText(): string { |
|
| 649 | + if (!$this->footerAdded) { |
|
| 650 | + $this->footerAdded = true; |
|
| 651 | + $this->ensureBodyIsClosed(); |
|
| 652 | + $this->htmlBody .= $this->tail; |
|
| 653 | + } |
|
| 654 | + return $this->plainBody; |
|
| 655 | + } |
|
| 656 | 656 | } |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | |
| 403 | 403 | $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
| 404 | 404 | if ($plainTitle !== false) { |
| 405 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 405 | + $this->plainBody .= $plainTitle.PHP_EOL.PHP_EOL; |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | |
| 440 | 440 | $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
| 441 | 441 | if ($plainText !== false) { |
| 442 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 442 | + $this->plainBody .= $plainText.PHP_EOL.PHP_EOL; |
|
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | |
@@ -469,18 +469,18 @@ discard block |
||
| 469 | 469 | |
| 470 | 470 | $htmlText = $text; |
| 471 | 471 | if ($metaInfo) { |
| 472 | - $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText; |
|
| 472 | + $htmlText = '<em style="color:#777;">'.$metaInfo.'</em><br>'.$htmlText; |
|
| 473 | 473 | } |
| 474 | 474 | if ($icon !== '') { |
| 475 | - $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
| 475 | + $icon = '<img src="'.htmlspecialchars($icon).'" alt="•">'; |
|
| 476 | 476 | } else { |
| 477 | 477 | $icon = '•'; |
| 478 | 478 | } |
| 479 | 479 | $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
| 480 | 480 | if ($plainText !== false) { |
| 481 | - $this->plainBody .= ' * ' . $plainText; |
|
| 481 | + $this->plainBody .= ' * '.$plainText; |
|
| 482 | 482 | if ($plainMetaInfo !== false) { |
| 483 | - $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
| 483 | + $this->plainBody .= ' ('.$plainMetaInfo.')'; |
|
| 484 | 484 | } |
| 485 | 485 | $this->plainBody .= PHP_EOL; |
| 486 | 486 | } |
@@ -541,8 +541,8 @@ discard block |
||
| 541 | 541 | $textColor = $this->themingDefaults->getTextColorPrimary(); |
| 542 | 542 | |
| 543 | 543 | $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); |
| 544 | - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 545 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 544 | + $this->plainBody .= $plainTextLeft.': '.$urlLeft.PHP_EOL; |
|
| 545 | + $this->plainBody .= $plainTextRight.': '.$urlRight.PHP_EOL.PHP_EOL; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -573,10 +573,10 @@ discard block |
||
| 573 | 573 | $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]); |
| 574 | 574 | |
| 575 | 575 | if ($plainText !== false) { |
| 576 | - $this->plainBody .= $plainText . ': '; |
|
| 576 | + $this->plainBody .= $plainText.': '; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - $this->plainBody .= $url . PHP_EOL; |
|
| 579 | + $this->plainBody .= $url.PHP_EOL; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | public function addFooter(string $text = '', ?string $lang = null) { |
| 602 | 602 | if ($text === '') { |
| 603 | 603 | $l10n = $this->l10nFactory->get('lib', $lang); |
| 604 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.'); |
|
| 604 | + $text = $this->themingDefaults->getName().' - '.$this->themingDefaults->getSlogan($lang).'<br>'.$l10n->t('This is an automatically sent email, please do not reply.'); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | if ($this->footerAdded) { |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | |
| 614 | 614 | $this->htmlBody .= vsprintf($this->footer, [$text]); |
| 615 | 615 | $this->htmlBody .= $this->tail; |
| 616 | - $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 616 | + $this->plainBody .= PHP_EOL.'-- '.PHP_EOL; |
|
| 617 | 617 | $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
| 618 | 618 | } |
| 619 | 619 | |
@@ -36,297 +36,297 @@ |
||
| 36 | 36 | * |
| 37 | 37 | */ |
| 38 | 38 | class OC_Defaults { |
| 39 | - private $theme; |
|
| 39 | + private $theme; |
|
| 40 | 40 | |
| 41 | - private $defaultEntity; |
|
| 42 | - private $defaultName; |
|
| 43 | - private $defaultTitle; |
|
| 44 | - private $defaultBaseUrl; |
|
| 45 | - private $defaultSyncClientUrl; |
|
| 46 | - private $defaultiOSClientUrl; |
|
| 47 | - private $defaultiTunesAppId; |
|
| 48 | - private $defaultAndroidClientUrl; |
|
| 49 | - private $defaultDocBaseUrl; |
|
| 50 | - private $defaultDocVersion; |
|
| 51 | - private $defaultSlogan; |
|
| 52 | - private $defaultColorPrimary; |
|
| 53 | - private $defaultTextColorPrimary; |
|
| 41 | + private $defaultEntity; |
|
| 42 | + private $defaultName; |
|
| 43 | + private $defaultTitle; |
|
| 44 | + private $defaultBaseUrl; |
|
| 45 | + private $defaultSyncClientUrl; |
|
| 46 | + private $defaultiOSClientUrl; |
|
| 47 | + private $defaultiTunesAppId; |
|
| 48 | + private $defaultAndroidClientUrl; |
|
| 49 | + private $defaultDocBaseUrl; |
|
| 50 | + private $defaultDocVersion; |
|
| 51 | + private $defaultSlogan; |
|
| 52 | + private $defaultColorPrimary; |
|
| 53 | + private $defaultTextColorPrimary; |
|
| 54 | 54 | |
| 55 | - public function __construct() { |
|
| 56 | - $config = \OC::$server->getConfig(); |
|
| 55 | + public function __construct() { |
|
| 56 | + $config = \OC::$server->getConfig(); |
|
| 57 | 57 | |
| 58 | - $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */ |
|
| 59 | - $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */ |
|
| 60 | - $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */ |
|
| 61 | - $this->defaultBaseUrl = 'https://nextcloud.com'; |
|
| 62 | - $this->defaultSyncClientUrl = $config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients'); |
|
| 63 | - $this->defaultiOSClientUrl = $config->getSystemValue('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8'); |
|
| 64 | - $this->defaultiTunesAppId = $config->getSystemValue('customclient_ios_appid', '1125420102'); |
|
| 65 | - $this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client'); |
|
| 66 | - $this->defaultDocBaseUrl = 'https://docs.nextcloud.com'; |
|
| 67 | - $this->defaultDocVersion = \OC_Util::getVersion()[0]; // used to generate doc links |
|
| 68 | - $this->defaultColorPrimary = '#0082c9'; |
|
| 69 | - $this->defaultTextColorPrimary = '#ffffff'; |
|
| 58 | + $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */ |
|
| 59 | + $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */ |
|
| 60 | + $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */ |
|
| 61 | + $this->defaultBaseUrl = 'https://nextcloud.com'; |
|
| 62 | + $this->defaultSyncClientUrl = $config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients'); |
|
| 63 | + $this->defaultiOSClientUrl = $config->getSystemValue('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8'); |
|
| 64 | + $this->defaultiTunesAppId = $config->getSystemValue('customclient_ios_appid', '1125420102'); |
|
| 65 | + $this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client'); |
|
| 66 | + $this->defaultDocBaseUrl = 'https://docs.nextcloud.com'; |
|
| 67 | + $this->defaultDocVersion = \OC_Util::getVersion()[0]; // used to generate doc links |
|
| 68 | + $this->defaultColorPrimary = '#0082c9'; |
|
| 69 | + $this->defaultTextColorPrimary = '#ffffff'; |
|
| 70 | 70 | |
| 71 | - $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php'; |
|
| 72 | - if (file_exists($themePath)) { |
|
| 73 | - // prevent defaults.php from printing output |
|
| 74 | - ob_start(); |
|
| 75 | - require_once $themePath; |
|
| 76 | - ob_end_clean(); |
|
| 77 | - if (class_exists('OC_Theme')) { |
|
| 78 | - $this->theme = new OC_Theme(); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - } |
|
| 71 | + $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php'; |
|
| 72 | + if (file_exists($themePath)) { |
|
| 73 | + // prevent defaults.php from printing output |
|
| 74 | + ob_start(); |
|
| 75 | + require_once $themePath; |
|
| 76 | + ob_end_clean(); |
|
| 77 | + if (class_exists('OC_Theme')) { |
|
| 78 | + $this->theme = new OC_Theme(); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @param string $method |
|
| 85 | - */ |
|
| 86 | - private function themeExist($method) { |
|
| 87 | - if (isset($this->theme) && method_exists($this->theme, $method)) { |
|
| 88 | - return true; |
|
| 89 | - } |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 83 | + /** |
|
| 84 | + * @param string $method |
|
| 85 | + */ |
|
| 86 | + private function themeExist($method) { |
|
| 87 | + if (isset($this->theme) && method_exists($this->theme, $method)) { |
|
| 88 | + return true; |
|
| 89 | + } |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Returns the base URL |
|
| 95 | - * @return string URL |
|
| 96 | - */ |
|
| 97 | - public function getBaseUrl() { |
|
| 98 | - if ($this->themeExist('getBaseUrl')) { |
|
| 99 | - return $this->theme->getBaseUrl(); |
|
| 100 | - } else { |
|
| 101 | - return $this->defaultBaseUrl; |
|
| 102 | - } |
|
| 103 | - } |
|
| 93 | + /** |
|
| 94 | + * Returns the base URL |
|
| 95 | + * @return string URL |
|
| 96 | + */ |
|
| 97 | + public function getBaseUrl() { |
|
| 98 | + if ($this->themeExist('getBaseUrl')) { |
|
| 99 | + return $this->theme->getBaseUrl(); |
|
| 100 | + } else { |
|
| 101 | + return $this->defaultBaseUrl; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Returns the URL where the sync clients are listed |
|
| 107 | - * @return string URL |
|
| 108 | - */ |
|
| 109 | - public function getSyncClientUrl() { |
|
| 110 | - if ($this->themeExist('getSyncClientUrl')) { |
|
| 111 | - return $this->theme->getSyncClientUrl(); |
|
| 112 | - } else { |
|
| 113 | - return $this->defaultSyncClientUrl; |
|
| 114 | - } |
|
| 115 | - } |
|
| 105 | + /** |
|
| 106 | + * Returns the URL where the sync clients are listed |
|
| 107 | + * @return string URL |
|
| 108 | + */ |
|
| 109 | + public function getSyncClientUrl() { |
|
| 110 | + if ($this->themeExist('getSyncClientUrl')) { |
|
| 111 | + return $this->theme->getSyncClientUrl(); |
|
| 112 | + } else { |
|
| 113 | + return $this->defaultSyncClientUrl; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Returns the URL to the App Store for the iOS Client |
|
| 119 | - * @return string URL |
|
| 120 | - */ |
|
| 121 | - public function getiOSClientUrl() { |
|
| 122 | - if ($this->themeExist('getiOSClientUrl')) { |
|
| 123 | - return $this->theme->getiOSClientUrl(); |
|
| 124 | - } else { |
|
| 125 | - return $this->defaultiOSClientUrl; |
|
| 126 | - } |
|
| 127 | - } |
|
| 117 | + /** |
|
| 118 | + * Returns the URL to the App Store for the iOS Client |
|
| 119 | + * @return string URL |
|
| 120 | + */ |
|
| 121 | + public function getiOSClientUrl() { |
|
| 122 | + if ($this->themeExist('getiOSClientUrl')) { |
|
| 123 | + return $this->theme->getiOSClientUrl(); |
|
| 124 | + } else { |
|
| 125 | + return $this->defaultiOSClientUrl; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Returns the AppId for the App Store for the iOS Client |
|
| 131 | - * @return string AppId |
|
| 132 | - */ |
|
| 133 | - public function getiTunesAppId() { |
|
| 134 | - if ($this->themeExist('getiTunesAppId')) { |
|
| 135 | - return $this->theme->getiTunesAppId(); |
|
| 136 | - } else { |
|
| 137 | - return $this->defaultiTunesAppId; |
|
| 138 | - } |
|
| 139 | - } |
|
| 129 | + /** |
|
| 130 | + * Returns the AppId for the App Store for the iOS Client |
|
| 131 | + * @return string AppId |
|
| 132 | + */ |
|
| 133 | + public function getiTunesAppId() { |
|
| 134 | + if ($this->themeExist('getiTunesAppId')) { |
|
| 135 | + return $this->theme->getiTunesAppId(); |
|
| 136 | + } else { |
|
| 137 | + return $this->defaultiTunesAppId; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Returns the URL to Google Play for the Android Client |
|
| 143 | - * @return string URL |
|
| 144 | - */ |
|
| 145 | - public function getAndroidClientUrl() { |
|
| 146 | - if ($this->themeExist('getAndroidClientUrl')) { |
|
| 147 | - return $this->theme->getAndroidClientUrl(); |
|
| 148 | - } else { |
|
| 149 | - return $this->defaultAndroidClientUrl; |
|
| 150 | - } |
|
| 151 | - } |
|
| 141 | + /** |
|
| 142 | + * Returns the URL to Google Play for the Android Client |
|
| 143 | + * @return string URL |
|
| 144 | + */ |
|
| 145 | + public function getAndroidClientUrl() { |
|
| 146 | + if ($this->themeExist('getAndroidClientUrl')) { |
|
| 147 | + return $this->theme->getAndroidClientUrl(); |
|
| 148 | + } else { |
|
| 149 | + return $this->defaultAndroidClientUrl; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Returns the documentation URL |
|
| 155 | - * @return string URL |
|
| 156 | - */ |
|
| 157 | - public function getDocBaseUrl() { |
|
| 158 | - if ($this->themeExist('getDocBaseUrl')) { |
|
| 159 | - return $this->theme->getDocBaseUrl(); |
|
| 160 | - } else { |
|
| 161 | - return $this->defaultDocBaseUrl; |
|
| 162 | - } |
|
| 163 | - } |
|
| 153 | + /** |
|
| 154 | + * Returns the documentation URL |
|
| 155 | + * @return string URL |
|
| 156 | + */ |
|
| 157 | + public function getDocBaseUrl() { |
|
| 158 | + if ($this->themeExist('getDocBaseUrl')) { |
|
| 159 | + return $this->theme->getDocBaseUrl(); |
|
| 160 | + } else { |
|
| 161 | + return $this->defaultDocBaseUrl; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Returns the title |
|
| 167 | - * @return string title |
|
| 168 | - */ |
|
| 169 | - public function getTitle() { |
|
| 170 | - if ($this->themeExist('getTitle')) { |
|
| 171 | - return $this->theme->getTitle(); |
|
| 172 | - } else { |
|
| 173 | - return $this->defaultTitle; |
|
| 174 | - } |
|
| 175 | - } |
|
| 165 | + /** |
|
| 166 | + * Returns the title |
|
| 167 | + * @return string title |
|
| 168 | + */ |
|
| 169 | + public function getTitle() { |
|
| 170 | + if ($this->themeExist('getTitle')) { |
|
| 171 | + return $this->theme->getTitle(); |
|
| 172 | + } else { |
|
| 173 | + return $this->defaultTitle; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Returns the short name of the software |
|
| 179 | - * @return string title |
|
| 180 | - */ |
|
| 181 | - public function getName() { |
|
| 182 | - if ($this->themeExist('getName')) { |
|
| 183 | - return $this->theme->getName(); |
|
| 184 | - } else { |
|
| 185 | - return $this->defaultName; |
|
| 186 | - } |
|
| 187 | - } |
|
| 177 | + /** |
|
| 178 | + * Returns the short name of the software |
|
| 179 | + * @return string title |
|
| 180 | + */ |
|
| 181 | + public function getName() { |
|
| 182 | + if ($this->themeExist('getName')) { |
|
| 183 | + return $this->theme->getName(); |
|
| 184 | + } else { |
|
| 185 | + return $this->defaultName; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Returns the short name of the software containing HTML strings |
|
| 191 | - * @return string title |
|
| 192 | - */ |
|
| 193 | - public function getHTMLName() { |
|
| 194 | - if ($this->themeExist('getHTMLName')) { |
|
| 195 | - return $this->theme->getHTMLName(); |
|
| 196 | - } else { |
|
| 197 | - return $this->defaultName; |
|
| 198 | - } |
|
| 199 | - } |
|
| 189 | + /** |
|
| 190 | + * Returns the short name of the software containing HTML strings |
|
| 191 | + * @return string title |
|
| 192 | + */ |
|
| 193 | + public function getHTMLName() { |
|
| 194 | + if ($this->themeExist('getHTMLName')) { |
|
| 195 | + return $this->theme->getHTMLName(); |
|
| 196 | + } else { |
|
| 197 | + return $this->defaultName; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Returns entity (e.g. company name) - used for footer, copyright |
|
| 203 | - * @return string entity name |
|
| 204 | - */ |
|
| 205 | - public function getEntity() { |
|
| 206 | - if ($this->themeExist('getEntity')) { |
|
| 207 | - return $this->theme->getEntity(); |
|
| 208 | - } else { |
|
| 209 | - return $this->defaultEntity; |
|
| 210 | - } |
|
| 211 | - } |
|
| 201 | + /** |
|
| 202 | + * Returns entity (e.g. company name) - used for footer, copyright |
|
| 203 | + * @return string entity name |
|
| 204 | + */ |
|
| 205 | + public function getEntity() { |
|
| 206 | + if ($this->themeExist('getEntity')) { |
|
| 207 | + return $this->theme->getEntity(); |
|
| 208 | + } else { |
|
| 209 | + return $this->defaultEntity; |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Returns slogan |
|
| 215 | - * @return string slogan |
|
| 216 | - */ |
|
| 217 | - public function getSlogan(?string $lang = null) { |
|
| 218 | - if ($this->themeExist('getSlogan')) { |
|
| 219 | - return $this->theme->getSlogan($lang); |
|
| 220 | - } else { |
|
| 221 | - if ($this->defaultSlogan === null) { |
|
| 222 | - $l10n = \OC::$server->getL10N('lib', $lang); |
|
| 223 | - $this->defaultSlogan = $l10n->t('a safe home for all your data'); |
|
| 224 | - } |
|
| 225 | - return $this->defaultSlogan; |
|
| 226 | - } |
|
| 227 | - } |
|
| 213 | + /** |
|
| 214 | + * Returns slogan |
|
| 215 | + * @return string slogan |
|
| 216 | + */ |
|
| 217 | + public function getSlogan(?string $lang = null) { |
|
| 218 | + if ($this->themeExist('getSlogan')) { |
|
| 219 | + return $this->theme->getSlogan($lang); |
|
| 220 | + } else { |
|
| 221 | + if ($this->defaultSlogan === null) { |
|
| 222 | + $l10n = \OC::$server->getL10N('lib', $lang); |
|
| 223 | + $this->defaultSlogan = $l10n->t('a safe home for all your data'); |
|
| 224 | + } |
|
| 225 | + return $this->defaultSlogan; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * Returns logo claim |
|
| 231 | - * @return string logo claim |
|
| 232 | - * @deprecated 13.0.0 |
|
| 233 | - */ |
|
| 234 | - public function getLogoClaim() { |
|
| 235 | - return ''; |
|
| 236 | - } |
|
| 229 | + /** |
|
| 230 | + * Returns logo claim |
|
| 231 | + * @return string logo claim |
|
| 232 | + * @deprecated 13.0.0 |
|
| 233 | + */ |
|
| 234 | + public function getLogoClaim() { |
|
| 235 | + return ''; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Returns short version of the footer |
|
| 240 | - * @return string short footer |
|
| 241 | - */ |
|
| 242 | - public function getShortFooter() { |
|
| 243 | - if ($this->themeExist('getShortFooter')) { |
|
| 244 | - $footer = $this->theme->getShortFooter(); |
|
| 245 | - } else { |
|
| 246 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
| 247 | - ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
| 248 | - ' – ' . $this->getSlogan(); |
|
| 249 | - } |
|
| 238 | + /** |
|
| 239 | + * Returns short version of the footer |
|
| 240 | + * @return string short footer |
|
| 241 | + */ |
|
| 242 | + public function getShortFooter() { |
|
| 243 | + if ($this->themeExist('getShortFooter')) { |
|
| 244 | + $footer = $this->theme->getShortFooter(); |
|
| 245 | + } else { |
|
| 246 | + $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
| 247 | + ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
| 248 | + ' – ' . $this->getSlogan(); |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - return $footer; |
|
| 252 | - } |
|
| 251 | + return $footer; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Returns long version of the footer |
|
| 256 | - * @return string long footer |
|
| 257 | - */ |
|
| 258 | - public function getLongFooter() { |
|
| 259 | - if ($this->themeExist('getLongFooter')) { |
|
| 260 | - $footer = $this->theme->getLongFooter(); |
|
| 261 | - } else { |
|
| 262 | - $footer = $this->getShortFooter(); |
|
| 263 | - } |
|
| 254 | + /** |
|
| 255 | + * Returns long version of the footer |
|
| 256 | + * @return string long footer |
|
| 257 | + */ |
|
| 258 | + public function getLongFooter() { |
|
| 259 | + if ($this->themeExist('getLongFooter')) { |
|
| 260 | + $footer = $this->theme->getLongFooter(); |
|
| 261 | + } else { |
|
| 262 | + $footer = $this->getShortFooter(); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - return $footer; |
|
| 266 | - } |
|
| 265 | + return $footer; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * @param string $key |
|
| 270 | - * @return string URL to doc with key |
|
| 271 | - */ |
|
| 272 | - public function buildDocLinkToKey($key) { |
|
| 273 | - if ($this->themeExist('buildDocLinkToKey')) { |
|
| 274 | - return $this->theme->buildDocLinkToKey($key); |
|
| 275 | - } |
|
| 276 | - return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key; |
|
| 277 | - } |
|
| 268 | + /** |
|
| 269 | + * @param string $key |
|
| 270 | + * @return string URL to doc with key |
|
| 271 | + */ |
|
| 272 | + public function buildDocLinkToKey($key) { |
|
| 273 | + if ($this->themeExist('buildDocLinkToKey')) { |
|
| 274 | + return $this->theme->buildDocLinkToKey($key); |
|
| 275 | + } |
|
| 276 | + return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * Returns primary color |
|
| 281 | - * @return string |
|
| 282 | - */ |
|
| 283 | - public function getColorPrimary() { |
|
| 284 | - if ($this->themeExist('getColorPrimary')) { |
|
| 285 | - return $this->theme->getColorPrimary(); |
|
| 286 | - } |
|
| 287 | - if ($this->themeExist('getMailHeaderColor')) { |
|
| 288 | - return $this->theme->getMailHeaderColor(); |
|
| 289 | - } |
|
| 290 | - return $this->defaultColorPrimary; |
|
| 291 | - } |
|
| 279 | + /** |
|
| 280 | + * Returns primary color |
|
| 281 | + * @return string |
|
| 282 | + */ |
|
| 283 | + public function getColorPrimary() { |
|
| 284 | + if ($this->themeExist('getColorPrimary')) { |
|
| 285 | + return $this->theme->getColorPrimary(); |
|
| 286 | + } |
|
| 287 | + if ($this->themeExist('getMailHeaderColor')) { |
|
| 288 | + return $this->theme->getMailHeaderColor(); |
|
| 289 | + } |
|
| 290 | + return $this->defaultColorPrimary; |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * @return array scss variables to overwrite |
|
| 295 | - */ |
|
| 296 | - public function getScssVariables() { |
|
| 297 | - if ($this->themeExist('getScssVariables')) { |
|
| 298 | - return $this->theme->getScssVariables(); |
|
| 299 | - } |
|
| 300 | - return []; |
|
| 301 | - } |
|
| 293 | + /** |
|
| 294 | + * @return array scss variables to overwrite |
|
| 295 | + */ |
|
| 296 | + public function getScssVariables() { |
|
| 297 | + if ($this->themeExist('getScssVariables')) { |
|
| 298 | + return $this->theme->getScssVariables(); |
|
| 299 | + } |
|
| 300 | + return []; |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - public function shouldReplaceIcons() { |
|
| 304 | - return false; |
|
| 305 | - } |
|
| 303 | + public function shouldReplaceIcons() { |
|
| 304 | + return false; |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * Themed logo url |
|
| 309 | - * |
|
| 310 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 311 | - * @return string |
|
| 312 | - */ |
|
| 313 | - public function getLogo($useSvg = true) { |
|
| 314 | - if ($this->themeExist('getLogo')) { |
|
| 315 | - return $this->theme->getLogo($useSvg); |
|
| 316 | - } |
|
| 307 | + /** |
|
| 308 | + * Themed logo url |
|
| 309 | + * |
|
| 310 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 311 | + * @return string |
|
| 312 | + */ |
|
| 313 | + public function getLogo($useSvg = true) { |
|
| 314 | + if ($this->themeExist('getLogo')) { |
|
| 315 | + return $this->theme->getLogo($useSvg); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - if ($useSvg) { |
|
| 319 | - $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg'); |
|
| 320 | - } else { |
|
| 321 | - $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png'); |
|
| 322 | - } |
|
| 323 | - return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion())); |
|
| 324 | - } |
|
| 318 | + if ($useSvg) { |
|
| 319 | + $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg'); |
|
| 320 | + } else { |
|
| 321 | + $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png'); |
|
| 322 | + } |
|
| 323 | + return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion())); |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - public function getTextColorPrimary() { |
|
| 327 | - if ($this->themeExist('getTextColorPrimary')) { |
|
| 328 | - return $this->theme->getTextColorPrimary(); |
|
| 329 | - } |
|
| 330 | - return $this->defaultTextColorPrimary; |
|
| 331 | - } |
|
| 326 | + public function getTextColorPrimary() { |
|
| 327 | + if ($this->themeExist('getTextColorPrimary')) { |
|
| 328 | + return $this->theme->getTextColorPrimary(); |
|
| 329 | + } |
|
| 330 | + return $this->defaultTextColorPrimary; |
|
| 331 | + } |
|
| 332 | 332 | } |
@@ -77,1774 +77,1774 @@ |
||
| 77 | 77 | */ |
| 78 | 78 | class Manager implements IManager { |
| 79 | 79 | |
| 80 | - /** @var IProviderFactory */ |
|
| 81 | - private $factory; |
|
| 82 | - /** @var ILogger */ |
|
| 83 | - private $logger; |
|
| 84 | - /** @var IConfig */ |
|
| 85 | - private $config; |
|
| 86 | - /** @var ISecureRandom */ |
|
| 87 | - private $secureRandom; |
|
| 88 | - /** @var IHasher */ |
|
| 89 | - private $hasher; |
|
| 90 | - /** @var IMountManager */ |
|
| 91 | - private $mountManager; |
|
| 92 | - /** @var IGroupManager */ |
|
| 93 | - private $groupManager; |
|
| 94 | - /** @var IL10N */ |
|
| 95 | - private $l; |
|
| 96 | - /** @var IFactory */ |
|
| 97 | - private $l10nFactory; |
|
| 98 | - /** @var IUserManager */ |
|
| 99 | - private $userManager; |
|
| 100 | - /** @var IRootFolder */ |
|
| 101 | - private $rootFolder; |
|
| 102 | - /** @var CappedMemoryCache */ |
|
| 103 | - private $sharingDisabledForUsersCache; |
|
| 104 | - /** @var EventDispatcherInterface */ |
|
| 105 | - private $legacyDispatcher; |
|
| 106 | - /** @var LegacyHooks */ |
|
| 107 | - private $legacyHooks; |
|
| 108 | - /** @var IMailer */ |
|
| 109 | - private $mailer; |
|
| 110 | - /** @var IURLGenerator */ |
|
| 111 | - private $urlGenerator; |
|
| 112 | - /** @var \OC_Defaults */ |
|
| 113 | - private $defaults; |
|
| 114 | - /** @var IEventDispatcher */ |
|
| 115 | - private $dispatcher; |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Manager constructor. |
|
| 120 | - * |
|
| 121 | - * @param ILogger $logger |
|
| 122 | - * @param IConfig $config |
|
| 123 | - * @param ISecureRandom $secureRandom |
|
| 124 | - * @param IHasher $hasher |
|
| 125 | - * @param IMountManager $mountManager |
|
| 126 | - * @param IGroupManager $groupManager |
|
| 127 | - * @param IL10N $l |
|
| 128 | - * @param IFactory $l10nFactory |
|
| 129 | - * @param IProviderFactory $factory |
|
| 130 | - * @param IUserManager $userManager |
|
| 131 | - * @param IRootFolder $rootFolder |
|
| 132 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 133 | - * @param IMailer $mailer |
|
| 134 | - * @param IURLGenerator $urlGenerator |
|
| 135 | - * @param \OC_Defaults $defaults |
|
| 136 | - */ |
|
| 137 | - public function __construct( |
|
| 138 | - ILogger $logger, |
|
| 139 | - IConfig $config, |
|
| 140 | - ISecureRandom $secureRandom, |
|
| 141 | - IHasher $hasher, |
|
| 142 | - IMountManager $mountManager, |
|
| 143 | - IGroupManager $groupManager, |
|
| 144 | - IL10N $l, |
|
| 145 | - IFactory $l10nFactory, |
|
| 146 | - IProviderFactory $factory, |
|
| 147 | - IUserManager $userManager, |
|
| 148 | - IRootFolder $rootFolder, |
|
| 149 | - EventDispatcherInterface $legacyDispatcher, |
|
| 150 | - IMailer $mailer, |
|
| 151 | - IURLGenerator $urlGenerator, |
|
| 152 | - \OC_Defaults $defaults, |
|
| 153 | - IEventDispatcher $dispatcher |
|
| 154 | - ) { |
|
| 155 | - $this->logger = $logger; |
|
| 156 | - $this->config = $config; |
|
| 157 | - $this->secureRandom = $secureRandom; |
|
| 158 | - $this->hasher = $hasher; |
|
| 159 | - $this->mountManager = $mountManager; |
|
| 160 | - $this->groupManager = $groupManager; |
|
| 161 | - $this->l = $l; |
|
| 162 | - $this->l10nFactory = $l10nFactory; |
|
| 163 | - $this->factory = $factory; |
|
| 164 | - $this->userManager = $userManager; |
|
| 165 | - $this->rootFolder = $rootFolder; |
|
| 166 | - $this->legacyDispatcher = $legacyDispatcher; |
|
| 167 | - $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
| 168 | - $this->legacyHooks = new LegacyHooks($this->legacyDispatcher); |
|
| 169 | - $this->mailer = $mailer; |
|
| 170 | - $this->urlGenerator = $urlGenerator; |
|
| 171 | - $this->defaults = $defaults; |
|
| 172 | - $this->dispatcher = $dispatcher; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Convert from a full share id to a tuple (providerId, shareId) |
|
| 177 | - * |
|
| 178 | - * @param string $id |
|
| 179 | - * @return string[] |
|
| 180 | - */ |
|
| 181 | - private function splitFullId($id) { |
|
| 182 | - return explode(':', $id, 2); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Verify if a password meets all requirements |
|
| 187 | - * |
|
| 188 | - * @param string $password |
|
| 189 | - * @throws \Exception |
|
| 190 | - */ |
|
| 191 | - protected function verifyPassword($password) { |
|
| 192 | - if ($password === null) { |
|
| 193 | - // No password is set, check if this is allowed. |
|
| 194 | - if ($this->shareApiLinkEnforcePassword()) { |
|
| 195 | - throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - return; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Let others verify the password |
|
| 202 | - try { |
|
| 203 | - $this->legacyDispatcher->dispatch(new ValidatePasswordPolicyEvent($password)); |
|
| 204 | - } catch (HintException $e) { |
|
| 205 | - throw new \Exception($e->getHint()); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Check for generic requirements before creating a share |
|
| 211 | - * |
|
| 212 | - * @param \OCP\Share\IShare $share |
|
| 213 | - * @throws \InvalidArgumentException |
|
| 214 | - * @throws GenericShareException |
|
| 215 | - * |
|
| 216 | - * @suppress PhanUndeclaredClassMethod |
|
| 217 | - */ |
|
| 218 | - protected function generalCreateChecks(\OCP\Share\IShare $share) { |
|
| 219 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 220 | - // We expect a valid user as sharedWith for user shares |
|
| 221 | - if (!$this->userManager->userExists($share->getSharedWith())) { |
|
| 222 | - throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
| 223 | - } |
|
| 224 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 225 | - // We expect a valid group as sharedWith for group shares |
|
| 226 | - if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
| 227 | - throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
| 228 | - } |
|
| 229 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 230 | - if ($share->getSharedWith() !== null) { |
|
| 231 | - throw new \InvalidArgumentException('SharedWith should be empty'); |
|
| 232 | - } |
|
| 233 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 234 | - if ($share->getSharedWith() === null) { |
|
| 235 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
| 236 | - } |
|
| 237 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { |
|
| 238 | - if ($share->getSharedWith() === null) { |
|
| 239 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
| 240 | - } |
|
| 241 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 242 | - if ($share->getSharedWith() === null) { |
|
| 243 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
| 244 | - } |
|
| 245 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 246 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); |
|
| 247 | - if ($circle === null) { |
|
| 248 | - throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
| 249 | - } |
|
| 250 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_ROOM) { |
|
| 251 | - } else { |
|
| 252 | - // We can't handle other types yet |
|
| 253 | - throw new \InvalidArgumentException('unknown share type'); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - // Verify the initiator of the share is set |
|
| 257 | - if ($share->getSharedBy() === null) { |
|
| 258 | - throw new \InvalidArgumentException('SharedBy should be set'); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // Cannot share with yourself |
|
| 262 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 263 | - $share->getSharedWith() === $share->getSharedBy()) { |
|
| 264 | - throw new \InvalidArgumentException('Can’t share with yourself'); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - // The path should be set |
|
| 268 | - if ($share->getNode() === null) { |
|
| 269 | - throw new \InvalidArgumentException('Path should be set'); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - // And it should be a file or a folder |
|
| 273 | - if (!($share->getNode() instanceof \OCP\Files\File) && |
|
| 274 | - !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 275 | - throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // And you can't share your rootfolder |
|
| 279 | - if ($this->userManager->userExists($share->getSharedBy())) { |
|
| 280 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 281 | - $userFolderPath = $userFolder->getPath(); |
|
| 282 | - } else { |
|
| 283 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 284 | - $userFolderPath = $userFolder->getPath(); |
|
| 285 | - } |
|
| 286 | - if ($userFolderPath === $share->getNode()->getPath()) { |
|
| 287 | - throw new \InvalidArgumentException('You can’t share your root folder'); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - // Check if we actually have share permissions |
|
| 291 | - if (!$share->getNode()->isShareable()) { |
|
| 292 | - $path = $userFolder->getRelativePath($share->getNode()->getPath()); |
|
| 293 | - $message_t = $this->l->t('You are not allowed to share %s', [$path]); |
|
| 294 | - throw new GenericShareException($message_t, $message_t, 404); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // Permissions should be set |
|
| 298 | - if ($share->getPermissions() === null) { |
|
| 299 | - throw new \InvalidArgumentException('A share requires permissions'); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $isFederatedShare = $share->getNode()->getStorage()->instanceOfStorage('\OCA\Files_Sharing\External\Storage'); |
|
| 303 | - $permissions = 0; |
|
| 304 | - $mount = $share->getNode()->getMountPoint(); |
|
| 305 | - if (!$isFederatedShare && $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy()) { |
|
| 306 | - // When it's a reshare use the parent share permissions as maximum |
|
| 307 | - $userMountPointId = $mount->getStorageRootId(); |
|
| 308 | - $userMountPoints = $userFolder->getById($userMountPointId); |
|
| 309 | - $userMountPoint = array_shift($userMountPoints); |
|
| 310 | - |
|
| 311 | - /* Check if this is an incoming share */ |
|
| 312 | - $incomingShares = $this->getSharedWith($share->getSharedBy(), Share::SHARE_TYPE_USER, $userMountPoint, -1, 0); |
|
| 313 | - $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), Share::SHARE_TYPE_GROUP, $userMountPoint, -1, 0)); |
|
| 314 | - $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), Share::SHARE_TYPE_CIRCLE, $userMountPoint, -1, 0)); |
|
| 315 | - $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), Share::SHARE_TYPE_ROOM, $userMountPoint, -1, 0)); |
|
| 316 | - |
|
| 317 | - /** @var \OCP\Share\IShare[] $incomingShares */ |
|
| 318 | - if (!empty($incomingShares)) { |
|
| 319 | - foreach ($incomingShares as $incomingShare) { |
|
| 320 | - $permissions |= $incomingShare->getPermissions(); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - } else { |
|
| 324 | - /* |
|
| 80 | + /** @var IProviderFactory */ |
|
| 81 | + private $factory; |
|
| 82 | + /** @var ILogger */ |
|
| 83 | + private $logger; |
|
| 84 | + /** @var IConfig */ |
|
| 85 | + private $config; |
|
| 86 | + /** @var ISecureRandom */ |
|
| 87 | + private $secureRandom; |
|
| 88 | + /** @var IHasher */ |
|
| 89 | + private $hasher; |
|
| 90 | + /** @var IMountManager */ |
|
| 91 | + private $mountManager; |
|
| 92 | + /** @var IGroupManager */ |
|
| 93 | + private $groupManager; |
|
| 94 | + /** @var IL10N */ |
|
| 95 | + private $l; |
|
| 96 | + /** @var IFactory */ |
|
| 97 | + private $l10nFactory; |
|
| 98 | + /** @var IUserManager */ |
|
| 99 | + private $userManager; |
|
| 100 | + /** @var IRootFolder */ |
|
| 101 | + private $rootFolder; |
|
| 102 | + /** @var CappedMemoryCache */ |
|
| 103 | + private $sharingDisabledForUsersCache; |
|
| 104 | + /** @var EventDispatcherInterface */ |
|
| 105 | + private $legacyDispatcher; |
|
| 106 | + /** @var LegacyHooks */ |
|
| 107 | + private $legacyHooks; |
|
| 108 | + /** @var IMailer */ |
|
| 109 | + private $mailer; |
|
| 110 | + /** @var IURLGenerator */ |
|
| 111 | + private $urlGenerator; |
|
| 112 | + /** @var \OC_Defaults */ |
|
| 113 | + private $defaults; |
|
| 114 | + /** @var IEventDispatcher */ |
|
| 115 | + private $dispatcher; |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Manager constructor. |
|
| 120 | + * |
|
| 121 | + * @param ILogger $logger |
|
| 122 | + * @param IConfig $config |
|
| 123 | + * @param ISecureRandom $secureRandom |
|
| 124 | + * @param IHasher $hasher |
|
| 125 | + * @param IMountManager $mountManager |
|
| 126 | + * @param IGroupManager $groupManager |
|
| 127 | + * @param IL10N $l |
|
| 128 | + * @param IFactory $l10nFactory |
|
| 129 | + * @param IProviderFactory $factory |
|
| 130 | + * @param IUserManager $userManager |
|
| 131 | + * @param IRootFolder $rootFolder |
|
| 132 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 133 | + * @param IMailer $mailer |
|
| 134 | + * @param IURLGenerator $urlGenerator |
|
| 135 | + * @param \OC_Defaults $defaults |
|
| 136 | + */ |
|
| 137 | + public function __construct( |
|
| 138 | + ILogger $logger, |
|
| 139 | + IConfig $config, |
|
| 140 | + ISecureRandom $secureRandom, |
|
| 141 | + IHasher $hasher, |
|
| 142 | + IMountManager $mountManager, |
|
| 143 | + IGroupManager $groupManager, |
|
| 144 | + IL10N $l, |
|
| 145 | + IFactory $l10nFactory, |
|
| 146 | + IProviderFactory $factory, |
|
| 147 | + IUserManager $userManager, |
|
| 148 | + IRootFolder $rootFolder, |
|
| 149 | + EventDispatcherInterface $legacyDispatcher, |
|
| 150 | + IMailer $mailer, |
|
| 151 | + IURLGenerator $urlGenerator, |
|
| 152 | + \OC_Defaults $defaults, |
|
| 153 | + IEventDispatcher $dispatcher |
|
| 154 | + ) { |
|
| 155 | + $this->logger = $logger; |
|
| 156 | + $this->config = $config; |
|
| 157 | + $this->secureRandom = $secureRandom; |
|
| 158 | + $this->hasher = $hasher; |
|
| 159 | + $this->mountManager = $mountManager; |
|
| 160 | + $this->groupManager = $groupManager; |
|
| 161 | + $this->l = $l; |
|
| 162 | + $this->l10nFactory = $l10nFactory; |
|
| 163 | + $this->factory = $factory; |
|
| 164 | + $this->userManager = $userManager; |
|
| 165 | + $this->rootFolder = $rootFolder; |
|
| 166 | + $this->legacyDispatcher = $legacyDispatcher; |
|
| 167 | + $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
| 168 | + $this->legacyHooks = new LegacyHooks($this->legacyDispatcher); |
|
| 169 | + $this->mailer = $mailer; |
|
| 170 | + $this->urlGenerator = $urlGenerator; |
|
| 171 | + $this->defaults = $defaults; |
|
| 172 | + $this->dispatcher = $dispatcher; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Convert from a full share id to a tuple (providerId, shareId) |
|
| 177 | + * |
|
| 178 | + * @param string $id |
|
| 179 | + * @return string[] |
|
| 180 | + */ |
|
| 181 | + private function splitFullId($id) { |
|
| 182 | + return explode(':', $id, 2); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Verify if a password meets all requirements |
|
| 187 | + * |
|
| 188 | + * @param string $password |
|
| 189 | + * @throws \Exception |
|
| 190 | + */ |
|
| 191 | + protected function verifyPassword($password) { |
|
| 192 | + if ($password === null) { |
|
| 193 | + // No password is set, check if this is allowed. |
|
| 194 | + if ($this->shareApiLinkEnforcePassword()) { |
|
| 195 | + throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + return; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Let others verify the password |
|
| 202 | + try { |
|
| 203 | + $this->legacyDispatcher->dispatch(new ValidatePasswordPolicyEvent($password)); |
|
| 204 | + } catch (HintException $e) { |
|
| 205 | + throw new \Exception($e->getHint()); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Check for generic requirements before creating a share |
|
| 211 | + * |
|
| 212 | + * @param \OCP\Share\IShare $share |
|
| 213 | + * @throws \InvalidArgumentException |
|
| 214 | + * @throws GenericShareException |
|
| 215 | + * |
|
| 216 | + * @suppress PhanUndeclaredClassMethod |
|
| 217 | + */ |
|
| 218 | + protected function generalCreateChecks(\OCP\Share\IShare $share) { |
|
| 219 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 220 | + // We expect a valid user as sharedWith for user shares |
|
| 221 | + if (!$this->userManager->userExists($share->getSharedWith())) { |
|
| 222 | + throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
| 223 | + } |
|
| 224 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 225 | + // We expect a valid group as sharedWith for group shares |
|
| 226 | + if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
| 227 | + throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
| 228 | + } |
|
| 229 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 230 | + if ($share->getSharedWith() !== null) { |
|
| 231 | + throw new \InvalidArgumentException('SharedWith should be empty'); |
|
| 232 | + } |
|
| 233 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 234 | + if ($share->getSharedWith() === null) { |
|
| 235 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
| 236 | + } |
|
| 237 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { |
|
| 238 | + if ($share->getSharedWith() === null) { |
|
| 239 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
| 240 | + } |
|
| 241 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 242 | + if ($share->getSharedWith() === null) { |
|
| 243 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
| 244 | + } |
|
| 245 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 246 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); |
|
| 247 | + if ($circle === null) { |
|
| 248 | + throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
| 249 | + } |
|
| 250 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_ROOM) { |
|
| 251 | + } else { |
|
| 252 | + // We can't handle other types yet |
|
| 253 | + throw new \InvalidArgumentException('unknown share type'); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + // Verify the initiator of the share is set |
|
| 257 | + if ($share->getSharedBy() === null) { |
|
| 258 | + throw new \InvalidArgumentException('SharedBy should be set'); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // Cannot share with yourself |
|
| 262 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 263 | + $share->getSharedWith() === $share->getSharedBy()) { |
|
| 264 | + throw new \InvalidArgumentException('Can’t share with yourself'); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // The path should be set |
|
| 268 | + if ($share->getNode() === null) { |
|
| 269 | + throw new \InvalidArgumentException('Path should be set'); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + // And it should be a file or a folder |
|
| 273 | + if (!($share->getNode() instanceof \OCP\Files\File) && |
|
| 274 | + !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 275 | + throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // And you can't share your rootfolder |
|
| 279 | + if ($this->userManager->userExists($share->getSharedBy())) { |
|
| 280 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 281 | + $userFolderPath = $userFolder->getPath(); |
|
| 282 | + } else { |
|
| 283 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 284 | + $userFolderPath = $userFolder->getPath(); |
|
| 285 | + } |
|
| 286 | + if ($userFolderPath === $share->getNode()->getPath()) { |
|
| 287 | + throw new \InvalidArgumentException('You can’t share your root folder'); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + // Check if we actually have share permissions |
|
| 291 | + if (!$share->getNode()->isShareable()) { |
|
| 292 | + $path = $userFolder->getRelativePath($share->getNode()->getPath()); |
|
| 293 | + $message_t = $this->l->t('You are not allowed to share %s', [$path]); |
|
| 294 | + throw new GenericShareException($message_t, $message_t, 404); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // Permissions should be set |
|
| 298 | + if ($share->getPermissions() === null) { |
|
| 299 | + throw new \InvalidArgumentException('A share requires permissions'); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $isFederatedShare = $share->getNode()->getStorage()->instanceOfStorage('\OCA\Files_Sharing\External\Storage'); |
|
| 303 | + $permissions = 0; |
|
| 304 | + $mount = $share->getNode()->getMountPoint(); |
|
| 305 | + if (!$isFederatedShare && $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy()) { |
|
| 306 | + // When it's a reshare use the parent share permissions as maximum |
|
| 307 | + $userMountPointId = $mount->getStorageRootId(); |
|
| 308 | + $userMountPoints = $userFolder->getById($userMountPointId); |
|
| 309 | + $userMountPoint = array_shift($userMountPoints); |
|
| 310 | + |
|
| 311 | + /* Check if this is an incoming share */ |
|
| 312 | + $incomingShares = $this->getSharedWith($share->getSharedBy(), Share::SHARE_TYPE_USER, $userMountPoint, -1, 0); |
|
| 313 | + $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), Share::SHARE_TYPE_GROUP, $userMountPoint, -1, 0)); |
|
| 314 | + $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), Share::SHARE_TYPE_CIRCLE, $userMountPoint, -1, 0)); |
|
| 315 | + $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), Share::SHARE_TYPE_ROOM, $userMountPoint, -1, 0)); |
|
| 316 | + |
|
| 317 | + /** @var \OCP\Share\IShare[] $incomingShares */ |
|
| 318 | + if (!empty($incomingShares)) { |
|
| 319 | + foreach ($incomingShares as $incomingShare) { |
|
| 320 | + $permissions |= $incomingShare->getPermissions(); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + } else { |
|
| 324 | + /* |
|
| 325 | 325 | * Quick fix for #23536 |
| 326 | 326 | * Non moveable mount points do not have update and delete permissions |
| 327 | 327 | * while we 'most likely' do have that on the storage. |
| 328 | 328 | */ |
| 329 | - $permissions = $share->getNode()->getPermissions(); |
|
| 330 | - if (!($mount instanceof MoveableMount)) { |
|
| 331 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // Check that we do not share with more permissions than we have |
|
| 336 | - if ($share->getPermissions() & ~$permissions) { |
|
| 337 | - $path = $userFolder->getRelativePath($share->getNode()->getPath()); |
|
| 338 | - $message_t = $this->l->t('Can’t increase permissions of %s', [$path]); |
|
| 339 | - throw new GenericShareException($message_t, $message_t, 404); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - // Check that read permissions are always set |
|
| 344 | - // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
| 345 | - $noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
| 346 | - || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL; |
|
| 347 | - if (!$noReadPermissionRequired && |
|
| 348 | - ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
| 349 | - throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
| 353 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
| 354 | - $message_t = $this->l->t('Files can’t be shared with delete permissions'); |
|
| 355 | - throw new GenericShareException($message_t); |
|
| 356 | - } |
|
| 357 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
| 358 | - $message_t = $this->l->t('Files can’t be shared with create permissions'); |
|
| 359 | - throw new GenericShareException($message_t); |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Validate if the expiration date fits the system settings |
|
| 366 | - * |
|
| 367 | - * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
| 368 | - * @return \OCP\Share\IShare The modified share object |
|
| 369 | - * @throws GenericShareException |
|
| 370 | - * @throws \InvalidArgumentException |
|
| 371 | - * @throws \Exception |
|
| 372 | - */ |
|
| 373 | - protected function validateExpirationDateInternal(\OCP\Share\IShare $share) { |
|
| 374 | - $expirationDate = $share->getExpirationDate(); |
|
| 375 | - |
|
| 376 | - if ($expirationDate !== null) { |
|
| 377 | - //Make sure the expiration date is a date |
|
| 378 | - $expirationDate->setTime(0, 0, 0); |
|
| 379 | - |
|
| 380 | - $date = new \DateTime(); |
|
| 381 | - $date->setTime(0, 0, 0); |
|
| 382 | - if ($date >= $expirationDate) { |
|
| 383 | - $message = $this->l->t('Expiration date is in the past'); |
|
| 384 | - throw new GenericShareException($message, $message, 404); |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - // If expiredate is empty set a default one if there is a default |
|
| 389 | - $fullId = null; |
|
| 390 | - try { |
|
| 391 | - $fullId = $share->getFullId(); |
|
| 392 | - } catch (\UnexpectedValueException $e) { |
|
| 393 | - // This is a new share |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if ($fullId === null && $expirationDate === null && $this->shareApiInternalDefaultExpireDate()) { |
|
| 397 | - $expirationDate = new \DateTime(); |
|
| 398 | - $expirationDate->setTime(0,0,0); |
|
| 399 | - $expirationDate->add(new \DateInterval('P'.$this->shareApiInternalDefaultExpireDays().'D')); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - // If we enforce the expiration date check that is does not exceed |
|
| 403 | - if ($this->shareApiInternalDefaultExpireDateEnforced()) { |
|
| 404 | - if ($expirationDate === null) { |
|
| 405 | - throw new \InvalidArgumentException('Expiration date is enforced'); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - $date = new \DateTime(); |
|
| 409 | - $date->setTime(0, 0, 0); |
|
| 410 | - $date->add(new \DateInterval('P' . $this->shareApiInternalDefaultExpireDays() . 'D')); |
|
| 411 | - if ($date < $expirationDate) { |
|
| 412 | - $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiInternalDefaultExpireDays()]); |
|
| 413 | - throw new GenericShareException($message, $message, 404); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $accepted = true; |
|
| 418 | - $message = ''; |
|
| 419 | - \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
| 420 | - 'expirationDate' => &$expirationDate, |
|
| 421 | - 'accepted' => &$accepted, |
|
| 422 | - 'message' => &$message, |
|
| 423 | - 'passwordSet' => $share->getPassword() !== null, |
|
| 424 | - ]); |
|
| 425 | - |
|
| 426 | - if (!$accepted) { |
|
| 427 | - throw new \Exception($message); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - $share->setExpirationDate($expirationDate); |
|
| 431 | - |
|
| 432 | - return $share; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Validate if the expiration date fits the system settings |
|
| 437 | - * |
|
| 438 | - * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
| 439 | - * @return \OCP\Share\IShare The modified share object |
|
| 440 | - * @throws GenericShareException |
|
| 441 | - * @throws \InvalidArgumentException |
|
| 442 | - * @throws \Exception |
|
| 443 | - */ |
|
| 444 | - protected function validateExpirationDate(\OCP\Share\IShare $share) { |
|
| 445 | - $expirationDate = $share->getExpirationDate(); |
|
| 446 | - |
|
| 447 | - if ($expirationDate !== null) { |
|
| 448 | - //Make sure the expiration date is a date |
|
| 449 | - $expirationDate->setTime(0, 0, 0); |
|
| 450 | - |
|
| 451 | - $date = new \DateTime(); |
|
| 452 | - $date->setTime(0, 0, 0); |
|
| 453 | - if ($date >= $expirationDate) { |
|
| 454 | - $message = $this->l->t('Expiration date is in the past'); |
|
| 455 | - throw new GenericShareException($message, $message, 404); |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - // If expiredate is empty set a default one if there is a default |
|
| 460 | - $fullId = null; |
|
| 461 | - try { |
|
| 462 | - $fullId = $share->getFullId(); |
|
| 463 | - } catch (\UnexpectedValueException $e) { |
|
| 464 | - // This is a new share |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
| 468 | - $expirationDate = new \DateTime(); |
|
| 469 | - $expirationDate->setTime(0,0,0); |
|
| 470 | - $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - // If we enforce the expiration date check that is does not exceed |
|
| 474 | - if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
| 475 | - if ($expirationDate === null) { |
|
| 476 | - throw new \InvalidArgumentException('Expiration date is enforced'); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - $date = new \DateTime(); |
|
| 480 | - $date->setTime(0, 0, 0); |
|
| 481 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
| 482 | - if ($date < $expirationDate) { |
|
| 483 | - $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
|
| 484 | - throw new GenericShareException($message, $message, 404); |
|
| 485 | - } |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - $accepted = true; |
|
| 489 | - $message = ''; |
|
| 490 | - \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
| 491 | - 'expirationDate' => &$expirationDate, |
|
| 492 | - 'accepted' => &$accepted, |
|
| 493 | - 'message' => &$message, |
|
| 494 | - 'passwordSet' => $share->getPassword() !== null, |
|
| 495 | - ]); |
|
| 496 | - |
|
| 497 | - if (!$accepted) { |
|
| 498 | - throw new \Exception($message); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - $share->setExpirationDate($expirationDate); |
|
| 502 | - |
|
| 503 | - return $share; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Check for pre share requirements for user shares |
|
| 508 | - * |
|
| 509 | - * @param \OCP\Share\IShare $share |
|
| 510 | - * @throws \Exception |
|
| 511 | - */ |
|
| 512 | - protected function userCreateChecks(\OCP\Share\IShare $share) { |
|
| 513 | - // Check if we can share with group members only |
|
| 514 | - if ($this->shareWithGroupMembersOnly()) { |
|
| 515 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 516 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 517 | - // Verify we can share with this user |
|
| 518 | - $groups = array_intersect( |
|
| 519 | - $this->groupManager->getUserGroupIds($sharedBy), |
|
| 520 | - $this->groupManager->getUserGroupIds($sharedWith) |
|
| 521 | - ); |
|
| 522 | - if (empty($groups)) { |
|
| 523 | - throw new \Exception('Sharing is only allowed with group members'); |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - /* |
|
| 329 | + $permissions = $share->getNode()->getPermissions(); |
|
| 330 | + if (!($mount instanceof MoveableMount)) { |
|
| 331 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // Check that we do not share with more permissions than we have |
|
| 336 | + if ($share->getPermissions() & ~$permissions) { |
|
| 337 | + $path = $userFolder->getRelativePath($share->getNode()->getPath()); |
|
| 338 | + $message_t = $this->l->t('Can’t increase permissions of %s', [$path]); |
|
| 339 | + throw new GenericShareException($message_t, $message_t, 404); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + // Check that read permissions are always set |
|
| 344 | + // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
| 345 | + $noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
| 346 | + || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL; |
|
| 347 | + if (!$noReadPermissionRequired && |
|
| 348 | + ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
| 349 | + throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
| 353 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
| 354 | + $message_t = $this->l->t('Files can’t be shared with delete permissions'); |
|
| 355 | + throw new GenericShareException($message_t); |
|
| 356 | + } |
|
| 357 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
| 358 | + $message_t = $this->l->t('Files can’t be shared with create permissions'); |
|
| 359 | + throw new GenericShareException($message_t); |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Validate if the expiration date fits the system settings |
|
| 366 | + * |
|
| 367 | + * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
| 368 | + * @return \OCP\Share\IShare The modified share object |
|
| 369 | + * @throws GenericShareException |
|
| 370 | + * @throws \InvalidArgumentException |
|
| 371 | + * @throws \Exception |
|
| 372 | + */ |
|
| 373 | + protected function validateExpirationDateInternal(\OCP\Share\IShare $share) { |
|
| 374 | + $expirationDate = $share->getExpirationDate(); |
|
| 375 | + |
|
| 376 | + if ($expirationDate !== null) { |
|
| 377 | + //Make sure the expiration date is a date |
|
| 378 | + $expirationDate->setTime(0, 0, 0); |
|
| 379 | + |
|
| 380 | + $date = new \DateTime(); |
|
| 381 | + $date->setTime(0, 0, 0); |
|
| 382 | + if ($date >= $expirationDate) { |
|
| 383 | + $message = $this->l->t('Expiration date is in the past'); |
|
| 384 | + throw new GenericShareException($message, $message, 404); |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + // If expiredate is empty set a default one if there is a default |
|
| 389 | + $fullId = null; |
|
| 390 | + try { |
|
| 391 | + $fullId = $share->getFullId(); |
|
| 392 | + } catch (\UnexpectedValueException $e) { |
|
| 393 | + // This is a new share |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if ($fullId === null && $expirationDate === null && $this->shareApiInternalDefaultExpireDate()) { |
|
| 397 | + $expirationDate = new \DateTime(); |
|
| 398 | + $expirationDate->setTime(0,0,0); |
|
| 399 | + $expirationDate->add(new \DateInterval('P'.$this->shareApiInternalDefaultExpireDays().'D')); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + // If we enforce the expiration date check that is does not exceed |
|
| 403 | + if ($this->shareApiInternalDefaultExpireDateEnforced()) { |
|
| 404 | + if ($expirationDate === null) { |
|
| 405 | + throw new \InvalidArgumentException('Expiration date is enforced'); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + $date = new \DateTime(); |
|
| 409 | + $date->setTime(0, 0, 0); |
|
| 410 | + $date->add(new \DateInterval('P' . $this->shareApiInternalDefaultExpireDays() . 'D')); |
|
| 411 | + if ($date < $expirationDate) { |
|
| 412 | + $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiInternalDefaultExpireDays()]); |
|
| 413 | + throw new GenericShareException($message, $message, 404); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $accepted = true; |
|
| 418 | + $message = ''; |
|
| 419 | + \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
| 420 | + 'expirationDate' => &$expirationDate, |
|
| 421 | + 'accepted' => &$accepted, |
|
| 422 | + 'message' => &$message, |
|
| 423 | + 'passwordSet' => $share->getPassword() !== null, |
|
| 424 | + ]); |
|
| 425 | + |
|
| 426 | + if (!$accepted) { |
|
| 427 | + throw new \Exception($message); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + $share->setExpirationDate($expirationDate); |
|
| 431 | + |
|
| 432 | + return $share; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Validate if the expiration date fits the system settings |
|
| 437 | + * |
|
| 438 | + * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
| 439 | + * @return \OCP\Share\IShare The modified share object |
|
| 440 | + * @throws GenericShareException |
|
| 441 | + * @throws \InvalidArgumentException |
|
| 442 | + * @throws \Exception |
|
| 443 | + */ |
|
| 444 | + protected function validateExpirationDate(\OCP\Share\IShare $share) { |
|
| 445 | + $expirationDate = $share->getExpirationDate(); |
|
| 446 | + |
|
| 447 | + if ($expirationDate !== null) { |
|
| 448 | + //Make sure the expiration date is a date |
|
| 449 | + $expirationDate->setTime(0, 0, 0); |
|
| 450 | + |
|
| 451 | + $date = new \DateTime(); |
|
| 452 | + $date->setTime(0, 0, 0); |
|
| 453 | + if ($date >= $expirationDate) { |
|
| 454 | + $message = $this->l->t('Expiration date is in the past'); |
|
| 455 | + throw new GenericShareException($message, $message, 404); |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + // If expiredate is empty set a default one if there is a default |
|
| 460 | + $fullId = null; |
|
| 461 | + try { |
|
| 462 | + $fullId = $share->getFullId(); |
|
| 463 | + } catch (\UnexpectedValueException $e) { |
|
| 464 | + // This is a new share |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
| 468 | + $expirationDate = new \DateTime(); |
|
| 469 | + $expirationDate->setTime(0,0,0); |
|
| 470 | + $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + // If we enforce the expiration date check that is does not exceed |
|
| 474 | + if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
| 475 | + if ($expirationDate === null) { |
|
| 476 | + throw new \InvalidArgumentException('Expiration date is enforced'); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + $date = new \DateTime(); |
|
| 480 | + $date->setTime(0, 0, 0); |
|
| 481 | + $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
| 482 | + if ($date < $expirationDate) { |
|
| 483 | + $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
|
| 484 | + throw new GenericShareException($message, $message, 404); |
|
| 485 | + } |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + $accepted = true; |
|
| 489 | + $message = ''; |
|
| 490 | + \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
| 491 | + 'expirationDate' => &$expirationDate, |
|
| 492 | + 'accepted' => &$accepted, |
|
| 493 | + 'message' => &$message, |
|
| 494 | + 'passwordSet' => $share->getPassword() !== null, |
|
| 495 | + ]); |
|
| 496 | + |
|
| 497 | + if (!$accepted) { |
|
| 498 | + throw new \Exception($message); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + $share->setExpirationDate($expirationDate); |
|
| 502 | + |
|
| 503 | + return $share; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Check for pre share requirements for user shares |
|
| 508 | + * |
|
| 509 | + * @param \OCP\Share\IShare $share |
|
| 510 | + * @throws \Exception |
|
| 511 | + */ |
|
| 512 | + protected function userCreateChecks(\OCP\Share\IShare $share) { |
|
| 513 | + // Check if we can share with group members only |
|
| 514 | + if ($this->shareWithGroupMembersOnly()) { |
|
| 515 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 516 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 517 | + // Verify we can share with this user |
|
| 518 | + $groups = array_intersect( |
|
| 519 | + $this->groupManager->getUserGroupIds($sharedBy), |
|
| 520 | + $this->groupManager->getUserGroupIds($sharedWith) |
|
| 521 | + ); |
|
| 522 | + if (empty($groups)) { |
|
| 523 | + throw new \Exception('Sharing is only allowed with group members'); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + /* |
|
| 528 | 528 | * TODO: Could be costly, fix |
| 529 | 529 | * |
| 530 | 530 | * Also this is not what we want in the future.. then we want to squash identical shares. |
| 531 | 531 | */ |
| 532 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
|
| 533 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 534 | - foreach ($existingShares as $existingShare) { |
|
| 535 | - // Ignore if it is the same share |
|
| 536 | - try { |
|
| 537 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 538 | - continue; |
|
| 539 | - } |
|
| 540 | - } catch (\UnexpectedValueException $e) { |
|
| 541 | - //Shares are not identical |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // Identical share already existst |
|
| 545 | - if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
| 546 | - throw new \Exception('Path is already shared with this user'); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - // The share is already shared with this user via a group share |
|
| 550 | - if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 551 | - $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
| 552 | - if (!is_null($group)) { |
|
| 553 | - $user = $this->userManager->get($share->getSharedWith()); |
|
| 554 | - |
|
| 555 | - if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
| 556 | - throw new \Exception('Path is already shared with this user'); |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Check for pre share requirements for group shares |
|
| 565 | - * |
|
| 566 | - * @param \OCP\Share\IShare $share |
|
| 567 | - * @throws \Exception |
|
| 568 | - */ |
|
| 569 | - protected function groupCreateChecks(\OCP\Share\IShare $share) { |
|
| 570 | - // Verify group shares are allowed |
|
| 571 | - if (!$this->allowGroupSharing()) { |
|
| 572 | - throw new \Exception('Group sharing is now allowed'); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - // Verify if the user can share with this group |
|
| 576 | - if ($this->shareWithGroupMembersOnly()) { |
|
| 577 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 578 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 579 | - if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
| 580 | - throw new \Exception('Sharing is only allowed within your own groups'); |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - /* |
|
| 532 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
|
| 533 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 534 | + foreach ($existingShares as $existingShare) { |
|
| 535 | + // Ignore if it is the same share |
|
| 536 | + try { |
|
| 537 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 538 | + continue; |
|
| 539 | + } |
|
| 540 | + } catch (\UnexpectedValueException $e) { |
|
| 541 | + //Shares are not identical |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // Identical share already existst |
|
| 545 | + if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
| 546 | + throw new \Exception('Path is already shared with this user'); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + // The share is already shared with this user via a group share |
|
| 550 | + if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 551 | + $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
| 552 | + if (!is_null($group)) { |
|
| 553 | + $user = $this->userManager->get($share->getSharedWith()); |
|
| 554 | + |
|
| 555 | + if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
| 556 | + throw new \Exception('Path is already shared with this user'); |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Check for pre share requirements for group shares |
|
| 565 | + * |
|
| 566 | + * @param \OCP\Share\IShare $share |
|
| 567 | + * @throws \Exception |
|
| 568 | + */ |
|
| 569 | + protected function groupCreateChecks(\OCP\Share\IShare $share) { |
|
| 570 | + // Verify group shares are allowed |
|
| 571 | + if (!$this->allowGroupSharing()) { |
|
| 572 | + throw new \Exception('Group sharing is now allowed'); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + // Verify if the user can share with this group |
|
| 576 | + if ($this->shareWithGroupMembersOnly()) { |
|
| 577 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 578 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 579 | + if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
| 580 | + throw new \Exception('Sharing is only allowed within your own groups'); |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + /* |
|
| 585 | 585 | * TODO: Could be costly, fix |
| 586 | 586 | * |
| 587 | 587 | * Also this is not what we want in the future.. then we want to squash identical shares. |
| 588 | 588 | */ |
| 589 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 590 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 591 | - foreach ($existingShares as $existingShare) { |
|
| 592 | - try { |
|
| 593 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 594 | - continue; |
|
| 595 | - } |
|
| 596 | - } catch (\UnexpectedValueException $e) { |
|
| 597 | - //It is a new share so just continue |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
| 601 | - throw new \Exception('Path is already shared with this group'); |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * Check for pre share requirements for link shares |
|
| 608 | - * |
|
| 609 | - * @param \OCP\Share\IShare $share |
|
| 610 | - * @throws \Exception |
|
| 611 | - */ |
|
| 612 | - protected function linkCreateChecks(\OCP\Share\IShare $share) { |
|
| 613 | - // Are link shares allowed? |
|
| 614 | - if (!$this->shareApiAllowLinks()) { |
|
| 615 | - throw new \Exception('Link sharing is not allowed'); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - // Link shares by definition can't have share permissions |
|
| 619 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
|
| 620 | - throw new \InvalidArgumentException('Link shares can’t have reshare permissions'); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // Check if public upload is allowed |
|
| 624 | - if (!$this->shareApiLinkAllowPublicUpload() && |
|
| 625 | - ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
| 626 | - throw new \InvalidArgumentException('Public upload is not allowed'); |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * To make sure we don't get invisible link shares we set the parent |
|
| 632 | - * of a link if it is a reshare. This is a quick word around |
|
| 633 | - * until we can properly display multiple link shares in the UI |
|
| 634 | - * |
|
| 635 | - * See: https://github.com/owncloud/core/issues/22295 |
|
| 636 | - * |
|
| 637 | - * FIXME: Remove once multiple link shares can be properly displayed |
|
| 638 | - * |
|
| 639 | - * @param \OCP\Share\IShare $share |
|
| 640 | - */ |
|
| 641 | - protected function setLinkParent(\OCP\Share\IShare $share) { |
|
| 642 | - |
|
| 643 | - // No sense in checking if the method is not there. |
|
| 644 | - if (method_exists($share, 'setParent')) { |
|
| 645 | - $storage = $share->getNode()->getStorage(); |
|
| 646 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
| 647 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 648 | - $share->setParent($storage->getShareId()); |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * @param File|Folder $path |
|
| 655 | - */ |
|
| 656 | - protected function pathCreateChecks($path) { |
|
| 657 | - // Make sure that we do not share a path that contains a shared mountpoint |
|
| 658 | - if ($path instanceof \OCP\Files\Folder) { |
|
| 659 | - $mounts = $this->mountManager->findIn($path->getPath()); |
|
| 660 | - foreach ($mounts as $mount) { |
|
| 661 | - if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
| 662 | - throw new \InvalidArgumentException('Path contains files shared with you'); |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * Check if the user that is sharing can actually share |
|
| 670 | - * |
|
| 671 | - * @param \OCP\Share\IShare $share |
|
| 672 | - * @throws \Exception |
|
| 673 | - */ |
|
| 674 | - protected function canShare(\OCP\Share\IShare $share) { |
|
| 675 | - if (!$this->shareApiEnabled()) { |
|
| 676 | - throw new \Exception('Sharing is disabled'); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
| 680 | - throw new \Exception('Sharing is disabled for you'); |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * Share a path |
|
| 686 | - * |
|
| 687 | - * @param \OCP\Share\IShare $share |
|
| 688 | - * @return Share The share object |
|
| 689 | - * @throws \Exception |
|
| 690 | - * |
|
| 691 | - * TODO: handle link share permissions or check them |
|
| 692 | - */ |
|
| 693 | - public function createShare(\OCP\Share\IShare $share) { |
|
| 694 | - $this->canShare($share); |
|
| 695 | - |
|
| 696 | - $this->generalCreateChecks($share); |
|
| 697 | - |
|
| 698 | - // Verify if there are any issues with the path |
|
| 699 | - $this->pathCreateChecks($share->getNode()); |
|
| 700 | - |
|
| 701 | - /* |
|
| 589 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 590 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 591 | + foreach ($existingShares as $existingShare) { |
|
| 592 | + try { |
|
| 593 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 594 | + continue; |
|
| 595 | + } |
|
| 596 | + } catch (\UnexpectedValueException $e) { |
|
| 597 | + //It is a new share so just continue |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
| 601 | + throw new \Exception('Path is already shared with this group'); |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * Check for pre share requirements for link shares |
|
| 608 | + * |
|
| 609 | + * @param \OCP\Share\IShare $share |
|
| 610 | + * @throws \Exception |
|
| 611 | + */ |
|
| 612 | + protected function linkCreateChecks(\OCP\Share\IShare $share) { |
|
| 613 | + // Are link shares allowed? |
|
| 614 | + if (!$this->shareApiAllowLinks()) { |
|
| 615 | + throw new \Exception('Link sharing is not allowed'); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + // Link shares by definition can't have share permissions |
|
| 619 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
|
| 620 | + throw new \InvalidArgumentException('Link shares can’t have reshare permissions'); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // Check if public upload is allowed |
|
| 624 | + if (!$this->shareApiLinkAllowPublicUpload() && |
|
| 625 | + ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
| 626 | + throw new \InvalidArgumentException('Public upload is not allowed'); |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * To make sure we don't get invisible link shares we set the parent |
|
| 632 | + * of a link if it is a reshare. This is a quick word around |
|
| 633 | + * until we can properly display multiple link shares in the UI |
|
| 634 | + * |
|
| 635 | + * See: https://github.com/owncloud/core/issues/22295 |
|
| 636 | + * |
|
| 637 | + * FIXME: Remove once multiple link shares can be properly displayed |
|
| 638 | + * |
|
| 639 | + * @param \OCP\Share\IShare $share |
|
| 640 | + */ |
|
| 641 | + protected function setLinkParent(\OCP\Share\IShare $share) { |
|
| 642 | + |
|
| 643 | + // No sense in checking if the method is not there. |
|
| 644 | + if (method_exists($share, 'setParent')) { |
|
| 645 | + $storage = $share->getNode()->getStorage(); |
|
| 646 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
| 647 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 648 | + $share->setParent($storage->getShareId()); |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * @param File|Folder $path |
|
| 655 | + */ |
|
| 656 | + protected function pathCreateChecks($path) { |
|
| 657 | + // Make sure that we do not share a path that contains a shared mountpoint |
|
| 658 | + if ($path instanceof \OCP\Files\Folder) { |
|
| 659 | + $mounts = $this->mountManager->findIn($path->getPath()); |
|
| 660 | + foreach ($mounts as $mount) { |
|
| 661 | + if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
| 662 | + throw new \InvalidArgumentException('Path contains files shared with you'); |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * Check if the user that is sharing can actually share |
|
| 670 | + * |
|
| 671 | + * @param \OCP\Share\IShare $share |
|
| 672 | + * @throws \Exception |
|
| 673 | + */ |
|
| 674 | + protected function canShare(\OCP\Share\IShare $share) { |
|
| 675 | + if (!$this->shareApiEnabled()) { |
|
| 676 | + throw new \Exception('Sharing is disabled'); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
| 680 | + throw new \Exception('Sharing is disabled for you'); |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * Share a path |
|
| 686 | + * |
|
| 687 | + * @param \OCP\Share\IShare $share |
|
| 688 | + * @return Share The share object |
|
| 689 | + * @throws \Exception |
|
| 690 | + * |
|
| 691 | + * TODO: handle link share permissions or check them |
|
| 692 | + */ |
|
| 693 | + public function createShare(\OCP\Share\IShare $share) { |
|
| 694 | + $this->canShare($share); |
|
| 695 | + |
|
| 696 | + $this->generalCreateChecks($share); |
|
| 697 | + |
|
| 698 | + // Verify if there are any issues with the path |
|
| 699 | + $this->pathCreateChecks($share->getNode()); |
|
| 700 | + |
|
| 701 | + /* |
|
| 702 | 702 | * On creation of a share the owner is always the owner of the path |
| 703 | 703 | * Except for mounted federated shares. |
| 704 | 704 | */ |
| 705 | - $storage = $share->getNode()->getStorage(); |
|
| 706 | - if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 707 | - $parent = $share->getNode()->getParent(); |
|
| 708 | - while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 709 | - $parent = $parent->getParent(); |
|
| 710 | - } |
|
| 711 | - $share->setShareOwner($parent->getOwner()->getUID()); |
|
| 712 | - } else { |
|
| 713 | - if ($share->getNode()->getOwner()) { |
|
| 714 | - $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
| 715 | - } else { |
|
| 716 | - $share->setShareOwner($share->getSharedBy()); |
|
| 717 | - } |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - //Verify share type |
|
| 721 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 722 | - $this->userCreateChecks($share); |
|
| 723 | - |
|
| 724 | - //Verify the expiration date |
|
| 725 | - $share = $this->validateExpirationDateInternal($share); |
|
| 726 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 727 | - $this->groupCreateChecks($share); |
|
| 728 | - |
|
| 729 | - //Verify the expiration date |
|
| 730 | - $share = $this->validateExpirationDateInternal($share); |
|
| 731 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 732 | - $this->linkCreateChecks($share); |
|
| 733 | - $this->setLinkParent($share); |
|
| 734 | - |
|
| 735 | - /* |
|
| 705 | + $storage = $share->getNode()->getStorage(); |
|
| 706 | + if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 707 | + $parent = $share->getNode()->getParent(); |
|
| 708 | + while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 709 | + $parent = $parent->getParent(); |
|
| 710 | + } |
|
| 711 | + $share->setShareOwner($parent->getOwner()->getUID()); |
|
| 712 | + } else { |
|
| 713 | + if ($share->getNode()->getOwner()) { |
|
| 714 | + $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
| 715 | + } else { |
|
| 716 | + $share->setShareOwner($share->getSharedBy()); |
|
| 717 | + } |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + //Verify share type |
|
| 721 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 722 | + $this->userCreateChecks($share); |
|
| 723 | + |
|
| 724 | + //Verify the expiration date |
|
| 725 | + $share = $this->validateExpirationDateInternal($share); |
|
| 726 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 727 | + $this->groupCreateChecks($share); |
|
| 728 | + |
|
| 729 | + //Verify the expiration date |
|
| 730 | + $share = $this->validateExpirationDateInternal($share); |
|
| 731 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 732 | + $this->linkCreateChecks($share); |
|
| 733 | + $this->setLinkParent($share); |
|
| 734 | + |
|
| 735 | + /* |
|
| 736 | 736 | * For now ignore a set token. |
| 737 | 737 | */ |
| 738 | - $share->setToken( |
|
| 739 | - $this->secureRandom->generate( |
|
| 740 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
| 741 | - \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
| 742 | - ) |
|
| 743 | - ); |
|
| 744 | - |
|
| 745 | - //Verify the expiration date |
|
| 746 | - $share = $this->validateExpirationDate($share); |
|
| 747 | - |
|
| 748 | - //Verify the password |
|
| 749 | - $this->verifyPassword($share->getPassword()); |
|
| 750 | - |
|
| 751 | - // If a password is set. Hash it! |
|
| 752 | - if ($share->getPassword() !== null) { |
|
| 753 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 754 | - } |
|
| 755 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 756 | - $share->setToken( |
|
| 757 | - $this->secureRandom->generate( |
|
| 758 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
| 759 | - \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
| 760 | - ) |
|
| 761 | - ); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - // Cannot share with the owner |
|
| 765 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 766 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
| 767 | - throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - // Generate the target |
|
| 771 | - $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
| 772 | - $target = \OC\Files\Filesystem::normalizePath($target); |
|
| 773 | - $share->setTarget($target); |
|
| 774 | - |
|
| 775 | - // Pre share event |
|
| 776 | - $event = new GenericEvent($share); |
|
| 777 | - $this->legacyDispatcher->dispatch('OCP\Share::preShare', $event); |
|
| 778 | - if ($event->isPropagationStopped() && $event->hasArgument('error')) { |
|
| 779 | - throw new \Exception($event->getArgument('error')); |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - $oldShare = $share; |
|
| 783 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 784 | - $share = $provider->create($share); |
|
| 785 | - //reuse the node we already have |
|
| 786 | - $share->setNode($oldShare->getNode()); |
|
| 787 | - |
|
| 788 | - // Reset the target if it is null for the new share |
|
| 789 | - if ($share->getTarget() === '') { |
|
| 790 | - $share->setTarget($target); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - // Post share event |
|
| 794 | - $event = new GenericEvent($share); |
|
| 795 | - $this->legacyDispatcher->dispatch('OCP\Share::postShare', $event); |
|
| 796 | - |
|
| 797 | - $this->dispatcher->dispatchTyped(new Share\Events\ShareCreatedEvent($share)); |
|
| 798 | - |
|
| 799 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 800 | - $mailSend = $share->getMailSend(); |
|
| 801 | - if ($mailSend === true) { |
|
| 802 | - $user = $this->userManager->get($share->getSharedWith()); |
|
| 803 | - if ($user !== null) { |
|
| 804 | - $emailAddress = $user->getEMailAddress(); |
|
| 805 | - if ($emailAddress !== null && $emailAddress !== '') { |
|
| 806 | - $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); |
|
| 807 | - $l = $this->l10nFactory->get('lib', $userLang); |
|
| 808 | - $this->sendMailNotification( |
|
| 809 | - $l, |
|
| 810 | - $share->getNode()->getName(), |
|
| 811 | - $this->urlGenerator->linkToRouteAbsolute('files_sharing.Accept.accept', ['shareId' => $share->getFullId()]), |
|
| 812 | - $share->getSharedBy(), |
|
| 813 | - $emailAddress, |
|
| 814 | - $share->getExpirationDate() |
|
| 815 | - ); |
|
| 816 | - $this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
| 817 | - } else { |
|
| 818 | - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
| 819 | - } |
|
| 820 | - } else { |
|
| 821 | - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
| 822 | - } |
|
| 823 | - } else { |
|
| 824 | - $this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']); |
|
| 825 | - } |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - return $share; |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - /** |
|
| 832 | - * Send mail notifications |
|
| 833 | - * |
|
| 834 | - * This method will catch and log mail transmission errors |
|
| 835 | - * |
|
| 836 | - * @param IL10N $l Language of the recipient |
|
| 837 | - * @param string $filename file/folder name |
|
| 838 | - * @param string $link link to the file/folder |
|
| 839 | - * @param string $initiator user ID of share sender |
|
| 840 | - * @param string $shareWith email address of share receiver |
|
| 841 | - * @param \DateTime|null $expiration |
|
| 842 | - */ |
|
| 843 | - protected function sendMailNotification(IL10N $l, |
|
| 844 | - $filename, |
|
| 845 | - $link, |
|
| 846 | - $initiator, |
|
| 847 | - $shareWith, |
|
| 848 | - \DateTime $expiration = null) { |
|
| 849 | - $initiatorUser = $this->userManager->get($initiator); |
|
| 850 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 851 | - |
|
| 852 | - $message = $this->mailer->createMessage(); |
|
| 853 | - |
|
| 854 | - $emailTemplate = $this->mailer->createEMailTemplate('files_sharing.RecipientNotification', [ |
|
| 855 | - 'filename' => $filename, |
|
| 856 | - 'link' => $link, |
|
| 857 | - 'initiator' => $initiatorDisplayName, |
|
| 858 | - 'expiration' => $expiration, |
|
| 859 | - 'shareWith' => $shareWith, |
|
| 860 | - ]); |
|
| 861 | - |
|
| 862 | - $emailTemplate->setSubject($l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename])); |
|
| 863 | - $emailTemplate->addHeader(); |
|
| 864 | - $emailTemplate->addHeading($l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename]), false); |
|
| 865 | - $text = $l->t('%1$s shared »%2$s« with you.', [$initiatorDisplayName, $filename]); |
|
| 866 | - |
|
| 867 | - $emailTemplate->addBodyText( |
|
| 868 | - htmlspecialchars($text . ' ' . $l->t('Click the button below to open it.')), |
|
| 869 | - $text |
|
| 870 | - ); |
|
| 871 | - $emailTemplate->addBodyButton( |
|
| 872 | - $l->t('Open »%s«', [$filename]), |
|
| 873 | - $link |
|
| 874 | - ); |
|
| 875 | - |
|
| 876 | - $message->setTo([$shareWith]); |
|
| 877 | - |
|
| 878 | - // The "From" contains the sharers name |
|
| 879 | - $instanceName = $this->defaults->getName(); |
|
| 880 | - $senderName = $l->t( |
|
| 881 | - '%1$s via %2$s', |
|
| 882 | - [ |
|
| 883 | - $initiatorDisplayName, |
|
| 884 | - $instanceName |
|
| 885 | - ] |
|
| 886 | - ); |
|
| 887 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
| 888 | - |
|
| 889 | - // The "Reply-To" is set to the sharer if an mail address is configured |
|
| 890 | - // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
| 891 | - $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
| 892 | - if ($initiatorEmail !== null) { |
|
| 893 | - $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
| 894 | - $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : '')); |
|
| 895 | - } else { |
|
| 896 | - $emailTemplate->addFooter('', $l->getLanguageCode()); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - $message->useTemplate($emailTemplate); |
|
| 900 | - try { |
|
| 901 | - $failedRecipients = $this->mailer->send($message); |
|
| 902 | - if (!empty($failedRecipients)) { |
|
| 903 | - $this->logger->error('Share notification mail could not be sent to: ' . implode(', ', $failedRecipients)); |
|
| 904 | - return; |
|
| 905 | - } |
|
| 906 | - } catch (\Exception $e) { |
|
| 907 | - $this->logger->logException($e, ['message' => 'Share notification mail could not be sent']); |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - /** |
|
| 912 | - * Update a share |
|
| 913 | - * |
|
| 914 | - * @param \OCP\Share\IShare $share |
|
| 915 | - * @return \OCP\Share\IShare The share object |
|
| 916 | - * @throws \InvalidArgumentException |
|
| 917 | - */ |
|
| 918 | - public function updateShare(\OCP\Share\IShare $share) { |
|
| 919 | - $expirationDateUpdated = false; |
|
| 920 | - |
|
| 921 | - $this->canShare($share); |
|
| 922 | - |
|
| 923 | - try { |
|
| 924 | - $originalShare = $this->getShareById($share->getFullId()); |
|
| 925 | - } catch (\UnexpectedValueException $e) { |
|
| 926 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - // We can't change the share type! |
|
| 930 | - if ($share->getShareType() !== $originalShare->getShareType()) { |
|
| 931 | - throw new \InvalidArgumentException('Can’t change share type'); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - // We can only change the recipient on user shares |
|
| 935 | - if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
| 936 | - $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
|
| 937 | - throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - // Cannot share with the owner |
|
| 941 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 942 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
| 943 | - throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - $this->generalCreateChecks($share); |
|
| 947 | - |
|
| 948 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 949 | - $this->userCreateChecks($share); |
|
| 950 | - |
|
| 951 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 952 | - //Verify the expiration date |
|
| 953 | - $this->validateExpirationDate($share); |
|
| 954 | - $expirationDateUpdated = true; |
|
| 955 | - } |
|
| 956 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 957 | - $this->groupCreateChecks($share); |
|
| 958 | - |
|
| 959 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 960 | - //Verify the expiration date |
|
| 961 | - $this->validateExpirationDate($share); |
|
| 962 | - $expirationDateUpdated = true; |
|
| 963 | - } |
|
| 964 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 965 | - $this->linkCreateChecks($share); |
|
| 966 | - |
|
| 967 | - $this->updateSharePasswordIfNeeded($share, $originalShare); |
|
| 968 | - |
|
| 969 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 970 | - //Verify the expiration date |
|
| 971 | - $this->validateExpirationDate($share); |
|
| 972 | - $expirationDateUpdated = true; |
|
| 973 | - } |
|
| 974 | - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 975 | - // The new password is not set again if it is the same as the old |
|
| 976 | - // one, unless when switching from sending by Talk to sending by |
|
| 977 | - // mail. |
|
| 978 | - $plainTextPassword = $share->getPassword(); |
|
| 979 | - if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare) && |
|
| 980 | - !($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk())) { |
|
| 981 | - $plainTextPassword = null; |
|
| 982 | - } |
|
| 983 | - if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { |
|
| 984 | - // If the same password was already sent by mail the recipient |
|
| 985 | - // would already have access to the share without having to call |
|
| 986 | - // the sharer to verify her identity |
|
| 987 | - throw new \InvalidArgumentException('Can’t enable sending the password by Talk without setting a new password'); |
|
| 988 | - } |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - $this->pathCreateChecks($share->getNode()); |
|
| 992 | - |
|
| 993 | - // Now update the share! |
|
| 994 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 995 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 996 | - $share = $provider->update($share, $plainTextPassword); |
|
| 997 | - } else { |
|
| 998 | - $share = $provider->update($share); |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - if ($expirationDateUpdated === true) { |
|
| 1002 | - \OC_Hook::emit(Share::class, 'post_set_expiration_date', [ |
|
| 1003 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 1004 | - 'itemSource' => $share->getNode()->getId(), |
|
| 1005 | - 'date' => $share->getExpirationDate(), |
|
| 1006 | - 'uidOwner' => $share->getSharedBy(), |
|
| 1007 | - ]); |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
| 1011 | - \OC_Hook::emit(Share::class, 'post_update_password', [ |
|
| 1012 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 1013 | - 'itemSource' => $share->getNode()->getId(), |
|
| 1014 | - 'uidOwner' => $share->getSharedBy(), |
|
| 1015 | - 'token' => $share->getToken(), |
|
| 1016 | - 'disabled' => is_null($share->getPassword()), |
|
| 1017 | - ]); |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
| 1021 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 1022 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 1023 | - } else { |
|
| 1024 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 1025 | - } |
|
| 1026 | - \OC_Hook::emit(Share::class, 'post_update_permissions', [ |
|
| 1027 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 1028 | - 'itemSource' => $share->getNode()->getId(), |
|
| 1029 | - 'shareType' => $share->getShareType(), |
|
| 1030 | - 'shareWith' => $share->getSharedWith(), |
|
| 1031 | - 'uidOwner' => $share->getSharedBy(), |
|
| 1032 | - 'permissions' => $share->getPermissions(), |
|
| 1033 | - 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
| 1034 | - ]); |
|
| 1035 | - } |
|
| 1036 | - |
|
| 1037 | - return $share; |
|
| 1038 | - } |
|
| 1039 | - |
|
| 1040 | - /** |
|
| 1041 | - * Accept a share. |
|
| 1042 | - * |
|
| 1043 | - * @param IShare $share |
|
| 1044 | - * @param string $recipientId |
|
| 1045 | - * @return IShare The share object |
|
| 1046 | - * @throws \InvalidArgumentException |
|
| 1047 | - * @since 9.0.0 |
|
| 1048 | - */ |
|
| 1049 | - public function acceptShare(IShare $share, string $recipientId): IShare { |
|
| 1050 | - [$providerId, ] = $this->splitFullId($share->getFullId()); |
|
| 1051 | - $provider = $this->factory->getProvider($providerId); |
|
| 1052 | - |
|
| 1053 | - if (!method_exists($provider, 'acceptShare')) { |
|
| 1054 | - // TODO FIX ME |
|
| 1055 | - throw new \InvalidArgumentException('Share provider does not support accepting'); |
|
| 1056 | - } |
|
| 1057 | - $provider->acceptShare($share, $recipientId); |
|
| 1058 | - $event = new GenericEvent($share); |
|
| 1059 | - $this->legacyDispatcher->dispatch('OCP\Share::postAcceptShare', $event); |
|
| 1060 | - |
|
| 1061 | - return $share; |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - /** |
|
| 1065 | - * Updates the password of the given share if it is not the same as the |
|
| 1066 | - * password of the original share. |
|
| 1067 | - * |
|
| 1068 | - * @param \OCP\Share\IShare $share the share to update its password. |
|
| 1069 | - * @param \OCP\Share\IShare $originalShare the original share to compare its |
|
| 1070 | - * password with. |
|
| 1071 | - * @return boolean whether the password was updated or not. |
|
| 1072 | - */ |
|
| 1073 | - private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Share\IShare $originalShare) { |
|
| 1074 | - // Password updated. |
|
| 1075 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
| 1076 | - //Verify the password |
|
| 1077 | - $this->verifyPassword($share->getPassword()); |
|
| 1078 | - |
|
| 1079 | - // If a password is set. Hash it! |
|
| 1080 | - if ($share->getPassword() !== null) { |
|
| 1081 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 1082 | - |
|
| 1083 | - return true; |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - return false; |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - /** |
|
| 1091 | - * Delete all the children of this share |
|
| 1092 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
| 1093 | - * |
|
| 1094 | - * @param \OCP\Share\IShare $share |
|
| 1095 | - * @return \OCP\Share\IShare[] List of deleted shares |
|
| 1096 | - */ |
|
| 1097 | - protected function deleteChildren(\OCP\Share\IShare $share) { |
|
| 1098 | - $deletedShares = []; |
|
| 1099 | - |
|
| 1100 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1101 | - |
|
| 1102 | - foreach ($provider->getChildren($share) as $child) { |
|
| 1103 | - $deletedChildren = $this->deleteChildren($child); |
|
| 1104 | - $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
| 1105 | - |
|
| 1106 | - $provider->delete($child); |
|
| 1107 | - $deletedShares[] = $child; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - return $deletedShares; |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - /** |
|
| 1114 | - * Delete a share |
|
| 1115 | - * |
|
| 1116 | - * @param \OCP\Share\IShare $share |
|
| 1117 | - * @throws ShareNotFound |
|
| 1118 | - * @throws \InvalidArgumentException |
|
| 1119 | - */ |
|
| 1120 | - public function deleteShare(\OCP\Share\IShare $share) { |
|
| 1121 | - try { |
|
| 1122 | - $share->getFullId(); |
|
| 1123 | - } catch (\UnexpectedValueException $e) { |
|
| 1124 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - $event = new GenericEvent($share); |
|
| 1128 | - $this->legacyDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
| 1129 | - |
|
| 1130 | - // Get all children and delete them as well |
|
| 1131 | - $deletedShares = $this->deleteChildren($share); |
|
| 1132 | - |
|
| 1133 | - // Do the actual delete |
|
| 1134 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1135 | - $provider->delete($share); |
|
| 1136 | - |
|
| 1137 | - // All the deleted shares caused by this delete |
|
| 1138 | - $deletedShares[] = $share; |
|
| 1139 | - |
|
| 1140 | - // Emit post hook |
|
| 1141 | - $event->setArgument('deletedShares', $deletedShares); |
|
| 1142 | - $this->legacyDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - |
|
| 1146 | - /** |
|
| 1147 | - * Unshare a file as the recipient. |
|
| 1148 | - * This can be different from a regular delete for example when one of |
|
| 1149 | - * the users in a groups deletes that share. But the provider should |
|
| 1150 | - * handle this. |
|
| 1151 | - * |
|
| 1152 | - * @param \OCP\Share\IShare $share |
|
| 1153 | - * @param string $recipientId |
|
| 1154 | - */ |
|
| 1155 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
|
| 1156 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 1157 | - $provider = $this->factory->getProvider($providerId); |
|
| 1158 | - |
|
| 1159 | - $provider->deleteFromSelf($share, $recipientId); |
|
| 1160 | - $event = new GenericEvent($share); |
|
| 1161 | - $this->legacyDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - public function restoreShare(IShare $share, string $recipientId): IShare { |
|
| 1165 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 1166 | - $provider = $this->factory->getProvider($providerId); |
|
| 1167 | - |
|
| 1168 | - return $provider->restore($share, $recipientId); |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - /** |
|
| 1172 | - * @inheritdoc |
|
| 1173 | - */ |
|
| 1174 | - public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
|
| 1175 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 1176 | - throw new \InvalidArgumentException('Can’t change target of link share'); |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
| 1180 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
| 1181 | - } |
|
| 1182 | - |
|
| 1183 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 1184 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 1185 | - if (is_null($sharedWith)) { |
|
| 1186 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
| 1187 | - } |
|
| 1188 | - $recipient = $this->userManager->get($recipientId); |
|
| 1189 | - if (!$sharedWith->inGroup($recipient)) { |
|
| 1190 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
| 1191 | - } |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 1195 | - $provider = $this->factory->getProvider($providerId); |
|
| 1196 | - |
|
| 1197 | - $provider->move($share, $recipientId); |
|
| 1198 | - } |
|
| 1199 | - |
|
| 1200 | - public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
| 1201 | - $providers = $this->factory->getAllProviders(); |
|
| 1202 | - |
|
| 1203 | - return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
| 1204 | - $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
| 1205 | - foreach ($newShares as $fid => $data) { |
|
| 1206 | - if (!isset($shares[$fid])) { |
|
| 1207 | - $shares[$fid] = []; |
|
| 1208 | - } |
|
| 1209 | - |
|
| 1210 | - $shares[$fid] = array_merge($shares[$fid], $data); |
|
| 1211 | - } |
|
| 1212 | - return $shares; |
|
| 1213 | - }, []); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * @inheritdoc |
|
| 1218 | - */ |
|
| 1219 | - public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
| 1220 | - if ($path !== null && |
|
| 1221 | - !($path instanceof \OCP\Files\File) && |
|
| 1222 | - !($path instanceof \OCP\Files\Folder)) { |
|
| 1223 | - throw new \InvalidArgumentException('invalid path'); |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - try { |
|
| 1227 | - $provider = $this->factory->getProviderForType($shareType); |
|
| 1228 | - } catch (ProviderException $e) { |
|
| 1229 | - return []; |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 1233 | - |
|
| 1234 | - /* |
|
| 738 | + $share->setToken( |
|
| 739 | + $this->secureRandom->generate( |
|
| 740 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
| 741 | + \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
| 742 | + ) |
|
| 743 | + ); |
|
| 744 | + |
|
| 745 | + //Verify the expiration date |
|
| 746 | + $share = $this->validateExpirationDate($share); |
|
| 747 | + |
|
| 748 | + //Verify the password |
|
| 749 | + $this->verifyPassword($share->getPassword()); |
|
| 750 | + |
|
| 751 | + // If a password is set. Hash it! |
|
| 752 | + if ($share->getPassword() !== null) { |
|
| 753 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 754 | + } |
|
| 755 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 756 | + $share->setToken( |
|
| 757 | + $this->secureRandom->generate( |
|
| 758 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
| 759 | + \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
| 760 | + ) |
|
| 761 | + ); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + // Cannot share with the owner |
|
| 765 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 766 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
| 767 | + throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + // Generate the target |
|
| 771 | + $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
| 772 | + $target = \OC\Files\Filesystem::normalizePath($target); |
|
| 773 | + $share->setTarget($target); |
|
| 774 | + |
|
| 775 | + // Pre share event |
|
| 776 | + $event = new GenericEvent($share); |
|
| 777 | + $this->legacyDispatcher->dispatch('OCP\Share::preShare', $event); |
|
| 778 | + if ($event->isPropagationStopped() && $event->hasArgument('error')) { |
|
| 779 | + throw new \Exception($event->getArgument('error')); |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + $oldShare = $share; |
|
| 783 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 784 | + $share = $provider->create($share); |
|
| 785 | + //reuse the node we already have |
|
| 786 | + $share->setNode($oldShare->getNode()); |
|
| 787 | + |
|
| 788 | + // Reset the target if it is null for the new share |
|
| 789 | + if ($share->getTarget() === '') { |
|
| 790 | + $share->setTarget($target); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + // Post share event |
|
| 794 | + $event = new GenericEvent($share); |
|
| 795 | + $this->legacyDispatcher->dispatch('OCP\Share::postShare', $event); |
|
| 796 | + |
|
| 797 | + $this->dispatcher->dispatchTyped(new Share\Events\ShareCreatedEvent($share)); |
|
| 798 | + |
|
| 799 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 800 | + $mailSend = $share->getMailSend(); |
|
| 801 | + if ($mailSend === true) { |
|
| 802 | + $user = $this->userManager->get($share->getSharedWith()); |
|
| 803 | + if ($user !== null) { |
|
| 804 | + $emailAddress = $user->getEMailAddress(); |
|
| 805 | + if ($emailAddress !== null && $emailAddress !== '') { |
|
| 806 | + $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); |
|
| 807 | + $l = $this->l10nFactory->get('lib', $userLang); |
|
| 808 | + $this->sendMailNotification( |
|
| 809 | + $l, |
|
| 810 | + $share->getNode()->getName(), |
|
| 811 | + $this->urlGenerator->linkToRouteAbsolute('files_sharing.Accept.accept', ['shareId' => $share->getFullId()]), |
|
| 812 | + $share->getSharedBy(), |
|
| 813 | + $emailAddress, |
|
| 814 | + $share->getExpirationDate() |
|
| 815 | + ); |
|
| 816 | + $this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
| 817 | + } else { |
|
| 818 | + $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
| 819 | + } |
|
| 820 | + } else { |
|
| 821 | + $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
| 822 | + } |
|
| 823 | + } else { |
|
| 824 | + $this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']); |
|
| 825 | + } |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + return $share; |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + /** |
|
| 832 | + * Send mail notifications |
|
| 833 | + * |
|
| 834 | + * This method will catch and log mail transmission errors |
|
| 835 | + * |
|
| 836 | + * @param IL10N $l Language of the recipient |
|
| 837 | + * @param string $filename file/folder name |
|
| 838 | + * @param string $link link to the file/folder |
|
| 839 | + * @param string $initiator user ID of share sender |
|
| 840 | + * @param string $shareWith email address of share receiver |
|
| 841 | + * @param \DateTime|null $expiration |
|
| 842 | + */ |
|
| 843 | + protected function sendMailNotification(IL10N $l, |
|
| 844 | + $filename, |
|
| 845 | + $link, |
|
| 846 | + $initiator, |
|
| 847 | + $shareWith, |
|
| 848 | + \DateTime $expiration = null) { |
|
| 849 | + $initiatorUser = $this->userManager->get($initiator); |
|
| 850 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 851 | + |
|
| 852 | + $message = $this->mailer->createMessage(); |
|
| 853 | + |
|
| 854 | + $emailTemplate = $this->mailer->createEMailTemplate('files_sharing.RecipientNotification', [ |
|
| 855 | + 'filename' => $filename, |
|
| 856 | + 'link' => $link, |
|
| 857 | + 'initiator' => $initiatorDisplayName, |
|
| 858 | + 'expiration' => $expiration, |
|
| 859 | + 'shareWith' => $shareWith, |
|
| 860 | + ]); |
|
| 861 | + |
|
| 862 | + $emailTemplate->setSubject($l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename])); |
|
| 863 | + $emailTemplate->addHeader(); |
|
| 864 | + $emailTemplate->addHeading($l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename]), false); |
|
| 865 | + $text = $l->t('%1$s shared »%2$s« with you.', [$initiatorDisplayName, $filename]); |
|
| 866 | + |
|
| 867 | + $emailTemplate->addBodyText( |
|
| 868 | + htmlspecialchars($text . ' ' . $l->t('Click the button below to open it.')), |
|
| 869 | + $text |
|
| 870 | + ); |
|
| 871 | + $emailTemplate->addBodyButton( |
|
| 872 | + $l->t('Open »%s«', [$filename]), |
|
| 873 | + $link |
|
| 874 | + ); |
|
| 875 | + |
|
| 876 | + $message->setTo([$shareWith]); |
|
| 877 | + |
|
| 878 | + // The "From" contains the sharers name |
|
| 879 | + $instanceName = $this->defaults->getName(); |
|
| 880 | + $senderName = $l->t( |
|
| 881 | + '%1$s via %2$s', |
|
| 882 | + [ |
|
| 883 | + $initiatorDisplayName, |
|
| 884 | + $instanceName |
|
| 885 | + ] |
|
| 886 | + ); |
|
| 887 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
| 888 | + |
|
| 889 | + // The "Reply-To" is set to the sharer if an mail address is configured |
|
| 890 | + // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
| 891 | + $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
| 892 | + if ($initiatorEmail !== null) { |
|
| 893 | + $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
| 894 | + $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : '')); |
|
| 895 | + } else { |
|
| 896 | + $emailTemplate->addFooter('', $l->getLanguageCode()); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + $message->useTemplate($emailTemplate); |
|
| 900 | + try { |
|
| 901 | + $failedRecipients = $this->mailer->send($message); |
|
| 902 | + if (!empty($failedRecipients)) { |
|
| 903 | + $this->logger->error('Share notification mail could not be sent to: ' . implode(', ', $failedRecipients)); |
|
| 904 | + return; |
|
| 905 | + } |
|
| 906 | + } catch (\Exception $e) { |
|
| 907 | + $this->logger->logException($e, ['message' => 'Share notification mail could not be sent']); |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + /** |
|
| 912 | + * Update a share |
|
| 913 | + * |
|
| 914 | + * @param \OCP\Share\IShare $share |
|
| 915 | + * @return \OCP\Share\IShare The share object |
|
| 916 | + * @throws \InvalidArgumentException |
|
| 917 | + */ |
|
| 918 | + public function updateShare(\OCP\Share\IShare $share) { |
|
| 919 | + $expirationDateUpdated = false; |
|
| 920 | + |
|
| 921 | + $this->canShare($share); |
|
| 922 | + |
|
| 923 | + try { |
|
| 924 | + $originalShare = $this->getShareById($share->getFullId()); |
|
| 925 | + } catch (\UnexpectedValueException $e) { |
|
| 926 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + // We can't change the share type! |
|
| 930 | + if ($share->getShareType() !== $originalShare->getShareType()) { |
|
| 931 | + throw new \InvalidArgumentException('Can’t change share type'); |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + // We can only change the recipient on user shares |
|
| 935 | + if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
| 936 | + $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
|
| 937 | + throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + // Cannot share with the owner |
|
| 941 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 942 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
| 943 | + throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + $this->generalCreateChecks($share); |
|
| 947 | + |
|
| 948 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 949 | + $this->userCreateChecks($share); |
|
| 950 | + |
|
| 951 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 952 | + //Verify the expiration date |
|
| 953 | + $this->validateExpirationDate($share); |
|
| 954 | + $expirationDateUpdated = true; |
|
| 955 | + } |
|
| 956 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 957 | + $this->groupCreateChecks($share); |
|
| 958 | + |
|
| 959 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 960 | + //Verify the expiration date |
|
| 961 | + $this->validateExpirationDate($share); |
|
| 962 | + $expirationDateUpdated = true; |
|
| 963 | + } |
|
| 964 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 965 | + $this->linkCreateChecks($share); |
|
| 966 | + |
|
| 967 | + $this->updateSharePasswordIfNeeded($share, $originalShare); |
|
| 968 | + |
|
| 969 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 970 | + //Verify the expiration date |
|
| 971 | + $this->validateExpirationDate($share); |
|
| 972 | + $expirationDateUpdated = true; |
|
| 973 | + } |
|
| 974 | + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 975 | + // The new password is not set again if it is the same as the old |
|
| 976 | + // one, unless when switching from sending by Talk to sending by |
|
| 977 | + // mail. |
|
| 978 | + $plainTextPassword = $share->getPassword(); |
|
| 979 | + if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare) && |
|
| 980 | + !($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk())) { |
|
| 981 | + $plainTextPassword = null; |
|
| 982 | + } |
|
| 983 | + if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { |
|
| 984 | + // If the same password was already sent by mail the recipient |
|
| 985 | + // would already have access to the share without having to call |
|
| 986 | + // the sharer to verify her identity |
|
| 987 | + throw new \InvalidArgumentException('Can’t enable sending the password by Talk without setting a new password'); |
|
| 988 | + } |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + $this->pathCreateChecks($share->getNode()); |
|
| 992 | + |
|
| 993 | + // Now update the share! |
|
| 994 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 995 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 996 | + $share = $provider->update($share, $plainTextPassword); |
|
| 997 | + } else { |
|
| 998 | + $share = $provider->update($share); |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + if ($expirationDateUpdated === true) { |
|
| 1002 | + \OC_Hook::emit(Share::class, 'post_set_expiration_date', [ |
|
| 1003 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 1004 | + 'itemSource' => $share->getNode()->getId(), |
|
| 1005 | + 'date' => $share->getExpirationDate(), |
|
| 1006 | + 'uidOwner' => $share->getSharedBy(), |
|
| 1007 | + ]); |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
| 1011 | + \OC_Hook::emit(Share::class, 'post_update_password', [ |
|
| 1012 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 1013 | + 'itemSource' => $share->getNode()->getId(), |
|
| 1014 | + 'uidOwner' => $share->getSharedBy(), |
|
| 1015 | + 'token' => $share->getToken(), |
|
| 1016 | + 'disabled' => is_null($share->getPassword()), |
|
| 1017 | + ]); |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
| 1021 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 1022 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 1023 | + } else { |
|
| 1024 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 1025 | + } |
|
| 1026 | + \OC_Hook::emit(Share::class, 'post_update_permissions', [ |
|
| 1027 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 1028 | + 'itemSource' => $share->getNode()->getId(), |
|
| 1029 | + 'shareType' => $share->getShareType(), |
|
| 1030 | + 'shareWith' => $share->getSharedWith(), |
|
| 1031 | + 'uidOwner' => $share->getSharedBy(), |
|
| 1032 | + 'permissions' => $share->getPermissions(), |
|
| 1033 | + 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
| 1034 | + ]); |
|
| 1035 | + } |
|
| 1036 | + |
|
| 1037 | + return $share; |
|
| 1038 | + } |
|
| 1039 | + |
|
| 1040 | + /** |
|
| 1041 | + * Accept a share. |
|
| 1042 | + * |
|
| 1043 | + * @param IShare $share |
|
| 1044 | + * @param string $recipientId |
|
| 1045 | + * @return IShare The share object |
|
| 1046 | + * @throws \InvalidArgumentException |
|
| 1047 | + * @since 9.0.0 |
|
| 1048 | + */ |
|
| 1049 | + public function acceptShare(IShare $share, string $recipientId): IShare { |
|
| 1050 | + [$providerId, ] = $this->splitFullId($share->getFullId()); |
|
| 1051 | + $provider = $this->factory->getProvider($providerId); |
|
| 1052 | + |
|
| 1053 | + if (!method_exists($provider, 'acceptShare')) { |
|
| 1054 | + // TODO FIX ME |
|
| 1055 | + throw new \InvalidArgumentException('Share provider does not support accepting'); |
|
| 1056 | + } |
|
| 1057 | + $provider->acceptShare($share, $recipientId); |
|
| 1058 | + $event = new GenericEvent($share); |
|
| 1059 | + $this->legacyDispatcher->dispatch('OCP\Share::postAcceptShare', $event); |
|
| 1060 | + |
|
| 1061 | + return $share; |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + /** |
|
| 1065 | + * Updates the password of the given share if it is not the same as the |
|
| 1066 | + * password of the original share. |
|
| 1067 | + * |
|
| 1068 | + * @param \OCP\Share\IShare $share the share to update its password. |
|
| 1069 | + * @param \OCP\Share\IShare $originalShare the original share to compare its |
|
| 1070 | + * password with. |
|
| 1071 | + * @return boolean whether the password was updated or not. |
|
| 1072 | + */ |
|
| 1073 | + private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Share\IShare $originalShare) { |
|
| 1074 | + // Password updated. |
|
| 1075 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
| 1076 | + //Verify the password |
|
| 1077 | + $this->verifyPassword($share->getPassword()); |
|
| 1078 | + |
|
| 1079 | + // If a password is set. Hash it! |
|
| 1080 | + if ($share->getPassword() !== null) { |
|
| 1081 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 1082 | + |
|
| 1083 | + return true; |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + return false; |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + /** |
|
| 1091 | + * Delete all the children of this share |
|
| 1092 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
| 1093 | + * |
|
| 1094 | + * @param \OCP\Share\IShare $share |
|
| 1095 | + * @return \OCP\Share\IShare[] List of deleted shares |
|
| 1096 | + */ |
|
| 1097 | + protected function deleteChildren(\OCP\Share\IShare $share) { |
|
| 1098 | + $deletedShares = []; |
|
| 1099 | + |
|
| 1100 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1101 | + |
|
| 1102 | + foreach ($provider->getChildren($share) as $child) { |
|
| 1103 | + $deletedChildren = $this->deleteChildren($child); |
|
| 1104 | + $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
| 1105 | + |
|
| 1106 | + $provider->delete($child); |
|
| 1107 | + $deletedShares[] = $child; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + return $deletedShares; |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + /** |
|
| 1114 | + * Delete a share |
|
| 1115 | + * |
|
| 1116 | + * @param \OCP\Share\IShare $share |
|
| 1117 | + * @throws ShareNotFound |
|
| 1118 | + * @throws \InvalidArgumentException |
|
| 1119 | + */ |
|
| 1120 | + public function deleteShare(\OCP\Share\IShare $share) { |
|
| 1121 | + try { |
|
| 1122 | + $share->getFullId(); |
|
| 1123 | + } catch (\UnexpectedValueException $e) { |
|
| 1124 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + $event = new GenericEvent($share); |
|
| 1128 | + $this->legacyDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
| 1129 | + |
|
| 1130 | + // Get all children and delete them as well |
|
| 1131 | + $deletedShares = $this->deleteChildren($share); |
|
| 1132 | + |
|
| 1133 | + // Do the actual delete |
|
| 1134 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1135 | + $provider->delete($share); |
|
| 1136 | + |
|
| 1137 | + // All the deleted shares caused by this delete |
|
| 1138 | + $deletedShares[] = $share; |
|
| 1139 | + |
|
| 1140 | + // Emit post hook |
|
| 1141 | + $event->setArgument('deletedShares', $deletedShares); |
|
| 1142 | + $this->legacyDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + |
|
| 1146 | + /** |
|
| 1147 | + * Unshare a file as the recipient. |
|
| 1148 | + * This can be different from a regular delete for example when one of |
|
| 1149 | + * the users in a groups deletes that share. But the provider should |
|
| 1150 | + * handle this. |
|
| 1151 | + * |
|
| 1152 | + * @param \OCP\Share\IShare $share |
|
| 1153 | + * @param string $recipientId |
|
| 1154 | + */ |
|
| 1155 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
|
| 1156 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 1157 | + $provider = $this->factory->getProvider($providerId); |
|
| 1158 | + |
|
| 1159 | + $provider->deleteFromSelf($share, $recipientId); |
|
| 1160 | + $event = new GenericEvent($share); |
|
| 1161 | + $this->legacyDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + public function restoreShare(IShare $share, string $recipientId): IShare { |
|
| 1165 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 1166 | + $provider = $this->factory->getProvider($providerId); |
|
| 1167 | + |
|
| 1168 | + return $provider->restore($share, $recipientId); |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + /** |
|
| 1172 | + * @inheritdoc |
|
| 1173 | + */ |
|
| 1174 | + public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
|
| 1175 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 1176 | + throw new \InvalidArgumentException('Can’t change target of link share'); |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
| 1180 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
| 1181 | + } |
|
| 1182 | + |
|
| 1183 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 1184 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 1185 | + if (is_null($sharedWith)) { |
|
| 1186 | + throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
| 1187 | + } |
|
| 1188 | + $recipient = $this->userManager->get($recipientId); |
|
| 1189 | + if (!$sharedWith->inGroup($recipient)) { |
|
| 1190 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
| 1191 | + } |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 1195 | + $provider = $this->factory->getProvider($providerId); |
|
| 1196 | + |
|
| 1197 | + $provider->move($share, $recipientId); |
|
| 1198 | + } |
|
| 1199 | + |
|
| 1200 | + public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
| 1201 | + $providers = $this->factory->getAllProviders(); |
|
| 1202 | + |
|
| 1203 | + return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
| 1204 | + $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
| 1205 | + foreach ($newShares as $fid => $data) { |
|
| 1206 | + if (!isset($shares[$fid])) { |
|
| 1207 | + $shares[$fid] = []; |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + $shares[$fid] = array_merge($shares[$fid], $data); |
|
| 1211 | + } |
|
| 1212 | + return $shares; |
|
| 1213 | + }, []); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * @inheritdoc |
|
| 1218 | + */ |
|
| 1219 | + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
| 1220 | + if ($path !== null && |
|
| 1221 | + !($path instanceof \OCP\Files\File) && |
|
| 1222 | + !($path instanceof \OCP\Files\Folder)) { |
|
| 1223 | + throw new \InvalidArgumentException('invalid path'); |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + try { |
|
| 1227 | + $provider = $this->factory->getProviderForType($shareType); |
|
| 1228 | + } catch (ProviderException $e) { |
|
| 1229 | + return []; |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 1233 | + |
|
| 1234 | + /* |
|
| 1235 | 1235 | * Work around so we don't return expired shares but still follow |
| 1236 | 1236 | * proper pagination. |
| 1237 | 1237 | */ |
| 1238 | 1238 | |
| 1239 | - $shares2 = []; |
|
| 1240 | - |
|
| 1241 | - while (true) { |
|
| 1242 | - $added = 0; |
|
| 1243 | - foreach ($shares as $share) { |
|
| 1244 | - try { |
|
| 1245 | - $this->checkExpireDate($share); |
|
| 1246 | - } catch (ShareNotFound $e) { |
|
| 1247 | - //Ignore since this basically means the share is deleted |
|
| 1248 | - continue; |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - $added++; |
|
| 1252 | - $shares2[] = $share; |
|
| 1253 | - |
|
| 1254 | - if (count($shares2) === $limit) { |
|
| 1255 | - break; |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1258 | - |
|
| 1259 | - // If we did not fetch more shares than the limit then there are no more shares |
|
| 1260 | - if (count($shares) < $limit) { |
|
| 1261 | - break; |
|
| 1262 | - } |
|
| 1263 | - |
|
| 1264 | - if (count($shares2) === $limit) { |
|
| 1265 | - break; |
|
| 1266 | - } |
|
| 1267 | - |
|
| 1268 | - // If there was no limit on the select we are done |
|
| 1269 | - if ($limit === -1) { |
|
| 1270 | - break; |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - $offset += $added; |
|
| 1274 | - |
|
| 1275 | - // Fetch again $limit shares |
|
| 1276 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 1277 | - |
|
| 1278 | - // No more shares means we are done |
|
| 1279 | - if (empty($shares)) { |
|
| 1280 | - break; |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - $shares = $shares2; |
|
| 1285 | - |
|
| 1286 | - return $shares; |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - /** |
|
| 1290 | - * @inheritdoc |
|
| 1291 | - */ |
|
| 1292 | - public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
| 1293 | - try { |
|
| 1294 | - $provider = $this->factory->getProviderForType($shareType); |
|
| 1295 | - } catch (ProviderException $e) { |
|
| 1296 | - return []; |
|
| 1297 | - } |
|
| 1298 | - |
|
| 1299 | - $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 1300 | - |
|
| 1301 | - // remove all shares which are already expired |
|
| 1302 | - foreach ($shares as $key => $share) { |
|
| 1303 | - try { |
|
| 1304 | - $this->checkExpireDate($share); |
|
| 1305 | - } catch (ShareNotFound $e) { |
|
| 1306 | - unset($shares[$key]); |
|
| 1307 | - } |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - return $shares; |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - /** |
|
| 1314 | - * @inheritdoc |
|
| 1315 | - */ |
|
| 1316 | - public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
| 1317 | - $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 1318 | - |
|
| 1319 | - // Only get deleted shares |
|
| 1320 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 1321 | - return $share->getPermissions() === 0; |
|
| 1322 | - }); |
|
| 1323 | - |
|
| 1324 | - // Only get shares where the owner still exists |
|
| 1325 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 1326 | - return $this->userManager->userExists($share->getShareOwner()); |
|
| 1327 | - }); |
|
| 1328 | - |
|
| 1329 | - return $shares; |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * @inheritdoc |
|
| 1334 | - */ |
|
| 1335 | - public function getShareById($id, $recipient = null) { |
|
| 1336 | - if ($id === null) { |
|
| 1337 | - throw new ShareNotFound(); |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - list($providerId, $id) = $this->splitFullId($id); |
|
| 1341 | - |
|
| 1342 | - try { |
|
| 1343 | - $provider = $this->factory->getProvider($providerId); |
|
| 1344 | - } catch (ProviderException $e) { |
|
| 1345 | - throw new ShareNotFound(); |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - $share = $provider->getShareById($id, $recipient); |
|
| 1349 | - |
|
| 1350 | - $this->checkExpireDate($share); |
|
| 1351 | - |
|
| 1352 | - return $share; |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - /** |
|
| 1356 | - * Get all the shares for a given path |
|
| 1357 | - * |
|
| 1358 | - * @param \OCP\Files\Node $path |
|
| 1359 | - * @param int $page |
|
| 1360 | - * @param int $perPage |
|
| 1361 | - * |
|
| 1362 | - * @return Share[] |
|
| 1363 | - */ |
|
| 1364 | - public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
| 1365 | - return []; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - /** |
|
| 1369 | - * Get the share by token possible with password |
|
| 1370 | - * |
|
| 1371 | - * @param string $token |
|
| 1372 | - * @return Share |
|
| 1373 | - * |
|
| 1374 | - * @throws ShareNotFound |
|
| 1375 | - */ |
|
| 1376 | - public function getShareByToken($token) { |
|
| 1377 | - // tokens can't be valid local user names |
|
| 1378 | - if ($this->userManager->userExists($token)) { |
|
| 1379 | - throw new ShareNotFound(); |
|
| 1380 | - } |
|
| 1381 | - $share = null; |
|
| 1382 | - try { |
|
| 1383 | - if ($this->shareApiAllowLinks()) { |
|
| 1384 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
|
| 1385 | - $share = $provider->getShareByToken($token); |
|
| 1386 | - } |
|
| 1387 | - } catch (ProviderException $e) { |
|
| 1388 | - } catch (ShareNotFound $e) { |
|
| 1389 | - } |
|
| 1390 | - |
|
| 1391 | - |
|
| 1392 | - // If it is not a link share try to fetch a federated share by token |
|
| 1393 | - if ($share === null) { |
|
| 1394 | - try { |
|
| 1395 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE); |
|
| 1396 | - $share = $provider->getShareByToken($token); |
|
| 1397 | - } catch (ProviderException $e) { |
|
| 1398 | - } catch (ShareNotFound $e) { |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1401 | - |
|
| 1402 | - // If it is not a link share try to fetch a mail share by token |
|
| 1403 | - if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 1404 | - try { |
|
| 1405 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL); |
|
| 1406 | - $share = $provider->getShareByToken($token); |
|
| 1407 | - } catch (ProviderException $e) { |
|
| 1408 | - } catch (ShareNotFound $e) { |
|
| 1409 | - } |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 1413 | - try { |
|
| 1414 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_CIRCLE); |
|
| 1415 | - $share = $provider->getShareByToken($token); |
|
| 1416 | - } catch (ProviderException $e) { |
|
| 1417 | - } catch (ShareNotFound $e) { |
|
| 1418 | - } |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_ROOM)) { |
|
| 1422 | - try { |
|
| 1423 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_ROOM); |
|
| 1424 | - $share = $provider->getShareByToken($token); |
|
| 1425 | - } catch (ProviderException $e) { |
|
| 1426 | - } catch (ShareNotFound $e) { |
|
| 1427 | - } |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - if ($share === null) { |
|
| 1431 | - throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - $this->checkExpireDate($share); |
|
| 1435 | - |
|
| 1436 | - /* |
|
| 1239 | + $shares2 = []; |
|
| 1240 | + |
|
| 1241 | + while (true) { |
|
| 1242 | + $added = 0; |
|
| 1243 | + foreach ($shares as $share) { |
|
| 1244 | + try { |
|
| 1245 | + $this->checkExpireDate($share); |
|
| 1246 | + } catch (ShareNotFound $e) { |
|
| 1247 | + //Ignore since this basically means the share is deleted |
|
| 1248 | + continue; |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + $added++; |
|
| 1252 | + $shares2[] = $share; |
|
| 1253 | + |
|
| 1254 | + if (count($shares2) === $limit) { |
|
| 1255 | + break; |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | + |
|
| 1259 | + // If we did not fetch more shares than the limit then there are no more shares |
|
| 1260 | + if (count($shares) < $limit) { |
|
| 1261 | + break; |
|
| 1262 | + } |
|
| 1263 | + |
|
| 1264 | + if (count($shares2) === $limit) { |
|
| 1265 | + break; |
|
| 1266 | + } |
|
| 1267 | + |
|
| 1268 | + // If there was no limit on the select we are done |
|
| 1269 | + if ($limit === -1) { |
|
| 1270 | + break; |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + $offset += $added; |
|
| 1274 | + |
|
| 1275 | + // Fetch again $limit shares |
|
| 1276 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 1277 | + |
|
| 1278 | + // No more shares means we are done |
|
| 1279 | + if (empty($shares)) { |
|
| 1280 | + break; |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + $shares = $shares2; |
|
| 1285 | + |
|
| 1286 | + return $shares; |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + /** |
|
| 1290 | + * @inheritdoc |
|
| 1291 | + */ |
|
| 1292 | + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
| 1293 | + try { |
|
| 1294 | + $provider = $this->factory->getProviderForType($shareType); |
|
| 1295 | + } catch (ProviderException $e) { |
|
| 1296 | + return []; |
|
| 1297 | + } |
|
| 1298 | + |
|
| 1299 | + $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 1300 | + |
|
| 1301 | + // remove all shares which are already expired |
|
| 1302 | + foreach ($shares as $key => $share) { |
|
| 1303 | + try { |
|
| 1304 | + $this->checkExpireDate($share); |
|
| 1305 | + } catch (ShareNotFound $e) { |
|
| 1306 | + unset($shares[$key]); |
|
| 1307 | + } |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + return $shares; |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + /** |
|
| 1314 | + * @inheritdoc |
|
| 1315 | + */ |
|
| 1316 | + public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
| 1317 | + $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 1318 | + |
|
| 1319 | + // Only get deleted shares |
|
| 1320 | + $shares = array_filter($shares, function (IShare $share) { |
|
| 1321 | + return $share->getPermissions() === 0; |
|
| 1322 | + }); |
|
| 1323 | + |
|
| 1324 | + // Only get shares where the owner still exists |
|
| 1325 | + $shares = array_filter($shares, function (IShare $share) { |
|
| 1326 | + return $this->userManager->userExists($share->getShareOwner()); |
|
| 1327 | + }); |
|
| 1328 | + |
|
| 1329 | + return $shares; |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * @inheritdoc |
|
| 1334 | + */ |
|
| 1335 | + public function getShareById($id, $recipient = null) { |
|
| 1336 | + if ($id === null) { |
|
| 1337 | + throw new ShareNotFound(); |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + list($providerId, $id) = $this->splitFullId($id); |
|
| 1341 | + |
|
| 1342 | + try { |
|
| 1343 | + $provider = $this->factory->getProvider($providerId); |
|
| 1344 | + } catch (ProviderException $e) { |
|
| 1345 | + throw new ShareNotFound(); |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + $share = $provider->getShareById($id, $recipient); |
|
| 1349 | + |
|
| 1350 | + $this->checkExpireDate($share); |
|
| 1351 | + |
|
| 1352 | + return $share; |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + /** |
|
| 1356 | + * Get all the shares for a given path |
|
| 1357 | + * |
|
| 1358 | + * @param \OCP\Files\Node $path |
|
| 1359 | + * @param int $page |
|
| 1360 | + * @param int $perPage |
|
| 1361 | + * |
|
| 1362 | + * @return Share[] |
|
| 1363 | + */ |
|
| 1364 | + public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
| 1365 | + return []; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + /** |
|
| 1369 | + * Get the share by token possible with password |
|
| 1370 | + * |
|
| 1371 | + * @param string $token |
|
| 1372 | + * @return Share |
|
| 1373 | + * |
|
| 1374 | + * @throws ShareNotFound |
|
| 1375 | + */ |
|
| 1376 | + public function getShareByToken($token) { |
|
| 1377 | + // tokens can't be valid local user names |
|
| 1378 | + if ($this->userManager->userExists($token)) { |
|
| 1379 | + throw new ShareNotFound(); |
|
| 1380 | + } |
|
| 1381 | + $share = null; |
|
| 1382 | + try { |
|
| 1383 | + if ($this->shareApiAllowLinks()) { |
|
| 1384 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
|
| 1385 | + $share = $provider->getShareByToken($token); |
|
| 1386 | + } |
|
| 1387 | + } catch (ProviderException $e) { |
|
| 1388 | + } catch (ShareNotFound $e) { |
|
| 1389 | + } |
|
| 1390 | + |
|
| 1391 | + |
|
| 1392 | + // If it is not a link share try to fetch a federated share by token |
|
| 1393 | + if ($share === null) { |
|
| 1394 | + try { |
|
| 1395 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE); |
|
| 1396 | + $share = $provider->getShareByToken($token); |
|
| 1397 | + } catch (ProviderException $e) { |
|
| 1398 | + } catch (ShareNotFound $e) { |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | + |
|
| 1402 | + // If it is not a link share try to fetch a mail share by token |
|
| 1403 | + if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 1404 | + try { |
|
| 1405 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL); |
|
| 1406 | + $share = $provider->getShareByToken($token); |
|
| 1407 | + } catch (ProviderException $e) { |
|
| 1408 | + } catch (ShareNotFound $e) { |
|
| 1409 | + } |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 1413 | + try { |
|
| 1414 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_CIRCLE); |
|
| 1415 | + $share = $provider->getShareByToken($token); |
|
| 1416 | + } catch (ProviderException $e) { |
|
| 1417 | + } catch (ShareNotFound $e) { |
|
| 1418 | + } |
|
| 1419 | + } |
|
| 1420 | + |
|
| 1421 | + if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_ROOM)) { |
|
| 1422 | + try { |
|
| 1423 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_ROOM); |
|
| 1424 | + $share = $provider->getShareByToken($token); |
|
| 1425 | + } catch (ProviderException $e) { |
|
| 1426 | + } catch (ShareNotFound $e) { |
|
| 1427 | + } |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + if ($share === null) { |
|
| 1431 | + throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + $this->checkExpireDate($share); |
|
| 1435 | + |
|
| 1436 | + /* |
|
| 1437 | 1437 | * Reduce the permissions for link shares if public upload is not enabled |
| 1438 | 1438 | */ |
| 1439 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
| 1440 | - !$this->shareApiLinkAllowPublicUpload()) { |
|
| 1441 | - $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
| 1442 | - } |
|
| 1443 | - |
|
| 1444 | - return $share; |
|
| 1445 | - } |
|
| 1446 | - |
|
| 1447 | - protected function checkExpireDate($share) { |
|
| 1448 | - if ($share->isExpired()) { |
|
| 1449 | - $this->deleteShare($share); |
|
| 1450 | - throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
| 1451 | - } |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - /** |
|
| 1455 | - * Verify the password of a public share |
|
| 1456 | - * |
|
| 1457 | - * @param \OCP\Share\IShare $share |
|
| 1458 | - * @param string $password |
|
| 1459 | - * @return bool |
|
| 1460 | - */ |
|
| 1461 | - public function checkPassword(\OCP\Share\IShare $share, $password) { |
|
| 1462 | - $passwordProtected = $share->getShareType() !== IShare::TYPE_LINK |
|
| 1463 | - || $share->getShareType() !== IShare::TYPE_EMAIL |
|
| 1464 | - || $share->getShareType() !== IShare::TYPE_CIRCLE; |
|
| 1465 | - if (!$passwordProtected) { |
|
| 1466 | - //TODO maybe exception? |
|
| 1467 | - return false; |
|
| 1468 | - } |
|
| 1469 | - |
|
| 1470 | - if ($password === null || $share->getPassword() === null) { |
|
| 1471 | - return false; |
|
| 1472 | - } |
|
| 1473 | - |
|
| 1474 | - $newHash = ''; |
|
| 1475 | - if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
| 1476 | - return false; |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - if (!empty($newHash)) { |
|
| 1480 | - $share->setPassword($newHash); |
|
| 1481 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1482 | - $provider->update($share); |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - return true; |
|
| 1486 | - } |
|
| 1487 | - |
|
| 1488 | - /** |
|
| 1489 | - * @inheritdoc |
|
| 1490 | - */ |
|
| 1491 | - public function userDeleted($uid) { |
|
| 1492 | - $types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_EMAIL]; |
|
| 1493 | - |
|
| 1494 | - foreach ($types as $type) { |
|
| 1495 | - try { |
|
| 1496 | - $provider = $this->factory->getProviderForType($type); |
|
| 1497 | - } catch (ProviderException $e) { |
|
| 1498 | - continue; |
|
| 1499 | - } |
|
| 1500 | - $provider->userDeleted($uid, $type); |
|
| 1501 | - } |
|
| 1502 | - } |
|
| 1503 | - |
|
| 1504 | - /** |
|
| 1505 | - * @inheritdoc |
|
| 1506 | - */ |
|
| 1507 | - public function groupDeleted($gid) { |
|
| 1508 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 1509 | - $provider->groupDeleted($gid); |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - /** |
|
| 1513 | - * @inheritdoc |
|
| 1514 | - */ |
|
| 1515 | - public function userDeletedFromGroup($uid, $gid) { |
|
| 1516 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 1517 | - $provider->userDeletedFromGroup($uid, $gid); |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - /** |
|
| 1521 | - * Get access list to a path. This means |
|
| 1522 | - * all the users that can access a given path. |
|
| 1523 | - * |
|
| 1524 | - * Consider: |
|
| 1525 | - * -root |
|
| 1526 | - * |-folder1 (23) |
|
| 1527 | - * |-folder2 (32) |
|
| 1528 | - * |-fileA (42) |
|
| 1529 | - * |
|
| 1530 | - * fileA is shared with user1 and user1@server1 |
|
| 1531 | - * folder2 is shared with group2 (user4 is a member of group2) |
|
| 1532 | - * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
| 1533 | - * |
|
| 1534 | - * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
| 1535 | - * [ |
|
| 1536 | - * users => [ |
|
| 1537 | - * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
| 1538 | - * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
| 1539 | - * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
| 1540 | - * ], |
|
| 1541 | - * remote => [ |
|
| 1542 | - * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
| 1543 | - * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
| 1544 | - * ], |
|
| 1545 | - * public => bool |
|
| 1546 | - * mail => bool |
|
| 1547 | - * ] |
|
| 1548 | - * |
|
| 1549 | - * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
| 1550 | - * [ |
|
| 1551 | - * users => ['user1', 'user2', 'user4'], |
|
| 1552 | - * remote => bool, |
|
| 1553 | - * public => bool |
|
| 1554 | - * mail => bool |
|
| 1555 | - * ] |
|
| 1556 | - * |
|
| 1557 | - * This is required for encryption/activity |
|
| 1558 | - * |
|
| 1559 | - * @param \OCP\Files\Node $path |
|
| 1560 | - * @param bool $recursive Should we check all parent folders as well |
|
| 1561 | - * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it) |
|
| 1562 | - * @return array |
|
| 1563 | - */ |
|
| 1564 | - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
| 1565 | - $owner = $path->getOwner(); |
|
| 1566 | - |
|
| 1567 | - if ($owner === null) { |
|
| 1568 | - return []; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - $owner = $owner->getUID(); |
|
| 1572 | - |
|
| 1573 | - if ($currentAccess) { |
|
| 1574 | - $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
| 1575 | - } else { |
|
| 1576 | - $al = ['users' => [], 'remote' => false, 'public' => false]; |
|
| 1577 | - } |
|
| 1578 | - if (!$this->userManager->userExists($owner)) { |
|
| 1579 | - return $al; |
|
| 1580 | - } |
|
| 1581 | - |
|
| 1582 | - //Get node for the owner and correct the owner in case of external storages |
|
| 1583 | - $userFolder = $this->rootFolder->getUserFolder($owner); |
|
| 1584 | - if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
| 1585 | - $nodes = $userFolder->getById($path->getId()); |
|
| 1586 | - $path = array_shift($nodes); |
|
| 1587 | - if ($path->getOwner() === null) { |
|
| 1588 | - return []; |
|
| 1589 | - } |
|
| 1590 | - $owner = $path->getOwner()->getUID(); |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - $providers = $this->factory->getAllProviders(); |
|
| 1594 | - |
|
| 1595 | - /** @var Node[] $nodes */ |
|
| 1596 | - $nodes = []; |
|
| 1597 | - |
|
| 1598 | - |
|
| 1599 | - if ($currentAccess) { |
|
| 1600 | - $ownerPath = $path->getPath(); |
|
| 1601 | - $ownerPath = explode('/', $ownerPath, 4); |
|
| 1602 | - if (count($ownerPath) < 4) { |
|
| 1603 | - $ownerPath = ''; |
|
| 1604 | - } else { |
|
| 1605 | - $ownerPath = $ownerPath[3]; |
|
| 1606 | - } |
|
| 1607 | - $al['users'][$owner] = [ |
|
| 1608 | - 'node_id' => $path->getId(), |
|
| 1609 | - 'node_path' => '/' . $ownerPath, |
|
| 1610 | - ]; |
|
| 1611 | - } else { |
|
| 1612 | - $al['users'][] = $owner; |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - // Collect all the shares |
|
| 1616 | - while ($path->getPath() !== $userFolder->getPath()) { |
|
| 1617 | - $nodes[] = $path; |
|
| 1618 | - if (!$recursive) { |
|
| 1619 | - break; |
|
| 1620 | - } |
|
| 1621 | - $path = $path->getParent(); |
|
| 1622 | - } |
|
| 1623 | - |
|
| 1624 | - foreach ($providers as $provider) { |
|
| 1625 | - $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
| 1626 | - |
|
| 1627 | - foreach ($tmp as $k => $v) { |
|
| 1628 | - if (isset($al[$k])) { |
|
| 1629 | - if (is_array($al[$k])) { |
|
| 1630 | - if ($currentAccess) { |
|
| 1631 | - $al[$k] += $v; |
|
| 1632 | - } else { |
|
| 1633 | - $al[$k] = array_merge($al[$k], $v); |
|
| 1634 | - $al[$k] = array_unique($al[$k]); |
|
| 1635 | - $al[$k] = array_values($al[$k]); |
|
| 1636 | - } |
|
| 1637 | - } else { |
|
| 1638 | - $al[$k] = $al[$k] || $v; |
|
| 1639 | - } |
|
| 1640 | - } else { |
|
| 1641 | - $al[$k] = $v; |
|
| 1642 | - } |
|
| 1643 | - } |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - return $al; |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - /** |
|
| 1650 | - * Create a new share |
|
| 1651 | - * @return \OCP\Share\IShare |
|
| 1652 | - */ |
|
| 1653 | - public function newShare() { |
|
| 1654 | - return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - /** |
|
| 1658 | - * Is the share API enabled |
|
| 1659 | - * |
|
| 1660 | - * @return bool |
|
| 1661 | - */ |
|
| 1662 | - public function shareApiEnabled() { |
|
| 1663 | - return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
| 1664 | - } |
|
| 1665 | - |
|
| 1666 | - /** |
|
| 1667 | - * Is public link sharing enabled |
|
| 1668 | - * |
|
| 1669 | - * @return bool |
|
| 1670 | - */ |
|
| 1671 | - public function shareApiAllowLinks() { |
|
| 1672 | - return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
| 1673 | - } |
|
| 1674 | - |
|
| 1675 | - /** |
|
| 1676 | - * Is password on public link requires |
|
| 1677 | - * |
|
| 1678 | - * @return bool |
|
| 1679 | - */ |
|
| 1680 | - public function shareApiLinkEnforcePassword() { |
|
| 1681 | - return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
| 1682 | - } |
|
| 1683 | - |
|
| 1684 | - /** |
|
| 1685 | - * Is default link expire date enabled |
|
| 1686 | - * |
|
| 1687 | - * @return bool |
|
| 1688 | - */ |
|
| 1689 | - public function shareApiLinkDefaultExpireDate() { |
|
| 1690 | - return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 1691 | - } |
|
| 1692 | - |
|
| 1693 | - /** |
|
| 1694 | - * Is default link expire date enforced |
|
| 1695 | - *` |
|
| 1696 | - * @return bool |
|
| 1697 | - */ |
|
| 1698 | - public function shareApiLinkDefaultExpireDateEnforced() { |
|
| 1699 | - return $this->shareApiLinkDefaultExpireDate() && |
|
| 1700 | - $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 1701 | - } |
|
| 1702 | - |
|
| 1703 | - |
|
| 1704 | - /** |
|
| 1705 | - * Number of default link expire days |
|
| 1706 | - * @return int |
|
| 1707 | - */ |
|
| 1708 | - public function shareApiLinkDefaultExpireDays() { |
|
| 1709 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 1710 | - } |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * Is default internal expire date enabled |
|
| 1714 | - * |
|
| 1715 | - * @return bool |
|
| 1716 | - */ |
|
| 1717 | - public function shareApiInternalDefaultExpireDate(): bool { |
|
| 1718 | - return $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes'; |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - /** |
|
| 1722 | - * Is default expire date enforced |
|
| 1723 | - *` |
|
| 1724 | - * @return bool |
|
| 1725 | - */ |
|
| 1726 | - public function shareApiInternalDefaultExpireDateEnforced(): bool { |
|
| 1727 | - return $this->shareApiInternalDefaultExpireDate() && |
|
| 1728 | - $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes'; |
|
| 1729 | - } |
|
| 1730 | - |
|
| 1731 | - |
|
| 1732 | - /** |
|
| 1733 | - * Number of default expire days |
|
| 1734 | - * @return int |
|
| 1735 | - */ |
|
| 1736 | - public function shareApiInternalDefaultExpireDays(): int { |
|
| 1737 | - return (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
| 1738 | - } |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * Allow public upload on link shares |
|
| 1742 | - * |
|
| 1743 | - * @return bool |
|
| 1744 | - */ |
|
| 1745 | - public function shareApiLinkAllowPublicUpload() { |
|
| 1746 | - return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
| 1747 | - } |
|
| 1748 | - |
|
| 1749 | - /** |
|
| 1750 | - * check if user can only share with group members |
|
| 1751 | - * @return bool |
|
| 1752 | - */ |
|
| 1753 | - public function shareWithGroupMembersOnly() { |
|
| 1754 | - return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - /** |
|
| 1758 | - * Check if users can share with groups |
|
| 1759 | - * @return bool |
|
| 1760 | - */ |
|
| 1761 | - public function allowGroupSharing() { |
|
| 1762 | - return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - public function allowEnumeration(): bool { |
|
| 1766 | - return $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - public function limitEnumerationToGroups(): bool { |
|
| 1770 | - return $this->allowEnumeration() && |
|
| 1771 | - $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
| 1772 | - } |
|
| 1773 | - |
|
| 1774 | - /** |
|
| 1775 | - * Copied from \OC_Util::isSharingDisabledForUser |
|
| 1776 | - * |
|
| 1777 | - * TODO: Deprecate fuction from OC_Util |
|
| 1778 | - * |
|
| 1779 | - * @param string $userId |
|
| 1780 | - * @return bool |
|
| 1781 | - */ |
|
| 1782 | - public function sharingDisabledForUser($userId) { |
|
| 1783 | - if ($userId === null) { |
|
| 1784 | - return false; |
|
| 1785 | - } |
|
| 1786 | - |
|
| 1787 | - if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
| 1788 | - return $this->sharingDisabledForUsersCache[$userId]; |
|
| 1789 | - } |
|
| 1790 | - |
|
| 1791 | - if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 1792 | - $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 1793 | - $excludedGroups = json_decode($groupsList); |
|
| 1794 | - if (is_null($excludedGroups)) { |
|
| 1795 | - $excludedGroups = explode(',', $groupsList); |
|
| 1796 | - $newValue = json_encode($excludedGroups); |
|
| 1797 | - $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 1798 | - } |
|
| 1799 | - $user = $this->userManager->get($userId); |
|
| 1800 | - $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
| 1801 | - if (!empty($usersGroups)) { |
|
| 1802 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 1803 | - // if the user is only in groups which are disabled for sharing then |
|
| 1804 | - // sharing is also disabled for the user |
|
| 1805 | - if (empty($remainingGroups)) { |
|
| 1806 | - $this->sharingDisabledForUsersCache[$userId] = true; |
|
| 1807 | - return true; |
|
| 1808 | - } |
|
| 1809 | - } |
|
| 1810 | - } |
|
| 1811 | - |
|
| 1812 | - $this->sharingDisabledForUsersCache[$userId] = false; |
|
| 1813 | - return false; |
|
| 1814 | - } |
|
| 1815 | - |
|
| 1816 | - /** |
|
| 1817 | - * @inheritdoc |
|
| 1818 | - */ |
|
| 1819 | - public function outgoingServer2ServerSharesAllowed() { |
|
| 1820 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 1821 | - } |
|
| 1822 | - |
|
| 1823 | - /** |
|
| 1824 | - * @inheritdoc |
|
| 1825 | - */ |
|
| 1826 | - public function outgoingServer2ServerGroupSharesAllowed() { |
|
| 1827 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no') === 'yes'; |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - /** |
|
| 1831 | - * @inheritdoc |
|
| 1832 | - */ |
|
| 1833 | - public function shareProviderExists($shareType) { |
|
| 1834 | - try { |
|
| 1835 | - $this->factory->getProviderForType($shareType); |
|
| 1836 | - } catch (ProviderException $e) { |
|
| 1837 | - return false; |
|
| 1838 | - } |
|
| 1839 | - |
|
| 1840 | - return true; |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - public function getAllShares(): iterable { |
|
| 1844 | - $providers = $this->factory->getAllProviders(); |
|
| 1845 | - |
|
| 1846 | - foreach ($providers as $provider) { |
|
| 1847 | - yield from $provider->getAllShares(); |
|
| 1848 | - } |
|
| 1849 | - } |
|
| 1439 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
| 1440 | + !$this->shareApiLinkAllowPublicUpload()) { |
|
| 1441 | + $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
| 1442 | + } |
|
| 1443 | + |
|
| 1444 | + return $share; |
|
| 1445 | + } |
|
| 1446 | + |
|
| 1447 | + protected function checkExpireDate($share) { |
|
| 1448 | + if ($share->isExpired()) { |
|
| 1449 | + $this->deleteShare($share); |
|
| 1450 | + throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
| 1451 | + } |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + /** |
|
| 1455 | + * Verify the password of a public share |
|
| 1456 | + * |
|
| 1457 | + * @param \OCP\Share\IShare $share |
|
| 1458 | + * @param string $password |
|
| 1459 | + * @return bool |
|
| 1460 | + */ |
|
| 1461 | + public function checkPassword(\OCP\Share\IShare $share, $password) { |
|
| 1462 | + $passwordProtected = $share->getShareType() !== IShare::TYPE_LINK |
|
| 1463 | + || $share->getShareType() !== IShare::TYPE_EMAIL |
|
| 1464 | + || $share->getShareType() !== IShare::TYPE_CIRCLE; |
|
| 1465 | + if (!$passwordProtected) { |
|
| 1466 | + //TODO maybe exception? |
|
| 1467 | + return false; |
|
| 1468 | + } |
|
| 1469 | + |
|
| 1470 | + if ($password === null || $share->getPassword() === null) { |
|
| 1471 | + return false; |
|
| 1472 | + } |
|
| 1473 | + |
|
| 1474 | + $newHash = ''; |
|
| 1475 | + if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
| 1476 | + return false; |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + if (!empty($newHash)) { |
|
| 1480 | + $share->setPassword($newHash); |
|
| 1481 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1482 | + $provider->update($share); |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + return true; |
|
| 1486 | + } |
|
| 1487 | + |
|
| 1488 | + /** |
|
| 1489 | + * @inheritdoc |
|
| 1490 | + */ |
|
| 1491 | + public function userDeleted($uid) { |
|
| 1492 | + $types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_EMAIL]; |
|
| 1493 | + |
|
| 1494 | + foreach ($types as $type) { |
|
| 1495 | + try { |
|
| 1496 | + $provider = $this->factory->getProviderForType($type); |
|
| 1497 | + } catch (ProviderException $e) { |
|
| 1498 | + continue; |
|
| 1499 | + } |
|
| 1500 | + $provider->userDeleted($uid, $type); |
|
| 1501 | + } |
|
| 1502 | + } |
|
| 1503 | + |
|
| 1504 | + /** |
|
| 1505 | + * @inheritdoc |
|
| 1506 | + */ |
|
| 1507 | + public function groupDeleted($gid) { |
|
| 1508 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 1509 | + $provider->groupDeleted($gid); |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + /** |
|
| 1513 | + * @inheritdoc |
|
| 1514 | + */ |
|
| 1515 | + public function userDeletedFromGroup($uid, $gid) { |
|
| 1516 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 1517 | + $provider->userDeletedFromGroup($uid, $gid); |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + /** |
|
| 1521 | + * Get access list to a path. This means |
|
| 1522 | + * all the users that can access a given path. |
|
| 1523 | + * |
|
| 1524 | + * Consider: |
|
| 1525 | + * -root |
|
| 1526 | + * |-folder1 (23) |
|
| 1527 | + * |-folder2 (32) |
|
| 1528 | + * |-fileA (42) |
|
| 1529 | + * |
|
| 1530 | + * fileA is shared with user1 and user1@server1 |
|
| 1531 | + * folder2 is shared with group2 (user4 is a member of group2) |
|
| 1532 | + * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
| 1533 | + * |
|
| 1534 | + * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
| 1535 | + * [ |
|
| 1536 | + * users => [ |
|
| 1537 | + * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
| 1538 | + * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
| 1539 | + * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
| 1540 | + * ], |
|
| 1541 | + * remote => [ |
|
| 1542 | + * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
| 1543 | + * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
| 1544 | + * ], |
|
| 1545 | + * public => bool |
|
| 1546 | + * mail => bool |
|
| 1547 | + * ] |
|
| 1548 | + * |
|
| 1549 | + * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
| 1550 | + * [ |
|
| 1551 | + * users => ['user1', 'user2', 'user4'], |
|
| 1552 | + * remote => bool, |
|
| 1553 | + * public => bool |
|
| 1554 | + * mail => bool |
|
| 1555 | + * ] |
|
| 1556 | + * |
|
| 1557 | + * This is required for encryption/activity |
|
| 1558 | + * |
|
| 1559 | + * @param \OCP\Files\Node $path |
|
| 1560 | + * @param bool $recursive Should we check all parent folders as well |
|
| 1561 | + * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it) |
|
| 1562 | + * @return array |
|
| 1563 | + */ |
|
| 1564 | + public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
| 1565 | + $owner = $path->getOwner(); |
|
| 1566 | + |
|
| 1567 | + if ($owner === null) { |
|
| 1568 | + return []; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + $owner = $owner->getUID(); |
|
| 1572 | + |
|
| 1573 | + if ($currentAccess) { |
|
| 1574 | + $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
| 1575 | + } else { |
|
| 1576 | + $al = ['users' => [], 'remote' => false, 'public' => false]; |
|
| 1577 | + } |
|
| 1578 | + if (!$this->userManager->userExists($owner)) { |
|
| 1579 | + return $al; |
|
| 1580 | + } |
|
| 1581 | + |
|
| 1582 | + //Get node for the owner and correct the owner in case of external storages |
|
| 1583 | + $userFolder = $this->rootFolder->getUserFolder($owner); |
|
| 1584 | + if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
| 1585 | + $nodes = $userFolder->getById($path->getId()); |
|
| 1586 | + $path = array_shift($nodes); |
|
| 1587 | + if ($path->getOwner() === null) { |
|
| 1588 | + return []; |
|
| 1589 | + } |
|
| 1590 | + $owner = $path->getOwner()->getUID(); |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + $providers = $this->factory->getAllProviders(); |
|
| 1594 | + |
|
| 1595 | + /** @var Node[] $nodes */ |
|
| 1596 | + $nodes = []; |
|
| 1597 | + |
|
| 1598 | + |
|
| 1599 | + if ($currentAccess) { |
|
| 1600 | + $ownerPath = $path->getPath(); |
|
| 1601 | + $ownerPath = explode('/', $ownerPath, 4); |
|
| 1602 | + if (count($ownerPath) < 4) { |
|
| 1603 | + $ownerPath = ''; |
|
| 1604 | + } else { |
|
| 1605 | + $ownerPath = $ownerPath[3]; |
|
| 1606 | + } |
|
| 1607 | + $al['users'][$owner] = [ |
|
| 1608 | + 'node_id' => $path->getId(), |
|
| 1609 | + 'node_path' => '/' . $ownerPath, |
|
| 1610 | + ]; |
|
| 1611 | + } else { |
|
| 1612 | + $al['users'][] = $owner; |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + // Collect all the shares |
|
| 1616 | + while ($path->getPath() !== $userFolder->getPath()) { |
|
| 1617 | + $nodes[] = $path; |
|
| 1618 | + if (!$recursive) { |
|
| 1619 | + break; |
|
| 1620 | + } |
|
| 1621 | + $path = $path->getParent(); |
|
| 1622 | + } |
|
| 1623 | + |
|
| 1624 | + foreach ($providers as $provider) { |
|
| 1625 | + $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
| 1626 | + |
|
| 1627 | + foreach ($tmp as $k => $v) { |
|
| 1628 | + if (isset($al[$k])) { |
|
| 1629 | + if (is_array($al[$k])) { |
|
| 1630 | + if ($currentAccess) { |
|
| 1631 | + $al[$k] += $v; |
|
| 1632 | + } else { |
|
| 1633 | + $al[$k] = array_merge($al[$k], $v); |
|
| 1634 | + $al[$k] = array_unique($al[$k]); |
|
| 1635 | + $al[$k] = array_values($al[$k]); |
|
| 1636 | + } |
|
| 1637 | + } else { |
|
| 1638 | + $al[$k] = $al[$k] || $v; |
|
| 1639 | + } |
|
| 1640 | + } else { |
|
| 1641 | + $al[$k] = $v; |
|
| 1642 | + } |
|
| 1643 | + } |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + return $al; |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + /** |
|
| 1650 | + * Create a new share |
|
| 1651 | + * @return \OCP\Share\IShare |
|
| 1652 | + */ |
|
| 1653 | + public function newShare() { |
|
| 1654 | + return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + /** |
|
| 1658 | + * Is the share API enabled |
|
| 1659 | + * |
|
| 1660 | + * @return bool |
|
| 1661 | + */ |
|
| 1662 | + public function shareApiEnabled() { |
|
| 1663 | + return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
| 1664 | + } |
|
| 1665 | + |
|
| 1666 | + /** |
|
| 1667 | + * Is public link sharing enabled |
|
| 1668 | + * |
|
| 1669 | + * @return bool |
|
| 1670 | + */ |
|
| 1671 | + public function shareApiAllowLinks() { |
|
| 1672 | + return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
| 1673 | + } |
|
| 1674 | + |
|
| 1675 | + /** |
|
| 1676 | + * Is password on public link requires |
|
| 1677 | + * |
|
| 1678 | + * @return bool |
|
| 1679 | + */ |
|
| 1680 | + public function shareApiLinkEnforcePassword() { |
|
| 1681 | + return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + /** |
|
| 1685 | + * Is default link expire date enabled |
|
| 1686 | + * |
|
| 1687 | + * @return bool |
|
| 1688 | + */ |
|
| 1689 | + public function shareApiLinkDefaultExpireDate() { |
|
| 1690 | + return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 1691 | + } |
|
| 1692 | + |
|
| 1693 | + /** |
|
| 1694 | + * Is default link expire date enforced |
|
| 1695 | + *` |
|
| 1696 | + * @return bool |
|
| 1697 | + */ |
|
| 1698 | + public function shareApiLinkDefaultExpireDateEnforced() { |
|
| 1699 | + return $this->shareApiLinkDefaultExpireDate() && |
|
| 1700 | + $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 1701 | + } |
|
| 1702 | + |
|
| 1703 | + |
|
| 1704 | + /** |
|
| 1705 | + * Number of default link expire days |
|
| 1706 | + * @return int |
|
| 1707 | + */ |
|
| 1708 | + public function shareApiLinkDefaultExpireDays() { |
|
| 1709 | + return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 1710 | + } |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * Is default internal expire date enabled |
|
| 1714 | + * |
|
| 1715 | + * @return bool |
|
| 1716 | + */ |
|
| 1717 | + public function shareApiInternalDefaultExpireDate(): bool { |
|
| 1718 | + return $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes'; |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + /** |
|
| 1722 | + * Is default expire date enforced |
|
| 1723 | + *` |
|
| 1724 | + * @return bool |
|
| 1725 | + */ |
|
| 1726 | + public function shareApiInternalDefaultExpireDateEnforced(): bool { |
|
| 1727 | + return $this->shareApiInternalDefaultExpireDate() && |
|
| 1728 | + $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes'; |
|
| 1729 | + } |
|
| 1730 | + |
|
| 1731 | + |
|
| 1732 | + /** |
|
| 1733 | + * Number of default expire days |
|
| 1734 | + * @return int |
|
| 1735 | + */ |
|
| 1736 | + public function shareApiInternalDefaultExpireDays(): int { |
|
| 1737 | + return (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
| 1738 | + } |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * Allow public upload on link shares |
|
| 1742 | + * |
|
| 1743 | + * @return bool |
|
| 1744 | + */ |
|
| 1745 | + public function shareApiLinkAllowPublicUpload() { |
|
| 1746 | + return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
| 1747 | + } |
|
| 1748 | + |
|
| 1749 | + /** |
|
| 1750 | + * check if user can only share with group members |
|
| 1751 | + * @return bool |
|
| 1752 | + */ |
|
| 1753 | + public function shareWithGroupMembersOnly() { |
|
| 1754 | + return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + /** |
|
| 1758 | + * Check if users can share with groups |
|
| 1759 | + * @return bool |
|
| 1760 | + */ |
|
| 1761 | + public function allowGroupSharing() { |
|
| 1762 | + return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + public function allowEnumeration(): bool { |
|
| 1766 | + return $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + public function limitEnumerationToGroups(): bool { |
|
| 1770 | + return $this->allowEnumeration() && |
|
| 1771 | + $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
| 1772 | + } |
|
| 1773 | + |
|
| 1774 | + /** |
|
| 1775 | + * Copied from \OC_Util::isSharingDisabledForUser |
|
| 1776 | + * |
|
| 1777 | + * TODO: Deprecate fuction from OC_Util |
|
| 1778 | + * |
|
| 1779 | + * @param string $userId |
|
| 1780 | + * @return bool |
|
| 1781 | + */ |
|
| 1782 | + public function sharingDisabledForUser($userId) { |
|
| 1783 | + if ($userId === null) { |
|
| 1784 | + return false; |
|
| 1785 | + } |
|
| 1786 | + |
|
| 1787 | + if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
| 1788 | + return $this->sharingDisabledForUsersCache[$userId]; |
|
| 1789 | + } |
|
| 1790 | + |
|
| 1791 | + if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 1792 | + $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 1793 | + $excludedGroups = json_decode($groupsList); |
|
| 1794 | + if (is_null($excludedGroups)) { |
|
| 1795 | + $excludedGroups = explode(',', $groupsList); |
|
| 1796 | + $newValue = json_encode($excludedGroups); |
|
| 1797 | + $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 1798 | + } |
|
| 1799 | + $user = $this->userManager->get($userId); |
|
| 1800 | + $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
| 1801 | + if (!empty($usersGroups)) { |
|
| 1802 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 1803 | + // if the user is only in groups which are disabled for sharing then |
|
| 1804 | + // sharing is also disabled for the user |
|
| 1805 | + if (empty($remainingGroups)) { |
|
| 1806 | + $this->sharingDisabledForUsersCache[$userId] = true; |
|
| 1807 | + return true; |
|
| 1808 | + } |
|
| 1809 | + } |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + $this->sharingDisabledForUsersCache[$userId] = false; |
|
| 1813 | + return false; |
|
| 1814 | + } |
|
| 1815 | + |
|
| 1816 | + /** |
|
| 1817 | + * @inheritdoc |
|
| 1818 | + */ |
|
| 1819 | + public function outgoingServer2ServerSharesAllowed() { |
|
| 1820 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 1821 | + } |
|
| 1822 | + |
|
| 1823 | + /** |
|
| 1824 | + * @inheritdoc |
|
| 1825 | + */ |
|
| 1826 | + public function outgoingServer2ServerGroupSharesAllowed() { |
|
| 1827 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no') === 'yes'; |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + /** |
|
| 1831 | + * @inheritdoc |
|
| 1832 | + */ |
|
| 1833 | + public function shareProviderExists($shareType) { |
|
| 1834 | + try { |
|
| 1835 | + $this->factory->getProviderForType($shareType); |
|
| 1836 | + } catch (ProviderException $e) { |
|
| 1837 | + return false; |
|
| 1838 | + } |
|
| 1839 | + |
|
| 1840 | + return true; |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + public function getAllShares(): iterable { |
|
| 1844 | + $providers = $this->factory->getAllProviders(); |
|
| 1845 | + |
|
| 1846 | + foreach ($providers as $provider) { |
|
| 1847 | + yield from $provider->getAllShares(); |
|
| 1848 | + } |
|
| 1849 | + } |
|
| 1850 | 1850 | } |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | |
| 396 | 396 | if ($fullId === null && $expirationDate === null && $this->shareApiInternalDefaultExpireDate()) { |
| 397 | 397 | $expirationDate = new \DateTime(); |
| 398 | - $expirationDate->setTime(0,0,0); |
|
| 398 | + $expirationDate->setTime(0, 0, 0); |
|
| 399 | 399 | $expirationDate->add(new \DateInterval('P'.$this->shareApiInternalDefaultExpireDays().'D')); |
| 400 | 400 | } |
| 401 | 401 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | |
| 408 | 408 | $date = new \DateTime(); |
| 409 | 409 | $date->setTime(0, 0, 0); |
| 410 | - $date->add(new \DateInterval('P' . $this->shareApiInternalDefaultExpireDays() . 'D')); |
|
| 410 | + $date->add(new \DateInterval('P'.$this->shareApiInternalDefaultExpireDays().'D')); |
|
| 411 | 411 | if ($date < $expirationDate) { |
| 412 | 412 | $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiInternalDefaultExpireDays()]); |
| 413 | 413 | throw new GenericShareException($message, $message, 404); |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | |
| 467 | 467 | if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
| 468 | 468 | $expirationDate = new \DateTime(); |
| 469 | - $expirationDate->setTime(0,0,0); |
|
| 469 | + $expirationDate->setTime(0, 0, 0); |
|
| 470 | 470 | $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
| 471 | 471 | } |
| 472 | 472 | |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | |
| 479 | 479 | $date = new \DateTime(); |
| 480 | 480 | $date->setTime(0, 0, 0); |
| 481 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
| 481 | + $date->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
| 482 | 482 | if ($date < $expirationDate) { |
| 483 | 483 | $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
| 484 | 484 | throw new GenericShareException($message, $message, 404); |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | // Generate the target |
| 771 | - $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
| 771 | + $target = $this->config->getSystemValue('share_folder', '/').'/'.$share->getNode()->getName(); |
|
| 772 | 772 | $target = \OC\Files\Filesystem::normalizePath($target); |
| 773 | 773 | $share->setTarget($target); |
| 774 | 774 | |
@@ -813,12 +813,12 @@ discard block |
||
| 813 | 813 | $emailAddress, |
| 814 | 814 | $share->getExpirationDate() |
| 815 | 815 | ); |
| 816 | - $this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
| 816 | + $this->logger->debug('Sent share notification to '.$emailAddress.' for share with ID '.$share->getId(), ['app' => 'share']); |
|
| 817 | 817 | } else { |
| 818 | - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
| 818 | + $this->logger->debug('Share notification not sent to '.$share->getSharedWith().' because email address is not set.', ['app' => 'share']); |
|
| 819 | 819 | } |
| 820 | 820 | } else { |
| 821 | - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
| 821 | + $this->logger->debug('Share notification not sent to '.$share->getSharedWith().' because user could not be found.', ['app' => 'share']); |
|
| 822 | 822 | } |
| 823 | 823 | } else { |
| 824 | 824 | $this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']); |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | $text = $l->t('%1$s shared »%2$s« with you.', [$initiatorDisplayName, $filename]); |
| 866 | 866 | |
| 867 | 867 | $emailTemplate->addBodyText( |
| 868 | - htmlspecialchars($text . ' ' . $l->t('Click the button below to open it.')), |
|
| 868 | + htmlspecialchars($text.' '.$l->t('Click the button below to open it.')), |
|
| 869 | 869 | $text |
| 870 | 870 | ); |
| 871 | 871 | $emailTemplate->addBodyButton( |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | $initiatorEmail = $initiatorUser->getEMailAddress(); |
| 892 | 892 | if ($initiatorEmail !== null) { |
| 893 | 893 | $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
| 894 | - $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : '')); |
|
| 894 | + $emailTemplate->addFooter($instanceName.($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - '.$this->defaults->getSlogan($l->getLanguageCode()) : '')); |
|
| 895 | 895 | } else { |
| 896 | 896 | $emailTemplate->addFooter('', $l->getLanguageCode()); |
| 897 | 897 | } |
@@ -900,7 +900,7 @@ discard block |
||
| 900 | 900 | try { |
| 901 | 901 | $failedRecipients = $this->mailer->send($message); |
| 902 | 902 | if (!empty($failedRecipients)) { |
| 903 | - $this->logger->error('Share notification mail could not be sent to: ' . implode(', ', $failedRecipients)); |
|
| 903 | + $this->logger->error('Share notification mail could not be sent to: '.implode(', ', $failedRecipients)); |
|
| 904 | 904 | return; |
| 905 | 905 | } |
| 906 | 906 | } catch (\Exception $e) { |
@@ -1153,7 +1153,7 @@ discard block |
||
| 1153 | 1153 | * @param string $recipientId |
| 1154 | 1154 | */ |
| 1155 | 1155 | public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
| 1156 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 1156 | + list($providerId,) = $this->splitFullId($share->getFullId()); |
|
| 1157 | 1157 | $provider = $this->factory->getProvider($providerId); |
| 1158 | 1158 | |
| 1159 | 1159 | $provider->deleteFromSelf($share, $recipientId); |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | 1164 | public function restoreShare(IShare $share, string $recipientId): IShare { |
| 1165 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 1165 | + list($providerId,) = $this->splitFullId($share->getFullId()); |
|
| 1166 | 1166 | $provider = $this->factory->getProvider($providerId); |
| 1167 | 1167 | |
| 1168 | 1168 | return $provider->restore($share, $recipientId); |
@@ -1183,7 +1183,7 @@ discard block |
||
| 1183 | 1183 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
| 1184 | 1184 | $sharedWith = $this->groupManager->get($share->getSharedWith()); |
| 1185 | 1185 | if (is_null($sharedWith)) { |
| 1186 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
| 1186 | + throw new \InvalidArgumentException('Group "'.$share->getSharedWith().'" does not exist'); |
|
| 1187 | 1187 | } |
| 1188 | 1188 | $recipient = $this->userManager->get($recipientId); |
| 1189 | 1189 | if (!$sharedWith->inGroup($recipient)) { |
@@ -1191,7 +1191,7 @@ discard block |
||
| 1191 | 1191 | } |
| 1192 | 1192 | } |
| 1193 | 1193 | |
| 1194 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 1194 | + list($providerId,) = $this->splitFullId($share->getFullId()); |
|
| 1195 | 1195 | $provider = $this->factory->getProvider($providerId); |
| 1196 | 1196 | |
| 1197 | 1197 | $provider->move($share, $recipientId); |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
| 1201 | 1201 | $providers = $this->factory->getAllProviders(); |
| 1202 | 1202 | |
| 1203 | - return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
| 1203 | + return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
| 1204 | 1204 | $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
| 1205 | 1205 | foreach ($newShares as $fid => $data) { |
| 1206 | 1206 | if (!isset($shares[$fid])) { |
@@ -1317,12 +1317,12 @@ discard block |
||
| 1317 | 1317 | $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); |
| 1318 | 1318 | |
| 1319 | 1319 | // Only get deleted shares |
| 1320 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 1320 | + $shares = array_filter($shares, function(IShare $share) { |
|
| 1321 | 1321 | return $share->getPermissions() === 0; |
| 1322 | 1322 | }); |
| 1323 | 1323 | |
| 1324 | 1324 | // Only get shares where the owner still exists |
| 1325 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 1325 | + $shares = array_filter($shares, function(IShare $share) { |
|
| 1326 | 1326 | return $this->userManager->userExists($share->getShareOwner()); |
| 1327 | 1327 | }); |
| 1328 | 1328 | |
@@ -1361,7 +1361,7 @@ discard block |
||
| 1361 | 1361 | * |
| 1362 | 1362 | * @return Share[] |
| 1363 | 1363 | */ |
| 1364 | - public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
| 1364 | + public function getSharesByPath(\OCP\Files\Node $path, $page = 0, $perPage = 50) { |
|
| 1365 | 1365 | return []; |
| 1366 | 1366 | } |
| 1367 | 1367 | |
@@ -1606,7 +1606,7 @@ discard block |
||
| 1606 | 1606 | } |
| 1607 | 1607 | $al['users'][$owner] = [ |
| 1608 | 1608 | 'node_id' => $path->getId(), |
| 1609 | - 'node_path' => '/' . $ownerPath, |
|
| 1609 | + 'node_path' => '/'.$ownerPath, |
|
| 1610 | 1610 | ]; |
| 1611 | 1611 | } else { |
| 1612 | 1612 | $al['users'][] = $owner; |
@@ -1706,7 +1706,7 @@ discard block |
||
| 1706 | 1706 | * @return int |
| 1707 | 1707 | */ |
| 1708 | 1708 | public function shareApiLinkDefaultExpireDays() { |
| 1709 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 1709 | + return (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 1710 | 1710 | } |
| 1711 | 1711 | |
| 1712 | 1712 | /** |
@@ -1734,7 +1734,7 @@ discard block |
||
| 1734 | 1734 | * @return int |
| 1735 | 1735 | */ |
| 1736 | 1736 | public function shareApiInternalDefaultExpireDays(): int { |
| 1737 | - return (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
| 1737 | + return (int) $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | 1740 | /** |
@@ -242,2011 +242,2011 @@ |
||
| 242 | 242 | * TODO: hookup all manager classes |
| 243 | 243 | */ |
| 244 | 244 | class Server extends ServerContainer implements IServerContainer { |
| 245 | - /** @var string */ |
|
| 246 | - private $webRoot; |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @param string $webRoot |
|
| 250 | - * @param \OC\Config $config |
|
| 251 | - */ |
|
| 252 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 253 | - parent::__construct(); |
|
| 254 | - $this->webRoot = $webRoot; |
|
| 255 | - |
|
| 256 | - // To find out if we are running from CLI or not |
|
| 257 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 258 | - |
|
| 259 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 260 | - return $c; |
|
| 261 | - }); |
|
| 262 | - |
|
| 263 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 264 | - $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 265 | - |
|
| 266 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 267 | - $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
| 268 | - |
|
| 269 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 270 | - $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
| 271 | - |
|
| 272 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 273 | - $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 274 | - |
|
| 275 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 276 | - |
|
| 277 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - $this->registerService(IPreview::class, function (Server $c) { |
|
| 281 | - return new PreviewManager( |
|
| 282 | - $c->getConfig(), |
|
| 283 | - $c->getRootFolder(), |
|
| 284 | - $c->getAppDataDir('preview'), |
|
| 285 | - $c->getEventDispatcher(), |
|
| 286 | - $c->getGeneratorHelper(), |
|
| 287 | - $c->getSession()->get('user_id') |
|
| 288 | - ); |
|
| 289 | - }); |
|
| 290 | - $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
| 291 | - |
|
| 292 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 293 | - return new \OC\Preview\Watcher( |
|
| 294 | - $c->getAppDataDir('preview') |
|
| 295 | - ); |
|
| 296 | - }); |
|
| 297 | - |
|
| 298 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 299 | - $view = new View(); |
|
| 300 | - $util = new Encryption\Util( |
|
| 301 | - $view, |
|
| 302 | - $c->getUserManager(), |
|
| 303 | - $c->getGroupManager(), |
|
| 304 | - $c->getConfig() |
|
| 305 | - ); |
|
| 306 | - return new Encryption\Manager( |
|
| 307 | - $c->getConfig(), |
|
| 308 | - $c->getLogger(), |
|
| 309 | - $c->getL10N('core'), |
|
| 310 | - new View(), |
|
| 311 | - $util, |
|
| 312 | - new ArrayCache() |
|
| 313 | - ); |
|
| 314 | - }); |
|
| 315 | - $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
| 316 | - |
|
| 317 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 318 | - $util = new Encryption\Util( |
|
| 319 | - new View(), |
|
| 320 | - $c->getUserManager(), |
|
| 321 | - $c->getGroupManager(), |
|
| 322 | - $c->getConfig() |
|
| 323 | - ); |
|
| 324 | - return new Encryption\File( |
|
| 325 | - $util, |
|
| 326 | - $c->getRootFolder(), |
|
| 327 | - $c->getShareManager() |
|
| 328 | - ); |
|
| 329 | - }); |
|
| 330 | - |
|
| 331 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 332 | - $view = new View(); |
|
| 333 | - $util = new Encryption\Util( |
|
| 334 | - $view, |
|
| 335 | - $c->getUserManager(), |
|
| 336 | - $c->getGroupManager(), |
|
| 337 | - $c->getConfig() |
|
| 338 | - ); |
|
| 339 | - |
|
| 340 | - return new Encryption\Keys\Storage($view, $util); |
|
| 341 | - }); |
|
| 342 | - $this->registerService('TagMapper', function (Server $c) { |
|
| 343 | - return new TagMapper($c->getDatabaseConnection()); |
|
| 344 | - }); |
|
| 345 | - |
|
| 346 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 347 | - $tagMapper = $c->query('TagMapper'); |
|
| 348 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
| 349 | - }); |
|
| 350 | - $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
| 351 | - |
|
| 352 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 353 | - $config = $c->getConfig(); |
|
| 354 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 355 | - return new $factoryClass($this); |
|
| 356 | - }); |
|
| 357 | - $this->registerService(ISystemTagManager::class, function (Server $c) { |
|
| 358 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 359 | - }); |
|
| 360 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 361 | - |
|
| 362 | - $this->registerService(ISystemTagObjectMapper::class, function (Server $c) { |
|
| 363 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 364 | - }); |
|
| 365 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 366 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 367 | - $view = new View(); |
|
| 368 | - $root = new Root( |
|
| 369 | - $manager, |
|
| 370 | - $view, |
|
| 371 | - null, |
|
| 372 | - $c->getUserMountCache(), |
|
| 373 | - $this->getLogger(), |
|
| 374 | - $this->getUserManager() |
|
| 375 | - ); |
|
| 376 | - $connector = new HookConnector($root, $view, $c->getEventDispatcher()); |
|
| 377 | - $connector->viewToNode(); |
|
| 378 | - |
|
| 379 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 380 | - $previewConnector->connectWatcher(); |
|
| 381 | - |
|
| 382 | - return $root; |
|
| 383 | - }); |
|
| 384 | - $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
| 385 | - |
|
| 386 | - $this->registerService(IRootFolder::class, function (Server $c) { |
|
| 387 | - return new LazyRoot(function () use ($c) { |
|
| 388 | - return $c->query('RootFolder'); |
|
| 389 | - }); |
|
| 390 | - }); |
|
| 391 | - $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
| 392 | - |
|
| 393 | - $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
| 394 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 395 | - |
|
| 396 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 397 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
| 398 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 399 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]); |
|
| 400 | - |
|
| 401 | - /** @var IEventDispatcher $dispatcher */ |
|
| 402 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 403 | - $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
| 404 | - }); |
|
| 405 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
| 406 | - \OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $group->getGID()]); |
|
| 407 | - |
|
| 408 | - /** @var IEventDispatcher $dispatcher */ |
|
| 409 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 410 | - $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
| 411 | - }); |
|
| 412 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 413 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]); |
|
| 414 | - |
|
| 415 | - /** @var IEventDispatcher $dispatcher */ |
|
| 416 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 417 | - $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
| 418 | - }); |
|
| 419 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 420 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]); |
|
| 421 | - |
|
| 422 | - /** @var IEventDispatcher $dispatcher */ |
|
| 423 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 424 | - $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
| 425 | - }); |
|
| 426 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 427 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 428 | - |
|
| 429 | - /** @var IEventDispatcher $dispatcher */ |
|
| 430 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 431 | - $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
| 432 | - }); |
|
| 433 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 434 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 435 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 436 | - \OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 437 | - |
|
| 438 | - /** @var IEventDispatcher $dispatcher */ |
|
| 439 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 440 | - $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
| 441 | - }); |
|
| 442 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 443 | - /** @var IEventDispatcher $dispatcher */ |
|
| 444 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 445 | - $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
| 446 | - }); |
|
| 447 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 448 | - /** @var IEventDispatcher $dispatcher */ |
|
| 449 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 450 | - $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
| 451 | - }); |
|
| 452 | - return $groupManager; |
|
| 453 | - }); |
|
| 454 | - $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 455 | - |
|
| 456 | - $this->registerService(Store::class, function (Server $c) { |
|
| 457 | - $session = $c->getSession(); |
|
| 458 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 459 | - $tokenProvider = $c->query(IProvider::class); |
|
| 460 | - } else { |
|
| 461 | - $tokenProvider = null; |
|
| 462 | - } |
|
| 463 | - $logger = $c->getLogger(); |
|
| 464 | - return new Store($session, $logger, $tokenProvider); |
|
| 465 | - }); |
|
| 466 | - $this->registerAlias(IStore::class, Store::class); |
|
| 467 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
| 468 | - $dbConnection = $c->getDatabaseConnection(); |
|
| 469 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
| 470 | - }); |
|
| 471 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 472 | - |
|
| 473 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 474 | - $manager = $c->getUserManager(); |
|
| 475 | - $session = new \OC\Session\Memory(''); |
|
| 476 | - $timeFactory = new TimeFactory(); |
|
| 477 | - // Token providers might require a working database. This code |
|
| 478 | - // might however be called when ownCloud is not yet setup. |
|
| 479 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 480 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
| 481 | - } else { |
|
| 482 | - $defaultTokenProvider = null; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - $legacyDispatcher = $c->getEventDispatcher(); |
|
| 486 | - |
|
| 487 | - $userSession = new \OC\User\Session( |
|
| 488 | - $manager, |
|
| 489 | - $session, |
|
| 490 | - $timeFactory, |
|
| 491 | - $defaultTokenProvider, |
|
| 492 | - $c->getConfig(), |
|
| 493 | - $c->getSecureRandom(), |
|
| 494 | - $c->getLockdownManager(), |
|
| 495 | - $c->getLogger(), |
|
| 496 | - $c->query(IEventDispatcher::class) |
|
| 497 | - ); |
|
| 498 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 499 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 500 | - |
|
| 501 | - /** @var IEventDispatcher $dispatcher */ |
|
| 502 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 503 | - $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password)); |
|
| 504 | - }); |
|
| 505 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 506 | - /** @var $user \OC\User\User */ |
|
| 507 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 508 | - |
|
| 509 | - /** @var IEventDispatcher $dispatcher */ |
|
| 510 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 511 | - $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); |
|
| 512 | - }); |
|
| 513 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
| 514 | - /** @var $user \OC\User\User */ |
|
| 515 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 516 | - $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 517 | - |
|
| 518 | - /** @var IEventDispatcher $dispatcher */ |
|
| 519 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 520 | - $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user)); |
|
| 521 | - }); |
|
| 522 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 523 | - /** @var $user \OC\User\User */ |
|
| 524 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 525 | - |
|
| 526 | - /** @var IEventDispatcher $dispatcher */ |
|
| 527 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 528 | - $dispatcher->dispatchTyped(new UserDeletedEvent($user)); |
|
| 529 | - }); |
|
| 530 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 531 | - /** @var $user \OC\User\User */ |
|
| 532 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 533 | - |
|
| 534 | - /** @var IEventDispatcher $dispatcher */ |
|
| 535 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 536 | - $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 537 | - }); |
|
| 538 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 539 | - /** @var $user \OC\User\User */ |
|
| 540 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 541 | - |
|
| 542 | - /** @var IEventDispatcher $dispatcher */ |
|
| 543 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 544 | - $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 545 | - }); |
|
| 546 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 547 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 548 | - |
|
| 549 | - /** @var IEventDispatcher $dispatcher */ |
|
| 550 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 551 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 552 | - }); |
|
| 553 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
| 554 | - /** @var $user \OC\User\User */ |
|
| 555 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 556 | - |
|
| 557 | - /** @var IEventDispatcher $dispatcher */ |
|
| 558 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 559 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); |
|
| 560 | - }); |
|
| 561 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 562 | - /** @var IEventDispatcher $dispatcher */ |
|
| 563 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 564 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 565 | - }); |
|
| 566 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 567 | - /** @var $user \OC\User\User */ |
|
| 568 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 569 | - |
|
| 570 | - /** @var IEventDispatcher $dispatcher */ |
|
| 571 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 572 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 573 | - }); |
|
| 574 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 575 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
| 576 | - |
|
| 577 | - /** @var IEventDispatcher $dispatcher */ |
|
| 578 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 579 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 580 | - }); |
|
| 581 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 582 | - /** @var IEventDispatcher $dispatcher */ |
|
| 583 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 584 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 585 | - }); |
|
| 586 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 587 | - /** @var $user \OC\User\User */ |
|
| 588 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 589 | - |
|
| 590 | - /** @var IEventDispatcher $dispatcher */ |
|
| 591 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 592 | - $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
| 593 | - }); |
|
| 594 | - return $userSession; |
|
| 595 | - }); |
|
| 596 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 597 | - $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
| 598 | - |
|
| 599 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 600 | - |
|
| 601 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 602 | - $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
| 603 | - |
|
| 604 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 605 | - return new \OC\AllConfig( |
|
| 606 | - $c->getSystemConfig() |
|
| 607 | - ); |
|
| 608 | - }); |
|
| 609 | - $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
| 610 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 611 | - |
|
| 612 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 613 | - return new \OC\SystemConfig($config); |
|
| 614 | - }); |
|
| 615 | - $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
| 616 | - |
|
| 617 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 618 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 619 | - }); |
|
| 620 | - $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
| 621 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 622 | - |
|
| 623 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 624 | - return new \OC\L10N\Factory( |
|
| 625 | - $c->getConfig(), |
|
| 626 | - $c->getRequest(), |
|
| 627 | - $c->getUserSession(), |
|
| 628 | - \OC::$SERVERROOT |
|
| 629 | - ); |
|
| 630 | - }); |
|
| 631 | - $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
| 632 | - |
|
| 633 | - $this->registerService(IURLGenerator::class, function (Server $c) { |
|
| 634 | - $config = $c->getConfig(); |
|
| 635 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 636 | - $request = $c->getRequest(); |
|
| 637 | - return new \OC\URLGenerator( |
|
| 638 | - $config, |
|
| 639 | - $cacheFactory, |
|
| 640 | - $request |
|
| 641 | - ); |
|
| 642 | - }); |
|
| 643 | - $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
| 644 | - |
|
| 645 | - $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
| 646 | - $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 647 | - |
|
| 648 | - $this->registerService(ICache::class, function ($c) { |
|
| 649 | - return new Cache\File(); |
|
| 650 | - }); |
|
| 651 | - $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
| 652 | - |
|
| 653 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 654 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 655 | - ArrayCache::class, |
|
| 656 | - ArrayCache::class, |
|
| 657 | - ArrayCache::class |
|
| 658 | - ); |
|
| 659 | - $config = $c->getConfig(); |
|
| 660 | - |
|
| 661 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 662 | - $v = \OC_App::getAppVersions(); |
|
| 663 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 664 | - $version = implode(',', $v); |
|
| 665 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 666 | - $path = \OC::$SERVERROOT; |
|
| 667 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 668 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 669 | - $config->getSystemValue('memcache.local', null), |
|
| 670 | - $config->getSystemValue('memcache.distributed', null), |
|
| 671 | - $config->getSystemValue('memcache.locking', null) |
|
| 672 | - ); |
|
| 673 | - } |
|
| 674 | - return $arrayCacheFactory; |
|
| 675 | - }); |
|
| 676 | - $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
| 677 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 678 | - |
|
| 679 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 680 | - $systemConfig = $c->getSystemConfig(); |
|
| 681 | - return new RedisFactory($systemConfig); |
|
| 682 | - }); |
|
| 683 | - |
|
| 684 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 685 | - return new \OC\Activity\Manager( |
|
| 686 | - $c->getRequest(), |
|
| 687 | - $c->getUserSession(), |
|
| 688 | - $c->getConfig(), |
|
| 689 | - $c->query(IValidator::class) |
|
| 690 | - ); |
|
| 691 | - }); |
|
| 692 | - $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 693 | - |
|
| 694 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 695 | - return new \OC\Activity\EventMerger( |
|
| 696 | - $c->getL10N('lib') |
|
| 697 | - ); |
|
| 698 | - }); |
|
| 699 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 700 | - |
|
| 701 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 702 | - return new AvatarManager( |
|
| 703 | - $c->query(\OC\User\Manager::class), |
|
| 704 | - $c->getAppDataDir('avatar'), |
|
| 705 | - $c->getL10N('lib'), |
|
| 706 | - $c->getLogger(), |
|
| 707 | - $c->getConfig() |
|
| 708 | - ); |
|
| 709 | - }); |
|
| 710 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 711 | - $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
| 712 | - |
|
| 713 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 714 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 715 | - |
|
| 716 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 717 | - $logType = $c->query(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 718 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
| 719 | - $logger = $factory->get($logType); |
|
| 720 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
| 721 | - |
|
| 722 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
| 723 | - }); |
|
| 724 | - $this->registerAlias(ILogger::class, \OC\Log::class); |
|
| 725 | - $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
| 726 | - // PSR-3 logger |
|
| 727 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 728 | - |
|
| 729 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 730 | - return new LogFactory($c, $this->getSystemConfig()); |
|
| 731 | - }); |
|
| 732 | - |
|
| 733 | - $this->registerService(IJobList::class, function (Server $c) { |
|
| 734 | - $config = $c->getConfig(); |
|
| 735 | - return new \OC\BackgroundJob\JobList( |
|
| 736 | - $c->getDatabaseConnection(), |
|
| 737 | - $config, |
|
| 738 | - new TimeFactory() |
|
| 739 | - ); |
|
| 740 | - }); |
|
| 741 | - $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
| 742 | - |
|
| 743 | - $this->registerService(IRouter::class, function (Server $c) { |
|
| 744 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 745 | - $logger = $c->getLogger(); |
|
| 746 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 747 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 748 | - } else { |
|
| 749 | - $router = new \OC\Route\Router($logger); |
|
| 750 | - } |
|
| 751 | - return $router; |
|
| 752 | - }); |
|
| 753 | - $this->registerDeprecatedAlias('Router', IRouter::class); |
|
| 754 | - |
|
| 755 | - $this->registerService(ISearch::class, function ($c) { |
|
| 756 | - return new Search(); |
|
| 757 | - }); |
|
| 758 | - $this->registerDeprecatedAlias('Search', ISearch::class); |
|
| 759 | - |
|
| 760 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 761 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 762 | - $this->getMemCacheFactory(), |
|
| 763 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 764 | - ); |
|
| 765 | - }); |
|
| 766 | - |
|
| 767 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 768 | - return new SecureRandom(); |
|
| 769 | - }); |
|
| 770 | - $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 771 | - |
|
| 772 | - $this->registerService(ICrypto::class, function (Server $c) { |
|
| 773 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 774 | - }); |
|
| 775 | - $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
| 776 | - |
|
| 777 | - $this->registerService(IHasher::class, function (Server $c) { |
|
| 778 | - return new Hasher($c->getConfig()); |
|
| 779 | - }); |
|
| 780 | - $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
| 781 | - |
|
| 782 | - $this->registerService(ICredentialsManager::class, function (Server $c) { |
|
| 783 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 784 | - }); |
|
| 785 | - $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
| 786 | - |
|
| 787 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 788 | - $systemConfig = $c->getSystemConfig(); |
|
| 789 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 790 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 791 | - if (!$factory->isValidType($type)) { |
|
| 792 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 793 | - } |
|
| 794 | - $connectionParams = $factory->createConnectionParams(); |
|
| 795 | - $connection = $factory->getConnection($type, $connectionParams); |
|
| 796 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 797 | - return $connection; |
|
| 798 | - }); |
|
| 799 | - $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
| 800 | - |
|
| 801 | - |
|
| 802 | - $this->registerService(IClientService::class, function (Server $c) { |
|
| 803 | - $user = \OC_User::getUser(); |
|
| 804 | - $uid = $user ? $user : null; |
|
| 805 | - return new ClientService( |
|
| 806 | - $c->getConfig(), |
|
| 807 | - $c->getLogger(), |
|
| 808 | - new \OC\Security\CertificateManager( |
|
| 809 | - $uid, |
|
| 810 | - new View(), |
|
| 811 | - $c->getConfig(), |
|
| 812 | - $c->getLogger(), |
|
| 813 | - $c->getSecureRandom() |
|
| 814 | - ) |
|
| 815 | - ); |
|
| 816 | - }); |
|
| 817 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 818 | - $this->registerService(IEventLogger::class, function (Server $c) { |
|
| 819 | - $eventLogger = new EventLogger(); |
|
| 820 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 821 | - // In debug mode, module is being activated by default |
|
| 822 | - $eventLogger->activate(); |
|
| 823 | - } |
|
| 824 | - return $eventLogger; |
|
| 825 | - }); |
|
| 826 | - $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
| 827 | - |
|
| 828 | - $this->registerService(IQueryLogger::class, function (Server $c) { |
|
| 829 | - $queryLogger = new QueryLogger(); |
|
| 830 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 831 | - // In debug mode, module is being activated by default |
|
| 832 | - $queryLogger->activate(); |
|
| 833 | - } |
|
| 834 | - return $queryLogger; |
|
| 835 | - }); |
|
| 836 | - $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
| 837 | - |
|
| 838 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 839 | - return new TempManager( |
|
| 840 | - $c->getLogger(), |
|
| 841 | - $c->getConfig() |
|
| 842 | - ); |
|
| 843 | - }); |
|
| 844 | - $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
| 845 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 846 | - |
|
| 847 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 848 | - return new \OC\App\AppManager( |
|
| 849 | - $c->getUserSession(), |
|
| 850 | - $c->getConfig(), |
|
| 851 | - $c->query(\OC\AppConfig::class), |
|
| 852 | - $c->getGroupManager(), |
|
| 853 | - $c->getMemCacheFactory(), |
|
| 854 | - $c->getEventDispatcher(), |
|
| 855 | - $c->getLogger() |
|
| 856 | - ); |
|
| 857 | - }); |
|
| 858 | - $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
| 859 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 860 | - |
|
| 861 | - $this->registerService(IDateTimeZone::class, function (Server $c) { |
|
| 862 | - return new DateTimeZone( |
|
| 863 | - $c->getConfig(), |
|
| 864 | - $c->getSession() |
|
| 865 | - ); |
|
| 866 | - }); |
|
| 867 | - $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
| 868 | - |
|
| 869 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 870 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 871 | - |
|
| 872 | - return new DateTimeFormatter( |
|
| 873 | - $c->getDateTimeZone()->getTimeZone(), |
|
| 874 | - $c->getL10N('lib', $language) |
|
| 875 | - ); |
|
| 876 | - }); |
|
| 877 | - $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
| 878 | - |
|
| 879 | - $this->registerService(IUserMountCache::class, function (Server $c) { |
|
| 880 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 881 | - $listener = new UserMountCacheListener($mountCache); |
|
| 882 | - $listener->listen($c->getUserManager()); |
|
| 883 | - return $mountCache; |
|
| 884 | - }); |
|
| 885 | - $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
| 886 | - |
|
| 887 | - $this->registerService(IMountProviderCollection::class, function (Server $c) { |
|
| 888 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
| 889 | - $mountCache = $c->query(IUserMountCache::class); |
|
| 890 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 891 | - |
|
| 892 | - // builtin providers |
|
| 893 | - |
|
| 894 | - $config = $c->getConfig(); |
|
| 895 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 896 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 897 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 898 | - |
|
| 899 | - return $manager; |
|
| 900 | - }); |
|
| 901 | - $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
| 902 | - |
|
| 903 | - $this->registerService('IniWrapper', function ($c) { |
|
| 904 | - return new IniGetWrapper(); |
|
| 905 | - }); |
|
| 906 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 907 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
| 908 | - if ($busClass) { |
|
| 909 | - list($app, $class) = explode('::', $busClass, 2); |
|
| 910 | - if ($c->getAppManager()->isInstalled($app)) { |
|
| 911 | - \OC_App::loadApp($app); |
|
| 912 | - return $c->query($class); |
|
| 913 | - } else { |
|
| 914 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 915 | - } |
|
| 916 | - } else { |
|
| 917 | - $jobList = $c->getJobList(); |
|
| 918 | - return new CronBus($jobList); |
|
| 919 | - } |
|
| 920 | - }); |
|
| 921 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 922 | - return new TrustedDomainHelper($this->getConfig()); |
|
| 923 | - }); |
|
| 924 | - $this->registerService(Throttler::class, function (Server $c) { |
|
| 925 | - return new Throttler( |
|
| 926 | - $c->getDatabaseConnection(), |
|
| 927 | - new TimeFactory(), |
|
| 928 | - $c->getLogger(), |
|
| 929 | - $c->getConfig() |
|
| 930 | - ); |
|
| 931 | - }); |
|
| 932 | - $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
| 933 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 934 | - // IConfig and IAppManager requires a working database. This code |
|
| 935 | - // might however be called when ownCloud is not yet setup. |
|
| 936 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 937 | - $config = $c->getConfig(); |
|
| 938 | - $appManager = $c->getAppManager(); |
|
| 939 | - } else { |
|
| 940 | - $config = null; |
|
| 941 | - $appManager = null; |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - return new Checker( |
|
| 945 | - new EnvironmentHelper(), |
|
| 946 | - new FileAccessHelper(), |
|
| 947 | - new AppLocator(), |
|
| 948 | - $config, |
|
| 949 | - $c->getMemCacheFactory(), |
|
| 950 | - $appManager, |
|
| 951 | - $c->getTempManager(), |
|
| 952 | - $c->getMimeTypeDetector() |
|
| 953 | - ); |
|
| 954 | - }); |
|
| 955 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 956 | - if (isset($this['urlParams'])) { |
|
| 957 | - $urlParams = $this['urlParams']; |
|
| 958 | - } else { |
|
| 959 | - $urlParams = []; |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 963 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 964 | - ) { |
|
| 965 | - $stream = 'fakeinput://data'; |
|
| 966 | - } else { |
|
| 967 | - $stream = 'php://input'; |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - return new Request( |
|
| 971 | - [ |
|
| 972 | - 'get' => $_GET, |
|
| 973 | - 'post' => $_POST, |
|
| 974 | - 'files' => $_FILES, |
|
| 975 | - 'server' => $_SERVER, |
|
| 976 | - 'env' => $_ENV, |
|
| 977 | - 'cookies' => $_COOKIE, |
|
| 978 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 979 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 980 | - : '', |
|
| 981 | - 'urlParams' => $urlParams, |
|
| 982 | - ], |
|
| 983 | - $this->getSecureRandom(), |
|
| 984 | - $this->getConfig(), |
|
| 985 | - $this->getCsrfTokenManager(), |
|
| 986 | - $stream |
|
| 987 | - ); |
|
| 988 | - }); |
|
| 989 | - $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
| 990 | - |
|
| 991 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 992 | - return new Mailer( |
|
| 993 | - $c->getConfig(), |
|
| 994 | - $c->getLogger(), |
|
| 995 | - $c->query(Defaults::class), |
|
| 996 | - $c->getURLGenerator(), |
|
| 997 | - $c->getL10N('lib'), |
|
| 998 | - $c->query(IEventDispatcher::class), |
|
| 999 | - $c->getL10NFactory() |
|
| 1000 | - ); |
|
| 1001 | - }); |
|
| 1002 | - $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
| 1003 | - |
|
| 1004 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
| 1005 | - $config = $c->getConfig(); |
|
| 1006 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 1007 | - if (is_null($factoryClass)) { |
|
| 1008 | - throw new \Exception('ldapProviderFactory not set'); |
|
| 1009 | - } |
|
| 1010 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 1011 | - $factory = new $factoryClass($this); |
|
| 1012 | - return $factory->getLDAPProvider(); |
|
| 1013 | - }); |
|
| 1014 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 1015 | - $ini = $c->getIniWrapper(); |
|
| 1016 | - $config = $c->getConfig(); |
|
| 1017 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 1018 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 1019 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 1020 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1021 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 1022 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 1023 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
| 1024 | - } |
|
| 1025 | - return new DBLockingProvider( |
|
| 1026 | - $c->getDatabaseConnection(), |
|
| 1027 | - $c->getLogger(), |
|
| 1028 | - new TimeFactory(), |
|
| 1029 | - $ttl, |
|
| 1030 | - !\OC::$CLI |
|
| 1031 | - ); |
|
| 1032 | - } |
|
| 1033 | - return new NoopLockingProvider(); |
|
| 1034 | - }); |
|
| 1035 | - $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
| 1036 | - |
|
| 1037 | - $this->registerService(IMountManager::class, function () { |
|
| 1038 | - return new \OC\Files\Mount\Manager(); |
|
| 1039 | - }); |
|
| 1040 | - $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
| 1041 | - |
|
| 1042 | - $this->registerService(IMimeTypeDetector::class, function (Server $c) { |
|
| 1043 | - return new \OC\Files\Type\Detection( |
|
| 1044 | - $c->getURLGenerator(), |
|
| 1045 | - $c->getLogger(), |
|
| 1046 | - \OC::$configDir, |
|
| 1047 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 1048 | - ); |
|
| 1049 | - }); |
|
| 1050 | - $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
| 1051 | - |
|
| 1052 | - $this->registerService(IMimeTypeLoader::class, function (Server $c) { |
|
| 1053 | - return new \OC\Files\Type\Loader( |
|
| 1054 | - $c->getDatabaseConnection() |
|
| 1055 | - ); |
|
| 1056 | - }); |
|
| 1057 | - $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
| 1058 | - $this->registerService(BundleFetcher::class, function () { |
|
| 1059 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 1060 | - }); |
|
| 1061 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 1062 | - return new Manager( |
|
| 1063 | - $c->query(IValidator::class), |
|
| 1064 | - $c->getLogger() |
|
| 1065 | - ); |
|
| 1066 | - }); |
|
| 1067 | - $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 1068 | - |
|
| 1069 | - $this->registerService(CapabilitiesManager::class, function (Server $c) { |
|
| 1070 | - $manager = new CapabilitiesManager($c->getLogger()); |
|
| 1071 | - $manager->registerCapability(function () use ($c) { |
|
| 1072 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 1073 | - }); |
|
| 1074 | - $manager->registerCapability(function () use ($c) { |
|
| 1075 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1076 | - }); |
|
| 1077 | - return $manager; |
|
| 1078 | - }); |
|
| 1079 | - $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
| 1080 | - |
|
| 1081 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1082 | - $config = $c->getConfig(); |
|
| 1083 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1084 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1085 | - $factory = new $factoryClass($this); |
|
| 1086 | - $manager = $factory->getManager(); |
|
| 1087 | - |
|
| 1088 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1089 | - $manager = $c->getUserManager(); |
|
| 1090 | - $user = $manager->get($id); |
|
| 1091 | - if (is_null($user)) { |
|
| 1092 | - $l = $c->getL10N('core'); |
|
| 1093 | - $displayName = $l->t('Unknown user'); |
|
| 1094 | - } else { |
|
| 1095 | - $displayName = $user->getDisplayName(); |
|
| 1096 | - } |
|
| 1097 | - return $displayName; |
|
| 1098 | - }); |
|
| 1099 | - |
|
| 1100 | - return $manager; |
|
| 1101 | - }); |
|
| 1102 | - $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
| 1103 | - |
|
| 1104 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1105 | - /* |
|
| 245 | + /** @var string */ |
|
| 246 | + private $webRoot; |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @param string $webRoot |
|
| 250 | + * @param \OC\Config $config |
|
| 251 | + */ |
|
| 252 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 253 | + parent::__construct(); |
|
| 254 | + $this->webRoot = $webRoot; |
|
| 255 | + |
|
| 256 | + // To find out if we are running from CLI or not |
|
| 257 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 258 | + |
|
| 259 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 260 | + return $c; |
|
| 261 | + }); |
|
| 262 | + |
|
| 263 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 264 | + $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 265 | + |
|
| 266 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 267 | + $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
| 268 | + |
|
| 269 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 270 | + $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
| 271 | + |
|
| 272 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 273 | + $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 274 | + |
|
| 275 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 276 | + |
|
| 277 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + $this->registerService(IPreview::class, function (Server $c) { |
|
| 281 | + return new PreviewManager( |
|
| 282 | + $c->getConfig(), |
|
| 283 | + $c->getRootFolder(), |
|
| 284 | + $c->getAppDataDir('preview'), |
|
| 285 | + $c->getEventDispatcher(), |
|
| 286 | + $c->getGeneratorHelper(), |
|
| 287 | + $c->getSession()->get('user_id') |
|
| 288 | + ); |
|
| 289 | + }); |
|
| 290 | + $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
| 291 | + |
|
| 292 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 293 | + return new \OC\Preview\Watcher( |
|
| 294 | + $c->getAppDataDir('preview') |
|
| 295 | + ); |
|
| 296 | + }); |
|
| 297 | + |
|
| 298 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 299 | + $view = new View(); |
|
| 300 | + $util = new Encryption\Util( |
|
| 301 | + $view, |
|
| 302 | + $c->getUserManager(), |
|
| 303 | + $c->getGroupManager(), |
|
| 304 | + $c->getConfig() |
|
| 305 | + ); |
|
| 306 | + return new Encryption\Manager( |
|
| 307 | + $c->getConfig(), |
|
| 308 | + $c->getLogger(), |
|
| 309 | + $c->getL10N('core'), |
|
| 310 | + new View(), |
|
| 311 | + $util, |
|
| 312 | + new ArrayCache() |
|
| 313 | + ); |
|
| 314 | + }); |
|
| 315 | + $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
| 316 | + |
|
| 317 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 318 | + $util = new Encryption\Util( |
|
| 319 | + new View(), |
|
| 320 | + $c->getUserManager(), |
|
| 321 | + $c->getGroupManager(), |
|
| 322 | + $c->getConfig() |
|
| 323 | + ); |
|
| 324 | + return new Encryption\File( |
|
| 325 | + $util, |
|
| 326 | + $c->getRootFolder(), |
|
| 327 | + $c->getShareManager() |
|
| 328 | + ); |
|
| 329 | + }); |
|
| 330 | + |
|
| 331 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 332 | + $view = new View(); |
|
| 333 | + $util = new Encryption\Util( |
|
| 334 | + $view, |
|
| 335 | + $c->getUserManager(), |
|
| 336 | + $c->getGroupManager(), |
|
| 337 | + $c->getConfig() |
|
| 338 | + ); |
|
| 339 | + |
|
| 340 | + return new Encryption\Keys\Storage($view, $util); |
|
| 341 | + }); |
|
| 342 | + $this->registerService('TagMapper', function (Server $c) { |
|
| 343 | + return new TagMapper($c->getDatabaseConnection()); |
|
| 344 | + }); |
|
| 345 | + |
|
| 346 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 347 | + $tagMapper = $c->query('TagMapper'); |
|
| 348 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
| 349 | + }); |
|
| 350 | + $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
| 351 | + |
|
| 352 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 353 | + $config = $c->getConfig(); |
|
| 354 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 355 | + return new $factoryClass($this); |
|
| 356 | + }); |
|
| 357 | + $this->registerService(ISystemTagManager::class, function (Server $c) { |
|
| 358 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 359 | + }); |
|
| 360 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 361 | + |
|
| 362 | + $this->registerService(ISystemTagObjectMapper::class, function (Server $c) { |
|
| 363 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 364 | + }); |
|
| 365 | + $this->registerService('RootFolder', function (Server $c) { |
|
| 366 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 367 | + $view = new View(); |
|
| 368 | + $root = new Root( |
|
| 369 | + $manager, |
|
| 370 | + $view, |
|
| 371 | + null, |
|
| 372 | + $c->getUserMountCache(), |
|
| 373 | + $this->getLogger(), |
|
| 374 | + $this->getUserManager() |
|
| 375 | + ); |
|
| 376 | + $connector = new HookConnector($root, $view, $c->getEventDispatcher()); |
|
| 377 | + $connector->viewToNode(); |
|
| 378 | + |
|
| 379 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 380 | + $previewConnector->connectWatcher(); |
|
| 381 | + |
|
| 382 | + return $root; |
|
| 383 | + }); |
|
| 384 | + $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
| 385 | + |
|
| 386 | + $this->registerService(IRootFolder::class, function (Server $c) { |
|
| 387 | + return new LazyRoot(function () use ($c) { |
|
| 388 | + return $c->query('RootFolder'); |
|
| 389 | + }); |
|
| 390 | + }); |
|
| 391 | + $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
| 392 | + |
|
| 393 | + $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
| 394 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 395 | + |
|
| 396 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 397 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
| 398 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 399 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]); |
|
| 400 | + |
|
| 401 | + /** @var IEventDispatcher $dispatcher */ |
|
| 402 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 403 | + $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
| 404 | + }); |
|
| 405 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
| 406 | + \OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $group->getGID()]); |
|
| 407 | + |
|
| 408 | + /** @var IEventDispatcher $dispatcher */ |
|
| 409 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 410 | + $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
| 411 | + }); |
|
| 412 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 413 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]); |
|
| 414 | + |
|
| 415 | + /** @var IEventDispatcher $dispatcher */ |
|
| 416 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 417 | + $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
| 418 | + }); |
|
| 419 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 420 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]); |
|
| 421 | + |
|
| 422 | + /** @var IEventDispatcher $dispatcher */ |
|
| 423 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 424 | + $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
| 425 | + }); |
|
| 426 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 427 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 428 | + |
|
| 429 | + /** @var IEventDispatcher $dispatcher */ |
|
| 430 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 431 | + $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
| 432 | + }); |
|
| 433 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 434 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 435 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 436 | + \OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 437 | + |
|
| 438 | + /** @var IEventDispatcher $dispatcher */ |
|
| 439 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 440 | + $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
| 441 | + }); |
|
| 442 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 443 | + /** @var IEventDispatcher $dispatcher */ |
|
| 444 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 445 | + $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
| 446 | + }); |
|
| 447 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 448 | + /** @var IEventDispatcher $dispatcher */ |
|
| 449 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 450 | + $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
| 451 | + }); |
|
| 452 | + return $groupManager; |
|
| 453 | + }); |
|
| 454 | + $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 455 | + |
|
| 456 | + $this->registerService(Store::class, function (Server $c) { |
|
| 457 | + $session = $c->getSession(); |
|
| 458 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 459 | + $tokenProvider = $c->query(IProvider::class); |
|
| 460 | + } else { |
|
| 461 | + $tokenProvider = null; |
|
| 462 | + } |
|
| 463 | + $logger = $c->getLogger(); |
|
| 464 | + return new Store($session, $logger, $tokenProvider); |
|
| 465 | + }); |
|
| 466 | + $this->registerAlias(IStore::class, Store::class); |
|
| 467 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
| 468 | + $dbConnection = $c->getDatabaseConnection(); |
|
| 469 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
| 470 | + }); |
|
| 471 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 472 | + |
|
| 473 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 474 | + $manager = $c->getUserManager(); |
|
| 475 | + $session = new \OC\Session\Memory(''); |
|
| 476 | + $timeFactory = new TimeFactory(); |
|
| 477 | + // Token providers might require a working database. This code |
|
| 478 | + // might however be called when ownCloud is not yet setup. |
|
| 479 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 480 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
| 481 | + } else { |
|
| 482 | + $defaultTokenProvider = null; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + $legacyDispatcher = $c->getEventDispatcher(); |
|
| 486 | + |
|
| 487 | + $userSession = new \OC\User\Session( |
|
| 488 | + $manager, |
|
| 489 | + $session, |
|
| 490 | + $timeFactory, |
|
| 491 | + $defaultTokenProvider, |
|
| 492 | + $c->getConfig(), |
|
| 493 | + $c->getSecureRandom(), |
|
| 494 | + $c->getLockdownManager(), |
|
| 495 | + $c->getLogger(), |
|
| 496 | + $c->query(IEventDispatcher::class) |
|
| 497 | + ); |
|
| 498 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 499 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 500 | + |
|
| 501 | + /** @var IEventDispatcher $dispatcher */ |
|
| 502 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 503 | + $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password)); |
|
| 504 | + }); |
|
| 505 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 506 | + /** @var $user \OC\User\User */ |
|
| 507 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 508 | + |
|
| 509 | + /** @var IEventDispatcher $dispatcher */ |
|
| 510 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 511 | + $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); |
|
| 512 | + }); |
|
| 513 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
| 514 | + /** @var $user \OC\User\User */ |
|
| 515 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 516 | + $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 517 | + |
|
| 518 | + /** @var IEventDispatcher $dispatcher */ |
|
| 519 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 520 | + $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user)); |
|
| 521 | + }); |
|
| 522 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 523 | + /** @var $user \OC\User\User */ |
|
| 524 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 525 | + |
|
| 526 | + /** @var IEventDispatcher $dispatcher */ |
|
| 527 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 528 | + $dispatcher->dispatchTyped(new UserDeletedEvent($user)); |
|
| 529 | + }); |
|
| 530 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 531 | + /** @var $user \OC\User\User */ |
|
| 532 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 533 | + |
|
| 534 | + /** @var IEventDispatcher $dispatcher */ |
|
| 535 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 536 | + $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 537 | + }); |
|
| 538 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 539 | + /** @var $user \OC\User\User */ |
|
| 540 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 541 | + |
|
| 542 | + /** @var IEventDispatcher $dispatcher */ |
|
| 543 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 544 | + $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 545 | + }); |
|
| 546 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 547 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 548 | + |
|
| 549 | + /** @var IEventDispatcher $dispatcher */ |
|
| 550 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 551 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 552 | + }); |
|
| 553 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
| 554 | + /** @var $user \OC\User\User */ |
|
| 555 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 556 | + |
|
| 557 | + /** @var IEventDispatcher $dispatcher */ |
|
| 558 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 559 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); |
|
| 560 | + }); |
|
| 561 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 562 | + /** @var IEventDispatcher $dispatcher */ |
|
| 563 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 564 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 565 | + }); |
|
| 566 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 567 | + /** @var $user \OC\User\User */ |
|
| 568 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 569 | + |
|
| 570 | + /** @var IEventDispatcher $dispatcher */ |
|
| 571 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 572 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 573 | + }); |
|
| 574 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 575 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
| 576 | + |
|
| 577 | + /** @var IEventDispatcher $dispatcher */ |
|
| 578 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 579 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 580 | + }); |
|
| 581 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 582 | + /** @var IEventDispatcher $dispatcher */ |
|
| 583 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 584 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 585 | + }); |
|
| 586 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 587 | + /** @var $user \OC\User\User */ |
|
| 588 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 589 | + |
|
| 590 | + /** @var IEventDispatcher $dispatcher */ |
|
| 591 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 592 | + $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
| 593 | + }); |
|
| 594 | + return $userSession; |
|
| 595 | + }); |
|
| 596 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 597 | + $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
| 598 | + |
|
| 599 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 600 | + |
|
| 601 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 602 | + $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
| 603 | + |
|
| 604 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 605 | + return new \OC\AllConfig( |
|
| 606 | + $c->getSystemConfig() |
|
| 607 | + ); |
|
| 608 | + }); |
|
| 609 | + $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
| 610 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 611 | + |
|
| 612 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 613 | + return new \OC\SystemConfig($config); |
|
| 614 | + }); |
|
| 615 | + $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
| 616 | + |
|
| 617 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 618 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 619 | + }); |
|
| 620 | + $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
| 621 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 622 | + |
|
| 623 | + $this->registerService(IFactory::class, function (Server $c) { |
|
| 624 | + return new \OC\L10N\Factory( |
|
| 625 | + $c->getConfig(), |
|
| 626 | + $c->getRequest(), |
|
| 627 | + $c->getUserSession(), |
|
| 628 | + \OC::$SERVERROOT |
|
| 629 | + ); |
|
| 630 | + }); |
|
| 631 | + $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
| 632 | + |
|
| 633 | + $this->registerService(IURLGenerator::class, function (Server $c) { |
|
| 634 | + $config = $c->getConfig(); |
|
| 635 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 636 | + $request = $c->getRequest(); |
|
| 637 | + return new \OC\URLGenerator( |
|
| 638 | + $config, |
|
| 639 | + $cacheFactory, |
|
| 640 | + $request |
|
| 641 | + ); |
|
| 642 | + }); |
|
| 643 | + $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
| 644 | + |
|
| 645 | + $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
| 646 | + $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 647 | + |
|
| 648 | + $this->registerService(ICache::class, function ($c) { |
|
| 649 | + return new Cache\File(); |
|
| 650 | + }); |
|
| 651 | + $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
| 652 | + |
|
| 653 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 654 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 655 | + ArrayCache::class, |
|
| 656 | + ArrayCache::class, |
|
| 657 | + ArrayCache::class |
|
| 658 | + ); |
|
| 659 | + $config = $c->getConfig(); |
|
| 660 | + |
|
| 661 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 662 | + $v = \OC_App::getAppVersions(); |
|
| 663 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 664 | + $version = implode(',', $v); |
|
| 665 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 666 | + $path = \OC::$SERVERROOT; |
|
| 667 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 668 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 669 | + $config->getSystemValue('memcache.local', null), |
|
| 670 | + $config->getSystemValue('memcache.distributed', null), |
|
| 671 | + $config->getSystemValue('memcache.locking', null) |
|
| 672 | + ); |
|
| 673 | + } |
|
| 674 | + return $arrayCacheFactory; |
|
| 675 | + }); |
|
| 676 | + $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
| 677 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 678 | + |
|
| 679 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 680 | + $systemConfig = $c->getSystemConfig(); |
|
| 681 | + return new RedisFactory($systemConfig); |
|
| 682 | + }); |
|
| 683 | + |
|
| 684 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 685 | + return new \OC\Activity\Manager( |
|
| 686 | + $c->getRequest(), |
|
| 687 | + $c->getUserSession(), |
|
| 688 | + $c->getConfig(), |
|
| 689 | + $c->query(IValidator::class) |
|
| 690 | + ); |
|
| 691 | + }); |
|
| 692 | + $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 693 | + |
|
| 694 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 695 | + return new \OC\Activity\EventMerger( |
|
| 696 | + $c->getL10N('lib') |
|
| 697 | + ); |
|
| 698 | + }); |
|
| 699 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 700 | + |
|
| 701 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 702 | + return new AvatarManager( |
|
| 703 | + $c->query(\OC\User\Manager::class), |
|
| 704 | + $c->getAppDataDir('avatar'), |
|
| 705 | + $c->getL10N('lib'), |
|
| 706 | + $c->getLogger(), |
|
| 707 | + $c->getConfig() |
|
| 708 | + ); |
|
| 709 | + }); |
|
| 710 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 711 | + $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
| 712 | + |
|
| 713 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 714 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 715 | + |
|
| 716 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 717 | + $logType = $c->query(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 718 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
| 719 | + $logger = $factory->get($logType); |
|
| 720 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
| 721 | + |
|
| 722 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
| 723 | + }); |
|
| 724 | + $this->registerAlias(ILogger::class, \OC\Log::class); |
|
| 725 | + $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
| 726 | + // PSR-3 logger |
|
| 727 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 728 | + |
|
| 729 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 730 | + return new LogFactory($c, $this->getSystemConfig()); |
|
| 731 | + }); |
|
| 732 | + |
|
| 733 | + $this->registerService(IJobList::class, function (Server $c) { |
|
| 734 | + $config = $c->getConfig(); |
|
| 735 | + return new \OC\BackgroundJob\JobList( |
|
| 736 | + $c->getDatabaseConnection(), |
|
| 737 | + $config, |
|
| 738 | + new TimeFactory() |
|
| 739 | + ); |
|
| 740 | + }); |
|
| 741 | + $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
| 742 | + |
|
| 743 | + $this->registerService(IRouter::class, function (Server $c) { |
|
| 744 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 745 | + $logger = $c->getLogger(); |
|
| 746 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 747 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 748 | + } else { |
|
| 749 | + $router = new \OC\Route\Router($logger); |
|
| 750 | + } |
|
| 751 | + return $router; |
|
| 752 | + }); |
|
| 753 | + $this->registerDeprecatedAlias('Router', IRouter::class); |
|
| 754 | + |
|
| 755 | + $this->registerService(ISearch::class, function ($c) { |
|
| 756 | + return new Search(); |
|
| 757 | + }); |
|
| 758 | + $this->registerDeprecatedAlias('Search', ISearch::class); |
|
| 759 | + |
|
| 760 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 761 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 762 | + $this->getMemCacheFactory(), |
|
| 763 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 764 | + ); |
|
| 765 | + }); |
|
| 766 | + |
|
| 767 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 768 | + return new SecureRandom(); |
|
| 769 | + }); |
|
| 770 | + $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 771 | + |
|
| 772 | + $this->registerService(ICrypto::class, function (Server $c) { |
|
| 773 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 774 | + }); |
|
| 775 | + $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
| 776 | + |
|
| 777 | + $this->registerService(IHasher::class, function (Server $c) { |
|
| 778 | + return new Hasher($c->getConfig()); |
|
| 779 | + }); |
|
| 780 | + $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
| 781 | + |
|
| 782 | + $this->registerService(ICredentialsManager::class, function (Server $c) { |
|
| 783 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 784 | + }); |
|
| 785 | + $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
| 786 | + |
|
| 787 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 788 | + $systemConfig = $c->getSystemConfig(); |
|
| 789 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 790 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 791 | + if (!$factory->isValidType($type)) { |
|
| 792 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 793 | + } |
|
| 794 | + $connectionParams = $factory->createConnectionParams(); |
|
| 795 | + $connection = $factory->getConnection($type, $connectionParams); |
|
| 796 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 797 | + return $connection; |
|
| 798 | + }); |
|
| 799 | + $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
| 800 | + |
|
| 801 | + |
|
| 802 | + $this->registerService(IClientService::class, function (Server $c) { |
|
| 803 | + $user = \OC_User::getUser(); |
|
| 804 | + $uid = $user ? $user : null; |
|
| 805 | + return new ClientService( |
|
| 806 | + $c->getConfig(), |
|
| 807 | + $c->getLogger(), |
|
| 808 | + new \OC\Security\CertificateManager( |
|
| 809 | + $uid, |
|
| 810 | + new View(), |
|
| 811 | + $c->getConfig(), |
|
| 812 | + $c->getLogger(), |
|
| 813 | + $c->getSecureRandom() |
|
| 814 | + ) |
|
| 815 | + ); |
|
| 816 | + }); |
|
| 817 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 818 | + $this->registerService(IEventLogger::class, function (Server $c) { |
|
| 819 | + $eventLogger = new EventLogger(); |
|
| 820 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 821 | + // In debug mode, module is being activated by default |
|
| 822 | + $eventLogger->activate(); |
|
| 823 | + } |
|
| 824 | + return $eventLogger; |
|
| 825 | + }); |
|
| 826 | + $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
| 827 | + |
|
| 828 | + $this->registerService(IQueryLogger::class, function (Server $c) { |
|
| 829 | + $queryLogger = new QueryLogger(); |
|
| 830 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 831 | + // In debug mode, module is being activated by default |
|
| 832 | + $queryLogger->activate(); |
|
| 833 | + } |
|
| 834 | + return $queryLogger; |
|
| 835 | + }); |
|
| 836 | + $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
| 837 | + |
|
| 838 | + $this->registerService(TempManager::class, function (Server $c) { |
|
| 839 | + return new TempManager( |
|
| 840 | + $c->getLogger(), |
|
| 841 | + $c->getConfig() |
|
| 842 | + ); |
|
| 843 | + }); |
|
| 844 | + $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
| 845 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 846 | + |
|
| 847 | + $this->registerService(AppManager::class, function (Server $c) { |
|
| 848 | + return new \OC\App\AppManager( |
|
| 849 | + $c->getUserSession(), |
|
| 850 | + $c->getConfig(), |
|
| 851 | + $c->query(\OC\AppConfig::class), |
|
| 852 | + $c->getGroupManager(), |
|
| 853 | + $c->getMemCacheFactory(), |
|
| 854 | + $c->getEventDispatcher(), |
|
| 855 | + $c->getLogger() |
|
| 856 | + ); |
|
| 857 | + }); |
|
| 858 | + $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
| 859 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 860 | + |
|
| 861 | + $this->registerService(IDateTimeZone::class, function (Server $c) { |
|
| 862 | + return new DateTimeZone( |
|
| 863 | + $c->getConfig(), |
|
| 864 | + $c->getSession() |
|
| 865 | + ); |
|
| 866 | + }); |
|
| 867 | + $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
| 868 | + |
|
| 869 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 870 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 871 | + |
|
| 872 | + return new DateTimeFormatter( |
|
| 873 | + $c->getDateTimeZone()->getTimeZone(), |
|
| 874 | + $c->getL10N('lib', $language) |
|
| 875 | + ); |
|
| 876 | + }); |
|
| 877 | + $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
| 878 | + |
|
| 879 | + $this->registerService(IUserMountCache::class, function (Server $c) { |
|
| 880 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 881 | + $listener = new UserMountCacheListener($mountCache); |
|
| 882 | + $listener->listen($c->getUserManager()); |
|
| 883 | + return $mountCache; |
|
| 884 | + }); |
|
| 885 | + $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
| 886 | + |
|
| 887 | + $this->registerService(IMountProviderCollection::class, function (Server $c) { |
|
| 888 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
| 889 | + $mountCache = $c->query(IUserMountCache::class); |
|
| 890 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 891 | + |
|
| 892 | + // builtin providers |
|
| 893 | + |
|
| 894 | + $config = $c->getConfig(); |
|
| 895 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 896 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 897 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 898 | + |
|
| 899 | + return $manager; |
|
| 900 | + }); |
|
| 901 | + $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
| 902 | + |
|
| 903 | + $this->registerService('IniWrapper', function ($c) { |
|
| 904 | + return new IniGetWrapper(); |
|
| 905 | + }); |
|
| 906 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 907 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
| 908 | + if ($busClass) { |
|
| 909 | + list($app, $class) = explode('::', $busClass, 2); |
|
| 910 | + if ($c->getAppManager()->isInstalled($app)) { |
|
| 911 | + \OC_App::loadApp($app); |
|
| 912 | + return $c->query($class); |
|
| 913 | + } else { |
|
| 914 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 915 | + } |
|
| 916 | + } else { |
|
| 917 | + $jobList = $c->getJobList(); |
|
| 918 | + return new CronBus($jobList); |
|
| 919 | + } |
|
| 920 | + }); |
|
| 921 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 922 | + return new TrustedDomainHelper($this->getConfig()); |
|
| 923 | + }); |
|
| 924 | + $this->registerService(Throttler::class, function (Server $c) { |
|
| 925 | + return new Throttler( |
|
| 926 | + $c->getDatabaseConnection(), |
|
| 927 | + new TimeFactory(), |
|
| 928 | + $c->getLogger(), |
|
| 929 | + $c->getConfig() |
|
| 930 | + ); |
|
| 931 | + }); |
|
| 932 | + $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
| 933 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 934 | + // IConfig and IAppManager requires a working database. This code |
|
| 935 | + // might however be called when ownCloud is not yet setup. |
|
| 936 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 937 | + $config = $c->getConfig(); |
|
| 938 | + $appManager = $c->getAppManager(); |
|
| 939 | + } else { |
|
| 940 | + $config = null; |
|
| 941 | + $appManager = null; |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + return new Checker( |
|
| 945 | + new EnvironmentHelper(), |
|
| 946 | + new FileAccessHelper(), |
|
| 947 | + new AppLocator(), |
|
| 948 | + $config, |
|
| 949 | + $c->getMemCacheFactory(), |
|
| 950 | + $appManager, |
|
| 951 | + $c->getTempManager(), |
|
| 952 | + $c->getMimeTypeDetector() |
|
| 953 | + ); |
|
| 954 | + }); |
|
| 955 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 956 | + if (isset($this['urlParams'])) { |
|
| 957 | + $urlParams = $this['urlParams']; |
|
| 958 | + } else { |
|
| 959 | + $urlParams = []; |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 963 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 964 | + ) { |
|
| 965 | + $stream = 'fakeinput://data'; |
|
| 966 | + } else { |
|
| 967 | + $stream = 'php://input'; |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + return new Request( |
|
| 971 | + [ |
|
| 972 | + 'get' => $_GET, |
|
| 973 | + 'post' => $_POST, |
|
| 974 | + 'files' => $_FILES, |
|
| 975 | + 'server' => $_SERVER, |
|
| 976 | + 'env' => $_ENV, |
|
| 977 | + 'cookies' => $_COOKIE, |
|
| 978 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 979 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 980 | + : '', |
|
| 981 | + 'urlParams' => $urlParams, |
|
| 982 | + ], |
|
| 983 | + $this->getSecureRandom(), |
|
| 984 | + $this->getConfig(), |
|
| 985 | + $this->getCsrfTokenManager(), |
|
| 986 | + $stream |
|
| 987 | + ); |
|
| 988 | + }); |
|
| 989 | + $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
| 990 | + |
|
| 991 | + $this->registerService(IMailer::class, function (Server $c) { |
|
| 992 | + return new Mailer( |
|
| 993 | + $c->getConfig(), |
|
| 994 | + $c->getLogger(), |
|
| 995 | + $c->query(Defaults::class), |
|
| 996 | + $c->getURLGenerator(), |
|
| 997 | + $c->getL10N('lib'), |
|
| 998 | + $c->query(IEventDispatcher::class), |
|
| 999 | + $c->getL10NFactory() |
|
| 1000 | + ); |
|
| 1001 | + }); |
|
| 1002 | + $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
| 1003 | + |
|
| 1004 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
| 1005 | + $config = $c->getConfig(); |
|
| 1006 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 1007 | + if (is_null($factoryClass)) { |
|
| 1008 | + throw new \Exception('ldapProviderFactory not set'); |
|
| 1009 | + } |
|
| 1010 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 1011 | + $factory = new $factoryClass($this); |
|
| 1012 | + return $factory->getLDAPProvider(); |
|
| 1013 | + }); |
|
| 1014 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 1015 | + $ini = $c->getIniWrapper(); |
|
| 1016 | + $config = $c->getConfig(); |
|
| 1017 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 1018 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 1019 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 1020 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1021 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 1022 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 1023 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
| 1024 | + } |
|
| 1025 | + return new DBLockingProvider( |
|
| 1026 | + $c->getDatabaseConnection(), |
|
| 1027 | + $c->getLogger(), |
|
| 1028 | + new TimeFactory(), |
|
| 1029 | + $ttl, |
|
| 1030 | + !\OC::$CLI |
|
| 1031 | + ); |
|
| 1032 | + } |
|
| 1033 | + return new NoopLockingProvider(); |
|
| 1034 | + }); |
|
| 1035 | + $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
| 1036 | + |
|
| 1037 | + $this->registerService(IMountManager::class, function () { |
|
| 1038 | + return new \OC\Files\Mount\Manager(); |
|
| 1039 | + }); |
|
| 1040 | + $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
| 1041 | + |
|
| 1042 | + $this->registerService(IMimeTypeDetector::class, function (Server $c) { |
|
| 1043 | + return new \OC\Files\Type\Detection( |
|
| 1044 | + $c->getURLGenerator(), |
|
| 1045 | + $c->getLogger(), |
|
| 1046 | + \OC::$configDir, |
|
| 1047 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 1048 | + ); |
|
| 1049 | + }); |
|
| 1050 | + $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
| 1051 | + |
|
| 1052 | + $this->registerService(IMimeTypeLoader::class, function (Server $c) { |
|
| 1053 | + return new \OC\Files\Type\Loader( |
|
| 1054 | + $c->getDatabaseConnection() |
|
| 1055 | + ); |
|
| 1056 | + }); |
|
| 1057 | + $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
| 1058 | + $this->registerService(BundleFetcher::class, function () { |
|
| 1059 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 1060 | + }); |
|
| 1061 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 1062 | + return new Manager( |
|
| 1063 | + $c->query(IValidator::class), |
|
| 1064 | + $c->getLogger() |
|
| 1065 | + ); |
|
| 1066 | + }); |
|
| 1067 | + $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 1068 | + |
|
| 1069 | + $this->registerService(CapabilitiesManager::class, function (Server $c) { |
|
| 1070 | + $manager = new CapabilitiesManager($c->getLogger()); |
|
| 1071 | + $manager->registerCapability(function () use ($c) { |
|
| 1072 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 1073 | + }); |
|
| 1074 | + $manager->registerCapability(function () use ($c) { |
|
| 1075 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1076 | + }); |
|
| 1077 | + return $manager; |
|
| 1078 | + }); |
|
| 1079 | + $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
| 1080 | + |
|
| 1081 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1082 | + $config = $c->getConfig(); |
|
| 1083 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1084 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1085 | + $factory = new $factoryClass($this); |
|
| 1086 | + $manager = $factory->getManager(); |
|
| 1087 | + |
|
| 1088 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1089 | + $manager = $c->getUserManager(); |
|
| 1090 | + $user = $manager->get($id); |
|
| 1091 | + if (is_null($user)) { |
|
| 1092 | + $l = $c->getL10N('core'); |
|
| 1093 | + $displayName = $l->t('Unknown user'); |
|
| 1094 | + } else { |
|
| 1095 | + $displayName = $user->getDisplayName(); |
|
| 1096 | + } |
|
| 1097 | + return $displayName; |
|
| 1098 | + }); |
|
| 1099 | + |
|
| 1100 | + return $manager; |
|
| 1101 | + }); |
|
| 1102 | + $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
| 1103 | + |
|
| 1104 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1105 | + /* |
|
| 1106 | 1106 | * Dark magic for autoloader. |
| 1107 | 1107 | * If we do a class_exists it will try to load the class which will |
| 1108 | 1108 | * make composer cache the result. Resulting in errors when enabling |
| 1109 | 1109 | * the theming app. |
| 1110 | 1110 | */ |
| 1111 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 1112 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 1113 | - $classExists = true; |
|
| 1114 | - } else { |
|
| 1115 | - $classExists = false; |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1119 | - return new ThemingDefaults( |
|
| 1120 | - $c->getConfig(), |
|
| 1121 | - $c->getL10N('theming'), |
|
| 1122 | - $c->getURLGenerator(), |
|
| 1123 | - $c->getMemCacheFactory(), |
|
| 1124 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
| 1125 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
| 1126 | - $c->getAppManager(), |
|
| 1127 | - $c->getNavigationManager() |
|
| 1128 | - ); |
|
| 1129 | - } |
|
| 1130 | - return new \OC_Defaults(); |
|
| 1131 | - }); |
|
| 1132 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 1133 | - return new SCSSCacher( |
|
| 1134 | - $c->getLogger(), |
|
| 1135 | - $c->query(\OC\Files\AppData\Factory::class), |
|
| 1136 | - $c->getURLGenerator(), |
|
| 1137 | - $c->getConfig(), |
|
| 1138 | - $c->getThemingDefaults(), |
|
| 1139 | - \OC::$SERVERROOT, |
|
| 1140 | - $this->getMemCacheFactory(), |
|
| 1141 | - $c->query(IconsCacher::class), |
|
| 1142 | - new TimeFactory() |
|
| 1143 | - ); |
|
| 1144 | - }); |
|
| 1145 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1146 | - return new JSCombiner( |
|
| 1147 | - $c->getAppDataDir('js'), |
|
| 1148 | - $c->getURLGenerator(), |
|
| 1149 | - $this->getMemCacheFactory(), |
|
| 1150 | - $c->getSystemConfig(), |
|
| 1151 | - $c->getLogger() |
|
| 1152 | - ); |
|
| 1153 | - }); |
|
| 1154 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1155 | - $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1156 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1157 | - |
|
| 1158 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 1159 | - // FIXME: Instantiiated here due to cyclic dependency |
|
| 1160 | - $request = new Request( |
|
| 1161 | - [ |
|
| 1162 | - 'get' => $_GET, |
|
| 1163 | - 'post' => $_POST, |
|
| 1164 | - 'files' => $_FILES, |
|
| 1165 | - 'server' => $_SERVER, |
|
| 1166 | - 'env' => $_ENV, |
|
| 1167 | - 'cookies' => $_COOKIE, |
|
| 1168 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1169 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1170 | - : null, |
|
| 1171 | - ], |
|
| 1172 | - $c->getSecureRandom(), |
|
| 1173 | - $c->getConfig() |
|
| 1174 | - ); |
|
| 1175 | - |
|
| 1176 | - return new CryptoWrapper( |
|
| 1177 | - $c->getConfig(), |
|
| 1178 | - $c->getCrypto(), |
|
| 1179 | - $c->getSecureRandom(), |
|
| 1180 | - $request |
|
| 1181 | - ); |
|
| 1182 | - }); |
|
| 1183 | - $this->registerService(CsrfTokenManager::class, function (Server $c) { |
|
| 1184 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 1185 | - |
|
| 1186 | - return new CsrfTokenManager( |
|
| 1187 | - $tokenGenerator, |
|
| 1188 | - $c->query(SessionStorage::class) |
|
| 1189 | - ); |
|
| 1190 | - }); |
|
| 1191 | - $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
| 1192 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1193 | - return new SessionStorage($c->getSession()); |
|
| 1194 | - }); |
|
| 1195 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1196 | - $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
| 1197 | - |
|
| 1198 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 1199 | - return new ContentSecurityPolicyNonceManager( |
|
| 1200 | - $c->getCsrfTokenManager(), |
|
| 1201 | - $c->getRequest() |
|
| 1202 | - ); |
|
| 1203 | - }); |
|
| 1204 | - |
|
| 1205 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1206 | - $config = $c->getConfig(); |
|
| 1207 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1208 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1209 | - $factory = new $factoryClass($this); |
|
| 1210 | - |
|
| 1211 | - $manager = new \OC\Share20\Manager( |
|
| 1212 | - $c->getLogger(), |
|
| 1213 | - $c->getConfig(), |
|
| 1214 | - $c->getSecureRandom(), |
|
| 1215 | - $c->getHasher(), |
|
| 1216 | - $c->getMountManager(), |
|
| 1217 | - $c->getGroupManager(), |
|
| 1218 | - $c->getL10N('lib'), |
|
| 1219 | - $c->getL10NFactory(), |
|
| 1220 | - $factory, |
|
| 1221 | - $c->getUserManager(), |
|
| 1222 | - $c->getLazyRootFolder(), |
|
| 1223 | - $c->getEventDispatcher(), |
|
| 1224 | - $c->getMailer(), |
|
| 1225 | - $c->getURLGenerator(), |
|
| 1226 | - $c->getThemingDefaults(), |
|
| 1227 | - $c->query(IEventDispatcher::class) |
|
| 1228 | - ); |
|
| 1229 | - |
|
| 1230 | - return $manager; |
|
| 1231 | - }); |
|
| 1232 | - $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1233 | - |
|
| 1234 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1235 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1236 | - |
|
| 1237 | - // register default plugins |
|
| 1238 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1239 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1240 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1241 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1242 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1243 | - |
|
| 1244 | - return $instance; |
|
| 1245 | - }); |
|
| 1246 | - $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1247 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1248 | - |
|
| 1249 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1250 | - |
|
| 1251 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1252 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1253 | - |
|
| 1254 | - $this->registerService('SettingsManager', function (Server $c) { |
|
| 1255 | - $manager = new \OC\Settings\Manager( |
|
| 1256 | - $c->getLogger(), |
|
| 1257 | - $c->getL10NFactory(), |
|
| 1258 | - $c->getURLGenerator(), |
|
| 1259 | - $c |
|
| 1260 | - ); |
|
| 1261 | - return $manager; |
|
| 1262 | - }); |
|
| 1263 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1264 | - return new \OC\Files\AppData\Factory( |
|
| 1265 | - $c->getRootFolder(), |
|
| 1266 | - $c->getSystemConfig() |
|
| 1267 | - ); |
|
| 1268 | - }); |
|
| 1269 | - |
|
| 1270 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 1271 | - return new LockdownManager(function () use ($c) { |
|
| 1272 | - return $c->getSession(); |
|
| 1273 | - }); |
|
| 1274 | - }); |
|
| 1275 | - |
|
| 1276 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1277 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 1278 | - }); |
|
| 1279 | - |
|
| 1280 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1281 | - return new CloudIdManager(); |
|
| 1282 | - }); |
|
| 1283 | - |
|
| 1284 | - $this->registerService(IConfig::class, function (Server $c) { |
|
| 1285 | - return new GlobalScale\Config($c->getConfig()); |
|
| 1286 | - }); |
|
| 1287 | - |
|
| 1288 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
| 1289 | - return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
| 1290 | - }); |
|
| 1291 | - |
|
| 1292 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1293 | - return new CloudFederationFactory(); |
|
| 1294 | - }); |
|
| 1295 | - |
|
| 1296 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1297 | - $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1298 | - |
|
| 1299 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1300 | - $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1301 | - |
|
| 1302 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1303 | - return new Defaults( |
|
| 1304 | - $c->getThemingDefaults() |
|
| 1305 | - ); |
|
| 1306 | - }); |
|
| 1307 | - $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
| 1308 | - |
|
| 1309 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1310 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1311 | - }); |
|
| 1312 | - |
|
| 1313 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1314 | - return new ShareHelper( |
|
| 1315 | - $c->query(\OCP\Share\IManager::class) |
|
| 1316 | - ); |
|
| 1317 | - }); |
|
| 1318 | - |
|
| 1319 | - $this->registerService(Installer::class, function (Server $c) { |
|
| 1320 | - return new Installer( |
|
| 1321 | - $c->getAppFetcher(), |
|
| 1322 | - $c->getHTTPClientService(), |
|
| 1323 | - $c->getTempManager(), |
|
| 1324 | - $c->getLogger(), |
|
| 1325 | - $c->getConfig(), |
|
| 1326 | - \OC::$CLI |
|
| 1327 | - ); |
|
| 1328 | - }); |
|
| 1329 | - |
|
| 1330 | - $this->registerService(IApiFactory::class, function (Server $c) { |
|
| 1331 | - return new ApiFactory($c->getHTTPClientService()); |
|
| 1332 | - }); |
|
| 1333 | - |
|
| 1334 | - $this->registerService(IInstanceFactory::class, function (Server $c) { |
|
| 1335 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1336 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
| 1337 | - }); |
|
| 1338 | - |
|
| 1339 | - $this->registerService(IContactsStore::class, function (Server $c) { |
|
| 1340 | - return new ContactsStore( |
|
| 1341 | - $c->getContactsManager(), |
|
| 1342 | - $c->getConfig(), |
|
| 1343 | - $c->getUserManager(), |
|
| 1344 | - $c->getGroupManager() |
|
| 1345 | - ); |
|
| 1346 | - }); |
|
| 1347 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1348 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1349 | - |
|
| 1350 | - $this->registerService(IStorageFactory::class, function () { |
|
| 1351 | - return new StorageFactory(); |
|
| 1352 | - }); |
|
| 1353 | - |
|
| 1354 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
| 1355 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1356 | - |
|
| 1357 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1358 | - |
|
| 1359 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1360 | - |
|
| 1361 | - $this->connectDispatcher(); |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - /** |
|
| 1365 | - * @return \OCP\Calendar\IManager |
|
| 1366 | - */ |
|
| 1367 | - public function getCalendarManager() { |
|
| 1368 | - return $this->query(\OC\Calendar\Manager::class); |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - /** |
|
| 1372 | - * @return \OCP\Calendar\Resource\IManager |
|
| 1373 | - */ |
|
| 1374 | - public function getCalendarResourceBackendManager() { |
|
| 1375 | - return $this->query(\OC\Calendar\Resource\Manager::class); |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * @return \OCP\Calendar\Room\IManager |
|
| 1380 | - */ |
|
| 1381 | - public function getCalendarRoomBackendManager() { |
|
| 1382 | - return $this->query(\OC\Calendar\Room\Manager::class); |
|
| 1383 | - } |
|
| 1384 | - |
|
| 1385 | - private function connectDispatcher() { |
|
| 1386 | - $dispatcher = $this->getEventDispatcher(); |
|
| 1387 | - |
|
| 1388 | - // Delete avatar on user deletion |
|
| 1389 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
| 1390 | - $logger = $this->getLogger(); |
|
| 1391 | - $manager = $this->getAvatarManager(); |
|
| 1392 | - /** @var IUser $user */ |
|
| 1393 | - $user = $e->getSubject(); |
|
| 1394 | - |
|
| 1395 | - try { |
|
| 1396 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1397 | - $avatar->remove(); |
|
| 1398 | - } catch (NotFoundException $e) { |
|
| 1399 | - // no avatar to remove |
|
| 1400 | - } catch (\Exception $e) { |
|
| 1401 | - // Ignore exceptions |
|
| 1402 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1403 | - } |
|
| 1404 | - }); |
|
| 1405 | - |
|
| 1406 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1407 | - $manager = $this->getAvatarManager(); |
|
| 1408 | - /** @var IUser $user */ |
|
| 1409 | - $user = $e->getSubject(); |
|
| 1410 | - $feature = $e->getArgument('feature'); |
|
| 1411 | - $oldValue = $e->getArgument('oldValue'); |
|
| 1412 | - $value = $e->getArgument('value'); |
|
| 1413 | - |
|
| 1414 | - // We only change the avatar on display name changes |
|
| 1415 | - if ($feature !== 'displayName') { |
|
| 1416 | - return; |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - try { |
|
| 1420 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1421 | - $avatar->userChanged($feature, $oldValue, $value); |
|
| 1422 | - } catch (NotFoundException $e) { |
|
| 1423 | - // no avatar to remove |
|
| 1424 | - } |
|
| 1425 | - }); |
|
| 1426 | - |
|
| 1427 | - /** @var IEventDispatcher $eventDispatched */ |
|
| 1428 | - $eventDispatched = $this->query(IEventDispatcher::class); |
|
| 1429 | - $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1430 | - } |
|
| 1431 | - |
|
| 1432 | - /** |
|
| 1433 | - * @return \OCP\Contacts\IManager |
|
| 1434 | - */ |
|
| 1435 | - public function getContactsManager() { |
|
| 1436 | - return $this->query(\OCP\Contacts\IManager::class); |
|
| 1437 | - } |
|
| 1438 | - |
|
| 1439 | - /** |
|
| 1440 | - * @return \OC\Encryption\Manager |
|
| 1441 | - */ |
|
| 1442 | - public function getEncryptionManager() { |
|
| 1443 | - return $this->query(\OCP\Encryption\IManager::class); |
|
| 1444 | - } |
|
| 1445 | - |
|
| 1446 | - /** |
|
| 1447 | - * @return \OC\Encryption\File |
|
| 1448 | - */ |
|
| 1449 | - public function getEncryptionFilesHelper() { |
|
| 1450 | - return $this->query('EncryptionFileHelper'); |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - /** |
|
| 1454 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 1455 | - */ |
|
| 1456 | - public function getEncryptionKeyStorage() { |
|
| 1457 | - return $this->query('EncryptionKeyStorage'); |
|
| 1458 | - } |
|
| 1459 | - |
|
| 1460 | - /** |
|
| 1461 | - * The current request object holding all information about the request |
|
| 1462 | - * currently being processed is returned from this method. |
|
| 1463 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1464 | - * |
|
| 1465 | - * @return \OCP\IRequest |
|
| 1466 | - */ |
|
| 1467 | - public function getRequest() { |
|
| 1468 | - return $this->query(IRequest::class); |
|
| 1469 | - } |
|
| 1470 | - |
|
| 1471 | - /** |
|
| 1472 | - * Returns the preview manager which can create preview images for a given file |
|
| 1473 | - * |
|
| 1474 | - * @return IPreview |
|
| 1475 | - */ |
|
| 1476 | - public function getPreviewManager() { |
|
| 1477 | - return $this->query(IPreview::class); |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - /** |
|
| 1481 | - * Returns the tag manager which can get and set tags for different object types |
|
| 1482 | - * |
|
| 1483 | - * @see \OCP\ITagManager::load() |
|
| 1484 | - * @return ITagManager |
|
| 1485 | - */ |
|
| 1486 | - public function getTagManager() { |
|
| 1487 | - return $this->query(ITagManager::class); |
|
| 1488 | - } |
|
| 1489 | - |
|
| 1490 | - /** |
|
| 1491 | - * Returns the system-tag manager |
|
| 1492 | - * |
|
| 1493 | - * @return ISystemTagManager |
|
| 1494 | - * |
|
| 1495 | - * @since 9.0.0 |
|
| 1496 | - */ |
|
| 1497 | - public function getSystemTagManager() { |
|
| 1498 | - return $this->query(ISystemTagManager::class); |
|
| 1499 | - } |
|
| 1500 | - |
|
| 1501 | - /** |
|
| 1502 | - * Returns the system-tag object mapper |
|
| 1503 | - * |
|
| 1504 | - * @return ISystemTagObjectMapper |
|
| 1505 | - * |
|
| 1506 | - * @since 9.0.0 |
|
| 1507 | - */ |
|
| 1508 | - public function getSystemTagObjectMapper() { |
|
| 1509 | - return $this->query(ISystemTagObjectMapper::class); |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - /** |
|
| 1513 | - * Returns the avatar manager, used for avatar functionality |
|
| 1514 | - * |
|
| 1515 | - * @return IAvatarManager |
|
| 1516 | - */ |
|
| 1517 | - public function getAvatarManager() { |
|
| 1518 | - return $this->query(IAvatarManager::class); |
|
| 1519 | - } |
|
| 1520 | - |
|
| 1521 | - /** |
|
| 1522 | - * Returns the root folder of ownCloud's data directory |
|
| 1523 | - * |
|
| 1524 | - * @return IRootFolder |
|
| 1525 | - */ |
|
| 1526 | - public function getRootFolder() { |
|
| 1527 | - return $this->query(IRootFolder::class); |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - /** |
|
| 1531 | - * Returns the root folder of ownCloud's data directory |
|
| 1532 | - * This is the lazy variant so this gets only initialized once it |
|
| 1533 | - * is actually used. |
|
| 1534 | - * |
|
| 1535 | - * @return IRootFolder |
|
| 1536 | - */ |
|
| 1537 | - public function getLazyRootFolder() { |
|
| 1538 | - return $this->query(IRootFolder::class); |
|
| 1539 | - } |
|
| 1540 | - |
|
| 1541 | - /** |
|
| 1542 | - * Returns a view to ownCloud's files folder |
|
| 1543 | - * |
|
| 1544 | - * @param string $userId user ID |
|
| 1545 | - * @return \OCP\Files\Folder|null |
|
| 1546 | - */ |
|
| 1547 | - public function getUserFolder($userId = null) { |
|
| 1548 | - if ($userId === null) { |
|
| 1549 | - $user = $this->getUserSession()->getUser(); |
|
| 1550 | - if (!$user) { |
|
| 1551 | - return null; |
|
| 1552 | - } |
|
| 1553 | - $userId = $user->getUID(); |
|
| 1554 | - } |
|
| 1555 | - $root = $this->getRootFolder(); |
|
| 1556 | - return $root->getUserFolder($userId); |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - /** |
|
| 1560 | - * Returns an app-specific view in ownClouds data directory |
|
| 1561 | - * |
|
| 1562 | - * @return \OCP\Files\Folder |
|
| 1563 | - * @deprecated since 9.2.0 use IAppData |
|
| 1564 | - */ |
|
| 1565 | - public function getAppFolder() { |
|
| 1566 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1567 | - $root = $this->getRootFolder(); |
|
| 1568 | - if (!$root->nodeExists($dir)) { |
|
| 1569 | - $folder = $root->newFolder($dir); |
|
| 1570 | - } else { |
|
| 1571 | - $folder = $root->get($dir); |
|
| 1572 | - } |
|
| 1573 | - return $folder; |
|
| 1574 | - } |
|
| 1575 | - |
|
| 1576 | - /** |
|
| 1577 | - * @return \OC\User\Manager |
|
| 1578 | - */ |
|
| 1579 | - public function getUserManager() { |
|
| 1580 | - return $this->query(IUserManager::class); |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - /** |
|
| 1584 | - * @return \OC\Group\Manager |
|
| 1585 | - */ |
|
| 1586 | - public function getGroupManager() { |
|
| 1587 | - return $this->query(IGroupManager::class); |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - /** |
|
| 1591 | - * @return \OC\User\Session |
|
| 1592 | - */ |
|
| 1593 | - public function getUserSession() { |
|
| 1594 | - return $this->query(IUserSession::class); |
|
| 1595 | - } |
|
| 1596 | - |
|
| 1597 | - /** |
|
| 1598 | - * @return \OCP\ISession |
|
| 1599 | - */ |
|
| 1600 | - public function getSession() { |
|
| 1601 | - return $this->getUserSession()->getSession(); |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - /** |
|
| 1605 | - * @param \OCP\ISession $session |
|
| 1606 | - */ |
|
| 1607 | - public function setSession(\OCP\ISession $session) { |
|
| 1608 | - $this->query(SessionStorage::class)->setSession($session); |
|
| 1609 | - $this->getUserSession()->setSession($session); |
|
| 1610 | - $this->query(Store::class)->setSession($session); |
|
| 1611 | - } |
|
| 1612 | - |
|
| 1613 | - /** |
|
| 1614 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1615 | - */ |
|
| 1616 | - public function getTwoFactorAuthManager() { |
|
| 1617 | - return $this->query(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - /** |
|
| 1621 | - * @return \OC\NavigationManager |
|
| 1622 | - */ |
|
| 1623 | - public function getNavigationManager() { |
|
| 1624 | - return $this->query(INavigationManager::class); |
|
| 1625 | - } |
|
| 1626 | - |
|
| 1627 | - /** |
|
| 1628 | - * @return \OCP\IConfig |
|
| 1629 | - */ |
|
| 1630 | - public function getConfig() { |
|
| 1631 | - return $this->query(AllConfig::class); |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - /** |
|
| 1635 | - * @return \OC\SystemConfig |
|
| 1636 | - */ |
|
| 1637 | - public function getSystemConfig() { |
|
| 1638 | - return $this->query(SystemConfig::class); |
|
| 1639 | - } |
|
| 1640 | - |
|
| 1641 | - /** |
|
| 1642 | - * Returns the app config manager |
|
| 1643 | - * |
|
| 1644 | - * @return IAppConfig |
|
| 1645 | - */ |
|
| 1646 | - public function getAppConfig() { |
|
| 1647 | - return $this->query(IAppConfig::class); |
|
| 1648 | - } |
|
| 1649 | - |
|
| 1650 | - /** |
|
| 1651 | - * @return IFactory |
|
| 1652 | - */ |
|
| 1653 | - public function getL10NFactory() { |
|
| 1654 | - return $this->query(IFactory::class); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - /** |
|
| 1658 | - * get an L10N instance |
|
| 1659 | - * |
|
| 1660 | - * @param string $app appid |
|
| 1661 | - * @param string $lang |
|
| 1662 | - * @return IL10N |
|
| 1663 | - */ |
|
| 1664 | - public function getL10N($app, $lang = null) { |
|
| 1665 | - return $this->getL10NFactory()->get($app, $lang); |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - /** |
|
| 1669 | - * @return IURLGenerator |
|
| 1670 | - */ |
|
| 1671 | - public function getURLGenerator() { |
|
| 1672 | - return $this->query(IURLGenerator::class); |
|
| 1673 | - } |
|
| 1674 | - |
|
| 1675 | - /** |
|
| 1676 | - * @return AppFetcher |
|
| 1677 | - */ |
|
| 1678 | - public function getAppFetcher() { |
|
| 1679 | - return $this->query(AppFetcher::class); |
|
| 1680 | - } |
|
| 1681 | - |
|
| 1682 | - /** |
|
| 1683 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1684 | - * getMemCacheFactory() instead. |
|
| 1685 | - * |
|
| 1686 | - * @return ICache |
|
| 1687 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1688 | - */ |
|
| 1689 | - public function getCache() { |
|
| 1690 | - return $this->query(ICache::class); |
|
| 1691 | - } |
|
| 1692 | - |
|
| 1693 | - /** |
|
| 1694 | - * Returns an \OCP\CacheFactory instance |
|
| 1695 | - * |
|
| 1696 | - * @return \OCP\ICacheFactory |
|
| 1697 | - */ |
|
| 1698 | - public function getMemCacheFactory() { |
|
| 1699 | - return $this->query(Factory::class); |
|
| 1700 | - } |
|
| 1701 | - |
|
| 1702 | - /** |
|
| 1703 | - * Returns an \OC\RedisFactory instance |
|
| 1704 | - * |
|
| 1705 | - * @return \OC\RedisFactory |
|
| 1706 | - */ |
|
| 1707 | - public function getGetRedisFactory() { |
|
| 1708 | - return $this->query('RedisFactory'); |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * Returns the current session |
|
| 1714 | - * |
|
| 1715 | - * @return \OCP\IDBConnection |
|
| 1716 | - */ |
|
| 1717 | - public function getDatabaseConnection() { |
|
| 1718 | - return $this->query(IDBConnection::class); |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - /** |
|
| 1722 | - * Returns the activity manager |
|
| 1723 | - * |
|
| 1724 | - * @return \OCP\Activity\IManager |
|
| 1725 | - */ |
|
| 1726 | - public function getActivityManager() { |
|
| 1727 | - return $this->query(\OCP\Activity\IManager::class); |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - /** |
|
| 1731 | - * Returns an job list for controlling background jobs |
|
| 1732 | - * |
|
| 1733 | - * @return IJobList |
|
| 1734 | - */ |
|
| 1735 | - public function getJobList() { |
|
| 1736 | - return $this->query(IJobList::class); |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - /** |
|
| 1740 | - * Returns a logger instance |
|
| 1741 | - * |
|
| 1742 | - * @return ILogger |
|
| 1743 | - */ |
|
| 1744 | - public function getLogger() { |
|
| 1745 | - return $this->query(ILogger::class); |
|
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - /** |
|
| 1749 | - * @return ILogFactory |
|
| 1750 | - * @throws \OCP\AppFramework\QueryException |
|
| 1751 | - */ |
|
| 1752 | - public function getLogFactory() { |
|
| 1753 | - return $this->query(ILogFactory::class); |
|
| 1754 | - } |
|
| 1755 | - |
|
| 1756 | - /** |
|
| 1757 | - * Returns a router for generating and matching urls |
|
| 1758 | - * |
|
| 1759 | - * @return IRouter |
|
| 1760 | - */ |
|
| 1761 | - public function getRouter() { |
|
| 1762 | - return $this->query(IRouter::class); |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - /** |
|
| 1766 | - * Returns a search instance |
|
| 1767 | - * |
|
| 1768 | - * @return ISearch |
|
| 1769 | - */ |
|
| 1770 | - public function getSearch() { |
|
| 1771 | - return $this->query(ISearch::class); |
|
| 1772 | - } |
|
| 1773 | - |
|
| 1774 | - /** |
|
| 1775 | - * Returns a SecureRandom instance |
|
| 1776 | - * |
|
| 1777 | - * @return \OCP\Security\ISecureRandom |
|
| 1778 | - */ |
|
| 1779 | - public function getSecureRandom() { |
|
| 1780 | - return $this->query(ISecureRandom::class); |
|
| 1781 | - } |
|
| 1782 | - |
|
| 1783 | - /** |
|
| 1784 | - * Returns a Crypto instance |
|
| 1785 | - * |
|
| 1786 | - * @return ICrypto |
|
| 1787 | - */ |
|
| 1788 | - public function getCrypto() { |
|
| 1789 | - return $this->query(ICrypto::class); |
|
| 1790 | - } |
|
| 1791 | - |
|
| 1792 | - /** |
|
| 1793 | - * Returns a Hasher instance |
|
| 1794 | - * |
|
| 1795 | - * @return IHasher |
|
| 1796 | - */ |
|
| 1797 | - public function getHasher() { |
|
| 1798 | - return $this->query(IHasher::class); |
|
| 1799 | - } |
|
| 1800 | - |
|
| 1801 | - /** |
|
| 1802 | - * Returns a CredentialsManager instance |
|
| 1803 | - * |
|
| 1804 | - * @return ICredentialsManager |
|
| 1805 | - */ |
|
| 1806 | - public function getCredentialsManager() { |
|
| 1807 | - return $this->query(ICredentialsManager::class); |
|
| 1808 | - } |
|
| 1809 | - |
|
| 1810 | - /** |
|
| 1811 | - * Get the certificate manager for the user |
|
| 1812 | - * |
|
| 1813 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1814 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1815 | - */ |
|
| 1816 | - public function getCertificateManager($userId = '') { |
|
| 1817 | - if ($userId === '') { |
|
| 1818 | - $userSession = $this->getUserSession(); |
|
| 1819 | - $user = $userSession->getUser(); |
|
| 1820 | - if (is_null($user)) { |
|
| 1821 | - return null; |
|
| 1822 | - } |
|
| 1823 | - $userId = $user->getUID(); |
|
| 1824 | - } |
|
| 1825 | - return new CertificateManager( |
|
| 1826 | - $userId, |
|
| 1827 | - new View(), |
|
| 1828 | - $this->getConfig(), |
|
| 1829 | - $this->getLogger(), |
|
| 1830 | - $this->getSecureRandom() |
|
| 1831 | - ); |
|
| 1832 | - } |
|
| 1833 | - |
|
| 1834 | - /** |
|
| 1835 | - * Returns an instance of the HTTP client service |
|
| 1836 | - * |
|
| 1837 | - * @return IClientService |
|
| 1838 | - */ |
|
| 1839 | - public function getHTTPClientService() { |
|
| 1840 | - return $this->query(IClientService::class); |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - /** |
|
| 1844 | - * Create a new event source |
|
| 1845 | - * |
|
| 1846 | - * @return \OCP\IEventSource |
|
| 1847 | - */ |
|
| 1848 | - public function createEventSource() { |
|
| 1849 | - return new \OC_EventSource(); |
|
| 1850 | - } |
|
| 1851 | - |
|
| 1852 | - /** |
|
| 1853 | - * Get the active event logger |
|
| 1854 | - * |
|
| 1855 | - * The returned logger only logs data when debug mode is enabled |
|
| 1856 | - * |
|
| 1857 | - * @return IEventLogger |
|
| 1858 | - */ |
|
| 1859 | - public function getEventLogger() { |
|
| 1860 | - return $this->query(IEventLogger::class); |
|
| 1861 | - } |
|
| 1862 | - |
|
| 1863 | - /** |
|
| 1864 | - * Get the active query logger |
|
| 1865 | - * |
|
| 1866 | - * The returned logger only logs data when debug mode is enabled |
|
| 1867 | - * |
|
| 1868 | - * @return IQueryLogger |
|
| 1869 | - */ |
|
| 1870 | - public function getQueryLogger() { |
|
| 1871 | - return $this->query(IQueryLogger::class); |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - /** |
|
| 1875 | - * Get the manager for temporary files and folders |
|
| 1876 | - * |
|
| 1877 | - * @return \OCP\ITempManager |
|
| 1878 | - */ |
|
| 1879 | - public function getTempManager() { |
|
| 1880 | - return $this->query(ITempManager::class); |
|
| 1881 | - } |
|
| 1882 | - |
|
| 1883 | - /** |
|
| 1884 | - * Get the app manager |
|
| 1885 | - * |
|
| 1886 | - * @return \OCP\App\IAppManager |
|
| 1887 | - */ |
|
| 1888 | - public function getAppManager() { |
|
| 1889 | - return $this->query(IAppManager::class); |
|
| 1890 | - } |
|
| 1891 | - |
|
| 1892 | - /** |
|
| 1893 | - * Creates a new mailer |
|
| 1894 | - * |
|
| 1895 | - * @return IMailer |
|
| 1896 | - */ |
|
| 1897 | - public function getMailer() { |
|
| 1898 | - return $this->query(IMailer::class); |
|
| 1899 | - } |
|
| 1900 | - |
|
| 1901 | - /** |
|
| 1902 | - * Get the webroot |
|
| 1903 | - * |
|
| 1904 | - * @return string |
|
| 1905 | - */ |
|
| 1906 | - public function getWebRoot() { |
|
| 1907 | - return $this->webRoot; |
|
| 1908 | - } |
|
| 1909 | - |
|
| 1910 | - /** |
|
| 1911 | - * @return \OC\OCSClient |
|
| 1912 | - */ |
|
| 1913 | - public function getOcsClient() { |
|
| 1914 | - return $this->query('OcsClient'); |
|
| 1915 | - } |
|
| 1916 | - |
|
| 1917 | - /** |
|
| 1918 | - * @return IDateTimeZone |
|
| 1919 | - */ |
|
| 1920 | - public function getDateTimeZone() { |
|
| 1921 | - return $this->query(IDateTimeZone::class); |
|
| 1922 | - } |
|
| 1923 | - |
|
| 1924 | - /** |
|
| 1925 | - * @return IDateTimeFormatter |
|
| 1926 | - */ |
|
| 1927 | - public function getDateTimeFormatter() { |
|
| 1928 | - return $this->query(IDateTimeFormatter::class); |
|
| 1929 | - } |
|
| 1930 | - |
|
| 1931 | - /** |
|
| 1932 | - * @return IMountProviderCollection |
|
| 1933 | - */ |
|
| 1934 | - public function getMountProviderCollection() { |
|
| 1935 | - return $this->query(IMountProviderCollection::class); |
|
| 1936 | - } |
|
| 1937 | - |
|
| 1938 | - /** |
|
| 1939 | - * Get the IniWrapper |
|
| 1940 | - * |
|
| 1941 | - * @return IniGetWrapper |
|
| 1942 | - */ |
|
| 1943 | - public function getIniWrapper() { |
|
| 1944 | - return $this->query('IniWrapper'); |
|
| 1945 | - } |
|
| 1946 | - |
|
| 1947 | - /** |
|
| 1948 | - * @return \OCP\Command\IBus |
|
| 1949 | - */ |
|
| 1950 | - public function getCommandBus() { |
|
| 1951 | - return $this->query('AsyncCommandBus'); |
|
| 1952 | - } |
|
| 1953 | - |
|
| 1954 | - /** |
|
| 1955 | - * Get the trusted domain helper |
|
| 1956 | - * |
|
| 1957 | - * @return TrustedDomainHelper |
|
| 1958 | - */ |
|
| 1959 | - public function getTrustedDomainHelper() { |
|
| 1960 | - return $this->query('TrustedDomainHelper'); |
|
| 1961 | - } |
|
| 1962 | - |
|
| 1963 | - /** |
|
| 1964 | - * Get the locking provider |
|
| 1965 | - * |
|
| 1966 | - * @return ILockingProvider |
|
| 1967 | - * @since 8.1.0 |
|
| 1968 | - */ |
|
| 1969 | - public function getLockingProvider() { |
|
| 1970 | - return $this->query(ILockingProvider::class); |
|
| 1971 | - } |
|
| 1972 | - |
|
| 1973 | - /** |
|
| 1974 | - * @return IMountManager |
|
| 1975 | - **/ |
|
| 1976 | - public function getMountManager() { |
|
| 1977 | - return $this->query(IMountManager::class); |
|
| 1978 | - } |
|
| 1979 | - |
|
| 1980 | - /** |
|
| 1981 | - * @return IUserMountCache |
|
| 1982 | - */ |
|
| 1983 | - public function getUserMountCache() { |
|
| 1984 | - return $this->query(IUserMountCache::class); |
|
| 1985 | - } |
|
| 1986 | - |
|
| 1987 | - /** |
|
| 1988 | - * Get the MimeTypeDetector |
|
| 1989 | - * |
|
| 1990 | - * @return IMimeTypeDetector |
|
| 1991 | - */ |
|
| 1992 | - public function getMimeTypeDetector() { |
|
| 1993 | - return $this->query(IMimeTypeDetector::class); |
|
| 1994 | - } |
|
| 1995 | - |
|
| 1996 | - /** |
|
| 1997 | - * Get the MimeTypeLoader |
|
| 1998 | - * |
|
| 1999 | - * @return IMimeTypeLoader |
|
| 2000 | - */ |
|
| 2001 | - public function getMimeTypeLoader() { |
|
| 2002 | - return $this->query(IMimeTypeLoader::class); |
|
| 2003 | - } |
|
| 2004 | - |
|
| 2005 | - /** |
|
| 2006 | - * Get the manager of all the capabilities |
|
| 2007 | - * |
|
| 2008 | - * @return CapabilitiesManager |
|
| 2009 | - */ |
|
| 2010 | - public function getCapabilitiesManager() { |
|
| 2011 | - return $this->query(CapabilitiesManager::class); |
|
| 2012 | - } |
|
| 2013 | - |
|
| 2014 | - /** |
|
| 2015 | - * Get the EventDispatcher |
|
| 2016 | - * |
|
| 2017 | - * @return EventDispatcherInterface |
|
| 2018 | - * @since 8.2.0 |
|
| 2019 | - * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
| 2020 | - */ |
|
| 2021 | - public function getEventDispatcher() { |
|
| 2022 | - return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
| 2023 | - } |
|
| 2024 | - |
|
| 2025 | - /** |
|
| 2026 | - * Get the Notification Manager |
|
| 2027 | - * |
|
| 2028 | - * @return \OCP\Notification\IManager |
|
| 2029 | - * @since 8.2.0 |
|
| 2030 | - */ |
|
| 2031 | - public function getNotificationManager() { |
|
| 2032 | - return $this->query(\OCP\Notification\IManager::class); |
|
| 2033 | - } |
|
| 2034 | - |
|
| 2035 | - /** |
|
| 2036 | - * @return ICommentsManager |
|
| 2037 | - */ |
|
| 2038 | - public function getCommentsManager() { |
|
| 2039 | - return $this->query(ICommentsManager::class); |
|
| 2040 | - } |
|
| 2041 | - |
|
| 2042 | - /** |
|
| 2043 | - * @return \OCA\Theming\ThemingDefaults |
|
| 2044 | - */ |
|
| 2045 | - public function getThemingDefaults() { |
|
| 2046 | - return $this->query('ThemingDefaults'); |
|
| 2047 | - } |
|
| 2048 | - |
|
| 2049 | - /** |
|
| 2050 | - * @return \OC\IntegrityCheck\Checker |
|
| 2051 | - */ |
|
| 2052 | - public function getIntegrityCodeChecker() { |
|
| 2053 | - return $this->query('IntegrityCodeChecker'); |
|
| 2054 | - } |
|
| 2055 | - |
|
| 2056 | - /** |
|
| 2057 | - * @return \OC\Session\CryptoWrapper |
|
| 2058 | - */ |
|
| 2059 | - public function getSessionCryptoWrapper() { |
|
| 2060 | - return $this->query('CryptoWrapper'); |
|
| 2061 | - } |
|
| 2062 | - |
|
| 2063 | - /** |
|
| 2064 | - * @return CsrfTokenManager |
|
| 2065 | - */ |
|
| 2066 | - public function getCsrfTokenManager() { |
|
| 2067 | - return $this->query(CsrfTokenManager::class); |
|
| 2068 | - } |
|
| 2069 | - |
|
| 2070 | - /** |
|
| 2071 | - * @return Throttler |
|
| 2072 | - */ |
|
| 2073 | - public function getBruteForceThrottler() { |
|
| 2074 | - return $this->query(Throttler::class); |
|
| 2075 | - } |
|
| 2076 | - |
|
| 2077 | - /** |
|
| 2078 | - * @return IContentSecurityPolicyManager |
|
| 2079 | - */ |
|
| 2080 | - public function getContentSecurityPolicyManager() { |
|
| 2081 | - return $this->query(ContentSecurityPolicyManager::class); |
|
| 2082 | - } |
|
| 2083 | - |
|
| 2084 | - /** |
|
| 2085 | - * @return ContentSecurityPolicyNonceManager |
|
| 2086 | - */ |
|
| 2087 | - public function getContentSecurityPolicyNonceManager() { |
|
| 2088 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 2089 | - } |
|
| 2090 | - |
|
| 2091 | - /** |
|
| 2092 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2093 | - * |
|
| 2094 | - * @return \OCA\Files_External\Service\BackendService |
|
| 2095 | - */ |
|
| 2096 | - public function getStoragesBackendService() { |
|
| 2097 | - return $this->query(BackendService::class); |
|
| 2098 | - } |
|
| 2099 | - |
|
| 2100 | - /** |
|
| 2101 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2102 | - * |
|
| 2103 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 2104 | - */ |
|
| 2105 | - public function getGlobalStoragesService() { |
|
| 2106 | - return $this->query(GlobalStoragesService::class); |
|
| 2107 | - } |
|
| 2108 | - |
|
| 2109 | - /** |
|
| 2110 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2111 | - * |
|
| 2112 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 2113 | - */ |
|
| 2114 | - public function getUserGlobalStoragesService() { |
|
| 2115 | - return $this->query(UserGlobalStoragesService::class); |
|
| 2116 | - } |
|
| 2117 | - |
|
| 2118 | - /** |
|
| 2119 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2120 | - * |
|
| 2121 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
| 2122 | - */ |
|
| 2123 | - public function getUserStoragesService() { |
|
| 2124 | - return $this->query(UserStoragesService::class); |
|
| 2125 | - } |
|
| 2126 | - |
|
| 2127 | - /** |
|
| 2128 | - * @return \OCP\Share\IManager |
|
| 2129 | - */ |
|
| 2130 | - public function getShareManager() { |
|
| 2131 | - return $this->query(\OCP\Share\IManager::class); |
|
| 2132 | - } |
|
| 2133 | - |
|
| 2134 | - /** |
|
| 2135 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 2136 | - */ |
|
| 2137 | - public function getCollaboratorSearch() { |
|
| 2138 | - return $this->query(\OCP\Collaboration\Collaborators\ISearch::class); |
|
| 2139 | - } |
|
| 2140 | - |
|
| 2141 | - /** |
|
| 2142 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 2143 | - */ |
|
| 2144 | - public function getAutoCompleteManager() { |
|
| 2145 | - return $this->query(IManager::class); |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - /** |
|
| 2149 | - * Returns the LDAP Provider |
|
| 2150 | - * |
|
| 2151 | - * @return \OCP\LDAP\ILDAPProvider |
|
| 2152 | - */ |
|
| 2153 | - public function getLDAPProvider() { |
|
| 2154 | - return $this->query('LDAPProvider'); |
|
| 2155 | - } |
|
| 2156 | - |
|
| 2157 | - /** |
|
| 2158 | - * @return \OCP\Settings\IManager |
|
| 2159 | - */ |
|
| 2160 | - public function getSettingsManager() { |
|
| 2161 | - return $this->query('SettingsManager'); |
|
| 2162 | - } |
|
| 2163 | - |
|
| 2164 | - /** |
|
| 2165 | - * @return \OCP\Files\IAppData |
|
| 2166 | - */ |
|
| 2167 | - public function getAppDataDir($app) { |
|
| 2168 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2169 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 2170 | - return $factory->get($app); |
|
| 2171 | - } |
|
| 2172 | - |
|
| 2173 | - /** |
|
| 2174 | - * @return \OCP\Lockdown\ILockdownManager |
|
| 2175 | - */ |
|
| 2176 | - public function getLockdownManager() { |
|
| 2177 | - return $this->query('LockdownManager'); |
|
| 2178 | - } |
|
| 2179 | - |
|
| 2180 | - /** |
|
| 2181 | - * @return \OCP\Federation\ICloudIdManager |
|
| 2182 | - */ |
|
| 2183 | - public function getCloudIdManager() { |
|
| 2184 | - return $this->query(ICloudIdManager::class); |
|
| 2185 | - } |
|
| 2186 | - |
|
| 2187 | - /** |
|
| 2188 | - * @return \OCP\GlobalScale\IConfig |
|
| 2189 | - */ |
|
| 2190 | - public function getGlobalScaleConfig() { |
|
| 2191 | - return $this->query(IConfig::class); |
|
| 2192 | - } |
|
| 2193 | - |
|
| 2194 | - /** |
|
| 2195 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2196 | - */ |
|
| 2197 | - public function getCloudFederationProviderManager() { |
|
| 2198 | - return $this->query(ICloudFederationProviderManager::class); |
|
| 2199 | - } |
|
| 2200 | - |
|
| 2201 | - /** |
|
| 2202 | - * @return \OCP\Remote\Api\IApiFactory |
|
| 2203 | - */ |
|
| 2204 | - public function getRemoteApiFactory() { |
|
| 2205 | - return $this->query(IApiFactory::class); |
|
| 2206 | - } |
|
| 2207 | - |
|
| 2208 | - /** |
|
| 2209 | - * @return \OCP\Federation\ICloudFederationFactory |
|
| 2210 | - */ |
|
| 2211 | - public function getCloudFederationFactory() { |
|
| 2212 | - return $this->query(ICloudFederationFactory::class); |
|
| 2213 | - } |
|
| 2214 | - |
|
| 2215 | - /** |
|
| 2216 | - * @return \OCP\Remote\IInstanceFactory |
|
| 2217 | - */ |
|
| 2218 | - public function getRemoteInstanceFactory() { |
|
| 2219 | - return $this->query(IInstanceFactory::class); |
|
| 2220 | - } |
|
| 2221 | - |
|
| 2222 | - /** |
|
| 2223 | - * @return IStorageFactory |
|
| 2224 | - */ |
|
| 2225 | - public function getStorageFactory() { |
|
| 2226 | - return $this->query(IStorageFactory::class); |
|
| 2227 | - } |
|
| 2228 | - |
|
| 2229 | - /** |
|
| 2230 | - * Get the Preview GeneratorHelper |
|
| 2231 | - * |
|
| 2232 | - * @return GeneratorHelper |
|
| 2233 | - * @since 17.0.0 |
|
| 2234 | - */ |
|
| 2235 | - public function getGeneratorHelper() { |
|
| 2236 | - return $this->query(\OC\Preview\GeneratorHelper::class); |
|
| 2237 | - } |
|
| 2238 | - |
|
| 2239 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 2240 | - $this->registerService($alias, function (IContainer $container) use ($target, $alias) { |
|
| 2241 | - try { |
|
| 2242 | - /** @var ILogger $logger */ |
|
| 2243 | - $logger = $container->query(ILogger::class); |
|
| 2244 | - $logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2245 | - } catch (QueryException $e) { |
|
| 2246 | - // Could not get logger. Continue |
|
| 2247 | - } |
|
| 2248 | - |
|
| 2249 | - return $container->query($target); |
|
| 2250 | - }, false); |
|
| 2251 | - } |
|
| 1111 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 1112 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 1113 | + $classExists = true; |
|
| 1114 | + } else { |
|
| 1115 | + $classExists = false; |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1119 | + return new ThemingDefaults( |
|
| 1120 | + $c->getConfig(), |
|
| 1121 | + $c->getL10N('theming'), |
|
| 1122 | + $c->getURLGenerator(), |
|
| 1123 | + $c->getMemCacheFactory(), |
|
| 1124 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
| 1125 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
| 1126 | + $c->getAppManager(), |
|
| 1127 | + $c->getNavigationManager() |
|
| 1128 | + ); |
|
| 1129 | + } |
|
| 1130 | + return new \OC_Defaults(); |
|
| 1131 | + }); |
|
| 1132 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 1133 | + return new SCSSCacher( |
|
| 1134 | + $c->getLogger(), |
|
| 1135 | + $c->query(\OC\Files\AppData\Factory::class), |
|
| 1136 | + $c->getURLGenerator(), |
|
| 1137 | + $c->getConfig(), |
|
| 1138 | + $c->getThemingDefaults(), |
|
| 1139 | + \OC::$SERVERROOT, |
|
| 1140 | + $this->getMemCacheFactory(), |
|
| 1141 | + $c->query(IconsCacher::class), |
|
| 1142 | + new TimeFactory() |
|
| 1143 | + ); |
|
| 1144 | + }); |
|
| 1145 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1146 | + return new JSCombiner( |
|
| 1147 | + $c->getAppDataDir('js'), |
|
| 1148 | + $c->getURLGenerator(), |
|
| 1149 | + $this->getMemCacheFactory(), |
|
| 1150 | + $c->getSystemConfig(), |
|
| 1151 | + $c->getLogger() |
|
| 1152 | + ); |
|
| 1153 | + }); |
|
| 1154 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1155 | + $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1156 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1157 | + |
|
| 1158 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 1159 | + // FIXME: Instantiiated here due to cyclic dependency |
|
| 1160 | + $request = new Request( |
|
| 1161 | + [ |
|
| 1162 | + 'get' => $_GET, |
|
| 1163 | + 'post' => $_POST, |
|
| 1164 | + 'files' => $_FILES, |
|
| 1165 | + 'server' => $_SERVER, |
|
| 1166 | + 'env' => $_ENV, |
|
| 1167 | + 'cookies' => $_COOKIE, |
|
| 1168 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1169 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1170 | + : null, |
|
| 1171 | + ], |
|
| 1172 | + $c->getSecureRandom(), |
|
| 1173 | + $c->getConfig() |
|
| 1174 | + ); |
|
| 1175 | + |
|
| 1176 | + return new CryptoWrapper( |
|
| 1177 | + $c->getConfig(), |
|
| 1178 | + $c->getCrypto(), |
|
| 1179 | + $c->getSecureRandom(), |
|
| 1180 | + $request |
|
| 1181 | + ); |
|
| 1182 | + }); |
|
| 1183 | + $this->registerService(CsrfTokenManager::class, function (Server $c) { |
|
| 1184 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 1185 | + |
|
| 1186 | + return new CsrfTokenManager( |
|
| 1187 | + $tokenGenerator, |
|
| 1188 | + $c->query(SessionStorage::class) |
|
| 1189 | + ); |
|
| 1190 | + }); |
|
| 1191 | + $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
| 1192 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1193 | + return new SessionStorage($c->getSession()); |
|
| 1194 | + }); |
|
| 1195 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1196 | + $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
| 1197 | + |
|
| 1198 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 1199 | + return new ContentSecurityPolicyNonceManager( |
|
| 1200 | + $c->getCsrfTokenManager(), |
|
| 1201 | + $c->getRequest() |
|
| 1202 | + ); |
|
| 1203 | + }); |
|
| 1204 | + |
|
| 1205 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1206 | + $config = $c->getConfig(); |
|
| 1207 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1208 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1209 | + $factory = new $factoryClass($this); |
|
| 1210 | + |
|
| 1211 | + $manager = new \OC\Share20\Manager( |
|
| 1212 | + $c->getLogger(), |
|
| 1213 | + $c->getConfig(), |
|
| 1214 | + $c->getSecureRandom(), |
|
| 1215 | + $c->getHasher(), |
|
| 1216 | + $c->getMountManager(), |
|
| 1217 | + $c->getGroupManager(), |
|
| 1218 | + $c->getL10N('lib'), |
|
| 1219 | + $c->getL10NFactory(), |
|
| 1220 | + $factory, |
|
| 1221 | + $c->getUserManager(), |
|
| 1222 | + $c->getLazyRootFolder(), |
|
| 1223 | + $c->getEventDispatcher(), |
|
| 1224 | + $c->getMailer(), |
|
| 1225 | + $c->getURLGenerator(), |
|
| 1226 | + $c->getThemingDefaults(), |
|
| 1227 | + $c->query(IEventDispatcher::class) |
|
| 1228 | + ); |
|
| 1229 | + |
|
| 1230 | + return $manager; |
|
| 1231 | + }); |
|
| 1232 | + $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1233 | + |
|
| 1234 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1235 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1236 | + |
|
| 1237 | + // register default plugins |
|
| 1238 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1239 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1240 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1241 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1242 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1243 | + |
|
| 1244 | + return $instance; |
|
| 1245 | + }); |
|
| 1246 | + $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1247 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1248 | + |
|
| 1249 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1250 | + |
|
| 1251 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1252 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1253 | + |
|
| 1254 | + $this->registerService('SettingsManager', function (Server $c) { |
|
| 1255 | + $manager = new \OC\Settings\Manager( |
|
| 1256 | + $c->getLogger(), |
|
| 1257 | + $c->getL10NFactory(), |
|
| 1258 | + $c->getURLGenerator(), |
|
| 1259 | + $c |
|
| 1260 | + ); |
|
| 1261 | + return $manager; |
|
| 1262 | + }); |
|
| 1263 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1264 | + return new \OC\Files\AppData\Factory( |
|
| 1265 | + $c->getRootFolder(), |
|
| 1266 | + $c->getSystemConfig() |
|
| 1267 | + ); |
|
| 1268 | + }); |
|
| 1269 | + |
|
| 1270 | + $this->registerService('LockdownManager', function (Server $c) { |
|
| 1271 | + return new LockdownManager(function () use ($c) { |
|
| 1272 | + return $c->getSession(); |
|
| 1273 | + }); |
|
| 1274 | + }); |
|
| 1275 | + |
|
| 1276 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1277 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 1278 | + }); |
|
| 1279 | + |
|
| 1280 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1281 | + return new CloudIdManager(); |
|
| 1282 | + }); |
|
| 1283 | + |
|
| 1284 | + $this->registerService(IConfig::class, function (Server $c) { |
|
| 1285 | + return new GlobalScale\Config($c->getConfig()); |
|
| 1286 | + }); |
|
| 1287 | + |
|
| 1288 | + $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
| 1289 | + return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
| 1290 | + }); |
|
| 1291 | + |
|
| 1292 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1293 | + return new CloudFederationFactory(); |
|
| 1294 | + }); |
|
| 1295 | + |
|
| 1296 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1297 | + $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1298 | + |
|
| 1299 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1300 | + $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1301 | + |
|
| 1302 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1303 | + return new Defaults( |
|
| 1304 | + $c->getThemingDefaults() |
|
| 1305 | + ); |
|
| 1306 | + }); |
|
| 1307 | + $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
| 1308 | + |
|
| 1309 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1310 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1311 | + }); |
|
| 1312 | + |
|
| 1313 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1314 | + return new ShareHelper( |
|
| 1315 | + $c->query(\OCP\Share\IManager::class) |
|
| 1316 | + ); |
|
| 1317 | + }); |
|
| 1318 | + |
|
| 1319 | + $this->registerService(Installer::class, function (Server $c) { |
|
| 1320 | + return new Installer( |
|
| 1321 | + $c->getAppFetcher(), |
|
| 1322 | + $c->getHTTPClientService(), |
|
| 1323 | + $c->getTempManager(), |
|
| 1324 | + $c->getLogger(), |
|
| 1325 | + $c->getConfig(), |
|
| 1326 | + \OC::$CLI |
|
| 1327 | + ); |
|
| 1328 | + }); |
|
| 1329 | + |
|
| 1330 | + $this->registerService(IApiFactory::class, function (Server $c) { |
|
| 1331 | + return new ApiFactory($c->getHTTPClientService()); |
|
| 1332 | + }); |
|
| 1333 | + |
|
| 1334 | + $this->registerService(IInstanceFactory::class, function (Server $c) { |
|
| 1335 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1336 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
| 1337 | + }); |
|
| 1338 | + |
|
| 1339 | + $this->registerService(IContactsStore::class, function (Server $c) { |
|
| 1340 | + return new ContactsStore( |
|
| 1341 | + $c->getContactsManager(), |
|
| 1342 | + $c->getConfig(), |
|
| 1343 | + $c->getUserManager(), |
|
| 1344 | + $c->getGroupManager() |
|
| 1345 | + ); |
|
| 1346 | + }); |
|
| 1347 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1348 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1349 | + |
|
| 1350 | + $this->registerService(IStorageFactory::class, function () { |
|
| 1351 | + return new StorageFactory(); |
|
| 1352 | + }); |
|
| 1353 | + |
|
| 1354 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
| 1355 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1356 | + |
|
| 1357 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1358 | + |
|
| 1359 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1360 | + |
|
| 1361 | + $this->connectDispatcher(); |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + /** |
|
| 1365 | + * @return \OCP\Calendar\IManager |
|
| 1366 | + */ |
|
| 1367 | + public function getCalendarManager() { |
|
| 1368 | + return $this->query(\OC\Calendar\Manager::class); |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + /** |
|
| 1372 | + * @return \OCP\Calendar\Resource\IManager |
|
| 1373 | + */ |
|
| 1374 | + public function getCalendarResourceBackendManager() { |
|
| 1375 | + return $this->query(\OC\Calendar\Resource\Manager::class); |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * @return \OCP\Calendar\Room\IManager |
|
| 1380 | + */ |
|
| 1381 | + public function getCalendarRoomBackendManager() { |
|
| 1382 | + return $this->query(\OC\Calendar\Room\Manager::class); |
|
| 1383 | + } |
|
| 1384 | + |
|
| 1385 | + private function connectDispatcher() { |
|
| 1386 | + $dispatcher = $this->getEventDispatcher(); |
|
| 1387 | + |
|
| 1388 | + // Delete avatar on user deletion |
|
| 1389 | + $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
| 1390 | + $logger = $this->getLogger(); |
|
| 1391 | + $manager = $this->getAvatarManager(); |
|
| 1392 | + /** @var IUser $user */ |
|
| 1393 | + $user = $e->getSubject(); |
|
| 1394 | + |
|
| 1395 | + try { |
|
| 1396 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1397 | + $avatar->remove(); |
|
| 1398 | + } catch (NotFoundException $e) { |
|
| 1399 | + // no avatar to remove |
|
| 1400 | + } catch (\Exception $e) { |
|
| 1401 | + // Ignore exceptions |
|
| 1402 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1403 | + } |
|
| 1404 | + }); |
|
| 1405 | + |
|
| 1406 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1407 | + $manager = $this->getAvatarManager(); |
|
| 1408 | + /** @var IUser $user */ |
|
| 1409 | + $user = $e->getSubject(); |
|
| 1410 | + $feature = $e->getArgument('feature'); |
|
| 1411 | + $oldValue = $e->getArgument('oldValue'); |
|
| 1412 | + $value = $e->getArgument('value'); |
|
| 1413 | + |
|
| 1414 | + // We only change the avatar on display name changes |
|
| 1415 | + if ($feature !== 'displayName') { |
|
| 1416 | + return; |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + try { |
|
| 1420 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1421 | + $avatar->userChanged($feature, $oldValue, $value); |
|
| 1422 | + } catch (NotFoundException $e) { |
|
| 1423 | + // no avatar to remove |
|
| 1424 | + } |
|
| 1425 | + }); |
|
| 1426 | + |
|
| 1427 | + /** @var IEventDispatcher $eventDispatched */ |
|
| 1428 | + $eventDispatched = $this->query(IEventDispatcher::class); |
|
| 1429 | + $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1430 | + } |
|
| 1431 | + |
|
| 1432 | + /** |
|
| 1433 | + * @return \OCP\Contacts\IManager |
|
| 1434 | + */ |
|
| 1435 | + public function getContactsManager() { |
|
| 1436 | + return $this->query(\OCP\Contacts\IManager::class); |
|
| 1437 | + } |
|
| 1438 | + |
|
| 1439 | + /** |
|
| 1440 | + * @return \OC\Encryption\Manager |
|
| 1441 | + */ |
|
| 1442 | + public function getEncryptionManager() { |
|
| 1443 | + return $this->query(\OCP\Encryption\IManager::class); |
|
| 1444 | + } |
|
| 1445 | + |
|
| 1446 | + /** |
|
| 1447 | + * @return \OC\Encryption\File |
|
| 1448 | + */ |
|
| 1449 | + public function getEncryptionFilesHelper() { |
|
| 1450 | + return $this->query('EncryptionFileHelper'); |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + /** |
|
| 1454 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 1455 | + */ |
|
| 1456 | + public function getEncryptionKeyStorage() { |
|
| 1457 | + return $this->query('EncryptionKeyStorage'); |
|
| 1458 | + } |
|
| 1459 | + |
|
| 1460 | + /** |
|
| 1461 | + * The current request object holding all information about the request |
|
| 1462 | + * currently being processed is returned from this method. |
|
| 1463 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1464 | + * |
|
| 1465 | + * @return \OCP\IRequest |
|
| 1466 | + */ |
|
| 1467 | + public function getRequest() { |
|
| 1468 | + return $this->query(IRequest::class); |
|
| 1469 | + } |
|
| 1470 | + |
|
| 1471 | + /** |
|
| 1472 | + * Returns the preview manager which can create preview images for a given file |
|
| 1473 | + * |
|
| 1474 | + * @return IPreview |
|
| 1475 | + */ |
|
| 1476 | + public function getPreviewManager() { |
|
| 1477 | + return $this->query(IPreview::class); |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + /** |
|
| 1481 | + * Returns the tag manager which can get and set tags for different object types |
|
| 1482 | + * |
|
| 1483 | + * @see \OCP\ITagManager::load() |
|
| 1484 | + * @return ITagManager |
|
| 1485 | + */ |
|
| 1486 | + public function getTagManager() { |
|
| 1487 | + return $this->query(ITagManager::class); |
|
| 1488 | + } |
|
| 1489 | + |
|
| 1490 | + /** |
|
| 1491 | + * Returns the system-tag manager |
|
| 1492 | + * |
|
| 1493 | + * @return ISystemTagManager |
|
| 1494 | + * |
|
| 1495 | + * @since 9.0.0 |
|
| 1496 | + */ |
|
| 1497 | + public function getSystemTagManager() { |
|
| 1498 | + return $this->query(ISystemTagManager::class); |
|
| 1499 | + } |
|
| 1500 | + |
|
| 1501 | + /** |
|
| 1502 | + * Returns the system-tag object mapper |
|
| 1503 | + * |
|
| 1504 | + * @return ISystemTagObjectMapper |
|
| 1505 | + * |
|
| 1506 | + * @since 9.0.0 |
|
| 1507 | + */ |
|
| 1508 | + public function getSystemTagObjectMapper() { |
|
| 1509 | + return $this->query(ISystemTagObjectMapper::class); |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + /** |
|
| 1513 | + * Returns the avatar manager, used for avatar functionality |
|
| 1514 | + * |
|
| 1515 | + * @return IAvatarManager |
|
| 1516 | + */ |
|
| 1517 | + public function getAvatarManager() { |
|
| 1518 | + return $this->query(IAvatarManager::class); |
|
| 1519 | + } |
|
| 1520 | + |
|
| 1521 | + /** |
|
| 1522 | + * Returns the root folder of ownCloud's data directory |
|
| 1523 | + * |
|
| 1524 | + * @return IRootFolder |
|
| 1525 | + */ |
|
| 1526 | + public function getRootFolder() { |
|
| 1527 | + return $this->query(IRootFolder::class); |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + /** |
|
| 1531 | + * Returns the root folder of ownCloud's data directory |
|
| 1532 | + * This is the lazy variant so this gets only initialized once it |
|
| 1533 | + * is actually used. |
|
| 1534 | + * |
|
| 1535 | + * @return IRootFolder |
|
| 1536 | + */ |
|
| 1537 | + public function getLazyRootFolder() { |
|
| 1538 | + return $this->query(IRootFolder::class); |
|
| 1539 | + } |
|
| 1540 | + |
|
| 1541 | + /** |
|
| 1542 | + * Returns a view to ownCloud's files folder |
|
| 1543 | + * |
|
| 1544 | + * @param string $userId user ID |
|
| 1545 | + * @return \OCP\Files\Folder|null |
|
| 1546 | + */ |
|
| 1547 | + public function getUserFolder($userId = null) { |
|
| 1548 | + if ($userId === null) { |
|
| 1549 | + $user = $this->getUserSession()->getUser(); |
|
| 1550 | + if (!$user) { |
|
| 1551 | + return null; |
|
| 1552 | + } |
|
| 1553 | + $userId = $user->getUID(); |
|
| 1554 | + } |
|
| 1555 | + $root = $this->getRootFolder(); |
|
| 1556 | + return $root->getUserFolder($userId); |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + /** |
|
| 1560 | + * Returns an app-specific view in ownClouds data directory |
|
| 1561 | + * |
|
| 1562 | + * @return \OCP\Files\Folder |
|
| 1563 | + * @deprecated since 9.2.0 use IAppData |
|
| 1564 | + */ |
|
| 1565 | + public function getAppFolder() { |
|
| 1566 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1567 | + $root = $this->getRootFolder(); |
|
| 1568 | + if (!$root->nodeExists($dir)) { |
|
| 1569 | + $folder = $root->newFolder($dir); |
|
| 1570 | + } else { |
|
| 1571 | + $folder = $root->get($dir); |
|
| 1572 | + } |
|
| 1573 | + return $folder; |
|
| 1574 | + } |
|
| 1575 | + |
|
| 1576 | + /** |
|
| 1577 | + * @return \OC\User\Manager |
|
| 1578 | + */ |
|
| 1579 | + public function getUserManager() { |
|
| 1580 | + return $this->query(IUserManager::class); |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + /** |
|
| 1584 | + * @return \OC\Group\Manager |
|
| 1585 | + */ |
|
| 1586 | + public function getGroupManager() { |
|
| 1587 | + return $this->query(IGroupManager::class); |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + /** |
|
| 1591 | + * @return \OC\User\Session |
|
| 1592 | + */ |
|
| 1593 | + public function getUserSession() { |
|
| 1594 | + return $this->query(IUserSession::class); |
|
| 1595 | + } |
|
| 1596 | + |
|
| 1597 | + /** |
|
| 1598 | + * @return \OCP\ISession |
|
| 1599 | + */ |
|
| 1600 | + public function getSession() { |
|
| 1601 | + return $this->getUserSession()->getSession(); |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * @param \OCP\ISession $session |
|
| 1606 | + */ |
|
| 1607 | + public function setSession(\OCP\ISession $session) { |
|
| 1608 | + $this->query(SessionStorage::class)->setSession($session); |
|
| 1609 | + $this->getUserSession()->setSession($session); |
|
| 1610 | + $this->query(Store::class)->setSession($session); |
|
| 1611 | + } |
|
| 1612 | + |
|
| 1613 | + /** |
|
| 1614 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1615 | + */ |
|
| 1616 | + public function getTwoFactorAuthManager() { |
|
| 1617 | + return $this->query(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + /** |
|
| 1621 | + * @return \OC\NavigationManager |
|
| 1622 | + */ |
|
| 1623 | + public function getNavigationManager() { |
|
| 1624 | + return $this->query(INavigationManager::class); |
|
| 1625 | + } |
|
| 1626 | + |
|
| 1627 | + /** |
|
| 1628 | + * @return \OCP\IConfig |
|
| 1629 | + */ |
|
| 1630 | + public function getConfig() { |
|
| 1631 | + return $this->query(AllConfig::class); |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + /** |
|
| 1635 | + * @return \OC\SystemConfig |
|
| 1636 | + */ |
|
| 1637 | + public function getSystemConfig() { |
|
| 1638 | + return $this->query(SystemConfig::class); |
|
| 1639 | + } |
|
| 1640 | + |
|
| 1641 | + /** |
|
| 1642 | + * Returns the app config manager |
|
| 1643 | + * |
|
| 1644 | + * @return IAppConfig |
|
| 1645 | + */ |
|
| 1646 | + public function getAppConfig() { |
|
| 1647 | + return $this->query(IAppConfig::class); |
|
| 1648 | + } |
|
| 1649 | + |
|
| 1650 | + /** |
|
| 1651 | + * @return IFactory |
|
| 1652 | + */ |
|
| 1653 | + public function getL10NFactory() { |
|
| 1654 | + return $this->query(IFactory::class); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + /** |
|
| 1658 | + * get an L10N instance |
|
| 1659 | + * |
|
| 1660 | + * @param string $app appid |
|
| 1661 | + * @param string $lang |
|
| 1662 | + * @return IL10N |
|
| 1663 | + */ |
|
| 1664 | + public function getL10N($app, $lang = null) { |
|
| 1665 | + return $this->getL10NFactory()->get($app, $lang); |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + /** |
|
| 1669 | + * @return IURLGenerator |
|
| 1670 | + */ |
|
| 1671 | + public function getURLGenerator() { |
|
| 1672 | + return $this->query(IURLGenerator::class); |
|
| 1673 | + } |
|
| 1674 | + |
|
| 1675 | + /** |
|
| 1676 | + * @return AppFetcher |
|
| 1677 | + */ |
|
| 1678 | + public function getAppFetcher() { |
|
| 1679 | + return $this->query(AppFetcher::class); |
|
| 1680 | + } |
|
| 1681 | + |
|
| 1682 | + /** |
|
| 1683 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1684 | + * getMemCacheFactory() instead. |
|
| 1685 | + * |
|
| 1686 | + * @return ICache |
|
| 1687 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1688 | + */ |
|
| 1689 | + public function getCache() { |
|
| 1690 | + return $this->query(ICache::class); |
|
| 1691 | + } |
|
| 1692 | + |
|
| 1693 | + /** |
|
| 1694 | + * Returns an \OCP\CacheFactory instance |
|
| 1695 | + * |
|
| 1696 | + * @return \OCP\ICacheFactory |
|
| 1697 | + */ |
|
| 1698 | + public function getMemCacheFactory() { |
|
| 1699 | + return $this->query(Factory::class); |
|
| 1700 | + } |
|
| 1701 | + |
|
| 1702 | + /** |
|
| 1703 | + * Returns an \OC\RedisFactory instance |
|
| 1704 | + * |
|
| 1705 | + * @return \OC\RedisFactory |
|
| 1706 | + */ |
|
| 1707 | + public function getGetRedisFactory() { |
|
| 1708 | + return $this->query('RedisFactory'); |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * Returns the current session |
|
| 1714 | + * |
|
| 1715 | + * @return \OCP\IDBConnection |
|
| 1716 | + */ |
|
| 1717 | + public function getDatabaseConnection() { |
|
| 1718 | + return $this->query(IDBConnection::class); |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + /** |
|
| 1722 | + * Returns the activity manager |
|
| 1723 | + * |
|
| 1724 | + * @return \OCP\Activity\IManager |
|
| 1725 | + */ |
|
| 1726 | + public function getActivityManager() { |
|
| 1727 | + return $this->query(\OCP\Activity\IManager::class); |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + /** |
|
| 1731 | + * Returns an job list for controlling background jobs |
|
| 1732 | + * |
|
| 1733 | + * @return IJobList |
|
| 1734 | + */ |
|
| 1735 | + public function getJobList() { |
|
| 1736 | + return $this->query(IJobList::class); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + /** |
|
| 1740 | + * Returns a logger instance |
|
| 1741 | + * |
|
| 1742 | + * @return ILogger |
|
| 1743 | + */ |
|
| 1744 | + public function getLogger() { |
|
| 1745 | + return $this->query(ILogger::class); |
|
| 1746 | + } |
|
| 1747 | + |
|
| 1748 | + /** |
|
| 1749 | + * @return ILogFactory |
|
| 1750 | + * @throws \OCP\AppFramework\QueryException |
|
| 1751 | + */ |
|
| 1752 | + public function getLogFactory() { |
|
| 1753 | + return $this->query(ILogFactory::class); |
|
| 1754 | + } |
|
| 1755 | + |
|
| 1756 | + /** |
|
| 1757 | + * Returns a router for generating and matching urls |
|
| 1758 | + * |
|
| 1759 | + * @return IRouter |
|
| 1760 | + */ |
|
| 1761 | + public function getRouter() { |
|
| 1762 | + return $this->query(IRouter::class); |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + /** |
|
| 1766 | + * Returns a search instance |
|
| 1767 | + * |
|
| 1768 | + * @return ISearch |
|
| 1769 | + */ |
|
| 1770 | + public function getSearch() { |
|
| 1771 | + return $this->query(ISearch::class); |
|
| 1772 | + } |
|
| 1773 | + |
|
| 1774 | + /** |
|
| 1775 | + * Returns a SecureRandom instance |
|
| 1776 | + * |
|
| 1777 | + * @return \OCP\Security\ISecureRandom |
|
| 1778 | + */ |
|
| 1779 | + public function getSecureRandom() { |
|
| 1780 | + return $this->query(ISecureRandom::class); |
|
| 1781 | + } |
|
| 1782 | + |
|
| 1783 | + /** |
|
| 1784 | + * Returns a Crypto instance |
|
| 1785 | + * |
|
| 1786 | + * @return ICrypto |
|
| 1787 | + */ |
|
| 1788 | + public function getCrypto() { |
|
| 1789 | + return $this->query(ICrypto::class); |
|
| 1790 | + } |
|
| 1791 | + |
|
| 1792 | + /** |
|
| 1793 | + * Returns a Hasher instance |
|
| 1794 | + * |
|
| 1795 | + * @return IHasher |
|
| 1796 | + */ |
|
| 1797 | + public function getHasher() { |
|
| 1798 | + return $this->query(IHasher::class); |
|
| 1799 | + } |
|
| 1800 | + |
|
| 1801 | + /** |
|
| 1802 | + * Returns a CredentialsManager instance |
|
| 1803 | + * |
|
| 1804 | + * @return ICredentialsManager |
|
| 1805 | + */ |
|
| 1806 | + public function getCredentialsManager() { |
|
| 1807 | + return $this->query(ICredentialsManager::class); |
|
| 1808 | + } |
|
| 1809 | + |
|
| 1810 | + /** |
|
| 1811 | + * Get the certificate manager for the user |
|
| 1812 | + * |
|
| 1813 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1814 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1815 | + */ |
|
| 1816 | + public function getCertificateManager($userId = '') { |
|
| 1817 | + if ($userId === '') { |
|
| 1818 | + $userSession = $this->getUserSession(); |
|
| 1819 | + $user = $userSession->getUser(); |
|
| 1820 | + if (is_null($user)) { |
|
| 1821 | + return null; |
|
| 1822 | + } |
|
| 1823 | + $userId = $user->getUID(); |
|
| 1824 | + } |
|
| 1825 | + return new CertificateManager( |
|
| 1826 | + $userId, |
|
| 1827 | + new View(), |
|
| 1828 | + $this->getConfig(), |
|
| 1829 | + $this->getLogger(), |
|
| 1830 | + $this->getSecureRandom() |
|
| 1831 | + ); |
|
| 1832 | + } |
|
| 1833 | + |
|
| 1834 | + /** |
|
| 1835 | + * Returns an instance of the HTTP client service |
|
| 1836 | + * |
|
| 1837 | + * @return IClientService |
|
| 1838 | + */ |
|
| 1839 | + public function getHTTPClientService() { |
|
| 1840 | + return $this->query(IClientService::class); |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + /** |
|
| 1844 | + * Create a new event source |
|
| 1845 | + * |
|
| 1846 | + * @return \OCP\IEventSource |
|
| 1847 | + */ |
|
| 1848 | + public function createEventSource() { |
|
| 1849 | + return new \OC_EventSource(); |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + /** |
|
| 1853 | + * Get the active event logger |
|
| 1854 | + * |
|
| 1855 | + * The returned logger only logs data when debug mode is enabled |
|
| 1856 | + * |
|
| 1857 | + * @return IEventLogger |
|
| 1858 | + */ |
|
| 1859 | + public function getEventLogger() { |
|
| 1860 | + return $this->query(IEventLogger::class); |
|
| 1861 | + } |
|
| 1862 | + |
|
| 1863 | + /** |
|
| 1864 | + * Get the active query logger |
|
| 1865 | + * |
|
| 1866 | + * The returned logger only logs data when debug mode is enabled |
|
| 1867 | + * |
|
| 1868 | + * @return IQueryLogger |
|
| 1869 | + */ |
|
| 1870 | + public function getQueryLogger() { |
|
| 1871 | + return $this->query(IQueryLogger::class); |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + /** |
|
| 1875 | + * Get the manager for temporary files and folders |
|
| 1876 | + * |
|
| 1877 | + * @return \OCP\ITempManager |
|
| 1878 | + */ |
|
| 1879 | + public function getTempManager() { |
|
| 1880 | + return $this->query(ITempManager::class); |
|
| 1881 | + } |
|
| 1882 | + |
|
| 1883 | + /** |
|
| 1884 | + * Get the app manager |
|
| 1885 | + * |
|
| 1886 | + * @return \OCP\App\IAppManager |
|
| 1887 | + */ |
|
| 1888 | + public function getAppManager() { |
|
| 1889 | + return $this->query(IAppManager::class); |
|
| 1890 | + } |
|
| 1891 | + |
|
| 1892 | + /** |
|
| 1893 | + * Creates a new mailer |
|
| 1894 | + * |
|
| 1895 | + * @return IMailer |
|
| 1896 | + */ |
|
| 1897 | + public function getMailer() { |
|
| 1898 | + return $this->query(IMailer::class); |
|
| 1899 | + } |
|
| 1900 | + |
|
| 1901 | + /** |
|
| 1902 | + * Get the webroot |
|
| 1903 | + * |
|
| 1904 | + * @return string |
|
| 1905 | + */ |
|
| 1906 | + public function getWebRoot() { |
|
| 1907 | + return $this->webRoot; |
|
| 1908 | + } |
|
| 1909 | + |
|
| 1910 | + /** |
|
| 1911 | + * @return \OC\OCSClient |
|
| 1912 | + */ |
|
| 1913 | + public function getOcsClient() { |
|
| 1914 | + return $this->query('OcsClient'); |
|
| 1915 | + } |
|
| 1916 | + |
|
| 1917 | + /** |
|
| 1918 | + * @return IDateTimeZone |
|
| 1919 | + */ |
|
| 1920 | + public function getDateTimeZone() { |
|
| 1921 | + return $this->query(IDateTimeZone::class); |
|
| 1922 | + } |
|
| 1923 | + |
|
| 1924 | + /** |
|
| 1925 | + * @return IDateTimeFormatter |
|
| 1926 | + */ |
|
| 1927 | + public function getDateTimeFormatter() { |
|
| 1928 | + return $this->query(IDateTimeFormatter::class); |
|
| 1929 | + } |
|
| 1930 | + |
|
| 1931 | + /** |
|
| 1932 | + * @return IMountProviderCollection |
|
| 1933 | + */ |
|
| 1934 | + public function getMountProviderCollection() { |
|
| 1935 | + return $this->query(IMountProviderCollection::class); |
|
| 1936 | + } |
|
| 1937 | + |
|
| 1938 | + /** |
|
| 1939 | + * Get the IniWrapper |
|
| 1940 | + * |
|
| 1941 | + * @return IniGetWrapper |
|
| 1942 | + */ |
|
| 1943 | + public function getIniWrapper() { |
|
| 1944 | + return $this->query('IniWrapper'); |
|
| 1945 | + } |
|
| 1946 | + |
|
| 1947 | + /** |
|
| 1948 | + * @return \OCP\Command\IBus |
|
| 1949 | + */ |
|
| 1950 | + public function getCommandBus() { |
|
| 1951 | + return $this->query('AsyncCommandBus'); |
|
| 1952 | + } |
|
| 1953 | + |
|
| 1954 | + /** |
|
| 1955 | + * Get the trusted domain helper |
|
| 1956 | + * |
|
| 1957 | + * @return TrustedDomainHelper |
|
| 1958 | + */ |
|
| 1959 | + public function getTrustedDomainHelper() { |
|
| 1960 | + return $this->query('TrustedDomainHelper'); |
|
| 1961 | + } |
|
| 1962 | + |
|
| 1963 | + /** |
|
| 1964 | + * Get the locking provider |
|
| 1965 | + * |
|
| 1966 | + * @return ILockingProvider |
|
| 1967 | + * @since 8.1.0 |
|
| 1968 | + */ |
|
| 1969 | + public function getLockingProvider() { |
|
| 1970 | + return $this->query(ILockingProvider::class); |
|
| 1971 | + } |
|
| 1972 | + |
|
| 1973 | + /** |
|
| 1974 | + * @return IMountManager |
|
| 1975 | + **/ |
|
| 1976 | + public function getMountManager() { |
|
| 1977 | + return $this->query(IMountManager::class); |
|
| 1978 | + } |
|
| 1979 | + |
|
| 1980 | + /** |
|
| 1981 | + * @return IUserMountCache |
|
| 1982 | + */ |
|
| 1983 | + public function getUserMountCache() { |
|
| 1984 | + return $this->query(IUserMountCache::class); |
|
| 1985 | + } |
|
| 1986 | + |
|
| 1987 | + /** |
|
| 1988 | + * Get the MimeTypeDetector |
|
| 1989 | + * |
|
| 1990 | + * @return IMimeTypeDetector |
|
| 1991 | + */ |
|
| 1992 | + public function getMimeTypeDetector() { |
|
| 1993 | + return $this->query(IMimeTypeDetector::class); |
|
| 1994 | + } |
|
| 1995 | + |
|
| 1996 | + /** |
|
| 1997 | + * Get the MimeTypeLoader |
|
| 1998 | + * |
|
| 1999 | + * @return IMimeTypeLoader |
|
| 2000 | + */ |
|
| 2001 | + public function getMimeTypeLoader() { |
|
| 2002 | + return $this->query(IMimeTypeLoader::class); |
|
| 2003 | + } |
|
| 2004 | + |
|
| 2005 | + /** |
|
| 2006 | + * Get the manager of all the capabilities |
|
| 2007 | + * |
|
| 2008 | + * @return CapabilitiesManager |
|
| 2009 | + */ |
|
| 2010 | + public function getCapabilitiesManager() { |
|
| 2011 | + return $this->query(CapabilitiesManager::class); |
|
| 2012 | + } |
|
| 2013 | + |
|
| 2014 | + /** |
|
| 2015 | + * Get the EventDispatcher |
|
| 2016 | + * |
|
| 2017 | + * @return EventDispatcherInterface |
|
| 2018 | + * @since 8.2.0 |
|
| 2019 | + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
| 2020 | + */ |
|
| 2021 | + public function getEventDispatcher() { |
|
| 2022 | + return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
| 2023 | + } |
|
| 2024 | + |
|
| 2025 | + /** |
|
| 2026 | + * Get the Notification Manager |
|
| 2027 | + * |
|
| 2028 | + * @return \OCP\Notification\IManager |
|
| 2029 | + * @since 8.2.0 |
|
| 2030 | + */ |
|
| 2031 | + public function getNotificationManager() { |
|
| 2032 | + return $this->query(\OCP\Notification\IManager::class); |
|
| 2033 | + } |
|
| 2034 | + |
|
| 2035 | + /** |
|
| 2036 | + * @return ICommentsManager |
|
| 2037 | + */ |
|
| 2038 | + public function getCommentsManager() { |
|
| 2039 | + return $this->query(ICommentsManager::class); |
|
| 2040 | + } |
|
| 2041 | + |
|
| 2042 | + /** |
|
| 2043 | + * @return \OCA\Theming\ThemingDefaults |
|
| 2044 | + */ |
|
| 2045 | + public function getThemingDefaults() { |
|
| 2046 | + return $this->query('ThemingDefaults'); |
|
| 2047 | + } |
|
| 2048 | + |
|
| 2049 | + /** |
|
| 2050 | + * @return \OC\IntegrityCheck\Checker |
|
| 2051 | + */ |
|
| 2052 | + public function getIntegrityCodeChecker() { |
|
| 2053 | + return $this->query('IntegrityCodeChecker'); |
|
| 2054 | + } |
|
| 2055 | + |
|
| 2056 | + /** |
|
| 2057 | + * @return \OC\Session\CryptoWrapper |
|
| 2058 | + */ |
|
| 2059 | + public function getSessionCryptoWrapper() { |
|
| 2060 | + return $this->query('CryptoWrapper'); |
|
| 2061 | + } |
|
| 2062 | + |
|
| 2063 | + /** |
|
| 2064 | + * @return CsrfTokenManager |
|
| 2065 | + */ |
|
| 2066 | + public function getCsrfTokenManager() { |
|
| 2067 | + return $this->query(CsrfTokenManager::class); |
|
| 2068 | + } |
|
| 2069 | + |
|
| 2070 | + /** |
|
| 2071 | + * @return Throttler |
|
| 2072 | + */ |
|
| 2073 | + public function getBruteForceThrottler() { |
|
| 2074 | + return $this->query(Throttler::class); |
|
| 2075 | + } |
|
| 2076 | + |
|
| 2077 | + /** |
|
| 2078 | + * @return IContentSecurityPolicyManager |
|
| 2079 | + */ |
|
| 2080 | + public function getContentSecurityPolicyManager() { |
|
| 2081 | + return $this->query(ContentSecurityPolicyManager::class); |
|
| 2082 | + } |
|
| 2083 | + |
|
| 2084 | + /** |
|
| 2085 | + * @return ContentSecurityPolicyNonceManager |
|
| 2086 | + */ |
|
| 2087 | + public function getContentSecurityPolicyNonceManager() { |
|
| 2088 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 2089 | + } |
|
| 2090 | + |
|
| 2091 | + /** |
|
| 2092 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2093 | + * |
|
| 2094 | + * @return \OCA\Files_External\Service\BackendService |
|
| 2095 | + */ |
|
| 2096 | + public function getStoragesBackendService() { |
|
| 2097 | + return $this->query(BackendService::class); |
|
| 2098 | + } |
|
| 2099 | + |
|
| 2100 | + /** |
|
| 2101 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2102 | + * |
|
| 2103 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 2104 | + */ |
|
| 2105 | + public function getGlobalStoragesService() { |
|
| 2106 | + return $this->query(GlobalStoragesService::class); |
|
| 2107 | + } |
|
| 2108 | + |
|
| 2109 | + /** |
|
| 2110 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2111 | + * |
|
| 2112 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 2113 | + */ |
|
| 2114 | + public function getUserGlobalStoragesService() { |
|
| 2115 | + return $this->query(UserGlobalStoragesService::class); |
|
| 2116 | + } |
|
| 2117 | + |
|
| 2118 | + /** |
|
| 2119 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2120 | + * |
|
| 2121 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
| 2122 | + */ |
|
| 2123 | + public function getUserStoragesService() { |
|
| 2124 | + return $this->query(UserStoragesService::class); |
|
| 2125 | + } |
|
| 2126 | + |
|
| 2127 | + /** |
|
| 2128 | + * @return \OCP\Share\IManager |
|
| 2129 | + */ |
|
| 2130 | + public function getShareManager() { |
|
| 2131 | + return $this->query(\OCP\Share\IManager::class); |
|
| 2132 | + } |
|
| 2133 | + |
|
| 2134 | + /** |
|
| 2135 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 2136 | + */ |
|
| 2137 | + public function getCollaboratorSearch() { |
|
| 2138 | + return $this->query(\OCP\Collaboration\Collaborators\ISearch::class); |
|
| 2139 | + } |
|
| 2140 | + |
|
| 2141 | + /** |
|
| 2142 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 2143 | + */ |
|
| 2144 | + public function getAutoCompleteManager() { |
|
| 2145 | + return $this->query(IManager::class); |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + /** |
|
| 2149 | + * Returns the LDAP Provider |
|
| 2150 | + * |
|
| 2151 | + * @return \OCP\LDAP\ILDAPProvider |
|
| 2152 | + */ |
|
| 2153 | + public function getLDAPProvider() { |
|
| 2154 | + return $this->query('LDAPProvider'); |
|
| 2155 | + } |
|
| 2156 | + |
|
| 2157 | + /** |
|
| 2158 | + * @return \OCP\Settings\IManager |
|
| 2159 | + */ |
|
| 2160 | + public function getSettingsManager() { |
|
| 2161 | + return $this->query('SettingsManager'); |
|
| 2162 | + } |
|
| 2163 | + |
|
| 2164 | + /** |
|
| 2165 | + * @return \OCP\Files\IAppData |
|
| 2166 | + */ |
|
| 2167 | + public function getAppDataDir($app) { |
|
| 2168 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2169 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 2170 | + return $factory->get($app); |
|
| 2171 | + } |
|
| 2172 | + |
|
| 2173 | + /** |
|
| 2174 | + * @return \OCP\Lockdown\ILockdownManager |
|
| 2175 | + */ |
|
| 2176 | + public function getLockdownManager() { |
|
| 2177 | + return $this->query('LockdownManager'); |
|
| 2178 | + } |
|
| 2179 | + |
|
| 2180 | + /** |
|
| 2181 | + * @return \OCP\Federation\ICloudIdManager |
|
| 2182 | + */ |
|
| 2183 | + public function getCloudIdManager() { |
|
| 2184 | + return $this->query(ICloudIdManager::class); |
|
| 2185 | + } |
|
| 2186 | + |
|
| 2187 | + /** |
|
| 2188 | + * @return \OCP\GlobalScale\IConfig |
|
| 2189 | + */ |
|
| 2190 | + public function getGlobalScaleConfig() { |
|
| 2191 | + return $this->query(IConfig::class); |
|
| 2192 | + } |
|
| 2193 | + |
|
| 2194 | + /** |
|
| 2195 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2196 | + */ |
|
| 2197 | + public function getCloudFederationProviderManager() { |
|
| 2198 | + return $this->query(ICloudFederationProviderManager::class); |
|
| 2199 | + } |
|
| 2200 | + |
|
| 2201 | + /** |
|
| 2202 | + * @return \OCP\Remote\Api\IApiFactory |
|
| 2203 | + */ |
|
| 2204 | + public function getRemoteApiFactory() { |
|
| 2205 | + return $this->query(IApiFactory::class); |
|
| 2206 | + } |
|
| 2207 | + |
|
| 2208 | + /** |
|
| 2209 | + * @return \OCP\Federation\ICloudFederationFactory |
|
| 2210 | + */ |
|
| 2211 | + public function getCloudFederationFactory() { |
|
| 2212 | + return $this->query(ICloudFederationFactory::class); |
|
| 2213 | + } |
|
| 2214 | + |
|
| 2215 | + /** |
|
| 2216 | + * @return \OCP\Remote\IInstanceFactory |
|
| 2217 | + */ |
|
| 2218 | + public function getRemoteInstanceFactory() { |
|
| 2219 | + return $this->query(IInstanceFactory::class); |
|
| 2220 | + } |
|
| 2221 | + |
|
| 2222 | + /** |
|
| 2223 | + * @return IStorageFactory |
|
| 2224 | + */ |
|
| 2225 | + public function getStorageFactory() { |
|
| 2226 | + return $this->query(IStorageFactory::class); |
|
| 2227 | + } |
|
| 2228 | + |
|
| 2229 | + /** |
|
| 2230 | + * Get the Preview GeneratorHelper |
|
| 2231 | + * |
|
| 2232 | + * @return GeneratorHelper |
|
| 2233 | + * @since 17.0.0 |
|
| 2234 | + */ |
|
| 2235 | + public function getGeneratorHelper() { |
|
| 2236 | + return $this->query(\OC\Preview\GeneratorHelper::class); |
|
| 2237 | + } |
|
| 2238 | + |
|
| 2239 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 2240 | + $this->registerService($alias, function (IContainer $container) use ($target, $alias) { |
|
| 2241 | + try { |
|
| 2242 | + /** @var ILogger $logger */ |
|
| 2243 | + $logger = $container->query(ILogger::class); |
|
| 2244 | + $logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2245 | + } catch (QueryException $e) { |
|
| 2246 | + // Could not get logger. Continue |
|
| 2247 | + } |
|
| 2248 | + |
|
| 2249 | + return $container->query($target); |
|
| 2250 | + }, false); |
|
| 2251 | + } |
|
| 2252 | 2252 | } |
@@ -50,380 +50,380 @@ |
||
| 50 | 50 | |
| 51 | 51 | class ThemingDefaults extends \OC_Defaults { |
| 52 | 52 | |
| 53 | - /** @var IConfig */ |
|
| 54 | - private $config; |
|
| 55 | - /** @var IL10N */ |
|
| 56 | - private $l; |
|
| 57 | - /** @var ImageManager */ |
|
| 58 | - private $imageManager; |
|
| 59 | - /** @var IURLGenerator */ |
|
| 60 | - private $urlGenerator; |
|
| 61 | - /** @var ICacheFactory */ |
|
| 62 | - private $cacheFactory; |
|
| 63 | - /** @var Util */ |
|
| 64 | - private $util; |
|
| 65 | - /** @var IAppManager */ |
|
| 66 | - private $appManager; |
|
| 67 | - /** @var INavigationManager */ |
|
| 68 | - private $navigationManager; |
|
| 69 | - |
|
| 70 | - /** @var string */ |
|
| 71 | - private $name; |
|
| 72 | - /** @var string */ |
|
| 73 | - private $title; |
|
| 74 | - /** @var string */ |
|
| 75 | - private $entity; |
|
| 76 | - /** @var string */ |
|
| 77 | - private $url; |
|
| 78 | - /** @var string */ |
|
| 79 | - private $color; |
|
| 80 | - |
|
| 81 | - /** @var string */ |
|
| 82 | - private $iTunesAppId; |
|
| 83 | - /** @var string */ |
|
| 84 | - private $iOSClientUrl; |
|
| 85 | - /** @var string */ |
|
| 86 | - private $AndroidClientUrl; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * ThemingDefaults constructor. |
|
| 90 | - * |
|
| 91 | - * @param IConfig $config |
|
| 92 | - * @param IL10N $l |
|
| 93 | - * @param ImageManager $imageManager |
|
| 94 | - * @param IURLGenerator $urlGenerator |
|
| 95 | - * @param ICacheFactory $cacheFactory |
|
| 96 | - * @param Util $util |
|
| 97 | - * @param IAppManager $appManager |
|
| 98 | - */ |
|
| 99 | - public function __construct(IConfig $config, |
|
| 100 | - IL10N $l, |
|
| 101 | - IURLGenerator $urlGenerator, |
|
| 102 | - ICacheFactory $cacheFactory, |
|
| 103 | - Util $util, |
|
| 104 | - ImageManager $imageManager, |
|
| 105 | - IAppManager $appManager, |
|
| 106 | - INavigationManager $navigationManager |
|
| 107 | - ) { |
|
| 108 | - parent::__construct(); |
|
| 109 | - $this->config = $config; |
|
| 110 | - $this->l = $l; |
|
| 111 | - $this->imageManager = $imageManager; |
|
| 112 | - $this->urlGenerator = $urlGenerator; |
|
| 113 | - $this->cacheFactory = $cacheFactory; |
|
| 114 | - $this->util = $util; |
|
| 115 | - $this->appManager = $appManager; |
|
| 116 | - $this->navigationManager = $navigationManager; |
|
| 117 | - |
|
| 118 | - $this->name = parent::getName(); |
|
| 119 | - $this->title = parent::getTitle(); |
|
| 120 | - $this->entity = parent::getEntity(); |
|
| 121 | - $this->url = parent::getBaseUrl(); |
|
| 122 | - $this->color = parent::getColorPrimary(); |
|
| 123 | - $this->iTunesAppId = parent::getiTunesAppId(); |
|
| 124 | - $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
| 125 | - $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function getName() { |
|
| 129 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function getHTMLName() { |
|
| 133 | - return $this->config->getAppValue('theming', 'name', $this->name); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function getTitle() { |
|
| 137 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function getEntity() { |
|
| 141 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - public function getBaseUrl() { |
|
| 145 | - return $this->config->getAppValue('theming', 'url', $this->url); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function getSlogan(?string $lang = null) { |
|
| 149 | - return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang))); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function getImprintUrl() { |
|
| 153 | - return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function getPrivacyUrl() { |
|
| 157 | - return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - public function getShortFooter() { |
|
| 161 | - $slogan = $this->getSlogan(); |
|
| 162 | - $baseUrl = $this->getBaseUrl(); |
|
| 163 | - if ($baseUrl !== '') { |
|
| 164 | - $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
| 165 | - ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
| 166 | - } else { |
|
| 167 | - $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
| 168 | - } |
|
| 169 | - $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
| 170 | - |
|
| 171 | - $links = [ |
|
| 172 | - [ |
|
| 173 | - 'text' => $this->l->t('Legal notice'), |
|
| 174 | - 'url' => (string)$this->getImprintUrl() |
|
| 175 | - ], |
|
| 176 | - [ |
|
| 177 | - 'text' => $this->l->t('Privacy policy'), |
|
| 178 | - 'url' => (string)$this->getPrivacyUrl() |
|
| 179 | - ], |
|
| 180 | - ]; |
|
| 181 | - |
|
| 182 | - $navigation = $this->navigationManager->getAll(INavigationManager::TYPE_GUEST); |
|
| 183 | - $guestNavigation = array_map(function ($nav) { |
|
| 184 | - return [ |
|
| 185 | - 'text' => $nav['name'], |
|
| 186 | - 'url' => $nav['href'] |
|
| 187 | - ]; |
|
| 188 | - }, $navigation); |
|
| 189 | - $links = array_merge($links, $guestNavigation); |
|
| 190 | - |
|
| 191 | - $legalLinks = ''; |
|
| 192 | - $divider = ''; |
|
| 193 | - foreach ($links as $link) { |
|
| 194 | - if ($link['url'] !== '' |
|
| 195 | - && filter_var($link['url'], FILTER_VALIDATE_URL) |
|
| 196 | - ) { |
|
| 197 | - $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
| 198 | - ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
| 199 | - $divider = ' · '; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - if ($legalLinks !== '') { |
|
| 203 | - $footer .= '<br/>' . $legalLinks; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return $footer; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Color that is used for the header as well as for mail headers |
|
| 211 | - * |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - public function getColorPrimary() { |
|
| 215 | - return $this->config->getAppValue('theming', 'color', $this->color); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Themed logo url |
|
| 220 | - * |
|
| 221 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 224 | - public function getLogo($useSvg = true): string { |
|
| 225 | - $logo = $this->config->getAppValue('theming', 'logoMime', false); |
|
| 226 | - |
|
| 227 | - $logoExists = true; |
|
| 228 | - try { |
|
| 229 | - $this->imageManager->getImage('logo', $useSvg); |
|
| 230 | - } catch (\Exception $e) { |
|
| 231 | - $logoExists = false; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 235 | - |
|
| 236 | - if (!$logo || !$logoExists) { |
|
| 237 | - if ($useSvg) { |
|
| 238 | - $logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg'); |
|
| 239 | - } else { |
|
| 240 | - $logo = $this->urlGenerator->imagePath('core', 'logo/logo.png'); |
|
| 241 | - } |
|
| 242 | - return $logo . '?v=' . $cacheBusterCounter; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Themed background image url |
|
| 250 | - * |
|
| 251 | - * @return string |
|
| 252 | - */ |
|
| 253 | - public function getBackground(): string { |
|
| 254 | - return $this->imageManager->getImageUrl('background'); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @return string |
|
| 259 | - */ |
|
| 260 | - public function getiTunesAppId() { |
|
| 261 | - return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - public function getiOSClientUrl() { |
|
| 268 | - return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @return string |
|
| 273 | - */ |
|
| 274 | - public function getAndroidClientUrl() { |
|
| 275 | - return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @return array scss variables to overwrite |
|
| 281 | - */ |
|
| 282 | - public function getScssVariables() { |
|
| 283 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
| 284 | - if ($value = $cache->get('getScssVariables')) { |
|
| 285 | - return $value; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - $variables = [ |
|
| 289 | - 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
| 290 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
| 291 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
| 292 | - 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
| 293 | - 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
| 294 | - ]; |
|
| 295 | - |
|
| 296 | - $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
|
| 297 | - $variables['image-logoheader'] = "url('".$this->imageManager->getImageUrl('logoheader')."')"; |
|
| 298 | - $variables['image-favicon'] = "url('".$this->imageManager->getImageUrl('favicon')."')"; |
|
| 299 | - $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; |
|
| 300 | - $variables['image-login-plain'] = 'false'; |
|
| 301 | - |
|
| 302 | - if ($this->config->getAppValue('theming', 'color', null) !== null) { |
|
| 303 | - $variables['color-primary'] = $this->getColorPrimary(); |
|
| 304 | - $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
| 305 | - $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { |
|
| 309 | - $variables['image-login-plain'] = 'true'; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $variables['has-legal-links'] = 'false'; |
|
| 313 | - if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
| 314 | - $variables['has-legal-links'] = 'true'; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - $cache->set('getScssVariables', $variables); |
|
| 318 | - return $variables; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Check if the image should be replaced by the theming app |
|
| 323 | - * and return the new image location then |
|
| 324 | - * |
|
| 325 | - * @param string $app name of the app |
|
| 326 | - * @param string $image filename of the image |
|
| 327 | - * @return bool|string false if image should not replaced, otherwise the location of the image |
|
| 328 | - */ |
|
| 329 | - public function replaceImagePath($app, $image) { |
|
| 330 | - if ($app === '' || $app === 'files_sharing') { |
|
| 331 | - $app = 'core'; |
|
| 332 | - } |
|
| 333 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 334 | - |
|
| 335 | - try { |
|
| 336 | - $customFavicon = $this->imageManager->getImage('favicon'); |
|
| 337 | - } catch (NotFoundException $e) { |
|
| 338 | - $customFavicon = null; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - $route = false; |
|
| 342 | - if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
| 343 | - $route = $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]); |
|
| 344 | - } |
|
| 345 | - if (($image === 'favicon-touch.png' || $image === 'favicon-fb.png') && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
| 346 | - $route = $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]); |
|
| 347 | - } |
|
| 348 | - if ($image === 'manifest.json') { |
|
| 349 | - try { |
|
| 350 | - $appPath = $this->appManager->getAppPath($app); |
|
| 351 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
| 352 | - return false; |
|
| 353 | - } |
|
| 354 | - } catch (AppPathNotFoundException $e) { |
|
| 355 | - } |
|
| 356 | - $route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest'); |
|
| 357 | - } |
|
| 358 | - if (strpos($image, 'filetypes/') === 0 && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) { |
|
| 359 | - $route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if ($route) { |
|
| 363 | - return $route . '?v=' . $cacheBusterValue; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - return false; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Increases the cache buster key |
|
| 371 | - */ |
|
| 372 | - private function increaseCacheBuster() { |
|
| 373 | - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 374 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
| 375 | - $this->cacheFactory->createDistributed('theming-')->clear(); |
|
| 376 | - $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Update setting in the database |
|
| 381 | - * |
|
| 382 | - * @param string $setting |
|
| 383 | - * @param string $value |
|
| 384 | - */ |
|
| 385 | - public function set($setting, $value) { |
|
| 386 | - $this->config->setAppValue('theming', $setting, $value); |
|
| 387 | - $this->increaseCacheBuster(); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Revert settings to the default value |
|
| 392 | - * |
|
| 393 | - * @param string $setting setting which should be reverted |
|
| 394 | - * @return string default value |
|
| 395 | - */ |
|
| 396 | - public function undo($setting) { |
|
| 397 | - $this->config->deleteAppValue('theming', $setting); |
|
| 398 | - $this->increaseCacheBuster(); |
|
| 399 | - |
|
| 400 | - switch ($setting) { |
|
| 401 | - case 'name': |
|
| 402 | - $returnValue = $this->getEntity(); |
|
| 403 | - break; |
|
| 404 | - case 'url': |
|
| 405 | - $returnValue = $this->getBaseUrl(); |
|
| 406 | - break; |
|
| 407 | - case 'slogan': |
|
| 408 | - $returnValue = $this->getSlogan(); |
|
| 409 | - break; |
|
| 410 | - case 'color': |
|
| 411 | - $returnValue = $this->getColorPrimary(); |
|
| 412 | - break; |
|
| 413 | - default: |
|
| 414 | - $returnValue = ''; |
|
| 415 | - break; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - return $returnValue; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Color of text in the header and primary buttons |
|
| 423 | - * |
|
| 424 | - * @return string |
|
| 425 | - */ |
|
| 426 | - public function getTextColorPrimary() { |
|
| 427 | - return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
| 428 | - } |
|
| 53 | + /** @var IConfig */ |
|
| 54 | + private $config; |
|
| 55 | + /** @var IL10N */ |
|
| 56 | + private $l; |
|
| 57 | + /** @var ImageManager */ |
|
| 58 | + private $imageManager; |
|
| 59 | + /** @var IURLGenerator */ |
|
| 60 | + private $urlGenerator; |
|
| 61 | + /** @var ICacheFactory */ |
|
| 62 | + private $cacheFactory; |
|
| 63 | + /** @var Util */ |
|
| 64 | + private $util; |
|
| 65 | + /** @var IAppManager */ |
|
| 66 | + private $appManager; |
|
| 67 | + /** @var INavigationManager */ |
|
| 68 | + private $navigationManager; |
|
| 69 | + |
|
| 70 | + /** @var string */ |
|
| 71 | + private $name; |
|
| 72 | + /** @var string */ |
|
| 73 | + private $title; |
|
| 74 | + /** @var string */ |
|
| 75 | + private $entity; |
|
| 76 | + /** @var string */ |
|
| 77 | + private $url; |
|
| 78 | + /** @var string */ |
|
| 79 | + private $color; |
|
| 80 | + |
|
| 81 | + /** @var string */ |
|
| 82 | + private $iTunesAppId; |
|
| 83 | + /** @var string */ |
|
| 84 | + private $iOSClientUrl; |
|
| 85 | + /** @var string */ |
|
| 86 | + private $AndroidClientUrl; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * ThemingDefaults constructor. |
|
| 90 | + * |
|
| 91 | + * @param IConfig $config |
|
| 92 | + * @param IL10N $l |
|
| 93 | + * @param ImageManager $imageManager |
|
| 94 | + * @param IURLGenerator $urlGenerator |
|
| 95 | + * @param ICacheFactory $cacheFactory |
|
| 96 | + * @param Util $util |
|
| 97 | + * @param IAppManager $appManager |
|
| 98 | + */ |
|
| 99 | + public function __construct(IConfig $config, |
|
| 100 | + IL10N $l, |
|
| 101 | + IURLGenerator $urlGenerator, |
|
| 102 | + ICacheFactory $cacheFactory, |
|
| 103 | + Util $util, |
|
| 104 | + ImageManager $imageManager, |
|
| 105 | + IAppManager $appManager, |
|
| 106 | + INavigationManager $navigationManager |
|
| 107 | + ) { |
|
| 108 | + parent::__construct(); |
|
| 109 | + $this->config = $config; |
|
| 110 | + $this->l = $l; |
|
| 111 | + $this->imageManager = $imageManager; |
|
| 112 | + $this->urlGenerator = $urlGenerator; |
|
| 113 | + $this->cacheFactory = $cacheFactory; |
|
| 114 | + $this->util = $util; |
|
| 115 | + $this->appManager = $appManager; |
|
| 116 | + $this->navigationManager = $navigationManager; |
|
| 117 | + |
|
| 118 | + $this->name = parent::getName(); |
|
| 119 | + $this->title = parent::getTitle(); |
|
| 120 | + $this->entity = parent::getEntity(); |
|
| 121 | + $this->url = parent::getBaseUrl(); |
|
| 122 | + $this->color = parent::getColorPrimary(); |
|
| 123 | + $this->iTunesAppId = parent::getiTunesAppId(); |
|
| 124 | + $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
| 125 | + $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function getName() { |
|
| 129 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function getHTMLName() { |
|
| 133 | + return $this->config->getAppValue('theming', 'name', $this->name); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function getTitle() { |
|
| 137 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public function getEntity() { |
|
| 141 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + public function getBaseUrl() { |
|
| 145 | + return $this->config->getAppValue('theming', 'url', $this->url); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function getSlogan(?string $lang = null) { |
|
| 149 | + return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang))); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function getImprintUrl() { |
|
| 153 | + return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function getPrivacyUrl() { |
|
| 157 | + return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + public function getShortFooter() { |
|
| 161 | + $slogan = $this->getSlogan(); |
|
| 162 | + $baseUrl = $this->getBaseUrl(); |
|
| 163 | + if ($baseUrl !== '') { |
|
| 164 | + $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
| 165 | + ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
| 166 | + } else { |
|
| 167 | + $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
| 168 | + } |
|
| 169 | + $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
| 170 | + |
|
| 171 | + $links = [ |
|
| 172 | + [ |
|
| 173 | + 'text' => $this->l->t('Legal notice'), |
|
| 174 | + 'url' => (string)$this->getImprintUrl() |
|
| 175 | + ], |
|
| 176 | + [ |
|
| 177 | + 'text' => $this->l->t('Privacy policy'), |
|
| 178 | + 'url' => (string)$this->getPrivacyUrl() |
|
| 179 | + ], |
|
| 180 | + ]; |
|
| 181 | + |
|
| 182 | + $navigation = $this->navigationManager->getAll(INavigationManager::TYPE_GUEST); |
|
| 183 | + $guestNavigation = array_map(function ($nav) { |
|
| 184 | + return [ |
|
| 185 | + 'text' => $nav['name'], |
|
| 186 | + 'url' => $nav['href'] |
|
| 187 | + ]; |
|
| 188 | + }, $navigation); |
|
| 189 | + $links = array_merge($links, $guestNavigation); |
|
| 190 | + |
|
| 191 | + $legalLinks = ''; |
|
| 192 | + $divider = ''; |
|
| 193 | + foreach ($links as $link) { |
|
| 194 | + if ($link['url'] !== '' |
|
| 195 | + && filter_var($link['url'], FILTER_VALIDATE_URL) |
|
| 196 | + ) { |
|
| 197 | + $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
| 198 | + ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
| 199 | + $divider = ' · '; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + if ($legalLinks !== '') { |
|
| 203 | + $footer .= '<br/>' . $legalLinks; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return $footer; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Color that is used for the header as well as for mail headers |
|
| 211 | + * |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + public function getColorPrimary() { |
|
| 215 | + return $this->config->getAppValue('theming', 'color', $this->color); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Themed logo url |
|
| 220 | + * |
|
| 221 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 224 | + public function getLogo($useSvg = true): string { |
|
| 225 | + $logo = $this->config->getAppValue('theming', 'logoMime', false); |
|
| 226 | + |
|
| 227 | + $logoExists = true; |
|
| 228 | + try { |
|
| 229 | + $this->imageManager->getImage('logo', $useSvg); |
|
| 230 | + } catch (\Exception $e) { |
|
| 231 | + $logoExists = false; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 235 | + |
|
| 236 | + if (!$logo || !$logoExists) { |
|
| 237 | + if ($useSvg) { |
|
| 238 | + $logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg'); |
|
| 239 | + } else { |
|
| 240 | + $logo = $this->urlGenerator->imagePath('core', 'logo/logo.png'); |
|
| 241 | + } |
|
| 242 | + return $logo . '?v=' . $cacheBusterCounter; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Themed background image url |
|
| 250 | + * |
|
| 251 | + * @return string |
|
| 252 | + */ |
|
| 253 | + public function getBackground(): string { |
|
| 254 | + return $this->imageManager->getImageUrl('background'); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @return string |
|
| 259 | + */ |
|
| 260 | + public function getiTunesAppId() { |
|
| 261 | + return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + public function getiOSClientUrl() { |
|
| 268 | + return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @return string |
|
| 273 | + */ |
|
| 274 | + public function getAndroidClientUrl() { |
|
| 275 | + return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @return array scss variables to overwrite |
|
| 281 | + */ |
|
| 282 | + public function getScssVariables() { |
|
| 283 | + $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
| 284 | + if ($value = $cache->get('getScssVariables')) { |
|
| 285 | + return $value; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + $variables = [ |
|
| 289 | + 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
| 290 | + 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
| 291 | + 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
| 292 | + 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
| 293 | + 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
| 294 | + ]; |
|
| 295 | + |
|
| 296 | + $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
|
| 297 | + $variables['image-logoheader'] = "url('".$this->imageManager->getImageUrl('logoheader')."')"; |
|
| 298 | + $variables['image-favicon'] = "url('".$this->imageManager->getImageUrl('favicon')."')"; |
|
| 299 | + $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; |
|
| 300 | + $variables['image-login-plain'] = 'false'; |
|
| 301 | + |
|
| 302 | + if ($this->config->getAppValue('theming', 'color', null) !== null) { |
|
| 303 | + $variables['color-primary'] = $this->getColorPrimary(); |
|
| 304 | + $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
| 305 | + $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { |
|
| 309 | + $variables['image-login-plain'] = 'true'; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $variables['has-legal-links'] = 'false'; |
|
| 313 | + if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
| 314 | + $variables['has-legal-links'] = 'true'; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + $cache->set('getScssVariables', $variables); |
|
| 318 | + return $variables; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Check if the image should be replaced by the theming app |
|
| 323 | + * and return the new image location then |
|
| 324 | + * |
|
| 325 | + * @param string $app name of the app |
|
| 326 | + * @param string $image filename of the image |
|
| 327 | + * @return bool|string false if image should not replaced, otherwise the location of the image |
|
| 328 | + */ |
|
| 329 | + public function replaceImagePath($app, $image) { |
|
| 330 | + if ($app === '' || $app === 'files_sharing') { |
|
| 331 | + $app = 'core'; |
|
| 332 | + } |
|
| 333 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 334 | + |
|
| 335 | + try { |
|
| 336 | + $customFavicon = $this->imageManager->getImage('favicon'); |
|
| 337 | + } catch (NotFoundException $e) { |
|
| 338 | + $customFavicon = null; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + $route = false; |
|
| 342 | + if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
| 343 | + $route = $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]); |
|
| 344 | + } |
|
| 345 | + if (($image === 'favicon-touch.png' || $image === 'favicon-fb.png') && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
| 346 | + $route = $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]); |
|
| 347 | + } |
|
| 348 | + if ($image === 'manifest.json') { |
|
| 349 | + try { |
|
| 350 | + $appPath = $this->appManager->getAppPath($app); |
|
| 351 | + if (file_exists($appPath . '/img/manifest.json')) { |
|
| 352 | + return false; |
|
| 353 | + } |
|
| 354 | + } catch (AppPathNotFoundException $e) { |
|
| 355 | + } |
|
| 356 | + $route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest'); |
|
| 357 | + } |
|
| 358 | + if (strpos($image, 'filetypes/') === 0 && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) { |
|
| 359 | + $route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if ($route) { |
|
| 363 | + return $route . '?v=' . $cacheBusterValue; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + return false; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Increases the cache buster key |
|
| 371 | + */ |
|
| 372 | + private function increaseCacheBuster() { |
|
| 373 | + $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 374 | + $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
| 375 | + $this->cacheFactory->createDistributed('theming-')->clear(); |
|
| 376 | + $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Update setting in the database |
|
| 381 | + * |
|
| 382 | + * @param string $setting |
|
| 383 | + * @param string $value |
|
| 384 | + */ |
|
| 385 | + public function set($setting, $value) { |
|
| 386 | + $this->config->setAppValue('theming', $setting, $value); |
|
| 387 | + $this->increaseCacheBuster(); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Revert settings to the default value |
|
| 392 | + * |
|
| 393 | + * @param string $setting setting which should be reverted |
|
| 394 | + * @return string default value |
|
| 395 | + */ |
|
| 396 | + public function undo($setting) { |
|
| 397 | + $this->config->deleteAppValue('theming', $setting); |
|
| 398 | + $this->increaseCacheBuster(); |
|
| 399 | + |
|
| 400 | + switch ($setting) { |
|
| 401 | + case 'name': |
|
| 402 | + $returnValue = $this->getEntity(); |
|
| 403 | + break; |
|
| 404 | + case 'url': |
|
| 405 | + $returnValue = $this->getBaseUrl(); |
|
| 406 | + break; |
|
| 407 | + case 'slogan': |
|
| 408 | + $returnValue = $this->getSlogan(); |
|
| 409 | + break; |
|
| 410 | + case 'color': |
|
| 411 | + $returnValue = $this->getColorPrimary(); |
|
| 412 | + break; |
|
| 413 | + default: |
|
| 414 | + $returnValue = ''; |
|
| 415 | + break; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + return $returnValue; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Color of text in the header and primary buttons |
|
| 423 | + * |
|
| 424 | + * @return string |
|
| 425 | + */ |
|
| 426 | + public function getTextColorPrimary() { |
|
| 427 | + return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
| 428 | + } |
|
| 429 | 429 | } |