summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-05-02 16:03:58 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2019-05-06 17:55:30 +0200
commit249a5dbdba0dc3628c0f3490680de61dc91aafc8 (patch)
tree452f288909bb811146a0683b8a75c1b87932aadc /core/src
parente0c62352b71441c2f843fd5f023000af342011a8 (diff)
downloadnextcloud-server-249a5dbdba0dc3628c0f3490680de61dc91aafc8.tar.gz
nextcloud-server-249a5dbdba0dc3628c0f3490680de61dc91aafc8.zip
Move oc_webroot, OC.webroot and OC.getRootPath() to the bundle
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'core/src')
-rw-r--r--core/src/OC/index.js13
-rw-r--r--core/src/OC/routing.js22
-rw-r--r--core/src/OC/webroot.js34
-rw-r--r--core/src/globals.js3
4 files changed, 66 insertions, 6 deletions
diff --git a/core/src/OC/index.js b/core/src/OC/index.js
index f852ef1d309..ab5552c8e57 100644
--- a/core/src/OC/index.js
+++ b/core/src/OC/index.js
@@ -30,6 +30,7 @@ import {isUserAdmin} from './admin'
import L10N from './l10n'
import {
generateUrl,
+ getRootPath,
filePath,
linkTo,
linkToOCS,
@@ -44,6 +45,7 @@ import search from './search'
import Util from './util'
import {debug} from './debug'
import {redirect, reload} from './navigation'
+import webroot from './webroot'
/** @namespace OC */
export default {
@@ -65,6 +67,7 @@ export default {
Util,
debug,
generateUrl,
+ getRootPath,
filePath,
redirect,
reload,
@@ -72,4 +75,14 @@ export default {
linkToOCS,
linkToRemote,
linkToRemoteBase,
+ /**
+ * Relative path to Nextcloud root.
+ * For example: "/nextcloud"
+ *
+ * @type string
+ *
+ * @deprecated since 8.2, use OC.getRootPath() instead
+ * @see OC#getRootPath
+ */
+ webroot,
}
diff --git a/core/src/OC/routing.js b/core/src/OC/routing.js
index e2038e4d03e..0c57f01b963 100644
--- a/core/src/OC/routing.js
+++ b/core/src/OC/routing.js
@@ -20,6 +20,7 @@
*/
import _ from 'underscore'
+
import OC from './index'
/**
@@ -35,7 +36,7 @@ export const linkTo = (app, file) => filePath(app, '', file)
* @param {string} service id
* @return {string} the url
*/
-export const linkToRemoteBase = service => OC.getRootPath() + '/remote.php/' + service
+export const linkToRemoteBase = service => getRootPath() + '/remote.php/' + service
/**
* @brief Creates an absolute url for remote use
@@ -52,7 +53,7 @@ export const linkToRemote = service => window.location.protocol + '//' + window.
*/
export const linkToOCS = (service, version) => {
version = (version !== 2) ? 1 : 2
- return window.location.protocol + '//' + window.location.host + OC.getRootPath() + '/ocs/v' + version + '.php/' + service + '/'
+ return window.location.protocol + '//' + window.location.host + getRootPath() + '/ocs/v' + version + '.php/' + service + '/'
}
/**
@@ -90,10 +91,10 @@ export const generateUrl = (url, params, options) => {
}
if (oc_config.modRewriteWorking === true) {
- return OC.getRootPath() + _build(url, params);
+ return getRootPath() + _build(url, params);
}
- return OC.getRootPath() + '/index.php' + _build(url, params);
+ return getRootPath() + '/index.php' + _build(url, params);
}
/**
@@ -105,7 +106,7 @@ export const generateUrl = (url, params, options) => {
*/
export const filePath = (app, type, file) => {
const isCore = OC.coreApps.indexOf(app) !== -1
- let link = OC.getRootPath()
+ let link = getRootPath()
if (file.substring(file.length - 3) === 'php' && !isCore) {
link += '/index.php/apps/' + app;
if (file !== 'index.php') {
@@ -144,3 +145,14 @@ export const filePath = (app, type, file) => {
}
return link
}
+
+/**
+ * Returns the web root path where this Nextcloud instance
+ * is accessible, with a leading slash.
+ * For example "/nextcloud".
+ *
+ * @return {string} web root path
+ *
+ * @since 8.2
+ */
+export const getRootPath = () => OC.webroot
diff --git a/core/src/OC/webroot.js b/core/src/OC/webroot.js
new file mode 100644
index 00000000000..cf9da346f92
--- /dev/null
+++ b/core/src/OC/webroot.js
@@ -0,0 +1,34 @@
+/*
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+let webroot = window._oc_webroot
+
+if (typeof webroot === 'undefined') {
+ webroot = location.pathname
+ var pos = webroot.indexOf('/index.php/')
+ if (pos !== -1) {
+ webroot = webroot.substr(0, pos)
+ } else {
+ webroot = webroot.substr(0, webroot.lastIndexOf('/'))
+ }
+}
+
+export default webroot
diff --git a/core/src/globals.js b/core/src/globals.js
index 01a7f3452ef..bbe65009403 100644
--- a/core/src/globals.js
+++ b/core/src/globals.js
@@ -108,8 +108,9 @@ window['moment'] = moment
window['OC'] = OC
setDeprecatedProp('oc_config', OC.config, 'use OC.config instead')
-setDeprecatedProp('oc_isadmin', OC.isUserAdmin(), 'use OC.isUserAdmin() instead')
setDeprecatedProp('oc_debug', OC.debug, 'use OC.debug instead')
+setDeprecatedProp('oc_isadmin', OC.isUserAdmin(), 'use OC.isUserAdmin() instead')
+setDeprecatedProp('oc_webroot', OC.webroot, 'use OC.getRootPath() instead')
setDeprecatedProp('OCDialogs', OC.dialogs, 'use OC.dialogs instead')
window['OCP'] = OCP
window['OCA'] = OCA