post.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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();
  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?> - I&ntilde;igo Valentin</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?> - I&ntilde;igo Valentin'/>
  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='I&ntilde;igo Valentin'/>
  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?> - I&ntilde;igo Valentin'/>
  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 class='section' id='post'>
  104. <h3 class='section_title'><?=$title?></h3>
  105. <div class='entry'>
  106. <?php
  107. if (strlen($image) > 0){
  108. ?>
  109. <img id='post_main_image' src='<?=$lserver?>/img/blog/x6/<?=$image?>' alt='<?=$title?>' title='<?=$title?>' />
  110. <?php
  111. }
  112. ?>
  113. <?=$text?>
  114. <?php
  115. $q_image = mysqli_query($con, "SELECT image FROM post_image WHERE post = $id ORDER BY idx OFFSET 1");
  116. if (mysqli_num_rows($q_image) > 0){
  117. ?>
  118. <div id='image_reel'>
  119. <?php
  120. while ($r_image = mysqli_fetch_array($q_image)){
  121. ?>
  122. <img src='<?=$lserver?>/img/blog/x6/<?=$r_image["image"]?>' alt='<?=$title?>' title='<?=$title?>' />
  123. <?php
  124. }
  125. ?>
  126. </div> <!-- #image_reel -->
  127. <?php
  128. }
  129. ?>
  130. <hr/>
  131. <!-- TODO: Tags and share -->
  132. <?php
  133. $q_share = mysqli_query($con, "SELECT id FROM share WHERE visible = 1 ORDER BY idx;");
  134. while ($r_share = mysqli_fetch_array($q_share)){
  135. ?>
  136. <?=share_link($con, $r_share["id"], $lserver, "$server/blog/$permalink", $lang)?>
  137. <?php
  138. }
  139. ?>
  140. <hr/>
  141. <?php
  142. #Comments
  143. if ($r_post["comments"] == 1){
  144. $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;");
  145. $count = mysqli_num_rows($q_comment);
  146. if ($count == 1){
  147. ?>
  148. <span class='comment_counter'>1 <?=text($con, "BLOG_COMMENTS_1", $lang)?></span>
  149. <?php
  150. }
  151. else if ($count == 0){
  152. ?>
  153. <span class='comment_counter'><?=text($con, "BLOG_COMMENTS_0", $lang)?></span>
  154. <?php
  155. }
  156. else{
  157. ?>
  158. <span class='comment_counter'><?=$count?> <?=text($con, "BLOG_COMMENTS_X", $lang)?></span>
  159. <?php
  160. }
  161. while ($r_comment = mysqli_fetch_array($q_comment)){
  162. $user = $r_comment["username"];
  163. $user_string = $user;
  164. if (strlen($user) == 0){
  165. $user = mysqli_fetch_array(mysqli_query($con, "SELECT concat(fname, concat(' ', lname)) AS name FROM user WHERE id = $r_comment[user];"))["name"];
  166. $user_string = "<span class='comment_user_registered'>$user</span>";
  167. }
  168. ?>
  169. <div itemprop='comment' itemscope itemtype='http://schema.org/UserComments' id='comment_<?=$r_comment["id"]?>' class='comment'>
  170. <h4 class='comment_user'><?=$user_string?></h4>
  171. <meta itemprop='creator' content='<?=$user?>'>
  172. <span class='comment_date date'>
  173. <time itemprop='commentTime' datetime='<?=$r_comment["cdate"]?>'>
  174. <?=$r_comment["dtime"]?>
  175. </span>
  176. <p itemprop='commentText' class='comment_text'><?=$r_comment["text"]?></p>
  177. </div>
  178. <?php
  179. }
  180. //Comment form
  181. ?>
  182. <div class='comment' id='comment_new'>
  183. <textarea id='new_comment_text' name='text' maxlength='1800' onfocus='showCommentIdentification();' placeholder='TR#Your comment...'></textarea>
  184. <div id='identification_form'>
  185. <br/>
  186. <input id='new_comment_user' name='user' maxlength='50' type='text' placeholder='TR#Your name'/>
  187. <input type='button' value='TR#Send comment'/>
  188. </div>
  189. </div>
  190. <?php
  191. }
  192. else{
  193. ?>
  194. <h4>TR#Comments are closed in this post</h4>
  195. <?php
  196. }
  197. ?>
  198. <hr/>
  199. <?php
  200. // Previous / next
  201. $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;");
  202. $q_next = mysqli_query($con, "SELECT id, permalink, title FROM post WHERE id <> $id AND dtime >= '$r_post[dtime]' ORDER BY dtime LIMIT 1;");
  203. if (mysqli_num_rows($q_prev) > 0 || mysqli_num_rows($q_next) > 0){
  204. ?>
  205. <table id='prev_next'>
  206. <tr>
  207. <td id='prev'>
  208. <?php
  209. if (mysqli_num_rows($q_prev) > 0){
  210. $r_prev = mysqli_fetch_array($q_prev);
  211. ?>
  212. <a href='<?=$lserver?>/blog/<?=$r_prev["permalink"]?>'>
  213. <span class='info'>Previous post:</span>
  214. <br/>
  215. <span class='title'><?=text($con, $r_prev["title"], $lang)?></span>
  216. </a>
  217. <?php
  218. }
  219. ?>
  220. </td>
  221. <td id='next'>
  222. <?php
  223. if (mysqli_num_rows($q_next) > 0){
  224. $r_next = mysqli_fetch_array($q_next);
  225. ?>
  226. <a href='<?=$lserver?>/blog/<?=$r_next["permalink"]?>'>
  227. <span class='info'>Next post:</span>
  228. <br/>
  229. <span class='title'><?=text($con, $r_next["title"], $lang)?></span>
  230. </a>
  231. <?php
  232. }
  233. ?>
  234. </td>
  235. </tr>
  236. </table>
  237. <?php
  238. }
  239. ?>
  240. <hr/>
  241. <!-- TODO: Related posts -->
  242. </div> <!-- .entry -->
  243. </div> <!-- .section -->
  244. <?php
  245. include $doc_root . "footer.php";
  246. stats($con, $cur_section, $cur_entry);
  247. ?>
  248. </body>
  249. </html>