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

documentItem::getThumbnail()   F

Complexity

Conditions 35
Paths 3896

Size

Total Lines 139
Code Lines 71

Duplication

Lines 86
Ratio 61.87 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 35
eloc 71
nc 3896
nop 3
dl 86
loc 139
rs 2
c 4
b 0
f 0

How to fix   Long Method    Complexity   

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:

1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * documentItem class
5
 * document object
6
 *
7
 * @author NAVER ([email protected])
8
 * @package /modules/document
9
 * @version 0.1
10
 */
11
class documentItem extends Object
12
{
13
	/**
14
	 * Document number
15
	 * @var int
16
	 */
17
	var $document_srl = 0;
18
	/**
19
	 * Language code
20
	 * @var string
21
	 */
22
	var $lang_code = null;
23
	/**
24
	 * Status of allow trackback
25
	 * @var bool
26
	 */
27
	var $allow_trackback_status = null;
28
	/**
29
	 * column list
30
	 * @var array
31
	 */
32
	var $columnList = array();
33
	/**
34
	 * allow script access list
35
	 * @var array
36
	 */
37
	var $allowscriptaccessList = array();
38
	/**
39
	 * allow script access key
40
	 * @var int
41
	 */
42
	var $allowscriptaccessKey = 0;
43
	/**
44
	 * upload file list
45
	 * @var array
46
	 */
47
	var $uploadedFiles = array();
48
49
	/**
50
	 * Constructor
51
	 * @param int $document_srl
52
	 * @param bool $load_extra_vars
53
	 * @param array columnList
54
	 * @return void
55
	 */
56
	function documentItem($document_srl = 0, $load_extra_vars = true, $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...
57
	{
58
		$this->document_srl = $document_srl;
59
		$this->columnList = $columnList;
60
61
		$this->_loadFromDB($load_extra_vars);
62
	}
63
64
	function setDocument($document_srl, $load_extra_vars = true)
65
	{
66
		$this->document_srl = $document_srl;
67
		$this->_loadFromDB($load_extra_vars);
68
	}
69
70
	/**
71
	 * Get data from database, and set the value to documentItem object
72
	 * @param bool $load_extra_vars
73
	 * @return void
74
	 */
75
	function _loadFromDB($load_extra_vars = true)
76
	{
77
		if(!$this->document_srl) return;
78
79
		$document_item = false;
80
		$cache_put = false;
0 ignored issues
show
Unused Code introduced by
$cache_put 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...
81
		$columnList = array();
82
		$this->columnList = array();
83
84
		// cache controll
85
		$oCacheHandler = CacheHandler::getInstance('object');
86
		if($oCacheHandler->isSupport())
87
		{
88
			$cache_key = 'document_item:' . getNumberingPath($this->document_srl) . $this->document_srl;
89
			$document_item = $oCacheHandler->get($cache_key);
90
			if($document_item !== false)
91
			{
92
				$columnList = array('readed_count', 'voted_count', 'blamed_count', 'comment_count', 'trackback_count');
93
			}
94
		}
95
96
		$args = new stdClass();
97
		$args->document_srl = $this->document_srl;
98
		$output = executeQuery('document.getDocument', $args, $columnList);
99
100
		if($document_item === false)
101
		{
102
			$document_item = $output->data;
103
104
				//insert in cache
105
			if($document_item && $oCacheHandler->isSupport())
106
			{
107
				$oCacheHandler->put($cache_key, $document_item);
0 ignored issues
show
Bug introduced by
The variable $cache_key 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...
108
			}
109
		}
110
		else
111
		{
112
			$document_item->readed_count = $output->data->readed_count;
113
			$document_item->voted_count = $output->data->voted_count;
114
			$document_item->blamed_count = $output->data->blamed_count;
115
			$document_item->comment_count = $output->data->comment_count;
116
			$document_item->trackback_count = $output->data->trackback_count;
117
		}
118
119
		$this->setAttribute($document_item, $load_extra_vars);
120
	}
121
122
	function setAttribute($attribute, $load_extra_vars=true)
123
	{
124
		if(!$attribute->document_srl)
125
		{
126
			$this->document_srl = null;
127
			return;
128
		}
129
		$this->document_srl = $attribute->document_srl;
130
		$this->lang_code = $attribute->lang_code;
131
		$this->adds($attribute);
132
133
		// Tags
134
		if($this->get('tags'))
135
		{
136
			$tag_list = explode(',', $this->get('tags'));
137
			$tag_list = array_map('trim', $tag_list);
138
			$this->add('tag_list', $tag_list);
139
		}
140
141
		$oDocumentModel = getModel('document');
142
		if($load_extra_vars)
143
		{
144
			$GLOBALS['XE_DOCUMENT_LIST'][$attribute->document_srl] = $this;
145
			$oDocumentModel->setToAllDocumentExtraVars();
146
		}
147
		$GLOBALS['XE_DOCUMENT_LIST'][$this->document_srl] = $this;
148
	}
149
150
	function isExists()
151
	{
152
		return $this->document_srl ? true : false;
153
	}
154
155
	function isGranted()
156
	{
157
		if($_SESSION['own_document'][$this->document_srl]) return true;
158
159
		if(!Context::get('is_logged')) return false;
160
161
		$logged_info = Context::get('logged_info');
162
		if($logged_info->is_admin == 'Y') return true;
163
164
		$oModuleModel = getModel('module');
165
		$grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($this->get('module_srl')), $logged_info);
166
		if($grant->manager) return true;
167
168 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)) return true;
169
170
		return false;
171
	}
172
173
	function setGrant()
174
	{
175
		$_SESSION['own_document'][$this->document_srl] = true;
176
	}
177
178
	function isAccessible()
179
	{
180
		return $_SESSION['accessible'][$this->document_srl]==true?true:false;
181
	}
182
183
	function allowComment()
184
	{
185
		// init write, document is not exists. so allow comment status is true
186
		if(!$this->isExists()) return true;
187
188
		return $this->get('comment_status') == 'ALLOW' ? true : false;
189
	}
190
191
	function allowTrackback()
192
	{
193
		static $allow_trackback_status = null;
194
		if(is_null($allow_trackback_status))
195
		{
196
			
197
			// Check the tarckback module exist
198
			if(!getClass('trackback'))
199
			{
200
				$allow_trackback_status = false;
201
			}
202
			else
203
			{
204
				// If the trackback module is configured to be disabled, do not allow. Otherwise, check the setting of each module.
205
				$oModuleModel = getModel('module');
206
				$trackback_config = $oModuleModel->getModuleConfig('trackback');
207
				
208
				if(!$trackback_config)
209
				{
210
					$trackback_config = new stdClass();
211
				}
212
				
213
				if(!isset($trackback_config->enable_trackback)) $trackback_config->enable_trackback = 'Y';
214
				if($trackback_config->enable_trackback != 'Y') $allow_trackback_status = false;
215
				else
216
				{
217
					$module_srl = $this->get('module_srl');
218
					// Check settings of each module
219
					$module_config = $oModuleModel->getModulePartConfig('trackback', $module_srl);
220
					if($module_config->enable_trackback == 'N') $allow_trackback_status = false;
221
					else if($this->get('allow_trackback')=='Y' || !$this->isExists()) $allow_trackback_status = true;
222
				}
223
			}
224
		}
225
		return $allow_trackback_status;
226
	}
227
228
	function isLocked()
229
	{
230
		if(!$this->isExists()) return false;
231
232
		return $this->get('comment_status') == 'ALLOW' ? false : true;
233
	}
234
235
	function isEditable()
236
	{
237
		if($this->isGranted() || !$this->get('member_srl')) return true;
238
		return false;
239
	}
240
241
	function isSecret()
242
	{
243
		$oDocumentModel = getModel('document');
244
		return $this->get('status') == $oDocumentModel->getConfigStatus('secret') ? true : false;
245
	}
246
247
	function isNotice()
248
	{
249
		return $this->get('is_notice') == 'Y' ? true : false;
250
	}
251
252
	function useNotify()
253
	{
254
		return $this->get('notify_message')=='Y' ? true : false;
255
	}
256
257
	function doCart()
258
	{
259
		if(!$this->document_srl) return false;
260
		if($this->isCarted()) $this->removeCart();
261
		else $this->addCart();
262
	}
263
264
	function addCart()
265
	{
266
		$_SESSION['document_management'][$this->document_srl] = true;
267
	}
268
269
	function removeCart()
270
	{
271
		unset($_SESSION['document_management'][$this->document_srl]);
272
	}
273
274
	function isCarted()
275
	{
276
		return $_SESSION['document_management'][$this->document_srl];
277
	}
278
279
	/**
280
	 * Send notify message to document owner
281
	 * @param string $type
282
	 * @param string $content
283
	 * @return void
284
	 */
285
	function notify($type, $content)
286
	{
287
		if(!$this->document_srl) return;
288
		// return if it is not useNotify
289
		if(!$this->useNotify()) return;
290
		// Pass if an author is not a logged-in user
291
		if(!$this->get('member_srl')) return;
292
		// Return if the currently logged-in user is an author
293
		$logged_info = Context::get('logged_info');
294
		if($logged_info->member_srl == $this->get('member_srl')) return;
295
		// List variables
296
		if($type) $title = "[".$type."] ";
297
		$title .= cut_str(strip_tags($content), 10, '...');
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...
298
		$content = sprintf('%s<br /><br />from : <a href="%s" target="_blank">%s</a>',$content, getFullUrl('','document_srl',$this->document_srl), getFullUrl('','document_srl',$this->document_srl));
299
		$receiver_srl = $this->get('member_srl');
300
		$sender_member_srl = $logged_info->member_srl;
301
		// Send a message
302
		$oCommunicationController = getController('communication');
303
		$oCommunicationController->sendMessage($sender_member_srl, $receiver_srl, $title, $content, false);
304
	}
305
306
	function getLangCode()
307
	{
308
		return $this->get('lang_code');
309
	}
310
311 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...
312
	{
313
		if($this->isGranted())
314
		{
315
			return $this->get('ipaddress');
316
		}
317
318
		return '*' . strstr($this->get('ipaddress'), '.');
319
	}
320
321
	function isExistsHomepage()
322
	{
323
		if(trim($this->get('homepage'))) return true;
324
		return false;
325
	}
326
327
	function getHomepageUrl()
328
	{
329
		$url = trim($this->get('homepage'));
330
		if(!$url) return;
331
332 View Code Duplication
		if(strncasecmp('http://', $url, 7) !== 0 && strncasecmp('https://', $url, 8) !== 0)  $url = 'http://' . $url;
333
334
		return $url;
335
	}
336
337
	function getMemberSrl()
338
	{
339
		return $this->get('member_srl');
340
	}
341
342
	function getUserID()
343
	{
344
		return htmlspecialchars($this->get('user_id'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
345
	}
346
347
	function getUserName()
348
	{
349
		return htmlspecialchars($this->get('user_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
350
	}
351
352
	function getNickName()
353
	{
354
		return htmlspecialchars($this->get('nick_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
355
	}
356
357
	function getLastUpdater()
358
	{
359
		return htmlspecialchars($this->get('last_updater'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
360
	}
361
362
	function getTitleText($cut_size = 0, $tail='...')
363
	{
364
		if(!$this->document_srl) return;
365
366
		if($cut_size) $title = cut_str($this->get('title'), $cut_size, $tail);
367
		else $title = $this->get('title');
368
369
		return $title;
370
	}
371
372
	function getTitle($cut_size = 0, $tail='...')
373
	{
374
		if(!$this->document_srl) return;
375
376
		$title = $this->getTitleText($cut_size, $tail);
377
378
		$attrs = array();
379
		$this->add('title_color', trim($this->get('title_color')));
380
		if($this->get('title_bold')=='Y') $attrs[] = "font-weight:bold;";
381
		if($this->get('title_color') && $this->get('title_color') != 'N') $attrs[] = "color:#".$this->get('title_color');
382
383
		if(count($attrs)) return sprintf("<span style=\"%s\">%s</span>", implode(';',$attrs), htmlspecialchars($title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false));
384
		else return htmlspecialchars($title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
385
	}
386
387
	function getContentText($strlen = 0)
388
	{
389
		if(!$this->document_srl) return;
390
391
		if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return Context::getLang('msg_is_secret');
392
393
		$result = $this->_checkAccessibleFromStatus();
394
		if($result) $_SESSION['accessible'][$this->document_srl] = true;
395
396
		$content = $this->get('content');
397
		$content = preg_replace_callback('/<(object|param|embed)[^>]*/is', array($this, '_checkAllowScriptAccess'), $content);
398
		$content = preg_replace_callback('/<object[^>]*>/is', array($this, '_addAllowScriptAccess'), $content);
399
400
		if($strlen) return cut_str(strip_tags($content),$strlen,'...');
401
402
		return htmlspecialchars($content);
403
	}
404
405 View Code Duplication
	function _addAllowScriptAccess($m)
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...
406
	{
407
		if($this->allowscriptaccessList[$this->allowscriptaccessKey] == 1)
408
		{
409
			$m[0] = $m[0].'<param name="allowscriptaccess" value="never"></param>';
410
		}
411
		$this->allowscriptaccessKey++;
412
		return $m[0];
413
	}
414
415 View Code Duplication
	function _checkAllowScriptAccess($m)
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...
416
	{
417
		if($m[1] == 'object')
418
		{
419
			$this->allowscriptaccessList[] = 1;
420
		}
421
422
		if($m[1] == 'param')
423
		{
424
			if(stripos($m[0], 'allowscriptaccess'))
425
			{
426
				$m[0] = '<param name="allowscriptaccess" value="never"';
427
				if(substr($m[0], -1) == '/')
428
				{
429
					$m[0] .= '/';
430
				}
431
				$this->allowscriptaccessList[count($this->allowscriptaccessList)-1]--;
432
			}
433
		}
434
		else if($m[1] == 'embed')
435
		{
436
			if(stripos($m[0], 'allowscriptaccess'))
437
			{
438
				$m[0] = preg_replace('/always|samedomain/i', 'never', $m[0]);
439
			}
440
			else
441
			{
442
				$m[0] = preg_replace('/\<embed/i', '<embed allowscriptaccess="never"', $m[0]);
443
			}
444
		}
445
		return $m[0];
446
	}
447
448
	function getContent($add_popup_menu = true, $add_content_info = true, $resource_realpath = false, $add_xe_content_class = true, $stripEmbedTagException = false)
449
	{
450
		if(!$this->document_srl) return;
451
452
		if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return Context::getLang('msg_is_secret');
453
454
		$result = $this->_checkAccessibleFromStatus();
455
		if($result) $_SESSION['accessible'][$this->document_srl] = true;
456
457
		$content = $this->get('content');
458
		if(!$stripEmbedTagException) stripEmbedTagForAdmin($content, $this->get('member_srl'));
459
460
		// Define a link if using a rewrite module
461
		$oContext = &Context::getInstance();
462
		if($oContext->allow_rewrite)
463
		{
464
			$content = preg_replace('/<a([ \t]+)href=("|\')\.\/\?/i',"<a href=\\2". Context::getRequestUri() ."?", $content);
465
		}
466
		// To display a pop-up menu
467
		if($add_popup_menu)
468
		{
469
			$content = sprintf(
470
				'%s<div class="document_popup_menu"><a href="#popup_menu_area" class="document_%d" onclick="return false">%s</a></div>',
471
				$content,
472
				$this->document_srl, Context::getLang('cmd_document_do')
473
			);
474
		}
475
		// If additional content information is set
476 View Code Duplication
		if($add_content_info)
477
		{
478
			$memberSrl = $this->get('member_srl');
479
			if($memberSrl < 0)
480
			{
481
				$memberSrl = 0;
482
			}
483
			$content = sprintf(
484
				'<!--BeforeDocument(%d,%d)--><div class="document_%d_%d xe_content">%s</div><!--AfterDocument(%d,%d)-->',
485
				$this->document_srl, $memberSrl,
486
				$this->document_srl, $memberSrl,
487
				$content,
488
				$this->document_srl, $memberSrl,
489
				$this->document_srl, $memberSrl
490
			);
491
			// Add xe_content class although accessing content is not required
492
		}
493
		else
494
		{
495
			if($add_xe_content_class) $content = sprintf('<div class="xe_content">%s</div>', $content);
496
		}
497
		// Change the image path to a valid absolute path if resource_realpath is true
498
		if($resource_realpath)
499
		{
500
			$content = preg_replace_callback('/<img([^>]+)>/i',array($this,'replaceResourceRealPath'), $content);
501
		}
502
503
		return $content;
504
	}
505
506
	/**
507
	 * Return transformed content by Editor codes
508
	 * @param bool $add_popup_menu
509
	 * @param bool $add_content_info
510
	 * @param bool $resource_realpath
511
	 * @param bool $add_xe_content_class
512
	 * @return string
513
	 */
514
	function getTransContent($add_popup_menu = true, $add_content_info = true, $resource_realpath = false, $add_xe_content_class = true)
515
	{
516
		$oEditorController = getController('editor');
517
518
		$content = $this->getContent($add_popup_menu, $add_content_info, $resource_realpath, $add_xe_content_class);
519
		$content = $oEditorController->transComponent($content);
520
521
		return $content;
522
	}
523
524 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...
525
	{
526
		$content = $this->getContent(FALSE, FALSE);
527
		
528
		$content = nl2br($content);
529
530
		// For a newlink, inert a whitespace
531
		$content = preg_replace('!(<br[\s]*/{0,1}>[\s]*)+!is', ' ', $content);
532
533
		// Replace tags such as </p> , </div> , </li> and others to a whitespace
534
		$content = str_replace(array('</p>', '</div>', '</li>', '-->'), ' ', $content);
535
536
		// Remove Tags
537
		$content = preg_replace('!<([^>]*?)>!is', '', $content);
538
539
		// Replace < , >, "
540
		$content = str_replace(array('&lt;', '&gt;', '&quot;', '&nbsp;'), array('<', '>', '"', ' '), $content);
541
542
		// Delete  a series of whitespaces
543
		$content = preg_replace('/ ( +)/is', ' ', $content);
544
545
		// Truncate string
546
		$content = trim(cut_str($content, $str_size, $tail));
547
548
		// Replace back < , <, "
549
		$content = str_replace(array('<', '>', '"'),array('&lt;', '&gt;', '&quot;'), $content);
550
551
		return $content;
552
	}
553
554
	function getRegdate($format = 'Y.m.d H:i:s')
555
	{
556
		return zdate($this->get('regdate'), $format);
557
	}
558
559 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...
560
	{
561
		$regdate = $this->get('regdate');
562
		$year = substr($regdate,0,4);
563
		$month = substr($regdate,4,2);
564
		$day = substr($regdate,6,2);
565
		$hour = substr($regdate,8,2);
566
		$min = substr($regdate,10,2);
567
		$sec = substr($regdate,12,2);
568
		return mktime($hour,$min,$sec,$month,$day,$year);
569
	}
570
571
	function getRegdateGM()
572
	{
573
		return $this->getRegdate('D, d M Y H:i:s').' '.$GLOBALS['_time_zone'];
574
	}
575
576
	function getRegdateDT()
577
	{
578
		return $this->getRegdate('Y-m-d').'T'.$this->getRegdate('H:i:s').substr($GLOBALS['_time_zone'],0,3).':'.substr($GLOBALS['_time_zone'],3,2);
579
	}
580
581
	function getUpdate($format = 'Y.m.d H:i:s')
582
	{
583
		return zdate($this->get('last_update'), $format);
584
	}
585
586 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...
587
	{
588
		$year = substr($this->get('last_update'),0,4);
589
		$month = substr($this->get('last_update'),4,2);
590
		$day = substr($this->get('last_update'),6,2);
591
		$hour = substr($this->get('last_update'),8,2);
592
		$min = substr($this->get('last_update'),10,2);
593
		$sec = substr($this->get('last_update'),12,2);
594
		return mktime($hour,$min,$sec,$month,$day,$year);
595
	}
596
597
	function getUpdateGM()
598
	{
599
		return gmdate("D, d M Y H:i:s", $this->getUpdateTime());
600
	}
601
602
	function getUpdateDT()
603
	{
604
		return $this->getUpdate('Y-m-d').'T'.$this->getUpdate('H:i:s').substr($GLOBALS['_time_zone'],0,3).':'.substr($GLOBALS['_time_zone'],3,2);
605
	}
606
607
	function getPermanentUrl()
608
	{
609
		return getFullUrl('','document_srl',$this->get('document_srl'));
610
	}
611
612
	function getTrackbackUrl()
613
	{
614
		if(!$this->document_srl) return;
615
616
		// Generate a key to prevent spams
617
		$oTrackbackModel = getModel('trackback');
618
		if($oTrackbackModel) return $oTrackbackModel->getTrackbackUrl($this->document_srl, $this->getDocumentMid());
0 ignored issues
show
Bug introduced by
The method getTrackbackUrl() does not seem to exist on object<ModuleObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
619
	}
620
621
	/**
622
	 * Update readed count
623
	 * @return void
624
	 */
625
	function updateReadedCount()
626
	{
627
		$oDocumentController = getController('document');
628
		if($oDocumentController->updateReadedCount($this))
629
		{
630
			$readed_count = $this->get('readed_count');
631
			$this->add('readed_count', $readed_count+1);
632
		}
633
	}
634
635
	function isExtraVarsExists()
636
	{
637
		if(!$this->get('module_srl')) return false;
638
		$oDocumentModel = getModel('document');
639
		$extra_keys = $oDocumentModel->getExtraKeys($this->get('module_srl'));
640
		return count($extra_keys)?true:false;
641
	}
642
643
	function getExtraVars()
644
	{
645
		if(!$this->get('module_srl') || !$this->document_srl) return null;
646
647
		$oDocumentModel = getModel('document');
648
		return $oDocumentModel->getExtraVars($this->get('module_srl'), $this->document_srl);
649
	}
650
651 View Code Duplication
	function getExtraValue($idx)
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...
652
	{
653
		$extra_vars = $this->getExtraVars();
654
		if(is_array($extra_vars) && array_key_exists($idx,$extra_vars))
655
		{
656
			return $extra_vars[$idx]->getValue();
657
		}
658
		else
659
		{
660
			return '';
661
		}
662
	}
663
664 View Code Duplication
	function getExtraValueHTML($idx)
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...
665
	{
666
		$extra_vars = $this->getExtraVars();
667
		if(is_array($extra_vars) && array_key_exists($idx,$extra_vars))
668
		{
669
			return $extra_vars[$idx]->getValueHTML();
670
		}
671
		else
672
		{
673
			return '';
674
		}
675
	}
676
677 View Code Duplication
	function getExtraEidValue($eid)
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...
678
	{
679
		$extra_vars = $this->getExtraVars();
680
681
		if($extra_vars)
682
		{
683
			// Handle extra variable(eid)
684
			foreach($extra_vars as $idx => $key)
685
			{
686
				$extra_eid[$key->eid] = $key;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$extra_eid was never initialized. Although not strictly required by PHP, it is generally a good practice to add $extra_eid = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
687
			}
688
		}
689
		
690
		if(is_array($extra_eid) && array_key_exists($eid,$extra_eid))
691
		{
692
			return $extra_eid[$eid]->getValue();
0 ignored issues
show
Bug introduced by
The variable $extra_eid 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...
693
		}
694
		else
695
		{
696
			return '';
697
		}
698
	}
699
700 View Code Duplication
	function getExtraEidValueHTML($eid)
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...
701
	{
702
		$extra_vars = $this->getExtraVars();
703
		// Handle extra variable(eid)
704
		foreach($extra_vars as $idx => $key)
705
		{
706
			$extra_eid[$key->eid] = $key;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$extra_eid was never initialized. Although not strictly required by PHP, it is generally a good practice to add $extra_eid = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
707
		}
708
		
709
		if(is_array($extra_eid) && array_key_exists($eid,$extra_eid))
710
		{
711
			return $extra_eid[$eid]->getValueHTML();
0 ignored issues
show
Bug introduced by
The variable $extra_eid 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...
712
		}
713
		else
714
		{
715
			return '';
716
		}
717
	}
718
719
	function getExtraVarsValue($key)
720
	{
721
		$extra_vals = unserialize($this->get('extra_vars'));
722
		$val = $extra_vals->$key;
723
		return $val;
724
	}
725
726
	function getCommentCount()
727
	{
728
		return $this->get('comment_count');
729
	}
730
731
	function getComments()
732
	{
733
		if(!$this->getCommentCount()) return;
734
		if(!$this->isGranted() && $this->isSecret()) return;
735
		// cpage is a number of comment pages
736
		$cpageStr = sprintf('%d_cpage', $this->document_srl);
737
		$cpage = Context::get($cpageStr);
738
739
		if(!$cpage)
740
		{
741
			$cpage = Context::get('cpage');
742
		}
743
744
		// Get a list of comments
745
		$oCommentModel = getModel('comment');
746
		$output = $oCommentModel->getCommentList($this->document_srl, $cpage, $is_admin);
0 ignored issues
show
Bug introduced by
The variable $is_admin 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...
747
		if(!$output->toBool() || !count($output->data)) return;
748
		// Create commentItem object from a comment list
749
		// If admin priviledge is granted on parent posts, you can read its child posts.
750
		$accessible = array();
751
		$comment_list = array();
752
		foreach($output->data as $key => $val)
753
		{
754
			$oCommentItem = new commentItem();
755
			$oCommentItem->setAttribute($val);
756
			// If permission is granted to the post, you can access it temporarily
757
			if($oCommentItem->isGranted()) $accessible[$val->comment_srl] = true;
758
			// If the comment is set to private and it belongs child post, it is allowable to read the comment for who has a admin privilege on its parent post
759
			if($val->parent_srl>0 && $val->is_secret == 'Y' && !$oCommentItem->isAccessible() && $accessible[$val->parent_srl]===true)
760
			{
761
				$oCommentItem->setAccessible();
762
			}
763
			$comment_list[$val->comment_srl] = $oCommentItem;
764
		}
765
		// Variable setting to be displayed on the skin
766
		Context::set($cpageStr, $output->page_navigation->cur_page);
767
		Context::set('cpage', $output->page_navigation->cur_page);
768
		if($output->total_page>1) $this->comment_page_navigation = $output->page_navigation;
0 ignored issues
show
Bug introduced by
The property comment_page_navigation 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...
769
770
		return $comment_list;
771
	}
772
773
	function getTrackbackCount()
774
	{
775
		return $this->get('trackback_count');
776
	}
777
778
	function getTrackbacks()
779
	{
780
		if(!$this->document_srl) return;
781
782
		if(!$this->allowTrackback() || !$this->get('trackback_count')) return;
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->allowTrackback() 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...
783
784
		$oTrackbackModel = getModel('trackback');
785
		return $oTrackbackModel->getTrackbackList($this->document_srl, $is_admin);
0 ignored issues
show
Bug introduced by
The variable $is_admin 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...
Bug introduced by
The method getTrackbackList() does not seem to exist on object<ModuleObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
786
	}
787
788
	function thumbnailExists($width = 80, $height = 0, $type = '')
789
	{
790
		if(!$this->document_srl) return false;
791
		if(!$this->getThumbnail($width, $height, $type)) return false;
792
		return true;
793
	}
794
795
	function getThumbnail($width = 80, $height = 0, $thumbnail_type = '')
796
	{
797
		// Return false if the document doesn't exist
798
		if(!$this->document_srl) return;
799
800
		if($this->isSecret() && !$this->isGranted())
801
		{
802
			return;
803
		}
804
805
		// If not specify its height, create a square
806
		if(!$height) $height = $width;
807
808
		// Return false if neither attachement nor image files in the document
809
		$content = $this->get('content');
810 View Code Duplication
		if(!$this->get('uploaded_count'))
811
		{
812
			if(!$content)
813
			{
814
				$args = new stdClass();
815
				$args->document_srl = $this->document_srl;
816
				$output = executeQuery('document.getDocument', $args, array('content'));
817
				if($output->toBool() && $output->data)
818
				{
819
					$content = $output->data->content;
820
					$this->add('content', $content);
821
				}
822
			}
823
824
			if(!preg_match("!<img!is", $content)) return;
825
		}
826
		// Get thumbnai_type information from document module's configuration
827
		if(!in_array($thumbnail_type, array('crop','ratio')))
828
		{
829
			$config = $GLOBALS['__document_config__'];
830
			if(!$config)
831
			{
832
				$oDocumentModel = getModel('document');
833
				$config = $oDocumentModel->getDocumentConfig();
834
				$GLOBALS['__document_config__'] = $config;
835
			}
836
			$thumbnail_type = $config->thumbnail_type;
837
		}
838
		// Define thumbnail information
839
		$thumbnail_path = sprintf('files/thumbnails/%s',getNumberingPath($this->document_srl, 3));
840
		$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
841
		$thumbnail_url  = Context::getRequestUri().$thumbnail_file;
842
		// Return false if thumbnail file exists and its size is 0. Otherwise, return its path
843 View Code Duplication
		if(file_exists($thumbnail_file))
844
		{
845
			if(filesize($thumbnail_file)<1) return false;
846
			else return $thumbnail_url;
847
		}
848
849
		// Target File
850
		$source_file = null;
851
		$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...
852
853
		// Find an iamge file among attached files if exists
854 View Code Duplication
		if($this->hasUploadedFiles())
855
		{
856
			$file_list = $this->getUploadedFiles();
857
858
			$first_image = null;
859
			foreach($file_list as $file)
860
			{
861
				if($file->direct_download !== 'Y') continue;
862
863
				if($file->cover_image === 'Y' && file_exists($file->uploaded_filename))
864
				{
865
					$source_file = $file->uploaded_filename;
866
					break;
867
				}
868
869
				if($first_image) continue;
870
871
				if(preg_match("/\.(jpe?g|png|gif|bmp)$/i", $file->source_filename))
872
				{
873
					if(file_exists($file->uploaded_filename))
874
					{
875
						$first_image = $file->uploaded_filename;
876
					}
877
				}
878
			}
879
880
			if(!$source_file && $first_image)
881
			{
882
				$source_file = $first_image;
883
			}
884
		}
885
		// If not exists, file an image file from the content
886
		$is_tmp_file = false;
887 View Code Duplication
		if(!$source_file)
888
		{
889
			$random = new Password();
890
891
			preg_match_all("!<img[^>]*src=(?:\"|\')([^\"\']*?)(?:\"|\')!is", $content, $matches, PREG_SET_ORDER);
892
893
			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...
894
			{
895
				$target_src = trim($target_image[1]);
896
				if(preg_match('/\/(common|modules|widgets|addons|layouts|m\.layouts)\//i', $target_src)) continue;
897
898
				if(!preg_match('/^(http|https):\/\//i',$target_src))
899
				{
900
					$target_src = Context::getRequestUri().$target_src;
901
				}
902
903
				$target_src = htmlspecialchars_decode($target_src);
904
905
				$tmp_file = _XE_PATH_ . 'files/cache/tmp/' . $random->createSecureSalt(32, 'hex');
906
				FileHandler::getRemoteFile($target_src, $tmp_file);
907
				if(!file_exists($tmp_file)) continue;
908
909
				$imageinfo = getimagesize($tmp_file);
910
				list($_w, $_h) = $imageinfo;
911
				if($imageinfo === false || ($_w < ($width * 0.3) && $_h < ($height * 0.3))) {
912
					FileHandler::removeFile($tmp_file);
913
					continue;
914
				}
915
916
				$source_file = $tmp_file;
917
				$is_tmp_file = true;
918
				break;
919
			}
920
		}
921
922
		if($source_file)
923
		{
924
			$output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
925
		}
926
		if($is_tmp_file) FileHandler::removeFile($source_file);
927
		// Return its path if a thumbnail is successfully genetated
928
		if($output) return $thumbnail_url;
0 ignored issues
show
Bug introduced by
The variable $output 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...
929
		// Create an empty file not to re-generate the thumbnail
930
		else FileHandler::writeFile($thumbnail_file, '','w');
931
932
		return;
933
	}
934
935
	/**
936
	 * Functions to display icons for new post, latest update, secret(private) post, image/video/attachment
937
	 * Determine new post and latest update by $time_interval
938
	 * @param int $time_interval
939
	 * @return array
940
	 */
941
	function getExtraImages($time_interval = 43200)
942
	{
943
		if(!$this->document_srl) return;
944
		// variables for icon list
945
		$buffs = array();
946
947
		$check_files = false;
0 ignored issues
show
Unused Code introduced by
$check_files 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...
948
949
		// Check if secret post is
950
		if($this->isSecret()) $buffs[] = "secret";
951
952
		// Set the latest time
953
		$time_check = date("YmdHis", $_SERVER['REQUEST_TIME']-$time_interval);
954
955
		// Check new post
956
		if($this->get('regdate')>$time_check) $buffs[] = "new";
957
		else if($this->get('last_update')>$time_check) $buffs[] = "update";
958
959
		/*
960
		   $content = $this->get('content');
961
962
		// Check image files
963
		preg_match_all('!<img([^>]*?)>!is', $content, $matches);
964
		$cnt = count($matches[0]);
965
		for($i=0;$i<$cnt;$i++) {
966
		if(preg_match('/editor_component=/',$matches[0][$i])&&!preg_match('/image_(gallery|link)/i',$matches[0][$i])) continue;
967
		$buffs[] = "image";
968
		$check_files = true;
969
		break;
970
		}
971
972
		// Check video files
973
		if(preg_match('!<embed([^>]*?)>!is', $content) || preg_match('/editor_component=("|\')*multimedia_link/i', $content) ) {
974
		$buffs[] = "movie";
975
		$check_files = true;
976
		}
977
		 */
978
979
		// Check the attachment
980
		if($this->hasUploadedFiles()) $buffs[] = "file";
981
982
		return $buffs;
983
	}
984
985
	function getStatus()
986
	{
987
		if(!$this->get('status')) return $this->getDefaultStatus();
0 ignored issues
show
Bug introduced by
The method getDefaultStatus() does not seem to exist on object<documentItem>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
988
		return $this->get('status');
989
	}
990
991
	/**
992
	 * Return the value obtained from getExtraImages with image tag
993
	 * @param int $time_check
994
	 * @return string
995
	 */
996
	function printExtraImages($time_check = 43200)
997
	{
998
		if(!$this->document_srl) return;
999
		// Get the icon directory
1000
		$path = sprintf('%s%s',getUrl(), 'modules/document/tpl/icons/');
1001
1002
		$buffs = $this->getExtraImages($time_check);
1003
		if(!count($buffs)) return;
1004
1005
		$buff = array();
1006
		foreach($buffs as $key => $val)
0 ignored issues
show
Bug introduced by
The expression $buffs of type null|array 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...
1007
		{
1008
			$buff[] = sprintf('<img src="%s%s.gif" alt="%s" title="%s" style="margin-right:2px;" />', $path, $val, $val, $val);
1009
		}
1010
		return implode('', $buff);
1011
	}
1012
1013 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...
1014
	{
1015
		if(!$this->document_srl) return;
1016
1017
		if($this->isSecret() && !$this->isGranted()) return false;
1018
		return $this->get('uploaded_count')? true : false;
1019
	}
1020
1021
	function getUploadedFiles($sortIndex = 'file_srl')
1022
	{
1023
		if(!$this->document_srl) return;
1024
1025
		if($this->isSecret() && !$this->isGranted()) return;
1026
		if(!$this->get('uploaded_count')) return;
1027
1028
		if(!$this->uploadedFiles[$sortIndex])
1029
		{
1030
			$oFileModel = getModel('file');
1031
			$this->uploadedFiles[$sortIndex] = $oFileModel->getFiles($this->document_srl, array(), $sortIndex, true);
1032
		}
1033
1034
		return $this->uploadedFiles[$sortIndex];
1035
	}
1036
1037
	/**
1038
	 * Return Editor html
1039
	 * @return string
1040
	 */
1041 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...
1042
	{
1043
		$module_srl = $this->get('module_srl');
1044
		if(!$module_srl) $module_srl = Context::get('module_srl');
1045
1046
		$oEditorModel = getModel('editor');
1047
		return $oEditorModel->getModuleEditor('document', $module_srl, $this->document_srl, 'document_srl', 'content');
1048
	}
1049
1050
	/**
1051
	 * Check whether to have a permission to write comment
1052
	 * Authority to write a comment and to write a document is separated
1053
	 * @return bool
1054
	 */
1055
	function isEnableComment()
1056
	{
1057
		// Return false if not authorized, if a secret document, if the document is set not to allow any comment
1058
		if (!$this->allowComment()) return false;
1059
		if(!$this->isGranted() && $this->isSecret()) return false;
1060
1061
		return true;
1062
	}
1063
1064
	/**
1065
	 * Return comment editor's html
1066
	 * @return string
1067
	 */
1068
	function getCommentEditor()
1069
	{
1070
		if(!$this->isEnableComment()) return;
1071
1072
		$oEditorModel = getModel('editor');
1073
		return $oEditorModel->getModuleEditor('comment', $this->get('module_srl'), $comment_srl, 'comment_srl', 'content');
0 ignored issues
show
Bug introduced by
The variable $comment_srl 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...
1074
	}
1075
1076
	/**
1077
	 * Return author's profile image
1078
	 * @return string
1079
	 */
1080 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...
1081
	{
1082
		if(!$this->isExists() || !$this->get('member_srl')) return;
1083
		$oMemberModel = getModel('member');
1084
		$profile_info = $oMemberModel->getProfileImage($this->get('member_srl'));
1085
		if(!$profile_info) return;
1086
1087
		return $profile_info->src;
1088
	}
1089
1090
	/**
1091
	 * Return author's signiture
1092
	 * @return string
1093
	 */
1094 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...
1095
	{
1096
		// Pass if a document doesn't exist
1097
		if(!$this->isExists() || !$this->get('member_srl')) return;
1098
		// Get signature information
1099
		$oMemberModel = getModel('member');
1100
		$signature = $oMemberModel->getSignature($this->get('member_srl'));
1101
		// Check if a maximum height of signiture is set in the member module
1102
		if(!isset($GLOBALS['__member_signature_max_height']))
1103
		{
1104
			$oModuleModel = getModel('module');
1105
			$member_config = $oModuleModel->getModuleConfig('member');
1106
			$GLOBALS['__member_signature_max_height'] = $member_config->signature_max_height;
1107
		}
1108
		if($signature)
1109
		{
1110
			$max_signature_height = $GLOBALS['__member_signature_max_height'];
1111
			if($max_signature_height) $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);
1112
		}
1113
1114
		return $signature;
1115
	}
1116
1117
	/**
1118
	 * Change an image path in the content to absolute path
1119
	 * @param array $matches
1120
	 * @return mixed
1121
	 */
1122
	function replaceResourceRealPath($matches)
1123
	{
1124
		return preg_replace('/src=(["\']?)files/i','src=$1'.Context::getRequestUri().'files', $matches[0]);
1125
	}
1126
1127
	/**
1128
	 * Check accessible by document status
1129
	 * @param array $matches
0 ignored issues
show
Bug introduced by
There is no parameter named $matches. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1130
	 * @return mixed
1131
	 */
1132
	function _checkAccessibleFromStatus()
1133
	{
1134
		$logged_info = Context::get('logged_info');
1135
		if($logged_info->is_admin == 'Y') return true;
1136
1137
		$status = $this->get('status');
1138
		if(empty($status)) return false;
1139
1140
		$oDocumentModel = getModel('document');
1141
		$configStatusList = $oDocumentModel->getStatusList();
1142
1143
		if($status == $configStatusList['public'] || $status == $configStatusList['publish'])
1144
			return true;
1145
		else if($status == $configStatusList['private'] || $status == $configStatusList['secret'])
1146
		{
1147
			if($this->get('member_srl') == $logged_info->member_srl)
1148
				return true;
1149
		}
1150
		return false;
1151
	}
1152
1153
	function getTranslationLangCodes()
1154
	{
1155
		$obj = new stdClass;
1156
		$obj->document_srl = $this->document_srl;
1157
		// -2 is an index for content. We are interested if content has other translations.
1158
		$obj->var_idx = -2;
1159
		$output = executeQueryArray('document.getDocumentTranslationLangCodes', $obj);
1160
1161
		if (!$output->data)
1162
		{
1163
			$output->data = array();
1164
		}
1165
		// add original page's lang code as well
1166
		$origLangCode = new stdClass;
1167
		$origLangCode->lang_code = $this->getLangCode();
1168
		$output->data[] = $origLangCode;
1169
1170
		return $output->data;
1171
	}
1172
1173
1174
	/**
1175
	 * Returns the document's mid in order to construct SEO friendly URLs
1176
	 * @return string
1177
	 */
1178
	function getDocumentMid()
1179
	{
1180
		$model = getModel('module');
1181
		$module = $model->getModuleInfoByModuleSrl($this->get('module_srl'));
1182
		return $module->mid;
1183
	}
1184
1185
	/**
1186
	 * Returns the document's type (document/page/wiki/board/etc)
1187
	 * @return string
1188
	 */
1189
	function getDocumentType()
1190
	{
1191
		$model = getModel('module');
1192
		$module = $model->getModuleInfoByModuleSrl($this->get('module_srl'));
1193
		return $module->module;
1194
	}
1195
1196
	/**
1197
	 * Returns the document's alias
1198
	 * @return string
1199
	 */
1200
	function getDocumentAlias()
1201
	{
1202
		$oDocumentModel = getModel('document');
1203
		return $oDocumentModel->getAlias($this->document_srl);
1204
	}
1205
1206
	/**
1207
	 * Returns the document's actual title (browser_title)
1208
	 * @return string
1209
	 */
1210
	function getModuleName()
1211
	{
1212
		$model = getModel('module');
1213
		$module = $model->getModuleInfoByModuleSrl($this->get('module_srl'));
1214
		return $module->browser_title;
1215
	}
1216
1217
	function getBrowserTitle()
1218
	{
1219
		return $this->getModuleName();
1220
	}
1221
}
1222
/* End of file document.item.php */
1223
/* Location: ./modules/document/document.item.php */
1224