XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
TplsetUploadForm.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 // TODO github issue loop bug #200 bug loop with archive zip/tar.gz
16 public $_allowExtensions = ['tar'];
17 //public $_allowExtensions = ['tar', 'tar.gz', 'tgz', 'gz'];
18
19 public function getTokenName()
20 {
21 return 'module.legacyRender.TplsetUploadForm.TOKEN';
22 }
23
24 public function prepare()
25 {
26 //
27 // Set form properties
28 //
29 $this->mFormProperties['upload'] =new XCube_FileProperty('upload');
30 $this->mFormProperties['tplset_name'] =new XCube_StringProperty('tplset_name');
31
32 //
33 // Set field properties
34 //
35 $this->mFieldProperties['upload'] =new XCube_FieldProperty($this);
36 $this->mFieldProperties['upload']->setDependsByArray(['required']);
37 $this->mFieldProperties['upload']->addMessage('required', _AD_LEGACYRENDER_ERROR_REQUIRED, _AD_LEGACYRENDER_LANG_TPLSET_UPLOAD_FILE);
38
39 $this->mFieldProperties['tplset_name'] =new XCube_FieldProperty($this);
40 $this->mFieldProperties['tplset_name']->setDependsByArray(['maxlength']);
41 $this->mFieldProperties['tplset_name']->addMessage('maxlength', _AD_LEGACYRENDER_ERROR_MAXLENGTH, _AD_LEGACYRENDER_LANG_TPLSET_DESC, '50');
42 $this->mFieldProperties['tplset_name']->addVar('maxlength', '50');
43 }
44
45 public function validateUpload()
46 {
47 $formFile = $this->get('upload');
48 if (null != $formFile) {
49 $flag = false;
50 foreach ($this->_allowExtensions as $ext) {
51 $flag |= preg_match('/' . str_replace('.', "\.", $ext) . '$/', $formFile->getFileName());
52 }
53
54 if (!$flag) {
55 $this->addErrorMessage(_AD_LEGACYRENDER_ERROR_EXTENSION_IS_WRONG);
56 }
57 }
58 }
59}
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.
Represents string property.