]>
Commit | Line | Data |
---|---|---|
1f4408de NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\ImportBundle\Controller; | |
4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
1f4408de NL |
7 | |
8 | class PocketController extends Controller | |
9 | { | |
10 | /** | |
7019c7cf | 11 | * @Route("/pocket", name="import_pocket") |
1f4408de | 12 | */ |
d51b38ed | 13 | public function indexAction() |
1f4408de | 14 | { |
7019c7cf JB |
15 | return $this->render('WallabagImportBundle:Pocket:index.html.twig', [ |
16 | 'import' => $this->get('wallabag_import.pocket.import'), | |
17 | ]); | |
1f4408de NL |
18 | } |
19 | ||
1f4408de | 20 | /** |
7019c7cf | 21 | * @Route("/pocket/auth", name="import_pocket_auth") |
1f4408de NL |
22 | */ |
23 | public function authAction() | |
24 | { | |
252ebd60 JB |
25 | $requestToken = $this->get('wallabag_import.pocket.import') |
26 | ->getRequestToken($this->generateUrl('import', [], true)); | |
27 | ||
28 | $this->get('session')->set('import.pocket.code', $requestToken); | |
1f4408de | 29 | |
252ebd60 JB |
30 | return $this->redirect( |
31 | 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', [], true), | |
32 | 301 | |
33 | ); | |
1f4408de NL |
34 | } |
35 | ||
36 | /** | |
7019c7cf | 37 | * @Route("/pocket/callback", name="import_pocket_callback") |
1f4408de NL |
38 | */ |
39 | public function callbackAction() | |
40 | { | |
252ebd60 | 41 | $message = 'Import failed, please try again.'; |
0aa344dc | 42 | $pocket = $this->get('wallabag_import.pocket.import'); |
252ebd60 JB |
43 | |
44 | // something bad happend on pocket side | |
45 | if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) { | |
46 | $this->get('session')->getFlashBag()->add( | |
47 | 'notice', | |
48 | $message | |
49 | ); | |
50 | ||
51 | return $this->redirect($this->generateUrl('import_pocket')); | |
52 | } | |
53 | ||
54 | if (true === $pocket->import()) { | |
55 | $summary = $pocket->getSummary(); | |
b1d05721 | 56 | $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; |
252ebd60 JB |
57 | } |
58 | ||
59 | $this->get('session')->getFlashBag()->add( | |
60 | 'notice', | |
61 | $message | |
62 | ); | |
1f4408de NL |
63 | |
64 | return $this->redirect($this->generateUrl('homepage')); | |
65 | } | |
1f4408de | 66 | } |