mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
Merge remote-tracking branch 'origin' into thread_options
Conflicts: public/src/templates.js
This commit is contained in:
23
app.js
23
app.js
@@ -33,20 +33,33 @@ global.modules = modules;
|
||||
console.log('Setting up default categories...');
|
||||
|
||||
modules.categories.create({
|
||||
'name': 'General',
|
||||
'description': 'A place to talk about whateeeever you want'
|
||||
'name': 'Announcements',
|
||||
'description': 'A place to talk about whateeeever you want',
|
||||
'blockclass': 'category-purple',
|
||||
'icon' : 'icon-bullhorn'
|
||||
});
|
||||
|
||||
modules.categories.create({
|
||||
'name': 'General Discussion',
|
||||
'description': 'A place to talk about whateeeever you want',
|
||||
'blockclass': 'category-purple',
|
||||
'icon' : 'icon-comment'
|
||||
});
|
||||
|
||||
|
||||
modules.categories.create({
|
||||
'name': 'NodeBB Development',
|
||||
'description': 'Bugs? Dont worry, we dont read this thread, so post them here.'
|
||||
'description': 'Bugs? Dont worry, we dont read this thread, so post them here.',
|
||||
'blockclass': 'category-purple',
|
||||
'icon' : 'icon-github-alt'
|
||||
});
|
||||
|
||||
|
||||
modules.categories.create({
|
||||
'name': 'Design Create Play',
|
||||
'description': 'In future an example of how a hidden category should look like.'
|
||||
'name': 'Blogs',
|
||||
'description': 'In future an example of how a hidden category should look like.',
|
||||
'blockclass': 'category-purple',
|
||||
'icon' : 'icon-pencil'
|
||||
});
|
||||
|
||||
} else console.log('Good.');
|
||||
|
||||
@@ -297,3 +297,29 @@ footer.footer {
|
||||
display:inline-block;
|
||||
width:100px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.category-icon {
|
||||
width: 100%;
|
||||
height: 90px;
|
||||
text-align: center;
|
||||
border-radius: 5px;
|
||||
margin: 0;
|
||||
padding-top:20px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.category-row h4 {
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
color: #555;
|
||||
}
|
||||
.category-row a {
|
||||
text-decoration: none;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.category-purple {
|
||||
background: #ab1290;
|
||||
color: white;
|
||||
}
|
||||
@@ -30,6 +30,7 @@ var ajaxify = {};
|
||||
|
||||
var url = url.replace(/\/$/, "");
|
||||
var tpl_url = (url === '' || url === '/') ? 'home' : url.split('/')[0];
|
||||
tpl_url = templates.get_custom_map(tpl_url);
|
||||
|
||||
if (templates[tpl_url]) {
|
||||
window.history.pushState({}, url, "/" + url);
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
var templates = {};
|
||||
|
||||
(function() {
|
||||
var ready_callback;
|
||||
var ready_callback,
|
||||
config;
|
||||
|
||||
templates.get_custom_map = function(tpl) {
|
||||
return (config['custom_mapping'] && config['custom_mapping'][tpl]) ? config['custom_mapping'][tpl] : tpl;
|
||||
}
|
||||
|
||||
templates.ready = function(callback) {
|
||||
//quick implementation because introducing a lib to handle several async callbacks
|
||||
@@ -21,6 +26,10 @@ var templates = {};
|
||||
var timestamp = new Date().getTime();
|
||||
var loaded = templatesToLoad.length;
|
||||
|
||||
$.getJSON('/templates/config.json', function(data) {
|
||||
config = data;
|
||||
});
|
||||
|
||||
for (var t in templatesToLoad) {
|
||||
(function(file) {
|
||||
$.get('/templates/' + file + '.tpl?v=' + timestamp, function(html) {
|
||||
@@ -146,7 +155,10 @@ function load_template(callback) {
|
||||
url = (url === '' || url === '/') ? 'home' : url;
|
||||
|
||||
jQuery.get(API_URL + url, function(data) {
|
||||
document.getElementById('content').innerHTML = templates[url.split('/')[0]].parse(JSON.parse(data));
|
||||
var tpl = url.split('/')[0];
|
||||
tpl = templates.get_custom_map(tpl);
|
||||
|
||||
document.getElementById('content').innerHTML = templates[tpl].parse(JSON.parse(data));
|
||||
if (callback) callback();
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<button id="new_post" class="btn btn-primary btn-large">New Topic</button>
|
||||
<button id="new_post" class="btn btn-primary btn-large {show_topic_button}">New Topic</button>
|
||||
<ul class="topic-container">
|
||||
<!-- BEGIN topics -->
|
||||
<a href="../../topic/{topics.slug}"><li class="topic-row">
|
||||
|
||||
8
public/templates/config.json
Normal file
8
public/templates/config.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"custom_mapping": {
|
||||
"users": "account",
|
||||
"latest": "category",
|
||||
"popular": "category",
|
||||
"active": "category"
|
||||
}
|
||||
}
|
||||
@@ -27,15 +27,15 @@
|
||||
</button>
|
||||
<div class="nav-collapse collapse">
|
||||
<ul class="nav">
|
||||
<li id="fat-menu" class="active dropdown">
|
||||
<a href="#" id="topic_dropdown" role="button" class="dropdown-toggle" data-toggle="dropdown">Topics <span class="badge badge-inverse">3</span></a>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="topic_dropdown">
|
||||
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">latest post</a></li>
|
||||
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">another latest post</a></li>
|
||||
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">moar latest posts</a></li>
|
||||
</ul>
|
||||
<li>
|
||||
<a href="/latest">Recent <span class="badge badge-inverse">3</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/popular">Popular</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/active">Active</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
<ul class="nav pull-right" id="right-menu">
|
||||
<li><a href="/account" id="user_label"></a></li>
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
<h3>Categories</h3>
|
||||
<ul class="topic-container">
|
||||
|
||||
<div class="row category-row">
|
||||
<!-- BEGIN categories -->
|
||||
<a href="category/{categories.slug}"><li class="topic-row">
|
||||
<div class="span3">
|
||||
<a href="category/{categories.slug}">
|
||||
<h4>{categories.name}</h4>
|
||||
<p>{categories.description}</p>
|
||||
</li></a>
|
||||
<!-- {categories.description} -->
|
||||
<div class="category-icon {categories.blockclass}">
|
||||
<i class="{categories.icon} icon-4x"></i>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<!-- END categories -->
|
||||
</ul>
|
||||
</div>
|
||||
@@ -18,7 +18,7 @@
|
||||
<div class="post-block">
|
||||
<div id="content_{posts.pid}" class="post-content">{posts.content}</div>
|
||||
<div class="profile-block">
|
||||
<img class="hidden-desktop" src="{posts.gravatar}10" align="left" /> posted by <strong>{posts.username}</strong> {posts.relativeTime} ago
|
||||
<img class="hidden-desktop" src="{posts.gravatar}10" align="left" /> posted by <strong><a href="/users/{posts.uid}">{posts.username}</a></strong> {posts.relativeTime} ago
|
||||
<span class="post-buttons">
|
||||
<div id="ids_{posts.pid}_{posts.uid}" class="edit {posts.display_moderator_tools} hidden-phone"><i class="icon-pencil"></i></div>
|
||||
<div id="ids_{posts.pid}_{posts.uid}" class="delete {posts.display_moderator_tools} hidden-phone"><i class="icon-trash"></i></div>
|
||||
@@ -106,7 +106,7 @@
|
||||
usercount = usernames.length;
|
||||
|
||||
for (var i = 0, ii=usercount; i<ii; i++) {
|
||||
usernames[i] = '<strong>' + usernames[i] + '</strong>';
|
||||
usernames[i] = '<strong>' + '<a href="/users/'+users.uids[i]+'">' + usernames[i] + '</a></strong>';
|
||||
}
|
||||
|
||||
// headexplosion.gif for fun, to see if I could do this in one line of code. feel free to refactor haha
|
||||
|
||||
@@ -15,6 +15,8 @@ var RDB = require('./redis.js'),
|
||||
// Topic Info
|
||||
RDB.set('cid:' + cid + ':name', data.name);
|
||||
RDB.set('cid:' + cid + ':description', data.description);
|
||||
RDB.set('cid:' + cid + ':icon', data.icon);
|
||||
RDB.set('cid:' + cid + ':blockclass', data.blockclass);
|
||||
RDB.set('cid:' + cid + ':slug', slug);
|
||||
|
||||
RDB.set('category:slug:' + slug + ':cid', cid);
|
||||
@@ -29,11 +31,15 @@ var RDB = require('./redis.js'),
|
||||
RDB.lrange('categories:cid', 0, -1, function(cids) {
|
||||
var name = [],
|
||||
description = [],
|
||||
icon = [],
|
||||
blockclass = [],
|
||||
slug = [];
|
||||
|
||||
for (var i=0, ii=cids.length; i<ii; i++) {
|
||||
name.push('cid:' + cids[i] + ':name');
|
||||
description.push('cid:' + cids[i] + ':description');
|
||||
icon.push('cid:' + cids[i] + ':icon');
|
||||
blockclass.push('cid:' + cids[i] + ':blockclass');
|
||||
slug.push('cid:' + cids[i] + ':slug');
|
||||
}
|
||||
|
||||
@@ -41,11 +47,15 @@ var RDB = require('./redis.js'),
|
||||
RDB.multi()
|
||||
.mget(name)
|
||||
.mget(description)
|
||||
.mget(icon)
|
||||
.mget(blockclass)
|
||||
.mget(slug)
|
||||
.exec(function(err, replies) {
|
||||
name = replies[0];
|
||||
description = replies[1];
|
||||
slug = replies[2];
|
||||
icon = replies[2];
|
||||
blockclass = replies[3];
|
||||
slug = replies[4];
|
||||
|
||||
var categories = [];
|
||||
for (var i=0, ii=cids.length; i<ii; i++) {
|
||||
@@ -54,6 +64,8 @@ var RDB = require('./redis.js'),
|
||||
'cid' : cids[i],
|
||||
'slug' : slug[i],
|
||||
'description' : description[i],
|
||||
'blockclass' : blockclass[i],
|
||||
'icon' : icon[i],
|
||||
/*'topics' : [0,1], later
|
||||
'latest_post' : {
|
||||
'uid' : 1,
|
||||
|
||||
@@ -67,7 +67,11 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
callback({'category_id': category_id, 'topics': topics});
|
||||
callback({
|
||||
'show_topic_button' : category_id ? 'show' : 'hidden',
|
||||
'category_id': category_id,
|
||||
'topics': topics
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -326,17 +326,13 @@ var config = require('../config.js'),
|
||||
RDB.get('username:' + username + ':uid', callback);
|
||||
};
|
||||
|
||||
User.get_username_by_uid = function(uid, callback) {
|
||||
User.getUserField(uid, 'username', callback);
|
||||
};
|
||||
|
||||
User.get_usernames_by_uids = function(uids, callback) {
|
||||
|
||||
var usernames = [];
|
||||
|
||||
for(var i=0, ii=uids.length; i<ii; ++i) {
|
||||
|
||||
User.get_username_by_uid(uids[i], function(username){
|
||||
User.getUserField(uids[i],'username', function(username){
|
||||
|
||||
usernames.push(username);
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@ passport.deserializeUser(function(uid, done) {
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
// Dunno wtf this does
|
||||
// app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
|
||||
// Useful if you want to use app.put and app.delete (instead of app.post all the time)
|
||||
@@ -124,7 +125,7 @@ passport.deserializeUser(function(uid, done) {
|
||||
|
||||
// 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'];
|
||||
var routes = ['', 'login', 'register', 'account', 'latest', 'popular', 'active'];
|
||||
|
||||
for (var i=0, ii=routes.length; i<ii; i++) {
|
||||
(function(route) {
|
||||
@@ -191,11 +192,25 @@ passport.deserializeUser(function(uid, done) {
|
||||
break;
|
||||
case 'category' :
|
||||
global.modules.topics.get(function(data) {
|
||||
console.log(data);
|
||||
res.send(JSON.stringify(data));
|
||||
}, req.params.id);
|
||||
break;
|
||||
case 'account' :
|
||||
case 'latest' :
|
||||
global.modules.topics.get(function(data) {
|
||||
res.send(JSON.stringify(data));
|
||||
});
|
||||
break;
|
||||
case 'popular' :
|
||||
global.modules.topics.get(function(data) {
|
||||
res.send(JSON.stringify(data));
|
||||
});
|
||||
break;
|
||||
case 'active' :
|
||||
global.modules.topics.get(function(data) {
|
||||
res.send(JSON.stringify(data));
|
||||
});
|
||||
break;
|
||||
case 'users' :
|
||||
get_account_fn(req, res, function(userData) {
|
||||
res.send(JSON.stringify(userData));
|
||||
});
|
||||
@@ -313,19 +328,24 @@ passport.deserializeUser(function(uid, done) {
|
||||
//to baris, move this into account.js or sth later - just moved this out here for you to utilize client side tpl parsing
|
||||
//I didn't want to change too much so you should probably sort out the params etc
|
||||
function get_account_fn(req, res, callback) {
|
||||
console.log("GOING TO ACCOUNT");
|
||||
|
||||
if (req.user === undefined)
|
||||
return res.redirect('/403');
|
||||
|
||||
user.getUserData(req.user.uid, function(data) {
|
||||
var requestedUserId = req.user.uid;
|
||||
|
||||
if(req.params.id != req.user.uid)
|
||||
requestedUserId = req.params.id;
|
||||
|
||||
user.getUserData(requestedUserId, function(data) {
|
||||
if(data)
|
||||
{
|
||||
data.joindate = utils.relativeTime(data.joindate);
|
||||
|
||||
console.log("user data" + JSON.stringify(data));
|
||||
|
||||
var userData = {user:data};
|
||||
callback(userData);
|
||||
callback({user:data});
|
||||
}
|
||||
else
|
||||
callback({user:{}});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -349,11 +369,28 @@ passport.deserializeUser(function(uid, done) {
|
||||
res.send('User list');
|
||||
});
|
||||
|
||||
app.get('/users/:username', function(req, res) {
|
||||
global.modules.user.get_uid_by_username(req.params.username, function(uid) {
|
||||
res.send('User profile for uid: ' + uid);
|
||||
});
|
||||
app.get('/users/:uid', handleUserProfile);
|
||||
app.get('/users/:uid/:username*', handleUserProfile);
|
||||
|
||||
|
||||
function handleUserProfile(req, res) {
|
||||
|
||||
if(req.params.uid == 0) {
|
||||
res.send("User doesn't exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
user.getUserData(req.params.uid, function(data) {
|
||||
if(data) {
|
||||
if(req.url.indexOf(data.username) == -1)
|
||||
res.redirect(301, '/users/'+req.params.uid+'/'+data.username);
|
||||
else
|
||||
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("users/' + req.params.uid +'/'+data.username + '");});</script>' + templates['footer']);
|
||||
}
|
||||
else
|
||||
res.send("User doesn't exist!");
|
||||
});
|
||||
}
|
||||
|
||||
app.get('/test', function(req, res) {
|
||||
global.modules.topics.delete(1, 1);
|
||||
|
||||
@@ -123,12 +123,6 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
||||
|
||||
});
|
||||
|
||||
socket.on('api:user.getNameByUid', function(data) {
|
||||
modules.user.get_username_by_uid(data.uid, function(data){
|
||||
socket.emit('api:user.getNameByUid', data);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('user.exists', function(data) {
|
||||
modules.user.exists(socket, data.username);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user