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
00034 class ilForumExport
00035 {
00041 var $ilias;
00042
00049 var $dbTable;
00050
00056 var $className="ilForumExport";
00057
00064 var $orderField;
00065
00066 var $whereCondition = "1";
00067
00068 var $txtQuote1 = "[quote]";
00069 var $txtQuote2 = "[/quote]";
00070 var $replQuote1 = "<blockquote class=\"quote\"><hr size=\"1\" color=\"#000000\">";
00071 var $replQuote2 = "<hr size=\"1\" color=\"#000000\"/></blockquote>";
00072
00073
00074 var $pageHits = 20;
00075
00076
00077 var $id;
00078
00083 function ilForumExport()
00084 {
00085 global $ilias;
00086
00087 $this->ilias =& $ilias;
00088 }
00089
00090
00091
00098 function setOrderField($orderField)
00099 {
00100 if ($orderField == "")
00101 {
00102 die($this->className . "::setOrderField(): No orderField given.");
00103 }
00104 else
00105 {
00106 $this->orderField = $orderField;
00107 }
00108 }
00109
00116 function getOrderField()
00117 {
00118 return $this->orderField;
00119 }
00120
00127 function setDbTable($dbTable)
00128 {
00129 if ($dbTable == "")
00130 {
00131 die($this->className . "::setDbTable(): No database table given.");
00132 }
00133 else
00134 {
00135 $this->dbTable = $dbTable;
00136 }
00137 }
00138
00145 function getDbTable()
00146 {
00147 return $this->dbTable;
00148 }
00149
00156 function setWhereCondition($whereCondition = "1")
00157 {
00158 $this->whereCondition = $whereCondition;
00159 return true;
00160 }
00161
00168 function getWhereCondition()
00169 {
00170 return $this->whereCondition;
00171 }
00172
00173
00179 function getOneTopic()
00180 {
00181 $query = "SELECT * FROM frm_data WHERE ( ".$this->whereCondition." )";
00182
00183 $result = $this->ilias->db->getRow($query, DB_FETCHMODE_ASSOC);
00184
00185 $this->setWhereCondition("1");
00186
00187 $result["top_name"] = trim(stripslashes($result["top_name"]));
00188 $result["top_description"] = nl2br(stripslashes($result["top_description"]));
00189
00190 return $result;
00191 }
00192
00193
00194
00200 function getOneThread()
00201 {
00202 $query = "SELECT * FROM frm_threads WHERE ( ".$this->whereCondition." )";
00203
00204 $result = $this->ilias->db->getRow($query, DB_FETCHMODE_ASSOC);
00205
00206 $this->setWhereCondition("1");
00207
00208 $result["thr_subject"] = trim(stripslashes($result["thr_subject"]));
00209
00210 return $result;
00211 }
00212
00213
00214
00221 function getFirstPostNode($tree_id)
00222 {
00223 $query = "SELECT * FROM frm_posts, frm_posts_tree ".
00224 "WHERE pos_pk = pos_fk ".
00225 "AND parent_pos = 0 ".
00226 "AND thr_fk = '".$tree_id."'";
00227 $res = $this->ilias->db->query($query);
00228
00229 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
00230
00231 return $this->fetchPostNodeData($row);
00232 }
00233
00234
00242 function getPostTree($a_node)
00243 {
00244 $subtree = array();
00245
00246 $query = "SELECT * FROM frm_posts_tree ".
00247 "LEFT JOIN frm_posts ON frm_posts.pos_pk = frm_posts_tree.pos_fk ".
00248 "WHERE frm_posts_tree.lft BETWEEN '".$a_node["lft"]."' AND '".$a_node["rgt"]."' ".
00249 "AND thr_fk = '".$a_node["tree"]."'";
00250 if ($this->orderField != "")
00251 $query .= " ORDER BY ".$this->orderField." DESC";
00252
00253 $res = $this->ilias->db->query($query);
00254
00255 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00256 {
00257 $subtree[] = $this->fetchPostNodeData($row);
00258 }
00259
00260 return $subtree;
00261 }
00262
00263
00264
00271 function fetchPostNodeData($a_row)
00272 {
00273 $data = array(
00274 "pos_pk" => $a_row->pos_pk,
00275 "author" => $a_row->pos_usr_id,
00276 "message" => $a_row->pos_message,
00277 "subject" => $a_row->pos_subject,
00278 "pos_cens_com" => $a_row->pos_cens_com,
00279 "pos_cens" => $a_row->pos_cens,
00280 "date" => $a_row->date,
00281 "create_date" => $a_row->pos_date,
00282 "update" => $a_row->pos_update,
00283 "update_user" => $a_row->update_user,
00284 "tree" => $a_row->thr_fk,
00285 "parent" => $a_row->parent_pos,
00286 "lft" => $a_row->lft,
00287 "rgt" => $a_row->rgt,
00288 "depth" => $a_row->depth,
00289 "id" => $a_row->fpt_pk,
00290 "import_name" => $a_row->import_name
00291 );
00292
00293 $data["message"] = stripslashes($data["message"]);
00294
00295 return $data ? $data : array();
00296 }
00297
00298
00299
00307 function getUser($a_user_id)
00308 {
00309 $userObj = new ilObjUser($a_user_id);
00310
00311 return $userObj;
00312 }
00313
00314
00315
00316
00323 function convertDate($date)
00324 {
00325 global $lng;
00326
00327 # if ($date > date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d"), date("Y"))))
00328 # {
00329 # return $lng->txt("today").", ".ilFormat::formatDate($date,"time");
00330 # }
00331
00332 return ilFormat::formatDate($date);
00333 }
00334
00335
00336
00344 function countUserArticles($user)
00345 {
00346 $q = "SELECT * FROM frm_posts WHERE ";
00347 $q .= "pos_usr_id ='".$user."'";
00348
00349 $res = $this->ilias->db->query($q);
00350
00351 return $res->numRows();
00352 }
00353
00354
00355
00363 function prepareText($text,$edit=0)
00364 {
00365 global $lng;
00366
00367 if ($edit == 1)
00368 {
00369 $text = str_replace($this->txtQuote1, "", $text);
00370 $text = str_replace($this->txtQuote2, "", $text);
00371 $text = $this->txtQuote1.$text.$this->txtQuote2;
00372 }
00373 else
00374 {
00375
00376 $startZ = substr_count ($text, $this->txtQuote1);
00377 $endZ = substr_count ($text, $this->txtQuote2);
00378
00379
00380 if ($startZ > 0 || $endZ > 0)
00381 {
00382 if ($startZ > $endZ)
00383 {
00384 $diff = $startZ - $endZ;
00385
00386 for ($i = 0; $i < $diff; $i++)
00387 {
00388 $text .= $this->txtQuote2;
00389 }
00390 }
00391 elseif ($startZ < $endZ)
00392 {
00393 $diff = $endZ - $startZ;
00394
00395 for ($i = 0; $i < $diff; $i++)
00396 {
00397 $text = $this->txtQuote1.$text;
00398 }
00399 }
00400
00401
00402 if ($startZ > 1)
00403 {
00404 $start_firstPos = strpos($text, $this->txtQuote1);
00405 $text_s2 = str_replace($this->txtQuote1, "", substr($text, ($start_firstPos+strlen($this->txtQuote1))));
00406 $text_s1 = substr($text, 0, ($start_firstPos+strlen($this->txtQuote1)));
00407 $text = $text_s1.$text_s2;
00408 }
00409 if ($endZ > 1)
00410 {
00411 $end_firstPos = strrpos($text, $this->txtQuote2);
00412 $text_e1 = str_replace($this->txtQuote2, "", substr($text, 0, $end_firstPos));
00413 $text_e2 = substr($text, $end_firstPos);
00414 $text = $text_e1.$text_e2;
00415 }
00416
00417 if ($edit == 0)
00418 {
00419 $text = str_replace($this->txtQuote1, "<blockquote><span><b>".$lng->txt("quote")."</b>:</blockquote>".$this->replQuote1, $text);
00420 $text = str_replace($this->txtQuote2, $this->replQuote2, $text);
00421 }
00422 }
00423 }
00424 $text = stripslashes($text);
00425 return $text;
00426 }
00427
00428
00429
00436 function getOnePost($post)
00437 {
00438 global $lng;
00439
00440 $q = "SELECT frm_posts.*, usr_data.lastname FROM frm_posts, usr_data WHERE ";
00441 $q .= "pos_pk = '".$post."' AND ";
00442 $q .= "pos_usr_id = usr_id";
00443
00444 $q = "SELECT frm_posts.* FROM frm_posts WHERE ";
00445 $q .= "pos_pk = '".$post."' ";
00446
00447 $result = $this->ilias->db->getRow($q, DB_FETCHMODE_ASSOC);
00448
00449 $ROW = $this->fetchPostNodeData($result);
00450
00451 $result["create_date"] = $this->convertDate($result["pos_date"]);
00452 $result["message"] = nl2br(stripslashes($result["pos_message"]));
00453 $result["author"] = nl2br(stripslashes($result["pos_usr_id"]));
00454 $result["date"] = date;
00455 $result["update"] = $result["pos_update"];
00456
00457
00458 return $result;
00459 }
00460
00461
00468 function getThreadList($topic)
00469 {
00470 $q = "SELECT frm_threads.*, usr_data.lastname FROM frm_threads, usr_data WHERE ";
00471 $q .= "thr_top_fk ='".$topic."' AND ";
00472 $q .= "thr_usr_id = usr_id";
00473
00474 $q = "SELECT frm_threads.* FROM frm_threads WHERE ";
00475 $q .= "thr_top_fk ='".$topic."' ";
00476
00477 if ($this->orderField != "")
00478 {
00479 $q .= " ORDER BY ".$this->orderField;
00480 }
00481
00482 $res = $this->ilias->db->query($q);
00483
00484 return $res;
00485 }
00486
00487 function getUserData($id,$a_import_name = 0)
00488 {
00489 global $lng;
00490
00491 if($id && ilObject::_exists($id) && ilObjectFactory::getInstanceByObjId($id,false))
00492 {
00493 $query = "SELECT * FROM usr_data WHERE usr_id = '".$id."'";
00494 $res = $this->ilias->db->query($query);
00495 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00496 {
00497 $tmp_array["usr_id"] = $row->usr_id;
00498 $tmp_array["login"] = $row->login;
00499 $tmp_array["create_date"] = $row->create_date;
00500 $tmp_array["id"] = $row->usr_id;
00501
00502 }
00503 return $tmp_array ? $tmp_array : array();
00504 }
00505 else
00506 {
00507 $login = $a_import_name ? $a_import_name." (".$lng->txt("imported").")" : $lng->txt("unknown");
00508
00509 return array("usr_id" => 0,"login" => $login);
00510 }
00511 }
00512 }