Ejemplo n.º 1
0
 public function onPost()
 {
     if ($this->user->hasRight('user_activity_add')) {
         try {
             $contentType = Base::getRequestHeader('Content-Type');
             switch ($contentType) {
                 case Writer\Atom::$mime:
                     $atom = new Atom();
                     $atom->import($this->getRequest(ReaderInterface::DOM));
                     foreach ($atom as $entry) {
                         try {
                             $this->insertEntry($entry);
                         } catch (\Exception $e) {
                         }
                     }
                     break;
                 default:
                     throw new Exception('Invalid content type');
                     break;
             }
             $msg = new Data\Message('You have successful create a message', true);
             $this->setResponse($msg, WriterInterface::XML);
         } catch (Exception $e) {
             $msg = new Data\Message($e->getMessage(), false);
             $this->setResponse($msg, WriterInterface::XML);
         }
     } else {
         $msg = new Data\Message('Access not allowed', false);
         $this->setResponse($msg, WriterInterface::XML, $this->user->isAnonymous() ? 401 : 403);
     }
 }
Ejemplo n.º 2
0
 protected function onAtom(Atom $atom)
 {
     $entry = $atom->current();
     $this->testCase->assertEquals('Atom draft-07 snapshot', $entry->getTitle());
     $this->testCase->assertEquals('tag:example.org,2003:3.2397', $entry->getId());
     $this->testCase->assertEquals('2003-12-13 08:29:29', $entry->getPublished()->format('Y-m-d H:i:s'));
     $this->testCase->assertEquals('foobar', $entry->getContent());
 }
Ejemplo n.º 3
0
 protected function getEntryRecord()
 {
     $entry = new Entry();
     $entry->setTitle('Atom draft-07 snapshot');
     $entry->addLink(new Link('http://example.org/2005/04/02/atom', 'alternate', 'text/html'));
     $entry->addLink(new Link('http://example.org/audio/ph34r_my_podcast.mp3', 'enclosure', 'audio/mpeg', null, null, 1337));
     $entry->setId('tag:example.org,2003:3.2397');
     $entry->setUpdated(new DateTime('2005-07-31T12:29:29'));
     $entry->setPublished(new DateTime('2003-12-13T08:29:29-04:00'));
     $entry->addAuthor(new Person('Mark Pilgrim', 'http://example.org/', '*****@*****.**'));
     $entry->addContributor(new Person('Sam Ruby'));
     $entry->addContributor(new Person('Joe Gregorio'));
     $entry->addCategory(new Category('news'));
     $entry->setContent(new Text('<div xmlns="http://www.w3.org/1999/xhtml"><p><i>[Update: The Atom draft is finished.]</i></p></div>', 'xhtml'));
     $entry->setSummary(new Text('foobar', 'text'));
     $entry->setRights('Copyright (c) 2003, Mark Pilgrim');
     $atom = new AtomRecord();
     $atom->setTitle('dive into mark');
     $atom->setSubTitle(new Text('A <em>lot</em> of effort went into making this effortless', 'html'));
     $atom->setUpdated(new DateTime('2005-07-31T12:29:29Z'));
     $atom->setId('tag:example.org,2003:3');
     $atom->addLink(new Link('http://example.org/', 'alternate', 'text/html', 'en'));
     $atom->addLink(new Link('http://example.org/feed.atom', 'self', 'application/atom+xml'));
     $atom->setRights('Copyright (c) 2003, Mark Pilgrim');
     $atom->setGenerator(new Generator('Example Toolkit', 'http://www.example.com/', '1.0'));
     $entry->setSource($atom);
     return $entry;
 }
Ejemplo n.º 4
0
    public function testSerialize()
    {
        $entry = new Entry();
        $entry->addAuthor(new Person('foobar', 'http://foo.com', '*****@*****.**'));
        $entry->addCategory(new Category('foobar', 'http://foo.com', 'Foobar'));
        $entry->setContent(new Text('foobar'));
        $entry->addContributor(new Person('foobar', 'http://foo.com', '*****@*****.**'));
        $entry->setId('http://localhost.com#1');
        $entry->setRights('foo');
        $entry->setTitle('Star City');
        $entry->setPublished(new DateTime('Tue, 10 Jun 2003 04:00:00 GMT'));
        $entry->setUpdated(new DateTime('Tue, 10 Jun 2003 04:00:00 GMT'));
        $entry->addLink(new Link('http://localhost.com', 'me', 'application/xml', 'en', 'Foobar', 1337));
        $entry->setSummary(new Text('lreom ipsum'));
        $atom = new Atom();
        $atom->addAuthor(new Person('foobar', 'http://foo.com', '*****@*****.**'));
        $atom->addCategory(new Category('foobar', 'http://foo.com', 'Foobar'));
        $atom->addContributor(new Person('foobar', 'http://foo.com', '*****@*****.**'));
        $atom->setGenerator(new Generator('foobar', 'http://foo.com', '1.0'));
        $atom->setIcon('http://localhost.com/icon.png');
        $atom->setLogo('http://localhost.com/logo.png');
        $atom->setId('http://localhost.com#1');
        $atom->setRights('foo');
        $atom->setTitle('Foo has bar');
        $atom->setUpdated(new DateTime('Tue, 10 Jun 2003 04:00:00 GMT'));
        $atom->addLink(new Link('http://localhost.com', 'me', 'application/xml', 'en', 'Foobar', 1337));
        $atom->setSubTitle(new Text('And some more content'));
        $atom->add($entry);
        $content = <<<JSON
{
  "author": [{
    "name": "foobar",
    "uri": "http://foo.com",
    "email": "*****@*****.**"
  }],
  "category": [{
    "term": "foobar",
    "scheme": "http://foo.com",
    "label": "Foobar"
  }],
  "contributor": [{
    "name": "foobar",
    "uri": "http://foo.com",
    "email": "*****@*****.**"
  }],
  "generator": {
    "text": "foobar",
    "uri": "http://foo.com",
    "version": "1.0"
  },
  "icon": "http://localhost.com/icon.png",
  "logo": "http://localhost.com/logo.png",
  "id": "http://localhost.com#1",
  "link": [{
    "href": "http://localhost.com",
    "rel": "me",
    "type": "application/xml",
    "hreflang": "en",
    "title": "Foobar",
    "length": 1337
  }],
  "rights": "foo",
  "subTitle": {
  \t"content": "And some more content"
  },
  "title": "Foo has bar",
  "updated": "2003-06-10T04:00:00Z",
  "entry": [{
    "author": [{
      "name": "foobar",
      "uri": "http://foo.com",
      "email": "*****@*****.**"
    }],
    "category": [{
      "term": "foobar",
      "scheme": "http://foo.com",
      "label": "Foobar"
    }],
    "content": {
      "content": "foobar"
    },
    "contributor": [{
      "name": "foobar",
      "uri": "http://foo.com",
      "email": "*****@*****.**"
    }],
    "id": "http://localhost.com#1",
    "link": [{
      "href": "http://localhost.com",
      "rel": "me",
      "type": "application/xml",
      "hreflang": "en",
      "title": "Foobar",
      "length": 1337
    }],
    "published": "2003-06-10T04:00:00Z",
    "rights": "foo",
    "summary": {
      "content": "lreom ipsum"
    },
    "title": "Star City",
    "updated": "2003-06-10T04:00:00Z"
  }]
}
JSON;
        $this->assertRecordEqualsContent($atom, $content);
    }