/CoreCMS/core/functions/get_entry.php

https://github.com/danielhahne/corecms · PHP · 113 lines · 92 code · 20 blank · 1 comment · 18 complexity · 1df9ba1bb517b949ee83b488bd745b63 MD5 · raw file

  1. <?php
  2. $b = $_SERVER['REQUEST_URI'];
  3. if($entry) {
  4. $b = substr($b,0,strrpos($b,"/")) . "/core/";
  5. $id = $entry;
  6. $isPerma = true;
  7. } else {
  8. $b = substr($b,0,mb_strrpos($b,"/core/")+6);
  9. $id = $_REQUEST["id"];
  10. }
  11. $root = $_SERVER['DOCUMENT_ROOT'] . $b;
  12. $http = "http://" . $_SERVER['HTTP_HOST'] . substr($b,0,strlen($b)-5);
  13. require_once($root . "user/configuration.php");
  14. require_once($root . "themes/".$theme."/configuration.php");
  15. require_once($root . "functions/session.php");
  16. if(is_numeric($id)) {
  17. $type = "entry";
  18. } else {
  19. $type = "page";
  20. }
  21. $id = secure($id);
  22. if($type == "page") {
  23. $data = mysql_query("SELECT p.* FROM core_pages p WHERE p.page_title = \"$id\"");
  24. $page_clicks = 0;
  25. while($p = mysql_fetch_array($data)) {
  26. $url = $p["page_url"];
  27. $path = $root . "user/pages/" . $url;
  28. $page_clicks = $p['hits']+1;
  29. require($path);
  30. }
  31. mysql_query("UPDATE core_pages p SET
  32. p.hits = $page_clicks
  33. WHERE p.page_title = $id");
  34. }
  35. if($type == "entry") {
  36. $data = mysql_query("SELECT e.* FROM core_entries e WHERE e.entry_id = $id AND e.entry_show = 1");
  37. $entry_clicks = 0;
  38. if(@mysql_num_rows($data) < 1) {
  39. die("Invalid id, no entry to be shown");
  40. }
  41. while($e = mysql_fetch_array($data)) {
  42. $entry_id = $e['entry_id'];
  43. $entry_title = $e['entry_title'];
  44. // DATE
  45. $t = $e["entry_date"];
  46. $y = substr($t,0,4);
  47. $m = substr($t,5,2);
  48. $d = substr($t,8,2);
  49. $entry_date = date($date_format,mktime(0,0,0,$m,$d,$y));
  50. $entry_text = $e['entry_text'];
  51. $entry_extra1 = $e['entry_extra1'];
  52. $entry_extra2 = $e['entry_extra2'];
  53. $entry_visit_link = $e['entry_visit_link'];
  54. $entry_client = $e['entry_client'];
  55. $entry_position = $e['entry_position'];
  56. $entry_hits = $e['hits']+1;
  57. $entry_new = $e['entry_new'];
  58. if($entry_new == 1) {
  59. $isNew = true;
  60. } else {
  61. $isNew = false;
  62. }
  63. if($nice_permalinks) {
  64. $entry_perma = "$http".$entry_id;
  65. } else {
  66. $entry_perma = "$http"."?entry=$entry_id";
  67. }
  68. $data_e2t = @mysql_query("SELECT e2t.tag_id FROM core_entry2tag e2t WHERE e2t.entry_id = $entry_id");
  69. $tag_str = "";
  70. while($e2t = @mysql_fetch_array($data_e2t)) {
  71. $tag_id = $e2t["tag_id"];
  72. $data_tags = @mysql_query("SELECT t.tag_text FROM core_tags t WHERE t.tag_id = $tag_id");
  73. while($t = @mysql_fetch_array($data_tags)) {
  74. $tag_text = $t["tag_text"];
  75. $tag_str = $tag_str . "<a class=\"tag-link\" name=\"tag".$tag_id."\" href=\"#tag-"._encode($tag_text)."\">".$tag_text."</a>".$separator_tags;
  76. }
  77. }
  78. $entry_tags = substr($tag_str,0,strlen($tag_str)-strlen($separator_tags));
  79. $layout_path = $root . "user/uploads/" . treat_string($entry_title) . "/layout.php";
  80. if(is_file($layout_path) && (@filesize($layout_path) > 0)) {
  81. require($layout_path);
  82. } else {
  83. require($theme_path . "parts/entry.php");
  84. }
  85. }
  86. mysql_query("UPDATE core_entries e SET
  87. e.hits = $entry_hits
  88. WHERE e.entry_id = $id");
  89. }
  90. if($isPerma) {
  91. echo "<a class=\"index-link\" href=\"$http\">back to index</a>";
  92. }
  93. ?>