Yoshihisa Fukuhara
higef****@users*****
2006年 3月 1日 (水) 14:40:36 JST
Index: affelio/apps/diary/Diary/Admin.pm
diff -u /dev/null affelio/apps/diary/Diary/Admin.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/Admin.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,132 @@
+# 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.
+#
+
+package Diary;
+{
+ use strict;
+
+ ######################################################################
+ #run_admin
+ ######################################################################
+ sub run_admin{
+ my $self = shift;
+ my $afap = $self->{afap};
+ my $cgi = $self->{cgi};
+ my $wi = $self->{wi};
+
+ my %handlers = (
+ "write_diary", "WriteDiary",
+ "pref_set","PrefSet",
+ "edit_category", "EditCategory");
+
+ ###########################
+ #Check access
+ ###########################
+ unless ($afap->check_access("DF_access")) {
+ $self->accessErrorExit('Access Denied. You don\'t have permission to this application.');
+ }
+ unless ($afap->get_visitor_info("type") eq "self"){
+ $self->accessErrorExit('Access Denied. You don\'t have permission to this application.');
+ }
+ ###########################
+ #Going to the owner mode
+ ###########################
+ $afap->{af}->set_owner_mode();
+
+ ##############################################################
+ #prep vars
+ ##############################################################
+ my %output_data = ("tmpl_path", Cwd::getcwd()."/templates/");
+
+ ##############################################################
+ #Model invocation
+ ##############################################################
+ my $mode = $wi->PTN_mode($cgi->url_param("mode"));
+ if ($mode eq "") {$mode="write_diary";}
+ debug_print("Diary::Admin::run: mode=$mode");
+
+ my $classname = "Diary::" . $handlers{$mode};
+ debug_print("Diary::Admin::run: handler= $classname");
+ eval "use $classname";
+ if($@){
+ throw Affelio::exception::SystemException("Could not load handler [$mode]");
+ }
+ debug_print("Diary::Admin::run: handler function loaded.");
+
+ my $ret="";
+ try{
+ debug_print("Diary::Admin::run: handler function..... ");
+ handler($cgi, $self, \%output_data);
+ debug_print("Diary::Admin::run: handler function done.");
+ }catch Error with{
+ my $e = shift;
+ $output_data{"err_msg"} .= $e->stacktrace;
+ };
+ debug_print("Diary::Admin::run: $output_data{tmpl_file}");
+ ##############################################################
+ #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 $self->translate_templateL10N($self->get_HTML_header_owner("Diary:Owner mode"));
+ print $self->translate_templateL10N($tmpl->output);
+ print $afap->get_HTML_footer;
+
+}
+
+######################################################################
+#Get_HTML_header_owner
+######################################################################
+sub get_HTML_header_owner{
+ my $self = shift;
+# my $af = $self->{af};
+ my $app__page_title = shift;
+
+ #Set template file name
+ my $TMPL_FILE = "$self->{afap}->{af}->{site__tmpldyn_dir}/_header.tmpl";
+ #Set data for template
+ my %output_data = ();
+ $output_data{'app__css_path'} = $self->{afap}->{af}->{site__web_root}."/templates/default/owner_side";
+ $output_data{'app__page_title'} = "Affelio Owner's page";
+ $output_data{"site__skin_dir"} = $self->{afap}->{af}->{site__web_root} . "/skins/" . $self->{afap}->{af}->{userpref__skin};
+ $output_data{'site__web_root'} = $self->{afap}->{af}->{site__web_root};
+ $output_data{'site__locale'} = $self->{afap}->{af}->{site__locale};
+
+ $self->{afap}->{af}->get_module_list(\%output_data, $self->{afap}->{af}->{site__web_root},"self");
+ $self->{afap}->{af}->get_guest_owner_list(\%output_data);
+
+ #Initiate Template
+ my $tmpl = new HTML::Template( filename => $TMPL_FILE,
+ die_on_bad_params => 0);
+ $tmpl->param(%output_data);
+
+ my $menu_tmpl = new HTML::Template( filename => "./templates/admin_menu.tmpl",
+ die_on_bad_params => 0);
+ $menu_tmpl->param(access_control_URL => $self->{afap}->get_URL("access_control"));
+
+ my $final_out = $self->translate_templateL10N($tmpl->output)
+ . '<div class="afMain">' . "\n".$self->translate_templateL10N($menu_tmpl->output);
+
+ return($final_out);
+}
+
+}
+1;
Index: affelio/apps/diary/Diary/EditCategory.pm
diff -u /dev/null affelio/apps/diary/Diary/EditCategory.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/EditCategory.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,99 @@
+# Copyright (C) 2005 FishGrove 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.
+
+
+package Diary::EditCategory;
+{
+use strict;
+#use lib("../../../extlib/");
+#use lib("../../../lib/");
+#use Diary::L10N;
+#use DBI;
+#use Jcode;
+#use LWP::UserAgent;
+#use HTTP::Request::Common qw(POST);
+#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 Exporter;
+ @Diary::EditCategory::ISA = "Exporter";
+ @Diary::EditCategory::EXPORT = qw (show handler);
+
+
+ #######################################################################
+ #handler
+ #######################################################################
+ sub handler{
+ my $cgi = shift;
+ my $diary = shift;
+ my $out_ref = shift;
+
+ debug_print("Diary::EditCategory::handler: start.");
+
+ ###############################
+ #normal show
+ ###############################
+ $out_ref->{tmpl_file}
+ = $diary->{afap}->{app__fs_root}."/templates/edit_category.tmpl";
+
+ show($diary, $cgi, $out_ref);
+ debug_print("Diary::EditCategory::handler: end.");
+ }
+
+ #######################################################################
+ #show
+ #######################################################################
+ sub show{
+ my $diary= shift;
+ my $cgi=shift;
+ my $output_ref = shift;
+ debug_print("Diary::EditCategory::show start.");
+
+ my $wi = new Affelio::misc::WebInput();
+ my $category = $diary->escape($cgi->param("category"));
+ my $c_id = $wi->PTN_num($cgi->param("c_id"));
+ my $action = $wi->PTN_mode($cgi->param("action"));
+ if ($action eq "submit" && $category ne ""){
+ debug_print("Diary::Category::show: insert new category.");
+ # prevent double submit
+ my @same = $diary->getall("SELECT id FROM $diary->{category_table} WHERE category = '$category'");
+ if($#same >= 0) { return; }
+
+ $diary->{dbh}->do("INSERT INTO $diary->{category_table} VALUES (NULL, '$category')");
+
+ debug_print("Diary::Category::show: Done, insert category.");
+ $output_ref->{"DONE_ADD"} = '1';
+ }elsif($action eq "update" && $category ne "" && $c_id ne ""){
+ $diary->{dbh}->do("UPDATE $diary->{category_table} SET category = '$category' WHERE id = $c_id");
+ $output_ref->{"DONE_UPDATE"} = '1';
+ }
+ my @categories = $diary->getall("SELECT id, category FROM $diary->{category_table}");
+ $output_ref->{"CATEGORIES"}= \@categories;
+
+ debug_print("Diary::EditCategory::show: set output.");
+
+ $output_ref->{"EDIT_CATEGORY"} = '1';
+ debug_print("Diary::EditCategory::show end.");
+ }
+
+}
+1;
Index: affelio/apps/diary/Diary/GetRss.pm
diff -u /dev/null affelio/apps/diary/Diary/GetRss.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/GetRss.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,82 @@
+# 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.
+
+package Diary;
+{
+ use strict;
+ use Affelio::misc::Debug qw( debug_print);
+
+ ######################################################################
+ #run_getrss
+ ######################################################################
+ sub run_getrss{
+ my $self = shift;
+ my $afap = $self->{afap};
+ my $cgi = $self->{cgi};
+
+ my $wi = new Affelio::misc::WebInput();
+ my $count = $wi->PTN_num($cgi->url_param("count"));
+
+ debug_print("Diary::GetRss: start");
+
+ ###########################
+ #Check DF_access
+ ###########################
+ unless ($afap->check_access("DF_access")) {
+ $self->accessErrorExit('Access Denied. You don\'t have permission to this application.');
+ }
+
+ unless ($count) { $count = 5; }
+
+ my $tmpl = new HTML::Template(filename => './templates/rss.tmpl');
+
+ my @entries = $self->getall("SELECT * FROM $self->{entry_table} ORDER BY timestamp DESC LIMIT $count");
+
+ my @item_list;
+ my @items;
+ my $web_root = $self->{afap}->get_site_info('web_root');
+ my $uname = $self->{afap}->get_owner_info('nickname');
+
+ foreach (@entries) {
+ my $link = "$afap->{app__fs_root}/show_diary.cgi?id=$_->{id}";
+ push @item_list, { LINK => $link, };
+ my ($sec, $min, $hour, $mday, $mon, $year) = localtime($_->{timestamp});
+ push @items, {
+ TITLE => $_->{title},
+ LINK => $link,
+ DESCRIPTION => $_->{contents},
+ DATE => sprintf("%4d-%02d-%02dT%02d:%02d+09:00", $year, $mon, $mday, $hour, $min),
+ CREATOR => $uname,
+ TPING => $web_root."$afap->{app__fs_root}/tb.cgi/$_->{id}",
+ };
+ }
+
+ $tmpl->param(
+ LINK => $web_root,
+ NICKNAME => $uname,
+ ITEM_LIST => \@item_list,
+ ITEMS => \@items,
+ );
+
+ print "Content-type: application/xml; charset=UTF-8\n";
+ print "Pragma: no-cache", "\n\n";
+ print $tmpl->output;
+
+ debug_print("Diary::GetRss: end");
+}
+
+}
+1;
Index: affelio/apps/diary/Diary/PrefSet.pm
diff -u /dev/null affelio/apps/diary/Diary/PrefSet.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/PrefSet.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,124 @@
+# Copyright (C) 2005 FishGrove 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.
+
+
+package Diary::PrefSet;
+{
+use strict;
+#use lib("../../../extlib/");
+#use lib("../../../lib/");
+#use Diary::L10N;
+#use DBI;
+#use Jcode;
+#use LWP::UserAgent;
+#use HTTP::Request::Common qw(POST);
+#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 Exporter;
+ @Diary::PrefSet::ISA = "Exporter";
+ @Diary::PrefSet::EXPORT = qw (show handler);
+
+
+ #######################################################################
+ #handler
+ #######################################################################
+ sub handler{
+ my $cgi = shift;
+ my $diary = shift;
+ my $out_ref = shift;
+
+ debug_print("Diary::RdfSet::handler: start.");
+
+ ###############################
+ #normal show
+ ###############################
+ $out_ref->{tmpl_file}
+ = $diary->{afap}->{app__fs_root}."/templates/rdf_set.tmpl";
+
+ show($diary, $cgi, $out_ref);
+ debug_print("Diary::RdfSet::handler: end.");
+ }
+
+ #######################################################################
+ #show
+ #######################################################################
+ sub show{
+ my $diary= shift;
+ my $cgi=shift;
+ my $output_ref = shift;
+ debug_print("Diary::RdfSet::show start.");
+
+ my $wi = new Affelio::misc::WebInput();
+ my $action = $wi->PTN_mode($cgi->param("action"));
+ my $type = $wi->PTN_mode($cgi->param("type"));
+ my $url = $wi->PTN_URL($cgi->param("url"));
+
+ if ($action eq "submit"){
+ if ($type eq 'import' && $url ne "") {
+ debug_print("Diary::RdfSet::show: Set the RDF file.");
+ if ($url) {
+ setRDFURL($diary, $url);
+ $output_ref->{"SET_RDF"} = '<AF_M text="RDF file was imported.">';
+ }
+ } else { # normal diary
+ debug_print("Diary::RdfSet::show: Unset the RDF file.");
+ unsetRDFURL($diary);
+ $output_ref->{"UNSET_RDF"} = '<AF_M text="The RDF file was unlinked.">';
+ }
+ }
+
+ my $rdf_url = $diary->getRDFURL;
+ if ($rdf_url){
+ $output_ref->{"use_rdf"} = 'CHECKED';
+ $output_ref->{"rdf_url"} = $rdf_url;
+ }else{
+ $output_ref->{"default"} = 'CHECKED';
+ }
+
+ debug_print("Diary::RdfSet::show end.");
+ }
+
+##############################################
+# setRDFURL
+##############################################
+
+sub setRDFURL {
+ my ($diary, $url) = @_;
+ local (*OUT);
+
+ open(OUT, "> $diary->{datadir}url");
+ print OUT $url;
+ close(OUT);
+}
+
+##############################################
+# unsetRDF
+##############################################
+
+sub unsetRDFURL {
+ my $diary = shift;
+ unlink("$diary->{datadir}url") if (-f "$diary->{datadir}url");
+}
+
+}
+1;
Index: affelio/apps/diary/Diary/ReadRdf.pm
diff -u /dev/null affelio/apps/diary/Diary/ReadRdf.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/ReadRdf.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,148 @@
+# Copyright (C) 2005 FishGrove 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.
+
+
+package Diary::ReadRdf;
+{
+use strict;
+use lib("../../../extlib/");
+use lib("../../../lib/");
+use lib("../extlib/");
+use Diary::L10N;
+use DBI;
+use Jcode;
+use LWP::UserAgent;
+use HTTP::Request::Common qw(POST);
+use AffelioApp;
+#use HTML::Template;
+#use CGI;
+use Cwd;
+use XML::Parser;
+use XML::RSS;
+
+ use Affelio::misc::Debug qw( debug_print);
+ use Affelio::misc::WebInput;
+ use Affelio::exception::SystemException;
+ use Error qw(:try);
+
+ use Exporter;
+ @Diary::ReadRdf::ISA = "Exporter";
+ @Diary::ReadRdf::EXPORT = qw (show handler);
+
+
+ #######################################################################
+ #handler
+ #######################################################################
+ sub handler{
+ my $cgi = shift;
+ my $diary = shift;
+ my $out_ref = shift;
+
+ debug_print("Diary::ReadRdf::handler: start.");
+
+ ###############################
+ #normal show
+ ###############################
+ $out_ref->{tmpl_file}
+ = $diary->{afap}->{app__fs_root}."/templates/external_blog.tmpl";
+
+ show($diary, $cgi, $out_ref);
+ debug_print("Diary::ReadRdf::handler: end.");
+ }
+
+ #######################################################################
+ #show
+ #######################################################################
+ sub show{
+ my $diary= shift;
+ my $cgi=shift;
+ my $output_ref = shift;
+ debug_print("Diary::ReadRdf::show start.");
+
+ my $urlfile = $diary->{datadir}.'url';
+ my $rssfile = $diary->getRDFURL;
+
+# send request
+ my $req = new HTTP::Request(GET => $rssfile);
+ my $ua = new LWP::UserAgent;
+ my $res = $ua->request($req);
+ my $str;
+ if ($res->is_success) {
+ $str = $res->content;
+ $str =~ s/&/&/g; # escape '&'
+ }
+ else {
+ unlink($urlfile) if (-f $urlfile);
+ $diary->errorExit("Failed to get RDF File");
+ debug_print("Diary::ReadRdf::show Failed to get RDF.");
+ }
+
+ my $rss = new XML::RSS;
+ unless (eval { $rss->parse($str); }) {
+# $diary->unsetRDFURL;
+ unlink($urlfile) if (-f $urlfile);
+ $diary->errorExit("Failed to parse RDF File");
+ debug_print("Diary::ReadRdf::show Failed to parse RDF.");
+ }
+
+ my @entries;
+ my @entry_list;
+ my $i = 0;
+ foreach (@{ $rss->{items} }) {
+ push @entries, {
+ TITLE => $_->{'title'},
+ LINK => $_->{'link'},
+ CONTENTS=> &escape_html($_->{'description'}),
+ DATE => $_->{dc}->{'date'},
+ };
+ push @entry_list, {
+ TITLE => $_->{'title'},
+ LINK => $_->{'link'},
+ };
+ last if (++$i >= 10);
+ }
+# $output_ref->{WRITABLE} = $writable;
+ $output_ref->{WRITABLE} = '0';
+ $output_ref->{RSS_URL} = $rssfile;
+ $output_ref->{TITLE_MAIN} = $rss->channel('title');
+ $output_ref->{LINK_MAIN} = $rss->channel('link');
+ $output_ref->{ENTRIES} = \@entries;
+ $output_ref->{ENTRY_LIST} = \@entry_list;
+
+ debug_print("Diary::ReadRdf::show end.");
+ }
+
+sub escape_html {
+ my $html = shift;
+
+ if ($html =~ /</) {
+ $html =~ s/<(.*)>//g;
+ $html =~ s/&/&/g;
+ $html =~ s/&(quot|apos);/"/g;
+ }
+
+ $html =~ s/&/&/g;
+ $html =~ s/"/"/g;
+ $html =~ s/'/'/g;
+ $html =~ s/<[^>]*>//g;
+ $html =~ s/</</g;
+ $html =~ s/>/>/g;
+ return $html;
+}
+
+
+}
+1;
Index: affelio/apps/diary/Diary/ShowDiary.pm
diff -u /dev/null affelio/apps/diary/Diary/ShowDiary.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/ShowDiary.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,215 @@
+# 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.
+#
+# $Id: ShowDiary.pm,v 1.1 2006/03/01 05:40:35 higefuku Exp $
+
+package Diary::ShowDiary;
+{
+use strict;
+use lib("../../../extlib/");
+use lib("../../../lib/");
+use Diary::L10N;
+use DBI;
+use Jcode;
+use LWP::UserAgent;
+use HTTP::Request::Common qw(POST);
+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 Exporter;
+ @Diary::ShowDiary::ISA = "Exporter";
+ @Diary::ShowDiary::EXPORT = qw (show handler);
+
+
+ #######################################################################
+ #handler
+ #######################################################################
+ sub handler{
+ my $cgi = shift;
+ my $diary = shift;
+ my $out_ref = shift;
+
+ debug_print("Diary::ShowDiary::handler: start.");
+
+
+ ###############################
+ #normal show
+ ###############################
+ $out_ref->{tmpl_file}
+ = $diary->{afap}->{app__fs_root}."/templates/show_diary.tmpl";
+
+ show($diary, $cgi, $out_ref);
+ debug_print("Diary::ShowDiary::handler: end.");
+ }
+
+ #######################################################################
+ #show
+ #######################################################################
+ sub show{
+ my $diary= shift;
+ my $cgi=shift;
+ my $output_ref = shift;
+ debug_print("Diary::ShowDiary::show start.");
+
+ my $wi = new Affelio::misc::WebInput();
+ my $id = $wi->PTN_num($cgi->url_param("id"));
+ if($diary->{afap}->check_access("write_comment")){
+ $output_ref->{COMMENT_WRITE} = '1';
+ }
+
+#my $id = $afap->{cgi}->param('id') or $diary->errorExit("An article number was not specified");
+#$diary->errorExit("The specified article does not exist") unless existsEntry($diary,$id);
+
+ debug_print("Diary::ShowDiary::get diary. $id");
+ my $entry = getEntry($diary,$id);
+ my ($sec, $min, $hour) = localtime($entry->{timestamp});
+
+ my $category = $diary->getColumn("select category from $diary->{category_table} where id=$entry->{c_id}");
+
+ debug_print("Diary::ShowDiary::get diary. $entry->{title}");
+
+# Diary
+ my $images="";
+ if (!($entry->{contents} =~ s/<image=\"([A-Za-z0-9\-\_]*\.(jpg)|(png)|(gif)|(bmp)|(jpeg))\">/<a href=\"show_image.cgi\?id=$entry->{id}&filename=$1&size=l\"><img src=\"show_image.cgi\?id=$entry->{id}&filename=$1&size=s\" boader=\"0\"\<\/a>/ig)){
+ $images=getUploadedImages($diary, $entry->{id}, 300, 300);
+ }
+
+ $output_ref->{"ID"} = $entry->{id};
+ $output_ref->{"CATEGORY"} = $category;
+ $output_ref->{"MONTH"} = $entry->{month};
+ $output_ref->{"DAY"} = $entry->{day};
+ $output_ref->{"HOUR"} = $hour;
+ $output_ref->{"MIN"} = $min;
+ $output_ref->{"TITLE"} = $entry->{title};
+ $output_ref->{"CONTENTS"} = $entry->{contents};
+ $output_ref->{"IMAGES"} = $images;
+ $output_ref->{"USERNAME"} = $entry->{user};
+
+
+# Comment
+if($diary->getCommentsNo($id) > 0) {
+ $output_ref->{"HAS_COMMENTS"} = "1";
+ my @comments_param;
+ my @comments = getComments($diary, $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}
+ };
+ }
+ $output_ref->{"COMMENTS"} = \@comments_param;
+}
+
+
+ $output_ref->{"install_title"} = $diary->{afap}->get_app_info("install_title");
+ debug_print("Diary::ShowDiary::show end.");
+ }
+}
+
+
+
+##############################################
+# getEntry
+##############################################
+
+sub getEntry {
+ my $diary = shift;
+ my $id = $diary->escape(shift, 'int');
+ my @ret = $diary->getall("SELECT * FROM $diary->{entry_table} WHERE id = $id");
+ return $ret[0];
+}
+
+
+##############################################
+# existsEntry
+##############################################
+
+sub existsEntry {
+ my $diary = shift;
+ my $id = $diary->escape(shift, 'int');
+ return $diary->getColumn("SELECT COUNT(*) FROM $diary->{entry_table} WHERE id = $id") > 0;
+}
+
+##############################################
+# getComments
+##############################################
+
+sub getComments {
+ my $diary = shift;
+ my $id = $diary->escape(shift, 'int');
+ return $diary->getall("SELECT * FROM $diary->{comment_table} WHERE id = $id ORDER BY timestamp");
+}
+
+
+##############################################
+# getCommentsNo
+##############################################
+
+#sub getCommentsNo {
+# my $diary = shift;
+# my $id = $diary->escape(shift, 'int');
+# return $diary->getColumn("SELECT count(*) FROM $diary->{comment_table} WHERE id = $id");
+#}
+
+##############################################
+# getTrackbacksNo
+##############################################
+
+sub getTrackbacksNo {
+ my $diary = shift;
+ my $id = $diary->escape(shift, 'int');
+ return $diary->getColumn("SELECT COUNT(*) FROM $diary->{tb_table} WHERE id = $id");
+}
+
+##############################################
+# getUploadedImages
+##############################################
+
+sub getUploadedImages {
+ my ($diary, $id, $width, $height) = @_;
+
+ $width = "&w=$width" if ($width);
+ $height = "&h=$height" if ($height);
+
+ my $imgdir = "$diary->{datadir}img/$id/";
+ my $ret;
+
+ local (*DIR);
+ opendir(DIR, $imgdir);
+ while (my $file = readdir(DIR)) {
+ if (-f $imgdir.$file) {
+ $ret .= "<a href=\"show_image.cgi?id=$id&filename=$file\" target=\"_blank\">".
+ "<img src=\"show_image.cgi?id=$id&filename=$file$width$height\" border=\"0\" />".
+ "</a><br />";
+ }
+ }
+ closedir(DIR);
+
+ return $ret ? "<p>$ret</p>" : "";
+}
+
+1;
Index: affelio/apps/diary/Diary/ShowImage.pm
diff -u /dev/null affelio/apps/diary/Diary/ShowImage.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/ShowImage.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,104 @@
+# 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.
+#
+
+package Diary;
+{
+ use strict;
+ use Image::Magick;
+
+ use Affelio::misc::Debug qw( debug_print);
+
+ ######################################################################
+ #run_showimage
+ ######################################################################
+ sub run_showimage{
+ my $self = shift;
+ my $afap = $self->{afap};
+ my $cgi = $self->{cgi};
+ my $wi = $self->{wi};
+
+ debug_print("Diary::ShowImage: start");
+
+ ###########################
+ #Check DF_access
+ ###########################
+ unless ($afap->check_access("DF_access")) {
+ $self->accessErrorExit('Access Denied. You don\'t have permission to this application.');
+ }
+
+ my $id = $wi->PTN_num($cgi->url_param("id"));
+ my $filename = $wi->PTN_basefilename($cgi->url_param("filename"));
+ my $width = $wi->PTN_num($cgi->url_param("w"));
+ my $height = $wi->PTN_num($cgi->url_param("h"));
+ my $size = $wi->PTN_mode($cgi->url_param("size"));
+ my $type = $filename;
+ $type =~ s/[^.]+\.(.*)/$1/i;
+ $type =~ s/jpg/jpeg/i;
+ my $filepath;
+ my $thumbpath;
+
+ if ($id eq '0'){
+ $filepath = "$self->{datadir}tmp/".$filename;
+ $thumbpath = "$self->{datadir}tmp/thumb/".$filename;
+ }else{
+ $filepath = "$self->{datadir}img/$id/".$filename;
+ $thumbpath = "$self->{datadir}img/$id/thumb/".$filename;
+ }
+
+
+ binmode STDOUT;
+ print "Content-type: image/$type\n\n";
+ if ($size eq "s"){
+ &output_img($thumbpath);
+ }
+ elsif ($width and $height and (eval 'use Image::Magick; 1;')) {
+ try {
+ my $image = new Image::Magick;
+ $image->Read(filename => $filepath);
+ my ($w, $h) = $image->Get('columns', 'rows');
+ if ($w > $width or $h > $height) {
+ $image->Resize(geometry => $width.'x'.$height);
+ $image->Set(quality => 75);
+ }
+ $image->Write(file => \*STDOUT);
+ }
+ catch Error with {
+ my $e = shift;
+ &output_img($filepath);
+ };
+ }
+ else {
+ &output_img($filepath);
+ }
+
+
+ debug_print("Diary::ShowImage: end");
+
+}
+
+sub output_img {
+ my $file = shift;
+ local (*IMG);
+ open(IMG, "$file") or die;
+ binmode IMG;
+ print while (<IMG>);
+ close(IMG);
+}
+
+
+}
+1;
Index: affelio/apps/diary/Diary/ShowTb.pm
diff -u /dev/null affelio/apps/diary/Diary/ShowTb.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/ShowTb.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,137 @@
+# 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.
+#
+
+package Diary::ShowTb;
+{
+use strict;
+use Jcode;
+use lib("../../../extlib/");
+use lib("../../../lib/");
+use Diary::L10N;
+use DBI;
+use LWP::UserAgent;
+use HTTP::Request::Common qw(POST);
+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 Exporter;
+ @Diary::ShowTb::ISA = "Exporter";
+ @Diary::ShowTb::EXPORT = qw (show handler);
+
+
+ #######################################################################
+ #handler
+ #######################################################################
+ sub handler{
+ my $cgi = shift;
+ my $diary = shift;
+ my $out_ref = shift;
+
+ debug_print("Diary::ShowTb::handler: start.");
+
+
+ ###############################
+ #normal show
+ ###############################
+ $out_ref->{tmpl_file}
+ = $diary->{afap}->{app__fs_root}."/templates/show_trackback.tmpl";
+
+ show($diary, $cgi, $out_ref);
+ debug_print("Diary::ShowTb::handler: end.");
+ }
+
+ #######################################################################
+ #show
+ #######################################################################
+ sub show{
+ my $diary= shift;
+ my $cgi=shift;
+ my $output_ref = shift;
+ debug_print("Diary::Showtb::show start.");
+
+ my $wi = new Affelio::misc::WebInput();
+ my $id = $wi->PTN_num($cgi->url_param("id"));
+
+ my @ts = getTrackbacks($diary,$id);
+ my @trackbacks;
+ foreach (@ts) {
+ my ($sec, $min, $hour, $mday, $mon, $year) = localtime($_->{timestamp});
+ $year += 1900; $mon += 1;
+ push @trackbacks, {
+ TITLE => $diary->escape($_->{title}),
+ BLOG_NAME => $diary->escape($_->{blog_name}),
+ URL => $_->{url},
+ EXCERPT => $diary->escape($_->{excerpt}),
+ DATE => "$year/$mon/$mday $hour:$min",
+ };
+ }
+
+ $output_ref->{PING_URL} = $diary->{afap}->{af}->{site__web_root}."/apps/$diary->{afap}->{install_name}/tb.cgi/$id";
+ $output_ref->{TRACKBACKS} =\@trackbacks;
+ debug_print("Diary::Showtb::show end.");
+}
+
+##############################################
+# getTrackbacks
+##############################################
+
+sub getTrackbacks {
+ my $diary = shift;
+ my $id = shift;
+ my @ret = $diary->getall("SELECT * FROM $diary->{tb_table} WHERE id = $id");
+
+ foreach (@ret) {
+ $_->{excerpt} = Jcode::convert($_->{excerpt}, 'utf8');
+ }
+ reset (@ret);
+
+ return @ret;
+}
+
+##############################################
+# getURLDescription
+##############################################
+
+#sub getURLDescription {
+# my $self = shift;
+# my $id = shift
+
+# my ($entry) = $self->getall("SELECT * FROM $self->{entry_table} WHERE id = $id");
+# my $tmpl = new HTML::Template(filename => "./templates/tpingrdf.tmpl");
+# my ($sec, $min, $hour, $mday, $mon, $year) = localtime($entry->{timestamp});
+# $year += 1900; $mon += 1;
+
+# $tmpl->param(
+# TITLE => $entry->{title},
+# TURL => "$self->{afap}->{af}->{site__web_root}/apps/$self->{afap}->{install_name}/tb/tb.cgi/$id",
+# IDENT => "$self->{afap}->{af}->{site__web_root}/apps/$self->{afap}->{install_name}/show_diary.cgi?id=$id",
+# DESCRIPTION => $entry->{contents},
+# CREATOR => $self->{afap}->{af}->{user__nickname},
+# DATE => sprintf("%4d-%02d-%02dT%02d:%02d+09:00", $year, $mon, $mday, $hour, $min),
+# );
+
+# return $tmpl->output;
+#}
+
+}
+1;
Index: affelio/apps/diary/Diary/Top.pm
diff -u /dev/null affelio/apps/diary/Diary/Top.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/Top.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,238 @@
+# 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.
+
+
+package Diary::Top;
+{
+use strict;
+use Affelio::misc::Debug qw( debug_print);
+
+use Exporter;
+ @ Diary::Top::ISA = "Exporter";
+ @ Diary::Top::EXPORT = qw (show handler);
+
+
+ #######################################################################
+ #handler
+ #######################################################################
+ sub handler{
+ my $cgi = shift;
+ my $diary = shift;
+ my $out_ref = shift;
+
+ debug_print("Diary::Top::handler: start.");
+ ###############################
+ #normal show
+ ###############################
+ $out_ref->{tmpl_file}
+ = $diary->{afap}->{app__fs_root}."/templates/list_diary.tmpl";
+
+ show($diary, $cgi, $out_ref);
+ debug_print("Diary::Top::handler: end.");
+ }
+
+ #######################################################################
+ #show
+ #######################################################################
+ sub show{
+ my $diary= shift;
+ my $cgi=shift;
+ my $output_ref = shift;
+ debug_print("Diary::Top::show start.");
+
+ my $wi = new Affelio::misc::WebInput();
+ my $year = $wi->PTN_num($cgi->url_param("year"));
+ my $month = $wi->PTN_num($cgi->url_param("month"));
+ my $day = $wi->PTN_num($cgi->url_param("day"));
+ my $c_id = $wi->PTN_num($cgi->url_param("c_id"));
+
+ my $edit = 0;
+ my $user;
+ if($diary->{afap}->check_access("write_diary")) {
+ $user = $diary->{afap}->get_owner_info("nickname");
+ $edit = 1;
+ }
+
+
+ my @entries_param=();
+ $output_ref->{"ENTRIES"} = \@entries_param;
+ my @entries;
+
+ if($year and $month){
+ @entries = getEntries($diary, $year, $month, $day);
+ if($day and $#entries == 0) {
+ my ($tid) = @entries;
+ print getURLDescription($diary, $tid->{id});
+ }
+ }
+ elsif($c_id){
+ @entries = getEntriesCategory($diary, $c_id);
+ }else{
+ debug_print("Diary::Top::show: get newest entries.");
+ @entries = getNewestEntries($diary);
+ }
+
+ my $i = 0;
+ my $category;
+ foreach(@entries) {
+ my ($sec, $min, $hour) = localtime($_->{timestamp});
+
+ if ($_->{c_id} eq ""){
+ $category='<AF_M text="none">';
+ }else{
+ $category = $diary->getColumn("select category from $diary->{category_table} where id=$_->{c_id}");
+ }
+
+ my $images="";
+ if (!($_->{contents} =~ s/<image=\"([A-Za-z0-9\-\_]*\.(jpg)|(png)|(gif)|(bmp)|(jpeg))\">/<a href=\"show_image.cgi\?id=$_->{id}&filename=$1&size=l\"><img src=\"show_image.cgi\?id=$_->{id}&filename=$1&size=s\" border=\"0\"><\/a>/ig)){
+ $images=getUploadedImages($diary, $_->{id}, 300, 300);
+ }
+ my $username=$_->{user};
+
+ push @entries_param,
+ {
+ MONTH => $_->{month},
+ DAY => $_->{day},
+ HOUR => sprintf("%02d", $hour),
+ MIN => sprintf("%02d", $min),
+ TITLE => $_->{title},
+ CATEGORY=> $category,
+ USERNAME=> $username,
+ CONTENTS=> $_->{contents},
+ COMMENT_NO => $diary->getCommentsNo($_->{id}),
+ TRACKBACKS => getTrackbacksNo($diary, $_->{id}),
+ ID => $_->{id},
+ IMAGES => $images,
+ EDITABLE=> $edit
+ };
+ }
+ debug_print("Diary::Top::show: set output.");
+#$tmpl->param(ENTRIES => \@entries_param, EDITABLE => $edit);
+ $output_ref->{"ENTRIES"} = \@entries_param;
+ $output_ref->{"EDITABLE"} = $edit;
+ $output_ref->{"install_title"} = $diary->{afap}->get_app_info("install_title");
+ debug_print("Diary::Top::show end.");
+ }
+}
+
+
+##############################################
+# getEntries
+#############################################
+
+sub getEntries {
+ my $diary = shift;
+ my $year = $diary->escape(shift, 'int');
+ my $month = $diary->escape(shift, 'int');
+ my $day = $diary->escape(shift, 'int');
+
+ my $query = "SELECT * FROM $diary->{entry_table} WHERE year = $year AND month = $month";
+
+ if ($day) {
+ $query .= " AND day = $day";
+ }
+
+ $query .= " ORDER BY timestamp DESC";
+
+ return $diary->getall($query);
+}
+
+##############################################
+# getEntriesCategory
+#############################################
+
+sub getEntriesCategory {
+ my $diary = shift;
+ my $c_id = shift;
+ my $query = "SELECT * FROM $diary->{entry_table} WHERE c_id=$c_id";
+ $query .= " ORDER BY timestamp DESC";
+ return $diary->getall($query);
+}
+
+
+##############################################
+# getNewestEntries
+##############################################
+
+sub getNewestEntries {
+ my ($diary, $num) = @_;
+ unless ($num) { $num = 5; }
+ return $diary->getall("SELECT * FROM $diary->{entry_table} ORDER BY timestamp DESC LIMIT $num");
+}
+
+
+##############################################
+# getTrackbacksNo
+##############################################
+
+sub getTrackbacksNo {
+ my $diary = shift;
+ my $id = $diary->escape(shift, 'int');
+ return $diary->getColumn("SELECT COUNT(*) FROM $diary->{tb_table} WHERE id = $id");
+}
+
+##############################################
+# getUploadedImages
+##############################################
+
+sub getUploadedImages {
+ my ($diary, $id, $width, $height) = @_;
+
+ $width = "&w=$width" if ($width);
+ $height = "&h=$height" if ($height);
+
+ my $imgdir = "$diary->{datadir}img/$id/";
+ my $ret;
+
+ local (*DIR);
+ opendir(DIR, $imgdir);
+ while (my $file = readdir(DIR)) {
+ if (-f $imgdir.$file) {
+ $ret .= "<a href=\"show_image.cgi?id=$id&filename=$file\" target=\"_blank\">".
+ "<img src=\"show_image.cgi?id=$id&filename=$file$width$height\" border=\"0\" />".
+ "</a><br />";
+ }
+ }
+ closedir(DIR);
+
+ return $ret ? "<p>$ret</p>" : "";
+}
+
+##############################################
+# getURLDescription
+##############################################
+
+sub getURLDescription {
+ my $diary = shift;
+ my $id = $diary->escape(shift, 'int');
+
+ my ($entry) = $diary->getall("SELECT * FROM $diary->{entry_table} WHERE id = $id");
+ my $tmpl = new HTML::Template(filename => "../templates/tpingrdf.tmpl");
+ my ($sec, $min, $hour, $mday, $mon, $year) = localtime($entry->{timestamp});
+ $year += 1900; $mon += 1;
+
+ $tmpl->param(
+ TITLE => $entry->{title},
+ TURL => "$self->{afap}->{af}->{site__web_root}/apps/$self->{afap}->{install_name}/tb/tb.cgi/$id",
+ IDENT => "$self->{afap}->{af}->{site__web_root}/apps/$self->{afap}->{install_name}/show_diary.cgi?id=$id",
+ DESCRIPTION => $entry->{contents},
+ CREATOR => $self->{afap}->{af}->{user__nickname},
+ DATE => sprintf("%4d-%02d-%02dT%02d:%02d+09:00", $year, $mon, $mday, $hour, $min),
+ );
+
+ return $tmpl->output;
+}
+
Index: affelio/apps/diary/Diary/UploadImage.pm
diff -u /dev/null affelio/apps/diary/Diary/UploadImage.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/UploadImage.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,135 @@
+# 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.
+
+package Diary;
+{
+ use strict;
+ use Affelio::misc::Debug qw( debug_print);
+
+ ######################################################################
+ #run_upload
+ ######################################################################
+ sub run_upload{
+ my $self = shift;
+ my $afap = $self->{afap};
+ my $cgi = $self->{cgi};
+ my $wi = $self->{wi};
+
+ debug_print("Diary::UploadImage: start");
+
+ ###########################
+ #Check DF_access
+ ###########################
+ unless ($afap->check_access("DF_access")) {
+ $self->accessErrorExit('Access Denied. You don\'t have permission to this application.');
+ }
+ unless ($afap->check_access("write_diary")) {
+ $self->accessErrorExit('Access Denied. You don\'t have permission to this application.');
+ }
+
+
+ ##############################################################
+ #Model invocation
+ ##############################################################
+ my %output_data = ("tmpl_path", Cwd::getcwd()."/templates/",
+ "style_path", $afap->{af}->{site__web_root} . "/skins/" . $afap->{af}->{userpref__skin}."/style.css");
+ my $tmpl = new HTML::Template(filename => "templates/uploader.tmpl",
+ die_on_bad_params => 0);
+ if ($cgi->param("upload")){
+ $self->saveUploadedImage($cgi->param("upload"),\%output_data);
+ }
+ $tmpl->param(%output_data);
+
+ print "Content-type: text/html; charset=UTF-8\n";
+ print "Pragma: no-cache", "\n\n";
+ print $self->translate_templateL10N($tmpl->output);
+
+ debug_print("Diary::UploadImage: end");
+
+}
+
+##############################################
+# saveUploadedImage
+##############################################
+
+sub saveUploadedImage {
+ use Image::Magick;
+ use File::Basename;
+ my ($self, $filehandle, $output_data, $id) = @_;
+ my $afap = $self->{afap};
+ my $file;
+ my $buf;
+ my $filesize = 0;
+ my $bytesread;
+ my $basename;
+
+ if ($filehandle){
+ fileparse_set_fstype("MSDOS"); #For IE user
+ $basename = basename($filehandle,"");
+ if ($basename =~ /^[a-zA-Z0-9\.\-\_]{1,32}$/ ){ #Check Filename
+ unless ($basename =~ /^[a-zA-Z0-9\.\-\_]{1,28}\.(jpg|jpeg|png|gif|bmp)$/i) {
+ print "Uploaded file had invalid MIME type";
+ }
+ while ($bytesread = read($filehandle, $buf, 1024)) {
+ $file .= $buf;
+# $self->errorExit('Uploaded file was too big') if (++$filesize >= 300);
+ }
+ my $imgdir = "$self->{datadir}img/";
+ unless (-d $imgdir) {
+ mkdir $imgdir;
+ }
+ my $tmp_imgdir = "$self->{datadir}tmp/";
+ unless (-d $tmp_imgdir) {
+ mkdir $tmp_imgdir;
+ }
+
+
+ my $basedir = $tmp_imgdir;
+
+ my $thumbdir = $basedir."thumb/";
+ unless (-d $thumbdir) {
+ mkdir $thumbdir;
+ }
+
+ my $distfile = $basedir.$basename;
+ my $thumbfile = $thumbdir.$basename;
+ # Save file
+ local (*OUT);
+ open(OUT, "> $distfile") or $output_data->{err}= "Failed to open file";
+ binmode OUT;
+ print OUT $file;
+ close(OUT);
+
+# (eval 'use Image::Magick; 1;' ) ? ( $tmpl->param(IMAGEMAGICK => 0) ) : ( $tmpl->param(IMAGEMAGICK =>1) );
+ my $image = Image::Magick->new;
+ $image->Read( $distfile );
+ $image->Resize( geometry=>"300x300" );
+ $image->Set( quality=>75 );
+ $image->Write( $thumbfile );
+
+ }else{
+ $output_data->{err}= "You can only use ascii character in your file name";
+ }
+ }
+ else{
+ $output_data->{err}= "Please select a file.";
+ }
+ $output_data->{img}= $basename;
+}
+
+
+}
+1;
Index: affelio/apps/diary/Diary/WriteComment.pm
diff -u /dev/null affelio/apps/diary/Diary/WriteComment.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/WriteComment.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,160 @@
+# Copyright (C) 2005 FishGrove 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.
+
+
+package Diary::WriteComment;
+{
+use strict;
+use lib("../../../extlib/");
+use lib("../../../lib/");
+use Diary::L10N;
+use DBI;
+use Jcode;
+use LWP::UserAgent;
+use HTTP::Request::Common qw(POST);
+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 Exporter;
+ @Diary::WriteComment::ISA = "Exporter";
+ @Diary::WriteComment::EXPORT = qw (show handler);
+
+
+ #######################################################################
+ #handler
+ #######################################################################
+ sub handler{
+ my $cgi = shift;
+ my $diary = shift;
+ my $out_ref = shift;
+
+ debug_print("Diary::WriteComment::handler: start.");
+
+ ###############################
+ #normal show
+ ###############################
+ $diary->checkAccess('write_comment');
+
+ show($diary, $cgi, $out_ref);
+ debug_print("Diary::WriteComment::handler: end.");
+ }
+
+ #######################################################################
+ #show
+ #######################################################################
+ sub show{
+ my $diary= shift;
+ my $cgi=shift;
+ my $output_ref = shift;
+ debug_print("Diary::WriteComment::show start.");
+
+ my $wi = new Affelio::misc::WebInput();
+ my $id = $wi->PTN_num($cgi->param("id"));
+ my $sub_mode = $wi->PTN_mode($cgi->param("action"));
+ my $comment = $cgi->param("comment");
+
+ $diary->errorExit('An article number was not specified') if (!$id);
+ $diary->errorExit("The specified article does not exist") unless $diary->existsEntry($id);
+ my $user = $diary->{afap}->get_visitor_info("nickname");
+
+ ###############################
+ #arg
+ ###############################
+# try{
+ if( $sub_mode eq "confirm" ){
+ debug_print("Diary::WriteComment::show: before confirm");
+ $output_ref->{tmpl_file} = $diary->{afap}->{app__fs_root}."/templates/write_comment_confirm.tmpl";
+ $output_ref->{"COMMENT_SHOW"} = $diary->escape($comment);
+ $output_ref->{"COMMENT"} = $comment;
+ $output_ref->{"ID"} = $id;
+ $output_ref->{"REQUIRE_NAME"} = 1 unless ($user);
+ debug_print("Diary::WriteComment::show: after confirm");
+ }
+ elsif($sub_mode eq "commit") {
+ $output_ref->{tmpl_file} = $diary->{afap}->{app__fs_root}."/templates/write_comment.tmpl";
+ $output_ref->{"COMMIT"} = 1;
+ $output_ref->{"ID"} = $id;
+
+ if(!$user){
+ $user = escape_comment($diary,$cgi->param('visitor_name'));
+ }else{
+ my $url = $diary->{afap}->get_visitor_info('afid');
+ if ($url =~ /<a href="([^"]*)"/) {
+ $url = $1;
+ }
+
+ $url = $diary->{afap}->get_site_info('web_root').'/outgoing.cgi?dest_url='.$url;
+ $user = "<a href=\"$url\">".$diary->{afap}->get_visitor_info("nickname")."</a>";
+
+ try {
+ addComment($diary, $id, $user, $comment);
+ }
+ catch Error with {
+ my $e = shift;
+ $output_ref->{err_msg} .= $e->stacktrace . '<BR>';
+ }
+ }
+ debug_print("Diary::WriteComment::show end.");
+ }
+}
+# print $diary->getRedirection("show_diary.cgi?id=$id");
+# exit;
+# else {
+# $diary->errorExit('Invalid Access');
+# }
+
+
+##############################################
+# addComment
+##############################################
+
+sub addComment {
+ my $diary = shift;
+ my $id = $diary->escape(shift, 'int');
+ my $user = shift;
+ my $comment = $diary->escape(shift);
+ my $time = time;
+
+ my @same = $diary->getall("SELECT id FROM $diary->{comment_table} WHERE user = '$user' AND comment = '$comment'");
+ if($#same >= 0) { return; }
+
+ $diary->{dbh}->do("INSERT INTO $diary->{comment_table} VALUES ($id, '$user', '$comment', $time)");
+}
+
+sub escape_comment {
+ my ($diary, $str) = @_;
+
+ $str =~ s/[\t\a]//g;
+ $str =~ s/&/&/g;
+ $str =~ s/['"]/"/g;
+ $str =~ s/</</g;
+ $str =~ s/>/>/g;
+ $str =~ s/(\r\n|\r|\n)/<br \/>/g;
+
+ return $str;
+}
+
+
+
+}
Index: affelio/apps/diary/Diary/WriteDiary.pm
diff -u /dev/null affelio/apps/diary/Diary/WriteDiary.pm:1.1
--- /dev/null Wed Mar 1 14:40:36 2006
+++ affelio/apps/diary/Diary/WriteDiary.pm Wed Mar 1 14:40:35 2006
@@ -0,0 +1,331 @@
+# 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.
+
+
+package Diary::WriteDiary;
+{
+use strict;
+use Jcode;
+use LWP::UserAgent;
+use HTTP::Request::Common qw(POST);
+use File::Copy;
+
+use Affelio::misc::Debug qw( debug_print);
+
+use Exporter;
+ @ Diary::WriteDiary::ISA = "Exporter";
+ @ Diary::WriteDiary::EXPORT = qw (show handler);
+
+
+ #######################################################################
+ #handler
+ #######################################################################
+ sub handler{
+ my $cgi = shift;
+ my $diary = shift;
+ my $out_ref = shift;
+
+ debug_print("Diary::Write::handler: start.");
+
+ ###############################
+ #normal show
+ ###############################
+ show($diary, $cgi, $out_ref);
+ debug_print("Diary::Write::handler: end.");
+ }
+
+ #######################################################################
+ #show
+ #######################################################################
+ sub show{
+ my $diary= shift;
+ my $cgi=shift;
+ my $output_ref = shift;
+ debug_print("Diary::Write::show start.");
+
+ my $wi = new Affelio::misc::WebInput();
+ my $sub_mode = $wi->PTN_mode($cgi->param("action"));
+ my $title = $cgi->param("title");
+ my $contents = $cgi->param("contents");
+ my $category = $wi->PTN_num($cgi->param("category"));
+ my $tping = $wi->PTN_URL($cgi->param("tping_url"));
+ my $id = $wi->PTN_num($cgi->param("id"));
+
+ ###############################
+ #arg
+ ###############################
+ try{
+ if( ($sub_mode eq "edit") && ($id)){
+ my $tmp_imgdir = "$diary->{datadir}tmp/";
+ my $tmp_thumbdir = "$diary->{datadir}tmp/thumb/";
+ removeFiles($diary,$tmp_imgdir);
+ removeFiles($diary,$tmp_thumbdir);
+
+ copyFiles($diary,$id);
+ $output_ref->{tmpl_file} = $diary->{afap}->{app__fs_root}."/templates/write_diary_edit.tmpl";
+ my $entry = getEntry($diary,$id);
+ $output_ref->{"ID"} = $id;
+ $output_ref->{"TITLE"} = $entry->{"title"};
+ $output_ref->{"CONTENTS"} = $diary->br2n($entry->{"contents"});
+ debug_print("Diary::Write::show:edit get category");
+ my @categories = $diary->getall("SELECT id, category FROM $diary->{category_table}");
+ debug_print("Diary::Write::show: num of category $#categories");
+ if ($#categories >= 0) {
+ foreach(@categories){
+ if ($entry->{c_id} == $_->{id}){
+ $_->{SELECT} = '1';
+ }else{
+ $_->{SELECT} = '0';
+ }
+ }
+ $output_ref->{"CATEGORIES"}= \@categories;
+ }
+
+ }elsif( $sub_mode eq "update" && ($id) ){
+ $title=$diary->escape($title);
+ $contents = $diary->escape($contents);
+ # update entry
+ debug_print("Diary::Write::show: before update entry");
+ updateEntry($diary,$id,$title,$contents,$category);
+ copyUploadImage($diary, $id);
+ # send trackback ping
+ debug_print("Diary::Write::show: ping");
+ if ($tping) {
+ sendTrackbackPing($diary, $tping, $title, $contents, $id);
+ }
+ $output_ref->{tmpl_file} = $diary->{afap}->{app__fs_root}."/templates/write_diary_done.tmpl";
+ }
+ elsif( $sub_mode eq "submit" ){
+ $title=$diary->escape($title);
+ $contents = $diary->escape($contents);
+ # add entry
+ debug_print("Diary::Write::show: before add entry");
+ my $new_id = addEntry($diary, $title, $contents, $category);
+ copyUploadImage($diary, $new_id);
+ debug_print("Diary::Write::show: post news");
+ $diary->{afap}->post_news($title,
+ "",
+ $diary->{afap}->get_visitor_info("nickname"),
+ $diary->{afap}->get_site_info("web_root") . "/apps/".
+ $diary->{afap}->{install_name} . "/list_diary.cgi");
+
+ debug_print("Diary::Write::show: ping");
+ # send trackback ping
+ if ($tping) {
+ sendTrackbackPing($diary, $tping, $title, $contents, $new_id);
+ }
+ debug_print("Diary::Write::show: load tmpl");
+
+ $output_ref->{tmpl_file} = $diary->{afap}->{app__fs_root}."/templates/write_diary_done.tmpl";
+ debug_print("Diary::Write::show: after submit");
+ }else{
+ my $tmp_imgdir = "$diary->{datadir}tmp/";
+ my $tmp_thumbdir = "$diary->{datadir}tmp/thumb/";
+ removeFiles($diary,$tmp_imgdir);
+ removeFiles($diary,$tmp_thumbdir);
+
+ $output_ref->{tmpl_file} = $diary->{afap}->{app__fs_root}."/templates/write_diary_edit.tmpl";
+ $output_ref->{"TITLE"} = $diary->escape($title);
+ $output_ref->{"CONTENTS"} = $diary->escape($contents);
+ debug_print("Diary::Write::show: get category");
+ my @categories = $diary->getall("SELECT id, category FROM $diary->{category_table}");
+ debug_print("Diary::Write::show: num of category $#categories");
+ if ($#categories >= 0) {
+ $output_ref->{"CATEGORIES"}= \@categories;
+ }
+ }
+ }catch Error with{
+ my $e = shift;
+ $output_ref->{err_msg} .= $e->stacktrace . '<BR>';
+ };
+
+ debug_print("Diary::Write::show end.");
+ }
+
+ ##############################################
+ # addEntry
+ ##############################################
+
+ sub addEntry {
+ my $diary = shift;
+ my $title = $diary->escape(shift);
+ my $contents = $diary->escape(shift);
+ my $c_id = shift;
+ my $user = $diary->{nickname};
+ my $uri = $diary->{afid};
+ my $pwd;
+ my $time = shift;
+ debug_print("Diary::Write::addEntry: start.");
+ unless ($time) { $time = time; }
+
+ my ($sec, $min, $hour, $mday, $mon, $year) = localtime($time);
+ $year += 1900; $mon += 1;
+ if ($c_id eq ""){ $c_id = "NULL";}
+ debug_print("Diary::Write::addEntry: prevent double submit.");
+ # prevent double submit
+ my @same = $diary->getall("SELECT id FROM $diary->{entry_table} WHERE title = '$title' AND contents = '$contents'");
+ if($#same >= 0) { return; }
+
+ debug_print("Diary::Write::addEntry: insert new entry.");
+ $diary->{dbh}->do("INSERT INTO $diary->{entry_table} VALUES (NULL, '$title', '$contents', $year, $mon, $mday, $time, $c_id, '$user', '$uri', NULL, 0)");
+
+ my $id = $diary->getColumn("SELECT MAX(id) FROM $diary->{entry_table}");
+ return $id;
+}
+
+##############################################
+# updateEntry
+##############################################
+sub updateEntry {
+ my $diary = shift;
+ my $id = $diary->escape(shift, 'int');
+ my $title = $diary->escape(shift);
+ my $contents = $diary->escape(shift);
+ my $c_id = $diary->escape(shift, 'int');
+ $diary->{dbh}->do("UPDATE $diary->{entry_table} SET title = '$title', contents = '$contents', c_id=$c_id WHERE id = $id");
+}
+
+
+##############################################
+# getEntry
+##############################################
+
+sub getEntry {
+ my $diary = shift;
+ my $id = $diary->escape(shift, 'int');
+ my @ret = $diary->getall("SELECT * FROM $diary->{entry_table} WHERE id = $id");
+ return $ret[0];
+}
+
+
+##############################################
+# sendTrackbackPing
+##############################################
+
+sub sendTrackbackPing {
+ my ($diary, $url, $title, $contents, $id) = @_;
+ $id = $diary->getColumn("SELECT MAX(id) FROM $diary->{entry_table}") unless ($id);
+ my %form = (
+ title => $title,
+ excerpt => "",#Jcode::convert($contents, 'utf8', 'auto'),
+ url => $diary->{afap}->get_site_info('web_root')."/apps/$diary->{afap}->{install_name}/index.cgi?id=$id",
+ blog_name => $diary->{afap}->get_app_info("install_title")."/".$diary->{afap}->get_owner_info('nickname'),
+ );
+ my $req = POST($url, [%form]);
+ my $ua = new LWP::UserAgent;
+ my $res = $ua->request($req);
+ my $str = $res->as_string;
+ if ($str =~ /<error>[^1]*1[^<]*<\/error>/) {
+ $diary->errorExit('Failed to send trackback ping');
+ }
+}
+
+##############################################
+# removeUploadedImage
+##############################################
+
+ sub removeUploadedImage {
+ my ($diary, $id) = @_;
+
+ $id = $diary->getColumn("SELECT MAX(id) FROM $diary->{entry_table}") unless ($id);
+
+ my $imgdir = "$diary->{datadir}img/$id/";
+ if (-d $imgdir) {
+ local (*DIR);
+ opendir(DIR, $imgdir);
+ while (my $file = readdir(DIR)) {
+ unlink ($imgdir.$file) if (-f $imgdir.$file);
+ }
+ closedir(DIR);
+ rmdir $imgdir;
+ }
+ }
+
+##############################################
+# copyUploadImage
+##############################################
+sub copyUploadImage {
+ my ($diary, $id) = @_;
+ my $imgdir = "$diary->{datadir}img/$id/";
+ my $thumbdir = "$diary->{datadir}img/$id/thumb/";
+ my $tmp_imgdir = "$diary->{datadir}tmp/";
+ my $tmp_thumbdir = "$diary->{datadir}tmp/thumb/";
+ my $file;
+ local (*DIR);
+ unless (-d $imgdir) {
+ mkdir $imgdir;
+ }
+ unless (-d $thumbdir) {
+ mkdir $thumbdir;
+ }
+
+ if (-d $tmp_thumbdir) {
+ opendir(DIR, $tmp_thumbdir);
+ while ($file = readdir(DIR)) {
+ move($tmp_thumbdir.$file, $thumbdir.$file);
+ }
+ closedir(DIR);
+ }
+ if (-d $tmp_imgdir) {
+ opendir(DIR, $tmp_imgdir);
+ while ($file = readdir(DIR)) {
+ move($tmp_imgdir.$file, $imgdir.$file);
+ }
+ closedir(DIR);
+ }
+}
+
+
+sub removeFiles {
+ my ($diary, $rmdir) = @_;
+
+ local (*DIR);
+ my $file;
+ if (-d $rmdir) {
+ opendir(DIR, $rmdir);
+ while ($file = readdir(DIR)) {
+ unlink ($rmdir.$file) if (-f $rmdir.$file);
+ }
+ closedir(DIR);
+ }
+
+}
+
+sub copyFiles {
+ my ($diary, $id) = @_;
+ my $tmp_imgdir = "$diary->{datadir}tmp/";
+ my $tmp_thumbdir = "$diary->{datadir}tmp/thumb/";
+ my $imgdir = "$diary->{datadir}img/$id/";
+ my $thumbdir = "$diary->{datadir}img/$id/thumb/";
+ local (*DIR);
+ my $file;
+ if (-d $thumbdir) {
+ opendir(DIR, $thumbdir);
+ while ($file = readdir(DIR)) {
+ copy ($thumbdir.$file, $tmp_thumbdir.$file);
+ }
+ closedir(DIR);
+ }
+ if (-d $imgdir) {
+ opendir(DIR, $imgdir);
+ while ($file = readdir(DIR)) {
+ copy ($imgdir.$file, $tmp_imgdir.$file);
+ }
+ closedir(DIR);
+ }
+}
+
+}