aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--documentation/theming/preview/icons.php21
-rw-r--r--engine/classes/ElggEntity.php41
-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
-rw-r--r--js/lib/ui.js8
-rw-r--r--mod/pages/views/default/pages/icon.php4
-rw-r--r--views/default/css/elements/icons.php42
-rw-r--r--views/default/input/userpicker.php2
-rw-r--r--views/default/page/elements/topbar.php2
-rw-r--r--views/default/profile/icon.php71
-rw-r--r--views/foaf/page/shells/default.php7
14 files changed, 221 insertions, 223 deletions
diff --git a/documentation/theming/preview/icons.php b/documentation/theming/preview/icons.php
index 2a3a9bb7e..665f1f817 100644
--- a/documentation/theming/preview/icons.php
+++ b/documentation/theming/preview/icons.php
@@ -36,6 +36,27 @@ $url = current_page_url();
<div class="mbl">
<?php echo elgg_view('graphics/ajax_loader', array('hidden' => false)); ?>
</div>
+ <h2>Avatars</h2>
+ <div class="mbl">
+ <?php
+ $user = new ElggUser();
+ $sizes = array('large', 'medium', 'small', 'tiny');
+ echo '<table>';
+ echo '<tr>';
+ foreach ($sizes as $size) {
+ echo "<td class=\"center\"><h4>$size</h4></td>";
+ }
+ echo '</tr>';
+ echo '<tr>';
+ foreach ($sizes as $size) {
+ echo '<td class="phs">';
+ echo elgg_view_entity_icon($user, $size, array('hover' => false));
+ echo '</td>';
+ }
+ echo '</tr>';
+ echo '</table>';
+ ?>
+ </div>
</div>
</body>
</html> \ No newline at end of file
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php
index 21aa72561..5e43ab582 100644
--- a/engine/classes/ElggEntity.php
+++ b/engine/classes/ElggEntity.php
@@ -833,18 +833,49 @@ abstract class ElggEntity extends ElggData implements
}
/**
+ * Get the URL for this entity's icon
+ *
+ * Plugins can register for the 'entity:icon:url', <type> plugin hook
+ * to customize the icon for an entity.
+ *
+ * @param string $size Size of the icon: tiny, small, medium, large
+ *
+ * @return string The URL
+ * @since 1.8.0
+ */
+ public function getIconURL($size = 'medium') {
+ $size = elgg_strtolower($size);
+
+ if (isset($this->icon_override[$size])) {
+ elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8);
+ return $this->icon_override[$size];
+ }
+
+ $url = "_graphics/icons/default/$size.png";
+ $url = elgg_normalize_url($url);
+
+ $type = $this->getType();
+ $params = array(
+ 'entity' => $this,
+ 'size' => $size,
+ );
+
+ $url = elgg_trigger_plugin_hook('entity:icon:url', $type, $params, $url);
+
+ return elgg_normalize_url($url);
+ }
+
+ /**
* Returns a URL for the entity's icon.
*
* @param string $size Either 'large', 'medium', 'small' or 'tiny'
*
* @return string The url or false if no url could be worked out.
- * @see get_entity_icon_url()
+ * @deprecated Use getIconURL()
*/
public function getIcon($size = 'medium') {
- if (isset($this->icon_override[$size])) {
- return $this->icon_override[$size];
- }
- return get_entity_icon_url($this, $size);
+ elgg_deprecated_notice("getIcon() deprecated by getIconURL()", 1.8);
+ return $this->getIconURL($size);
}
/**
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.
diff --git a/js/lib/ui.js b/js/lib/ui.js
index bf918cbf4..2ea0ccc46 100644
--- a/js/lib/ui.js
+++ b/js/lib/ui.js
@@ -94,7 +94,7 @@ elgg.ui.initHoverMenu = function(parent) {
}
// avatar image menu link
- $(parent).find(".elgg-user-icon").mouseover(function() {
+ $(parent).find(".elgg-avatar").mouseover(function() {
$(this).children(".elgg-icon-hover-menu").show();
})
.mouseout(function() {
@@ -103,7 +103,7 @@ elgg.ui.initHoverMenu = function(parent) {
// avatar contextual menu
- $(".elgg-user-icon > .elgg-icon-hover-menu").click(function(e) {
+ $(".elgg-avatar > .elgg-icon-hover-menu").click(function(e) {
var $hovermenu = $(this).parent().find(".elgg-hover-menu");
@@ -111,7 +111,7 @@ elgg.ui.initHoverMenu = function(parent) {
if ($hovermenu.css('display') == "block") {
$hovermenu.fadeOut();
} else {
- $avatar = $(this).closest(".elgg-user-icon");
+ $avatar = $(this).closest(".elgg-avatar");
$hovermenu.css("top", ($avatar.height()) + "px")
.css("left", ($avatar.width()-15) + "px")
.fadeIn('normal');
@@ -123,7 +123,7 @@ elgg.ui.initHoverMenu = function(parent) {
// hide avatar menu when user clicks elsewhere
$(document).click(function(event) {
- if ($(event.target).parents(".elgg-user-icon").length == 0) {
+ if ($(event.target).parents(".elgg-avatar").length == 0) {
$(".elgg-hover-menu").fadeOut();
}
});
diff --git a/mod/pages/views/default/pages/icon.php b/mod/pages/views/default/pages/icon.php
index fd084bca7..ede0e49d1 100644
--- a/mod/pages/views/default/pages/icon.php
+++ b/mod/pages/views/default/pages/icon.php
@@ -24,4 +24,6 @@ if (!empty($vars['align'])) {
?>
-<a href="<?php echo $annotation->getURL(); ?>"><img src="<?php echo $entity->getIcon($vars['size']); ?>" <?php echo $align; ?> /></a>
+<a href="<?php echo $annotation->getURL(); ?>">
+ <img src="<?php echo $entity->getIconURL($vars['size']); ?>" <?php echo $align; ?> />
+</a>
diff --git a/views/default/css/elements/icons.php b/views/default/css/elements/icons.php
index 18ea4899e..3f9121eb1 100644
--- a/views/default/css/elements/icons.php
+++ b/views/default/css/elements/icons.php
@@ -69,7 +69,7 @@
.elgg-icon-hover-menu:hover {
background-position: -150px -32px;
}
-.elgg-user-icon > .elgg-icon-hover-menu {
+.elgg-avatar > .elgg-icon-hover-menu {
display: none;
position: absolute;
right: 0;
@@ -78,26 +78,27 @@
cursor: pointer;
}
-<?php //@todo prefix with elgg- ?>
.elgg-ajax-loader {
background-color: white;
background-image: url(<?php echo elgg_get_site_url(); ?>_graphics/ajax_loader_bw.gif);
background-repeat: no-repeat;
background-position: center center;
- min-height:33px;
- min-width:33px;
+ min-height: 33px;
+ min-width: 33px;
}
/* ***************************************
AVATAR ICONS
*************************************** */
-.elgg-user-icon {
- position:relative;
+.elgg-avatar {
+ position: relative;
}
-.elgg-user-icon.tiny,
-img.tiny {
- width:25px;
- height:25px;
+.elgg-avatar > a > img {
+ display: block;
+}
+.elgg-avatar-tiny > a > img {
+ width: 25px;
+ height: 25px;
/* remove the border-radius if you don't want rounded avatars in supported browsers */
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
@@ -108,10 +109,9 @@ img.tiny {
-khtml-background-size: 25px;
-moz-background-size: 25px;
}
-.elgg-user-icon.small,
-img.small {
- width:40px;
- height:40px;
+.elgg-avatar-small > a > img {
+ width: 40px;
+ height: 40px;
/* remove the border-radius if you don't want rounded avatars in supported browsers */
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
@@ -122,11 +122,11 @@ img.small {
-khtml-background-size: 40px;
-moz-background-size: 40px;
}
-img.large {
- width:200px;
- height:200px;
+.elgg-avatar-medium > a > img {
+ width: 100px;
+ height: 100px;
+}
+.elgg-avatar-large > a > img {
+ width: 200px;
+ height: 200px;
}
-img.medium {
- width:100px;
- height:100px;
-} \ No newline at end of file
diff --git a/views/default/input/userpicker.php b/views/default/input/userpicker.php
index 20198d236..c9cfe2d8f 100644
--- a/views/default/input/userpicker.php
+++ b/views/default/input/userpicker.php
@@ -26,7 +26,7 @@ function user_picker_add_user($user_id) {
return FALSE;
}
- $icon = $user->getIcon('tiny');
+ $icon = $user->getIconURL('tiny');
$code = '<li class="user-picker-entry">';
$code .= "<img class=\"livesearch_icon\" src=\"$icon\" />";
diff --git a/views/default/page/elements/topbar.php b/views/default/page/elements/topbar.php
index 31d709b7b..40306fcc3 100644
--- a/views/default/page/elements/topbar.php
+++ b/views/default/page/elements/topbar.php
@@ -22,7 +22,7 @@ echo elgg_view('output/url', array(
// avatar
$user_link = $user->getURL();
-$user_image = $user->getIcon('topbar');
+$user_image = $user->getIconURL('topbar');
$image = "<img src=\"$user_image\" alt=\"$user->name\" class=\"elgg-border-plain\" />";
echo elgg_view('output/url', array(
'href' => $user_link,
diff --git a/views/default/profile/icon.php b/views/default/profile/icon.php
index 5685c0a73..1a36ca3cd 100644
--- a/views/default/profile/icon.php
+++ b/views/default/profile/icon.php
@@ -1,77 +1,16 @@
<?php
/**
* Elgg profile icon
- *
+ *
+ * @deprecated 1.8 use elgg_view_entity_icon()
+ *
* @uses $vars['entity'] The user entity. If none specified, the current user is assumed.
* @uses $vars['size'] The size - small, medium or large. If none specified, medium is assumed.
- * @uses $vars['align']
* @uses $vars['override']
* @uses $vars['js']
*/
-$user = elgg_get_array_value('entity', $vars, get_loggedin_user());
-$size = elgg_get_array_value('size', $vars, 'medium');
-if (!in_array($size, array('topbar', 'tiny', 'small', 'medium', 'large', 'master'))) {
- $size = 'medium';
-}
-
-if (!($user instanceof ElggUser)) {
- return true;
-}
-
-$name = htmlspecialchars($user->name, ENT_QUOTES, 'UTF-8');
-$username = $user->username;
-
-$icontime = $user->icontime;
-if (!$icontime) {
- $icontime = "default";
-}
-
-$js = elgg_get_array_value('js', $vars, '');
-
-// Get any align and js
-if (!empty($vars['align'])) {
- $align = " align=\"{$vars['align']}\" ";
-} else {
- $align = '';
-}
-
$override = elgg_get_array_value('override', $vars, false);
+$vars['hover'] = !$override;
-$spacer_url = elgg_get_site_url() . '_graphics/spacer.gif';
-$icon_url = $user->getIcon($size);
-$icon = "<img src=\"$spacer_url\" $align alt=\"$name\" title=\"$name\" $js style=\"background: url($icon_url) no-repeat;\" class=\"$size\" />";
-
-// no hover menu if override set
-if ($override) {
- echo $icon;
- return true;
-}
-
-?>
-<div class="elgg-user-icon <?php echo $size; ?>">
-<?php
-$params = array(
- 'entity' => $user,
- 'username' => $username,
- 'name' => $name,
-);
-echo elgg_view('profile/hover', $params);
-
-if ((isadminloggedin()) || (!$user->isBanned())) {
-?>
- <a href="<?php echo $user->getURL(); ?>" class="icon" >
-<?php
-}
-
-// Rounded avatar corners - CSS3 method
-// users avatar as background image so we can clip it with border-radius in supported browsers
-echo $icon;
-
-if ((isadminloggedin()) || (!$user->isBanned())) {
-?>
- </a>
-<?php
-}
-?>
-</div>
+echo elgg_view('icon/user/default', $vars);
diff --git a/views/foaf/page/shells/default.php b/views/foaf/page/shells/default.php
index 1cd0ed82e..d360f209b 100644
--- a/views/foaf/page/shells/default.php
+++ b/views/foaf/page/shells/default.php
@@ -1,10 +1,12 @@
<?php
/**
- * Elgg XML output pageshell
+ * FOAF pageshell
*
* @package Elgg
* @subpackage Core
*
+ * // @todo removed below because blog is a plugin
+ * <foaf:weblog rdf:resource="<?php echo elgg_get_site_url(); ?>pg/blog/<?php echo $owner->username; ?>" />
*/
header("Content-Type: text/xml");
@@ -39,8 +41,7 @@ if (!$owner = elgg_get_page_owner_entity()) {
<foaf:nick><?php echo $owner->username; ?></foaf:nick>
<foaf:name><?php echo $owner->name; ?></foaf:name>
<foaf:homepage rdf:resource="<?php echo $owner->getURL(); ?>" />
- <foaf:depiction rdf:resource="<?php echo elgg_format_url($owner->getIcon('large')); ?>" />
- <foaf:weblog rdf:resource="<?php echo elgg_get_site_url(); ?>pg/blog/<?php echo $owner->username; ?>" />
+ <foaf:depiction rdf:resource="<?php echo elgg_format_url($owner->getIconURL('large')); ?>" />
<?php
echo $vars['body'];
?>