GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( d80144...902697 )
by gyeong-won
12:23
created

ttimport::importModule()   F

Complexity

Conditions 75
Paths 1152

Size

Total Lines 351
Code Lines 219

Duplication

Lines 51
Ratio 14.53 %

Importance

Changes 0
Metric Value
cc 75
eloc 219
nc 1152
nop 8
dl 51
loc 351
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
@set_time_limit(0);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
4
@require_once('./modules/importer/extract.class.php');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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();
0 ignored issues
show
Unused Code introduced by
$category_list is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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();
0 ignored issues
show
Unused Code introduced by
$category_list is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
$tag is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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'];
0 ignored issues
show
Bug introduced by
The variable $_REMOTE does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
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;
0 ignored issues
show
Bug introduced by
The property files does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like $parent_srl defined by $this->insertComment($va...nfo, 0, $author_xml_id) on line 224 can also be of type null or object; however, ttimport::insertComment() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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;
0 ignored issues
show
Bug introduced by
The variable $args does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
244
				$args->module_srl = $obj->module_srl;
245
				$args->logs = serialize(null);
246
				$output = executeQuery('textyle.insertPublishLog', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
311
							}
312
						}
313
314
						$result = $this->insertTextyleGuestbookItem($val, $module_srl, $member_info,$textyle_guestbook_srl,0,$author_xml_id);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
$homepage is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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)
0 ignored issues
show
Bug Best Practice introduced by
The expression $author_xml_id of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression \FileHandler::makeDir($path) of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
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;
0 ignored issues
show
Unused Code introduced by
$tmp_obj is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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;
0 ignored issues
show
Bug introduced by
The variable $sequence does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
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;
0 ignored issues
show
Bug introduced by
The variable $parent_args does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
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