aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2015-10-07 18:08:51 +0200
committerNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2015-10-08 13:29:41 +0200
commit880a0e1c0ba7d0ab3320678b076402379a08c8a2 (patch)
tree2d3d53811a7988974543fc61c70e55ac70e9be5b /src/Wallabag
parent3bfbd22f13e778c6b9713cde0cdf5b7b824f1ff2 (diff)
downloadwallabag-880a0e1c0ba7d0ab3320678b076402379a08c8a2.tar.gz
wallabag-880a0e1c0ba7d0ab3320678b076402379a08c8a2.tar.zst
wallabag-880a0e1c0ba7d0ab3320678b076402379a08c8a2.zip
implement bookmarklet
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php40
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/_bookmarklet.html.twig1
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Static/howto.html.twig4
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig1
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Static/howto.html.twig3
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php25
6 files changed, 65 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index a9f35c36..f7b52eaf 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -15,6 +15,23 @@ use Pagerfanta\Pagerfanta;
15class EntryController extends Controller 15class EntryController extends Controller
16{ 16{
17 /** 17 /**
18 * @param Entry $entry
19 */
20 private function updateEntry(Entry $entry)
21 {
22 try {
23 $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
24 $em = $this->getDoctrine()->getManager();
25 $em->persist($entry);
26 $em->flush();
27 } catch (\Exception $e) {
28 return false;
29 }
30
31 return true;
32 }
33
34 /**
18 * @param Request $request 35 * @param Request $request
19 * 36 *
20 * @Route("/new-entry", name="new_entry") 37 * @Route("/new-entry", name="new_entry")
@@ -30,12 +47,7 @@ class EntryController extends Controller
30 $form->handleRequest($request); 47 $form->handleRequest($request);
31 48
32 if ($form->isValid()) { 49 if ($form->isValid()) {
33 $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); 50 $this->updateEntry($entry);
34
35 $em = $this->getDoctrine()->getManager();
36 $em->persist($entry);
37 $em->flush();
38
39 $this->get('session')->getFlashBag()->add( 51 $this->get('session')->getFlashBag()->add(
40 'notice', 52 'notice',
41 'Entry saved' 53 'Entry saved'
@@ -52,6 +64,22 @@ class EntryController extends Controller
52 /** 64 /**
53 * @param Request $request 65 * @param Request $request
54 * 66 *
67 * @Route("/bookmarklet", name="bookmarklet")
68 *
69 * @return \Symfony\Component\HttpFoundation\Response
70 */
71 public function addEntryViaBookmarklet(Request $request)
72 {
73 $entry = new Entry($this->getUser());
74 $entry->setUrl($request->get('url'));
75 $this->updateEntry($entry);
76
77 return $this->redirect($this->generateUrl('homepage'));
78 }
79
80 /**
81 * @param Request $request
82 *
55 * @Route("/new", name="new") 83 * @Route("/new", name="new")
56 * 84 *
57 * @return \Symfony\Component\HttpFoundation\Response 85 * @return \Symfony\Component\HttpFoundation\Response
diff --git a/src/Wallabag/CoreBundle/Resources/views/_bookmarklet.html.twig b/src/Wallabag/CoreBundle/Resources/views/_bookmarklet.html.twig
new file mode 100644
index 00000000..c8fb5612
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Resources/views/_bookmarklet.html.twig
@@ -0,0 +1 @@
<a id="bookmarklet" ondragend="this.click();" href="javascript:var url=location.href||url;var wllbg=window.open('{{ url('bookmarklet') }}?url=' + encodeURI(url),'_blank');wllbg.close();void(0);">{% trans %}bag it!{% endtrans %}</a>
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Static/howto.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Static/howto.html.twig
index 58cb316b..6a320692 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Static/howto.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Static/howto.html.twig
@@ -22,7 +22,7 @@
22 </ul> 22 </ul>
23 <h3>{% trans %}Bookmarklet{% endtrans %}</h3> 23 <h3>{% trans %}Bookmarklet{% endtrans %}</h3>
24 <p> 24 <p>
25 {% trans %}Drag &amp; drop this link to your bookmarks bar:{% endtrans %} {% trans %}bag it!{% endtrans %} 25 {% trans %}Drag &amp; drop this link to your bookmarks bar:{% endtrans %}
26 </p> 26 {% include 'WallabagCoreBundle::_bookmarklet.html.twig' %}
27 27
28{% endblock %} 28{% endblock %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig
index de4ed2e7..26de7943 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig
@@ -51,6 +51,7 @@
51 </div> 51 </div>
52 </li> 52 </li>
53 <li><a href="{{ path('config') }}">{% trans %}config{% endtrans %}</a></li> 53 <li><a href="{{ path('config') }}">{% trans %}config{% endtrans %}</a></li>
54 <li><a href="{{ path('howto') }}">{% trans %}howto{% endtrans %}</a></li>
54 <li><a href="{{ path('about') }}">{% trans %}about{% endtrans %}</a></li> 55 <li><a href="{{ path('about') }}">{% trans %}about{% endtrans %}</a></li>
55 <li><a class="icon icon-power" href="{{ path('fos_user_security_logout') }}" title="{% trans %}logout{% endtrans %}">{% trans %}logout{% endtrans %}</a></li> 56 <li><a class="icon icon-power" href="{{ path('fos_user_security_logout') }}" title="{% trans %}logout{% endtrans %}">{% trans %}logout{% endtrans %}</a></li>
56 </ul> 57 </ul>
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Static/howto.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Static/howto.html.twig
index 78591172..63b51aaa 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Static/howto.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Static/howto.html.twig
@@ -42,7 +42,8 @@
42 42
43 43
44 <div id="set4" class="col s12"> 44 <div id="set4" class="col s12">
45 {% trans %}Drag &amp; drop this link to your bookmarks bar:{% endtrans %} {% trans %}bag it!{% endtrans %} 45 {% trans %}Drag &amp; drop this link to your bookmarks bar:{% endtrans %}
46 {% include 'WallabagCoreBundle::_bookmarklet.html.twig' %}
46 </div> 47 </div>
47 48
48 </div> 49 </div>
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
index 2862417e..5ac39d12 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
@@ -31,6 +31,31 @@ class EntryControllerTest extends WallabagCoreTestCase
31 $this->assertCount(1, $crawler->filter('button[type=submit]')); 31 $this->assertCount(1, $crawler->filter('button[type=submit]'));
32 } 32 }
33 33
34 public function testPostNewViaBookmarklet()
35 {
36 $this->logInAs('admin');
37 $client = $this->getClient();
38
39 $crawler = $client->request('GET', '/');
40
41 $this->assertCount(4, $crawler->filter('div[class=entry]'));
42
43 // Good URL
44 $crawler = $client->request('GET', '/bookmarklet', array('url' => $this->url));
45 $this->assertEquals(302, $client->getResponse()->getStatusCode());
46 $crawler = $client->followRedirect();
47 $crawler = $client->request('GET', '/');
48 $this->assertCount(5, $crawler->filter('div[class=entry]'));
49
50 $em = $client->getContainer()
51 ->get('doctrine.orm.entity_manager');
52 $entry = $em
53 ->getRepository('WallabagCoreBundle:Entry')
54 ->findOneByUrl($this->url);
55 $em->remove($entry);
56 $em->flush();
57 }
58
34 public function testPostNewEmpty() 59 public function testPostNewEmpty()
35 { 60 {
36 $this->logInAs('admin'); 61 $this->logInAs('admin');