/**
  * @param \RainLoop\Model\Account|string|null $mAccount
  * @param int $iStorageType
  * @param string $sKey
  * @param bool $bMkDir = false
  * @param bool $bForDeleteAction = false
  *
  * @return string
  */
 public function generateFileName($mAccount, $iStorageType, $sKey, $bMkDir = false, $bForDeleteAction = false)
 {
     if (null === $mAccount) {
         $iStorageType = \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY;
     }
     $sEmail = $sSubEmail = '';
     if ($mAccount instanceof \RainLoop\Model\Account) {
         $sEmail = $mAccount->ParentEmailHelper();
         if ($this->bLocal && $mAccount->IsAdditionalAccount() && !$bForDeleteAction) {
             $sSubEmail = $mAccount->Email();
         }
     }
     if (\is_string($mAccount) && empty($sEmail)) {
         $sEmail = $mAccount;
     }
     $sEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', $sEmail);
     $sSubEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', $sSubEmail);
     $sTypePath = $sKeyPath = '';
     switch ($iStorageType) {
         default:
         case \RainLoop\Providers\Storage\Enumerations\StorageType::USER:
         case \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY:
             $sTypePath = 'data';
             $sKeyPath = \md5($sKey);
             $sKeyPath = \substr($sKeyPath, 0, 2) . '/' . $sKeyPath;
             break;
         case \RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG:
             $sTypePath = 'cfg';
             $sKeyPath = \preg_replace('/[_]+/', '_', \preg_replace('/[^a-zA-Z0-9\\/]/', '_', $sKey));
             break;
     }
     $sFilePath = '';
     if (\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY === $iStorageType) {
         $sFilePath = $this->sDataPath . '/' . $sTypePath . '/__nobody__/' . $sKeyPath;
     } else {
         if (!empty($sEmail)) {
             $sFilePath = $this->sDataPath . '/' . $sTypePath . '/' . \str_pad(\rtrim(\substr($sEmail, 0, 2), '@'), 2, '_') . '/' . $sEmail . '/' . (0 < \strlen($sSubEmail) ? $sSubEmail . '/' : '') . ($bForDeleteAction ? '' : $sKeyPath);
         }
     }
     if ($bMkDir && !$bForDeleteAction && !empty($sFilePath) && !@\is_dir(\dirname($sFilePath))) {
         if (!@\mkdir(\dirname($sFilePath), 0755, true)) {
             throw new \RainLoop\Exceptions\Exception('Can\'t make storage directory "' . $sFilePath . '"');
         }
     }
     return $sFilePath;
 }
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param array $aAccounts = array()
  *
  * @return array
  */
 public function SetAccounts($oAccount, $aAccounts = array())
 {
     $sParentEmail = $oAccount->ParentEmailHelper();
     if (!\is_array($aAccounts) || 0 >= \count($aAccounts) || 1 === \count($aAccounts) && !empty($aAccounts[$sParentEmail])) {
         $this->StorageProvider()->Clear($oAccount, \RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG, 'accounts');
     } else {
         $this->StorageProvider()->Put($oAccount, \RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG, 'accounts', @\json_encode($aAccounts));
     }
 }
Esempio n. 3
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sKey
  * @param bool $bMkDir = false
  *
  * @return string
  */
 private function generateFileName($oAccount, $sKey, $bMkDir = false)
 {
     $sEmail = $sSubEmail = '';
     if ($oAccount instanceof \RainLoop\Model\Account) {
         $sEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', $oAccount->ParentEmailHelper());
         if ($oAccount->IsAdditionalAccount()) {
             $sSubEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', $oAccount->Email());
         }
     }
     if (empty($sEmail)) {
         $sEmail = '__unknown__';
     }
     $sKeyPath = \sha1($sKey);
     $sKeyPath = \substr($sKeyPath, 0, 2) . '/' . \substr($sKeyPath, 2, 2) . '/' . $sKeyPath;
     $sFilePath = $this->sDataPath . '/' . \str_pad(\rtrim(\substr($sEmail, 0, 2), '@'), 2, '_') . '/' . $sEmail . '/' . (0 < \strlen($sSubEmail) ? $sSubEmail . '/' : '') . $sKeyPath;
     if ($bMkDir && !empty($sFilePath) && !@\is_dir(\dirname($sFilePath))) {
         if (!@\mkdir(\dirname($sFilePath), 0755, true)) {
             throw new \RainLoop\Exceptions\Exception('Can\'t make storage directory "' . $sFilePath . '"');
         }
     }
     return $sFilePath;
 }