Skip to content

Node.js based forum software built for the modern web

fixed #4093

Julian Lamafbbb33878fb
diff --git a/src/meta/templates.js b/src/meta/templates.js
index d7e86591ec..cc6f6ad2cd 100644
--- a/src/meta/templates.js
+++ b/src/meta/templates.js
@@ -56,17 +56,13 @@ Templates.compile = function(callback) {
},
baseTpls: function(next) {
utils.walk(baseTemplatesPath, next);
- },
- themeTpls: function(next) {
- utils.walk(themeTemplatesPath, next);
}
}, function(err, data) {
var coreTpls = data.coreTpls,
baseTpls = data.baseTpls,
- themeTpls = data.themeTpls,
paths = {};
- if (!baseTpls || !themeTpls) {
+ if (!baseTpls) {
winston.warn('[meta/templates] Could not find base template files at: ' + baseTemplatesPath);
}
@@ -80,7 +76,7 @@ Templates.compile = function(callback) {
baseTpls.forEach(function(el, i) {
paths[baseTpls[i]] = path.join(baseTemplatesPath, baseTpls[i]);
});
-
+// console.log(pluginTemplates);
for (var tpl in pluginTemplates) {
if (pluginTemplates.hasOwnProperty(tpl)) {
diff --git a/src/plugins.js b/src/plugins.js
index 3e8669b08b..d1559b2b3d 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -152,16 +152,48 @@ var fs = require('fs'),
};
Plugins.getTemplates = function(callback) {
- var templates = {};
+ var templates = {},
+ tplName;
+
+ async.waterfall([
+ async.apply(db.getSortedSetRange, 'plugins:active', 0, -1),
+ function(plugins, next) {
+ var pluginBasePath = path.join(__dirname, '../node_modules');
+ var paths = plugins.map(function(plugin) {
+ return path.join(pluginBasePath, plugin);
+ });
+
+ // Filter out plugins with invalid paths
+ async.filter(paths, function(path, next) {
+ fs.access(path, fs.R_OK, function(err) {
+ next(!err);
+ });
+ }, function(paths) {
+ next(null, paths);
+ });
+ },
+ function(paths, next) {
+ async.map(paths, Plugins.loadPluginInfo, next);
+ }
+ ], function(err, plugins) {
+ if (err) {
+ return callback(err);
+ }
- Plugins.showInstalled(function(err, plugins) {
async.each(plugins, function(plugin, next) {
- if (plugin.id && plugin.active && (plugin.templates || plugin.id.startsWith('nodebb-theme-'))) {
+ if (plugin.templates || plugin.id.startsWith('nodebb-theme-')) {
+ winston.verbose('[plugins] Loading templates (' + plugin.id + ')');
var templatesPath = path.join(__dirname, '../node_modules', plugin.id, plugin.templates || 'templates');
utils.walk(templatesPath, function(err, pluginTemplates) {
if (pluginTemplates) {
pluginTemplates.forEach(function(pluginTemplate) {
- templates["/" + pluginTemplate.replace(templatesPath, '').substring(1)] = pluginTemplate;
+ tplName = "/" + pluginTemplate.replace(templatesPath, '').substring(1);
+
+ if (templates.hasOwnProperty(tplName)) {
+ winston.verbose('[plugins] ' + tplName + ' replaced by ' + plugin.id);
+ }
+
+ templates[tplName] = pluginTemplate;
});
} else {
winston.warn('[plugins/' + plugin.id + '] A templates directory was defined for this plugin, but was not found.');