Merge branch 'master' into optimize-22-09-2013

Conflicts:
	package.json
v1.18.x
Julian Lam 12 years ago
commit 99440585e6

1
.gitignore vendored

@ -6,6 +6,7 @@ npm-debug.log
node_modules/
sftp-config.json
config.json
public/src/nodebb.min.js
public/config.json
public/css/*.css
public/themes/*

@ -1,9 +1,12 @@
Please support NodeBB development! Check out our IndieGoGo campaign and like, share, and follow us :)
[NodeBB Homepage](http://www.nodebb.org/ "NodeBB") # [Follow on Twitter](http://www.twitter.com/NodeBB/ "NodeBB Twitter") # [Like us on Facebook](http://www.facebook.com/NodeBB/ "NodeBB Facebook")
# NodeBB
**NodeBB** is a robust Node.js driven forum built on a redis database. It is powered by web sockets, and is compatible down to IE8.
* [NodeBB Homepage](http://www.nodebb.org/ "NodeBB")
* [Follow on Twitter](http://www.twitter.com/NodeBB/ "NodeBB Twitter")
* [Like us on Facebook](http://www.facebook.com/NodeBB/ "NodeBB Facebook")
* [Join us on IRC](https://kiwiirc.com/client/irc.freenode.net/nodebb) - #nodebb on Freenode
![NodeBB Main Category Listing](http://i.imgur.com/ZBrHqLr.png)
![NodeBB Topic Page](http://i.imgur.com/YSBA6Vr.png)

@ -24,8 +24,11 @@
nconf.argv().env();
var fs = require('fs'),
async = require('async'),
winston = require('winston'),
pkg = require('./package.json'),
path = require('path'),
uglifyjs = require('uglify-js'),
meta;
// Runtime environment
@ -69,6 +72,61 @@
winston.info('Base Configuration OK.');
}
// Minify JS
var toMinify = [
'/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'
],
minified, mtime;
toMinify = toMinify.map(function (jsPath) {
return path.join(__dirname + '/public', jsPath);
});
async.parallel({
mtime: function (next) {
async.map(toMinify, 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) {
var minFile = path.join(__dirname, 'public/src/nodebb.min.js');
if (!fs.existsSync(minFile)) {
winston.warn('No minified client-side library found');
return next(null, 0);
}
fs.stat(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');
} else {
winston.info('Minifying client-side libraries');
minified = uglifyjs.minify(toMinify);
fs.writeFile(path.join(__dirname, '/public/src', 'nodebb.min.js'), minified.code, function (err) {
if (!err) {
winston.info('Minified client-side libraries');
} else {
winston.error('Problem minifying client-side libraries, exiting.');
process.exit();
}
});
}
});
meta.configs.init(function () {
// Initial setup for Redis & Reds
var reds = require('reds'),

@ -36,7 +36,8 @@
"nodebb-plugin-mentions": "~0.1.0",
"nodebb-plugin-markdown": "~0.1.0",
"rss": "~0.2.0",
"prompt": "~0.2.11"
"prompt": "~0.2.11",
"uglify-js": "~2.4.0"
},
"bugs": {
"url": "https://github.com/designcreateplay/NodeBB/issues"
@ -44,26 +45,20 @@
"engines": {
"node": ">=0.8"
},
"contributors": [
{
"contributors": [{
"name": "Andrew Rodrigues",
"email": "andrew@designcreateplay.com"
},
{
}, {
"name": "Julian Lam",
"email": "julian@designcreateplay.com"
},
{
}, {
"name": "Barış Soner Uşaklı",
"email": "baris@designcreateplay.com"
},
{
}, {
"name": "Damian Bushong",
"url": "https://github.com/damianb"
},
{
}, {
"name": "Matt Smith",
"url": "https://github.com/soimafreak"
}
]
}]
}

@ -275,7 +275,7 @@ var socket,
if (active) {
jQuery('#main-nav li a').each(function() {
var href = this.getAttribute('href');
if (active == "sort-posts" || active == "sort-reputation" || active == "search" || active== "latest")
if (active == "sort-posts" || active == "sort-reputation" || active == "search" || active == "latest" || active == "online")
active = 'users';
if (href && href.match(active)) {
jQuery(this.parentNode).addClass('active');
@ -286,6 +286,7 @@ var socket,
$('span.timeago').timeago();
setTimeout(function() {
window.scrollTo(0, 1); // rehide address bar on mobile after page load completes.
}, 100);
@ -432,12 +433,11 @@ var socket,
ajaxify.go("search/" + input.val(), null, "search");
input.val('');
return false;
})
});
});
showWelcomeMessage = location.href.indexOf('loggedin') !== -1;
loadConfig();
}());

@ -26,7 +26,6 @@
fields: ['username', 'picture', 'userslug']
});
socket.on('api:updateHeader', function(data) {
jQuery('#search-button').on('click', function() {
jQuery('#search-fields').removeClass('hide').show();
jQuery(this).hide();
@ -67,7 +66,16 @@
</li>');
rightMenu.append(userli);
var logoutli = $('<li><a href="' + RELATIVE_PATH + '/logout">Log out</a></li>');
var logoutli = $('<li><a href="#">Log out</a></li>');
logoutli.on('click', function() {
var csrf_token = $('#csrf_token').val();
$.post(RELATIVE_PATH + '/logout', {
_csrf: csrf_token
}, function() {
window.location = RELATIVE_PATH + '/';
});
});
rightMenu.append(logoutli);
}
} else {
@ -86,6 +94,11 @@
right_menu.appendChild(registerEl);
right_menu.appendChild(loginEl);
}
$('#main-nav a,#right-menu a').off('click').on('click', function() {
if($('.navbar .navbar-collapse').hasClass('in'))
$('.navbar-header button').click();
});
});
// Notifications dropdown

@ -12,6 +12,13 @@
$('#search-form input').val(searchQuery);
$('#mobile-search-form').off('submit').on('submit', function() {
var input = $(this).find('input');
ajaxify.go("search/" + input.val(), null, "search");
input.val('');
return false;
});
});
})();

@ -223,6 +223,15 @@
}
});
var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');
if(bookmark) {
// need to find out why it doesnt work without setTimeout -baris
setTimeout(function() {
app.scrollToPost(parseInt(bookmark, 10));
}, 300);
}
$('#post-container').on('click', '.deleted', function(ev) {
$(this).toggleClass('deleted-expanded');
});
@ -659,6 +668,7 @@
var scrollBottom = scrollTop + windowHeight;
if (scrollTop < 50 && postcount > 1) {
localStorage.removeItem("topic:" + tid + ":bookmark");
postAuthorImage.src = (jQuery('.main-post .avatar img').attr('src'));
mobileAuthorOverlay.innerHTML = 'Posted by ' + jQuery('.main-post').attr('data-username') + ', ' + jQuery('.main-post').find('.relativeTimeAgo').html();
pagination.innerHTML = '0 out of ' + postcount;
@ -666,7 +676,7 @@
}
var count = 0;
var count = 0, smallestNonNegative = 0;
jQuery('.sub-posts').each(function() {
count++;
@ -682,6 +692,11 @@
if (inView) {
if(elTop - scrollTop > smallestNonNegative) {
localStorage.setItem("topic:" + tid + ":bookmark", el.attr('data-pid'));
smallestNonNegative = Number.MAX_VALUE;
}
pagination.innerHTML = this.postnumber + ' out of ' + postcount;
postAuthorImage.src = (jQuery(this).find('.profile-image-block img').attr('src'));
mobileAuthorOverlay.innerHTML = 'Posted by ' + jQuery(this).attr('data-username') + ', ' + jQuery(this).find('.relativeTimeAgo').html();

@ -74,7 +74,12 @@
});
socket.on('api:user.isOnline', function(data) {
if(active == 'online' && !loadingMoreUsers) {
$('#users-container').empty();
startLoading('users:online', 0);
}
});
function onUsersLoaded(users) {
var html = templates.prepare(templates['users'].blocks['users']).parse({
@ -91,23 +96,31 @@
set = 'users:postcount';
} else if (active === 'sort-reputation') {
set = 'users:reputation';
} else if (active === 'online') {
set = 'users:online';
}
if (set) {
startLoading(set, $('#users-container').children().length);
}
}
function startLoading(set, after) {
loadingMoreUsers = true;
socket.emit('api:users.loadMore', {
set: set,
after: $('#users-container').children().length
after: after
}, function(data) {
if (data.users.length) {
onUsersLoaded(data.users);
$('#load-more-users-btn').removeClass('disabled');
} else {
$('#load-more-users-btn').addClass('disabled');
}
loadingMoreUsers = false;
});
}
}
$('#load-more-users-btn').on('click', loadMoreUsers);

@ -8,27 +8,16 @@
<script>
var RELATIVE_PATH = "{relative_path}";
</script>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="{relative_path}/vendor/jquery/js/jquery-ui-1.10.3.custom.min.js"></script>
<script src="{relative_path}/vendor/jquery/js/jquery.timeago.js"></script>
<script src="{relative_path}/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="{relative_path}/socket.io/socket.io.js"></script>
<script src="{relative_path}/src/app.js"></script>
<script src="{relative_path}/vendor/requirejs/require.js"></script>
<script src="{relative_path}/vendor/bootbox/bootbox.min.js"></script>
<script src="{relative_path}/src/nodebb.min.js"></script>
<script>
require.config({
baseUrl: "{relative_path}/src/modules",
waitSeconds: 3
});
</script>
<script src="{relative_path}/src/templates.js"></script>
<script src="{relative_path}/src/ajaxify.js"></script>
<script src="{relative_path}/src/jquery.form.js"></script>
<script src="{relative_path}/src/utils.js"></script>
<link rel="stylesheet" type="text/css" href="{relative_path}/css/nodebb.css" />
</head>
<body>
@ -54,9 +43,9 @@
<li>
<a href="/users">Users</a>
</li>
<!--Enable when /search form is completed <li class="visible-xs">
<li class="visible-xs">
<a href="/search">Search</a>
</li>-->
</li>
<li>
<a href="/"></a>
</li>

@ -3,8 +3,18 @@
<li class="active">Search</li>
</ol>
<form id="mobile-search-form" class="navbar-form navbar-right visible-xs" role="search" method="GET" action="">
<div class="" id="search-fields">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search" name="query" value="">
</div>
<button type="submit" class="btn btn-default hide">Search</button>
</div>
</form>
<div class="category search">
<div class="">
<div class="{show_results}">
<ul id="topics-container" data-search-query="{search_query}">
<h3>Topics</h3>
<div class="alert alert-info {show_no_topics}">No topics found!</div>

@ -3,6 +3,7 @@
<li class=''><a href='/users/latest'>Latest Users</a></li>
<li class=''><a href='/users/sort-posts'>Top Posters</a></li>
<li class=''><a href='/users/sort-reputation'>Most Reputation</a></li>
<li class=''><a href='/users/online'>Online</a></li>
<li class=''><a href='/users/search'>Search</a></li>
</ul>

@ -105,6 +105,8 @@
width: 70%;
margin-left: 10px;
overflow: hidden;
max-height: 33px;
margin-bottom: 0px;
}
}
}

File diff suppressed because it is too large Load Diff

@ -137,7 +137,7 @@ var fs = require('fs'),
hookList = this.loadedHooks[hook];
if (hookList && Array.isArray(hookList)) {
if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\'');
//if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\'');
var hookType = hook.split(':')[0];
switch (hookType) {
case 'filter':

@ -70,7 +70,7 @@ var RDB = require('./redis.js'),
Posts.getPostFields(pid, ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted'], function(postData) {
if (postData.deleted === '1') return callback(null);
else {
postData.relativeTime = new Date(parseInt(postData.timestamp, 10)).toISOString();
postData.relativeTime = new Date(parseInt(postData.timestamp || 0, 10)).toISOString();
next(null, postData);
}
});

@ -186,6 +186,7 @@ var user = require('./../user.js'),
return res.json({
show_no_topics: 'hide',
show_no_posts: 'hide',
show_results: 'hide',
search_query: '',
posts: [],
topics: []
@ -235,6 +236,7 @@ var user = require('./../user.js'),
return res.json({
show_no_topics: results[1].length ? 'hide' : '',
show_no_posts: results[0].length ? 'hide' : '',
show_results: '',
search_query: req.params.term,
posts: results[0],
topics: results[1]

@ -90,19 +90,14 @@
}
Auth.create_routes = function(app) {
app.get('/logout', function(req, res) {
app.post('/logout', function(req, res) {
if (req.user && req.user.uid > 0) {
winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
req.logout();
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + templates['logout'] + templates['footer']);
});
} else res.redirect('/');
}
res.send(200)
});
if (login_strategies.indexOf('twitter') !== -1) {

@ -25,7 +25,6 @@ var user = require('./../user.js'),
});
}
});
});
app.get('/users', function(req, res) {
@ -64,6 +63,15 @@ var user = require('./../user.js'),
});
});
app.get('/users/online', function(req, res) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route("users/online", "users") + templates['footer']);
});
});
app.get('/users/search', function(req, res) {
app.build_header({
req: req,
@ -436,6 +444,7 @@ var user = require('./../user.js'),
app.get('/api/users/sort-posts', getUsersSortedByPosts);
app.get('/api/users/sort-reputation', getUsersSortedByReputation);
app.get('/api/users/latest', getUsersSortedByJoinDate);
app.get('/api/users/online', getOnlineUsers);
app.get('/api/users/search', getUsersForSearch);
@ -469,6 +478,16 @@ var user = require('./../user.js'),
});
}
function getOnlineUsers(req, res) {
user.getUsers('users:online', 0, 49, function(err, data) {
res.json({
search_display: 'none',
loadmore_display: 'block',
users: data
});
});
}
function getUsersForSearch(req, res) {
res.json({
search_display: 'block',

@ -48,33 +48,28 @@ var express = require('express'),
metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])),
templateValues = {
cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
title: meta.config['title'] || 'NodeBB',
browserTitle: meta.config['title'] || 'NodeBB',
title: meta.config.title || 'NodeBB',
browserTitle: meta.config.title || 'NodeBB',
csrf: options.res.locals.csrf_token,
relative_path: nconf.get('relative_path'),
meta_tags: metaString
};
// meta.build_title(options.title, (options.req.user ? options.req.user.uid : 0), function(err, title) {
// if (!err) templateValues.browserTitle = title;
// callback(null, templates['header'].parse(templateValues));
// });
callback(null, templates['header'].parse(templateValues));
callback(null, templates.header.parse(templateValues));
};
// Middlewares
app.use(express.compress());
app.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico')));
app.use(require('less-middleware')({
src: path.join(__dirname, '../', 'public'),
prefix: nconf.get('relative_path')
prefix: nconf.get('relative_path'),
yuicompress: true
}));
app.use(nconf.get('relative_path'), express.static(path.join(__dirname, '../', 'public')));
app.use(express.bodyParser()); // Puts POST vars in request.body
app.use(express.cookieParser()); // If you want to parse cookies (res.cookies)
app.use(express.compress());
app.use(express.session({
store: new RedisStore({
client: RDB,
@ -481,6 +476,8 @@ var express = require('express'),
});
app.get('/search', function (req, res) {
if (!req.user)
return res.redirect('/403');
app.build_header({
req: req,
res: res
@ -490,6 +487,8 @@ var express = require('express'),
});
app.get('/search/:term', function (req, res) {
if (!req.user)
return res.redirect('/403');
app.build_header({
req: req,
res: res

@ -23,6 +23,7 @@ var SocketIO = require('socket.io').listen(global.server, {
client: RDB,
ttl: 60 * 60 * 24 * 14
}),
nconf = require('nconf'),
socketCookieParser = express.cookieParser(nconf.get('secret')),
admin = {
'categories': require('./admin/categories.js'),
@ -53,6 +54,8 @@ var SocketIO = require('socket.io').listen(global.server, {
userSockets[uid].push(socket);
if (uid) {
RDB.zadd('users:online', Date.now(), uid, function(err, data) {
socket.join('uid_' + uid);
io.sockets. in ('global').emit('api:user.isOnline', isUserOnline(uid));
@ -63,6 +66,7 @@ var SocketIO = require('socket.io').listen(global.server, {
uid: uid
});
});
});
}
});
});
@ -80,7 +84,9 @@ var SocketIO = require('socket.io').listen(global.server, {
delete users[sessionID];
delete userSockets[uid];
if (uid) {
RDB.zrem('users:online', uid, function(err, data) {
io.sockets. in ('global').emit('api:user.isOnline', isUserOnline(uid));
});
}
}
@ -100,7 +106,7 @@ var SocketIO = require('socket.io').listen(global.server, {
socket.on('api:get_all_rooms', function(data) {
socket.emit('api:get_all_rooms', io.sockets.manager.rooms);
})
});
function updateRoomBrowsingText(roomName) {

Loading…
Cancel
Save