summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2013-09-26 18:41:19 +0200
committerBart Visscher <bartv@thisnet.nl>2013-10-04 18:11:02 +0200
commit61a9098b7d88656d0297a18c1b7685c04d1c64dc (patch)
tree085e22056dcf0bfdfd50468398bcdd367b8bd224 /lib/private
parentce9436c0518d8ce522646dde33dbac141cc35c46 (diff)
downloadnextcloud-server-61a9098b7d88656d0297a18c1b7685c04d1c64dc.tar.gz
nextcloud-server-61a9098b7d88656d0297a18c1b7685c04d1c64dc.zip
Add Helper and URLGenerator interfaces to server container
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/helper.php52
-rw-r--r--lib/private/server.php20
-rwxr-xr-xlib/private/util.php4
3 files changed, 26 insertions, 50 deletions
diff --git a/lib/private/helper.php b/lib/private/helper.php
index 66e7acb407a..a34640d8e36 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -41,8 +41,7 @@ class OC_Helper {
* Returns a url to the given app and file.
*/
public static function linkToRoute($route, $parameters = array()) {
- $urlLinkTo = OC::getRouter()->generate($route, $parameters);
- return $urlLinkTo;
+ return OC::$server->getURLGenerator()->linkToRoute($route, $parameters);
}
/**
@@ -56,32 +55,7 @@ class OC_Helper {
* Returns a url to the given app and file.
*/
public static function linkTo( $app, $file, $args = array() ) {
- if( $app != '' ) {
- $app_path = OC_App::getAppPath($app);
- // Check if the app is in the app folder
- if ($app_path && file_exists($app_path . '/' . $file)) {
- if (substr($file, -3) == 'php' || substr($file, -3) == 'css') {
- $urlLinkTo = OC::$WEBROOT . '/index.php/apps/' . $app;
- $urlLinkTo .= ($file != 'index.php') ? '/' . $file : '';
- } else {
- $urlLinkTo = OC_App::getAppWebPath($app) . '/' . $file;
- }
- } else {
- $urlLinkTo = OC::$WEBROOT . '/' . $app . '/' . $file;
- }
- } else {
- if (file_exists(OC::$SERVERROOT . '/core/' . $file)) {
- $urlLinkTo = OC::$WEBROOT . '/core/' . $file;
- } else {
- $urlLinkTo = OC::$WEBROOT . '/' . $file;
- }
- }
-
- if ($args && $query = http_build_query($args, '', '&')) {
- $urlLinkTo .= '?' . $query;
- }
-
- return $urlLinkTo;
+ return OC::$server->getURLGenerator()->linkTo($app, $file, $args);
}
/**
@@ -107,7 +81,7 @@ class OC_Helper {
* Returns a absolute url to the given app and file.
*/
public static function makeURLAbsolute($url) {
- return OC_Request::serverProtocol() . '://' . OC_Request::serverHost() . $url;
+ return OC::$server->getURLGenerator()->makeURLAbsolute($url);
}
/**
@@ -156,25 +130,7 @@ class OC_Helper {
* Returns the path to the image.
*/
public static function imagePath($app, $image) {
- // Read the selected theme from the config file
- $theme = OC_Util::getTheme();
-
- // Check if the app is in the app folder
- if (file_exists(OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) {
- return OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image";
- } elseif (file_exists(OC_App::getAppPath($app) . "/img/$image")) {
- return OC_App::getAppWebPath($app) . "/img/$image";
- } elseif (!empty($app) and file_exists(OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) {
- return OC::$WEBROOT . "/themes/$theme/$app/img/$image";
- } elseif (!empty($app) and file_exists(OC::$SERVERROOT . "/$app/img/$image")) {
- return OC::$WEBROOT . "/$app/img/$image";
- } elseif (file_exists(OC::$SERVERROOT . "/themes/$theme/core/img/$image")) {
- return OC::$WEBROOT . "/themes/$theme/core/img/$image";
- } elseif (file_exists(OC::$SERVERROOT . "/core/img/$image")) {
- return OC::$WEBROOT . "/core/img/$image";
- } else {
- throw new RuntimeException('image not found: image:' . $image . ' webroot:' . OC::$WEBROOT . ' serverroot:' . OC::$SERVERROOT);
- }
+ return OC::$server->getURLGenerator()->imagePath($app, $image);
}
/**
diff --git a/lib/private/server.php b/lib/private/server.php
index e4cc0c6da81..4000f546a3b 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -105,6 +105,12 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('L10NFactory', function($c) {
return new \OC\L10N\Factory();
});
+ $this->registerService('URLGenerator', function($c) {
+ return new \OC\URLGenerator();
+ });
+ $this->registerService('AppHelper', function($c) {
+ return new \OC\AppHelper();
+ });
$this->registerService('UserCache', function($c) {
return new UserCache();
});
@@ -230,6 +236,20 @@ class Server extends SimpleContainer implements IServerContainer {
}
/**
+ * @return \OC\URLGenerator
+ */
+ function getURLGenerator() {
+ return $this->query('URLGenerator');
+ }
+
+ /**
+ * @return \OC\Helper
+ */
+ function getHelper() {
+ return $this->query('AppHelper');
+ }
+
+ /**
* Returns an ICache instance
*
* @return \OCP\ICache
diff --git a/lib/private/util.php b/lib/private/util.php
index ae9aef69b4c..04a020ff006 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -982,9 +982,9 @@ class OC_Util {
* @param string $url Url to get content
* @return string of the response or false on error
* This function get the content of a page via curl, if curl is enabled.
- * If not, file_get_element is used.
+ * If not, file_get_contents is used.
*/
- public static function getUrlContent($url){
+ public static function getUrlContent($url) {
if (function_exists('curl_init')) {
$curl = curl_init();