1: <?php
2: 3: 4: 5:
6:
7: if (!defined('XOOPS_ROOT_PATH')) exit();
8:
9: require_once XOOPS_ROOT_PATH . "/core/XCube_ActionForm.class.php";
10:
11: class User_AvatarEditForm extends XCube_ActionForm
12: {
13: var $mOldAvatarFilename = null;
14: var $mFormFile = null;
15:
16: var $mWidth = 0;
17: var $mHeight = 0;
18:
19: function getTokenName()
20: {
21: return "module.user.AvatarEditForm.TOKEN" . $this->get('uid');
22: }
23:
24: function prepare($width, $height, $maxfilesize)
25: {
26: $this->mWidth = $width;
27: $this->mHeight = $height;
28:
29:
30:
31:
32: $this->mFormProperties['uid'] =new XCube_IntProperty('uid');
33: $this->mFormProperties['uploadavatar'] =new XCube_ImageFileProperty('uploadavatar');
34:
35:
36:
37:
38: $this->mFieldProperties['uploadavatar'] =new XCube_FieldProperty($this);
39: $this->mFieldProperties['uploadavatar']->setDependsByArray(array('extension', 'maxfilesize'));
40: $this->mFieldProperties['uploadavatar']->addMessage('extension', _MD_USER_ERROR_AVATAR_EXTENSION);
41: $this->mFieldProperties['uploadavatar']->addVar('extension', "jpg,gif,png");
42: $this->mFieldProperties['uploadavatar']->addMessage('maxfilesize', _MD_USER_ERROR_AVATAR_MAXFILESIZE);
43: $this->mFieldProperties['uploadavatar']->addVar('maxfilesize', $maxfilesize);
44: }
45:
46: function validateUploadavatar()
47: {
48: if ($this->get('uploadavatar') != null) {
49: 50: 51: 52: 53: 54: 55: 56: 57:
58: }
59: }
60:
61: function load(&$obj)
62: {
63: $this->set('uid', $obj->get('uid'));
64: $this->mOldAvatarFilename = $obj->get('user_avatar');
65: }
66:
67: function update(&$obj)
68: {
69: $obj->set('uid', $this->get('uid'));
70:
71: $this->mFormFile = $this->get('uploadavatar');
72:
73: if ($this->mFormFile != null) {
74: $this->mFormFile->setRandomToBodyName('cavt');
75:
76: $filename = $this->mFormFile->getFileName();
77: $this->mFormFile->setBodyName(substr($filename, 0, 25));
78:
79: $obj->set('user_avatar', $this->mFormFile->getFileName());
80: }
81: }
82:
83: 84: 85:
86: function createAvatar()
87: {
88: $avatar = null;
89: if ($this->mFormFile != null) {
90: $avatarHandler =& xoops_getmodulehandler('avatar', 'user');
91: $avatar =& $avatarHandler->create();
92: $avatar->set('avatar_file', $this->mFormFile->getFileName());
93: $avatar->set('avatar_mimetype', $this->mFormFile->getContentType());
94: $avatar->set('avatar_type', 'C');
95: }
96:
97: return $avatar;
98: }
99: }
100:
101: ?>
102: