PageRenderTime 30ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/main/forum/forum_low.php

http://github.com/FSB/Fire-Soft-Board-2
PHP | 465 lines | 306 code | 56 blank | 103 comment | 46 complexity | a833e84af7e846fede4a00ef7367fc82 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. * Version bas debit du forum
  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 = true;
  22. /**
  23. * Affichage de la barre de navigation du footer
  24. *
  25. * @var bool
  26. */
  27. public $_show_page_footer_nav = true;
  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. * Page en cours
  48. *
  49. * @var int
  50. */
  51. public $page;
  52. /**
  53. * Sujets par page
  54. *
  55. * @var int
  56. */
  57. public $topic_per_page = 100;
  58. /**
  59. * Messages par page
  60. *
  61. * @var int
  62. */
  63. public $post_per_page = 30;
  64. /**
  65. * Navigation
  66. *
  67. * @var array
  68. */
  69. public $nav = array();
  70. /**
  71. * Page bas débit ?
  72. *
  73. * @var bool
  74. */
  75. public $is_low_page = true;
  76. /**
  77. * Constructeur
  78. *
  79. */
  80. public function main()
  81. {
  82. $this->mode = Http::request('mode');
  83. $this->id = intval(Http::request('id'));
  84. $this->page = intval(Http::request('page'));
  85. if ($this->page <= 0)
  86. {
  87. $this->page = 1;
  88. }
  89. Fsb::$tpl->set_file('forum/forum_low.html');
  90. Fsb::$tpl->set_vars(array(
  91. 'HIGH_VERSION' => sprintf(Fsb::$session->lang('low_high'), Fsb::$cfg->get('forum_name')),
  92. 'U_LOW_INDEX' => sid(ROOT . 'index.' . PHPEXT . '?p=low'),
  93. ));
  94. $call = new Call($this);
  95. $call->functions(array(
  96. 'mode' => array(
  97. 'forum' => 'low_forum',
  98. 'topic' => 'low_topic',
  99. 'index' => 'low_index',
  100. 'default' => 'low_index',
  101. ),
  102. ));
  103. }
  104. /**
  105. * Affichage des forums sur l'index
  106. *
  107. */
  108. public function low_index()
  109. {
  110. Fsb::$tpl->set_switch('low_index');
  111. Fsb::$tpl->set_vars(array(
  112. 'U_HIGH_VERSION' => sid(ROOT . 'index.' . PHPEXT . '?p=index'),
  113. ));
  114. // Liste des forums autorises
  115. $forums = Forum::get_authorized(array('ga_view'));
  116. // Affichage d'une categorie
  117. $sql_cat = '';
  118. if ($this->id)
  119. {
  120. $sql = 'SELECT f_left, f_right
  121. FROM ' . SQL_PREFIX . 'forums
  122. WHERE f_parent = 0
  123. AND f_id = ' . $this->id;
  124. if ($data = Fsb::$db->request($sql))
  125. {
  126. $this->nav = Forum::nav($this->id, array(), $this);
  127. $sql_cat = 'AND f_left >= ' . $data['f_left'] . ' AND f_right <= ' . $data['f_right'];
  128. }
  129. }
  130. // Affichage des forums
  131. $sql = 'SELECT *
  132. FROM ' . SQL_PREFIX . 'forums
  133. WHERE (f_parent = 0 OR f_id IN (' . implode(', ', $forums) . '))
  134. ' . $sql_cat . '
  135. ORDER BY f_left';
  136. $result = Fsb::$db->query($sql, 'forums_');
  137. while ($row = Fsb::$db->row($result))
  138. {
  139. if ($row['f_parent'] == 0)
  140. {
  141. $last_cat = $row;
  142. }
  143. else
  144. {
  145. if ($last_cat)
  146. {
  147. Fsb::$tpl->set_blocks('cat', array(
  148. 'NAME' => $last_cat['f_name'],
  149. 'U_CAT' => sid(ROOT . 'index.' . PHPEXT . '?p=low&amp;mode=index&amp;id=' . $last_cat['f_id']),
  150. ));
  151. $last_cat = null;
  152. }
  153. Fsb::$tpl->set_blocks('cat.forum', array(
  154. 'NAME' => $row['f_name'],
  155. 'MARGIN' => 40 * $row['f_level'],
  156. 'TOTAL' => sprintf(Fsb::$session->lang('low_index_total'), $row['f_total_topic'], $row['f_total_post']),
  157. 'U_FORUM' => ($row['f_type'] == FORUM_TYPE_DIRECT_URL) ? $row['f_location'] : sid(ROOT . 'index.' . PHPEXT . '?p=low&amp;mode=forum&amp;id=' . $row['f_id']),
  158. ));
  159. }
  160. }
  161. Fsb::$db->free($result);
  162. }
  163. /**
  164. * Affichage des sujets
  165. *
  166. */
  167. public function low_forum()
  168. {
  169. // Informations sur le forum
  170. $sql = 'SELECT *
  171. FROM ' . SQL_PREFIX . 'forums
  172. WHERE f_id = ' . $this->id;
  173. $result = Fsb::$db->query($sql, 'forums_' . $this->id . '_');
  174. $data = Fsb::$db->row($result);
  175. Fsb::$db->free($result);
  176. if (!$data || $data['f_parent'] == 0 || $data['f_password'])
  177. {
  178. Http::redirect(ROOT . 'index.' . PHPEXT . '?p=low');
  179. }
  180. // Verification des droits d'acces
  181. if (!Fsb::$session->is_authorized($this->id, 'ga_view') || !Fsb::$session->is_authorized($this->id, 'ga_view_topics'))
  182. {
  183. Http::redirect(ROOT . 'index.' . PHPEXT . '?p=low');
  184. }
  185. Fsb::$tpl->set_switch('low_forum');
  186. Fsb::$tpl->set_vars(array(
  187. 'FORUM_TITLE' => $data['f_name'],
  188. 'U_HIGH_VERSION' => sid(ROOT . 'index.' . PHPEXT . '?p=forum&amp;f_id=' . $this->id),
  189. ));
  190. // Navigation de la page
  191. $this->nav = Forum::nav($this->id, array(), $this);
  192. // Ce qu'on va afficher, en fonction du type de forum
  193. switch ($data['f_type'])
  194. {
  195. case FORUM_TYPE_NORMAL :
  196. Fsb::$tpl->set_switch('show_topics');
  197. break;
  198. case FORUM_TYPE_SUBCAT :
  199. Fsb::$tpl->unset_switch('show_topics');
  200. break;
  201. case FORUM_TYPE_INDIRECT_URL :
  202. Fsb::$db->update('forums', array(
  203. 'f_location_view' => array('(f_location_view + 1)', 'is_field' => true),
  204. ), 'WHERE f_id = ' . $this->id);
  205. Http::redirect($data['f_location']);
  206. break;
  207. case FORUM_TYPE_DIRECT_URL :
  208. Http::redirect($data['f_location']);
  209. break;
  210. }
  211. // Affichage des sous forums
  212. if ($data['f_right'] - $data['f_left'] > 1)
  213. {
  214. $sql = 'SELECT f_id, f_name, f_type, f_total_topic, f_total_post
  215. FROM ' . SQL_PREFIX . 'forums
  216. WHERE f_left > ' . $data['f_left'] . '
  217. AND f_right < ' . $data['f_right'] . '
  218. AND f_level = ' . $data['f_level'] . ' + 1
  219. AND f_id IN (' . implode(', ', Forum::get_authorized(array('ga_view'))) . ')';
  220. $result = Fsb::$db->query($sql, 'forums_' . $this->id . '_');
  221. while ($row = Fsb::$db->row($result))
  222. {
  223. Fsb::$tpl->set_blocks('sub', array(
  224. 'NAME' => $row['f_name'],
  225. 'TOTAL' => sprintf(Fsb::$session->lang('low_index_total'), $row['f_total_topic'], $row['f_total_post']),
  226. 'U_FORUM' => ($row['f_type'] == FORUM_TYPE_DIRECT_URL) ? $row['f_location'] : sid(ROOT . 'index.' . PHPEXT . '?p=low&amp;mode=forum&amp;id=' . $row['f_id']),
  227. ));
  228. }
  229. Fsb::$db->free($result);
  230. }
  231. // Total de sujets du forum
  232. $sql = 'SELECT COUNT(*) AS total
  233. FROM ' . SQL_PREFIX . 'topics
  234. WHERE (f_id = ' . $this->id . ' OR t_trace = ' . $this->id . ')
  235. AND t_approve = 0';
  236. $total = Fsb::$db->get($sql, 'total');
  237. if ($data['f_global_announce'])
  238. {
  239. $total += Fsb::$cfg->get('total_global_announce');
  240. $sql_announce = ' OR t_type = ' . GLOBAL_ANNOUNCE;
  241. }
  242. // Pagination
  243. $total_page = ceil($total / $this->topic_per_page);
  244. if ($total_page > 1)
  245. {
  246. Fsb::$tpl->set_vars(array(
  247. 'PAGINATION' => Html::pagination($this->page, $total_page, ROOT . 'index.' . PHPEXT . '?p=low&amp;mode=forum&amp;id=' . $this->id),
  248. ));
  249. }
  250. // Affichage des sujets
  251. $sql = 'SELECT *
  252. FROM ' . SQL_PREFIX . 'topics
  253. WHERE f_id = ' . $this->id
  254. . $sql_announce . '
  255. ORDER BY t_type, t_last_p_time DESC
  256. LIMIT ' . (($this->page - 1) * $this->topic_per_page) . ', ' . $this->topic_per_page;
  257. $result = Fsb::$db->query($sql);
  258. while ($row = Fsb::$db->row($result))
  259. {
  260. Fsb::$tpl->set_blocks('topic', array(
  261. 'TITLE' => Parser::title($row['t_title']),
  262. 'IS_ANNOUNCE' => ($row['t_type'] <= 1) ? true : false,
  263. 'TOTAL' => sprintf(String::plural('low_answer', $row['t_total_post'] - 1), $row['t_total_post'] - 1),
  264. 'U_TOPIC' => sid(ROOT . 'index.' . PHPEXT . '?p=low&amp;mode=topic&amp;id=' . $row['t_id']),
  265. ));
  266. }
  267. Fsb::$db->free($result);
  268. }
  269. /**
  270. * Affichage des sujets
  271. *
  272. */
  273. public function low_topic()
  274. {
  275. // Si la fonction de notification est activee on ajoute une jointure a la requete
  276. $sql_select = $sql_join = '';
  277. if (Fsb::$mods->is_active('topic_notification'))
  278. {
  279. $sql_select = ', tn.u_id AS can_notify, tn.tn_status';
  280. $sql_join = 'LEFT JOIN ' . SQL_PREFIX . 'topics_notification tn ON tn.t_id = t.t_id AND tn.u_id = ' . Fsb::$session->id();
  281. }
  282. // Informations sur le sujet
  283. $sql = 'SELECT t.*, tr.p_id AS last_unread_id' . $sql_select . '
  284. FROM ' . SQL_PREFIX . 'topics t
  285. LEFT JOIN ' . SQL_PREFIX . 'topics_read tr
  286. ON t.t_id = tr.t_id
  287. AND tr.u_id = ' . Fsb::$session->id() . '
  288. ' . $sql_join . '
  289. WHERE t.t_id = ' . $this->id;
  290. $data = Fsb::$db->request($sql);
  291. // Verification des droits d'acces
  292. if (!$data || !Fsb::$session->is_authorized($data['f_id'], 'ga_view') || !Fsb::$session->is_authorized($data['f_id'], 'ga_view_topics') || !Fsb::$session->is_authorized($data['f_id'], 'ga_read'))
  293. {
  294. Http::redirect(ROOT . 'index.' . PHPEXT . '?p=low');
  295. }
  296. // Navigation de la page
  297. $this->nav = Forum::nav($data['f_id'], array(array(
  298. 'url' => sid(ROOT . 'index.' . PHPEXT . '?p=low&amp;mode=topic&amp;id=' . $data['t_id']),
  299. 'name' => Parser::title($data['t_title']),
  300. )), $this);
  301. Fsb::$tpl->set_switch('low_topic');
  302. Fsb::$tpl->set_vars(array(
  303. 'TOPIC_TITLE' => Parser::title($data['t_title']),
  304. 'U_HIGH_VERSION' => sid(ROOT . 'index.' . PHPEXT . '?p=topic&amp;t_id=' . $this->id),
  305. ));
  306. // Pagination
  307. $total_page = ceil($data['t_total_post'] / $this->post_per_page);
  308. if ($total_page > 1)
  309. {
  310. Fsb::$tpl->set_vars(array(
  311. 'PAGINATION' => Html::pagination($this->page, $total_page, ROOT . 'index.' . PHPEXT . '?p=low&amp;mode=topic&amp;id=' . $this->id),
  312. ));
  313. }
  314. // On commence par recuperer les ID des messages qui seront affiches
  315. $sql = 'SELECT p_id
  316. FROM ' . SQL_PREFIX . 'posts
  317. WHERE t_id = ' . $data['t_id'] . '
  318. AND p_approve = 0
  319. ORDER BY p_time
  320. LIMIT ' . (($this->page - 1) * $this->post_per_page) . ', ' . ($this->post_per_page);
  321. $result = Fsb::$db->query($sql);
  322. $idx = array();
  323. while ($row = Fsb::$db->row($result))
  324. {
  325. $idx[] = $row['p_id'];
  326. }
  327. Fsb::$db->free($result);
  328. if (!$idx)
  329. {
  330. Http::redirect(ROOT . 'index.' . PHPEXT . '?p=low');
  331. }
  332. // Affichage des messages
  333. $parser = new Parser();
  334. $sql = 'SELECT p.u_id, p.f_id, p.t_id, p.p_nickname, p.p_time, p.p_text, p.p_map, u.u_auth
  335. FROM ' . SQL_PREFIX . 'posts p
  336. LEFT JOIN ' . SQL_PREFIX . 'users u
  337. ON u.u_id = p.u_id
  338. WHERE p.p_id IN (' . implode(', ', $idx) . ')
  339. ORDER BY p.p_time';
  340. $result = Fsb::$db->query($sql);
  341. while ($row = Fsb::$db->row($result))
  342. {
  343. // Informations passees au parseur de message
  344. $parser_info = array(
  345. 'u_id' => $row['u_id'],
  346. 'p_nickname' => $row['p_nickname'],
  347. 'u_auth' => $row['u_auth'],
  348. 'f_id' => $row['f_id'],
  349. 't_id' => $row['t_id'],
  350. );
  351. $parser->parse_html = (Fsb::$cfg->get('activate_html') && $row['u_auth'] >= MODOSUP) ? true : false;
  352. Fsb::$tpl->set_blocks('post', array(
  353. 'CONTENT' => $parser->mapped_message($row['p_text'], $row['p_map'], $parser_info),
  354. 'NICKNAME' => htmlspecialchars($row['p_nickname']),
  355. 'DATE' => Fsb::$session->print_date($row['p_time']),
  356. 'U_NICKNAME' => sid(ROOT . 'index.' . PHPEXT . '?p=userprofile&amp;id=' . $row['u_id']),
  357. ));
  358. }
  359. Fsb::$db->free($result);
  360. // Marquer le sujet lu
  361. if (Fsb::$session->is_logged() && $data['t_last_p_time'] > MAX_UNREAD_TOPIC_TIME)
  362. {
  363. if (!$data['last_unread_id'] || $data['last_unread_id'] < $data['t_last_p_id'])
  364. {
  365. Fsb::$db->insert('topics_read', array(
  366. 'u_id' => array(Fsb::$session->id(), true),
  367. 't_id' => array($data['t_id'], true),
  368. 'p_id' => $data['t_last_p_id'],
  369. ), 'REPLACE');
  370. }
  371. // Remise a jour de la notification du membre
  372. if (Fsb::$mods->is_active('topic_notification') && Fsb::$session->data['u_activate_auto_notification'] & NOTIFICATION_EMAIL && $data['can_notify'] && $data['tn_status'] == IS_NOTIFIED)
  373. {
  374. Fsb::$db->update('topics_notification', array(
  375. 'tn_status' => IS_NOT_NOTIFIED,
  376. ), 'WHERE u_id = ' . Fsb::$session->id() . ' AND t_id = ' . $data['t_id']);
  377. }
  378. }
  379. // Visions du sujet
  380. $update_total_view = true;
  381. if (Fsb::$mods->is_active('cookie_view'))
  382. {
  383. // Page deja visitee durant la session ?
  384. $cookie_view = Http::getcookie('cookie_view');
  385. if ($cookie_view)
  386. {
  387. $cookie_view = @unserialize($cookie_view);
  388. $update_total_view = (is_array($cookie_view) && in_array($data['t_id'], $cookie_view)) ? false : true;
  389. }
  390. if ($update_total_view)
  391. {
  392. if (!is_array($cookie_view))
  393. {
  394. $cookie_view = array();
  395. }
  396. $cookie_view[] = $data['t_id'];
  397. Http::cookie('cookie_view', serialize($cookie_view), 0);
  398. }
  399. }
  400. // +1 visite au sujet si pas deja visite
  401. if ($update_total_view)
  402. {
  403. Fsb::$db->update('topics', array(
  404. 't_total_view' => array('(t_total_view + 1)', 'is_field' => true),
  405. ), 'WHERE t_id = ' . $data['t_id']);
  406. }
  407. }
  408. }
  409. /* EOF */