mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
Merge branch 'master' of github.com:psychobunny/node-forum
This commit is contained in:
6
app.js
6
app.js
@@ -1,5 +1,5 @@
|
|||||||
var categories = require('./src/categories.js'),
|
var categories = require('./src/categories.js'),
|
||||||
templates = require('./src/templates.js'),
|
templates = require('./public/src/templates.js'),
|
||||||
webserver = require('./src/webserver.js'),
|
webserver = require('./src/webserver.js'),
|
||||||
websockets = require('./src/websockets.js'),
|
websockets = require('./src/websockets.js'),
|
||||||
fs = require('fs');
|
fs = require('fs');
|
||||||
@@ -7,11 +7,15 @@ var categories = require('./src/categories.js'),
|
|||||||
DEVELOPMENT = true;
|
DEVELOPMENT = true;
|
||||||
|
|
||||||
global.configuration = {};
|
global.configuration = {};
|
||||||
|
global.templates = {};
|
||||||
|
|
||||||
(function(config) {
|
(function(config) {
|
||||||
config['ROOT_DIRECTORY'] = __dirname;
|
config['ROOT_DIRECTORY'] = __dirname;
|
||||||
|
|
||||||
templates.init();
|
templates.init();
|
||||||
|
templates.ready(function() {
|
||||||
|
webserver.init();
|
||||||
|
});
|
||||||
|
|
||||||
//setup scripts to be moved outside of the app in future.
|
//setup scripts to be moved outside of the app in future.
|
||||||
function setup_categories() {
|
function setup_categories() {
|
||||||
|
|||||||
@@ -699,4 +699,11 @@ body .navbar .nodebb-inline-block {
|
|||||||
|
|
||||||
#right-menu{
|
#right-menu{
|
||||||
float:right;
|
float:right;
|
||||||
|
}
|
||||||
|
|
||||||
|
#admin-redis-info {
|
||||||
|
span {
|
||||||
|
display:inline-block;
|
||||||
|
width:200px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ var ajaxify = {};
|
|||||||
tpl_url = url;
|
tpl_url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (templates[tpl_url]) {
|
if (templates[tpl_url] && !templates.force_refresh(tpl_url)) {
|
||||||
if (quiet !== true) {
|
if (quiet !== true) {
|
||||||
window.history.pushState({
|
window.history.pushState({
|
||||||
"url": url
|
"url": url
|
||||||
|
|||||||
@@ -1,8 +1,21 @@
|
|||||||
var templates = {};
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
(function (module) {
|
||||||
|
|
||||||
var ready_callback,
|
var ready_callback,
|
||||||
config = {};
|
config = {},
|
||||||
|
templates,
|
||||||
|
fs = null;
|
||||||
|
|
||||||
|
module.exports = templates = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs = require('fs');
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
templates.force_refresh = function(tpl) {
|
||||||
|
return !!config.force_refresh[tpl];
|
||||||
|
}
|
||||||
|
|
||||||
templates.get_custom_map = function(tpl) {
|
templates.get_custom_map = function(tpl) {
|
||||||
if (config['custom_mapping'] && tpl) {
|
if (config['custom_mapping'] && tpl) {
|
||||||
@@ -12,11 +25,11 @@ var templates = {};
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
templates.ready = function(callback) {
|
templates.ready = function(callback) {
|
||||||
//quick implementation because introducing a lib to handle several async callbacks
|
|
||||||
if (callback == null && ready_callback) ready_callback();
|
if (callback == null && ready_callback) ready_callback();
|
||||||
else ready_callback = callback;
|
else ready_callback = callback;
|
||||||
};
|
};
|
||||||
@@ -26,51 +39,82 @@ var templates = {};
|
|||||||
template.html = raw_tpl;
|
template.html = raw_tpl;
|
||||||
template.parse = parse;
|
template.parse = parse;
|
||||||
template.blocks = {};
|
template.blocks = {};
|
||||||
|
|
||||||
return template;
|
return template;
|
||||||
};
|
};
|
||||||
|
|
||||||
function loadTemplates(templatesToLoad) {
|
function loadTemplates(templatesToLoad) {
|
||||||
var timestamp = new Date().getTime();
|
function loadServer() {
|
||||||
var loaded = templatesToLoad.length;
|
var loaded = templatesToLoad.length;
|
||||||
|
|
||||||
$.getJSON('/templates/config.json', function(data) {
|
for (var t in templatesToLoad) {
|
||||||
config = data;
|
(function(file) {
|
||||||
});
|
fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + file + '.tpl', function(err, html) {
|
||||||
|
var template = function() {
|
||||||
|
this.toString = function() {
|
||||||
|
return this.html;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
for (var t in templatesToLoad) {
|
template.prototype.file = file;
|
||||||
(function(file) {
|
template.prototype.parse = parse;
|
||||||
$.get('/templates/' + file + '.tpl?v=' + timestamp, function(html) {
|
template.prototype.html = String(html);
|
||||||
|
|
||||||
var template = function() {
|
global.templates[file] = new template;
|
||||||
this.toString = function() {
|
|
||||||
return this.html;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
template.prototype.parse = parse;
|
loaded--;
|
||||||
template.prototype.html = String(html);
|
if (loaded == 0) templates.ready();
|
||||||
template.prototype.blocks = {};
|
});
|
||||||
|
}(templatesToLoad[t]));
|
||||||
templates[file] = new template;
|
}
|
||||||
|
|
||||||
loaded--;
|
|
||||||
if (loaded == 0) templates.ready();
|
|
||||||
}).fail(function() {
|
|
||||||
loaded--;
|
|
||||||
if (loaded == 0) templates.ready();
|
|
||||||
});
|
|
||||||
}(templatesToLoad[t]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadClient() {
|
||||||
|
var timestamp = new Date().getTime();
|
||||||
|
var loaded = templatesToLoad.length;
|
||||||
|
|
||||||
|
jQuery.getJSON('/templates/config.json', function(data) {
|
||||||
|
config = data;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (var t in templatesToLoad) {
|
||||||
|
(function(file) {
|
||||||
|
jQuery.get('/templates/' + file + '.tpl?v=' + timestamp, function(html) {
|
||||||
|
|
||||||
|
var template = function() {
|
||||||
|
this.toString = function() {
|
||||||
|
return this.html;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template.prototype.parse = parse;
|
||||||
|
template.prototype.html = String(html);
|
||||||
|
template.prototype.blocks = {};
|
||||||
|
|
||||||
|
templates[file] = new template;
|
||||||
|
|
||||||
|
loaded--;
|
||||||
|
if (loaded == 0) templates.ready();
|
||||||
|
}).fail(function() {
|
||||||
|
loaded--;
|
||||||
|
if (loaded == 0) templates.ready();
|
||||||
|
});
|
||||||
|
}(templatesToLoad[t]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs === null) loadClient();
|
||||||
|
else loadServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function init() {
|
templates.init = function() {
|
||||||
loadTemplates([
|
loadTemplates([
|
||||||
'header', 'footer', 'register', 'home', 'topic','account', 'category', 'users', 'accountedit', 'friends',
|
'header', 'footer', 'register', 'home', 'topic','account', 'category', 'users', 'accountedit', 'friends',
|
||||||
'login', 'reset', 'reset_code', 'account',
|
'login', 'reset', 'reset_code', 'account',
|
||||||
'confirm', '403',
|
'confirm', '403', 'logout',
|
||||||
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext',
|
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext',
|
||||||
'admin/index', 'admin/categories', 'admin/users', 'admin/topics', 'admin/settings', 'admin/themes', 'admin/twitter', 'admin/facebook', 'admin/gplus'
|
'admin/index', 'admin/categories', 'admin/users', 'admin/topics', 'admin/settings', 'admin/themes', 'admin/twitter', 'admin/facebook', 'admin/gplus', 'admin/redis'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,9 +201,17 @@ var templates = {};
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
|
if ('undefined' !== typeof window) {
|
||||||
|
window.templates = module.exports;
|
||||||
|
templates.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
})('undefined' === typeof module ? {module:{exports:{}}} : module)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
|
||||||
|
|
||||||
function load_template(callback, url, template) {
|
function load_template(callback, url, template) {
|
||||||
var location = document.location || window.location,
|
var location = document.location || window.location,
|
||||||
@@ -184,4 +236,6 @@ function load_template(callback, url, template) {
|
|||||||
document.getElementById('content').innerHTML = templates[tpl].parse(JSON.parse(data));
|
document.getElementById('content').innerHTML = templates[tpl].parse(JSON.parse(data));
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,8 @@
|
|||||||
<li class=''><a href='/admin/topics'><i class='icon-book'></i> Topics</a></li>
|
<li class=''><a href='/admin/topics'><i class='icon-book'></i> Topics</a></li>
|
||||||
<li class=''><a href='/admin/themes'><i class='icon-th'></i> Themes</a></li>
|
<li class=''><a href='/admin/themes'><i class='icon-th'></i> Themes</a></li>
|
||||||
<li class=''><a href='/admin/settings'><i class='icon-cogs'></i> Settings</a></li>
|
<li class=''><a href='/admin/settings'><i class='icon-cogs'></i> Settings</a></li>
|
||||||
|
<li class=''><a href='/admin/redis'><i class='icon-hdd'></i> Redis</a></li>
|
||||||
|
|
||||||
<li class="nav-header">Social Authentication</li>
|
<li class="nav-header">Social Authentication</li>
|
||||||
<li class=''><a href='/admin/twitter'><i class='icon-twitter'></i>Twitter</a></li>
|
<li class=''><a href='/admin/twitter'><i class='icon-twitter'></i>Twitter</a></li>
|
||||||
<li class=''><a href='/admin/facebook'><i class='icon-facebook'></i>Facebook</a></li>
|
<li class=''><a href='/admin/facebook'><i class='icon-facebook'></i>Facebook</a></li>
|
||||||
|
|||||||
23
public/templates/admin/redis.tpl
Normal file
23
public/templates/admin/redis.tpl
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<h1>Redis</h1>
|
||||||
|
<hr />
|
||||||
|
<div id="admin-redis-info">
|
||||||
|
<span>Redis Version</span> <span class="text-right">{redis_version}</span><br/>
|
||||||
|
<hr/>
|
||||||
|
<span>Uptime in Seconds</span> <span class="text-right">{uptime_in_seconds}</span><br/>
|
||||||
|
<span>Uptime in Days</span> <span class="text-right">{uptime_in_days}</span><br/>
|
||||||
|
<hr/>
|
||||||
|
<span>Connected Clients</span> <span class="text-right">{connected_clients}</span><br/>
|
||||||
|
<span>Connected Slaves</span> <span class="text-right">{connected_slaves}</span><br/>
|
||||||
|
<span>Blocked Clients</span> <span class="text-right">{blocked_clients}</span><br/>
|
||||||
|
<hr/>
|
||||||
|
|
||||||
|
<span>Used Memory</span> <span class="text-right">{used_memory_human}</span><br/>
|
||||||
|
<span>Memory Fragmentation Ratio</span> <span class="text-right">{mem_fragmentation_ratio}</span><br/>
|
||||||
|
<hr/>
|
||||||
|
<span>Total Connections Received</span> <span class="text-right">{total_connections_received}</span><br/>
|
||||||
|
<span>Total Commands Processed</span> <span class="text-right">{total_commands_processed}</span><br/>
|
||||||
|
<hr/>
|
||||||
|
<span>Keyspace Hits</span> <span class="text-right">{keyspace_hits}</span><br/>
|
||||||
|
<span>Keyspace Misses</span> <span class="text-right">{keyspace_misses}</span><br/>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -9,5 +9,8 @@
|
|||||||
"latest": "category",
|
"latest": "category",
|
||||||
"popular": "category",
|
"popular": "category",
|
||||||
"active": "category"
|
"active": "category"
|
||||||
|
},
|
||||||
|
"force_refresh": {
|
||||||
|
"logout": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
|
|
||||||
var user = require('./../user.js'),
|
var user = require('./../user.js'),
|
||||||
topics = require('./../topics.js');
|
topics = require('./../topics.js'),
|
||||||
|
RDB = require('./../redis.js');
|
||||||
|
|
||||||
(function(Admin) {
|
(function(Admin) {
|
||||||
Admin.create_routes = function(app) {
|
Admin.create_routes = function(app) {
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var routes = ['categories', 'users', 'topics', 'settings', 'themes', 'twitter', 'facebook', 'gplus'];
|
var routes = ['categories', 'users', 'topics', 'settings', 'themes', 'twitter', 'facebook', 'gplus', 'redis'];
|
||||||
|
|
||||||
for (var i=0, ii=routes.length; i<ii; i++) {
|
for (var i=0, ii=routes.length; i<ii; i++) {
|
||||||
(function(route) {
|
(function(route) {
|
||||||
app.get('/admin/' + route, function(req, res) {
|
app.get('/admin/' + route, function(req, res) {
|
||||||
|
console.log("derp " +route);
|
||||||
res.send(templates['admin/header'] + app.create_route('admin/' + route) + templates['admin/footer']);
|
res.send(templates['admin/header'] + app.create_route('admin/' + route) + templates['admin/footer']);
|
||||||
});
|
});
|
||||||
}(routes[i]));
|
}(routes[i]));
|
||||||
@@ -52,6 +54,31 @@ var user = require('./../user.js'),
|
|||||||
res.send(JSON.stringify(data));
|
res.send(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case 'redis':
|
||||||
|
console.log('going into redis');
|
||||||
|
RDB.info(function(err, data) {
|
||||||
|
data = data.split("\r\n");
|
||||||
|
var finalData = {};
|
||||||
|
|
||||||
|
for(var i in data) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
data[i] = data[i].replace(/:/,"\":\"");
|
||||||
|
var json = "{\"" + data[i] + "\"}";
|
||||||
|
|
||||||
|
var jsonObject = JSON.parse(json);
|
||||||
|
for(var key in jsonObject) {
|
||||||
|
finalData[key] = jsonObject[key];
|
||||||
|
}
|
||||||
|
}catch(err){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(finalData);
|
||||||
|
res.send(JSON.stringify(finalData));
|
||||||
|
});
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
res.send('{}');
|
res.send('{}');
|
||||||
}
|
}
|
||||||
|
|||||||
114
src/templates.js
114
src/templates.js
@@ -1,114 +0,0 @@
|
|||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
|
|
||||||
// to be deprecated in favour of client-side only templates.
|
|
||||||
|
|
||||||
(function(Templates) {
|
|
||||||
|
|
||||||
global.templates = {};
|
|
||||||
|
|
||||||
function loadTemplates(templatesToLoad) {
|
|
||||||
for (var t in templatesToLoad) {
|
|
||||||
(function(file) {
|
|
||||||
fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + file + '.tpl', function(err, html) {
|
|
||||||
var template = function() {
|
|
||||||
this.toString = function() {
|
|
||||||
return this.html;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
template.prototype.file = file;
|
|
||||||
template.prototype.parse = parse;
|
|
||||||
template.prototype.html = String(html);
|
|
||||||
|
|
||||||
global.templates[file] = new template;
|
|
||||||
});
|
|
||||||
}(templatesToLoad[t]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Templates.init = function() {
|
|
||||||
loadTemplates([
|
|
||||||
'header', 'footer', 'register', 'home', 'topic', 'account', 'friends',
|
|
||||||
'login', 'reset', 'reset_code',
|
|
||||||
'403', 'logout',
|
|
||||||
'admin/header', 'admin/footer', 'admin/index',
|
|
||||||
'emails/header', 'emails/footer',
|
|
||||||
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
var parse = function(data) {
|
|
||||||
function replace(key, value, template) {
|
|
||||||
var searchRegex = new RegExp('{' + key + '}', 'g');
|
|
||||||
return template.replace(searchRegex, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeRegex(block) {
|
|
||||||
return new RegExp("<!-- BEGIN " + block + " -->[^]*<!-- END " + block + " -->", 'g');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBlock(regex, block, template) {
|
|
||||||
data = template.match(regex);
|
|
||||||
if (data == null) return;
|
|
||||||
|
|
||||||
data = data[0]
|
|
||||||
.replace("<!-- BEGIN " + block + " -->", "")
|
|
||||||
.replace("<!-- END " + block + " -->", "");
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setBlock(regex, block, template) {
|
|
||||||
return template.replace(regex, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
var template = this.html, regex, block;
|
|
||||||
|
|
||||||
return (function parse(data, namespace, template) {
|
|
||||||
console.log(this.file + ' is being called on server side. Templates will be deprecated soon');
|
|
||||||
if (Object.keys(data).length == 0) {
|
|
||||||
regex = makeRegex('[^]*');
|
|
||||||
template = template.replace(regex, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var d in data) {
|
|
||||||
if (data.hasOwnProperty(d)) {
|
|
||||||
if (data[d] instanceof String || data[d] === null) {
|
|
||||||
continue;
|
|
||||||
} else if (data[d].constructor == Array) {
|
|
||||||
namespace += d;
|
|
||||||
|
|
||||||
regex = makeRegex(d),
|
|
||||||
block = getBlock(regex, namespace, template)
|
|
||||||
if (block == null) continue;
|
|
||||||
|
|
||||||
var numblocks = data[d].length - 1, i = 0, result = "";
|
|
||||||
|
|
||||||
do {
|
|
||||||
result += parse(data[d][i], namespace + '.', block);
|
|
||||||
} while (i++ < numblocks);
|
|
||||||
|
|
||||||
template = setBlock(regex, result, template);
|
|
||||||
|
|
||||||
} else if (data[d] instanceof Object) {
|
|
||||||
namespace += d + '.';
|
|
||||||
|
|
||||||
regex = makeRegex(d),
|
|
||||||
block = getBlock(regex, namespace, template)
|
|
||||||
if (block == null) continue;
|
|
||||||
|
|
||||||
block = parse(data[d], namespace, block);
|
|
||||||
template = setBlock(regex, block, template);
|
|
||||||
} else {
|
|
||||||
template = replace(namespace + d, data[d], template);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return template;
|
|
||||||
|
|
||||||
})(data, "", template);
|
|
||||||
}
|
|
||||||
|
|
||||||
}(exports));
|
|
||||||
@@ -90,7 +90,7 @@ var config = require('../config.js'),
|
|||||||
|
|
||||||
if(key === 'email') {
|
if(key === 'email') {
|
||||||
User.setUserField(uid, 'gravatarpicture', User.createGravatarURLFromEmail(data[key]));
|
User.setUserField(uid, 'gravatarpicture', User.createGravatarURLFromEmail(data[key]));
|
||||||
RDB.set('email:' + email +':uid', uid);
|
RDB.set('email:' + data['email'] +':uid', uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ var express = require('express'),
|
|||||||
|
|
||||||
|
|
||||||
(function(app) {
|
(function(app) {
|
||||||
var templates = global.templates;
|
var templates = null;
|
||||||
|
|
||||||
// Middlewares
|
// Middlewares
|
||||||
app.use(express.favicon()); // 2 args: string path and object options (i.e. expire time etc)
|
app.use(express.favicon()); // 2 args: string path and object options (i.e. expire time etc)
|
||||||
@@ -38,6 +38,11 @@ var express = require('express'),
|
|||||||
key: 'express.sid'
|
key: 'express.sid'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.init = function() {
|
||||||
|
templates = global.templates;
|
||||||
|
}
|
||||||
|
|
||||||
auth.initialize(app);
|
auth.initialize(app);
|
||||||
|
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
user = require('./user.js'),
|
user = require('./user.js'),
|
||||||
posts = require('./posts.js'),
|
posts = require('./posts.js'),
|
||||||
topics = require('./topics.js'),
|
topics = require('./topics.js'),
|
||||||
categories = require('./categories.js'),
|
categories = require('./categories.js');
|
||||||
templates = require('./templates.js');
|
|
||||||
|
|
||||||
(function(io) {
|
(function(io) {
|
||||||
var users = {},
|
var users = {},
|
||||||
@@ -50,10 +49,6 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
|
|
||||||
var uid = users[hs.sessionID];
|
var uid = users[hs.sessionID];
|
||||||
|
|
||||||
if (DEVELOPMENT === true) {
|
|
||||||
// refreshing templates
|
|
||||||
templates.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*process.on('uncaughtException', function(err) {
|
/*process.on('uncaughtException', function(err) {
|
||||||
// handle the error safely
|
// handle the error safely
|
||||||
|
|||||||
Reference in New Issue
Block a user