Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. <?php
  2. header("content-type:application/xhtml+xml; charset =utf-8", "application/xhtml+xml; charset =utf-8");
  3.  
  4. $BASE_PATH = ".";
  5.  
  6. function readInfo($infoPath, $short = True)
  7. {
  8. $infoFile = fopen("$infoPath/info", "r");
  9. $user = rtrim(fgets($infoFile));
  10. $info["user"] = $user;
  11. $password = rtrim(fgets($infoFile));
  12. $info["password"] = $password;
  13. $desc = "";
  14.  
  15. if (!$short) {
  16. while (false !== ($line = fgets($infoFile))) {
  17. $desc .= $line;
  18. }
  19. }
  20. $info["desc"] = $desc;
  21.  
  22.  
  23. return $info;
  24. }
  25.  
  26.  
  27. function createHTMLPost($blogPath,$blogname, $entry)
  28. {
  29. $data = getPost($blogPath, $entry);
  30.  
  31. $Postentry = htmlspecialchars($data["entry"]);
  32.  
  33. $year = $data["year"];
  34. $month = $data["month"];
  35. $day = $data["day"];
  36. $hour = $data["hour"];
  37. $minute = $data["minute"];
  38. $second = $data["second"];
  39.  
  40. $date = "$year-$month-$day, $hour:$minute:$second";
  41. echo "<li class=\"post\">\n";
  42. echo "<div class=\"content\"><pre>$Postentry</pre><br/><span class=\"date\">$date</span></div>";
  43. echo "<ul class=\"files\">";
  44. foreach (glob("$blogPath/$entry{0,1,2,3}.*", GLOB_BRACE) as $file) {
  45. $filename = basename($file);
  46. echo "<li><a href=\"$file\">$filename</a></li>";
  47. }
  48. echo "</ul>\n";
  49. echo "<h2>Komentarze:</h2>\n";
  50. echo "<ul class=\"comments\">\n";
  51.  
  52. $max=0;
  53. $comments = [];
  54. foreach (glob("$blogPath/$entry.k/*") as $file) {
  55. $id = intval(basename($file));
  56. $comments[$id] = $file;
  57. $max=$id+1;
  58. }
  59. for($id=0;$id<$max;$id+=1){
  60. if($comments[$id] !==null)
  61. createHTMLcomment($comments[$id]);
  62. }
  63. $urlblog=htmlspecialchars($blogname);
  64. $urlEntry=htmlspecialchars($entry);
  65. echo "<a href=\"dodajKomentarz.php?blogname=$urlblog&amp;entry=$urlEntry\" >Dodaj Komentarz</a>";
  66. echo "</ul>";
  67. echo "</li>\n";
  68. }
  69.  
  70. function getPost($path, $name)
  71. {
  72. $data["entry"] = "";
  73. $post = fopen("$path/$name", "r");
  74. while (($ext = fgets($post)) !== False)
  75. $data["entry"] .= $ext;
  76. fclose($post);
  77. $data["name"] = $name;
  78. $data["year"] = substr($name, 0, 4);
  79. $data["month"] = substr($name, 4, 2);
  80. $data["day"] = substr($name, 6, 2);
  81. $data["hour"] = substr($name, 8, 2);
  82. $data["minute"] = substr($name, 10, 2);
  83. $data["second"] = substr($name, 12, 2);
  84. $data["unique"] = substr($name, 14, 2);
  85.  
  86. return $data;
  87. }
  88.  
  89. function createHTMLcomment($commentPath)
  90. {
  91. $comment = fopen($commentPath, "r");
  92. $reaction = htmlspecialchars(rtrim(fgets($comment)));
  93. $date = htmlspecialchars(rtrim(fgets($comment)));
  94. $user = htmlspecialchars(rtrim(fgets($comment)));
  95. $content = "";
  96. while (($line = fgets($comment)) !== False) {
  97. $content .= $line;
  98. }
  99. $content = htmlspecialchars($content);
  100. echo "<li class=\"comment\">Rodzaj: $reaction<br/> Treść: $content<br/><span class=\"date\">$date</span><br/><span class=\"user\">Autor: $user</span></li>";
  101. fclose($comment);
  102. }
  103.  
  104. function showBlog($blogPath, $blog)
  105. {
  106. ?>
  107. <!-- --><?php //echo '<'.'?xml version="1.0" encoding="utf-8"?'.'>'."\n"; ?>
  108. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="pl">
  109. <head>
  110. <meta http-equiv="content-type" content="application/xhtml+xml; charset =utf-8"/>
  111. <title><?php echo $blog?></title>
  112. </head>
  113. <body>
  114. <?php include("Menu.php") ?>
  115. <?php
  116. $info = readFromInfo($blogPath, False);
  117. echo "<h1>$blog</h1>";
  118. echo "<div class=\"desc\">";
  119. echo htmlspecialchars($info["desc"]);
  120. echo "<br/>Właścicel bloga:";
  121. echo "<span class=\"user\"><br/>";
  122. echo htmlspecialchars($info["user"]);
  123. echo "</span>";
  124. echo "</div>";
  125.  
  126. echo "<ul>";
  127. foreach (scandir($blogPath) as $entry) {
  128. if (mb_ereg_match('[0-9]{16}$', $entry)) {
  129. createHTMLPost($blogPath,$blog, $entry);
  130. }
  131. }
  132. echo "</ul>";
  133. ?>
  134. </body>
  135. </html>
  136. <?php
  137. }
  138.  
  139. function listBlogs($BASE_PATH)
  140. {
  141. ?>
  142. <!-- --><?php //echo '<'.'?xml version="1.0" encoding="utf-8"?'.'>'."\n"; ?>
  143. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="pl">
  144. <head>
  145. <meta http-equiv="content-type" content="application/xhtml+xml; charset =utf-8"/>
  146. <title>Lista Blogów</title>
  147. </head>
  148. <body>
  149. <?php include("Menu.php") ?>
  150. <ul>
  151. <?php
  152. foreach (glob("$BASE_PATH/*/info") as $blog) {
  153. $blogName = dirname($blog);
  154. $info = readFromInfo($blogName, False);
  155. $desc = htmlspecialchars($info["desc"]);
  156. $user = htmlspecialchars($info["user"]);
  157.  
  158. $blogActualName = htmlspecialchars(basename($blogName));
  159. echo "<li><a href=\"?nazwa=$blogActualName\">$blogActualName - $desc [$user]</a></li>";
  160. }
  161. ?>
  162. </ul>
  163. </body>
  164. </html>
  165. <?php
  166. }
  167.  
  168.  
  169.  
  170. $blog = $_GET["nazwa"];
  171. $blogPath = "$BASE_PATH/$blog";
  172. if (!isset($_GET["nazwa"])) {
  173. listBlogs($BASE_PATH);
  174. } else if (file_exists("$blogPath/info") and is_dir($blogPath)) {
  175. showBlog($blogPath, $blog);
  176. } else {
  177. header("Status: 404 Not Found");
  178. echo "brak takiego bloga";
  179. }
  180. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement