XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
blacklistAction.class.php
1<?php
5 * @package Message
6 * @version 2.5.0
7 * @author Nuno Luciano aka gigamaster, 2020 XCL23
8 * @author Osamu Utsugi aka Marijuana
9 * @copyright (c) 2005-2025 The XOOPSCube Project, Authors
10 * @license GPL 3.0
11 */
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16
18{
19 private $mActionForm;
20 private array $blackuser = [];
21 private $mService;
22
23 public function execute()
24 {
25 $this->setUrl('index.php?action=blacklist');
26 $modobj = $this->getSettings();
27 $uid = (int)$this->root->mContext->mRequest->getRequest('uid');
28 if (0 !== $uid) { //Add
29 $this->addblklist($modobj, $uid);
30 } else {
31 switch ($this->root->mContext->mRequest->getRequest('cmd')) {
32 case 'add':
33 $modHand = xoops_getmodulehandler('settings', _MY_DIRNAME);
34 $uid = $modHand->getuidTouname($this->root->mContext->mRequest->getRequest('uname'));
35 if ($uid > 0) {
36 $this->addblklist($modobj, $uid);
37 } else {
38 $this->setErr(_MD_MESSAGE_SETTINGS_MSG19);
39 }
40 break;
41 case 'del': //Delete
42 $this->delblklist($modobj);
43 break;
44 default:
45 if ('' !== $modobj->get('blacklist')) {
46 $blusers = explode(',', $modobj->get('blacklist'));
47 foreach ($blusers as $bluid) {
48 $this->blackuser[$bluid] = $this->getLinkUnameFromId($bluid);
49 }
50 }
51 }
52 }
53 // service UserSearch
54 $this->mService = $this->root->mServiceManager->getService('UserSearch');
55 }
56
57 private function delblklist($modobj)
58 {
59 $deluid = $this->root->mContext->mRequest->getRequest('deluid');
60 if (!is_array($deluid) || 0 === count($deluid)) {
61 $this->setErr(_MD_MESSAGE_DELETEMSG2);
62 return;
63 }
64
65 $adduid = false;
66 if (!empty($deluid) && is_array($deluid)) {
67 $modHand = xoops_getmodulehandler('settings', _MY_DIRNAME);
68 $lists = explode(',', $modobj->get('blacklist'));
69 foreach ($lists as $auid) {
70 if (!in_array($auid, $deluid, true) && $modHand->chkUser($auid)) {
71 $adduid[] = $auid;
72 }
73 }
74 if (is_array($adduid)) {
75 $modobj->set('blacklist', implode(',', $adduid));
76 } else {
77 $modobj->set('blacklist', '');
78 }
79 if ($modHand->insert($modobj)) {
80 $this->setErr(_MD_MESSAGE_SETTINGS_MSG16);
81 } else {
82 $this->setErr(_MD_MESSAGE_SETTINGS_MSG17);
83 }
84 }
85 }
86
87 private function addblklist($modobj, $uid)
88 {
89 $modHand = xoops_getmodulehandler('settings', _MY_DIRNAME);
90 $blackuser = $this->getLinkUnameFromId($uid);
91 $lists = explode(',', $modobj->get('blacklist'));
92 if (in_array($uid, $lists, true)) {
93 $this->setErr(XCube_Utils::formatString(_MD_MESSAGE_SETTINGS_MSG14, $blackuser));
94 return;
95 }
96 if ('' === $lists[0]) {
97 $modobj->set('blacklist', $uid);
98 } else {
99 $lists[] = $uid;
100 $modobj->set('blacklist', implode(',', $lists));
101 }
102 if ($modHand->insert($modobj, true)) {
103 $this->setErr(XCube_Utils::formatString(_MD_MESSAGE_SETTINGS_MSG12, $blackuser));
104 } else {
105 $this->setErr(XCube_Utils::formatString(_MD_MESSAGE_SETTINGS_MSG13, $blackuser));
106 }
107 }
108
109 public function executeView(&$render)
110 {
111 $render->setTemplateName('message_blaclist.html');
112 $render->setAttribute('blackuser', $this->blackuser);
113 $render->setAttribute('UserSearch', $this->mService);
114 $render->setAttribute('message_url', XOOPS_URL.'/modules/message/index.php');
115 }
116}
static formatString()
[Static] Formats string with special care for international.