Skip to content

Commit 3cdc0ba

Browse files
committed
[spalenque] - #13908 * add image size to og image meta tag
1 parent f3faa01 commit 3cdc0ba

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

news/code/ui/frontend/NewsOpenGraphObjectExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ public function getOGImage()
3030
$image = $this->owner->Image();
3131
$default_image = Director::absoluteURL('/themes/openstack/images/summit/openstacklogo-fb.png');
3232

33-
return $image->Exists() ? Director::absoluteURL($image->getURL()) : $default_image;
33+
$og_image = new OGImage();
34+
$og_image->Width = 200;
35+
$og_image->Height = 200;
36+
$og_image->AbsoluteURL = Director::absoluteURL($image->getURL());
37+
38+
return $image->Exists() ? $og_image : $default_image;
3439
}
3540

3641
public function getOGTitle()

openstack/code/utils/OGImage.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright 2018 Openstack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
/**
15+
* Object to allow og:image:width
16+
*/
17+
class OGImage implements IMediaFile
18+
{
19+
20+
public $AbsoluteURL, $Width, $Height, $Type;
21+
22+
function getWidth(){
23+
return $this->Width;
24+
}
25+
26+
/**
27+
* Media height in pixels
28+
*
29+
* @return integer
30+
*/
31+
function getHeight(){
32+
return $this->Height;
33+
}
34+
35+
/**
36+
* Media URL
37+
*
38+
* @return string
39+
*/
40+
function getAbsoluteURL(){
41+
return $this->AbsoluteURL;
42+
}
43+
44+
/**
45+
* Media mime type
46+
*
47+
* @return string
48+
*/
49+
function getType(){
50+
return $this->Type;
51+
}
52+
}

0 commit comments

Comments
 (0)