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

[livejournal] r22960: 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/cgi-bin/LJ/FaqCat.pm
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-24 14:32:48 UTC (rev 22959)
+++ branches/faq-refactor/cgi-bin/LJ/Faq.pm	2012-09-24 14:41:04 UTC (rev 22960)
@@ -48,13 +48,15 @@
 # returns: The newly populated LJ::Faq object.
 # </LJFUNC>
 sub load {
-    my $class = shift;
-    my $faqid = int(shift);
+    my ( $class, $faqid, %opts ) = @_;
+
+    $faqid = int $faqid;
     croak ("invalid faqid: $faqid")
         unless $faqid > 0;
 
-    my %opts = @_;
-    my $lang = delete $opts{lang} || $LJ::DEFAULT_LANG;
+    my $check = delete $opts{'check'};
+    my $lang  = delete $opts{'lang'} || $LJ::DEFAULT_LANG;
+
     croak("unknown parameters: " . join(", ", keys %opts))
         if %opts;
 
@@ -70,6 +72,9 @@
              "FROM faq WHERE faqid=?",
              undef, $faqid);
         die $dbr->errstr if $dbr->err;
+
+        return undef if $check && !$f;
+
         $faq = $class->new(%$f, lang => $lang);
 
     } else { # Don't load fields that lang_update_in_place will overwrite.
@@ -79,6 +84,9 @@
              "FROM faq WHERE faqid=?",
              undef, $faqid);
         die $dbr->errstr if $dbr->err;
+
+        return undef if $check && !$f;
+
         $faq = $class->new(%$f, lang => $lang);
         $faq->lang_update_in_place;
     }
@@ -205,6 +213,13 @@
     return $self->{sortorder};
 }
 
+sub page_url {
+    my ($self) = @_;
+
+    my $faqid = $self->faqid;
+    return "$LJ::SITEROOT/support/faq/$faqid.html";
+}
+
 # <LJFUNC>
 # name: LJ::Faq::has_summary
 # class: general
@@ -488,4 +503,13 @@
     return sort { $scores{$b->{faqid}} <=> $scores{$a->{faqid}} } @results;
 }
 
+sub note_usage {
+    my ( $self, $remote ) = @_;
+
+    my $dbh = LJ::get_db_writer();
+    $dbh->do(
+        'REPLACE INTO faquses SET faqid=?, userid=?, dateview=NOW()',
+        undef, $self->faqid, $remote->userid );
+}
+
 1;

Modified: branches/faq-refactor/cgi-bin/LJ/FaqCat.pm
===================================================================
--- branches/faq-refactor/cgi-bin/LJ/FaqCat.pm	2012-09-24 14:32:48 UTC (rev 22959)
+++ branches/faq-refactor/cgi-bin/LJ/FaqCat.pm	2012-09-24 14:41:04 UTC (rev 22960)
@@ -1,6 +1,8 @@
 package LJ::FaqCat;
 use strict;
 
+my $faq_dmid;
+
 sub new {
     my $class = ref $_[0] ? ref shift : shift;
     my $opts  = ref $_[0] ? shift : {@_};
@@ -40,7 +42,43 @@
     return @res;
 }
 
+sub load {
+    my ( $class, $id ) = @_;
+    my ($faqcat) = $class->load_by_ids($id);
+    return $faqcat;
+}
 
+sub load_all {
+    my ($class) = @_;
 
+    my $dbh = LJ::get_db_reader();
+    my $rows = $dbh->selectall_arrayref(
+        'SELECT * FROM faqcat ORDER BY catorder', { 'Slice' => {} } );
+
+    return map { $class->new($_) } @$rows;
+}
+
+sub catname_display {
+    my ( $self, $lang ) = @_;
+
+    if ( $lang eq $LJ::DEFAULT_LANGUAGE ) {
+        return $self->faqcatname;
+    }
+
+    unless ( defined $faq_dmid ) {
+        my $dom = LJ::Lang::get_dom('faq');
+        $faq_dmid = $dom->{'dmid'};
+    }
+
+    my $varname = 'cat.' . $self->faqcat;
+    return LJ::Lang::get_text( $lang, $varname, $faq_dmid );
+}
+
+sub page_url {
+    my ($self) = @_;
+
+    my $faqcat = $self->faqcat;
+    return "$LJ::SITEROOT/support/faq/cat/$faqcat.html";
+}
+
 1;
-

Modified: branches/faq-refactor/htdocs/support/faqsearch.bml
===================================================================
--- branches/faq-refactor/htdocs/support/faqsearch.bml	2012-09-24 14:32:48 UTC (rev 22959)
+++ branches/faq-refactor/htdocs/support/faqsearch.bml	2012-09-24 14:41:04 UTC (rev 22960)
@@ -49,8 +49,8 @@
     }
 
     if (defined $q && length $q < 2) {
-	$body .= "<p><i>($ML{'.error.tooshort'})</i></p>";
-	return;
+        $body .= "<p><i>($ML{'.error.tooshort'})</i></p>";
+        return;
     }
 
     # If for some other reason it isn't set or
@@ -82,18 +82,18 @@
     if (@results > 25) { @results = @results[0..24]; }
 
     my $term = sub {
-	my $term = shift;
-	return "<span class='searchhighlight'>" . LJ::ehtml($term) . "</span>";
+        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 $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="
+        $body .= "<li><a href='/support/faqbrowse.bml?faqid="
             . $f->faqid . "&amp;q=$ueq$ul'>$dq</a></li>";
     }
     $body .= "</ul>";

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