diff options
Diffstat (limited to 'views/default/icon')
-rw-r--r-- | views/default/icon/default.php | 32 | ||||
-rw-r--r-- | views/default/icon/user/default.php | 103 |
2 files changed, 130 insertions, 5 deletions
diff --git a/views/default/icon/default.php b/views/default/icon/default.php index 3ef1a05a1..7f13a1189 100644 --- a/views/default/icon/default.php +++ b/views/default/icon/default.php @@ -34,17 +34,39 @@ if (isset($vars['href'])) { $url = $vars['href']; } -$img = elgg_view('output/img', array( +$icon_sizes = elgg_get_config('icon_sizes'); +$size = $vars['size']; + +if (!isset($vars['width'])) { + $vars['width'] = $size != 'master' ? $icon_sizes[$size]['w'] : null; +} +if (!isset($vars['height'])) { + $vars['height'] = $size != 'master' ? $icon_sizes[$size]['h'] : null; +} + +$img_params = array( 'src' => $entity->getIconURL($vars['size']), - 'alt' => $title, - 'class' => $class, -)); + 'alt' => $title, +); + +if (!empty($class)) { + $img_params['class'] = $class; +} + +if (!empty($vars['width'])) { + $img_params['width'] = $vars['width']; +} + +if (!empty($vars['height'])) { + $img_params['height'] = $vars['height']; +} + +$img = elgg_view('output/img', $img_params); if ($url) { $params = array( 'href' => $url, 'text' => $img, - 'title' => $title, 'is_trusted' => true, ); $class = elgg_extract('link_class', $vars, ''); diff --git a/views/default/icon/user/default.php b/views/default/icon/user/default.php new file mode 100644 index 000000000..c0b0e7483 --- /dev/null +++ b/views/default/icon/user/default.php @@ -0,0 +1,103 @@ +<?php +/** + * Elgg user icon + * + * Rounded avatar corners - CSS3 method + * uses avatar as background image so we can clip it with border-radius in supported browsers + * + * @uses $vars['entity'] The user entity. If none specified, the current user is assumed. + * @uses $vars['size'] The size - tiny, small, medium or large. (medium) + * @uses $vars['use_hover'] Display the hover menu? (true) + * @uses $vars['use_link'] Wrap a link around image? (true) + * @uses $vars['class'] Optional class added to the .elgg-avatar div + * @uses $vars['img_class'] Optional CSS class added to img + * @uses $vars['link_class'] Optional CSS class for the link + * @uses $vars['href'] Optional override of the link href + */ + +$user = elgg_extract('entity', $vars, elgg_get_logged_in_user_entity()); +$size = elgg_extract('size', $vars, 'medium'); +if (!in_array($size, array('topbar', 'tiny', 'small', 'medium', 'large', 'master'))) { + $size = 'medium'; +} + +$class = "elgg-avatar elgg-avatar-$size"; +if (isset($vars['class'])) { + $class = "$class {$vars['class']}"; +} + +$use_link = elgg_extract('use_link', $vars, true); + +if (!($user instanceof ElggUser)) { + return true; +} + +$name = htmlspecialchars($user->name, ENT_QUOTES, 'UTF-8', false); +$username = $user->username; + +$icontime = $user->icontime; +if (!$icontime) { + $icontime = "default"; +} + +$js = elgg_extract('js', $vars, ''); +if ($js) { + elgg_deprecated_notice("Passing 'js' to icon views is deprecated.", 1.8, 5); +} + +$img_class = ''; +if (isset($vars['img_class'])) { + $img_class = $vars['img_class']; +} + +$use_hover = elgg_extract('use_hover', $vars, true); +if (isset($vars['override'])) { + elgg_deprecated_notice("Use 'use_hover' rather than 'override' with user avatars", 1.8, 5); + $use_hover = false; +} +if (isset($vars['hover'])) { + // only 1.8.0 was released with 'hover' as the key + $use_hover = $vars['hover']; +} + +$spacer_url = elgg_get_site_url() . '_graphics/spacer.gif'; + +$icon_url = elgg_format_url($user->getIconURL($size)); +$icon = elgg_view('output/img', array( + 'src' => $spacer_url, + 'alt' => $name, + 'title' => $name, + 'class' => $img_class, + 'style' => "background: url($icon_url) no-repeat;", +)); + +$show_menu = $use_hover && (elgg_is_admin_logged_in() || !$user->isBanned()); + +?> +<div class="<?php echo $class; ?>"> +<?php + +if ($show_menu) { + $params = array( + 'entity' => $user, + 'username' => $username, + 'name' => $name, + ); + echo elgg_view_icon('hover-menu'); + echo elgg_view_menu('user_hover', $params); +} + +if ($use_link) { + $class = elgg_extract('link_class', $vars, ''); + $url = elgg_extract('href', $vars, $user->getURL()); + echo elgg_view('output/url', array( + 'href' => $url, + 'text' => $icon, + 'is_trusted' => true, + 'class' => $class, + )); +} else { + echo "<a>$icon</a>"; +} +?> +</div> |