Yoshihisa Fukuhara
higef****@users*****
2006年 3月 1日 (水) 14:40:35 JST
Index: affelio/apps/diary/AF_app.cfg diff -u affelio/apps/diary/AF_app.cfg:1.4 affelio/apps/diary/AF_app.cfg:1.5 --- affelio/apps/diary/AF_app.cfg:1.4 Tue Nov 22 22:26:33 2005 +++ affelio/apps/diary/AF_app.cfg Wed Mar 1 14:40:35 2006 @@ -4,10 +4,10 @@ [application] app_URI=http://affelio.jp/NS/apps/diary app_name=diary -app_version=1.1 +app_version=2.0 app_desc=Affelioæ¥è¨ app_author=Affelio project -guest_index=list_diary.cgi +guest_index=index.cgi owner_index=owner.cgi action_types=write_diary, write_comment action_types_desc=æ¥è¨æ¸ãè¾¼ã¿, ã³ã¡ã³ãæ¸ã込㿠Index: affelio/apps/diary/CHANGES diff -u affelio/apps/diary/CHANGES:1.1 affelio/apps/diary/CHANGES:1.2 --- affelio/apps/diary/CHANGES:1.1 Tue Jul 12 06:15:07 2005 +++ affelio/apps/diary/CHANGES Wed Mar 1 14:40:35 2006 @@ -1,3 +1,7 @@ +2.0.0 (Mar 1, 2006) + Please update your database. + -> upgrade/index.cgi + 1.0.0 (July 12, 2005) Change: Diary.pm Allow to use anchor tag in diary Index: affelio/apps/diary/Diary.pm diff -u affelio/apps/diary/Diary.pm:1.34 affelio/apps/diary/Diary.pm:1.35 --- affelio/apps/diary/Diary.pm:1.34 Thu Feb 23 22:36:03 2006 +++ affelio/apps/diary/Diary.pm Wed Mar 1 14:40:35 2006 @@ -1,4 +1,4 @@ -# 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 @@ -13,41 +13,54 @@ # 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 lib '../../extlib'; -use lib '../../lib'; - -use lib '.'; -use Diary::L10N; - -use DBI; -use Jcode; -use LWP::UserAgent; -use HTTP::Request::Common qw(POST); -use AffelioApp; -use HTML::Template; -use Image::Magick; - -############################################## -# Constructor for diary -############################################## -sub new { - my ($proto, $afap) = @_; - unless ($afap) { die("Diary::new: Error: missing username\n"); } +package Diary; +{ + use strict; + use lib("../../extlib"); + use lib("../../lib"); + use Diary::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); + + ###################################################################### + #Constructor + ###################################################################### + sub new{ + my $class = shift; + my %param = @_; + + debug_print("Diary::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("Diary::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->{entry_table} = "diary_$afap->{install_name}_entries"; + $self->{pref_table} = "diary_$afap->{install_name}_pref"; + $self->{category_table} = "diary_$afap->{install_name}_categories"; $self->{comment_table} = "diary_$afap->{install_name}_comments"; $self->{tb_table} = "diary_$afap->{install_name}_tb"; - $self->{max_entries} = 365; $self->{recent_entries_no} = 10; $self->{header_title} = 'Affelio Diary'; $self->{header_show} = 0; @@ -61,28 +74,43 @@ my $DBConfig = Config::Tiny->new(); $DBConfig = Config::Tiny->read("$self->{afap}->{af}->{site__user_dir}/db.cfg"); $self->{dbtype} = $DBConfig->{db}->{type}; - + my @rets; if ($self->{dbtype} eq 'mysql') { - @rets = getall($self, "SHOW TABLES like '$self->{entry_table}'"); + @rets = getall($self, "SHOW TABLES like '$self->{entry_table}'"); } else { # SQLite - @rets = getall($self, "SELECT * FROM sqlite_master WHERE type = 'table' AND name = '$self->{entry_table}'"); + @rets = getall($self, "SELECT * FROM sqlite_master WHERE type = 'table' AND name = '$self->{entry_table}'"); } - + # entries my $pkey_modifier = $self->{dbtype} eq 'mysql' ? " AUTO_INCREMENT PRIMARY KEY " : " PRIMARY KEY "; create_table($self, $self->{entry_table}, - "CREATE TABLE $self->{entry_table} ( + "CREATE TABLE $self->{entry_table} ( id INTEGER $pkey_modifier , title TEXT, contents TEXT, year INTEGER, month INTEGER, day INTEGER, - timestamp INTEGER + timestamp INTEGER, +c_id INTEGER, +user TEXT, +uri TEXT, +pwd TEXT, +draft INTEGER )"); + # categories + my $pkey_modifier = $self->{dbtype} eq 'mysql' ? " AUTO_INCREMENT PRIMARY KEY " : " PRIMARY KEY "; + if (create_table($self, $self->{category_table}, + "CREATE TABLE $self->{category_table} ( + id INTEGER $pkey_modifier , + category TEXT + )")){ + $self->{dbh}->do("INSERT INTO $self->{category_table} (id, category) VALUES (NULL, 'none')"); + } + # comments create_table($self, $self->{comment_table}, "CREATE TABLE $self->{comment_table} ( @@ -103,211 +131,108 @@ timestamp INTEGER )"); - bless $self, $proto; + #general setting table + if (create_table($self, $self->{pref_table}, + "CREATE TABLE $self->{pref_table} ( + key TEXT, value TEXT)")){ + $self->{dbh}->do("INSERT INTO $self->{pref_table} (key, value) VALUES ('email', '$self->{afap}->{af}->{user__email1}')"); + $self->{dbh}->do("INSERT INTO $self->{pref_table} (key, value) VALUES ('max_entries', '10000')"); + $self->{dbh}->do("INSERT INTO $self->{pref_table} (key, value) VALUES ('max_comments', '256')"); + $self->{dbh}->do("INSERT INTO $self->{pref_table} (key, value) VALUES ('max_commentlen', '1000')"); + $self->{dbh}->do("INSERT INTO $self->{pref_table} (key, value) VALUES ('max_textlen', '10000')"); + $self->{dbh}->do("INSERT INTO $self->{pref_table} (key, value) VALUES ('show_author', '0')"); + $self->{dbh}->do("INSERT INTO $self->{pref_table} (key, value) VALUES ('image_size', '300')"); + } + bless $self, $class; + debug_print("Diary::new: end."); return $self; -} - + } -############################################## -# Destructor -############################################## -sub DESTROY { + ###################################################################### + #run + ###################################################################### + sub run{ my $self = shift; - $self->{dbh}->disconnect; -} - - -############################################## -# addEntry -############################################## - -sub addEntry { - my $self = shift; - my $title = $self->escape(shift); - my $contents = $self->escape(shift); - my $time = shift; - - unless ($time) { $time = time; } - - my ($sec, $min, $hour, $mday, $mon, $year) = localtime($time); - $year += 1900; $mon += 1; - - # prevent double submit - my @same = $self->getall("SELECT id FROM $self->{entry_table} WHERE title = '$title' AND contents = '$contents'"); - if($#same >= 0) { return; } - - # log rotation - if($self->getColumn("SELECT count(*) FROM $self->{entry_table}") >= $self->{max_entries}) { - my $erase = $self->getColumn("SELECT MIN(timestamp) FROM $self->{entry_table}"); - my $erase_id = $self->getColumn("SELECT id FROM $self->{entry_table} WHERE timestamp = '$erase'"); - $self->removeEntry($erase_id); - } - - $self->{dbh}->do("INSERT INTO $self->{entry_table} VALUES (NULL, '$title', '$contents', $year, $mon, $mday, $time)"); + my $afap = $self->{afap}; + my $cgi = $self->{cgi}; + my $wi = $self->{wi}; - # send trackback ping by using urls in entry - my $id = $self->getColumn("SELECT MAX(id) FROM $self->{entry_table}"); -# $self->send_trackback_ping($id, $title, $contents); -} - - -############################################## -# updateEntry -############################################## - -sub updateEntry { - my $self = shift; - my $id = $self->escape(shift, 'int'); - my $title = $self->escape(shift); - my $contents = $self->escape(shift); - $self->{dbh}->do("UPDATE $self->{entry_table} SET title = '$title', contents = '$contents' WHERE id = $id"); -} - - -############################################## -# removeEntry -############################################## - -sub removeEntry { - my $self = shift; - my $id = $self->escape(shift, 'int'); - $self->{dbh}->do("DELETE FROM $self->{entry_table} WHERE id = $id"); - $self->{dbh}->do("DELETE FROM $self->{comment_table} WHERE id = $id"); - $self->{dbh}->do("DELETE FROM $self->{tb_table} WHERE id = $id"); - if (-f $self->{datadir}."$id.stor") { - unlink $self->{datadir}."$id.stor"; - } - $self->removeUploadedImage($id); -} - - -############################################## -# getEntry -############################################## - -sub getEntry { - my $self = shift; - my $id = $self->escape(shift, 'int'); - my @ret = $self->getall("SELECT * FROM $self->{entry_table} WHERE id = $id"); - return $ret[0]; -} - -############################################## -# existsEntry -############################################## - -sub existsEntry { - my $self = shift; - my $id = $self->escape(shift, 'int'); - return $self->getColumn("SELECT COUNT(*) FROM $self->{entry_table} WHERE id = $id") > 0; -} - -############################################## -# getEntries -############################################# - -sub getEntries { - my $self = shift; - my $year = $self->escape(shift, 'int'); - my $month = $self->escape(shift, 'int'); - my $day = $self->escape(shift, 'int'); - - my $query = "SELECT * FROM $self->{entry_table} WHERE year = $year AND month = $month"; - - if ($day) { - $query .= " AND day = $day"; - } - - $query .= " ORDER BY timestamp DESC"; - - return $self->getall($query); -} - - -############################################## -# getNewestEntries -############################################## - -sub getNewestEntries { - my ($self, $num) = @_; - unless ($num) { $num = 5; } - return $self->getall("SELECT * FROM $self->{entry_table} ORDER BY timestamp DESC LIMIT $num"); -} - - -############################################## -# addComment -############################################## + my %handlers = ("top","Top", + "show_diary", "ShowDiary", + "show_image", "ShowImage", + "show_tb", "ShowTb", + "write_diary", "WriteDiary", + "write_comment", "WriteComment", + "read_rdf", "ReadRdf"); -sub addComment { - my $self = shift; - my $id = $self->escape(shift, 'int'); - my $user = shift; - my $comment = $self->escape_comment(shift); - my $time = time; - - my @same = $self->getall("SELECT id FROM $self->{comment_table} WHERE user = '$user' AND comment = '$comment'"); - if($#same >= 0) { return; } + ########################### + #Check DF_access + ########################### + unless ($afap->check_access("DF_access")) { + $self->accessErrorExit('Access Denied. You don\'t have permission to this application.'); + } + + $self->{year} = $wi->PTN_num($cgi->url_param("year")); + $self->{month} = $wi->PTN_num($cgi->url_param("month")); + $self->{day} = $wi->PTN_num($cgi->url_param("day")); + $self->{id} = $wi->PTN_num($cgi->url_param("id")); + $self->{header_title} = "Diary"; + $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("Diary::run: mode=$mode"); + + if ($mode eq "write_diary" && !$afap->check_access("write_diary")) { + $self->accessErrorExit("Access Error."); + } + if ($mode eq "top" && (-f "$self->{datadir}url")) { + $self->{header_show} = 1; + $mode="read_rdf"; + } + + my $classname = "Diary::" . $handlers{$mode}; + debug_print("Diary::run: handler= $classname"); + eval "use $classname"; + if($@){ + throw Affelio::exception::SystemException("Could not load handler [$mode]"); + } + debug_print("Diary::run: handler function loaded."); + + my $ret=""; + try{ + debug_print("Diary::run: handler function..... "); + handler($cgi, $self, \%output_data); + debug_print("Diary::run: handler function done."); + }catch Error with{ + my $e = shift; + $output_data{"err_msg"} .= $e->stacktrace; + }; + ############################################################## + #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->{afap}->get_HTML_header("Diary"); + print $self->translate_templateL10N($self->get_HTML_header); + print $self->translate_templateL10N($tmpl->output); +# print $afap->get_HTML_footer; + print $self->get_HTML_footer; - $self->{dbh}->do("INSERT INTO $self->{comment_table} VALUES ($id, '$user', '$comment', $time)"); -} - - -############################################## -# getComments -############################################## - -sub getComments { - my $self = shift; - my $id = $self->escape(shift, 'int'); - return $self->getall("SELECT * FROM $self->{comment_table} WHERE id = $id ORDER BY timestamp"); -} - -############################################## -# getVisitorInfo -############################################## - -sub getVisitorInfo { - my $self = shift; - my $id = $self->escape(shift, 'int'); - - my $uname = $self->getColumn("SELECT user FROM $self->{comment_table} WHERE id = $id"); - if ($uname) { - if ($uname =~ /([^<]*)<br \/>(.*)/) { - return ($1, $2); - } - else { - return ($uname); - } - } - return (""); -} - -############################################## -# getCommentsNo -############################################## - -sub getCommentsNo { - my $self = shift; - my $id = $self->escape(shift, 'int'); - return $self->getColumn("SELECT count(*) FROM $self->{comment_table} WHERE id = $id"); -} - -sub getColumn { - my ($self, $query) = @_; - my $sth = $self->{dbh}->prepare($query); - $sth->execute; - my $num; - $sth->bind_columns(undef, \$num); - $sth->fetch; - $sth->finish; - if($num) { - return $num; - } - else { - return 0; - } } ############################################## @@ -315,104 +240,74 @@ ############################################## sub get_HTML_header { - my $self = shift; - - return "" if ($self->{header_show} == 1) ; - - # conetnt type - my $header = - "Content-type: text/html; charset=UTF-8\n". - "Pragma: no-cache\n\n"; - - # affelio header - $header .= $self->{afap}->get_HTML_header($self->{header_title}); - - my $tmpl = HTML::Template->new(filename => "./templates/menu.tmpl"); - - # calender - my $calender; - if($self->{afap}->{cgi}->param('year') and $self->{afap}->{cgi}->param('month')) { - $calender = $self->getCalender($self->{afap}->{cgi}->param('year'), $self->{afap}->{cgi}->param('month')); - } - elsif($self->{afap}->{cgi}->param('id')) { - my $id = - my @date = $self->getall("SELECT year, month FROM $self->{entry_table} WHERE id = ".$self->{afap}->{cgi}->param('id')); - $calender = $self->getCalender($date[0]->{year}, $date[0]->{month}); - } - else { - $calender = $self->getCalender; - } - - # archives - my @archives = $self->getall("SELECT DISTINCT year, month FROM $self->{entry_table} LIMIT 10"); - if ($#archives >= 0) { - shift @archives unless $archives[0]->{year}; - $tmpl->param(ARCHIVES => \@archives); - } - - # recent entries - my @entries = $self->getall("SELECT id, title FROM $self->{entry_table} ORDER BY timestamp DESC LIMIT 10"); - if ($#entries >= 0) { - $tmpl->param(RECENT_ENTRIES => \@entries); - } - - # recent comments - my @comments = $self->getall("SELECT $self->{comment_table}.id, title, user FROM $self->{entry_table}, $self->{comment_table} WHERE $self->{entry_table}.id = $self->{comment_table}.id ORDER BY $self->{comment_table}.timestamp DESC LIMIT 10"); - if ($#comments >= 0) { - $tmpl->param(RECENT_COMMENTS => \@comments); - } - - # recent trackbacks - my @trackbacks = $self->getall("SELECT id, blog_name, title FROM $self->{tb_table} ORDER BY timestamp DESC LIMIT 10"); - if ($#trackbacks >= 0) { - $tmpl->param(RECENT_TRACKBACKS => \@trackbacks); - } - - $tmpl->param(CALENDER => $self->translate_templateL10N($calender), ); - - if ($self->{afap}->check_access('write_diary')) { - $tmpl->param(EDITABLE => 1); - unless (eval { require XML::Parser; }) { - $tmpl->param(NO_PARSER => 1); - } - } - $header .= $tmpl->output; - - $self->{header_show} = 1; - - return $header; -} - -###################################################################### -#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); + debug_print("Diary::get_HTML_headr start."); + return "" if ($self->{header_show} == 1) ; + my $header = ""; #Initiate Template - my $tmpl = new HTML::Template( filename => $TMPL_FILE, - die_on_bad_params => 0); - $tmpl->param(%output_data); + my $tmpl_menu = new HTML::Template(filename => "./templates/menu.tmpl", + die_on_bad_params => 0); + # calender + my $calender; + if($self->{year} and $self->{month}) { + $calender = $self->getCalender($self->{year}, $self->{month}); + } + elsif($self->{id}) { + my @date = $self->getall("SELECT year, month FROM $self->{entry_table} WHERE id = ".$self->{id}); + $calender = $self->getCalender($date[0]->{year}, $date[0]->{month}); + } + else { + $calender = $self->getCalender; + } - my $final_out = $self->{afap}->{af}->translate_templateL10N($tmpl->output) - . '<div class="afMain">' . "\n"; + # archives + my @archives = $self->getall("SELECT DISTINCT year, month, count(id) as count_acvs FROM $self->{entry_table} GROUP BY year, month ORDER BY year,month DESC LIMIT 10"); + if ($#archives >= 0) { + shift @archives unless $archives[0]->{year}; + $tmpl_menu->param(ARCHIVES => \@archives); + } - return($final_out); + # categories + my @categories = $self->getall("select distinct c_id, count($self->{entry_table}.id) as count_cid, category from $self->{entry_table} inner join $self->{category_table} on $self->{entry_table}.c_id = $self->{category_table}.id group by $self->{entry_table}.c_id ORDER BY c_id DESC"); + + if ($#categories >= 0) { + $tmpl_menu->param(CATEGORIES => \@categories); + } + + # recent entries + my @entries = $self->getall("SELECT id, title FROM $self->{entry_table} ORDER BY timestamp DESC LIMIT 10"); + if ($#entries >= 0) { + $tmpl_menu->param(RECENT_ENTRIES => \@entries); + } + + # recent comments + my @comments = $self->getall("SELECT $self->{comment_table}.id, title, $self->{comment_table}.user FROM $self->{entry_table}, $self->{comment_table} WHERE $self->{entry_table}.id = $self->{comment_table}.id ORDER BY $self->{comment_table}.timestamp DESC LIMIT 10"); + if ($#comments >= 0) { + $tmpl_menu->param(RECENT_COMMENTS => \@comments); + } + + # recent trackbacks + my @trackbacks = $self->getall("SELECT id, blog_name, title FROM $self->{tb_table} ORDER BY timestamp DESC LIMIT 10"); + if ($#trackbacks >= 0) { + $tmpl_menu->param(RECENT_TRACKBACKS => \@trackbacks); + } + + $tmpl_menu->param(CALENDER => $calender); + + if ($self->{afap}->check_access('write_diary')) { + $tmpl_menu->param(EDITABLE => 1); + unless (eval { require XML::Parser; }) { + $tmpl_menu->param(NO_PARSER => 1); + } + } + + $header .= $tmpl_menu->output; + + $self->{header_show} = 1; + debug_print("Diary::get_HTML_headr end."); + + return $header; } ############################################## @@ -426,77 +321,6 @@ } ############################################## -# redirection -############################################## - -sub getRedirection { - my ($self, $file) = @_; - my $webroot = $self->{afap}->get_site_info('web_root'); - return - "Content-type: text/html; charset=UTF-8\n". - "Location: $webroot/apps/$self->{afap}->{install_name}/$file"."\n\n"; -} - -############################################## -# checkAccess -############################################## - -sub checkAccess { - my ($self, $page_name) = @_; - unless ($self->{afap}->check_access($page_name)) { - $self->accessErrorExit("You have no permittion on this page"); - } -} - -############################################## -# errorExit -############################################## - -sub errorExit { - my $self = shift; - my $msg = $self->escape(shift); - - my $tmpl = new HTML::Template(filename => './templates/error.tmpl'); - $tmpl->param(MESSAGE => $msg); - - unless ($self->{header_show}) { - print "Content-type: text/html; charset=UTF-8\n\n"; - print $self->translate_templateL10N($self->{afap}->get_HTML_header($self->{header_title})); - } - print $self->translate_templateL10N($tmpl->output); - print $self->translate_templateL10N($self->{afap}->get_HTML_footer); - exit; -} - -############################################## -# accessErrorExit -############################################## - -sub accessErrorExit { - my $self = shift; - my $msg = $self->escape(shift); - my $affelio_id = $self->{afap}->get_visitor_info("afid"); - my $visitor_type=$self->{afap}->get_visitor_info("type"); - - $visitor_type="pb" if ($visitor_type eq ""); - - my $tmpl = new HTML::Template(filename => "./templates/access_error.tmpl"); - $tmpl->param( - AFID => $affelio_id, - VIS_TYPE=> $visitor_type, - MESSAGE => $msg, - ); - - unless ($self->{header_show}) { - print "Content-type: text/html; charset=UTF-8\n\n"; - print $self->translate_templateL10N($self->{afap}->get_HTML_header($self->{header_title})); - } - print $self->translate_templateL10N($tmpl->output); - print $self->translate_templateL10N($self->{afap}->get_HTML_footer); - exit; -} - -############################################## # getCalender ############################################## @@ -533,7 +357,7 @@ my @daytable = (0 .. 31); $daytable[0] = ''; foreach(@days) { - $daytable[$_->{day}] = "<a href=\"list_diary.cgi?year=$year&month=$mon&day=$_->{day}\"><b>$_->{day}</b></a>"; + $daytable[$_->{day}] = "<a href=\"index.cgi?year=$year&month=$mon&day=$_->{day}\"><b>$_->{day}</b></a>"; } my @weeks_param; @@ -556,302 +380,90 @@ return $tmpl->output; } - -############################################## -# addTrackback -############################################## - -sub addTrackback { - my $self = shift; - my $id = $self->escape(shift, 'int'); - my $title = $self->escape(shift); - my $url = $self->escape(shift); - my $excerpt = $self->escape(shift); - my $blog_name = $self->escape(shift); - my $timestamp = $self->escape(shift, 'int'); - $self->{dbh}->do("INSERT INTO $self->{tb_table} VALUES($id, '$title', '$url', '$excerpt', '$blog_name', $timestamp)"); -} - -############################################## -# getTrackbacks -############################################## - -sub getTrackbacks { - my $self = shift; - my $id = $self->escape(shift, 'int'); - my @ret = $self->getall("SELECT * FROM $self->{tb_table} WHERE id = $id"); - - foreach (@ret) { - $_->{excerpt} = Jcode::convert($_->{excerpt}, 'utf8'); - } - reset (@ret); - - return @ret; -} - -############################################## -# getTrackbacksNo -############################################## - -sub getTrackbacksNo { - my $self = shift; - my $id = $self->escape(shift, 'int'); - return $self->getColumn("SELECT COUNT(*) FROM $self->{tb_table} WHERE id = $id"); -} - -############################################## -# sendTrackbackPing -############################################## - -sub sendTrackbackPing { - my ($self, $url, $title, $contents, $id) = @_; +sub weekly_days { + my ($self, $year, $mon) = @_; + my @weeks; + my @mday = (31,31,28,31,30,31,30,31,31,30,31,30,31); + if (($year % 4 == 0) and ($year % 100) or ($year % 400 == 0)) { $mday[2] = 29 }; - $id = $self->getColumn("SELECT MAX(id) FROM $self->{entry_table}") unless ($id); + my $lastday = $mday[$mon]; + @mday = (1 .. $mday[$mon]); + if($mon < 3){ $mon += 12; $year--; } + my $first_day = ($year+int($year/4)-int($year/100)+int($year/400)+int((13*$mon+8)/5)+1)% 7; - my %form = ( - title => $title, - excerpt => "",#Jcode::convert($contents, 'utf8', 'auto'), - url => $self->{afap}->get_site_info('web_root')."/apps/$self->{afap}->{install_name}/show_diary.cgi?id=$id", - blog_name => $self->{afap}->get_owner_info('nickname')."'s Affelio Diary", - ); - 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>/) { - $self->errorExit('Failed to send trackback ping'); + my $day = 1; + for my $week (0 .. 7) { + my @days; + for(my $i = 0; $i < 7; $i++) { + push @days, + (($week == 0 and $i < $first_day) or ($day > $lastday)) ? + '' : $day++; + } + $weeks[$week] = \@days; } + + return @weeks; } ############################################## -# setRDFURL -############################################## - -sub setRDFURL { - my ($self, $url) = @_; - local (*OUT); - - open(OUT, "> $self->{datadir}url"); - print OUT $url; - close(OUT); -} - -############################################## -# getRDFURL +# getCommentsNo ############################################## -sub getRDFURL { +sub getCommentsNo { my $self = shift; - if (-f "$self->{datadir}url") { - local (*IN); - open (IN, "$self->{datadir}url"); - my $rssfile = <IN>; - $rssfile =~ s/[\r\n]//g; - close(IN); - return $rssfile; - } - return undef; + my $id = $self->escape(shift, 'int'); + return $self->getColumn("SELECT count(*) FROM $self->{comment_table} WHERE id = $id"); } ############################################## -# unsetRDF +# existsEntry ############################################## -sub unsetRDFURL { +sub existsEntry { my $self = shift; - unlink("$self->{datadir}url") if (-f "$self->{datadir}url"); + my $id = $self->escape(shift, 'int'); + return $self->getColumn("SELECT COUNT(*) FROM $self->{entry_table} WHERE id = $id") > 0; } ############################################## -# getRSS +# Internal functions ############################################## - -sub getRSS { - my ($self, $count) = @_; - unless ($count) { $count = 5; } - - my $tmpl = new HTML::Template(filename => './templates/rss.tmpl'); - - my @entries = $self->getNewestEntries($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 = "$web_root/apps/$self->{afap}->{install_name}/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."apps/$self->{afap}->{install_name}/tb.cgi/$_->{id}", - }; - } +sub getall { + my ($self, $query) = @_; - $tmpl->param( - LINK => $web_root, - NICKNAME => $uname, - ITEM_LIST => \@item_list, - ITEMS => \@items, - ); - - return $tmpl->output; -} - -############################################## -# getURLDescription -############################################## - -sub getURLDescription { - my $self = shift; - my $id = $self->escape(shift, 'int'); + my $sth = $self->{dbh}->prepare($query); + $sth->execute; - 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; + my @ret; + while(my $row = $sth->fetchrow_hashref) { + push @ret, $row; + } + $sth->finish; - $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; -} - -############################################## -# saveUploadedImage -############################################## - -sub saveUploadedImage { - use File::Basename; - my ($self, $filehandle, $id) = @_; - my $afap = $self->{afap}; - my $file; - my $buf; - my $filesize = 0; - my $bytesread; - $id = $self->getColumn("SELECT MAX(id) FROM $self->{entry_table}") unless ($id); - - if ($filehandle){ - fileparse_set_fstype("MSDOS"); #For IE user - my $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) { - $self->errorExit('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 $basedir = $imgdir."$id/"; - unless (-d $basedir) { - mkdir $basedir; - } - 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 $self->errorExit('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{ - $self->errorExit('You can only use ascii character in your file name'); - } - } - else{ - $self->errorExit('Please select a file.'); - } + return @ret; } -############################################## -# removeUploadedImage -############################################## - -sub removeUploadedImage { - my ($self, $id) = @_; - - $id = $self->getColumn("SELECT MAX(id) FROM $self->{entry_table}") unless ($id); - - my $imgdir = "$self->{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; +sub getColumn { + my ($self, $query) = @_; + my $sth = $self->{dbh}->prepare($query); + $sth->execute; + my $num; + $sth->bind_columns(undef, \$num); + $sth->fetch; + $sth->finish; + if($num) { + return $num; } -} - -############################################## -# getUploadedImages -############################################## - -sub getUploadedImages { - my ($self, $id, $width, $height) = @_; - - $width = "&w=$width" if ($width); - $height = "&h=$height" if ($height); - - my $imgdir = "$self->{datadir}img/$id/"; - my $thumbdir = "$self->{datadir}img/$id/thumb/"; - my $ret; - my $size; - - local (*DIR); - opendir(DIR, $imgdir); - while (my $file = readdir(DIR)) { - if (-f $imgdir.$file) { - if (-f $thumbdir.$file){ - $size="s"; - }else{ - $size="l"; - } - $ret .= "<a href=\"show_image.cgi?id=$id&filename=$file&size=l\" target=\"_blank\">". - "<img src=\"show_image.cgi?id=$id&filename=$file$width$height&size=$size\" border=\"0\" />". - "</a><br />"; - } + else { + return 0; } - closedir(DIR); - - return $ret ? "<p>$ret</p>" : ""; } -############################################## -# Internal functions -############################################## - sub create_table { my ($self, $table_name, $sql) = @_; my @rets; + my $ret=0; if ($self->{dbtype} eq 'mysql') { @rets = getall($self, "SHOW TABLES like '$table_name'"); } @@ -861,28 +473,9 @@ if ($#rets < 0) { $self->{dbh}->do($sql); + $ret=1; } -} - -sub send_trackback_ping { - my ($self, $id, $title, $contents) = @_; - my @urls = $contents =~ /(s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/g; - - foreach(@urls) { - my $url = $self->discover_tb($_); - if($url) { - my %form = ( - title => $title, - excerpt => $contents, - url => "$self->{afap}->{af}->{site__web_root}/apps/$self->{afap}->{install_name}/show_diary.cgi?id=$id", - blog_name => "$self->{afap}->{af}->{user__nickname}'s affelio diary", - ); - my $req = POST($url, [%form]); - my $ua = new LWP::UserAgent; - my $res = $ua->request($req); - my $str = $res->as_string; - } - } + return $ret; } sub escape { @@ -894,13 +487,19 @@ else { $str =~ s/[\t\a]//g; $str =~ s/&/&/g; - $str =~ s/["']/"/g; + $str =~ s/"/"/g; + $str =~ s/'/'/g; $str =~ s/</</g; $str =~ s/>/>/g; - $str =~ s/<(\/?)(a|p|i|b|big|strong|small|em|u|blockquote)>/<$1$2>/ig; + $str =~ s/<(\/?)(a|p|i|b|big|strong|small|em|u|blockquote|br)>/<$1$2>/ig; + $str =~ s/<image="([A-Za-z0-9\-\_]*\.(jpg)|(png)|(gif)|(bmp)|(jpeg))">/<image="$1">/ig; + $str =~ s/<a +href=(")?(s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+) *(")? *>/<a href="$2">/ig; $str =~ s/""/"/g; - $str =~ s/(\r\n|\r|\n)/<br \/>/g; +# $str =~ s/(\r\n|\r|\n)/<br \/>/g; + $str =~ s/\x0D\x0A/<BR>/g; + $str =~ s/\x0D/<BR>/g; + $str =~ s/\x0A/<BR>/g; while ($str =~ /(<(a|p|i|b|big|strong|small|em|u|blockquote)\b(?:(?!<\/\2>).)*(?:<\2>|$))/sigx) { $self->errorExit("Error: You may mistype a tag or forget to close it."); @@ -910,92 +509,60 @@ return $str; } -sub escape_comment { - my ($self, $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; +sub br2n { + my ($self, $str) = @_; + $str =~ s/<BR>/\x0D\x0A/ig; + return $str; } +############################################## +# errorExit +############################################## -sub autolink { - my ($self, $str) = @_; +sub errorExit { + my $self = shift; + my $msg = $self->escape(shift); - $str =~ s/(https?|ftp)\:([\w|\:\!\#\$\%\=\&\-\^\`\\\|\@\~\[\{\]\}\;\+\*\,\.\?\/]+)/<a href=\"$1\:$2\" target=\"_blank\">$1\:$2<\/a>/ig; - - return $str; -} - -sub getall { - my ($self, $query) = @_; - - my $sth = $self->{dbh}->prepare($query); - $sth->execute; + my $tmpl = new HTML::Template(filename => './templates/error.tmpl'); + $tmpl->param(MESSAGE => $msg); - my @ret; - while(my $row = $sth->fetchrow_hashref) { - push @ret, $row; + unless ($self->{header_show}) { + print "Content-type: text/html; charset=UTF-8\n\n"; + print $self->translate_templateL10N($self->{afap}->get_HTML_header($self->{header_title})); } - $sth->finish; - - return @ret; + print $self->translate_templateL10N($tmpl->output); + print $self->translate_templateL10N($self->{afap}->get_HTML_footer); + exit; } -sub weekly_days { - my ($self, $year, $mon) = @_; - my @weeks; - my @mday = (31,31,28,31,30,31,30,31,31,30,31,30,31); - if (($year % 4 == 0) and ($year % 100) or ($year % 400 == 0)) { $mday[2] = 29 }; - - my $lastday = $mday[$mon]; - @mday = (1 .. $mday[$mon]); - if($mon < 3){ $mon += 12; $year--; } - my $first_day = ($year+int($year/4)-int($year/100)+int($year/400)+int((13*$mon+8)/5)+1)% 7; +############################################## +# accessErrorExit +############################################## - my $day = 1; - for my $week (0 .. 7) { - my @days; - for(my $i = 0; $i < 7; $i++) { - push @days, - (($week == 0 and $i < $first_day) or ($day > $lastday)) ? - '' : $day++; - } - $weeks[$week] = \@days; - } - - return @weeks; -} +sub accessErrorExit { + my $self = shift; + my $msg = $self->escape(shift); + my $affelio_id = $self->{afap}->get_visitor_info("afid"); + my $visitor_type=$self->{afap}->get_visitor_info("type"); + + $visitor_type="pb" if ($visitor_type eq ""); + + my $tmpl = new HTML::Template(filename => $self->{afap}->{app__fs_root}."/templates/access_error.tmpl"); + $tmpl->param( + AFID => $affelio_id, + VIS_TYPE=> $visitor_type, + MESSAGE => $msg, + ); -# Refer to: http://lowlife.jp/yasusii/stories/8.html -sub discover_tb { - my ($self, $url) = @_; - my $ua = LWP::UserAgent->new; - $ua->agent('TrackBack/1.0'); - $ua->parse_head(0); - $ua->timeout(15); - my $req = HTTP::Request->new(GET => $url); - my $res = $ua->request($req); - return unless $res->is_success; - my $c = $res->content; - (my $url_no_anchor = $url) =~ s/#.*$//; - my $item; - while ($c =~ m!(<rdf:RDF.*?</rdf:RDF>)!sg) { - my $rdf = $1; - my($perm_url) = $rdf =~ m!dc:identifier="([^"]+)"!; - next unless $perm_url eq $url || $perm_url eq $url_no_anchor; - if ($rdf =~ m!trackback:ping="([^"]+)"!) { - return $1; - } elsif ($rdf =~ m!about="([^"]+)"!) { - return $1; - } - } + unless ($self->{header_show}) { + print "Content-type: text/html; charset=UTF-8\n\n"; + print $self->translate_templateL10N($self->{afap}->get_HTML_header($self->{header_title})); + } + print $self->translate_templateL10N($tmpl->output); + print $self->translate_templateL10N($self->{afap}->get_HTML_footer); + exit; } + ############################################################################ #L10N added by slash ############################################################################ @@ -1029,7 +596,49 @@ } return($mesg); } -############################################################################ +############################################## +# checkAccess +############################################## + +sub checkAccess { + my ($self, $page_name) = @_; + unless ($self->{afap}->check_access($page_name)) { + $self->accessErrorExit("You have no permittion on this page"); + } +} +############################################## +# getRDFURL +############################################## + +sub getRDFURL { + my $self = shift; + if (-f "$self->{datadir}url") { + local (*IN); + open (IN, "$self->{datadir}url"); + my $rssfile = <IN>; + $rssfile =~ s/[\r\n]//g; + close(IN); + return $rssfile; + } + return undef; +} + +############################################## +# addTrackback +############################################## + +sub addTrackback { + my $self = shift; + my $id = $self->escape(shift, 'int'); + my $title = $self->escape(shift); + my $url = $self->escape(shift); + my $excerpt = $self->escape(shift); + my $blog_name = $self->escape(shift); + my $timestamp = $self->escape(shift, 'int'); + $self->{dbh}->do("INSERT INTO $self->{tb_table} VALUES($id, '$title', '$url', '$excerpt', '$blog_name', $timestamp)"); +} + +} 1; Index: affelio/apps/diary/admin.cgi diff -u /dev/null affelio/apps/diary/admin.cgi:1.1 --- /dev/null Wed Mar 1 14:40:35 2006 +++ affelio/apps/diary/admin.cgi Wed Mar 1 14:40:35 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 Diary; +use Diary::Admin; + +try{ + my $admin = new Diary(); + $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/diary/get_rss.cgi diff -u affelio/apps/diary/get_rss.cgi:1.3 affelio/apps/diary/get_rss.cgi:1.4 --- affelio/apps/diary/get_rss.cgi:1.3 Fri Jul 1 11:06:39 2005 +++ affelio/apps/diary/get_rss.cgi Wed Mar 1 14:40:35 2006 @@ -1,5 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2005 FishGrove Inc. + +# Copyright (C) 2005 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,9 +16,19 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -require 'init.pl'; +use strict; +use lib("../../extlib"); +use Error qw(:try); +use Diary; +use Diary::GetRss; -print "Content-type: application/xml; charset=UTF-8\n"; -print "Pragma: no-cache", "\n\n"; +try{ + my $rss = new Diary(); + $rss->run_getrss(); +}catch Error with{ + my $e = shift; + print "Content-type: text/html; charset=UTF-8\n"; + print "Pragma: no-cache", "\n\n"; + print $e->stacktrace; +}; -print $diary->getRSS; Index: affelio/apps/diary/index.cgi diff -u /dev/null affelio/apps/diary/index.cgi:1.1 --- /dev/null Wed Mar 1 14:40:35 2006 +++ affelio/apps/diary/index.cgi Wed Mar 1 14:40:35 2006 @@ -0,0 +1,34 @@ +#!/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 Diary; + +try{ + my $diary = new Diary(); + $diary->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/diary/list_diary.cgi diff -u affelio/apps/diary/list_diary.cgi:1.9 affelio/apps/diary/list_diary.cgi:1.10 --- affelio/apps/diary/list_diary.cgi:1.9 Wed Jul 6 07:06:14 2005 +++ affelio/apps/diary/list_diary.cgi Wed Mar 1 14:40:35 2006 @@ -15,64 +15,5 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -require('init.pl'); - -if (-f "$diary->{datadir}url") { - print $diary->getRedirection('external_blog.cgi'); - exit; -} - -print $diary->translate_templateL10N($diary->get_HTML_header); - -my $user = $afap->{cgi}->param("user"); -my $edit = 0; - -if($afap->check_access("write_diary")) { - $user = $afap->get_owner_info("nickname"); - $edit = 1; -} - -my $tmpl = HTML::Template->new(filename => "./templates/list_diary.tmpl"); -#$tmpl->param(NICKNAME => $afap->get_owner_info("nickname")); - -my @entries_param; -my $year = $afap->{cgi}->param("year"); -my $month = $afap->{cgi}->param("month"); -my $day = $afap->{cgi}->param("day"); -my @entries; - -if($year and $month){ - @entries = $diary->getEntries($year, $month, $day); - if($day and $#entries == 0) { - my ($tid) = @entries; - print $diary->getURLDescription($tid->{id}); - } -} -else { - @entries = $diary->getNewestEntries; -} - -my $i = 0; -foreach(@entries) { - my ($sec, $min, $hour) = localtime($_->{timestamp}); - push @entries_param, - { - MONTH => $_->{month}, - DAY => $_->{day}, - #TIME => sprintf("%02d:%02d", $hour, $min), - TITLE => $_->{title}, - CONTENTS=> $_->{contents}, - COMMENT_NO => $diary->getCommentsNo($_->{id}), - TRACKBACKS => $diary->getTrackbacksNo($_->{id}), - ID => $_->{id}, - IMAGES => $diary->getUploadedImages($_->{id}, 300, 300), - EDITABLE=> $edit - }; -} -$tmpl->param(ENTRIES => \@entries_param, EDITABLE => $edit); - -$tmpl->param(install_title => $afap->get_app_info("install_title")); - -print $diary->translate_templateL10N($tmpl->output); - -print $diary->get_HTML_footer; +print "Content-type: text/html; charset=UTF-8\n". + "Location: index.cgi"."\n\n"; Index: affelio/apps/diary/owner.cgi diff -u affelio/apps/diary/owner.cgi:1.7 affelio/apps/diary/owner.cgi:1.8 --- affelio/apps/diary/owner.cgi:1.7 Wed Jan 25 11:30:51 2006 +++ affelio/apps/diary/owner.cgi Wed Mar 1 14:40:35 2006 @@ -14,51 +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. -our $mymode="owner"; -require 'init.pl'; - -$diary->checkAccess("write_diary"); - -if ($afap->{cgi}->param('save_state')) { - my $type = $afap->{cgi}->param('type'); - if ($type eq 'import') { - if ($afap->{cgi}->param('url')) { - $diary->setRDFURL($afap->{cgi}->param('url')); - print $diary->getRedirection('external_blog.cgi'); exit; - } - } - else { # normal diary - $diary->unsetRDFURL; - print $diary->getRedirection('list_diary.cgi'); exit; - } -} - -my $tmpl = new HTML::Template(filename => './templates/owner.tmpl'); -my $url = $diary->getRDFURL; -if ($url) { - $tmpl->param( - URL => $url, - SELECT_IMPORT => 'checked' - ); -} -else { - $tmpl->param(SELECT_DIARY => 'checked'); -} - -eval { require XML::Parser; } or $tmpl->param(NO_PARSER => 1); - -$tmpl->param(access_control_URL => $afap->get_URL("access_control")); - -if ($afap->{cgi}->param('mode') eq "rdf_set") { - $tmpl->param(RDF_SET => '1'); -} - -# put Content-type -print "Content-type: text/html; charset=UTF-8\n"; -print "Pragma: no-cache", "\n\n"; -# put HTML Header -#print Affelio::App::Admin::get_HTML_header($afap); -print $diary->get_HTML_header_owner; -print $diary->translate_templateL10N($tmpl->output); -print $diary->get_HTML_footer; +print "Content-type: text/html; charset=UTF-8\n". + "Location: admin.cgi"."\n\n"; Index: affelio/apps/diary/show_image.cgi diff -u affelio/apps/diary/show_image.cgi:1.8 affelio/apps/diary/show_image.cgi:1.9 --- affelio/apps/diary/show_image.cgi:1.8 Thu Feb 23 22:36:03 2006 +++ affelio/apps/diary/show_image.cgi Wed Mar 1 14:40:35 2006 @@ -1,5 +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,53 +16,19 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -require 'init.pl'; +use strict; use lib("../../extlib"); use Error qw(:try); +use Diary; +use Diary::ShowImage; -my $id = $afap->{cgi}->param('id') or die; -my $filename = $afap->{cgi}->param('filename') or die; - -my $type = $filename; -$type =~ s/[^.]+\.(.*)/$1/i; -$type =~ s/jpg/jpeg/i; -my $filepath = "$diary->{datadir}img/$id/".$filename; -my $thumbpath = "$diary->{datadir}img/$id/thumb/".$filename; - -my $width = $afap->{cgi}->param('w'); -my $height = $afap->{cgi}->param('h'); -my $size = $afap->{cgi}->param('size'); - -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); -} +try{ + my $show = new Diary(); + $show->run_showimage(); +}catch Error with{ + my $e = shift; + print "Content-type: text/html; charset=UTF-8\n"; + print "Pragma: no-cache", "\n\n"; + print $e->stacktrace; +}; -sub output_img { - my $file = shift; - local (*IMG); - open(IMG, "$file") or die; - binmode IMG; - print while (<IMG>); - close(IMG); -} Index: affelio/apps/diary/tb.cgi diff -u affelio/apps/diary/tb.cgi:1.2 affelio/apps/diary/tb.cgi:1.3 --- affelio/apps/diary/tb.cgi:1.2 Sat Jul 2 07:47:21 2005 +++ affelio/apps/diary/tb.cgi Wed Mar 1 14:40:35 2006 @@ -1,4 +1,5 @@ #!/usr/bin/perl -w + # Copyright 2002 Benjamin Trott. # This code is released under the Artistic License. use strict; @@ -15,13 +16,14 @@ # use Diary; +my $diary = new Diary(); my $cgi = new CGI(); +unless ($diary->{afap}->check_access("DF_access")) { + exit; +} -my $afap = new AffelioApp(ConfigDir => Cwd::getcwd(), - cgi => $cgi); -my $diary = new Diary($afap); -my $datadir = $afap->get_userdata_dir; +my $datadir = $diary->{afap}->get_userdata_dir; #------------- my $DataDir = $datadir; @@ -45,9 +47,9 @@ $i->{title} ||= $i->{url}; $i->{timestamp} = time; #------------- - $i->{title} = Jcode::convert($i->{title}, 'euc'); - $i->{excerpt} = Jcode::convert($i->{excerpt}, 'euc'); - $i->{blog_name} = Jcode::convert($i->{blog_name}, 'euc'); +# $i->{title} = Jcode::convert($i->{title}, 'utf8'); +# $i->{excerpt} = Jcode::convert($i->{excerpt}, 'utf8'); +# $i->{blog_name} = Jcode::convert($i->{blog_name}, 'utf8'); #------------- respond_exit("No URL (url)") unless $i->{url}; my $data = load_data($tb_id); Index: affelio/apps/diary/upload.cgi diff -u /dev/null affelio/apps/diary/upload.cgi:1.1 --- /dev/null Wed Mar 1 14:40:35 2006 +++ affelio/apps/diary/upload.cgi Wed Mar 1 14:40:35 2006 @@ -0,0 +1,34 @@ +#!/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 Diary; +use Diary::UploadImage; + +try{ + my $uploader = new Diary(); + $uploader->run_upload(); +}catch Error with{ + my $e = shift; + print "Content-type: text/html; charset=UTF-8\n"; + print "Pragma: no-cache", "\n\n"; + print $e->stacktrace; +}; +