-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathPageOpenGraphObjectExtension.php
More file actions
89 lines (73 loc) · 2.92 KB
/
Copy pathPageOpenGraphObjectExtension.php
File metadata and controls
89 lines (73 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Copyright 2016 Open Infrastructure Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
final class TwitterCardMetadataBuilder
{
public static function buildTwitterCardMetaTags(&$tags){
// IOS
$tags .= '<meta name="twitter:card" content="summary" />'.PHP_EOL;
$tags .= sprintf('<meta name="twitter:site" content="%s" />', OPENSTACK_TWITTER_ACCOUNT).PHP_EOL;
}
}
class PageOpenGraphObjectExtension extends OpenGraphObjectExtension
{
public static $default_image = 'images/openstack-logo-full.png';
public function MetaTags(&$tags)
{
parent::MetaTags($tags);
$this->buildAppLinksMetaTags($tags);
}
protected function buildAppLinksMetaTags(&$tags){
TwitterCardMetadataBuilder::buildTwitterCardMetaTags($tags);
}
public function getMetaValue($field_name) {
$field_value = '';
$parent = $this->owner->Parent();
if ($this->owner->hasMethod($field_name) || $this->owner->getField($field_name)) {
if ($field_name == 'MetaImage' && $this->owner->MetaImage()->Exists()) {
return $this->owner->MetaImage();
} else if ($this->owner->getField($field_name) != '') {
return $this->owner->getField($field_name);
}
}
while( $parent && $parent->exists() ) {
if ($parent->hasMethod($field_name)) {
if ($field_name == 'MetaImage' && $parent->MetaImage()->Exists()) {
$field_value = $parent->$field_name();
break;
} else if ($parent->getField($field_name)) {
$field_value = $parent->getField($field_name);
break;
}
}
$parent = $parent->Parent();
}
return $field_value;
}
public function getOGImage()
{
$meta_image = $this->getMetaValue('MetaImage');
if ($meta_image && $meta_image->Exists())
return Director::absoluteurl($meta_image->getURL());
return Director::absoluteurl(CloudAssetTemplateHelpers::cloud_url(self::$default_image));
}
public function getOGTitle()
{
$meta_title = $this->getMetaValue('MetaTitle');
if($meta_title) {
$title = trim($meta_title);
if(!empty($title)) return $title;
}
return $this->owner->Title." - OpenStack Open Source Cloud Computing Software";
}
}