public function avatarAction() { $profilMapper = new UserMapper(); $profil = $profilMapper->getUserById($this->getUser()->getId()); $avatarAllowedFiletypes = $this->getConfig()->get('avatar_filetypes'); $avatarHeight = $this->getConfig()->get('avatar_height'); $avatarWidth = $this->getConfig()->get('avatar_width'); $avatarSize = $this->getConfig()->get('avatar_size'); $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuPanel'), array('controller' => 'panel', 'action' => 'index'))->add($this->getTranslator()->trans('menuSettings'), array('controller' => 'panel', 'action' => 'settings'))->add($this->getTranslator()->trans('menuAvatar'), array('controller' => 'panel', 'action' => 'avatar')); if ($this->getRequest()->isPost() && !empty($_FILES['avatar']['name'])) { $path = $this->getConfig()->get('avatar_uploadpath'); $file = $_FILES['avatar']['name']; $file_tmpe = $_FILES['avatar']['tmp_name']; $endung = strtolower(pathinfo($file, PATHINFO_EXTENSION)); $file_size = $_FILES['avatar']['size']; if (in_array($endung, explode(' ', $avatarAllowedFiletypes))) { $size = getimagesize($file_tmpe); $width = $size[0]; $height = $size[1]; if ($file_size <= $avatarSize and $width == $avatarWidth and $height == $avatarHeight) { $avatar = $path . $this->getUser()->getId() . '.' . $endung; if ($profil->getAvatar() != '') { $settingMapper = new SettingMapper(); $settingMapper->delAvatarById($this->getUser()->getId()); } $model = new \Modules\User\Models\User(); $model->setId($this->getUser()->getId()); $model->setAvatar($avatar); $profilMapper->save($model); if (move_uploaded_file($file_tmpe, $avatar)) { $this->addMessage('successAvatar'); } } else { $this->addMessage('failedFilesize', 'warning'); } } else { $this->addMessage('failedFiletypes', 'warning'); } $this->redirect(array('action' => 'avatar')); } elseif ($this->getRequest()->isPost() && $this->getRequest()->getPost('avatar_delete') != '') { $settingMapper = new SettingMapper(); $settingMapper->delAvatarById($this->getUser()->getId()); $this->addMessage('avatarSuccessDelete'); $this->redirect(array('action' => 'avatar')); } $this->getView()->set('profil', $profil); $this->getView()->set('avatar_height', $avatarHeight); $this->getView()->set('avatar_width', $avatarWidth); $this->getView()->set('avatar_size', $avatarSize); $this->getView()->set('avatar_filetypes', $avatarAllowedFiletypes); }