XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
MessageForm.class.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16
17require_once XOOPS_ROOT_PATH.'/core/XCube_ActionForm.class.php';
18require_once XOOPS_MODULE_PATH.'/legacy/class/Legacy_Validator.class.php';
19
21{
22 public $fuid = 0;
23
24// public function __construct()
25// {
26// parent::__construct();
27// }
28
29 public function getTokenName()
30 {
31 return 'module.message.NewMessage.TOKEN';
32 }
33
34 private function set_Property($key, $classname = 'XCube_StringProperty')
35 {
36 $this->mFormProperties[$key] = new $classname($key);
37 }
38
39 public function prepare()
40 {
41 $this->set_Property('uname');
42 $this->set_Property('title');
43 $this->set_Property('Legacy_Event_User_Preview');
44 $this->set_Property('Legacy_Event_User_Submit');
45 $this->set_Property('note', 'XCube_TextProperty');
46
47 $this->mFieldProperties['uname'] = new XCube_FieldProperty($this);
48 $this->mFieldProperties['uname']->setDependsByArray(['required', 'maxlength']);
49 $this->mFieldProperties['uname']->addMessage('required', _MD_MESSAGE_FORMERROR1);
50 $this->mFieldProperties['uname']->addMessage('maxlength', _MD_MESSAGE_FORMERROR2);
51 $this->mFieldProperties['uname']->addVar('maxlength', '30');
52
53 $this->mFieldProperties['title'] = new XCube_FieldProperty($this);
54 $this->mFieldProperties['title']->setDependsByArray(['required', 'maxlength']);
55 $this->mFieldProperties['title']->addMessage('required', _MD_MESSAGE_FORMERROR3);
56 $this->mFieldProperties['title']->addMessage('maxlength', _MD_MESSAGE_FORMERROR4);
57 $this->mFieldProperties['title']->addVar('maxlength', '100');
58
59 $this->mFieldProperties['note'] = new XCube_FieldProperty($this);
60 $this->mFieldProperties['note']->setDependsByArray(['required']);
61 $this->mFieldProperties['note']->addMessage('required', _MD_MESSAGE_FORMERROR5);
62 }
63
64 public function validateUname()
65 {
66 if ('' !== $this->get('uname')) {
67 $uname = mb_strcut($this->get('uname'), 0, 30);
68 $userhand = xoops_gethandler('user');
69 $criteria = new CriteriaCompo(new Criteria('uname', $uname));
70 $uobj = $userhand->getObjects($criteria);
71 if (isset($uobj) && is_array($uobj) && 1 === count($uobj)) {
72 $this->fuid = $uobj[0]->get('uid');
73 } else {
74 $this->fuid = 0;
75 $this->addErrorMessage(_MD_MESSAGE_FORMERROR6);
76 }
77 $this->set('uname', $uname);
78 }
79 }
80
81 public function getShow($name, $type = 'toShow')
82 {
83 if (isset($this->mFormProperties[$name])) {
84 $root = XCube_Root::getSingleton();
85 $textFilter = $root->getTextFilter();
86 return $textFilter->$type($this->mFormProperties[$name]->getValue(null));
87 }
88 return '';
89 }
90
91 public function update(&$obj)
92 {
93 $root = XCube_Root::getSingleton();
94 $obj->set('uid', $this->fuid);
95 $obj->set('from_uid', $root->mContext->mXoopsUser->get('uid'));
96 $obj->set('title', $this->get('title'));
97 $obj->set('message', $this->get('note'));
98 $obj->set('utime', time());
99 }
100
101 public function setRes($obj)
102 {
103 $title = $obj->get('title', 'n');
104 if (!preg_match('/^Re:/i', $title)) {
105 $title = 'Re: '.$title;
106 }
107
108 $userhand = xoops_gethandler('user');
109 $uobj = $userhand->get($obj->get('from_uid'));
110 if (is_object($uobj)) {
111 $this->set('uname', $uobj->get('uname'));
112 $this->set('title', $title);
113 $this->set('note', '[quote]'.$obj->get('message').'[/quote]');
114 return true;
115 }
116 return false;
117 }
118
119 public function setUser(&$user)
120 {
121 $this->set('uname', $user->get('uname'));
122 }
123}
update(&$obj)
[Abstract] Updates an object with properties values.
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.