Просмотр файла article.php

Размер файла: 5.35Kb
  1. <?php
  2. define('_WBLIB', 1);
  3. require_once ('inc/core.php');
  4.  
  5. $req = mysql_query("SELECT * FROM `article` WHERE `id` = '$id' AND `type` = '2' LIMIT 1");
  6. if (mysql_num_rows($req) == 0 ) {
  7. require_once ('inc/head.php');
  8. echo '<div class="error">Статья не найдена</div>';
  9. require_once ('inc/foot.php');
  10. exit;
  11. }
  12. $art = mysql_fetch_assoc($req);
  13.  
  14. // Заголовки
  15. $title = $art['name'];
  16. require_once ('inc/head.php');
  17. #############################
  18.  
  19. // Счетчик прочтений
  20. if ($_SESSION['lib'] != $id) {
  21. $_SESSION['lib'] = $id;
  22. $libcount = intval($art['count']) + 1;
  23. mysql_query("UPDATE `article` SET `count` = '" . $libcount . "' WHERE `id` = '" . $id . "'");
  24. }
  25. echo '<div class="title">'.$art['name'].'</div>';
  26.  
  27. $simvol = $set['simvols']; // Число символов на страницу по умолчанию
  28.  
  29. // Постраничная навигация читаемой статьи
  30. // Используется модифицированный код от hintoz
  31. $tx = $art['text'];
  32. $strrpos = mb_strrpos($tx, " ");
  33. $pages = 1;
  34. // Вычисляем номер страницы
  35. if (isset($_GET['page'])) {
  36. $page = abs(intval($_GET['page']));
  37. if ($page == 0)
  38. $page = 1;
  39. $start = $page - 1;
  40. }
  41. else {
  42. $page = $start + 1;
  43. }
  44. $t_si = 0;
  45. if ($strrpos) {
  46. while ($t_si < $strrpos) {
  47. $string = mb_substr($tx, $t_si, $simvol);
  48. $t_ki = mb_strrpos($string, " ");
  49. $m_sim = $t_ki;
  50. $strings[$pages] = $string;
  51. $t_si = $t_ki + $t_si;
  52. if ($page == $pages) {
  53. $page_text = $strings[$pages];
  54. }
  55. if ($strings[$pages] == "") {
  56. $t_si = $strrpos++;
  57. }
  58. else {
  59. $pages++;
  60. }
  61. }
  62. if ($page >= $pages) {
  63. $page = $pages - 1;
  64. $page_text = $strings[$page];
  65. }
  66. $pages = $pages - 1;
  67. if ($page != $pages) {
  68. $prb = mb_strrpos($page_text, " ");
  69. $page_text = mb_substr($page_text, 0, $prb);
  70. }
  71. }
  72. else {
  73. $page_text = $tx;
  74. }
  75. // Предварительна фильтрация статьи и вывод
  76. $page_text = htmlentities($page_text, ENT_QUOTES, 'UTF-8');
  77. $page_text = nl2br($page_text);
  78. $page_text = smileys($page_text);
  79. $page_text = tags($page_text);
  80. echo '<div class="link">' . $page_text . '</div>';
  81. if ($pages > 1) {
  82. nav($pages,$page,$num,'article.php?id='.$id.'&amp;');
  83. }
  84. echo '<div class="link"><b>Название статьи :</b> '.$art['name'].'<br/>
  85. <b>Дата добавления</b> : '.date('d.m.Y|H:i',$art['time']).'<br/>
  86. <b>Просмотров :</b> '.$art['count'].'';
  87. if($set['java']) echo '<br/><img src="images/java.png" alt="java"/> <a href="java.php?id='.$id.'">Скачать Java-книгу</a>';
  88. if($set['txt']) echo '<br/><img src="images/txt.png" alt="java"/> <a href="txt.php?id='.$id.'">Скачать в Txt</a>';
  89. echo '</div>';
  90.  
  91. if ($set['rate']) {
  92. $rate = explode('|', $art['rate']);
  93. if ((isset($_GET['plus']) || isset($_GET['minus'])) && !$_SESSION['rate_article' . $id]) {
  94. if (isset($_GET['plus']))
  95. $rate[0] = $rate[0] + 1;
  96. else
  97. $rate[1] = $rate[1] + 1;
  98. mysql_query("UPDATE `article` SET `rate`='" . $rate[0] . '|' . $rate[1] . "' WHERE `id`='$id' AND `type` = '2'");
  99. $_SESSION['rate_article' . $id] = 1;
  100. }
  101. $sum = ($rate[1] + $rate[0]) ? round(100 / ($rate[1] + $rate[0]) * $rate[0]) : 50;
  102. echo '<div class="link"><b>Рейтинг статьи</b>' . (!$_SESSION['rate_article' . $id] ? '(<a href="article.php?id=' . $id . '&amp;plus">+</a>/<a href="article.php?id=' . $id . '&amp;minus">-</a>)' : '(+/-)') . ': <font color="green">' . $rate[0] .
  103. '</font>/<font color="red">' . $rate[1] . '</font>
  104. <br /><img src="img.php?img=' . $sum . '" alt="Рейтинг" />';
  105. echo '</div>';
  106. }
  107.  
  108. if ($set['comm']) {
  109. $count = mysql_result(mysql_query("SELECT COUNT(*) FROM `comm` WHERE `id_article` = '$id';"), 0);
  110. echo '<div class="bar"><a href="comm.php?id='.$id.'">Комментарии</a> ['.$count.']</div>';
  111. }
  112.  
  113. // Доступ администратора
  114. if ($level > 0 ) {
  115. echo '<div class="func">';
  116. echo '<a href="panel/edit_article.php?id='.$id.'">Редактировать статью</a><br/>';
  117. echo '<a href="panel/del_article.php?id='.$id.'">Удалить статью</a>';
  118. echo '</div>';
  119. }
  120.  
  121.  
  122. $tree = array();
  123. $dirid = $art['id_cat'];
  124. while ($dirid != '0' && $dirid != "") {
  125. $req = mysql_query("SELECT * FROM `article` WHERE `type` = 1 AND `id` = '$dirid' LIMIT 1");
  126. $res = mysql_fetch_assoc($req);
  127. $tree[] = '<a href="view.php?id=' . $dirid . '">' .$res['name']. '</a>';
  128. $dirid = $res['id_cat'];
  129. }
  130. krsort($tree);
  131. $cdir = array_pop($tree);
  132. echo '<div class="title"><a href="index.php?">Главная</a> &raquo; ';
  133. foreach ($tree as $value) {
  134. echo $value . ' &raquo; ';
  135. }
  136. echo '<a href="view.php?id=' . $art['id_cat'] . '">' . strip_tags($cdir) . '</a></div>';
  137. require_once ('inc/foot.php');
  138. ?>