Add some changes for Nextcloud 34+ #2055

This commit is contained in:
the-djmaze 2026-10-29 14:33:17 +01:00
parent b5315e4044
commit 8afb1049f7
5 changed files with 102 additions and 8 deletions

View file

@ -28,7 +28,12 @@
* Custom 'data' folder path
*/
if (class_exists('OC')) {
define('APP_DATA_FOLDER_PATH', \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/').'/appdata_snappymail/');
define('APP_DATA_FOLDER_PATH', \rtrim(\trim(
\method_exists(\OC::$server, 'getSystemConfig')
? \OC::$server->getSystemConfig()->getValue('datadirectory', '')
// Nextcloud 34+
: \OC::$server->get(\OCP\IConfig::class)->getSystemValue('datadirectory', '')
), '\\/') . '/appdata_snappymail/');
} else {
http_response_code(400);
header($_SERVER['SERVER_PROTOCOL'].' 400 Bad Request', true, 400);

View file

@ -37,7 +37,11 @@ class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy
public function getSnappyMailNonce() {
static $sNonce;
if (!$sNonce) {
$cspManager = \OC::$server->getContentSecurityPolicyNonceManager();
$cspManager = (\method_exists(\OC::$server, 'getContentSecurityPolicyNonceManager')
? \OC::$server->getContentSecurityPolicyNonceManager()
// Nextcloud 34+
: \OC::$server->get(\OC\Security\CSP\ContentSecurityPolicyNonceManager::class)
);
$sNonce = $cspManager->getNonce() ?: \SnappyMail\UUID::generate();
if (\method_exists($cspManager, 'browserSupportsCspV3') && !$cspManager->browserSupportsCspV3()) {
$this->addAllowedScriptDomain("'nonce-{$sNonce}'");

View file

@ -3,6 +3,7 @@
namespace RainLoop\Actions;
use RainLoop\Enumerations\Capa;
use SnappyMail\Nextcloud;
trait Themes
{
@ -71,8 +72,8 @@ trait Themes
}
if (\class_exists('OC', false)) {
$sDir = \OC::$SERVERROOT . '/themes'; // custom user themes
if (\is_dir($sDir) && ($rDirH = \opendir($sDir))) {
$sDir = Nextcloud::themesDir();
if ($sDir && ($rDirH = \opendir($sDir))) {
while (($sFile = \readdir($rDirH)) !== false) {
if ('.' !== $sFile[0] && \is_dir("{$sDir}/{$sFile}") && \file_exists("{$sDir}/{$sFile}/snappymail/style.css")) {
$aCache[] = $sFile . '@nextcloud';
@ -113,8 +114,8 @@ trait Themes
$bLess = false;
if ('@nextcloud' === \substr($sTheme, -10)) {
$sBase = \OC::$WEBROOT . '/';
$sThemeCSSFile = \OC::$SERVERROOT . '/themes/' . \str_replace('@nextcloud', '/snappymail/style.css', $sTheme);
$sBase = Nextcloud::webRoot() . '/';
$sThemeCSSFile = Nextcloud::themesDir() . '/' . \str_replace('@nextcloud', '/snappymail/style.css', $sTheme);
} else {
$bCustomTheme = '@custom' === \substr($sTheme, -7);
if ($bCustomTheme) {

View file

@ -63,8 +63,7 @@ abstract class Log
}
if (\class_exists('OC')) {
// \OCP\Log\logger('snappymail')->log(\intval($level), $msg);
\OCP\Log\logger('snappymail')->{static::$levels[$level]}($msg);
\SnappyMail\Nextcloud::log($level, $msg);
}
*/
}

View file

@ -0,0 +1,85 @@
<?php
namespace SnappyMail;
/**
* Nextcloud 34+
* @CarlSchwan 2026-03-10
* refactor: remove long deprecated IServerContainer methods
*
* https://github.com/nextcloud/server/commit/39c14c383b698467711a2de09870d7c032d92f63
*/
abstract class Nextcloud
{
public static function themesDir(): ?string
{
if (\class_exists('OC', false)) {
$sDir = \OC::$SERVERROOT . '/themes'; // custom user themes
if (\is_dir($sDir)) {
return $sDir;
}
}
return null;
}
public static function webRoot(): ?string
{
return \class_exists('OC', false) ? \OC::$WEBROOT : null;
}
public static function getConfig(): object
{
return \method_exists(\OC::$server, 'getConfig')
? \OC::$server->getConfig()
// Nextcloud 34+
: \OC::$server->get(\OCP\IAppConfig);
}
public static function getSystemConfigValue(string $key, mixed $default = null): mixed
{
return \method_exists(\OC::$server, 'getSystemConfig')
? \OC::$server->getSystemConfig()->getValue($key, $default)
// Nextcloud 34+
: \OC::$server->get(\OCP\IConfig::class)->getSystemValue($key, $default);
}
public static function getUserSession(): mixed
{
return \method_exists(\OC::$server, 'getUserSession')
? \OC::$server->getUserSession()
// Nextcloud 34+
: \OC::$server->get(\OCP\IUserSession::class);
}
public static function setUserSessionValue(string $key, mixed $value): void
{
if (\method_exists(\OC::$server, 'getUserSession')) {
\OC::$server->getUserSession()[$key] = $value;
} else {
// Nextcloud 34+
\OC::$server->get(\OCP\IUserSession::class)->getSession()->set($key, $value);
}
}
private static
$levels = [
\LOG_EMERG => 'EMERGENCY',
\LOG_ALERT => 'ALERT',
\LOG_CRIT => 'CRITICAL',
\LOG_ERR => 'ERROR',
\LOG_WARNING => 'WARNING',
\LOG_NOTICE => 'NOTICE',
\LOG_INFO => 'INFO',
\LOG_DEBUG => 'DEBUG',
];
public static function log(int $level, string $msg): void
{
// https://www.php-fig.org/psr/psr-3/#3-psrlogloggerinterface
if (\class_exists('OCP\Log\logger')) {
// \OCP\Log\logger('snappymail')->log($level, $msg);
\OCP\Log\logger('snappymail')->{static::$levels[$level]}($msg);
}
}
}