示例#1
0
 public function setUserAvatar($userId, $uploadedFileName, array $editionalParams = array())
 {
     $avatar = $this->findByUserId($userId);
     if (!$avatar) {
         $avatar = new BOL_Avatar();
         $avatar->userId = $userId;
     } else {
         $oldHash = $avatar->hash;
     }
     $avatar->hash = time();
     // destination path
     $avatarPath = $this->getAvatarPath($userId, 1, $avatar->hash);
     $avatarBigPath = $this->getAvatarPath($userId, 2, $avatar->hash);
     $avatarOriginalPath = $this->getAvatarPath($userId, 3, $avatar->hash);
     // pluginfiles tmp path
     $avatarPFPath = $this->getAvatarPluginFilesPath($userId, 1, $avatar->hash);
     $avatarPFBigPath = $this->getAvatarPluginFilesPath($userId, 2, $avatar->hash);
     $avatarPFOriginalPath = $this->getAvatarPluginFilesPath($userId, 3, $avatar->hash);
     if (!is_writable(dirname($avatarPFPath))) {
         return false;
     }
     try {
         $image = new UTIL_Image($uploadedFileName);
         $config = OW::getConfig();
         $configAvatarSize = $config->getValue('base', 'avatar_size');
         $configBigAvatarSize = $config->getValue('base', 'avatar_big_size');
         $image->copyImage($avatarPFOriginalPath)->resizeImage($configBigAvatarSize, $configBigAvatarSize, true)->saveImage($avatarPFBigPath)->resizeImage($configAvatarSize, $configAvatarSize, true)->saveImage($avatarPFPath);
         $this->updateAvatar($avatar);
         $params = array('avatarId' => $avatar->id, 'userId' => $userId, 'trackAction' => isset($editionalParams['trackAction']) ? $editionalParams['trackAction'] : true);
         $event = new OW_Event('base.after_avatar_update', array_merge($editionalParams, $params));
         OW::getEventManager()->trigger($event);
         // remove old images
         if (isset($oldHash)) {
             $oldAvatarPath = $this->getAvatarPath($userId, 1, $oldHash);
             $oldAvatarBigPath = $this->getAvatarPath($userId, 2, $oldHash);
             $oldAvatarOriginalPath = $this->getAvatarPath($userId, 3, $oldHash);
             $this->removeAvatarImage($oldAvatarPath);
             $this->removeAvatarImage($oldAvatarBigPath);
             $this->removeAvatarImage($oldAvatarOriginalPath);
         }
         $storage = OW::getStorage();
         $storage->copyFile($avatarPFOriginalPath, $avatarOriginalPath);
         $storage->copyFile($avatarPFBigPath, $avatarBigPath);
         $storage->copyFile($avatarPFPath, $avatarPath);
         @unlink($avatarPFPath);
         @unlink($avatarPFBigPath);
         @unlink($avatarPFOriginalPath);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
示例#2
0
 public function setUserAvatar($userId, $uploadedFileName)
 {
     $avatar = $this->findByUserId($userId);
     if (!$avatar) {
         $avatar = new BOL_Avatar();
         $avatar->userId = $userId;
     } else {
         $oldHash = $avatar->hash;
     }
     $avatar->hash = time();
     // destination path
     $avatarPath = $this->getAvatarPath($userId, 1, $avatar->hash);
     $avatarBigPath = $this->getAvatarPath($userId, 2, $avatar->hash);
     $avatarOriginalPath = $this->getAvatarPath($userId, 3, $avatar->hash);
     // pluginfiles tmp path
     $avatarPFPath = $this->getAvatarPluginFilesPath($userId, 1, $avatar->hash);
     $avatarPFBigPath = $this->getAvatarPluginFilesPath($userId, 2, $avatar->hash);
     $avatarPFOriginalPath = $this->getAvatarPluginFilesPath($userId, 3, $avatar->hash);
     if (!is_writable(dirname($avatarPFPath))) {
         return false;
     }
     try {
         $image = new UTIL_Image($uploadedFileName);
         $config = OW::getConfig();
         $configAvatarSize = $config->getValue('base', 'avatar_size');
         $configBigAvatarSize = $config->getValue('base', 'avatar_big_size');
         $image->copyImage($avatarPFOriginalPath)->resizeImage($configBigAvatarSize, $configBigAvatarSize, true)->saveImage($avatarPFBigPath)->resizeImage($configAvatarSize, $configAvatarSize, true)->saveImage($avatarPFPath);
         $this->updateAvatar($avatar);
         // remove old images
         if (isset($oldHash)) {
             $oldAvatarPath = $this->getAvatarPath($userId, 1, $oldHash);
             $oldAvatarBigPath = $this->getAvatarPath($userId, 2, $oldHash);
             $oldAvatarOriginalPath = $this->getAvatarPath($userId, 3, $oldHash);
             $this->removeAvatarImage($oldAvatarPath);
             $this->removeAvatarImage($oldAvatarBigPath);
             $this->removeAvatarImage($oldAvatarOriginalPath);
         }
         $storage = OW::getStorage();
         $storage->copyFile($avatarPFOriginalPath, $avatarOriginalPath);
         $storage->copyFile($avatarPFBigPath, $avatarBigPath);
         $storage->copyFile($avatarPFPath, $avatarPath);
         @unlink($avatarPFPath);
         @unlink($avatarPFBigPath);
         @unlink($avatarPFOriginalPath);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }