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