diff --git a/app.js b/app.js index 614a9dd5cd..e448a6a534 100644 --- a/app.js +++ b/app.js @@ -20,11 +20,11 @@ global.configuration = {}; if (data.categories.length === 0) { console.log('Setting up default categories...'); - fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, categories) { - categories = JSON.parse(categories); + fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, default_categories) { + default_categories = JSON.parse(default_categories); - for (var category in categories) { - categories.create(categories[category]); + for (var category in default_categories) { + categories.create(default_categories[category]); } }); diff --git a/package.json b/package.json index 69583881ff..72e0ad08c3 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "marked": "0.2.8", "bcrypt": "0.7.5", "node-gyp": "0.9.5", - "async": "0.2.8" + "async": "0.2.8", + "node-imagemagick": "0.1.8" }, "devDependencies": {}, "optionalDependencies": {}, diff --git a/public/src/app.js b/public/src/app.js index d5404d66ab..e2bda92774 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -31,10 +31,16 @@ var socket, contentEl.value = data.post; }); + + socket.on('disconnect', function(data){ + $('#disconnect-modal').show(); + $('#reload-button').on('click',function(){ + $('#disconnect-modal').hide(); + window.location.reload(); + }); + }); }, async: false - - }); // use unique alert_id to have multiple alerts visible at a time, use the same alert_id to fade out the current instance @@ -274,7 +280,33 @@ var socket, }, false); // Posting + var formattingBar = document.getElementById('formatting-bar'), + postContentEl = document.getElementById('post_content'); jQuery('#post_window').slideToggle(0); + formattingBar.addEventListener('click', function(e) { + if (e.target.nodeName === 'I') { + switch(e.target.className) { + case 'icon-bold': + var cursorEnd = postContentEl.value.length; + postContentEl.value = postContentEl.value + '**bolded text**'; + postContentEl.selectionStart = cursorEnd+2; + postContentEl.selectionEnd = postContentEl.value.length - 2; + break; + case 'icon-italic': + var cursorEnd = postContentEl.value.length; + postContentEl.value = postContentEl.value + '*italicised text*'; + postContentEl.selectionStart = cursorEnd+1; + postContentEl.selectionEnd = postContentEl.value.length - 1; + break; + case 'icon-list': + var cursorEnd = postContentEl.value.length; + postContentEl.value = postContentEl.value + "\n\n* list item"; + postContentEl.selectionStart = cursorEnd+4; + postContentEl.selectionEnd = postContentEl.value.length; + break; + } + } + }, false); }) diff --git a/public/templates/account.tpl b/public/templates/account.tpl index eba82fcc6f..91c76d4ad9 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -59,7 +59,7 @@
- Add Friend + Follow

@@ -72,6 +72,8 @@ var theirid = '{theirid}'; (function() { + var isFriend = {isFriend}; + function addCommas(text) { return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); } @@ -90,7 +92,10 @@ var theirid = '{theirid}'; if( yourid !== theirid) { editLink.hide(); - addFriendBtn.show(); + if(isFriend) + addFriendBtn.hide(); + else + addFriendBtn.show(); } else { addFriendBtn.hide(); @@ -99,16 +104,14 @@ var theirid = '{theirid}'; addFriendBtn.on('click', function() { $.post('/users/addfriend', {uid: theirid}, function(data) { + addFriendBtn.remove(); $('#user-action-alert').html('Friend Added!').show(); } ); return false; }); - - }); - }()); \ No newline at end of file diff --git a/public/templates/friends.tpl b/public/templates/friends.tpl index 233bafa3ad..57edeb8563 100644 --- a/public/templates/friends.tpl +++ b/public/templates/friends.tpl @@ -32,7 +32,7 @@ {friends.postcount} - Unfriend + Unfollow @@ -72,7 +72,7 @@ var friendCount = '{friendCount}'; $.post('/users/removefriend', {uid: friendid}, function(data) { - button.parent().remove(); + removeBtn.parent().remove(); } ); return false; diff --git a/public/templates/header.tpl b/public/templates/header.tpl index c7b4449ad4..e46d640e9f 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -61,10 +61,10 @@
-
+
- +
@@ -78,6 +78,19 @@
+ + +
\ No newline at end of file diff --git a/src/routes/user.js b/src/routes/user.js index fe92c1913c..ac8fa9a1b8 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -91,20 +91,31 @@ var user = require('./../user.js'), if(!req.user) return res.redirect('/403'); - if(req.files.userPhoto.size > 131072) { + if(req.files.userPhoto.size > 262144) { res.send({ - error: 'Images must be smaller than 128kb!' + error: 'Images must be smaller than 256kb!' }); return; } + var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif']; + var type = req.files.userPhoto.type; + console.log(req.files.userPhoto); + + if(allowedTypes.indexOf(type) === -1) { + res.send({ + error: 'Allowed image types are png, jpg and gif!' + }); + return; + } + user.getUserField(req.user.uid, 'uploadedpicture', function(oldpicture) { if(!oldpicture) { uploadUserPicture(req.user.uid, req.files.userPhoto.name, req.files.userPhoto.path, res); return; } - + var index = oldpicture.lastIndexOf('/'); var filename = oldpicture.substr(index + 1); @@ -152,6 +163,17 @@ var user = require('./../user.js'), user.setUserField(uid, 'uploadedpicture', imageUrl); user.setUserField(uid, 'picture', imageUrl); + var im = require('node-imagemagick'); + + im.resize({ + srcPath: global.configuration['ROOT_DIRECTORY'] + uploadPath, + dstPath: global.configuration['ROOT_DIRECTORY'] + uploadPath, + width: 128 + }, function(err, stdout, stderr){ + if (err) + throw err; + }); + }); os.on('error', function(err) { @@ -244,7 +266,10 @@ var user = require('./../user.js'), }); } else { getUserDataByUserName(req.params.username, callerUID, function(userData) { - res.send(JSON.stringify(userData)); + user.isFriend(callerUID, userData.theirid, function(isFriend) { + userData.isFriend = isFriend; + res.send(JSON.stringify(userData)); + }); }); } @@ -252,8 +277,6 @@ var user = require('./../user.js'), app.get('/api/users/:username?/:section?', api_method); - - function getUserDataByUserName(username, callerUID, callback) { user.get_uid_by_username(username, function(uid) { diff --git a/src/user.js b/src/user.js index 04d0af9ca0..4af1fc23b0 100644 --- a/src/user.js +++ b/src/user.js @@ -378,7 +378,7 @@ var config = require('../config.js'), for(var i=0, ii=data.length; i