} // load user object (not a proper eatStaticUser instance) from session $user = unserialize(eatStatic::getValue('user', 'session')); $stub = ''; try { switch ($path[0]) { /** * blog URL handling */ /** * home page */ case "": require EATSTATIC_ROOT . '/eatStaticBlog.class.php'; $blog = new eatStaticBlog(); $blog->getPostFiles(); $posts = $blog->getRecentPosts(); $page_title = BLOG_TITLE . ' :: ' . BLOG_TAG_LINE; // set up paginator $paginator = new eatStaticPaginator(); $paginator->total = count($blog->post_files); $paginator->pagination_root = 'posts/all/'; $stub = "blog_index.php"; break; /** * blog post page */ /** * blog post page */ case "posts":
function hydrate() { $this->raw_data = $this->read_file($this->data_file_path); if ($this->raw_data == '') { // no post content found } $ext = $this->getExtension($this->data_file_path); if ($ext == 'md') { $this->source_format = 'markdown'; require_once LIB_ROOT . "/php-markdown/Markdown.inc.php"; } $parts = explode("\n", $this->raw_data); $str = ''; $format_str = ''; // get title from first line $this->title = $parts[0]; $body = true; $meta = false; $raw_body = ''; $raw_meta = ''; // the rest is body for ($i = 1; $i < sizeof($parts); $i++) { $str = $str . $parts[$i]; if ($i > 1) { // the body section can be the rest of the file, // or you can mark the end of the body section with -- // you can then put meta data fields in the file if (eatStatic::stripLineBreaks($parts[$i]) == '--' && $meta == false) { $body = false; $meta = true; } if ($body) { $raw_body = $raw_body . $parts[$i] . "\n"; // formatted body - for text format, line breaks need to be replaced with br, but not between html elements if ($this->source_format == 'text') { if (substr($parts[$i], -1) != '>') { $format_str = $format_str . $parts[$i] . "<br />\n"; } else { $format_str = $format_str . $parts[$i] . "\n"; } } } // get meta info if ($meta && eatStatic::stripLineBreaks($parts[$i]) != '--') { //die('meta:'.$parts[$i]); if ($parts[$i] != '') { $this->handleMeta($parts[$i]); $raw_meta = $raw_meta . $parts[$i] . "\n"; } } } } if ($this->source_format == 'markdown') { // remove hashes from title $this->title = str_replace('#', '', $this->title); // parse the markdown into HTML $this->formatted_body = Michelf\Markdown::defaultTransform($raw_body); } else { $this->formatted_body = $format_str; } $this->raw_body = $raw_body; $this->raw_meta = $raw_meta; $this->body = $str; $this->file_name = basename($this->data_file_path); if ($this->source_format == 'markdown') { $this->slug = str_replace('.md', '', $this->file_name); } else { $this->slug = str_replace('.txt', '', $this->file_name); } $this->date = substr($this->file_name, 0, 10); $this->slug_trimmed = str_replace($this->date . '-', '', $this->slug); $this->nice_date = date(NICE_DATE_FORMAT, strtotime($this->date)); $this->timestamp = strtotime($this->date); // get gallery items if there are any $gallery = new eatStaticGallery($this->slug . '/'); $this->gallery_items = $gallery->gallery_items; // set up the URI if (WP_URLS) { $date_str = date('Y', strtotime($this->date)) . '-' . date('m', strtotime($this->date)) . '-' . date('d', strtotime($this->date)); $this->uri = SITE_ROOT . date('Y', strtotime($this->date)) . '/' . date('m', strtotime($this->date)) . '/' . date('d', strtotime($this->date)) . '/' . str_replace($date_str . '-', '', $this->slug) . '/'; } else { $this->uri = SITE_ROOT . 'posts/' . $this->slug . PAGE_EXT; } // get the next and previous urls $blog = new eatStaticBlog(); $blog->getPostFiles(); foreach ($blog->post_files as $key => $val) { if ($val == $this->data_file_path) { if ($key > 0) { $this->prev_url = $this->uriFromFilename(basename($blog->post_files[$key - 1])); } if ($key < count($blog->post_files) - 1) { $this->next_url = $this->uriFromFilename(basename($blog->post_files[$key + 1])); } } } }