/** * @param \RainLoop\Account|string|null $mAccount * @param int $iStorageType * @param string $sKey * @param bool $bMkDir = false * * @return string */ private function generateFileName($mAccount, $iStorageType, $sKey, $bMkDir = false) { if (null === $mAccount) { $iStorageType = \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY; } $sEmail = $mAccount instanceof \RainLoop\Account ? \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', ('' === $mAccount->ParentEmail() ? '' : $mAccount->ParentEmail() . '/') . $mAccount->Email()) : ''; if (\is_string($mAccount) && empty($sEmail)) { $sEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', $mAccount); } $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 . '/' . rtrim(substr($sEmail, 0, 2), '@') . '/' . $sEmail . '/' . $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; }
/** * @param \RainLoop\Account $oAccount * @param string $sKey * @param bool $bMkDir = false * * @return string */ private function generateFileName($oAccount, $sKey, $bMkDir = false) { $sEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', ('' === $oAccount->ParentEmail() ? '' : $oAccount->ParentEmail() . '/') . $oAccount->Email()); $sKeyPath = \sha1($sKey); $sKeyPath = \substr($sKeyPath, 0, 2) . '/' . \substr($sKeyPath, 2, 2) . '/' . $sKeyPath; $sFilePath = $this->sDataPath . '/' . rtrim(substr($sEmail, 0, 2), '@') . '/' . $sEmail . '/' . $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; }