PageRenderTime 71ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/forum/gym_sitemaps/includes/gym_rss_functions.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 435 lines | 389 code | 1 blank | 45 comment | 48 complexity | 8d1033e2241bccf8478d88db3129b495 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. *
  4. * @package phpBB SEO GYM Sitemaps
  5. * @version $Id: gym_rss_functions.php 286 2010-12-04 19:24:05Z dcz $
  6. * @copyright (c) 2006 - 2010 www.phpbb-seo.com
  7. * @license http://opensource.org/osi3.0/licenses/lgpl-license.php GNU Lesser General Public License
  8. *
  9. */
  10. // First basic security
  11. if ( !defined('IN_PHPBB') ) {
  12. exit;
  13. }
  14. define('GYM_RSS_FUNC_INC', true);
  15. /**
  16. * get_gym_links($gym_config).
  17. * retunrs the link array
  18. */
  19. function get_gym_links($gym_config) {
  20. global $phpbb_root_path, $config, $phpEx, $user, $cache, $db, $phpbb_seo;
  21. $links = array();
  22. $_phpbb_seo = !empty($phpbb_seo);
  23. $board_url = $_phpbb_seo ? $phpbb_seo->seo_path['phpbb_url'] : generate_board_url() . '/';
  24. $gym_link_tpl = '<a href="%1$s" title="%3$s" class="gym"><img src="' . $board_url . 'gym_sitemaps/images/%2$s" alt="%3$s" width="14" height="14"/>&nbsp;%3$s</a>';
  25. $google_threshold = max(1, (int) $gym_config['google_threshold']);
  26. //compute guest auth
  27. $cache_file = '_gym_auth_guests_forum';
  28. if (($auth_guest_list = $cache->get($cache_file)) === false) {
  29. $auth_guest_list = array('list' => array(), 'read' => array(), 'list_post' => array(), 'read_post' => array(), 'skip_pass' => array(), 'skip_cat' => array(), 'skip_all' => array(), 'skip_link' => array(), 'thresholded' => array(), 'empty' => array());
  30. $guest_data = array('user_id' => ANONYMOUS,
  31. 'user_type' => USER_IGNORE,
  32. 'user_permissions' . (defined('XLANG_AKEY') ? XLANG_AKEY : '') => '',
  33. );
  34. $g_auth = new auth();
  35. $g_auth->acl($guest_data);
  36. // the forum id array
  37. $forum_list_ary = $g_auth->acl_getf('f_list', true);
  38. foreach ($forum_list_ary as $forum_id => $null) {
  39. $auth_guest_list['list'][$forum_id] = (int) $forum_id;
  40. }
  41. $forum_read_ary = $g_auth->acl_getf('f_read', true);
  42. foreach ($forum_read_ary as $forum_id => $null) {
  43. $auth_guest_list['read'][$forum_id] = (int) $forum_id;
  44. }
  45. ksort($auth_guest_list['list']);
  46. ksort($auth_guest_list['read']);
  47. $sql = "SELECT forum_id, forum_type, forum_password
  48. FROM " . FORUMS_TABLE . "
  49. WHERE forum_type <> " . FORUM_POST . " OR forum_password <> ''";
  50. $result = $db->sql_query($sql);
  51. while ( $row = $db->sql_fetchrow($result) ) {
  52. $forum_id = (int) $row['forum_id'];
  53. if ($row['forum_password']) {
  54. $auth_guest_list['skip_pass'][$forum_id] = $forum_id;
  55. }
  56. if ($row['forum_type'] == FORUM_CAT) {
  57. $auth_guest_list['skip_cat'][$forum_id] = $forum_id;
  58. } else if ($row['forum_type'] == FORUM_LINK) {
  59. $auth_guest_list['skip_link'][$forum_id] = $forum_id;
  60. }
  61. $auth_guest_list['skip_all'][$forum_id] = $forum_id;
  62. }
  63. $db->sql_freeresult($result);
  64. // Now let's grabb the list of forum with not enough topics to have a sitemap
  65. // Only care about postable forum ;-)
  66. $sql = "SELECT forum_id, forum_topics
  67. FROM " . FORUMS_TABLE . "
  68. WHERE forum_type = " . FORUM_POST . "
  69. AND forum_topics < $google_threshold";
  70. $result = $db->sql_query($sql);
  71. while ( $row = $db->sql_fetchrow($result) ) {
  72. $forum_id = (int) $row['forum_id'];
  73. $auth_guest_list['thresholded'][$forum_id] = $forum_id;
  74. if (empty($row['forum_topics'])) {
  75. $auth_guest_list['empty'][$forum_id] = $forum_id;
  76. }
  77. }
  78. ksort($auth_guest_list['skip_pass']);
  79. ksort($auth_guest_list['skip_all']);
  80. ksort($auth_guest_list['skip_link']);
  81. ksort($auth_guest_list['skip_cat']);
  82. // Never mind about forum links
  83. $auth_guest_list['read'] = array_diff_assoc($auth_guest_list['read'], $auth_guest_list['skip_link']);
  84. $auth_guest_list['list'] = array_diff_assoc($auth_guest_list['list'], $auth_guest_list['skip_link']);
  85. ksort($auth_guest_list['read']);
  86. ksort($auth_guest_list['list']);
  87. $auth_guest_list['list_post'] = array_diff_assoc($auth_guest_list['list'], $auth_guest_list['skip_all']);
  88. $auth_guest_list['read_post'] = array_diff_assoc($auth_guest_list['read'], $auth_guest_list['skip_all']);
  89. $cache->put($cache_file, $auth_guest_list);
  90. }
  91. $links = array();
  92. $links['main'] = $links['setup']['google'] = $links['setup']['rss'] = $links['setup']['html'] = array();
  93. // Find out about active modes
  94. $google_active = $rss_active = $html_active = false;
  95. $gym_modules = array(
  96. 'google' => array('forum', 'xml', 'txt'),
  97. 'rss' => array('forum'),
  98. 'html' => array('forum'),
  99. );
  100. foreach ($gym_modules as $type => $modules) {
  101. foreach ($modules as $module) {
  102. if (!empty($gym_config[$type . '_' . $module . '_installed'])) {
  103. ${$type . '_active'} = true;
  104. break;
  105. }
  106. }
  107. }
  108. $do_display_cat = $do_display_main = $do_display_index = false;
  109. // Google sitemaps
  110. if ($google_active) {
  111. $display_google_main_links = (boolean) get_gym_option('google', 'gym', 'link_main', OVERRIDE_MODULE, $gym_config);
  112. $display_google_index_links = (boolean) get_gym_option('google', 'gym', 'link_index', OVERRIDE_MODULE, $gym_config);
  113. $display_google_cat_links = (boolean) get_gym_option('google', 'gym', 'link_cat', OVERRIDE_MODULE, $gym_config);
  114. $override_google_mod_rewrite = get_override('google', 'modrewrite', $gym_config);
  115. $google_mod_rewrite = (boolean) get_gym_option('google', 'gym', 'modrewrite', $override_google_mod_rewrite, $gym_config);
  116. $override_google_gzip = get_override('google', 'gzip', $gym_config);
  117. $google_gzip = (boolean) get_gym_option('google', 'forum', 'gzip', $override_google_gzip, $gym_config);
  118. $google_gzip_ext = ($google_gzip || $config['gzip_compress']) ? (get_gym_option('google', 'forum', 'gzip_ext', $override_google_gzip, $gym_config) ? '.gz' : '') : '';
  119. $google_url = $_phpbb_seo ? $phpbb_seo->sslify($gym_config['google_url'], $phpbb_seo->ssl['use'], false) : $gym_config['google_url'];
  120. $sitemap_url = $google_url . ($google_mod_rewrite ? 'sitemapindex.xml' . $google_gzip_ext : "sitemap.$phpEx");
  121. $links['setup']['google'] = array(
  122. 'override_mod_rewrite' => $override_google_mod_rewrite,
  123. 'mod_rewrite' => $google_mod_rewrite,
  124. 'override_gzip' => $override_google_gzip,
  125. 'link_main' => $display_google_main_links,
  126. 'link_index' => $display_google_index_links,
  127. 'link_cat' => $display_google_cat_links,
  128. 'gzip' => $google_gzip,
  129. 'gzip_ext' => $google_gzip_ext,
  130. 'google_url' => $google_url,
  131. 'threshold' => max(1, (int) $gym_config['google_threshold']),
  132. 'l_google_sitemap' => $user->lang['GOOGLE_SITEMAP'],
  133. 'l_google_sitemap_of' => $user->lang['GOOGLE_MAP_OF'],
  134. );
  135. // only publicly readable and not thresholded forums will be listed
  136. if (!empty($gym_config['google_forum_installed'])) {
  137. $google_forum_mod_rewrite = (boolean) get_gym_option('google', 'forum', 'modrewrite', $override_google_mod_rewrite, $gym_config);
  138. $google_auth_guest = array_diff_assoc($auth_guest_list['read_post'], set_exclude_list($gym_config['google_forum_exclude']), $auth_guest_list['thresholded']);
  139. $google_forum_exclude = set_exclude_list($gym_config['google_forum_exclude']) + $auth_guest_list['skip_all'];
  140. $links['setup']['google'] = array_merge( $links['setup']['google'],
  141. array(
  142. 'forum_google' => true,
  143. 'forum_cat_google' => $google_url . ($google_forum_mod_rewrite && $_phpbb_seo ? "%1\$s.xml$google_gzip_ext" : "sitemap.$phpEx?forum=%2\$s"),
  144. 'auth_guest' => $google_auth_guest,
  145. 'forum_exclude' => $google_forum_exclude,
  146. ));
  147. }
  148. $links['main'] = array_merge( $links['main'],
  149. array(
  150. 'GYM_GOOGLE_TITLE' => $user->lang['GOOGLE_SITEMAPINDEX'],
  151. 'GYM_GOOGLE_URL' => $sitemap_url,
  152. 'GYM_GOOGLE_LINK' => $display_google_main_links ? sprintf($gym_link_tpl, $sitemap_url, 'sitemap-icon.gif', $user->lang['GOOGLE_SITEMAPINDEX']) : '',
  153. 'GYM_GOOGLE_THRESOLD' => (int) $links['setup']['google']['threshold'],
  154. ));
  155. $do_display_main = $display_google_main_links ? true : $do_display_main;
  156. $do_display_index = $display_google_index_links ? true : $do_display_index;
  157. $do_display_cat = $display_google_cat_links ? true : $do_display_cat;
  158. }
  159. // RSS
  160. if ($rss_active) {
  161. $display_rss_main_links = (boolean) get_gym_option('rss', 'gym', 'link_main', OVERRIDE_MODULE, $gym_config);
  162. $display_rss_index_links = (boolean) get_gym_option('rss', 'gym', 'link_index', OVERRIDE_MODULE, $gym_config);
  163. $display_rss_cat_links = (boolean) get_gym_option('rss', 'gym', 'link_cat', OVERRIDE_MODULE, $gym_config);
  164. $override_rss_mod_rewrite = get_override('rss', 'modrewrite', $gym_config);
  165. $rss_mod_rewrite = (boolean) get_gym_option('rss', 'gym', 'modrewrite', $override_rss_mod_rewrite, $gym_config);
  166. $rss_modrtype = max(0, (int) get_gym_option('rss', 'gym', 'modrtype', $override_rss_mod_rewrite, $gym_config));
  167. $override_rss_gzip = get_override('rss', 'gzip', $gym_config);
  168. $rss_gzip = (boolean) get_gym_option('rss', 'forum', 'gzip', $override_rss_gzip, $gym_config);
  169. $rss_gzip_ext = ($rss_gzip || $config['gzip_compress']) ? (get_gym_option('rss', 'forum', 'gzip_ext', $override_rss_gzip, $gym_config) ? '.gz' : '') : '';
  170. // Take car of linking type
  171. $link_type_sep = $rss_mod_rewrite ? '/' : '&amp;';
  172. $link_type_to_options = array('n' => 'news', 'nd' => 'news'. $link_type_sep . 'digest', 'r' => '', 'rd' => 'digest');
  173. $link_type_bit = isset($link_type_to_options[$gym_config['rss_linking_type']]) ? $link_type_to_options[$gym_config['rss_linking_type']] : '';
  174. $rss_url = $_phpbb_seo ? $phpbb_seo->sslify($gym_config['rss_url'], $phpbb_seo->ssl['use'], false) : $gym_config['rss_url'];
  175. $rss_main_url = $rss_url . ($rss_mod_rewrite ? 'rss/' . ($link_type_bit ? $link_type_bit . '/' : '') . 'rss.xml' . $rss_gzip_ext : "gymrss.$phpEx" . ($link_type_bit ? '?' . $link_type_bit : ''));
  176. $rss_chan_url = $rss_url . ($rss_mod_rewrite ? 'rss/' . ($link_type_bit ? $link_type_bit . '/' : '') : "gymrss.$phpEx?channels" . ($link_type_bit ? '&amp;' . $link_type_bit : ''));
  177. $links['setup']['rss'] = array(
  178. 'display_alternate' => (int) $gym_config['rss_alternate'],
  179. 'link_main' => $display_rss_main_links,
  180. 'link_index' => $display_rss_index_links,
  181. 'link_cat' => $display_rss_cat_links,
  182. 'override_mod_rewrite' => $override_rss_mod_rewrite,
  183. 'mod_rewrite' => $rss_mod_rewrite,
  184. 'override_gzip' => $override_rss_gzip,
  185. 'gzip' => $rss_gzip,
  186. 'gzip_ext' => $rss_gzip_ext,
  187. 'rss_url' => $rss_url,
  188. 'l_rss_feed' => $user->lang['RSS_FEED'],
  189. 'l_rss_feed_of' => $user->lang['RSS_FEED_OF'],
  190. );
  191. if (!empty($gym_config['rss_forum_installed'])) {
  192. $rss_forum_allow_auth = (boolean) get_gym_option('rss', 'forum', 'allow_auth', $gym_config['rss_override'], $gym_config);
  193. // only readable forums can be listed
  194. $rss_auth_guest = array_diff_assoc($auth_guest_list['read_post'], set_exclude_list($gym_config['rss_forum_exclude']), $auth_guest_list['empty']);
  195. $rss_forum_exclude = set_exclude_list($gym_config['rss_forum_exclude']) + $auth_guest_list['skip_all'] + $auth_guest_list['empty'];
  196. $rss_forum_mod_rewrite = (boolean) get_gym_option('rss', 'forum', 'modrewrite', $override_rss_mod_rewrite, $gym_config);
  197. $rss_forum_modrtype = max(0, (int) get_gym_option('rss', 'forum', 'modrtype', $override_rss_mod_rewrite, $gym_config));
  198. $links['setup']['rss'] = array_merge( $links['setup']['rss'],
  199. array(
  200. 'display_forum_alternate' => (int) $gym_config['rss_forum_alternate'],
  201. 'forum_rss' => !empty($gym_config['rss_forum_installed']),
  202. 'forum_cat_rss' => $rss_url . ($rss_forum_mod_rewrite && $_phpbb_seo ? ($rss_forum_modrtype > 1 ? "%1\$s/" . ($link_type_bit ? $link_type_bit . '/' : '') . "forum.xml$rss_gzip_ext" : "forum" . $phpbb_seo->seo_delim['forum'] . "%2\$s/" . ($link_type_bit ? $link_type_bit . '/' : '') . "forum.xml$rss_gzip_ext") : "gymrss.$phpEx?forum=%2\$s" . ($link_type_bit ? '&amp;' . $link_type_bit : '')),
  203. 'auth_guest' => $rss_auth_guest,
  204. 'forum_exclude' => $rss_forum_exclude,
  205. 'forum_allow_auth' => $rss_forum_allow_auth,
  206. ));
  207. }
  208. $links['main'] = array_merge( $links['main'],
  209. array(
  210. 'GYM_RSS_TITLE' => $user->lang['RSS_FEED'],
  211. 'GYM_RSS_URL' => $rss_main_url,
  212. 'GYM_RSS_LINK' => $display_rss_main_links ? sprintf($gym_link_tpl, $rss_main_url, 'feed-icon.png', $user->lang['RSS_FEED']) : '',
  213. 'GYM_RSS_CHAN_TITLE' => $user->lang['RSS_CHAN_LIST_TITLE'],
  214. 'GYM_RSS_CHAN_URL' => $rss_chan_url,
  215. 'GYM_RSS_CHAN_LINK' => $display_rss_main_links ? sprintf($gym_link_tpl, $rss_chan_url, 'feed-icon.png', $user->lang['RSS_CHAN_LIST_TITLE']) : '',
  216. ));
  217. $do_display_main = $display_rss_main_links ? true : $do_display_main;
  218. $do_display_index = $display_rss_index_links ? true : $do_display_index;
  219. $do_display_cat = $display_rss_cat_links ? true : $do_display_cat;
  220. }
  221. // HTML
  222. if ($html_active) {
  223. $display_html_main_links = (boolean) get_gym_option('html', 'gym', 'link_main', OVERRIDE_MODULE, $gym_config);
  224. $display_html_index_links = (boolean) get_gym_option('html', 'gym', 'link_index', OVERRIDE_MODULE, $gym_config);
  225. $display_html_cat_links = (boolean) get_gym_option('html', 'gym', 'link_cat', OVERRIDE_MODULE, $gym_config);
  226. $override_html_mod_rewrite = get_override('html', 'modrewrite', $gym_config);
  227. $html_mod_rewrite = (boolean) get_gym_option('html', 'gym', 'modrewrite', $override_html_mod_rewrite, $gym_config);
  228. $html_allow_map = (boolean) $gym_config['html_allow_map'];
  229. $html_allow_cat_map = (boolean) $gym_config['html_allow_cat_map'];
  230. $html_allow_news = (boolean) $gym_config['html_allow_news'];
  231. $html_allow_cat_news = (boolean) $gym_config['html_allow_cat_news'];
  232. $html_url = $_phpbb_seo ? $phpbb_seo->sslify($gym_config['html_url'], $phpbb_seo->ssl['use'], false) : $gym_config['html_url'];
  233. $html_map_url = $gym_config['html_allow_map'] ? $html_url . ($html_mod_rewrite ? 'maps/' : "map.$phpEx") : '';
  234. $html_news_url = $gym_config['html_allow_news'] ? $html_url . ($html_mod_rewrite ? 'news/' : "map.$phpEx?news") : '';
  235. $links['setup']['html'] = array(
  236. 'link_main' => $display_html_main_links,
  237. 'link_index' => $display_html_index_links,
  238. 'link_cat' => $display_html_cat_links,
  239. 'override_mod_rewrite' => $override_html_mod_rewrite,
  240. 'mod_rewrite' => $html_mod_rewrite,
  241. 'html_url' => $html_url,
  242. 'allow_map' => $html_allow_map,
  243. 'allow_news' => $html_allow_news,
  244. 'allow_cat_map' => $html_allow_cat_map,
  245. 'allow_cat_news' => $html_allow_cat_news,
  246. 'l_html_news' => $user->lang['HTML_NEWS'],
  247. 'l_html_map' => $user->lang['HTML_MAP'],
  248. 'l_html_news_of' => $user->lang['HTML_NEWS_OF'],
  249. 'l_html_map_of' => $user->lang['HTML_MAP_OF'],
  250. );
  251. if (!empty($gym_config['html_forum_installed'])) {
  252. $html_forum_mod_rewrite = (boolean) get_gym_option('html', 'forum', 'modrewrite', $override_html_mod_rewrite, $gym_config);
  253. $html_forum_allow_map = (boolean) get_gym_option('html', 'forum', 'allow_map', $gym_config['html_override'], $gym_config);
  254. $html_forum_allow_cat_map = (boolean) get_gym_option('html', 'forum', 'allow_cat_map', $gym_config['html_override'], $gym_config);
  255. $html_forum_allow_news = (boolean) get_gym_option('html', 'forum', 'allow_news', $gym_config['html_override'], $gym_config);
  256. $html_forum_allow_cat_news = (boolean) get_gym_option('html', 'forum', 'allow_cat_news', $gym_config['html_override'], $gym_config);
  257. $html_auth_guest = array_diff_assoc($auth_guest_list['list'], set_exclude_list($gym_config['html_forum_exclude']), $auth_guest_list['empty']);
  258. $html_forum_allow_auth = (boolean) get_gym_option('html', 'forum', 'allow_auth', $gym_config['html_override'], $gym_config);
  259. $html_forum_exclude = set_exclude_list($gym_config['html_forum_exclude']) + $auth_guest_list['skip_link'] + $auth_guest_list['empty'];
  260. $links['setup']['html'] = array_merge( $links['setup']['html'],
  261. array(
  262. 'forum_allow_map' => $html_forum_allow_map,
  263. 'forum_map_url' => $html_allow_map ? $html_url . ($html_forum_mod_rewrite ? 'maps/forum/' : "map.$phpEx?forum") : '',
  264. 'forum_allow_news' => $html_forum_allow_news,
  265. 'forum_news_url' => $html_allow_news ? $html_url . ($html_forum_mod_rewrite ? 'news/forum/' : "map.$phpEx?forum=news") : '',
  266. 'forum_allow_cat_map' => $html_forum_allow_cat_map,
  267. 'forum_cat_map' => $html_url . ($html_forum_mod_rewrite && $_phpbb_seo ? 'maps/forum/%1$s/' : "map.$phpEx?forum=%2\$s"),
  268. 'forum_allow_cat_news' => $html_forum_allow_cat_news,
  269. 'forum_cat_news' => $html_url . ($html_forum_mod_rewrite && $_phpbb_seo ? 'news/forum/%1$s/' : "map.$phpEx?forum=%2\$s&amp;news"),
  270. 'auth_guest' => $html_auth_guest,
  271. 'forum_exclude' => $html_forum_exclude,
  272. 'forum_allow_auth' => $html_forum_allow_auth,
  273. ));
  274. }
  275. $links['main'] = array_merge( $links['main'],
  276. array(
  277. 'GYM_HTML_NEWS_TITLE' => $user->lang['HTML_NEWS'],
  278. 'GYM_HTML_NEWS_URL' => $html_news_url,
  279. 'GYM_HTML_NEWS_LINK' => $display_html_main_links ? sprintf($gym_link_tpl, $html_news_url, 'html_news.gif', $user->lang['HTML_NEWS']) : '',
  280. 'GYM_HTML_MAP_TITLE' => $user->lang['HTML_MAP'],
  281. 'GYM_HTML_MAP_URL' => $html_map_url,
  282. 'GYM_HTML_MAP_LINK' => $display_html_main_links ? sprintf($gym_link_tpl, $html_map_url, 'maps-icon.gif', $user->lang['HTML_MAP']) : '',
  283. 'GYM_HTML_THEFORUM_NEWS_TITLE' => $user->lang['HTML_FORUM_NEWS'],
  284. 'GYM_HTML_THEFORUM_NEWS_URL' => $links['setup']['html']['forum_news_url'],
  285. 'GYM_HTML_THEFORUM_NEWS_LINK' => sprintf($gym_link_tpl, $links['setup']['html']['forum_news_url'], 'html_news.gif', $user->lang['HTML_FORUM_NEWS']),
  286. 'GYM_HTML_THEFORUM_MAP_TITLE' => $user->lang['HTML_FORUM_MAP'],
  287. 'GYM_HTML_THEFORUM_MAP_URL' => $links['setup']['html']['forum_map_url'],
  288. 'GYM_HTML_THEFORUM_MAP_LINK' => sprintf($gym_link_tpl, $links['setup']['html']['forum_map_url'], 'maps-icon.gif', $user->lang['HTML_FORUM_MAP']),
  289. ));
  290. $do_display_main = $display_html_main_links ? true : $do_display_main;
  291. $do_display_index = $display_html_index_links ? true : $do_display_index;
  292. $do_display_cat = $display_html_cat_links ? true : $do_display_cat;
  293. }
  294. $links['setup']['main'] = array(
  295. 'link_main' => ($gym_config['gym_link_main'] && $do_display_main) ? 1 : 0,
  296. 'link_index' => ($gym_config['gym_link_index'] && $do_display_index) ? 1 : 0,
  297. 'link_cat' => ($gym_config['gym_link_cat'] && $do_display_cat) ? 1 : 0,
  298. 'f_public_read' => array_diff_assoc($auth_guest_list['read'], $auth_guest_list['skip_pass']) + array_intersect_assoc($auth_guest_list['skip_cat'], $auth_guest_list['list']),
  299. );
  300. $links['main'] = array_merge( $links['main'],
  301. array(
  302. 'GYM_LINKS' => $links['setup']['main']['link_main'],
  303. 'GYM_LINKS_CAT' => $links['setup']['main']['link_cat'],
  304. ));
  305. $links['alternate'] = array();
  306. if (!empty($links['setup']['rss']['display_alternate'])) {
  307. $links['alternate'] = array(
  308. array(
  309. 'TITLE' => $user->lang['RSS_FEED'],
  310. 'URL' => $rss_main_url
  311. ),
  312. array(
  313. 'TITLE' => $user->lang['RSS_CHAN_LIST_TITLE'],
  314. 'URL' => $rss_chan_url
  315. ),
  316. );
  317. }
  318. return $links;
  319. }
  320. /**
  321. * get_feed_data($_params)
  322. * returns the parsed feed.
  323. * */
  324. function get_feed_data($_params) {
  325. global $user, $config;
  326. $feed_data = array(
  327. 'items' => array(),
  328. 'setup' => array('date' => false, 'author' => false, 'desclen' => 0, 'chantitle' => '', 'chanlink' => ''),
  329. );
  330. @ini_set('user_agent','GYM Sitemaps &amp; RSS / www.phpBB-SEO.com');
  331. @ini_set('default_socket_timeout', 5);
  332. $xml = @file_get_contents($_params['url']);
  333. if ($xml) {
  334. // Get encoding
  335. $encoding = get_match('`encoding=[\'"]([a-z0-9_-]+)[\'"]`Usi', $xml);
  336. $encoding = !empty($encoding) ? strtolower($encoding) : detect_encoding($xml);
  337. if(preg_match('`<item>(.*)</item>`si', $xml, $matches)){
  338. // Get chan info
  339. $feed_data['setup']['chantitle'] = get_match('`<title>(.*)</title>`Usi', $xml, $encoding);
  340. $feed_data['setup']['chanlink'] = get_match('`<link>(.*)</link>`Usi', $xml, $encoding);
  341. $xml = trim($matches[0]);
  342. unset($matches);
  343. preg_match_all('`<item>(.*)</item>`Usi', $xml, $matches);
  344. unset($matches[0]);
  345. if (!empty($matches[1]) && is_array($matches[1])) {
  346. $i = 1;
  347. foreach($matches[1] as $key => $item) {
  348. if ($i > $_params['limit']) {
  349. break;
  350. }
  351. if ($title = get_match('`<title>(.*)</title>`Usi', $item, $encoding)) {
  352. if ($link = get_match('`<link>(.*)</link>`Usi', $item, $encoding)) {
  353. $feed_data['items'][$i]['PUBDATE'] = false;
  354. if ($pubdate = get_match('`<pubDate>(.*)</pubDate>`Usi', $item, $encoding)) {
  355. if (($pubdate = strtotime($pubdate, $user->time_now)) > 0) {
  356. $feed_data['items'][$i]['PUBDATE'] = $user->format_date($pubdate, $config['default_dateformat']);
  357. $feed_data['setup']['date'] = true;
  358. }
  359. }
  360. $feed_data['items'][$i]['DESC'] = false;
  361. if ($_params['desc'] && $description = get_match('`<description>(.*)</description>`Usi', $item, $encoding)) {
  362. if (empty($_params['html'])) {
  363. $description = htmlspecialchars($_params['striptags'] ? strip_tags($description) : $description, ENT_COMPAT, 'UTF-8');
  364. }
  365. $feed_data['items'][$i]['DESC'] = str_replace(array("\r", "\n"), '<br />', $description);
  366. $feed_data['setup']['desclen'] += utf8_strlen($feed_data['items'][$i]['DESC']);
  367. }
  368. $feed_data['items'][$i]['SOURCE'] = false;
  369. if ($source = get_match('`<source[\s]+url="(.*)">(.*)</source>`Usi', $item, $encoding)) {
  370. $feed_data['items'][$i]['SOURCE'] = htmlspecialchars($source, ENT_COMPAT, 'UTF-8');
  371. }
  372. $feed_data['items'][$i]['TITLE'] = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
  373. $feed_data['items'][$i]['LINK'] = htmlspecialchars($link, ENT_COMPAT, 'UTF-8');
  374. $feed_data['items'][$i]['IMG'] = $user->img('topic_read', $feed_data['items'][$i]['TITLE'], false, '', 'src');
  375. $i++;
  376. }
  377. }
  378. unset($matches[1][$key]);
  379. }
  380. }
  381. unset($matches);
  382. }
  383. }
  384. unset($xml);
  385. return $feed_data;
  386. }
  387. /**
  388. * detect_encoding($string)
  389. * Inspired from php.net : http://www.php.net/mb_detect_encoding
  390. */
  391. function detect_encoding($string) {
  392. if (function_exists('mb_detect_encoding')) {
  393. if ($encoding = @mb_detect_encoding($string . 'a')) {
  394. return strtolower($encoding);
  395. }
  396. }
  397. // Else at least try to see if utf-8, otherwise fall back to iso-8859-1
  398. // non-overlong 2-byte|excluding overlongs|straight 3-byte|excluding surrogates|planes 1-3|planes 4-15|plane 16
  399. return preg_match('%(?:[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF] |\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})+%xs', $string) ? 'utf-8' : 'iso-8859-1';
  400. }
  401. /**
  402. * get_match($pattern, $string, $encoding)
  403. * returns properly encoded match from feed
  404. */
  405. function get_match($pattern, $string, $encoding = 'utf-8') {
  406. static $filters = array('<![CDATA['=>'', ']]>'=>'');
  407. $string = strtr($string, $filters);
  408. preg_match($pattern, $string, $out);
  409. if(!empty($out[1])) {
  410. // cdata
  411. $out[1] = strtr($out[1], $filters);
  412. if( strtolower($encoding) != 'utf-8') {
  413. $out[1] = utf8_recode($out[1], $encoding);
  414. }
  415. return @html_entity_decode(trim($out[1]), ENT_COMPAT, 'UTF-8');
  416. } else {
  417. return '';
  418. }
  419. }
  420. /**
  421. * set_exclude_list($id_list) will build up the public unauthed ids
  422. */
  423. function set_exclude_list($id_list) {
  424. $exclude_list = empty($id_list) ? array() : explode(',', $id_list);
  425. $ret = array();
  426. foreach ($exclude_list as $value ) {
  427. $value = (int) trim($value);
  428. if (!empty($value)) {
  429. $ret[$value] = $value;
  430. }
  431. }
  432. return $ret;
  433. }
  434. ?>