*** blosxom-xmlrpc.cgi.orig 2007-02-10 23:55:40.000000000 +0900 --- blosxom-xmlrpc.cgi 2007-02-11 00:07:03.000000000 +0900 *************** *** 99,109 **** --- 99,115 ---- use strict; use File::Find; use File::stat; + use File::Copy; use POSIX qw(strftime); use XMLRPC::Transport::HTTP; + use HTML::Entities; use CGI::Carp qw(fatalsToBrowser); use CGI; + if ( -e "config.cgi" ) { + package blosxom; + require 'config.cgi'; + } # Remove trailing / from url and datadir $datadir =~ s!/$!!; $url =~ s!/$!!; *************** *** 112,118 **** $webfavdir =~ s!/$!!; $webfavurl =~ s!/$!!; - sub auth { debug( 4, "BXR.auth", @_ ); my $user = shift @_; --- 118,123 ---- *************** *** 140,145 **** --- 145,156 ---- sub getPostIdFromFilename { debug( 4, "BXR.getPostIdFromFilename", @_ ); my $filename = shift @_; + if ((! -e $filename) and (-e $filename.".post")) { + open(FILE, "<$filename.post"); + $filename = "$datadir"; + $filename .= ; + close(FILE); + } $filename =~ s!$datadir!!; return $filename; } *************** *** 155,160 **** --- 166,177 ---- $postid = "$datadir/$postid"; } } + if ((! -e $postid) and (-e $postid.".post")) { + open(FILE, "<$postid.post"); + $postid = "$datadir"; + $postid .= ; + close(FILE); + } debug( 4, "BXR.getFilenameFromPostId exit", $postid ); return $postid; } *************** *** 174,180 **** sub getIsoTime { debug( 4, "BXR.getIsoTime", @_ ); my $time = shift @_ || time; ! my $isoTime = strftime( "%Y-%m-%dT%TZ", gmtime($time) ); debug( 4, "BXR.getIsoTime", $isoTime ); return $isoTime; } --- 191,198 ---- sub getIsoTime { debug( 4, "BXR.getIsoTime", @_ ); my $time = shift @_ || time; ! #my $isoTime = strftime( "%Y-%m-%dT%TZ", gmtime($time) ); ! my $isoTime = strftime( "%Y-%m-%dT%H:%M:%S", gmtime($time) ); debug( 4, "BXR.getIsoTime", $isoTime ); return $isoTime; } *************** *** 191,196 **** --- 209,233 ---- return $time; } + sub getCategoryNameFromId { + my $catid = shift; + my $alias = ''; + my @path = split(/\//, $catid); + my %aliases = %blosxom::categories_aliases; + my $sep = $blosxom::categories_sep; + + foreach (@path) { + next if !$_; + $_ = $aliases{$_} if $aliases{$_}; + $alias .= qq!$sep$_!; + } + + $alias =~ s!^$sep!!; + $alias = "n/a" if (!$alias); + return $alias; + } + + # Debug Levels: # 1 = API Module Calls # 2 = Blosxom Module Calls *************** *** 200,206 **** my $messDebugLevel = shift @_; if ( $messDebugLevel <= $debugLevel ) { my $method = shift @_; ! open FILE, ">>$datadir/bxrlog.txt" or print STDERR "Can't open error log\n"; print FILE "$method:"; foreach (@_) { --- 237,243 ---- my $messDebugLevel = shift @_; if ( $messDebugLevel <= $debugLevel ) { my $method = shift @_; ! open FILE, ">>$datadir/bxrlog.log" or print STDERR "Can't open error log\n"; print FILE "$method:"; foreach (@_) { *************** *** 213,220 **** my $path_info = $ENV{'PATH_INFO'} || ''; ! if ( $path_info =~ /rpc2/i ) { ! XMLRPC::Transport::HTTP::CGI->dispatch_to( 'metaWeblog', 'blogger' ) ->handle; } elsif ( $path_info =~ /atom/i ) { # Do ATOM stuff here --- 250,265 ---- my $path_info = $ENV{'PATH_INFO'} || ''; ! BXR::debug( 2, "request", $path_info ); ! if ( $path_info =~ /RPC2/i ) { ! my $request_method = $ENV{'REQUEST_METHOD'} || ''; ! unless( $request_method =~ 'POST' ) { ! $path_info =~ s!.*RPC2/!!; ! $path_info = $url."/".$path_info; ! print "Location: $path_info\r\n\r\n"; ! exit; ! } ! XMLRPC::Transport::HTTP::CGI->dispatch_to( 'metaWeblog', 'blogger', 'mt' ) ->handle; } elsif ( $path_info =~ /atom/i ) { # Do ATOM stuff here *************** *** 331,339 **** sub SetHtmlBegin { # set var with following html/css code (note: \n and extra white space will be included, don't use tabs!). # needs $PageTile, $Meta (optional) on entry, Printed as html header, mainly a color malleable style sheet. ! $_[0] = qq( ! $PageTitle $Meta --- 376,384 ---- sub SetHtmlBegin { # set var with following html/css code (note: \n and extra white space will be included, don't use tabs!). # needs $PageTile, $Meta (optional) on entry, Printed as html header, mainly a color malleable style sheet. ! $_[0] = qq( ! $PageTitle $Meta *************** *** 407,413 **** sub Error { # report fatal errors from Render (or other) and exit. ! print qq(Content-Type: text/html; charset=ISO-8859-1) if (shift); #print cgi header $PageTitle = 'Fatal Error'; $BlogText = qq($_[0] $_[1]); --- 452,458 ---- sub Error { # report fatal errors from Render (or other) and exit. ! print qq(Content-Type: text/html; charset=utf-8) if (shift); #print cgi header $PageTitle = 'Fatal Error'; $BlogText = qq($_[0] $_[1]); *************** *** 506,512 **** ? $cookie{'password'} = $c->param('password') : 0; unless ( BXR::auth( $cookie{'username'}, $cookie{'password'} ) ) { ! print $c->header(); $PageTitle = "Please Enter Password"; unless ( RenderExternalFlavour($BXR::weblogin) ) { SetHtmlVars(); --- 551,557 ---- ? $cookie{'password'} = $c->param('password') : 0; unless ( BXR::auth( $cookie{'username'}, $cookie{'password'} ) ) { ! print $c->header(-charset=>'utf-8'); $PageTitle = "Please Enter Password"; unless ( RenderExternalFlavour($BXR::weblogin) ) { SetHtmlVars(); *************** *** 528,534 **** -value => \%cookie, -expires => $expire ); ! print $c->header( -cookie => $cookie ); return 1; } } --- 573,579 ---- -value => \%cookie, -expires => $expire ); ! print $c->header( -cookie => $cookie, -charset => 'utf-8' ); return 1; } } *************** *** 1121,1126 **** --- 1166,1172 ---- defined($cats{$start}) ? delete($cats{$start}) : 0; $cats{"/"}++; + %cats = sort keys %cats; BXR::debug( 4, "blosxom::getCategories Category", keys(%cats) ); return ( \%cats ); } *************** *** 1160,1166 **** my %struct; $struct{'postid'} = $filename; $struct{'dateCreated'} = File::stat::stat($filename)->mtime; ! $struct{'title'} = shift @post; foreach (@post) { $struct{'description'} .= $_; } --- 1206,1214 ---- my %struct; $struct{'postid'} = $filename; $struct{'dateCreated'} = File::stat::stat($filename)->mtime; ! my $title = shift @post; ! $title =~ s!\x0D|\x0A!!g; ! $struct{'title'} = $title; foreach (@post) { $struct{'description'} .= $_; } *************** *** 1205,1212 **** unless ( -e $filename ) { open POST, ">$filename" or die "Can't Open File $filename: $!"; ! print POST "$struct->{'title'}\n"; ! print POST "$struct->{'description'}\n"; close POST; my $files = chmod $BXR::file_permission, $filename; } --- 1253,1262 ---- unless ( -e $filename ) { open POST, ">$filename" or die "Can't Open File $filename: $!"; ! #print POST HTML::Entities::decode_entities($struct->{'title'})."\n"; ! #print POST HTML::Entities::decode_entities($struct->{'description'})."\n"; ! print POST $struct->{'title'}."\n"; ! print POST $struct->{'description'}."\n"; close POST; my $files = chmod $BXR::file_permission, $filename; } *************** *** 1290,1295 **** --- 1340,1346 ---- $filename = "$start/$filename"; open FILE, ">$filename"; + binmode FILE; print FILE "$struct->{'bits'}"; close FILE; *************** *** 1319,1328 **** --- 1370,1387 ---- } else { my $date = BXR::getIsoTime( $post->{'dateCreated'} ); + $post->{'title'} = SOAP::Data->type(string => $post->{'title'}); + $post->{'description'} = SOAP::Data->type(string => $post->{'description'}); $post->{'dateCreated'} = SOAP::Data->type( dateTime => "$date" ); $post->{'postid'} = BXR::getPostIdFromFilename( $post->{'postid'} ); ( $post->{'link'} = $BXR::url . $post->{'postid'} ) =~ s/$BXR::file_extension/html/; + my @cats; + my $catList = $post->{'categories'}; + foreach ( @$catList ) { + push @cats, SOAP::Data->type(string => BXR::getCategoryNameFromId($_)); + } + $post->{'categories'} = \@cats; $post->{'permaLink'} = $post->{'link'}; return $post; } *************** *** 1349,1354 **** --- 1408,1414 ---- return \@retList; } + sub getCategoryList { return getCategories(@_) } sub getCategories { BXR::debug( 1, "metaWeblog.getCategories", @_ ); shift if UNIVERSAL::isa( $_[0] => __PACKAGE__ ); *************** *** 1361,1370 **** my $cats = blosxom::getCategories(); my %retList; foreach ( keys %{$cats} ) { - $_ = BXR::getCategoryFromFilename($_); $retList{'struct'}{$_}{'description'} = "No Description"; - $retList{'struct'}{$_}{'rssUrl'} = "$BXR::url/$_/index.rss"; $retList{'struct'}{$_}{'htmlUrl'} = "$BXR::url/$_"; } return %retList; } --- 1421,1432 ---- my $cats = blosxom::getCategories(); my %retList; foreach ( keys %{$cats} ) { $retList{'struct'}{$_}{'description'} = "No Description"; $retList{'struct'}{$_}{'htmlUrl'} = "$BXR::url/$_"; + $retList{'struct'}{$_}{'rssUrl'} = "$BXR::url/$_/index.rss"; + #$retList{'struct'}{$_}{'title'} = BXR::getCategoryFromFilename($_); + $retList{'struct'}{$_}{'title'} = $_; + $retList{'struct'}{$_}{'categoryid'} = $_; } return %retList; } *************** *** 1400,1409 **** my $rc = BXR::getPostIdFromFilename( blosxom::editPost($struct) ); if ( $rc == 1 ) { ! return "true"; } else { ! return "false"; } } --- 1462,1471 ---- my $rc = BXR::getPostIdFromFilename( blosxom::editPost($struct) ); if ( $rc == 1 ) { ! return SOAP::Data->type(boolean => "true"); } else { ! return SOAP::Data->type(boolean => "false"); } } *************** *** 1456,1462 **** BXR::auth( $username, $password ); my %struct = ( ! userid => 1, firstname => $BXR::firstName, lastname => $BXR::lastName, nickname => $BXR::nickname, --- 1518,1524 ---- BXR::auth( $username, $password ); my %struct = ( ! userid => $BXR::username, firstname => $BXR::firstName, lastname => $BXR::lastName, nickname => $BXR::nickname, *************** *** 1572,1577 **** --- 1634,1724 ---- my $rc = blosxom::deletePost($filename); } + package mt; + sub getPostCategories { + BXR::debug( 1, "mt.getPostCategories", @_ ); + shift if UNIVERSAL::isa( $_[0] => __PACKAGE__ ); + my $postid = shift; + my $username = shift; + my $password = shift; + my $category = BXR::getCategoryFromFilename($postid); + my @return; + push @return, { + categoryName => $category, + categoryId => $category, + isPrimary => SOAP::Data->type(boolean => "true") + }; + return \@return; + } + sub setPostCategories { + BXR::debug( 1, "mt.setPostCategories", @_ ); + shift if UNIVERSAL::isa( $_[0] => __PACKAGE__ ); + my $postid = shift; + my $username = shift; + my $password = shift; + my $category = shift @_; + my $filename = BXR::getFilenameFromPostId($postid); + BXR::debug( 1, "sizeof category", $#$category); + if ($#$category >= 0) { + my $fname = $filename; + $fname =~ s!.*/([^/]*)!$1!; + my $movepath = BXR::getFilenameFromPostId(@$category[0]->{categoryId}."/".$fname); + File::Copy::move $filename, $movepath; + open(FILE, ">$filename.post"); + print FILE @$category[0]->{categoryId}."/".$fname; + close(FILE); + } + return SOAP::Data->type(boolean => "true"); + } + sub publishPost { + BXR::debug( 1, "mt.publishPost", @_ ); + shift if UNIVERSAL::isa( $_[0] => __PACKAGE__ ); + my $postid = shift; + my $username = shift; + my $password = shift; + my $filename = BXR::getFilenameFromPostId($postid); + if ( $filename !~ /$BXR::file_extension$/ ) { + $_ = $filename; + my ($fname, $ext) = /(.*)\.([^\.]+)/; + my $movepath = $fname.".".$BXR::file_extension; + File::Copy::move $filename, $movepath; + } + return SOAP::Data->type(boolean => "true"); + } + + sub getCategoryList { + BXR::debug( 1, "mt.getCategoryList", @_ ); + shift if UNIVERSAL::isa( $_[0] => __PACKAGE__ ); + my $blogid = shift; + my $username = shift; + my $password = shift; + + BXR::auth( $username, $password ); + + my $cats = blosxom::getCategories(); + my @return; + foreach ( keys %{$cats} ) { + my $cid = BXR::getCategoryFromFilename($_); + my $cnm = BXR::getCategoryNameFromId($cid); + push @return, { + categoryName => SOAP::Data->type(string => $cnm), + categoryId => $cid + }; + } + @return = sort {$a->{categoryId} cmp $b->{categoryId}} @return; + return \@return; + } + + sub getTrackbackPings { + my @data; + return \@data; + } + + sub supportedTextFilters { + my @data; + return \@data; + } + =head1 NAME BXR: The Blosxom XML-RPC and Web Editor Interface