|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */ |
|
3
|
|
|
/** |
|
4
|
|
|
* @class mcontent |
|
5
|
|
|
* @author NAVER ([email protected]) |
|
6
|
|
|
* @brief widget to display mcontent |
|
7
|
|
|
* @version 0.1 |
|
8
|
|
|
*/ |
|
9
|
|
|
class mcontent extends WidgetHandler |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @brief Widget execution |
|
13
|
|
|
* |
|
14
|
|
|
* Get extra_vars declared in ./widgets/widget/conf/info.xml as arguments |
|
15
|
|
|
* After generating the result, do not print but return it. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
function proc($args) |
|
19
|
|
|
{ |
|
20
|
|
|
// Targets to sort |
|
21
|
|
|
if(!in_array($args->order_target, array('list_order','update_order'))) $args->order_target = 'list_order'; |
|
22
|
|
|
// Sort order |
|
23
|
|
|
if(!in_array($args->order_type, array('asc','desc'))) $args->order_type = 'asc'; |
|
24
|
|
|
// The number of displayed lists |
|
25
|
|
|
$args->list_count = (int)$args->list_count; |
|
26
|
|
|
if(!$args->list_count) $args->list_count = 5; |
|
27
|
|
|
// Cut the length of the title |
|
28
|
|
|
if(!$args->subject_cut_size) $args->subject_cut_size = 0; |
|
29
|
|
|
// Cut the length of contents |
|
30
|
|
|
if(!$args->content_cut_size) $args->content_cut_size = 100; |
|
31
|
|
|
// Viewing options |
|
32
|
|
|
$args->option_view_arr = explode(',',$args->option_view); |
|
33
|
|
|
// markup options |
|
34
|
|
|
if(!$args->markup_type) $args->markup_type = 'list'; |
|
35
|
|
|
// Set variables for internal use |
|
36
|
|
|
$oModuleModel = getModel('module'); |
|
37
|
|
|
$module_srls = $args->modules_info = $args->module_srls_info = $args->mid_lists = array(); |
|
38
|
|
|
$site_module_info = Context::get('site_module_info'); |
|
39
|
|
|
// List URLs if a type is RSS |
|
40
|
|
View Code Duplication |
if($args->content_type == 'rss') |
|
41
|
|
|
{ |
|
42
|
|
|
$args->rss_urls = array(); |
|
43
|
|
|
$rss_urls = array_unique(array($args->rss_url0,$args->rss_url1,$args->rss_url2,$args->rss_url3,$args->rss_url4)); |
|
44
|
|
|
for($i=0,$c=count($rss_urls);$i<$c;$i++) |
|
45
|
|
|
{ |
|
46
|
|
|
if($rss_urls[$i]) $args->rss_urls[] = $rss_urls[$i]; |
|
47
|
|
|
} |
|
48
|
|
|
// Get module information after listing module_srls if the module is not RSS |
|
49
|
|
|
} |
|
50
|
|
|
else |
|
51
|
|
|
{ |
|
52
|
|
|
$obj = new stdClass(); |
|
53
|
|
|
// Apply to all modules in the site if a target module is not specified |
|
54
|
|
|
if(!$args->module_srls) |
|
55
|
|
|
{ |
|
56
|
|
|
$obj->site_srl = (int)$site_module_info->site_srl; |
|
57
|
|
|
$output = executeQueryArray('widgets.content.getMids', $obj); |
|
58
|
|
|
if($output->data) |
|
59
|
|
|
{ |
|
60
|
|
|
foreach($output->data as $key => $val) |
|
61
|
|
|
{ |
|
62
|
|
|
$args->modules_info[$val->mid] = $val; |
|
63
|
|
|
$args->module_srls_info[$val->module_srl] = $val; |
|
64
|
|
|
$args->mid_lists[$val->module_srl] = $val->mid; |
|
65
|
|
|
$module_srls[] = $val->module_srl; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$args->modules_info = $oModuleModel->getMidList($obj); |
|
70
|
|
|
// Apply to the module only if a target module is specified |
|
71
|
|
|
} |
|
72
|
|
|
else |
|
73
|
|
|
{ |
|
74
|
|
|
$obj->module_srls = $args->module_srls; |
|
75
|
|
|
$output = executeQueryArray('widgets.content.getMids', $obj); |
|
76
|
|
|
if($output->data) |
|
77
|
|
|
{ |
|
78
|
|
|
foreach($output->data as $key => $val) |
|
79
|
|
|
{ |
|
80
|
|
|
$args->modules_info[$val->mid] = $val; |
|
81
|
|
|
$args->module_srls_info[$val->module_srl] = $val; |
|
82
|
|
|
$module_srls[] = $val->module_srl; |
|
83
|
|
|
} |
|
84
|
|
|
$idx = explode(',',$args->module_srls); |
|
85
|
|
|
for($i=0,$c=count($idx);$i<$c;$i++) |
|
86
|
|
|
{ |
|
87
|
|
|
$srl = $idx[$i]; |
|
88
|
|
|
if(!$args->module_srls_info[$srl]) continue; |
|
89
|
|
|
$args->mid_lists[$srl] = $args->module_srls_info[$srl]->mid; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
// Exit if no module is found |
|
94
|
|
|
if(!count($args->modules_info)) return Context::get('msg_not_founded'); |
|
95
|
|
|
$args->module_srl = implode(',',$module_srls); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Method is separately made because content extraction, articles, comments, trackbacks, RSS and other elements exist |
|
100
|
|
|
*/ |
|
101
|
|
|
// tab mode |
|
102
|
|
View Code Duplication |
if($args->tab_type == 'none' || $args->tab_type == '') |
|
103
|
|
|
{ |
|
104
|
|
|
switch($args->content_type) |
|
105
|
|
|
{ |
|
106
|
|
|
case 'comment': |
|
107
|
|
|
$content_items = $this->_getCommentItems($args); |
|
108
|
|
|
break; |
|
109
|
|
|
case 'image': |
|
110
|
|
|
$content_items = $this->_getImageItems($args); |
|
111
|
|
|
break; |
|
112
|
|
|
case 'rss': |
|
113
|
|
|
$content_items = $this->getRssItems($args); |
|
114
|
|
|
break; |
|
115
|
|
|
case 'trackback': |
|
116
|
|
|
$content_items = $this->_getTrackbackItems($args); |
|
117
|
|
|
break; |
|
118
|
|
|
default: |
|
119
|
|
|
$content_items = $this->_getDocumentItems($args); |
|
120
|
|
|
break; |
|
121
|
|
|
} |
|
122
|
|
|
// If not a tab type |
|
123
|
|
|
} |
|
124
|
|
|
else |
|
125
|
|
|
{ |
|
126
|
|
|
$content_items = array(); |
|
127
|
|
|
|
|
128
|
|
|
switch($args->content_type) |
|
129
|
|
|
{ |
|
130
|
|
|
case 'comment': |
|
131
|
|
|
foreach($args->mid_lists as $module_srl => $mid) |
|
132
|
|
|
{ |
|
133
|
|
|
$args->module_srl = $module_srl; |
|
134
|
|
|
$content_items[$module_srl] = $this->_getCommentItems($args); |
|
135
|
|
|
} |
|
136
|
|
|
break; |
|
137
|
|
|
case 'image': |
|
138
|
|
|
foreach($args->mid_lists as $module_srl => $mid) |
|
139
|
|
|
{ |
|
140
|
|
|
$args->module_srl = $module_srl; |
|
141
|
|
|
$content_items[$module_srl] = $this->_getImageItems($args); |
|
142
|
|
|
} |
|
143
|
|
|
break; |
|
144
|
|
|
case 'rss': |
|
145
|
|
|
$content_items = $this->getRssItems($args); |
|
146
|
|
|
break; |
|
147
|
|
|
case 'trackback': |
|
148
|
|
|
foreach($args->mid_lists as $module_srl => $mid){ |
|
149
|
|
|
$args->module_srl = $module_srl; |
|
150
|
|
|
$content_items[$module_srl] = $this->_getTrackbackItems($args); |
|
151
|
|
|
} |
|
152
|
|
|
break; |
|
153
|
|
|
default: |
|
154
|
|
|
foreach($args->mid_lists as $module_srl => $mid) |
|
155
|
|
|
{ |
|
156
|
|
|
$args->module_srl = $module_srl; |
|
157
|
|
|
$content_items[$module_srl] = $this->_getDocumentItems($args); |
|
158
|
|
|
} |
|
159
|
|
|
break; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
$output = $this->_compile($args,$content_items); |
|
164
|
|
|
return $output; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @brief Return to the list of comments extracted mcontentItem |
|
169
|
|
|
*/ |
|
170
|
|
|
function _getCommentItems($args) |
|
171
|
|
|
{ |
|
172
|
|
|
// CommentModel:: getCommentList() to take advantage of the variable order |
|
173
|
|
|
$obj = new stdClass(); |
|
174
|
|
|
$obj->module_srl = $args->module_srl; |
|
175
|
|
|
$obj->sort_index = $args->order_target; |
|
176
|
|
|
$obj->list_count = $args->list_count; |
|
177
|
|
|
// Get model object of the comment module getCommentList() method runs |
|
178
|
|
|
$oCommentModel = getModel('comment'); |
|
179
|
|
|
$output = $oCommentModel->getNewestCommentList($obj); |
|
180
|
|
|
|
|
181
|
|
|
$content_items = array(); |
|
182
|
|
|
|
|
183
|
|
|
if(!count($output)) return; |
|
184
|
|
|
|
|
185
|
|
|
foreach($output as $key => $oComment) |
|
186
|
|
|
{ |
|
187
|
|
|
$attribute = $oComment->getObjectVars(); |
|
188
|
|
|
$title = $oComment->getSummary($args->content_cut_size); |
|
189
|
|
|
$thumbnail = $oComment->getThumbnail(); |
|
190
|
|
|
$url = sprintf("%s#comment_%s",getUrl('', 'mid', $args->mid_lists[$attribute->module_srl], 'document_srl',$oComment->get('document_srl')),$oComment->get('comment_srl')); |
|
191
|
|
|
|
|
192
|
|
|
$attribute->mid = $args->mid_lists[$attribute->module_srl]; |
|
193
|
|
|
$browser_title = $args->module_srls_info[$attribute->module_srl]->browser_title; |
|
194
|
|
|
$domain = $args->module_srls_info[$attribute->module_srl]->domain; |
|
195
|
|
|
|
|
196
|
|
|
$content_item = new mcontentItem($browser_title); |
|
197
|
|
|
$content_item->adds($attribute); |
|
198
|
|
|
$content_item->setTitle($title); |
|
199
|
|
|
$content_item->setThumbnail($thumbnail); |
|
200
|
|
|
$content_item->setLink($url); |
|
201
|
|
|
$content_item->setDomain($domain); |
|
202
|
|
|
$content_item->add('mid', $args->mid_lists[$attribute->module_srl]); |
|
203
|
|
|
$content_items[] = $content_item; |
|
204
|
|
|
} |
|
205
|
|
|
return $content_items; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
function _getDocumentItems($args) |
|
209
|
|
|
{ |
|
210
|
|
|
// Get model object of the document module and make the result as an object |
|
211
|
|
|
$oDocumentModel = getModel('document'); |
|
212
|
|
|
// Get categories |
|
213
|
|
|
$obj = new stdClass(); |
|
214
|
|
|
$obj->module_srl = $args->module_srl; |
|
215
|
|
|
$output = executeQueryArray('widgets.content.getCategories',$obj); |
|
216
|
|
View Code Duplication |
if($output->toBool() && $output->data) |
|
217
|
|
|
{ |
|
218
|
|
|
foreach($output->data as $key => $val) |
|
219
|
|
|
{ |
|
220
|
|
|
$category_lists[$val->module_srl][$val->category_srl] = $val; |
|
|
|
|
|
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
// Get a list of documents |
|
224
|
|
|
$obj->module_srl = $args->module_srl; |
|
225
|
|
|
$obj->sort_index = $args->order_target; |
|
226
|
|
|
$obj->order_type = $args->order_type=="desc"?"asc":"desc"; |
|
227
|
|
|
$obj->list_count = $args->list_count; |
|
228
|
|
|
$obj->statusList = array('PUBLIC'); |
|
229
|
|
|
$output = executeQueryArray('widgets.content.getNewestDocuments', $obj); |
|
230
|
|
|
if(!$output->toBool() || !$output->data) return; |
|
231
|
|
|
// If the result exists, make each document as an object |
|
232
|
|
|
$content_items = array(); |
|
233
|
|
|
$first_thumbnail_idx = -1; |
|
234
|
|
|
if(count($output->data)) |
|
235
|
|
|
{ |
|
236
|
|
View Code Duplication |
foreach($output->data as $key => $attribute) |
|
237
|
|
|
{ |
|
238
|
|
|
$oDocument = new documentItem(); |
|
239
|
|
|
$oDocument->setAttribute($attribute, false); |
|
240
|
|
|
$GLOBALS['XE_DOCUMENT_LIST'][$oDocument->document_srl] = $oDocument; |
|
241
|
|
|
$document_srls[] = $oDocument->document_srl; |
|
|
|
|
|
|
242
|
|
|
} |
|
243
|
|
|
$oDocumentModel->setToAllDocumentExtraVars(); |
|
244
|
|
|
|
|
245
|
|
|
for($i=0,$c=count($document_srls);$i<$c;$i++) |
|
|
|
|
|
|
246
|
|
|
{ |
|
247
|
|
|
$oDocument = $GLOBALS['XE_DOCUMENT_LIST'][$document_srls[$i]]; |
|
248
|
|
|
$document_srl = $oDocument->document_srl; |
|
249
|
|
|
$module_srl = $oDocument->get('module_srl'); |
|
250
|
|
|
$category_srl = $oDocument->get('category_srl'); |
|
251
|
|
|
$thumbnail = $oDocument->getThumbnail(); |
|
252
|
|
|
$content_item = new mcontentItem( $args->module_srls_info[$module_srl]->browser_title ); |
|
253
|
|
|
$content_item->adds($oDocument->getObjectVars()); |
|
254
|
|
|
$content_item->setTitle($oDocument->getTitleText()); |
|
255
|
|
|
$content_item->setCategory( $category_lists[$module_srl][$category_srl]->title ); |
|
|
|
|
|
|
256
|
|
|
$content_item->setDomain( $args->module_srls_info[$module_srl]->domain ); |
|
257
|
|
|
$content_item->setContent($oDocument->getSummary($args->content_cut_size)); |
|
258
|
|
|
$content_item->setLink( getSiteUrl($domain,'', 'mid',$args->mid_lists[$module_srl], 'document_srl',$document_srl) ); |
|
|
|
|
|
|
259
|
|
|
$content_item->setThumbnail($thumbnail); |
|
260
|
|
|
$content_item->add('mid', $args->mid_lists[$module_srl]); |
|
261
|
|
|
if($first_thumbnail_idx==-1 && $thumbnail) $first_thumbnail_idx = $i; |
|
262
|
|
|
$content_items[] = $content_item; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
$content_items[0]->setFirstThumbnailIdx($first_thumbnail_idx); |
|
266
|
|
|
} |
|
267
|
|
|
return $content_items; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
function _getImageItems($args) |
|
271
|
|
|
{ |
|
272
|
|
|
$oDocumentModel = getModel('document'); |
|
273
|
|
|
|
|
274
|
|
|
$obj = new stdClass(); |
|
275
|
|
|
$obj->module_srls = $obj->module_srl = $args->module_srl; |
|
276
|
|
|
$obj->direct_download = 'Y'; |
|
277
|
|
|
$obj->isvalid = 'Y'; |
|
278
|
|
|
// Get categories |
|
279
|
|
|
$output = executeQueryArray('widgets.content.getCategories',$obj); |
|
280
|
|
View Code Duplication |
if($output->toBool() && $output->data) |
|
281
|
|
|
{ |
|
282
|
|
|
foreach($output->data as $key => $val) |
|
283
|
|
|
{ |
|
284
|
|
|
$category_lists[$val->module_srl][$val->category_srl] = $val; |
|
|
|
|
|
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
// Get a file list in each document on the module |
|
288
|
|
|
$obj->list_count = $args->list_count; |
|
289
|
|
|
$files_output = executeQueryArray("file.getOneFileInDocument", $obj); |
|
290
|
|
|
$files_count = count($files_output->data); |
|
291
|
|
|
if(!$files_count) return; |
|
292
|
|
|
|
|
293
|
|
|
$content_items = array(); |
|
294
|
|
|
|
|
295
|
|
View Code Duplication |
for($i=0;$i<$files_count;$i++) $document_srl_list[] = $files_output->data[$i]->document_srl; |
|
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
$tmp_document_list = $oDocumentModel->getDocuments($document_srl_list); |
|
|
|
|
|
|
298
|
|
|
|
|
299
|
|
|
if(!count($tmp_document_list)) return; |
|
300
|
|
|
|
|
301
|
|
|
foreach($tmp_document_list as $oDocument) |
|
302
|
|
|
{ |
|
303
|
|
|
$attribute = $oDocument->getObjectVars(); |
|
304
|
|
|
$browser_title = $args->module_srls_info[$attribute->module_srl]->browser_title; |
|
305
|
|
|
$domain = $args->module_srls_info[$attribute->module_srl]->domain; |
|
306
|
|
|
$category = $category_lists[$attribute->module_srl]->text; |
|
|
|
|
|
|
307
|
|
|
$content = $oDocument->getSummary($args->content_cut_size); |
|
308
|
|
|
$url = sprintf("%s#%s",$oDocument->getPermanentUrl() ,$oDocument->getCommentCount()); |
|
309
|
|
|
$thumbnail = $oDocument->getThumbnail(); |
|
310
|
|
|
$content_item = new mcontentItem($browser_title); |
|
311
|
|
|
$content_item->adds($attribute); |
|
312
|
|
|
$content_item->setCategory($category); |
|
313
|
|
|
$content_item->setContent($content); |
|
314
|
|
|
$content_item->setLink($url); |
|
315
|
|
|
$content_item->setThumbnail($thumbnail); |
|
316
|
|
|
$content_item->setExtraImages($extra_images); |
|
|
|
|
|
|
317
|
|
|
$content_item->setDomain($domain); |
|
318
|
|
|
$content_item->add('mid', $args->mid_lists[$attribute->module_srl]); |
|
319
|
|
|
$content_items[] = $content_item; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
return $content_items; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
function getRssItems($args) |
|
326
|
|
|
{ |
|
327
|
|
|
$content_items = array(); |
|
328
|
|
|
$args->mid_lists = array(); |
|
329
|
|
|
|
|
330
|
|
View Code Duplication |
foreach($args->rss_urls as $key => $rss) |
|
331
|
|
|
{ |
|
332
|
|
|
$args->rss_url = $rss; |
|
333
|
|
|
$content_item = $this->_getRssItems($args); |
|
334
|
|
|
if(count($content_item) > 0) |
|
335
|
|
|
{ |
|
336
|
|
|
$browser_title = $content_item[0]->getBrowserTitle(); |
|
337
|
|
|
$args->mid_lists[] = $browser_title; |
|
338
|
|
|
$content_items[] = $content_item; |
|
339
|
|
|
} |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
if($args->tab_type == 'none' || $args->tab_type == '') |
|
343
|
|
|
{ |
|
344
|
|
|
$items = array(); |
|
345
|
|
View Code Duplication |
foreach($content_items as $key => $val) |
|
346
|
|
|
{ |
|
347
|
|
|
foreach($val as $k => $v) |
|
348
|
|
|
{ |
|
349
|
|
|
$date = $v->get('regdate'); |
|
350
|
|
|
$i=0; |
|
351
|
|
|
while(array_key_exists(sprintf('%s%02d',$date,$i), $items)) $i++; |
|
352
|
|
|
$items[sprintf('%s%02d',$date,$i)] = $v; |
|
353
|
|
|
} |
|
354
|
|
|
} |
|
355
|
|
|
if($args->order_type =='asc') ksort($items); |
|
356
|
|
|
else krsort($items); |
|
357
|
|
|
$content_items = array_slice(array_values($items),0,$args->list_count); |
|
358
|
|
|
} return $content_items; |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
View Code Duplication |
function _getRssBody($value) |
|
|
|
|
|
|
362
|
|
|
{ |
|
363
|
|
|
if(!$value || is_string($value)) return $value; |
|
364
|
|
|
if(is_object($value)) $value = get_object_vars($value); |
|
365
|
|
|
$body = null; |
|
366
|
|
|
if(!count($value)) return; |
|
367
|
|
|
foreach($value as $key => $val) |
|
368
|
|
|
{ |
|
369
|
|
|
if($key == 'body') |
|
370
|
|
|
{ |
|
371
|
|
|
$body = $val; |
|
372
|
|
|
continue; |
|
373
|
|
|
} |
|
374
|
|
|
if(is_object($val)||is_array($val)) $body = $this->_getRssBody($val); |
|
375
|
|
|
if($body !== null) return $body; |
|
376
|
|
|
} |
|
377
|
|
|
return $body; |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
View Code Duplication |
function _getSummary($content, $str_size = 50) |
|
|
|
|
|
|
381
|
|
|
{ |
|
382
|
|
|
$content = preg_replace('!(<br[\s]*/{0,1}>[\s]*)+!is', ' ', $content); |
|
383
|
|
|
// Replace tags such as </p> , </div> , </li> and others to a whitespace |
|
384
|
|
|
$content = str_replace(array('</p>', '</div>', '</li>'), ' ', $content); |
|
385
|
|
|
// Remove Tag |
|
386
|
|
|
$content = preg_replace('!<([^>]*?)>!is','', $content); |
|
387
|
|
|
// Replace tags to < , > , " |
|
388
|
|
|
$content = str_replace(array('<','>','"',' '), array('<','>','"',' '), $content); |
|
389
|
|
|
// Delete a series of whitespaces |
|
390
|
|
|
$content = preg_replace('/ ( +)/is', ' ', $content); |
|
391
|
|
|
// Truncate string |
|
392
|
|
|
$content = trim(cut_str($content, $str_size, $tail)); |
|
|
|
|
|
|
393
|
|
|
// Replace back < , > , " to theoriginal tags |
|
394
|
|
|
$content = str_replace(array('<','>','"'),array('<','>','"'), $content); |
|
395
|
|
|
// Fixed a newline bug on a set of consecutive English letters |
|
396
|
|
|
$content = preg_replace('/([a-z0-9\+:\/\.\~,\|\!\@\#\$\%\^\&\*\(\)\_]){20}/is',"$0-",$content); |
|
397
|
|
|
return $content; |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* @brief function to receive contents from rss url |
|
403
|
|
|
* For Tistory blog in Korea, the original RSS url has location header without contents. Fixed to work as same as rss_reader widget. |
|
404
|
|
|
*/ |
|
405
|
|
|
function requestFeedContents($rss_url) |
|
406
|
|
|
{ |
|
407
|
|
|
$rss_url = str_replace('&','&',Context::convertEncodingStr($rss_url)); |
|
408
|
|
|
return FileHandler::getRemoteResource($rss_url, null, 3, 'GET', 'application/xml'); |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
function _getRssItems($args) |
|
412
|
|
|
{ |
|
413
|
|
|
// Date Format |
|
414
|
|
|
$DATE_FORMAT = $args->date_format ? $args->date_format : "Y-m-d H:i:s"; |
|
|
|
|
|
|
415
|
|
|
|
|
416
|
|
|
$buff = $this->requestFeedContents($args->rss_url); |
|
417
|
|
|
|
|
418
|
|
|
$encoding = preg_match("/<\?xml.*encoding=\"(.+)\".*\?>/i", $buff, $matches); |
|
419
|
|
View Code Duplication |
if($encoding && stripos($matches[1], "UTF-8") === FALSE) $buff = Context::convertEncodingStr($buff); |
|
420
|
|
|
|
|
421
|
|
|
$buff = preg_replace("/<\?xml.*\?>/i", "", $buff); |
|
422
|
|
|
|
|
423
|
|
|
$oXmlParser = new XmlParser(); |
|
424
|
|
|
$xml_doc = $oXmlParser->parse($buff); |
|
425
|
|
|
$rss = new stdClass(); |
|
426
|
|
|
if($xml_doc->rss) |
|
427
|
|
|
{ |
|
428
|
|
|
$rss->title = $xml_doc->rss->channel->title->body; |
|
429
|
|
|
$rss->link = $xml_doc->rss->channel->link->body; |
|
430
|
|
|
|
|
431
|
|
|
$items = $xml_doc->rss->channel->item; |
|
432
|
|
|
|
|
433
|
|
|
if(!$items) return; |
|
434
|
|
|
if($items && !is_array($items)) $items = array($items); |
|
435
|
|
|
|
|
436
|
|
|
$content_items = array(); |
|
437
|
|
|
|
|
438
|
|
View Code Duplication |
foreach ($items as $key => $value) |
|
439
|
|
|
{ |
|
440
|
|
|
if($key >= $args->list_count) break; |
|
441
|
|
|
unset($item); |
|
442
|
|
|
$item = new stdClass(); |
|
443
|
|
|
|
|
444
|
|
|
foreach($value as $key2 => $value2) |
|
445
|
|
|
{ |
|
446
|
|
|
if(is_array($value2)) $value2 = array_shift($value2); |
|
447
|
|
|
$item->{$key2} = $this->_getRssBody($value2); |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
$content_item = new mcontentItem($rss->title); |
|
451
|
|
|
$content_item->setContentsLink($rss->link); |
|
452
|
|
|
$content_item->setTitle($item->title); |
|
453
|
|
|
$content_item->setNickName(max($item->author,$item->{'dc:creator'})); |
|
454
|
|
|
//$content_item->setCategory($item->category); |
|
455
|
|
|
$item->description = preg_replace('!<a href=!is','<a target="_blank" rel="noopener" href=', $item->description); |
|
456
|
|
|
$content_item->setContent($this->_getSummary($item->description, $args->content_cut_size)); |
|
457
|
|
|
$content_item->setLink($item->link); |
|
458
|
|
|
$date = date('YmdHis', strtotime(max($item->pubdate,$item->pubDate,$item->{'dc:date'}))); |
|
459
|
|
|
$content_item->setRegdate($date); |
|
460
|
|
|
|
|
461
|
|
|
$content_items[] = $content_item; |
|
462
|
|
|
} |
|
463
|
|
|
} |
|
464
|
|
|
else if($xml_doc->{'rdf:rdf'}) |
|
465
|
|
|
{ |
|
466
|
|
|
// rss1.0 supported (XE's XML is case-insensitive because XML parser converts all to small letters) Fixed by misol |
|
467
|
|
|
$rss->title = $xml_doc->{'rdf:rdf'}->channel->title->body; |
|
468
|
|
|
$rss->link = $xml_doc->{'rdf:rdf'}->channel->link->body; |
|
469
|
|
|
|
|
470
|
|
|
$items = $xml_doc->{'rdf:rdf'}->item; |
|
471
|
|
|
|
|
472
|
|
|
if(!$items) return; |
|
473
|
|
|
if($items && !is_array($items)) $items = array($items); |
|
474
|
|
|
|
|
475
|
|
|
$content_items = array(); |
|
476
|
|
|
|
|
477
|
|
View Code Duplication |
foreach ($items as $key => $value) |
|
478
|
|
|
{ |
|
479
|
|
|
if($key >= $args->list_count) break; |
|
480
|
|
|
unset($item); |
|
481
|
|
|
$item = new stdClass(); |
|
482
|
|
|
|
|
483
|
|
|
foreach($value as $key2 => $value2) |
|
484
|
|
|
{ |
|
485
|
|
|
if(is_array($value2)) $value2 = array_shift($value2); |
|
486
|
|
|
$item->{$key2} = $this->_getRssBody($value2); |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
$content_item = new mcontentItem($rss->title); |
|
490
|
|
|
$content_item->setContentsLink($rss->link); |
|
491
|
|
|
$content_item->setTitle($item->title); |
|
492
|
|
|
$content_item->setNickName(max($item->author,$item->{'dc:creator'})); |
|
493
|
|
|
//$content_item->setCategory($item->category); |
|
494
|
|
|
$item->description = preg_replace('!<a href=!is','<a target="_blank" rel="noopener" href=', $item->description); |
|
495
|
|
|
$content_item->setContent($this->_getSummary($item->description, $args->content_cut_size)); |
|
496
|
|
|
$content_item->setLink($item->link); |
|
497
|
|
|
$date = date('YmdHis', strtotime(max($item->pubdate,$item->pubDate,$item->{'dc:date'}))); |
|
498
|
|
|
$content_item->setRegdate($date); |
|
499
|
|
|
|
|
500
|
|
|
$content_items[] = $content_item; |
|
501
|
|
|
} |
|
502
|
|
|
} |
|
503
|
|
|
else if($xml_doc->feed && $xml_doc->feed->attrs->xmlns == 'http://www.w3.org/2005/Atom') |
|
504
|
|
|
{ |
|
505
|
|
|
// Atom 1.0 spec supported by misol |
|
506
|
|
|
$rss->title = $xml_doc->feed->title->body; |
|
507
|
|
|
$links = $xml_doc->feed->link; |
|
508
|
|
View Code Duplication |
if(is_array($links)) |
|
509
|
|
|
{ |
|
510
|
|
|
foreach ($links as $value) |
|
511
|
|
|
{ |
|
512
|
|
|
if($value->attrs->rel == 'alternate') |
|
513
|
|
|
{ |
|
514
|
|
|
$rss->link = $value->attrs->href; |
|
515
|
|
|
break; |
|
516
|
|
|
} |
|
517
|
|
|
} |
|
518
|
|
|
} |
|
519
|
|
|
else if($links->attrs->rel == 'alternate') $rss->link = $links->attrs->href; |
|
520
|
|
|
|
|
521
|
|
|
$items = $xml_doc->feed->entry; |
|
522
|
|
|
|
|
523
|
|
|
if(!$items) return; |
|
524
|
|
|
if($items && !is_array($items)) $items = array($items); |
|
525
|
|
|
|
|
526
|
|
|
$content_items = array(); |
|
527
|
|
|
|
|
528
|
|
|
foreach ($items as $key => $value) |
|
529
|
|
|
{ |
|
530
|
|
|
if($key >= $args->list_count) break; |
|
531
|
|
|
unset($item); |
|
532
|
|
|
|
|
533
|
|
|
foreach($value as $key2 => $value2) |
|
534
|
|
|
{ |
|
535
|
|
|
if(is_array($value2)) $value2 = array_shift($value2); |
|
536
|
|
|
$item->{$key2} = $this->_getRssBody($value2); |
|
|
|
|
|
|
537
|
|
|
} |
|
538
|
|
|
|
|
539
|
|
|
$content_item = new mcontentItem($rss->title); |
|
540
|
|
|
$links = $value->link; |
|
541
|
|
View Code Duplication |
if(is_array($links)) |
|
542
|
|
|
{ |
|
543
|
|
|
foreach ($links as $val) |
|
544
|
|
|
{ |
|
545
|
|
|
if($val->attrs->rel == 'alternate') |
|
546
|
|
|
{ |
|
547
|
|
|
$item->link = $val->attrs->href; |
|
|
|
|
|
|
548
|
|
|
break; |
|
549
|
|
|
} |
|
550
|
|
|
} |
|
551
|
|
|
} |
|
552
|
|
|
else if($links->attrs->rel == 'alternate') $item->link = $links->attrs->href; |
|
|
|
|
|
|
553
|
|
|
|
|
554
|
|
|
$content_item->setContentsLink($rss->link); |
|
555
|
|
View Code Duplication |
if($item->title) |
|
|
|
|
|
|
556
|
|
|
{ |
|
557
|
|
|
if(stripos($value->title->attrs->type, "html") === FALSE) $item->title = $value->title->body; |
|
|
|
|
|
|
558
|
|
|
} |
|
559
|
|
|
$content_item->setTitle($item->title); |
|
|
|
|
|
|
560
|
|
|
$content_item->setNickName(max($item->author,$item->{'dc:creator'})); |
|
|
|
|
|
|
561
|
|
|
$content_item->setAuthorSite($value->author->uri->body); |
|
562
|
|
|
|
|
563
|
|
|
//$content_item->setCategory($item->category); |
|
564
|
|
|
$item->description = ($item->content) ? $item->content : $item->description = $item->summary; |
|
|
|
|
|
|
565
|
|
|
$item->description = preg_replace('!<a href=!is','<a target="_blank" rel="noopener" href=', $item->description); |
|
|
|
|
|
|
566
|
|
|
|
|
567
|
|
View Code Duplication |
if(($item->content && stripos($value->content->attrs->type, "html") === FALSE) || (!$item->content && stripos($value->summary->attrs->type, "html") === FALSE)) |
|
|
|
|
|
|
568
|
|
|
{ |
|
569
|
|
|
$item->description = htmlspecialchars($item->description, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
|
|
|
|
|
|
570
|
|
|
|
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
$content_item->setContent($this->_getSummary($item->description, $args->content_cut_size)); |
|
|
|
|
|
|
574
|
|
|
$content_item->setLink($item->link); |
|
|
|
|
|
|
575
|
|
|
$date = date('YmdHis', strtotime(max($item->published,$item->updated,$item->{'dc:date'}))); |
|
|
|
|
|
|
576
|
|
|
$content_item->setRegdate($date); |
|
577
|
|
|
|
|
578
|
|
|
$content_items[] = $content_item; |
|
579
|
|
|
} |
|
580
|
|
|
} |
|
581
|
|
|
return $content_items; |
|
|
|
|
|
|
582
|
|
|
} |
|
583
|
|
|
|
|
584
|
|
|
function _getTrackbackItems($args){ |
|
585
|
|
|
// Get categories |
|
586
|
|
|
$output = executeQueryArray('widgets.content.getCategories',$obj); |
|
|
|
|
|
|
587
|
|
View Code Duplication |
if($output->toBool() && $output->data) |
|
588
|
|
|
{ |
|
589
|
|
|
foreach($output->data as $key => $val) { |
|
590
|
|
|
$category_lists[$val->module_srl][$val->category_srl] = $val; |
|
|
|
|
|
|
591
|
|
|
} |
|
592
|
|
|
} |
|
593
|
|
|
|
|
594
|
|
|
$obj->module_srl = $args->module_srl; |
|
595
|
|
|
$obj->sort_index = $args->order_target; |
|
596
|
|
|
$obj->list_count = $args->list_count; |
|
597
|
|
|
// Get model object from the trackback module and execute getTrackbackList() method |
|
598
|
|
|
$oTrackbackModel = getModel('trackback'); |
|
599
|
|
|
$output = $oTrackbackModel->getNewestTrackbackList($obj); |
|
|
|
|
|
|
600
|
|
|
// If an error occurs, just ignore it. |
|
601
|
|
|
if(!$output->toBool() || !$output->data) return; |
|
602
|
|
|
// If the result exists, make each document as an object |
|
603
|
|
|
$content_items = array(); |
|
604
|
|
|
foreach($output->data as $key => $item) |
|
605
|
|
|
{ |
|
606
|
|
|
$domain = $args->module_srls_info[$item->module_srl]->domain; |
|
607
|
|
|
$category = $category_lists[$item->module_srl]->text; |
|
|
|
|
|
|
608
|
|
|
$url = getSiteUrl($domain,'','mid', $args->mid_lists[$item->module_srl],'document_srl',$item->document_srl); |
|
609
|
|
|
$browser_title = $args->module_srls_info[$item->module_srl]->browser_title; |
|
610
|
|
|
|
|
611
|
|
|
$content_item = new mcontentItem($browser_title); |
|
612
|
|
|
$content_item->adds($item); |
|
613
|
|
|
$content_item->setTitle($item->title); |
|
614
|
|
|
$content_item->setCategory($category); |
|
615
|
|
|
$content_item->setNickName($item->blog_name); |
|
616
|
|
|
$content_item->setContent($item->excerpt); ///<< |
|
617
|
|
|
$content_item->setDomain($domain); ///<< |
|
618
|
|
|
$content_item->setLink($url); |
|
619
|
|
|
$content_item->add('mid', $args->mid_lists[$item->module_srl]); |
|
620
|
|
|
$content_item->setRegdate($item->regdate); |
|
621
|
|
|
$content_items[] = $content_item; |
|
622
|
|
|
} |
|
623
|
|
|
return $content_items; |
|
624
|
|
|
} |
|
625
|
|
|
|
|
626
|
|
|
function _compile($args,$content_items) |
|
627
|
|
|
{ |
|
628
|
|
|
$oTemplate = &TemplateHandler::getInstance(); |
|
629
|
|
|
// Set variables for widget |
|
630
|
|
|
$widget_info = new stdClass(); |
|
631
|
|
|
$widget_info->modules_info = $args->modules_info; |
|
632
|
|
|
$widget_info->option_view_arr = $args->option_view_arr; |
|
633
|
|
|
$widget_info->list_count = $args->list_count; |
|
634
|
|
|
$widget_info->subject_cut_size = $args->subject_cut_size; |
|
635
|
|
|
$widget_info->content_cut_size = $args->content_cut_size; |
|
636
|
|
|
|
|
637
|
|
|
$widget_info->thumbnail_type = $args->thumbnail_type; |
|
638
|
|
|
$widget_info->thumbnail_width = $args->thumbnail_width; |
|
639
|
|
|
$widget_info->thumbnail_height = $args->thumbnail_height; |
|
640
|
|
|
$widget_info->mid_lists = $args->mid_lists; |
|
641
|
|
|
|
|
642
|
|
|
$widget_info->show_browser_title = $args->show_browser_title; |
|
643
|
|
|
$widget_info->show_category = $args->show_category; |
|
644
|
|
|
$widget_info->show_comment_count = $args->show_comment_count; |
|
645
|
|
|
$widget_info->show_trackback_count = $args->show_trackback_count; |
|
646
|
|
|
$widget_info->show_icon = $args->show_icon; |
|
647
|
|
|
|
|
648
|
|
|
$widget_info->list_type = $args->list_type; |
|
649
|
|
|
$widget_info->tab_type = $args->tab_type; |
|
650
|
|
|
|
|
651
|
|
|
$widget_info->markup_type = $args->markup_type; |
|
652
|
|
|
$widget_info->content_items = $content_items; |
|
653
|
|
|
|
|
654
|
|
|
unset($args->option_view_arr); |
|
655
|
|
|
unset($args->modules_info); |
|
656
|
|
|
|
|
657
|
|
|
Context::set('colorset', $args->colorset); |
|
658
|
|
|
Context::set('widget_info', $widget_info); |
|
659
|
|
|
|
|
660
|
|
|
$tpl_path = sprintf('%sskins/%s', $this->widget_path, $args->skin); |
|
661
|
|
|
return $oTemplate->compile($tpl_path, "content"); |
|
662
|
|
|
} |
|
663
|
|
|
} |
|
664
|
|
|
|
|
665
|
|
|
class mcontentItem extends BaseObject |
|
666
|
|
|
{ |
|
667
|
|
|
|
|
668
|
|
|
var $browser_title = null; |
|
669
|
|
|
var $has_first_thumbnail_idx = false; |
|
670
|
|
|
var $first_thumbnail_idx = null; |
|
671
|
|
|
var $contents_link = null; |
|
672
|
|
|
var $domain = null; |
|
673
|
|
|
|
|
674
|
|
|
function mcontentItem($browser_title='') |
|
|
|
|
|
|
675
|
|
|
{ |
|
676
|
|
|
$this->browser_title = $browser_title; |
|
677
|
|
|
} |
|
678
|
|
|
function setContentsLink($link) |
|
679
|
|
|
{ |
|
680
|
|
|
$this->contents_link = $link; |
|
681
|
|
|
} |
|
682
|
|
View Code Duplication |
function setFirstThumbnailIdx($first_thumbnail_idx) |
|
|
|
|
|
|
683
|
|
|
{ |
|
684
|
|
|
if(is_null($this->first_thumbnail) && $first_thumbnail_idx>-1) { |
|
|
|
|
|
|
685
|
|
|
$this->has_first_thumbnail_idx = true; |
|
686
|
|
|
$this->first_thumbnail_idx= $first_thumbnail_idx; |
|
687
|
|
|
} |
|
688
|
|
|
} |
|
689
|
|
|
function setExtraImages($extra_images) |
|
690
|
|
|
{ |
|
691
|
|
|
$this->add('extra_images',$extra_images); |
|
692
|
|
|
} |
|
693
|
|
View Code Duplication |
function setDomain($domain) |
|
|
|
|
|
|
694
|
|
|
{ |
|
695
|
|
|
static $default_domain = null; |
|
696
|
|
|
if(!$domain) |
|
697
|
|
|
{ |
|
698
|
|
|
if(is_null($default_domain)) $default_domain = Context::getDefaultUrl(); |
|
699
|
|
|
$domain = $default_domain; |
|
700
|
|
|
} |
|
701
|
|
|
$this->domain = $domain; |
|
702
|
|
|
} |
|
703
|
|
|
function setLink($url) |
|
704
|
|
|
{ |
|
705
|
|
|
$this->add('url',$url); |
|
706
|
|
|
} |
|
707
|
|
|
function setTitle($title) |
|
708
|
|
|
{ |
|
709
|
|
|
$this->add('title',$title); |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
function setThumbnail($thumbnail) |
|
713
|
|
|
{ |
|
714
|
|
|
$this->add('thumbnail',$thumbnail); |
|
715
|
|
|
} |
|
716
|
|
|
function setContent($content) |
|
717
|
|
|
{ |
|
718
|
|
|
$this->add('content',$content); |
|
719
|
|
|
} |
|
720
|
|
|
function setRegdate($regdate) |
|
721
|
|
|
{ |
|
722
|
|
|
$this->add('regdate',$regdate); |
|
723
|
|
|
} |
|
724
|
|
|
function setNickName($nick_name) |
|
725
|
|
|
{ |
|
726
|
|
|
$this->add('nick_name',$nick_name); |
|
727
|
|
|
} |
|
728
|
|
|
// Save author's homepage url by misol |
|
729
|
|
|
function setAuthorSite($site_url) |
|
730
|
|
|
{ |
|
731
|
|
|
$this->add('author_site',$site_url); |
|
732
|
|
|
} |
|
733
|
|
|
function setCategory($category) |
|
734
|
|
|
{ |
|
735
|
|
|
$this->add('category',$category); |
|
736
|
|
|
} |
|
737
|
|
|
function getBrowserTitle() |
|
738
|
|
|
{ |
|
739
|
|
|
return $this->browser_title; |
|
740
|
|
|
} |
|
741
|
|
|
function getDomain() |
|
742
|
|
|
{ |
|
743
|
|
|
return $this->domain; |
|
744
|
|
|
} |
|
745
|
|
|
function getContentsLink() |
|
746
|
|
|
{ |
|
747
|
|
|
return $this->contents_link; |
|
748
|
|
|
} |
|
749
|
|
|
|
|
750
|
|
|
function getFirstThumbnailIdx() |
|
751
|
|
|
{ |
|
752
|
|
|
return $this->first_thumbnail_idx; |
|
753
|
|
|
} |
|
754
|
|
|
|
|
755
|
|
|
function getLink() |
|
756
|
|
|
{ |
|
757
|
|
|
return $this->get('url'); |
|
758
|
|
|
} |
|
759
|
|
|
function getModuleSrl() |
|
760
|
|
|
{ |
|
761
|
|
|
return $this->get('module_srl'); |
|
762
|
|
|
} |
|
763
|
|
|
function getTitle($cut_size = 0, $tail='...') |
|
764
|
|
|
{ |
|
765
|
|
|
$title = strip_tags($this->get('title')); |
|
766
|
|
|
|
|
767
|
|
|
if($cut_size) $title = cut_str($title, $cut_size, $tail); |
|
768
|
|
|
|
|
769
|
|
|
$attrs = array(); |
|
770
|
|
|
if($this->get('title_bold') == 'Y') $attrs[] = 'font-weight:bold'; |
|
771
|
|
View Code Duplication |
if($this->get('title_color') && $this->get('title_color') != 'N') $attrs[] = 'color:#'.$this->get('title_color'); |
|
772
|
|
|
|
|
773
|
|
|
if(count($attrs)) $title = sprintf("<span style=\"%s\">%s</span>", implode(';', $attrs), htmlspecialchars($title)); |
|
774
|
|
|
|
|
775
|
|
|
return $title; |
|
776
|
|
|
} |
|
777
|
|
|
function getContent() |
|
778
|
|
|
{ |
|
779
|
|
|
return $this->get('content'); |
|
780
|
|
|
} |
|
781
|
|
|
function getCategory() |
|
782
|
|
|
{ |
|
783
|
|
|
return $this->get('category'); |
|
784
|
|
|
} |
|
785
|
|
|
function getNickName() |
|
786
|
|
|
{ |
|
787
|
|
|
return $this->get('nick_name'); |
|
788
|
|
|
} |
|
789
|
|
|
function getAuthorSite() |
|
790
|
|
|
{ |
|
791
|
|
|
return $this->get('author_site'); |
|
792
|
|
|
} |
|
793
|
|
|
function getCommentCount() |
|
794
|
|
|
{ |
|
795
|
|
|
$comment_count = $this->get('comment_count'); |
|
796
|
|
|
return $comment_count>0 ? $comment_count : ''; |
|
797
|
|
|
} |
|
798
|
|
|
function getTrackbackCount() |
|
799
|
|
|
{ |
|
800
|
|
|
$trackback_count = $this->get('trackback_count'); |
|
801
|
|
|
return $trackback_count>0 ? $trackback_count : ''; |
|
802
|
|
|
} |
|
803
|
|
|
function getRegdate($format = 'Y.m.d H:i:s') |
|
804
|
|
|
{ |
|
805
|
|
|
return zdate($this->get('regdate'), $format); |
|
806
|
|
|
} |
|
807
|
|
|
function printExtraImages() |
|
808
|
|
|
{ |
|
809
|
|
|
return $this->get('extra_images'); |
|
810
|
|
|
} |
|
811
|
|
|
function haveFirstThumbnail() |
|
812
|
|
|
{ |
|
813
|
|
|
return $this->has_first_thumbnail_idx; |
|
814
|
|
|
} |
|
815
|
|
|
function getThumbnail() |
|
816
|
|
|
{ |
|
817
|
|
|
return $this->get('thumbnail'); |
|
818
|
|
|
} |
|
819
|
|
|
function getMemberSrl() |
|
820
|
|
|
{ |
|
821
|
|
|
return $this->get('member_srl'); |
|
822
|
|
|
} |
|
823
|
|
|
} |
|
824
|
|
|
/* End of file mcontent.class.php */ |
|
825
|
|
|
/* Location: ./widgets/mcontent/mcontent.class.php */ |
|
826
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.