1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @class syndicationController |
6
|
|
|
* @author NAVER ([email protected]) |
7
|
|
|
* @brief syndication module's Controller class |
8
|
|
|
**/ |
9
|
|
|
|
10
|
|
|
class syndicationController extends syndication |
11
|
|
|
{ |
12
|
|
|
var $ping_message = ''; |
13
|
|
|
|
14
|
|
View Code Duplication |
function triggerInsertDocument(&$obj) { |
|
|
|
|
15
|
|
|
if($obj->module_srl < 1) return $this->makeObject(); |
16
|
|
|
|
17
|
|
|
$oSyndicationModel = getModel('syndication'); |
18
|
|
|
$oModuleModel = getModel('module'); |
19
|
|
|
|
20
|
|
|
if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject(); |
21
|
|
|
|
22
|
|
|
$config = $oModuleModel->getModuleConfig('syndication'); |
23
|
|
|
|
24
|
|
|
if($config->syndication_use!='Y') return $this->makeObject(); |
25
|
|
|
|
26
|
|
|
$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl); |
27
|
|
|
$id = $oSyndicationModel->getID('article', $target_id); |
28
|
|
|
$this->ping($id, 'article'); |
29
|
|
|
|
30
|
|
|
return $this->makeObject(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
function triggerUpdateDocument(&$obj) { |
|
|
|
|
34
|
|
|
if($obj->module_srl < 1) return $this->makeObject(); |
35
|
|
|
|
36
|
|
|
$oSyndicationModel = getModel('syndication'); |
37
|
|
|
$oModuleModel = getModel('module'); |
38
|
|
|
|
39
|
|
|
if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject(); |
40
|
|
|
|
41
|
|
|
$config = $oModuleModel->getModuleConfig('syndication'); |
42
|
|
|
|
43
|
|
|
if($config->syndication_use!='Y') return $this->makeObject(); |
44
|
|
|
|
45
|
|
|
$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl); |
46
|
|
|
$id = $oSyndicationModel->getID('article', $target_id); |
47
|
|
|
$this->ping($id, 'article'); |
48
|
|
|
|
49
|
|
|
return $this->makeObject(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function triggerDeleteDocument(&$obj) { |
53
|
|
|
if($obj->module_srl < 1) return $this->makeObject(); |
54
|
|
|
|
55
|
|
|
$oSyndicationModel = getModel('syndication'); |
56
|
|
|
$oModuleModel = getModel('module'); |
57
|
|
|
|
58
|
|
|
if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject(); |
59
|
|
|
|
60
|
|
|
$config = $oModuleModel->getModuleConfig('syndication'); |
61
|
|
|
|
62
|
|
|
if($config->syndication_use!='Y') return $this->makeObject(); |
63
|
|
|
|
64
|
|
|
$this->insertLog($obj->module_srl, $obj->document_srl, $obj->title, $obj->content); |
65
|
|
|
|
66
|
|
|
$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl); |
67
|
|
|
$id = $oSyndicationModel->getID('article', $target_id); |
68
|
|
|
$this->ping($id, 'deleted'); |
69
|
|
|
|
70
|
|
|
return $this->makeObject(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// @deplicate |
74
|
|
View Code Duplication |
function triggerDeleteModule(&$obj) { |
|
|
|
|
75
|
|
|
$oSyndicationModel = getModel('syndication'); |
76
|
|
|
$oModuleModel = getModel('module'); |
77
|
|
|
|
78
|
|
|
if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject(); |
79
|
|
|
|
80
|
|
|
$config = $oModuleModel->getModuleConfig('syndication'); |
81
|
|
|
|
82
|
|
|
if($config->syndication_use!='Y') return $this->makeObject(); |
83
|
|
|
|
84
|
|
|
$output = executeQuery('syndication.getExceptModule', $obj); |
85
|
|
|
if($output->data->count) return $this->makeObject(); |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
$id = $oSyndicationModel->getID('site', $obj->module_srl); |
89
|
|
|
$this->ping($id, 'deleted'); |
90
|
|
|
|
91
|
|
|
return $this->makeObject(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
function triggerMoveDocumentModule(&$obj) |
95
|
|
|
{ |
96
|
|
|
if($obj->module_srl < 1) return $this->makeObject(); |
97
|
|
|
|
98
|
|
|
$oSyndicationModel = getModel('syndication'); |
99
|
|
|
$oModuleModel = getModel('module'); |
100
|
|
|
|
101
|
|
|
if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject(); |
102
|
|
|
|
103
|
|
|
$config = $oModuleModel->getModuleConfig('syndication'); |
104
|
|
|
|
105
|
|
|
if($config->syndication_use!='Y') return $this->makeObject(); |
106
|
|
|
|
107
|
|
|
$arr_document_srl = explode(',', $obj->document_srls); |
108
|
|
|
if(!$arr_document_srl) return $this->makeObject(); |
|
|
|
|
109
|
|
|
|
110
|
|
|
foreach($arr_document_srl as $document_srl) |
111
|
|
|
{ |
112
|
|
|
$target_id = sprintf('%s-%s', $obj->module_srl, $document_srl); |
113
|
|
|
$id = $oSyndicationModel->getID('article', $target_id); |
114
|
|
|
$this->ping($id, 'article'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $this->makeObject(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
View Code Duplication |
function triggerMoveDocumentToTrash(&$obj) { |
|
|
|
|
121
|
|
|
$oSyndicationModel = getModel('syndication'); |
122
|
|
|
$oModuleModel = getModel('module'); |
123
|
|
|
|
124
|
|
|
if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject(); |
125
|
|
|
|
126
|
|
|
$config = $oModuleModel->getModuleConfig('syndication'); |
127
|
|
|
|
128
|
|
|
if($config->syndication_use!='Y') return $this->makeObject(); |
129
|
|
|
|
130
|
|
|
$this->insertLog($obj->module_srl, $obj->document_srl, '', ''); |
131
|
|
|
|
132
|
|
|
$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl); |
133
|
|
|
$id = $oSyndicationModel->getID('article', $target_id); |
134
|
|
|
$this->ping($id, 'deleted'); |
135
|
|
|
|
136
|
|
|
return $this->makeObject(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
View Code Duplication |
function triggerRestoreTrash(&$obj) { |
|
|
|
|
140
|
|
|
$oSyndicationModel = getModel('syndication'); |
141
|
|
|
$oModuleModel = getModel('module'); |
142
|
|
|
|
143
|
|
|
if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject(); |
144
|
|
|
|
145
|
|
|
$config = $oModuleModel->getModuleConfig('syndication'); |
146
|
|
|
|
147
|
|
|
if($config->syndication_use!='Y') return $this->makeObject(); |
148
|
|
|
|
149
|
|
|
// 신디케이션 삭제 로그 제거 |
150
|
|
|
$this->deleteLog($obj->module_srl, $obj->document_srl); |
151
|
|
|
|
152
|
|
|
$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl); |
153
|
|
|
$id = $oSyndicationModel->getID('article', $target_id); |
154
|
|
|
$this->ping($id, 'article'); |
155
|
|
|
|
156
|
|
|
return $this->makeObject(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
function insertLog($module_srl, $document_srl, $title = null, $summary = null) |
160
|
|
|
{ |
161
|
|
|
$args = new stdClass; |
162
|
|
|
$args->module_srl = $module_srl; |
163
|
|
|
$args->document_srl = $document_srl; |
164
|
|
|
$args->title = $title; |
165
|
|
|
$args->summary = $summary; |
166
|
|
|
$output = executeQuery('syndication.insertLog', $args); |
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
function deleteLog($module_srl, $document_srl) |
170
|
|
|
{ |
171
|
|
|
$args = new stdClass; |
172
|
|
|
$args->module_srl = $module_srl; |
173
|
|
|
$args->document_srl = $document_srl; |
174
|
|
|
$output = executeQuery('syndication.deleteLog', $args); |
|
|
|
|
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
function ping($id, $type, $page=1) { |
178
|
|
|
$this->ping_message = ''; |
179
|
|
|
debugPrint($id); |
180
|
|
|
$oSyndicationModel = getModel('syndication'); |
181
|
|
|
|
182
|
|
|
$oModuleModel = getModel('module'); |
183
|
|
|
$config = $oModuleModel->getModuleConfig('syndication'); |
184
|
|
|
|
185
|
|
|
if(!$config->syndication_token) |
186
|
|
|
{ |
187
|
|
|
$this->ping_message = 'Syndication Token empty'; |
188
|
|
|
$oSyndicationModel->setResentPingLog($this->ping_message); |
189
|
|
|
return false; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if(!$this->checkOpenSSLSupport()) |
193
|
|
|
{ |
194
|
|
|
$lang = Context::get('lang'); |
195
|
|
|
$this->ping_message = $lang->msg_need_openssl_support; |
196
|
|
|
$oSyndicationModel->setResentPingLog($this->ping_message); |
197
|
|
|
return false; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
if(substr($config->site_url,-1)!='/') |
201
|
|
|
{ |
202
|
|
|
$config->site_url .= '/'; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
$ping_url = 'https://apis.naver.com/crawl/nsyndi/v2'; |
206
|
|
|
$ping_header = array(); |
207
|
|
|
$ping_header['Host'] = 'apis.naver.com'; |
208
|
|
|
$ping_header['Pragma'] = 'no-cache'; |
209
|
|
|
$ping_header['Accept'] = '*/*'; |
210
|
|
|
$ping_header['Authorization'] = sprintf("Bearer %s", $config->syndication_token); |
211
|
|
|
|
212
|
|
|
$request_config = array(); |
213
|
|
|
$request_config['ssl_verify_peer'] = false; |
214
|
|
|
|
215
|
|
|
$ping_body = getNotEncodedFullUrl('', 'module', 'syndication', 'act', 'getSyndicationList', 'id', $id, 'type', $type, 'page', $page, 'syndication_password', $config->syndication_password); |
216
|
|
|
|
217
|
|
|
$buff = FileHandler::getRemoteResource($ping_url, null, 10, 'POST', 'application/x-www-form-urlencoded', $ping_header, array(), array('ping_url'=>$ping_body), $request_config); |
218
|
|
|
|
219
|
|
|
$xml = new XmlParser(); |
220
|
|
|
$xmlDoc= $xml->parse($buff); |
221
|
|
|
|
222
|
|
|
if($xmlDoc->result->error_code->body != '000') |
223
|
|
|
{ |
224
|
|
|
if(!$buff) |
225
|
|
|
{ |
226
|
|
|
$this->ping_message = 'Socket connection error. Check your Server Environment.'; |
227
|
|
|
} |
228
|
|
|
else |
229
|
|
|
{ |
230
|
|
|
$this->ping_message = $xmlDoc->result->message->body; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
$oSyndicationModel->setResentPingLog($this->ping_message); |
234
|
|
|
return false; |
235
|
|
|
} |
236
|
|
|
return true; |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|
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.