Node.js based forum software built for the modern web
closes #590
Baris Usakli190948336a51
diff --git a/public/language/en/global.json b/public/language/en/global.jsonindex f1615549d3..00576a18be 100644--- a/public/language/en/global.json+++ b/public/language/en/global.json@@ -6,6 +6,8 @@"403.message": "You seem to have stumbled upon a page that you do not have access to. Perhaps you should <a href='/login'>try logging in</a>?","404.title": "Not Found","404.message": "You seem to have stumbled upon a page that does not exist. Return to the <a href='/''>home page</a>.",+ "500.title": "Internal error.",+ "500.message": "Ooops! Looks like something went wrong!","logout": "Logout","logout.title": "You are now logged out.","logout.message": "You have successfully logged out of NodeBB",diff --git a/public/src/forum/favourites.js b/public/src/forum/favourites.jsindex 20b77b4d41..e23572e1b2 100644--- a/public/src/forum/favourites.js+++ b/public/src/forum/favourites.js@@ -3,10 +3,6 @@ define(['forum/accountheader'], function(header) {AccountHeader.init = function() {header.init();-- $('.user-favourite-posts .topic-row').on('click', function() {- ajaxify.go($(this).attr('topic-url'));- });};return AccountHeader;diff --git a/public/src/templates.js b/public/src/templates.jsindex d185b7c16e..6772f998b7 100644--- a/public/src/templates.js+++ b/public/src/templates.js@@ -172,7 +172,7 @@} else if (data && data.status === 403) {return ajaxify.go('403');} else {- app.alertError("Can't load template data!");+ app.alertError(data.responseJSON.error);}});@@ -319,18 +319,18 @@if (conditionalBlock[1]) {// there is an else statement- if (!value) {- template = template.replace(matches[i], conditionalBlock[1]);+ if (!value) {+ template = template.replace(matches[i], conditionalBlock[1]);} else {- template = template.replace(matches[i], conditionalBlock[0]);+ template = template.replace(matches[i], conditionalBlock[0]);}} else {- // regular if statement+ // regular if statementif (!value) {template = template.replace(matches[i], '');}}- }+ }}}@@ -341,7 +341,7 @@checkConditional('@first', blockInfo.iterator === 0);checkConditional('@last', blockInfo.iterator === blockInfo.total);}-+template = replace(namespace + d, data[d], template);}}diff --git a/public/templates/500.tpl b/public/templates/500.tplnew file mode 100644index 0000000000..e3c110a50d--- /dev/null+++ b/public/templates/500.tpl@@ -0,0 +1,5 @@+<div class="alert alert-danger">+ <strong>[[global:500.title]]</strong>+ <p>[[global:500.message]]</p>+ <p>{errorMessage}</p>+</div>\ No newline at end of filediff --git a/public/templates/favourites.tpl b/public/templates/favourites.tplindex 19e8726f2f..4bd4c442c7 100644--- a/public/templates/favourites.tpl+++ b/public/templates/favourites.tpl@@ -6,17 +6,31 @@</span></div>- <div id="no-favourites-notice" class="alert alert-warning {show_nofavourites}">You don't have any favourites, favourite some posts to see them here!</div>+ <!-- IF show_nofavourites -->+ <div id="no-favourites-notice" class="alert alert-warning">You don't have any favourites, favourite some posts to see them here!</div>+ <!-- ENDIF show_nofavourites --><div class="row"><div class="col-md-12 user-favourite-posts"><!-- BEGIN posts -->- <div class="topic-row img-thumbnail clearfix" topic-url="topic/{posts.tid}/#{posts.pid}">- <span><strong>{posts.username}</strong> : </span>- <span>{posts.category_name} >> {posts.title}</span>- <div>{posts.content}</div>+ <div class="topic-row img-thumbnail clearfix">+ <a href="/user/baris">+ <img title="{posts.username}" class="img-rounded user-img" src="{posts.picture}">+ </a>++ <a href="../../topic/{posts.tid}/#{posts.pid}">+ <strong><span>{posts.username}</span></strong>+ <p>{posts.content}</p>+ </a>+<div>- <span class="pull-right timeago" title="{posts.relativeTime}"></span>+ <span class="pull-right">+ posted in+ <a href="../../category/{posts.categorySlug}">+ <i class="fa {posts.categoryIcon}"></i> {posts.categoryName}+ </a>+ <span class="timeago" title="{posts.relativeTime}"></span>+ </span></div></div><br/>diff --git a/src/posts.js b/src/posts.jsindex 3fd6205b57..646f38dded 100644--- a/src/posts.js+++ b/src/posts.js@@ -250,8 +250,9 @@ var RDB = require('./redis'),async.waterfall([function(next) {Posts.getPostFields(pid, ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted'], function(err, postData) {- if (postData.deleted === '1') return callback(null);- else {+ if (postData.deleted === '1') {+ return callback(null);+ } else {postData.relativeTime = new Date(parseInt(postData.timestamp || 0, 10)).toISOString();next(null, postData);}@@ -264,10 +265,15 @@ var RDB = require('./redis'),},function(postData, next) {topics.getTopicFields(postData.tid, ['title', 'cid', 'slug', 'deleted'], function(err, topicData) {- if (err) return callback(err);- else if (topicData.deleted === '1') return callback(null);- categories.getCategoryField(topicData.cid, 'name', function(err, categoryData) {- postData.category_name = categoryData;+ if (err) {+ return callback(err);+ } else if (topicData.deleted === '1') {+ return callback(null);+ }+ categories.getCategoryFields(topicData.cid, ['name', 'icon', 'slug'], function(err, categoryData) {+ postData.categoryName = categoryData.name;+ postData.categoryIcon = categoryData.icon;+ postData.categorySlug = categoryData.slug;postData.title = validator.sanitize(topicData.title).escape();postData.topicSlug = topicData.slug;next(null, postData);@@ -277,13 +283,19 @@ var RDB = require('./redis'),function(postData, next) {if (postData.content) {postTools.parse(postData.content, function(err, content) {- if (!err) postData.content = utils.strip_tags(content);+ if (!err) {+ postData.content = utils.strip_tags(content);+ }next(err, postData);});- } else next(null, postData);+ } else {+ next(null, postData);+ }}], function(err, postData) {- if (!err) posts.push(postData);+ if (!err) {+ posts.push(postData);+ }callback(err);});}diff --git a/src/routes/api.js b/src/routes/api.jsindex 746243f420..389763bac5 100644--- a/src/routes/api.js+++ b/src/routes/api.js@@ -143,14 +143,14 @@ var path = require('path'),});});- app.get('/recent/:term?', function (req, res) {+ app.get('/recent/:term?', function (req, res, next) {var uid = (req.user) ? req.user.uid : 0;topics.getLatestTopics(uid, 0, 19, req.params.term, function (err, data) {- if (!err) {- res.json(data);- } else {- res.send(500);+ if(err) {+ return next(err);}++ res.json(data);});});@@ -295,6 +295,10 @@ var path = require('path'),app.get('/403', function (req, res) {res.json({});});++ app.get('/500', function(req, res) {+ res.json({errorMessage: 'testing'});+ })});}}(exports));\ No newline at end of filediff --git a/src/routes/user.js b/src/routes/user.jsindex 9a3364071c..b0de83ebcb 100644--- a/src/routes/user.js+++ b/src/routes/user.js@@ -351,15 +351,17 @@ var fs = require('fs'),}user.getUserFields(uid, ['username', 'userslug'], function (err, userData) {- if (err)+ if (err) {return next(err);+ }if (userData) {posts.getFavourites(uid, function (err, posts) {- if (err)+ if (err) {return next(err);+ }userData.posts = posts;- userData.show_nofavourites = posts.length ? 'hide' : 'show';+ userData.show_nofavourites = posts.length === 0;res.json(userData);});} else {diff --git a/src/webserver.js b/src/webserver.jsindex 624f08258d..716bd5dcfe 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -301,10 +301,10 @@ var path = require('path'),// here and next(err) appropriately, or if// we possibly recovered from the error, simply next().console.error(err.stack);+ var status = err.status || 500;+ res.status(status);- res.status(err.status || 500);-- res.json('500', {+ res.json(status, {error: err.message});});@@ -360,7 +360,7 @@ var path = require('path'),// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)(function () {- var routes = ['login', 'register', 'account', 'recent', '403', '404'],+ var routes = ['login', 'register', 'account', 'recent', '403', '404', '500'],loginRequired = ['unread', 'search', 'notifications'];async.each(routes.concat(loginRequired), function(route, next) {