4 include_once
'./Services/Xml/classes/class.ilSaxParser.php';
5 require_once
'Modules/Forum/classes/class.ilForumProperties.php';
6 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
41 parent::__construct();
43 $this->
setXMLContent(
'<?xml version="1.0" encoding="utf-8"?>'.$a_xml_data);
44 $this->aobject =
new ilObjUser(ANONYMOUS_USER_ID);
54 $this->importDirectory = $a_val;
64 return $this->importDirectory;
91 xml_set_object($a_xml_parser, $this);
92 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
93 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
108 $this->entity =
'forum';
109 $this->forumArray = array();
113 $this->entity =
'thread';
114 $this->threadArray = array();
118 $this->mediaObjects = array();
119 $this->entity =
'post';
120 $this->postArray = array();
124 $this->entity =
'content';
125 $this->contentArray = array();
129 $this->mediaObjects[] = $a_attribs;
144 $this->cdata = trim($this->cdata);
145 $arrayname = strtolower($this->entity).
'Array';
146 $x = &$this->$arrayname;
151 $query_num_posts =
"SELECT COUNT(pos_pk) cnt 153 WHERE pos_top_fk = ".$ilDB->quote(
154 $this->lastHandledForumId,
'integer');
156 $res_pos = $ilDB->query($query_num_posts);
157 $data_pos = $ilDB->fetchAssoc($res_pos);
158 $num_posts = $data_pos[
'cnt'];
160 $query_num_threads =
"SELECT COUNT(thr_pk) cnt 162 WHERE thr_top_fk = ".$ilDB->quote(
163 $this->lastHandledForumId,
'integer');
165 $res_thr = $ilDB->query($query_num_threads);
166 $data_thr = $ilDB->fetchAssoc($res_thr);
167 $num_threads = $data_thr[
'cnt'];
169 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
172 SET top_last_post = %s, 174 top_num_threads = %s, 176 WHERE top_frm_fk = %s",
177 array(
'text',
'integer',
'integer',
'integer',
'integer'),
178 array($update_str, $num_posts, $num_threads, $this->frm_last_mapped_top_usr_id, $this->forum_obj_id)
183 $x[
'Id'] = $this->cdata;
187 $x[
'ObjId'] = $this->cdata;
191 $x[
'Title'] = $this->cdata;
195 $x[
'Description'] = $this->cdata;
199 $x[
'DefaultView'] = $this->cdata;
203 $x[
'Pseudonyms'] = $this->cdata;
207 $x[
'Statistics'] = $this->cdata;
210 case 'ThreadRatings':
211 $x[
'ThreadRatings'] = $this->cdata;
214 case 'PostingActivation':
215 $x[
'PostingActivation'] = $this->cdata;
218 case 'PresetSubject':
219 $x[
'PresetSubject'] = $this->cdata;
223 $x[
'PresetRe'] = $this->cdata;
226 case 'NotificationType':
227 $x[
'NotificationType'] = $this->cdata;
230 case 'ForceNotification':
231 $x[
'ForceNotification'] = $this->cdata;
234 case 'ToggleNotification':
235 $x[
'ToggleNotification'] = $this->cdata;
239 $x[
'LastPost'] = $this->cdata;
243 $x[
'Moderator'] = $this->cdata;
247 $x[
'CreateDate'] = $this->cdata;
251 $x[
'UpdateDate'] = $this->cdata;
255 $x[
'FileUpload'] = $this->cdata;
259 $x[
'UpdateUserId'] = $this->cdata;
263 $x[
'AuthorId'] = $this->cdata;
265 case 'isAuthorModerator':
266 $x[
'isAuthorModerator'] = $this->cdata;
270 $x[
'UserId'] = $this->cdata;
271 if( $this->entity ==
'forum' && $this->forumArray )
276 $this->forum->createSettings();
279 $this->forumArray[
'UserId'],
'' 282 $this->frm_last_mapped_top_usr_id = $forum_array[
'usr_id'];
285 $this->forumArray[
'UpdateUserId'],
'' 290 $_SESSION[
"AccountId"] = $update_forum_array[
'usr_id'];
291 $this->forum->setTitle($this->forumArray[
"Title"]);
292 $this->forum->setDescription($this->forumArray[
"Description"]);
293 $this->forum->update();
299 $newObjProp->setDefaultView((
int)$this->forumArray[
'DefaultView']);
300 $newObjProp->setAnonymisation((
int)$this->forumArray[
'Pseudonyms']);
301 $newObjProp->setStatisticsStatus((
int)$this->forumArray[
'Statistics']);
302 $newObjProp->setIsThreadRatingEnabled((
int)$this->forumArray[
'ThreadRatings']);
303 $newObjProp->setPostActivation((
int)$this->forumArray[
'PostingActivation']);
304 $newObjProp->setPresetSubject((
int)$this->forumArray[
'PresetSubject']);
305 $newObjProp->setAddReSubject((
int)$this->forumArray[
'PresetRe']);
306 $newObjProp->setNotificationType($this->forumArray[
'NotificationType'] ? $this->forumArray[
'NotificationType'] :
'all_users');
307 $newObjProp->setAdminForceNoti((
int)$this->forumArray[
'ForceNotification']);
308 $newObjProp->setUserToggleNoti((
int)$this->forumArray[
'ToggleNotification']);
309 $newObjProp->setFileUploadAllowed((
int)$this->forumArray[
'FileUpload']);
310 $newObjProp->setThreadSorting($this->forumArray[
'Sorting']);
311 $newObjProp->setMarkModeratorPosts($this->forumArray[
'MarkModeratorPosts']);
312 $newObjProp->update();
315 $this->forum_obj_id = $newObjProp->getObjId();
316 $this->mapping[
'frm'][$this->forumArray[
'Id']] = $id;
317 $this->lastHandledForumId = $id;
319 unset($this->forumArray);
325 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
328 SET thr_last_post = %s 330 array(
'text',
'integer'),
331 array($update_str, $this->lastHandledThreadId)
336 $x[
'Subject'] = $this->cdata;
340 $x[
'Alias'] = $this->cdata;
344 $x[
'Sticky'] = $this->cdata;
348 $x[
'Sorting'] = $this->cdata;
351 case 'MarkModeratorPosts':
352 $x[
'MarkModeratorPosts'] = $this->cdata;
356 $x[
'Closed'] = $this->cdata;
358 if($this->entity ==
'thread' && $this->threadArray)
360 require_once
'Modules/Forum/classes/class.ilForumTopic.php';
363 $this->forumThread->setId($this->threadArray[
'Id']);
364 $this->forumThread->setForumId( $this->lastHandledForumId );
365 $this->forumThread->setSubject($this->threadArray[
'Subject']);
366 $this->forumThread->setSticky($this->threadArray[
'Sticky']);
367 $this->forumThread->setClosed($this->threadArray[
'Closed']);
368 $this->forumThread->setCreateDate($this->threadArray[
'CreateDate']);
369 $this->forumThread->setChangeDate($this->threadArray[
'UpdateDate']);
370 $this->forumThread->setImportName($this->threadArray[
'ImportName']);
373 $this->threadArray[
'UserId'], $this->threadArray[
'Alias']
376 $this->forumThread->setDisplayUserId($usr_data[
'usr_id']);
377 $this->forumThread->setUserAlias($usr_data[
'usr_alias']);
381 $this->threadArray[
'AuthorId'] = $this->threadArray[
'UserId'];
385 $this->threadArray[
'AuthorId']
387 $this->forumThread->setThrAuthorId((
int)$author_id_data[
'usr_id']);
389 $this->forumThread->insert();
391 $this->mapping[
'thr'][$this->threadArray[
'Id']] = $this->forumThread->getId();
392 $this->lastHandledThreadId = $this->forumThread->getId();
394 unset($this->threadArray);
403 $x[
'Censorship'] = $this->cdata;
406 case 'CensorshipMessage':
407 $x[
'CensorshipMessage'] = $this->cdata;
411 $x[
'Notification'] = $this->cdata;
415 $x[
'ImportName'] = $this->cdata;
419 $x[
'Status'] = $this->cdata;
423 $x[
'Message'] = $this->cdata;
427 $x[
'Lft'] = $this->cdata;
431 $x[
'Rgt'] = $this->cdata;
435 $x[
'Depth'] = $this->cdata;
439 $x[
'ParentId'] = $this->cdata;
441 if($this->entity ==
'post' && $this->postArray)
443 require_once
'Modules/Forum/classes/class.ilForumPost.php';
446 $this->forumPost->setId($this->postArray[
'Id']);
447 $this->forumPost->setCensorship($this->postArray[
'Censorship']);
448 $this->forumPost->setCensorshipComment($this->postArray[
'CensorshipMessage']);
449 $this->forumPost->setNotification($this->postArray[
'Notification']);
450 $this->forumPost->setImportName($this->postArray[
'ImportName']);
451 $this->forumPost->setStatus($this->postArray[
'Status']);
452 $this->forumPost->setMessage($this->postArray[
'Message']);
453 $this->forumPost->setSubject($this->postArray[
'Subject']);
454 $this->forumPost->setLft($this->postArray[
'Lft']);
455 $this->forumPost->setRgt($this->postArray[
'Rgt']);
456 $this->forumPost->setDepth($this->postArray[
'Depth']);
457 $this->forumPost->setParentId($this->postArray[
'ParentId']);
458 $this->forumPost->setThread($this->forumThread);
459 $this->forumPost->setThreadId($this->lastHandledThreadId);
460 $this->forumPost->setForumId($this->lastHandledForumId);
461 $this->forumPost->setCreateDate($this->postArray[
'CreateDate']);
462 $this->forumPost->setChangeDate($this->postArray[
'UpdateDate']);
465 $this->postArray[
'UserId'], $this->postArray[
'Alias']
468 $this->postArray[
'UpdateUserId']
470 $this->forumPost->setDisplayUserId($usr_data[
'usr_id']);
471 $this->forumPost->setUserAlias($usr_data[
'usr_alias']);
472 $this->forumPost->setUpdateUserId($update_usr_data[
'usr_id']);
476 $this->postArray[
'AuthorId'] = $this->postArray[
'UserId'];
479 $this->postArray[
'AuthorId']
481 $this->forumPost->setPosAuthorId((
int)$author_id_data[
'usr_id']);
483 if($this->postArray[
'isAuthorModerator'] ===
'NULL')
485 $this->forumPost->setIsAuthorModerator(NULL);
489 $this->forumPost->setIsAuthorModerator((
int)$this->postArray[
'isAuthorModerator']);
492 $this->forumPost->insert();
494 if($this->mapping[
'pos'][$this->postArray[
'ParentId']])
496 $parentId = $this->mapping[
'pos'][$this->postArray[
'ParentId']];
503 $postTreeNodeId = $ilDB->nextId(
'frm_posts_tree');
504 $ilDB->insert(
'frm_posts_tree', array(
505 'fpt_pk' => array(
'integer', $postTreeNodeId),
506 'thr_fk' => array(
'integer', $this->lastHandledThreadId),
507 'pos_fk' => array(
'integer', $this->forumPost->getId()),
508 'parent_pos' => array(
'integer', $parentId),
509 'lft' => array(
'integer', $this->postArray[
'Lft']),
510 'rgt' => array(
'integer', $this->postArray[
'Rgt']),
511 'depth' => array(
'integer', $this->postArray[
'Depth']),
512 'fpt_date' => array(
'timestamp', date(
'Y-m-d H:i:s'))
515 $this->mapping[
'pos'][$this->postArray[
'Id']] = $this->forumPost->getId();
516 $this->lastHandledPostId = $this->forumPost->getId();
518 $media_objects_found =
false;
519 foreach($this->mediaObjects as $mob_attr)
522 if(file_exists($importfile))
527 $this->forumPost->setMessage(
530 "src=\"" . $mob_attr[
"label"] .
"\"",
531 "src=\"" . preg_replace(
"/(il)_[\d]+_(mob)_([\d]+)/",
"$1_0_$2_$3", $mob_attr[
"label"]) .
"\"" 533 "src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $mob->getId() .
"\"",
534 $this->forumPost->getMessage()
537 $media_objects_found =
true;
541 if($media_objects_found)
543 $this->forumPost->update();
546 unset($this->postArray);
552 $x[
'content'] = $this->cdata;
556 $filedata =
new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
558 $importPath = $this->contentArray[
'content'];
560 if( strlen($importPath) )
564 $newFilename = preg_replace(
"/^\d+_\d+(_.*)/ims", $this->forum->getId().
"_".$this->lastHandledPostId.
"$1", basename($importPath));
565 $path = $filedata->getForumPath();
566 $newPath = $path.
'/'.$newFilename;
567 @copy($importPath, $newPath);
581 $select =
'SELECT od.obj_id, ud.login 583 INNER JOIN usr_data ud 584 ON od.obj_id = ud.usr_id';
586 if($param ==
'import')
588 $where =
' WHERE od.import_id = '.$ilDB->quote(
589 'il_'.$this->import_install_id.
'_usr_'.$imp_usr_id,
'text' 595 $where =
' WHERE ud.usr_id = '.$ilDB->quote(
596 $imp_usr_id,
'integer' 600 $query = $ilDB->query($select.$where);
610 'usr_id' =>
$res[
'obj_id'],
611 'usr_alias' =>
$res[
'login']
623 'usr_id' => $this->aobject->getId(),
624 'usr_alias' => $this->aobject->getLogin()
633 if( (
int)$imp_usr_id > 0 )
637 if( $this->import_install_id != IL_INST_ID && IL_INST_ID > 0 )
640 if( $this->user_id_mapping[$imp_usr_id] )
642 return $this->user_id_mapping[$imp_usr_id];
650 $this->user_id_mapping[$imp_usr_id] =
$res;
657 $this->user_id_mapping[$imp_usr_id] = $return_value;
659 return $return_value;
663 else if( $this->import_install_id == IL_INST_ID && IL_INST_ID == 0 )
666 if( $this->user_id_mapping[$imp_usr_id] )
668 return $this->user_id_mapping[$imp_usr_id];
676 $this->user_id_mapping[$imp_usr_id] =
$res;
683 if( $this->user_id_mapping[$imp_usr_id] )
685 return $this->user_id_mapping[$imp_usr_id];
693 $this->user_id_mapping[$imp_usr_id] =
$res;
700 $this->user_id_mapping[$imp_usr_id] = $return_value;
702 return $return_value;
711 if( $this->user_id_mapping[$imp_usr_id] )
713 return $this->user_id_mapping[$imp_usr_id];
721 $this->user_id_mapping[$imp_usr_id] =
$res;
728 $this->user_id_mapping[$imp_usr_id] = $return_value;
730 return $return_value;
738 'usr_id' => $imp_usr_id,
739 'usr_alias' => $imp_usr_alias
746 $this->import_install_id = $id;
753 $query =
"SELECT top_pk FROM frm_data 754 WHERE top_frm_fk = ".$ilDB->quote(
755 $this->forum->getId(),
'integer');
759 return $data[
'top_pk'];
773 $a_data = preg_replace(
"/\t+/",
" ",$a_data);
775 $this->cdata .= $a_data;
788 return $this->result > 0;
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
getImportDirectory()
Get import directory.
startParsing()
stores xml data in array
getUserIdAndAlias($imp_usr_id, $imp_usr_alias='')
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
getIdAndAliasArray($imp_usr_id, $param='import')
__construct($forum, $a_xml_data)
Constructor.
static getInstance($a_obj_id=0)
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
setHandlers($a_xml_parser)
set event handlers
start()
starts parsing an changes object by side effect.
This class handles all operations on files for the forum object.
setSchemaVersion($schema_version)
setImportDirectory($a_val)
Set import directory.
setXMLContent($a_xml_content)