XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
content.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
9 class content extends WidgetHandler
10 {
18  function proc($args)
19  {
20  // Targets to sort
21  if(!in_array($args->order_target, array('regdate','update_order'))) $args->order_target = 'regdate';
22  // Sort order
23  if(!in_array($args->order_type, array('asc','desc'))) $args->order_type = 'asc';
24  // Pages
25  $args->page_count = (int)$args->page_count;
26  if(!$args->page_count) $args->page_count = 1;
27  // The number of displayed lists
28  $args->list_count = (int)$args->list_count;
29  if(!$args->list_count) $args->list_count = 5;
30  // The number of thumbnail columns
31  $args->cols_list_count = (int)$args->cols_list_count;
32  if(!$args->cols_list_count) $args->cols_list_count = 5;
33  // Cut the length of the title
34  if(!$args->subject_cut_size) $args->subject_cut_size = 0;
35  // Cut the length of contents
36  if(!$args->content_cut_size) $args->content_cut_size = 100;
37  // Cut the length of nickname
38  if(!$args->nickname_cut_size) $args->nickname_cut_size = 0;
39  // Display time of the latest post
40  if(!$args->duration_new) $args->duration_new = 12;
41  // How to create thumbnails
42  if(!$args->thumbnail_type) $args->thumbnail_type = 'crop';
43  // Horizontal size of thumbnails
44  if(!$args->thumbnail_width) $args->thumbnail_width = 100;
45  // Vertical size of thumbnails
46  if(!$args->thumbnail_height) $args->thumbnail_height = 75;
47  // Viewing options
48  $args->option_view_arr = explode(',',$args->option_view);
49  // markup options
50  if(!$args->markup_type) $args->markup_type = 'table';
51  // Set variables used internally
52  $oModuleModel = getModel('module');
53  $module_srls = $args->modules_info = $args->module_srls_info = $args->mid_lists = array();
54  $site_module_info = Context::get('site_module_info');
55  // List URLs if a type is RSS
56  if($args->content_type == 'rss')
57  {
58  $args->rss_urls = array();
59  $rss_urls = array_unique(array($args->rss_url0,$args->rss_url1,$args->rss_url2,$args->rss_url3,$args->rss_url4));
60  for($i=0,$c=count($rss_urls);$i<$c;$i++)
61  {
62  if($rss_urls[$i]) $args->rss_urls[] = $rss_urls[$i];
63  }
64  // Get module information after listing module_srls if the module is not RSS
65  }
66  else
67  {
68  $obj = new stdClass();
69  // Apply to all modules in the site if a target module is not specified
70  if(!$args->module_srls)
71  {
72  $obj->site_srl = (int)$site_module_info->site_srl;
73  $output = executeQueryArray('widgets.content.getMids', $obj);
74  if($output->data)
75  {
76  foreach($output->data as $key => $val)
77  {
78  $args->modules_info[$val->mid] = $val;
79  $args->module_srls_info[$val->module_srl] = $val;
80  $args->mid_lists[$val->module_srl] = $val->mid;
81  $module_srls[] = $val->module_srl;
82  }
83  }
84 
85  $args->modules_info = $oModuleModel->getMidList($obj);
86  // Apply to the module only if a target module is specified
87  }
88  else
89  {
90  $obj->module_srls = $args->module_srls;
91  $output = executeQueryArray('widgets.content.getMids', $obj);
92  if($output->data)
93  {
94  foreach($output->data as $key => $val)
95  {
96  $args->modules_info[$val->mid] = $val;
97  $args->module_srls_info[$val->module_srl] = $val;
98  $module_srls[] = $val->module_srl;
99  }
100  $idx = explode(',',$args->module_srls);
101  for($i=0,$c=count($idx);$i<$c;$i++)
102  {
103  $srl = $idx[$i];
104  if(!$args->module_srls_info[$srl]) continue;
105  $args->mid_lists[$srl] = $args->module_srls_info[$srl]->mid;
106  }
107  }
108  }
109  // Exit if no module is found
110  if(!count($args->modules_info)) return Context::get('msg_not_founded');
111  $args->module_srl = implode(',',$module_srls);
112  }
113 
117  // tab type
118  if($args->tab_type == 'none' || $args->tab_type == '')
119  {
120  switch($args->content_type)
121  {
122  case 'comment':
123  $content_items = $this->_getCommentItems($args);
124  break;
125  case 'image':
126  $content_items = $this->_getImageItems($args);
127  break;
128  case 'rss':
129  $content_items = $this->getRssItems($args);
130  break;
131  case 'trackback':
132  $content_items = $this->_getTrackbackItems($args);
133  break;
134  default:
135  $content_items = $this->_getDocumentItems($args);
136  break;
137  }
138  // If not a tab type
139  }
140  else
141  {
142  $content_items = array();
143 
144  switch($args->content_type)
145  {
146  case 'comment':
147  foreach($args->mid_lists as $module_srl => $mid)
148  {
149  $args->module_srl = $module_srl;
150  $content_items[$module_srl] = $this->_getCommentItems($args);
151  }
152  break;
153  case 'image':
154  foreach($args->mid_lists as $module_srl => $mid)
155  {
156  $args->module_srl = $module_srl;
157  $content_items[$module_srl] = $this->_getImageItems($args);
158  }
159  break;
160  case 'rss':
161  $content_items = $this->getRssItems($args);
162  break;
163  case 'trackback':
164  foreach($args->mid_lists as $module_srl => $mid)
165  {
166  $args->module_srl = $module_srl;
167  $content_items[$module_srl] = $this->_getTrackbackItems($args);
168  }
169  break;
170  default:
171  foreach($args->mid_lists as $module_srl => $mid)
172  {
173  $args->module_srl = $module_srl;
174  $content_items[$module_srl] = $this->_getDocumentItems($args);
175  }
176  break;
177  }
178  }
179 
180  $output = $this->_compile($args,$content_items);
181  return $output;
182  }
183 
188  {
189  // List variables to use CommentModel::getCommentList()
190  $obj = new stdClass();
191  $obj->module_srl = $args->module_srl;
192  $obj->sort_index = $args->order_target;
193  $obj->list_count = $args->list_count * $args->page_count;
194  // Get model object of the comment module and execute getCommentList() method
195  $oCommentModel = getModel('comment');
196  $output = $oCommentModel->getNewestCommentList($obj);
197 
198  $content_items = array();
199 
200  if(!count($output)) return;
201 
202  foreach($output as $key => $oComment)
203  {
204  $attribute = $oComment->getObjectVars();
205  $title = $oComment->getSummary($args->content_cut_size);
206  $thumbnail = $oComment->getThumbnail($args->thumbnail_width,$args->thumbnail_height,$args->thumbnail_type);
207  $url = sprintf("%s#comment_%s",getUrl('','mid', $args->mid_lists[$attribute->module_srl], 'document_srl',$oComment->get('document_srl')),$oComment->get('comment_srl'));
208 
209  $attribute->mid = $args->mid_lists[$attribute->module_srl];
210  $browser_title = $args->module_srls_info[$attribute->module_srl]->browser_title;
211  $domain = $args->module_srls_info[$attribute->module_srl]->domain;
212 
213  $content_item = new contentItem($browser_title);
214  $content_item->adds($attribute);
215  $content_item->setTitle($title);
216  $content_item->setThumbnail($thumbnail);
217  $content_item->setLink($url);
218  $content_item->setDomain($domain);
219  $content_item->add('mid', $args->mid_lists[$attribute->module_srl]);
220  $content_items[] = $content_item;
221  }
222  return $content_items;
223  }
224 
226  {
227  // Get model object from the document module
228  $oDocumentModel = getModel('document');
229  // Get categories
230  $obj = new stdClass();
231  $obj->module_srl = $args->module_srl;
232  $output = executeQueryArray('widgets.content.getCategories',$obj);
233  if($output->toBool() && $output->data)
234  {
235  foreach($output->data as $key => $val)
236  {
237  $category_lists[$val->module_srl][$val->category_srl] = $val;
238  }
239  }
240  // Get a list of documents
241  $obj->module_srl = $args->module_srl;
242  $obj->category_srl = $args->category_srl;
243  $obj->sort_index = $args->order_target;
244  if($args->order_target == 'list_order' || $args->order_target == 'update_order')
245  {
246  $obj->order_type = $args->order_type=="desc"?"asc":"desc";
247  }
248  else
249  {
250  $obj->order_type = $args->order_type=="desc"?"desc":"asc";
251  }
252  $obj->list_count = $args->list_count * $args->page_count;
253  $obj->statusList = array('PUBLIC');
254  $output = executeQueryArray('widgets.content.getNewestDocuments', $obj);
255  if(!$output->toBool() || !$output->data) return;
256  // If the result exists, make each document as an object
257  $content_items = array();
258  $first_thumbnail_idx = -1;
259  if(count($output->data))
260  {
261  foreach($output->data as $key => $attribute)
262  {
263  $oDocument = new documentItem();
264  $oDocument->setAttribute($attribute, false);
265  $GLOBALS['XE_DOCUMENT_LIST'][$oDocument->document_srl] = $oDocument;
266  $document_srls[] = $oDocument->document_srl;
267  }
268  $oDocumentModel->setToAllDocumentExtraVars();
269 
270  for($i=0,$c=count($document_srls);$i<$c;$i++)
271  {
272  $oDocument = $GLOBALS['XE_DOCUMENT_LIST'][$document_srls[$i]];
273  $document_srl = $oDocument->document_srl;
274  $module_srl = $oDocument->get('module_srl');
275  $category_srl = $oDocument->get('category_srl');
276  $thumbnail = $oDocument->getThumbnail($args->thumbnail_width,$args->thumbnail_height,$args->thumbnail_type);
277 
278  $content_item = new contentItem( $args->module_srls_info[$module_srl]->browser_title );
279  $content_item->adds($oDocument->getObjectVars());
280  $content_item->add('original_content', $oDocument->get('content'));
281  $content_item->setTitle($oDocument->getTitleText());
282  $content_item->setCategory( $category_lists[$module_srl][$category_srl]->title );
283  $content_item->setDomain( $args->module_srls_info[$module_srl]->domain );
284  $content_item->setContent($oDocument->getSummary($args->content_cut_size));
285  $content_item->setLink( getSiteUrl($domain, '', 'mid', $args->mid_lists[$module_srl],'document_srl',$document_srl) );
286  $content_item->setThumbnail($thumbnail);
287  $content_item->setExtraImages($oDocument->printExtraImages($args->duration_new * 60 * 60));
288  $content_item->add('mid', $args->mid_lists[$module_srl]);
289  if($first_thumbnail_idx==-1 && $thumbnail) $first_thumbnail_idx = $i;
290  $content_items[] = $content_item;
291  }
292 
293  $content_items[0]->setFirstThumbnailIdx($first_thumbnail_idx);
294  }
295 
296  $oSecurity = new Security($content_items);
297  $oSecurity->encodeHTML('..variables.content', '..variables.user_name', '..variables.nick_name');
298 
299  return $content_items;
300  }
301 
303  {
304  $oDocumentModel = getModel('document');
305 
306  $obj->module_srls = $obj->module_srl = $args->module_srl;
307  $obj->direct_download = 'Y';
308  $obj->isvalid = 'Y';
309  // Get categories
310  $output = executeQueryArray('widgets.content.getCategories',$obj);
311  if($output->toBool() && $output->data)
312  {
313  foreach($output->data as $key => $val)
314  {
315  $category_lists[$val->module_srl][$val->category_srl] = $val;
316  }
317  }
318  // Get a file list in each document on the module
319  $obj->list_count = $args->list_count * $args->page_count;
320  $files_output = executeQueryArray("file.getOneFileInDocument", $obj);
321  $files_count = count($files_output->data);
322  if(!$files_count) return;
323 
324  $content_items = array();
325 
326  for($i=0;$i<$files_count;$i++) $document_srl_list[] = $files_output->data[$i]->document_srl;
327 
328  $tmp_document_list = $oDocumentModel->getDocuments($document_srl_list);
329 
330  if(!count($tmp_document_list)) return;
331 
332  foreach($tmp_document_list as $oDocument)
333  {
334  $attribute = $oDocument->getObjectVars();
335  $browser_title = $args->module_srls_info[$attribute->module_srl]->browser_title;
336  $domain = $args->module_srls_info[$attribute->module_srl]->domain;
337  $category = $category_lists[$attribute->module_srl]->text;
338  $content = $oDocument->getSummary($args->content_cut_size);
339  $url = sprintf("%s#%s",$oDocument->getPermanentUrl() ,$oDocument->getCommentCount());
340  $thumbnail = $oDocument->getThumbnail($args->thumbnail_width,$args->thumbnail_height,$args->thumbnail_type);
341  $extra_images = $oDocument->printExtraImages($args->duration_new);
342 
343  $content_item = new contentItem($browser_title);
344  $content_item->adds($attribute);
345  $content_item->setCategory($category);
346  $content_item->setContent($content);
347  $content_item->setLink($url);
348  $content_item->setThumbnail($thumbnail);
349  $content_item->setExtraImages($extra_images);
350  $content_item->setDomain($domain);
351  $content_item->add('mid', $args->mid_lists[$attribute->module_srl]);
352  $content_items[] = $content_item;
353  }
354 
355  return $content_items;
356  }
357 
358  function getRssItems($args)
359  {
360  $content_items = array();
361  $args->mid_lists = array();
362 
363  foreach($args->rss_urls as $key => $rss)
364  {
365  $args->rss_url = $rss;
366  $content_item = $this->_getRssItems($args);
367  if(count($content_item) > 0)
368  {
369  $browser_title = $content_item[0]->getBrowserTitle();
370  $args->mid_lists[] = $browser_title;
371  $content_items[] = $content_item;
372  }
373  }
374  // If it is not a tab type
375  if($args->tab_type == 'none' || $args->tab_type == '')
376  {
377  $items = array();
378  foreach($content_items as $key => $val)
379  {
380  foreach($val as $k => $v)
381  {
382  $date = $v->get('regdate');
383  $i=0;
384  while(array_key_exists(sprintf('%s%02d',$date,$i), $items)) $i++;
385  $items[sprintf('%s%02d',$date,$i)] = $v;
386  }
387  }
388  if($args->order_type =='asc') ksort($items);
389  else krsort($items);
390  $content_items = array_slice(array_values($items),0,$args->list_count*$args->page_count);
391  // Tab Type
392  }
393  else
394  {
395  foreach($content_items as $key=> $content_item_list)
396  {
397  $items = array();
398  foreach($content_item_list as $k => $content_item)
399  {
400  $date = $content_item->get('regdate');
401  $i=0;
402  while(array_key_exists(sprintf('%s%02d',$date,$i), $items)) $i++;
403  $items[sprintf('%s%02d',$date,$i)] = $content_item;
404  }
405  if($args->order_type =='asc') ksort($items);
406  else krsort($items);
407 
408  $content_items[$key] = array_values($items);
409  }
410  }
411  return $content_items;
412  }
413 
414  function _getRssBody($value)
415  {
416  if(!$value || is_string($value)) return $value;
417  if(is_object($value)) $value = get_object_vars($value);
418  $body = null;
419  if(!count($value)) return;
420  foreach($value as $key => $val)
421  {
422  if($key == 'body')
423  {
424  $body = $val;
425  continue;
426  }
427  if(is_object($val)||is_array($val)) $body = $this->_getRssBody($val);
428  if($body !== null) return $body;
429  }
430  return $body;
431  }
432 
433  function _getSummary($content, $str_size = 50)
434  {
435  $content = preg_replace('!(<br[\s]*/{0,1}>[\s]*)+!is', ' ', $content);
436  // Replace tags such as </p> , </div> , </li> and others to a whitespace
437  $content = str_replace(array('</p>', '</div>', '</li>'), ' ', $content);
438  // Remove Tag
439  $content = preg_replace('!<([^>]*?)>!is','', $content);
440  // Replace tags to <, >, " and whitespace
441  $content = str_replace(array('&lt;','&gt;','&quot;','&nbsp;'), array('<','>','"',' '), $content);
442  // Delete a series of whitespaces
443  $content = preg_replace('/ ( +)/is', ' ', $content);
444  // Truncate string
445  $content = trim(cut_str($content, $str_size, $tail));
446  // Replace back <, >, " to the original tags
447  $content = str_replace(array('<','>','"'),array('&lt;','&gt;','&quot;'), $content);
448  // Fixed to a newline bug for consecutive sets of English letters
449  $content = preg_replace('/([a-z0-9\+:\/\.\~,\|\!\@\#\$\%\^\&\*\(\)\_]){20}/is',"$0-",$content);
450  return $content;
451  }
452 
457  function requestFeedContents($rss_url)
458  {
459  $rss_url = str_replace('&amp;','&',Context::convertEncodingStr($rss_url));
460  return FileHandler::getRemoteResource($rss_url, null, 3, 'GET', 'application/xml');
461  }
462 
463  function _getRssItems($args)
464  {
465  // Date Format
466  $DATE_FORMAT = $args->date_format ? $args->date_format : "Y-m-d H:i:s";
467 
468  $buff = $this->requestFeedContents($args->rss_url);
469 
470  $encoding = preg_match("/<\?xml.*encoding=\"(.+)\".*\?>/i", $buff, $matches);
471  if($encoding && stripos($matches[1], "UTF-8") === FALSE) $buff = Context::convertEncodingStr($buff);
472 
473  $buff = preg_replace("/<\?xml.*\?>/i", "", $buff);
474 
475  $oXmlParser = new XmlParser();
476  $xml_doc = $oXmlParser->parse($buff);
477  if($xml_doc->rss)
478  {
479  $rss->title = $xml_doc->rss->channel->title->body;
480  $rss->link = $xml_doc->rss->channel->link->body;
481 
482  $items = $xml_doc->rss->channel->item;
483 
484  if(!$items) return;
485  if($items && !is_array($items)) $items = array($items);
486 
487  $content_items = array();
488 
489  foreach ($items as $key => $value)
490  {
491  if($key >= $args->list_count * $args->page_count) break;
492  unset($item);
493 
494  foreach($value as $key2 => $value2)
495  {
496  if(is_array($value2)) $value2 = array_shift($value2);
497  $item->{$key2} = $this->_getRssBody($value2);
498  }
499 
500  $content_item = new contentItem($rss->title);
501  $content_item->setContentsLink($rss->link);
502  $content_item->setTitle($item->title);
503  $content_item->setNickName(max($item->author,$item->{'dc:creator'}));
504  //$content_item->setCategory($item->category);
505  $item->description = preg_replace('!<a href=!is','<a target="_blank" rel="noopener" href=', $item->description);
506  $content_item->setContent($this->_getSummary($item->description, $args->content_cut_size));
507  $content_item->setThumbnail($this->_getRssThumbnail($item->description));
508  $content_item->setLink($item->link);
509  $date = date('YmdHis', strtotime(max($item->pubdate,$item->pubDate,$item->{'dc:date'})));
510  $content_item->setRegdate($date);
511 
512  $content_items[] = $content_item;
513  }
514  }
515  else if($xml_doc->{'rdf:rdf'})
516  {
517  // rss1.0 supported (XE's XML is case-insensitive because XML parser converts all to small letters. Fixed by misol
518  $rss->title = $xml_doc->{'rdf:rdf'}->channel->title->body;
519  $rss->link = $xml_doc->{'rdf:rdf'}->channel->link->body;
520 
521  $items = $xml_doc->{'rdf:rdf'}->item;
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 * $args->page_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 contentItem($rss->title);
540  $content_item->setContentsLink($rss->link);
541  $content_item->setTitle($item->title);
542  $content_item->setNickName(max($item->author,$item->{'dc:creator'}));
543  //$content_item->setCategory($item->category);
544  $item->description = preg_replace('!<a href=!is','<a target="_blank" rel="noopener" href=', $item->description);
545  $content_item->setContent($this->_getSummary($item->description, $args->content_cut_size));
546  $content_item->setThumbnail($this->_getRssThumbnail($item->description));
547  $content_item->setLink($item->link);
548  $date = date('YmdHis', strtotime(max($item->pubdate,$item->pubDate,$item->{'dc:date'})));
549  $content_item->setRegdate($date);
550 
551  $content_items[] = $content_item;
552  }
553  }
554  else if($xml_doc->feed && $xml_doc->feed->attrs->xmlns == 'http://www.w3.org/2005/Atom')
555  {
556  // Atom 1.0 spec supported by misol
557  $rss->title = $xml_doc->feed->title->body;
558  $links = $xml_doc->feed->link;
559  if(is_array($links))
560  {
561  foreach ($links as $value)
562  {
563  if($value->attrs->rel == 'alternate')
564  {
565  $rss->link = $value->attrs->href;
566  break;
567  }
568  }
569  }
570  else if($links->attrs->rel == 'alternate') $rss->link = $links->attrs->href;
571 
572  $items = $xml_doc->feed->entry;
573 
574  if(!$items) return;
575  if($items && !is_array($items)) $items = array($items);
576 
577  $content_items = array();
578 
579  foreach ($items as $key => $value)
580  {
581  if($key >= $args->list_count * $args->page_count) break;
582  unset($item);
583 
584  foreach($value as $key2 => $value2)
585  {
586  if(is_array($value2)) $value2 = array_shift($value2);
587  $item->{$key2} = $this->_getRssBody($value2);
588  }
589 
590  $content_item = new contentItem($rss->title);
591  $links = $value->link;
592  if(is_array($links))
593  {
594  foreach ($links as $val)
595  {
596  if($val->attrs->rel == 'alternate')
597  {
598  $item->link = $val->attrs->href;
599  break;
600  }
601  }
602  }
603  else if($links->attrs->rel == 'alternate') $item->link = $links->attrs->href;
604 
605  $content_item->setContentsLink($rss->link);
606  if($item->title)
607  {
608  if(stripos($value->title->attrs->type, "html") === FALSE) $item->title = $value->title->body;
609  }
610  $content_item->setTitle($item->title);
611  $content_item->setNickName(max($item->author,$item->{'dc:creator'}));
612  $content_item->setAuthorSite($value->author->uri->body);
613 
614  //$content_item->setCategory($item->category);
615  $item->description = ($item->content) ? $item->content : $item->description = $item->summary;
616  $item->description = preg_replace('!<a href=!is','<a target="_blank" rel="noopener" href=', $item->description);
617 
618  if(($item->content && stripos($value->content->attrs->type, "html") === FALSE) || (!$item->content && stripos($value->summary->attrs->type, "html") === FALSE))
619  {
620  $item->description = htmlspecialchars($item->description, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
621 
622  }
623 
624  $content_item->setContent($this->_getSummary($item->description, $args->content_cut_size));
625  $content_item->setThumbnail($this->_getRssThumbnail($item->description));
626  $content_item->setLink($item->link);
627  $date = date('YmdHis', strtotime(max($item->published,$item->updated,$item->{'dc:date'})));
628  $content_item->setRegdate($date);
629 
630  $content_items[] = $content_item;
631  }
632  }
633  return $content_items;
634  }
635 
636  function _getRssThumbnail($content)
637  {
638  @preg_match('@<img[^>]+src\s*=\s*(?:"(.+)"|\'(.+)\'|([^\s>(?:/>)]+))@', $content, $matches);
639 
640  if($matches[1])
641  {
642  return $matches[1];
643  }
644  elseif($matches[2])
645  {
646  return $matches[2];
647  }
648  elseif($matches[3])
649  {
650  return $matches[3];
651  }
652  else
653  {
654  return NULL;
655  }
656  }
657 
659  {
660  $oTrackbackModel = getModel('trackback');
661  if(!$oTrackbackModel)
662  {
663  return;
664  }
665 
666  $obj = new stdClass;
667  // Get categories
668  $output = executeQueryArray('widgets.content.getCategories',$obj);
669  if($output->toBool() && $output->data)
670  {
671  foreach($output->data as $key => $val)
672  {
673  $category_lists[$val->module_srl][$val->category_srl] = $val;
674  }
675  }
676 
677  $obj->module_srl = $args->module_srl;
678  $obj->sort_index = $args->order_target;
679  $obj->list_count = $args->list_count * $args->page_count;
680 
681  // Get model object from the trackback module and execute getTrackbackList() method
682  $output = $oTrackbackModel->getNewestTrackbackList($obj);
683  // If an error occurs, just ignore it.
684  if(!$output->toBool() || !$output->data) return;
685  // If the result exists, make each document as an object
686  $content_items = array();
687  foreach($output->data as $key => $item)
688  {
689  $domain = $args->module_srls_info[$item->module_srl]->domain;
690  $category = $category_lists[$item->module_srl]->text;
691  $url = getSiteUrl($domain,'','document_srl',$item->document_srl);
692  $browser_title = $args->module_srls_info[$item->module_srl]->browser_title;
693 
694  $content_item = new contentItem($browser_title);
695  $content_item->adds($item);
696  $content_item->setTitle($item->title);
697  $content_item->setCategory($category);
698  $content_item->setNickName($item->blog_name);
699  $content_item->setContent($item->excerpt);
700  $content_item->setDomain($domain);
701  $content_item->setLink($url);
702  $content_item->add('mid', $args->mid_lists[$item->module_srl]);
703  $content_item->setRegdate($item->regdate);
704  $content_items[] = $content_item;
705  }
706  return $content_items;
707  }
708 
709  function _compile($args,$content_items)
710  {
711  $oTemplate = &TemplateHandler::getInstance();
712  // Set variables for widget
713  $widget_info = new stdClass();
714  $widget_info->modules_info = $args->modules_info;
715  $widget_info->option_view_arr = $args->option_view_arr;
716  $widget_info->list_count = $args->list_count;
717  $widget_info->page_count = $args->page_count;
718  $widget_info->subject_cut_size = $args->subject_cut_size;
719  $widget_info->content_cut_size = $args->content_cut_size;
720  $widget_info->nickname_cut_size = $args->nickname_cut_size;
721  $widget_info->new_window = $args->new_window;
722 
723  $widget_info->duration_new = $args->duration_new * 60*60;
724  $widget_info->thumbnail_type = $args->thumbnail_type;
725  $widget_info->thumbnail_width = $args->thumbnail_width;
726  $widget_info->thumbnail_height = $args->thumbnail_height;
727  $widget_info->cols_list_count = $args->cols_list_count;
728  $widget_info->mid_lists = $args->mid_lists;
729 
730  $widget_info->show_browser_title = $args->show_browser_title;
731  $widget_info->show_category = $args->show_category;
732  $widget_info->show_comment_count = $args->show_comment_count;
733  $widget_info->show_trackback_count = $args->show_trackback_count;
734  $widget_info->show_icon = $args->show_icon;
735 
736  $widget_info->list_type = $args->list_type;
737  $widget_info->tab_type = $args->tab_type;
738 
739  $widget_info->markup_type = $args->markup_type;
740  // If it is a tab type, list up tab items and change key value(module_srl) to index
741  if($args->tab_type != 'none' && $args->tab_type)
742  {
743  $tab = array();
744  foreach($args->mid_lists as $module_srl => $mid)
745  {
746  if(!is_array($content_items[$module_srl]) || !count($content_items[$module_srl])) continue;
747 
748  unset($tab_item);
749  $tab_item = new stdClass();
750  $tab_item->title = $content_items[$module_srl][0]->getBrowserTitle();
751  $tab_item->content_items = $content_items[$module_srl];
752  $tab_item->domain = $content_items[$module_srl][0]->getDomain();
753  $tab_item->url = $content_items[$module_srl][0]->getContentsLink();
754  if(!$tab_item->url) $tab_item->url = getSiteUrl($tab_item->domain, '','mid',$mid);
755  $tab[] = $tab_item;
756  }
757  $widget_info->tab = $tab;
758  }
759  else
760  {
761  $widget_info->content_items = $content_items;
762  }
763  unset($args->option_view_arr);
764  unset($args->modules_info);
765 
766  Context::set('colorset', $args->colorset);
767  Context::set('widget_info', $widget_info);
768 
769  $tpl_path = sprintf('%sskins/%s', $this->widget_path, $args->skin);
770  return $oTemplate->compile($tpl_path, "content");
771  }
772 }
773 
774 class contentItem extends BaseObject
775 {
776  var $browser_title = null;
779  var $contents_link = null;
780  var $domain = null;
781 
783  {
784  $this->browser_title = $browser_title;
785  }
786  function setContentsLink($link)
787  {
788  $this->contents_link = $link;
789  }
791  {
792  if(is_null($this->first_thumbnail) && $first_thumbnail_idx>-1)
793  {
794  $this->has_first_thumbnail_idx = true;
795  $this->first_thumbnail_idx= $first_thumbnail_idx;
796  }
797  }
798  function setExtraImages($extra_images)
799  {
800  $this->add('extra_images',$extra_images);
801  }
802  function setDomain($domain)
803  {
804  static $default_domain = null;
805  if(!$domain)
806  {
807  if(is_null($default_domain)) $default_domain = Context::getDefaultUrl();
808  $domain = $default_domain;
809  }
810  $this->domain = $domain;
811  }
812  function setLink($url)
813  {
814  $this->add('url', strip_tags($url));
815  }
816  function setTitle($title)
817  {
818  $this->add('title', strip_tags($title));
819  }
820  function setThumbnail($thumbnail)
821  {
822  $this->add('thumbnail', $thumbnail);
823  }
824  function setContent($content)
825  {
826  $this->add('content', removeHackTag($content));
827  }
828  function setRegdate($regdate)
829  {
830  $this->add('regdate', strip_tags($regdate));
831  }
832  function setNickName($nick_name)
833  {
834  $this->add('nick_name', strip_tags($nick_name));
835  }
836  // Save author's homepage url. By misol
837  function setAuthorSite($site_url)
838  {
839  $this->add('author_site', strip_tags($site_url));
840  }
841  function setCategory($category)
842  {
843  $this->add('category', strip_tags($category));
844  }
845  function getBrowserTitle()
846  {
847  return $this->browser_title;
848  }
849  function getDomain()
850  {
851  return $this->domain;
852  }
853  function getContentsLink()
854  {
855  return $this->contents_link;
856  }
857 
859  {
861  }
862 
863  function getLink()
864  {
865  return $this->get('url');
866  }
867  function getModuleSrl()
868  {
869  return $this->get('module_srl');
870  }
871  function getTitle($cut_size = 0, $tail='...')
872  {
873  $title = htmlspecialchars($this->get('title'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
874 
875  if($cut_size) $title = cut_str($title, $cut_size, $tail);
876 
877  $attrs = array();
878  if($this->get('title_bold') == 'Y') $attrs[] = 'font-weight:bold';
879  if($this->get('title_color') && $this->get('title_color') != 'N') $attrs[] = 'color:#'.$this->get('title_color');
880 
881  if(count($attrs)) $title = sprintf("<span style=\"%s\">%s</span>", implode(';', $attrs), $title);
882 
883  return $title;
884  }
885  function getContent()
886  {
887  return $this->get('content');
888  }
889  function getCategory()
890  {
891  return $this->get('category');
892  }
893  function getNickName($cut_size = 0, $tail='...')
894  {
895  if($cut_size) $nick_name = cut_str($this->get('nick_name'), $cut_size, $tail);
896  else $nick_name = $this->get('nick_name');
897 
898  return $nick_name;
899  }
900  function getAuthorSite()
901  {
902  return $this->get('author_site');
903  }
904  function getCommentCount()
905  {
906  $comment_count = $this->get('comment_count');
907  return $comment_count>0 ? $comment_count : '';
908  }
909  function getTrackbackCount()
910  {
911  $trackback_count = $this->get('trackback_count');
912  return $trackback_count>0 ? $trackback_count : '';
913  }
914  function getRegdate($format = 'Y.m.d H:i:s')
915  {
916  return zdate($this->get('regdate'), $format);
917  }
918  function printExtraImages()
919  {
920  return $this->get('extra_images');
921  }
923  {
925  }
926  function getThumbnail()
927  {
928  return $this->get('thumbnail');
929  }
930  function getMemberSrl()
931  {
932  return $this->get('member_srl');
933  }
934 }
935 /* End of file content.class.php */
936 /* Location: ./widgets/content/content.class.php */
setFirstThumbnailIdx($first_thumbnail_idx)
$oModuleModel
Definition: ko.install.php:236
_compile($args, $content_items)
zdate($str, $format= 'Y-m-d H:i:s', $conversion=TRUE)
Definition: func.inc.php:692
getRssItems($args)
$args title
Definition: ko.install.php:189
$obj
Definition: ko.install.php:262
if(file_exists(_XE_PATH_. 'config/config.user.inc.php')) if(!defined('__DEBUG__')) if(!defined('__DEBUG_OUTPUT__')) if(!defined('__DEBUG_PROTECT__')) if(!defined('__DEBUG_PROTECT_IP__')) if(!defined('__DEBUG_DB_OUTPUT__')) if(!defined('__LOG_SLOW_QUERY__')) if(!defined('__LOG_SLOW_TRIGGER__')) if(!defined('__LOG_SLOW_ADDON__')) if(!defined('__LOG_SLOW_WIDGET__')) if(!defined('__DEBUG_QUERY__')) if(!defined('__OB_GZHANDLER_ENABLE__')) if(!defined('__ENABLE_PHPUNIT_TEST__')) if(!defined('__PROXY_SERVER__')) if(!defined('__ERROR_LOG__')) if(!defined('__DISABLE_DEFAULT_CSS__')) if(!defined('__AUTO_OPCACHE_INVALIDATE__')) if((__DEBUG_OUTPUT__==2)&&version_compare(PHP_VERSION, '6.0.0')===-1) if(version_compare(PHP_VERSION, '5.3.0') >=0) $GLOBALS['__xe_autoload_file_map']
Definition: config.inc.php:324
$output
Definition: ko.install.php:193
add($key, $val)
requestFeedContents($rss_url)
function to receive contents from rss url For Tistory blog in Korea, the original RSS url has locatio...
set($key, $val, $set_to_get_vars=0)
setAuthorSite($site_url)
_getTrackbackItems($args)
_getDocumentItems($args)
Handler class for widget execution.
__construct($browser_title='')
getRemoteResource($url, $body=null, $timeout=3, $method= 'GET', $content_type=null, $headers=array(), $cookies=array(), $post_data=array(), $request_config=array())
_getRssThumbnail($content)
_getCommentItems($args)
Get a list of comments and return contentItem.
$args
Definition: ko.install.php:185
setTitle($title)
setRegdate($regdate)
setDomain($domain)
$document_srl
Definition: ko.install.php:279
widget to display content
$oDocumentModel
Definition: ko.install.php:259
_getImageItems($args)
_getSummary($content, $str_size=50)
getTitle($cut_size=0, $tail='...')
setThumbnail($thumbnail)
setNickName($nick_name)
_getRssBody($value)
removeHackTag($content)
Definition: func.inc.php:1123
getModel($module_name)
Definition: func.inc.php:145
getNickName($cut_size=0, $tail='...')
_getRssItems($args)
convertEncodingStr($str)
setContent($content)
executeQueryArray($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:219
$module_srl
Definition: ko.install.php:254
setContentsLink($link)
cut_str($string, $cut_size=0, $tail= '...')
Definition: func.inc.php:508
setExtraImages($extra_images)
getRegdate($format= 'Y.m.d H:i:s')
proc($args)
Widget handler.
getUrl()
Definition: func.inc.php:297
getSiteUrl()
Definition: func.inc.php:411
setCategory($category)