00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once("classes/class.ilSaxParser.php");
00025
00035 class ilForumImportParser extends ilSaxParser
00036 {
00037 var $parent;
00038 var $counter;
00039
00048 function ilForumImportParser($a_xml_file,$a_parent_id)
00049 {
00050 define('EXPORT_VERSION',4);
00051
00052 parent::ilSaxParser($a_xml_file);
00053
00054
00055 $this->parent = $a_parent_id;
00056 $this->counter = 0;
00057
00058 }
00059
00060
00061 function getParent()
00062 {
00063 return $this->parent;
00064 }
00065
00066 function __pushParentId($a_id)
00067 {
00068 $this->parent[] = $a_id;
00069 }
00070 function __popParentId()
00071 {
00072 array_pop($this->parent);
00073
00074 return true;
00075 }
00076 function __getParentId()
00077 {
00078 return $this->parent[count($this->parent) - 1];
00079 }
00080
00081 function getRefId()
00082 {
00083 return $this->ref_id;
00084 }
00085
00086
00092 function setHandlers($a_xml_parser)
00093 {
00094 xml_set_object($a_xml_parser,$this);
00095 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00096 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00097 }
00098
00102 function startParsing()
00103 {
00104
00105 parent::startParsing();
00106
00107 return true;
00108 }
00109
00110
00114 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
00115 {
00116 global $ilErr;
00117
00118 switch($a_name)
00119 {
00120
00121 case "forum":
00122 if($a_attribs["exportVersion"] < EXPORT_VERSION)
00123 {
00124 $ilErr->raiseError("!!! This export Version isn't supported, update your ILIAS 2 installation"
00125 ,$ilErr->WARNING);
00126 }
00127 $this->__createNew($a_attribs["id"]);
00128
00129
00130 $this->parent = array(0);
00131 break;
00132
00133 case "title":
00134 case "description":
00135 $this->cdata = '';
00136 break;
00137
00138 case "moderator":
00139 if($mod = ilObjUser::_getImportedUserId($a_attribs["id"]))
00140 {
00141 $this->__addModerator($mod);
00142 }
00143
00144 case "thread":
00145
00146 $this->thread = array();
00147 $this->thread_start = true;
00148 $this->__pushParentId(0);
00149 #this->parent = array(0);
00150 break;
00151
00152 case "threadAuthor":
00153 $this->thread["author"] = ilObjUser::_getImportedUserId($a_attribs["id"]);
00154 $this->thread["login"] = $a_attribs["login"];
00155 break;
00156
00157
00158 case "posting":
00159
00160 $this->post = array();
00161 break;
00162
00163 case "postingAuthor":
00164 $this->post["author"] = ilObjUser::_getImportedUserId($a_attribs["id"]);
00165 $this->post["login"] = $a_attribs["login"];
00166 break;
00167
00168 }
00169 }
00170
00171
00175 function handlerEndTag($a_xml_parser, $a_name)
00176 {
00177 switch($a_name)
00178 {
00179
00180 case "title":
00181 $this->forum->setTitle($this->cdata);
00182 $this->forum->update();
00183 break;
00184
00185 case "description":
00186 $this->forum->setDescription($this->cdata);
00187 $this->forum->update();
00188
00189
00190 $this->__addTopic();
00191 break;
00192
00193
00194 case "thread":
00195 $this->__popParentId();
00196 #unset($this->parent[count($this->parent)-1]);
00197 break;
00198
00199 case "threadTitle":
00200 $this->thread["title"] = $this->cdata;
00201 break;
00202
00203 case "threadCreationDate":
00204 $this->thread["c_time"] = $this->cdata;
00205 break;
00206
00207
00208 case "posting":
00209 $this->__popParentId();
00210 #unset($this->parent[count($this->parent)-1]);
00211 break;
00212
00213 case "postingTitle":
00214 $this->post["title"] = $this->cdata;
00215 break;
00216
00217 case "postingCreationDate":
00218 $this->post["c_time"] = $this->cdata;
00219 break;
00220
00221 case "message":
00222 $this->post["message"] = $this->cdata;
00223
00224
00225 if($this->thread_start)
00226 {
00227 $this->__addThread();
00228 $this->thread_start = false;
00229 }
00230 else
00231 {
00232 $this->__addPost();
00233 }
00234 break;
00235
00236 case "forum":
00237 break;
00238
00239 }
00240 $this->cdata = '';
00241 }
00242
00243
00247 function handlerCharacterData($a_xml_parser, $a_data)
00248 {
00249
00250
00251
00252
00253 $a_data = str_replace("<","<",$a_data);
00254 $a_data = str_replace(">",">",$a_data);
00255
00256 if(!empty($a_data))
00257 {
00258 $this->cdata .= $a_data;
00259 }
00260 }
00261
00262
00263 function __createNew($a_id)
00264 {
00265 include_once "classes/class.ilObjForum.php";
00266
00267 $this->forum =& new ilObjForum();
00268 $this->forum->setImportId($a_id);
00269 $this->forum->setTitle("empty");
00270 $this->forum->create();
00271 $this->forum->createReference();
00272
00273 $this->forum->putInTree($_GET["ref_id"]);
00274
00275
00276 $this->forum->setPermissions($this->forum->getRefId());
00277
00278
00279 $this->roles = $this->forum->initDefaultRoles();
00280
00281
00282 $this->ref_id = $this->forum->getRefId();
00283
00284
00285 return true;
00286 }
00287
00288 function __addThread()
00289 {
00290 $this->__initForumObject();
00291
00292 $this->forum_obj->setImportName($this->thread["login"]);
00293 $this->forum_obj->setWhereCondition("top_frm_fk = ".$this->forum->getId());
00294 $topic = $this->forum_obj->getOneTopic();
00295
00296
00297
00298
00299
00300 $this->__pushParentId((int) $this->forum_obj->generateThread($topic["top_pk"],$this->thread["author"],
00301 $this->thread["title"],
00302 $this->post["message"],0,0,0,date("Y-m-d H:i:s",$this->thread["c_time"])));
00303
00304 $this->forum_obj->setDbTable("frm_data");
00305 $this->forum_obj->setWhereCondition("top_pk = ".$topic["top_pk"]);
00306 $this->forum_obj->updateVisits($topic["top_pk"]);
00307
00308 }
00309
00310 function __addPost()
00311 {
00312 $this->forum_obj->setImportName($this->post["login"]);
00313 $this->forum_obj->setWhereCondition("top_frm_fk = ".$this->forum->getId());
00314 $topic = $this->forum_obj->getOneTopic();
00315 $post = $this->forum_obj->getPostById($this->__getParentId());
00316 #$post = $this->forum_obj->getPostById($this->parent[count($this->parent)-1]);
00317
00318
00319
00320
00321 $this->__pushParentId((int) $this->forum_obj->generatePost($topic["top_pk"],$post["pos_thr_fk"],$this->post["author"],
00322 $this->post["message"],$this->parent[count($this->parent)-1],
00323 0,0,$this->post["title"],date("Y-m-d H:i:s",$this->post["c_time"])));
00324
00325 return true;
00326 }
00327
00328 function __initForumObject()
00329 {
00330 include_once "classes/class.ilForum.php";
00331
00332 $this->forum_obj =& new ilForum();
00333 $this->forum_obj->setForumRefId($this->ref_id);
00334
00335 return true;
00336 }
00337
00338 function __addTopic()
00339 {
00340 global $ilDB;
00341
00342 $query = "INSERT INTO frm_data VALUES('0','".
00343 $this->forum->getId()."','".
00344 ilUtil::prepareDBString($this->forum->getTitle())."','".
00345 ilUtil::prepareDBString($this->forum->getDescription())."','".
00346 "0','0','".
00347 "','".$this->roles[0]."','".
00348 date("Y:m:d H:i:s")."','".
00349 "0','".
00350 date("Y:m:d H:i:s")."','".
00351 "0','".
00352 $_SESSION["AccountId"]."')";
00353
00354 $ilDB->query($query);
00355
00356
00357 $this->__addModerator($_SESSION["AccountId"]);
00358 return true;
00359 }
00360
00361 function __addModerator($id)
00362 {
00363 global $rbacadmin;
00364
00365 $rbacadmin->assignUser($this->roles[0],$id, "n");
00366 ilObjUser::updateActiveRoles($id);
00367
00368 return true;
00369 }
00370
00371
00372 }
00373 ?>