Source of file SiteTreeExtension.php
Size: 32,331 Bytes - Last Modified: 2021-12-24T05:17:49+00:00
/var/www/docs.ssmods.com/process/src/src/Extensions/SiteTreeExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940 | <?php namespace Innoweb\SocialMeta\Extensions; use BurnBright\ExternalURLField\ExternalURLField; use SilverStripe\AssetAdmin\Forms\UploadField; use SilverStripe\Assets\File; use SilverStripe\Assets\Image; use SilverStripe\CMS\Controllers\RootURLController; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\Controller; use SilverStripe\Control\Director; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextareaField; use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\ORM\FieldType\DBHTMLVarchar; use SilverStripe\ORM\FieldType\DBText; use SilverStripe\ORM\FieldType\DBVarchar; use SilverStripe\Security\Member; use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\View\ArrayData; use SilverStripe\View\HTML; use SilverStripe\i18n\i18n; use SilverStripe\ORM\ArrayList; class SiteTreeExtension extends \SilverStripe\CMS\Model\SiteTreeExtension { public const INCLUDE_SITE_JSONLD_HOME = 'home'; public const INCLUDE_SITE_JSONLD_ALL = 'all'; private static $title_divider = ' - '; private static $metadata_tab_enabled = true; private static $meta_description_fallback_fields = []; private static $meta_description_fallback_to_site = true; private static $minify_jsonld = true; private static $include_site_jsonld = self::INCLUDE_SITE_JSONLD_HOME; private static $db = [ 'MetaTitle' => 'Varchar(255)', 'MetaCanonicalURL' => 'ExternalURL' ]; private static $has_one = [ 'MetaImage' => Image::class ]; private static $owns = [ 'MetaImage' ]; public function getSocialMetaConfig() { $siteConfig = SiteConfig::current_site_config(); return $siteConfig->getCurrentSocialMetaConfig(); } /** * @param array $tags */ public function MetaComponents(array &$tags) { // update title tag if ($title = $this->owner->getSocialMetaValue('Title')) { $tags['title'] = [ 'tag' => 'title', 'content' => $title, ]; } // update meta description if ($description = $this->owner->getSocialMetaValue('Description')) { $tags['description'] = [ 'attributes' => [ 'name' => 'description', 'content' => $description, ], ]; } if ($metaAuthor = $this->owner->getSocialMetaValue('Author')) { $tags['author'] = [ 'attributes' => [ 'name' => 'author', 'content' => $metaAuthor, ], ]; } if ($canonicalURL = $this->owner->getSocialMetaValue('CanonicalURL')) { $tags['canonical'] = [ 'tag' => 'link', 'attributes' => [ 'rel' => 'canonical', 'href' => $canonicalURL, ], ]; } $twitterCardType = $this->owner->getSocialMetaValue('TwitterCardType'); $twitterImageURL = $this->owner->getSocialMetaValue('TwitterImageURL'); $twitterSite = $this->owner->getSocialMetaValue('TwitterSite'); $twitterTitle = $this->owner->getSocialMetaValue('TwitterTitle'); $twitterDescription = $this->owner->getSocialMetaValue('TwitterDescription'); $twitterCreators = $this->owner->getSocialMetaValue('TwitterCreators'); if ($twitterCardType) { $tags['twitter:card'] = [ 'attributes' => [ 'name' => 'twitter:card', 'content' => $twitterCardType, ], ]; } if ($twitterSite) { $tags['twitter:site'] = [ 'attributes' => [ 'name' => 'twitter:site', 'content' => $twitterSite, ], ]; } if ($twitterTitle) { $tags['twitter:title'] = [ 'attributes' => [ 'name' => 'twitter:title', 'content' => $twitterTitle, ], ]; } if ($twitterDescription) { $tags['twitter:description'] = [ 'attributes' => [ 'name' => 'twitter:description', 'content' => $twitterDescription, ], ]; } if ($twitterImageURL) { $tags['twitter:image'] = [ 'attributes' => [ 'name' => 'twitter:image', 'content' => $twitterImageURL, ], ]; } if ($twitterCreators && is_array($twitterCreators)) { foreach ($twitterCreators as $key => $twitterCreator) { $tags['twitter:creator_' . $key] = [ 'attributes' => [ 'name' => 'twitter:creator', 'content' => $twitterCreator, ], ]; } } // Facebook / OpenGraph $facebookAppID = $this->owner->getSocialMetaValue('FacebookAppID'); $facebookAdminIDs = $this->owner->getSocialMetaValue('FacebookAdminIDs'); $openGraphType = $this->owner->getSocialMetaValue('OpenGraphType'); $openGraphURL = $this->owner->getSocialMetaValue('OpenGraphURL'); $openGraphTitle = $this->owner->getSocialMetaValue('OpenGraphTitle'); $openGraphDescription = $this->owner->getSocialMetaValue('OpenGraphDescription'); $openGraphLocale = $this->owner->getSocialMetaValue('OpenGraphLocale'); $openGraphSite = $this->owner->getSocialMetaValue('OpenGraphSite'); $openGraphImage = $this->owner->getSocialMetaValue('OpenGraphImage'); $openGraphSeeAlsoEntries = $this->owner->getSocialMetaValue('OpenGraphSeeAlsoEntries'); if ($facebookAppID) { $tags['fb:app_id'] = [ 'attributes' => [ 'name' => 'fb:app_id', 'content' => $facebookAppID, ], ]; } if ($facebookAdminIDs && is_array($facebookAdminIDs)) { foreach ($facebookAdminIDs as $key => $facebookAdminID) { $tags['fb:admins_' . $key] = [ 'attributes' => [ 'property' => 'fb:admins', 'content' => $facebookAdminID, ], ]; } } if ($openGraphType) { $tags['og:type'] = [ 'attributes' => [ 'property' => 'og:type', 'content' => $openGraphType, ], ]; } if ($openGraphURL) { $tags['og:url'] = [ 'attributes' => [ 'property' => 'og:url', 'content' => $openGraphURL, ], ]; } if ($openGraphTitle) { $tags['og:title'] = [ 'attributes' => [ 'property' => 'og:title', 'content' => $openGraphTitle, ], ]; } if ($openGraphDescription) { $tags['og:description'] = [ 'attributes' => [ 'property' => 'og:description', 'content' => $openGraphDescription, ], ]; } if ($openGraphLocale) { $tags['og:locale'] = [ 'attributes' => [ 'property' => 'og:locale', 'content' => $openGraphLocale, ], ]; } if ($openGraphSite) { $tags['og:site_name'] = [ 'attributes' => [ 'property' => 'og:site_name', 'content' => $openGraphSite, ], ]; } if ($openGraphImage) { $tags['og:image'] = [ 'attributes' => [ 'property' => 'og:image', 'content' => $openGraphImage->getAbsoluteURL(), ], ]; if (Director::is_https()) { $tags['og:image:secure_url'] = [ 'attributes' => [ 'property' => 'og:image:secure_url', 'content' => $openGraphImage->getAbsoluteURL(), ], ]; } $tags['og:image:type'] = [ 'attributes' => [ 'property' => 'og:image:type', 'content' => $openGraphImage->getMimeType(), ], ]; $tags['og:image:width'] = [ 'attributes' => [ 'property' => 'og:image:width', 'content' => $openGraphImage->getWidth(), ], ]; $tags['og:image:height'] = [ 'attributes' => [ 'property' => 'og:image:height', 'content' => $openGraphImage->getHeight(), ], ]; $tags['og:image:alt'] = [ 'attributes' => [ 'property' => 'og:image:alt', 'content' => $openGraphImage->Title, ], ]; } if ($openGraphSeeAlsoEntries && $openGraphSeeAlsoEntries->exists()) { foreach ($openGraphSeeAlsoEntries as $key => $openGraphSeeAlsoEntry) { $tags['og:see_also_' . $key] = [ 'attributes' => [ 'property' => 'og:see_also', 'content' => $openGraphSeeAlsoEntry->URL, ], ]; } } // Articles if ($openGraphType === 'article') { $facebookPublisher = $this->owner->getSocialMetaValue('FacebookPublisher'); $openGraphAuthors = $this->owner->getSocialMetaValue('OpenGraphAuthors'); $openGraphPublicationTime = $this->owner->getSocialMetaValue('OpenGraphPublicationTime'); $openGraphModificationTime = $this->owner->getSocialMetaValue('OpenGraphModificationTime'); $openGraphSection = $this->owner->getSocialMetaValue('OpenGraphSection'); $openGraphTags = $this->owner->getSocialMetaValue('OpenGraphTags'); if ($facebookPublisher) { $tags['article:publisher'] = [ 'attributes' => [ 'property' => 'article:publisher', 'content' => $facebookPublisher, ], ]; } if ($openGraphAuthors && is_array($openGraphAuthors)) { foreach ($openGraphAuthors as $key => $openGraphAuthor) { $tags['article:author_' . $key] = [ 'attributes' => [ 'property' => 'article:author_' . $key, 'content' => $openGraphAuthor, ], ]; } } if ($openGraphPublicationTime) { $tags['article:published_time'] = [ 'attributes' => [ 'property' => 'article:published_time', 'content' => $openGraphPublicationTime, ], ]; } if ($openGraphModificationTime) { $tags['article:modification_time'] = [ 'attributes' => [ 'property' => 'article:modification_time', 'content' => $openGraphModificationTime, ], ]; } if ($openGraphSection) { $tags['article:section'] = [ 'attributes' => [ 'property' => 'article:section', 'content' => $openGraphSection, ], ]; } if ($openGraphTags && is_array($openGraphTags)) { foreach ($openGraphTags as $key => $openGraphTag) { $tags['article:tag_' . $key] = [ 'attributes' => [ 'property' => 'article:tag', 'content' => $openGraphTag, ], ]; } } } // schema data $schemaData = null; $pageSchemaData = $this->owner->getSocialMetaValue('SchemaData'); $includeSiteSchemaData = $this->owner->getIncludeSiteSchemaData(); if ($pageSchemaData && $includeSiteSchemaData) { $config = $this->owner->getSocialMetaConfig(); if (isset($pageSchemaData['@type']) || isset($pageSchemaData['@context'])) { // page array directly defines a type. create an array and place both blocks in it $schemaData = []; $schemaData[] = $config->getMicroDataSchemaData(); $schemaData[] = $pageSchemaData; } else if (count($pageSchemaData) > 1) { // page data define more than one type. add site data to top of page array array_unshift($pageSchemaData, $config->getMicroDataSchemaData()); $schemaData = $pageSchemaData; } else if (count($pageSchemaData) == 1) { // page data defines on type, wrapped in an array. $schemaData = array_merge($config->getMicroDataSchemaData(), $pageSchemaData[0]); } } else if ($pageSchemaData) { $schemaData = $pageSchemaData; } else if ($includeSiteSchemaData) { $config = $this->owner->getSocialMetaConfig(); $schemaData = $config->getMicroDataSchemaData(); } if ($schemaData) { $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; if (Config::inst()->get(self::class, 'minify_jsonld') === false) { $options = $options | JSON_PRETTY_PRINT; } $tags['ld+json'] = [ 'tag' => 'script', 'attributes' => [ 'type' => 'application/ld+json', ], 'content' => json_encode($schemaData, $options) ]; } } public function MetaTags(&$tagString) { $extraMeta = $this->owner->getSocialMetaValue('ExtraMeta'); if ($extraMeta) { $tagString .= "\n" . $extraMeta; } } public function getSocialMetaValue($key, $skipController = false) { if (!$skipController && $controller = Controller::curr()) { if ($controller->hasMethod('getSocialMetaObject')) { if ($object = $controller->getSocialMetaObject()) { if ($object->hasMethod('getSocialMeta' . $key) && ($value = $object->{'getSocialMeta' . $key}()) && $value !== false) { return $value; } if ($object->hasMethod('getDefaultSocialMeta' . $key) && ($value = $object->{'getDefaultSocialMeta' . $key}()) && $value !== false) { return $value; } } } if ($controller->hasMethod('getSocialMeta' . $key) && ($value = $controller->{'getSocialMeta' . $key}()) && $value !== false) { return $value; } } if ($this->owner->hasMethod('getSocialMeta' . $key) && ($value = $this->owner->{'getSocialMeta' . $key}()) && $value !== false) { return $value; } if ($this->owner->hasMethod('getDefaultSocialMeta' . $key) && ($value = $this->owner->{'getDefaultSocialMeta' . $key}()) && $value !== false) { return $value; } return null; } public function getDefaultSocialMetaTitle() { if ($this->owner->MetaTitle) { return $this->owner->MetaTitle; } $config = $this->owner->getSocialMetaConfig(); $siteName = $config->getSocialMetaValue('SiteName'); $divider = $this->owner->config()->get('title_divider'); if ($this->owner->Title) { return $this->owner->Title . $divider . $siteName; } return $siteName; } public function getDefaultSocialMetaDescription() { if ($this->owner->MetaDescription) { return $this->owner->MetaDescription; } if ($fallbackFields = $this->owner->config()->get('meta_description_fallback_fields')) { foreach ($fallbackFields as $fieldName) { if ($this->owner->hasDatabaseField($fieldName) && $this->owner->getField($fieldName)) { $field = $this->owner->dbObject($fieldName); if (is_a($field, DBHTMLVarchar::class)) { return $field->Plain(); } else if (is_a($field, DBHTMLText::class)) { return $field->Summary(); } else if (is_a($field, DBText::class)) { return $field->Summary(); } else if (is_a($field, DBVarchar::class)) { return $field->Plain(); } } } } if ($this->owner->config()->get('meta_description_fallback_to_site')) { $config = $this->owner->getSocialMetaConfig(); return $config->getSocialMetaValue('SiteDescription'); } return null; } public function getDefaultSocialMetaCanonicalURL() { return $this->owner->MetaCanonicalURL ?: preg_replace('/home\/$/i', '', $this->owner->AbsoluteLink()); } public function getDefaultSocialMetaExtraMeta() { return null; } public function getDefaultSocialMetaAuthors() { return null; } public function getDefaultSocialMetaAuthorString() { $names = $this->owner->getSocialMetaValue('AuthorsNames'); if ($names && count($names) > 0) { return implode(',', $names); } return null; } public function getDefaultSocialMetaAuthorsNames() { $authors = $this->owner->getSocialMetaValue('Authors'); if (is_string($authors)) { return explode(',', $authors); } if ($authors) { $names = []; foreach ($authors as $author) { if (is_a($author, Member::class) && $author->Name) { $names[] = $author->Name; } else if (is_a($author, ArrayData::class) && $author->Name) { $names[] = $author->Name; } else if (is_object($author) && $author->Name) { $names[] = $author->Name; } else if (is_array($author) && isset($author['Name'])) { $names[] = $author['Name']; } else if (is_string($author)) { $names[] = $author; } } return $names; } return null; } public function getDefaultSocialMetaImage() { $image = $this->owner->MetaImage(); if ($image && $image->exists()) { return $image; } $link = trim($this->owner->Link(), '/'); if ($link !== '' && $link !== RootURLController::get_homepage_link()) { // extract first image in page content $htmlValue = Injector::inst()->create('HTMLValue', $this->owner->Content); if ($images = $htmlValue->getElementsByTagName('img')) { foreach ($images as $img) { $path = urldecode(Director::makeRelative($img->getAttribute('src'))); $path = preg_replace('/_resampled\/[a-z0-9]*\//i', '', $path); if ($tmp = File::find($path)) { return $tmp; } } } } $config = $this->owner->getSocialMetaConfig(); return $config->getSocialMetaValue('SiteImage'); } public function getDefaultSocialMetaLocale() { return i18n::get_locale(); } public function getDefaultSocialMetaPublicationTime() { $version = $this->owner->allVersions()->filter('WasPublished', 1)->last(); if ($version) { $created = $version->relField('Created'); return date('c', strtotime($created)); } } public function getDefaultSocialMetaModificationTime() { return ($this->owner->LastEdited) ? $this->owner->dbObject('LastEdited')->Rfc3339() : null; } public function getDefaultSocialMetaCreationTime() { return ($this->owner->Created) ? $this->owner->dbObject('Created')->Rfc3339() : null; } public function getDefaultSocialMetaCategory() { return null; } public function getDefaultSocialMetaTags() { return null; } public function getDefaultSocialMetaTwitterCardType() { $image = $this->owner->getSocialMetaValue('TwitterImage'); if ($image) { if ($image->getWidth() >= 300 && $image->getHeight() >= 157) { return 'summary_large_image'; } } return 'summary'; } public function getDefaultSocialMetaTwitterImage() { $image = $this->owner->getSocialMetaValue('Image'); if ($image && $image->exists()) { $config = Config::inst()->get(self::class, 'image_size_twitter'); if ($config && isset($config['width']) && isset($config['height'])) { if ($image->hasMethod('FocusFill')) { return $image->FocusFill($config['width'], $config['height']); } return $image->Fill($config['width'], $config['height']); } } return null; } public function getDefaultSocialMetaTwitterImageURL() { $image = $this->owner->getSocialMetaValue('TwitterImage'); return ($image) ? $image->getAbsoluteURL() : null; } public function getDefaultSocialMetaTwitterSite() { $config = $this->owner->getSocialMetaConfig(); return $config->getSocialMetaValue('TwitterAccount'); } public function getDefaultSocialMetaTwitterTitle() { return $this->owner->getSocialMetaValue('Title'); } public function getDefaultSocialMetaTwitterDescription() { return $this->owner->getSocialMetaValue('Description'); } public function getDefaultSocialMetaTwitterCreators() { $authors = $this->owner->getSocialMetaValue('AuthorsNames'); if ($authors) { $creators = []; foreach ($authors as $author) { if (is_a($author, Member::class) && $author->TwitterHandle) { $creators[] = $author->TwitterHandle; } else if (is_a($author, ArrayData::class) && $author->TwitterHandle) { $creators[] = $author->TwitterHandle; } else if (is_object($author) && $author->TwitterHandle) { $creators[] = $author->TwitterHandle; } else if (is_array($author) && isset($author['TwitterHandle'])) { $creators[] = $author['TwitterHandle']; } } return $creators; } return null; } public function getDefaultSocialMetaFacebookAppID() { $config = $this->owner->getSocialMetaConfig(); return $config->getSocialMetaValue('FacebookAppID'); } public function getDefaultSocialMetaFacebookAdminIDs() { $config = $this->owner->getSocialMetaConfig(); return $config->getSocialMetaValue('FacebookAdminIDs'); } public function getDefaultSocialMetaFacebookPublisher() { $config = $this->owner->getSocialMetaConfig(); return $config->getSocialMetaValue('FacebookPage'); } public function getDefaultSocialMetaOpenGraphType() { $configType = Config::inst()->get(get_class($this->owner), 'socialmeta_opengraph_type'); return $configType ?: 'website'; } public function getDefaultSocialMetaOpenGraphURL() { return preg_replace('/home\/$/i', '', $this->owner->AbsoluteLink()); } public function getDefaultSocialMetaOpenGraphTitle() { return $this->owner->getSocialMetaValue('Title'); } public function getDefaultSocialMetaOpenGraphDescription() { return $this->owner->getSocialMetaValue('Description'); } public function getDefaultSocialMetaOpenGraphLocale() { return $this->owner->getSocialMetaValue('Locale'); } public function getDefaultSocialMetaOpenGraphSite() { $config = $this->owner->getSocialMetaConfig(); return $config->getSocialMetaValue('SiteName'); } public function getDefaultSocialMetaOpenGraphImage() { $image = $this->owner->getSocialMetaValue('Image'); if ($image && $image->exists()) { $config = Config::inst()->get(self::class, 'image_size_opengraph'); if ($config && isset($config['width']) && isset($config['height'])) { if ($image->hasMethod('FocusFill')) { return $image->FocusFill($config['width'], $config['height']); } return $image->Fill($config['width'], $config['height']); } } return null; } public function getDefaultSocialMetaOpenGraphImageURL() { $image = $this->owner->getSocialMetaValue('OpenGraphImage'); return ($image) ? $image->getAbsoluteURL() : null; } public function getDefaultSocialMetaOpenGraphAuthors() { $authors = $this->owner->getSocialMetaValue('AuthorsNames'); if ($authors) { $urls = []; foreach ($authors as $author) { if (is_a($author, Member::class) && $author->FacebookProfileURL) { $urls[] = $author->FacebookProfileURL; } else if (is_object($author) && $author->FacebookProfileURL) { $urls[] = $author->FacebookProfileURL; } else if (is_a($author, ArrayData::class) && $author->URL) { $urls[] = $author->URL; } else if (is_array($author) && isset($author['FacebookProfileURL'])) { $urls[] = $author['FacebookProfileURL']; } else if (is_array($author) && isset($author['URL'])) { $urls[] = $author['URL']; } } return $urls; } return null; } public function getDefaultSocialMetaOpenGraphPublicationTime() { return $this->owner->getSocialMetaValue('PublicationTime'); } public function getDefaultSocialMetaOpenGraphModificationTime() { return $this->owner->getSocialMetaValue('ModificationTime'); } public function getDefaultSocialMetaOpenGraphSection() { return $this->owner->getSocialMetaValue('Category'); } public function getDefaultSocialMetaOpenGraphTags() { return $this->owner->getSocialMetaValue('Tags'); } public function getDefaultSocialMetaOpenGraphSeeAlsoEntries() { $links = new ArrayList(); $config = $this->owner->getSocialMetaConfig(); $sameAsLinksField = $config->obj('SocialMetaSameAsLinks'); $sameAsLinks = $sameAsLinksField->getValues(); if ($sameAsLinks && count($sameAsLinks) > 0) { foreach ($sameAsLinks as $sameAsLink) { $links->push(ArrayData::create(['URL' => $sameAsLink])); } } if ($profiles = $config->getSocialMetaValue('ProfilePages')) { $links->merge($profiles); } return $links; } public function getDefaultSocialMetaSchemaData() { return null; } /** * Mark the page to include site jsonld data on this page * * @param bool $include */ public function setIncludeSiteSchemaData(bool $include) { $this->owner->include_site_jsonld_override = $include; } public function getIncludeSiteSchemaData() { $currentLink = trim($this->owner->Link(), '/'); if ( isset($this->owner->include_site_jsonld_override) ) { return $this->owner->include_site_jsonld_override; } else if ( $this->owner->config()->include_site_jsonld == self::INCLUDE_SITE_JSONLD_HOME && ($currentLink == '' || $currentLink === RootURLController::get_homepage_link()) ) { return true; } else if ( $this->owner->config()->include_site_jsonld == self::INCLUDE_SITE_JSONLD_ALL ) { return true; } return false; } public function updateCMSFields(FieldList $fields) { $metaTitleField = TextField::create( 'MetaTitle', $this->owner->fieldLabel('MetaTitle') ) ->setRightTitle(_t( SiteTree::class.'.METATITLEHELP', 'Shown at the top of the browser window and used as the "linked text" by search engines.' )) ->addExtraClass('help'); $metaURLField = ExternalURLField::create('MetaCanonicalURL', 'Canonical URL') ->setRightTitle(_t( SiteTree::class.'.METACANONICALURLHELP', 'This defaults to the absolute URL of the page. Only set this if search engines should count another URL as the original (e.g. if re-posting a blog post from another source).' )) ->setAttribute('placeholder', $this->owner->AbsoluteLink()); $metaImageField = UploadField::create( 'MetaImage', _t(SiteTree::class.'.METAIMAGELABEL', 'Image') ) ->setFolderName('Meta') ->setAllowedFileCategories('image'); $tabEnabled = $this->owner->config()->get('metadata_tab_enabled'); if ($tabEnabled) { $fields->removeByName('MetaDescription'); $fields->removeByName('ExtraMeta'); $fields->removeByName('Metadata'); $fields->addFieldsToTab( 'Root.Metadata', [ $metaTitleField, $metaURLField, $metaImageField, $metaDescriptionField = TextareaField::create('MetaDescription', $this->owner->fieldLabel('MetaDescription')), $metaExtraField = TextareaField::create('ExtraMeta', $this->owner->fieldLabel('ExtraMeta')) ] ); $metaDescriptionField ->setRightTitle( _t( SiteTree::class.'.METADESCHELP', "Search engines use this content for displaying search results (although it will not influence their ranking)." ) ) ->addExtraClass('help'); $metaExtraField ->setRightTitle( _t( SiteTree::class.'.METAEXTRAHELP', "HTML tags for additional meta information. For example <meta name=\"customName\" content=\"your custom content here\" />" ) ) ->addExtraClass('help'); } else { $fields->insertBefore($metaTitleField, 'MetaDescription'); $fields->insertBefore($metaURLField, 'MetaDescription'); } } public function updateFieldLabels(&$labels) { $labels['MetaTitle'] = _t(SiteTree::class.'.METATITLE', 'Title'); } } |