23#include "wordpressbuggy_p.h"
28#include <KLocalizedString>
33#include <QtCore/QStringList>
38 :
MovableType( server, *new WordpressBuggyPrivate, parent )
65 if ( d->mCategoriesList.isEmpty() ) {
66 kDebug() <<
"No categories in the cache yet. Have to fetch them first.";
67 d->mCreatePostCache << post;
69 this,SLOT(slotTriggerCreatePost()) );
73 kDebug() <<
"createPost()";
75 kError() <<
"WordpressBuggy::createPost: post is a null pointer";
76 emit
error (
Other, i18n(
"Post is a null pointer." ) );
79 kDebug() <<
"Creating new Post with blogId" <<
blogId();
85 if ( d->mSilentCreationList.contains( post ) ) {
86 kDebug() <<
"Post already in mSilentCreationList, this *should* never happen!";
88 d->mSilentCreationList << post;
92 QString xmlMarkup = QLatin1String(
"<?xml version=\"1.0\"?>");
93 xmlMarkup += QLatin1String(
"<methodCall>");
94 xmlMarkup += QLatin1String(
"<methodName>metaWeblog.newPost</methodName>");
95 xmlMarkup += QLatin1String(
"<params><param>");
96 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+
blogId()+QLatin1String(
"]]></string></value>");
97 xmlMarkup += QLatin1String(
"</param>");
98 xmlMarkup += QLatin1String(
"<param>");
99 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+
username()+QLatin1String(
"]]></string></value>");
100 xmlMarkup += QLatin1String(
"</param><param>");
101 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+
password()+QLatin1String(
"]]></string></value>");
102 xmlMarkup += QLatin1String(
"</param>");
103 xmlMarkup += QLatin1String(
"<param><struct>");
104 xmlMarkup += QLatin1String(
"<member><name>description</name>");
105 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+post->
content()+QLatin1String(
"]]></string></value>");
106 xmlMarkup += QLatin1String(
"</member><member>");
107 xmlMarkup += QLatin1String(
"<name>title</name>");
108 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+post->
title()+QLatin1String(
"]]></string></value>");
109 xmlMarkup += QLatin1String(
"</member><member>");
111 xmlMarkup += QLatin1String(
"<name>dateCreated</name>");
112 xmlMarkup += QLatin1String(
"<value><dateTime.iso8601>") +
113 post->
creationDateTime().dateTime().toUTC().toString( QLatin1String(
"yyyyMMddThh:mm:ss") ) +
114 QLatin1String(
"</dateTime.iso8601></value>");
115 xmlMarkup += QLatin1String(
"</member><member>");
116 xmlMarkup += QLatin1String(
"<name>mt_allow_comments</name>");
117 xmlMarkup += QString::fromLatin1(
"<value><int>%1</int></value>" ).arg( (
int)post->
isCommentAllowed() );
118 xmlMarkup += QLatin1String(
"</member><member>");
119 xmlMarkup += QLatin1String(
"<name>mt_allow_pings</name>");
120 xmlMarkup += QString::fromLatin1(
"<value><int>%1</int></value>" ).arg( (
int)post->
isTrackBackAllowed() );
121 xmlMarkup += QLatin1String(
"</member><member>");
123 xmlMarkup += QLatin1String(
"<name>mt_text_more</name>");
124 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
additionalContent() + QLatin1String(
"]]></string></value>");
125 xmlMarkup += QLatin1String(
"</member><member>");
127 xmlMarkup += QLatin1String(
"<name>wp_slug</name>");
128 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
slug() + QLatin1String(
"]]></string></value>");
129 xmlMarkup += QLatin1String(
"</member><member>");
130 xmlMarkup += QLatin1String(
"<name>mt_excerpt</name>");
131 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
summary() + QLatin1String(
"]]></string></value>");
132 xmlMarkup += QLatin1String(
"</member><member>");
133 xmlMarkup += QLatin1String(
"<name>mt_keywords</name>");
134 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
tags().join(QLatin1String(
",")) + QLatin1String(
"]]></string></value>");
135 xmlMarkup += QLatin1String(
"</member></struct></param>");
136 xmlMarkup += QLatin1String(
"<param><value><boolean>") +
137 QString::fromLatin1(
"%1" ).arg( (
int)(!post->
isPrivate() ) ) +
138 QLatin1String(
"</boolean></value></param>");
139 xmlMarkup += QLatin1String(
"</params></methodCall>");
142 QDataStream stream( &postData, QIODevice::WriteOnly );
143 stream.writeRawData( xmlMarkup.toUtf8(), xmlMarkup.toUtf8().length() );
145 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
url(), KIO::HideProgressInfo );
147 d->mCreatePostMap[ job ] = post;
150 kWarning() <<
"Failed to create job for: " <<
url().url();
154 QLatin1String(
"customHTTPHeader"), QLatin1String(
"X-hacker: Shame on you Wordpress, ") + QString() +
155 QLatin1String(
"you took another 4 hours of my life to work around the stupid dateTime bug.") );
156 job->addMetaData( QLatin1String(
"content-type"), QLatin1String(
"Content-Type: text/xml; charset=utf-8") );
157 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
158 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
160 connect( job, SIGNAL(result(KJob*)),
161 this, SLOT(slotCreatePost(KJob*)) );
178 if ( d->mCategoriesList.isEmpty() ) {
179 kDebug() <<
"No categories in the cache yet. Have to fetch them first.";
180 d->mModifyPostCache << post;
182 this,SLOT(slotTriggerModifyPost()) );
187 kError() <<
"WordpressBuggy::modifyPost: post is a null pointer";
188 emit
error (
Other, i18n(
"Post is a null pointer." ) );
192 kDebug() <<
"Uploading Post with postId" << post->
postId();
194 QString xmlMarkup = QLatin1String(
"<?xml version=\"1.0\"?>");
195 xmlMarkup += QLatin1String(
"<methodCall>");
196 xmlMarkup += QLatin1String(
"<methodName>metaWeblog.editPost</methodName>");
197 xmlMarkup += QLatin1String(
"<params><param>");
198 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+post->
postId()+QLatin1String(
"]]></string></value>");
199 xmlMarkup += QLatin1String(
"</param>");
200 xmlMarkup += QLatin1String(
"<param>");
201 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+
username()+QLatin1String(
"]]></string></value>");
202 xmlMarkup += QLatin1String(
"</param><param>");
203 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+
password()+QLatin1String(
"]]></string></value>");
204 xmlMarkup += QLatin1String(
"</param>");
205 xmlMarkup += QLatin1String(
"<param><struct>");
206 xmlMarkup += QLatin1String(
"<member><name>description</name>");
207 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+post->
content()+QLatin1String(
"]]></string></value>");
208 xmlMarkup += QLatin1String(
"</member><member>");
209 xmlMarkup += QLatin1String(
"<name>title</name>");
210 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+post->
title()+QLatin1String(
"]]></string></value>");
211 xmlMarkup += QLatin1String(
"</member><member>");
213 xmlMarkup += QLatin1String(
"<name>lastModified</name>");
214 xmlMarkup += QLatin1String(
"<value><dateTime.iso8601>") +
215 post->
modificationDateTime().dateTime().toUTC().toString( QLatin1String(
"yyyyMMddThh:mm:ss") ) +
216 QLatin1String(
"</dateTime.iso8601></value>");
217 xmlMarkup += QLatin1String(
"</member><member>");
218 xmlMarkup += QLatin1String(
"<name>dateCreated</name>");
219 xmlMarkup += QLatin1String(
"<value><dateTime.iso8601>") +
220 post->
creationDateTime().dateTime().toUTC().toString( QLatin1String(
"yyyyMMddThh:mm:ss") ) +
221 QLatin1String(
"</dateTime.iso8601></value>");
222 xmlMarkup += QLatin1String(
"</member><member>");
223 xmlMarkup += QLatin1String(
"<name>mt_allow_comments</name>");
224 xmlMarkup += QString::fromLatin1(
"<value><int>%1</int></value>" ).arg( (
int)post->
isCommentAllowed() );
225 xmlMarkup += QLatin1String(
"</member><member>");
226 xmlMarkup += QLatin1String(
"<name>mt_allow_pings</name>");
227 xmlMarkup += QString::fromLatin1(
"<value><int>%1</int></value>" ).arg( (
int)post->
isTrackBackAllowed() );
228 xmlMarkup += QLatin1String(
"</member><member>");
230 xmlMarkup += QLatin1String(
"<name>mt_text_more</name>");
231 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
additionalContent() + QLatin1String(
"]]></string></value>");
232 xmlMarkup += QLatin1String(
"</member><member>");
234 xmlMarkup += QLatin1String(
"<name>wp_slug</name>");
235 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
slug() + QLatin1String(
"]]></string></value>");
236 xmlMarkup += QLatin1String(
"</member><member>");
237 xmlMarkup += QLatin1String(
"<name>mt_excerpt</name>");
238 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
summary() + QLatin1String(
"]]></string></value>");
239 xmlMarkup += QLatin1String(
"</member><member>");
240 xmlMarkup += QLatin1String(
"<name>mt_keywords</name>");
241 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
tags().join( QLatin1String(
",") ) + QLatin1String(
"]]></string></value>");
242 xmlMarkup += QLatin1String(
"</member></struct></param>");
243 xmlMarkup += QLatin1String(
"<param><value><boolean>") +
244 QString::fromLatin1(
"%1" ).arg( (
int)( !post->
isPrivate() ) ) +
245 QLatin1String(
"</boolean></value></param>");
246 xmlMarkup += QLatin1String(
"</params></methodCall>");
249 QDataStream stream( &postData, QIODevice::WriteOnly );
250 stream.writeRawData( xmlMarkup.toUtf8(), xmlMarkup.toUtf8().length() );
252 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
url(), KIO::HideProgressInfo );
254 d->mModifyPostMap[ job ] = post;
257 kWarning() <<
"Failed to create job for: " <<
url().url();
261 QLatin1String(
"customHTTPHeader"), QLatin1String(
"X-hacker: Shame on you Wordpress, ") + QString() +
262 QLatin1String(
"you took another 4 hours of my life to work around the stupid dateTime bug.") );
263 job->addMetaData( QLatin1String(
"content-type"), QLatin1String(
"Content-Type: text/xml; charset=utf-8") );
264 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
265 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
267 connect( job, SIGNAL(result(KJob*)),
268 this, SLOT(slotModifyPost(KJob*)) );
274 return QLatin1String(
"Movable Type" );
277WordpressBuggyPrivate::WordpressBuggyPrivate()
281WordpressBuggyPrivate::~WordpressBuggyPrivate()
286QList<QVariant> WordpressBuggyPrivate::defaultArgs(
const QString &
id )
289 QList<QVariant> args;
290 if ( !
id.isEmpty() ) {
291 args << QVariant(
id );
293 args << QVariant( q->username() )
294 << QVariant( q->password() );
298void WordpressBuggyPrivate::slotCreatePost( KJob *job )
302 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
303 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
308 mCreatePostMap.remove( job );
310 if ( job->error() != 0 ) {
311 kError() <<
"slotCreatePost error:" << job->errorString();
316 QRegExp rxError( QLatin1String(
"faultString") );
317 if ( rxError.indexIn( data ) != -1 ) {
318 rxError = QRegExp( QLatin1String(
"<string>(.+)</string>") );
319 if ( rxError.indexIn( data ) != -1 ) {
320 kDebug() <<
"RegExp of faultString failed.";
322 kDebug() << rxError.cap( 1 );
327 QRegExp rxId( QLatin1String(
"<string>(.+)</string>") );
328 if ( rxId.indexIn( data ) == -1 ) {
329 kError() <<
"Could not regexp the id out of the result:" << data;
331 i18n(
"Could not regexp the id out of the result." ), post );
334 kDebug() <<
"QRegExp rx( \"<string>(.+)</string>\" ) matches" << rxId.cap( 1 );
337 if ( mSilentCreationList.contains( post ) )
340 setPostCategories( post, !post->
isPrivate() );
342 kDebug() <<
"emitting createdPost()"
343 <<
"for title: \"" << post->
title();
344 emit q->createdPost( post );
349void WordpressBuggyPrivate::slotModifyPost( KJob *job )
353 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
354 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
357 mModifyPostMap.remove( job );
359 if ( job->error() != 0 ) {
360 kError() <<
"slotModifyPost error:" << job->errorString();
365 QRegExp rxError( QLatin1String(
"faultString") );
366 if ( rxError.indexIn( data ) != -1 ) {
367 rxError = QRegExp( QLatin1String(
"<string>(.+)</string>") );
368 if ( rxError.indexIn( data ) != -1 ) {
369 kDebug() <<
"RegExp of faultString failed.";
371 kDebug() << rxError.cap( 1 );
376 QRegExp rxId( QLatin1String(
"<boolean>(.+)</boolean>") );
377 if ( rxId.indexIn( data ) == -1 ) {
378 kError() <<
"Could not regexp the id out of the result:" << data;
380 i18n(
"Could not regexp the id out of the result." ), post );
383 kDebug() <<
"QRegExp rx( \"<boolean>(.+)</boolean>\" ) matches" << rxId.cap( 1 );
385 if ( rxId.cap( 1 ).toInt() == 1 ) {
386 kDebug() <<
"Post successfully updated.";
387 if ( mSilentCreationList.contains( post ) ) {
389 emit q->createdPost( post );
390 mSilentCreationList.removeOne( post );
393 setPostCategories( post,
false );
399#include "moc_wordpressbuggy.cpp"
A class that represents a blog post on the server.
KDateTime creationDateTime() const
Returns the creation date time.
QString summary() const
Returns the summary.
bool isPrivate() const
Returns if the post is published or not.
void setPostId(const QString &postId)
Sets the post id value.
void setStatus(Status status)
Sets the status.
bool isCommentAllowed() const
Returns whether comments should be allowed.
QString content() const
Returns the content.
QStringList tags() const
Returns the tags list as a QStringList.
KDateTime modificationDateTime() const
Returns the modification date time.
QString title() const
Returns the title.
QStringList categories() const
Returns the categories.
QString additionalContent() const
Returns the additional content, (mt_text_more of MovableType API)
QString postId() const
Returns the postId.
@ Created
Status of a successfully created post.
QString slug() const
Returns the Wordpress posts Slug (or permalink will use for post) Currently just wordpress supports t...
bool isTrackBackAllowed() const
Returns whether track back should be allowed.
void setPrivate(bool privatePost)
Sets the post to private viewings only.
QString username() const
Returns the username used in blog authentication.
@ Other
Any other miscellaneous error.
@ XmlRpc
An error in the XML-RPC client.
QString blogId() const
Returns the unique ID for the specific blog on the server.
KUrl url() const
Get the URL for the blog's XML-RPC interface.
QString password() const
Returns the password of the blog.
void error(KBlog::Blog::ErrorType type, const QString &errorMessage)
This signal is emitted when an error occurs with XML parsing or a structural problem.
QString userAgent() const
Returns the HTTP user agent string used to make the HTTP requests.
virtual void listCategories()
List the categories of the blog.
void listedCategories(const QList< QMap< QString, QString > > &categories)
This signal is emitted when the last category of the listCategories() job has been fetched.
A class that can be used for access to Movable Type blogs.
A class that can be used for access to blogs (Wordpress, Drupal <5.6 and most likely many more) which...
void createPost(KBlog::BlogPost *post)
Create a new post on server.
WordpressBuggy(const KUrl &server, QObject *parent=0)
Create an object for WordpressBuggy.
QString interfaceName() const
Returns the of the inherited object.
virtual ~WordpressBuggy()
Destroy the object.
void modifyPost(KBlog::BlogPost *post)
Modify a post on server.
Namespace for blog related classes.
This file is part of the for accessing Blog Servers and defines the WordpressBuggy class.