Постилка в wordpress-движки

Сентябрь 2nd, 2008 | by Chippa |

Начало темы: тут

На входе подготовленный файл results.parser, в первой строке которого – тема поста, весь остальной текст в одну строку – тело поста.

#! /usr/bin/perl

use DBI;
use IO::Socket::INET;
use LWP::UserAgent;
use Time::Local;

$blog_url = «http://wordpress.com/»;
$blog_login = «odmin»;
$blog_password = «parol»;

open FILE, «results.parser» or die $!;
@count=<FILE>;
close (FILE);

$title = $count[0];
$content = $count[1];

poster($blog_url, $blog_login, $blog_password, $title, $content);

sub poster($blog_url, $blog_login, $blog_password, $title, $content)
{
# change this
my $burl = $blog_url; # don’t forget the trailing slash
my ( $usr, $pwd, $uid ) = ( $blog_login, $blog_password, 1 ); # uid=1 if you are the initial administrator

# ua
my $ua = LWP::UserAgent->new;
$ua->agent(‘wp-poster’);
$ua->cookie_jar( {} );

# login
my $req = HTTP::Request->new( POST => $burl . ‘wp-login.php’ );
$req->content_type(‘application/x-www-form-urlencoded’);
$req->content( sprintf(‘log=%s&pwd=%s&wp-submit=1&redirect_to=wp-admin/’,$usr,$pwd) );
my $res = $ua->request( $req );

# get _wpnonce and temp_id
$req = HTTP::Request->new( POST => $burl . ‘wp-admin/post-new.php’ );
$res = $ua->request( $req );
if ( $res->is_success ) {
if ( $res->content =~ m/»_wpnonce» value=»([0-9a-f9]+)».*’temp_ID’ value=’(-?[0-9]+)’/s ) {
# post
$req = HTTP::Request->new( POST => $burl . ‘wp-admin/post.php’ );
$req->content_type(‘application/x-www-form-urlencoded’);
$req->content( sprintf(
‘_wpnonce=%s’ .
‘&user_ID=%d’ .
‘&action=post&originalaction=post&post_type=post’ .
‘&temp_ID=%s’ .
‘&advanced_view=1′ .
#’&comment_status=open’ .
#’&ping_status=open’ .
#’&post_password=’ .
#’&post_name=’ . #slug
‘&post_status=publish’ .
#’&edit_date=1′ .
‘&post_title=%s’ .
‘&content=%s’ .
‘&post_pingback=1′ .
‘&prev_status=draft’ .
‘&publish=Publish’ .
‘&referredby=redo’
,
$1, #nonce
$uid,
$2, #tempid
$title, #title
$content #content
)
);
$res = $ua->request( $req );
&debug($res, 2);
} else { &debug($res, 1); print $res->content; }
}
else
{
&debug($res, 0);
}

#}

sub debug {
my ( $res, $id ) = @_;
print $id, ‘: ‘, $res->status_line, «\n»;
foreach ( $res->header_field_names ) {
print $_, ‘: ‘, $res->header($_), «\n»;
}
return;
}

Пару месяцев назад – работало. Как сейчас – незнаю.

Взято из открытых источников.

Регилка вордпрессов и парсер – в следующих постах.

You must be logged in to post a comment.