properly use OCP\Util instead of OC_Helper
This commit is contained in:
parent
3d55569a27
commit
e42f262d85
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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='';
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue