|
|
|
@ -14,7 +14,9 @@ var utils = require('./../public/src/utils.js'),
|
|
|
|
|
if (!err) {
|
|
|
|
|
Meta.config = config;
|
|
|
|
|
callback();
|
|
|
|
|
} else winston.error(err);
|
|
|
|
|
} else {
|
|
|
|
|
winston.error(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
list: function (callback) {
|
|
|
|
@ -36,20 +38,24 @@ var utils = require('./../public/src/utils.js'),
|
|
|
|
|
},
|
|
|
|
|
set: function (field, value, callback) {
|
|
|
|
|
RDB.hset('config', field, value, function (err, res) {
|
|
|
|
|
if (callback)
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback(err, res);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
setOnEmpty: function (field, value, callback) {
|
|
|
|
|
this.get(field, function (err, curValue) {
|
|
|
|
|
if (!curValue) Meta.configs.set(field, value, callback);
|
|
|
|
|
else callback();
|
|
|
|
|
if (!curValue) {
|
|
|
|
|
Meta.configs.set(field, value, callback);
|
|
|
|
|
} else {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
remove: function (field) {
|
|
|
|
|
RDB.hdel('config', field);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.themes = {
|
|
|
|
|
get: function (callback) {
|
|
|
|
@ -57,7 +63,9 @@ var utils = require('./../public/src/utils.js'),
|
|
|
|
|
fs.readdir(themePath, function (err, files) {
|
|
|
|
|
async.filter(files, function (file, next) {
|
|
|
|
|
fs.stat(path.join(themePath, file), function (err, fileStat) {
|
|
|
|
|
if (err) next(false);
|
|
|
|
|
if (err) {
|
|
|
|
|
next(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next((fileStat.isDirectory() && file.slice(0, 13) === 'nodebb-theme-'));
|
|
|
|
|
});
|
|
|
|
@ -68,10 +76,15 @@ var utils = require('./../public/src/utils.js'),
|
|
|
|
|
if (fs.existsSync(config)) {
|
|
|
|
|
fs.readFile(config, function (err, file) {
|
|
|
|
|
var configObj = JSON.parse(file.toString());
|
|
|
|
|
if (!configObj.screenshot) configObj.screenshot = nconf.get('relative_path') + '/images/themes/default.png';
|
|
|
|
|
if (!configObj.screenshot) {
|
|
|
|
|
configObj.screenshot = nconf.get('relative_path') + '/images/themes/default.png';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next(err, configObj);
|
|
|
|
|
});
|
|
|
|
|
} else next();
|
|
|
|
|
} else {
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
}, function (err, themes) {
|
|
|
|
|
themes = themes.filter(function (theme) {
|
|
|
|
|
return (theme !== undefined);
|
|
|
|
@ -81,7 +94,7 @@ var utils = require('./../public/src/utils.js'),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.title = {
|
|
|
|
|
build: function (urlFragment, current_user, callback) {
|
|
|
|
@ -98,8 +111,11 @@ var utils = require('./../public/src/utils.js'),
|
|
|
|
|
}, function (err, values) {
|
|
|
|
|
var title;
|
|
|
|
|
|
|
|
|
|
if (err) title = Meta.config.title || 'NodeBB';
|
|
|
|
|
else title = (values.title ? values.title + ' | ' : '') + (Meta.config.title || 'NodeBB');
|
|
|
|
|
if (err) {
|
|
|
|
|
title = Meta.config.title || 'NodeBB';
|
|
|
|
|
} else {
|
|
|
|
|
title = (values.title ? values.title + ' | ' : '') + (Meta.config.title || 'NodeBB');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, title, values.notifCount);
|
|
|
|
|
});
|
|
|
|
@ -125,9 +141,85 @@ var utils = require('./../public/src/utils.js'),
|
|
|
|
|
require('./topics').getTopicField(tid, 'title', function (err, title) {
|
|
|
|
|
callback(null, title);
|
|
|
|
|
});
|
|
|
|
|
} else callback(null);
|
|
|
|
|
} else {
|
|
|
|
|
callback(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.js = {
|
|
|
|
|
scripts: [
|
|
|
|
|
'/vendor/jquery/js/jquery.js',
|
|
|
|
|
'/vendor/jquery/js/jquery-ui-1.10.3.custom.min.js',
|
|
|
|
|
'/vendor/jquery/js/jquery.timeago.js',
|
|
|
|
|
'/vendor/bootstrap/js/bootstrap.min.js',
|
|
|
|
|
'/src/app.js',
|
|
|
|
|
'/vendor/requirejs/require.js',
|
|
|
|
|
'/vendor/bootbox/bootbox.min.js',
|
|
|
|
|
'/src/templates.js',
|
|
|
|
|
'/src/ajaxify.js',
|
|
|
|
|
'/src/jquery.form.js',
|
|
|
|
|
'/src/utils.js'
|
|
|
|
|
],
|
|
|
|
|
minFile: path.join(__dirname, '..', 'public/src/nodebb.min.js'),
|
|
|
|
|
get: function (callback) {
|
|
|
|
|
var mtime,
|
|
|
|
|
jsPaths = this.scripts.map(function (jsPath) {
|
|
|
|
|
return path.join(__dirname, '..', '/public', jsPath);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
|
|
|
|
async.parallel({
|
|
|
|
|
mtime: function (next) {
|
|
|
|
|
async.map(jsPaths, fs.stat, function (err, stats) {
|
|
|
|
|
async.reduce(stats, 0, function (memo, item, callback) {
|
|
|
|
|
mtime = +new Date(item.mtime);
|
|
|
|
|
callback(null, mtime > memo ? mtime : memo);
|
|
|
|
|
}, next);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
minFile: function (next) {
|
|
|
|
|
if (!fs.existsSync(Meta.js.minFile)) {
|
|
|
|
|
winston.warn('No minified client-side library found');
|
|
|
|
|
return next(null, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs.stat(Meta.js.minFile, function (err, stat) {
|
|
|
|
|
next(err, +new Date(stat.mtime));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (results.minFile > results.mtime) {
|
|
|
|
|
winston.info('No changes to client-side libraries -- skipping minification');
|
|
|
|
|
callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]);
|
|
|
|
|
} else {
|
|
|
|
|
Meta.js.minify(function () {
|
|
|
|
|
callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
callback(null, this.scripts);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
minify: function (callback) {
|
|
|
|
|
var uglifyjs = require('uglify-js'),
|
|
|
|
|
jsPaths = this.scripts.map(function (jsPath) {
|
|
|
|
|
return path.join(__dirname, '..', '/public', jsPath);
|
|
|
|
|
}),
|
|
|
|
|
minified;
|
|
|
|
|
|
|
|
|
|
winston.info('Minifying client-side libraries');
|
|
|
|
|
minified = uglifyjs.minify(jsPaths);
|
|
|
|
|
fs.writeFile(Meta.js.minFile, minified.code, function (err) {
|
|
|
|
|
if (!err) {
|
|
|
|
|
winston.info('Minified client-side libraries');
|
|
|
|
|
callback();
|
|
|
|
|
} else {
|
|
|
|
|
winston.error('Problem minifying client-side libraries, exiting.');
|
|
|
|
|
process.exit();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}(exports));
|