diff options
-rw-r--r-- | app/AppKernel.php | 2 | ||||
-rw-r--r-- | app/config/routing.yml | 2 | ||||
-rw-r--r-- | app/config/routing_dev.yml | 6 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 11 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/Content.php | 34 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Service/Extractor.php | 92 |
6 files changed, 135 insertions, 12 deletions
diff --git a/app/AppKernel.php b/app/AppKernel.php index b0a66dad..f0383038 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php | |||
@@ -16,13 +16,11 @@ class AppKernel extends Kernel | |||
16 | new Symfony\Bundle\AsseticBundle\AsseticBundle(), | 16 | new Symfony\Bundle\AsseticBundle\AsseticBundle(), |
17 | new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), | 17 | new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), |
18 | new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), | 18 | new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), |
19 | new AppBundle\AppBundle(), | ||
20 | new Wallabag\CoreBundle\WallabagCoreBundle(), | 19 | new Wallabag\CoreBundle\WallabagCoreBundle(), |
21 | ); | 20 | ); |
22 | 21 | ||
23 | if (in_array($this->getEnvironment(), array('dev', 'test'))) { | 22 | if (in_array($this->getEnvironment(), array('dev', 'test'))) { |
24 | $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); | 23 | $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); |
25 | $bundles[] = new Acme\DemoBundle\AcmeDemoBundle(); | ||
26 | $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); | 24 | $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); |
27 | $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); | 25 | $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); |
28 | $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); | 26 | $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); |
diff --git a/app/config/routing.yml b/app/config/routing.yml index b3c5291a..95c224ab 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml | |||
@@ -4,4 +4,4 @@ app: | |||
4 | 4 | ||
5 | homepage: | 5 | homepage: |
6 | pattern: / | 6 | pattern: / |
7 | defaults: { _controller: CoreBundle:Entry:showUnread } \ No newline at end of file | 7 | defaults: { _controller: WallabagCoreBundle:Entry:showUnread } \ No newline at end of file |
diff --git a/app/config/routing_dev.yml b/app/config/routing_dev.yml index 99130058..1a236e28 100644 --- a/app/config/routing_dev.yml +++ b/app/config/routing_dev.yml | |||
@@ -15,8 +15,4 @@ _errors: | |||
15 | prefix: /_error | 15 | prefix: /_error |
16 | 16 | ||
17 | _main: | 17 | _main: |
18 | resource: routing.yml | 18 | resource: routing.yml \ No newline at end of file |
19 | |||
20 | # AcmeDemoBundle routes (to be removed) | ||
21 | _acme_demo: | ||
22 | resource: "@AcmeDemoBundle/Resources/config/routing.yml" \ No newline at end of file | ||
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 2ebb416c..48d19307 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |||
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | use Wallabag\CoreBundle\Repository; | 8 | use Wallabag\CoreBundle\Repository; |
9 | use Wallabag\CoreBundle\Entity\Entries; | 9 | use Wallabag\CoreBundle\Entity\Entries; |
10 | use Wallabag\CoreBundle\Service\Extractor; | ||
10 | use Wallabag\Wallabag\Tools; | 11 | use Wallabag\Wallabag\Tools; |
11 | use Wallabag\Wallabag\Url; | 12 | use Wallabag\Wallabag\Url; |
12 | 13 | ||
@@ -32,10 +33,12 @@ class EntryController extends Controller | |||
32 | 33 | ||
33 | if ($form->isValid()) { | 34 | if ($form->isValid()) { |
34 | 35 | ||
35 | $content = Tools::getPageContent(new Url($entry->getUrl())); | 36 | $content = Extractor::extract($entry->getUrl()); |
36 | var_dump($content);die; | ||
37 | 37 | ||
38 | $em = $this->getDoctrine()->getEntityManager(); | 38 | $entry->setTitle($content->getTitle()); |
39 | $entry->setContent($content->getBody()); | ||
40 | |||
41 | $em = $this->getDoctrine()->getManager(); | ||
39 | $em->persist($entry); | 42 | $em->persist($entry); |
40 | $em->flush(); | 43 | $em->flush(); |
41 | 44 | ||
@@ -170,7 +173,7 @@ class EntryController extends Controller | |||
170 | */ | 173 | */ |
171 | public function deleteEntryAction(Request $request, Entries $entry) | 174 | public function deleteEntryAction(Request $request, Entries $entry) |
172 | { | 175 | { |
173 | $em = $this->getDoctrine()->getEntityManager(); | 176 | $em = $this->getDoctrine()->getManager(); |
174 | $em->remove($entry); | 177 | $em->remove($entry); |
175 | $em->flush(); | 178 | $em->flush(); |
176 | 179 | ||
diff --git a/src/Wallabag/CoreBundle/Helper/Content.php b/src/Wallabag/CoreBundle/Helper/Content.php new file mode 100644 index 00000000..81acbad7 --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/Content.php | |||
@@ -0,0 +1,34 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | class Content | ||
6 | { | ||
7 | private $title; | ||
8 | |||
9 | private $body; | ||
10 | |||
11 | public function __constructor() { | ||
12 | |||
13 | } | ||
14 | |||
15 | public function getTitle() | ||
16 | { | ||
17 | return $this->title; | ||
18 | } | ||
19 | |||
20 | public function setTitle($title) | ||
21 | { | ||
22 | $this->title = $title; | ||
23 | } | ||
24 | |||
25 | public function getBody() | ||
26 | { | ||
27 | return $this->body; | ||
28 | } | ||
29 | |||
30 | public function setBody($body) | ||
31 | { | ||
32 | $this->body = $body; | ||
33 | } | ||
34 | } \ No newline at end of file | ||
diff --git a/src/Wallabag/CoreBundle/Service/Extractor.php b/src/Wallabag/CoreBundle/Service/Extractor.php new file mode 100644 index 00000000..790386d4 --- /dev/null +++ b/src/Wallabag/CoreBundle/Service/Extractor.php | |||
@@ -0,0 +1,92 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Service; | ||
4 | |||
5 | use Wallabag\CoreBundle\Helper\Content; | ||
6 | use Wallabag\Wallabag\Url; | ||
7 | |||
8 | final class Extractor | ||
9 | { | ||
10 | public static function extract($url) { | ||
11 | $pageContent = Extractor::getPageContent(new Url(base64_encode($url))); | ||
12 | $title = ($pageContent['rss']['channel']['item']['title'] != '') ? $pageContent['rss']['channel']['item']['title'] : _('Untitled'); | ||
13 | $body = $pageContent['rss']['channel']['item']['description']; | ||
14 | |||
15 | $content = new Content(); | ||
16 | $content->setTitle($title); | ||
17 | $content->setBody($body);; | ||
18 | |||
19 | return $content; | ||
20 | } | ||
21 | /** | ||
22 | * Get the content for a given URL (by a call to FullTextFeed) | ||
23 | * | ||
24 | * @param Url $url | ||
25 | * @return mixed | ||
26 | */ | ||
27 | public static function getPageContent(Url $url) | ||
28 | { | ||
29 | // Saving and clearing context | ||
30 | $REAL = array(); | ||
31 | foreach( $GLOBALS as $key => $value ) { | ||
32 | if( $key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS' ) { | ||
33 | $GLOBALS[$key] = array(); | ||
34 | $REAL[$key] = $value; | ||
35 | } | ||
36 | } | ||
37 | // Saving and clearing session | ||
38 | if (isset($_SESSION)) { | ||
39 | $REAL_SESSION = array(); | ||
40 | foreach( $_SESSION as $key => $value ) { | ||
41 | $REAL_SESSION[$key] = $value; | ||
42 | unset($_SESSION[$key]); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | // Running code in different context | ||
47 | $scope = function() { | ||
48 | extract( func_get_arg(1) ); | ||
49 | $_GET = $_REQUEST = array( | ||
50 | "url" => $url->getUrl(), | ||
51 | "max" => 5, | ||
52 | "links" => "preserve", | ||
53 | "exc" => "", | ||
54 | "format" => "json", | ||
55 | "submit" => "Create Feed" | ||
56 | ); | ||
57 | ob_start(); | ||
58 | require func_get_arg(0); | ||
59 | $json = ob_get_contents(); | ||
60 | ob_end_clean(); | ||
61 | return $json; | ||
62 | }; | ||
63 | |||
64 | // Silence $scope function to avoid | ||
65 | // issues with FTRSS when error_reporting is to high | ||
66 | // FTRSS generates PHP warnings which break output | ||
67 | $json = @$scope(__DIR__ . "/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php", array("url" => $url)); | ||
68 | |||
69 | // Clearing and restoring context | ||
70 | foreach ($GLOBALS as $key => $value) { | ||
71 | if($key != "GLOBALS" && $key != "_SESSION" ) { | ||
72 | unset($GLOBALS[$key]); | ||
73 | } | ||
74 | } | ||
75 | foreach ($REAL as $key => $value) { | ||
76 | $GLOBALS[$key] = $value; | ||
77 | } | ||
78 | |||
79 | // Clearing and restoring session | ||
80 | if (isset($REAL_SESSION)) { | ||
81 | foreach($_SESSION as $key => $value) { | ||
82 | unset($_SESSION[$key]); | ||
83 | } | ||
84 | |||
85 | foreach($REAL_SESSION as $key => $value) { | ||
86 | $_SESSION[$key] = $value; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | return json_decode($json, true); | ||
91 | } | ||
92 | } \ No newline at end of file | ||