wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r17855: LJSUP-7052.

Committer: gprochaev
LJSUP-7052.
1. Remove unused code and data from previous ver verticals
2. Add parser for recent posts
3. Add "posted to" for recent posts

A   trunk/cgi-bin/LJ/Browse/
A   trunk/cgi-bin/LJ/Browse/Parser.pm
U   trunk/cgi-bin/LJ/Vertical.pm
U   trunk/cgi-bin/LJ/Widget/Browse.pm
U   trunk/cgi-bin/LJ/Widget/VerticalContentControl.pm
U   trunk/cgi-bin/ljdefaults.pl
U   trunk/htdocs/admin/browse/recent_posts.bml
U   trunk/templates/Browse/recent_posts.tmpl
Added: trunk/cgi-bin/LJ/Browse/Parser.pm
===================================================================
--- trunk/cgi-bin/LJ/Browse/Parser.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/Browse/Parser.pm	2010-12-03 04:57:48 UTC (rev 17855)
@@ -0,0 +1,125 @@
+package LJ::Browse::Parser;
+
+use strict;
+
+## Parsing text for Landing Page
+## args:
+##      text => Text to parse
+##      max_len => Truncate text on max_len chars
+## return:
+##      hashref
+##          text => parsed and cropped text
+##          images => arrayref for urls of cropped images
+##
+sub do_parse {
+    my $class = shift;
+    my %args = @_;
+
+    my $text = $args{'text'};
+    my $char_max = $args{'max_len'};
+
+    my $p = HTML::TokeParser->new(\$text);
+
+    my $ret = '';
+    my @open_tags = ();
+    my $content_len = 0;
+    my $images_crop_cnt = $args{'crop_image'};
+    my @images = ();
+    my $remove_tags = $args{'remove_tags'};
+
+warn $text;
+
+    while (my $token = $p->get_token) {
+        my $type = $token->[0];
+        my $tag  = $token->[1];
+        my $attr = $token->[2];  # hashref
+
+        if ($type eq "S") {
+            my $selfclose;
+
+            if ($tag eq 'img') {
+                next unless $images_crop_cnt;
+                $images_crop_cnt--;
+                my $r = LJ::crop_picture_from_web(
+                    source    => $attr->{'src'},
+                    size      => '200x200',
+                    username  => $LJ::PHOTOS_FEAT_POSTS_FB_USERNAME,
+                    password  => $LJ::PHOTOS_FEAT_POSTS_FB_PASSWORD,
+                    galleries => [ $LJ::PHOTOS_FEAT_POSTS_FB_GALLERY ],
+                );
+                push @images, $r->{url} if $r->{url};
+                next;
+            }
+
+            next if grep { $tag eq $_ } @$remove_tags;
+
+            # start tag
+            $ret .= "<$tag";
+
+            # assume tags are properly self-closed
+            $selfclose = 1 if lc $tag eq 'input' || lc $tag eq 'br' || lc $tag eq 'img';
+
+            # preserve order of attributes. the original order is
+            # in element 4 of $token
+            foreach my $attrname (@{$token->[3]}) {
+                if ($attrname eq '/') {
+                    $selfclose = 1;
+                    next;
+                }
+
+                # FIXME: ultra ghetto.
+                $attr->{$attrname} = LJ::no_utf8_flag($attr->{$attrname});
+                $ret .= " $attrname=\"" . LJ::ehtml($attr->{$attrname}) . "\"";
+            }
+
+            $ret .= $selfclose ? " />" : ">";
+
+            push @open_tags, $tag unless $selfclose;
+
+        } elsif ($type eq 'T' || $type eq 'D') {
+            my $content = $token->[1];
+
+            if (length($content) + $content_len > $char_max) {
+
+                # truncate and stop parsing
+                $content = LJ::text_trim($content, undef, ($char_max - $content_len));
+                $ret .= $content;
+                last;
+            }
+
+            $content_len += length $content;
+
+            $ret .= $content;
+
+        } elsif ($type eq 'C') {
+            # comment, don't care
+            $ret .= $token->[1];
+
+        } elsif ($type eq 'E') {
+            # end tag
+            pop @open_tags;
+            $ret .= "</$tag>";
+        }
+    }
+
+    $ret .= join("\n", map { "</$_>" } reverse @open_tags);
+
+    _after_parse (\$ret);
+
+warn $ret;
+
+    return {
+        text    => $ret,
+        images  => \@images,
+    }
+}
+
+sub _after_parse {
+    my $text = shift;
+
+    ## Remove multiple "br" tags
+    $$text =~ s#(\s*<br\s*/?>\s*){2,}# #gi;
+}
+
+1;
+

Modified: trunk/cgi-bin/LJ/Vertical.pm
===================================================================
--- trunk/cgi-bin/LJ/Vertical.pm	2010-12-02 11:09:01 UTC (rev 17854)
+++ trunk/cgi-bin/LJ/Vertical.pm	2010-12-03 04:57:48 UTC (rev 17855)
@@ -1631,7 +1631,7 @@
 }
 
 sub uri_map {
-    return \%LJ::VERTICAL_URI_MAP;
+    return undef;
 }
 
 # the name to pass to ads to identify verticals

Modified: trunk/cgi-bin/LJ/Widget/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Browse.pm	2010-12-02 11:09:01 UTC (rev 17854)
+++ trunk/cgi-bin/LJ/Widget/Browse.pm	2010-12-03 04:57:48 UTC (rev 17855)
@@ -8,6 +8,8 @@
 
 sub need_res { qw( stc/widgets/widgets-layout.css stc/widgets/search.css stc/widgets/add-community.css stc/widgets/featuredposts.css stc/widgets/featuredcomms.css ) }
 
+use LJ::Browse::Parser;
+
 sub _build_tree {
     my ($parent, $level, $test_uri, $vertical, @categories) = @_;
     my @tree = ();
@@ -247,28 +249,19 @@
             my $poster = $entry->poster;
             my $userpic = $entry->userpic;
             my @tags = $entry->tags;
-            my $event = $entry->event_html;
-            my ($is_removed_video) = $event =~ s/<iframe.*?>(.*)<\/iframe>/$1/;
-            $event =~ s#<img.*?>##gi;
             my $subject = $entry->subject_text || '***';
             my $trimmed_subj = LJ::html_trim ($subject, 60);
+            my $event = $entry->event_html;
 
-            my @images = ();
-            my $fb_photo_big = '';
-            @images = $entry->event_raw =~ m#img.*?src="(.*?)"#gi;
+            my $parsed = LJ::Browse::Parser->do_parse (
+                text        => $event,
+                remove_tags => [ 'b', 'p', 'div', 'span', 'strong' ],
+                max_len     => 1000,
+                crop_image  => 1,
+            );
+            $event = $parsed->{'text'};
+            my $images = $parsed->{'images'};
 
-            if (scalar @images) {
-                my $r = LJ::crop_picture_from_web(
-                    source    => $images[0],
-                    size      => '200x200',
-                    username  => $LJ::PHOTOS_FEAT_POSTS_FB_USERNAME,
-                    password  => $LJ::PHOTOS_FEAT_POSTS_FB_PASSWORD,
-                    galleries => [ $LJ::PHOTOS_FEAT_POSTS_FB_GALLERY ],
-                );
-                $fb_photo_big = $r->{url} || '';
-#                $fb_photo_big =~ s|^http://pics\.|http://l-pics.|;
-            }
-
             push @tmpl_posts, {
                 subject         => $trimmed_subj,
                 is_subject_trimmed => $subject ne $trimmed_subj ? 1 : 0,
@@ -279,11 +272,12 @@
                 mood            => $entry->prop('current_mood') || LJ::mood_name($entry->prop('current_moodid')) || '',
                 music           => $entry->prop('current_music'),
                 location        => $entry->prop('current_location'),
-                post_text       => LJ::html_trim ($event, 800),
+                post_text       => $event,
+                posted_to       => LJ::ljuser(LJ::get_username($entry->journalid)),
                 url_to_post     => $entry->url,
-                photo_for_post  => $fb_photo_big,
+                photo_for_post  => scalar @$images ? $images->[0] : '',
                 comments_count  => $entry->reply_count,
-                is_need_more    => $is_removed_video || bytes::length($entry->event_html) > 800 ? 1 : 0,
+                is_need_more    => $parsed->{'is_removed_video'} || bytes::length($entry->event_html) > 800 ? 1 : 0,
             };
         }
     }

Modified: trunk/cgi-bin/LJ/Widget/VerticalContentControl.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/VerticalContentControl.pm	2010-12-02 11:09:01 UTC (rev 17854)
+++ trunk/cgi-bin/LJ/Widget/VerticalContentControl.pm	2010-12-03 04:57:48 UTC (rev 17855)
@@ -164,19 +164,12 @@
     my $class = shift;
 
     my $remote = LJ::get_remote();
-    my @verticals;
+    my @verticals = ();
 
-    if (LJ::check_priv($remote, "vertical", "*") || $LJ::IS_DEV_SERVER) {
+    if (LJ::check_priv($remote, 'siteadmin', 'community_directory') || $LJ::IS_DEV_SERVER) {
         @verticals = LJ::Vertical->load_all;
     } else {
-        foreach my $vert (keys %LJ::VERTICAL_TREE) {
-            my $v = LJ::Vertical->load_by_name($vert);
-            next unless $v;
-
-            if ($v->remote_is_moderator) {
-                push @verticals, $v;
-            }
-        }
+        return ();
     }
 
     return sort { $a->name cmp $b->name } @verticals;

Modified: trunk/cgi-bin/ljdefaults.pl
===================================================================
--- trunk/cgi-bin/ljdefaults.pl	2010-12-02 11:09:01 UTC (rev 17854)
+++ trunk/cgi-bin/ljdefaults.pl	2010-12-03 04:57:48 UTC (rev 17855)
@@ -424,10 +424,6 @@
         #'DE' => { type => 'statede', save_region_code => 0, },
     );
 
-    %LJ::VERTICAL_URI_MAP =
-        map { $LJ::VERTICAL_TREE{$_}->{url_path} => $_ }
-        grep { $LJ::VERTICAL_TREE{$_}->{url_path} } keys %LJ::VERTICAL_TREE;
-
     %LJ::VALID_PAGE_NOTICES = (
         profile_design => 1,
         settings_design => 1,

Modified: trunk/htdocs/admin/browse/recent_posts.bml
===================================================================
--- trunk/htdocs/admin/browse/recent_posts.bml	2010-12-02 11:09:01 UTC (rev 17854)
+++ trunk/htdocs/admin/browse/recent_posts.bml	2010-12-03 04:57:48 UTC (rev 17855)
@@ -29,11 +29,11 @@
     my @vert_ids = map { { value => $_->vert_id, text => $_->name } } @verticals;
     @vert_ids = sort { $a->{'text'} cmp $b->{'text'} } @vert_ids;
 
-    $ret .= "<p>Select vertical: ";
+    $ret .= "<p> ";
     $ret .= LJ::html_select({
                 name => 'vert_id',
                 selected => $vert_id },
-                { text => 'Select Category',
+                { text => 'Select Vertical',
                 value => '' },
                 @vert_ids
             );

Modified: trunk/templates/Browse/recent_posts.tmpl
===================================================================
--- trunk/templates/Browse/recent_posts.tmpl	2010-12-02 11:09:01 UTC (rev 17854)
+++ trunk/templates/Browse/recent_posts.tmpl	2010-12-03 04:57:48 UTC (rev 17855)
@@ -14,6 +14,7 @@
 		<dl class="b-catalogue-item-header">
 			<dt class="b-catalogue-item-subject"><a href="<tmpl_var url_to_post>"><tmpl_var subject><tmpl_if is_subject_trimmed>&hellip;</tmpl_if></a></dt>
 			<dd class="b-catalogue-item-userpic"><tmpl_if userpic><img src="<tmpl_var userpic>" alt=""><tmpl_else><img src="/img/profile_icons/user.gif" alt=""/></tmpl_if></dd>
+            <tmpl_if posted_to><dd class="b-catalogue-item-author">Posted in: <TMPL_VAR posted_to> </dd></tmpl_if>
 			<tmpl_if poster><dd class="b-catalogue-item-author">Posted <TMPL_VAR posted_ago> by <TMPL_VAR poster> </dd></tmpl_if>
 			<tmpl_if tags><dd class="b-catalogue-item-tags">Tags: <tmpl_loop tags><tmpl_unless __first__>,&nbsp;</tmpl_unless><tmpl_var tag></tmpl_loop></dd></tmpl_if>
 			<tmpl_if mood><dd class="b-catalogue-item-mood">Mood: <tmpl_var mood></dd></tmpl_if>

Tags: bml, livejournal, pl, pm, tmpl, wisest-owl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments