public function rssAction($uri = null) { if (null === $this->application) { throw new FrontControllerException('A valid BackBee application is required.', FrontControllerException::INTERNAL_ERROR); } if (false === $this->application->getContainer()->has('site')) { throw new FrontControllerException('A BackBee\\Site instance is required.', FrontControllerException::INTERNAL_ERROR); } $site = $this->application->getContainer()->get('site'); if (false !== ($ext = strrpos($uri, '.'))) { $uri = substr($uri, 0, $ext); } if ('_root_' == $uri) { $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getRoot($site); } else { $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->findOneBy(array('_site' => $site, '_url' => '/' . $uri, '_state' => Page::getUndeletedStates())); } try { $this->application->info(sprintf('Handling URL request `rss%s`.', $uri)); $response = new Response($this->application->getRenderer()->render($page, 'rss', null, 'rss.phtml', false)); $response->headers->set('Content-Type', 'text/xml'); $response->setClientTtl(15); $response->setTtl(15); $this->send($response); } catch (\Exception $e) { $this->defaultAction('/rss/' . $uri); } }
/** * Checks for the uniqueness of the URL and postfixe it if need. * * @param \BackBee\NestedNode\Page $page The page * @param string &$url The reference of the generated URL */ public function getUniqueness(Page $page, $url) { if (!$this->preserveUnicity) { return $url; } $pageRepository = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page'); if (null === $pageRepository->findOneBy(['_url' => $url, '_root' => $page->getRoot(), '_state' => $page->getUndeletedStates()])) { return $url; } $baseUrl = $url . '-%d'; $matches = []; $existings = []; if (preg_match('#(.*)\\/$#', $baseUrl, $matches)) { $baseUrl = $matches[1] . '-%d/'; $existings = $pageRepository->createQueryBuilder('p')->andRootIs($page->getRoot())->andWhere('p._url LIKE :url')->setParameter('url', $matches[1] . '%/')->getQuery()->getResult(); } else { $existings = $this->application->getEntityManager()->getConnection()->executeQuery('SELECT p.uid FROM page p LEFT JOIN section s ON s.uid = p.section_uid WHERE s.root_uid = :root AND p.url REGEXP :regex', ['regex' => str_replace(['+'], ['[+]'], $url) . '(-[0-9]+)?$', 'root' => $page->getRoot()->getUid()])->fetchAll(); $uids = []; foreach ($existings as $existing) { $uids[] = $existing['uid']; } $existings = $pageRepository->findBy(['_uid' => $uids]); } $existingUrls = []; foreach ($existings as $existing) { if (!$existing->isDeleted() && $existing->getUid() !== $page->getUid()) { $existingUrls[] = $existing->getUrl(false); } } $count = 1; while (in_array($url, $existingUrls)) { $url = sprintf($baseUrl, $count++); } return $url; }