Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1.  
  2. <?php require 'header.php';
  3.  
  4. class BlogDisplay
  5. {
  6. private $blogname;
  7. private $blog_path;
  8.  
  9. public function __construct($blogname)
  10. {
  11. $this->blogname = $blogname;
  12. $this->blog_path = "../../blogs/" . $blogname;
  13. $this->show_posts();
  14. }
  15.  
  16. private function show_posts()
  17. {
  18. foreach (new DirectoryIterator($this->blog_path) as $post) {
  19. if ($this->is_post($post)) {
  20. $this->show_post($post);
  21. $this->file_links($post);
  22. $this->link_to_comment($post);
  23. $this->show_comments($post);
  24. }
  25. }
  26. }
  27.  
  28. private function is_post(DirectoryIterator $post)
  29. {
  30. return !($post->isDot() || strlen(basename($post)) != 16);
  31. }
  32.  
  33. private function show_post(DirectoryIterator $post)
  34. {
  35. echo "<h2> $post </h2>";
  36. echo "Jestem w pokazywaniu posta"
  37. $post_file = fopen("$this->blog_path/$post/$post", 'r');
  38. while (!feof($post_file)) {
  39. echo (fgets($post_file)."<br/>");
  40. }
  41. fclose($post_file);
  42. echo "<br />";
  43. }
  44.  
  45. private function file_links(DirectoryIterator $post)
  46. {
  47. foreach (new DirectoryIterator($this->blog_path."/".$post."/") as $file) {
  48. if (substr(basename($file), 0, 16) == basename($post) && substr(basename($file), -2, 2) != '$
  49. ?>
  50. <a href="<?php echo $this->blog_path."/".$post."/". $file ?>"><?php echo $file ?></a><br$
  51. <?php
  52. }
  53. }
  54. }
  55.  
  56. private function link_to_comment(DirectoryIterator $post)
  57. {
  58. echo '<a href="AddNewComment.php?post_name='.$post.'&nazwa='.$this->blogname.'"> Dodaj komentarz$
  59. }
  60.  
  61. private function show_comments(DirectoryIterator $post)
  62. {
  63. if(!file_exists("$this->blog_path/$post/$post.k")) return;
  64. echo '<h2>Komentarze:</h2>';
  65. foreach (new DirectoryIterator("$this->blog_path/$post/$post.k") as $comment){
  66. if(!$comment->isDot()){
  67. $comment_content = explode("\n", file_get_contents($comment->getPath()."/".$comment->get$
  68. for($i =3; $i< count($comment_content); $i++ ){
  69. echo "$comment_content[$i]<br/>";
  70. }
  71. }
  72. }
  73. }
  74. }
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement