PageRenderTime 27ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/include/inc_module/mod_feedimport/frontend.init.php

http://phpwcms.googlecode.com/
PHP | 215 lines | 136 code | 55 blank | 24 comment | 16 complexity | 537ee403593708f0a24b4bd224537514 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, ISC, MIT, LGPL-3.0, GPL-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * phpwcms content management system
  4. *
  5. * @author Oliver Georgi <oliver@phpwcms.de>
  6. * @copyright Copyright (c) 2002-2013, Oliver Georgi
  7. * @license http://opensource.org/licenses/GPL-2.0 GNU GPL-2
  8. * @link http://www.phpwcms.de
  9. *
  10. **/
  11. // Module/Plug-in Feed to Article import default settings
  12. // Init used to import feed to articles
  13. if(!empty($_getVar['feedimport'])) {
  14. // catch the Feed to be imported to article
  15. $feedimport_source = $_getVar['feedimport'];
  16. $feedimport_where = "cnt_status=1 AND cnt_module='feedimport' AND ";
  17. if(strlen($feedimport_source) > 32 && substr($feedimport_source, 32) == '-now') {
  18. $feedimport_source = substr($feedimport_source, 0, 32);
  19. } else {
  20. $feedimport_where .= 'IF(cnt_prio=0, 1, '.now().'-cnt_sort>cnt_prio) AND ';
  21. }
  22. $feedimport_where .= 'MD5(CONCAT(cnt_id,cnt_text))='._dbEscape($feedimport_source);
  23. unset($_getVar['feedimport']);
  24. $feedimport_result = _dbGet('phpwcms_content', 'cnt_id,cnt_name,cnt_text,cnt_object', $feedimport_where);
  25. if(isset($feedimport_result[0]['cnt_id'])) {
  26. $feedimport_result = $feedimport_result[0];
  27. $feedimport_result['cnt_object'] = @unserialize($feedimport_result['cnt_object']);
  28. }
  29. if(isset($feedimport_result['cnt_object']['structure_level_id'])) {
  30. // retrieve Feed now
  31. // Load SimplePie
  32. require_once(PHPWCMS_ROOT.'/include/inc_ext/simplepie.inc.php');
  33. $rss_obj = new SimplePie();
  34. // Feed URL
  35. $rss_obj->set_feed_url( $feedimport_result['cnt_text'] );
  36. // Output Encoding Charset
  37. $rss_obj->set_output_encoding( PHPWCMS_CHARSET );
  38. // Disable Feed cache
  39. $rss_obj->enable_cache( false );
  40. // Remove surrounding DIV
  41. $rss_obj->remove_div( true );
  42. // Init Feed
  43. $rss_obj->init();
  44. if( $rss_obj->data ) {
  45. $feedimport_result['status'] = array(
  46. 'Feed Importer Status - ' . date('Y-m-d, H:i:s') . LF . '===========================================',
  47. $feedimport_result['cnt_name'] . LF . $feedimport_result['cnt_text'] . LF
  48. );
  49. // need some additional functions
  50. include_once(PHPWCMS_ROOT.'/include/inc_lib/backend.functions.inc.php');
  51. foreach($rss_obj->get_items() as $rssvalue) {
  52. $article_unique_hash = md5( $feedimport_result['cnt_text'] . $rssvalue->get_title() . $rssvalue->get_date('U') );
  53. // check against crossreference table
  54. $sql = 'SELECT * FROM '.DB_PREPEND.'phpwcms_crossreference c ';
  55. $sql .= 'LEFT JOIN '.DB_PREPEND.'phpwcms_article a ';
  56. $sql .= 'ON c.cref_rid=a.article_id ';
  57. $sql .= "WHERE c.cref_type='feed_to_article_import' AND c.cref_str="._dbEscape('feedimport_'.$article_unique_hash).' AND ';
  58. $sql .= 'a.article_deleted=0 LIMIT 1';
  59. if(_dbQuery($sql, 'COUNT') > 0) {
  60. continue;
  61. }
  62. $article_title = html_entity_decode($rssvalue->get_title(), ENT_COMPAT, PHPWCMS_CHARSET);
  63. $article_alias = proof_alias(0, $article_title, 'ARTICLE');
  64. $article_begin = $rssvalue->get_date('U');
  65. $article_end = now()+(3600*24*365*10);
  66. $article_summary = $rssvalue->get_description();
  67. $article_content = $rssvalue->get_content();
  68. $article_description = preg_replace('/\s+/', ' ', html_entity_decode(strip_tags($article_summary), ENT_COMPAT, PHPWCMS_CHARSET));
  69. list($article_description) = explode("\n", wordwrap($article_description, 250), 2);
  70. list($article_description) = explode("-- ", $article_description, 2);
  71. $article_description = preg_replace('/(.*?\.).+?$/', '$1', $article_description);
  72. $article_author = $rssvalue->get_author();
  73. if($article_author) {
  74. $article_author = html_entity_decode($article_author->get_name());
  75. } else {
  76. $article_author = $feedimport_result['cnt_object']['author_name'];
  77. }
  78. if($feedimport_result['cnt_object']['source_link_add'] && $rssvalue->get_permalink()) {
  79. $article_content .= '<p><a href="'.$rssvalue->get_permalink().'" class="feed-permalink">' . (empty($feedimport_result['cnt_object']['source_link_text']) ? '@@Source@@' : $feedimport_result['cnt_object']['source_link_text']) . '</a></p>';
  80. }
  81. // define article data
  82. $data = array(
  83. 'article_created' => now(),
  84. "article_cid" => $feedimport_result['cnt_object']['structure_level_id'],
  85. "article_uid" => $feedimport_result['cnt_object']['author_id'],
  86. "article_title" => $article_title,
  87. "article_alias" => $article_alias,
  88. "article_keyword" => '',
  89. "article_public" => 1,
  90. "article_aktiv" => $feedimport_result['cnt_object']['activate_after_import'],
  91. "article_begin" => date('Y-m-d H:i:s', $article_begin),
  92. "article_end" => date('Y-m-d 23:59:59', $article_end),
  93. "article_subtitle" => '',
  94. "article_summary" => $article_content,
  95. "article_redirect" => '',
  96. "article_sort" => $article_begin,
  97. "article_username" => $article_author,
  98. "article_notitle" => 0,
  99. "article_hidesummary" => 0,
  100. "article_image" => array(
  101. 'tmpllist' => $feedimport_result['cnt_object']['article_template_list'],
  102. 'tmplfull' => $feedimport_result['cnt_object']['article_template_detail'],
  103. 'name' => '',
  104. 'id' => '',
  105. 'caption' => '',
  106. "hash" => '',
  107. 'list_usesummary' => 0,
  108. 'list_name' => '',
  109. 'list_id' => 0,
  110. 'list_width' => '',
  111. 'list_height' => '',
  112. 'list_zoom' => 0,
  113. 'list_caption' => '',
  114. "list_hash" => '',
  115. 'zoom' => 0
  116. ),
  117. "article_cache" => '',
  118. "article_nosearch" => 0,
  119. "article_nositemap" => 0,
  120. "article_aliasid" => 0,
  121. "article_headerdata" => 0,
  122. "article_morelink" => 1,
  123. "article_pagetitle" => '',
  124. "article_paginate" => 0,
  125. "article_priorize" => 0,
  126. "article_norss" => 0,
  127. "article_archive_status"=> 1,
  128. "article_menutitle" => '',
  129. 'article_description' => $article_description,
  130. 'article_serialized' => ''
  131. );
  132. $data['article_image'] = serialize($data['article_image']);
  133. $result = _dbInsert('phpwcms_article', $data);
  134. if(isset($result['INSERT_ID'])) {
  135. $feedimport_result['status'][] = date('Y-m-d, H:i:s', $article_begin) . LF . $article_title . LF . $rssvalue->get_permalink() . LF . PHPWCMS_URL . 'phpwcms.php?do=articles&p=2&s=1&id='.$result['INSERT_ID'];
  136. $data = array(
  137. 'cref_type' => 'feed_to_article_import',
  138. 'cref_rid' => $result['INSERT_ID'],
  139. 'cref_str' => 'feedimport_'.$article_unique_hash
  140. );
  141. _dbInsert('phpwcms_crossreference', $data);
  142. }
  143. }
  144. // check if status email should be sent
  145. if(!empty($feedimport_result['cnt_object']['import_status_email']) && is_valid_email($feedimport_result['cnt_object']['import_status_email'])) {
  146. $feedimport_result['status'] = implode(LF.LF, $feedimport_result['status']);
  147. sendEmail(array(
  148. 'recipient' => $feedimport_result['cnt_object']['import_status_email'],
  149. 'subject' => 'Import Status: ' . $feedimport_result['cnt_name'],
  150. 'isHTML' => 0,
  151. 'text' => $feedimport_result['status'],
  152. 'fromName' => 'Feed Importer'
  153. ));
  154. }
  155. }
  156. }
  157. // we quit here
  158. exit();
  159. }
  160. ?>