Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Commit

Permalink
fix(og): do a better job at resolving open graph images
Browse files Browse the repository at this point in the history
  • Loading branch information
hypeJunction committed Oct 25, 2016
1 parent 8ac878f commit 1e99b00
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,23 +452,37 @@ function get_discovery_description($entity) {
], false, false, 'default');
}

/**
* Get discoverable icon object
*
* @param ElggEntity $entity
* @return \ElggIcon|false
*/
function get_discovery_icon($entity) {
foreach (['open_graph_image', 'cover', 'icon'] as $type) {
$icon = $entity->getIcon('large', $type);
if ($icon->exists()) {
return $icon;
}
}
return false;
}

/**
* Get discoverable image URL
*
* @param ElggEntity $entity
* @return string
* @return string|void
*/
function get_discovery_image_url($entity) {

if (!elgg_instanceof($entity) || !is_discoverable($entity)) {
$entity = elgg_get_site_entity();
}

foreach (['open_graph_image', 'cover', 'icon'] as $type) {
$icon = $entity->getIcon('large', $type);
if ($icon->exists()) {
return elgg_get_inline_url($icon);
}
$icon = get_discovery_icon($entity);
if ($icon) {
return elgg_get_inline_url($icon);
}
}

Expand Down

0 comments on commit 1e99b00

Please sign in to comment.