Substitution of User Pics?
Nov. 10th, 2008 10:23 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
(Probably only of interest to
camomiletea,
scaryjeff,
afuna, or anyone else in Styles support)
There was a recent request about substituting a user's default userpic for the one they'd selected for a particular post. We figured it was possible through S2, but we don't give that level of detail through Support. I found out something interesting while trying to figure it out for myself...
The S2 Core stores the entry user icon in
Maybe
afuna or someone who knows the back-end better knows why, but I guess you can't re-cast a
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
There was a recent request about substituting a user's default userpic for the one they'd selected for a particular post. We figured it was possible through S2, but we don't give that level of detail through Support. I found out something interesting while trying to figure it out for myself...
The S2 Core stores the entry user icon in
$userpic
, an Image member of the EntryLite
class (usually called in print_entry()
like $e.userpic.url
). A user's default icon is stored in the User
class, which is derived from UserLite
. EntryLite
class also contains a UserLite
object called $poster
, the author of the entry. Since Expressive (unlike other layouts) passes the EntryLite
object into print_entry()
directly, I thought I could get away with something like this:
var User u = $e.poster as User;
var Image def_pic = $u.default_pic;
var string userpic = ($showuserpic and defined $e.userpic) ? ($def_pic + "<br />") : "";
It compiles, but it doesn't work, it just comes up with an empty string. Even trying to isolate the Image members doesn't work:var string pic_url = """<img src="$def_pic.url" alt="$e.userpic.alttext" title="$e.poster.name" height="$def_pic.height" width="$def_pic.width" />""";
Maybe
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
UserLite
object like you can an EntryLite
(print_entry()
in Expressive re-casts the EntryLite
argument into a Comment or Entry object, depending on the type). Even if the preceding were possible, this approach wouldn't work in most layers anyway, because they call print_entry()
on Entry
objects.
no subject
Date: 2008-11-10 04:27 pm (UTC)no subject
Date: 2008-11-10 05:07 pm (UTC)In other words, she (or her friends) could post with a certain icon, but through some magic, the offending icon would be replaced with their default. Unfortunately, there ain't no such thing as magic.
no subject
Date: 2008-11-10 05:14 pm (UTC)alas, as you said, no magic.
no subject
Date: 2008-11-10 05:20 pm (UTC)no subject
Date: 2008-11-10 05:31 pm (UTC)no subject
Date: 2008-11-10 05:50 pm (UTC)*blinks innocently*
no subject
Date: 2008-11-10 06:20 pm (UTC)no subject
Date: 2008-11-10 09:13 pm (UTC)no subject
Date: 2008-11-10 06:39 pm (UTC)no subject
Date: 2008-11-10 06:46 pm (UTC)no subject
Date: 2008-11-10 07:02 pm (UTC)no subject
Date: 2008-11-12 01:20 am (UTC)The UserLite object is used for efficiency, and if it's used explicitly instead of User, will not be populated with the additional data.
Not sure if there's anything you can get that data from.
no subject
Date: 2008-11-12 12:01 pm (UTC)I realized recently that the requester may have been referring to the "Use Shared User Icons" option on layouts, but I discovered that it only applies to community posts on one's Friends Page. Looking at FriendsPage.pm, do you think it's possible to extend to personal posts, and is that a worthwhile suggestion to submit?
no subject
Date: 2008-11-12 02:40 pm (UTC)