fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-06-25 07:26 am

[dw-free] add LJ::mysql_date and $u->atomid

[commit: http://hg.dwscoalition.org/dw-free/rev/f85d8534fa0f]

http://bugs.dwscoalition.org/show_bug.cgi?id=2738

Refactor out common code to calculate the tag uri for a user; update
comments.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/Entry.pm
  • cgi-bin/LJ/User.pm
  • cgi-bin/ljfeed.pl
  • cgi-bin/ljtimeutil.pl
--------------------------------------------------------------------------------
diff -r 6dd5f7c17c23 -r f85d8534fa0f cgi-bin/LJ/Entry.pm
--- a/cgi-bin/LJ/Entry.pm	Fri Jun 25 15:08:51 2010 +0800
+++ b/cgi-bin/LJ/Entry.pm	Fri Jun 25 15:32:49 2010 +0800
@@ -560,10 +560,8 @@ sub atom_id {
 
     my $u       = $self->{u};
     my $ditemid = $self->ditemid;
-    my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = gmtime( $u->timecreate );
-    my $journalcreated = sprintf( "%04d-%02d-%02d", $year+1900, $mon+1, $mday );
 
-    return "tag:$LJ::DOMAIN,$journalcreated:$u->{userid}:$ditemid";
+    return $u->atomid . ":$ditemid";
 }
 
 # returns an XML::Atom::Entry object for a feed
diff -r 6dd5f7c17c23 -r f85d8534fa0f cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm	Fri Jun 25 15:08:51 2010 +0800
+++ b/cgi-bin/LJ/User.pm	Fri Jun 25 15:32:49 2010 +0800
@@ -5653,6 +5653,13 @@ sub subscriptions {
 =head2 Syndication-Related Functions
 =cut
 
+# generate tag URI for user's atom id (RFC 4151)
+sub atomid {
+    my ( $u ) = @_;
+    my $journalcreated = LJ::mysql_date( $u->timecreate, 1 );
+    return "tag:$LJ::DOMAIN,$journalcreated:$u->{userid}";
+}
+
 # retrieve hash of basic syndicated info
 sub get_syndicated {
     my $u = shift;
diff -r 6dd5f7c17c23 -r f85d8534fa0f cgi-bin/ljfeed.pl
--- a/cgi-bin/ljfeed.pl	Fri Jun 25 15:08:51 2010 +0800
+++ b/cgi-bin/ljfeed.pl	Fri Jun 25 15:32:49 2010 +0800
@@ -440,9 +440,6 @@ sub create_view_atom
     $author->email( $journalu->email_for_feeds ) if $journalu && $journalu->email_for_feeds;
     $author->name(  $u->{'name'} );
 
-    my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = gmtime( $u->timecreate );
-    my $journalcreated = sprintf( "%04d-%02d-%02d", $year+1900, $mon+1, $mday );
-
     # feed information
     unless ($opts->{'single_entry'}) {
         $feed = XML::Atom::Feed->new( Version => 1 );
@@ -456,7 +453,7 @@ sub create_view_atom
         $xml->insertBefore( $xml->createComment( LJ::Hooks::run_hook("bot_director") ), $xml->documentElement());
 
         # attributes
-        $feed->id( "tag:$LJ::DOMAIN,$journalcreated:$u->{userid}" );
+        $feed->id( $u->atomid );
         $feed->title( $j->{'title'} || $u->{user} );
         if ( $j->{'subtitle'} ) {
             $feed->subtitle( $j->{'subtitle'} );
@@ -516,7 +513,7 @@ sub create_view_atom
         my $entry = XML::Atom::Entry->new( Version => 1 );
         my $entry_xml = $entry->{doc};
 
-        $entry->id( "tag:$LJ::DOMAIN,$journalcreated:$u->{userid}:$ditemid" );
+        $entry->id( $u->atomid . ":$ditemid" );
 
         # author isn't required if it is in the main <feed>
         # only add author if we are in a single entry view, or
@@ -895,9 +892,7 @@ sub create_view_userpics {
     $xml->insertBefore( $xml->createComment( $bot ), $xml->documentElement())
         if $bot;
 
-    my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = gmtime( $u->timecreate );
-    my $journalcreated = sprintf( "%04d-%02d-%02d", $year+1900, $mon+1, $mday );
-    $feed->id( "tag:$LJ::DOMAIN,$journalcreated:$u->{userid}:userpics" );
+    $feed->id( $u->atomid . ":userpics" );
     $feed->title( "$u->{user}'s userpics" );
 
     $feed->author( $author );
@@ -949,7 +944,7 @@ sub create_view_userpics {
         my $entry = XML::Atom::Entry->new( Version => 1 );
         my $entry_xml = $entry->{doc};
 
-        $entry->id( "tag:$LJ::DOMAIN,$journalcreated:$u->{userid}:userpics:$pic->{picid}" );
+        $entry->id( $u->atomid . ":userpics:$pic->{picid}" );
 
         my $title = ($pic->{picid} == $u->{defaultpicid}) ? "default userpic" : "userpic";
         $entry->title( $title );
diff -r 6dd5f7c17c23 -r f85d8534fa0f cgi-bin/ljtimeutil.pl
--- a/cgi-bin/ljtimeutil.pl	Fri Jun 25 15:08:51 2010 +0800
+++ b/cgi-bin/ljtimeutil.pl	Fri Jun 25 15:32:49 2010 +0800
@@ -140,15 +140,8 @@ sub time_to_w3c {
                    $hour, $min, $sec);
 }
 
-# <LJFUNC>
-# name: LJ::mysql_time
-# des:
-# class: time
-# info:
-# args:
-# des-:
-# returns:
-# </LJFUNC>
+# args: time in seconds from epoch; boolean for gmt instead of localtime
+# returns: date and time in ISO format
 sub mysql_time
 {
     my ($time, $gmt) = @_;
@@ -161,6 +154,16 @@ sub mysql_time
                    $ltime[2],
                    $ltime[1],
                    $ltime[0]);
+}
+
+# args: time in seconds from epoch; boolean for gmt instead of localtime
+# returns: date in ISO format
+sub mysql_date {
+    my ( $time, $gmt ) = @_;
+    $time ||= time();
+    my @ltime = $gmt ? gmtime( $time ) : localtime( $time );
+    return sprintf( "%04d-%02d-%02d",
+                    $ltime[5]+1900, $ltime[4]+1, $ltime[3] );
 }
 
 # <LJFUNC>
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org