aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-05 22:46:28 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-05 22:46:28 +0000
commite5227e9221edbce84eee82af7f2c9903de702f37 (patch)
tree5e402b5508a8af64ff40761087926dd0f9443303 /engine/lib
parent577eb6f725449fea5738ca122eedb5e4b2c8ff56 (diff)
downloadelgg-e5227e9221edbce84eee82af7f2c9903de702f37.tar.gz
elgg-e5227e9221edbce84eee82af7f2c9903de702f37.tar.bz2
Fixes #2559 refs #2475 added ElggEntity:getIconURL() and elgg_view_entity_icon()
git-svn-id: http://code.elgg.org/elgg/trunk@8039 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/deprecated-1.8.php75
-rw-r--r--engine/lib/entities.php117
-rw-r--r--engine/lib/input.php2
-rw-r--r--engine/lib/users.php11
-rw-r--r--engine/lib/views.php41
5 files changed, 125 insertions, 121 deletions
diff --git a/engine/lib/deprecated-1.8.php b/engine/lib/deprecated-1.8.php
index 3db32c522..f293c178f 100644
--- a/engine/lib/deprecated-1.8.php
+++ b/engine/lib/deprecated-1.8.php
@@ -2837,3 +2837,78 @@ function elgg_view_listing($icon, $info) {
elgg_deprecated_notice('elgg_view_listing deprecated by elgg_view_image_block', 1.8);
return elgg_view('layout/objects/image_block', array('image' => $icon, 'body' => $info));
}
+
+/**
+ * Return the icon URL for an entity.
+ *
+ * @tip Can be overridden by registering a plugin hook for entity:icon:url, $entity_type.
+ *
+ * @internal This is passed an entity rather than a guid to handle non-created entities.
+ *
+ * @param ElggEntity $entity The entity
+ * @param string $size Icon size
+ *
+ * @return string URL to the entity icon.
+ * @deprecated 1.8 Use $entity->getIconURL()
+ */
+function get_entity_icon_url(ElggEntity $entity, $size = 'medium') {
+ elgg_deprecated_notice("get_entity_icon_url() deprecated for getIconURL()", 1.8);
+ global $CONFIG;
+
+ $size = sanitise_string($size);
+ switch (strtolower($size)) {
+ case 'master':
+ $size = 'master';
+ break;
+
+ case 'large' :
+ $size = 'large';
+ break;
+
+ case 'topbar' :
+ $size = 'topbar';
+ break;
+
+ case 'tiny' :
+ $size = 'tiny';
+ break;
+
+ case 'small' :
+ $size = 'small';
+ break;
+
+ case 'medium' :
+ default:
+ $size = 'medium';
+ }
+
+ $url = false;
+
+ $viewtype = elgg_get_viewtype();
+
+ // Step one, see if anyone knows how to render this in the current view
+ $params = array('entity' => $entity, 'viewtype' => $viewtype, 'size' => $size);
+ $url = elgg_trigger_plugin_hook('entity:icon:url', $entity->getType(), $params, $url);
+
+ // Fail, so use default
+ if (!$url) {
+ $type = $entity->getType();
+ $subtype = $entity->getSubtype();
+
+ if (!empty($subtype)) {
+ $overrideurl = elgg_view("icon/{$type}/{$subtype}/{$size}", array('entity' => $entity));
+ if (!empty($overrideurl)) {
+ return $overrideurl;
+ }
+ }
+
+ $overrideurl = elgg_view("icon/{$type}/default/{$size}", array('entity' => $entity));
+ if (!empty($overrideurl)) {
+ return $overrideurl;
+ }
+
+ $url = "_graphics/icons/default/$size.png";
+ }
+
+ return elgg_normalize_url($url);
+}
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 2a3c6ba91..ac2679dfc 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1759,79 +1759,6 @@ function can_edit_entity_metadata($entity_guid, $user_guid = 0, $metadata = null
}
/**
- * Return the icon URL for an entity.
- *
- * @tip Can be overridden by registering a plugin hook for entity:icon:url, $entity_type.
- *
- * @internal This is passed an entity rather than a guid to handle non-created entities.
- *
- * @param ElggEntity $entity The entity
- * @param string $size Icon size
- *
- * @return string URL to the entity icon.
- */
-function get_entity_icon_url(ElggEntity $entity, $size = 'medium') {
- global $CONFIG;
-
- $size = sanitise_string($size);
- switch (strtolower($size)) {
- case 'master':
- $size = 'master';
- break;
-
- case 'large' :
- $size = 'large';
- break;
-
- case 'topbar' :
- $size = 'topbar';
- break;
-
- case 'tiny' :
- $size = 'tiny';
- break;
-
- case 'small' :
- $size = 'small';
- break;
-
- case 'medium' :
- default:
- $size = 'medium';
- }
-
- $url = false;
-
- $viewtype = elgg_get_viewtype();
-
- // Step one, see if anyone knows how to render this in the current view
- $params = array('entity' => $entity, 'viewtype' => $viewtype, 'size' => $size);
- $url = elgg_trigger_plugin_hook('entity:icon:url', $entity->getType(), $params, $url);
-
- // Fail, so use default
- if (!$url) {
- $type = $entity->getType();
- $subtype = $entity->getSubtype();
-
- if (!empty($subtype)) {
- $overrideurl = elgg_view("icon/{$type}/{$subtype}/{$size}", array('entity' => $entity));
- if (!empty($overrideurl)) {
- return $overrideurl;
- }
- }
-
- $overrideurl = elgg_view("icon/{$type}/default/{$size}", array('entity' => $entity));
- if (!empty($overrideurl)) {
- return $overrideurl;
- }
-
- $url = "_graphics/icons/default/$size.png";
- }
-
- return elgg_normalize_url($url);
-}
-
-/**
* Returns the URL for an entity.
*
* @tip Can be overridden with {@link register_entity_url_handler()}.
@@ -1869,7 +1796,6 @@ function get_entity_url($entity_guid) {
}
return elgg_normalize_url($url);
-
}
return false;
@@ -1909,46 +1835,6 @@ $entity_subtype = "all") {
}
/**
- * Default Icon handler for entities.
- *
- * @tip This will attempt to find a default entity for the current view and return a url.
- * This is registered at a high priority so that other handlers will pick it up first.
- *
- * @param string $hook entity:icon:url
- * @param string $entity_type all
- * @param mixed $returnvalue Previous hook's return value
- * @param array $params Array of params
- *
- * @return string|null String of URL for entity's icon
- * @elgg_plugin_hook_handler entity:icon:url all
- */
-function default_entity_icon_hook($hook, $entity_type, $returnvalue, $params) {
- global $CONFIG;
-
- if ((!$returnvalue) && ($hook == 'entity:icon:url')) {
- $entity = $params['entity'];
- $type = $entity->type;
- $subtype = get_subtype_from_id($entity->subtype);
- $viewtype = $params['viewtype'];
- $size = $params['size'];
-
- $url = "views/$viewtype/graphics/icons/$type/$subtype/$size.png";
-
- if (!@file_exists($CONFIG->path . $url)) {
- $url = "views/$viewtype/graphics/icons/$type/default/$size.png";
- }
-
- if (!@file_exists($CONFIG->path . $url)) {
- $url = "views/$viewtype/graphics/icons/default/$size.png";
- }
-
- if (@file_exists($CONFIG->path . $url)) {
- return elgg_get_site_url() . $url;
- }
- }
-}
-
-/**
* Registers an entity type and subtype as a public-facing entity that should
* be shown in search and by {@link elgg_list_registered_entities()}.
*
@@ -2311,8 +2197,5 @@ elgg_register_plugin_hook_handler("export", "all", "export_entity_plugin_hook",
/** Hook to get certain named bits of volatile data about an entity */
elgg_register_plugin_hook_handler('volatile', 'metadata', 'volatile_data_export_plugin_hook');
-/** Hook for rendering a default icon for entities */
-elgg_register_plugin_hook_handler('entity:icon:url', 'all', 'default_entity_icon_hook', 1000);
-
/** Register init system event **/
elgg_register_event_handler('init', 'system', 'entities_init');
diff --git a/engine/lib/input.php b/engine/lib/input.php
index 76daf5fa3..5ec347877 100644
--- a/engine/lib/input.php
+++ b/engine/lib/input.php
@@ -168,7 +168,7 @@ function input_livesearch_page_handler($page) {
'name' => $entity->name,
'desc' => $entity->username,
'icon' => '<img class="livesearch_icon" src="' .
- get_entity($entity->guid)->getIcon('tiny') . '" />',
+ get_entity($entity->guid)->getIconURL('tiny') . '" />',
'guid' => $entity->guid
));
$results[$entity->name . rand(1, 100)] = $json;
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 567f587ea..be7399a44 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -1276,10 +1276,15 @@ function user_create_hook_add_site_relationship($event, $object_type, $object) {
* @param array $params
* @return string
*/
-function user_avatar_hook($hook, $entity_type, $returnvalue, $params){
- $entity = $params['entity'];
+function user_avatar_hook($hook, $entity_type, $returnvalue, $params) {
+ $user = $params['entity'];
$size = $params['size'];
- return "pg/avatar/view/{$entity->username}?size=$size";
+
+ if (isset($user->icontime)) {
+ return "pg/avatar/view/$user->username?size=$size";
+ } else {
+ return "_graphics/icons/user/default{$size}.gif";
+ }
}
/**
diff --git a/engine/lib/views.php b/engine/lib/views.php
index e20c98929..56325ebda 100644
--- a/engine/lib/views.php
+++ b/engine/lib/views.php
@@ -774,6 +774,47 @@ function elgg_view_entity(ElggEntity $entity, $full = false, $bypass = true, $de
}
/**
+ * View the icon of an entity
+ *
+ * Entity views are determined by having a view named after the entity $type/$subtype.
+ * Entities that do not have a defined icon/$type/$subtype view will fall back to using
+ * the icon/$type/default view.
+ *
+ * @param ElggEntity $entity The entity to display
+ * @param string $string The size: tiny, small, medium, large
+ * @param array $vars An array of variables to pass to the view
+ *
+ * @return string HTML to display or false
+ */
+function elgg_view_entity_icon(ElggEntity $entity, $size = 'medium', $vars = array()) {
+
+ // No point continuing if entity is null
+ if (!$entity || !($entity instanceof ElggEntity)) {
+ return false;
+ }
+
+ $vars['entity'] = $entity;
+ $vars['size'] = $size;
+
+ $entity_type = $entity->getType();
+
+ $subtype = $entity->getSubtype();
+ if (empty($subtype)) {
+ $subtype = 'default';
+ }
+
+ $contents = '';
+ if (elgg_view_exists("icon/$entity_type/$subtype")) {
+ $contents = elgg_view("icon/$entity_type/$subtype", $vars);
+ }
+ if (empty($contents)) {
+ $contents = elgg_view("icon/$entity_type/default", $vars);
+ }
+
+ return $contents;
+}
+
+/**
* Returns a string of a rendered annotation.
*
* Annotation views are expected to be in annotation/$annotation_name.