public function write_index_sequence($dest_path, $title, $type, array $posts, $template = 'main.html', $archive_array = false, $posts_per_page = 20) { $sequence = 0; $new_dest_path = $dest_path; // $dest_uri = substring_after(substring_before($dest_path, '.', true), Updater::$dest_path); $dest_uri = substring_after(substring_after($dest_path, '/', true), Updater::$dest_path); $total_sequences = ceil(count($posts) / $posts_per_page); while ($posts) { $sequence++; $seq_array = array_splice($posts, 0, $posts_per_page); if ($sequence == 1) { continue; } // skip writing the redundant "-1" page $new_dest_path = $dest_path . '-' . $sequence . '.html'; $posts_data = array(); foreach ($seq_array as $p) { $posts_data[] = $p->array_for_template(); } $t = new Template($template); $t->content = array('page-title' => html_entity_decode(SmartyPants($title), ENT_QUOTES, 'UTF-8'), 'blog-title' => html_entity_decode(SmartyPants(self::$blog_title), ENT_QUOTES, 'UTF-8'), 'blog-url' => self::$blog_url, 'blog-description' => html_entity_decode(SmartyPants(self::$blog_description), ENT_QUOTES, 'UTF-8'), 'page-type' => $type, 'posts' => $posts_data, 'previous_page_url' => $sequence != 1 ? $sequence == 2 ? $dest_uri : $dest_uri . '-' . ($sequence - 1) : false, 'next_page_url' => $sequence < $total_sequences ? $dest_uri . '-' . ($sequence + 1) : false, 'archives' => $archive_array ? $archive_array : array()); $output_html = $t->outputHTML(); $output_path = dirname($new_dest_path); if (!file_exists($output_path)) { mkdir_as_parent_owner($output_path, 0755, true); } file_put_contents_as_dir_owner($new_dest_path, $output_html); } return $total_sequences; }
public function write_archive($posts) { $template = Updater::$archive_page_template; $t = new Template($template); $t->content = array('post-title' => 'Archive', 'post-type' => 'archive', 'page-type' => 'archive', 'page-title' => 'Archive', 'blog-title' => html_entity_decode(SmartyPants(self::$blog_title), ENT_QUOTES, 'UTF-8')); foreach ($posts as $post) { $t->content['posts'][] = array('title' => html_entity_decode(SmartyPants($post->title), ENT_QUOTES, 'UTF-8'), 'timestamp' => $post->timestamp, 'uri' => '/' . $post->year . '/' . str_pad($post->month, 2, '0', STR_PAD_LEFT) . '/' . $post->slug, 'tags' => $post->tags); $output_html = $t->outputHTML(); } if (!file_exists(Updater::$dest_path)) { mkdir_as_parent_owner(Updater::$dest_path, 0755, true); } file_put_contents_as_dir_owner(Updater::$dest_path . '/archive.html', $output_html); }