aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_graphics/icons/default/large.pngbin0 -> 4415 bytes
-rw-r--r--_graphics/icons/default/medium.pngbin0 -> 1772 bytes
-rw-r--r--_graphics/icons/default/small.pngbin0 -> 726 bytes
-rw-r--r--_graphics/icons/default/tiny.pngbin0 -> 555 bytes
-rw-r--r--engine/lib/elgglib.php64
-rw-r--r--engine/lib/entities.php38
6 files changed, 101 insertions, 1 deletions
diff --git a/_graphics/icons/default/large.png b/_graphics/icons/default/large.png
new file mode 100644
index 000000000..b84df49c7
--- /dev/null
+++ b/_graphics/icons/default/large.png
Binary files differ
diff --git a/_graphics/icons/default/medium.png b/_graphics/icons/default/medium.png
new file mode 100644
index 000000000..b207f839a
--- /dev/null
+++ b/_graphics/icons/default/medium.png
Binary files differ
diff --git a/_graphics/icons/default/small.png b/_graphics/icons/default/small.png
new file mode 100644
index 000000000..e4f69174a
--- /dev/null
+++ b/_graphics/icons/default/small.png
Binary files differ
diff --git a/_graphics/icons/default/tiny.png b/_graphics/icons/default/tiny.png
new file mode 100644
index 000000000..68173f524
--- /dev/null
+++ b/_graphics/icons/default/tiny.png
Binary files differ
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.
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 663ac9c4e..47ad8f89c 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -43,7 +43,12 @@
/**
* If set, overrides the value of getURL()
*/
- protected $url_override;
+ protected $url_override;
+
+ /**
+ * Icon override, overrides the value of getIcon().
+ */
+ protected $icon_override;
/**
* Temporary cache for metadata, permitting meta data access before a guid has obtained.
@@ -498,6 +503,36 @@
}
/**
+ * Return a url for the entity's icon, trying multiple alternatives.
+ *
+ * @param string $size Either 'large','medium','small' or 'tiny'
+ * @return string The url or false if no url could be worked out.
+ */
+ public function getIcon($size = 'medium')
+ {
+ if (isset($this->icon_override[$size])) return $this->icon_override[$size];
+ return elgg_get_entity_icon_url($this, $size);
+ }
+
+ /**
+ * Set an icon override for an icon and size.
+ *
+ * @param string $url The url of the icon.
+ * @param string $size The size its for.
+ * @return bool
+ */
+ public function setIcon($url, $size = 'medium')
+ {
+ $url = sanitise_string($url);
+ $size = sanitise_string($size);
+
+ if (!$this->icon_override) $this->icon_override = array();
+ $this->icon_override[$size] = $url;
+
+ return true;
+ }
+
+ /**
* Tests to see whether the object has been fully loaded.
*
* @return bool
@@ -1632,6 +1667,7 @@
}
+
/**
* Gets the URL for an entity, given a particular GUID
*