From c42862e15c82d0ffbb45d3bdc2bcfcea2d0c75f6 Mon Sep 17 00:00:00 2001 From: marcus Date: Thu, 31 Jul 2008 13:51:57 +0000 Subject: Closes #151: Introducing getIcon($size) git-svn-id: https://code.elgg.org/elgg/trunk@1629 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'engine/lib/elgglib.php') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 2aabe5c36..abfa28b35 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -277,6 +277,70 @@ return false; } + + /** + * Get the icon for an entity + * + * @param ElggEntity $entity The entity (passed an entity rather than a guid to handle non-created entities) + * @param string $size + */ + function elgg_get_entity_icon_url(ElggEntity $entity, $size = 'medium') + { + global $CONFIG; + + $size = sanitise_string($size); + switch (strtolower($size)) + { + case 'master': + case 'large' : $size = 'large'; break; + + case 'topbar' : + case 'tiny' : $size = 'tiny'; break; + + case 'small' : $size = 'small'; break; + + case 'medium' : + default: $size = 'medium'; + } + + $url = false; + + $view = elgg_get_viewtype(); + $location = elgg_get_view_location($view); + + // Use the object/subtype + $type = $entity->type; + $subtype = $entity->subtype; + + if (!$url) + { + $tmp_url = $location . "{$view}/graphics/icons/$type/$subtype/$size.png"; + if (file_exists($tmp_url)) + $url = $tmp_url; + } + + // Get the default for the object + if (!$url) + { + $tmp_url = $location . "{$view}/graphics/icons/$type/default/$size.png"; + if (file_exists($tmp_url)) + $url = $tmp_url; + } + + // If url still blank then attempt to use the view's defaults + if (!$url) + { + $tmp_url = $location . "{$view}/graphics/icons/default/$size.png"; + if (file_exists($tmp_url)) + $url = $tmp_url; + } + + // If all else fails + if (!$url) + $url = $CONFIG->url . "_graphics/icons/default/$size.png"; + + return $url; + } /** * When given an entity, views it intelligently. -- cgit v1.2.3