Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 12 years ago
commit 786baa8fe0

@ -1,14 +1,25 @@
# NodeBB # NodeBB
**NodeBB** is a robust nodejs driven forum built on a redis database. It is powered by web sockets, and is compatible down to IE8. **NodeBB** is a robust nodejs driven forum built on a redis database. It is powered by web sockets, and is compatible down to IE8.
![NodeBB Screenshot](http://i.imgur.com/mxRmLAg.png)
![NodeBB Login Page (with Social Logins)](http://i.imgur.com/q5tUUHW.png)
## Requirements
NodeBB requires a version of Node.js at least 0.8 or greater, and a Redis version 2.6 or greater.
## Installation ## Installation
NodeBB is powered by Node.js with a Redis database. They must be installed prior in order for NodeBB to work. `build-essential` exposes the build environment for `bcrypt` compilation. First, we install our base software stack. `build-essential` is required as it exposes the build environment for `bcrypt` compilation, we won't be compiling anything manually.
# apt-get install nodejs redis-server npm build-essential # apt-get install git nodejs redis-server npm build-essential
$ cd /path/to/nodebb/install/location
$ git clone git://github.com/designcreateplay/NodeBB.git nodebb
Next, obtain all of the dependencies required by NodeBB: Next, obtain all of the dependencies required by NodeBB:
$ cd nodebb
$ npm install $ npm install
Now we ensure that the configuration files are properly set up. NodeBB runs on port 4567 by default. The client side config can be set up thusly: Now we ensure that the configuration files are properly set up. NodeBB runs on port 4567 by default. The client side config can be set up thusly:

@ -0,0 +1,4 @@
<div class="alert alert-error">
<strong>Not found</strong>
<p>You seem to have stumbled upon a page that does not exist. Return to the <a href="/">home page</a></p>
</div>

@ -60,9 +60,88 @@ var RDB = require('./redis.js'),
Categories.get = function(callback, category_id, current_user) { Categories.get = function(callback, category_id, current_user) {
var range_var = (category_id) ? 'categories:' + category_id + ':tid' : 'topics:tid'; RDB.smembers('categories:' + category_id + ':tid', function(err, tids) {
RDB.multi()
.get('cid:' + category_id + ':name')
.smembers('cid:' + category_id + ':active_users')
.exec(function(err, replies) {
category_name = replies[0];
active_usernames = replies[1];
if (category_name === null) {
callback(false);
}
var active_users = [];
for (var username in active_usernames) {
active_users.push({'username': active_usernames[username]});
}
var categoryData = {
'category_name' : category_name,
'show_topic_button' : 'show',
'category_id': category_id,
'active_users': active_users,
'topics' : []
};
function getTopics(next) {
Categories.getTopicsByTids(tids, current_user, function(topics) {
next(null, topics);
}, category_id);
}
function getModerators(next) {
Categories.getModerators(category_id, function(moderators) {
next(null, moderators);
});
}
if (tids.length === 0) {
getModerators(function(err, moderators) {
categoryData.moderator_block_class = moderators.length > 0 ? '' : 'none';
categoryData.moderators = moderators;
RDB.smembers(range_var, function(err, tids) { callback(categoryData);
});
} else {
async.parallel([getTopics, getModerators], function(err, results) {
categoryData.topics = results[0];
categoryData.moderator_block_class = results[1].length > 0 ? '' : 'none';
categoryData.moderators = results[1];
callback(categoryData);
});
}
});
});
}
// not the permanent location for this function
Categories.getLatestTopics = function(current_user, start, end, callback) {
RDB.zrange('topics:recent', 0, -1, function(err, tids) {
var latestTopics = {
'category_name' : 'Recent',
'show_topic_button' : 'hidden',
'category_id': false,
'topics' : []
};
if (!tids.length) {
callback(latestTopics);
return;
}
Categories.getTopicsByTids(tids, current_user, function(topicData) {
latestTopics.topics = topicData;
callback(latestTopics);
});
});
}
Categories.getTopicsByTids = function(tids, current_user, callback, category_id /*temporary*/) {
var title = [], var title = [],
uid = [], uid = [],
timestamp = [], timestamp = [],
@ -83,12 +162,8 @@ var RDB = require('./redis.js'),
pinned.push('tid:' + tids[i] + ':pinned'); pinned.push('tid:' + tids[i] + ':pinned');
} }
var multi = RDB.multi()
.get('cid:' + category_id + ':name')
.smembers('cid:' + category_id + ':active_users');
if (tids.length > 0) { RDB.multi()
multi
.mget(title) .mget(title)
.mget(uid) .mget(uid)
.mget(timestamp) .mget(timestamp)
@ -97,48 +172,50 @@ var RDB = require('./redis.js'),
.mget(locked) .mget(locked)
.mget(deleted) .mget(deleted)
.mget(pinned) .mget(pinned)
} .exec(function(err, replies) {
var retrieved_topics = [];
multi.exec(function(err, replies) { title = replies[0];
category_name = replies[0]; uid = replies[1];
timestamp = replies[2];
slug = replies[3];
postcount = replies[4];
locked = replies[5];
deleted = replies[6];
pinned = replies[7];
if(category_id && category_name === null) { function getUserNames(next) {
callback(false); user.get_usernames_by_uids(uid, function(userNames) {
return; next(null, userNames);
});
} }
active_usernames = replies[1]; function hasReadTopics(next) {
var retrieved_topics = []; topics.hasReadTopics(tids, current_user, function(hasRead) {
next(null, hasRead);
});
}
if (tids.length == 0) { function getTeaserInfo(next) {
callback({ topics.get_teasers(tids, function(teasers) {
'category_name' : category_id ? category_name : 'Recent', next(null, teasers);
'show_topic_button' : category_id ? 'show' : 'hidden',
'category_id': category_id || 0,
'topics' : []
}); });
} }
title = replies[2]; // temporary. I don't think this call should belong here
uid = replies[3]; function getPrivileges(next) {
timestamp = replies[4]; Categories.privileges(category_id, current_user, function(user_privs) {
slug = replies[5]; next(null, user_privs);
postcount = replies[6]; });
locked = replies[7]; }
deleted = replies[8];
pinned = replies[9]; async.parallel([getUserNames, hasReadTopics, getTeaserInfo, getPrivileges], function(err, results) {
var usernames = results[0],
var usernames, hasReadTopics = results[1],
has_read, teaserInfo = results[2],
moderators, privileges = results[3];
teaser_info,
privileges; for (var i=0, ii=tids.length; i<ii; i++) {
function generate_topic() {
if (!usernames || !has_read || !moderators || !teaser_info || !privileges) return;
if (tids.length > 0) {
for (var i=0, ii=title.length; i<ii; i++) {
if (!deleted[i] || (deleted[i] && privileges.view_deleted) || uid[i] === current_user) { if (!deleted[i] || (deleted[i] && privileges.view_deleted) || uid[i] === current_user) {
retrieved_topics.push({ retrieved_topics.push({
'title' : title[i], 'title' : title[i],
@ -153,13 +230,12 @@ var RDB = require('./redis.js'),
'deleted-class': deleted[i] ? 'deleted' : '', 'deleted-class': deleted[i] ? 'deleted' : '',
'pinned': parseInt(pinned[i] || 0), // For sorting purposes 'pinned': parseInt(pinned[i] || 0), // For sorting purposes
'pin-icon': pinned[i] === '1' ? 'icon-pushpin' : 'none', 'pin-icon': pinned[i] === '1' ? 'icon-pushpin' : 'none',
'badgeclass' : (has_read[i] && current_user !=0) ? '' : 'badge-important', 'badgeclass' : (hasReadTopics[i] && current_user !=0) ? '' : 'badge-important',
'teaser_text': teaser_info[i].text, 'teaser_text': teaserInfo[i].text,
'teaser_username': teaser_info[i].username 'teaser_username': teaserInfo[i].username
}); });
} }
} }
}
// Float pinned topics to the top // Float pinned topics to the top
retrieved_topics = retrieved_topics.sort(function(a, b) { retrieved_topics = retrieved_topics.sort(function(a, b) {
@ -170,45 +246,8 @@ var RDB = require('./redis.js'),
} }
}); });
var active_users = [];
for (var username in active_usernames) {
active_users.push({'username': active_usernames[username]});
}
callback({
'category_name' : category_id ? category_name : 'Recent',
'show_topic_button' : category_id ? 'show' : 'hidden',
'category_id': category_id || 0,
'topics': retrieved_topics,
'active_users': active_users,
'moderator_block_class': moderators.length > 0 ? '' : 'none',
'moderators': moderators
});
}
user.get_usernames_by_uids(uid, function(userNames) {
usernames = userNames;
generate_topic();
});
topics.hasReadTopics(tids, current_user, function(hasRead) {
has_read = hasRead;
generate_topic();
});
Categories.getModerators(category_id, function(mods) {
moderators = mods;
generate_topic();
});
topics.get_teasers(tids, function(teasers) { callback(retrieved_topics);
teaser_info = teasers;
generate_topic();
});
Categories.privileges(category_id, current_user, function(user_privs) {
privileges = user_privs;
});
}); });
}); });
} }
@ -216,7 +255,7 @@ var RDB = require('./redis.js'),
Categories.getAllCategories = function(callback, current_user) { Categories.getAllCategories = function(callback, current_user) {
RDB.lrange('categories:cid', 0, -1, function(err, cids) { RDB.lrange('categories:cid', 0, -1, function(err, cids) {
RDB.handle(err); RDB.handle(err);
Categories.get_category(cids, callback, current_user); Categories.getCategories(cids, callback, current_user);
}); });
} }
@ -251,7 +290,7 @@ var RDB = require('./redis.js'),
Categories.get_category = function(cids, callback, current_user) { Categories.getCategories = function(cids, callback, current_user) {
var name = [], var name = [],
description = [], description = [],
icon = [], icon = [],

@ -141,7 +141,7 @@ var RDB = require('./redis.js'),
RDB.smove('categories:' + oldCid + ':tid', 'categories:' + cid + ':tid', tid, function(err, result) { RDB.smove('categories:' + oldCid + ':tid', 'categories:' + cid + ':tid', tid, function(err, result) {
if (!err && result === 1) { if (!err && result === 1) {
RDB.set('tid:' + tid + ':cid', cid); RDB.set('tid:' + tid + ':cid', cid);
categories.get_category([cid], function(data) { categories.getCategories([cid], function(data) {
RDB.set('tid:' + tid + ':category_name', data.categories[0].name); RDB.set('tid:' + tid + ':category_name', data.categories[0].name);
RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug); RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug);
}); });

@ -58,6 +58,11 @@ marked.setOptions({
voteData = results[1].voteData, voteData = results[1].voteData,
privileges = results[2]; privileges = results[2];
if (!postData) {
callback(false);
return;
}
for (var i=0, ii= postData.pid.length; i<ii; i++) { for (var i=0, ii= postData.pid.length; i<ii; i++) {
var uid = postData.uid[i], var uid = postData.uid[i],
pid = postData.pid[i]; pid = postData.pid[i];
@ -335,10 +340,13 @@ marked.setOptions({
// let everyone know that there is an unread topic in this category // let everyone know that there is an unread topic in this category
RDB.del('cid:' + category_id + ':read_by_uid'); RDB.del('cid:' + category_id + ':read_by_uid');
RDB.zadd('topics:recent', (new Date()).getTime(), tid);
//RDB.zadd('topics:active', tid);
// in future it may be possible to add topics to several categories, so leaving the door open here. // in future it may be possible to add topics to several categories, so leaving the door open here.
RDB.sadd('categories:' + category_id + ':tid', tid); RDB.sadd('categories:' + category_id + ':tid', tid);
RDB.set('tid:' + tid + ':cid', category_id); RDB.set('tid:' + tid + ':cid', category_id);
categories.get_category([category_id], function(data) { categories.getCategories([category_id], function(data) {
RDB.set('tid:' + tid + ':category_name', data.categories[0].name); RDB.set('tid:' + tid + ':category_name', data.categories[0].name);
RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug); RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug);
}); });

@ -71,7 +71,7 @@ var express = require('express'),
// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section) // Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)
(function() { (function() {
var routes = ['', 'login', 'register', 'account', 'latest', 'popular', 'active', '403']; var routes = ['', 'login', 'register', 'account', 'latest', 'popular', 'active', '403', '404'];
for (var i=0, ii=routes.length; i<ii; i++) { for (var i=0, ii=routes.length; i<ii; i++) {
(function(route) { (function(route) {
@ -183,17 +183,12 @@ var express = require('express'),
}, req.params.id, (req.user) ? req.user.uid : 0); }, req.params.id, (req.user) ? req.user.uid : 0);
break; break;
case 'latest' : case 'latest' :
categories.get(function(data) { categories.getLatestTopics((req.user) ? req.user.uid : 0, 0, 9, function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}); });
break; break;
case 'popular' : case 'popular' :
categories.get(function(data) { categories.get(function(data) {
console.log(data);
if(!data) { if(!data) {
res.send(false); res.send(false);
return; return;

Loading…
Cancel
Save