ILIAS  release_8 Revision v8.24
ilChatroomXMLParser Class Reference

Class ilChatroomXMLParser. More...

+ Inheritance diagram for ilChatroomXMLParser:
+ Collaboration diagram for ilChatroomXMLParser:

Public Member Functions

 __construct (ilObjChatroom $chat, string $a_xml_data)
 
 setImportInstallId (?string $id)
 
 getImportInstallId ()
 
 setHandlers ($a_xml_parser)
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag ($a_xml_parser, string $a_name)
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Protected Attributes

ilObjChatroom $chat
 
ilChatroom $room
 
string $cdata = ''
 
bool $in_sub_rooms = false
 
bool $in_messages = false
 
string $import_install_id = null
 
int $exportRoomId = 0
 
int $exportSubRoomId = 0
 
int $owner = 0
 
int $closed = 0
 
int $public = 0
 
int $timestamp = 0
 
string $message = ''
 
string $title = ''
 
array $userIds = []
 
array $subRoomIdMapping = []
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Member Functions

 isSameInstallation ()
 

Additional Inherited Members

- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Detailed Description

Class ilChatroomXMLParser.

Definition at line 24 of file class.ilChatroomXMLParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilChatroomXMLParser::__construct ( ilObjChatroom  $chat,
string  $a_xml_data 
)

Definition at line 45 of file class.ilChatroomXMLParser.php.

46 {
48
49 $this->chat = $chat;
50
51 $room = ilChatroom::byObjectId($this->chat->getId());
52 if ($room !== null) {
53 $this->room = $room;
54 } else {
55 $this->room = new ilChatroom();
56 $this->room->setSetting('object_id', $this->chat->getId());
57 $this->room->save();
58 }
59
60 $this->setXMLContent('<?xml version="1.0" encoding="utf-8"?>' . $a_xml_data);
61 }
Class ilChatroom.
static byObjectId(int $object_id)
setXMLContent(string $a_xml_content)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $chat, $room, ILIAS\GlobalScreen\Provider\__construct(), ilChatroom\byObjectId(), and ilSaxParser\setXMLContent().

+ Here is the call graph for this function:

Member Function Documentation

◆ getImportInstallId()

ilChatroomXMLParser::getImportInstallId ( )

Definition at line 68 of file class.ilChatroomXMLParser.php.

68 : ?string
69 {
71 }

References $import_install_id.

Referenced by isSameInstallation().

+ Here is the caller graph for this function:

◆ handlerBeginTag()

ilChatroomXMLParser::handlerBeginTag (   $a_xml_parser,
string  $a_name,
array  $a_attribs 
)

Definition at line 85 of file class.ilChatroomXMLParser.php.

85 : void
86 {
87 switch ($a_name) {
88 case 'SubRooms':
89 $this->in_sub_rooms = true;
90 break;
91
92 case 'Messages':
93 $this->in_messages = true;
94 break;
95 }
96 }

◆ handlerCharacterData()

ilChatroomXMLParser::handlerCharacterData (   $a_xml_parser,
string  $a_data 
)

Definition at line 250 of file class.ilChatroomXMLParser.php.

250 : void
251 {
252 if ($a_data !== "\n") {
253 $this->cdata .= preg_replace("/\t+/", ' ', $a_data);
254 }
255 }

◆ handlerEndTag()

ilChatroomXMLParser::handlerEndTag (   $a_xml_parser,
string  $a_name 
)

Definition at line 98 of file class.ilChatroomXMLParser.php.

98 : void
99 {
100 $this->cdata = trim($this->cdata);
101
102 switch ($a_name) {
103 case 'Title':
104 if ($this->in_sub_rooms) {
105 $this->title = ilUtil::stripSlashes($this->cdata);
106 } else {
107 $this->chat->setTitle(ilUtil::stripSlashes($this->cdata));
108 }
109 break;
110
111 case 'Description':
112 $this->chat->setDescription(ilUtil::stripSlashes($this->cdata));
113 break;
114
115 case 'OnlineStatus':
116 $this->room->setSetting('online_status', (int) $this->cdata);
117 break;
118
119 case 'AllowAnonymousAccess':
120 $this->room->setSetting('allow_anonymous', (int) $this->cdata);
121 break;
122
123 case 'AllowCustomUsernames':
124 $this->room->setSetting('allow_custom_usernames', (int) $this->cdata);
125 break;
126
127 case 'EnableHistory':
128 $this->room->setSetting('enable_history', (int) $this->cdata);
129 break;
130
131 case 'RestrictHistory':
132 $this->room->setSetting('restrict_history', (int) $this->cdata);
133 break;
134
135 case 'PrivateRoomsEnabled':
136 $this->room->setSetting('private_rooms_enabled', (int) $this->cdata);
137 break;
138
139 case 'DisplayPastMessages':
140 $this->room->setSetting('display_past_msgs', (int) $this->cdata);
141 break;
142
143 case 'AutoGeneratedUsernameSchema':
144 $this->room->setSetting('autogen_usernames', ilUtil::stripSlashes($this->cdata));
145 break;
146
147 case 'RoomId':
148 $this->exportRoomId = (int) $this->cdata;
149 break;
150
151 case 'SubRoomId':
152 $this->exportSubRoomId = (int) $this->cdata;
153 break;
154
155 case 'Owner':
156 $this->owner = (int) $this->cdata;
157 break;
158
159 case 'Closed':
160 $this->closed = (int) $this->cdata;
161 break;
162
163 case 'Public':
164 $this->public = (int) $this->cdata;
165 break;
166
167 case 'CreatedTimestamp':
168 $this->timestamp = (int) $this->cdata;
169 break;
170
171 case 'PrivilegedUserId':
172 $this->userIds[] = (int) $this->cdata;
173 break;
174
175 case 'SubRoom':
176 if ($this->exportRoomId > 0 && $this->isSameInstallation()) {
177 $user = new ilObjUser();
178 $user->setId((int) $this->owner);
179
180 $chat_user = new ilChatroomUser($user, $this->room);
181 $subRoomId = $this->room->addPrivateRoom(
182 $this->title,
183 $chat_user,
184 [
185 'public' => (bool) $this->public,
186 'created' => (int) $this->timestamp,
187 'closed' => (bool) $this->closed
188 ]
189 );
190
191 foreach ($this->userIds as $userId) {
192 $this->room->inviteUserToPrivateRoom($userId, $subRoomId);
193 }
194
195 $this->subRoomIdMapping[$this->exportSubRoomId] = $subRoomId;
196 }
197
198 $this->exportSubRoomId = 0;
199 $this->title = '';
200 $this->owner = 0;
201 $this->closed = 0;
202 $this->public = 0;
203 $this->timestamp = 0;
204 $this->userIds = [];
205 break;
206
207 case 'SubRooms':
208 $this->in_sub_rooms = false;
209 break;
210
211 case 'Body':
212 $this->message = $this->cdata;
213 break;
214
215 case 'Message':
216 if ($this->isSameInstallation()) {
217 $message = json_decode($this->message, true, 512, JSON_THROW_ON_ERROR);
218 if (
219 is_array($message) &&
220 (0 === $this->exportSubRoomId || array_key_exists($this->exportSubRoomId, $this->subRoomIdMapping))
221 ) {
222 $message['roomId'] = $this->room->getRoomId();
223 $message['subRoomId'] = $this->exportSubRoomId ? $this->subRoomIdMapping[$this->exportSubRoomId] : 0;
224 $message['sub'] = $message['subRoomId'];
225 $message['timestamp'] = $this->timestamp;
226
227 $this->room->addHistoryEntry($message);
228 }
229 }
230
231 $this->timestamp = 0;
232 $this->exportSubRoomId = 0;
233 break;
234
235 case 'Messages':
236 $this->in_messages = false;
237 break;
238
239 case 'Chatroom':
240 $this->chat->update();
241 // Set imported chats to offline
242 $this->room->setSetting('online_status', 0);
243 $this->room->save();
244 break;
245 }
246
247 $this->cdata = '';
248 }
Class ilChatroomUser.
User class.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")

References $cdata, $exportSubRoomId, $message, $timestamp, ILIAS\Repository\int(), isSameInstallation(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ isSameInstallation()

ilChatroomXMLParser::isSameInstallation ( )
private

Definition at line 73 of file class.ilChatroomXMLParser.php.

73 : bool
74 {
75 return defined('IL_INST_ID') && IL_INST_ID > 0 && $this->getImportInstallId() == IL_INST_ID;
76 }
const IL_INST_ID
Definition: constants.php:40

References getImportInstallId(), and IL_INST_ID.

Referenced by handlerEndTag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilChatroomXMLParser::setHandlers (   $a_xml_parser)
Parameters
XMLParser | resource$a_xml_parser
Returns
void

Reimplemented from ilSaxParser.

Definition at line 78 of file class.ilChatroomXMLParser.php.

78 : void
79 {
80 xml_set_object($a_xml_parser, $this);
81 xml_set_element_handler($a_xml_parser, [$this, 'handlerBeginTag'], [$this, 'handlerEndTag']);
82 xml_set_character_data_handler($a_xml_parser, [$this, 'handlerCharacterData']);
83 }

◆ setImportInstallId()

ilChatroomXMLParser::setImportInstallId ( ?string  $id)

Definition at line 63 of file class.ilChatroomXMLParser.php.

63 : void
64 {
65 $this->import_install_id = $id;
66 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

Field Documentation

◆ $cdata

string ilChatroomXMLParser::$cdata = ''
protected

Definition at line 28 of file class.ilChatroomXMLParser.php.

Referenced by handlerEndTag().

◆ $chat

ilObjChatroom ilChatroomXMLParser::$chat
protected

Definition at line 26 of file class.ilChatroomXMLParser.php.

Referenced by __construct().

◆ $closed

int ilChatroomXMLParser::$closed = 0
protected

Definition at line 35 of file class.ilChatroomXMLParser.php.

◆ $exportRoomId

int ilChatroomXMLParser::$exportRoomId = 0
protected

Definition at line 32 of file class.ilChatroomXMLParser.php.

◆ $exportSubRoomId

int ilChatroomXMLParser::$exportSubRoomId = 0
protected

Definition at line 33 of file class.ilChatroomXMLParser.php.

Referenced by handlerEndTag().

◆ $import_install_id

string ilChatroomXMLParser::$import_install_id = null
protected

Definition at line 31 of file class.ilChatroomXMLParser.php.

Referenced by getImportInstallId().

◆ $in_messages

bool ilChatroomXMLParser::$in_messages = false
protected

Definition at line 30 of file class.ilChatroomXMLParser.php.

◆ $in_sub_rooms

bool ilChatroomXMLParser::$in_sub_rooms = false
protected

Definition at line 29 of file class.ilChatroomXMLParser.php.

◆ $message

string ilChatroomXMLParser::$message = ''
protected

Definition at line 38 of file class.ilChatroomXMLParser.php.

Referenced by handlerEndTag().

◆ $owner

int ilChatroomXMLParser::$owner = 0
protected

Definition at line 34 of file class.ilChatroomXMLParser.php.

◆ $public

int ilChatroomXMLParser::$public = 0
protected

Definition at line 36 of file class.ilChatroomXMLParser.php.

◆ $room

ilChatroom ilChatroomXMLParser::$room
protected

Definition at line 27 of file class.ilChatroomXMLParser.php.

Referenced by __construct().

◆ $subRoomIdMapping

array ilChatroomXMLParser::$subRoomIdMapping = []
protected

Definition at line 43 of file class.ilChatroomXMLParser.php.

◆ $timestamp

int ilChatroomXMLParser::$timestamp = 0
protected

Definition at line 37 of file class.ilChatroomXMLParser.php.

Referenced by handlerEndTag().

◆ $title

string ilChatroomXMLParser::$title = ''
protected

Definition at line 39 of file class.ilChatroomXMLParser.php.

◆ $userIds

array ilChatroomXMLParser::$userIds = []
protected

Definition at line 41 of file class.ilChatroomXMLParser.php.


The documentation for this class was generated from the following file: