Guest User

Untitled

a guest
Jun 21st, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. <?php
  2.  
  3. // phpbb_news includes
  4. require('./config.inc.php');
  5. require('./include/bbparser.php');
  6. require('./include/functions.php');
  7.  
  8. // This allows us to include phpBB3 files without them causing a script exit
  9. define('IN_PHPBB',true);
  10.  
  11. // Set phpbb_root_path and phpEx to allow phpbb included files to include files of their own
  12. $phpbb_root_path = PHPBB3_DIR_ABSOLUTE;
  13. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  14. require(PHPBB3_DIR_ABSOLUTE . '/config.' . $phpEx);
  15. require(PHPBB3_DIR_ABSOLUTE . '/includes/constants.' . $phpEx);
  16. require(PHPBB3_DIR_ABSOLUTE . '/includes/db/' . $dbms . '.' . $phpEx);
  17.  
  18.  
  19.  
  20. // Initialize and connect to the database using phpbb's built in DB classes
  21. $db = new $sql_db();
  22. $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false);
  23.  
  24.  
  25. // Quickly find smilies location from phpbb3 config table under 'smilies_path'
  26. $sql = 'SELECT config_value FROM `' . CONFIG_TABLE . '` WHERE config_name = "smilies_path"';
  27. $result = $db->sql_query($sql);
  28. $smilies_path = $db->sql_fetchfield('config_value');
  29.  
  30. if($smilies_path == '') {
  31. $smilies_path = '/';
  32. }
  33.  
  34.  
  35. /*
  36. * First we need to get all valid children of our target forum or category - we do this by
  37. * finding all forums with a left_id and right_id within the left_id and right_id of the
  38. * target forum, and then selecting all topics from those forums.
  39. */
  40. $sql = '
  41. SELECT t.*,fn.*,p.*, u.*, (SELECT COUNT(*) FROM `' . POSTS_TABLE . '` cc WHERE cc.topic_id = t.topic_id AND cc.post_id != t.topic_first_post_id) as comment_count FROM `' . TOPICS_TABLE . '` t
  42. INNER JOIN (`' . FORUMS_TABLE . '` fn) ON (fn.forum_id = t.forum_id)
  43. INNER JOIN (`' . POSTS_TABLE . '` p) ON (p.post_id = t.topic_first_post_id)
  44. INNER JOIN (`' . USERS_TABLE . '` u) ON (u.user_id = t.topic_poster)
  45. WHERE t.forum_id IN
  46. (
  47. SELECT fm.forum_id FROM `' . FORUMS_TABLE . '` f
  48.  
  49. INNER JOIN (`' . FORUMS_TABLE . '` fm) ON
  50. (
  51. fm.left_id > f.left_id AND fm.right_id < f.right_id
  52. )
  53.  
  54. WHERE f.forum_id = ' . PHPBB3_NEWS_FORUM_ID . '
  55. ) OR t.forum_id = ' . PHPBB3_NEWS_FORUM_ID . '
  56. ORDER BY t.topic_time DESC';
  57.  
  58.  
  59. //Grab latest 10 news articles (edit this later)
  60. $result = $db->sql_query_limit($sql,PHPBB3_NEWS_LATEST_NUMBER);
  61.  
  62. //Loop over results, parse BBCode and sanitize output
  63. while($news_item = $db->sql_fetchrow($result)) {
  64. $bbp = new BBParser($news_item['post_text'],$news_item['bbcode_uid']);
  65.  
  66. $news_item['post_text'] = $bbp->parse();
  67.  
  68. $news_item['post_text'] = nl2br(str_replace('{SMILIES_PATH}',PHPBB3_DIR_RELATIVE . $smilies_path,html_entity_decode($news_item['post_text'])));
  69. $news_item['post_time'] = date('r',$news_item['post_time']);
  70. $news_item['post_length'] = strlen($news_item['post_text']);
  71.  
  72. $b_xml = '
  73. <item id="${topic_id}">
  74. <name>${topic_title}</name>
  75. <category id="${forum_id}">
  76. <name>${forum_name}</name>
  77. <description>${forum_desc}</description>
  78. </category>
  79. <author id="${topic_poster}">
  80. <name>${topic_first_poster_name}</name>
  81. <colour>${user_colour}</colour>
  82. </author>
  83. <content bbcode_uid="${bbcode_uid}" length="${post_length}">${post_text}</content>
  84. <comments count="${comment_count}" />
  85. </item>';
  86.  
  87. $i_xml .= stringExpand($b_xml,$news_item);
  88.  
  89. }
  90.  
  91.  
  92.  
  93. header('Content-type: text/xml');
  94. echo '
  95. <page title="Latest News">
  96. <news>
  97. ' . $i_xml . '
  98. </news>
  99. </page>';
  100.  
  101.  
  102. $db->sql_freeresult($result);
  103.  
  104.  
  105. ?>
Add Comment
Please, Sign In to add comment