Ejemplo n.º 1
0
 public function __invoke(array $post)
 {
     $post_data = new \Aruna\Micropub\PostData();
     $post = new PostViewModel($post_data->toMfArray($post));
     $q = "REPLACE INTO posts (id, published, post, type)\n            VALUES\n            (:id, :published, :post, :type)";
     $r = $this->db->prepare($q);
     $r->execute([":id" => $post->get("uid"), ":published" => $post->published(), ":post" => $post->toJson(), ":type" => $post->type()]);
     return $post;
 }
Ejemplo n.º 2
0
function main($in_dir, $out_dir)
{
    require_once __DIR__ . "/app.php";
    $files_parsed = 0;
    $postData = new Aruna\Micropub\PostData();
    foreach (list_files($in_dir) as $file) {
        // read post_data
        $in_filename = $file[0];
        $out_filename = $out_dir . "/" . basename($in_filename, ".json") . ".html";
        $post_data = json_decode(file_get_contents($in_filename), true);
        // convert mf json to viewModel
        $view_model = new Aruna\PostViewModel($postData->toMfArray($post_data));
        // render viewModel as html
        $post_html = $app['twig']->render("post_" . $view_model->type() . ".html", array("post" => $view_model));
        file_put_contents($out_filename, $post_html);
        $files_parsed += 1;
    }
    print sprintf("Processed %s files", $files_parsed);
}