Refactor out common code to calculate the tag uri for a user; update
comments.
Patch by kareila.
diffs (121 lines):
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>
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog