post.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. session_start();
  3. $http_host = $_SERVER["HTTP_HOST"];
  4. $doc_root = $_SERVER["DOCUMENT_ROOT"] . "/";
  5. include $doc_root . "functions.php";
  6. $proto = get_protocol();
  7. $con = start_db();
  8. $server = $proto . $http_host;
  9. $lang = select_language($con);
  10. $lserver = $server . "/" . $lang;
  11. // Get post data
  12. $permalink = mysqli_real_escape_string($con, $_GET["permalink"]);
  13. $q_post = mysqli_query($con, "SELECT * FROM post WHERE permalink = '$permalink' AND visible = 1;");
  14. if (mysqli_num_rows($q_post) == 0){
  15. header("Location: $lserver/blog/");
  16. exit(-1);
  17. }
  18. $r_post = mysqli_fetch_array($q_post);
  19. $id = $r_post["id"];
  20. $title = text($con, $r_post["title"], $lang);
  21. $text = text($con, $r_post["text"], $lang);
  22. $cur_section = "blog";
  23. $cur_entry = $id;
  24. // First image (if any)
  25. $image = "";
  26. $q_image = mysqli_query($con, "SELECT image FROM post_image WHERE post = $id ORDER BY idx LIMIT 1");
  27. if (mysqli_num_rows($q_image) > 0){
  28. $image = mysqli_fetch_array($q_image)["image"];
  29. }
  30. ?>
  31. <!DOCTYPE html>
  32. <html>
  33. <head>
  34. <meta content='text/html; charset=utf-8' http-equiv='content-type'/>
  35. <meta charset='utf-8'/>
  36. <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'/>
  37. <title><?=$title?> - <?=text($con, "USER_NAME", $lang);?></title>
  38. <link rel='shortcut icon' href='<?=$lserver?>/img/logo/favicon.ico'/>
  39. <!-- CSS files -->
  40. <style>
  41. <?php
  42. include $doc_root . "css/ui.css";
  43. include $doc_root . "css/blog.css";
  44. ?>
  45. </style>
  46. <!-- CSS for mobile version -->
  47. <style media='(max-width : 990px)'>
  48. <?php
  49. include $doc_root . "css/m/ui.css";
  50. include $doc_root . "css/m/blog.css";
  51. ?>
  52. </style>
  53. <!-- Script files -->
  54. <script type='text/javascript'>
  55. <?php
  56. include $doc_root . "script/ui.js";
  57. ?>
  58. </script>
  59. <!-- Meta tags -->
  60. <link rel='canonical' href='<?=$lserver?>/blog/<?=$permalink?>'/>
  61. <link rel='author' href='<?=$lserver?>'/>
  62. <link rel='publisher' href='<?=$lserver?>'/>
  63. <meta name='description' content='<?=$text?>'/>
  64. <meta property='og:title' content='<?=$title?> - <?=text($con, "USER_NAME", $lang);?>'/>
  65. <meta property='og:url' content='<?=$lserver?>/blog/<?=$permalink?>'/>
  66. <meta property='og:description' content='<?=$text?>'/>
  67. <?php
  68. if (strlen($image) == 0){
  69. ?>
  70. <meta property="og:image" content="<?=$lserver?>/img/logo/x3/favicon.ico"/>
  71. <?php
  72. }
  73. else{
  74. ?>
  75. <meta property="og:image" content="<?=$lserver?>/img/blog/x3/<?=$image?>"/>
  76. <?php
  77. }
  78. ?>
  79. <meta property='og:site_name' content='<?=text($con, "USER_NAME", $lang);?>'/>
  80. <meta property='og:type' content='website'/>
  81. <meta property='og:locale' content='<?=$lang?>'/>
  82. <meta name='twitter:card' content='summary'/>
  83. <meta name='twitter:title' content='<?=$title?> - <?=text($con, "USER_NAME", $lang);?>'/>
  84. <meta name='twitter:description' content='<?=$text?>'/>
  85. <?php
  86. if (strlen($image) == 0){
  87. ?>
  88. <meta property="twitter:image" content="<?=$lserver?>/img/logo/x3/favicon.ico"/>
  89. <?php
  90. }
  91. else{
  92. ?>
  93. <meta property="twitter:image" content="<?=$lserver?>/img/blog/x3/<?=$image?>"/>
  94. <?php
  95. }
  96. ?> <meta name='twitter:url' content='<?=$lserver?>/blog/<?=$permalink?>'/>
  97. <meta name='robots' content='index follow'/>
  98. </head>
  99. <body>
  100. <?php
  101. include $doc_root . "header.php";
  102. ?>
  103. <div id='content'>
  104. <div id='content_row'>
  105. <div id='content_cell_post' class='content_cell'>
  106. <div class='section' id='post'>
  107. <h3 class='section_title'><?=$title?></h3>
  108. <div class='entry'>
  109. <?php
  110. if (strlen($image) > 0){
  111. ?>
  112. <img id='post_main_image' src='<?=$lserver?>/img/blog/x6/<?=$image?>' alt='<?=$title?>' title='<?=$title?>' />
  113. <?php
  114. }
  115. ?>
  116. <?=$text?>
  117. <?php
  118. $q_image = mysqli_query($con, "SELECT image FROM post_image WHERE post = $id ORDER BY idx OFFSET 1");
  119. if (mysqli_num_rows($q_image) > 0){
  120. ?>
  121. <div id='image_reel'>
  122. <?php
  123. while ($r_image = mysqli_fetch_array($q_image)){
  124. ?>
  125. <img src='<?=$lserver?>/img/blog/x6/<?=$r_image["image"]?>' alt='<?=$title?>' title='<?=$title?>' />
  126. <?php
  127. }
  128. ?>
  129. </div> <!-- #image_reel -->
  130. <?php
  131. }
  132. ?>
  133. <hr/>
  134. <?php
  135. #Comments
  136. if ($r_post["comments"] == 1){
  137. $q_comment = mysqli_query($con, "SELECT id, post, DATE_FORMAT(dtime, '%Y-%m-%dT%T') AS cdate, DATE_FORMAT(dtime,'%b %d, %Y - %H:%i') AS dtime, user, username, text FROM post_comment WHERE post = $id;");
  138. $count = mysqli_num_rows($q_comment);
  139. if ($count == 1){
  140. ?>
  141. <span class='comment_counter'>1 <?=text($con, "BLOG_COMMENTS_1", $lang)?></span>
  142. <?php
  143. }
  144. else if ($count == 0){
  145. ?>
  146. <span class='comment_counter'><?=text($con, "BLOG_COMMENTS_0", $lang)?></span>
  147. <?php
  148. }
  149. else{
  150. ?>
  151. <span class='comment_counter'><?=$count?> <?=text($con, "BLOG_COMMENTS_X", $lang)?></span>
  152. <?php
  153. }
  154. while ($r_comment = mysqli_fetch_array($q_comment)){
  155. $user = $r_comment["username"];
  156. $user_string = $user;
  157. if (strlen($user) == 0){
  158. $user = mysqli_fetch_array(mysqli_query($con, "SELECT concat(fname, concat(' ', lname)) AS name FROM user WHERE id = $r_comment[user];"))["name"];
  159. $user_string = "<span class='comment_user_registered'>$user</span>";
  160. }
  161. ?>
  162. <div itemprop='comment' itemscope itemtype='http://schema.org/UserComments' id='comment_<?=$r_comment["id"]?>' class='comment'>
  163. <h4 class='comment_user'><?=$user_string?></h4>
  164. <meta itemprop='creator' content='<?=$user?>'>
  165. <span class='comment_date date'>
  166. <time itemprop='commentTime' datetime='<?=$r_comment["cdate"]?>'>
  167. <?=$r_comment["dtime"]?>
  168. </span>
  169. <p itemprop='commentText' class='comment_text'><?=$r_comment["text"]?></p>
  170. </div>
  171. <?php
  172. }
  173. //Comment form
  174. ?>
  175. <div class='comment' id='comment_new'>
  176. <textarea id='new_comment_text' name='text' maxlength='1800' onfocus='showCommentIdentification();' placeholder='<?=text($con, "COMMENT_YOUR", $lang)?>'></textarea>
  177. <div id='identification_form'>
  178. <br/>
  179. <input id='new_comment_user' name='user' maxlength='50' type='text' placeholder='<?text($con, "COMMENT_YOUR_NAME", $lang)?>'/>
  180. <input type='button' value='<?text($con, "COMMENT_PUBLISH", $lang)?>'/>
  181. </div>
  182. </div>
  183. <?php
  184. }
  185. else{
  186. ?>
  187. <h4><?text($con, "COMMENT_CLOSED_POST", $lang)?></h4>
  188. <?php
  189. }
  190. ?>
  191. </div> <!-- .entry -->
  192. </div> <!-- .section -->
  193. </div> <!-- .content_cell -->
  194. <div id='content_cell_info' class='content_cell'>
  195. <div class='section' id='info'>
  196. <div id="info_date" class='entry'>
  197. <span class='date'><?=format_date($r_post["dtime"], $lang)?></span>
  198. </div>
  199. <div id="info_share" class='entry'>
  200. <?php
  201. $q_share = mysqli_query($con, "SELECT id FROM share WHERE visible = 1 ORDER BY idx;");
  202. while ($r_share = mysqli_fetch_array($q_share)){
  203. ?>
  204. <?=share_link($con, $r_share["id"], $lserver, "$server/blog/$permalink", $lang)?>
  205. <?php
  206. }
  207. ?>
  208. </div>
  209. <?php
  210. $q_tag = mysqli_query($con, "SELECT tag FROM post_tag WHERE post = $id;");
  211. if (mysqli_num_rows($q_tag) > 0){
  212. ?>
  213. <div id="info_tags" class='entry'>
  214. <?php
  215. $tag_string = "<span id='tags'>" . text($con, "BLOG_TAGS", $lang) . ": ";
  216. $tag_raw = "";
  217. while ($r_tag = mysqli_fetch_array($q_tag)){
  218. $tag_string = $tag_string . "<a href='$lserver/blog/search/tag/$r_tag[tag]'>$r_tag[tag]</a>, ";
  219. $tag_raw = $tag_raw . "$r_tag[tag],";
  220. }
  221. $tag_string = substr($tag_string, 0, strlen($tag_string) - 2);
  222. $tag_string = $tag_string . "</span>";
  223. $tag_raw = substr($tag_raw, 0, strlen($tag_raw) - 1);
  224. ?>
  225. <span class='tags'><?=$tag_string?></span>
  226. <meta itemprop='keywords' content='<?=$tag_raw?>'/>
  227. </div> <!-- #info_tags -->
  228. <?php
  229. } // if (mysqli_num_rows($q_tag) > 0)
  230. ?>
  231. <?php
  232. // Previous / next
  233. $q_prev = mysqli_query($con, "SELECT id, permalink, title FROM post WHERE id <> $id AND dtime <= '$r_post[dtime]' ORDER BY dtime DESC LIMIT 1;");
  234. $q_next = mysqli_query($con, "SELECT id, permalink, title FROM post WHERE id <> $id AND dtime >= '$r_post[dtime]' ORDER BY dtime LIMIT 1;");
  235. if (mysqli_num_rows($q_prev) > 0 || mysqli_num_rows($q_next) > 0){
  236. ?>
  237. <div id='info_prev_next' class='entry'>
  238. <table id='prev_next'>
  239. <tr>
  240. <td id='prev'>
  241. <?php
  242. if (mysqli_num_rows($q_prev) > 0){
  243. $r_prev = mysqli_fetch_array($q_prev);
  244. ?>
  245. <a href='<?=$lserver?>/blog/<?=$r_prev["permalink"]?>'>
  246. <span class='info'>Previous post:</span>
  247. <br/>
  248. <span class='title'><?=text($con, $r_prev["title"], $lang)?></span>
  249. </a>
  250. <?php
  251. }
  252. ?>
  253. </td>
  254. <td id='next'>
  255. <?php
  256. if (mysqli_num_rows($q_next) > 0){
  257. $r_next = mysqli_fetch_array($q_next);
  258. ?>
  259. <a href='<?=$lserver?>/blog/<?=$r_next["permalink"]?>'>
  260. <span class='info'>Next post:</span>
  261. <br/>
  262. <span class='title'><?=text($con, $r_next["title"], $lang)?></span>
  263. </a>
  264. <?php
  265. }
  266. ?>
  267. </td>
  268. </tr>
  269. </table>
  270. </div> <!-- #info_prev_next -->
  271. <?php
  272. } // if (mysqli_num_rows($q_prev) > 0 || mysqli_num_rows($q_next) > 0)
  273. ?>
  274. <div id='info_related' class='entry'>
  275. TODO
  276. </div>
  277. <div id='info_all' class='entry'>
  278. TODO
  279. </div>
  280. </div> <!-- #info -->
  281. </div> <!-- .content-cell -->
  282. </div> <!-- #content-row -->
  283. </div> <!-- #content -->
  284. <?php
  285. include $doc_root . "footer.php";
  286. stats($con, $cur_section, $cur_entry);
  287. ?>
  288. </body>
  289. </html>