[Slashdotjp-dev 1552] [1083] * Add authors journal mode

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 3月 26日 (木) 17:35:40 JST


Revision: 1083
          http://svn.sourceforge.jp/view?root=slashdotjp&view=rev&rev=1083
Author:   tach
Date:     2009-03-26 17:35:40 +0900 (Thu, 26 Mar 2009)

Log Message:
-----------
 * Add authors journal mode
   - /journal.pl?op=authorview
 * Smart URL for authors
   - /authors/ => /authors.pl
   - /authors/journal/ => /journal.pl?op=authorview

Modified Paths:
--------------
    slashjp/trunk/Slash/Apache/User/User.pm
    slashjp/trunk/debian/changelog
    slashjp/trunk/plugins/Journal/journal.pl
    slashjp/trunk/plugins/Journal/templates/data;journal;default


-------------- next part --------------
Modified: slashjp/trunk/Slash/Apache/User/User.pm
===================================================================
--- slashjp/trunk/Slash/Apache/User/User.pm	2009-03-25 05:16:16 UTC (rev 1082)
+++ slashjp/trunk/Slash/Apache/User/User.pm	2009-03-26 08:35:40 UTC (rev 1083)
@@ -637,6 +637,29 @@
 		return OK;
 	}
 
+	# authors for slashdot.jp
+	if ($uri =~ m!^/authors(/[^?]*|/?)(\?.*)?$!) {
+		my($word, $query) = ($1, $2);
+		if ($word =~ s!/{2,}!/!g || $word =~ s!([^/])\z!$1/! || $word =~ s!^\z!/!) {
+			redirect($constants->{real_rootdir} . "/authors$word$query", 301);
+		}
+		$query =~ s/^\?//;
+		my $file = undef;
+		if ($word eq '/') {
+			$file = '/authors.pl';
+		} elsif ($word eq '/journal/') {
+			$file = '/journal.pl';
+			my @args = ($query);
+			push(@args, 'op=authorview');
+			$query = join('&', @args);
+		} else {
+			return NOT_FOUND;
+		}
+		$r->uri($file);
+		$r->args($query);
+		$r->filename($constants->{basedir} . $file);
+	}
+
 	# for self-references (/~/ and /my/)
 	if (($saveuri =~ m[^/(?:%7[eE]|~)] && $uri =~ m[^/~ (?: /(.*) | /? ) $]x)
 		# /my/ or /my can match, but not /mything

Modified: slashjp/trunk/debian/changelog
===================================================================
--- slashjp/trunk/debian/changelog	2009-03-25 05:16:16 UTC (rev 1082)
+++ slashjp/trunk/debian/changelog	2009-03-26 08:35:40 UTC (rev 1083)
@@ -12,8 +12,13 @@
   * Fix getStoryByTime() condition (never return "neverdisplay" stories)
   * Enable to use absolute path for content:encoded link in RSS.pm
   * Hide topics that is not searchable
+  * Add authors journal mode
+    - /journal.pl?op=authorview
+  * Smart URL for authors
+    - /authors/ => /authors.pl
+    - /authors/journal/ => /journal.pl?op=authorview
 
- -- Taku YASUI <tach****@osdn*****>  Tue, 24 Mar 2009 11:07:59 +0000
+ -- Taku YASUI <tach****@osdn*****>  Thu, 26 Mar 2009 08:33:54 +0000
 
 slash (2.5.0.233-7) unstable; urgency=low
 

Modified: slashjp/trunk/plugins/Journal/journal.pl
===================================================================
--- slashjp/trunk/plugins/Journal/journal.pl	2009-03-25 05:16:16 UTC (rev 1082)
+++ slashjp/trunk/plugins/Journal/journal.pl	2009-03-26 08:35:40 UTC (rev 1083)
@@ -74,6 +74,7 @@
 		searchusers	=> [ 1,			\&searchUsers		],
 		friends		=> [ 1,			\&displayFriends	],
 		friendview	=> [ 1,			\&displayArticleFriends	],
+		authorview	=> [ 1,			\&displayArticleAuthors	],
 
 		default		=> [ 1,			\&displayFriends	],
 	);
@@ -462,6 +463,80 @@
 	print getData('journalfoot');
 }
 
+sub displayArticleAuthors {
+	my($journal, $constants, $user, $form, $journal_reader) = @_;
+	my($date, $forward, $back, $nickname, $uid);
+	my @collection;
+	my $header_options = {};
+	my $links = {
+		title		=> 'authors journal',
+	};
+
+	_printHead('authorhead', { no_usermenu => 1 }) or return;
+
+	# clean it up
+	my $start = fixint($form->{start}) || 0;
+	my $uids = [ keys(%{$journal_reader->getAuthors()}) ];
+	my $articles = $journal_reader->getsByUids($uids, $start,
+		$constants->{journal_default_display} + 1
+	);
+
+	unless ($articles && @$articles) {
+		print getData('noviewfriends');
+		print getData('journalfoot');
+		return;
+	}
+
+	# check for extra articles ... we request one more than we need
+	# and if we get the extra one, we know we have extra ones, and
+	# we pop it off
+	if (@$articles == $constants->{journal_default_display} + 1) {
+		pop @$articles;
+		$forward = $start + $constants->{journal_default_display};
+	} else {
+		$forward = 0;
+	}
+
+	# if there are less than journal_default_display remaning,
+	# just set it to 0
+	if ($start > 0) {
+		$back = $start - $constants->{journal_default_display};
+		$back = $back > 0 ? $back : 0;
+	} else {
+		$back = -1;
+	}
+
+	my $topics = $journal_reader->getTopics;
+	for my $article (@$articles) {
+		my $commentcount = $article->[6]
+			? $journal_reader->getDiscussion($article->[6], 'commentcount')
+			: 0;
+
+		# should get comment count, too -- pudge
+		push @collection, {
+			article		=> balanceTags(strip_mode($article->[1], $article->[4]), { deep_nesting => 1 }),
+			date		=> $article->[0],
+			description	=> strip_notags($article->[2]),
+			topic		=> $topics->{$article->[5]},
+			discussion	=> $article->[6],
+			id		=> $article->[3],
+			commentcount	=> $commentcount,
+			uid		=> $article->[7],
+			nickname	=> $article->[8],
+		};
+	}
+
+	slashDisplay('authorsview', {
+		articles	=> \@collection,
+		uid		=> $uid,
+		nickname	=> $nickname,
+		back		=> $back,
+		forward		=> $forward,
+	});
+
+	print getData('journalfoot');
+}
+
 sub displayArticle {
 	my($journal, $constants, $user, $form, $journal_reader) = @_;
 	my($date, $forward, $back, @sorted_articles, $nickname, $uid, $karma, $discussion);

Modified: slashjp/trunk/plugins/Journal/templates/data;journal;default
===================================================================
--- slashjp/trunk/plugins/Journal/templates/data;journal;default	2009-03-25 05:16:16 UTC (rev 1082)
+++ slashjp/trunk/plugins/Journal/templates/data;journal;default	2009-03-26 08:35:40 UTC (rev 1083)
@@ -94,6 +94,10 @@
 [% CASE 'rss_fv_desc' %]
 	[% nickname %]'s Friends' [% constants.sitename %] Journals
 
+[% CASE 'authorhead' %]
+	[% returnme.data_constant = 1 %]
+	[% constants.sitename %] Authors' Journal
+
 [% END %]
 
 __seclev__



Slashdotjp-dev メーリングリストの案内
Back to archive index