Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r16153: LJSV-878 (ESN refactoring, part 1): clea...

Committer: ailyin
LJSV-878 (ESN refactoring, part 1): cleanup

U   trunk/cgi-bin/weblib.pl
Modified: trunk/cgi-bin/weblib.pl
===================================================================
--- trunk/cgi-bin/weblib.pl	2010-01-27 11:05:57 UTC (rev 16152)
+++ trunk/cgi-bin/weblib.pl	2010-01-27 11:34:48 UTC (rev 16153)
@@ -3284,428 +3284,6 @@
     return $ret;
 }
 
-# prints out UI for subscribing to some events
-sub subscribe_interface {
-    my ($u, %opts) = @_;
-
-    croak "subscribe_interface wants a \$u" unless LJ::isu($u);
-
-    my $catref       = delete $opts{'categories'};
-    my $journalu     = delete $opts{'journal'} || LJ::get_remote();
-    my $formauth     = delete $opts{'formauth'} || LJ::form_auth();
-    my $showtracking = delete $opts{'showtracking'} || 0;
-    my $getextra     = delete $opts{'getextra'} || '';
-    my $ret_url      = delete $opts{ret_url} || '';
-    my $def_notes    = delete $opts{'default_selected_notifications'} || [];
-    my $settings_page= delete $opts{'settings_page'} || 0;
-    my $post_to_settings_page = delete $opts{'post_to_settings_page'} || 0;
-
-    croak "Invalid user object passed to subscribe_interface" unless LJ::isu($journalu);
-
-    croak "Invalid options passed to subscribe_interface" if (scalar keys %opts);
-
-    LJ::need_res('stc/esn.css');
-    LJ::need_res('js/core.js');
-    LJ::need_res('js/dom.js');
-    LJ::need_res('js/checkallbutton.js');
-    LJ::need_res('js/esn.js');
-
-    my @categories = $catref ? @$catref : ();
-    my $ui_inbox  = BML::ml('subscribe_interface.inbox');
-    my $ui_manage = BML::ml('subscribe_interface.manage_settings');
-    my $ui_notify = BML::ml('subscribe_interface.notify_me2', { sitenameabbrev => $LJ::SITENAMEABBREV });
-    my $ui_by     = BML::ml('subscribe_interface.by2');
-
-    my $ret = "<div id='manageSettings'>";
-
-    unless ($settings_page) {
-        $ret .= "<span class='esnlinks'><a href='$LJ::SITEROOT/inbox/'>$ui_inbox</a> | $ui_manage</span>";
-    }
-
-    if ($post_to_settings_page) {
-        $ret .= "<form method='POST' action='$LJ::SITEROOT/manage/settings/?cat=notifications'>$formauth";
-    } elsif (!$settings_page) {
-        $ret .= "<form method='POST' action='$LJ::SITEROOT/manage/subscriptions/$getextra'>$formauth";
-    }
-
-    my $events_table = $settings_page ? '<table class="Subscribe" style="clear: none;" cellpadding="0" cellspacing="0">' : '<table class="Subscribe" cellpadding="0" cellspacing="0">';
-
-    my @notify_classes = LJ::NotificationMethod->all_classes or return "No notification methods";
-    # skip the inbox type; it's always on
-    @notify_classes = grep { $_ ne 'LJ::NotificationMethod::Inbox' } @notify_classes;
-
-    my $tracking = [];
-
-    # title of the tracking category
-    my $tracking_cat = "Subscription Tracking";
-
-    # if showtracking, add things the user is tracking to the categories
-    if ($showtracking) {
-        my @subscriptions = $u->find_subscriptions(method => 'Inbox');
-
-        foreach my $subsc ( sort {$a->id <=> $b->id } @subscriptions ) {
-            # if this event class is already being displayed above, skip over it
-            my $etypeid = $subsc->etypeid or next;
-            my ($evt_class) = (LJ::Event->class($etypeid) =~ /LJ::Event::(.+)/i);
-            next unless $evt_class;
-
-            # search for this class in categories
-            next if grep { $_ eq $evt_class } map { @$_ } map { values %$_ } @categories;
-
-            push @$tracking, $subsc;
-        }
-    }
-
-    push @categories, {$tracking_cat => $tracking};
-
-    my @catids;
-    my $catid = 0;
-
-    my %shown_subids = ();
-
-    foreach my $cat_hash (@categories) {
-        my ($category, $cat_events) = %$cat_hash;
-
-        push @catids, $catid;
-
-        # pending subscription objects
-        my $pending = [];
-
-        my $cat_empty = 1;
-        my $cat_html = '';
-
-        # is this category the tracking category?
-        my $is_tracking_category = $category eq $tracking_cat;
-
-        # build table of subscribeble events
-        foreach my $cat_event (@$cat_events) {
-            if ((ref $cat_event) =~ /Subscription/) {
-                push @$pending, $cat_event;
-            } elsif ($cat_event =~ /^LJ::Setting/) {
-                # special subscription that's an LJ::Setting instead of an LJ::Subscription
-                if ($settings_page) {
-                    push @$pending, $cat_event;
-                } else {
-                    next;
-                }
-            } else {
-                my $pending_sub = LJ::Subscription::Pending->new($u,
-                                                                 event => $cat_event,
-                                                                 journal => $journalu);
-                push @$pending, $pending_sub;
-            }
-        }
-
-        my $cat_title_key = lc($category);
-        $cat_title_key =~ s/ /-/g;
-        my $cat_title = BML::ml('subscribe_interface.category.'.$cat_title_key);
-        my $first_class = $catid == 0 ? " CategoryRowFirst" : "";
-        $cat_html .= qq {
-            <tbody class="CategoryRow-$catid">
-                <tr class="CategoryRow$first_class">
-                <td>
-                <span class="CategoryHeading">$cat_title</span><br />
-                <span class="CategoryHeadingNote">$ui_notify</span>
-                </td>
-                <td class="Caption">
-                $ui_by
-                </td>
-            };
-
-        my @pending_subscriptions;
-        # build list of subscriptions to show the user
-        {
-            unless ($is_tracking_category) {
-                foreach my $pending_sub (@$pending) {
-                    if (!ref $pending_sub) {
-                        push @pending_subscriptions, $pending_sub;
-                    } else {
-                        my %sub_args = $pending_sub->sub_info;
-                        delete $sub_args{ntypeid};
-                        $sub_args{method} = 'Inbox';
-
-                        my @existing_subs = $u->has_subscription(%sub_args);
-                        push @pending_subscriptions, (scalar @existing_subs ? @existing_subs : $pending_sub);
-                    }
-                }
-            } else {
-                push @pending_subscriptions, @$tracking;
-            }
-        }
-
-        # add notifytype headings
-        foreach my $notify_class (@notify_classes) {
-            my $title = eval { $notify_class->title($u) } or next;
-            my $ntypeid = $notify_class->ntypeid or next;
-
-            # create the checkall box for this event type.
-            my $disabled = ! $notify_class->configured_for_user($u);
-
-            if ($notify_class->disabled_url && $disabled) {
-                $title = "<a href='" . $notify_class->disabled_url . "'>$title</a>";
-            } elsif ($notify_class->url) {
-                $title = "<a href='" . $notify_class->url . "'>$title</a>";
-            }
-            $title .= " " . LJ::help_icon($notify_class->help_url) if $notify_class->help_url;
-
-            my $checkall_box = LJ::html_check({
-                id       => "CheckAll-$catid-$ntypeid",
-                label    => $title,
-                class    => "CheckAll",
-                noescape => 1,
-                disabled => $disabled,
-            });
-
-            $cat_html .= qq {
-                <td style='vertical-align: bottom;'>
-                    $checkall_box
-                    </td>
-                };
-        }
-
-        $cat_html .= '</tr>';
-
-        # inbox method
-        my $special_subs = 0;
-        my $sub_count = 0;
-        foreach my $pending_sub (@pending_subscriptions) {
-            if (!ref $pending_sub) {
-                next if $u->is_identity && $pending_sub->disabled($u);
-
-                my $disabled_class = $pending_sub->disabled($u) ? "Disabled" : "";
-                my $altrow_class = $sub_count % 2 == 1 ? "altrow" : "";
-                my $hidden = $pending_sub->selected($u) ? "" : " style='visibility: hidden;'";
-                my $sub_title = " " . $pending_sub->htmlcontrol_label($u);
-                $sub_title = LJ::run_hook("disabled_esn_sub", $u) . $sub_title if $pending_sub->disabled($u);
-
-                $cat_html .= "<tr class='$disabled_class $altrow_class'>";
-                $cat_html .= "<td>" . $pending_sub->htmlcontrol($u) . "$sub_title*</td>";
-                $cat_html .= "<td>&nbsp;</td>";
-                $cat_html .= "<td><span class='NotificationOptions'$hidden>" . $pending_sub->htmlcontrol($u, undef, undef, notif => 1, notif_catid => $catid, notif_ntypeid => 2) . "</span></td>";
-                $cat_html .= "<td><span class='NotificationOptions'$hidden>" . LJ::html_check({ disabled => 1 }) . "</span></td>"
-                    for 1 .. scalar @notify_classes - 1;
-                $cat_html .= "</tr>";
-
-                $special_subs++;
-                $sub_count++;
-                next;
-            }
-
-            next if $u->is_identity && !$pending_sub->enabled;
-            # print option to subscribe to this event, checked if already subscribed
-            my $input_name = $pending_sub->freeze or next;
-            my $title      = $pending_sub->as_html or next;
-            my $subscribed = ! $pending_sub->pending;
-
-            unless ($pending_sub->enabled) {
-                $title = LJ::run_hook("disabled_esn_sub", $u) . $title;
-            }
-            next if ! $pending_sub->event_class->is_visible && $showtracking;
-
-            my $evt_class = $pending_sub->event_class or next;
-            unless ($is_tracking_category) {
-                next unless eval { $evt_class->subscription_applicable($pending_sub) };
-                next if LJ::u_equals($journalu, $u) && $pending_sub->journalid && $pending_sub->journalid != $u->{userid};
-            } else {
-                my $no_show = 0;
-
-                foreach my $cat_info_ref (@$catref) {
-                    while (my ($_cat_name, $_cat_events) = each %$cat_info_ref) {
-                        foreach my $_cat_event (@$_cat_events) {
-                            next if $_cat_event =~ /^LJ::Setting/;
-                            unless (ref $_cat_event) {
-                                $_cat_event = LJ::Subscription::Pending->new($u, event => $_cat_event);
-                            }
-                            next unless $pending_sub->equals($_cat_event);
-                            $no_show = 1;
-                            last;
-                        }
-                    }
-                }
-
-                next if $no_show;
-            }
-
-            my $special_selected = 0;
-            if ($settings_page) {
-                # if non-ESN comment notifications are turned on, then check the box for
-                # the JournalNewComment event as well, since JournalNewComment notifications
-                # are a subset of the non-ESN notifications
-                my $etypeid = $pending_sub->etypeid;
-                if (!$is_tracking_category && LJ::Event->class($etypeid) =~ /JournalNewComment/ && LJ::Setting::CommentEmailNotify->selected($u)) {
-                    $special_selected = 1;
-                }
-            }
-
-            my $selected = $special_selected || $pending_sub->default_selected;
-
-            my $inactiveclass = $pending_sub->active ? '' : 'Inactive';
-            my $disabledclass = $pending_sub->enabled ? '' : 'Disabled';
-            my $altrowclass = $sub_count % 2 == 1 ? "altrow" : "";
-
-            $cat_html .= "<tr class='$inactiveclass $disabledclass $altrowclass'><td>";
-
-            if ($is_tracking_category && ! $pending_sub->pending) {
-                my $subid = $pending_sub->id;
-                my $deletesub_url = $settings_page ? "$LJ::SITEROOT/manage/settings/?cat=notifications&amp;deletesub_$subid=1" : "?deletesub_$subid=1";
-                $cat_html .= qq {
-                    <a href='$deletesub_url'><img src="$LJ::IMGPREFIX/portal/btn_del.gif" /></a>
-                };
-            }
-            my $always_checked = eval { "$evt_class"->always_checked; };
-            my $disabled = $always_checked ? 1 : !$pending_sub->enabled;
-
-            $cat_html  .= LJ::html_check({
-                id       => $input_name,
-                name     => $input_name,
-                class    => "SubscriptionInboxCheck",
-                selected => $selected,
-                noescape => 1,
-                label    => $title,
-                disabled => $disabled,
-            });
-
-            unless ($pending_sub->pending) {
-                $cat_html .= LJ::html_hidden({
-                    name  => "${input_name}-old",
-                    value => $subscribed,
-                });
-            }
-            
-            $cat_html .= "</td>";
-
-            $shown_subids{$pending_sub->id}++ unless $pending_sub->pending;
-
-            $cat_empty = 0;
-
-            # print out notification options for this subscription (hidden if not subscribed)
-            $cat_html .= "<td>&nbsp;</td>";
-            my $hidden = ($special_selected || $pending_sub->default_selected || ($subscribed && $pending_sub->active)) ? '' : ' style="visibility: hidden;"';
-
-            # is there an inbox notification for this?
-            my %sub_args = $pending_sub->sub_info;
-            $sub_args{ntypeid} = LJ::NotificationMethod::Inbox->ntypeid;
-            delete $sub_args{flags};
-            my ($inbox_sub) = $u->find_subscriptions(%sub_args);
-
-            foreach my $note_class (@notify_classes) {
-                my $ntypeid = eval { $note_class->ntypeid } or next;
-
-                $sub_args{ntypeid} = $ntypeid;
-                my @subs = $u->has_subscription(%sub_args);
-                @subs = () if !$u->prop('msn_enabled') && $sub_args{ntypeid} eq LJ::NotificationMethod::Alerts->ntypeid;
-
-                my $note_pending = LJ::Subscription::Pending->new($u, %sub_args);
-                if (@subs) {
-                    $note_pending = $subs[0];
-                }
-
-                if (($is_tracking_category || $pending_sub->is_tracking_category) && $note_pending->pending) {
-                    # flag this as a "tracking" subscription
-                    $note_pending->set_tracking;
-                }
-
-                my $notify_input_name = $note_pending->freeze;
-
-                # select email method by default
-                my $note_selected = (scalar @subs) ? 1 : ((!$selected || $special_selected) && $note_class eq 'LJ::NotificationMethod::Email');
-
-                # check the box if it's marked as being selected by default UNLESS
-                # there exists an inbox subscription and no email subscription
-                $note_selected = 1 if (! $inbox_sub || scalar @subs) && $selected && grep { $note_class eq $_ } @$def_notes;
-                $note_selected &&= $note_pending->active && $note_pending->enabled;
-
-                my $disabled = ! $pending_sub->enabled;
-                $disabled = 1 unless $note_class->configured_for_user($u);
-
-                $cat_html .= qq {
-                    <td><span class='NotificationOptions'$hidden>
-                    } . LJ::html_check({
-                        id       => $notify_input_name,
-                        name     => $notify_input_name,
-                        class    => "SubscribeCheckbox-$catid-$ntypeid",
-                        selected => $note_selected,
-                        noescape => 1,
-                        disabled => $disabled,
-                    }) . '</span>';
-
-                unless ($note_pending->pending) {
-                    $cat_html .= LJ::html_hidden({
-                        name  => "${notify_input_name}-old",
-                        value => (scalar @subs) ? 1 : 0,
-                    });
-                }
-
-                $cat_html .= '</td>';
-            }
-
-            $cat_html .= "</tr>";
-            $sub_count++;
-        }
-
-        my $cols = 2 + (scalar @notify_classes);
-
-        # show blurb if not tracking anything
-        if ($cat_empty && $is_tracking_category) {
-            my $blurb = "<?p <strong>" . LJ::Lang::ml('subscribe_interface.nosubs.title') . "</strong><br />";
-            $blurb .= LJ::Lang::ml('subscribe_interface.nosubs.text', { img => "<img src='$LJ::SITEROOT/img/btn_track.gif' width='22' height='20' align='absmiddle' alt='$ui_notify' />" }) . " p?>";
-
-            $cat_html .= "<tr>";
-            $cat_html .= "<td colspan='$cols'>$blurb</td>";
-            $cat_html .= "</tr>";
-        }
-
-        $cat_html .= "<tr><td colspan='$cols' style='font-size: smaller;'>* " . LJ::Lang::ml('subscribe_interface.special_subs.note') . "</td></tr>" if $special_subs;
-        $cat_html .= "</tbody>";
-        $events_table .= $cat_html unless ($is_tracking_category && !$showtracking);
-
-        $catid++;
-    }
-
-    $events_table .= '</table>';
-
-    # pass some info to javascript
-    my $catids = LJ::html_hidden({
-        'id'  => 'catids',
-        'value' => join(',', @catids),
-    });
-    my $ntypeids = LJ::html_hidden({
-        'id'  => 'ntypeids',
-        'value' => join(',', map { $_->ntypeid } LJ::NotificationMethod->all_classes),
-    });
-
-    $ret .= qq {
-        $ntypeids
-            $catids
-            $events_table
-        };
-
-    $ret .= LJ::html_hidden({name => 'mode', value => 'save_subscriptions'});
-    $ret .= LJ::html_hidden({name => 'ret_url', value => $ret_url});
-    $ret .= LJ::html_hidden({name => 'post_to_settings_page', value => $post_to_settings_page});
-
-    # print buttons
-    my $referer = BML::get_client_header('Referer');
-    my $uri = $LJ::SITEROOT . LJ::Request->uri;
-
-    # normalize the URLs -- ../index.bml doesn't make it a different page.
-    $uri =~ s/index\.bml//;
-    $referer =~ s/index\.bml//;
-
-    unless ($settings_page) {
-        $ret .= '<?standout ' .
-            LJ::html_submit(BML::ml('subscribe_interface.save')) . ' ' .
-            ($referer && $referer ne $uri ? "<input type='button' value='".BML::ml('subscribe_interface.cancel')."' onclick='window.location=\"$referer\"' />" : '')
-            . '';
-        $ret .= "standout?>";
-    }
-
-    $ret .= "</div>";
-    $ret .= "</form>" if !$settings_page || $post_to_settings_page;
-
-    return $ret;
-}
-
 # returns a placeholder link
 sub placeholder_link {
     my (%opts) = @_;

Tags: andy, livejournal, pl
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