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