cgi-bin/LJ/S2/IconsPage.pm
author fu
Fri Jan 27 17:59:59 2012 +0800
changeset 4240 5bab31c9f015
parent 3555 d8b263f1f765
child 4262 0d421138560e
permissions -rw-r--r--
http://bugs.dwscoalition.org/show_bug.cgi?id=4245

Call keywords in list context, so that we get a list instead of a comma-separated string. Add a bit of padding because we no longer have a physical comma.

Patch by fu.
     1 use strict;
     2 package LJ::S2;
     3 
     4 sub IconsPage {
     5     my ($u, $remote, $opts) = @_;
     6     my $get = $opts->{'getargs'};
     7 
     8     my $can_manage = ( $remote && $remote->can_manage( $u ) ) ? 1 : 0;
     9     my $p = Page($u, $opts);
    10     $p->{'_type'} = "IconsPage";
    11     $p->{'view'} = "icons";
    12 
    13     if ($u->should_block_robots) {
    14         $p->{'head_content'} .= LJ::robot_meta_tags();
    15     }
    16 
    17     $p->{can_manage} = $can_manage;
    18 
    19     my @allpics = LJ::Userpic->load_user_userpics($u);
    20     my $defaultpicid = $u ? $u->{'defaultpicid'} : undef;
    21 
    22     my $view_inactive = $can_manage || ( $get->{inactive} && $remote && ( LJ::check_priv( $remote, "supportviewscreened" ) ||
    23                                            LJ::check_priv( $remote, "supporthelp" ) ) );
    24     my $default_sortorder = S2::get_property_value($opts->{'ctx'}, 'icons_sort_order') || 'upload';
    25     my $sortorder = $get->{sortorder} || $default_sortorder;
    26 
    27     @allpics = grep { $_->state eq 'N' || ( $view_inactive && $_->state ne 'X' ) } @allpics;
    28 
    29     my @pics;
    30 
    31     if ( $sortorder eq 'keyword' ) {
    32         @pics = LJ::Userpic->separate_keywords( \@allpics );
    33     } else { # Upload Order
    34         $sortorder = 'upload';
    35         my @newpics;
    36         my $default_pic;
    37         foreach my $pic ( @allpics ) {
    38             my @keyword = $pic->keywords;
    39             if ( $pic->is_default ) {
    40                 $default_pic = { keywords => \@keyword, userpic => $pic };
    41             } else {
    42                 push @newpics, { keywords => \@keyword, userpic => $pic };
    43             }
    44         }
    45         @pics = $default_pic if $default_pic;
    46         @pics = ( @pics, @newpics );
    47     }
    48 
    49     my @sort_methods = ( 'upload', 'keyword' );
    50 
    51     $p->{sortorder} = $sortorder;
    52     $p->{sort_keyseq} = \@sort_methods;
    53     $p->{sort_urls} = {
    54         map { $_ => LJ::create_url(undef,
    55                 args => {
    56                     sortorder => ( $_ eq $default_sortorder ) ? undef : $_,
    57                 },
    58                 viewing_style => 1,
    59                 cur_args => $get,
    60             ) } @sort_methods
    61     };
    62 
    63     my $pagingbar;
    64     my $start_index = 0;
    65     my $page_size = S2::get_property_value($opts->{'ctx'}, "num_items_icons")+0;
    66     $p->{pages} = ItemRange_fromopts({
    67         items => \@pics,
    68         pagesize => $page_size || scalar @pics,
    69         page => $get->{page} || 1,
    70         url_of => sub {
    71             return LJ::create_url(undef,
    72                 args => {
    73                     page => $_[0],
    74                 },
    75                 keep_args => [ 'sortorder' ],
    76                 viewing_style => 1,
    77                 cur_args => $get,
    78             );
    79         }
    80     });
    81 
    82     my @pics_out;
    83 
    84     foreach my $pic_hash (@pics) {
    85         my $pic = $pic_hash->{userpic};
    86         my $keywords = $pic_hash->{keywords} || [ $pic_hash->{keyword} ];
    87 
    88         my $eh_comment = $pic->comment;
    89         if ( $eh_comment ) {
    90             LJ::CleanHTML::clean(\$eh_comment, {
    91                 'wordlength' => 40,
    92                 'addbreaks' => 0,
    93                 'tablecheck' => 1,
    94                 'mode' => 'deny',
    95             });
    96         }
    97 
    98         my $eh_description = $pic->description;
    99         if ( $eh_description ) {
   100             LJ::CleanHTML::clean(\$eh_description, {
   101                 'wordlength' => 40,
   102                 'addbreaks' => 0,
   103                 'tablecheck' => 1,
   104                 'mode' => 'deny',
   105             });
   106         }
   107 
   108         push @pics_out, {
   109             '_type' => 'Icon',
   110             id => $pic->picid,
   111             image => Image( $pic->url, $pic->width, $pic->height, LJ::ehtml( $pic->alttext ), title => LJ::ehtml( $pic->keywords ) ),
   112             keywords => [ map { LJ::ehtml($_) } sort { lc($a) cmp lc($b) } ( @$keywords ) ],
   113             comment => $eh_comment,
   114             description => $eh_description,
   115             default => ( $pic->is_default ) ? 1 : 0,
   116             active => $pic->state eq 'I' ? 0 : 1,
   117             link_url => $pic->url,
   118         };
   119     }
   120 
   121     $p->{icons} = \@pics_out;
   122 
   123     return $p;
   124 }
   125 
   126 1;