Exemplo n.º 1
0
    function atomAddPost($request)
    {
        header("Content-Type: application/atomserv+xml; charset=utf-8");
        // parse submitted data
        $xml = new SimpleXMLElement($request->content);
        $author = (object) array('name' => (string) $xml->author->name, 'email' => (string) $xml->author->email, 'uri' => (string) $xml->author->uri);
        $tags = array();
        foreach ($xml->category as $category) {
            $tags[] = (string) $category['term'];
        }
        $draft = isset($xml->draft);
        // create blog post
        $filesystem = new Minim_Model_Backend_Sqlite($GLOBALS['database']['dsn']);
        $post = new BlogPost();
        $post->setBackend($filesystem);
        $post->title = (string) $xml->title;
        $post->content = (string) $xml->content;
        $post->draft = $draft;
        $post->save();
        $location = "/blog/" . date("Y/m/d", $post->created) . "/{$post->title}";
        $primaryKey = $post->getPrimaryKeyValue();
        header("Content-Location: {$location}");
        header("Location: {$location}");
        echo <<<XML
<?xml version="1.0" ?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <id>{$primaryKey}</id>
  <title>{$post->title}</title>
  <link rel="edit" href="/blog/posts/{$post->id}" />
  <updated>{$post->created}</updated>
  <author><name>{$author->name}</name></author>
  <content>{$post->content}</summary>
</entry>
XML;
        exit;
    }