|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PiedWeb\CMSBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use PiedWeb\CMSBundle\Service\AppConfigHelper as App; |
|
6
|
|
|
use PiedWeb\CMSBundle\Service\Repository; |
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Related to the app. |
|
13
|
|
|
*/ |
|
14
|
|
|
class AppController extends AbstractController |
|
15
|
|
|
{ |
|
16
|
|
|
public function showFeed( |
|
17
|
|
|
Request $request, |
|
18
|
|
|
ParameterBagInterface $params |
|
19
|
|
|
) { |
|
20
|
|
|
$app = App::load($request, $params); |
|
21
|
|
|
// Retrieve info from homepage, for i18n, assuming it's named with locale |
|
22
|
|
|
$locale = $request->getLocale() ?? $params->get('locale'); |
|
23
|
|
|
$LocaleHomepage = Repository::getPageRepository($this->getDoctrine(), $params->get('pwc.entity_page')) |
|
24
|
|
|
->getPage($locale, $app->getHost(), $app->isFirstApp()); |
|
25
|
|
|
$page = $LocaleHomepage ?? Repository::getPageRepository($this->getDoctrine(), $params->get('pwc.entity_page')) |
|
26
|
|
|
->getPage('homepage', $app->getHost(), $app->isFirstApp()); |
|
27
|
|
|
|
|
28
|
|
|
return $this->render('@PiedWebCMS/page/rss.xml.twig', [ |
|
29
|
|
|
'pages' => $this->getPages(5, $request, $params), |
|
30
|
|
|
'page' => $page, |
|
31
|
|
|
'feedUri' => 'feed'.($params->get('locale') == $locale ? '' : '.'.$locale).'.xml', |
|
32
|
|
|
'app_base_url' => $app->getBaseUrl(), |
|
33
|
|
|
'app_name' => $app->getApp('name'), |
|
34
|
|
|
]); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function showSitemap( |
|
38
|
|
|
Request $request, |
|
39
|
|
|
ParameterBagInterface $params |
|
40
|
|
|
) { |
|
41
|
|
|
$app = App::load($request, $params); |
|
42
|
|
|
$pages = $this->getPages(null, $request, $params); |
|
43
|
|
|
|
|
44
|
|
|
if (!$pages) { |
|
45
|
|
|
throw $this->createNotFoundException(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $this->render('@PiedWebCMS/page/sitemap.'.$request->getRequestFormat().'.twig', [ |
|
49
|
|
|
'pages' => $pages, |
|
50
|
|
|
'app_base_url' => $app->getBaseUrl(), |
|
51
|
|
|
]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected function getPages(?int $limit = null, Request $request, ParameterBagInterface $params) |
|
55
|
|
|
{ |
|
56
|
|
|
$app = App::load($request, $params); |
|
57
|
|
|
$pages = Repository::getPageRepository($this->getDoctrine(), $params->get('pwc.entity_page')) |
|
58
|
|
|
->getIndexablePages( |
|
59
|
|
|
$app->getHost(), |
|
60
|
|
|
$app->isFirstApp(), |
|
61
|
|
|
$request->getLocale(), |
|
62
|
|
|
$params->get('locale'), |
|
63
|
|
|
$limit |
|
64
|
|
|
)->getQuery()->getResult(); |
|
65
|
|
|
|
|
66
|
|
|
//foreach ($pages as $page) echo $page->getMetaRobots().' '.$page->getTitle().'<br>'; |
|
67
|
|
|
//exit('feed updated'); |
|
68
|
|
|
|
|
69
|
|
|
return $pages; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|