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

[livejournal] r23000: LJSUP-13770 (refactor LJ FAQs from BML t...

Committer: ailyin
LJSUP-13770 (refactor LJ FAQs from BML to controllers)
U   branches/faq-refactor/cgi-bin/LJ/Faq.pm
U   branches/faq-refactor/htdocs/support/faq.bml
U   branches/faq-refactor/htdocs/support/faqbrowse.bml
U   branches/faq-refactor/htdocs/support/faqsearch.bml
Modified: branches/faq-refactor/cgi-bin/LJ/Faq.pm
===================================================================
--- branches/faq-refactor/cgi-bin/LJ/Faq.pm	2012-09-28 09:11:04 UTC (rev 22999)
+++ branches/faq-refactor/cgi-bin/LJ/Faq.pm	2012-09-28 09:17:39 UTC (rev 23000)
@@ -214,9 +214,9 @@
 }
 
 sub page_url {
-    my ($self) = @_;
+    my ( $self, %opts ) = @_;
 
-    my $faqid = $self->faqid;
+    my $faqid = $opts{'faqid'} || $self->faqid;
     return "$LJ::SITEROOT/support/faq/$faqid.html";
 }
 

Modified: branches/faq-refactor/htdocs/support/faq.bml
===================================================================
--- branches/faq-refactor/htdocs/support/faq.bml	2012-09-28 09:11:04 UTC (rev 22999)
+++ branches/faq-refactor/htdocs/support/faq.bml	2012-09-28 09:17:39 UTC (rev 23000)
@@ -1,103 +1 @@
-<?page
-title=>FAQ
-body<=
-
-<?_code
-{
-    use strict;
-    use vars qw(%GET);
-
-    LJ::set_active_crumb('faq');
-
-    my $curlang = BML::get_language();
-    my $deflang = BML::get_language_default();
-    my $altlang = $curlang ne $deflang;
-    my ($mll, $mld);
-    if ($altlang) {
-        $mll = LJ::Lang::get_lang($curlang);
-        $mld = LJ::Lang::get_dom("faq");
-        $altlang = 0 unless $mll && $mld;
-    }
-
-    my $dbr = LJ::get_db_reader(); my $sth;
-    my %faqcat; my %faqq;
-    my $ret = "";
-
-    # Search box
-    $ret .= "<div style='width: 30%; float: right'><?standout ";
-    $ret .= "<strong>".BML::ml('.cannotfind', {faqsearch => "href='./faqsearch.bml'"})."</strong>";
-    $ret .= "<p>$ML{'.cannotfind.note'}</p>";
-    $ret .= " standout?></div>";
-
-    $ret .= "<?h1 $ML{'.faq.title'} h1?>";
- 
-    $ret .= "<?p $ML{'.faq.title.text'} p?>";
-
-    if ($altlang) {
-        my $sql = "SELECT fc.faqcat, t.text AS 'faqcatname', fc.catorder FROM faqcat fc, ".
-            "ml_text t, ml_latest l, ml_items i WHERE ".
-            "t.dmid=$mld->{'dmid'} AND l.dmid=$mld->{'dmid'} AND i.dmid=$mld->{'dmid'} AND ".
-            "l.lnid=$mll->{'lnid'} AND l.itid=i.itid AND i.itcode=CONCAT('cat.', fc.faqcat) ".
-            "AND l.txtid=t.txtid AND fc.faqcat<>'int-abuse'";
-        $sth = $dbr->prepare($sql);
-    } else {
-        $sth = $dbr->prepare("SELECT faqcat, faqcatname, catorder FROM faqcat ".
-                             "WHERE faqcat<>'int-abuse'");
-    }
-    $sth->execute;
-    while ($_ = $sth->fetchrow_hashref) {
-        $faqcat{$_->{'faqcat'}} = $_;
-    }
-
-    my $remote = LJ::get_remote();
-    my $user;
-    my $user_url;
-
-    # Get remote username and journal URL, or example user's username and journal URL
-    if ($remote) {
-        $user = $remote->user;
-        $user_url = $remote->journal_base;
-    } else {
-        my $u = LJ::load_user($LJ::EXAMPLE_USER_ACCOUNT);
-        $user = $u ? $u->user : "<b>[Unknown or undefined example username]</b>";
-        $user_url = $u ? $u->journal_base : "<b>[Unknown or undefined example username]</b>";
-    }
-
-    foreach my $f (LJ::Faq->load_all(lang => $curlang)) {
-        $f->render_in_place({user => $user, url => $user_url});
-        $faqq{$f->faqid} = $f;
-    }
-
-    foreach my $faqcat (sort { $faqcat{$a}->{'catorder'} <=>
-                                   $faqcat{$b}->{'catorder'} } keys %faqcat)
-    {
-        next if $GET{'cat'} && $GET{'cat'} ne $faqcat;
-        $ret .= "<?h2 ";
-        $ret .= LJ::ehtml($faqcat{$faqcat}->{'faqcatname'});
-        $ret .= " (<a href='faqbrowse.bml?faqcat=$faqcat'>";
-        $ret .= $ML{'.view.all'};
-        $ret .= "</a>) h2?>\n";
-        $ret .= "<ul>\n";
-        foreach my $faqid (sort { $faqq{$a}->sortorder <=> $faqq{$b}->sortorder } grep { $faqq{$_}->faqcat eq $faqcat } keys %faqq)
-        {
-            my $q = $faqq{$faqid}->question_html;
-            next unless $q;
-            BML::note_mod_time($faqq{$faqid}->unixmodtime);
-            $q =~ s/^\s+//; $q =~ s/\s+$//;
-            $q =~ s!\n!<br />!g;
-            $ret .= "<li><a href='faqbrowse.bml?faqid=$faqid'>$q</a></li>\n";
-        }
-        $ret .= "</ul>\n";
-    }
-    $ret .= "<?hr?>";
-    $ret .= BML::ml('.faq.back.link', {backlink=>'href="./"'});
-
-    return $ret;
-}
-
-_code?>
-
-<=body
-page?><?_c <LJDEP>
-link: htdocs/support/faqbrowse.bml, htdocs/support/index.bml
-</LJDEP> _c?>
+<!-- this page is not used anymore, see LJ::Support::Controller::FaqList -->

Modified: branches/faq-refactor/htdocs/support/faqbrowse.bml
===================================================================
--- branches/faq-refactor/htdocs/support/faqbrowse.bml	2012-09-28 09:11:04 UTC (rev 22999)
+++ branches/faq-refactor/htdocs/support/faqbrowse.bml	2012-09-28 09:17:39 UTC (rev 23000)
@@ -1,249 +1,2 @@
-<?page
-head<=
-<?searchcss?>
-
-<script language='JavaScript'>
-<!--
-    function showAnswer() {
-        if (!document.getElementById) {
-            return true;
-        }
-        var a = document.getElementById('answer');
-        var r = document.getElementById('rm');
-        if (!a || !r) {
-            return true;
-        }
-        r.style.display = 'none';
-        a.style.display = 'block';
-        return false;
-    }
-//-->
-</script>
-<=head
-body<=
-<?_code
-{
-    use strict;
-    use vars qw(%GET);
-
-    # get faqid and redirect to faq.bml if none
-    my $faqidarg = $GET{'faqid'} + 0;
-    my $faqcatarg = $GET{'faqcat'};
-    
-    unless ($faqidarg || $faqcatarg) {
-        return BML::redirect("faq.bml");
-    }
-    
-    # make title and body references to BML scratch area
-    my $title = \$_[0]->{'title'};
-    my $body = \$_[0]->{'body'};
-    $$body = '';
-    $$title = '';
-
-    # get language settings
-    my $curlang = $GET{'lang'} || BML::get_language();
-    my $deflang = BML::get_language_default();
-    my $altlang = $curlang ne $deflang;
-    my $mll = LJ::Lang::get_lang($curlang);
-    my $mld = LJ::Lang::get_dom("faq");
-    $altlang = 0 unless $mll && $mld;
-    my $lang = $altlang ? $curlang : $deflang;
-
-    my $mode = ($GET{'view'} eq 'full' || $faqidarg) ? 'answer' : 'summary';
-
-    my @faqs;
-
-    my $dbr = LJ::get_db_reader();
-    if ($faqidarg) {
-        # loading single faqid
-        $$title = BML::ml('.title_num', { 'num' => $faqidarg });
-        @faqs = (LJ::Faq->load($faqidarg, lang => $lang));
-
-    } elsif ($faqcatarg) {
-        # loading entire faqcat
-        my $catname;
-        if ($altlang) {
-            $catname = LJ::Lang::get_text($curlang, "cat.$faqcatarg", $mld->{'dmid'});
-        } else {
-            $catname = $dbr->selectrow_array("SELECT faqcatname FROM faqcat WHERE faqcat=?",
-                                                undef, $faqcatarg);
-            die $dbr->errstr if $dbr->err;
-        }
-
-        $$title = BML::ml('.title_cat', { 'catname' => LJ::ehtml($catname) });
-        @faqs = LJ::Faq->load_all(lang => $lang, cat => $faqcatarg);
-    }
-
-    my $remote = LJ::get_remote();
-    my $user;
-    my $user_url;
-
-    # Get remote username and journal URL, or example user's username and journal URL
-    if ($remote) {
-        $user = $remote->user;
-        $user_url = $remote->journal_base;
-    } else {
-        my $u = LJ::load_user($LJ::EXAMPLE_USER_ACCOUNT);
-        $user = $u ? $u->user : "<b>[Unknown or undefined example username]</b>";
-        $user_url = $u ? $u->journal_base : "<b>[Unknown or undefined example username]</b>";
-    }
-
-    LJ::Faq->render_in_place({lang => $lang, user => $user, url => $user_url}, @faqs);
-
-    my $count = 0;
-    my $dbh;
-    my $backfaqcat;
-    my $categoryname;
-    foreach my $f (@faqs) {
-        my $faqid = $f->faqid; # Used throughout, including in interpolations
-        $dbh ||= LJ::get_db_writer();
-
-        # log this faq view
-        if ($remote && ! $LJ::DISABLED{faquses}) {
-            $dbh->do("REPLACE INTO faquses (faqid, userid, dateview) ".
-                     "VALUES (?, ?, NOW())", undef, $faqid,
-                     $remote->{'userid'});
-        }
-
-        BML::note_mod_time($f->unixmodtime);
-
-        my $summary = $f->summary_raw;
-        my $answer = $f->answer_raw;
-
-        # Old FAQs don't have summaries, so show the answer instead
-        $summary = $answer unless $f->has_summary;
-
-        # escape question
-        my $question = $f->question_html;
-        $question =~ s/^\s+//; $question =~ s/\s+$//;
-        $question =~ s/\n/<br \/>/g;
-        
-        # Clean this as if it were an entry, but don't allow lj-cuts
-        LJ::CleanHTML::clean_event(\$summary, {'ljcut_disable' => 1});
-        LJ::CleanHTML::clean_event(\$answer,  {'ljcut_disable' => 1})
-            if $f->has_summary;
-
-        # Highlight search terms
-        my $term = sub {
-            my $xterm = shift;
-            return $xterm if $xterm =~ m!^https?://!;
-            return "<span class='searchhighlight'>" . LJ::ehtml($xterm) . "</span>";
-        };
-        my $qterm = $GET{'q'};
-        if ($qterm) {
-            $question =~ s/(\Q$qterm\E)/$term->($1)/ige;
-
-            # don't highlight terms in URLs or HTML tags
-            $summary =~ s!((?:https?://[^>]+)?\Q$qterm\E)!$term->($1)!ige
-                unless $summary =~ m!<[^>]*\Q$qterm\E[^>]*>!;
-
-            $answer =~ s!((?:https?://[^>]+)?\Q$qterm\E)!$term->($1)!ige
-                unless $answer =~ m!<[^>]*\Q$qterm\E[^>]*>!;
-        }
-
-        if (LJ::are_hooks("faq.$faqid.transform")) {
-           # run hook to transform the text of this FAQ before it's finally rendered
-           LJ::run_hook("faq.$faqid.transform", $remote,
-                        question => \$question, summary => \$summary, answer => \$answer);
-        }
-
-        # display output
-        $$body .= "<?h1";
-        if ($faqcatarg) {
-            $$body .= " <a style='text-decoration: none;' " .
-                      "href='faqbrowse.bml?faqid=$faqid'>&#x00bb;</a>";
-        }
-        $$body .= " $question h1?>";
-        $$body .= "<div style='margin-left: 20px;'>";
-
-        $$body .= "<div name='summary' id='summary'>$summary</div>";
-        $$body .= "<br />";
-
-        if ($mode eq 'summary' && $f->has_summary) {
-            my $q = $qterm ? "&amp;q=" . LJ::eurl($qterm) : '';
-
-            $$body .= "<div id='rm' name='rm'>";
-            my $oc = $faqcatarg ? '' : "onclick='return showAnswer();'";
-            $$body .= "<b>(&nbsp;<a $oc href='faqbrowse.bml?faqid=$faqid$q&amp;view=full'>" .
-                "$ML{'.more'}</a>&nbsp;)</b>";
-            $$body .= "</div>";
-        }
-
-        if (!$faqcatarg && $f->has_summary) {
-            # If we're just viewing one faq and it has a summary
-            if ($mode eq 'answer') {
-                $$body .= "<div id='answer' name='answer'>$answer</div>";
-            } else {
-                $$body .= "<div id='answer' name='answer' style='display: none'>$answer</div>";
-            }
-        }
-
-        $$body .= "</div>";
-
-        my $lastmodwho = LJ::get_username($f->lastmoduserid);
-        if ($lastmodwho) {
-            $$body .= "<p align=\"right\"><b>$ML{'.lastupdated'}</b><br />"
-                . $f->lastmodtime . " ($lastmodwho)</p>";
-        }
-
-        $backfaqcat = $f->faqcat;
-        if (LJ::check_priv($remote, "faqedit", "*") ||
-            LJ::check_priv($remote, "faqedit", $backfaqcat))
-        {
-            $$body .= "<p align=\"right\"><a href=\"/admin/faq/faqedit.bml?id=$faqid\">$ML{'.edit.faq'}</a></p>";
-        }
-
-        # this is incredibly ugly. i'm sorry.
-        if ($altlang && LJ::check_priv($remote, "translate", $curlang)) {
-            my @itids;
-            push @itids, LJ::Lang::get_itemid($mld->{'dmid'}, "$faqid.$_")
-                foreach qw(1question 3summary 2answer);
-            my $items = join(",", map { $mld->{'dmid'} . ":" . $_ } @itids);
-            $$body .= "<p align=\"right\"><a href=\"/translate/editpage.bml?lang=$curlang&amp;items=$items\">";
-            $$body .= "$ML{'.translate.faq'}</a></p>";
-        }
-
-        $count++;
-
-        # get the name of this faq's category, if loading a single faqid
-        if ($faqidarg) {
-            if ($altlang) {
-                $categoryname = LJ::Lang::get_text($curlang, "cat.$backfaqcat", $mld->{'dmid'});
-            } else {
-                $categoryname = $dbr->selectrow_array("SELECT faqcatname FROM faqcat WHERE faqcat=?",
-                                             undef, $backfaqcat);
-            }
-        }
-     }
-
-     # nothing found?
-     unless ($count) {
-         $$title = $ML{'Error'};
-         $$body .= "<p><b>$ML{'.error.nofaq'}</b></p>\n";
-     }
-
-     $$body .= "<?hr?>";
-
-     if ($categoryname) {
-         $$body .= BML::ml('.backfaqcat3', {'aopts' => "href='/support/faqbrowse.bml?faqcat=$backfaqcat'", 'categoryname' => $categoryname}) . "<br />"
-            if $backfaqcat && $faqidarg;
-     } else {
-         $$body .= BML::ml('.backfaqcat2', {'aopts' => "href='/support/faqbrowse.bml?faqcat=$backfaqcat'"}) . "<br />"
-            if $backfaqcat && $faqidarg;
-     }
-
-     $$body .= BML::ml('.backfaq2', { 'aopts' => 'href="faq.bml"' }) . "<br />";
-     $$body .= BML::ml('.backsearch', { 'aopts' => 'href="/support/faqsearch.bml"' }) . "<br />";
-     $$body .= BML::ml('.backsupport2', { 'aopts' => 'href="/support/"' });
-
-     # we're dynamic, set title as crumb title
-     LJ::set_dynamic_crumb($_[0]->{'title'}, 'faq');
-
-     return $_[0]->{'body'};
-}
-_code?>
-<=body
-title=><?_code return $_[0]->{'title'}; _code?>
-page?><?_c <LJDEP>
-link: htdocs/support/index.bml, htdocs/support/faq.bml
-</LJDEP> _c?>
+<!-- this page is not used anymore, see LJ::Support::Controller::FaqItem /
+    LJ::Support::Controller::FaqCat -->

Modified: branches/faq-refactor/htdocs/support/faqsearch.bml
===================================================================
--- branches/faq-refactor/htdocs/support/faqsearch.bml	2012-09-28 09:11:04 UTC (rev 22999)
+++ branches/faq-refactor/htdocs/support/faqsearch.bml	2012-09-28 09:17:39 UTC (rev 23000)
@@ -1,112 +1 @@
-<?_code
-{
-    use strict;
-    use vars qw(%GET $title $body);
-
-    $title = $ML{'.title'};
-
-    $body = "<?standout $ML{'.info'} standout?><br />";
-    $body .= "<form method='GET'>";
-    $body .= "<table><tr><td>$ML{'.label.term'}: </td>";
-    $body .= "<td>" . LJ::html_text({ size => 30, value => $GET{'q'}, name => 'q' });
-    $body .= "&nbsp;" . LJ::html_submit($ML{'.button.search'});
-    $body .= "</td></tr>";
-
-    $body .= "<tr><td>";
-
-    my @langs;
-    foreach my $code (@LJ::LANGS) {
-        my $l = LJ::Lang::get_lang($code);
-        next unless $l;
-
-        my $item = "langname.$code";
-        my $namethislang = BML::ml($item);
-        my $namenative = LJ::Lang::get_text($l->{'lncode'}, $item);
-
-        push @langs, $code;
-
-        my $s = $namenative;
-        $s .= " ($namethislang)" if $namethislang ne $namenative;
-        push @langs, $s;
-    }
-
-    my $curr = BML::get_language();
-    $body .= "$ML{'.label.lang'}: ";
-    $body .= "</td><td>";
-    my $sel = $GET{'lang'} || $curr;
-    $body .= LJ::html_select
-        ({ name => 'lang',
-           selected => $sel, },
-         @langs);
-    
-    $body .= "&nbsp;$ML{'.example'}";
-    $body .= "</td></tr></table></form>";
-
-    my $q = $GET{'q'};
-    if (defined $q && !$q) {
-        $body .= "<p><i>($ML{'.error.noterm'})</i></p>";
-        return;
-    }
-
-    if (defined $q && length $q < 2) {
-        $body .= "<p><i>($ML{'.error.tooshort'})</i></p>";
-        return;
-    }
-
-    # If for some other reason it isn't set or
-    # this is an initial page load
-    return unless $q;
-
-    my $lang = $GET{lang} || $curr || $LJ::DEFAULT_LANG;
-    my $remote = LJ::get_remote();
-    my $user;
-    my $user_url;
-
-    # Get remote username and journal URL, or example user's username and journal URL
-    if ($remote) {
-        $user = $remote->user;
-        $user_url = $remote->journal_base;
-    } else {
-        my $u = LJ::load_user($LJ::EXAMPLE_USER_ACCOUNT);
-        $user = $u ? $u->user : "<b>[Unknown or undefined example username]</b>";
-        $user_url = $u ? $u->journal_base : "<b>[Unknown or undefined example username]</b>";
-    }
-
-    my @results = LJ::Faq->load_matching($q, lang => $lang, user => $user, url => $user_url);
-
-    if (@results < 1) { # ain't no results
-        $body .= "<p><i>($ML{'.error.noresults'})</i></p>";
-        return;
-    }
-
-    if (@results > 25) { @results = @results[0..24]; }
-
-    my $term = sub {
-        my $term = shift;
-        return "<span class='searchhighlight'>" . LJ::ehtml($term) . "</span>";
-    };
-
-    $body .= "<ul class='spaced'>";
-    foreach my $f (@results) {
-        my $dq = $f->question_html;
-        $dq =~ s/\Q$q\E/$term->($&)/ige;
-        my $ueq = LJ::eurl($q);
-        my $ul = $GET{'lang'} ne $curr ? "&amp;lang=".$GET{'lang'} : '';
-
-        $body .= "<li><a href='/support/faqbrowse.bml?faqid="
-            . $f->faqid . "&amp;q=$ueq$ul'>$dq</a></li>";
-    }
-    $body .= "</ul>";
-
-    return;
-}
-_code?><?page
-title=><?_code return $title; _code?>
-body=><?_code  return $body; _code?>
-head<=
-<?searchcss?>
-<style type="text/css">
-ul.spaced li { margin-top: 0.7em; }
-</style>
-<=head
-page?>
+<!-- this page is not used anymore, see LJ::Support::Controller::FaqSearch -->

Tags: ailyin, andy, bml, livejournal, pm
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