From 6b5fb98a941e4951fe66a9e734a57d93e754df66 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Wed, 27 Nov 2013 22:57:38 +0400 Subject: [PATCH] first pab commit --- .../Providers/PersonalAddressBook.php | 43 +++++++++ .../MySqlPersonalAddressBook.php | 88 +++++++++++++++++++ .../PersonalAddressBookInterface.php | 11 +++ 3 files changed, 142 insertions(+) create mode 100644 rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook.php create mode 100644 rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/MySqlPersonalAddressBook.php create mode 100644 rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/PersonalAddressBookInterface.php diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook.php new file mode 100644 index 000000000..e2edaba86 --- /dev/null +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook.php @@ -0,0 +1,43 @@ +oDriver = null; + if ($oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface) + { + $this->oDriver = $oDriver; + } + } + + /** + * @return bool + */ + public function IsActive() + { + return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface && + $this->oDriver->IsSupported(); + } + + /** + * @return bool + */ + public function IsSupported() + { + return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface && + $this->oDriver->IsSupported(); + } +} \ No newline at end of file diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/MySqlPersonalAddressBook.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/MySqlPersonalAddressBook.php new file mode 100644 index 000000000..3d1811a7f --- /dev/null +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/MySqlPersonalAddressBook.php @@ -0,0 +1,88 @@ +oLogger = $oLogger instanceof \MailSo\Log\Logger ? $oLogger : null; + } + + /** + * @return bool + */ + public function IsSupported() + { + $aDrivers = \class_exists('PDO') ? \PDO::getAvailableDrivers() : array(); + return \is_array($aDrivers) ? \in_array('mysql', $aDrivers) : false; + } + + /** + * @param \RainLoop\Account $oAccount + * @staticvar array $aPdoCache + * @return \PDO + */ + private function getPDO($oAccount) + { + static $aPdoCache = array(); + + $sEmail = $oAccount->ParentEmailHelper(); + if (isset($aPdoCache[$sEmail])) + { + return $aPdoCache[$sEmail]; + } + + if (!\class_exists('PDO')) + { + throw new \Exception('class_exists=PDO'); + } + + $sVersionFile = ''; + $sDsn = ''; + $sDbLogin = ''; + $sDbPassword = ''; + + $oPdo = false; + try + { + $oPdo = new \PDO($sDsn, $sDbLogin, $sDbPassword); + if ($oPdo) + { + $oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + + if (!@\file_exists($sVersionFile) || + (string) @file_get_contents($sVersionFile) !== (string) \RainLoop\Providers\Contacts\Classes\Db::Version()) + { + $this->syncTables($oPdo, $sVersionFile); + } + + $oPdo->sqliteCreateFunction('SIMPLESEARCH', function ($sEmailValue, $sNameValue, $sMask) { + return \preg_match('/'.\preg_quote($sMask, '/').'/ui', + $sEmailValue.' '.$sNameValue) ? 1 : 0; + }); + + } + } + catch (\Exception $oException) + { + throw $oException; + $oPdo = false; + } + + if ($oPdo) + { + $aPdoCache[$oAccount->ParentEmailHelper()] = $oPdo; + } + + return $oPdo; + } +} \ No newline at end of file diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/PersonalAddressBookInterface.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/PersonalAddressBookInterface.php new file mode 100644 index 000000000..9685a33d1 --- /dev/null +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/PersonalAddressBookInterface.php @@ -0,0 +1,11 @@ +