/mcsrv/news.php

https://bitbucket.org/mhell/mhmcr · PHP · 83 lines · 81 code · 0 blank · 2 comment · 18 complexity · 06822736e4056b497ca15d70abdfb5e7 MD5 · raw file

  1. <?php
  2. header('Content-Type: text/html;charset=UTF-8');
  3. require_once('../system.php');
  4. $news = '';
  5. $way_style = 'style/';
  6. $page_title = 'Новостная лента';
  7. if (isset($_GET['l']))
  8. $curlist = (int) $_GET['l']; //страница
  9. else
  10. $curlist = 1;
  11. if (isset($_GET['id']))
  12. $spec_new = (int) $_GET['id']; //страница
  13. else
  14. $spec_new = -1;
  15. function arrowsGenerator($link, $curpage, $itemsnum)
  16. {
  17. $numoflists = ceil($itemsnum / 10);
  18. $arrows = '';
  19. if ($numoflists > 10 and $curpage > 4) {
  20. $showliststart = $curpage - 4;
  21. $showlistend = $curpage + 5;
  22. if ($showliststart < 1)
  23. $showliststart = 1;
  24. if ($showlistend > $numoflists)
  25. $showlistend = $numoflists;
  26. } else {
  27. $showliststart = 1;
  28. if ($numoflists < 10)
  29. $showlistend = $numoflists;
  30. else
  31. $showlistend = 10;
  32. }
  33. if ($numoflists > 1) {
  34. if ($curpage > 1)
  35. $arrows .= '<a href="' . $link . 'l=' . ($curpage - 1) . '"><</a> ';
  36. for ($i = $showliststart; $i <= $showlistend; $i++)
  37. $arrows .= '<a href="' . $link . 'l=' . $i . '">' . $i . '</a> ';
  38. if ($curpage < $numoflists)
  39. $arrows .= '<a href="' . $link . 'l=' . ($curpage + 1) . '">></a>';
  40. }
  41. return $arrows;
  42. }
  43. function AddMem($id, $title, $text, $date) //генерация HTML
  44. {
  45. global $news;
  46. $news .= '<div class="newsItem">
  47. <p class="title">' . $title . '</p>
  48. <hr />
  49. <p>' . $text . '</p>
  50. <p class="datetime">Добавлено ' . $date . '</p>
  51. </div>
  52. ';
  53. }
  54. /* Для RSS - уникальная ссылка на каждую новость */
  55. if ($spec_new != -1) {
  56. $result = mysql_query("SELECT * FROM ".$db['tables']['news']." WHERE id='" . $spec_new . "'");
  57. if (mysql_num_rows($result) == 1) {
  58. $line = mysql_fetch_array($result);
  59. $parts = explode('[!break-short]',$line['content']);
  60. $line['content'] = $parts[0];
  61. AddMem($line['id'], $line['name'], html_entity_decode($line['content']), $line['date']);
  62. }
  63. include('../inc/serverstate.php');
  64. require_once($way_style . 'news.html');
  65. exit;
  66. }
  67. // вывод из БД
  68. $result = mysql_query("SELECT * FROM ".$db['tables']['news']." ORDER by date DESC LIMIT " . (10 * ($curlist - 1)) . ",10");
  69. if (mysql_num_rows($result) != 0) {
  70. while ($line = mysql_fetch_array($result)) {
  71. $parts = explode('[!break-short]',$line['content']);
  72. $line['content'] = $parts[0];
  73. AddMem($line['id'], $line['name'], html_entity_decode($line['content']), $line['date']);
  74. }
  75. $result = mysql_query("SELECT COUNT(*) FROM ".$db['tables']['news']);
  76. $line = mysql_fetch_array($result);
  77. $newsnum = $line[0];
  78. $news .= '<p class="list-pages">' . arrowsGenerator("news.php?", $curlist, $newsnum) . '</p>';
  79. } else
  80. $news .= "<h3>Новостная лента пуста...</h3>";
  81. require_once('../inc/serverstate.php');
  82. include_once $way_style . 'news.html';
  83. ?>