From 3d55569a277a68c9dac54b33684c3e22839386d8 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Fri, 18 Dec 2015 11:37:18 +0100 Subject: OC_Helper::makeURLAbsolute is not used anymore --- lib/private/helper.php | 12 ------------ tests/lib/helper.php | 42 ------------------------------------------ 2 files changed, 54 deletions(-) diff --git a/lib/private/helper.php b/lib/private/helper.php index 72282362fe6..92ae25de4cc 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -69,18 +69,6 @@ class OC_Helper { ); } - /** - * Makes an $url absolute - * @param string $url the url - * @return string the absolute url - * @deprecated Use \OC::$server->getURLGenerator()->getAbsoluteURL($url) - * - * Returns a absolute url to the given app and file. - */ - public static function makeURLAbsolute($url) { - return OC::$server->getURLGenerator()->getAbsoluteURL($url); - } - /** * Creates an url for remote use * @param string $service id diff --git a/tests/lib/helper.php b/tests/lib/helper.php index 51f7342f456..794502e5e21 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -243,48 +243,6 @@ class Test_Helper extends \Test\TestCase { // Url generator methods - /** - * @small - * test absolute URL construction - * @dataProvider provideDocRootURLs - */ - function testMakeAbsoluteURLDocRoot($url, $expectedResult) { - \OC::$WEBROOT = ''; - $result = \OC_Helper::makeURLAbsolute($url); - - $this->assertEquals($expectedResult, $result); - } - - /** - * @small - * test absolute URL construction - * @dataProvider provideSubDirURLs - */ - function testMakeAbsoluteURLSubDir($url, $expectedResult) { - \OC::$WEBROOT = '/owncloud'; - $result = \OC_Helper::makeURLAbsolute($url); - - $this->assertEquals($expectedResult, $result); - } - - public function provideDocRootURLs() { - return array( - array('index.php', 'http://localhost/index.php'), - array('/index.php', 'http://localhost/index.php'), - array('/apps/index.php', 'http://localhost/apps/index.php'), - array('apps/index.php', 'http://localhost/apps/index.php'), - ); - } - - public function provideSubDirURLs() { - return array( - array('index.php', 'http://localhost/owncloud/index.php'), - array('/index.php', 'http://localhost/owncloud/index.php'), - array('/apps/index.php', 'http://localhost/owncloud/apps/index.php'), - array('apps/index.php', 'http://localhost/owncloud/apps/index.php'), - ); - } - /** * @small * test linkToAbsolute URL construction -- cgit v1.2.3 From e42f262d85ddd891ce823dd5d9b5a4a87c8a7786 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Fri, 18 Dec 2015 11:46:21 +0100 Subject: properly use OCP\Util instead of OC_Helper --- lib/private/helper.php | 16 ---------------- lib/private/util.php | 8 ++++---- lib/public/util.php | 5 ++++- settings/help.php | 4 ++-- tests/lib/helper.php | 46 ---------------------------------------------- 5 files changed, 10 insertions(+), 69 deletions(-) diff --git a/lib/private/helper.php b/lib/private/helper.php index 92ae25de4cc..efbc6bda1db 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -53,22 +53,6 @@ use Symfony\Component\Process\ExecutableFinder; class OC_Helper { private static $templateManager; - /** - * Creates an absolute url - * @param string $app app - * @param string $file file - * @param array $args array with param=>value, will be appended to the returned url - * The value of $args will be urlencoded - * @return string the url - * - * Returns a absolute url to the given app and file. - */ - public static function linkToAbsolute($app, $file, $args = array()) { - return OC::$server->getURLGenerator()->getAbsoluteURL( - OC::$server->getURLGenerator()->linkTo($app, $file, $args) - ); - } - /** * Creates an url for remote use * @param string $service id diff --git a/lib/private/util.php b/lib/private/util.php index c63befb3f32..2ecacc53bd4 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -974,7 +974,7 @@ class OC_Util { */ public static function checkAppEnabled($app) { if (!OC_App::isEnabled($app)) { - header('Location: ' . OC_Helper::linkToAbsolute('', 'index.php')); + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); exit(); } } @@ -988,7 +988,7 @@ class OC_Util { public static function checkLoggedIn() { // Check if we are a user if (!OC_User::isLoggedIn()) { - header('Location: ' . OC_Helper::linkToAbsolute('', 'index.php', + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php', [ 'redirect_url' => \OC::$server->getRequest()->getRequestUri() ] @@ -1006,7 +1006,7 @@ class OC_Util { public static function checkAdminUser() { OC_Util::checkLoggedIn(); if (!OC_User::isAdminUser(OC_User::getUser())) { - header('Location: ' . OC_Helper::linkToAbsolute('', 'index.php')); + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); exit(); } } @@ -1046,7 +1046,7 @@ class OC_Util { } if (!$isSubAdmin) { - header('Location: ' . OC_Helper::linkToAbsolute('', 'index.php')); + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); exit(); } return true; diff --git a/lib/public/util.php b/lib/public/util.php index da4aa6e9deb..6f5016fa4a1 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -269,7 +269,10 @@ class Util { * @since 4.0.0 - parameter $args was added in 4.5.0 */ public static function linkToAbsolute( $app, $file, $args = array() ) { - return(\OC_Helper::linkToAbsolute( $app, $file, $args )); + $urlGenerator = \OC::$server->getURLGenerator(); + return $urlGenerator->getAbsoluteURL( + $urlGenerator->linkTo($app, $file, $args) + ); } /** diff --git a/settings/help.php b/settings/help.php index 21b48242706..848ce06cf49 100644 --- a/settings/help.php +++ b/settings/help.php @@ -34,11 +34,11 @@ OC_Util::addStyle( "settings", "settings" ); if(isset($_GET['mode']) and $_GET['mode'] === 'admin') { - $url=OC_Helper::linkToAbsolute( 'core', 'doc/admin/index.html' ); + $url=\OCP\Util::linkToAbsolute( 'core', 'doc/admin/index.html' ); $style1=''; $style2=' active'; }else{ - $url=OC_Helper::linkToAbsolute( 'core', 'doc/user/index.html' ); + $url=\OCP\Util::linkToAbsolute( 'core', 'doc/user/index.html' ); $style1=' active'; $style2=''; } diff --git a/tests/lib/helper.php b/tests/lib/helper.php index 794502e5e21..22737f170d8 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -243,52 +243,6 @@ class Test_Helper extends \Test\TestCase { // Url generator methods - /** - * @small - * test linkToAbsolute URL construction - * @dataProvider provideDocRootAppAbsoluteUrlParts - */ - public function testLinkToAbsoluteDocRoot($app, $file, $args, $expectedResult) { - \OC::$WEBROOT = ''; - $result = \OC_Helper::linkToAbsolute($app, $file, $args); - - $this->assertEquals($expectedResult, $result); - } - - /** - * @small - * test linkToAbsolute URL construction in sub directory - * @dataProvider provideSubDirAppAbsoluteUrlParts - */ - public function testLinkToAbsoluteSubDir($app, $file, $args, $expectedResult) { - \OC::$WEBROOT = '/owncloud'; - $result = \OC_Helper::linkToAbsolute($app, $file, $args); - - $this->assertEquals($expectedResult, $result); - } - - /** - * @return array - */ - public function provideDocRootAppAbsoluteUrlParts() { - return array( - array('files', 'ajax/list.php', array(), 'http://localhost/index.php/apps/files/ajax/list.php'), - array('files', 'ajax/list.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/index.php/apps/files/ajax/list.php?trut=trat&dut=dat'), - array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/index.php?trut=trat&dut=dat'), - ); - } - - /** - * @return array - */ - public function provideSubDirAppAbsoluteUrlParts() { - return array( - array('files', 'ajax/list.php', array(), 'http://localhost/owncloud/index.php/apps/files/ajax/list.php'), - array('files', 'ajax/list.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/owncloud/index.php/apps/files/ajax/list.php?trut=trat&dut=dat'), - array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/owncloud/index.php?trut=trat&dut=dat'), - ); - } - /** * @small * test linkToRemoteBase URL construction -- cgit v1.2.3 From 450e2f3bd308388e5df01b2b2ea38e6bf16b1c67 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Fri, 18 Dec 2015 12:00:18 +0100 Subject: Move OC_Helper code to OCP\Util for linkToRemote --- lib/private/helper.php | 26 -------------------------- lib/public/util.php | 6 +++++- tests/lib/helper.php | 32 -------------------------------- 3 files changed, 5 insertions(+), 59 deletions(-) diff --git a/lib/private/helper.php b/lib/private/helper.php index efbc6bda1db..bd69c13de50 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -53,32 +53,6 @@ use Symfony\Component\Process\ExecutableFinder; class OC_Helper { private static $templateManager; - /** - * Creates an url for remote use - * @param string $service id - * @return string the url - * - * Returns a url to the given service. - */ - public static function linkToRemoteBase($service) { - return OC::$server->getURLGenerator()->linkTo('', 'remote.php') . '/' . $service; - } - - /** - * Creates an absolute url for remote use - * @param string $service id - * @param bool $add_slash - * @return string the url - * - * Returns a absolute url to the given service. - */ - public static function linkToRemote($service, $add_slash = true) { - return OC::$server->getURLGenerator()->getAbsoluteURL( - self::linkToRemoteBase($service) - . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : '') - ); - } - /** * Creates an absolute url for public use * @param string $service id diff --git a/lib/public/util.php b/lib/public/util.php index 6f5016fa4a1..a9fe0e47de6 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -282,7 +282,11 @@ class Util { * @since 4.0.0 */ public static function linkToRemote( $service ) { - return(\OC_Helper::linkToRemote( $service )); + $urlGenerator = \OC::$server->getURLGenerator(); + $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; + return $urlGenerator->getAbsoluteURL( + $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') + ); } /** diff --git a/tests/lib/helper.php b/tests/lib/helper.php index 22737f170d8..468d32bc37a 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -243,38 +243,6 @@ class Test_Helper extends \Test\TestCase { // Url generator methods - /** - * @small - * test linkToRemoteBase URL construction - */ - public function testLinkToRemoteBase() { - \OC::$WEBROOT = ''; - $result = \OC_Helper::linkToRemoteBase('webdav'); - $this->assertEquals('/remote.php/webdav', $result); - - \OC::$WEBROOT = '/owncloud'; - $result = \OC_Helper::linkToRemoteBase('webdav'); - $this->assertEquals('/owncloud/remote.php/webdav', $result); - } - - /** - * @small - * test linkToRemote URL construction - */ - public function testLinkToRemote() { - \OC::$WEBROOT = ''; - $result = \OC_Helper::linkToRemote('webdav'); - $this->assertEquals('http://localhost/remote.php/webdav/', $result); - $result = \OC_Helper::linkToRemote('webdav', false); - $this->assertEquals('http://localhost/remote.php/webdav', $result); - - \OC::$WEBROOT = '/owncloud'; - $result = \OC_Helper::linkToRemote('webdav'); - $this->assertEquals('http://localhost/owncloud/remote.php/webdav/', $result); - $result = \OC_Helper::linkToRemote('webdav', false); - $this->assertEquals('http://localhost/owncloud/remote.php/webdav', $result); - } - /** * @small * test linkToPublic URL construction -- cgit v1.2.3