1: <?php
2:
3: if (!defined('XOOPS_ROOT_PATH')) exit();
4:
5: require_once XOOPS_ROOT_PATH . "/core/XCube_ActionForm.class.php";
6: require_once XOOPS_MODULE_PATH . "/legacy/class/Legacy_Validator.class.php";
7:
8: class User_AvatarUploadForm extends XCube_ActionForm
9: {
10: var $mOldFileName = null;
11: var $_mIsNew = null;
12: var $mFormFile = null;
13: var $_allowExtensions = array('tar', 'tar.gz', 'tgz', 'gz', 'zip');
14:
15: function getTokenName()
16: {
17: return "module.user.AvatarUploadForm.TOKEN";
18: }
19:
20: function prepare()
21: {
22:
23:
24:
25: $this->mFormProperties['upload'] =new XCube_FileProperty('upload');
26:
27:
28:
29:
30: $this->mFieldProperties['upload'] =new XCube_FieldProperty($this);
31: $this->mFieldProperties['upload']->setDependsByArray(array('required'));
32: $this->mFieldProperties['upload']->addMessage('required', _AD_USER_ERROR_REQUIRED, _AD_USER_LANG_AVATAR_UPLOAD_FILE);
33:
34: }
35:
36: function validateUpload()
37: {
38: $formFile = $this->get('upload');
39: if ($formFile != null) {
40: $flag = false;
41: foreach ($this->_allowExtensions as $ext) {
42: $flag |= preg_match("/" . str_replace(".", "\.", $ext) . "$/", $formFile->getFileName());
43: }
44:
45: if (!$flag) {
46: $this->addErrorMessage(_AD_USER_ERROR_EXTENSION_IS_WRONG);
47: }
48: }
49: }
50: }
51:
52: ?>
53: