public function createFeedEntryAction(Request $request)
 {
     $feed = $this->getFeedRepository()->find($request->request->get('feed_id'));
     if (null === $feed) {
         $this->app->abort(404, "Feed not found");
     }
     $user = $this->getAuthenticatedUser();
     $publisher = $this->getFeedPublisherRepository()->findOneBy(['feed' => $feed, 'user' => $user]);
     if ('' === ($title = trim($request->request->get('title', '')))) {
         $this->app->abort(400, "Bad request");
     }
     if (!$feed->isPublisher($user)) {
         $this->app->abort(403, 'Unauthorized action');
     }
     $entry = new FeedEntry();
     $entry->setAuthorEmail($request->request->get('author_mail'))->setAuthorName($request->request->get('author_name'))->setTitle($title)->setFeed($feed)->setPublisher($publisher)->setSubtitle($request->request->get('subtitle', ''));
     $feed->addEntry($entry);
     $publishing = RecordsRequest::fromRequest($this->app, $request, true, [], ['bas_chupub']);
     $manager = $this->getEntityManager();
     foreach ($publishing as $record) {
         $item = new FeedItem();
         $item->setEntry($entry)->setRecordId($record->get_record_id())->setSbasId($record->get_sbas_id());
         $entry->addItem($item);
         $manager->persist($item);
     }
     $manager->persist($entry);
     $manager->persist($feed);
     $manager->flush();
     $this->dispatch(PhraseaEvents::FEED_ENTRY_CREATE, new FeedEntryEvent($entry, $request->request->get('notify')));
     return $this->app->json(['error' => false, 'message' => false]);
 }
Beispiel #2
0
 public function connect(Application $app)
 {
     $app['controller.prod.feed'] = $this;
     $controllers = $app['controllers_factory'];
     $app['firewall']->addMandatoryAuthentication($controllers);
     $controllers->post('/requestavailable/', function (Application $app, Request $request) {
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $publishing = RecordsRequest::fromRequest($app, $request, true, [], ['bas_chupub']);
         return $app['twig']->render('prod/actions/publish/publish.html.twig', ['publishing' => $publishing, 'feeds' => $feeds]);
     });
     $controllers->post('/entry/create/', function (Application $app, Request $request) {
         $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($request->request->get('feed_id'));
         if (null === $feed) {
             $app->abort(404, "Feed not found");
         }
         $publisher = $app['EM']->getRepository('Phraseanet:FeedPublisher')->findOneBy(['feed' => $feed, 'user' => $app['authentication']->getUser()]);
         if ('' === ($title = trim($request->request->get('title', '')))) {
             $app->abort(400, "Bad request");
         }
         if (!$feed->isPublisher($app['authentication']->getUser())) {
             $app->abort(403, 'Unathorized action');
         }
         $entry = new FeedEntry();
         $entry->setAuthorEmail($request->request->get('author_mail'))->setAuthorName($request->request->get('author_name'))->setTitle($title)->setFeed($feed)->setPublisher($publisher)->setSubtitle($request->request->get('subtitle', ''));
         $feed->addEntry($entry);
         $publishing = RecordsRequest::fromRequest($app, $request, true, [], ['bas_chupub']);
         foreach ($publishing as $record) {
             $item = new FeedItem();
             $item->setEntry($entry)->setRecordId($record->get_record_id())->setSbasId($record->get_sbas_id());
             $entry->addItem($item);
             $app['EM']->persist($item);
         }
         $app['EM']->persist($entry);
         $app['EM']->persist($feed);
         $app['EM']->flush();
         $app['events-manager']->trigger('__FEED_ENTRY_CREATE__', ['entry_id' => $entry->getId(), 'notify_email' => (bool) $request->request->get('notify')], $entry);
         $datas = ['error' => false, 'message' => false];
         return $app->json($datas);
     })->bind('prod_feeds_entry_create')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->get('/entry/{id}/edit/', function (Application $app, Request $request, $id) {
         $entry = $app['EM']->getRepository('Phraseanet:FeedEntry')->find($id);
         if (!$entry->isPublisher($app['authentication']->getUser())) {
             throw new AccessDeniedHttpException();
         }
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', ['entry' => $entry, 'feeds' => $feeds]);
         return new Response($datas);
     })->bind('feed_entry_edit')->assert('id', '\\d+')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->post('/entry/{id}/update/', function (Application $app, Request $request, $id) {
         $datas = ['error' => true, 'message' => '', 'datas' => ''];
         $entry = $app['EM']->getRepository('Phraseanet:FeedEntry')->find($id);
         if (null === $entry) {
             $app->abort(404, 'Entry not found');
         }
         if (!$entry->isPublisher($app['authentication']->getUser())) {
             $app->abort(403, 'Unathorized action');
         }
         if ('' === ($title = trim($request->request->get('title', '')))) {
             $app->abort(400, "Bad request");
         }
         $entry->setAuthorEmail($request->request->get('author_mail'))->setAuthorName($request->request->get('author_name'))->setTitle($title)->setSubtitle($request->request->get('subtitle', ''));
         $currentFeedId = $entry->getFeed()->getId();
         $new_feed_id = $request->request->get('feed_id', $currentFeedId);
         if ($currentFeedId !== (int) $new_feed_id) {
             $new_feed = $app['EM']->getRepository('Phraseanet:Feed')->find($new_feed_id);
             if ($new_feed === null) {
                 $app->abort(404, 'Feed not found');
             }
             if (!$new_feed->isPublisher($app['authentication']->getUser())) {
                 $app->abort(403, 'You are not publisher of this feed');
             }
             $entry->setFeed($new_feed);
         }
         $items = explode(';', $request->request->get('sorted_lst'));
         foreach ($items as $item_sort) {
             $item_sort_datas = explode('_', $item_sort);
             if (count($item_sort_datas) != 2) {
                 continue;
             }
             $item = $app['EM']->getRepository('Phraseanet:FeedItem')->find($item_sort_datas[0]);
             $item->setOrd($item_sort_datas[1]);
             $app['EM']->persist($item);
         }
         $app['EM']->persist($entry);
         $app['EM']->flush();
         return $app->json(['error' => false, 'message' => 'succes', 'datas' => $app['twig']->render('prod/feeds/entry.html.twig', ['entry' => $entry])]);
     })->bind('prod_feeds_entry_update')->assert('id', '\\d+')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->post('/entry/{id}/delete/', function (Application $app, Request $request, $id) {
         $datas = ['error' => true, 'message' => ''];
         $entry = $app['EM']->getRepository('Phraseanet:FeedEntry')->find($id);
         if (null === $entry) {
             $app->abort(404, 'Entry not found');
         }
         if (!$entry->isPublisher($app['authentication']->getUser()) && $entry->getFeed()->isOwner($app['authentication']->getUser()) === false) {
             $app->abort(403, $app->trans('Action Forbidden : You are not the publisher'));
         }
         $app['EM']->remove($entry);
         $app['EM']->flush();
         return $app->json(['error' => false, 'message' => 'succes']);
     })->bind('prod_feeds_entry_delete')->assert('id', '\\d+')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->get('/', function (Application $app, Request $request) {
         $request = $app['request'];
         $page = (int) $request->query->get('page');
         $page = $page > 0 ? $page : 1;
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $datas = $app['twig']->render('prod/feeds/feeds.html.twig', ['feeds' => $feeds, 'feed' => new Aggregate($app['EM'], $feeds), 'page' => $page]);
         return new Response($datas);
     })->bind('prod_feeds');
     $controllers->get('/feed/{id}/', function (Application $app, Request $request, $id) {
         $page = (int) $request->query->get('page');
         $page = $page > 0 ? $page : 1;
         $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id);
         if (!$feed->isAccessible($app['authentication']->getUser(), $app)) {
             $app->abort(404, 'Feed not found');
         }
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $datas = $app['twig']->render('prod/feeds/feeds.html.twig', ['feed' => $feed, 'feeds' => $feeds, 'page' => $page]);
         return new Response($datas);
     })->bind('prod_feeds_feed')->assert('id', '\\d+');
     $controllers->get('/subscribe/aggregated/', function (Application $app, Request $request) {
         $renew = $request->query->get('renew') === 'true';
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $link = $app['feed.aggregate-link-generator']->generate(new Aggregate($app['EM'], $feeds), $app['authentication']->getUser(), AggregateLinkGenerator::FORMAT_RSS, null, $renew);
         $output = ['texte' => '<p>' . $app->trans('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.') . '</p><p>' . $app->trans('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
         <div><input type="text" readonly="readonly" class="input_select_copy" value="' . $link->getURI() . '"/></div>', 'titre' => $app->trans('publications::votre rss personnel')];
         return $app->json($output);
     })->bind('prod_feeds_subscribe_aggregated');
     $controllers->get('/subscribe/{id}/', function (Application $app, Request $request, $id) {
         $renew = $request->query->get('renew') === 'true';
         $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id);
         if (!$feed->isAccessible($app['authentication']->getUser(), $app)) {
             $app->abort(404, 'Feed not found');
         }
         $link = $app['feed.user-link-generator']->generate($feed, $app['authentication']->getUser(), FeedLinkGenerator::FORMAT_RSS, null, $renew);
         $output = ['texte' => '<p>' . $app->trans('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.') . '</p><p>' . $app->trans('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
         <div><input type="text" style="width:100%" value="' . $link->getURI() . '"/></div>', 'titre' => $app->trans('publications::votre rss personnel')];
         return $app->json($output);
     })->bind('prod_feeds_subscribe_feed')->assert('id', '\\d+');
     return $controllers;
 }
 protected function addItem(Application $app, \DOMDocument $document, \DOMNode $feed, FeedEntry $entry)
 {
     foreach ($entry->getItems() as $content) {
         $this->addContent($app, $document, $feed, $content);
     }
 }
Beispiel #4
0
 public function checkATOMEntryNode(\DOMNode $node, \DOMXPath $xpath, Feed $feed, FeedEntry $entry)
 {
     foreach ($node->childNodes as $child) {
         if ($child->nodeType !== XML_TEXT_NODE) {
             switch ($child->nodeName) {
                 case 'id':
                     $this->assertEquals(sprintf('%sentry/%d/', self::$DI['app']['feed.user-link-generator']->generatePublic($feed, 'atom', 1)->getURI(), $entry->getId()), $child->nodeValue);
                     break;
                 case 'link':
                     foreach ($child->attributes as $attribute) {
                         if ($attribute->name == "href") {
                             $this->assertEquals(sprintf('%sentry/%d/', self::$DI['app']['feed.user-link-generator']->generatePublic($feed, 'atom', 1)->getURI(), $entry->getId()), $attribute->value);
                             break;
                         }
                     }
                     break;
                 case 'updated':
                     $this->assertEquals($entry->getUpdatedOn()->format(DATE_ATOM), $child->nodeValue);
                     break;
                 case 'published':
                     $this->assertEquals($entry->getCreatedOn()->format(DATE_ATOM), $child->nodeValue);
                     break;
                 case 'title':
                     $this->assertEquals($entry->getTitle(), $child->nodeValue);
                     break;
                 case 'content':
                     $this->assertEquals($entry->getSubtitle(), $child->nodeValue);
                     break;
                 case 'author':
                     foreach ($node->childNodes as $child) {
                         if ($child->nodeType !== XML_TEXT_NODE && $child->nodeName == "email") {
                             $this->assertEquals($entry->getAuthorEmail(), $child->nodeValue);
                         }
                         if ($child->nodeType !== XML_TEXT_NODE && $child->nodeName == "name") {
                             $this->assertEquals($entry->getAuthorName(), $child->nodeValue);
                         }
                     }
                     break;
             }
         }
     }
     $content = $entry->getItems()->toArray();
     $available_medium = ['image', 'audio', 'video'];
     array_walk($content, $this->removeBadItems($content, $available_medium));
     $media_group = $xpath->query("/Atom:feed/Atom:entry[0]/media:group");
     if ($media_group->length > 0) {
         foreach ($media_group as $media) {
             $entry_item = array_shift($content);
             if ($entry_item instanceof FeedEntry) {
                 $this->verifyMediaItem($entry_item, $media);
             }
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getItem($id)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getItem', array($id));
     return parent::getItem($id);
 }
 private function insertOneFeedEntry(EntityManager $em, \Pimple $DI, Feed $feed, $public)
 {
     $entry = new FeedEntry();
     $entry->setFeed($feed);
     $entry->setTitle("test");
     $entry->setSubtitle("description");
     $entry->setAuthorName('user');
     $entry->setAuthorEmail('*****@*****.**');
     $publisher = $feed->getPublisher($DI['user']);
     if ($publisher !== null) {
         $entry->setPublisher($publisher);
     }
     $feed->addEntry($entry);
     $em->persist($entry);
     $em->persist($feed);
     $this->insertOneFeedItem($em, $DI, $entry, $public);
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     if (false === $this->hasFeedBackup($app)) {
         return false;
     }
     $sql = 'DELETE FROM Feeds';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM FeedEntries';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM FeedPublishers';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM FeedItems';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM FeedTokens';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM AggregateTokens';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $conn = $app->getApplicationBox()->get_connection();
     $sql = 'SELECT id, title, subtitle, public, created_on, updated_on, base_id FROM feeds_backup;';
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $n = 0;
     $em = $app['orm.em'];
     $fpSql = 'SELECT id, usr_id, owner, created_on FROM feed_publishers WHERE feed_id = :feed_id;';
     $fpStmt = $conn->prepare($fpSql);
     $feSql = 'SELECT id, title, description, created_on, updated_on, author_name, author_email FROM feed_entries WHERE feed_id = :feed_id AND publisher = :publisher_id;';
     $feStmt = $conn->prepare($feSql);
     $fiSql = 'SELECT sbas_id, record_id, ord FROM feed_entry_elements WHERE entry_id = :entry_id;';
     $fiStmt = $conn->prepare($fiSql);
     $ftSql = 'SELECT token, usr_id, aggregated FROM feed_tokens WHERE feed_id = :feed_id;';
     $ftStmt = $conn->prepare($ftSql);
     $faSql = 'SELECT token, usr_id FROM feed_tokens WHERE aggregated = 1;';
     $faStmt = $conn->prepare($faSql);
     foreach ($rs as $row) {
         $feed = new Feed();
         $feed->setTitle($row['title']);
         $feed->setSubtitle($row['subtitle']);
         $feed->setIconUrl(false);
         $feed->setIsPublic($row['public']);
         $feed->setCreatedOn(new \DateTime($row['created_on']));
         $feed->setUpdatedOn(new \DateTime($row['updated_on']));
         $feed->setBaseId($row['base_id']);
         $fpStmt->execute([':feed_id' => $row['id']]);
         $fpRes = $fpStmt->fetchAll(\PDO::FETCH_ASSOC);
         foreach ($fpRes as $fpRow) {
             if (null === ($user = $this->loadUser($app['orm.em'], $fpRow['usr_id']))) {
                 continue;
             }
             $feedPublisher = new FeedPublisher();
             $feedPublisher->setFeed($feed);
             $feed->addPublisher($feedPublisher);
             $feedPublisher->setCreatedOn(new \DateTime($fpRow['created_on']));
             $feedPublisher->setIsOwner((bool) $fpRow['owner']);
             $feedPublisher->setUser($user);
             $feStmt->execute([':feed_id' => $row['id'], ':publisher_id' => $fpRow['id']]);
             $feRes = $feStmt->fetchAll(\PDO::FETCH_ASSOC);
             foreach ($feRes as $feRow) {
                 $feedEntry = new FeedEntry();
                 $feedEntry->setFeed($feed);
                 $feed->addEntry($feedEntry);
                 $feedEntry->setPublisher($feedPublisher);
                 $feedEntry->setTitle($feRow['title']);
                 $feedEntry->setSubtitle($feRow['description']);
                 $feedEntry->setAuthorName((string) $feRow['author_name']);
                 $feedEntry->setAuthorEmail((string) $feRow['author_email']);
                 $feedEntry->setCreatedOn(new \DateTime($feRow['created_on']));
                 $feedEntry->setUpdatedOn(new \DateTime($feRow['updated_on']));
                 $fiStmt->execute([':entry_id' => $feRow['id']]);
                 $fiRes = $fiStmt->fetchAll(\PDO::FETCH_ASSOC);
                 foreach ($fiRes as $fiRow) {
                     $feedItem = new FeedItem();
                     $feedItem->setEntry($feedEntry);
                     $feedEntry->addItem($feedItem);
                     $feedItem->setOrd($fiRow['ord']);
                     $feedItem->setSbasId($fiRow['sbas_id']);
                     $feedItem->setRecordId($fiRow['record_id']);
                     $em->persist($feedItem);
                 }
                 $em->persist($feedEntry);
             }
             $em->persist($feedPublisher);
         }
         $ftStmt->execute([':feed_id' => $row['id']]);
         $ftRes = $ftStmt->fetchAll(\PDO::FETCH_ASSOC);
         foreach ($ftRes as $ftRow) {
             if (null === ($user = $this->loadUser($app['orm.em'], $ftRow['usr_id']))) {
                 continue;
             }
             $token = new FeedToken();
             $token->setFeed($feed);
             $feed->addToken($token);
             $token->setUser($user);
             $token->setValue($ftRow['token']);
             $em->persist($token);
         }
         $em->persist($feed);
         $n++;
         if ($n % 100 === 0) {
             $em->flush();
             $em->clear();
         }
     }
     $fiStmt->closeCursor();
     $feStmt->closeCursor();
     $fpStmt->closeCursor();
     $ftStmt->closeCursor();
     $faStmt->execute();
     $faRes = $faStmt->fetchAll(\PDO::FETCH_ASSOC);
     foreach ($faRes as $faRow) {
         if (null === ($user = $this->loadUser($app['orm.em'], $faRow['usr_id']))) {
             continue;
         }
         $token = new AggregateToken();
         $token->setUser($user);
         $token->setValue($faRow['token']);
         $em->persist($token);
     }
     $faStmt->closeCursor();
     $em->flush();
     $em->clear();
     return true;
 }
Beispiel #8
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     try {
         $sql = 'ALTER TABLE `ssel` ADD `migrated` INT NOT NULL DEFAULT "0"';
         $stmt = $appbox->get_connection()->prepare($sql);
         $stmt->execute();
         $stmt->closeCursor();
     } catch (\Exception $e) {
     }
     $sql = 'SELECT ssel_id, usr_id, name, descript, pub_date, updater, pub_restrict, homelink
             FROM ssel
             WHERE (public = "1" OR homelink="1")
               AND migrated = 0';
     $stmt = $appbox->get_connection()->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $date_ref = new DateTime();
     $n = 0;
     $app['orm.em']->getEventManager()->removeEventSubscriber(new TimestampableListener());
     foreach ($rs as $row) {
         if (null === ($user = $this->loadUser($app['orm.em'], $row['usr_id']))) {
             continue;
         }
         $feed = $this->get_feed($app, $appbox, $user, $row['pub_restrict'], $row['homelink']);
         if (!$feed instanceof Feed) {
             continue;
         }
         $publishers = $feed->getPublishers();
         $entry = new FeedEntry();
         $entry->setAuthorEmail((string) $user->getEmail());
         $entry->setAuthorName((string) $user->getDisplayName());
         $entry->setFeed($feed);
         $entry->setPublisher($publishers->first());
         $entry->setTitle($row['name']);
         $entry->setSubtitle($row['descript']);
         $feed->addEntry($entry);
         $date_create = new DateTime($row['pub_date']);
         if ($date_create < $date_ref) {
             $date_ref = $date_create;
         }
         $entry->setCreatedOn($date_create);
         if ($row['updater'] != '0000-00-00 00:00:00') {
             $date_update = new DateTime($row['updater']);
             $entry->setUpdatedOn($date_update);
         }
         $sql = 'SELECT sselcont_id, ssel_id, base_id, record_id
                 FROM sselcont
                 WHERE ssel_id = :ssel_id
                 ORDER BY ord ASC';
         $stmt = $appbox->get_connection()->prepare($sql);
         $stmt->execute([':ssel_id' => $row['ssel_id']]);
         $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
         $stmt->closeCursor();
         foreach ($rs as $row) {
             try {
                 $record = new record_adapter($app, phrasea::sbasFromBas($app, $row['base_id']), $row['record_id']);
                 $item = new FeedItem();
                 $item->setEntry($entry);
                 $entry->addItem($item);
                 $item->setRecordId($record->get_record_id());
                 $item->setSbasId($record->get_sbas_id());
                 $app['orm.em']->persist($item);
             } catch (NotFoundHttpException $e) {
             }
         }
         $app['orm.em']->persist($entry);
         $sql = 'UPDATE ssel SET deleted = "1", migrated="1"
                 WHERE ssel_id = :ssel_id';
         $stmt = $appbox->get_connection()->prepare($sql);
         $stmt->execute([':ssel_id' => $row['ssel_id']]);
         $stmt->closeCursor();
         $app['orm.em']->persist($feed);
         $n++;
         if ($n % 1000 == 0) {
             $app['orm.em']->flush();
             $app['orm.em']->clear();
         }
     }
     $this->set_feed_dates($date_ref);
     $app['orm.em']->flush();
     $app['orm.em']->clear();
     $app['orm.em']->getEventManager()->removeEventSubscriber(new TimestampableListener());
     return true;
 }
 /**
  * @param User      $user
  * @param FeedEntry $entry
  *
  * @return Token
  */
 public function createFeedEntryToken(User $user, FeedEntry $entry)
 {
     return $this->create($user, self::TYPE_FEED_ENTRY, null, $entry->getId());
 }
Beispiel #10
0
 protected function addItem(Application $app, \DOMDocument $document, \DOMNode $node, FeedEntry $entry)
 {
     $item = $this->addTag($document, $node, 'item');
     $feed = $entry->getFeed();
     if ($feed->isPublic()) {
         $link = $app['feed.link-generator-collection']->generatePublic($feed, FeedLinkGenerator::FORMAT_RSS);
     } else {
         $link = $app['feed.link-generator-collection']->generate($feed, $app['authentication']->getUser(), FeedLinkGenerator::FORMAT_RSS);
     }
     $this->addTag($document, $item, 'title', $entry->getTitle());
     $this->addTag($document, $item, 'description', $entry->getSubtitle());
     $author = sprintf('%s (%s)', $entry->getAuthorEmail(), $entry->getAuthorName());
     $created_on = $entry->getCreatedOn()->format(DATE_RFC2822);
     $this->addTag($document, $item, 'author', $author);
     $this->addTag($document, $item, 'pubDate', $created_on);
     $this->addTag($document, $item, 'guid', $link->getURI());
     $this->addTag($document, $item, 'link', $link->getURI());
     /**
      *  Missing :
      *
      *  category  Includes the item in one or more categories. More.
      *  comments  URL of a page for comments relating to the item. More.
      *  enclosure  Describes a media object that is attached to the item. More.
      *  source    The RSS channel that the item came from. More.
      *
      */
     foreach ($entry->getItems() as $content) {
         $this->addContent($app, $document, $item, $content);
     }
     return $item;
 }
Beispiel #11
0
 /**
  * Retrieve detailled information about one feed entry
  *
  * @param  FeedEntry $entry
  *
  * @return array
  */
 private function list_publication_entry(Application $app, FeedEntry $entry)
 {
     $items = array_map(function ($item) use($app) {
         return $this->list_publication_entry_item($app, $item);
     }, iterator_to_array($entry->getItems()));
     return ['id' => $entry->getId(), 'author_email' => $entry->getAuthorEmail(), 'author_name' => $entry->getAuthorName(), 'created_on' => $entry->getCreatedOn()->format(DATE_ATOM), 'updated_on' => $entry->getUpdatedOn()->format(DATE_ATOM), 'title' => $entry->getTitle(), 'subtitle' => $entry->getSubtitle(), 'items' => $items, 'feed_id' => $entry->getFeed()->getId(), 'feed_title' => $entry->getFeed()->getTitle(), 'feed_url' => '/feeds/' . $entry->getFeed()->getId() . '/content/', 'url' => '/feeds/entry/' . $entry->getId() . '/'];
 }
Beispiel #12
0
 /**
  * Retrieve detailled information about one feed entry
  *
  * @param  FeedEntry $entry
  * @return array
  */
 protected function list_publication_entry(FeedEntry $entry)
 {
     $items = [];
     foreach ($entry->getItems() as $item) {
         $items[] = $this->list_publication_entry_item($item);
     }
     return ['id' => $entry->getId(), 'author_email' => $entry->getAuthorEmail(), 'author_name' => $entry->getAuthorName(), 'created_on' => $entry->getCreatedOn()->format(DATE_ATOM), 'updated_on' => $entry->getUpdatedOn()->format(DATE_ATOM), 'title' => $entry->getTitle(), 'subtitle' => $entry->getSubtitle(), 'items' => $items, 'feed_id' => $entry->getFeed()->getId(), 'feed_url' => '/feeds/' . $entry->getFeed()->getId() . '/content/', 'url' => '/feeds/entry/' . $entry->getId() . '/'];
 }
Beispiel #13
0
 protected function addItem(Application $app, \DOMDocument $document, \DOMNode $feed, FeedEntry $entry, FeedLink $link)
 {
     $entry_node = $this->addTag($document, $feed, 'entry');
     $link = sprintf('%sentry/%d/', $link->getURI(), $entry->getId());
     $this->addTag($document, $entry_node, 'id', $link);
     $link_tag = $this->addTag($document, $entry_node, 'link');
     $link_tag->setAttribute('rel', 'self');
     $link_tag->setAttribute('href', $link);
     $updated_on = $entry->getUpdatedOn()->format(DATE_ATOM);
     $created_on = $entry->getCreatedOn()->format(DATE_ATOM);
     $this->addTag($document, $entry_node, 'updated', $updated_on);
     $this->addTag($document, $entry_node, 'published', $created_on);
     $this->addTag($document, $entry_node, 'title', $entry->getTitle());
     $author = $this->addTag($document, $entry_node, 'author');
     if ($entry->getAuthorEmail()) {
         $this->addTag($document, $author, 'email', $entry->getAuthorEmail());
     }
     if ($entry->getAuthorName()) {
         $this->addTag($document, $author, 'name', $entry->getAuthorName());
     }
     $this->addTag($document, $entry_node, 'content', $entry->getSubtitle());
     foreach ($entry->getItems() as $content) {
         $this->addContent($app, $document, $entry_node, $content);
     }
     return $entry_node;
 }