[Slashdotjp-dev 496] CVS update: slashjp/plugins/YASS

Zurück zum Archiv-Index

Tatsuki SUGIURA sugi****@users*****
2006年 7月 12日 (水) 20:42:07 JST


Index: slashjp/plugins/YASS/PLUGIN
diff -u slashjp/plugins/YASS/PLUGIN:1.2 slashjp/plugins/YASS/PLUGIN:1.3
--- slashjp/plugins/YASS/PLUGIN:1.2	Fri Dec 24 05:13:47 2004
+++ slashjp/plugins/YASS/PLUGIN	Wed Jul 12 20:42:07 2006
@@ -1,4 +1,4 @@
-# $Id: PLUGIN,v 1.2 2004/12/23 20:13:47 oliver Exp $
+# $Id: PLUGIN,v 1.3 2006/07/12 11:42:07 sugi Exp $
 name=YASS
 description="YASS lets you keep url lists from links in stories"
 htdoc=sites.pl
Index: slashjp/plugins/YASS/YASS.pm
diff -u slashjp/plugins/YASS/YASS.pm:1.2 slashjp/plugins/YASS/YASS.pm:1.3
--- slashjp/plugins/YASS/YASS.pm:1.2	Fri Dec 24 05:13:47 2004
+++ slashjp/plugins/YASS/YASS.pm	Wed Jul 12 20:42:07 2006
@@ -1,7 +1,7 @@
 # This code is a part of Slash, and is released under the GPL.
-# Copyright 1997-2004 by Open Source Development Network. See README
+# Copyright 1997-2005 by Open Source Technology Group. See README
 # and COPYING for more information, or see http://slashcode.com/.
-# $Id: YASS.pm,v 1.2 2004/12/23 20:13:47 oliver Exp $
+# $Id: YASS.pm,v 1.3 2006/07/12 11:42:07 sugi Exp $
 
 package Slash::YASS;
 
@@ -14,7 +14,7 @@
 use base 'Slash::DB::Utility';
 use base 'Slash::DB::MySQL';
 
-($VERSION) = ' $Revision: 1.2 $ ' =~ /\$Revision:\s+([^\s]+)/;
+($VERSION) = ' $Revision: 1.3 $ ' =~ /\$Revision:\s+([^\s]+)/;
 
 sub new {
 	my($class, $user) = @_;
@@ -32,19 +32,38 @@
 
 sub getSidsURLs {
 	my ($self) = @_;
-	$self->sqlSelectAll("sid, value", "story_param", "name='url'");
+	# This was originally written to return an arrayref of
+	# arrayrefs of two values: sid, url.  Since the stories
+	# tables converted to stoids, this became a little more
+	# complicated, but that's OK.
+	my $stoid_value_hr = $self->sqlSelectAllHashref(
+		'stoid',
+		'stoid, value',
+		'story_param',
+		"name='url'");
+	return [ ] if !$stoid_value_hr || !%$stoid_value_hr;
+	my @stoids = sort keys %$stoid_value_hr;
+	my $stoids_in = join(',', @stoids);
+	my $sid_stoid_ar = $self->sqlSelectAll('sid, stoid', 'stories',
+		"stoid IN ($stoids_in)");
+	# The duples are [sid,stoid] now; replace them in place with
+	# [sid,value].
+	for my $duple (@$sid_stoid_ar) {
+		$duple->[1] = $stoid_value_hr->{ $duple->[1] }{value} || '';
+	}
+	return $sid_stoid_ar;
 }
 
 sub create {
 	my ($self, $hash) = @_;
-	$hash->{'-touched'} = "now()";
+	$hash->{'-touched'} = "NOW()";
 	$self->sqlInsert('yass_sites', $hash);
 }
 
 sub success {
 	my ($self, $id) = @_;
 	my %hash;
-	$hash{'-touched'} = "now()";
+	$hash{'-touched'} = "NOW()";
 	$hash{failures} = "0";
 	$self->sqlUpdate('yass_sites', \%hash, "id = $id");
 }
@@ -59,20 +78,18 @@
 
 sub exists {
 	my ($self, $sid, $url) = @_;
-	my $q_url = $self->sqlQuote($url);
-	my $q_sid = $self->sqlQuote($sid);
-	my $return = 1 
-		if  $self->sqlSelect('id', 'yass_sites', "sid = $q_sid AND url = $q_url");
-	unless ($return) {
-		$return = $self->sqlSelect('sid', 'yass_sites', "sid = $q_sid");
-	}
+	my $url_q = $self->sqlQuote($url);
+	my $sid_q = $self->sqlQuote($sid);
+	my $return = $self->sqlSelect('id', 'yass_sites', "sid = $sid_q AND url = $url_q")
+		|| $self->sqlSelect('id', 'yass_sites', "sid = $sid_q")
+		|| 0;
 	return $return;
 }
 
 sub failed {
 	my ($self, $id) = @_;
 	my %hash;
-	$hash{'-touched'} = "now()";
+	$hash{'-touched'} = "NOW()";
 	$hash{-failures} = "failures+1";
 	$self->sqlUpdate('yass_sites', \%hash, "id = $id");
 }
@@ -91,17 +108,14 @@
 		$order = "ORDER BY title ASC";
 	}
 
-	if($all) {
-		$where = "stories.sid = yass_sites.sid",
-	} else {
-		$where = "stories.sid = yass_sites.sid and failures < $failures",
-	}
+	$where = 'stories.sid = yass_sites.sid AND stories.stoid=story_text.stoid';
+	$where .= " AND failures < $failures" if !$all;
 
 	my $sites = $self->sqlSelectAllHashrefArray(
-		"yass_sites.sid as sid, url, title, id, failures", 
-		"yass_sites, stories", 
+		"yass_sites.sid AS sid, url, title, id, failures", 
+		"yass_sites, stories, story_text", 
 		$where,
-		$order);
+		$order) || [];
 
 	return $sites;
 }
Index: slashjp/plugins/YASS/dump
diff -u slashjp/plugins/YASS/dump:1.2 slashjp/plugins/YASS/dump:1.3
--- slashjp/plugins/YASS/dump:1.2	Fri Dec 24 05:13:47 2004
+++ slashjp/plugins/YASS/dump	Wed Jul 12 20:42:07 2006
@@ -1,5 +1,5 @@
 #
-# $Id: dump,v 1.2 2004/12/23 20:13:47 oliver Exp $
+# $Id: dump,v 1.3 2006/07/12 11:42:07 sugi Exp $
 #
 
 INSERT INTO vars (name, value, description) VALUES ('yass_failures', '14', 'If you have failures for this many days, deactive the site.');
Index: slashjp/plugins/YASS/mysql_schema
diff -u slashjp/plugins/YASS/mysql_schema:1.2 slashjp/plugins/YASS/mysql_schema:1.3
--- slashjp/plugins/YASS/mysql_schema:1.2	Fri Dec 24 05:13:47 2004
+++ slashjp/plugins/YASS/mysql_schema	Wed Jul 12 20:42:07 2006
@@ -1,5 +1,5 @@
 #
-# $Id: mysql_schema,v 1.2 2004/12/23 20:13:47 oliver Exp $
+# $Id: mysql_schema,v 1.3 2006/07/12 11:42:07 sugi Exp $
 #
 
 DROP TABLE IF EXISTS yass_sites;
Index: slashjp/plugins/YASS/sitecheck.pl
diff -u slashjp/plugins/YASS/sitecheck.pl:1.2 slashjp/plugins/YASS/sitecheck.pl:1.3
--- slashjp/plugins/YASS/sitecheck.pl:1.2	Fri Dec 24 05:13:47 2004
+++ slashjp/plugins/YASS/sitecheck.pl	Wed Jul 12 20:42:07 2006
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# $Id: sitecheck.pl,v 1.2 2004/12/23 20:13:47 oliver Exp $
+# $Id: sitecheck.pl,v 1.3 2006/07/12 11:42:07 sugi Exp $
 
 use strict;
 use LWP::UserAgent;
@@ -26,49 +26,53 @@
 
 	slashdLog('Checking YASS sites Begin');
 	my $sids = $yass->getSidsURLs();
-	for (@$sids) {
-		print "checking \t$_->[1]\n";
-		my $value = $yass->exists($_->[0], $_->[1]);
-		if ($value == 1) {
-			print "\texists\n";
+	for my $duple (@$sids) {
+		my($sid, $url) = @$duple;
+		my $logentry;
+		$logentry = "checking sid='$sid' url='$url'...";
+		my $value = $yass->exists($sid, $url);
+		if ($value == -1) {
+			$logentry .= " ok.";
 		} elsif ($value) {
-			my $rdf = $slashdb->getStory($_->[0], 'rdf');
-			$yass->setURL($value, $_->[1], $rdf);
-			print "\tupdating\n";
+			my $rdf = $slashdb->getStory($sid, 'rdf');
+			$yass->setURL($value, $url, $rdf);
+			$logentry .= " updated.";
 		} else {
-			my $rdf = $slashdb->getStory($_->[0], 'rdf');
-			my $time = $slashdb->getStory($_->[0], 'time');
+			my $rdf = $slashdb->getStory($sid, 'rdf');
+			my $time = $slashdb->getStory($sid, 'time');
 			my $return = $yass->create({
-				 sid => $_->[0],
-				 url => $_->[1],
+				 sid => $sid,
+				 url => $url,
 				 rdf => $rdf ? $rdf : '',
 				 created => $time,
-			 });
-			print "\tadding\n";
+			});
+			$logentry .= " added.";
 		}
+		slashdLog($logentry);
 	}
 	my $sites = $yass->getActive();
 	my $junk;
 	my $ua = LWP::UserAgent->new();
 	my($winners, $losers);
-	for (@$sites) {
-		print "$_->{id}\t$_->{url}";
-		my $response = $ua->get($_->{url} . $constants->{yass_extra});
+	for my $hr (@$sites) {
+		my $logentry;
+		$logentry = "checking id=$hr->{id} url='$hr->{url}'...";
+		my $response = $ua->get($hr->{url} . $constants->{yass_extra});
 		if ($response->is_success) {
-			$yass->success($_->{id});
-			print "\tactive\n";
+			$yass->success($hr->{id});
+			$logentry .= " active.";
 			$winners++;
 		} else {
-			$yass->failed($_->{id});
-			print "\tdead\n";
+			$yass->failed($hr->{id});
+			$logentry .= " dead.";
 			$losers++;
 		}
+		slashdLog($logentry);
 	}
 	my $total = $winners + $losers;
-	slashdLog("Total sites $total\tActive Sites $winners\tFailed sites $losers");
 	slashdLog('Checking YASS sites End');
 
-	return ;
+	return "$total sites, $winners active, $losers dead";
 };
 
 1;
Index: slashjp/plugins/YASS/sites.pl
diff -u slashjp/plugins/YASS/sites.pl:1.3 slashjp/plugins/YASS/sites.pl:1.4
--- slashjp/plugins/YASS/sites.pl:1.3	Fri Dec 31 21:37:17 2004
+++ slashjp/plugins/YASS/sites.pl	Wed Jul 12 20:42:07 2006
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# $Id: sites.pl,v 1.3 2004/12/31 12:37:17 oliver Exp $
+# $Id: sites.pl,v 1.4 2006/07/12 11:42:07 sugi Exp $
 
 use strict;
 use Slash;
@@ -14,11 +14,11 @@
 	my $form = getCurrentForm();
 	my $gSkin = getCurrentSkin();
 
-	if ($form->{'content_type'} eq 'rss') {
-		return xmlDisplay('rss', {
+	if ($form->{content_type} =~ $constants->{feed_types}) {
+		return xmlDisplay($form->{content_type} => {
 				channel => {
 				title   => "$constants->{sitename} links",
-				'link'  => "$gSkin->{absolutedir}/sites.pl?content_type=rss",
+				'link'  => "$gSkin->{absolutedir}/sites.pl",
 			},
 			items   => $yass->getActive(15),
 		});


Slashdotjp-dev メーリングリストの案内
Zurück zum Archiv-Index