Merge all example plugins

This commit is contained in:
the-djmaze 2022-05-31 10:47:14 +02:00
parent f588c91570
commit eb61563db4
23 changed files with 230 additions and 425 deletions

View file

@ -9,22 +9,21 @@ class ChangeSmtpEhloMessagePlugin extends \RainLoop\Plugins\AbstractPlugin
public function Init() : void
{
$this->addHook('smtp.credentials', 'FilterSmtpCredentials');
$this->addHook('smtp.before-connect', 'FilterSmtpCredentials');
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param array $aSmtpCredentials
*/
public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
public function FilterSmtpCredentials(\RainLoop\Model\Account $oAccount,
\MailSo\Smtp\SmtpClient $oSmtpClient,
array &$aSmtpCredentials)
{
if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials))
{
// Default:
// $aSmtpCredentials['Ehlo'] = \MailSo\Smtp\SmtpClient::EhloHelper();
//
// or write your custom php
$aSmtpCredentials['Ehlo'] = 'localhost';
}
// Default:
// $aSmtpCredentials['Ehlo'] = \MailSo\Smtp\SmtpClient::EhloHelper();
//
// or write your custom php
$aSmtpCredentials['Ehlo'] = 'localhost';
}
}

View file

@ -1,21 +0,0 @@
<?php
class ContactsExampleSuggestions implements \RainLoop\Providers\Suggestions\ISuggestions
{
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sQuery
* @param int $iLimit = 20
*
* @return array
*/
public function Process(RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20): array
{
$aResult = array(
array($oAccount->Email(), ''),
array('email@domain.com', 'name')
);
return $aResult;
}
}

View file

@ -1,20 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,35 +0,0 @@
<?php
class ContactsSuggestionsExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'Custom Contacts Suggestions Example',
CATEGORY = 'General',
DESCRIPTION = 'Custom contacts suggestions example';
public function Init() : void
{
$this->addHook('main.fabrica', 'MainFabrica');
}
/**
* @param string $sName
* @param mixed $mResult
*/
public function MainFabrica($sName, &$mResult)
{
switch ($sName)
{
case 'suggestions':
if (!\is_array($mResult))
{
$mResult = array();
}
include_once __DIR__.'/ContactsExampleSuggestions.php';
$mResult[] = new ContactsExampleSuggestions();
break;
}
}
}

View file

@ -1,34 +0,0 @@
<?php
class CustomAdminSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'Custom Admin Settings',
CATEGORY = 'General',
DESCRIPTION = 'Custom admin settings example';
/**
* @return void
*/
public function Init() : void
{
$this->UseLangs(true); // start use langs folder
$this->addJs('js/CustomAdminSettings.js', true); // add js file
$this->addJsonHook('JsonAdminGetData', 'JsonAdminGetData');
$this->addTemplate('templates/PluginCustomAdminSettingsTab.html', true);
}
/**
* @return array
*/
public function JsonAdminGetData()
{
return $this->jsonResponse(__FUNCTION__, array(
'PHP' => phpversion()
));
}
}

View file

@ -1,44 +0,0 @@
(function () {
if (!window.rl)
{
return;
}
/**
* @constructor
*/
function CustomAdminSettings()
{
this.php = ko.observable('');
this.loading = ko.observable(false);
}
CustomAdminSettings.prototype.onBuild = function () // special function
{
var self = this;
this.loading(true);
rl.pluginRemoteRequest((iError, oData) => {
self.loading(false);
if (!iError) {
self.php(oData.Result.PHP || '');
}
if (rl.Enums.StorageResultType.Abort === iError) {
// show abort
}
}, 'JsonAdminGetData');
};
rl.addSettingsViewModelForAdmin(CustomAdminSettings, 'PluginCustomAdminSettingsTab',
'SETTINGS_CUSTOM_ADMIN_CUSTOM_TAB_PLUGIN/TAB_NAME', 'custom');
}());

View file

@ -1,4 +0,0 @@
[SETTINGS_CUSTOM_ADMIN_CUSTOM_TAB_PLUGIN]
TAB_NAME = "Custom Extension Tab"
LEGEND_CUSTOM = "Custom Extension Tab (Example)"
LABEL_PHP_VERSION = "PHP version"

View file

@ -1,4 +0,0 @@
[SETTINGS_CUSTOM_ADMIN_CUSTOM_TAB_PLUGIN]
TAB_NAME = "Плагин"
LEGEND_CUSTOM = "Плагин (Пример)"
LABEL_PHP_VERSION = "PHP версия"

View file

@ -1,20 +0,0 @@
The MIT License (MIT)
Copyright (c) 2013 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,44 +0,0 @@
<?php
class CustomAuthExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'Custom Auth Example Extension',
VERSION = '2.1',
REQUIRED = '2.5.0',
CATEGORY = 'Login',
DESCRIPTION = 'Custom auth mechanism example';
public function Init() : void
{
$this->addHook('login.credentials', 'FilterLoginCredentials');
}
/**
* @param string $sEmail
* @param string $sLogin
* @param string $sPassword
*
* @throws \RainLoop\Exceptions\ClientException
*/
public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword)
{
// Your custom php logic
// You may change login credentials
if ('demo@snappymail.eu' === $sEmail)
{
$sEmail = 'user@snappymail.eu';
$sLogin = 'user@snappymail.eu';
$sPassword = 'super-puper-password';
}
else
{
// or throw auth exeption
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
// or
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountNotAllowed);
// or
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainNotAllowed);
}
}
}

View file

@ -1,20 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,62 +0,0 @@
<?php
class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'Custom Settings Tab',
CATEGORY = 'General',
DESCRIPTION = 'Example extension for custom settings tabs';
/**
* @return void
*/
public function Init() : void
{
$this->UseLangs(true); // start use langs folder
$this->addJs('js/CustomUserSettings.js'); // add js file
$this->addJsonHook('JsonGetCustomUserData', 'JsonGetCustomUserData');
$this->addJsonHook('JsonSaveCustomUserData', 'JsonSaveCustomUserData');
$this->addTemplate('templates/PluginCustomSettingsTab.html');
}
/**
* @return array
*/
public function JsonGetCustomUserData()
{
$aSettings = $this->getUserSettings();
$sUserFacebook = isset($aSettings['UserFacebook']) ? $aSettings['UserFacebook'] : '';
$sUserSkype = isset($aSettings['UserSkype']) ? $aSettings['UserSkype'] : '';
// or get user's data from your custom storage ( DB / LDAP / ... ).
\sleep(1);
return $this->jsonResponse(__FUNCTION__, array(
'UserFacebook' => $sUserFacebook,
'UserSkype' => $sUserSkype
));
}
/**
* @return array
*/
public function JsonSaveCustomUserData()
{
$sUserFacebook = $this->jsonParam('UserFacebook');
$sUserSkype = $this->jsonParam('UserSkype');
// or put user's data to your custom storage ( DB / LDAP / ... ).
\sleep(1);
return $this->jsonResponse(__FUNCTION__, $this->saveUserSettings(array(
'UserFacebook' => $sUserFacebook,
'UserSkype' => $sUserSkype
)));
}
}

View file

@ -1,81 +0,0 @@
(function () {
if (!window.rl)
{
return;
}
/**
* @constructor
*/
function CustomUserSettings()
{
this.userSkype = ko.observable('');
this.userFacebook = ko.observable('');
this.loading = ko.observable(false);
this.saving = ko.observable(false);
this.savingOrLoading = ko.computed(function () {
return this.loading() || this.saving();
}, this);
}
CustomUserSettings.prototype.customJsonSaveData = function ()
{
var self = this;
if (this.saving())
{
return false;
}
this.saving(true);
rl.pluginRemoteRequest((iError, oData) => {
self.saving(false);
if (!iError)
{
// true
}
else if (rl.Enums.StorageResultType.Abort === iError) {
// show abort
}
else
{
// false
}
}, 'JsonSaveCustomUserData', {
'UserSkype': this.userSkype(),
'UserFacebook': this.userFacebook()
});
};
CustomUserSettings.prototype.onBuild = function () // special function
{
var self = this;
this.loading(true);
rl.pluginRemoteRequest((iError, oData) => {
self.loading(false);
if (!iError)
{
self.userSkype(oData.Result.UserSkype || '');
self.userFacebook(oData.Result.UserFacebook || '');
}
}, 'JsonGetCustomUserData');
};
rl.addSettingsViewModel(CustomUserSettings, 'PluginCustomSettingsTab',
'SETTINGS_CUSTOM_PLUGIN/TAB_NAME', 'custom');
}());

View file

@ -1,6 +0,0 @@
[SETTINGS_CUSTOM_PLUGIN]
TAB_NAME = "Custom Extension"
LEGEND_CUSTOM = "Custom Extension (Example)"
LABEL_SKYPE = "Skype"
LABEL_FACEBOOK = "Facebook"
BUTTON_SAVE = "Save"

View file

@ -1,6 +0,0 @@
[SETTINGS_CUSTOM_PLUGIN]
TAB_NAME = "Плагин"
LEGEND_CUSTOM = "Плагин (Пример)"
LABEL_SKYPE = "Skype"
LABEL_FACEBOOK = "Facebook"
BUTTON_SAVE = "Сохранить"

View file

@ -31,6 +31,22 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
$this->addTemplate(string $sFile, bool $bAdminScope = false);
$this->addTemplateHook(string $sName, string $sPlace, string $sLocalTemplateName, bool $bPrepend = false);
*/
// $this->addHook('login.credentials', 'FilterLoginCredentials');
$this->UseLangs(true); // start use langs folder
// User Settings tab
$this->addJs('js/ExampleUserSettings.js'); // add js file
$this->addJsonHook('JsonGetExampleUserData', 'JsonGetExampleUserData');
$this->addJsonHook('JsonSaveExampleUserData', 'JsonSaveExampleUserData');
$this->addTemplate('templates/ExampleUserSettingsTab.html');
// Admin Settings tab
$this->addJs('js/ExampleAdminSettings.js', true); // add js file
$this->addJsonHook('JsonAdminGetData', 'JsonAdminGetData');
$this->addTemplate('templates/ExampleAdminSettingsTab.html', true);
}
/**
@ -61,6 +77,77 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
}
}
public function JsonAdminGetData()
{
return $this->jsonResponse(__FUNCTION__, array(
'PHP' => \phpversion()
));
}
/**
* @param string $sEmail
* @param string $sLogin
* @param string $sPassword
*
* @throws \RainLoop\Exceptions\ClientException
*/
public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword)
{
// Your custom php logic
// You may change login credentials
if ('demo@snappymail.eu' === $sEmail)
{
$sEmail = 'user@snappymail.eu';
$sLogin = 'user@snappymail.eu';
$sPassword = 'super-duper-password';
}
else
{
// or throw auth exeption
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
// or
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountNotAllowed);
// or
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainNotAllowed);
}
}
/**
* @return array
*/
public function JsonGetExampleUserData()
{
$aSettings = $this->getUserSettings();
$sUserFacebook = isset($aSettings['UserFacebook']) ? $aSettings['UserFacebook'] : '';
$sUserSkype = isset($aSettings['UserSkype']) ? $aSettings['UserSkype'] : '';
// or get user's data from your custom storage ( DB / LDAP / ... ).
\sleep(1);
return $this->jsonResponse(__FUNCTION__, array(
'UserFacebook' => $sUserFacebook,
'UserSkype' => $sUserSkype
));
}
/**
* @return array
*/
public function JsonSaveExampleUserData()
{
$sUserFacebook = $this->jsonParam('UserFacebook');
$sUserSkype = $this->jsonParam('UserSkype');
// or put user's data to your custom storage ( DB / LDAP / ... ).
\sleep(1);
return $this->jsonResponse(__FUNCTION__, $this->saveUserSettings(array(
'UserFacebook' => $sUserFacebook,
'UserSkype' => $sUserSkype
)));
}
/*
public function Config() : \RainLoop\Config\Plugin
public function Description() : string

View file

@ -0,0 +1,37 @@
(rl => { if (rl) {
class ExampleAdminSettings
{
constructor()
{
this.php = ko.observable('');
this.loading = ko.observable(false);
}
onBuild()
{
this.loading(true);
rl.pluginRemoteRequest((iError, oData) => {
this.loading(false);
if (iError) {
console.error({
iError: iError,
oData: oData
});
} else {
this.php(oData.Result.PHP || '');
}
}, 'JsonAdminGetData');
}
}
rl.addSettingsViewModelForAdmin(ExampleAdminSettings, 'ExampleAdminSettingsTab',
'SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN/TAB_NAME', 'Example');
}})(window.rl);

View file

@ -0,0 +1,68 @@
(rl => { if (rl) {
class ExampleUserSettings
{
constructor()
{
this.userSkype = ko.observable('');
this.userFacebook = ko.observable('');
this.loading = ko.observable(false);
this.saving = ko.observable(false);
this.savingOrLoading = ko.computed(() => {
return this.loading() || this.saving();
});
}
exampleJsonSaveData()
{
if (!this.saving()) {
this.saving(true);
rl.pluginRemoteRequest((iError, oData) => {
this.saving(false);
if (iError) {
console.error({
iError: iError,
oData: oData
});
} else {
console.dir({
iError: iError,
oData: oData
});
}
}, 'JsonSaveExampleUserData', {
'UserSkype': this.userSkype(),
'UserFacebook': this.userFacebook()
});
}
}
onBuild()
{
this.loading(true);
rl.pluginRemoteRequest((iError, oData) => {
this.loading(false);
if (!iError) {
self.userSkype(oData.Result.UserSkype || '');
self.userFacebook(oData.Result.UserFacebook || '');
}
}, 'JsonGetExampleUserData');
}
}
rl.addSettingsViewModel(ExampleUserSettings, 'ExampleUserSettingsTab',
'SETTINGS_EXAMPLE_PLUGIN/TAB_NAME', 'Example');
}})(window.rl);

View file

@ -0,0 +1,15 @@
{
"SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN": {
"TAB_NAME": "Example Extension Tab",
"LEGEND_EXAMPLE": "Example Extension Tab (Example)",
"LABEL_PHP_VERSION": "PHP version"
},
"SETTINGS_EXAMPLE_PLUGIN": {
"TAB_NAME": "Example Extension",
"LEGEND_EXAMPLE": "Example Extension (Example)",
"LABEL_PHP_VERSION": "PHP version",
"LABEL_SKYPE": "Skype",
"LABEL_FACEBOOK": "Facebook",
"BUTTON_SAVE": "Save"
}
}

View file

@ -1,13 +1,13 @@
<div>
<div class="form-horizontal">
<div class="legend">
<span class="i18n" data-i18n="SETTINGS_CUSTOM_ADMIN_CUSTOM_TAB_PLUGIN/LEGEND_CUSTOM"></span>
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN/LEGEND_EXAMPLE"></span>
&nbsp;&nbsp;&nbsp;
<i class="icon-spinner animated" style="margin-top: 5px" data-bind="visible: loading"></i>
</div>
<div class="control-group">
<label class="control-label">
<span class="i18n" data-i18n="SETTINGS_CUSTOM_ADMIN_CUSTOM_TAB_PLUGIN/LABEL_PHP_VERSION"></span>
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN/LABEL_PHP_VERSION"></span>
</label>
<div class="controls" style="padding-top: 5px">
<b data-bind="text: php"></b>

View file

@ -1,13 +1,13 @@
<div>
<div class="form-horizontal">
<div class="legend">
<span class="i18n" data-i18n="SETTINGS_CUSTOM_PLUGIN/LEGEND_CUSTOM"></span>
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/LEGEND_EXAMPLE"></span>
&nbsp;&nbsp;&nbsp;
<i class="icon-spinner animated" style="margin-top: 5px" data-bind="visible: loading"></i>
</div>
<div class="control-group">
<label class="control-label">
<span class="i18n" data-i18n="SETTINGS_CUSTOM_PLUGIN/LABEL_SKYPE"></span>
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/LABEL_SKYPE"></span>
</label>
<div class="controls">
<input type="text" data-bind="value: userSkype, enable: !savingOrLoading()" />
@ -15,7 +15,7 @@
</div>
<div class="control-group">
<label class="control-label">
<span class="i18n" data-i18n="SETTINGS_CUSTOM_PLUGIN/LABEL_FACEBOOK"></span>
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/LABEL_FACEBOOK"></span>
</label>
<div class="controls">
<input type="text" data-bind="value: userFacebook, enable: !savingOrLoading()" />
@ -23,10 +23,10 @@
</div>
<div class="control-group">
<div class="controls">
<button class="btn" data-bind="click: customJsonSaveData, enable: !savingOrLoading()">
<button class="btn" data-bind="click: exampleJsonSaveData, enable: !savingOrLoading()">
<i data-bind="css: {'icon-floppy': !saving(), 'icon-spinner animated': saving()}" class="icon-floppy"></i>
&nbsp;&nbsp;
<span class="i18n" data-i18n="SETTINGS_CUSTOM_PLUGIN/BUTTON_SAVE"></span>
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/BUTTON_SAVE"></span>
</button>
</div>
</div>

View file

@ -24,12 +24,7 @@
data-i18n="[placeholder]GLOBAL/PASSWORD">
</div>
<div id="plugin-Login-BottomControlGroup"></div>
<div class="controls">
<button class="btn btn-large btn-block buttonLogin"
data-bind="command: submitCommand"
data-i18n="LOGIN/BUTTON_SIGN_IN"></button>
</div>
<div style="display: flex">
<div class="controls" style="display: flex">
<div class="signMeLabel" data-bind="visible: signMeVisibility, component: {
name: 'CheckboxSimple',
params: {
@ -45,4 +40,9 @@
</a>
</div>
</div>
<div>
<button class="btn btn-large btn-block buttonLogin"
data-bind="command: submitCommand"
data-i18n="LOGIN/BUTTON_SIGN_IN"></button>
</div>
</form>