Source of file OpenGraphExtension.php
Size: 2,728 Bytes - Last Modified: 2021-12-23T10:38:30+00:00
/var/www/docs.ssmods.com/process/src/code/OpenGraphExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 | <?php class OpenGraphExtension extends DataExtension { public static $keys = array( 'title', 'type', 'image', 'image:width', 'image:height', 'url', 'description', 'determiner', 'locale', 'locale:alternate', 'site_name', 'audio', 'video' ); private function getCanonicalURL($url) { return Director::protocolAndHost() . $url; } public function getOpenGraph_type() { return 'website'; } public function getOpenGraph_locale() { return i18n::get_locale(); } public function getOpenGraph_description() { return $this->owner->MetaDescription; } public function getOpenGraph_site_name() { return SiteConfig::current_site_config()->Title; } public function getOpenGraphImage() { $page = $this->owner->data(); $tries = array('HeroImage', 'PostImage', 'Image', 'FeaturedImage'); foreach($tries as $t) { $i = $page->hasOneComponent($t); if($i) { return $page->getComponent($t); } } return null; } public function getOpenGraph_image_height() { $im = $this->owner->getOpenGraphImage(); if($im && $im->exists()) { return $im->Height; } } public function getOpenGraph_image_width() { $im = $this->owner->getOpenGraphImage(); if($im && $im->exists()) { return $im->Width; } } public function getOpenGraph_image() { $im = $this->owner->getOpenGraphImage(); if($im && $im->exists()) { return $this->getCanonicalURL($im->URL); } } public function getOpenGraph_title() { return $this->owner->Title; } public function getOpenGraph_url() { $page = $this->owner; return $this->getCanonicalUrl($page->XML_val('Link')); } public function getOpenGraph_determiner() { return null; } public function getOpenGraph_audio() { return null; } public function getOpenGraph_video() { return null; } public function getOpenGraph_locale_alternate() { return null; } public function getOpenGraph() { $tags = ''; foreach(OpenGraphExtension::$keys as $k) { $key = str_replace(':', '_', $k); $action = "getOpenGraph_$key"; $val = $this->owner->$action(); if($val) { $val = Convert::raw2att($val); $tags .= "<meta property=\"og:$k\" content=\"$val\" />\n"; } } return $tags; } } |