журнал журнал (shhh) wrote in changelog,
журнал журнал
shhh
changelog

[livejournal] r23410: LJSUP-14463: XML-RPC: To extend getevent...

Committer: nnikulochkina
LJSUP-14463: XML-RPC: To extend getevents function
U   trunk/cgi-bin/ljprotocol.pl
Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2012-12-03 14:18:18 UTC (rev 23409)
+++ trunk/cgi-bin/ljprotocol.pl	2012-12-04 07:49:52 UTC (rev 23410)
@@ -104,6 +104,7 @@
      "222" => E_PERM,    
      "223" => E_TEMP,
      "224" => E_TEMP,
+     "225" => E_TEMP,
 
      # Access Errors
      "300" => E_TEMP,
@@ -4181,6 +4182,81 @@
         my $in = join(',', @ids) || "0";
         $where = "AND jitemid IN ($in)";
     }
+    elsif ($req->{'selecttype'} eq 'tag') {
+        
+        my $empty_res = {
+            skip => $skip,
+            xc3  => { u => $u },
+            events => [],
+        };
+
+        my $howmany = $req->{'howmany'} || 20;
+        if ($howmany > 50) { $howmany = 50; }
+        $howmany = $howmany + 0;
+
+        $limit = "LIMIT $howmany";
+        $offset = "OFFSET $skip";
+
+        my $jitemids;
+
+        my ($tagids, $tagnames, $tags, $known_tags) = ([], [], {}, {});
+
+        return fail($err,225)
+            unless LJ::Tags::is_valid_tagstring($req->{'tags'}, $tagnames, { omit_underscore_check => 1 });
+
+        $tags = LJ::Tags::get_usertags($uowner, { remote => $u });
+        
+        return $empty_res unless $tags && %$tags;
+
+        while ( my ($tid, $tag) = each %$tags ) {
+            $known_tags->{LJ::Text->normalize_tag_name($tag->{name})} = $tid;
+        }
+
+        my $tagmode = lc $req->{'tagmode'};
+
+        $tagids = [ map {
+            my $tid = $known_tags->{LJ::Text->normalize_tag_name($_)};
+            $tid ? 
+                $tid : 
+                ( $tagmode eq 'and' ? return $empty_res : () ); 
+        } @$tagnames ];
+
+        return $empty_res unless $tagids && @$tagids;
+        
+        if ($tagmode eq 'and') {
+
+            my $limit = $LJ::TAG_INTERSECTION;
+            $#{$tagids} = $limit - 1 if @{$tagids} > $limit;
+            my $in = join(',', map { $_+0 } @{$tagids});
+            my $sth = $dbcr->prepare("SELECT jitemid, kwid FROM logtagsrecent WHERE journalid = ? AND kwid IN ($in)");
+            $sth->execute($ownerid);
+
+            my %mix;
+            while (my $row = $sth->fetchrow_arrayref) {
+                my ($jitemid, $kwid) = @$row;
+                $mix{$jitemid}++;
+            }
+
+            my $need = @{$tagids};
+            foreach my $jitemid (keys %mix) {
+                delete $mix{$jitemid} if $mix{$jitemid} < $need;
+            }
+            
+            $jitemids = [keys %mix];
+        } else { # mode: 'or'
+            # select jitemids uniquely
+            my $in = join(',', map { $_+0 } @{$tagids});
+            $jitemids = $dbcr->selectcol_arrayref(qq{
+                SELECT DISTINCT jitemid FROM logtagsrecent WHERE journalid = ? AND kwid IN ($in)
+                }, undef, $ownerid);
+        }
+
+        return $empty_res unless @$jitemids;
+   
+        $where = " AND jitemid IN (" .
+            join(',', map { $_ + 0 } @$jitemids) .
+            ")";
+    }
     else {
         return fail($err,200,'xmlrpc.des.bad_value',{'param'=>'selecttype'});
     }

Tags: livejournal, nikulochkina, nnikulochkina, 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