]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2559 refs #2475 added ElggEntity:getIconURL() and elgg_view_entity_icon()
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 5 Feb 2011 22:46:28 +0000 (22:46 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 5 Feb 2011 22:46:28 +0000 (22:46 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8039 36083f99-b078-4883-b0ff-0f9b5a30f544

14 files changed:
documentation/theming/preview/icons.php
engine/classes/ElggEntity.php
engine/lib/deprecated-1.8.php
engine/lib/entities.php
engine/lib/input.php
engine/lib/users.php
engine/lib/views.php
js/lib/ui.js
mod/pages/views/default/pages/icon.php
views/default/css/elements/icons.php
views/default/input/userpicker.php
views/default/page/elements/topbar.php
views/default/profile/icon.php
views/foaf/page/shells/default.php

index 2a3a9bb7e0753bea1d440ddda0af2d76b282497c..665f1f817e39b905181411c4f103d05c14dc8dbd 100644 (file)
@@ -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
index 21aa72561d49d1e657b0fb0677e514dbe7c81104..5e43ab5824ecd84093cf4bdf8db288468add238f 100644 (file)
@@ -832,19 +832,50 @@ abstract class ElggEntity extends ElggData implements
                return $url;
        }
 
+       /**
+        * 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);
        }
 
        /**
index 3db32c5226c23c73e4899f079e811f8cc572f38a..f293c178f1d38620fae37323430eeb389c65b1e2 100644 (file)
@@ -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);
+}
index 2a3c6ba9108c9d49365661852bac72694ab0a8bd..ac2679dfcce04f70b15c5b7696daae70fefe6ddb 100644 (file)
@@ -1758,79 +1758,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.
  *
@@ -1869,7 +1796,6 @@ function get_entity_url($entity_guid) {
                }
 
                return elgg_normalize_url($url);
-
        }
 
        return false;
@@ -1908,46 +1834,6 @@ $entity_subtype = "all") {
        return true;
 }
 
-/**
- * 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');
index 76daf5fa3eff277fe6817481bb1d93bf6f6e1caa..5ec34787732aa8e84d0212a061841845be5a6eb4 100644 (file)
@@ -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;
index 567f587ead5e4b27432f6408f4c602153bb4de24..be7399a44130081442abb77c6145fea71c644f18 100644 (file)
@@ -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";
+       }
 }
 
 /**
index e20c98929c35aeaaebc7359e6d681d9d5a558e3f..56325ebda76a3c6c6e1f4de27cfda3aff416a6c0 100644 (file)
@@ -773,6 +773,47 @@ function elgg_view_entity(ElggEntity $entity, $full = false, $bypass = true, $de
        return $contents;
 }
 
+/**
+ * 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.
  *
index bf918cbf4fe32897eca11ab205e0c3f4c6ad491c..2ea0ccc46ed6316e2d992f1ab7f6d7677b83fde2 100644 (file)
@@ -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();
                }
        });
index fd084bca78d6b9ebe1468d0711faf7fb6407d9d2..ede0e49d10a89cb5d1cd94f64360d7f490c243a3 100644 (file)
@@ -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>
index 18ea4899e52774b75dd4b030272b905b179ec1ac..3f9121eb15645ae265df6215e082d4f2c5417629 100644 (file)
@@ -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;
        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
index 20198d2362330abc601eedbd13e50cfa2c5b0c20..c9cfe2d8fcbff0c0ba8920f8add3afdecc643997 100644 (file)
@@ -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\" />";
index 31d709b7b60ab988919fa249c151cc8a04c6f7ec..40306fcc3115953a31b7661c577f85124af542d7 100644 (file)
@@ -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,
index 5685c0a73c096a9a8448b255be9f3ed5b2f6faa4..1a36ca3cdb966a3d6578125fd738a98dd21a8ac5 100644 (file)
@@ -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);
index 1cd0ed82e01534393ffe153db38a7f4c60de2b10..d360f209b03a18020d0e4788071f98da9293799a 100644 (file)
@@ -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'];
                ?>