NoteOnMe博客平台搭建
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

335 行
12 KiB

3 年前
  1. <!DOCTYPE html>
  2. <head>
  3. <script src="js/jquery.min.js"></script>
  4. <script src="js/bootstrap.min.js"></script>
  5. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  6. <script src="js/jquery.singlePageNav.min.js"></script>
  7. <script src="js/setting.js"></script>
  8. <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
  9. <meta charset="utf-8"/>
  10. <style>
  11. pre{
  12. white-space:pre-wrap;
  13. word-wrap:break-word;
  14. }
  15. </style>
  16. <link type="text/css" href="highlight/styles/a11y-light.css?t={{time()}}" rel="stylesheet">
  17. <script src="highlight/highlight.pack.js"></script>
  18. <script>
  19. </script>
  20. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  21. <link rel="stylesheet" type="text/css" href="css/templatemo-style.css?t={{time()}}">
  22. <script src="require.js" ></script>
  23. </head><body>
  24. <?php
  25. require_once "pdo.php";
  26. session_start();
  27. $stmt = $pdo->prepare('SELECT content, headline,user_id FROM article WHERE article_id = :article_id');
  28. $stmt->execute(array( ':article_id' => $_GET["article_id"]));
  29. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  30. if ( $row == false ) {
  31. header('Location: index.php');
  32. }
  33. $stmt2 = $pdo->prepare('SELECT name FROM users WHERE user_id=:user_id');
  34. $stmt2->execute(array( ':user_id' => $row["user_id"]));
  35. $row2 = $stmt2->fetch(PDO::FETCH_ASSOC);
  36. if (!isset($_SESSION['user_id'] ))
  37. {
  38. echo("
  39. <script type='text/javascript' >
  40. $(document).ready(function(){
  41. $('#new_comment').hide();
  42. $('.hii').hide();
  43. });
  44. </script>"
  45. );
  46. }
  47. ?>
  48. <div class="fixed-header">
  49. <div class="container">
  50. <div class="navbar-header">
  51. <button type="button" class="navbar-toggle">
  52. <span class="icon-bar"></span>
  53. <span class="icon-bar"></span>
  54. <span class="icon-bar"></span>
  55. </button>
  56. <a class="navbar-brand" href="#">NOTE</a>
  57. </div>
  58. <nav class="main-menu">
  59. </form>
  60. <ul>
  61. <li><a class="external" href="index.php">Home</a></li>
  62. <li><div class="hidee"><a class=" external " href="edit_article.php?article_id=<?=$_GET["article_id"]?>">编辑</a></div></li>
  63. </ul>
  64. </nav>
  65. </div>
  66. </div>
  67. <?php
  68. if (!isset($_SESSION['user_id'] )||$_SESSION['user_id']!=$row['user_id'])
  69. {
  70. echo("
  71. <script type='text/javascript' >
  72. $(document).ready(function(){
  73. $('.hidee').hide();
  74. });
  75. </script>"
  76. );
  77. }
  78. ?>
  79. <div class="container">
  80. <section class="col-md-12 content" id="home" >
  81. <div class="col-lg-12 col-md-12 content-item content-item-1 background"style=" background-color: rgba(255,255,255, 1); ">
  82. <pre>
  83. <div class="text-center" >
  84. <h1 class="main-title text-center dark-blue-text" style="margin-top:0em;"> <?=$row['headline']?></h1>
  85. <p><a href="personal_page.php?user_id=<?=$row["user_id"]?>" style= "margin-bottom: 5px;text-align:centre;" > 作者:<?=$row2['name']?></a></p>
  86. </div>
  87. <div id="article" >
  88. <?echo(htmlentities($row['content']))?>
  89. </div>
  90. </pre>
  91. </div>
  92. </section>
  93. <section class="col-md-12 content " >
  94. <div class="col-lg-12 col-md-12 content-item content-item-1 background" style="padding-top:2em;background-color: rgba(255,255,255, 0.7); ">
  95. <form method="post" name="contact-form" class="contact-form hii" id="new_comment" action='comment.php'>
  96. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
  97. <div class="form-group contact-field">
  98. <textarea name="comment" rows="5" class="form-control" id="message" placeholder="欢迎留下你的思考~" required></textarea>
  99. </div>
  100. </div>
  101. <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
  102. <div class="form-group margin-b-0">
  103. <button type="submit" id="form-submit" class="btn no-bg btn-contact">提交</button>
  104. <input type="hidden" name="id" id="id" >
  105. <input type="hidden" name="article_id" value=<?=$_GET['article_id']?>>
  106. </div>
  107. </div>
  108. </form>
  109. <ul>
  110. <hr/>
  111. <?php
  112. $num_comment=-1;
  113. $stmt0 = $pdo->prepare('SELECT * FROM commentsss WHERE article_id = :article_id ORDER BY comment_id' );
  114. $stmt0->execute(array( ':article_id' => $_GET["article_id"]));
  115. $buf=array();
  116. while ( $row0 = $stmt0->fetch(PDO::FETCH_ASSOC) )
  117. {
  118. if($row0['comment_id']==$num_comment+1)
  119. {
  120. if($row0['feedback_id']!=NULL)
  121. {
  122. $buf[]=$row0;
  123. }
  124. else{
  125. $main_comment=$row0;
  126. }
  127. }
  128. else{
  129. $num_comment++;
  130. echo('<div class="row">');
  131. echo('<li> <div class="col-lg-1 col-md-1 "><a href="personal_page.php?user_id='.$main_comment['user_id'].'">');
  132. echo(htmlentities($main_comment['name']));
  133. echo('</a></div><div class="col-lg-10 col-md-10 text-centre" >');
  134. echo(htmlentities($main_comment['content']));
  135. echo("</p><hr/></div>");
  136. if($buf!=null){
  137. echo(" <div class='col-lg-1 col-md-1 '> <a data-toggle='collapse'
  138. href='#b".$num_comment."'>more</a>");
  139. echo("</a></div>");
  140. echo(' <div class="col-lg-12 col-md-12 collapse" id="b'.$num_comment.'">');
  141. $num=0;
  142. foreach($buf as $feedback)
  143. {
  144. echo('<div class="row">');
  145. echo(' <div class="col-lg-1 col-md-1 "><a href="personal_page.php?user_id='.$feedback['user_id'].'">');
  146. echo(htmlentities($feedback['name']));
  147. echo('</a></div><div class="col-lg-11 col-md-11 text-centre" >');
  148. echo(htmlentities($feedback['content']));
  149. echo("</p><hr/></div></div>");
  150. $num++;
  151. }
  152. echo('<form method="post" name="contact-form" class="contact-form hii" action="feedback.php">');
  153. echo(' <textarea name="feedback" rows="2" class="form-control" placeholder="回复" required></textarea>');
  154. echo('<input type="hidden" name="article_id" value="'.$feedback['article_id'].'">');
  155. echo('<input type="hidden" name="comment_id" value="'.$num_comment.'">');
  156. echo('<input type="hidden" name="feedback_id" value="'.$num.'" >');
  157. echo(' <button type="submit" style="margin:1em;" class="btn no-bg btn-contact ">提交</button>');
  158. echo("</form></div></li></div>");
  159. }
  160. else{
  161. echo(" <div class='col-lg-1 col-md-1 '> <a data-toggle='collapse'
  162. href='#b".$num_comment."'>评论</a>");
  163. echo("</a></div>");
  164. echo(" <div class='col-lg-12 col-md-12 '>");
  165. echo('<div id="b'.$num_comment.'" class="collapse">');
  166. echo('<form method="post" name="contact-form" class="contact-form hii" action="feedback.php">');
  167. echo(' <textarea name="feedback" rows="2" class="form-control" placeholder="回复" required></textarea>');
  168. echo('<input type="hidden" name="article_id" value="'.$main_comment['article_id'].'">');
  169. echo('<input type="hidden" name="comment_id" value="'.$num_comment.'">');
  170. echo('<input type="hidden" name="feedback_id" value="0" >');
  171. echo(' <button type="submit" style="margin:1em;" class="btn no-bg btn-contact ">提交</button>');
  172. echo("</form></div></div></li></div>");
  173. }
  174. $buf=array();
  175. if($row0['feedback_id']!=NULL)
  176. {
  177. $buf[]=$row0;
  178. }
  179. else{
  180. $main_comment=$row0;
  181. }
  182. }
  183. }
  184. if(isset($main_comment))
  185. {
  186. $num_comment++;
  187. echo('<div class="row">');
  188. echo('<li> <div class="col-lg-1 col-md-1 "><a href="personal_page.php?user_id='.$main_comment['user_id'].'">');
  189. echo(htmlentities($main_comment['name']));
  190. echo('</a></div><div class="col-lg-10 col-md-10 text-centre" >');
  191. echo(htmlentities($main_comment['content']));
  192. echo("</p><hr/></div>");
  193. if($buf!=null){
  194. echo(" <div class='col-lg-1 col-md-1 '> <a data-toggle='collapse'
  195. href='#b".$num_comment."'>more</a>");
  196. echo("</a></div>");
  197. echo(' <div class="col-lg-12 col-md-12 collapse" id="b'.$num_comment.'">');
  198. $num=0;
  199. foreach($buf as $feedback)
  200. {
  201. echo('<div class="row">');
  202. echo(' <div class="col-lg-1 col-md-1 "><a href="personal_page.php?user_id='.$feedback['user_id'].'">');
  203. echo(htmlentities($feedback['name']));
  204. echo('</a></div><div class="col-lg-11 col-md-11 text-centre" >');
  205. echo(htmlentities($feedback['content']));
  206. echo("</p><hr/></div></div>");
  207. $num++;
  208. }
  209. echo('<form method="post" name="contact-form" class="contact-form hii" action="feedback.php">');
  210. echo(' <textarea name="feedback" rows="2" class="form-control" placeholder="回复" required></textarea>');
  211. echo('<input type="hidden" name="article_id" value="'.$feedback['article_id'].'">');
  212. echo('<input type="hidden" name="comment_id" value="'.$num_comment.'">');
  213. echo('<input type="hidden" name="feedback_id" value="'.$num.'" >');
  214. echo(' <button type="submit" style="margin:1em;" class="btn no-bg btn-contact ">提交</button>');
  215. echo("</form></div></li></div>");
  216. }
  217. else{
  218. echo(" <div class='col-lg-1 col-md-1 '> <a data-toggle='collapse'
  219. href='#b".$num_comment."'>评论</a>");
  220. echo("</a></div>");
  221. echo(" <div class='col-lg-12 col-md-12 '>");
  222. echo('<div id="b'.$num_comment.'" class="collapse">');
  223. echo('<form method="post" name="contact-form" class="contact-form hii" action="feedback.php">');
  224. echo(' <textarea name="feedback" rows="2" class="form-control" placeholder="回复" required></textarea>');
  225. echo('<input type="hidden" name="article_id" value="'.$main_comment['article_id'].'">');
  226. echo('<input type="hidden" name="comment_id" value="'.$num_comment.'">');
  227. echo('<input type="hidden" name="feedback_id" value="0" >');
  228. echo(' <button type="submit" style="margin:1em;" class="btn no-bg btn-contact ">提交</button>');
  229. echo("</form></div></div></li></div>");
  230. }
  231. }
  232. $num_comment++;
  233. echo("
  234. <script>
  235. $(document).ready(function(){
  236. $('#id').val(".$num_comment.");
  237. });
  238. </script>");
  239. ?>
  240. </ul>
  241. </div>
  242. </section>
  243. </div>
  244. <div class="text-center footer">
  245. <div class="container"> NOTEBOOK</div>
  246. </div>
  247. </body>
  248. </html>
  249. <script>
  250. $(document).ready(function(){
  251. var str=<?=json_encode($row['content'])?>;
  252. $("#article").html(marked(str));
  253. });
  254. </script>
  255. <script>
  256. require.config({
  257. paths : {
  258. "marked" : ["https://cdn.jsdelivr.net/npm/marked/marked.min"],
  259. "highlight" : "highlight/highlight.pack"
  260. }
  261. })
  262. require(["marked","highlight"], function (marked,highlight) {
  263. var rendererMD = new marked.Renderer();
  264. marked.setOptions({
  265. renderer: rendererMD,
  266. gfm: true,
  267. tables: true,
  268. breaks: false,
  269. pedantic: false,
  270. sanitize: false,
  271. smartLists: true,
  272. smartypants: false
  273. });
  274. marked.setOptions({
  275. highlight: function (code) {
  276. return highlight.highlightAuto(code).value;
  277. }
  278. });
  279. var str=<?=json_encode($row['content'])?>;
  280. $("#article").html(marked(str));
  281. });
  282. </script>