Changeset 1717

Show
Ignore:
Timestamp:
01/10/06 06:22:40
Author:
miyagawa
Message:

0.06: Recent Change integration; show user icon

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Kwiki-TypeKey/trunk/Changes

    r1539 r1717  
    11Revision history for Perl extension Kwiki::TypeKey 
     2 
     30.06  Mon Jan  9 21:06:46 UTC 2006 
     4        * Now it shows your picture taken from TypeKey when you're logged in. 
     5        * Integrated with Recent Changes page, showing your pic there too. 
     6          (Thanks to Ingy dot Net for his Kwiki-fu) 
    27 
    380.05  Wed Apr  6 15:45:29 JST 2005 
  • Kwiki-TypeKey/trunk/lib/Kwiki/TypeKey.pm

    r1589 r1717  
    55use mixin 'Kwiki::Installer'; 
    66 
    7 our $VERSION = 0.05
     7our $VERSION = 0.06
    88 
    99const class_id => 'user_name'; 
     
    1212const cgi_class => 'Kwiki::TypeKey::CGI'; 
    1313 
     14field -package => 'Kwiki::PageMeta', 'edit_by_icon'; 
     15 
    1416sub register { 
    1517    my $registry = shift; 
     
    1719    $registry->add(action  => "return_typekey"); 
    1820    $registry->add(action  => "logout_typekey"); 
     21    $registry->add(hook    => "page_metadata:sort_order", post => 'sort_order_hook'); 
     22    $registry->add(hook    => "page_metadata:update", post => 'update_hook'); 
     23} 
     24 
     25sub sort_order_hook { 
     26    my $hook = pop; 
     27    return $hook->returned, 'edit_by_icon'; 
     28} 
     29 
     30sub update_hook { 
     31    my $meta = $self->hub->pages->current->metadata; 
     32    $meta->edit_by_icon($self->hub->users->current->icon); 
    1933} 
    2034 
    2135sub return_typekey { 
    2236    my %cookie = map { ($_ => scalar $self->cgi->$_) } qw(email name nick ts sig); 
     37    $cookie{icon} = $self->fetch_icon($cookie{name}); 
    2338    $self->hub->cookie->write(typekey => \%cookie); 
    2439    $self->redirect("?" . $self->cgi->page); 
     40} 
     41 
     42sub fetch_icon { 
     43    my $name = shift; 
     44 
     45    # WWW::Blog::Metadata is slow. Go easy with regexp. 
     46    my $ua = LWP::UserAgent->new; 
     47    my $res = $ua->get("http://profile.typekey.com/$name/"); 
     48    if ($res->is_success) { 
     49        return ($res->content =~ m!<div class="photo">\n\s*<img src="(.*?)"!s)[0]; 
     50    } 
     51    return; 
    2552} 
    2653 
     
    103130<div id="user_name_title"> 
    104131<em>[% IF hub.users.current.name -%] 
    105 (Logged In as <a href="http://profile.typekey.com/[% hub.users.current.name %]/">[% hub.users.current.nick | html %]</a>: <a href="[% script_name %]?action=logout_typekey">Logout</a>) 
     132(You are <a href="http://profile.typekey.com/[% hub.users.current.name %]/">[% hub.users.current.nick | html %]</a>: <a href="[% script_name %]?action=logout_typekey">Logout</a>) 
    106133[%- ELSE -%] 
    107134[%- USE tk = url("https://www.typekey.com/t/typekey/login") -%] 
     
    115142<p>You've now successfully logged out.</p> 
    116143<!-- END logout_typekey.html --> 
     144__template/tt2/recent_changes_content.html__ 
     145<table class="recent_changes"> 
     146[% FOR page = pages %] 
     147[% SET tk_username = page.metadata.edit_by; 
     148   SET tk_icon = page.metadata.edit_by_icon %] 
     149<tr> 
     150    <td class="page_name">[% page.kwiki_link %]</td> 
     151    <td class="edit_by_icon" style="text-align: right">[% IF tk_icon %]<img class="edit-by-icon" src="[% tk_icon %]" height="24" style="vertical-align:middle" align="right" />[% END %]</td> 
     152    <td class="edit_by_left"><a href="http://profile.typekey.com/[% tk_username %]/">[% tk_username %]</a></td> 
     153    <td class="edit_time">[% page.edit_time %]</td> 
     154</tr> 
     155[% END %] 
     156</table> 
     157__theme/basic/template/tt2/theme_title_pane.html__ 
     158<div id="title_pane"> 
     159  <h1> 
     160[% IF hub.users.current.icon %]<a href="[% script_name %]?"><img src="[% hub.users.current.icon %]" height="36" style="vertical-align: middle; border: 0" /></a>[% END -%] 
     161  [% screen_title || self.class_title %] 
     162  </h1> 
     163</div> 
  • Kwiki-TypeKey/trunk/lib/Kwiki/Users/TypeKey.pm

    r1539 r1717  
    3333field 'nick'; 
    3434field 'ts'; 
     35field 'icon'; 
    3536 
    3637sub set_user_name { 
     
    4142 
    4243    $self->validate_sig($cookie) or return; 
    43     for my $key (qw(email name nick ts)) { 
     44    for my $key (qw(email name nick ts icon)) { 
    4445        $self->$key($cookie->{$key}); 
    4546    }