XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AvatarUploadForm.class.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7require_once XOOPS_ROOT_PATH . '/core/XCube_ActionForm.class.php';
8require_once XOOPS_MODULE_PATH . '/legacy/class/Legacy_Validator.class.php';
9
11{
12 public $mOldFileName = null;
13 public $_mIsNew = null;
14 public $mFormFile = null;
15 public $_allowExtensions = ['tar', 'tar.gz', 'tgz', 'gz', 'zip'];
16
17 public function getTokenName()
18 {
19 return 'module.user.AvatarUploadForm.TOKEN';
20 }
21
22 public function prepare()
23 {
24 //
25 // Set form properties
26 //
27 $this->mFormProperties['upload'] =new XCube_FileProperty('upload');
28
29 //
30 // Set field properties
31 //
32 $this->mFieldProperties['upload'] =new XCube_FieldProperty($this);
33 $this->mFieldProperties['upload']->setDependsByArray(['required']);
34 $this->mFieldProperties['upload']->addMessage('required', _AD_USER_ERROR_REQUIRED, _AD_USER_LANG_AVATAR_UPLOAD_FILE);
35 }
36
37 public function validateUpload()
38 {
39 $formFile = $this->get('upload');
40 if (null != $formFile) {
41 $flag = false;
42 foreach ($this->_allowExtensions as $ext) {
43 $flag |= preg_match('/' . str_replace('.', "\.", $ext) . '$/', $formFile->getFileName());
44 }
45
46 if (!$flag) {
47 $this->addErrorMessage(_AD_USER_ERROR_EXTENSION_IS_WRONG);
48 }
49 }
50 }
51}
getTokenName()
Gets the token name of this actionform's token.
prepare()
[Abstract] Set up form properties and field properties.
addErrorMessage( $message)
Adds a message to the form's error message buffer.
[Abstract] Used for validating member property values of XCube_ActionForm.
Represents the special property which handles uploaded file.