/**
  * Return top parent which is not granted to edit
  *
  * @param PageInterface $page
  * @return PageInterface $parent
  */
 private function getTopNotGrantedParent(PageInterface $page)
 {
     while ($page->getParent() && $this->securityContext->isGranted('EDIT', $page->getParent())) {
         $page = $page->getParent();
     }
     return $page->getParent() ?: $page;
 }
 /**
  * Updates the SEO page values for given page instance
  *
  * @param PageInterface $page
  */
 protected function updateSeoPage(PageInterface $page, $locale)
 {
     /**
      * @var LanguageVersion $languageVersion
      */
     $languageVersion = $page->getSite()->getLanguageVersion($locale);
     $siteTitle = $languageVersion->getTitle() ?: $page->getSite()->getName();
     if (!$page->getParent()) {
         $title = $siteTitle;
     } else {
         if ($page->getTitle()) {
             $title = $page->getTitle() . ' - ' . $siteTitle;
         } elseif ($page->getName()) {
             $title = $page->getName() . ' - ' . $siteTitle;
         }
     }
     $this->seoPage->setTitle($title);
     $this->seoPage->addMeta('property', 'og:title', $title);
     if ($page->getMetaDescription()) {
         $this->seoPage->addMeta('name', 'description', $page->getMetaDescription());
         $this->seoPage->addMeta('property', 'og:description', $page->getMetaDescription());
     } elseif ($languageVersion->getMetaDescription()) {
         $this->seoPage->addMeta('name', 'description', $languageVersion->getMetaDescription());
         $this->seoPage->addMeta('property', 'og:description', $languageVersion->getMetaDescription());
     }
     if ($page->getMetaKeyword()) {
         $this->seoPage->addMeta('name', 'keywords', $page->getMetaKeyword());
     } elseif ($languageVersion->getMetaKeywords()) {
         $this->seoPage->addMeta('name', 'keywords', $languageVersion->getMetaKeywords());
     }
     $this->seoPage->addMeta('property', 'og:site_name', $languageVersion->getTitle());
     $this->seoPage->addMeta('property', 'og:url', 'http://' . $languageVersion->getHost() . $languageVersion->getRelativePath());
     $this->seoPage->addMeta('property', 'og:type', 'website');
     $this->seoPage->addHtmlAttributes('prefix', 'og: http://ogp.me/ns#');
 }
 /**
  * @param \Sonata\PageBundle\Model\PageInterface $page
  *
  * @return void
  */
 public function fixUrl(PageInterface $page)
 {
     if ($page->isInternal()) {
         $page->setUrl(null);
         // internal routes do not have any url ...
         return;
     }
     // hybrid page cannot be altered
     if (!$page->isHybrid()) {
         // make sure Page has a valid url
         if ($page->getParent()) {
             foreach ($page->getTranslations() as $trans) {
                 $locale = $trans->getLocale();
                 if (!$trans->getSlug()) {
                     $trans->setSlug(ModelPage::slugify($trans->getName()));
                 }
                 $parent = $page->getParent();
                 foreach ($parent->getTranslations() as $ptrans) {
                     if ($ptrans->getLocale() === $locale) {
                         $url = $ptrans->getUrl();
                         if ($url == '/') {
                             $base = '/';
                         } elseif (substr($url, -1) != '/') {
                             $base = $url . '/';
                         } else {
                             $base = $url;
                         }
                         $trans->setUrl($base . $trans->getSlug());
                     }
                 }
             }
         } else {
             foreach ($page->getTranslations() as $trans) {
                 // a parent page does not have any slug - can have a custom url ...
                 $trans->setUrl('/' . $trans->getSlug());
             }
         }
     }
     foreach ($page->getChildren() as $child) {
         $this->fixUrl($child);
     }
 }
 /**
  * Updates the SEO page values for given page instance
  *
  * @param PageInterface $page
  */
 protected function updateSeoPage(PageInterface $page, Request $request)
 {
     /**
      * @var LanguageVersion $languageVersion
      */
     $languageVersion = $page->getSite()->getLanguageVersion($request->getLocale());
     $siteTitle = $languageVersion->getTitle() ?: $page->getSite()->getName();
     if (!$page->getParent()) {
         $title = $siteTitle;
     } else {
         if ($page->getTitle()) {
             $title = $page->getTitle() . ' - ' . $siteTitle;
         } elseif ($page->getName()) {
             $title = $page->getName() . ' - ' . $siteTitle;
         } else {
             $title = $siteTitle;
         }
     }
     $this->seoPage->setTitle($title);
     $this->seoPage->addMeta('property', 'og:title', $title);
     if ($page->getMetaDescription()) {
         $this->seoPage->addMeta('name', 'description', $page->getMetaDescription());
         $this->seoPage->addMeta('property', 'og:description', $page->getMetaDescription());
     } elseif ($languageVersion->getMetaDescription()) {
         $this->seoPage->addMeta('name', 'description', $languageVersion->getMetaDescription());
         $this->seoPage->addMeta('property', 'og:description', $languageVersion->getMetaDescription());
     }
     if ($page->getMetaKeyword()) {
         $this->seoPage->addMeta('name', 'keywords', $page->getMetaKeyword());
     } elseif ($languageVersion->getMetaKeywords()) {
         $this->seoPage->addMeta('name', 'keywords', $languageVersion->getMetaKeywords());
     }
     if ($page->getOgImage()) {
         //$ogImageUrl = $this->get('sonata.media.twig.extension')->path($ogImage, 'og_image'); TODO
         $this->seoPage->addMeta('property', 'og:image', strpos($page->getOgImage(), '://') !== false ? $page->getOgImage() : sprintf('%s://%s%s', isset($_SERVER['HTTPS']) ? 'https' : 'http', $_SERVER['HTTP_HOST'], $page->getOgImage()));
     }
     $this->seoPage->addMeta('property', 'og:site_name', $languageVersion->getTitle());
     $this->seoPage->addMeta('property', 'og:url', $request->getUri());
     $this->seoPage->addMeta('property', 'og:type', 'website');
     $this->seoPage->addHtmlAttributes('prefix', 'og: http://ogp.me/ns#');
 }
 /**
  * {@inheritdoc}
  */
 public function fixUrl(PageInterface $page)
 {
     if ($page->isInternal()) {
         $page->setUrl(null);
         // internal routes do not have any url ...
         return;
     }
     // hybrid page cannot be altered
     if (!$page->isHybrid()) {
         // make sure Page has a valid url
         if ($page->getParent()) {
             if (!$page->getSlug()) {
                 $page->setSlug(Page::slugify($page->getName()));
             }
             if ($page->getParent()->getUrl() == '/') {
                 $base = '/';
             } elseif (substr($page->getParent()->getUrl(), -1) != '/') {
                 $base = $page->getParent()->getUrl() . '/';
             } else {
                 $base = $page->getParent()->getUrl();
             }
             $page->setUrl($base . $page->getSlug());
         } else {
             // a parent page does not have any slug - can have a custom url ...
             $page->setSlug(null);
             $page->setUrl('/' . $page->getSlug());
         }
     }
     foreach ($page->getChildren() as $child) {
         $this->fixUrl($child);
     }
 }
示例#6
0
 public function fixUrl(PageInterface $page)
 {
     // hybrid page cannot be altered
     if (!$page->isHybrid()) {
         if (!$page->getSlug()) {
             $page->setSlug(Page::slugify($page->getName()));
         }
         // make sure Page has a valid url
         if ($page->getParent()) {
             $base = $page->getParent()->getUrl() == '/' ? '/' : $page->getParent()->getUrl() . '/';
             $page->setUrl($base . $page->getSlug());
         } else {
             $page->setUrl('/' . $page->getSlug());
         }
     }
     foreach ($page->getChildren() as $child) {
         $this->fixUrl($child);
     }
 }