X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FEntryController.php;h=6769799b7f35e2f6693311fac517d4e4f1d723bd;hb=18d5f4541e1b3eea9926497e082724807453fc8c;hp=e6580a579b6821992c6207f078af5991fa548d53;hpb=d13de40db6fe5a006eb050908450b7adf3fcbf6c;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index e6580a57..6769799b 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -14,6 +14,23 @@ use Pagerfanta\Pagerfanta; class EntryController extends Controller { + /** + * @param Entry $entry + */ + private function updateEntry(Entry $entry) + { + try { + $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + } catch (\Exception $e) { + return false; + } + + return true; + } + /** * @param Request $request * @@ -30,20 +47,7 @@ class EntryController extends Controller $form->handleRequest($request); if ($form->isValid()) { - $content = $this->get('wallabag_core.graby')->fetchContent($entry->getUrl()); - - $entry->setUrl($content['url'] ?: $entry->getUrl()); - $entry->setTitle($content['title']); - $entry->setContent($content['html']); - $entry->setMimetype($content['content_type']); - if (isset($content['open_graph']['og_image'])) { - $entry->setPreviewPicture($content['open_graph']['og_image']); - } - - $em = $this->getDoctrine()->getManager(); - $em->persist($entry); - $em->flush(); - + $this->updateEntry($entry); $this->get('session')->getFlashBag()->add( 'notice', 'Entry saved' @@ -57,6 +61,22 @@ class EntryController extends Controller )); } + /** + * @param Request $request + * + * @Route("/bookmarklet", name="bookmarklet") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function addEntryViaBookmarklet(Request $request) + { + $entry = new Entry($this->getUser()); + $entry->setUrl($request->get('url')); + $this->updateEntry($entry); + + return $this->redirect($this->generateUrl('homepage')); + } + /** * @param Request $request * @@ -200,7 +220,7 @@ class EntryController extends Controller throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); } - $form = $this->get('form.factory')->create(new EntryFilterType()); + $form = $this->get('form.factory')->create(new EntryFilterType($repository, $this->getUser())); if ($request->query->has($form->getName())) { // manually bind values from the request @@ -304,7 +324,7 @@ class EntryController extends Controller * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function deleteEntryAction(Entry $entry) + public function deleteEntryAction(Request $request, Entry $entry) { $this->checkUserAction($entry); @@ -317,7 +337,7 @@ class EntryController extends Controller 'Entry deleted' ); - return $this->redirect($this->generateUrl('homepage')); + return $this->redirect($request->headers->get('referer')); } /**