Ejemplo n.º 1
0
 protected function getFirstAuthor(Atom\Entry $entry)
 {
     $authors = $entry->getAuthor();
     if (!empty($authors)) {
         return current($authors);
     }
     return null;
 }
Ejemplo n.º 2
0
 private function insertEntry(Entry $entry)
 {
     // get global id
     $urn = new Urn($entry->id);
     $globalId = $urn->getNss();
     // get author of the entry
     $author = current($entry->author);
     if (!empty($author)) {
         $urn = new Urn($author['uri']);
         $con = new Condition();
         $con->add('globalId', '=', $urn->getNss());
         $con->add('name', '=', $author['name']);
         $userId = $this->sql->select($this->registry['table.user_account'], array('id'), $con, Sql::SELECT_FIELD);
         $user = new User($userId, $this->registry);
         $handler = new Handler($user);
     } else {
         throw new Exception('No author set');
     }
     // get threading extension
     $thread = $entry->getElement()->getElementsByTagNameNS('http://purl.org/syndication/thread/1.0', 'in-reply-to');
     $refId = 0;
     if ($thread->length > 0) {
         // search for referenced activity globalId
         $ref = $thread->item(0)->getAttribute('ref');
         $urn = new Urn($ref);
         $con = new Condition(array('globalId', '=', $urn->getNss()));
         $refId = $this->hm->getTable('AmunService\\User\\Activity')->getField('id', $con);
         if (empty($refId)) {
             throw new Exception('Invalid referenced id');
         }
     }
     $activity = $this->hm->getTable('AmunService\\User\\Activity')->getRecord();
     $activity->globalId = $globalId;
     $activity->parentId = $refId;
     $activity->table = 'amun_user_activity';
     $activity->verb = 'add';
     $activity->summary = $entry->content;
     $activity->date = $entry->updated->format(DateTime::SQL);
     $handler->create($activity);
 }
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);
    }
Ejemplo n.º 5
0
 public function callback(Entry $entry)
 {
     $dom = $entry->getDom();
     $verb = $dom->getElementsByTagNameNS('http://activitystrea.ms/spec/1.0/', 'verb')->item(0);
     if ($verb instanceof DOMElement) {
         $activity = $this->hm->getTable('AmunService\\User\\Activity')->getRecord();
         $activity->setVerb($verb->nodeValue);
         $activity->setSummary($entry->content);
         $activity->table = 'amun_user_activity';
         return $this->create($activity);
     } else {
         throw new Exception('Verb not set');
     }
 }