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 ( 278e53...818459 )
by gyeong-won
39:17 queued 30:14
created

seoController::getBrowserTitle()   D

Complexity

Conditions 9
Paths 22

Size

Total Lines 37
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 27
nc 22
nop 1
dl 0
loc 37
rs 4.909
c 0
b 0
f 0
1
<?php
2
class seoController extends seo
3
{
4
	function getBrowserTitle($document_title = null)
5
	{
6
		$site_module_info = Context::get('site_module_info');
7
		if ($site_module_info->site_srl != 0) return Context::getBrowserTitle();
8
9
		$config = $this->getConfig();
10
		if ($config->use_optimize_title != 'Y') return Context::getBrowserTitle();
11
12
		$current_module_info = Context::get('current_module_info');
13
		$is_index = ($current_module_info->module_srl == $site_module_info->module_srl) ? true : false;
14
15
		$piece = array();
16
		$piece['[:site_name:]'] = $config->site_name;
17
		$piece['[:site_slogan:]'] = $config->site_slogan;
18
		$piece['[:module_title:]'] = $current_module_info->browser_title;
19
		if ($document_title) $piece['[:document_title:]'] = $document_title;
20
21
		if ($config->use_optimize_title == 'Y') {
22
			$title = array();
23
			if ($piece['[:document_title:]']) {
24
				$title[] = $piece['[:document_title:]'];
25
				$title[] = $piece['[:module_title:]'];
26
				$title[] = $piece['[:site_name:]'];
27
			} else {
28
				if ($is_index) {
29
					$title[] = $piece['[:site_name:]'];
30
					if ($piece['[:site_slogan:]']) $title[] = $piece['[:site_slogan:]'];
31
				} else {
32
					$title[] = $piece['[:module_title:]'];
33
					$title[] = $piece['[:site_name:]'];
34
				}
35
			}
36
			$title = implode(' - ', $title);
37
		}
38
39
		return $title;
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...
40
	}
41
42
	function triggerBeforeDisplay(&$output_content)
43
	{
44
		if (Context::getResponseMethod() != 'HTML') return;
45
		if (Context::get('module') == 'admin') return;
46
47
		require_once(_XE_PATH_ . 'libs/idna_convert/idna_convert.class.php');
48
49
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
50
51
		$locales = array(
52
			'de' => 'de_DE',
53
			'en' => 'en_US',
54
			'es' => 'es_ES',
55
			'fr' => 'fr_FR',
56
			'ja' => 'ja_JP',
57
			'jp' => 'ja_JP',
58
			'ko' => 'ko_KR',
59
			'mn' => 'mn_MN',
60
			'ru' => 'ru_RU',
61
			'tr' => 'tr_TR',
62
			'vi' => 'vi_VN',
63
			'zh-CN' => 'zh_CN',
64
			'zh-TW' => 'zh_TW',
65
		);
66
67
		$oModuleModel = getModel('module');
0 ignored issues
show
Unused Code introduced by
$oModuleModel 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...
68
		$config = $this->getConfig();
69
		$IDN = new idna_convert(array('idn_version' => 2008));
70
		$request_uri = $IDN->encode(Context::get('request_uri'));
71
72
		$logged_info = Context::get('logged_info');
0 ignored issues
show
Unused Code introduced by
$logged_info 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...
73
		$current_module_info = Context::get('current_module_info');
74
		$site_module_info = Context::get('site_module_info');
75
		$document_srl = Context::get('document_srl');
76
		$is_article = false;
77
		$single_image = false;
78
		$is_index = ($current_module_info->module_srl == $site_module_info->module_srl) ? true : false;
79
80
		$piece = new stdClass;
81
		$piece->document_title = null;
82
		$piece->type = 'website';
83
		$piece->url = getFullUrl('');
84
		$piece->title = Context::getBrowserTitle();
85
		$piece->description = $config->site_description;
86
		$piece->keywords = $config->site_keywords;
87
		$piece->tags = array();
88
		$piece->image = array();
89
		$piece->author = null;
90
91
		if(stristr($_SERVER['HTTP_USER_AGENT'], 'facebookexternalhit') != FALSE) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stristr($_SERVER['HTTP_U... 'facebookexternalhit') of type string to the boolean FALSE. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
92
			$single_image = true;
93
		}
94
95
		if ($document_srl) {
96
			$oDocument = Context::get('oDocument');
97
			if (!is_a($oDocument, 'documentItem')) {
98
				$oDocumentModel = getModel('document');
99
				$oDocument = $oDocumentModel->getDocument($document_srl);
100
			}
101
102
			if (is_a($oDocument, 'documentItem') && $document_srl == $oDocument->document_srl) {
103
				$is_article = true;
104
			}
105
		}
106
107
		// 문서 데이터 수집
108
		if ($is_article) {
109
			if (!$oDocument->isSecret()) {
110
				$piece->document_title = $oDocument->getTitleText();
0 ignored issues
show
Bug introduced by
The variable $oDocument 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...
111
				$piece->url = getFullUrl('', 'mid', $current_module_info->mid, 'document_srl',$document_srl);
112
				$piece->type = 'article';
113
				$piece->description = trim(str_replace('&nbsp;', ' ', $oDocument->getContentText(400)));
114
				$piece->author = $oDocument->getNickName();
115
				$tags = $oDocument->get('tag_list');
116
				if (count($tags)) $piece->tags = $tags;
117
118
				$document_images = false;
119
				if($oCacheHandler->isSupport()) {
120
					$cache_key_document_images = 'seo:document_images:' . $document_srl;
121
					$document_images = $oCacheHandler->get($cache_key_document_images);
122
				}
123
124
				if($document_images === false && $oDocument->hasUploadedFiles()) {
125
					$image_ext = array('bmp', 'gif', 'jpg', 'jpeg', 'png');
126
					$document_images = array();
127
128
					foreach ($oDocument->getUploadedFiles() as $file) {
129
						if ($file->isvalid != 'Y') continue;
130
131
						$ext = array_pop(explode('.', $file->uploaded_filename));
0 ignored issues
show
Bug introduced by
explode('.', $file->uploaded_filename) cannot be passed to array_pop() as the parameter $array expects a reference.
Loading history...
132
133
						if (!in_array(strtolower($ext), $image_ext)) continue;
134
						list($width, $height) = @getimagesize($file->uploaded_filename);
135
						if($width < 100 && $height < 100) continue;
136
137
						$image = array(
138
							'filepath' => $file->uploaded_filename,
139
							'width' => $width,
140
							'height' => $height
141
						);
142
143
						if($file->cover_image === 'Y') {
144
							array_unshift($document_images, $image);
145
						} else {
146
							$document_images[] = $image;
147
						}
148
					}
149
150
					if($oCacheHandler->isSupport()) {
151
						$oCacheHandler->put($cache_key_document_images, $document_images);
0 ignored issues
show
Bug introduced by
The variable $cache_key_document_images 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...
152
					}
153
				}
154
155
				if($document_images) $piece->image = $document_images;
156
			} else {
157
				$piece->url = getFullUrl('', 'mid', $current_module_info->mid);
158
			}
159
		} else {
160
			if (!$is_index) {
161
				$page = (Context::get('page') > 1) ? Context::get('page') : null;
162
				$piece->url = getNotEncodedFullUrl('mid', $current_module_info->mid, 'page',$page);
163
			}
164
		}
165
166
		$piece->title = $this->getBrowserTitle($piece->document_title);
167
168
		if($oCacheHandler->isSupport()) {
169
			$cache_key = 'seo:site_image';
170
			$site_image = $oCacheHandler->get($cache_key);
171
			if($site_image) {
172
				$site_image['url'] = $config->site_image_url;
173
			}
174
			$piece->image[] = $site_image;
175
		}
176
177
		$this->addLink('canonical', $piece->url);
178
		$this->addMeta('keywords', $piece->keywords, 'name');
179
		$this->addMeta('description', $piece->description, 'name');
180
181
		// Open Graph
182
		$this->addMeta('og:locale', $locales[Context::getLangType()]);
183
		$this->addMeta('og:type', $piece->type);
184
		$this->addMeta('og:url', $piece->url);
185
		$this->addMeta('og:site_name', $config->site_name);
186
		$this->addMeta('og:title', $piece->title);
187
		$this->addMeta('og:description', $piece->description);
188
		if($is_article) {
189
			if(Context::getLangType() !== $oDocument->getLangCode()) {
190
				$this->addMeta('og:locale:alternate', $locales[$oDocument->getLangCode()]);
191
			}
192
			$this->addMeta('article:published_time', $oDocument->getRegdate('c'));
193
			$this->addMeta('article:modified_time', $oDocument->getUpdate('c'));
194
			foreach ($piece->tags as $tag) {
195
				$this->addMeta('article:tag', $tag);
196
			}
197
		}
198
199
		foreach ($piece->image as $img) {
0 ignored issues
show
Bug introduced by
The expression $piece->image of type array|boolean 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...
200
			if(!$img['url']) {
201
				if(!$img['filepath']) continue;
202
				$img['url'] = $request_uri . $img['filepath'];
203
			}
204
205
			$this->addMeta('og:image', $img['url']);
206
			$this->addMeta('og:image:width', $img['width']);
207
			$this->addMeta('og:image:height', $img['height']);
208
			if($single_image) break;
209
		}
210
211
		$this->canonical_url = $piece->url;
212
213
		$this->applySEO();
214
215
		if ($config->use_optimize_title == 'Y') Context::setBrowserTitle($piece->title);
216
	}
217
218
	function triggerAfterFileDeleteFile($data)
219
	{
220
		$document_srl = $data->upload_target_srl;
221
		if(!$document_srl) return $this->makeObject();
222
223
		$this->deleteCacheDocumentImages($document_srl);
224
	}
225
226
	function triggerAfterDocumentUpdateDocument($data)
227
	{
228
		$document_srl = $data->document_srl;
229
		$this->deleteCacheDocumentImages($document_srl);
230
	}
231
232
	function triggerAfterDocumentDeleteDocument($data)
233
	{
234
		$document_srl = $data->document_srl;
235
		$this->deleteCacheDocumentImages($document_srl);
236
	}
237
238
	private function deleteCacheDocumentImages($document_srl)
239
	{
240
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
241
		if($oCacheHandler->isSupport()) {
242
			$cache_key_document_images = 'seo:document_images:' . $document_srl;
243
			$oCacheHandler->delete($cache_key_document_images);
244
		}
245
	}
246
}
247
/* !End of file */
248