mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-02-24 14:57:26 +08:00
Draft code to run SnappyMail inside Nextcloud without iframe for
This commit is contained in:
parent
dcf4983a7d
commit
d52f2adb2b
4 changed files with 82 additions and 12 deletions
|
@ -16,6 +16,9 @@ class PageController extends Controller
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
// Uncomment to test without using an iframe
|
||||
// return static::index_embed();
|
||||
|
||||
\OC::$server->getNavigationManager()->setActiveEntry('snappymail');
|
||||
|
||||
\OCP\Util::addStyle('snappymail', 'style');
|
||||
|
@ -72,5 +75,61 @@ class PageController extends Controller
|
|||
{
|
||||
SnappyMailHelper::startApp();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draft code to run without using an iframe
|
||||
*/
|
||||
private static function index_embed()
|
||||
{
|
||||
\OC::$server->getNavigationManager()->setActiveEntry('snappymail');
|
||||
|
||||
\OCP\Util::addStyle('snappymail', 'style');
|
||||
|
||||
SnappyMailHelper::startApp(true);
|
||||
$webPath = \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app';
|
||||
$oConfig = \RainLoop\Api::Config();
|
||||
$oActions = \RainLoop\Api::Actions();
|
||||
$oHttp = \MailSo\Base\Http::SingletonInstance();
|
||||
$oServiceActions = new \RainLoop\ServiceActions($oHttp, $oActions);
|
||||
$sAppJsMin = $oConfig->Get('labs', 'use_app_debug_js', false) ? '' : '.min';
|
||||
$sAppCssMin = $oConfig->Get('labs', 'use_app_debug_css', false) ? '' : '.min';
|
||||
$sLanguage = $oActions->GetLanguage(false);
|
||||
|
||||
$sScriptNonce = \OC::$server->getContentSecurityPolicyNonceManager()->getNonce();
|
||||
// $sScriptNonce = \SnappyMail\UUID::generate();
|
||||
// \RainLoop\Service::setCSP($sScriptNonce);
|
||||
|
||||
$params = [
|
||||
'LoadingDescriptionEsc' => \htmlspecialchars($oConfig->Get('webmail', 'loading_description', 'SnappyMail'), ENT_QUOTES|ENT_IGNORE, 'UTF-8'),
|
||||
'BaseTemplates' => \RainLoop\Utils::ClearHtmlOutput($oServiceActions->compileTemplates(false)),
|
||||
'BaseAppBootScript' => \str_replace(
|
||||
'loadScript(`./?/',
|
||||
'loadScript(`'.$webPath.'/?/',
|
||||
\file_get_contents(APP_VERSION_ROOT_PATH.'static/js'.($sAppJsMin ? '/min' : '').'/boot'.$sAppJsMin.'.js')
|
||||
),
|
||||
'BaseAppBootScriptNonce' => $sScriptNonce,
|
||||
'BaseLanguage' => $oActions->compileLanguage($sLanguage, false),
|
||||
];
|
||||
|
||||
\OCP\Util::addHeader('style', ['id'=>'app-boot-css'], \file_get_contents(APP_VERSION_ROOT_PATH.'static/css/boot'.$sAppCssMin.'.css'));
|
||||
\OCP\Util::addHeader('link', ['type'=>'text/css','rel'=>'stylesheet','href'=>\RainLoop\Utils::WebStaticPath('css/app'.$sAppCssMin.'.css')], '');
|
||||
\OCP\Util::addHeader('style', ['id'=>'app-theme-style','data-href'=>$oActions->ThemeLink(false)],
|
||||
\preg_replace(
|
||||
'/\\s*([:;{},]+)\\s*/s',
|
||||
'$1',
|
||||
$oActions->compileCss($oActions->GetTheme(false), false)
|
||||
));
|
||||
|
||||
$response = new TemplateResponse('snappymail', 'index_embed', $params);
|
||||
|
||||
$csp = new ContentSecurityPolicy();
|
||||
$csp->addAllowedScriptDomain("'self'");
|
||||
$csp->useStrictDynamic(true);
|
||||
$csp->allowEvalScript(true); // $csp->addAllowedScriptDomain("'unsafe-eval'");
|
||||
$csp->addAllowedStyleDomain("'self'");
|
||||
$response->setContentSecurityPolicy($csp);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,14 +36,15 @@ class SnappyMailHelper
|
|||
if (!\class_exists('RainLoop\\Api')) {
|
||||
if ($api) {
|
||||
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
|
||||
} else {
|
||||
$_SERVER['SCRIPT_NAME'] = \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/index.php';
|
||||
}
|
||||
$_ENV['SNAPPYMAIL_NEXTCLOUD'] = true;
|
||||
$_SERVER['SCRIPT_NAME'] = \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/index.php';
|
||||
|
||||
$sData = \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/').'/appdata_snappymail/';
|
||||
if (\is_dir($sData)) {
|
||||
\define('APP_DATA_FOLDER_PATH', $sData);
|
||||
}
|
||||
|
||||
// Nextcloud the default spl_autoload_register() not working
|
||||
\spl_autoload_register(function($sClassName){
|
||||
$file = RAINLOOP_APP_LIBRARIES_PATH . \strtolower(\strtr($sClassName, '\\', DIRECTORY_SEPARATOR)) . '.php';
|
||||
|
@ -51,6 +52,7 @@ class SnappyMailHelper
|
|||
include_once $file;
|
||||
}
|
||||
});
|
||||
|
||||
require_once \OC::$server->getAppManager()->getAppPath('snappymail') . '/app/index.php';
|
||||
}
|
||||
}
|
||||
|
|
17
integrations/nextcloud/snappymail/templates/index_embed.php
Executable file
17
integrations/nextcloud/snappymail/templates/index_embed.php
Executable file
|
@ -0,0 +1,17 @@
|
|||
<div id="rl-app" data-admin="0" spellcheck="false">
|
||||
<div id="rl-loading">
|
||||
<div id="rl-loading-desc"><?php echo $_['LoadingDescriptionEsc']; ?></div>
|
||||
<i class="icon-spinner"></i>
|
||||
</div>
|
||||
<div id="rl-loading-error" hidden="">An error occurred.<br>Please refresh the page and try again.</div>
|
||||
<div id="rl-content" hidden="">
|
||||
<div id="rl-left"></div>
|
||||
<div id="rl-right"></div>
|
||||
</div>
|
||||
<div id="rl-popups"></div>
|
||||
<?php echo $_['BaseTemplates']; ?>
|
||||
</div>
|
||||
<?php
|
||||
echo '
|
||||
<script nonce="'.$_['BaseAppBootScriptNonce'].'" type="text/javascript">'.$_['BaseAppBootScript'].$_['BaseLanguage'].'</script>
|
||||
';
|
|
@ -17,15 +17,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$this->addHook('filter.app-data', 'FilterAppData');
|
||||
$this->addHook('json.attachments', 'SaveAttachments');
|
||||
|
||||
$sAppPath = \rtrim(\trim(\OC::$server->getAppManager()->getAppWebPath()), '\\/').'/app/';
|
||||
if (!$sAppPath) {
|
||||
$sUrl = \MailSo\Base\Http::SingletonInstance()->GetUrl();
|
||||
if (\str_contains($sUrl, '/index.php/apps/snappymail/')) {
|
||||
$sAppPath = \preg_replace('/\/index\.php\/apps\/snappymail.+$/',
|
||||
'/apps/snappymail/app/', $sUrl);
|
||||
}
|
||||
}
|
||||
$_SERVER['SCRIPT_NAME'] = $sAppPath;
|
||||
$this->addJs('js/attachments.js');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue