|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */ |
|
3
|
|
|
@set_time_limit(0); |
|
|
|
|
|
|
4
|
|
|
@require_once('./modules/importer/extract.class.php'); |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* ttimport class |
|
8
|
|
|
* ttxml import class |
|
9
|
|
|
* |
|
10
|
|
|
* @author NAVER ([email protected]) |
|
11
|
|
|
* @package /modules/importer |
|
12
|
|
|
* @version 0.1 |
|
13
|
|
|
*/ |
|
14
|
|
|
class ttimport |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Xml Parse |
|
18
|
|
|
* @var XmlParser |
|
19
|
|
|
*/ |
|
20
|
|
|
var $oXmlParser = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Import data in module.xml format |
|
24
|
|
|
* @param int $key |
|
25
|
|
|
* @param int $cur |
|
26
|
|
|
* @param string $index_file |
|
27
|
|
|
* @param int $unit_count |
|
28
|
|
|
* @param int $module_srl |
|
29
|
|
|
* @param int $guestbook_module_srl |
|
30
|
|
|
* @param string $user_id |
|
31
|
|
|
* @param string $module_name |
|
32
|
|
|
* @return int |
|
33
|
|
|
*/ |
|
34
|
|
|
function importModule($key, $cur, $index_file, $unit_count, $module_srl, $guestbook_module_srl, $user_id, $module_name=null) |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
// Pre-create the objects needed |
|
37
|
|
|
$this->oXmlParser = new XmlParser(); |
|
38
|
|
|
// Get category information of the target module |
|
39
|
|
|
$oDocumentController = getController('document'); |
|
40
|
|
|
$oDocumentModel = getModel('document'); |
|
41
|
|
|
$category_list = $category_titles = array(); |
|
|
|
|
|
|
42
|
|
|
$category_list = $oDocumentModel->getCategoryList($module_srl); |
|
43
|
|
|
if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; |
|
44
|
|
|
// First handle categorty information |
|
45
|
|
|
$category_file = preg_replace('/index$/i', 'category.xml', $index_file); |
|
46
|
|
|
if(file_exists($category_file)) |
|
47
|
|
|
{ |
|
48
|
|
|
// Create the xmlParser object |
|
49
|
|
|
$xmlDoc = $this->oXmlParser->loadXmlFile($category_file); |
|
50
|
|
|
// List category information |
|
51
|
|
|
if($xmlDoc->categories->category) |
|
52
|
|
|
{ |
|
53
|
|
|
$categories = array(); |
|
54
|
|
|
$idx = 0; |
|
55
|
|
|
$this->arrangeCategory($xmlDoc->categories, $categories, $idx, 0); |
|
56
|
|
|
|
|
57
|
|
|
$match_sequence = array(); |
|
58
|
|
|
foreach($categories as $k => $v) |
|
59
|
|
|
{ |
|
60
|
|
|
$category = $v->name; |
|
61
|
|
|
if(!$category || $category_titles[$category]) continue; |
|
62
|
|
|
|
|
63
|
|
|
$obj = null; |
|
64
|
|
|
$obj->title = $category; |
|
65
|
|
|
$obj->module_srl = $module_srl; |
|
66
|
|
|
if($v->parent) $obj->parent_srl = $match_sequence[$v->parent]; |
|
67
|
|
|
$output = $oDocumentController->insertCategory($obj); |
|
68
|
|
|
|
|
69
|
|
|
if($output->toBool()) $match_sequence[$v->sequence] = $category_titles[$category] = $output->get('category_srl'); |
|
70
|
|
|
} |
|
71
|
|
|
$oDocumentController->makeCategoryFile($module_srl); |
|
72
|
|
|
} |
|
73
|
|
|
FileHandler::removeFile($category_file); |
|
74
|
|
|
} |
|
75
|
|
|
$category_list = $category_titles = array(); |
|
|
|
|
|
|
76
|
|
|
$category_list = $oDocumentModel->getCategoryList($module_srl); |
|
77
|
|
|
if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; |
|
78
|
|
|
// Get administrator information |
|
79
|
|
|
$oMemberModel = getModel('member'); |
|
80
|
|
|
$member_info = $oMemberModel->getMemberInfoByUserID($user_id); |
|
81
|
|
|
$author_xml_id = 0; |
|
82
|
|
|
|
|
83
|
|
|
if(!$cur) $cur = 0; |
|
84
|
|
|
// Open an index file |
|
85
|
|
|
$f = fopen($index_file,"r"); |
|
86
|
|
|
// Pass if already read |
|
87
|
|
|
for($i=0;$i<$cur;$i++) fgets($f, 1024); |
|
88
|
|
|
// Read each line until the codition meets |
|
89
|
|
|
for($idx=$cur;$idx<$cur+$unit_count;$idx++) |
|
90
|
|
|
{ |
|
91
|
|
|
if(feof($f)) break; |
|
92
|
|
|
// Find a location |
|
93
|
|
|
$target_file = trim(fgets($f, 1024)); |
|
94
|
|
|
|
|
95
|
|
|
if(!file_exists($target_file)) continue; |
|
96
|
|
|
// Start importing data |
|
97
|
|
|
$fp = fopen($target_file,"r"); |
|
98
|
|
|
if(!$fp) continue; |
|
99
|
|
|
|
|
100
|
|
|
$obj = null; |
|
101
|
|
|
$obj->module_srl = $module_srl; |
|
102
|
|
|
$obj->document_srl = getNextSequence(); |
|
103
|
|
|
$obj->uploaded_count = 0; |
|
104
|
|
|
|
|
105
|
|
|
$files = array(); |
|
106
|
|
|
|
|
107
|
|
|
$started = false; |
|
108
|
|
|
$buff = null; |
|
109
|
|
|
// Start importing from the body data |
|
110
|
|
|
while(!feof($fp)) |
|
111
|
|
|
{ |
|
112
|
|
|
$str = fgets($fp, 1024); |
|
113
|
|
|
// Prepare an item |
|
114
|
|
|
if(substr($str,0,5) == '<post') |
|
115
|
|
|
{ |
|
116
|
|
|
$started = true; |
|
117
|
|
|
continue; |
|
118
|
|
|
// Import the attachment |
|
119
|
|
|
} |
|
120
|
|
View Code Duplication |
else if(substr($str,0,12) == '<attachment ') |
|
121
|
|
|
{ |
|
122
|
|
|
if($this->importAttaches($fp, $module_srl, $obj->document_srl, $files, $str)) $obj->uploaded_count++; |
|
123
|
|
|
continue; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if($started) $buff .= $str; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$xmlDoc = $this->oXmlParser->parse('<post>'.$buff); |
|
130
|
|
|
|
|
131
|
|
|
$author_xml_id = $xmlDoc->post->author->body; |
|
132
|
|
|
|
|
133
|
|
|
if($xmlDoc->post->category->body) |
|
134
|
|
|
{ |
|
135
|
|
|
$tmp_arr = explode('/',$xmlDoc->post->category->body); |
|
136
|
|
|
$category = trim($tmp_arr[count($tmp_arr)-1]); |
|
137
|
|
|
if($category_titles[$category]) $obj->category_srl = $category_titles[$category]; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
$obj->is_notice = 'N'; |
|
141
|
|
|
$obj->status = in_array($xmlDoc->post->visibility->body, array('public','syndicated'))?$oDocumentModel->getConfigStatus('public'):$oDocumentModel->getConfigStatus('secret'); |
|
142
|
|
|
$obj->title = $xmlDoc->post->title->body; |
|
143
|
|
|
$obj->content = $xmlDoc->post->content->body; |
|
144
|
|
|
$obj->password = md5($xmlDoc->post->password->body); |
|
145
|
|
|
$obj->commentStatus = $xmlDoc->post->acceptcomment->body=='1'?'ALLOW':'DENY'; |
|
146
|
|
|
$obj->allow_trackback = $xmlDoc->post->accepttrackback->body=='1'?'Y':'N'; |
|
147
|
|
|
//$obj->allow_comment = $xmlDoc->post->acceptComment->body=='1'?'Y':'N'; |
|
148
|
|
|
//$obj->allow_trackback = $xmlDoc->post->acceptTrackback->body=='1'?'Y':'N'; |
|
149
|
|
|
$obj->regdate = date("YmdHis",$xmlDoc->post->published->body); |
|
150
|
|
|
$obj->last_update = date("YmdHis", $xmlDoc->post->modified->body); |
|
151
|
|
|
if(!$obj->last_update) $obj->last_update = $obj->regdate; |
|
152
|
|
|
|
|
153
|
|
|
$tag = null; |
|
|
|
|
|
|
154
|
|
|
$tmp_tags = null; |
|
155
|
|
|
$tag = $xmlDoc->post->tag; |
|
156
|
|
|
if($tag) |
|
157
|
|
|
{ |
|
158
|
|
|
if(!is_array($tag)) $tag = array($tag); |
|
159
|
|
|
foreach($tag as $key => $val) $tmp_tags[] = $val->body; |
|
160
|
|
|
$obj->tags = implode(',',$tmp_tags); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
$obj->readed_count = 0; |
|
164
|
|
|
$obj->voted_count = 0; |
|
165
|
|
|
$obj->nick_name = $member_info->nick_name; |
|
166
|
|
|
$obj->user_name = $member_info->user_name; |
|
167
|
|
|
$obj->user_id = $member_info->user_id; |
|
168
|
|
|
$obj->member_srl = $member_info->member_srl; |
|
169
|
|
|
$obj->email_address = $member_info->email_address; |
|
170
|
|
|
$obj->homepage = $member_info->homepage; |
|
171
|
|
|
$obj->ipaddress = $_REMOTE['SERVER_ADDR']; |
|
|
|
|
|
|
172
|
|
|
$obj->list_order = $obj->update_order = $obj->document_srl*-1; |
|
173
|
|
|
$obj->notify_message = 'N'; |
|
174
|
|
|
// Change content information (attachment) |
|
175
|
|
|
$obj->content = str_replace('[##_ATTACH_PATH_##]/','',$obj->content); |
|
176
|
|
View Code Duplication |
if(count($files)) |
|
177
|
|
|
{ |
|
178
|
|
|
foreach($files as $key => $val) { |
|
179
|
|
|
$obj->content = preg_replace('/(src|href)\=(["\']?)'.preg_quote($key).'(["\']?)/i','$1="'.$val->url.'"',$obj->content); |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
$obj->content = preg_replace_callback('!\[##_Movie\|([^\|]*)\|(.*?)_##\]!is', array($this, '_replaceTTMovie'), $obj->content); |
|
184
|
|
|
|
|
185
|
|
|
if(count($files)) |
|
186
|
|
|
{ |
|
187
|
|
|
$this->files = $files; |
|
|
|
|
|
|
188
|
|
|
$obj->content = preg_replace_callback('!\[##_([a-z0-9]+)\|([^\|]*)\|([^\|]*)\|(.*?)_##\]!is', array($this, '_replaceTTAttach'), $obj->content); |
|
189
|
|
|
} |
|
190
|
|
|
// Trackback inserted |
|
191
|
|
|
$obj->trackback_count = 0; |
|
192
|
|
|
if($xmlDoc->post->trackback) |
|
193
|
|
|
{ |
|
194
|
|
|
$trackbacks = $xmlDoc->post->trackback; |
|
195
|
|
|
if(!is_array($trackbacks)) $trackbacks = array($trackbacks); |
|
196
|
|
|
if(count($trackbacks)) |
|
197
|
|
|
{ |
|
198
|
|
|
foreach($trackbacks as $key => $val) |
|
199
|
|
|
{ |
|
200
|
|
|
$tobj = null; |
|
201
|
|
|
$tobj->trackback_srl = getNextSequence(); |
|
202
|
|
|
$tobj->module_srl = $module_srl; |
|
203
|
|
|
$tobj->document_srl = $obj->document_srl; |
|
204
|
|
|
$tobj->url = $val->url->body; |
|
205
|
|
|
$tobj->title = $val->title->body; |
|
206
|
|
|
$tobj->blog_name = $val->site->body; |
|
207
|
|
|
$tobj->excerpt = $val->excerpt->body; |
|
208
|
|
|
$tobj->regdate = date("YmdHis",$val->received->body); |
|
209
|
|
|
$tobj->ipaddress = $val->ip->body; |
|
210
|
|
|
$tobj->list_order = -1*$tobj->trackback_srl; |
|
211
|
|
|
$output = executeQuery('trackback.insertTrackback', $tobj); |
|
212
|
|
|
if($output->toBool()) $obj->trackback_count++; |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
// Comment |
|
217
|
|
|
$obj->comment_count = 0; |
|
218
|
|
|
if($xmlDoc->post->comment) |
|
219
|
|
|
{ |
|
220
|
|
|
$comment = $xmlDoc->post->comment; |
|
221
|
|
|
if(!is_array($comment)) $comment = array($comment); |
|
222
|
|
|
foreach($comment as $key => $val) |
|
223
|
|
|
{ |
|
224
|
|
|
$parent_srl = $this->insertComment($val, $module_srl, $obj->document_srl, $member_info, 0, $author_xml_id); |
|
225
|
|
|
if($parent_srl === false) continue; |
|
226
|
|
|
|
|
227
|
|
|
$obj->comment_count++; |
|
228
|
|
View Code Duplication |
if($val->comment) |
|
229
|
|
|
{ |
|
230
|
|
|
$child_comment = $val->comment; |
|
231
|
|
|
if(!is_array($child_comment)) $child_comment = array($child_comment); |
|
232
|
|
|
foreach($child_comment as $k => $v) |
|
233
|
|
|
{ |
|
234
|
|
|
$result = $this->insertComment($v, $module_srl, $obj->document_srl, $member_info, $parent_srl, $author_xml_id); |
|
|
|
|
|
|
235
|
|
|
if($result !== false) $obj->comment_count++; |
|
236
|
|
|
} |
|
237
|
|
|
} |
|
238
|
|
|
} |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
if($module_name == 'textyle') |
|
242
|
|
|
{ |
|
243
|
|
|
$args->document_srl = $obj->document_srl; |
|
|
|
|
|
|
244
|
|
|
$args->module_srl = $obj->module_srl; |
|
245
|
|
|
$args->logs = serialize(null); |
|
246
|
|
|
$output = executeQuery('textyle.insertPublishLog', $args); |
|
|
|
|
|
|
247
|
|
|
// Visibility value of published state |
|
248
|
|
|
$status_published = array('public', 'syndicated'); |
|
249
|
|
|
// Save state if not published |
|
250
|
|
|
if(!in_array($xmlDoc->post->visibility->body, $status_published)) |
|
251
|
|
|
{ |
|
252
|
|
|
$obj->module_srl = $member_info->member_srl; |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
// Document |
|
256
|
|
|
$output = executeQuery('document.insertDocument', $obj); |
|
257
|
|
|
|
|
258
|
|
View Code Duplication |
if($output->toBool()) |
|
259
|
|
|
{ |
|
260
|
|
|
// Tags |
|
261
|
|
|
if($obj->tags) |
|
262
|
|
|
{ |
|
263
|
|
|
$tag_list = explode(',',$obj->tags); |
|
264
|
|
|
$tag_count = count($tag_list); |
|
265
|
|
|
for($i=0;$i<$tag_count;$i++) |
|
266
|
|
|
{ |
|
267
|
|
|
$args = new stdClass; |
|
268
|
|
|
$args->tag_srl = getNextSequence(); |
|
269
|
|
|
$args->module_srl = $module_srl; |
|
270
|
|
|
$args->document_srl = $obj->document_srl; |
|
271
|
|
|
$args->tag = trim($tag_list[$i]); |
|
272
|
|
|
$args->regdate = $obj->regdate; |
|
273
|
|
|
if(!$args->tag) continue; |
|
274
|
|
|
$output = executeQuery('tag.insertTag', $args); |
|
|
|
|
|
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
fclose($fp); |
|
280
|
|
|
FileHandler::removeFile($target_file); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
fclose($f); |
|
284
|
|
|
|
|
285
|
|
|
if(count($category_list)) foreach($category_list as $key => $val) $oDocumentController->updateCategoryCount($module_srl, $val->category_srl); |
|
286
|
|
|
// Guestbook information |
|
287
|
|
|
$guestbook_file = preg_replace('/index$/i', 'guestbook.xml', $index_file); |
|
288
|
|
|
if(file_exists($guestbook_file)) |
|
289
|
|
|
{ |
|
290
|
|
|
// Create the xmlParser object |
|
291
|
|
|
$xmlDoc = $this->oXmlParser->loadXmlFile($guestbook_file); |
|
292
|
|
|
// Handle guest book information |
|
293
|
|
|
if($guestbook_module_srl && $xmlDoc->guestbook->comment) |
|
294
|
|
|
{ |
|
295
|
|
|
$comment = $xmlDoc->guestbook->comment; |
|
296
|
|
|
if(!is_array($comment)) $comment = array($comment); |
|
297
|
|
|
|
|
298
|
|
|
if($module_name =='textyle') |
|
299
|
|
|
{ |
|
300
|
|
|
foreach($comment as $key => $val) |
|
301
|
|
|
{ |
|
302
|
|
|
$textyle_guestbook_srl = getNextSequence(); |
|
303
|
|
|
|
|
304
|
|
|
if($val->comment) |
|
305
|
|
|
{ |
|
306
|
|
|
$child_comment = $val->comment; |
|
307
|
|
|
if(!is_array($child_comment)) $child_comment = array($child_comment); |
|
308
|
|
|
foreach($child_comment as $k => $v) |
|
309
|
|
|
{ |
|
310
|
|
|
$result = $this->insertTextyleGuestbookItem($v, $module_srl, $member_info,0,$textyle_guestbook_srl,$author_xml_id); |
|
|
|
|
|
|
311
|
|
|
} |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
$result = $this->insertTextyleGuestbookItem($val, $module_srl, $member_info,$textyle_guestbook_srl,0,$author_xml_id); |
|
|
|
|
|
|
315
|
|
|
} |
|
316
|
|
|
} |
|
317
|
|
|
else |
|
318
|
|
|
{ |
|
319
|
|
|
foreach($comment as $key => $val) |
|
320
|
|
|
{ |
|
321
|
|
|
$obj = null; |
|
322
|
|
|
$obj->module_srl = $guestbook_module_srl; |
|
323
|
|
|
$obj->document_srl = getNextSequence(); |
|
324
|
|
|
$obj->uploaded_count = 0; |
|
325
|
|
|
$obj->is_notice = 'N'; |
|
326
|
|
|
$obj->status = $val->secret->body=='1'?$oDocumentModel->getConfigStatus('secret'):$oDocumentModel->getConfigStatus('public'); |
|
327
|
|
|
$obj->content = nl2br($val->content->body); |
|
328
|
|
|
|
|
329
|
|
|
// Extract a title form the bocy |
|
330
|
|
|
$obj->title = cut_str(strip_tags($obj->content),20,'...'); |
|
331
|
|
|
if ($obj->title == '') $obj->title = 'Untitled'; |
|
332
|
|
|
|
|
333
|
|
|
$obj->commentStatus = 'ALLOW'; |
|
334
|
|
|
$obj->allow_trackback = 'N'; |
|
335
|
|
|
$obj->regdate = date("YmdHis",$val->written->body); |
|
336
|
|
|
$obj->last_update = date("YmdHis", $val->written->body); |
|
337
|
|
|
if(!$obj->last_update) $obj->last_update = $obj->regdate; |
|
338
|
|
|
$obj->tags = ''; |
|
339
|
|
|
$obj->readed_count = 0; |
|
340
|
|
|
$obj->voted_count = 0; |
|
341
|
|
|
if($author_xml_id && $val->commenter->attrs->id == $author_xml_id) |
|
342
|
|
|
{ |
|
343
|
|
|
$obj->password = ''; |
|
344
|
|
|
$obj->nick_name = $member_info->nick_name; |
|
345
|
|
|
$obj->user_name = $member_info->user_name; |
|
346
|
|
|
$obj->user_id = $member_info->user_id; |
|
347
|
|
|
$obj->member_srl = $member_info->member_srl; |
|
348
|
|
|
$obj->email_address = $member_info->email_address; |
|
349
|
|
|
$obj->homepage = $member_info->homepage; |
|
350
|
|
|
} |
|
351
|
|
|
else |
|
352
|
|
|
{ |
|
353
|
|
|
$obj->password = $val->password->body; |
|
354
|
|
|
$obj->nick_name = $val->commenter->name->body; |
|
355
|
|
|
$obj->member_srl = 0; |
|
356
|
|
|
$homepage = $val->commenter->homepage->body; |
|
|
|
|
|
|
357
|
|
|
} |
|
358
|
|
|
$obj->ipaddress = $val->commenter->ip->body; |
|
359
|
|
|
$obj->list_order = $obj->update_order = $obj->document_srl*-1; |
|
360
|
|
|
$obj->notify_message = 'N'; |
|
361
|
|
|
$obj->trackback_count = 0; |
|
362
|
|
|
|
|
363
|
|
|
$obj->comment_count = 0; |
|
364
|
|
View Code Duplication |
if($val->comment) |
|
365
|
|
|
{ |
|
366
|
|
|
$child_comment = $val->comment; |
|
367
|
|
|
if(!is_array($child_comment)) $child_comment = array($child_comment); |
|
368
|
|
|
foreach($child_comment as $k => $v) |
|
369
|
|
|
{ |
|
370
|
|
|
$result = $this->insertComment($v, $module_srl, $obj->document_srl, $member_info, 0,$author_xml_id); |
|
371
|
|
|
if($result !== false) $obj->comment_count++; |
|
372
|
|
|
} |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
// Document |
|
376
|
|
|
$output = executeQuery('document.insertDocument', $obj); |
|
|
|
|
|
|
377
|
|
|
} |
|
378
|
|
|
} |
|
379
|
|
|
} |
|
380
|
|
|
FileHandler::removeFile($guestbook_file); |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
return $idx-1; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
/** |
|
387
|
|
|
* Insert textyle guest book |
|
388
|
|
|
* @param object $val |
|
389
|
|
|
* @param int $module_srl |
|
390
|
|
|
* @param object $member_info |
|
391
|
|
|
* @param int $textyle_guestbook_srl |
|
392
|
|
|
* @param int $parent_srl |
|
393
|
|
|
* @param int $author_xml_id |
|
394
|
|
|
* @return int|bool |
|
395
|
|
|
*/ |
|
396
|
|
|
function insertTextyleGuestbookItem($val, $module_srl, $member_info, $textyle_guestbook_srl,$parent_srl = 0, $author_xml_id=null) |
|
397
|
|
|
{ |
|
398
|
|
|
$tobj = null; |
|
399
|
|
|
if($textyle_guestbook_srl>0) |
|
400
|
|
|
{ |
|
401
|
|
|
$tobj->textyle_guestbook_srl = $textyle_guestbook_srl; |
|
402
|
|
|
} |
|
403
|
|
|
else |
|
404
|
|
|
{ |
|
405
|
|
|
$tobj->textyle_guestbook_srl = getNextSequence(); |
|
406
|
|
|
} |
|
407
|
|
|
$tobj->module_srl = $module_srl; |
|
408
|
|
|
$tobj->is_secret = $val->secret->body=='1'?1:-1; |
|
409
|
|
|
$tobj->content = nl2br($val->content->body); |
|
410
|
|
View Code Duplication |
if($author_xml_id && $val->commenter->attrs->id == $author_xml_id) |
|
|
|
|
|
|
411
|
|
|
{ |
|
412
|
|
|
$tobj->password = ''; |
|
413
|
|
|
$tobj->nick_name = $member_info->nick_name; |
|
414
|
|
|
$tobj->user_name = $member_info->user_name; |
|
415
|
|
|
$tobj->user_id = $member_info->user_id; |
|
416
|
|
|
$tobj->member_srl = $member_info->member_srl; |
|
417
|
|
|
$tobj->homepage = $member_info->homepage; |
|
418
|
|
|
$tobj->email_address = $member_info->email_address; |
|
419
|
|
|
} |
|
420
|
|
|
else |
|
421
|
|
|
{ |
|
422
|
|
|
$tobj->password = $val->password->body; |
|
423
|
|
|
$tobj->nick_name = $val->commenter->name->body; |
|
424
|
|
|
$tobj->homepage = $val->commenter->homepage->body; |
|
425
|
|
|
$tobj->member_srl = 0; |
|
426
|
|
|
} |
|
427
|
|
|
$tobj->last_update = $tobj->regdate = date("YmdHis",$val->written->body); |
|
428
|
|
|
$tobj->ipaddress = $val->commenter->ip->body; |
|
429
|
|
|
|
|
430
|
|
|
if($parent_srl>0) |
|
431
|
|
|
{ |
|
432
|
|
|
$tobj->parent_srl = $parent_srl; |
|
433
|
|
|
$tobj->list_order = $tobj->parent_srl * -1; |
|
434
|
|
|
} |
|
435
|
|
|
else |
|
436
|
|
|
{ |
|
437
|
|
|
$tobj->list_order = $tobj->textyle_guestbook_srl*-1; |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
$output = executeQuery('textyle.insertTextyleGuestbook', $tobj); |
|
441
|
|
|
|
|
442
|
|
|
if($output->toBool()) return $tobj->textyle_guestbook_srl; |
|
443
|
|
|
return false; |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
/** |
|
447
|
|
|
* Attachment |
|
448
|
|
|
* @param resource $fp |
|
449
|
|
|
* @param int $module_srl |
|
450
|
|
|
* @param int $upload_target_srl |
|
451
|
|
|
* @param array $files |
|
452
|
|
|
* @param string $buff |
|
453
|
|
|
* @return bool |
|
454
|
|
|
*/ |
|
455
|
|
|
function importAttaches($fp, $module_srl, $upload_target_srl, &$files, $buff) |
|
456
|
|
|
{ |
|
457
|
|
|
$uploaded_count = 0; |
|
458
|
|
|
|
|
459
|
|
|
$file_obj = null; |
|
460
|
|
|
$file_obj->file_srl = getNextSequence(); |
|
461
|
|
|
$file_obj->upload_target_srl = $upload_target_srl; |
|
462
|
|
|
$file_obj->module_srl = $module_srl; |
|
463
|
|
|
|
|
464
|
|
|
while(!feof($fp)) |
|
465
|
|
|
{ |
|
466
|
|
|
$str = fgets($fp, 1024); |
|
467
|
|
|
// If it ends with </attaches>, break |
|
468
|
|
|
if(trim($str) == '</attachment>') break; |
|
469
|
|
|
// If it starts with <file>, handle the attachement in the xml file |
|
470
|
|
|
if(substr($str, 0, 9)=='<content>') |
|
471
|
|
|
{ |
|
472
|
|
|
$file_obj->file = $this->saveTemporaryFile($fp, $str); |
|
473
|
|
|
continue; |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
$buff .= $str; |
|
477
|
|
|
} |
|
478
|
|
|
if(!file_exists($file_obj->file)) return false; |
|
479
|
|
|
|
|
480
|
|
|
$buff .= '</attachment>'; |
|
481
|
|
|
|
|
482
|
|
|
$xmlDoc = $this->oXmlParser->parse($buff); |
|
483
|
|
|
|
|
484
|
|
|
$file_obj->source_filename = $xmlDoc->attachment->label->body; |
|
485
|
|
|
$file_obj->download_count = $xmlDoc->attachment->downloads->body; |
|
486
|
|
|
$name = $xmlDoc->attachment->name->body; |
|
487
|
|
|
// Set upload path by checking if the attachement is an image or other kind of file |
|
488
|
|
|
if(preg_match("/\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp1|mp2|mp3|mp4|asf|wav|asx|mid|midi|asf|mov|moov|qt|rm|ram|ra|rmm|m4v)$/i", $file_obj->source_filename)) |
|
489
|
|
|
{ |
|
490
|
|
|
$path = sprintf("./files/attach/images/%s/%s", $module_srl,getNumberingPath($upload_target_srl,3)); |
|
491
|
|
|
$filename = $path.$file_obj->source_filename; |
|
492
|
|
|
$file_obj->direct_download = 'Y'; |
|
493
|
|
|
} |
|
494
|
|
|
else |
|
495
|
|
|
{ |
|
496
|
|
|
$path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); |
|
497
|
|
|
$filename = $path.md5(crypt(rand(1000000,900000), rand(0,100))); |
|
498
|
|
|
$file_obj->direct_download = 'N'; |
|
499
|
|
|
} |
|
500
|
|
|
// Create a directory |
|
501
|
|
|
if(!FileHandler::makeDir($path)) return; |
|
|
|
|
|
|
502
|
|
|
|
|
503
|
|
|
FileHandler::rename($file_obj->file, $filename); |
|
504
|
|
|
// Insert to the DB |
|
505
|
|
|
unset($file_obj->file); |
|
506
|
|
|
$file_obj->uploaded_filename = $filename; |
|
507
|
|
|
$file_obj->file_size = filesize($filename); |
|
508
|
|
|
$file_obj->comment = NULL; |
|
509
|
|
|
$file_obj->member_srl = 0; |
|
510
|
|
|
$file_obj->sid = md5(rand(rand(1111111,4444444),rand(4444445,9999999))); |
|
511
|
|
|
$file_obj->isvalid = 'Y'; |
|
512
|
|
|
$output = executeQuery('file.insertFile', $file_obj); |
|
513
|
|
|
|
|
514
|
|
|
if($output->toBool()) |
|
515
|
|
|
{ |
|
516
|
|
|
$uploaded_count++; |
|
517
|
|
|
$tmp_obj = null; |
|
|
|
|
|
|
518
|
|
View Code Duplication |
if($file_obj->direct_download == 'Y') $files[$name]->url = $file_obj->uploaded_filename; |
|
519
|
|
|
else $files[$name]->url = getUrl('','module','file','act','procFileDownload','file_srl',$file_obj->file_srl,'sid',$file_obj->sid); |
|
520
|
|
|
$files[$name]->direct_download = $file_obj->direct_download; |
|
521
|
|
|
$files[$name]->source_filename = $file_obj->source_filename; |
|
522
|
|
|
return true; |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
return false; |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
/** |
|
529
|
|
|
* Return a filename to temporarily use |
|
530
|
|
|
* @return string |
|
531
|
|
|
*/ |
|
532
|
|
View Code Duplication |
function getTmpFilename() |
|
|
|
|
|
|
533
|
|
|
{ |
|
534
|
|
|
$path = "./files/cache/importer"; |
|
535
|
|
|
if(!is_dir($path)) FileHandler::makeDir($path); |
|
536
|
|
|
$filename = sprintf("%s/%d", $path, rand(11111111,99999999)); |
|
537
|
|
|
if(file_exists($filename)) $filename .= rand(111,999); |
|
538
|
|
|
return $filename; |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
/** |
|
542
|
|
|
* Read buff until key value comes out from a specific file point |
|
543
|
|
|
* @param resource $fp |
|
544
|
|
|
* @param string $buff |
|
545
|
|
|
* @return string |
|
546
|
|
|
*/ |
|
547
|
|
View Code Duplication |
function saveTemporaryFile($fp, $buff) |
|
|
|
|
|
|
548
|
|
|
{ |
|
549
|
|
|
$temp_filename = $this->getTmpFilename(); |
|
550
|
|
|
$buff = substr($buff, 9); |
|
551
|
|
|
|
|
552
|
|
|
while(!feof($fp)) |
|
553
|
|
|
{ |
|
554
|
|
|
$str = trim(fgets($fp, 1024)); |
|
555
|
|
|
$buff .= $str; |
|
556
|
|
|
if(substr($str, -10) == '</content>') break; |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
$buff = substr($buff, 0, -10); |
|
560
|
|
|
|
|
561
|
|
|
$f = fopen($temp_filename, "w"); |
|
562
|
|
|
fwrite($f, base64_decode($buff)); |
|
563
|
|
|
fclose($f); |
|
564
|
|
|
return $temp_filename; |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
/** |
|
568
|
|
|
* Replace img tag in the ttxml |
|
569
|
|
|
* @param array $matches |
|
570
|
|
|
* @return string |
|
571
|
|
|
*/ |
|
572
|
|
|
function _replaceTTAttach($matches) |
|
573
|
|
|
{ |
|
574
|
|
|
$name = $matches[2]; |
|
575
|
|
|
if(!$name) return $matches[0]; |
|
576
|
|
|
|
|
577
|
|
|
$obj = $this->files[$name]; |
|
578
|
|
|
// If multimedia file is, |
|
579
|
|
|
if($obj->direct_download == 'Y') |
|
580
|
|
|
{ |
|
581
|
|
|
// If image file is |
|
582
|
|
|
if(preg_match('/\.(jpg|gif|jpeg|png)$/i', $obj->source_filename)) |
|
583
|
|
|
{ |
|
584
|
|
|
return sprintf('<img editor_component="image_link" src="%s" alt="%s" />', $obj->url, str_replace('"','\\"',$matches[4])); |
|
585
|
|
|
// If other multimedia file but image is, |
|
586
|
|
|
} |
|
587
|
|
|
else |
|
588
|
|
|
{ |
|
589
|
|
|
return sprintf('<img src="./common/img/blank.gif" editor_component="multimedia_link" multimedia_src="%s" width="400" height="320" style="display:block;width:400px;height:320px;border:2px dotted #4371B9;background:url(./modules/editor/components/multimedia_link/tpl/multimedia_link_component.gif) no-repeat center;" auto_start="false" alt="" />', $obj->url); |
|
590
|
|
|
} |
|
591
|
|
|
// If binary file is |
|
592
|
|
|
} |
|
593
|
|
|
else |
|
594
|
|
|
{ |
|
595
|
|
|
return sprintf('<a href="%s">%s</a>', $obj->url, $obj->source_filename); |
|
596
|
|
|
} |
|
597
|
|
|
} |
|
598
|
|
|
|
|
599
|
|
|
/** |
|
600
|
|
|
* Convert the video file |
|
601
|
|
|
* @return string |
|
602
|
|
|
*/ |
|
603
|
|
|
function _replaceTTMovie($matches) |
|
604
|
|
|
{ |
|
605
|
|
|
$key = $matches[1]; |
|
606
|
|
|
if(!$key) return $matches[0]; |
|
607
|
|
|
|
|
608
|
|
|
return |
|
609
|
|
|
'<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="402">'. |
|
610
|
|
|
'<param name="movie" value="http://flvs.daum.net/flvPlayer.swf?vid='.urlencode($key).'"/>'. |
|
611
|
|
|
'<param name="allowScriptAccess" value="always"/>'. |
|
612
|
|
|
'<param name="allowFullScreen" value="true"/>'. |
|
613
|
|
|
'<param name="bgcolor" value="#000000"/>'. |
|
614
|
|
|
'<embed src="http://flvs.daum.net/flvPlayer.swf?vid='.urlencode($key).'" width="100%" height="402" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" bgcolor="#000000"/>'. |
|
615
|
|
|
'</object>'; |
|
616
|
|
|
} |
|
617
|
|
|
|
|
618
|
|
|
/** |
|
619
|
|
|
* Comment |
|
620
|
|
|
* @param object $val |
|
621
|
|
|
* @param int $module_srl |
|
622
|
|
|
* @param int $document_srl |
|
623
|
|
|
* @param object $member_info |
|
624
|
|
|
* @param int $parent_srl |
|
625
|
|
|
* @param int $author_xml_id |
|
626
|
|
|
* @return bool|int|object |
|
627
|
|
|
*/ |
|
628
|
|
|
function insertComment($val, $module_srl, $document_srl, $member_info, $parent_srl = 0, $author_xml_id) |
|
629
|
|
|
{ |
|
630
|
|
|
$tobj = null; |
|
631
|
|
|
$tobj->comment_srl = getNextSequence(); |
|
632
|
|
|
$tobj->module_srl = $module_srl; |
|
633
|
|
|
$tobj->document_srl = $document_srl; |
|
634
|
|
|
$tobj->is_secret = $val->secret->body=='1'?'Y':'N'; |
|
635
|
|
|
$tobj->notify_message = 'N'; |
|
636
|
|
|
$tobj->content = nl2br($val->content->body); |
|
637
|
|
|
$tobj->voted_count = 0; |
|
638
|
|
|
$tobj->status = 1; |
|
639
|
|
View Code Duplication |
if($author_xml_id && $val->commenter->attrs->id == $author_xml_id) |
|
640
|
|
|
{ |
|
641
|
|
|
$tobj->password = ''; |
|
642
|
|
|
$tobj->nick_name = $member_info->nick_name; |
|
643
|
|
|
$tobj->user_name = $member_info->user_name; |
|
644
|
|
|
$tobj->user_id = $member_info->user_id; |
|
645
|
|
|
$tobj->member_srl = $member_info->member_srl; |
|
646
|
|
|
$tobj->homepage = $member_info->homepage; |
|
647
|
|
|
$tobj->email_address = $member_info->email_address; |
|
648
|
|
|
} |
|
649
|
|
|
else |
|
650
|
|
|
{ |
|
651
|
|
|
$tobj->password = $val->password->body; |
|
652
|
|
|
$tobj->nick_name = $val->commenter->name->body; |
|
653
|
|
|
$tobj->homepage = $val->commenter->homepage->body; |
|
654
|
|
|
$tobj->member_srl = 0; |
|
655
|
|
|
} |
|
656
|
|
|
$tobj->last_update = $tobj->regdate = date("YmdHis",$val->written->body); |
|
657
|
|
|
$tobj->ipaddress = $val->commenter->ip->body; |
|
658
|
|
|
$tobj->list_order = $tobj->comment_srl*-1; |
|
659
|
|
|
$tobj->sequence = $sequence; |
|
|
|
|
|
|
660
|
|
|
$tobj->parent_srl = $parent_srl; |
|
661
|
|
|
// Comment list first |
|
662
|
|
|
$list_args = new stdClass; |
|
663
|
|
|
$list_args->comment_srl = $tobj->comment_srl; |
|
664
|
|
|
$list_args->document_srl = $tobj->document_srl; |
|
665
|
|
|
$list_args->module_srl = $tobj->module_srl; |
|
666
|
|
|
$list_args->regdate = $tobj->regdate; |
|
667
|
|
|
// Set data directly if parent comment doesn't exist |
|
668
|
|
View Code Duplication |
if(!$tobj->parent_srl) |
|
669
|
|
|
{ |
|
670
|
|
|
$list_args->head = $list_args->arrange = $tobj->comment_srl; |
|
671
|
|
|
$list_args->depth = 0; |
|
672
|
|
|
// Get parent_srl if parent comment exists |
|
673
|
|
|
} |
|
674
|
|
|
else |
|
675
|
|
|
{ |
|
676
|
|
|
// Get parent_srl |
|
677
|
|
|
$parent_args->comment_srl = $tobj->parent_srl; |
|
|
|
|
|
|
678
|
|
|
$parent_output = executeQuery('comment.getCommentListItem', $parent_args); |
|
679
|
|
|
// Return if parent comment doesn't exist |
|
680
|
|
|
if(!$parent_output->toBool() || !$parent_output->data) return false; |
|
681
|
|
|
$parent = $parent_output->data; |
|
682
|
|
|
|
|
683
|
|
|
$list_args->head = $parent->head; |
|
684
|
|
|
$list_args->depth = $parent->depth+1; |
|
685
|
|
|
if($list_args->depth<2) $list_args->arrange = $tobj->comment_srl; |
|
686
|
|
|
else |
|
687
|
|
|
{ |
|
688
|
|
|
$list_args->arrange = $parent->arrange; |
|
689
|
|
|
$output = executeQuery('comment.updateCommentListArrange', $list_args); |
|
690
|
|
|
if(!$output->toBool()) return $output; |
|
691
|
|
|
} |
|
692
|
|
|
} |
|
693
|
|
|
|
|
694
|
|
|
$output = executeQuery('comment.insertCommentList', $list_args); |
|
695
|
|
|
if($output->toBool()) |
|
696
|
|
|
{ |
|
697
|
|
|
$output = executeQuery('comment.insertComment', $tobj); |
|
698
|
|
|
if($output->toBool()) return $tobj->comment_srl; |
|
699
|
|
|
} |
|
700
|
|
|
return false; |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
/** |
|
704
|
|
|
* List category |
|
705
|
|
|
* @param object $obj |
|
706
|
|
|
* @param array $category |
|
707
|
|
|
* @param int $idx |
|
708
|
|
|
* @param int $parent |
|
709
|
|
|
* @return void |
|
710
|
|
|
*/ |
|
711
|
|
|
function arrangeCategory($obj, &$category, &$idx, $parent = 0) |
|
712
|
|
|
{ |
|
713
|
|
|
if(!$obj->category) return; |
|
714
|
|
|
if(!is_array($obj->category)) $c = array($obj->category); |
|
715
|
|
|
else $c = $obj->category; |
|
716
|
|
|
foreach($c as $val) |
|
717
|
|
|
{ |
|
718
|
|
|
$idx++; |
|
719
|
|
|
$priority = $val->priority->body; |
|
720
|
|
|
$name = $val->name->body; |
|
721
|
|
|
$obj = null; |
|
722
|
|
|
$obj->priority = $priority; |
|
723
|
|
|
$obj->name = $name; |
|
724
|
|
|
$obj->sequence = $idx; |
|
725
|
|
|
$obj->parent = $parent; |
|
726
|
|
|
|
|
727
|
|
|
$category[$idx] = $obj; |
|
728
|
|
|
|
|
729
|
|
|
$this->arrangeCategory($val, $category, $idx, $idx); |
|
730
|
|
|
} |
|
731
|
|
|
} |
|
732
|
|
|
} |
|
733
|
|
|
/* End of file ttimport.class.php */ |
|
734
|
|
|
/* Location: ./modules/importer/ttimport.class.php */ |
|
735
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: