-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathYumAvatarController.php
More file actions
64 lines (52 loc) · 1.93 KB
/
Copy pathYumAvatarController.php
File metadata and controls
64 lines (52 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
// This controller handles the upload and the deletion of an Avatar
// image for the user profile.
Yii::import('YumModulesRoot.user.controllers.YumController');
class YumAvatarController extends YumController {
public function actionRemoveAvatar() {
$model = YumUser::model()->findByPk(Yii::app()->user->id);
$model->avatar = '';
$model->save();
$this->redirect(array(
Yum::module('profile')->profileViewRoute));
}
public function actionEnableGravatar() {
$model = YumUser::model()->findByPk(Yii::app()->user->id);
$model->avatar = 'gravatar';
$model->save();
$this->redirect(array(
Yum::module('profile')->profileViewRoute));
}
public function beforeAction($action) {
// Disallow guests
if(Yii::app()->user->isGuest)
$this->redirect(Yum::module()->loginUrl);
return parent::beforeAction($action);
}
public function actionEditAvatar() {
$model = YumUser::model()->findByPk(Yii::app()->user->id);
if(isset($_POST['YumUser'])) {
$model->attributes = $_POST['YumUser'];
$model->setScenario('avatarUpload');
if(Yum::module('avatar')->avatarMaxWidth != 0)
$model->setScenario('avatarSizeCheck');
$model->avatar = CUploadedFile::getInstanceByName('YumUser[avatar]');
if($model->validate()) {
if ($model->avatar instanceof CUploadedFile) {
// Prepend the id of the user to avoid filename conflicts
$filename = Yum::module('avatar')->avatarPath .'/'. $model->id . '_' . $_FILES['YumUser']['name']['avatar'];
$model->avatar->saveAs($filename);
$model->avatar = $filename;
if($model->save()) {
Yum::setFlash(Yum::t('The image was uploaded successfully'));
Yum::log(Yum::t('User {username} uploaded avatar image {filename}', array(
'{username}' => $model->username,
'{filename}' => $model->avatar)));
$this->redirect(array('//profile/profile/view'));
}
}
}
}
$this->render('edit_avatar', array('model' => $model));
}
}