4 include_once
'./Services/Xml/classes/class.ilSaxParser.php';
5 require_once
'Modules/Forum/classes/class.ilForumProperties.php';
36 $this->
setXMLContent(
'<?xml version="1.0" encoding="utf-8"?>'.$a_xml_data);
37 $this->aobject =
new ilObjUser(ANONYMOUS_USER_ID);
47 $this->importDirectory = $a_val;
57 return $this->importDirectory;
67 xml_set_object($a_xml_parser, $this);
68 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
69 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
84 $this->entity =
'forum';
85 $this->forumArray = array();
89 $this->entity =
'thread';
90 $this->threadArray = array();
94 $this->entity =
'post';
95 $this->postArray = array();
99 $this->entity =
'content';
100 $this->contentArray = array();
120 $this->cdata = trim($this->cdata);
121 $arrayname = strtolower($this->entity).
'Array';
122 $x = &$this->$arrayname;
127 $query_num_posts =
"SELECT COUNT(pos_pk) cnt
129 WHERE pos_top_fk = ".$ilDB->quote(
130 $this->lastHandledForumId,
'integer');
132 $res_pos = $ilDB->query($query_num_posts);
133 $data_pos = $ilDB->fetchAssoc($res_pos);
134 $num_posts = $data_pos[
'cnt'];
136 $query_num_threads =
"SELECT COUNT(thr_pk) cnt
138 WHERE thr_top_fk = ".$ilDB->quote(
139 $this->lastHandledForumId,
'integer');
141 $res_thr = $ilDB->query($query_num_threads);
142 $data_thr = $ilDB->fetchAssoc($res_thr);
143 $num_threads = $data_thr[
'cnt'];
145 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
148 SET top_last_post = %s,
151 WHERE top_frm_fk = %s",
152 array(
'text',
'integer',
'integer',
'integer'),
153 array($update_str, $num_posts, $num_threads, $this->forum_obj_id)
158 $x[
'Id'] = $this->cdata;
162 $x[
'ObjId'] = $this->cdata;
166 $x[
'Title'] = $this->cdata;
170 $x[
'Description'] = $this->cdata;
174 $x[
'DefaultView'] = $this->cdata;
178 $x[
'Pseudonyms'] = $this->cdata;
182 $x[
'Statistics'] = $this->cdata;
185 case 'PostingActivation':
186 $x[
'PostingActivation'] = $this->cdata;
189 case 'PresetSubject':
190 $x[
'PresetSubject'] = $this->cdata;
194 $x[
'PresetRe'] = $this->cdata;
197 case 'NotificationType':
198 $x[
'NotificationType'] = $this->cdata;
201 case 'ForceNotification':
202 $x[
'ForceNotification'] = $this->cdata;
205 case 'ToggleNotification':
206 $x[
'ToggleNotification'] = $this->cdata;
210 $x[
'LastPost'] = $this->cdata;
214 $x[
'Moderator'] = $this->cdata;
218 $x[
'CreateDate'] = $this->cdata;
222 $x[
'UpdateDate'] = $this->cdata;
226 $x[
'UpdateUserId'] = $this->cdata;
230 $x[
'UserId'] = $this->cdata;
231 if( $this->entity ==
'forum' && $this->forumArray )
236 $this->forum->createSettings();
239 $this->forumArray[
'UserId'],
''
242 $oldUsrId = $ilUser->getId();
244 $ilUser->setId($forum_array[
'usr_id']);
246 $this->forum->saveData( array() );
248 $ilUser->setId($oldUsrId);
251 $this->forumArray[
'UpdateUserId'],
''
256 $_SESSION[
"AccountId"] = $update_forum_array[
'usr_id'];
257 $this->forum->setTitle($this->forumArray[
"Title"]);
258 $this->forum->setDescription($this->forumArray[
"Description"]);
259 $this->forum->update();
265 $this->forum->getId() );
266 $newObjProp->setDefaultView(
267 (
int) $this->forumArray[
'DefaultView'] );
268 $newObjProp->setAnonymisation(
269 (
int) $this->forumArray[
'Pseudonyms'] );
270 $newObjProp->setStatisticsStatus(
271 (
int) $this->forumArray[
'Statistics'] );
272 $newObjProp->setPostActivation(
273 (
int) $this->forumArray[
'PostingActivation'] );
274 $newObjProp->setPresetSubject(
275 (
int) $this->forumArray[
'PresetSubject'] );
276 $newObjProp->setAddReSubject(
277 (
int) $this->forumArray[
'PresetRe'] );
278 $newObjProp->setNotificationType(
279 $this->forumArray[
'NotificationType'] ?
280 $this->forumArray[
'NotificationType'] :
'all_users');
281 $newObjProp->setAdminForceNoti(
282 (
int) $this->forumArray[
'ForceNotification'] );
283 $newObjProp->setUserToggleNoti(
284 (
int) $this->forumArray[
'ToggleNotification'] );
285 $newObjProp->insert();
288 $this->forum_obj_id = $newObjProp->getObjId();
289 $this->mapping[
'frm'][$this->forumArray[
'Id']] = $id;
290 $this->lastHandledForumId = $id;
292 unset($this->forumArray);
298 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
301 SET thr_last_post = %s
303 array(
'text',
'integer'),
304 array($update_str, $this->lastHandledThreadId)
309 $x[
'Subject'] = $this->cdata;
313 $x[
'Alias'] = $this->cdata;
317 $x[
'Sticky'] = $this->cdata;
321 $x[
'Closed'] = $this->cdata;
323 if($this->entity ==
'thread' && $this->threadArray)
325 require_once
'Modules/Forum/classes/class.ilForumTopic.php';
328 $this->forumThread->setId($this->threadArray[
'Id']);
329 $this->forumThread->setForumId( $this->lastHandledForumId );
330 $this->forumThread->setSubject($this->threadArray[
'Subject']);
331 $this->forumThread->setSticky($this->threadArray[
'Sticky']);
332 $this->forumThread->setClosed($this->threadArray[
'Closed']);
333 $this->forumThread->setCreateDate($this->threadArray[
'CreateDate']);
334 $this->forumThread->setChangeDate($this->threadArray[
'UpdateDate']);
335 $this->forumThread->setImportName($this->threadArray[
'ImportName']);
338 $this->threadArray[
'UserId'], $this->threadArray[
'Alias']
341 $this->forumThread->setUserId($usr_data[
'usr_id']);
342 $this->forumThread->setUserAlias($usr_data[
'usr_alias']);
344 $this->forumThread->insert();
346 $this->mapping[
'thr'][$this->threadArray[
'Id']] = $this->forumThread->getId();
347 $this->lastHandledThreadId = $this->forumThread->getId();
349 unset($this->threadArray);
358 $x[
'Censorship'] = $this->cdata;
361 case 'CensorshipMessage':
362 $x[
'CensorshipMessage'] = $this->cdata;
366 $x[
'Notification'] = $this->cdata;
370 $x[
'ImportName'] = $this->cdata;
374 $x[
'Status'] = $this->cdata;
378 $x[
'Message'] = $this->cdata;
382 $x[
'Lft'] = $this->cdata;
386 $x[
'Rgt'] = $this->cdata;
390 $x[
'Depth'] = $this->cdata;
394 $x[
'ParentId'] = $this->cdata;
396 if($this->entity ==
'post' && $this->postArray)
398 require_once
'Modules/Forum/classes/class.ilForumPost.php';
401 $this->forumPost->setId($this->postArray[
'Id']);
402 $this->forumPost->setCensorship($this->postArray[
'Censorship']);
403 $this->forumPost->setCensorshipComment($this->postArray[
'CensorshipMessage']);
404 $this->forumPost->setNotification($this->postArray[
'Notification']);
405 $this->forumPost->setImportName($this->postArray[
'ImportName']);
406 $this->forumPost->setStatus($this->postArray[
'Status']);
407 $this->forumPost->setMessage($this->postArray[
'Message']);
408 $this->forumPost->setSubject($this->postArray[
'Subject']);
409 $this->forumPost->setLft($this->postArray[
'Lft']);
410 $this->forumPost->setRgt($this->postArray[
'Rgt']);
411 $this->forumPost->setDepth($this->postArray[
'Depth']);
412 $this->forumPost->setParentId($this->postArray[
'ParentId']);
413 $this->forumPost->setThread($this->forumThread);
414 $this->forumPost->setThreadId($this->lastHandledThreadId);
415 $this->forumPost->setForumId($this->lastHandledForumId);
416 $this->forumPost->setCreateDate($this->postArray[
'CreateDate']);
417 $this->forumPost->setChangeDate($this->postArray[
'UpdateDate']);
420 $this->postArray[
'UserId'], $this->postArray[
'Alias']
423 $this->postArray[
'UpdateUserId']
426 $this->forumPost->setUserId($usr_data[
'usr_id']);
427 $this->forumPost->setUserAlias($usr_data[
'usr_alias']);
428 $this->forumPost->setUpdateUserId($update_usr_data[
'usr_id']);
430 $this->forumPost->insert();
432 if($this->mapping[
'pos'][$this->postArray[
'ParentId']])
434 $parentId = $this->mapping[
'pos'][$this->postArray[
'ParentId']];
441 $postTreeNodeId = $ilDB->nextId(
'frm_posts_tree');
442 $ilDB->insert(
'frm_posts_tree', array(
443 'fpt_pk' => array(
'integer', $postTreeNodeId),
444 'thr_fk' => array(
'integer', $this->lastHandledThreadId),
445 'pos_fk' => array(
'integer', $this->forumPost->getId()),
446 'parent_pos' => array(
'integer', $parentId),
447 'lft' => array(
'integer', $this->postArray[
'Lft']),
448 'rgt' => array(
'integer', $this->postArray[
'Rgt']),
449 'depth' => array(
'integer', $this->postArray[
'Depth']),
450 'fpt_date' => array(
'timestamp', date(
'Y-m-d H:i:s'))
453 $this->mapping[
'pos'][$this->postArray[
'Id']] = $this->forumPost->getId();
454 $this->lastHandledPostId = $this->forumPost->getId();
456 unset($this->postArray);
462 $x[
'content'] = $this->cdata;
470 $filedata =
new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
472 $importPath = $this->contentArray[
'content'];
474 if( strlen($importPath) )
478 $newFilename = preg_replace(
"/^\d+_\d+(_.*)/ims", $this->forum->getId().
"_".$this->lastHandledPostId.
"$1", basename($importPath));
479 $path = $filedata->getForumPath();
480 $newPath = $path.
'/'.$newFilename;
481 @copy($importPath, $newPath);
508 $select =
'SELECT od.obj_id, ud.login
510 INNER JOIN usr_data ud
511 ON od.obj_id = ud.usr_id';
513 if($param ==
'import')
515 $where =
' WHERE od.import_id = '.$ilDB->quote(
516 'il_'.$this->import_install_id.
'_usr_'.$imp_usr_id,
'text'
522 $where =
' WHERE ud.usr_id = '.$ilDB->quote(
523 $imp_usr_id,
'integer'
527 $query = $ilDB->query($select.$where);
537 'usr_id' =>
$res[
'obj_id'],
538 'usr_alias' =>
$res[
'login']
550 'usr_id' => $this->aobject->getId(),
551 'usr_alias' => $this->aobject->getLogin()
560 if( (
int)$imp_usr_id > 0 )
564 if( $this->import_install_id != IL_INST_ID && IL_INST_ID > 0 )
567 if( $this->user_id_mapping[$imp_usr_id] )
569 return $this->user_id_mapping[$imp_usr_id];
577 $this->user_id_mapping[$imp_usr_id] =
$res;
584 $this->user_id_mapping[$imp_usr_id] = $return_value;
586 return $return_value;
590 else if( $this->import_install_id == IL_INST_ID && IL_INST_ID == 0 )
593 if( $this->user_id_mapping[$imp_usr_id] )
595 return $this->user_id_mapping[$imp_usr_id];
603 $this->user_id_mapping[$imp_usr_id] =
$res;
610 if( $this->user_id_mapping[$imp_usr_id] )
612 return $this->user_id_mapping[$imp_usr_id];
620 $this->user_id_mapping[$imp_usr_id] =
$res;
627 $this->user_id_mapping[$imp_usr_id] = $return_value;
629 return $return_value;
638 if( $this->user_id_mapping[$imp_usr_id] )
640 return $this->user_id_mapping[$imp_usr_id];
648 $this->user_id_mapping[$imp_usr_id] =
$res;
655 $this->user_id_mapping[$imp_usr_id] = $return_value;
657 return $return_value;
665 'usr_id' => $imp_usr_id,
666 'usr_alias' => $imp_usr_alias
673 $this->import_install_id = $id;
680 $query =
"SELECT top_pk FROM frm_data
681 WHERE top_frm_fk = ".$ilDB->quote(
682 $this->forum->getId(),
'integer');
686 return $data[
'top_pk'];
700 $a_data = preg_replace(
"/\t+/",
" ",$a_data);
702 $this->cdata .= $a_data;
715 return $this->result > 0;