From 70f9f0bd7675ccd78a63d3c71ceb9fd2f36f84dc Mon Sep 17 00:00:00 2001 From: djmaze Date: Mon, 8 Nov 2021 17:40:21 +0100 Subject: [PATCH] Improved demo mode plugin --- plugins/demo-account/index.php | 2 +- plugins/demo-account/storage.php | 56 +++---------------- .../0.0.0/app/libraries/RainLoop/Actions.php | 4 +- .../Providers/Storage/FileStorage.php | 4 +- 4 files changed, 14 insertions(+), 52 deletions(-) diff --git a/plugins/demo-account/index.php b/plugins/demo-account/index.php index e866e949e..51f7e2851 100644 --- a/plugins/demo-account/index.php +++ b/plugins/demo-account/index.php @@ -86,7 +86,7 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin */ public function MainFabrica($sName, &$oDriver) { - if (('storage' === $sName || 'storage-local' === $sName) && \function_exists('apcu_store')) { + if ('storage' === $sName || 'storage-local' === $sName) { $oAccount = $this->Manager()->Actions()->GetAccount(); if ($this->isDemoAccount($oAccount)) { require_once __DIR__ . '/storage.php'; diff --git a/plugins/demo-account/storage.php b/plugins/demo-account/storage.php index e07bd48c5..dfb00e0fc 100644 --- a/plugins/demo-account/storage.php +++ b/plugins/demo-account/storage.php @@ -2,56 +2,18 @@ class DemoStorage extends \RainLoop\Providers\Storage\FileStorage { - /** - * @param \RainLoop\Model\Account|string|null $oAccount - */ - public function Put($oAccount, int $iStorageType, string $sKey, string $sValue) : bool - { - return !!\apcu_store($this->generateFileName($oAccount, $iStorageType, $sKey, true), $sValue); - } - - /** - * @param \RainLoop\Model\Account|string|null $oAccount - * @param mixed $mDefault = false - * - * @return mixed - */ - public function Get($oAccount, int $iStorageType, string $sKey, $mDefault = false) - { - $bValue = false; - $mValue = \apcu_fetch($this->generateFileName($oAccount, $iStorageType, $sKey), $bValue); - if (!$bValue) - { - $mValue = $mDefault; - } - - return $mValue; - } - - /** - * @param \RainLoop\Model\Account|string|null $oAccount - */ - public function Clear($oAccount, int $iStorageType, string $sKey) : bool - { - \apcu_delete($this->generateFileName($oAccount, $iStorageType, $sKey)); - - return true; - } - - /** - * @param \RainLoop\Model\Account|string $oAccount - */ - public function DeleteStorage($oAccount) : bool - { - return !!$oAccount; - } - /** * @param \RainLoop\Model\Account|string|null $mAccount */ - public function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string + protected function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string { - $sFileName = parent::generateFileName($mAccount, $iStorageType, $sKey, false, false); - return $sFileName.'/'.\RainLoop\Utils::GetConnectionToken().'/'; + if (\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY === $iStorageType) { + return parent::generateFileName($mAccount, $iStorageType, $sKey, $bMkDir, $bForDeleteAction); + } + + return $this->sDataPath + .'/demo' + .'/'.static::fixName(\RainLoop\Utils::GetConnectionToken()) + .'/'.($sKey ? static::fixName($sKey) : ''); } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 616ce6f1e..be196b9f3 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -828,9 +828,9 @@ class Actions 'RemoveColors' => (bool) $oConfig->Get('defaults', 'remove_colors', false), 'MPP' => (int) $oConfig->Get('webmail', 'messages_per_page', 25), 'MessageReadDelay' => (int) $oConfig->Get('webmail', 'message_read_delay', 5), - 'SoundNotification' => false, + 'SoundNotification' => true, 'NotificationSound' => 'new-mail', - 'DesktopNotifications' => false, + 'DesktopNotifications' => true, 'Layout' => (int) $oConfig->Get('defaults', 'view_layout', Enumerations\Layout::SIDE_PREVIEW), 'EditorDefaultType' => (string) $oConfig->Get('defaults', 'view_editor_type', ''), 'UseCheckboxesInList' => (bool) $oConfig->Get('defaults', 'view_use_checkboxes', true), diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/FileStorage.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/FileStorage.php index 2a08367d3..7859a62d1 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/FileStorage.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/FileStorage.php @@ -89,7 +89,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage * Replace control characters, ampersand, spaces and reserved characters (based on Win95 VFAT) * en.wikipedia.org/wiki/Filename#Reserved_characters_and_words */ - private static function fixName($filename) + protected static function fixName($filename) { return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $filename); } @@ -97,7 +97,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage /** * @param \RainLoop\Model\Account|string|null $mAccount */ - private function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string + protected function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string { $sEmail = $sSubEmail = ''; if (null === $mAccount) {