XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
newAction.class.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16
17require _MY_MODULE_PATH.'forms/MessageForm.class.php';
18
20{
21 private \MessageForm $mActionForm;
22 private $mService;
23
24 public function __construct()
25 {
26 parent::__construct();
27 $this->mActionForm = new MessageForm();
28 $this->mActionForm->prepare();
29 }
30
31 public function execute()
32 {
33 if (!$this->chk_use()) {
34 $this->setUrl('index.php?action=settings');
35 $this->setErr(_MD_MESSAGE_SETTINGS_MSG5);
36 } else {
37 $inboxid = (int)$this->root->mContext->mRequest->getRequest('res');
38 $to_userid = (int)$this->root->mContext->mRequest->getRequest('to_userid');
39
40 if ('POST' === $_SERVER['REQUEST_METHOD']) {
41 $this->mActionForm->fetch();
42 $this->mActionForm->validate();
43 if ($this->mActionForm->hasError()) {
44 $this->errMsg = $this->mActionForm->getErrorMessages();
45 } elseif (!$this->chk_use($this->mActionForm->fuid) || !$this->chk_deny($this->mActionForm->fuid)) {
46 $this->errMsg = _MD_MESSAGE_SETTINGS_MSG6;
47 } elseif ('' !== $this->mActionForm->get('Legacy_Event_User_Submit')) {
48 $this->isError = true;
49 $modHand = xoops_getmodulehandler('inbox', _MY_DIRNAME);
50 $modObj = $modHand->create();
51 $this->mActionForm->update($modObj);
52 if (!$modHand->insert($modObj)) {
53 $this->errMsg = _MD_MESSAGE_ACTIONMSG5;
54 } else {
55 $this->usemail();
56 $modHand->deleteDays($this->root->mContext->mModuleConfig['savedays'], $this->root->mContext->mModuleConfig['dletype']);
57 if (!$this->update_outbox($modObj)) {
58 $this->errMsg = _MD_MESSAGE_ACTIONMSG6;
59 } else {
60 $this->errMsg = _MD_MESSAGE_ACTIONMSG7;
61 }
62 }
63 }
64 } elseif ($inboxid > 0) {
65 $modHand = xoops_getmodulehandler('inbox', _MY_DIRNAME);
66 $modObj = $modHand->get($inboxid);
67 if (is_object($modObj) && $modObj->get('from_uid') > 0 && $modObj->get('uid') == $this->root->mContext->mXoopsUser->get('uid') && !$this->mActionForm->setRes($modObj)) {
68 $this->errMsg = _MD_MESSAGE_ACTIONMSG9;
69 }
70 } elseif ($to_userid > 0) {
71 $userhand = xoops_gethandler('user');
72 $user = $userhand->get($to_userid);
73 $this->mActionForm->setUser($user);
74 }
75 // service UserSearch
76 $this->mService = $this->root->mServiceManager->getService('UserSearch');
77 }
78 }
79
80 private function chk_deny($uid)
81 {
82 $fromid = $this->root->mContext->mXoopsUser->get('uid');
83 $modObj = $this->getSettings($uid);
84 $blacklist = $modObj->get('blacklist');
85 if ('' === $blacklist) {
86 return true;
87 }
88
89 if (strpos($blacklist, ',') !== false) {
90 $lists = explode(',', $blacklist);
91 if (!in_array($fromid, $lists, true)) {
92 return true;
93 }
94 } elseif ($blacklist !== $fromid) {
95 return true;
96 }
97 return false;
98 }
99
100 private function usemail()
101 {
102 $setting = $this->getSettings($this->mActionForm->fuid);
103 if (1 == $setting->get('tomail')) {
104 $userhand = xoops_gethandler('user');
105 $user = $userhand->get($this->mActionForm->fuid);
106
107 $mailer = $this->getMailer();
108 $mailer->setFromName($this->root->mContext->mXoopsConfig['sitename']);
109 $mailer->setFromEmail($this->root->mContext->mXoopsConfig['adminmail']);
110 $mailer->setToEmails($user->get('email'));
111 $mailer->setSubject(_MD_MESSAGE_MAILSUBJECT);
112 $mailer->setBody($this->getMailBody($setting->get('viewmsm')));
113 $mailer->send();
114 }
115 }
116
117 private function getMailBody($body = 0)
118 {
119
120
121 $tpl = new Smarty();
122
123 // WONT FIX ! Trying dynamic properties, even checking if the proper method exists
124 // $tpl->_canUpdateFromFile = true;
125 $tpl->compile_check = true;
126 $tpl->template_dir = _MY_MODULE_PATH.'language/'.$this->root->mLanguageManager->mLanguageName.'/';
127 $tpl->cache_dir = XOOPS_CACHE_PATH;
128 $tpl->compile_dir = XOOPS_COMPILE_PATH;
129
130 $tpl->assign('sitename', $this->root->mContext->mXoopsConfig['sitename']);
131 $tpl->assign('uname', $this->root->mContext->mXoopsUser->get('uname'));
132 if (1 == $body) {
133 $tpl->assign('note', $this->mActionForm->get('note'));
134 } else {
135 $tpl->assign('note', XCube_Utils::formatString(_MD_MESSAGE_MAILBODY, XOOPS_URL.'/'));
136 }
137 $tpl->assign('siteurl', XOOPS_URL.'/');
138 return $tpl->fetch(_MY_MODULE_PATH.'language/'.$this->root->mLanguageManager->mLanguageName.'/invitation.tpl');
139 }
140
141 private function update_outbox(&$obj)
142 {
143 $outHand = xoops_getmodulehandler('outbox');
144 $outHand->deleteDays($this->root->mContext->mModuleConfig['savedays']);
145 $outObj = $outHand->create();
146 $outObj->set('uid', $obj->get('from_uid'));
147 $outObj->set('to_uid', $obj->get('uid'));
148 $outObj->set('title', $obj->get('title'));
149 $outObj->set('message', $obj->get('message'));
150 $outObj->set('utime', $obj->get('utime'));
151 return $outHand->insert($outObj);
152 }
153
154 public function executeView(&$render)
155 {
156 $render->setTemplateName('message_new.html');
157 $render->setAttribute('mActionForm', $this->mActionForm);
158 $render->setAttribute('errMsg', $this->errMsg);
159 $render->setAttribute('UserSearch', $this->mService);
160 $render->setAttribute('message_url', XOOPS_URL.'/modules/message/index.php');
161 }
162}
static formatString()
[Static] Formats string with special care for international.