Tatsuki SUGIURA
sugi****@users*****
2006年 7月 12日 (水) 20:42:07 JST
Index: slashjp/plugins/Zoo/PLUGIN diff -u slashjp/plugins/Zoo/PLUGIN:1.2 slashjp/plugins/Zoo/PLUGIN:1.3 --- slashjp/plugins/Zoo/PLUGIN:1.2 Fri Dec 24 05:13:48 2004 +++ slashjp/plugins/Zoo/PLUGIN Wed Jul 12 20:42:07 2006 @@ -1,4 +1,4 @@ -# $Id: PLUGIN,v 1.2 2004/12/23 20:13:48 oliver Exp $ +# $Id: PLUGIN,v 1.3 2006/07/12 11:42:07 sugi Exp $ name=Zoo description="Friend and Foe system" mysql_schema=mysql_schema Index: slashjp/plugins/Zoo/Zoo.pm diff -u slashjp/plugins/Zoo/Zoo.pm:1.2 slashjp/plugins/Zoo/Zoo.pm:1.3 --- slashjp/plugins/Zoo/Zoo.pm:1.2 Fri Dec 24 05:13:48 2004 +++ slashjp/plugins/Zoo/Zoo.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: Zoo.pm,v 1.2 2004/12/23 20:13:48 oliver Exp $ +# $Id: Zoo.pm,v 1.3 2006/07/12 11:42:07 sugi Exp $ package Slash::Zoo; @@ -16,7 +16,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]+)/; # "There ain't no justice" -Niven # We can try. -Brian @@ -53,14 +53,14 @@ } } return [qw()] unless @people; - - my $rel = $self->sqlSelectAll( + @people = sort { $a <=> $b } @people; + my $people_str = join(",", @people); + + return $self->sqlSelectAll( 'uid, nickname, journal_last_entry_date', 'users', - " uid IN (" . join(",", @people) .") ", - " ORDER BY nickname " - ); - return $rel; + "uid IN ($people_str)", + 'ORDER BY nickname'); } # Get the details for relationships @@ -93,6 +93,7 @@ sub _set { my($self, $uid, $person, $type, $const) = @_; my $slashdb = getCurrentDB(); + #Removed this, since when we make the relationship it will now swap whatever bits we #need swapped, this no longer matters. -Brian # # Lets see if we need to wipe out a relationship first.... @@ -100,6 +101,7 @@ # # We need to check to see if type has value to make sure we are not looking at fan or freak # $self->delete($uid, $person, $current_standing->{type}) # if ($current_standing && $current_standing->{type}); + # First we do the main person # We insert to make sure a position exists for this relationship and then we update. # If I ever removed freak/fan from the table this could be done as a replace. @@ -116,12 +118,24 @@ $self->sqlInsert('people', { uid => $person, person => $uid }, { ignore => 1}); $self->sqlUpdate('people', { perceive => $s_type }, "uid = $person AND person = $uid"); + # Mark other users as dirty (needing to be changed) as + # appropriate, but do it a few at a time with a short + # sleep between, to avoid bogging the master DB or + # lagging its slave DBs. Yes, this method is called + # by interactive code, not (just) the backend, so I + # don't really like adding the sleep(), but we still + # need to do this. my $uid_ar = $self->sqlSelectColArrayref('uid', 'people', "person=$uid AND type='friend'"); push @$uid_ar, $person; - my $uid_list = join (',', @$uid_ar); - $self->sqlUpdate("users_info", { people_status => 'dirty' }, "uid IN ($uid_list)"); - $self->setUser_delete_memcached($uid_ar); + my $splice_count = 100; + while (@$uid_ar) { + my @uid_chunk = splice @$uid_ar, 0, $splice_count; + my $uid_list = join (',', @uid_chunk); + $self->sqlUpdate("users_info", { people_status => 'dirty' }, "uid IN ($uid_list)"); + $self->setUser_delete_memcached($uid_ar); + Time::HiRes::sleep(0.2); + } } @@ -195,7 +209,7 @@ sub getFriendsWithJournals { my($self) = @_; - my $uid = $ENV{SLASH_USER}; + my $uid = getCurrentUser('uid'); my($friends, $journals, $ids, %data); $friends = $self->sqlSelectAll( @@ -229,7 +243,7 @@ sub getFriendsForMessage { my($self) = @_; my $code = MSG_CODE_JOURNAL_FRIEND; - my $uid = $ENV{SLASH_USER}; + my $uid = getCurrentUser('uid'); my $cols = "pp.uid"; my $table = "people AS pp, users_messages as um"; my $where = <<SQL; @@ -256,21 +270,21 @@ sub rebuildUser { my($self, $uid) = @_; - my $data = $self->sqlSelectAllHashrefArray('*', 'people', "uid = $uid"); + my $data = $self->sqlSelectAllHashrefArray('*', 'people', "uid = $uid"); my $people; my @friends; if ($data) { for (@$data) { - if ($_->{type} eq 'friend') { + if ($_->{type} && $_->{type} eq 'friend') { $people->{FRIEND()}{$_->{person}} = 1; push @friends, $_->{person}; - } elsif ($_->{type} eq 'foe') { + } elsif ($_->{type} && $_->{type} eq 'foe') { $people->{FOE()}{$_->{person}} = 1; } - if ($_->{perceive} eq 'fan') { + if ($_->{perceive} && $_->{perceive} eq 'fan') { $people->{FAN()}{$_->{person}} = 1; - } elsif ($_->{perceive} eq 'freak') { + } elsif ($_->{perceive} && $_->{perceive} eq 'freak') { $people->{FREAK()}{$_->{person}} = 1; } } @@ -278,7 +292,7 @@ my $list = join (',', @friends); if (scalar(@friends) && $list) { - $data = $self->sqlSelectAllHashrefArray('*', 'people', "uid IN ($list) AND type IS NOT NULL"); + $data = $self->sqlSelectAllHashrefArray('*', 'people', "uid IN ($list) AND type IS NOT NULL"); for (@$data) { if ($_->{type} eq 'friend') { $people->{FOF()}{$_->{person}}{$_->{uid}} = 1; Index: slashjp/plugins/Zoo/mysql_prep diff -u slashjp/plugins/Zoo/mysql_prep:1.2 slashjp/plugins/Zoo/mysql_prep:1.3 --- slashjp/plugins/Zoo/mysql_prep:1.2 Fri Dec 24 05:13:48 2004 +++ slashjp/plugins/Zoo/mysql_prep Wed Jul 12 20:42:07 2006 @@ -1,5 +1,5 @@ # -# $Id: mysql_prep,v 1.2 2004/12/23 20:13:48 oliver Exp $ +# $Id: mysql_prep,v 1.3 2006/07/12 11:42:07 sugi Exp $ # INSERT INTO vars (name,value,description) VALUES ('people_max','200','Maximum number of friends/foes you can have'); Index: slashjp/plugins/Zoo/mysql_schema diff -u slashjp/plugins/Zoo/mysql_schema:1.2 slashjp/plugins/Zoo/mysql_schema:1.3 --- slashjp/plugins/Zoo/mysql_schema:1.2 Fri Dec 24 05:13:48 2004 +++ slashjp/plugins/Zoo/mysql_schema Wed Jul 12 20:42:07 2006 @@ -1,5 +1,5 @@ # -# $Id: mysql_schema,v 1.2 2004/12/23 20:13:48 oliver Exp $ +# $Id: mysql_schema,v 1.3 2006/07/12 11:42:07 sugi Exp $ # DROP TABLE IF EXISTS people; Index: slashjp/plugins/Zoo/rebuildPeople diff -u slashjp/plugins/Zoo/rebuildPeople:1.2 slashjp/plugins/Zoo/rebuildPeople:1.3 --- slashjp/plugins/Zoo/rebuildPeople:1.2 Fri Dec 24 05:13:48 2004 +++ slashjp/plugins/Zoo/rebuildPeople Wed Jul 12 20:42:07 2006 @@ -1,8 +1,8 @@ #!/usr/bin/perl -w # 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: rebuildPeople,v 1.2 2004/12/23 20:13:48 oliver Exp $ +# $Id: rebuildPeople,v 1.3 2006/07/12 11:42:07 sugi Exp $ use strict; use File::Basename; @@ -14,7 +14,7 @@ use vars qw( $slashdb $werder $constants $junk ); -(my $VERSION) = ' $Revision: 1.2 $ ' =~ /\$Revision:\s+([^\s]+)/; +(my $VERSION) = ' $Revision: 1.3 $ ' =~ /\$Revision:\s+([^\s]+)/; my $PROGNAME = basename($0); my %opts; @@ -63,7 +63,7 @@ $PROGNAME $VERSION 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/. EOT Index: slashjp/plugins/Zoo/rebuildPerson diff -u slashjp/plugins/Zoo/rebuildPerson:1.2 slashjp/plugins/Zoo/rebuildPerson:1.3 --- slashjp/plugins/Zoo/rebuildPerson:1.2 Fri Dec 24 05:13:48 2004 +++ slashjp/plugins/Zoo/rebuildPerson Wed Jul 12 20:42:07 2006 @@ -1,8 +1,8 @@ #!/usr/bin/perl -w # 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: rebuildPerson,v 1.2 2004/12/23 20:13:48 oliver Exp $ +# $Id: rebuildPerson,v 1.3 2006/07/12 11:42:07 sugi Exp $ use strict; use File::Basename; @@ -13,7 +13,7 @@ use vars qw( $slashdb $werder $constants $junk ); -(my $VERSION) = ' $Revision: 1.2 $ ' =~ /\$Revision:\s+([^\s]+)/; +(my $VERSION) = ' $Revision: 1.3 $ ' =~ /\$Revision:\s+([^\s]+)/; my $PROGNAME = basename($0); my %opts; @@ -58,7 +58,7 @@ $PROGNAME $VERSION 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/. EOT Index: slashjp/plugins/Zoo/zoo.pl diff -u slashjp/plugins/Zoo/zoo.pl:1.5 slashjp/plugins/Zoo/zoo.pl:1.6 --- slashjp/plugins/Zoo/zoo.pl:1.5 Fri Dec 31 21:37:18 2004 +++ slashjp/plugins/Zoo/zoo.pl Wed Jul 12 20:42:07 2006 @@ -1,8 +1,8 @@ #!/usr/bin/perl -w # 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: zoo.pl,v 1.5 2004/12/31 12:37:18 oliver Exp $ +# $Id: zoo.pl,v 1.6 2006/07/12 11:42:07 sugi Exp $ use strict; use Slash 2.003; # require Slash 2.3.x @@ -11,482 +11,83 @@ use Slash::Utility; use Slash::Zoo; use Slash::XML; -use Digest::SHA1; use vars qw($VERSION); -($VERSION) = ' $Revision: 1.5 $ ' =~ /\$Revision:\s+([^\s]+)/; +($VERSION) = ' $Revision: 1.6 $ ' =~ /\$Revision:\s+([^\s]+)/; sub main { - my $zoo = getObject('Slash::Zoo'); - my $constants = getCurrentStatic(); - my $slashdb = getCurrentDB(); - my $user = getCurrentUser(); - my $form = getCurrentForm(); - my $gSkin = getCurrentSkin(); - my $formname = 'zoo'; - my $formkey = $form->{formkey}; + my $zoo = getObject('Slash::Zoo'); + my $constants = getCurrentStatic(); + my $slashdb = getCurrentDB(); + my $user = getCurrentUser(); + my $form = getCurrentForm(); + my $gSkin = getCurrentSkin(); # require POST and logged-in user for these ops - my $user_ok = $user->{state}{post} && !$user->{is_anon}; + # we could move even this out to reskeys ... but right now, no real reason to + my $user_ok = $user->{state}{post}; # possible value of "op" parameter in form - my $ops = { - action => { - check => $user_ok, - formkey => ['formkey_check', 'valid_check'], - function => \&action - }, - add => { - check => $user_ok, - formkey => ['formkey_check', 'valid_check'], - function => \&action - }, - 'delete' => { - check => $user_ok, - formkey => ['formkey_check', 'valid_check'], - function => \&action - }, - addcheck => { - check => $user->{seclev}, - formkey => ['generate_formkey'], - function => \&check - }, - deletecheck => { - check => $user->{seclev}, - formkey => ['generate_formkey'], - function => \&check - }, - check => { - check => $user->{seclev}, - formkey => ['generate_formkey'], - function => \&check - }, - friends => { - check => 1, - function => \&friends - }, - fans => { - check => 1, - function => \&fans - }, - foes => { - check => 1, - function => \&foes - }, - freaks => { - check => 1, - function => \&freaks - }, - fof => { - check => 1, - function => \&fof - }, - 'eof' => { - check => 1, - function => \&enof - }, - all => { - check => 1, - function => \&all - }, - foaf => { - check => 1, - function => \&foaf - }, - default => { - check => 0, - function => \&list - }, - }; + my %ops = ( + action => [ $user_ok, \&action ], + check => [ 1, \&check ], + all => [ 1, \&people ], + ); + + $ops{$_} = $ops{action} for qw(add delete); + $ops{$_} = $ops{check} for qw(addcheck deletecheck); + $ops{$_} = $ops{all} for qw(friends fans foes freaks fof eof); - my ($note, $error_flag); my $op = $form->{'op'}; - if ($user->{seclev} < 100) { - if ($ops->{$op}{formkey}) { - for my $check (@{$ops->{$op}{formkey}}) { - $error_flag = formkeyHandler($check, $formname, $formkey, \$note); - $ops->{$op}{update_formkey} = 1 if $check eq 'formkey_check'; - last if $error_flag; - } - } - } - if ($error_flag) { - header() or return; - print $note; - footer(); - return; - } - - if ($ops->{$op}{update_formkey} && $user->{seclev} < 100 && ! $error_flag) { - # successful save action, no formkey errors, update existing formkey - # why assign to an unused variable? -- pudge - my $updated = $slashdb->updateFormkey($formkey, length($ENV{QUERY_STRING})); - } - errorLog("zoo.pl error_flag '$error_flag'") if $error_flag; - - if (!$op || !exists $ops->{$op} || !$ops->{$op}->{check}) { + if (!$op || !exists $ops{$op} || !$ops{$op}[ALLOWED]) { redirect("$gSkin->{rootdir}/"); return; } - $ops->{$op}->{function}->($zoo, $constants, $user, $form, $slashdb, $gSkin); + # We really should have a $zoo_reader that we also pass to + # these functions. - Jamie + + $ops{$op}[FUNCTION]->($zoo, $constants, $user, $form, $slashdb, $gSkin); my $r; if ($r = Apache->request) { return if $r->header_only; } - footer() unless $form->{content_type} eq 'rss' or $form->{content_type} eq 'foaf' or $op eq 'foaf'; -} - -sub list { - my($zoo, $constants, $user, $form, $slashdb, $gSkin) = @_; - # This was never linked to, but basically we send people to search who try to just hit the blank URL - # -Brian - redirect("$gSkin->{rootdir}/search.pl?op=users"); - return 1; -} - -sub friends { - my($zoo, $constants, $user, $form, $slashdb) = @_; - - my ($uid, $nick); - if ($form->{uid} || $form->{nick}) { - $uid = $form->{uid} ? $form->{uid} : $slashdb->getUserUID($form->{nick}); - $nick = $form->{nick} ? $form->{nick} : $slashdb->getUser($uid, 'nickname'); - } else { - $uid = $user->{uid}; - $nick = $user->{nick}; - } - - my $user_change = { }; - if ($uid != $user->{uid} && !isAnon($uid) && !$user->{is_anon}) { - # Store the fact that this user last looked at that user. - # For maximal convenience in stalking. - $user_change->{lastlookuid} = $uid; - $user_change->{lastlooktime} = time; - $user->{lastlookuid} = $uid; - $user->{lastlooktime} = time; - } - - my $editable = ($uid == $user->{uid} ? 1 : 0); - my $friends = $zoo->getRelationships($uid, FRIEND); - - if ($form->{content_type} eq 'rss') { - _rss($friends, $nick, 'friends'); - } elsif ($form->{content_type} eq 'foaf') { - _foaf( $friends, $uid, 'friends' ); - } else { - my $implied; - if ($editable) { - _printHead("yourfriendshead", { - nickname => $nick, - uid => $uid, - tab_selected_1 => 'me', - tab_selected_2 => 'friends' - }) or return; - $implied = FRIEND; - } else { - _printHead("friendshead", { - nickname => $nick, - uid => $uid, - tab_selected_1 => 'otheruser', - tab_selected_2 => 'friends' - }) or return; - } - - if (@$friends) { - slashDisplay('plainlist', { - people => $friends, - editable => $editable, - implied => $implied, - nickname => $nick - }); - } else { - if ($editable) { - print getData('yournofriends'); - } else { - print getData('nofriends', { nickname => $nick, uid => $uid }); - } - } - } - - # Store the new user we're looking at, if any. - if ($user_change && %$user_change) { - $slashdb->setUser($user->{uid}, $user_change); - } - - return 1; -} - -sub fof { - my($zoo, $constants, $user, $form, $slashdb) = @_; - - my ($uid, $nick); - if ($form->{uid} || $form->{nick}) { - $uid = $form->{uid} ? $form->{uid} : $slashdb->getUserUID($form->{nick}); - $nick = $form->{nick} ? $form->{nick} : $slashdb->getUser($uid, 'nickname'); - } else { - $uid = $user->{uid}; - $nick = $user->{nick}; - } - - my $user_change = { }; - if ($uid != $user->{uid} && !isAnon($uid) && !$user->{is_anon}) { - # Store the fact that this user last looked at that user. - # For maximal convenience in stalking. - $user_change->{lastlookuid} = $uid; - $user_change->{lastlooktime} = time; - $user->{lastlookuid} = $uid; - $user->{lastlooktime} = time; - } - - my $editable = ($uid == $user->{uid} ? 1 : 0); - my $friends = $zoo->getRelationships($uid, FOF); - - if ($form->{content_type} eq 'rss') { - _rss($friends, $nick, 'fof'); - } else { - my $implied; - if ($editable) { - _printHead("yourfriendsoffriendshead", { - nickname => $nick, - uid => $uid, - tab_selected_1 => 'me', - tab_selected_2 => 'friends' - }) or return; - $implied = FOF; - } else { - _printHead("friendsoffriendshead", { - nickname => $nick, - uid => $uid, - tab_selected_1 => 'otheruser', - tab_selected_2 => 'friends' - }) or return; - } - - if (@$friends) { - slashDisplay('plainlist', { - people => $friends, - editable => $editable, - implied => $implied, - nickname => $nick - }); - } else { - if ($editable) { - print getData('yournofriendsoffriends'); - } else { - print getData('nofriendsoffriends', { nickname => $nick, uid => $uid }); - } - } - } - - # Store the new user we're looking at, if any. - if ($user_change && %$user_change) { - $slashdb->setUser($user->{uid}, $user_change); - } - - return 1; -} - -sub enof { - my($zoo, $constants, $user, $form, $slashdb) = @_; - - my ($uid, $nick); - if ($form->{uid} || $form->{nick}) { - $uid = $form->{uid} ? $form->{uid} : $slashdb->getUserUID($form->{nick}); - $nick = $form->{nick} ? $form->{nick} : $slashdb->getUser($uid, 'nickname'); - } else { - $uid = $user->{uid}; - $nick = $user->{nick}; - } - - my $user_change = { }; - if ($uid != $user->{uid} && !isAnon($uid) && !$user->{is_anon}) { - # Store the fact that this user last looked at that user. - # For maximal convenience in stalking. - $user_change->{lastlookuid} = $uid; - $user_change->{lastlooktime} = time; - $user->{lastlookuid} = $uid; - $user->{lastlooktime} = time; - } - - my $editable = ($uid == $user->{uid} ? 1 : 0); - my $friends = $zoo->getRelationships($uid, EOF); - - if ($form->{content_type} eq 'rss') { - _rss($friends, $nick, 'friends'); - } else { - my $implied; - if ($editable) { - _printHead("yourfriendsenemieshead", { - nickname => $nick, - uid => $uid, - tab_selected_1 => 'me', - tab_selected_2 => 'friends', - }) or return; - $implied = EOF; - } else { - _printHead("friendsenemieshead", { - nickname => $nick, - uid => $uid, - tab_selected_1 => 'otheruser', - tab_selected_2 => 'friends', - }) or return; - } - - if (@$friends) { - slashDisplay('plainlist', { people => $friends, editable => $editable, implied => $implied, nickname => $nick }); - } else { - if ($editable) { - print getData('yournofriendsenemies'); - } else { - print getData('nofriendsenemies', { nickname => $nick, uid => $uid }); - } - } - } - - # Store the new user we're looking at, if any. - if ($user_change && %$user_change) { - $slashdb->setUser($user->{uid}, $user_change); - } - - return 1; -} - -sub foes { - my($zoo, $constants, $user, $form, $slashdb) = @_; - - my ($uid, $nick); - if ($form->{uid} || $form->{nick}) { - $uid = $form->{uid} ? $form->{uid} : $slashdb->getUserUID($form->{nick}); - $nick = $form->{nick} ? $form->{nick} : $slashdb->getUser($uid, 'nickname'); - } else { - $uid = $user->{uid}; - $nick = $user->{nick}; - } - - my $user_change = { }; - if ($uid != $user->{uid} && !isAnon($uid) && !$user->{is_anon}) { - # Store the fact that this user last looked at that user. - # For maximal convenience in stalking. - $user_change->{lastlookuid} = $uid; - $user_change->{lastlooktime} = time; - $user->{lastlookuid} = $uid; - $user->{lastlooktime} = time; - } - - my $editable = ($uid == $user->{uid} ? 1 : 0); - my $foes = $zoo->getRelationships($uid, FOE); - - if ($form->{content_type} eq 'rss') { - _rss($foes, $nick, 'foes'); - } elsif ($form->{content_type} eq 'foaf') { - _foaf($foes, $uid, "foes" ); - } else { - my $implied; - if ($editable) { - _printHead("yourfoeshead", { - nickname => $nick, - uid => $uid, - tab_selected_1 => 'me', - tab_selected_2 => 'foes', - }) or return; - $implied = FOE; - } else { - _printHead("foeshead", { - nickname => $nick, - uid => $uid, - tab_selected_1 => 'otheruser', - tab_selected_2 => 'foes', - }) or return; - } - - if (@$foes) { - slashDisplay('plainlist', { people => $foes, editable => $editable, implied => $implied, nickname => $nick }); - } else { - if ($editable) { - print getData('yournofoes'); - } else { - print getData('nofoes', { nickname => $nick, uid => $uid }); - } - } - } - - # Store the new user we're looking at, if any. - if ($user_change && %$user_change) { - $slashdb->setUser($user->{uid}, $user_change); - } - - return 1; + footer() unless $form->{content_type} && $form->{content_type} =~ $constants->{feed_types}; } -sub fans { +sub people { my($zoo, $constants, $user, $form, $slashdb) = @_; - my ($uid, $nick); - if ($form->{uid} || $form->{nick}) { - $uid = $form->{uid} ? $form->{uid} : $slashdb->getUserUID($form->{nick}); - $nick = $form->{nick} ? $form->{nick} : $slashdb->getUser($uid, 'nickname'); - } else { - $uid = $user->{uid}; - $nick = $user->{nick}; - } - - my $user_change = { }; - if ($uid != $user->{uid} && !isAnon($uid) && !$user->{is_anon}) { - # Store the fact that this user last looked at that user. - # For maximal convenience in stalking. - $user_change->{lastlookuid} = $uid; - $user_change->{lastlooktime} = time; - $user->{lastlookuid} = $uid; - $user->{lastlooktime} = time; - } - - my $editable = ($uid == $user->{uid} ? 1 : 0); - my $fans = $zoo->getRelationships($uid, FAN); - - if ($form->{content_type} eq 'rss') { - _rss($fans, $nick, 'fans'); - } else { - my $implied; - if ($editable) { - _printHead("yourfanshead", { - nickname => $nick, - uid => $uid, - tab_selected_1 => 'me', - tab_selected_2 => 'fans', - }) or return; - $implied = FAN; - } else { - _printHead("fanshead", { - nickname => $nick, - uid => $uid, - tab_selected_1 => 'otheruser', - tab_selected_2 => 'fans', - }) or return; - } - if (@$fans) { - slashDisplay('plainlist', { people => $fans, editable => $editable, implied => $implied, nickname => $nick }); - } else { - if ($editable) { - print getData('yournofans'); - } else { - print getData('nofans', { nickname => $nick, uid => $uid }); - } - } - } - - # Store the new user we're looking at, if any. - if ($user_change && %$user_change) { - $slashdb->setUser($user->{uid}, $user_change); - } + my %main_vars = ( + friends => { constant => FRIEND }, + fans => { constant => FAN }, + foes => { constant => FOE }, + freaks => { constant => FREAK }, + fof => { constant => FOF, + name1 => 'friends', + name2 => 'friendsoffriends', + }, + eof => { constant => EOF, + name1 => 'friends', + name2 => 'friendsenemies', + }, + all => { constant => undef, + op => 'people', + name1 => undef, + name2 => 'all', + }, + ); + + my $zoo_vars = $main_vars{$form->{op}}; + $zoo_vars->{op} ||= $form->{op}; + $zoo_vars->{name1} ||= $form->{op}; + $zoo_vars->{name2} ||= $form->{op}; + $zoo_vars->{head1} ||= "your$zoo_vars->{name2}head"; + $zoo_vars->{head2} ||= "$zoo_vars->{name2}head"; + $zoo_vars->{no1} ||= "yourno$zoo_vars->{name2}"; + $zoo_vars->{no2} ||= "no$zoo_vars->{name2}"; - return 1; -} - -sub freaks { - my($zoo, $constants, $user, $form, $slashdb) = @_; - - my ($uid, $nick); + my($uid, $nick); if ($form->{uid} || $form->{nick}) { $uid = $form->{uid} ? $form->{uid} : $slashdb->getUserUID($form->{nick}); $nick = $form->{nick} ? $form->{nick} : $slashdb->getUser($uid, 'nickname'); @@ -506,116 +107,45 @@ } my $editable = ($uid == $user->{uid} ? 1 : 0); - my $freaks = $zoo->getRelationships($uid, FREAK); + my $people = $zoo->getRelationships($uid, $zoo_vars->{constant}); - if ($form->{content_type} eq 'rss') { - _rss($freaks, $nick, 'freaks'); + if ($form->{content_type} && $form->{content_type} =~ $constants->{feed_types}) { + _rss($people, $nick, $zoo_vars->{op}); } else { my $implied; if ($editable) { - _printHead("yourfreakshead", { - nickname => $nick, - uid => $uid, + _printHead($zoo_vars->{head1}, { + nickname => $nick, + uid => $uid, tab_selected_1 => 'me', - tab_selected_2 => 'freaks', + tab_selected_2 => $zoo_vars->{name1}, }) or return; - $implied = FREAK; + $implied = $zoo_vars->{constant}; } else { - _printHead("freakshead", { - nickname => $nick, - uid => $uid, + _printHead($zoo_vars->{head2}, { + nickname => $nick, + uid => $uid, tab_selected_1 => 'otheruser', - tab_selected_2 => 'freaks', + tab_selected_2 => $zoo_vars->{name1}, }) or return; } - if (@$freaks) { - slashDisplay('plainlist', { people => $freaks, editable => $editable, implied => $implied, nickname => $nick }); - } else { - if ($editable) { - print getData('yournofreaks'); - } else { - print getData('nofreaks', { nickname => $nick, uid => $uid }); - } - } - } - - # Store the new user we're looking at, if any. - if ($user_change && %$user_change) { - $slashdb->setUser($user->{uid}, $user_change); - } - - return 1; -} - -sub foaf { - my($zoo, $constants, $user, $form, $slashdb) = @_; - - my ($uid, $nick); - if ($form->{uid} || $form->{nick}) { - $uid = $form->{uid} ? $form->{uid} : $slashdb->getUserUID($form->{nick}); - $nick = $form->{nick} ? $form->{nick} : $slashdb->getUser($uid, 'nickname'); - } else { - $uid = $user->{uid}; - $nick = $user->{nick}; - } - - my $known = $zoo->getRelationships($uid, FRIEND); - my $foes = $zoo->getRelationships($uid, FOE); - push( @$known, @$foes ); - - _foaf($known, $uid, "foaf" ); - -} - -sub all { - my($zoo, $constants, $user, $form, $slashdb) = @_; - - my ($uid, $nick); - if ($form->{uid} || $form->{nick}) { - $uid = $form->{uid} ? $form->{uid} : $slashdb->getUserUID($form->{nick}); - $nick = $form->{nick} ? $form->{nick} : $slashdb->getUser($uid, 'nickname'); - } else { - $uid = $user->{uid}; - $nick = $user->{nick}; - } - - my $user_change = { }; - if ($uid != $user->{uid} && !isAnon($uid) && !$user->{is_anon}) { - # Store the fact that this user last looked at that user. - # For maximal convenience in stalking. - $user_change->{lastlookuid} = $uid; - $user_change->{lastlooktime} = time; - $user->{lastlookuid} = $uid; - $user->{lastlooktime} = time; - } - my $editable = ($uid == $user->{uid} ? 1 : 0); - my $people = $zoo->getRelationships($uid); - - if ($form->{content_type} eq 'rss') { - _rss($people, $nick, 'people'); - } else { - if ($editable) { - _printHead("yourall", { # this doesn't look right to me - Jamie - nickname => $nick, - uid => $uid, - tab_selected_1 => 'me', - }) or return; - } else { - _printHead("yourhead", { # this doesn't look right to me - Jamie - nickname => $nick, - uid => $uid, - tab_selected_1 => 'otheruser', - }) or return; - } if (@$people) { - slashDisplay('plainlist', { people => $people, editable => $editable, nickname => $nick }); + slashDisplay('plainlist', { + people => $people, + editable => $editable, + implied => $implied, + nickname => $nick + }); } else { if ($editable) { - print getData('yournoall'); + print getData($zoo_vars->{no1}); } else { - print getData('noall', { nickname => $nick, uid => $uid }); + print getData($zoo_vars->{no2}, { + nickname => $nick, + uid => $uid + }); } } } @@ -631,13 +161,23 @@ sub action { my($zoo, $constants, $user, $form, $slashdb, $gSkin) = @_; - if ($form->{uid} == $user->{uid} || $form->{uid} == $constants->{anonymous_coward_uid} ) { - _printHead("mainhead", { nickname => $user->{nick}, uid => $user->{uid} }) or return; - print getData("no_go"); + my $reskey = getObject('Slash::ResKey'); + my $rkey = $reskey->key('zoo'); + unless ($rkey->use) { + _printHead('mainhead', { errstr => $rkey->errstr, rkey => $rkey }) or return; + use Data::Dumper; + print STDERR Dumper({ reskey => $rkey }); + return 1; + } + + if ($form->{uid} == $user->{uid} || $form->{uid} == $constants->{anonymous_coward_uid}) { + _printHead('mainhead', { nickname => $user->{nick}, uid => $user->{uid} }) or return; + print getData('no_go'); return 1; } else { if (testSocialized($zoo, $constants, $user) && ($form->{type} ne 'neutral' || $form->{op} eq 'delete' )) { - print getData("no_go"); + _printHead('mainhead', { nickname => $user->{nick}, uid => $user->{uid} }) or return; + print getData('no_go'); return 1; } @@ -687,6 +227,7 @@ } + # This is just to make sure the next view gets it right if ($form->{type} eq 'foe') { redirect("$gSkin->{rootdir}/my/foes"); @@ -700,7 +241,16 @@ sub check { my($zoo, $constants, $user, $form, $slashdb) = @_; - my $uid = $form->{uid} || ""; + my $reskey = getObject('Slash::ResKey'); + my $rkey = $reskey->key('zoo'); + unless ($rkey->create) { + _printHead('mainhead', { errstr => $rkey->errstr, rkey => $rkey }) or return; + use Data::Dumper; + print STDERR Dumper({ reskey => $rkey }); + return 1; + } + + my $uid = $form->{uid} || ''; my $nickname = $slashdb->getUser($uid, 'nickname'); if (!$uid || $nickname eq '') { @@ -708,7 +258,7 @@ # getSkinColors() as well. Slash::Utility::Anchor::getSkinColors(); - my $title = getData("no_uid"); + my $title = getData('no_uid'); header($title) or return; print $title; return 1; @@ -723,27 +273,20 @@ $user->{lastlookuid} = $uid; $user->{lastlooktime} = time; } - _printHead("confirm", { + + _printHead('confirm', { nickname => $nickname, uid => $uid, tab_selected_1 => ($uid == $user->{uid} ? 'me' : 'otheruser'), tab_selected_2 => 'relation' }) or return; + if ($uid == $user->{uid} || $uid == $constants->{anonymous_coward_uid} ) { - print getData("no_go"); + print getData('no_go'); return 1; } -# my (%mutual, @mutual); -# for my $rel (keys %{$user->{people}}) { -# for my $person (keys %{$user->{people}{$rel}}) { -# if ($compare->{$rel}{$person}) { -# push @{$mutual{$rel}}, $person; -# push @mutual, $person; -# } -# } -# } - my (%mutual, @mutual); + my(%mutual, @mutual); if ($user->{people}{FOF()}{$uid}) { for my $person (keys %{$user->{people}{FOF()}{$uid}}) { next unless $person; @@ -751,6 +294,7 @@ push @mutual, $person; } } + if ($user->{people}{EOF()}{$uid}) { for my $person (keys %{$user->{people}{EOF()}{$uid}}) { next unless $person; @@ -758,21 +302,24 @@ push @mutual, $person; } } + my $uids_2_nicknames = $slashdb->getUsersNicknamesByUID(\@mutual) if scalar(@mutual); my $type = $user->{people}{FOE()}{$uid} ? 'foe': ($user->{people}{FRIEND()}{$uid}? 'friend' :'neutral'); + slashDisplay('confirm', { - uid => $uid, - nickname => $nickname, - type => $type, - over_socialized => testSocialized($zoo, $constants, $user), - uids_2_nicknames => $uids_2_nicknames, - mutual => \%mutual + uid => $uid, + nickname => $nickname, + type => $type, + over_socialized => testSocialized($zoo, $constants, $user), + uids_2_nicknames => $uids_2_nicknames, + mutual => \%mutual, + rkey => $rkey, }); # Store the new user we're looking at, if any. - if ($user_change && %$user_change) { + if ($user_change && keys %$user_change) { $slashdb->setUser($user->{uid}, $user_change); } @@ -782,35 +329,40 @@ sub _printHead { my($head, $data) = @_; my $slashdb = getCurrentDB(); + # See comment in plugins/Journal/journal.pl for its call of # getSkinColors() as well. Slash::Utility::Anchor::getSkinColors(); + my $user = getCurrentUser(); my $useredit = $data->{uid} ? $slashdb->getUser($data->{uid}) : $user; + $data->{user} = $user; $data->{useredit} = $useredit; + my $title = getData($head, $data); $data->{title} = $title; header($title) or return; $data->{tab_selected_1} ||= 'me'; - slashDisplay("zoohead", $data); + slashDisplay('zoohead', $data); } sub _rss { my($entries, $nick, $type) = @_; my $constants = getCurrentStatic(); + my $form = getCurrentForm(); my $gSkin = getCurrentSkin(); my @items; for my $entry (@$entries) { push @items, { title => $entry->[1], - 'link' => ($gSkin->{absolutedir} . '/~' . fixparam($entry->[1]) . "/"), + 'link' => ($gSkin->{absolutedir} . '/~' . fixparam($entry->[1]) . '/'), }; } - xmlDisplay(rss => { + xmlDisplay($form->{content_type} => { channel => { title => "$constants->{sitename} $nick's ${type}", 'link' => "$gSkin->{absolutedir}/", @@ -822,61 +374,6 @@ }); } -sub _foaf { - my( $entries, $uid, $type) = @_; - my $constants = getCurrentStatic(); - my $form = getCurrentForm(); - my $reader = getObject('Slash::DB', { db_type => 'reader' }); - my $user = $reader->getUser($uid, ['nickname', 'realemail','homepage', 'journal_last_entry_date', 'emaildisplay']); - my $nickname = $user->{nickname}; - my $userpage = "$constants->{rootdir}/~" . fixparam($nickname) . "/"; - - - # basic foaf:Person - my $person = { - nick => $nickname, - holdsAccount => { - OnlineAccount => { - accountName => $nickname, - page => $userpage, - accountServiceHomepage => $constants->{rootdir}, - }, - } - }; - - # add various field is defined - # email address depending on display setting - $person->{mbox_sha1sum} = Digest::SHA1::sha1_hex('mailto:' . $user->{realemail}) if $user->{realemail} && $user->{emaildisplay} >= 1; - $person->{mbox} = "mailto:" . $user->{realemail} if $user->{realemail} && $user->{emaildisplay} >= 2; - $person->{homepage} = $user->{homepage} if $user->{homepage}; - $person->{weblog} = $userpage . "journal/" if $user->{journal_last_entry_date}; - - # add person's relationship - my @knows; - for my $entry (@$entries) { - my $p = $reader->getUser( $entry->[0] , ['nickname','realemail','emaildisplay'] ); - my $other = { Person => { - nick => $p->{nickname}, - seeAlso => "$constants->{rootdir}/~" . fixparam($p->{nickname}) . "/$type.rdf", - }}; - $other->{Person}{mbox_sha1sum} = Digest::SHA1::sha1_hex("mailto:" . $p->{realemail}) if $p->{emaildisplay} >= 1; - push @knows, $other; - - } - $person->{knows} = \@knows; - - # output RDF - $type = $type eq "foaf" ? "Friends and Foes" : $type; - xmlDisplay("foaf" ,{ - Document => { - title => "FOAF File for $nickname, with $type", - maker => "Slashcode zoo.pl $VERSION", - }, - Person => $person, - - }); -} - sub testSocialized { my($zoo, $constants, $user) = @_; return 0 if $user->{is_admin}; Index: slashjp/plugins/Zoo/zoo_run_people_log.pl diff -u slashjp/plugins/Zoo/zoo_run_people_log.pl:1.3 slashjp/plugins/Zoo/zoo_run_people_log.pl:1.4 --- slashjp/plugins/Zoo/zoo_run_people_log.pl:1.3 Fri Dec 31 21:37:18 2004 +++ slashjp/plugins/Zoo/zoo_run_people_log.pl Wed Jul 12 20:42:07 2006 @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -# $Id: zoo_run_people_log.pl,v 1.3 2004/12/31 12:37:18 oliver Exp $ +# $Id: zoo_run_people_log.pl,v 1.4 2006/07/12 11:42:07 sugi Exp $ use strict; use Slash::Constants qw( :messages :slashd :people ); @@ -32,7 +32,7 @@ for my $person (@$people) { my $new_people = $zoo->rebuildUser($person); $slashdb->setUser($person, { people => $new_people, people_status => 'ok'}); - sleep 2; # don't tax the DB too much, this isn't high-priority + Time::HiRes::sleep(0.5); # don't tax the DB too much, this isn't high-priority } $stats->updateStatDaily("zoo_counts", "value+" . @$people); slashdLog('Zoo fof/eof End');