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