1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/rainloop_ynh.git synced 2024-09-03 20:16:18 +02:00

ynl-ldap-addressbooks modification:

- report secondary mail.
- reformat sources.
This commit is contained in:
Djip007 2015-10-24 01:53:08 +02:00
parent f564778115
commit 9dd2b7329e
2 changed files with 60 additions and 39 deletions

View file

@ -2,14 +2,17 @@
class YnhLdapAddressbooks implements \RainLoop\Providers\Suggestions\ISuggestions { class YnhLdapAddressbooks implements \RainLoop\Providers\Suggestions\ISuggestions {
/** /**
*
* @var \MailSo\Log\Logger * @var \MailSo\Log\Logger
*/ */
private $oLogger = null; private $oLogger = null;
/** /**
*
* @param \RainLoop\Model\Account $oAccount * @param \RainLoop\Model\Account $oAccount
* @param string $sQuery * @param string $sQuery
* @param int $iLimit = 20 * @param int $iLimit
* = 20
* *
* @return array * @return array
*/ */
@ -70,7 +73,10 @@ class YnhLdapAddressbooks implements \RainLoop\Providers\Suggestions\ISuggestion
$sFilter .= '(displayName=*' . $sSearchEscaped . '*)'; $sFilter .= '(displayName=*' . $sSearchEscaped . '*)';
$sFilter .= '))'; $sFilter .= '))';
$aItems = array ( 'mail', 'displayName'); $aItems = array (
'mail',
'displayName'
);
$this->oLogger->Write ( 'YnhLdapAddressbooks: ldap_search : ' . $sSearchDn . ' / ' . $sFilter, \MailSo\Log\Enumerations\Type::INFO, 'LDAP' ); $this->oLogger->Write ( 'YnhLdapAddressbooks: ldap_search : ' . $sSearchDn . ' / ' . $sFilter, \MailSo\Log\Enumerations\Type::INFO, 'LDAP' );
@ -78,16 +84,24 @@ class YnhLdapAddressbooks implements \RainLoop\Providers\Suggestions\ISuggestion
if ($oS) { if ($oS) {
$aEntries = @\ldap_get_entries ( $oCon, $oS ); $aEntries = @\ldap_get_entries ( $oCon, $oS );
$this->oLogger->Write ( 'YnhLdapAddressbooks: ldap_search => ' . var_export ( $aEntries ), \MailSo\Log\Enumerations\Type::INFO, 'LDAP' ); $this->oLogger->Write ( 'YnhLdapAddressbooks: ldap_search => ' . var_export ( $aEntries ), \MailSo\Log\Enumerations\Type::INFO, 'LDAP' );
if (is_array ( $aEntries )) { if (is_array ( $aEntries )) {
if (isset ( $aEntries ['count'] )) { unset ( $aEntries ['count'] ); } if (isset ( $aEntries ['count'] )) {
unset ( $aEntries ['count'] );
}
foreach ( $aEntries as $aItem ) { foreach ( $aEntries as $aItem ) {
if ($aItem) {
$sEmail = \trim($aItem['mail'] [0] );
$sName = \trim ( $aItem ['displayname'] [0] ); $sName = \trim ( $aItem ['displayname'] [0] );
if (isset ( $aItem ['mail'] ['count'] )) {
unset ( $aItem ['mail'] ['count'] );
}
foreach ( $aItem ['mail'] as $sEmail ) {
$sEmail = \trim ( $sEmail );
if (! empty ( $sEmail )) { if (! empty ( $sEmail )) {
$aResult[] = array($sEmail, $sName); $aResult [] = array (
$sEmail,
$sName
);
} }
} }
} }
@ -109,7 +123,13 @@ class YnhLdapAddressbooks implements \RainLoop\Providers\Suggestions\ISuggestion
*/ */
private function escape($sStr) { private function escape($sStr) {
$aNewChars = array (); $aNewChars = array ();
$aChars = array ('\\', '*',' (', ')', \chr(0)); $aChars = array (
'\\',
'*',
' (',
')',
\chr ( 0 )
);
foreach ( $aChars as $iIndex => $sValue ) { foreach ( $aChars as $iIndex => $sValue ) {
$aNewChars [$iIndex] = '\\' . \str_pad ( \dechex ( \ord ( $sValue ) ), 2, '0' ); $aNewChars [$iIndex] = '\\' . \str_pad ( \dechex ( \ord ( $sValue ) ), 2, '0' );
@ -146,5 +166,5 @@ class YnhLdapAddressbooks implements \RainLoop\Providers\Suggestions\ISuggestion
public function SetLogger($oLogger) { public function SetLogger($oLogger) {
$this->oLogger = $oLogger instanceof \MailSo\Log\Logger ? $oLogger : null; $this->oLogger = $oLogger instanceof \MailSo\Log\Logger ? $oLogger : null;
} }
} }
?>

View file

@ -1,12 +1,12 @@
<?php <?php
class YnhLdapAddressbooksPlugin extends \RainLoop\Plugins\AbstractPlugin { class YnhLdapAddressbooksPlugin extends \RainLoop\Plugins\AbstractPlugin {
public function Init() { public function Init() {
$this->addHook ( 'main.fabrica', 'MainFabrica' ); $this->addHook ( 'main.fabrica', 'MainFabrica' );
} }
/** /**
* test if ldap is supported (but with ynh it nead ;) ) * test if ldap is supported (but with ynh it nead ;) )
*
* @return string * @return string
*/ */
public function Supported() { public function Supported() {
@ -17,6 +17,7 @@ class YnhLdapAddressbooksPlugin extends \RainLoop\Plugins\AbstractPlugin {
} }
/** /**
*
* @param string $sName * @param string $sName
* @param mixed $mResult * @param mixed $mResult
*/ */
@ -32,5 +33,5 @@ class YnhLdapAddressbooksPlugin extends \RainLoop\Plugins\AbstractPlugin {
$mResult [] = $oProvider; $mResult [] = $oProvider;
} }
} }
} }
?>