Merge remote-tracking branch 'origin/master' into 0.7.0

v1.18.x
barisusakli 10 years ago
commit f988959989

@ -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') {

@ -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;

@ -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, {

@ -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);

@ -26,8 +26,12 @@
</label>
</div>
<label>Number of Topic to Display in Sitemap</label>
<input class="form-control" type="text" placeholder="" data-field="sitemapTopics" />
<div class="form-group">
<label>Number of Topic to Display in Sitemap</label>
<input class="form-control" type="text" placeholder="" data-field="sitemapTopics" />
</div>
<button id="clear-sitemap-cache" class="btn btn-warning">Clear Sitemap Cache</button>
</form>
</div>

Loading…
Cancel
Save