Yoshihisa Fukuhara
higef****@users*****
2006年 6月 4日 (日) 10:48:07 JST
Index: affelio/apps/album/AF_app.cfg diff -u affelio/apps/album/AF_app.cfg:1.7 affelio/apps/album/AF_app.cfg:1.8 --- affelio/apps/album/AF_app.cfg:1.7 Tue Nov 22 22:27:23 2005 +++ affelio/apps/album/AF_app.cfg Sun Jun 4 10:48:07 2006 @@ -4,11 +4,11 @@ [application] app_URI=http://affelio.jp/NS/apps/album app_name=album -app_version=1.3.1 +app_version=1.5 app_desc=ãã©ãã¢ã«ãã app_author=Affelio project guest_index=index.cgi -owner_index=owner.cgi +owner_index=admin.cgi action_types=add_image, write_comment action_types_desc=ç»åç»é²,ã³ã¡ã³ãæ¸ã込㿠Index: affelio/apps/album/Album.pm diff -u affelio/apps/album/Album.pm:1.22 affelio/apps/album/Album.pm:1.23 --- affelio/apps/album/Album.pm:1.22 Fri Dec 23 21:29:24 2005 +++ affelio/apps/album/Album.pm Sun Jun 4 10:48:07 2006 @@ -16,28 +16,59 @@ package Album; -use strict; -use DBI; -use Jcode; -use HTML::Template; -use Config::Tiny; -use Album::L10N; +#use strict; +#use DBI; +#use Jcode; +#use HTML::Template; +#use Config::Tiny; +#use Album::L10N; + use strict; + use lib("../../extlib"); + use lib("../../lib"); + use Album::L10N; + use DBI; + use AffelioApp; + use HTML::Template; + use CGI; + use Cwd; + use Affelio::misc::Debug qw( debug_print); + use Affelio::misc::WebInput; + use Affelio::exception::SystemException; + use Error qw(:try); +use Album::ShowImage; ############################################## # Constructor ############################################## sub new { - my ($proto, $afap) = @_; - unless ($afap) { die("Album::new: Error: missing username\n"); } + my $class = shift; + my %param = @_; + + debug_print("Album::new: start."); + + my $cgi = new CGI; + my $wi = new Affelio::misc::WebInput(); + ########################### + #Load afap + ########################### + my $afap = new AffelioApp(ConfigDir => Cwd::getcwd(), cgi => $cgi); + debug_print("Album::new: AFAP loaded."); + + my $self = { + cgi => $cgi, + afap => $afap, + wi => $wi}; - my $self = {}; $self->{afap} = $afap; + $self->{uname} = $afap->{af}->{site__username}; + $self->{datadir} = $afap->get_userdata_dir(); + $self->{dbh} = $afap->get_userdata_dbh; + $self->{header_title} = 'Affelio Album'; $self->{tmpfile}= $afap->get_userdata_dir()."/.sqltmp"; $self->{album_tb}= "album_$afap->{install_name}_entries"; $self->{image_tb}= "album_$afap->{install_name}_images"; $self->{comment_tb}= "album_$afap->{install_name}_comments"; - $self->{dbh} = undef; - #initialize + $self->{header_show} = 0; ########################### #Locale init @@ -95,7 +126,7 @@ $self->{dbh} = $afap->get_userdata_dbh(); } - bless $self, $proto; + bless $self, $class; return $self; } @@ -109,6 +140,84 @@ } + ###################################################################### + #run + ###################################################################### + sub run{ + my $self = shift; + my $afap = $self->{afap}; + my $cgi = $self->{cgi}; + my $wi = $self->{wi}; + + my %handlers = ("top","Top", + "image_view", "ImageView", + "default", "Default", + "write_comment", "WriteComment", + "edit_caption", "EditCaption", + "show_album", "ShowAlbum", + "show_image", "ShowImage", + ); + + ########################### + #Check DF_access + ########################### + unless ($afap->check_access("DF_access")) { + $self->accessErrorExit('Access Denied. You don\'t have permission to this application.'); + } + + $self->{id} = $wi->PTN_num($cgi->param("id")); + $self->{header_title} = "Album"; + $self->{afid} = $afap->get_owner_info("afid"); + $self->{nickname} = $afap->get_owner_info("nickname"); + + ############################################################## + #prep vars + ############################################################## + my %output_data = ("tmpl_path", Cwd::getcwd()."/templates/"); + + + ############################################################## + #Model invocation + ############################################################## + my $mode = $wi->PTN_mode($cgi->param("mode")); + if ($mode eq "") {$mode="top";} + debug_print("Album::run: mode=$mode"); + + my $classname = "Album::" . $handlers{$mode}; + debug_print("Album::run: handler= $classname"); + eval "use $classname"; + if($@){ + throw Affelio::exception::SystemException("Could not load handler [$mode]"); + } + debug_print("Album::run: handler function loaded."); + + my $ret=""; + try{ + debug_print("Album::run: handler function..... "); + handler($cgi, $self, \%output_data); + debug_print("Album::run: handler function done."); + }catch Error with{ + my $e = shift; + $output_data{"err_msg"} .= $e->stacktrace; + }; + if ($mode ne "show_image"){ + ############################################################## + #Output View + ############################################################## + my $tmpl = new HTML::Template(filename => $output_data{tmpl_file}, + die_on_bad_params => 0); + $tmpl->param(%output_data); + + print "Content-type: text/html; charset=UTF-8\n"; + print "Pragma: no-cache", "\n\n"; + print $afap->get_HTML_header("Affelio Photo Album"); + print $self->translate_templateL10N($tmpl->output); + print $afap->get_HTML_footer; + } +} + + + ############################################## # addAlbum ############################################## @@ -405,6 +514,26 @@ return $str; } +sub escape_all { + my ($self, $str) = @_; + + $str =~ s/[\t\a]//g; + $str =~ s/&/&/g; + $str =~ s/"/"/g; + $str =~ s/'/'/g; + $str =~ s/</</g; + $str =~ s/>/>/g; + return $str; +} + +sub n2br { + my ($self, $str) = @_; + $str =~ s/\x0D\x0A/<br \/>/g; + $str =~ s/\x0D/<br \/>/g; + $str =~ s/\x0A/<br \/>/g; + + return $str; +} ############################################################################ # get primary key for DBs Index: affelio/apps/album/admin.cgi diff -u /dev/null affelio/apps/album/admin.cgi:1.1 --- /dev/null Sun Jun 4 10:48:07 2006 +++ affelio/apps/album/admin.cgi Sun Jun 4 10:48:07 2006 @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +# Copyright (C) 2006 Affelio Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +use strict; +use lib("../../extlib"); +use Error qw(:try); +use Album; +use Album::Admin; + +try{ + my $admin = new Album(); + $admin->run_admin(); +}catch Error with{ + my $e = shift; + print "Content-type: text/html; charset=UTF-8\n"; + print "Pragma: no-cache", "\n\n"; + print "<HTML>"; + print "<HEAD><TITLE>Error</TITLE></HEAD>"; + print "$e<BR><BR><HR><PRE>" . $e->stacktrace; +}; + Index: affelio/apps/album/index.cgi diff -u affelio/apps/album/index.cgi:1.2 affelio/apps/album/index.cgi:1.3 --- affelio/apps/album/index.cgi:1.2 Thu Aug 25 13:02:24 2005 +++ affelio/apps/album/index.cgi Sun Jun 4 10:48:07 2006 @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2005 FishGrove Inc. +# Copyright (C) 2006 Affelio Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,66 +15,20 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + use strict; use lib("../../extlib"); -use lib("../../lib"); -use HTML::Template; -use CGI; -use Cwd; -use AffelioApp; +use Error qw(:try); use Album; - -#Initialize AFAP -our $cgi = new CGI(); -our $afap = new AffelioApp(ConfigDir => Cwd::getcwd(), cgi => $cgi); -our $album = new Album($afap); - -# put Content-type -print "Content-type: text/html; charset=UTF-8\n"; -print "Pragma: no-cache", "\n\n"; -# put HTML Header -print $afap->get_HTML_header("Affelio Photo Album"); -# check access -unless ($afap->check_access("DF_access")) { - $album->errorExit('<AF_M text="Access denied">'); -} - -my $user = $afap->{cgi}->param("user"); - -my $tmpl; -############################################################### -# Owner can add album - my $edit = 0; - if ($afap->get_visitor_info("type") eq "self"){ - $edit = 1; - } - - $tmpl = HTML::Template->new(filename => "./templates/index.tmpl"); - my @entries_param; - my @entries; - my @images; - @entries = $album->getAllEntries; - $tmpl->param(install_title => $afap->get_app_info("install_title"), EDITABLE => $edit); - - foreach(@entries) { - my ($sec, $min, $hour, $mday, $mon, $year) = localtime($_->{update_time}); - $mon+=1; - $year+=1900; - @images = $album->getAllImage($_->{id}); - - push @entries_param, - { - MONTH => $mon, - DAY => $mday, - #TIME => sprintf("%02d:%02d", $hour, $min), - TITLE => $_->{title}, - CONTENTS=> $_->{contents}, - COMMENT_NO => $album->getCommentsNo($_->{id}), - ID => $_->{id}, - IMAGE => $images[0]->{image}, - }; - } - $tmpl->param(ENTRIES => \@entries_param); - print $album->translate_templateL10N( $tmpl->output ); - print $afap->get_HTML_footer(); +try{ + my $album = new Album(); + $album->run(); +}catch Error with{ + my $e = shift; + print "Content-type: text/html; charset=UTF-8\n"; + print "Pragma: no-cache", "\n\n"; + print "<HTML>"; + print "<HEAD><TITLE>Error</TITLE></HEAD>"; + print "$e<BR><BR><HR><PRE>" . $e->stacktrace; +}; Index: affelio/apps/album/owner.cgi diff -u affelio/apps/album/owner.cgi:1.2 affelio/apps/album/owner.cgi:1.3 --- affelio/apps/album/owner.cgi:1.2 Thu Aug 25 13:02:24 2005 +++ affelio/apps/album/owner.cgi Sun Jun 4 10:48:07 2006 @@ -1,6 +1,5 @@ #!/usr/bin/perl - -# Copyright (C) 2005 FishGrove Inc. +# Copyright (C) 2006 Affelio Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,241 +14,6 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -use strict; -use lib("../../extlib"); -use lib("../../lib"); -use HTML::Template; -use CGI; -use Cwd; -use AffelioApp; -use Album; - - -############################################## -#Initialize AFAP & put header -############################################## -our $cgi = new CGI(); -our $afap = new AffelioApp(ConfigDir => Cwd::getcwd(), cgi => $cgi); -our $album = new Album($afap); - -# put Content-type -print "Content-type: text/html; charset=UTF-8\n"; -print "Pragma: no-cache", "\n\n"; -# put HTML Header -print $afap->get_HTML_header("Affelio Photo Album"); -# check access -unless ($afap->get_visitor_info("type") eq "self"){ - $album->errorExit('<AF_M text="Access denied">'); -} - -############################################## -# Add new album -############################################## -if ($cgi->param("mode") eq "add_album"){ - my $tmpl = HTML::Template->new(filename => "./templates/owner/add_album.tmpl"); - my $title = $afap->{cgi}->param("title"); - my $contents = $afap->{cgi}->param("contents"); - my $user = $afap->get_visitor_info("nickname"); - my $afid = $afap->get_visitor_info("afid"); - - $tmpl->param(TITLE => $title, CONTENTS => $contents); - - if($afap->{cgi}->param("submit")) { - $tmpl->param(SUBMIT => "1"); - $album->addAlbum($title, $contents, $user, $afid); - my $ret = $album->getNewestAlbumId; - $tmpl->param(ID => $ret->{id}); - } -# Confirm information - elsif($afap->{cgi}->param("confirm")) { - $tmpl->param(CONFIRM => "1"); - } -# Edit infomation - else { - $tmpl->param(EDIT => "1"); - } - - print $album->translate_templateL10N( $tmpl->output ); - print $afap->get_HTML_footer(); - -############################################## -# Delete the album -############################################## -}elsif ($cgi->param("mode") eq "delete_album"){ - my $tmpl = HTML::Template->new(filename => "./templates/owner/delete_album.tmpl"); - my $id = $afap->{cgi}->param("id"); - $tmpl->param(ID => $id); - -# done delete - if($afap->{cgi}->param("delete")) { - $album->removeAlbum($id); - $tmpl->param(DONE => "1", DONE_LABEL => '<AF_M text="The album was deleted">'); - } -# confirm - elsif($afap->{cgi}->param("delete_confirm")) { - $tmpl->param(DELETE_CONFIRM => "1"); - } - print $album->translate_templateL10N( $tmpl->output ); - print $afap->get_HTML_footer(); - -############################################## -# Update album infomation (Title and caption) -############################################## -}elsif ($cgi->param("mode") eq "edit_album_caption"){ - my $tmpl = HTML::Template->new(filename => "./templates/owner/edit_album_caption.tmpl"); - my $id = $afap->{cgi}->param("id"); - $tmpl->param(ID => $id); -# done edit - if($afap->{cgi}->param("edit")) { - $album->updateEntry($id, $afap->{cgi}->param("title"), $afap->{cgi}->param("contents")); - $tmpl->param(DONE => "1", DONE_LABEL => '<AF_M text="Information was updated.">'); - } - -# comment edit - elsif ($afap->{cgi}->param("comment_edit")){ - $tmpl->param(EDIT => "1"); - my $entry = $album->getEntry($id); - $entry->{contents} =~ s/<br \/>/\n/g; - $tmpl->param( - TITLE => $entry->{title}, - CONTENTS => $entry->{contents}, - ); - } - print $album->translate_templateL10N( $tmpl->output ); - print $afap->get_HTML_footer(); - -############################################## -# Manage Contents (Show thumbnail and comments) -############################################## -}elsif ($cgi->param("mode") eq "manage_album_content"){ - my $tmpl = HTML::Template->new(filename => "./templates/owner/manage_album.tmpl"); - my $id = $afap->{cgi}->param("id"); - $tmpl->param(ID => $id); -# image edit -# if ($afap->{cgi}->param("image_arrange")){ -# $tmpl->param(ARRANGE => "1"); - -# show thumbnails - my $col_num=4; - my @image_files; - my @image_row; - my @image_filelist=$album->getAllImage($id); - if ($#image_filelist>=0){ - $tmpl->param(HAS_IMAGE => 1); - for (my $i=0; $i<($#image_filelist+1)%$col_num; $i++){ - push @image_filelist, - { - image => "", - pkey => "", - } - } - - for (my $i=0; $i<($#image_filelist+1)/$col_num; $i++){ - my $i_num=$i*$col_num; - for (my $j=0; $j<$col_num; $j++){ - push @image_files, - { - IMAGE => $image_filelist[$i_num+$j]->{image}, - ID2 => $id, - PKEY=> $image_filelist[$i_num+$j]->{pkey} - }; - } - push @image_row, - {IMG => [@image_files[$i_num..($i_num+($col_num-1))]]}; - } - $tmpl->param(THUMBNAIL => \@image_row); - } - -# comment - if($album->getCommentsNo($id) > 0) { - $tmpl->param(HAS_COMMENTS => 1); - my @comments_param; - my @comments = $album->getComments($id); - foreach(@comments) { - my ($sec, $min, $hour, $mday, $mon, $year) = localtime($_->{timestamp}); - $mon += 1; - push @comments_param, - { - UNAME => $_->{user}, - COMMENT_TIME => "$mon/$mday/$hour:$min", - COMMENT => $_->{comment}, - PKEY=> $_->{pkey} - }; - } - $tmpl->param(COMMENTS => \@comments_param); - } -# } - print $album->translate_templateL10N( $tmpl->output ); - print $afap->get_HTML_footer(); - -############################################## -# Delete Comments -############################################## -}elsif ($cgi->param("mode") eq "delete_comment"){ - my $tmpl = HTML::Template->new(filename => "./templates/owner/delete_comment.tmpl"); - my $id = $afap->{cgi}->param("id"); - my @pkey = $afap->{cgi}->param("delete_comment"); -#Done - if($afap->{cgi}->param("delete")) { - $album->removeComment($id, @ pkey); - $tmpl->param(ID => "$id"); - $tmpl->param(DONE => "1"); - } - print $album->translate_templateL10N( $tmpl->output ); - print $afap->get_HTML_footer(); - -############################################## -# Delete Images -############################################## -}elsif ($cgi->param("mode") eq "delete_image"){ - my $tmpl = HTML::Template->new(filename => "./templates/owner/delete_image.tmpl"); - my $id = $afap->{cgi}->param("id"); - my @pkey = $afap->{cgi}->param("delete_image"); -# Done - if($afap->{cgi}->param("delete")) { - $album->removeImage($id, @ pkey); - $tmpl->param(ID => "$id"); - $tmpl->param(DONE => "1"); - } - print $album->translate_templateL10N( $tmpl->output ); - print $afap->get_HTML_footer(); - -############################################## -# Default (Owner mode) -############################################## -}else{ - my $tmpl = HTML::Template->new(filename => "./templates/owner/owner.tmpl"); - $tmpl->param(access_control_URL => $afap->get_URL("access_control")); - - my @entries_param; - my $year = $afap->{cgi}->param("year"); - my $month = $afap->{cgi}->param("month"); - my $day = $afap->{cgi}->param("day"); - my @entries; - my @images; - @entries = $album->getAllEntries;; - - my $i = 0; - foreach(@entries) { - my ($sec, $min, $hour, $mday, $mon, $year) = localtime($_->{update_time}); - $mon+=1; - $year+=1900; - @images = $album->getAllImage($_->{id}); - push @entries_param, - { - MONTH => $mon, - DAY => $mday, - #TIME => sprintf("%02d:%02d", $hour, $min), - TITLE => $_->{title}, - CONTENTS=> $_->{contents}, - ID => $_->{id}, - IMAGE => $images[0]->{image}, - EDITABLE=> 1 - }; - } - $tmpl->param(ENTRIES => \@entries_param, EDITABLE => 1); - $tmpl->param(install_title => $afap->get_app_info("install_title")); - print $album->translate_templateL10N( $tmpl->output ); - print $afap->get_HTML_footer(); -} +print "Content-type: text/html; charset=UTF-8\n". + "Location: admin.cgi"."\n\n";