snappymail/plugins/kolab/index.php

95 lines
2.4 KiB
PHP
Raw Normal View History

2022-05-18 23:15:31 +08:00
<?php
class KolabPlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'Kolab',
2022-12-16 16:45:18 +08:00
VERSION = '2.2',
RELEASE = '2022-12-16',
2022-05-19 04:51:32 +08:00
CATEGORY = 'Contacts',
DESCRIPTION = 'Use an Address Book of Kolab.',
2022-12-16 16:45:18 +08:00
REQUIRED = '2.23.0';
2022-05-18 23:15:31 +08:00
public function Init() : void
{
// \RainLoop\Api::Config()->Set('contacts', 'enable', true);
if (\RainLoop\Api::Config()->Get('contacts', 'enable', false)) {
2022-05-19 14:34:09 +08:00
$this->UseLangs(true);
2022-05-18 23:15:31 +08:00
$this->addHook('filter.app-data', 'FilterAppData');
$this->addHook('main.fabrica', 'MainFabrica');
$this->addJs('js/settings.js');
$this->addTemplate('templates/KolabSettings.html');
$this->addJsonHook('KolabFolder', 'DoKolabFolder');
}
}
public function Supported() : string
{
return '';
}
private function Account() : \RainLoop\Model\Account
{
return \RainLoop\Api::Actions()->getAccountFromToken();
}
private function SettingsProvider() : \RainLoop\Providers\Settings
{
return \RainLoop\Api::Actions()->SettingsProvider(true);
}
private function Settings() : \RainLoop\Settings
{
return $this->SettingsProvider()->Load($this->Account());
}
public function DoKolabFolder() : array
{
// \error_log(\print_r($this->Manager()->Actions()->GetActionParams(), 1));
$sValue = $this->jsonParam('contact');
$oSettings = $this->Settings();
if (\is_string($sValue)) {
$oSettings->SetConf('KolabContactFolder', $sValue);
$this->SettingsProvider()->Save($this->Account(), $oSettings);
}
return $this->jsonResponse(__FUNCTION__, true);
}
public function FilterAppData($bAdmin, &$aResult) : void
{
// if ImapClient->IsSupported('METADATA')
2022-05-19 04:29:46 +08:00
if (!$bAdmin && \is_array($aResult) && !empty($aResult['Auth'])) {
2022-05-18 23:15:31 +08:00
$aResult['Capa']['Kolab'] = true;
$aResult['KolabContactFolder'] = (string) $this->Settings()->GetConf('KolabContactFolder', '');
}
}
/**
* @param mixed $mResult
*/
public function MainFabrica(string $sName, &$mResult)
{
/*
if ('suggestions' === $sName) {
if (!\is_array($mResult)) {
$mResult = array();
}
// $sFolder = \trim($this->Config()->Get('plugin', 'mailbox', ''));
// if ($sFolder) {
require_once __DIR__ . '/KolabContactsSuggestions.php';
$mResult[] = new KolabContactsSuggestions();
// }
}
*/
if ('address-book' === $sName) {
2022-05-19 04:51:32 +08:00
$sFolderName = $this->Settings()->GetConf('KolabContactFolder', '');
if ($sFolderName) {
require_once __DIR__ . '/KolabAddressBook.php';
$mResult = new KolabAddressBook($sFolderName);
}
2022-05-18 23:15:31 +08:00
}
}
}