23 #include "wordpressbuggy_p.h"
28 #include <KLocalizedString>
34 #include <QtCore/QStringList>
36 using namespace KBlog;
39 :
MovableType( server, *new WordpressBuggyPrivate, parent )
66 if ( d->mCategoriesList.isEmpty() ) {
67 kDebug() <<
"No categories in the cache yet. Have to fetch them first.";
68 d->mCreatePostCache << post;
70 this,SLOT(slotTriggerCreatePost()) );
74 kDebug() <<
"createPost()";
76 kError() <<
"WordpressBuggy::createPost: post is a null pointer";
77 emit
error (
Other, i18n(
"Post is a null pointer." ) );
80 kDebug() <<
"Creating new Post with blogId" <<
blogId();
86 if ( d->mSilentCreationList.contains( post ) ) {
87 kDebug() <<
"Post already in mSilentCreationList, this *should* never happen!";
89 d->mSilentCreationList << post;
93 QString xmlMarkup = QLatin1String(
"<?xml version=\"1.0\"?>");
94 xmlMarkup += QLatin1String(
"<methodCall>");
95 xmlMarkup += QLatin1String(
"<methodName>metaWeblog.newPost</methodName>");
96 xmlMarkup += QLatin1String(
"<params><param>");
97 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+
blogId()+QLatin1String(
"]]></string></value>");
98 xmlMarkup += QLatin1String(
"</param>");
99 xmlMarkup += QLatin1String(
"<param>");
100 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+
username()+QLatin1String(
"]]></string></value>");
101 xmlMarkup += QLatin1String(
"</param><param>");
102 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+
password()+QLatin1String(
"]]></string></value>");
103 xmlMarkup += QLatin1String(
"</param>");
104 xmlMarkup += QLatin1String(
"<param><struct>");
105 xmlMarkup += QLatin1String(
"<member><name>description</name>");
106 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+post->
content()+QLatin1String(
"]]></string></value>");
107 xmlMarkup += QLatin1String(
"</member><member>");
108 xmlMarkup += QLatin1String(
"<name>title</name>");
109 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+post->
title()+QLatin1String(
"]]></string></value>");
110 xmlMarkup += QLatin1String(
"</member><member>");
112 xmlMarkup += QLatin1String(
"<name>dateCreated</name>");
113 xmlMarkup += QLatin1String(
"<value><dateTime.iso8601>") +
114 post->
creationDateTime().dateTime().toUTC().toString( QLatin1String(
"yyyyMMddThh:mm:ss") ) +
115 QLatin1String(
"</dateTime.iso8601></value>");
116 xmlMarkup += QLatin1String(
"</member><member>");
117 xmlMarkup += QLatin1String(
"<name>mt_allow_comments</name>");
118 xmlMarkup += QString::fromLatin1(
"<value><int>%1</int></value>" ).arg( (
int)post->
isCommentAllowed() );
119 xmlMarkup += QLatin1String(
"</member><member>");
120 xmlMarkup += QLatin1String(
"<name>mt_allow_pings</name>");
121 xmlMarkup += QString::fromLatin1(
"<value><int>%1</int></value>" ).arg( (
int)post->
isTrackBackAllowed() );
122 xmlMarkup += QLatin1String(
"</member><member>");
124 xmlMarkup += QLatin1String(
"<name>mt_text_more</name>");
125 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
additionalContent() + QLatin1String(
"]]></string></value>");
126 xmlMarkup += QLatin1String(
"</member><member>");
128 xmlMarkup += QLatin1String(
"<name>wp_slug</name>");
129 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
slug() + QLatin1String(
"]]></string></value>");
130 xmlMarkup += QLatin1String(
"</member><member>");
131 xmlMarkup += QLatin1String(
"<name>mt_excerpt</name>");
132 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
summary() + QLatin1String(
"]]></string></value>");
133 xmlMarkup += QLatin1String(
"</member><member>");
134 xmlMarkup += QLatin1String(
"<name>mt_keywords</name>");
135 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
tags().join(QLatin1String(
",")) + QLatin1String(
"]]></string></value>");
136 xmlMarkup += QLatin1String(
"</member></struct></param>");
137 xmlMarkup += QLatin1String(
"<param><value><boolean>") +
138 QString::fromLatin1(
"%1" ).arg( (
int)(!post->
isPrivate() ) ) +
139 QLatin1String(
"</boolean></value></param>");
140 xmlMarkup += QLatin1String(
"</params></methodCall>");
143 QDataStream stream( &postData, QIODevice::WriteOnly );
144 stream.writeRawData( xmlMarkup.toUtf8(), xmlMarkup.toUtf8().length() );
146 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
url(), KIO::HideProgressInfo );
148 d->mCreatePostMap[ job ] = post;
151 kWarning() <<
"Failed to create job for: " <<
url().url();
155 QLatin1String(
"customHTTPHeader"), QLatin1String(
"X-hacker: Shame on you Wordpress, ") + QString() +
156 QLatin1String(
"you took another 4 hours of my life to work around the stupid dateTime bug.") );
157 job->addMetaData( QLatin1String(
"content-type"), QLatin1String(
"Content-Type: text/xml; charset=utf-8") );
158 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
159 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
161 connect( job, SIGNAL(result(KJob*)),
162 this, SLOT(slotCreatePost(KJob*)) );
179 if ( d->mCategoriesList.isEmpty() ) {
180 kDebug() <<
"No categories in the cache yet. Have to fetch them first.";
181 d->mModifyPostCache << post;
183 this,SLOT(slotTriggerModifyPost()) );
188 kError() <<
"WordpressBuggy::modifyPost: post is a null pointer";
189 emit
error (
Other, i18n(
"Post is a null pointer." ) );
193 kDebug() <<
"Uploading Post with postId" << post->
postId();
195 QString xmlMarkup = QLatin1String(
"<?xml version=\"1.0\"?>");
196 xmlMarkup += QLatin1String(
"<methodCall>");
197 xmlMarkup += QLatin1String(
"<methodName>metaWeblog.editPost</methodName>");
198 xmlMarkup += QLatin1String(
"<params><param>");
199 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+post->
postId()+QLatin1String(
"]]></string></value>");
200 xmlMarkup += QLatin1String(
"</param>");
201 xmlMarkup += QLatin1String(
"<param>");
202 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+
username()+QLatin1String(
"]]></string></value>");
203 xmlMarkup += QLatin1String(
"</param><param>");
204 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+
password()+QLatin1String(
"]]></string></value>");
205 xmlMarkup += QLatin1String(
"</param>");
206 xmlMarkup += QLatin1String(
"<param><struct>");
207 xmlMarkup += QLatin1String(
"<member><name>description</name>");
208 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+post->
content()+QLatin1String(
"]]></string></value>");
209 xmlMarkup += QLatin1String(
"</member><member>");
210 xmlMarkup += QLatin1String(
"<name>title</name>");
211 xmlMarkup += QLatin1String(
"<value><string><![CDATA[")+post->
title()+QLatin1String(
"]]></string></value>");
212 xmlMarkup += QLatin1String(
"</member><member>");
214 xmlMarkup += QLatin1String(
"<name>lastModified</name>");
215 xmlMarkup += QLatin1String(
"<value><dateTime.iso8601>") +
216 post->
modificationDateTime().dateTime().toUTC().toString( QLatin1String(
"yyyyMMddThh:mm:ss") ) +
217 QLatin1String(
"</dateTime.iso8601></value>");
218 xmlMarkup += QLatin1String(
"</member><member>");
219 xmlMarkup += QLatin1String(
"<name>dateCreated</name>");
220 xmlMarkup += QLatin1String(
"<value><dateTime.iso8601>") +
221 post->
creationDateTime().dateTime().toUTC().toString( QLatin1String(
"yyyyMMddThh:mm:ss") ) +
222 QLatin1String(
"</dateTime.iso8601></value>");
223 xmlMarkup += QLatin1String(
"</member><member>");
224 xmlMarkup += QLatin1String(
"<name>mt_allow_comments</name>");
225 xmlMarkup += QString::fromLatin1(
"<value><int>%1</int></value>" ).arg( (
int)post->
isCommentAllowed() );
226 xmlMarkup += QLatin1String(
"</member><member>");
227 xmlMarkup += QLatin1String(
"<name>mt_allow_pings</name>");
228 xmlMarkup += QString::fromLatin1(
"<value><int>%1</int></value>" ).arg( (
int)post->
isTrackBackAllowed() );
229 xmlMarkup += QLatin1String(
"</member><member>");
231 xmlMarkup += QLatin1String(
"<name>mt_text_more</name>");
232 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
additionalContent() + QLatin1String(
"]]></string></value>");
233 xmlMarkup += QLatin1String(
"</member><member>");
235 xmlMarkup += QLatin1String(
"<name>wp_slug</name>");
236 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
slug() + QLatin1String(
"]]></string></value>");
237 xmlMarkup += QLatin1String(
"</member><member>");
238 xmlMarkup += QLatin1String(
"<name>mt_excerpt</name>");
239 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
summary() + QLatin1String(
"]]></string></value>");
240 xmlMarkup += QLatin1String(
"</member><member>");
241 xmlMarkup += QLatin1String(
"<name>mt_keywords</name>");
242 xmlMarkup += QLatin1String(
"<value><string><![CDATA[") + post->
tags().join( QLatin1String(
",") ) + QLatin1String(
"]]></string></value>");
243 xmlMarkup += QLatin1String(
"</member></struct></param>");
244 xmlMarkup += QLatin1String(
"<param><value><boolean>") +
245 QString::fromLatin1(
"%1" ).arg( (
int)( !post->
isPrivate() ) ) +
246 QLatin1String(
"</boolean></value></param>");
247 xmlMarkup += QLatin1String(
"</params></methodCall>");
250 QDataStream stream( &postData, QIODevice::WriteOnly );
251 stream.writeRawData( xmlMarkup.toUtf8(), xmlMarkup.toUtf8().length() );
253 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
url(), KIO::HideProgressInfo );
255 d->mModifyPostMap[ job ] = post;
258 kWarning() <<
"Failed to create job for: " <<
url().url();
262 QLatin1String(
"customHTTPHeader"), QLatin1String(
"X-hacker: Shame on you Wordpress, ") + QString() +
263 QLatin1String(
"you took another 4 hours of my life to work around the stupid dateTime bug.") );
264 job->addMetaData( QLatin1String(
"content-type"), QLatin1String(
"Content-Type: text/xml; charset=utf-8") );
265 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
266 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
268 connect( job, SIGNAL(result(KJob*)),
269 this, SLOT(slotModifyPost(KJob*)) );
275 return QLatin1String(
"Movable Type" );
278 WordpressBuggyPrivate::WordpressBuggyPrivate()
282 WordpressBuggyPrivate::~WordpressBuggyPrivate()
287 QList<QVariant> WordpressBuggyPrivate::defaultArgs(
const QString &
id )
290 QList<QVariant> args;
291 if ( !
id.isEmpty() ) {
292 args << QVariant(
id );
294 args << QVariant( q->username() )
295 << QVariant( q->password() );
299 void WordpressBuggyPrivate::slotCreatePost( KJob *job )
303 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
304 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
309 mCreatePostMap.remove( job );
311 if ( job->error() != 0 ) {
312 kError() <<
"slotCreatePost error:" << job->errorString();
317 QRegExp rxError( QLatin1String(
"faultString") );
318 if ( rxError.indexIn( data ) != -1 ) {
319 rxError = QRegExp( QLatin1String(
"<string>(.+)</string>") );
320 if ( rxError.indexIn( data ) != -1 ) {
321 kDebug() <<
"RegExp of faultString failed.";
323 kDebug() << rxError.cap( 1 );
328 QRegExp rxId( QLatin1String(
"<string>(.+)</string>") );
329 if ( rxId.indexIn( data ) == -1 ) {
330 kError() <<
"Could not regexp the id out of the result:" << data;
332 i18n(
"Could not regexp the id out of the result." ), post );
335 kDebug() <<
"QRegExp rx( \"<string>(.+)</string>\" ) matches" << rxId.cap( 1 );
338 if ( mSilentCreationList.contains( post ) )
341 setPostCategories( post, !post->
isPrivate() );
343 kDebug() <<
"emitting createdPost()"
344 <<
"for title: \"" << post->
title();
345 emit q->createdPost( post );
350 void WordpressBuggyPrivate::slotModifyPost( KJob *job )
354 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
355 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
358 mModifyPostMap.remove( job );
360 if ( job->error() != 0 ) {
361 kError() <<
"slotModifyPost error:" << job->errorString();
366 QRegExp rxError( QLatin1String(
"faultString") );
367 if ( rxError.indexIn( data ) != -1 ) {
368 rxError = QRegExp( QLatin1String(
"<string>(.+)</string>") );
369 if ( rxError.indexIn( data ) != -1 ) {
370 kDebug() <<
"RegExp of faultString failed.";
372 kDebug() << rxError.cap( 1 );
377 QRegExp rxId( QLatin1String(
"<boolean>(.+)</boolean>") );
378 if ( rxId.indexIn( data ) == -1 ) {
379 kError() <<
"Could not regexp the id out of the result:" << data;
381 i18n(
"Could not regexp the id out of the result." ), post );
384 kDebug() <<
"QRegExp rx( \"<boolean>(.+)</boolean>\" ) matches" << rxId.cap( 1 );
386 if ( rxId.cap( 1 ).toInt() == 1 ) {
387 kDebug() <<
"Post successfully updated.";
388 if ( mSilentCreationList.contains( post ) ) {
390 emit q->createdPost( post );
391 mSilentCreationList.removeOne( post );
393 if ( !post->categories().isEmpty() ) {
394 setPostCategories( post,
false );
400 #include "moc_wordpressbuggy.cpp"
QString title() const
Returns the title.
void error(KBlog::Blog::ErrorType type, const QString &errorMessage)
This signal is emitted when an error occurs with XML parsing or a structural problem.
KDateTime creationDateTime() const
Returns the creation date time.
virtual void listCategories()
List the categories of the blog.
QStringList tags() const
Returns the tags list as a QStringList.
Status of a successfully created post.
QString interfaceName() const
Returns the of the inherited object.
bool isCommentAllowed() const
Returns whether comments should be allowed.
bool isTrackBackAllowed() const
Returns whether track back should be allowed.
QString summary() const
Returns the summary.
void setPostId(const QString &postId)
Sets the post id value.
QString username() const
Returns the username used in blog authentication.
QString additionalContent() const
Returns the additional content, (mt_text_more of MovableType API)
A class that can be used for access to blogs (Wordpress, Drupal <5.6 and most likely many more) which...
This file is part of the for accessing Blog Servers and defines the WordpressBuggy class...
KDateTime modificationDateTime() const
Returns the modification date time.
QString blogId() const
Returns the unique ID for the specific blog on the server.
void setStatus(Status status)
Sets the status.
KUrl url() const
Get the URL for the blog's XML-RPC interface.
QString slug() const
Returns the Wordpress posts Slug (or permalink will use for post) Currently just wordpress supports t...
A class that can be used for access to Movable Type blogs.
void setPrivate(bool privatePost)
Sets the post to private viewings only.
void createPost(KBlog::BlogPost *post)
Create a new post on server.
QString content() const
Returns the content.
void modifyPost(KBlog::BlogPost *post)
Modify a post on server.
A class that represents a blog post on the server.
virtual ~WordpressBuggy()
Destroy the object.
QStringList categories() const
Returns the categories.
WordpressBuggy(const KUrl &server, QObject *parent=0)
Create an object for WordpressBuggy.
bool isPrivate() const
Returns if the post is published or not.
Any other miscellaneous error.
void listedCategories(const QList< QMap< QString, QString > > &categories)
This signal is emitted when the last category of the listCategories() job has been fetched...
QString postId() const
Returns the postId.
QString userAgent() const
Returns the HTTP user agent string used to make the HTTP requests.
QString password() const
Returns the password of the blog.
An error in the XML-RPC client.