PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/main/forum/forum_rss.php

http://github.com/FSB/Fire-Soft-Board-2
PHP | 423 lines | 298 code | 37 blank | 88 comment | 31 complexity | 0db4d8a827eebc92d3ea8bbe2c059d56 MD5 | raw file
  1. <?php
  2. /**
  3. * Fire-Soft-Board version 2
  4. *
  5. * @package FSB2
  6. * @author Genova <genova@fire-soft-board.com>
  7. * @version $Id$
  8. * @license http://opensource.org/licenses/gpl-2.0.php GNU GPL 2
  9. */
  10. /**
  11. * Genere des flux RSS pour les messages ou pour les forums
  12. *
  13. */
  14. class Fsb_frame_child extends Fsb_frame
  15. {
  16. /**
  17. * Affichage de la barre de navigation du header
  18. *
  19. * @var bool
  20. */
  21. public $_show_page_header_nav = false;
  22. /**
  23. * Affichage de la barre de navigation du footer
  24. *
  25. * @var bool
  26. */
  27. public $_show_page_footer_nav = false;
  28. /**
  29. * Affichage de la boite des stats
  30. *
  31. * @var bool
  32. */
  33. public $_show_page_stats = false;
  34. /**
  35. * Mode
  36. *
  37. * @var string
  38. */
  39. public $mode;
  40. /**
  41. * ID
  42. *
  43. * @var int
  44. */
  45. public $id;
  46. /**
  47. * Type
  48. *
  49. * @var int
  50. */
  51. public $type;
  52. /**
  53. * Objet RSS
  54. *
  55. * @var Rss
  56. */
  57. public $rss;
  58. /**
  59. * Constructeur
  60. *
  61. */
  62. public function main()
  63. {
  64. // Acces au flux RSS ?
  65. if (!Fsb::$mods->is_active('rss'))
  66. {
  67. Display::message('not_allowed');
  68. }
  69. $this->mode = Http::request('mode');
  70. $this->type = Http::request('type');
  71. $this->id = intval(Http::request('id'));
  72. if (!in_array($this->type, array('rss2', 'atom')))
  73. {
  74. $this->type = 'rss2';
  75. }
  76. // Instance d'un objet RSS
  77. $this->rss = Rss::factory($this->type);
  78. switch ($this->mode)
  79. {
  80. case 'forum' :
  81. $this->rss_forum();
  82. break;
  83. case 'topic' :
  84. $this->rss_topic();
  85. break;
  86. case 'user' :
  87. $this->rss_user();
  88. break;
  89. case 'index' :
  90. default :
  91. $this->rss_index();
  92. break;
  93. }
  94. // Affichage du flux
  95. $this->rss->close();
  96. }
  97. /**
  98. * Affiche un flux RSS du sujet, chaque message etant un item different
  99. *
  100. */
  101. public function rss_topic()
  102. {
  103. if (!$this->id)
  104. {
  105. Display::message('not_allowed');
  106. }
  107. // Liste des messages
  108. $sql = 'SELECT p.p_id, p.p_text, p.p_time, p.u_id, p.p_nickname, p.p_map, t.t_title, t.t_description, t.f_id, t.t_id, u.u_activate_email, u.u_email, u.u_auth
  109. FROM ' . SQL_PREFIX . 'posts p
  110. INNER JOIN ' . SQL_PREFIX . 'topics t
  111. ON p.t_id = t.t_id
  112. LEFT JOIN ' . SQL_PREFIX . 'users u
  113. ON u.u_id = p.u_id
  114. WHERE t.t_id = ' . $this->id . '
  115. AND p.p_approve = 0
  116. ORDER BY p.p_time DESC';
  117. $result = Fsb::$db->query($sql);
  118. if ($row = Fsb::$db->row($result))
  119. {
  120. if (!Fsb::$session->is_authorized($row['f_id'], 'ga_read') || !Fsb::$session->is_authorized($row['f_id'], 'ga_view') || !Fsb::$session->is_authorized($row['f_id'], 'ga_view_topics'))
  121. {
  122. Display::message('not_allowed');
  123. }
  124. $parser = new Parser();
  125. $parser->parse_html = (Fsb::$cfg->get('activate_html') && $row['u_auth'] >= MODOSUP) ? true : false;
  126. $this->rss->open(
  127. Parser::title($row['t_title']),
  128. htmlspecialchars(($row['t_description']) ? $row['t_description'] : $parser->mapped_message($row['p_text'], $row['p_map'])),
  129. Fsb::$session->data['u_language'],
  130. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=rss&amp;mode=topic&amp;id=' . $this->id),
  131. $row['p_time']
  132. );
  133. do
  134. {
  135. // Informations passees au parseur de message
  136. $parser_info = array(
  137. 'u_id' => $row['u_id'],
  138. 'p_nickname' => $row['p_nickname'],
  139. 'u_auth' => $row['u_auth'],
  140. 'f_id' => $row['f_id'],
  141. 't_id' => $row['t_id'],
  142. );
  143. $parser->parse_html = (Fsb::$cfg->get('activate_html') && $row['u_auth'] >= MODOSUP) ? true : false;
  144. $this->rss->add_entry(
  145. Parser::title($row['t_title']),
  146. htmlspecialchars($parser->mapped_message($row['p_text'], $row['p_map'], $parser_info)),
  147. (($row['u_activate_email'] & 2) ? 'mailto:' . $row['u_email'] : Fsb::$cfg->get('forum_mail')) . ' ' . htmlspecialchars($row['p_nickname']),
  148. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=topic&p_id=' . $row['p_id'] . '#p' . $row['p_id']),
  149. $row['p_time']
  150. );
  151. }
  152. while ($row = Fsb::$db->row($result));
  153. }
  154. // Aucun message, on pioche donc directement les informations dans le sujet
  155. else
  156. {
  157. $sql = 'SELECT t_id, t_title, t_description, t_time
  158. FROM ' . SQL_PREFIX . 'topics
  159. WHERE t_id = ' . $this->id;
  160. $row = Fsb::$db->request($sql);
  161. $this->rss->open(
  162. Parser::title($row['t_title']),
  163. htmlspecialchars($row['t_description']),
  164. Fsb::$session->data['u_language'],
  165. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=rss&amp;mode=topic&amp;id=' . $this->id),
  166. $row['t_time']
  167. );
  168. }
  169. }
  170. /**
  171. * Affiche un flux RSS des sujets du forum, chaque sujet etant un item different
  172. *
  173. */
  174. public function rss_forum()
  175. {
  176. if (!$this->id || !Fsb::$session->is_authorized($this->id, 'ga_view') || !Fsb::$session->is_authorized($this->id, 'ga_view_topics'))
  177. {
  178. Display::message('not_allowed');
  179. }
  180. // Liste des messages
  181. $sql = 'SELECT f.f_name, p.p_id, p.u_id, p.f_id, p.p_text, p.p_time, p.p_nickname, p.p_map, t.t_id, t.t_title, t.t_description, u.u_activate_email, u.u_email, u.u_auth
  182. FROM ' . SQL_PREFIX . 'forums f
  183. LEFT JOIN ' . SQL_PREFIX . 'topics t
  184. ON f.f_id = t.f_id
  185. LEFT JOIN ' . SQL_PREFIX . 'posts p
  186. ON p.p_id = t.t_first_p_id
  187. LEFT JOIN ' . SQL_PREFIX . 'users u
  188. ON u.u_id = p.u_id
  189. WHERE t.f_id = ' . $this->id . '
  190. AND p.p_approve = 0
  191. ORDER BY t.t_last_p_time DESC
  192. LIMIT 100';
  193. $this->check_caching($sql, 'rss_' . $this->id . '_');
  194. $result = Fsb::$db->query($sql, 'rss_' . $this->id . '_');
  195. if ($row = Fsb::$db->row($result))
  196. {
  197. $this->rss->open(
  198. htmlspecialchars(Fsb::$cfg->get('forum_name') . Fsb::$session->getStyle('other', 'title_separator') . $row['f_name']),
  199. htmlspecialchars(sprintf(Fsb::$session->lang('rss_forum_name'), $row['f_name'])),
  200. Fsb::$session->data['u_language'],
  201. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=rss&amp;mode=forum&amp;id=' . $this->id),
  202. $row['p_time']
  203. );
  204. $parser = new Parser();
  205. do
  206. {
  207. // Informations passees au parseur de message
  208. $parser_info = array(
  209. 'u_id' => $row['u_id'],
  210. 'p_nickname' => $row['p_nickname'],
  211. 'u_auth' => $row['u_auth'],
  212. 'f_id' => $row['f_id'],
  213. 't_id' => $row['t_id'],
  214. );
  215. $parser->parse_html = (Fsb::$cfg->get('activate_html') && $row['u_auth'] >= MODOSUP) ? true : false;
  216. $this->rss->add_entry(
  217. Parser::title($row['t_title']),
  218. htmlspecialchars(($row['t_description']) ? $row['t_description'] : $parser->mapped_message($row['p_text'], $row['p_map'], $parser_info)),
  219. (($row['u_activate_email'] & 2) ? 'mailto:' . $row['u_email'] : Fsb::$cfg->get('forum_mail')) . ' ' . htmlspecialchars($row['p_nickname']),
  220. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=topic&t_id=' . $row['t_id']),
  221. $row['p_time']
  222. );
  223. }
  224. while ($row = Fsb::$db->row($result));
  225. }
  226. // Aucun sujet, on pioche donc directement les informations dans le forum
  227. else
  228. {
  229. $sql = 'SELECT f_id, f_name, f_text
  230. FROM ' . SQL_PREFIX . 'forums
  231. WHERE f_id = ' . $this->id;
  232. $row = Fsb::$db->request($sql);
  233. $this->rss->open(
  234. Parser::title($row['f_name']),
  235. htmlspecialchars($row['f_text']),
  236. Fsb::$session->data['u_language'],
  237. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=rss&amp;mode=forum&amp;id=' . $this->id),
  238. CURRENT_TIME
  239. );
  240. }
  241. }
  242. /**
  243. * Affiche un flux RSS des sujets de l'ensemble du forum
  244. *
  245. */
  246. public function rss_index()
  247. {
  248. // Liste des messages
  249. $sql = 'SELECT f.f_name, p.p_id, p.f_id, p.u_id, p.p_text, p.p_time, p.p_nickname, p.p_map, t.t_id, t.t_title, t.t_description, u.u_activate_email, u.u_email, u.u_auth
  250. FROM ' . SQL_PREFIX . 'forums f
  251. LEFT JOIN ' . SQL_PREFIX . 'topics t
  252. ON f.f_id = t.f_id
  253. INNER JOIN ' . SQL_PREFIX . 'posts p
  254. ON p.p_id = t.t_first_p_id
  255. LEFT JOIN ' . SQL_PREFIX . 'users u
  256. ON u.u_id = p.u_id
  257. WHERE p.p_approve = 0'
  258. . (($cat_id = intval(Http::request('cat'))) ? ' AND f.f_cat_id = ' . $cat_id : '')
  259. . (($forums_idx = Forum::get_authorized(array('ga_view', 'ga_view_topics'))) ? ' AND t.f_id IN (' . implode(', ', $forums_idx) . ')' : '') . '
  260. ORDER BY t.t_last_p_time DESC
  261. LIMIT 100';
  262. $result = Fsb::$db->query($sql);
  263. if ($row = Fsb::$db->row($result))
  264. {
  265. $this->rss->open(
  266. htmlspecialchars(Fsb::$cfg->get('forum_name') . Fsb::$session->getStyle('other', 'title_separator') . Fsb::$session->lang('rss_index')),
  267. htmlspecialchars(Fsb::$session->lang('rss_index')),
  268. Fsb::$session->data['u_language'],
  269. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=rss&amp;mode=index&amp;cat=' . $cat_id),
  270. $row['p_time']
  271. );
  272. $parser = new Parser();
  273. do
  274. {
  275. // Informations passees au parseur de message
  276. $parser_info = array(
  277. 'u_id' => $row['u_id'],
  278. 'p_nickname' => $row['p_nickname'],
  279. 'u_auth' => $row['u_auth'],
  280. 'f_id' => $row['f_id'],
  281. 't_id' => $row['t_id'],
  282. );
  283. $parser->parse_html = (Fsb::$cfg->get('activate_html') && $row['u_auth'] >= MODOSUP) ? true : false;
  284. $this->rss->add_entry(
  285. Parser::title($row['t_title']),
  286. htmlspecialchars(($row['t_description']) ? $row['t_description'] : $parser->mapped_message($row['p_text'], $row['p_map'], $parser_info)),
  287. (($row['u_activate_email'] & 2) ? 'mailto:' . $row['u_email'] : Fsb::$cfg->get('forum_mail')) . ' ' . htmlspecialchars($row['p_nickname']),
  288. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=topic&t_id=' . $row['t_id']),
  289. $row['p_time']
  290. );
  291. }
  292. while ($row = Fsb::$db->row($result));
  293. }
  294. // Aucun sujet ...
  295. else
  296. {
  297. $this->rss->open(
  298. htmlspecialchars(Fsb::$cfg->get('forum_name') . Fsb::$session->getStyle('other', 'title_separator') . Fsb::$session->lang('rss_index')),
  299. htmlspecialchars(Fsb::$session->lang('rss_index')),
  300. Fsb::$session->data['u_language'],
  301. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=rss&amp;mode=index&amp;cat=' . $cat_id),
  302. CURRENT_TIME
  303. );
  304. }
  305. }
  306. /**
  307. * Affiche un flux RSS des 10 derniers messages d'un membre
  308. *
  309. */
  310. public function rss_user()
  311. {
  312. if (!$this->id)
  313. {
  314. Display::message('not_allowed');
  315. }
  316. // Liste des messages
  317. $sql = 'SELECT p.p_id, p.p_text, p.p_time, p.u_id, p.p_nickname, p.p_map, t.t_title, t.t_description, t.f_id, u.u_nickname, u.u_activate_email, u.u_email, u.u_auth
  318. FROM ' . SQL_PREFIX . 'posts p
  319. INNER JOIN ' . SQL_PREFIX . 'topics t
  320. ON p.t_id = t.t_id
  321. LEFT JOIN ' . SQL_PREFIX . 'users u
  322. ON u.u_id = p.u_id
  323. WHERE p.u_id = ' . $this->id . '
  324. ORDER BY p.p_time DESC
  325. LIMIT 10';
  326. $result = Fsb::$db->query($sql);
  327. if ($row = Fsb::$db->row($result))
  328. {
  329. $parser = new Parser();
  330. $parser->parse_html = (Fsb::$cfg->get('activate_html') && $row['u_auth'] >= MODOSUP) ? true : false;
  331. $this->rss->open(
  332. htmlspecialchars($row['u_nickname']),
  333. '',
  334. Fsb::$session->data['u_language'],
  335. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=rss&amp;mode=user&amp;id=' . $this->id),
  336. $row['p_time']
  337. );
  338. do
  339. {
  340. $parser->parse_html = (Fsb::$cfg->get('activate_html') && $row['u_auth'] >= MODOSUP) ? true : false;
  341. $this->rss->add_entry(
  342. Parser::title($row['t_title']),
  343. htmlspecialchars($parser->mapped_message($row['p_text'], $row['p_map'])),
  344. (($row['u_activate_email'] & 2) ? 'mailto:' . $row['u_email'] : Fsb::$cfg->get('forum_mail')) . ' ' . htmlspecialchars($row['p_nickname']),
  345. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=topic&p_id=' . $row['p_id'] . '#p' . $row['p_id']),
  346. $row['p_time']
  347. );
  348. }
  349. while ($row = Fsb::$db->row($result));
  350. }
  351. // Aucun message pour ce membre ...
  352. else
  353. {
  354. $sql = 'SELECT u_nickname
  355. FROM ' . SQL_PREFIX . 'users
  356. WHERE u_id = ' . $this->id;
  357. $row = Fsb::$db->request($sql);
  358. $this->rss->open(
  359. htmlspecialchars($row['u_nickname']),
  360. '',
  361. Fsb::$session->data['u_language'],
  362. sid(Fsb::$cfg->get('fsb_path') . '/index.' . PHPEXT . '?p=rss&amp;mode=user&amp;id=' . $this->id),
  363. CURRENT_TIME
  364. );
  365. }
  366. }
  367. /**
  368. * Supprimes les RSS mis en cache dont le temps est expire
  369. *
  370. * @param string $sql
  371. * @param string $prefix
  372. */
  373. public function check_caching($sql, $prefix)
  374. {
  375. $hash = md5($sql);
  376. if (Fsb::$db->cache->exists($hash))
  377. {
  378. $time = Fsb::$db->cache->get_time($hash);
  379. if ($time < CURRENT_TIME - (Fsb::$cfg->get('rss_caching') * ONE_HOUR))
  380. {
  381. Fsb::$db->destroy_cache($prefix);
  382. }
  383. }
  384. }
  385. }
  386. /* EOF */