Merge remote-tracking branch 'origin/master'

v1.18.x
Julian Lam 8 years ago
commit 3e6a779dbc

@ -1,16 +1,38 @@
'use strict';
(function (exports) {
/* globals define, utils, config */
// export the class if we are in a Node-like system.
if (typeof module === 'object' && module.exports === exports) {
exports = module.exports/* = SemVer*/;
(function (factory) {
if (typeof module === 'object' && module.exports) {
var relative_path = require('nconf').get('relative_path');
module.exports = factory(require('../utils'), require('templates.js'), require('string'), relative_path);
} else if (typeof define === 'function' && define.amd) {
define('helpers', ['string'], function (string) {
return factory(utils, templates, string, config.relative_path);
});
} else {
window.helpers = factory(utils, templates, window.String, config.relative_path);
}
}(function (utils, templates, S, relative_path) {
var helpers = {
displayMenuItem: displayMenuItem,
buildMetaTag: buildMetaTag,
buildLinkTag: buildLinkTag,
stringify: stringify,
escape: escape,
stripTags: stripTags,
generateCategoryBackground: generateCategoryBackground,
generateChildrenCategories: generateChildrenCategories,
generateTopicClass: generateTopicClass,
displayUserSearch: displayUserSearch,
membershipBtn: membershipBtn,
spawnPrivilegeStates: spawnPrivilegeStates,
localeToHTML: localeToHTML,
renderTopicImage: renderTopicImage,
renderDigestAvatar: renderDigestAvatar,
userAgentIcons: userAgentIcons,
register: register,
};
var helpers = exports;
helpers.displayMenuItem = function (data, index) {
function displayMenuItem(data, index) {
var item = data.navigation[index];
if (!item) {
return false;
@ -35,17 +57,17 @@
}
return true;
};
}
helpers.buildMetaTag = function (tag) {
function buildMetaTag(tag) {
var name = tag.name ? 'name="' + tag.name + '" ' : '';
var property = tag.property ? 'property="' + tag.property + '" ' : '';
var content = tag.content ? 'content="' + tag.content.replace(/\n/g, ' ') + '" ' : '';
return '<meta ' + name + property + content + '/>\n\t';
};
}
helpers.buildLinkTag = function (tag) {
function buildLinkTag(tag) {
var link = tag.link ? 'link="' + tag.link + '" ' : '';
var rel = tag.rel ? 'rel="' + tag.rel + '" ' : '';
var type = tag.type ? 'type="' + tag.type + '" ' : '';
@ -53,29 +75,22 @@
var sizes = tag.sizes ? 'sizes="' + tag.sizes + '" ' : '';
return '<link ' + link + rel + type + sizes + href + '/>\n\t';
};
}
helpers.stringify = function (obj) {
function stringify(obj) {
// Turns the incoming object into a JSON string
return JSON.stringify(obj).replace(/&/gm, '&amp;').replace(/</gm, '&lt;').replace(/>/gm, '&gt;').replace(/"/g, '&quot;');
};
}
helpers.escape = function (str) {
if (typeof utils !== 'undefined') {
function escape(str) {
return utils.escapeHTML(str);
}
return require('../utils').escapeHTML(str);
};
helpers.stripTags = function (str) {
if (typeof window !== 'undefined' && window.S) {
return window.S(String(str)).stripTags().s;
}
var S = require('string');
function stripTags(str) {
return S(String(str)).stripTags().s;
};
}
helpers.generateCategoryBackground = function (category) {
function generateCategoryBackground(category) {
if (!category) {
return '';
}
@ -97,11 +112,10 @@
}
return style.join('; ') + ';';
};
}
helpers.generateChildrenCategories = function (category) {
function generateChildrenCategories(category) {
var html = '';
var relative_path = (typeof config !== 'undefined' ? config.relative_path : require('nconf').get('relative_path'));
if (!category || !category.children || !category.children.length) {
return html;
}
@ -117,9 +131,9 @@
});
html = html ? ('<span class="category-children">' + html + '</span>') : html;
return html;
};
}
helpers.generateTopicClass = function (topic) {
function generateTopicClass(topic) {
var style = [];
if (topic.locked) {
@ -139,14 +153,14 @@
}
return style.join(' ');
};
}
helpers.displayUserSearch = function (data, allowGuestUserSearching) {
function displayUserSearch(data, allowGuestUserSearching) {
return data.loggedIn || allowGuestUserSearching === 'true';
};
}
// Groups helpers
helpers.membershipBtn = function (groupObj) {
function membershipBtn(groupObj) {
if (groupObj.isMember && groupObj.name !== 'administrators') {
return '<button class="btn btn-danger" data-action="leave" data-group="' + groupObj.displayName + '"><i class="fa fa-times"></i> [[groups:membership.leave-group]]</button>';
}
@ -159,9 +173,9 @@
return '<button class="btn btn-success" data-action="join" data-group="' + groupObj.displayName + '"><i class="fa fa-plus"></i> [[groups:membership.join-group]]</button>';
}
return '';
};
}
helpers.spawnPrivilegeStates = function (member, privileges) {
function spawnPrivilegeStates(member, privileges) {
var states = [];
for (var priv in privileges) {
if (privileges.hasOwnProperty(priv)) {
@ -174,21 +188,21 @@
return states.map(function (priv) {
return '<td class="text-center" data-privilege="' + priv.name + '"><input type="checkbox"' + (priv.state ? ' checked' : '') + (member === 'guests' && priv.name === 'groups:moderate' ? ' disabled="disabled"' : '') + ' /></td>';
}).join('');
};
}
helpers.localeToHTML = function (locale, fallback) {
function localeToHTML(locale, fallback) {
locale = locale || fallback || 'en-GB';
return locale.replace('_', '-');
};
}
helpers.renderTopicImage = function (topicObj) {
function renderTopicImage(topicObj) {
if (topicObj.thumb) {
return '<img src="' + topicObj.thumb + '" class="img-circle user-img" title="' + topicObj.user.username + '" />';
}
return '<img component="user/picture" data-uid="' + topicObj.user.uid + '" src="' + topicObj.user.picture + '" class="user-img" title="' + topicObj.user.username + '" />';
};
}
helpers.renderDigestAvatar = function (block) {
function renderDigestAvatar(block) {
if (block.teaser) {
if (block.teaser.user.picture) {
return '<img style="vertical-align: middle; width: 16px; height: 16px; padding-right: 1em;" src="' + block.teaser.user.picture + '" title="' + block.teaser.user.username + '" />';
@ -199,9 +213,9 @@
return '<img style="vertical-align: middle; width: 16px; height: 16px; padding-right: 1em;" src="' + block.user.picture + '" title="' + block.user.username + '" />';
}
return '<div style="width: 16px; height: 16px; line-height: 16px; font-size: 10px; margin-right: 1em; background-color: ' + block.user['icon:bgColor'] + '; color: white; text-align: center; display: inline-block;">' + block.user['icon:text'] + '</div>';
};
}
helpers.userAgentIcons = function (data) {
function userAgentIcons(data) {
var icons = '';
switch (data.platform) {
@ -251,29 +265,13 @@
}
return icons;
};
exports.register = function () {
var templates;
if (typeof module === 'object') {
templates = require('templates.js');
} else {
templates = window.templates;
}
function register() {
Object.keys(helpers).forEach(function (helperName) {
templates.registerHelper(helperName, helpers[helperName]);
});
};
// export the class if we are in a Node-like system.
if (typeof module === 'object' && module.exports === exports) {
exports = module.exports/* = SemVer*/;
} else if (typeof define === 'function' && define.amd) {
// Use the define() function if we're in AMD land
define('helpers', exports);
} else if (typeof window === 'object') {
window.helpers = exports;
}
}(typeof exports === 'object' ? exports : {}));
return helpers;
}));

@ -12,16 +12,16 @@ var Meta = module.exports;
Meta.reloadRequired = false;
require('./meta/configs')(Meta);
require('./meta/themes')(Meta);
require('./meta/js')(Meta);
require('./meta/css')(Meta);
require('./meta/sounds')(Meta);
require('./meta/settings')(Meta);
require('./meta/logs')(Meta);
require('./meta/errors')(Meta);
require('./meta/tags')(Meta);
require('./meta/dependencies')(Meta);
Meta.configs = require('./meta/configs');
Meta.themes = require('./meta/themes');
Meta.js = require('./meta/js');
Meta.css = require('./meta/css');
Meta.sounds = require('./meta/sounds');
Meta.settings = require('./meta/settings');
Meta.logs = require('./meta/logs');
Meta.errors = require('./meta/errors');
Meta.tags = require('./meta/tags');
Meta.dependencies = require('./meta/dependencies');
Meta.templates = require('./meta/templates');
Meta.blacklist = require('./meta/blacklist');
Meta.languages = require('./meta/languages');

@ -6,18 +6,19 @@ var nconf = require('nconf');
var db = require('../database');
var pubsub = require('../pubsub');
var Meta = require('../meta');
var cacheBuster = require('./cacheBuster');
module.exports = function (Meta) {
Meta.config = {};
Meta.configs = {};
var Configs = module.exports;
Meta.configs.init = function (callback) {
delete Meta.config;
Meta.config = {};
Configs.init = function (callback) {
Meta.config = null;
async.waterfall([
function (next) {
Meta.configs.list(next);
Configs.list(next);
},
function (config, next) {
cacheBuster.read(function (err, buster) {
@ -32,26 +33,26 @@ module.exports = function (Meta) {
});
},
], callback);
};
};
Meta.configs.list = function (callback) {
Configs.list = function (callback) {
db.getObject('config', function (err, config) {
config = config || {};
config.version = nconf.get('version');
config.registry = nconf.get('registry');
callback(err, config);
});
};
};
Meta.configs.get = function (field, callback) {
Configs.get = function (field, callback) {
db.getObjectField('config', field, callback);
};
};
Meta.configs.getFields = function (fields, callback) {
Configs.getFields = function (fields, callback) {
db.getObjectFields('config', fields, callback);
};
};
Meta.configs.set = function (field, value, callback) {
Configs.set = function (field, value, callback) {
callback = callback || function () {};
if (!field) {
return callback(new Error('[[error:invalid-data]]'));
@ -59,11 +60,11 @@ module.exports = function (Meta) {
var data = {};
data[field] = value;
Meta.configs.setMultiple(data, callback);
};
Configs.setMultiple(data, callback);
};
Meta.configs.setMultiple = function (data, callback) {
Configs.setMultiple = function (data, callback) {
async.waterfall([
function (next) {
processConfig(data, next);
@ -76,16 +77,16 @@ module.exports = function (Meta) {
setImmediate(next);
},
], callback);
};
};
function processConfig(data, callback) {
function processConfig(data, callback) {
if (data.customCSS) {
return saveRenderedCss(data, callback);
}
setImmediate(callback);
}
}
function saveRenderedCss(data, callback) {
function saveRenderedCss(data, callback) {
var less = require('less');
async.waterfall([
function (next) {
@ -98,28 +99,28 @@ module.exports = function (Meta) {
setImmediate(next);
},
], callback);
}
}
function updateConfig(config) {
function updateConfig(config) {
updateLocalConfig(config);
pubsub.publish('config:update', config);
}
}
function updateLocalConfig(config) {
function updateLocalConfig(config) {
for (var field in config) {
if (config.hasOwnProperty(field)) {
Meta.config[field] = config[field];
}
}
}
}
pubsub.on('config:update', function onConfigReceived(config) {
pubsub.on('config:update', function onConfigReceived(config) {
if (typeof config === 'object' && Meta.config) {
updateLocalConfig(config);
}
});
});
Meta.configs.setOnEmpty = function (values, callback) {
Configs.setOnEmpty = function (values, callback) {
async.waterfall([
function (next) {
db.getObject('config', next);
@ -139,9 +140,8 @@ module.exports = function (Meta) {
}
},
], callback);
};
};
Meta.configs.remove = function (field, callback) {
Configs.remove = function (field, callback) {
db.deleteObjectField('config', field, callback);
};
};

@ -11,10 +11,9 @@ var db = require('../database');
var file = require('../file');
var minifier = require('./minifier');
module.exports = function (Meta) {
Meta.css = {};
var CSS = module.exports;
var buildImports = {
var buildImports = {
client: function (source) {
return '@import "./theme";\n' + source + '\n' + [
'@import "font-awesome";',
@ -44,9 +43,9 @@ module.exports = function (Meta) {
return str.replace(/\//g, path.sep);
}).join('\n');
},
};
};
function filterMissingFiles(filepaths, callback) {
function filterMissingFiles(filepaths, callback) {
async.filter(filepaths, function (filepath, next) {
file.exists(path.join(__dirname, '../../node_modules', filepath), function (err, exists) {
if (!exists) {
@ -56,9 +55,9 @@ module.exports = function (Meta) {
next(err, exists);
});
}, callback);
}
}
function getImports(files, prefix, extension, callback) {
function getImports(files, prefix, extension, callback) {
var pluginDirectories = [];
var source = '';
@ -85,9 +84,9 @@ module.exports = function (Meta) {
}, function (err) {
callback(err, source);
});
}
}
function getBundleMetadata(target, callback) {
function getBundleMetadata(target, callback) {
var paths = [
path.join(__dirname, '../../node_modules'),
path.join(__dirname, '../../public/vendor/fontawesome/less'),
@ -147,9 +146,9 @@ module.exports = function (Meta) {
callback(null, { paths: paths, imports: imports });
});
}
}
Meta.css.buildBundle = function (target, fork, callback) {
CSS.buildBundle = function (target, fork, callback) {
async.waterfall([
function (next) {
getBundleMetadata(target, next);
@ -164,5 +163,4 @@ module.exports = function (Meta) {
fs.writeFile(path.join(__dirname, '../../build/public', filename), bundle.code, next);
},
], callback);
};
};

@ -9,17 +9,17 @@ require('colors');
var pkg = require('../../package.json');
module.exports = function (Meta) {
Meta.dependencies = {};
var depsMissing = false;
var depsOutdated = false;
var Dependencies = module.exports;
Meta.dependencies.check = function (callback) {
var depsMissing = false;
var depsOutdated = false;
Dependencies.check = function (callback) {
var modules = Object.keys(pkg.dependencies);
winston.verbose('Checking dependencies for outdated modules');
async.each(modules, Meta.dependencies.checkModule, function (err) {
async.each(modules, Dependencies.checkModule, function (err) {
if (err) {
return callback(err);
}
@ -32,9 +32,9 @@ module.exports = function (Meta) {
callback(null);
}
});
};
};
Meta.dependencies.checkModule = function (moduleName, callback) {
Dependencies.checkModule = function (moduleName, callback) {
fs.readFile(path.join(__dirname, '../../node_modules/', moduleName, 'package.json'), {
encoding: 'utf-8',
}, function (err, pkgData) {
@ -47,14 +47,14 @@ module.exports = function (Meta) {
return callback(err);
}
pkgData = Meta.dependencies.parseModuleData(moduleName, pkgData);
pkgData = Dependencies.parseModuleData(moduleName, pkgData);
var satisfies = Meta.dependencies.doesSatisfy(pkgData, pkg.dependencies[moduleName]);
var satisfies = Dependencies.doesSatisfy(pkgData, pkg.dependencies[moduleName]);
callback(null, satisfies);
});
};
};
Meta.dependencies.parseModuleData = function (moduleName, pkgData) {
Dependencies.parseModuleData = function (moduleName, pkgData) {
try {
pkgData = JSON.parse(pkgData);
} catch (e) {
@ -63,9 +63,9 @@ module.exports = function (Meta) {
return null;
}
return pkgData;
};
};
Meta.dependencies.doesSatisfy = function (moduleData, packageJSONVersion) {
Dependencies.doesSatisfy = function (moduleData, packageJSONVersion) {
if (!moduleData) {
return false;
}
@ -77,5 +77,4 @@ module.exports = function (Meta) {
depsOutdated = true;
}
return satisfies;
};
};

@ -8,16 +8,15 @@ var cronJob = require('cron').CronJob;
var db = require('../database');
var analytics = require('../analytics');
module.exports = function (Meta) {
Meta.errors = {};
var Errors = module.exports;
var counters = {};
var counters = {};
new cronJob('0 * * * * *', function () {
Meta.errors.writeData();
}, null, true);
new cronJob('0 * * * * *', function () {
Errors.writeData();
}, null, true);
Meta.errors.writeData = function () {
Errors.writeData = function () {
var dbQueue = [];
if (Object.keys(counters).length > 0) {
for (var key in counters) {
@ -32,9 +31,9 @@ module.exports = function (Meta) {
}
});
}
};
};
Meta.errors.log404 = function (route, callback) {
Errors.log404 = function (route, callback) {
callback = callback || function () {};
if (!route) {
return setImmediate(callback);
@ -44,9 +43,9 @@ module.exports = function (Meta) {
counters[route] = counters[route] || 0;
counters[route] += 1;
setImmediate(callback);
};
};
Meta.errors.get = function (escape, callback) {
Errors.get = function (escape, callback) {
async.waterfall([
function (next) {
db.getSortedSetRevRangeWithScores('errors:404', 0, 199, next);
@ -60,9 +59,8 @@ module.exports = function (Meta) {
next(null, data);
},
], callback);
};
};
Meta.errors.clear = function (callback) {
Errors.clear = function (callback) {
db.delete('errors:404', callback);
};
};

@ -10,10 +10,9 @@ var file = require('../file');
var plugins = require('../plugins');
var minifier = require('./minifier');
module.exports = function (Meta) {
Meta.js = {};
var JS = module.exports;
Meta.js.scripts = {
JS.scripts = {
base: [
'node_modules/jquery/dist/jquery.js',
'node_modules/socket.io-client/dist/socket.io.js',
@ -87,11 +86,11 @@ module.exports = function (Meta) {
'zxcvbn.js': 'node_modules/zxcvbn/dist/zxcvbn.js',
ace: 'node_modules/ace-builds/src-min',
},
};
};
var basePath = path.resolve(__dirname, '../..');
var basePath = path.resolve(__dirname, '../..');
function minifyModules(modules, fork, callback) {
function minifyModules(modules, fork, callback) {
var moduleDirs = modules.reduce(function (prev, mod) {
var dir = path.resolve(path.dirname(mod.destPath));
if (prev.indexOf(dir) === -1) {
@ -126,10 +125,10 @@ module.exports = function (Meta) {
},
], callback);
});
}
}
function linkModules(callback) {
var modules = Meta.js.scripts.modules;
function linkModules(callback) {
var modules = JS.scripts.modules;
async.eachLimit(Object.keys(modules), 1000, function (relPath, next) {
var srcPath = path.join(__dirname, '../../', modules[relPath]);
@ -165,14 +164,14 @@ module.exports = function (Meta) {
}
});
}, callback);
}
}
var moduleDirs = ['modules', 'admin', 'client'];
var moduleDirs = ['modules', 'admin', 'client'];
function getModuleList(callback) {
var modules = Object.keys(Meta.js.scripts.modules).map(function (relPath) {
function getModuleList(callback) {
var modules = Object.keys(JS.scripts.modules).map(function (relPath) {
return {
srcPath: path.join(__dirname, '../../', Meta.js.scripts.modules[relPath]),
srcPath: path.join(__dirname, '../../', JS.scripts.modules[relPath]),
destPath: path.join(__dirname, '../../build/public/src/modules', relPath),
};
});
@ -225,9 +224,9 @@ module.exports = function (Meta) {
}, function (err) {
callback(err, moduleFiles);
});
}
}
function clearModules(callback) {
function clearModules(callback) {
var builtPaths = moduleDirs.map(function (p) {
return path.join(__dirname, '../../build/public/src', p);
});
@ -236,9 +235,9 @@ module.exports = function (Meta) {
}, function (err) {
callback(err);
});
}
}
Meta.js.buildModules = function (fork, callback) {
JS.buildModules = function (fork, callback) {
async.waterfall([
clearModules,
function (next) {
@ -252,9 +251,9 @@ module.exports = function (Meta) {
minifyModules(modules, fork, next);
},
], callback);
};
};
Meta.js.linkStatics = function (callback) {
JS.linkStatics = function (callback) {
rimraf(path.join(__dirname, '../../build/public/plugins'), function (err) {
if (err) {
return callback(err);
@ -272,9 +271,9 @@ module.exports = function (Meta) {
});
}, callback);
});
};
};
function getBundleScriptList(target, callback) {
function getBundleScriptList(target, callback) {
var pluginDirectories = [];
if (target === 'admin') {
@ -303,10 +302,10 @@ module.exports = function (Meta) {
return callback(err);
}
var scripts = Meta.js.scripts.base.concat(pluginScripts);
var scripts = JS.scripts.base.concat(pluginScripts);
if (target === 'client' && global.env !== 'development') {
scripts = scripts.concat(Meta.js.scripts.rjs);
scripts = scripts.concat(JS.scripts.rjs);
}
scripts = scripts.map(function (script) {
@ -319,9 +318,9 @@ module.exports = function (Meta) {
callback(null, scripts);
});
}
}
Meta.js.buildBundle = function (target, fork, callback) {
JS.buildBundle = function (target, fork, callback) {
var fileNames = {
client: 'nodebb.min.js',
admin: 'acp.min.js',
@ -342,9 +341,8 @@ module.exports = function (Meta) {
}, minify, fork, next);
},
], callback);
};
};
Meta.js.killMinifier = function () {
JS.killMinifier = function () {
minifier.killAll();
};
};

@ -3,18 +3,16 @@
var path = require('path');
var fs = require('fs');
module.exports = function (Meta) {
Meta.logs = {
path: path.join(__dirname, '..', '..', 'logs', 'output.log'),
};
var Logs = module.exports;
Meta.logs.get = function (callback) {
fs.readFile(Meta.logs.path, {
Logs.path = path.join(__dirname, '..', '..', 'logs', 'output.log');
Logs.get = function (callback) {
fs.readFile(Logs.path, {
encoding: 'utf-8',
}, callback);
};
};
Meta.logs.clear = function (callback) {
fs.truncate(Meta.logs.path, 0, callback);
};
Logs.clear = function (callback) {
fs.truncate(Logs.path, 0, callback);
};

@ -4,21 +4,21 @@ var async = require('async');
var db = require('../database');
var plugins = require('../plugins');
var Meta = require('../meta');
module.exports = function (Meta) {
Meta.settings = {};
var Settings = module.exports;
Meta.settings.get = function (hash, callback) {
Settings.get = function (hash, callback) {
db.getObject('settings:' + hash, function (err, settings) {
callback(err, settings || {});
});
};
};
Meta.settings.getOne = function (hash, field, callback) {
Settings.getOne = function (hash, field, callback) {
db.getObjectField('settings:' + hash, field, callback);
};
};
Meta.settings.set = function (hash, values, callback) {
Settings.set = function (hash, values, callback) {
async.waterfall([
function (next) {
db.setObject('settings:' + hash, values, next);
@ -33,13 +33,13 @@ module.exports = function (Meta) {
next();
},
], callback);
};
};
Meta.settings.setOne = function (hash, field, value, callback) {
Settings.setOne = function (hash, field, value, callback) {
db.setObjectField('settings:' + hash, field, value, callback);
};
};
Meta.settings.setOnEmpty = function (hash, values, callback) {
Settings.setOnEmpty = function (hash, values, callback) {
async.waterfall([
function (next) {
db.getObject('settings:' + hash, next);
@ -60,5 +60,4 @@ module.exports = function (Meta) {
}
},
], callback);
};
};

@ -9,14 +9,14 @@ var async = require('async');
var file = require('../file');
var plugins = require('../plugins');
var user = require('../user');
var Meta = require('../meta');
var soundsPath = path.join(__dirname, '../../build/public/sounds');
var uploadsPath = path.join(__dirname, '../../public/uploads/sounds');
module.exports = function (Meta) {
Meta.sounds = {};
var Sounds = module.exports;
Meta.sounds.addUploads = function addUploads(callback) {
Sounds.addUploads = function addUploads(callback) {
fs.readdir(uploadsPath, function (err, files) {
if (err) {
if (err.code !== 'ENOENT') {
@ -52,10 +52,10 @@ module.exports = function (Meta) {
callback();
});
};
};
Meta.sounds.build = function build(callback) {
Meta.sounds.addUploads(function (err) {
Sounds.build = function build(callback) {
Sounds.addUploads(function (err) {
if (err) {
return callback(err);
}
@ -93,11 +93,11 @@ module.exports = function (Meta) {
callback(err);
});
});
};
};
var keys = ['chat-incoming', 'chat-outgoing', 'notification'];
var keys = ['chat-incoming', 'chat-outgoing', 'notification'];
Meta.sounds.getUserSoundMap = function getUserSoundMap(uid, callback) {
Sounds.getUserSoundMap = function getUserSoundMap(uid, callback) {
async.parallel({
defaultMapping: function (next) {
Meta.configs.getFields(keys, next);
@ -129,5 +129,4 @@ module.exports = function (Meta) {
callback(null, soundMapping);
});
};
};

@ -4,12 +4,13 @@ var nconf = require('nconf');
var validator = require('validator');
var async = require('async');
var winston = require('winston');
var plugins = require('../plugins');
var Meta = require('../meta');
module.exports = function (Meta) {
Meta.tags = {};
var Tags = module.exports;
Meta.tags.parse = function (req, meta, link, callback) {
Tags.parse = function (req, meta, link, callback) {
async.parallel({
tags: function (next) {
var defaultTags = [{
@ -145,9 +146,9 @@ module.exports = function (Meta) {
link: link,
});
});
};
};
function addIfNotExists(meta, keyName, tagName, value) {
function addIfNotExists(meta, keyName, tagName, value) {
var exists = false;
meta.forEach(function (tag) {
if (tag[keyName] === tagName) {
@ -162,5 +163,4 @@ module.exports = function (Meta) {
data[keyName] = tagName;
meta.push(data);
}
}
};
}

@ -9,12 +9,12 @@ var async = require('async');
var file = require('../file');
var db = require('../database');
var Meta = require('../meta');
var events = require('../events');
module.exports = function (Meta) {
Meta.themes = {};
var Themes = module.exports;
Meta.themes.get = function (callback) {
Themes.get = function (callback) {
var themePath = nconf.get('themes_path');
if (typeof themePath !== 'string') {
return callback(null, []);
@ -72,9 +72,9 @@ module.exports = function (Meta) {
next(null, themes);
},
], callback);
};
};
Meta.themes.set = function (data, callback) {
Themes.set = function (data, callback) {
var themeData = {
'theme:type': data.type,
'theme:id': data.id,
@ -113,7 +113,7 @@ module.exports = function (Meta) {
Meta.configs.setMultiple(themeData, next);
// Re-set the themes path (for when NodeBB is reloaded)
Meta.themes.setPath(config);
Themes.setPath(config);
},
function (next) {
events.log({
@ -135,13 +135,13 @@ module.exports = function (Meta) {
}, callback);
break;
}
};
};
Meta.themes.setupPaths = function (callback) {
Themes.setupPaths = function (callback) {
async.waterfall([
function (next) {
async.parallel({
themesData: Meta.themes.get,
themesData: Themes.get,
currentThemeId: function (next) {
db.getObjectField('config', 'theme:id', next);
},
@ -162,13 +162,13 @@ module.exports = function (Meta) {
return callback(new Error('[[error:theme-not-found]]'));
}
Meta.themes.setPath(themeObj);
Themes.setPath(themeObj);
next();
},
], callback);
};
};
Meta.themes.setPath = function (themeObj) {
Themes.setPath = function (themeObj) {
// Theme's templates path
var themePath = nconf.get('base_templates_path');
var fallback = path.join(nconf.get('themes_path'), themeObj.id, 'templates');
@ -181,5 +181,4 @@ module.exports = function (Meta) {
nconf.set('theme_templates_path', themePath);
nconf.set('theme_config', path.join(nconf.get('themes_path'), themeObj.id, 'theme.json'));
};
};

Loading…
Cancel
Save