Tatsuki SUGIURA
sugi****@users*****
2006年 7月 12日 (水) 20:41:54 JST
Index: slashjp/plugins/Remarks/MANIFEST diff -u /dev/null slashjp/plugins/Remarks/MANIFEST:1.1 --- /dev/null Wed Jul 12 20:41:54 2006 +++ slashjp/plugins/Remarks/MANIFEST Wed Jul 12 20:41:54 2006 @@ -0,0 +1,4 @@ +Makefile.PL +MANIFEST +Remarks.pm +remarks.pl Index: slashjp/plugins/Remarks/Makefile.PL diff -u /dev/null slashjp/plugins/Remarks/Makefile.PL:1.1 --- /dev/null Wed Jul 12 20:41:54 2006 +++ slashjp/plugins/Remarks/Makefile.PL Wed Jul 12 20:41:54 2006 @@ -0,0 +1,8 @@ +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + 'NAME' => 'Slash::Remarks', + 'VERSION_FROM' => 'Remarks.pm', # finds $VERSION + 'PM' => { 'Remarks.pm' => '$(INST_LIBDIR)/Remarks.pm' }, +); Index: slashjp/plugins/Remarks/PLUGIN diff -u /dev/null slashjp/plugins/Remarks/PLUGIN:1.1 --- /dev/null Wed Jul 12 20:41:54 2006 +++ slashjp/plugins/Remarks/PLUGIN Wed Jul 12 20:41:54 2006 @@ -0,0 +1,7 @@ +# $Id: PLUGIN,v 1.1 2006/07/12 11:41:54 sugi Exp $ +name=Remarks +description="Remarks" +htdocs=remarks.pl +template=templates/data;remarks;default +template=templates/display;remarks;default +template=templates/config_remarks;misc;default Index: slashjp/plugins/Remarks/Remarks.pm diff -u /dev/null slashjp/plugins/Remarks/Remarks.pm:1.1 --- /dev/null Wed Jul 12 20:41:54 2006 +++ slashjp/plugins/Remarks/Remarks.pm Wed Jul 12 20:41:54 2006 @@ -0,0 +1,195 @@ +# This code is a part of Slash, and is released under the GPL. +# Copyright 1997-2005 by Open Source Technology Group. See README +# and COPYING for more information, or see http://slashcode.com/. +# $Id: Remarks.pm,v 1.1 2006/07/12 11:41:54 sugi Exp $ + +package Slash::Remarks; + +=head1 NAME + +Slash::Remarks - Perl extension for Remarks + + +=head1 SYNOPSIS + + use Slash::Remarks; + + +=head1 DESCRIPTION + +LONG DESCRIPTION. + + +=head1 EXPORTED FUNCTIONS + +=cut + +use strict; +use DBIx::Password; +use Slash; +use Slash::Display; +use Slash::Utility; + +use base 'Slash::DB::Utility'; +use base 'Slash::DB::MySQL'; +use vars qw($VERSION); + +($VERSION) = ' $Revision: 1.1 $ ' =~ /\$Revision:\s+([^\s]+)/; + +######################################################## +sub new { + my($class, $user) = @_; + my $self = {}; + + my $plugin = getCurrentStatic('plugin'); + return unless $plugin->{'Remarks'}; + + bless($self, $class); + $self->{virtual_user} = $user; + $self->sqlConnect; + + return $self; +} + +######################################################## +sub getRemarks { + my($self, $options) = @_; + + my $max = $options->{max} || 100; + + my @where; + if ($options->{min_priority}) { + push @where, 'priority >= ' . $self->sqlQuote($options->{min_priority}); + } + if ($options->{string}) { + push @where, 'remark LIKE ' . $self->sqlQuote('%' . $options->{string} . '%'); + } + + my $remarks = $self->sqlSelectAllHashrefArray( + 'rid, uid, stoid, time, remark, type, priority', + 'remarks', + join(' AND ', @where), + "ORDER BY rid DESC LIMIT $max" + ); + + return $remarks || []; +} + +######################################################## +sub createRemark { + my($self, $remark, $options) = @_; + + my $remark_t = $self->truncateStringForCharColumn($remark, 'remarks', 'remark'); + + $self->sqlInsert('remarks', { + uid => $options->{uid} || getCurrentAnonymousCoward('uid'), + stoid => $options->{stoid} || 0, + type => $options->{type} || 'user', + priority => $options->{priority} || 0, + -time => 'NOW()', + remark => $remark_t, + }); +} + +######################################################## +sub getRemarksStarting { + my($self, $starting, $options) = @_; + return [ ] unless $starting; + + my $starting_q = $self->sqlQuote($starting); + my $type_clause = $options->{type} + ? ' AND type=' . $self->sqlQuote($options->{type}) + : ''; + + return $self->sqlSelectAllHashrefArray( + 'rid, stoid, remarks.uid, remark, karma, remarks.type', + 'remarks, users_info', + "remarks.uid=users_info.uid AND rid >= $starting_q $type_clause" + ); +} + +######################################################## +sub getUserRemarkCount { + my($self, $uid, $secs_back) = @_; + return 0 unless $uid && $secs_back; + + return $self->sqlCount( + 'remarks', + "uid = $uid + AND time >= DATE_SUB(NOW(), INTERVAL $secs_back SECOND)" + ); +} + + +######################################################## +sub displayRemarksTable { + my($self, $options) = @_; + my $user = getCurrentUser(); + $self ||= getObject('Slash::Remarks'); + $options ||= {}; + $options->{string} = $user->{remarks_filter} if $user->{remarks_filter}; + $options->{min_priority} = $user->{remarks_min_priority} if $user->{min_priority}; + $options->{max} = $user->{remarks_limit} || 10; + + my $remarks_ref = $self->getRemarks($options); + return slashDisplay('display', { + remarks_ref => $remarks_ref, + print_whole => $options->{print_whole}, + print_div => $options->{print_div}, + remarks_max => $options->{max}, + }, { Page => 'remarks', Return => 1 }); +} + +######################################################## +sub ajaxFetch { + my($slashdb, $constants, $user, $form) = @_; + my $self = getObject('Slash::Remarks'); + my $options = {}; + + $options->{max} = $form->{limit} || 30; + + if ($form->{op} eq 'remarks_create') { + $options->{print_div} = 1; + $self->createRemark($form->{remark}, { + uid => $user->{uid}, + type => 'system', + }); + } + + return $self->displayRemarksTable($options); +} + +sub ajaxFetchConfigPanel { + my($slashdb, $constants, $user, $form) = @_; + slashDisplay('config_remarks', {}, { Return => 1 }); +} + +sub ajaxConfigSave { + my($slashdb, $constants, $user, $form) = @_; + my $data = {}; + if (defined $form->{limit}) { + $data->{remarks_limit} = $form->{limit} + } + if (defined $form->{filter}) { + $data->{remarks_filter} = $form->{filter}; + } + if (defined $form->{min_priority}) { + $data->{remarks_min_priority} = $form->{min_priority}; + } + $slashdb->setUser($user->{uid}, $data) if keys %$data; + # this should be in a template -- pudge + return "<a href=\"javascript:closePopup('remarksconfig-popup', 1)\">Close</a>"; +} + +1; + +__END__ + + +=head1 SEE ALSO + +Slash(3). + +=head1 VERSION + +$Id: Remarks.pm,v 1.1 2006/07/12 11:41:54 sugi Exp $ Index: slashjp/plugins/Remarks/remarks.pl diff -u /dev/null slashjp/plugins/Remarks/remarks.pl:1.1 --- /dev/null Wed Jul 12 20:41:54 2006 +++ slashjp/plugins/Remarks/remarks.pl Wed Jul 12 20:41:54 2006 @@ -0,0 +1,66 @@ +#!/usr/bin/perl +# This code is a part of Slash, and is released under the GPL. +# Copyright 1997-2005 by Open Source Technology Group. See README +# and COPYING for more information, or see http://slashcode.com/. +# $Id: remarks.pl,v 1.1 2006/07/12 11:41:54 sugi Exp $ + +use strict; +use warnings; + +use Slash 2.003; # require Slash 2.3.x +use Slash::Constants qw(:web); +use Slash::Display; +use Slash::Utility; +use Slash::XML; +use vars qw($VERSION); + +($VERSION) = ' $Revision: 1.1 $ ' =~ /\$Revision:\s+([^\s]+)/; + + +sub main { + my $slashdb = getCurrentDB(); + my $constants = getCurrentStatic(); + my $user = getCurrentUser(); + my $form = getCurrentForm(); + my $gSkin = getCurrentSkin(); + my $remarks = getObject('Slash::Remarks'); + + if (! $user->{is_admin}) { + redirect("$gSkin->{rootdir}/"); + return; + } + + my %ops = ( + display => \&display, + save_prefs => \&save_prefs, + + default => \&display + ); + + my $op = $form->{op}; + if (!$op || !exists $ops{$op} || !$ops{$op}[ALLOWED]) { + $op = 'default'; + } + + header('Remarks', '', { admin => 1 }) or return; + + $ops{$op}->($slashdb, $constants, $user, $form, $gSkin, $remarks); + + footer(); +} + + +sub display { + my($slashdb, $constants, $user, $form, $gSkin, $remarks) = @_; + print $remarks->displayRemarksTable({ max => 30, print_whole => 1 }); +} + +sub save_prefs { + my($slashdb, $constants, $user, $form, $gSkin) = @_; + +} + +createEnvironment(); +main(); + +1;