ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilForumXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6 include_once "./Modules/Forum/classes/class.ilFileDataForum.php";
7 include_once "Services/MediaObjects/classes/class.ilObjMediaObject.php";
8 include_once "Services/RTE/classes/class.ilRTE.php";
9 
25 {
26  public $forum_id = null;
27 
35  public function __construct()
36  {
37  parent::__construct();
38  }
39 
40 
41  public function setForumId($id)
42  {
43  $this->forum_id = $id;
44  }
45 
46 
53  public function setFileTargetDirectories($a_rel, $a_abs)
54  {
55  $this->target_dir_relative = $a_rel;
56  $this->target_dir_absolute = $a_abs;
57  }
58 
59  public function start()
60  {
61  global $DIC;
62  $ilDB = $DIC->database();
63 
64  ilUtil::makeDir($this->target_dir_absolute . "/objects");
65 
66  $query_frm = 'SELECT * FROM frm_settings fs ' .
67  'JOIN object_data od ON fs.obj_id = od.obj_id ' .
68  'JOIN frm_data ON top_frm_fk = od.obj_id ' .
69  'WHERE fs.obj_id = ' . $ilDB->quote($this->forum_id, 'integer');
70 
71  $res = $ilDB->query($query_frm);
72 
73  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
74  break;
75  }
76 
77  $this->xmlStartTag("Forum", null);
78 
79  $this->xmlElement("Id", null, (int) $row->top_pk);
80  $this->xmlElement("ObjId", null, (int) $row->obj_id);
81  $this->xmlElement("Title", null, $row->title);
82  $this->xmlElement("Description", null, $row->description);
83  $this->xmlElement("DefaultView", null, (int) $row->default_view);
84  $this->xmlElement("Pseudonyms", null, (int) $row->anonymized);
85  $this->xmlElement("Statistics", null, (int) $row->statistics_enabled);
86  $this->xmlElement("ThreadRatings", null, (int) $row->thread_rating);
87  $this->xmlElement("Sorting", null, (int) $row->thread_sorting);
88  $this->xmlElement("MarkModeratorPosts", null, (int) $row->mark_mod_posts);
89  $this->xmlElement("PostingActivation", null, (int) $row->post_activation);
90  $this->xmlElement("PresetSubject", null, (int) $row->preset_subject);
91  $this->xmlElement("PresetRe", null, (int) $row->add_re_subject);
92  $this->xmlElement("NotificationType", null, $row->notification_type);
93  $this->xmlElement("ForceNotification", null, (int) $row->admin_force_noti);
94  $this->xmlElement("ToggleNotification", null, (int) $row->user_toggle_noti);
95  $this->xmlElement("LastPost", null, $row->top_last_post);
96  $this->xmlElement("Moderator", null, (int) $row->top_mods);
97  $this->xmlElement("CreateDate", null, $row->top_date);
98  $this->xmlElement("UpdateDate", null, $row->top_update);
99  $this->xmlElement("FileUpload", null, (int) $row->file_upload_allowed);
100  $this->xmlElement("UpdateUserId", null, $row->update_user);
101  $this->xmlElement("UserId", null, (int) $row->top_usr_id);
102  $this->xmlElement("AuthorId", null, (int) $row->thr_author_id);
103 
104  $query_thr = "SELECT frm_threads.* " .
105  " FROM frm_threads " .
106  " INNER JOIN frm_data ON top_pk = thr_top_fk " .
107  'WHERE top_frm_fk = ' . $ilDB->quote($this->forum_id, 'integer');
108 
109  $res = $ilDB->query($query_thr);
110 
111  while ($row = $ilDB->fetchObject($res)) {
112  $this->xmlStartTag("Thread");
113 
114  $this->xmlElement("Id", null, (int) $row->thr_pk);
115  $this->xmlElement("Subject", null, $row->thr_subject);
116  $this->xmlElement("UserId", null, (int) $row->thr_display_user_id);
117  $this->xmlElement("AuthorId", null, (int) $row->thr_author_id);
118  $this->xmlElement("Alias", null, $row->thr_usr_alias);
119  $this->xmlElement("LastPost", null, $row->thr_last_post);
120  $this->xmlElement("CreateDate", null, $row->thr_date);
121  $this->xmlElement("UpdateDate", null, $row->thr_date);
122  $this->xmlElement("ImportName", null, $row->import_name);
123  $this->xmlElement("Sticky", null, (int) $row->is_sticky);
124  $this->xmlElement("Closed", null, (int) $row->is_closed);
125 
126  $query = 'SELECT frm_posts.*, frm_posts_tree.*
127  FROM frm_posts
128  INNER JOIN frm_data
129  ON top_pk = pos_top_fk
130  INNER JOIN frm_posts_tree
131  ON pos_fk = pos_pk
132  WHERE pos_thr_fk = ' . $ilDB->quote($row->thr_pk, 'integer') . ' ';
133  $query .= " ORDER BY frm_posts_tree.lft ASC";
134  $resPosts = $ilDB->query($query);
135 
136  $lastDepth = null;
137  while ($rowPost = $ilDB->fetchObject($resPosts)) {
138  /*
139  // Used for nested postings
140  if( $rowPost->depth < $lastDepth )
141  {
142  for( $i = $rowPost->depth; $i <= $lastDepth; $i++ )
143  {
144  $this->xmlEndTag("Post");
145  }
146  }*/
147 
148  $this->xmlStartTag("Post");
149  $this->xmlElement("Id", null, (int) $rowPost->pos_pk);
150  $this->xmlElement("UserId", null, (int) $rowPost->pos_display_user_id);
151  $this->xmlElement("AuthorId", null, (int) $rowPost->pos_author_id);
152  $this->xmlElement("Alias", null, $rowPost->pos_usr_alias);
153  $this->xmlElement("Subject", null, $rowPost->pos_subject);
154  $this->xmlElement("CreateDate", null, $rowPost->pos_date);
155  $this->xmlElement("UpdateDate", null, $rowPost->pos_update);
156  $this->xmlElement("UpdateUserId", null, (int) $rowPost->update_user);
157  $this->xmlElement("Censorship", null, (int) $rowPost->pos_cens);
158  $this->xmlElement("CensorshipMessage", null, $rowPost->pos_cens_com);
159  $this->xmlElement("Notification", null, $rowPost->notify);
160  $this->xmlElement("ImportName", null, $rowPost->import_name);
161  $this->xmlElement("Status", null, (int) $rowPost->pos_status);
162  $this->xmlElement("Message", null, ilRTE::_replaceMediaObjectImageSrc($rowPost->pos_message, 0));
163 
164  if ($rowPost->is_author_moderator === null) {
165  $is_moderator_string = 'NULL';
166  } else {
167  $is_moderator_string = (string) $rowPost->is_author_moderator;
168  }
169 
170  $this->xmlElement("isAuthorModerator", null, $is_moderator_string);
171 
172  $media_exists = false;
173  $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', $rowPost->pos_pk);
174  foreach ($mobs as $mob) {
175  $moblabel = "il_" . IL_INST_ID . "_mob_" . $mob;
176  if (ilObjMediaObject::_exists($mob)) {
177  if (!$media_exists) {
178  $this->xmlStartTag("MessageMediaObjects");
179  $media_exists = true;
180  }
181 
182  $mob_obj = new ilObjMediaObject($mob);
183  $imgattrs = array(
184  "label" => $moblabel,
185  "uri" => $this->target_dir_relative . "/objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
186  );
187 
188  $this->xmlElement("MediaObject", $imgattrs, null);
189  $mob_obj->exportFiles($this->target_dir_absolute);
190  }
191  }
192  if ($media_exists) {
193  $this->xmlEndTag("MessageMediaObjects");
194  }
195 
196  $this->xmlElement("Lft", null, (int) $rowPost->lft);
197  $this->xmlElement("Rgt", null, (int) $rowPost->rgt);
198  $this->xmlElement("Depth", null, (int) $rowPost->depth);
199  $this->xmlElement("ParentId", null, (int) $rowPost->parent_pos);
200 
201  $tmp_file_obj = new ilFileDataForum(
202  $this->forum_id,
203  $rowPost->pos_pk
204  );
205 
206  $set = array();
207  if (count($tmp_file_obj->getFilesOfPost())) {
208  foreach ($tmp_file_obj->getFilesOfPost() as $file) {
209  $this->xmlStartTag("Attachment");
210 
211  copy($file['path'], $this->target_dir_absolute . "/" . basename($file['path']));
212  $content = $this->target_dir_relative . "/" . basename($file['path']);
213  $this->xmlElement("Content", null, $content);
214 
215  $this->xmlEndTag("Attachment");
216  }
217  }
218 
219  //Used for nested postings
220  //$lastDepth = $rowPost->depth;
221 
222  $this->xmlEndTag("Post");
223  }
224  /*
225  // Used for nested postings
226  if( $lastDepth )
227  {
228  for( $i = 1; $i <= $lastDepth ; $i++ )
229  {
230  $this->xmlEndTag("Post");
231  }
232 
233  $lastDepth = null;
234  }*/
235  $this->xmlEndTag("Thread");
236  }
237  $this->xmlEndTag("Forum");
238 
239  return true;
240  }
241 
242  public function getXML()
243  {
244  // Replace ascii code 11 characters because of problems with xml sax parser
245  return str_replace('&#11;', '', $this->xmlDumpMem(false));
246  }
247 }
Add rich text string
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
global $DIC
Definition: saml.php:7
xmlDumpMem($format=true)
Returns xml document from memory.
if(!array_key_exists('StateId', $_REQUEST)) $id
XML writer class.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
xmlEndTag($tag)
Writes an endtag.
XML writer class.
foreach($_POST as $key=> $value) $res
$mobs
setFileTargetDirectories($a_rel, $a_abs)
Set file target directories.
Class ilObjMediaObject.
$query
Create styles array
The data for the language used.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
This class handles all operations on files for the forum object.
global $ilDB
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static _exists($a_id, $a_reference=false, $a_type=null)
checks wether a lm content object with specified id exists or not