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 — master ( b130b6...8a2f54 )
by gyeong-won
07:36
created

commentItem::getCommentMid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * commentItem class
6
 * comment BaseObject
7
 *
8
 * @author NAVER ([email protected])
9
 * @package /modules/comment
10
 * @version 0.1
11
 */
12
class commentItem extends BaseObject
13
{
14
15
	/**
16
	 * comment number
17
	 * @var int
18
	 */
19
	var $comment_srl = 0;
20
21
	/**
22
	 * Get the column list int the table
23
	 * @var array
24
	 */
25
	var $columnList = array();
26
27
	/**
28
	 * Constructor
29
	 * @param int $comment_srl
30
	 * @param array $columnList
31
	 * @return void
32
	 */
33
	function commentItem($comment_srl = 0, $columnList = array())
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
34
	{
35
		$this->comment_srl = $comment_srl;
36
		$this->columnList = $columnList;
37
		$this->_loadFromDB();
38
	}
39
40
	function setComment($comment_srl)
41
	{
42
		$this->comment_srl = $comment_srl;
43
		$this->_loadFromDB();
44
	}
45
46
	/**
47
	 * Load comment data from DB and set to commentItem object
48
	 * @return void
49
	 */
50
	function _loadFromDB()
51
	{
52
		if(!$this->comment_srl)
53
		{
54
			return;
55
		}
56
57
		$args = new stdClass();
58
		$args->comment_srl = $this->comment_srl;
59
		$output = executeQuery('comment.getComment', $args, $this->columnList);
60
61
		$this->setAttribute($output->data);
62
	}
63
64
	/**
65
	 * Comment attribute set to BaseObject object
66
	 * @return void
67
	 */
68
	function setAttribute($attribute)
69
	{
70
		if(!$attribute->comment_srl)
71
		{
72
			$this->comment_srl = NULL;
73
			return;
74
		}
75
76
		$this->comment_srl = $attribute->comment_srl;
77
		$this->adds($attribute);
78
79
		// define vars on the object for backward compatibility of skins
80
		if(count($attribute))
81
		{
82
			foreach($attribute as $key => $val)
83
			{
84
				$this->{$key} = $val;
85
			}
86
		}
87
	}
88
89
	function isExists()
90
	{
91
		return $this->comment_srl ? TRUE : FALSE;
92
	}
93
94
	function isGranted()
95
	{
96
		if($_SESSION['own_comment'][$this->comment_srl])
97
		{
98
			return TRUE;
99
		}
100
101
		if(!Context::get('is_logged'))
102
		{
103
			return FALSE;
104
		}
105
106
		$logged_info = Context::get('logged_info');
107
		if($logged_info->is_admin == 'Y')
108
		{
109
			return TRUE;
110
		}
111
112
		$grant = Context::get('grant');
113
		if($grant->manager)
114
		{
115
			return TRUE;
116
		}
117
118 View Code Duplication
		if($this->get('member_srl') && ($this->get('member_srl') == $logged_info->member_srl || $this->get('member_srl') * -1 == $logged_info->member_srl))
119
		{
120
			return TRUE;
121
		}
122
123
		return FALSE;
124
	}
125
126
	function setGrant()
127
	{
128
		$_SESSION['own_comment'][$this->comment_srl] = TRUE;
129
		$this->is_granted = TRUE;
0 ignored issues
show
Bug introduced by
The property is_granted 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...
130
	}
131
132
	function setAccessible()
133
	{
134
		$_SESSION['accessibled_comment'][$this->comment_srl] = TRUE;
135
	}
136
137
	function isEditable()
138
	{
139
		if($this->isGranted() || !$this->get('member_srl'))
140
		{
141
			return TRUE;
142
		}
143
		return FALSE;
144
	}
145
146
	function isSecret()
147
	{
148
		return $this->get('is_secret') == 'Y' ? TRUE : FALSE;
149
	}
150
151
	function isAccessible()
152
	{
153
		if($_SESSION['accessibled_comment'][$this->comment_srl])
154
		{
155
			return TRUE;
156
		}
157
158
		if($this->isGranted() || !$this->isSecret())
159
		{
160
			$this->setAccessible();
161
			return TRUE;
162
		}
163
164
		$oDocumentModel = getModel('document');
165
		$oDocument = $oDocumentModel->getDocument($this->get('document_srl'));
166
		if($oDocument->isGranted())
167
		{
168
			$this->setAccessible();
169
			return TRUE;
170
		}
171
172
		return FALSE;
173
	}
174
175
	function useNotify()
176
	{
177
		return $this->get('notify_message') == 'Y' ? TRUE : FALSE;
178
	}
179
180
	/**
181
	 * Notify to comment owner
182
	 * @return void
183
	 */
184
	function notify($type, $content)
185
	{
186
		// return if not useNotify
187
		if(!$this->useNotify())
188
		{
189
			return;
190
		}
191
192
		// pass if the author is not logged-in user 
193
		if(!$this->get('member_srl'))
194
		{
195
			return;
196
		}
197
198
		// return if the currently logged-in user is an author of the comment.
199
		$logged_info = Context::get('logged_info');
200
		if($logged_info->member_srl == $this->get('member_srl'))
201
		{
202
			return;
203
		}
204
205
		// get where the comment belongs to 
206
		$oDocumentModel = getModel('document');
207
		$oDocument = $oDocumentModel->getDocument($this->get('document_srl'));
0 ignored issues
show
Unused Code introduced by
$oDocument 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...
208
209
		// Variables
210
		if($type)
211
		{
212
			$title = "[" . $type . "] ";
213
		}
214
215
		$title .= cut_str(strip_tags($content), 30, '...');
0 ignored issues
show
Bug introduced by
The variable $title 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...
216
		$content = sprintf('%s<br /><br />from : <a href="%s#comment_%s" target="_blank">%s</a>', $content, getFullUrl('', 'document_srl', $this->get('document_srl')), $this->get('comment_srl'), getFullUrl('', 'document_srl', $this->get('document_srl')));
217
		$receiver_srl = $this->get('member_srl');
218
		$sender_member_srl = $logged_info->member_srl;
219
220
		// send a message
221
		$oCommunicationController = getController('communication');
222
		$oCommunicationController->sendMessage($sender_member_srl, $receiver_srl, $title, $content, FALSE);
223
	}
224
225 View Code Duplication
	function getIpAddress()
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...
226
	{
227
		if($this->isGranted())
228
		{
229
			return $this->get('ipaddress');
230
		}
231
232
		return '*' . strstr($this->get('ipaddress'), '.');
233
	}
234
235
	function isExistsHomepage()
236
	{
237
		if(trim($this->get('homepage')))
238
		{
239
			return TRUE;
240
		}
241
242
		return FALSE;
243
	}
244
245
	function getHomepageUrl()
246
	{
247
		$url = trim($this->get('homepage'));
248
		if(!$url)
249
		{
250
			return;
251
		}
252
253
		if(strncasecmp('http://', $url, 7) !== 0)
254
		{
255
			$url = "http://" . $url;
256
		}
257
258
		return htmlspecialchars($url, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
259
	}
260
261
	function getMemberSrl()
262
	{
263
		return $this->get('member_srl');
264
	}
265
266
	function getUserID()
267
	{
268
		return htmlspecialchars($this->get('user_id'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
269
	}
270
271
	function getUserName()
272
	{
273
		return htmlspecialchars($this->get('user_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
274
	}
275
276
	function getNickName()
277
	{
278
		return htmlspecialchars($this->get('nick_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
279
	}
280
281
	/**
282
	 * Return content with htmlspecialchars
283
	 * @return string
284
	 */
285
	function getContentText($strlen = 0)
286
	{
287
		if($this->isSecret() && !$this->isAccessible())
288
		{
289
			return Context::getLang('msg_is_secret');
290
		}
291
292
		$content = $this->get('content');
293
294
		if($strlen)
295
		{
296
			return cut_str(strip_tags($content), $strlen, '...');
297
		}
298
299
		return htmlspecialchars($content, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
300
	}
301
302
	/**
303
	 * Return content after filter
304
	 * @return string
305
	 */
306
	function getContent($add_popup_menu = TRUE, $add_content_info = TRUE, $add_xe_content_class = TRUE)
307
	{
308
		if($this->isSecret() && !$this->isAccessible())
309
		{
310
			return Context::getLang('msg_is_secret');
311
		}
312
313
		$content = $this->get('content');
314
		stripEmbedTagForAdmin($content, $this->get('member_srl'));
315
316
		// when displaying the comment on the pop-up menu
317
		if($add_popup_menu && Context::get('is_logged'))
318
		{
319
			$content = sprintf(
320
					'%s<div class="comment_popup_menu"><a href="#popup_menu_area" class="comment_%d" onclick="return false">%s</a></div>', $content, $this->comment_srl, Context::getLang('cmd_comment_do')
321
			);
322
		}
323
324
		// if additional information which can access contents is set
325 View Code Duplication
		if($add_content_info)
326
		{
327
			$memberSrl = $this->get('member_srl');
328
			if($memberSrl < 0)
329
			{
330
				$memberSrl = 0;
331
			}
332
			$content = sprintf(
333
					'<!--BeforeComment(%d,%d)--><div class="comment_%d_%d xe_content">%s</div><!--AfterComment(%d,%d)-->', $this->comment_srl, $memberSrl, $this->comment_srl, $memberSrl, $content, $this->comment_srl, $memberSrl
334
			);
335
			// xe_content class name should be specified although content access is not necessary.
336
		}
337
		else
338
		{
339
			if($add_xe_content_class)
340
			{
341
				$content = sprintf('<div class="xe_content">%s</div>', $content);
342
			}
343
		}
344
345
		return $content;
346
	}
347
348
	/**
349
	 * Return summary content
350
	 * @return string
351
	 */
352 View Code Duplication
	function getSummary($str_size = 50, $tail = '...')
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...
353
	{
354
		$content = $this->getContent(FALSE, FALSE);
355
356
		// for newline, insert a blank.
357
		$content = preg_replace('!(<br[\s]*/{0,1}>[\s]*)+!is', ' ', $content);
358
359
		// replace tags such as </p> , </div> , </li> by blanks.
360
		$content = str_replace(array('</p>', '</div>', '</li>', '-->'), ' ', $content);
361
362
		// Remove tags
363
		$content = preg_replace('!<([^>]*?)>!is', '', $content);
364
365
		// replace < , >, " 
366
		$content = str_replace(array('&lt;', '&gt;', '&quot;', '&nbsp;'), array('<', '>', '"', ' '), $content);
367
368
		// delete a series of blanks
369
		$content = preg_replace('/ ( +)/is', ' ', $content);
370
371
		// truncate strings
372
		$content = trim(cut_str($content, $str_size, $tail));
373
374
		// restore >, <, , "\
375
		$content = str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $content);
376
377
		return $content;
378
	}
379
380
	function getRegdate($format = 'Y.m.d H:i:s')
381
	{
382
		return zdate($this->get('regdate'), $format);
383
	}
384
385 View Code Duplication
	function getRegdateTime()
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...
386
	{
387
		$regdate = $this->get('regdate');
388
		$year = substr($regdate, 0, 4);
389
		$month = substr($regdate, 4, 2);
390
		$day = substr($regdate, 6, 2);
391
		$hour = substr($regdate, 8, 2);
392
		$min = substr($regdate, 10, 2);
393
		$sec = substr($regdate, 12, 2);
394
		return mktime($hour, $min, $sec, $month, $day, $year);
395
	}
396
397
	function getRegdateGM()
398
	{
399
		return $this->getRegdate('D, d M Y H:i:s') . ' ' . $GLOBALS['_time_zone'];
400
	}
401
402
	function getUpdate($format = 'Y.m.d H:i:s')
403
	{
404
		return zdate($this->get('last_update'), $format);
405
	}
406
407
	function getPermanentUrl()
408
	{
409
		return getFullUrl('', 'mid', $this->getCommentMid(), 'document_srl', $this->get('document_srl')) . '#comment_' . $this->get('comment_srl');
410
	}
411
412 View Code Duplication
	function getUpdateTime()
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...
413
	{
414
		$year = substr($this->get('last_update'), 0, 4);
415
		$month = substr($this->get('last_update'), 4, 2);
416
		$day = substr($this->get('last_update'), 6, 2);
417
		$hour = substr($this->get('last_update'), 8, 2);
418
		$min = substr($this->get('last_update'), 10, 2);
419
		$sec = substr($this->get('last_update'), 12, 2);
420
		return mktime($hour, $min, $sec, $month, $day, $year);
421
	}
422
423
	function getUpdateGM()
424
	{
425
		return gmdate("D, d M Y H:i:s", $this->getUpdateTime());
426
	}
427
428 View Code Duplication
	function hasUploadedFiles()
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...
429
	{
430
		if(($this->isSecret() && !$this->isAccessible()) && !$this->isGranted())
431
		{
432
			return FALSE;
433
		}
434
		return $this->get('uploaded_count') ? TRUE : FALSE;
435
	}
436
437
	function getUploadedFiles()
438
	{
439
		if(($this->isSecret() && !$this->isAccessible()) && !$this->isGranted())
440
		{
441
			return;
442
		}
443
444
		if(!$this->get('uploaded_count'))
445
		{
446
			return;
447
		}
448
449
		$oFileModel = getModel('file');
450
		$file_list = $oFileModel->getFiles($this->comment_srl, array(), 'file_srl', TRUE);
451
		return $file_list;
452
	}
453
454
	/**
455
	 * Return the editor html
456
	 * @return string
457
	 */
458 View Code Duplication
	function getEditor()
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...
459
	{
460
		$module_srl = $this->get('module_srl');
461
		if(!$module_srl)
462
		{
463
			$module_srl = Context::get('module_srl');
464
		}
465
		$oEditorModel = getModel('editor');
466
		return $oEditorModel->getModuleEditor('comment', $module_srl, $this->comment_srl, 'comment_srl', 'content');
467
	}
468
469
	/**
470
	 * Return author's profile image
471
	 * @return object
472
	 */
473 View Code Duplication
	function getProfileImage()
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...
474
	{
475
		if(!$this->isExists() || !$this->get('member_srl'))
476
		{
477
			return;
478
		}
479
		$oMemberModel = getModel('member');
480
		$profile_info = $oMemberModel->getProfileImage($this->get('member_srl'));
481
		if(!$profile_info)
482
		{
483
			return;
484
		}
485
486
		return $profile_info->src;
487
	}
488
489
	/**
490
	 * Return author's signiture
491
	 * @return string
492
	 */
493 View Code Duplication
	function getSignature()
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...
494
	{
495
		// pass if the posting not exists.
496
		if(!$this->isExists() || !$this->get('member_srl'))
497
		{
498
			return;
499
		}
500
501
		// get the signiture information
502
		$oMemberModel = getModel('member');
503
		$signature = $oMemberModel->getSignature($this->get('member_srl'));
504
505
		// check if max height of the signiture is specified on the member module
506
		if(!isset($GLOBALS['__member_signature_max_height']))
507
		{
508
			$oModuleModel = getModel('module');
509
			$member_config = $oModuleModel->getModuleConfig('member');
510
			$GLOBALS['__member_signature_max_height'] = $member_config->signature_max_height;
511
		}
512
513
		$max_signature_height = $GLOBALS['__member_signature_max_height'];
514
515
		if($max_signature_height)
516
		{
517
			$signature = sprintf('<div style="max-height:%dpx;overflow:auto;overflow-x:hidden;height:expression(this.scrollHeight > %d ? \'%dpx\': \'auto\')">%s</div>', $max_signature_height, $max_signature_height, $max_signature_height, $signature);
518
		}
519
520
		return $signature;
521
	}
522
523
	function thumbnailExists($width = 80, $height = 0, $type = '')
524
	{
525
		if(!$this->comment_srl)
526
		{
527
			return FALSE;
528
		}
529
530
		if(!$this->getThumbnail($width, $height, $type))
531
		{
532
			return FALSE;
533
		}
534
535
		return TRUE;
536
	}
537
538
	function getThumbnail($width = 80, $height = 0, $thumbnail_type = '')
539
	{
540
		// return false if no doc exists
541
		if(!$this->comment_srl)
542
		{
543
			return;
544
		}
545
546
		if($this->isSecret() && !$this->isGranted())
547
		{
548
			return;
549
		}
550
551
		// If signiture height setting is omitted, create a square
552
		if(!$height)
553
		{
554
			$height = $width;
555
		}
556
557
		$content = $this->get('content');
558 View Code Duplication
		if(!$this->hasUploadedFiles())
559
		{
560
			if(!$content)
561
			{
562
				$args = new stdClass();
563
				$args->comment_srl = $this->comment_srl;
564
				$output = executeQuery('document.getComment', $args, array('content'));
565
				if($output->toBool() && $output->data)
566
				{
567
					$content = $output->data->content;
568
					$this->add('content', $content);
569
				}
570
			}
571
572
			if(!preg_match("!<img!is", $content)) return;
573
		}
574
575
		// get thumbail generation info on the doc module configuration.
576
		if(!in_array($thumbnail_type, array('crop', 'ratio')))
577
		{
578
			$thumbnail_type = 'crop';
579
		}
580
581
		// Define thumbnail information
582
		$thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->comment_srl, 3));
583
		$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
584
		$thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type);
585
		$thumbnail_url = Context::getRequestUri() . $thumbnail_file;
586
587
		// return false if a size of existing thumbnail file is 0. otherwise return the file path
588 View Code Duplication
		if(file_exists($thumbnail_file) || file_exists($thumbnail_lockfile))
589
		{
590
			if(filesize($thumbnail_file) < 1)
591
			{
592
				return FALSE;
593
			}
594
			else
595
			{
596
				return $thumbnail_url;
597
			}
598
		}
599
600
		// Create lockfile to prevent race condition
601
		FileHandler::writeFile($thumbnail_lockfile, '', 'w');
602
603
		// Target file
604
		$source_file = NULL;
605
		$is_tmp_file = FALSE;
0 ignored issues
show
Unused Code introduced by
$is_tmp_file 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...
606
607
		// find an image file among attached files
608 View Code Duplication
		if($this->hasUploadedFiles())
609
		{
610
			$file_list = $this->getUploadedFiles();
611
612
			$first_image = null;
613
			foreach($file_list as $file)
614
			{
615
				if($file->direct_download !== 'Y') continue;
616
617
				if($file->cover_image === 'Y' && file_exists($file->uploaded_filename))
618
				{
619
					$source_file = $file->uploaded_filename;
620
					break;
621
				}
622
623
				if($first_image) continue;
624
625
				if(preg_match("/\.(jpe?g|png|gif|bmp)$/i", $file->source_filename))
626
				{
627
					if(file_exists($file->uploaded_filename))
628
					{
629
						$first_image = $file->uploaded_filename;
630
					}
631
				}
632
			}
633
634
			if(!$source_file && $first_image)
635
			{
636
				$source_file = $first_image;
637
			}
638
		}
639
640
		// get an image file from the doc content if no file attached. 
641
		$is_tmp_file = false;
642 View Code Duplication
		if(!$source_file)
643
		{
644
			$random = new Password();
645
646
			preg_match_all("!<img[^>]*src=(?:\"|\')([^\"\']*?)(?:\"|\')!is", $content, $matches, PREG_SET_ORDER);
647
648
			foreach($matches as $target_image)
0 ignored issues
show
Bug introduced by
The expression $matches of type null|array<integer,array<integer,string>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
649
			{
650
				$target_src = trim($target_image[1]);
651
				if(preg_match('/\/(common|modules|widgets|addons|layouts|m\.layouts)\//i', $target_src)) continue;
652
653
				if(!preg_match('/^(http|https):\/\//i',$target_src))
654
				{
655
					$target_src = Context::getRequestUri().$target_src;
656
				}
657
658
				$target_src = htmlspecialchars_decode($target_src);
659
660
				$tmp_file = _XE_PATH_ . 'files/cache/tmp/' . $random->createSecureSalt(32, 'hex');
661
				FileHandler::getRemoteFile($target_src, $tmp_file);
662
				if(!file_exists($tmp_file)) continue;
663
664
				$imageinfo = getimagesize($tmp_file);
665
				list($_w, $_h) = $imageinfo;
666
				if($imageinfo === false || ($_w < ($width * 0.3) && $_h < ($height * 0.3))) {
667
					FileHandler::removeFile($tmp_file);
668
					continue;
669
				}
670
671
				$source_file = $tmp_file;
672
				$is_tmp_file = true;
673
				break;
674
			}
675
		}
676
677
		$output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
678
679
		// Remove source file if it was temporary
680
		if($is_tmp_file)
681
		{
682
			FileHandler::removeFile($source_file);
683
		}
684
685
		// Remove lockfile
686
		FileHandler::removeFile($thumbnail_lockfile);
687
688
		// Return the thumbnail path if it was successfully generated
689
		if($output)
690
		{
691
			return $thumbnail_url;
692
		}
693
		// Create an empty file if thumbnail generation failed
694
		else
695
		{
696
			FileHandler::writeFile($thumbnail_file, '','w');
697
		}
698
699
		return;
700
	}
701
702
	function isCarted()
703
	{
704
		return $_SESSION['comment_management'][$this->comment_srl];
705
	}
706
	
707
	/**
708
	 * Returns the comment's mid in order to construct SEO friendly URLs
709
	 * @return string
710
	 */
711
	function getCommentMid()
712
	{
713
		$model = getModel('module');
714
		$module = $model->getModuleInfoByModuleSrl($this->get('module_srl'));
715
		return $module->mid;
716
	}
717
718
}
719
/* End of file comment.item.php */
720
/* Location: ./modules/comment/comment.item.php */
721