diff --git a/public/src/admin/settings.js b/public/src/admin/settings.js index 3dca037514..98ab422b14 100644 --- a/public/src/admin/settings.js +++ b/public/src/admin/settings.js @@ -86,14 +86,19 @@ define('admin/settings', ['uploader', 'sounds'], function(uploader, sounds) { $('button[data-action="email.test"]').off('click').on('click', function() { socket.emit('admin.email.test', function(err) { - app.alert({ - alert_id: 'test_email_sent', - type: !err ? 'info' : 'danger', - title: 'Test Email Sent', - message: err ? err.message : '', - timeout: 2500 - }); + if (err) { + return app.alertError(err.message); + } + app.alertSuccess('Test Email Sent'); + }); + return false; + }); + + $('#clear-sitemap-cache').off('click').on('click', function() { + socket.emit('admin.settings.clearSitemapCache', function() { + app.alertSuccess('Sitemap Cache Cleared!'); }); + return false; }); if (typeof callback === 'function') { diff --git a/src/sitemap.js b/src/sitemap.js index ffc072b871..aab7451a61 100644 --- a/src/sitemap.js +++ b/src/sitemap.js @@ -10,104 +10,121 @@ var path = require('path'), topics = require('./topics'), privileges = require('./privileges'), meta = require('./meta'), - utils = require('../public/src/utils'), - sitemap = { - obj: undefined, - getStaticUrls: function(callback) { - callback(null, [{ - url: '', - changefreq: 'weekly', - priority: '0.6' - }, { - url: '/recent', - changefreq: 'daily', - priority: '0.4' - }, { - url: '/users', - changefreq: 'daily', - priority: '0.4' - }]); - }, - getDynamicUrls: function(callback) { - var returnUrls = []; - - async.parallel({ - categoryUrls: function(next) { - var categoryUrls = []; - categories.getCategoriesByPrivilege(0, 'find', function(err, categoriesData) { - if (err) { - return next(err); - } - - categoriesData.forEach(function(category) { - if (category) { - categoryUrls.push({ - url: '/category/' + category.cid + '/' + encodeURIComponent(utils.slugify(category.name)), - changefreq: 'weekly', - priority: '0.4' - }); - } - }); + utils = require('../public/src/utils'); - next(null, categoryUrls); - }); - }, - topicUrls: function(next) { - var topicUrls = []; - - async.waterfall([ - function(next) { - db.getSortedSetRevRange('topics:recent', 0, parseInt(meta.config.sitemapTopics, 10) || -1, next); - }, - function(tids, next) { - privileges.topics.filter('read', tids, 0, next); - }, - function(tids, next) { - topics.getTopicsFields(tids, ['tid', 'title', 'lastposttime'], next); - } - ], function(err, topics) { - if (err) { - return next(err); - } - - topics.forEach(function(topic) { - if (topic) { - topicUrls.push({ - url: '/topic/' + topic.tid + '/' + encodeURIComponent(utils.slugify(topic.title)), - lastmodISO: utils.toISOString(topic.lastposttime), - changefreq: 'daily', - priority: '0.6' - }); - } - }); +var sitemap = {}; - next(null, topicUrls); - }); - } - }, function(err, data) { - if (!err) { - returnUrls = data.categoryUrls.concat(data.topicUrls); +sitemap.render = function(callback) { + if (sitemap.obj && sitemap.obj.cache.length) { + return sitemap.obj.toXML(callback); + } + + async.parallel([ + sitemap.getStaticUrls, + sitemap.getDynamicUrls + ], function(err, urls) { + if (err) { + return callback(err); + } + + urls = urls[0].concat(urls[1]); + + sitemap.obj = sm.createSitemap({ + hostname: nconf.get('url'), + cacheTime: 1000 * 60 * 60, // Cached for 1 hour + urls: urls + }); + + sitemap.obj.toXML(callback); + }); +}; + +sitemap.getStaticUrls = function(callback) { + callback(null, [{ + url: '', + changefreq: 'weekly', + priority: '0.6' + }, { + url: '/recent', + changefreq: 'daily', + priority: '0.4' + }, { + url: '/users', + changefreq: 'daily', + priority: '0.4' + }]); +}; + +sitemap.getDynamicUrls = function(callback) { + var returnUrls = []; + + async.parallel({ + categoryUrls: function(next) { + var categoryUrls = []; + categories.getCategoriesByPrivilege(0, 'find', function(err, categoriesData) { + if (err) { + return next(err); } - callback(err, returnUrls); + categoriesData.forEach(function(category) { + if (category) { + categoryUrls.push({ + url: '/category/' + category.cid + '/' + encodeURIComponent(utils.slugify(category.name)), + changefreq: 'weekly', + priority: '0.4' + }); + } + }); + + next(null, categoryUrls); }); }, - render: function(callback) { - if (sitemap.obj !== undefined && sitemap.obj.cache.length) { - return sitemap.obj.toXML(callback); - } - - async.parallel([sitemap.getStaticUrls, sitemap.getDynamicUrls], function(err, urls) { - urls = urls[0].concat(urls[1]); - sitemap.obj = sm.createSitemap({ - hostname: nconf.get('url'), - cacheTime: 1000 * 60 * 60, // Cached for 1 hour - urls: urls + topicUrls: function(next) { + var topicUrls = []; + + async.waterfall([ + function(next) { + db.getSortedSetRevRange('topics:recent', 0, parseInt(meta.config.sitemapTopics, 10) || -1, next); + }, + function(tids, next) { + privileges.topics.filter('read', tids, 0, next); + }, + function(tids, next) { + topics.getTopicsFields(tids, ['tid', 'title', 'lastposttime'], next); + } + ], function(err, topics) { + if (err) { + return next(err); + } + + topics.forEach(function(topic) { + if (topic) { + topicUrls.push({ + url: '/topic/' + topic.tid + '/' + encodeURIComponent(utils.slugify(topic.title)), + lastmodISO: utils.toISOString(topic.lastposttime), + changefreq: 'daily', + priority: '0.6' + }); + } }); - sitemap.obj.toXML(callback); + next(null, topicUrls); }); } - }; + }, function(err, data) { + if (!err) { + returnUrls = data.categoryUrls.concat(data.topicUrls); + } + + callback(err, returnUrls); + }); +}; + + +sitemap.clearCache = function() { + if (sitemap.obj) { + sitemap.obj.clearCache(); + } +}; module.exports = sitemap; diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index b659397220..36efef49f9 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -175,6 +175,11 @@ SocketAdmin.settings.set = function(socket, data, callback) { meta.settings.set(data.hash, data.values, callback); }; +SocketAdmin.settings.clearSitemapCache = function(socket, data, callback) { + require('../sitemap').clearCache(); + callback(); +}; + SocketAdmin.email.test = function(socket, data, callback) { if (plugins.hasListeners('action:email.send')) { emailer.send('test', socket.uid, { diff --git a/src/user.js b/src/user.js index c7d8649d22..5776478c22 100644 --- a/src/user.js +++ b/src/user.js @@ -162,6 +162,7 @@ var async = require('async'), }; User.setUserField = function(uid, field, value, callback) { + callback = callback || function() {}; db.setObjectField('user:' + uid, field, value, function(err) { if (err) { return callback(err) @@ -172,6 +173,7 @@ var async = require('async'), }; User.setUserFields = function(uid, data, callback) { + callback = callback || function() {}; db.setObject('user:' + uid, data, function(err) { if (err) { return callback(err); diff --git a/src/views/admin/settings/web-crawler.tpl b/src/views/admin/settings/web-crawler.tpl index c8fb03b0ff..349b5f6664 100644 --- a/src/views/admin/settings/web-crawler.tpl +++ b/src/views/admin/settings/web-crawler.tpl @@ -26,8 +26,12 @@ - - +