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; |
|
|
|
|
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'); |
|
|
|
|
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'); |
|
|
|
|
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) { |
|
|
|
|
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(); |
|
|
|
|
111
|
|
|
$piece->url = getFullUrl('', 'mid', $current_module_info->mid, 'document_srl',$document_srl); |
112
|
|
|
$piece->type = 'article'; |
113
|
|
|
$piece->description = trim(str_replace(' ', ' ', $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)); |
|
|
|
|
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); |
|
|
|
|
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) { |
|
|
|
|
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
|
|
|
|
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:
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
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: