PageRenderTime 65ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/widgets/content/content.class.php

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