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
Pull Request — develop (#2395)
by звезда
12:21
created

seo::getConfig()   C

Complexity

Conditions 10
Paths 256

Size

Total Lines 39

Duplication

Lines 10
Ratio 25.64 %

Importance

Changes 0
Metric Value
cc 10
nc 256
nop 0
dl 10
loc 39
rs 6.1333
c 0
b 0
f 0

How to fix   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
class seo extends ModuleObject
3
{
4
	public $SEO = array(
5
		'link' => array(),
6
		'meta' => array()
7
	);
8
9
	protected $canonical_url;
10
11
	private $triggers = array(
12
		array('display', 'seo', 'controller', 'triggerBeforeDisplay', 'before'),
13
		array('file.deleteFile', 'seo', 'controller', 'triggerAfterFileDeleteFile', 'after'),
14
		array('document.updateDocument', 'seo', 'controller', 'triggerAfterDocumentUpdateDocument', 'after'),
15
		array('document.deleteDocument', 'seo', 'controller', 'triggerAfterDocumentDeleteDocument', 'after'),
16
		array('module.dispAdditionSetup', 'seo', 'view', 'triggerDispSeoAdditionSetup', 'before')
17
	);
18
19
	public function getConfig()
20
	{
21
		$oModuleModel = getModel('module');
22
		$config = $oModuleModel->getModuleConfig('seo');
23
24
		require_once(_XE_PATH_ . 'libs/idna_convert/idna_convert.class.php');
25
		$IDN = new idna_convert(array('idn_version' => 2008));
26
		$request_uri = $IDN->encode(Context::get('request_uri'));
27
28
		if (!$config) $config = new stdClass;
29
		if (!$config->enable) $config->enable = 'Y';
30
		if (!$config->link_nofollow) $config->link_nofollow = 'N';
31
		if (!$config->use_optimize_title) $config->use_optimize_title = 'N';
32
		if (!$config->ga_except_admin) $config->ga_except_admin = 'N';
33
		if (!$config->ga_track_subdomain) $config->ga_track_subdomain = 'N';
34
		if ($config->site_image) 
35
		{
36
			$config->site_image_url = $request_uri . 'files/attach/site_image/' . $config->site_image;
37
38
			$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
39
			if($oCacheHandler->isSupport()) {
40
				$site_image = false;
0 ignored issues
show
Unused Code introduced by
$site_image 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...
41
				$cache_key = 'seo:site_image';
42
				$site_image = $oCacheHandler->get($cache_key);
43 View Code Duplication
				if(!$site_image) {
44
					$path = _XE_PATH_ . 'files/attach/site_image/';
45
					list($width, $height) = @getimagesize($path . $config->site_image);
46
					$site_image_dimension = array(
47
						'width' => $width,
48
						'height' => $height
49
					);
50
					$cache_key = 'seo:site_image';
51
					$oCacheHandler->put($cache_key, $site_image_dimension);
52
				}
53
			}
54
		}
55
56
		return $config;
57
	}
58
59
	public function addMeta($property, $content, $attr_name = 'property')
60
	{
61
		if (!$content) return;
62
63
		$oModuleController = getController('module');
64
		$oModuleController->replaceDefinedLangCode($content);
65
		if (!in_array($property, array('og:url'))) {
66
			$content = htmlspecialchars($content);
67
			$content = preg_replace("/(\s+)/", ' ', $content);
68
		}
69
70
		$this->SEO['meta'][] = array('property' => $property, 'content' => $content, 'attr_name' => $attr_name);
71
	}
72
73
	public function addLink($rel, $href)
74
	{
75
		if (!$href) return;
76
77
		$this->SEO['link'][] = array('rel' => $rel, 'href' => $href);
78
	}
79
80
	protected function applySEO()
81
	{
82
		$config = $this->getConfig();
83
		$logged_info = Context::get('logged_info');
84
85
		foreach ($this->SEO as $type => $list) {
86
			if (!$list || !count($list)) continue;
87
88
			foreach ($list as $val) {
89
				if ($type == 'meta') {
90
					$attr_name = $val['attr_name'];
91
					Context::addHtmlHeader('<meta ' . $attr_name . '="' . $val['property'] . '" content="' . $val['content'] . '" />');
92
				} elseif ($type == 'link') {
93
					Context::addHtmlHeader('<link rel="' . $val['rel'] . '" href="' . $val['href'] . '" />');
94
				}
95
			}
96
		}
97
98
		// Google Analytics
99
		if ($config->ga_id && !($config->ga_except_admin == 'Y' && $logged_info->is_admin == 'Y')) {
100
			$gaq_push = array();
101
			// $gaq_push[] = '_gaq.push([\'_setAccount\', \'' . $config->ga_id . '\']);';
102
			$gaq_push[] = "ga('create', '{$config->ga_id}', 'auto');";
103
			$canonical_url = str_replace(Context::get('request_uri'), '/', $this->canonical_url);
104
			$gaq_push[] = "ga('send', 'pageview', '{$canonical_url}');";
105
			$gaq_push = implode(PHP_EOL, $gaq_push);
106
107
			$ga_script = <<< GASCRIPT
108
<!-- Google Analytics -->
109
<script>
110
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
111
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
112
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
113
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
114
115
{$gaq_push}
116
</script>
117
GASCRIPT;
118
119
			Context::addHtmlHeader($ga_script . PHP_EOL);
120
		}
121
122
		// Naver Analytics
123
		if ($config->na_id && !($config->na_except_admin == 'Y' && $logged_info->is_admin == 'Y')) {
124
			$na_script = <<< NASCRIPT
125
<!-- NAVER Analytics -->
126
<script src="//wcs.naver.net/wcslog.js"></script>
127
<script>if(!wcs_add){var wcs_add={};};wcs_add['wa']='{$config->na_id}';if(typeof wcs_do!="undefined"){wcs_do();}</script>
128
NASCRIPT;
129
			Context::addHtmlFooter($na_script . PHP_EOL);
130
		}
131
	}
132
133
	function moduleInstall()
134
	{
135
		return $this->makeObject();
136
	}
137
138
	function checkUpdate()
139
	{
140
		$oModuleModel = getModel('module');
141
142
		$seo_config = $this->getConfig();
143
144
		if($seo_config->enable === 'Y') {
145
			foreach ($this->triggers as $trigger) {
146
				if (!$oModuleModel->getTrigger($trigger[0], $trigger[1], $trigger[2], $trigger[3], $trigger[4])) return TRUE;
147
			}
148
		}
149
150
		return FALSE;
151
	}
152
153
	function moduleUpdate()
154
	{
155
		$oModuleModel = getModel('module');
156
		$oModuleController = getController('module');
157
158
		$seo_config = $this->getConfig();
159
160
		if($seo_config->enable === 'Y') {
161
			foreach ($this->triggers as $trigger) {
162
				if (!$oModuleModel->getTrigger($trigger[0], $trigger[1], $trigger[2], $trigger[3], $trigger[4])) {
163
					$oModuleController->insertTrigger($trigger[0], $trigger[1], $trigger[2], $trigger[3], $trigger[4]);
164
				}
165
			}
166
		}
167
168
		return $this->makeObject(0, 'success_updated');
169
	}
170
171
	function moduleUninstall()
172
	{
173
		$oModuleController = getController('module');
174
175
		foreach ($this->triggers as $trigger) {
176
			$oModuleController->deleteTrigger($trigger[0], $trigger[1], $trigger[2], $trigger[3], $trigger[4]);
177
		}
178
179
		return $this->makeObject();
180
	}
181
182
	public function makeObject($code = 0, $message = 'success')
183
	{
184
		return class_exists('BaseObject') ? new BaseObject($code, $message) : new Object($code, $message);
185
	}
186
}
187
/* !End of file */
188