Example #1
0
 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]);
 }
Example #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;
 }
 /**
  * {@inheritDoc}
  */
 public function setAuthorEmail($authorEmail)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setAuthorEmail', array($authorEmail));
     return parent::setAuthorEmail($authorEmail);
 }
 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);
 }
Example #5
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;
 }