3 namespace Wallabag\ImportBundle\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
6 use Symfony\Component\Routing\Generator\UrlGeneratorInterface
;
7 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
8 use Wallabag\ImportBundle\Import\PocketImport
;
9 use Symfony\Component\HttpFoundation\Request
;
10 use Symfony\Component\Form\Extension\Core\Type\CheckboxType
;
13 class PocketController
extends Controller
16 * @Route("/pocket", name="import_pocket")
18 public function indexAction()
20 $pocket = $this->get('wallabag_import.pocket.import');
21 $form = $this->createFormBuilder($pocket)
22 ->add('read', CheckboxType
::class, array(
23 'label' => 'Mark all as read',
29 return $this->render('WallabagImportBundle:Pocket:index.html.twig', [
30 'import' => $this->get('wallabag_import.pocket.import'),
31 'has_consumer_key' => '' == trim($this->get('craue_config')->get('pocket_consumer_key')) ? false : true,
32 'form' => $form->createView(),
37 * @Route("/pocket/auth", name="import_pocket_auth")
39 public function authAction(Request
$request)
41 $requestToken = $this->get('wallabag_import.pocket.import')
42 ->getRequestToken($this->generateUrl('import', array(), UrlGeneratorInterface
::ABSOLUTE_URL
));
44 $this->get('session')->set('import.pocket.code', $requestToken);
45 $markAsRead = $request->request
->get('form')['read'];
46 $this->get('session')->set('read', $markAsRead);
48 return $this->redirect(
49 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', array(), UrlGeneratorInterface
::ABSOLUTE_URL
),
55 * @Route("/pocket/callback", name="import_pocket_callback")
57 public function callbackAction()
59 $message = 'Import failed, please try again.';
60 $pocket = $this->get('wallabag_import.pocket.import');
61 $markAsRead = $this->get('session')->get('read');
63 // something bad happend on pocket side
64 if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) {
65 $this->get('session')->getFlashBag()->add(
70 return $this->redirect($this->generateUrl('import_pocket'));
73 if (true === $pocket->setMarkAsRead($markAsRead)->import()) {
74 $summary = $pocket->getSummary();
75 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
78 $this->get('session')->remove('read');
80 $this->get('session')->getFlashBag()->add(
85 return $this->redirect($this->generateUrl('homepage'));