2014-03-15 02:10:50 +04:00
|
|
|
var _ = require('lodash'),
|
|
|
|
http = require('http'),
|
|
|
|
xml = require('xml'),
|
2015-03-24 23:23:23 +03:00
|
|
|
config = require('../../config'),
|
2016-09-09 13:23:47 +03:00
|
|
|
utils = require('../../utils'),
|
2016-10-04 18:33:43 +03:00
|
|
|
logging = require('../../logging'),
|
2015-03-24 23:23:23 +03:00
|
|
|
events = require('../../events'),
|
2015-11-12 15:29:45 +03:00
|
|
|
i18n = require('../../i18n'),
|
2014-03-15 02:10:50 +04:00
|
|
|
pingList;
|
|
|
|
|
|
|
|
// ToDo: Make this configurable
|
2014-09-10 08:06:24 +04:00
|
|
|
pingList = [{
|
|
|
|
host: 'blogsearch.google.com',
|
|
|
|
path: '/ping/RPC2'
|
|
|
|
}, {
|
|
|
|
host: 'rpc.pingomatic.com',
|
|
|
|
path: '/'
|
|
|
|
}];
|
2014-03-15 02:10:50 +04:00
|
|
|
|
|
|
|
function ping(post) {
|
|
|
|
var pingXML,
|
2014-12-10 17:03:39 +03:00
|
|
|
title = post.title,
|
2016-09-09 13:23:47 +03:00
|
|
|
url = utils.url.urlFor('post', {post: post}, true);
|
2014-03-15 02:10:50 +04:00
|
|
|
|
|
|
|
// Only ping when in production and not a page
|
2014-09-03 08:27:37 +04:00
|
|
|
if (process.env.NODE_ENV !== 'production' || post.page || config.isPrivacyDisabled('useRpcPing')) {
|
2014-03-15 02:10:50 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-08 06:58:01 +04: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 17:03:39 +03:00
|
|
|
// Build XML object.
|
|
|
|
pingXML = xml({
|
|
|
|
methodCall: [{
|
|
|
|
methodName: 'weblogUpdate.ping'
|
|
|
|
}, {
|
|
|
|
params: [{
|
|
|
|
param: [{
|
|
|
|
value: [{
|
|
|
|
string: title
|
2014-09-10 08:06:24 +04:00
|
|
|
}]
|
2014-12-10 17:03:39 +03:00
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
param: [{
|
|
|
|
value: [{
|
|
|
|
string: url
|
2014-03-15 02:10:50 +04:00
|
|
|
}]
|
2014-09-10 08:06:24 +04:00
|
|
|
}]
|
|
|
|
}]
|
2014-12-10 17:03:39 +03:00
|
|
|
}]
|
|
|
|
}, {declaration: true});
|
2014-03-15 02:10:50 +04:00
|
|
|
|
2014-12-10 17:03:39 +03:00
|
|
|
// Ping each of the defined services.
|
|
|
|
_.each(pingList, function (pingHost) {
|
|
|
|
var options = {
|
|
|
|
hostname: pingHost.host,
|
|
|
|
path: pingHost.path,
|
|
|
|
method: 'POST'
|
|
|
|
},
|
|
|
|
req;
|
2014-03-15 02:10:50 +04:00
|
|
|
|
2014-12-10 17:03:39 +03:00
|
|
|
req = http.request(options);
|
|
|
|
req.write(pingXML);
|
2016-10-04 18:33:43 +03:00
|
|
|
req.on('error', function handleError(err) {
|
|
|
|
err.context = i18n.t('errors.data.xml.xmlrpc.pingUpdateFailed.error');
|
|
|
|
err.help = i18n.t('errors.data.xml.xmlrpc.pingUpdateFailed.help', {url: 'http://support.ghost.org'});
|
|
|
|
logging.error(err);
|
|
|
|
});
|
2014-12-10 17:03:39 +03:00
|
|
|
req.end();
|
2014-03-15 02:10:50 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-05 14:22:11 +03:00
|
|
|
function listener(model) {
|
|
|
|
ping(model.toJSON());
|
|
|
|
}
|
|
|
|
|
|
|
|
function listen() {
|
|
|
|
events.on('post.published', listener);
|
2015-03-24 23:23:23 +03:00
|
|
|
}
|
|
|
|
|
2014-03-15 02:10:50 +04:00
|
|
|
module.exports = {
|
2016-06-05 14:22:11 +03:00
|
|
|
listen: listen
|
2014-09-10 08:06:24 +04:00
|
|
|
};
|