/** * Add the meta information. * * @param SeoPageInterface $seoPage * @param ProductInterface $product */ public function alterPage(SeoPageInterface $seoPage, ProductInterface $product) { $seoPage->addMeta('name', 'twitter:card', 'product')->addMeta('name', 'twitter:title', $product->getName())->addMeta('name', 'twitter:description', substr($product->getDescription(), 0, 200))->addMeta('name', 'twitter:label1', 'Price')->addMeta('name', 'twitter:data1', $this->numberHelper->formatCurrency($product->getPrice(), $this->currencyDetector->getCurrency()))->addMeta('name', 'twitter:label2', 'SKU')->addMeta('name', 'twitter:data2', $product->getSku())->addMeta('name', 'twitter:site', $this->site)->addMeta('name', 'twitter:creator', $this->creator)->addMeta('name', 'twitter:domain', $this->domain); if ($image = $product->getImage()) { $provider = $this->mediaPool->getProvider($image->getProviderName()); $seoPage->addMeta('property', 'twitter:image:src', $provider->generatePublicUrl($image, $this->mediaFormat)); } }
/** * @param SeoPageInterface $seoPage * * @return void */ protected function registerHeaders(SeoPageInterface $seoPage) { $attributeName = 'prefix'; $headAttributes = $seoPage->getHeadAttributes(); if (!isset($headAttributes[$attributeName])) { $headAttributes[$attributeName] = ''; } $headAttributes[$attributeName] .= 'og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# product: http://ogp.me/ns/product#'; $seoPage->setHeadAttributes($headAttributes); }
/** * @return string */ public function getOembedLinks() { $html = ''; foreach ($this->page->getOEmbedLinks() as $title => $link) { $html .= sprintf("<link rel=\"alternate\" type=\"application/json+oembed\" href=\"%s\" title=\"%s\" />\n", $link, $title); } return $html; }
/** * {@inheritdoc} */ public final function onKernelRequest(GetResponseEvent $event) { if (!$this->decoratorStrategy->isRouteUriDecorable($event->getRequest()->getPathInfo())) { return; } $this->handleKernelRequest($event); if ($this->site) { if ($this->site->getTitle()) { $this->seoPage->setTitle($this->site->getTitle()); } if ($this->site->getMetaDescription()) { $this->seoPage->addMeta('name', 'description', $this->site->getMetaDescription()); } if ($this->site->getMetaKeywords()) { $this->seoPage->addMeta('name', 'keywords', $this->site->getMetaKeywords()); } } }
/** * Updates the SEO page values for given page instance * * @param PageInterface $page */ protected function updateSeoPage(PageInterface $page) { if (!$this->seoPage) { return; } if (!$this->seoPage->getTitle() || $this->seoPage->getTitle() == $this->seoPageTitle) { $browserTitle = $page->getTitle() ?: $page->getName(); $this->seoPage->addTitle($browserTitle); } if ($page->getMetaDescription()) { $this->seoPage->addMeta('name', 'description', $page->getMetaDescription()); } if ($page->getMetaKeyword()) { $this->seoPage->addMeta('name', 'keywords', $page->getMetaKeyword()); } $this->seoPage->addMeta('property', 'og:type', 'article'); $this->seoPage->addHtmlAttributes('prefix', 'og: http://ogp.me/ns#'); }
/** * 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#'); }
/** * 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#'); }