aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/legacy/OC_Util.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/legacy/OC_Util.php')
-rw-r--r--lib/private/legacy/OC_Util.php258
1 files changed, 49 insertions, 209 deletions
diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php
index f82082d3d12..ebca1105838 100644
--- a/lib/private/legacy/OC_Util.php
+++ b/lib/private/legacy/OC_Util.php
@@ -9,7 +9,6 @@ use bantu\IniGetWrapper\IniGetWrapper;
use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager;
use OC\Files\SetupManager;
use OCP\Files\Template\ITemplateManager;
-use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IURLGenerator;
@@ -19,18 +18,13 @@ use OCP\Security\ISecureRandom;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;
+/**
+ * @deprecated 32.0.0 Use \OCP\Util or any appropriate official API instead
+ */
class OC_Util {
- public static $scripts = [];
public static $styles = [];
public static $headers = [];
- /** @var array Local cache of version.php */
- private static $versionCache = null;
-
- protected static function getAppManager() {
- return \OC::$server->getAppManager();
- }
-
/**
* Setup the file system
*
@@ -63,8 +57,8 @@ class OC_Util {
* Check if a password is required for each public link
*
* @param bool $checkGroupMembership Check group membership exclusion
- * @return boolean
- * @suppress PhanDeprecatedFunction
+ * @return bool
+ * @deprecated 32.0.0 use OCP\Share\IManager's shareApiLinkEnforcePassword directly
*/
public static function isPublicLinkPasswordRequired(bool $checkGroupMembership = true) {
/** @var IManager $shareManager */
@@ -78,6 +72,7 @@ class OC_Util {
* @param IGroupManager $groupManager
* @param IUser|null $user
* @return bool
+ * @deprecated 32.0.0 use OCP\Share\IManager's sharingDisabledForUser directly
*/
public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) {
/** @var IManager $shareManager */
@@ -90,7 +85,7 @@ class OC_Util {
* check if share API enforces a default expire date
*
* @return bool
- * @suppress PhanDeprecatedFunction
+ * @deprecated 32.0.0 use OCP\Share\IManager's shareApiLinkDefaultExpireDateEnforced directly
*/
public static function isDefaultExpireDateEnforced() {
/** @var IManager $shareManager */
@@ -103,6 +98,7 @@ class OC_Util {
*
* @param IUser|null $user
* @return int|\OCP\Files\FileInfo::SPACE_UNLIMITED|false|float Quota bytes
+ * @deprecated 9.0.0 - Use \OCP\IUser::getQuota or \OCP\IUser::getQuotaBytes
*/
public static function getUserQuota(?IUser $user) {
if (is_null($user)) {
@@ -112,7 +108,7 @@ class OC_Util {
if ($userQuota === 'none') {
return \OCP\Files\FileInfo::SPACE_UNLIMITED;
}
- return OC_Helper::computerFileSize($userQuota);
+ return \OCP\Util::computerFileSize($userQuota);
}
/**
@@ -191,14 +187,13 @@ class OC_Util {
$child = $target->newFolder($file);
self::copyr($source . '/' . $file, $child);
} else {
- $child = $target->newFile($file);
$sourceStream = fopen($source . '/' . $file, 'r');
if ($sourceStream === false) {
$logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']);
closedir($dir);
return;
}
- $child->putContent($sourceStream);
+ $target->newFile($file, $sourceStream);
}
}
}
@@ -206,12 +201,10 @@ class OC_Util {
}
/**
- * @return void
- * @suppress PhanUndeclaredMethod
+ * @deprecated 32.0.0 Call tearDown directly on SetupManager
*/
- public static function tearDownFS() {
- /** @var SetupManager $setupManager */
- $setupManager = \OC::$server->get(SetupManager::class);
+ public static function tearDownFS(): void {
+ $setupManager = \OCP\Server::get(SetupManager::class);
$setupManager->tearDown();
}
@@ -220,10 +213,9 @@ class OC_Util {
*
* @param string $application application to get the files from
* @param string $directory directory within this application (css, js, vendor, etc)
- * @param string $file the file inside of the above folder
- * @return string the path
+ * @param ?string $file the file inside of the above folder
*/
- private static function generatePath($application, $directory, $file) {
+ private static function generatePath($application, $directory, $file): string {
if (is_null($file)) {
$file = $application;
$application = '';
@@ -236,68 +228,14 @@ class OC_Util {
}
/**
- * add a javascript file
- *
- * @deprecated 24.0.0 - Use \OCP\Util::addScript
- *
- * @param string $application application id
- * @param string|null $file filename
- * @param bool $prepend prepend the Script to the beginning of the list
- * @return void
- */
- public static function addScript($application, $file = null, $prepend = false) {
- $path = OC_Util::generatePath($application, 'js', $file);
-
- // core js files need separate handling
- if ($application !== 'core' && $file !== null) {
- self::addTranslations($application);
- }
- self::addExternalResource($application, $prepend, $path, 'script');
- }
-
- /**
- * add a javascript file from the vendor sub folder
- *
- * @param string $application application id
- * @param string|null $file filename
- * @param bool $prepend prepend the Script to the beginning of the list
- * @return void
- */
- public static function addVendorScript($application, $file = null, $prepend = false) {
- $path = OC_Util::generatePath($application, 'vendor', $file);
- self::addExternalResource($application, $prepend, $path, 'script');
- }
-
- /**
- * add a translation JS file
- *
- * @deprecated 24.0.0
- *
- * @param string $application application id
- * @param string|null $languageCode language code, defaults to the current language
- * @param bool|null $prepend prepend the Script to the beginning of the list
- */
- public static function addTranslations($application, $languageCode = null, $prepend = false) {
- if (is_null($languageCode)) {
- $languageCode = \OC::$server->get(IFactory::class)->findLanguage($application);
- }
- if (!empty($application)) {
- $path = "$application/l10n/$languageCode";
- } else {
- $path = "l10n/$languageCode";
- }
- self::addExternalResource($application, $prepend, $path, 'script');
- }
-
- /**
* add a css file
*
* @param string $application application id
* @param string|null $file filename
* @param bool $prepend prepend the Style to the beginning of the list
- * @return void
+ * @deprecated 32.0.0 Use \OCP\Util::addStyle
*/
- public static function addStyle($application, $file = null, $prepend = false) {
+ public static function addStyle($application, $file = null, $prepend = false): void {
$path = OC_Util::generatePath($application, 'css', $file);
self::addExternalResource($application, $prepend, $path, 'style');
}
@@ -308,9 +246,9 @@ class OC_Util {
* @param string $application application id
* @param string|null $file filename
* @param bool $prepend prepend the Style to the beginning of the list
- * @return void
+ * @deprecated 32.0.0
*/
- public static function addVendorStyle($application, $file = null, $prepend = false) {
+ public static function addVendorStyle($application, $file = null, $prepend = false): void {
$path = OC_Util::generatePath($application, 'vendor', $file);
self::addExternalResource($application, $prepend, $path, 'style');
}
@@ -322,9 +260,8 @@ class OC_Util {
* @param bool $prepend prepend the file to the beginning of the list
* @param string $path
* @param string $type (script or style)
- * @return void
*/
- private static function addExternalResource($application, $prepend, $path, $type = 'script') {
+ private static function addExternalResource($application, $prepend, $path, $type = 'script'): void {
if ($type === 'style') {
if (!in_array($path, self::$styles)) {
if ($prepend === true) {
@@ -333,14 +270,6 @@ class OC_Util {
self::$styles[] = $path;
}
}
- } elseif ($type === 'script') {
- if (!in_array($path, self::$scripts)) {
- if ($prepend === true) {
- array_unshift(self::$scripts, $path);
- } else {
- self::$scripts [] = $path;
- }
- }
}
}
@@ -352,8 +281,9 @@ class OC_Util {
* @param array $attributes array of attributes for the element
* @param string $text the text content for the element
* @param bool $prepend prepend the header to the beginning of the list
+ * @deprecated 32.0.0 Use \OCP\Util::addHeader instead
*/
- public static function addHeader($tag, $attributes, $text = null, $prepend = false) {
+ public static function addHeader($tag, $attributes, $text = null, $prepend = false): void {
$header = [
'tag' => $tag,
'attributes' => $attributes,
@@ -369,7 +299,6 @@ class OC_Util {
/**
* check if the current server configuration is suitable for ownCloud
*
- * @param \OC\SystemConfig $config
* @return array arrays with error messages and hints
*/
public static function checkServer(\OC\SystemConfig $config) {
@@ -402,7 +331,7 @@ class OC_Util {
}
// Check if config folder is writable.
- if (!OC_Helper::isReadOnlyConfigEnabled()) {
+ if (!(bool)$config->getValue('config_is_read_only', false)) {
if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) {
$errors[] = [
'error' => $l->t('Cannot write into "config" directory.'),
@@ -414,19 +343,6 @@ class OC_Util {
}
}
- // Check if there is a writable install folder.
- if ($config->getValue('appstoreenabled', true)) {
- if (OC_App::getInstallPath() === null
- || !is_writable(OC_App::getInstallPath())
- || !is_readable(OC_App::getInstallPath())
- ) {
- $errors[] = [
- 'error' => $l->t('Cannot write into "apps" directory.'),
- 'hint' => $l->t('This can usually be fixed by giving the web server write access to the apps directory'
- . ' or disabling the App Store in the config file.')
- ];
- }
- }
// Create root dir.
if ($config->getValue('installed', false)) {
if (!is_dir($CONFIG_DATADIRECTORY)) {
@@ -550,8 +466,8 @@ class OC_Util {
* TODO: Should probably be implemented in the above generic dependency
* check somehow in the long-term.
*/
- if ($iniWrapper->getBool('mbstring.func_overload') !== null &&
- $iniWrapper->getBool('mbstring.func_overload') === true) {
+ if ($iniWrapper->getBool('mbstring.func_overload') !== null
+ && $iniWrapper->getBool('mbstring.func_overload') === true) {
$errors[] = [
'error' => $l->t('<code>mbstring.func_overload</code> is set to <code>%s</code> instead of the expected value <code>0</code>.', [$iniWrapper->getString('mbstring.func_overload')]),
'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini.')
@@ -592,6 +508,7 @@ class OC_Util {
*
* @param string $dataDirectory
* @return array arrays with error messages and hints
+ * @internal
*/
public static function checkDataDirectoryPermissions($dataDirectory) {
if (!\OC::$server->getConfig()->getSystemValueBool('check_data_directory_permissions', true)) {
@@ -620,6 +537,7 @@ class OC_Util {
*
* @param string $dataDirectory data directory path
* @return array errors found
+ * @internal
*/
public static function checkDataDirectoryValidity($dataDirectory) {
$l = \OC::$server->getL10N('lib');
@@ -644,9 +562,9 @@ class OC_Util {
* Check if the user is logged in, redirects to home if not. With
* redirect URL parameter to the request URI.
*
- * @return void
+ * @deprecated 32.0.0
*/
- public static function checkLoggedIn() {
+ public static function checkLoggedIn(): void {
// Check if we are a user
if (!\OC::$server->getUserSession()->isLoggedIn()) {
header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute(
@@ -668,10 +586,10 @@ class OC_Util {
/**
* Check if the user is a admin, redirects to home if not
*
- * @return void
+ * @deprecated 32.0.0
*/
- public static function checkAdminUser() {
- OC_Util::checkLoggedIn();
+ public static function checkAdminUser(): void {
+ self::checkLoggedIn();
if (!OC_User::isAdminUser(OC_User::getUser())) {
header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php'));
exit();
@@ -684,7 +602,7 @@ class OC_Util {
* the apps visible for the current user
*
* @return string URL
- * @suppress PhanDeprecatedFunction
+ * @deprecated 32.0.0 use IURLGenerator's linkToDefaultPageUrl directly
*/
public static function getDefaultPageUrl() {
/** @var IURLGenerator $urlGenerator */
@@ -695,9 +613,9 @@ class OC_Util {
/**
* Redirect to the user default page
*
- * @return void
+ * @deprecated 32.0.0
*/
- public static function redirectToDefaultPage() {
+ public static function redirectToDefaultPage(): void {
$location = self::getDefaultPageUrl();
header('Location: ' . $location);
exit();
@@ -708,7 +626,7 @@ class OC_Util {
*
* @return string
*/
- public static function getInstanceId() {
+ public static function getInstanceId(): string {
$id = \OC::$server->getSystemConfig()->getValue('instanceid', null);
if (is_null($id)) {
// We need to guarantee at least one letter in instanceid so it can be used as the session_name
@@ -725,11 +643,11 @@ class OC_Util {
* string or array of strings before displaying it on a web page.
*
* @param string|string[] $value
- * @return string|string[] an array of sanitized strings or a single sanitized string, depends on the input parameter.
+ * @return ($value is array ? string[] : string)
+ * @deprecated 32.0.0 use \OCP\Util::sanitizeHTML instead
*/
public static function sanitizeHTML($value) {
if (is_array($value)) {
- /** @var string[] $value */
$value = array_map(function ($value) {
return self::sanitizeHTML($value);
}, $value);
@@ -749,6 +667,7 @@ class OC_Util {
*
* @param string $component part of URI to encode
* @return string
+ * @deprecated 32.0.0 use \OCP\Util::encodePath instead
*/
public static function encodePath($component) {
$encoded = rawurlencode($component);
@@ -756,86 +675,6 @@ class OC_Util {
return $encoded;
}
-
- public function createHtaccessTestFile(\OCP\IConfig $config) {
- // php dev server does not support htaccess
- if (php_sapi_name() === 'cli-server') {
- return false;
- }
-
- // testdata
- $fileName = '/htaccesstest.txt';
- $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.';
-
- // creating a test file
- $testFile = $config->getSystemValueString('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
-
- if (file_exists($testFile)) {// already running this test, possible recursive call
- return false;
- }
-
- $fp = @fopen($testFile, 'w');
- if (!$fp) {
- throw new \OCP\HintException('Can\'t create test file to check for working .htaccess file.',
- 'Make sure it is possible for the web server to write to ' . $testFile);
- }
- fwrite($fp, $testContent);
- fclose($fp);
-
- return $testContent;
- }
-
- /**
- * Check if the .htaccess file is working
- *
- * @param \OCP\IConfig $config
- * @return bool
- * @throws Exception
- * @throws \OCP\HintException If the test file can't get written.
- */
- public function isHtaccessWorking(\OCP\IConfig $config) {
- if (\OC::$CLI || !$config->getSystemValueBool('check_for_working_htaccess', true)) {
- return true;
- }
-
- $testContent = $this->createHtaccessTestFile($config);
- if ($testContent === false) {
- return false;
- }
-
- $fileName = '/htaccesstest.txt';
- $testFile = $config->getSystemValueString('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
-
- // accessing the file via http
- $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName);
- try {
- $content = \OC::$server->get(IClientService::class)->newClient()->get($url)->getBody();
- } catch (\Exception $e) {
- $content = false;
- }
-
- if (str_starts_with($url, 'https:')) {
- $url = 'http:' . substr($url, 6);
- } else {
- $url = 'https:' . substr($url, 5);
- }
-
- try {
- $fallbackContent = \OC::$server->get(IClientService::class)->newClient()->get($url)->getBody();
- } catch (\Exception $e) {
- $fallbackContent = false;
- }
-
- // cleanup
- @unlink($testFile);
-
- /*
- * If the content is not equal to test content our .htaccess
- * is working as required
- */
- return $content !== $testContent && $fallbackContent !== $testContent;
- }
-
/**
* Check if current locale is non-UTF8
*
@@ -855,9 +694,9 @@ class OC_Util {
* Check if the setlocale call does not work. This can happen if the right
* local packages are not available on the server.
*
- * @return bool
+ * @internal
*/
- public static function isSetLocaleWorking() {
+ public static function isSetLocaleWorking(): bool {
if (self::isNonUTF8Locale()) {
// Borrowed from \Patchwork\Utf8\Bootup::initLocale
setlocale(LC_ALL, 'C.UTF-8', 'C');
@@ -875,9 +714,9 @@ class OC_Util {
/**
* Check if it's possible to get the inline annotations
*
- * @return bool
+ * @internal
*/
- public static function isAnnotationsWorking() {
+ public static function isAnnotationsWorking(): bool {
if (PHP_VERSION_ID >= 80300) {
/** @psalm-suppress UndefinedMethod */
$reflection = \ReflectionMethod::createFromMethodName(__METHOD__);
@@ -892,9 +731,9 @@ class OC_Util {
/**
* Check if the PHP module fileinfo is loaded.
*
- * @return bool
+ * @internal
*/
- public static function fileInfoLoaded() {
+ public static function fileInfoLoaded(): bool {
return function_exists('finfo_open');
}
@@ -940,15 +779,15 @@ class OC_Util {
* Normalize a unicode string
*
* @param string $value a not normalized string
- * @return bool|string
+ * @return string The normalized string or the input if the normalization failed
*/
- public static function normalizeUnicode($value) {
+ public static function normalizeUnicode(string $value): string {
if (Normalizer::isNormalized($value)) {
return $value;
}
$normalizedValue = Normalizer::normalize($value);
- if ($normalizedValue === null || $normalizedValue === false) {
+ if ($normalizedValue === false) {
\OCP\Server::get(LoggerInterface::class)->warning('normalizing failed for "' . $value . '"', ['app' => 'core']);
return $value;
}
@@ -964,6 +803,7 @@ class OC_Util {
* @param \OC\SystemConfig $config
* @return bool whether the core or any app needs an upgrade
* @throws \OCP\HintException When the upgrade from the given version is not allowed
+ * @deprecated 32.0.0 Use \OCP\Util::needUpgrade instead
*/
public static function needUpgrade(\OC\SystemConfig $config) {
if ($config->getValue('installed', false)) {