Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php require 'header.php';
- class BlogDisplay
- {
- private $blogname;
- private $blog_path;
- public function __construct($blogname)
- {
- $this->blogname = $blogname;
- $this->blog_path = "../../blogs/" . $blogname;
- $this->show_posts();
- }
- private function show_posts()
- {
- foreach (new DirectoryIterator($this->blog_path) as $post) {
- if ($this->is_post($post)) {
- $this->show_post($post);
- $this->file_links($post);
- $this->link_to_comment($post);
- $this->show_comments($post);
- }
- }
- }
- private function is_post(DirectoryIterator $post)
- {
- return !($post->isDot() || strlen(basename($post)) != 16);
- }
- private function show_post(DirectoryIterator $post)
- {
- echo "<h2> $post </h2>";
- echo "Jestem w pokazywaniu posta"
- $post_file = fopen("$this->blog_path/$post/$post", 'r');
- while (!feof($post_file)) {
- echo (fgets($post_file)."<br/>");
- }
- fclose($post_file);
- echo "<br />";
- }
- private function file_links(DirectoryIterator $post)
- {
- foreach (new DirectoryIterator($this->blog_path."/".$post."/") as $file) {
- if (substr(basename($file), 0, 16) == basename($post) && substr(basename($file), -2, 2) != '$
- ?>
- <a href="<?php echo $this->blog_path."/".$post."/". $file ?>"><?php echo $file ?></a><br$
- <?php
- }
- }
- }
- private function link_to_comment(DirectoryIterator $post)
- {
- echo '<a href="AddNewComment.php?post_name='.$post.'&nazwa='.$this->blogname.'"> Dodaj komentarz$
- }
- private function show_comments(DirectoryIterator $post)
- {
- if(!file_exists("$this->blog_path/$post/$post.k")) return;
- echo '<h2>Komentarze:</h2>';
- foreach (new DirectoryIterator("$this->blog_path/$post/$post.k") as $comment){
- if(!$comment->isDot()){
- $comment_content = explode("\n", file_get_contents($comment->getPath()."/".$comment->get$
- for($i =3; $i< count($comment_content); $i++ ){
- echo "$comment_content[$i]<br/>";
- }
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement