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 require_once("./classes/class.ilExplorer.php");
00035 require_once("./classes/class.ilForum.php");
00036
00037 class ilForumExplorer extends ilExplorer
00038 {
00044 var $thread_id;
00045 var $thread_subject;
00046
00047
00053 var $root_id;
00054
00060 var $forum;
00061
00067 function ilForumExplorer($a_target,$a_thread_id,$a_ref_id)
00068 {
00069 global $lng;
00070
00071 $lng->loadLanguageModule("forum");
00072
00073 parent::ilExplorer($a_target);
00074 $this->thread_id = $a_thread_id;
00075 $this->forum = new ilForum();
00076 $this->forum_obj =& ilObjectFactory::getInstanceByRefId($a_ref_id);
00077 $tmp_array = $this->forum->getFirstPostNode($this->thread_id);
00078 $this->root_id = $tmp_array["child"];
00079
00080 $this->__readThreadSubject();
00081
00082
00083 define(FULLNAME_MAXLENGTH,16);
00084 }
00085
00094 function setOutput($a_parent, $a_depth = 1)
00095 {
00096 global $lng,$ilUser;
00097 static $counter = 0;
00098
00099 if ($objects = $this->forum->getPostChilds($a_parent,$this->thread_id))
00100 {
00101 $tab = ++$a_depth - 2;
00102
00103 foreach ($objects as $key => $object)
00104 {
00105 if ($object["child"] != $this->root_id)
00106 {
00107 $parent_index = $this->getIndex($object);
00108 }
00109 $this->format_options["$counter"]["parent"] = $object["parent"];
00110 $this->format_options["$counter"]["child"] = $object["child"];
00111
00112 #$this->format_options["$counter"]["title"] = $object["title"]." <small class=\"small\">".$object["date"]."</small>".
00113 #"<small><br />".$object["subject"]."</small>";
00114
00115 $title = "<nobr>".$object["subject"]."</nobr><br>\n<nobr><small class=\"small\">".$lng->txt("from").": ".$object["loginname"]." [".$this->forum->convertDate($object["date"])."]</small></nobr>";
00116
00117 $this->format_options[$counter]['title'] = $title;
00118
00119 $this->format_options["$counter"]["type"] = $object["type"];
00120 $this->format_options["$counter"]["desc"] = "forums_the_".$object["type"];
00121 $this->format_options["$counter"]["depth"] = $tab;
00122 $this->format_options["$counter"]["container"] = false;
00123 $this->format_options["$counter"]["visible"] = true;
00124
00125
00126 for ($i = 0; $i < $tab; ++$i)
00127 {
00128 $this->format_options["$counter"]["tab"][] = 'blank';
00129 }
00130
00131 if ($object["child"] != $this->root_id and (!in_array($object["parent"],$this->expanded)
00132 or !$this->format_options["$parent_index"]["visible"]))
00133 {
00134 $this->format_options["$counter"]["visible"] = true;
00135 }
00136
00137 if ($object["child"] != $this->root_id)
00138 {
00139 $this->format_options["$parent_index"]["container"] = true;
00140
00141 if (in_array($object["parent"],$this->expanded))
00142 {
00143 $this->format_options["$parent_index"]["tab"][($tab-2)] = 'minus';
00144 }
00145 else
00146 {
00147 $this->format_options["$parent_index"]["tab"][($tab-2)] = 'minus';
00148 }
00149 }
00150
00151 ++$counter;
00152
00153
00154 $this->setOutput($object["child"],$a_depth);
00155 }
00156 }
00157 }
00158
00165 function getOutput()
00166 {
00167 global $tpl;
00168
00169 $this->format_options[0]["tab"] = array();
00170 $depth = $this->forum->getPostMaximumDepth($this->thread_id);
00171 for ($i=0;$i<$depth;++$i)
00172 {
00173 $this->createLines($i);
00174 }
00175
00176 $tpl->addBlockFile("EXPLORER_TOP", "exp_top", "tpl.explorer_top.html");
00177
00178
00179 $tpl->setVariable("BODY_CLASS", "il_Explorer");
00180
00181 $tpl_tree = new ilTemplate("tpl.tree.html", true, true);
00182
00183
00184
00185 $cur_depth = -1;
00186
00187 foreach ($this->format_options as $key => $options)
00188 {
00189
00190 $this->handleListEndTags($tpl_tree, $cur_depth, $options["depth"]);
00191
00192
00193 $this->handleListStartTags($tpl_tree, $cur_depth, $options["depth"]);
00194
00195 $cur_depth = $options["depth"];
00196
00197
00198
00199
00200
00201
00202
00203 $this->formatObject($tpl_tree,$options["child"],$options, $key);
00204
00205 }
00206
00207 $this->handleListEndTags($tpl_tree, $cur_depth, -1);
00208
00209 return $tpl_tree->get();
00210 }
00211
00220 function formatObject(&$tpl, $a_node_id,$a_option, $key)
00221 {
00222 global $lng,$ilUser;
00223
00224 if (!isset($a_node_id) or !is_array($a_option))
00225 {
00226 $this->ilias->raiseError(get_class($this)."::formatObject(): Missing parameter or wrong datatype! ".
00227 "node_id: ".$a_node_id." options:".var_dump($a_option),$this->ilias->error_obj->WARNING);
00228 }
00229
00230 if ($key == 0)
00231 {
00232 $tpl->setCurrentBlock("icon");
00233 $tpl->setVariable("ICON_IMAGE", ilUtil::getImagePath("icon_frm.gif"));
00234 $tpl->setVariable("TXT_ALT_IMG", $lng->txt("obj_frm"));
00235 $tpl->parseCurrentBlock();
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 $target = (strpos($this->target, "?") === false) ?
00274 $this->target."?" : $this->target."&";
00275
00276 $tpl->setCurrentBlock("link");
00277 $tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id."#".$a_node_id);
00278 #$a_option["title"] = strlen($a_option["title"]) <= FULLNAME_MAXLENGTH
00279 # ? $a_option["title"]
00280 # : substr($a_option["title"],0,FULLNAME_MAXLENGTH)."...";
00281
00282 if ($key == 0)
00283 {
00284 $tpl->setVariable("TITLE", "<strong>".$a_option["title"]."</strong>");
00285 }
00286 else
00287 {
00288 $tpl->setVariable("TITLE", $a_option["title"]);
00289 }
00290
00291 if($this->forum_obj->isRead($ilUser->getId(),$a_node_id))
00292 {
00293 $tpl->setVariable("A_CLASS",'class="postread"');
00294 }
00295 else
00296 {
00297 if($this->forum_obj->isNew($ilUser->getId(),$this->thread_id,$a_node_id))
00298 {
00299 $tpl->setVariable("A_CLASS",'class="postnew"');
00300 }
00301 else
00302 {
00303 $tpl->setVariable("A_CLASS",'class="postunread"');
00304 }
00305 $tpl->setVariable("ONCLICK",'onClick="this.className=\'postread\';"');
00306 }
00307
00308 if ($this->frame_target != "")
00309 {
00310 $tpl->setVariable("TARGET", " target=\"".$this->frame_target."\"");
00311 }
00312
00313 $tpl->parseCurrentBlock();
00314
00315 $tpl->setCurrentBlock("list_item");
00316 $tpl->parseCurrentBlock();
00317 $tpl->touchBlock("element");
00318
00319 }
00320
00328 function formatHeader(&$tpl)
00329 {
00330 global $lng, $ilias;
00331
00332 $frm = new ilForum();
00333 $frm->setWhereCondition("thr_pk = ".$this->thread_id);
00334 $threadData = $frm->getOneThread();
00335
00336 $tpl->setCurrentBlock("icon");
00337 $tpl->setVariable("ICON_IMAGE", ilUtil::getImagePath("icon_frm.gif"));
00338 $tpl->setVariable("TXT_ALT_IMG", $lng->txt("obj_frm"));
00339 $tpl->parseCurrentBlock();
00340 $tpl->setCurrentBlock("link");
00341 $tpl->setVariable("TITLE", $a_option["title"]." ".$lng->txt("forums_thread").": ".$threadData["thr_subject"]);
00342
00343 $tpl->setVariable("TARGET","target=content");
00344 $tpl->setVariable("LINK_TARGET",$this->target);
00345 $tpl->parseCurrentBlock();
00346
00347 $tpl->setCurrentBlock("list_item");
00348 $tpl->parseCurrentBlock();
00349 $tpl->touchBlock("element");
00350
00351 }
00352
00360 function createTarget($a_type,$a_node_id)
00361 {
00362 if (!isset($a_type) or !is_string($a_type) or !isset($a_node_id))
00363 {
00364 $this->ilias->raiseError(get_class($this)."::createTarget(): Missing parameter or wrong datatype! ".
00365 "type: ".$a_type." node_id:".$a_node_id,$this->ilias->error_obj->WARNING);
00366 }
00367 list($tmp,$get) = explode("?",$this->target);
00368
00369
00370
00371 $a_node_id = $a_type == '+' ? $a_node_id : -(int) $a_node_id;
00372
00373 return $_SERVER["PATH_INFO"]."?".$get."&fexpand=".$a_node_id;
00374 }
00375
00376
00383 function setExpand($a_node_id)
00384 {
00385 $first_node = $this->forum->getFirstPostNode($this->thread_id);
00386 $first_node_id = $first_node["id"];
00387 $_SESSION["fexpand"] = $_SESSION["fexpand"] ? $_SESSION["fexpand"] : array();
00388
00389
00390 if(empty($_SESSION["fexpand"]) or !in_array($first_node_id,$_SESSION["fexpand"]))
00391 {
00392 $all_nodes = $this->forum->getPostTree($first_node);
00393 foreach($all_nodes as $node)
00394 {
00395 $tmp_array[] = $node["id"];
00396 }
00397 $_SESSION["fexpand"] = array_merge($tmp_array,$_SESSION["fexpand"]);
00398 }
00399
00400 if($a_node_id > 0 && !in_array($a_node_id,$_SESSION["fexpand"]))
00401 {
00402 array_push($_SESSION["fexpand"],$a_node_id);
00403 }
00404
00405 if($a_node_id < 0)
00406 {
00407 $key = array_keys($_SESSION["fexpand"],-(int) $a_node_id);
00408 unset($_SESSION["fexpand"][$key[0]]);
00409 }
00410 $this->expanded = $_SESSION["fexpand"];
00411 }
00412
00413 function __readThreadSubject()
00414 {
00415 $this->forum->setWhereCondition("thr_pk = ".$this->thread_id);
00416 $threadData = $this->forum->getOneThread();
00417
00418 $this->thread_subject = $threadData["thr_subject"];
00419 }
00420
00421
00422 }
00423 ?>