2014-03-14 17:10:50 -05:00
|
|
|
var _ = require('lodash'),
|
|
|
|
http = require('http'),
|
|
|
|
xml = require('xml'),
|
2015-03-24 15:23:23 -05:00
|
|
|
config = require('../../config'),
|
|
|
|
errors = require('../../errors'),
|
|
|
|
events = require('../../events'),
|
2015-11-12 07:29:45 -05:00
|
|
|
i18n = require('../../i18n'),
|
2014-03-14 17:10:50 -05:00
|
|
|
pingList;
|
|
|
|
|
|
|
|
// ToDo: Make this configurable
|
2014-09-09 23:06:24 -05:00
|
|
|
pingList = [{
|
|
|
|
host: 'blogsearch.google.com',
|
|
|
|
path: '/ping/RPC2'
|
|
|
|
}, {
|
|
|
|
host: 'rpc.pingomatic.com',
|
|
|
|
path: '/'
|
|
|
|
}];
|
2014-03-14 17:10:50 -05:00
|
|
|
|
|
|
|
function ping(post) {
|
|
|
|
var pingXML,
|
2014-12-10 09:03:39 -05:00
|
|
|
title = post.title,
|
|
|
|
url = config.urlFor('post', {post: post}, true);
|
2014-03-14 17:10:50 -05:00
|
|
|
|
|
|
|
// Only ping when in production and not a page
|
2014-09-02 23:27:37 -05:00
|
|
|
if (process.env.NODE_ENV !== 'production' || post.page || config.isPrivacyDisabled('useRpcPing')) {
|
2014-03-14 17:10:50 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-07 21:58:01 -05:00
|
|
|
// Don't ping for the welcome to ghost post.
|
|
|
|
// This also handles the case where during ghost's first run
|
|
|
|
// models.init() inserts this post but permissions.init() hasn't
|
|
|
|
// (can't) run yet.
|
|
|
|
if (post.slug === 'welcome-to-ghost') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-10 09:03:39 -05:00
|
|
|
// Build XML object.
|
|
|
|
pingXML = xml({
|
|
|
|
methodCall: [{
|
|
|
|
methodName: 'weblogUpdate.ping'
|
|
|
|
}, {
|
|
|
|
params: [{
|
|
|
|
param: [{
|
|
|
|
value: [{
|
|
|
|
string: title
|
2014-09-09 23:06:24 -05:00
|
|
|
}]
|
2014-12-10 09:03:39 -05:00
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
param: [{
|
|
|
|
value: [{
|
|
|
|
string: url
|
2014-03-14 17:10:50 -05:00
|
|
|
}]
|
2014-09-09 23:06:24 -05:00
|
|
|
}]
|
|
|
|
}]
|
2014-12-10 09:03:39 -05:00
|
|
|
}]
|
|
|
|
}, {declaration: true});
|
2014-03-14 17:10:50 -05:00
|
|
|
|
2014-12-10 09:03:39 -05:00
|
|
|
// Ping each of the defined services.
|
|
|
|
_.each(pingList, function (pingHost) {
|
|
|
|
var options = {
|
|
|
|
hostname: pingHost.host,
|
|
|
|
path: pingHost.path,
|
|
|
|
method: 'POST'
|
|
|
|
},
|
|
|
|
req;
|
2014-03-14 17:10:50 -05:00
|
|
|
|
2014-12-10 09:03:39 -05:00
|
|
|
req = http.request(options);
|
|
|
|
req.write(pingXML);
|
|
|
|
req.on('error', function (error) {
|
|
|
|
errors.logError(
|
|
|
|
error,
|
2015-11-12 07:29:45 -05:00
|
|
|
i18n.t('errors.data.xml.xmlrpc.pingUpdateFailed.error'),
|
|
|
|
i18n.t('errors.data.xml.xmlrpc.pingUpdateFailed.help', {url: 'http://support.ghost.org'})
|
2014-12-10 09:03:39 -05:00
|
|
|
);
|
2014-03-14 17:10:50 -05:00
|
|
|
});
|
2014-12-10 09:03:39 -05:00
|
|
|
req.end();
|
2014-03-14 17:10:50 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-24 15:23:23 -05:00
|
|
|
function init() {
|
|
|
|
events.on('post.published', function (model) {
|
|
|
|
ping(model.toJSON());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-14 17:10:50 -05:00
|
|
|
module.exports = {
|
2015-03-24 15:23:23 -05:00
|
|
|
init: init
|
2014-09-09 23:06:24 -05:00
|
|
|
};
|