コード例 #1
0
 public function populateSitemap(SitemapPopulateEvent $event)
 {
     $section = $event->getSection();
     if (is_null($section) || $section == 'cms') {
         foreach ($this->locales as $locale) {
             $nodeRepository = $this->entityManager->getRepository('AlpixelCMSBundle:Node');
             $pages = $nodeRepository->findAllWithLocale($locale);
             foreach ($pages as $page) {
                 $hasController = true;
                 foreach ($this->contentTypes as $contentType) {
                     if (get_class($page) == $contentType['class'] && $contentType['controller'] === null) {
                         $hasController = false;
                     }
                 }
                 if ($hasController === false) {
                     continue;
                 }
                 $url = $this->router->generate('alpixel_cms', ['slug' => $page->getSlug(), '_locale' => $page->getLocale()], UrlGeneratorInterface::ABSOLUTE_URL);
                 $url = new UrlConcrete($url, $page->getDateUpdated(), UrlConcrete::CHANGEFREQ_MONTHLY, 0.7);
                 $urlLang = new GoogleMultilangUrlDecorator($url);
                 $translations = $nodeRepository->findTranslations($page);
                 foreach ($translations as $translation) {
                     if ($locale !== $translation->getLocale()) {
                         $url = $this->router->generate('alpixel_cms', ['slug' => $translation->getSlug(), '_locale' => $translation->getLocale()], UrlGeneratorInterface::ABSOLUTE_URL);
                         $urlLang->addLink($url, $translation->getLocale());
                     }
                 }
                 $event->getGenerator()->addUrl($urlLang, 'cms.' . $locale);
             }
         }
     }
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function populateSitemap(SitemapPopulateEvent $event)
 {
     $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('harentius_blog_homepage', [], true), $this->homepage->getUpdatedAt(), UrlConcrete::CHANGEFREQ_WEEKLY, 1.0), 'pages');
     // Pages
     $pages = $this->pageRepository->findPublishedNotSlugOrdered($this->homepageSlug);
     foreach ($pages as $page) {
         $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('harentius_blog_show', ['slug' => $page->getSlug()], true), $page->getUpdatedAt(), UrlConcrete::CHANGEFREQ_MONTHLY, 0.5), 'pages');
     }
     // Articles
     /** @var Article[] $articles */
     $articles = $this->articleRepository->findBy(['isPublished' => true], ['publishedAt' => 'DESC']);
     foreach ($articles as $article) {
         $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('harentius_blog_show', ['slug' => $article->getSlug()], true), $article->getUpdatedAt(), UrlConcrete::CHANGEFREQ_MONTHLY, 0.9), 'articles');
     }
     // Categories
     $addCategoriesRoutes = function ($categories) use($event, &$addCategoriesRoutes) {
         foreach ($categories as $category) {
             $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate("harentius_blog_category_{$category['id']}", [], true), null, UrlConcrete::CHANGEFREQ_MONTHLY, 0.8), 'categories');
             $addCategoriesRoutes($category['__children']);
         }
     };
     $addCategoriesRoutes($this->categoryRepository->notEmptyChildrenHierarchy());
     // Archives
     foreach ($this->archive->getList() as $year => $months) {
         foreach ($months as $number => $name) {
             $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('harentius_blog_archive_month', ['year' => $year, 'month' => $number], true), null, UrlConcrete::CHANGEFREQ_MONTHLY, 0.6), 'archive');
         }
         $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('harentius_blog_archive_year', ['year' => $year], true), null, UrlConcrete::CHANGEFREQ_MONTHLY, 0.6), 'archive');
     }
 }
コード例 #3
0
 /**
  * Generates the sitemap for the article posts for each category
  * @param SitemapPopulateEvent $event
  */
 private function generateArticlePages(SitemapPopulateEvent $event)
 {
     $articles = $this->entityManager->getRepository('AppBundle:Article')->findAll();
     foreach ($articles as $article) {
         $url = $this->router->generate('_article', array('category' => $article->getCategory(), 'article_slug' => $article->getSlug()), UrlGeneratorInterface::ABSOLUTE_URL);
         $event->getGenerator()->addUrl(new UrlConcrete($url, new \DateTime(), null, null), 'article_pages');
     }
 }
コード例 #4
0
ファイル: SitemapListener.php プロジェクト: beyzakokcan/ojs
 /**
  * @param SitemapPopulateEvent $event
  * @param Issue $issue
  * @return SitemapPopulateEvent
  */
 private function generateArticleLinks(SitemapPopulateEvent $event, Issue $issue)
 {
     $articles = $issue->getArticles();
     $journal = $issue->getJournal();
     foreach ($articles as $article) {
         $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('ojs_article_page', ['publisher' => $journal->getPublisher()->getSlug(), 'slug' => $journal->getSlug(), 'issue_id' => $issue->getId(), 'article_id' => $article->getId()], true), new \DateTime(), UrlConcrete::CHANGEFREQ_WEEKLY, 1), 'journals-' . $journal->getSlug());
     }
     return $event;
 }
コード例 #5
0
ファイル: SitemapListener.php プロジェクト: heavenwoo/blog
 public function populateSitemap(SitemapPopulateEvent $event)
 {
     $section = $event->getSection();
     if (is_null($section) || $section == 'default') {
         //get absolute homepage url
         $url = $this->router->generate('blog_index', array(), UrlGeneratorInterface::ABSOLUTE_URL);
         //add homepage url to the urlset named default
         $event->getGenerator()->addUrl(new UrlConcrete($url, new \DateTime(), UrlConcrete::CHANGEFREQ_HOURLY, 1), 'default');
     }
 }
コード例 #6
0
 /**
  * @param  SitemapPopulateEvent      $event
  * @throws \InvalidArgumentException
  */
 private function addUrlsFromRoutes(SitemapPopulateEvent $event)
 {
     $collection = $this->router->getRouteCollection();
     foreach ($collection->all() as $name => $route) {
         $options = $this->getOptions($name, $route);
         if ($options) {
             $event->getGenerator()->addUrl($this->getUrlConcrete($name, $options), $event->getSection() ? $event->getSection() : 'default');
         }
     }
 }
コード例 #7
0
 public function populateSitemap(SitemapPopulateEvent $event)
 {
     $section = $event->getSection();
     if (is_null($section) || $section == 'default') {
         //get absolute homepage url
         $urls = array('frontend_homepage' => $this->router->generate('frontend_homepage', array(), UrlGeneratorInterface::ABSOLUTE_URL), 'frontend_feedback' => $this->router->generate('frontend_feedback', array(), UrlGeneratorInterface::ABSOLUTE_URL), 'frontend_work_index' => $this->router->generate('frontend_work_index', array(), UrlGeneratorInterface::ABSOLUTE_URL), 'frontend_page_contacts' => $this->router->generate('frontend_page_contacts', array(), UrlGeneratorInterface::ABSOLUTE_URL));
         foreach ($urls as $url) {
             $event->getGenerator()->addUrl(new UrlConcrete($url, new \DateTime(), UrlConcrete::CHANGEFREQ_HOURLY, 1), 'default');
         }
     }
 }
コード例 #8
0
ファイル: SitemapListener.php プロジェクト: Immolare/Litige
 public function populateSitemap(SitemapPopulateEvent $event)
 {
     $section = $event->getSection();
     if (is_null($section) || $section == 'default') {
         //get absolute homepage url
         $url = $this->router->generate('homepage', array(), true);
         $urlBase = new Url\GoogleMultilangUrlDecorator(new Url\UrlConcrete($url, new \DateTime(), UrlConcrete::CHANGEFREQ_MONTHLY, 1));
         //add homepage url to the urlset named default
         $event->getGenerator()->addUrl($urlBase, 'default');
     }
 }
コード例 #9
0
 /**
  * Populate the sitemap.
  *
  * @param SitemapPopulateEvent $event
  */
 public function populateSitemap(SitemapPopulateEvent $event)
 {
     $section = $event->getSection();
     if (is_null($section) || $section == 'default') {
         $contentRepository = $this->em->getRepository('OpiferCmsBundle:Content');
         $content = $contentRepository->findAll();
         foreach ($content as $item) {
             if ($item->isPrivate() || !$item->isIndexable()) {
                 continue;
             }
             // Get absolute content url
             $url = $this->router->generate('_content', ['slug' => $item->getSlug()], true);
             // Add the url to the urlset named default
             $event->getGenerator()->addUrl(new UrlConcrete($url, new \DateTime(), UrlConcrete::CHANGEFREQ_HOURLY, 1), 'default');
         }
     }
 }
コード例 #10
0
 protected function generateUrlConcrete($path, $section = 'default', $params = array(), $priority = 1, $lastUpdate = null, $frequency = UrlConcrete::CHANGEFREQ_WEEKLY)
 {
     $url = $this->router->generate($path, $params, true);
     $this->event->getGenerator()->addUrl(new UrlConcrete($url, $lastUpdate ?: new \DateTime("now"), $frequency, $priority), $section);
 }