nodebb-plugin-group-gallery 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +8 -0
- package/.gitattributes +22 -0
- package/LICENSE +8 -0
- package/README.md +3 -0
- package/lib/comments.js +178 -0
- package/lib/config.js +47 -0
- package/lib/gallery.js +206 -0
- package/lib/nodebb.js +19 -0
- package/lib/sockets.js +113 -0
- package/lib/upgrade.js +101 -0
- package/library.js +258 -0
- package/package.json +34 -0
- package/plugin.json +30 -0
- package/static/js/lib/comments.js +163 -0
- package/static/js/lib/modal.js +111 -0
- package/static/js/lib/overview.js +15 -0
- package/static/js/lib/single.js +64 -0
- package/static/js/lib/uploader.js +37 -0
- package/static/js/main.js +147 -0
- package/static/less/style.less +145 -0
- package/static/templates/group-gallery/comments.tpl +15 -0
- package/static/templates/group-gallery/gallery.tpl +30 -0
- package/static/templates/group-gallery/modal/wrap.tpl +25 -0
- package/static/templates/group-gallery/single.tpl +75 -0
- package/static/templates/group-gallery/widget.tpl +18 -0
- package/static/vendor/fancybox/blank.gif +0 -0
- package/static/vendor/fancybox/fancybox_loading.gif +0 -0
- package/static/vendor/fancybox/fancybox_loading@2x.gif +0 -0
- package/static/vendor/fancybox/fancybox_overlay.png +0 -0
- package/static/vendor/fancybox/fancybox_sprite.png +0 -0
- package/static/vendor/fancybox/fancybox_sprite@2x.png +0 -0
- package/static/vendor/fancybox/jquery.fancybox-thumbs.css +55 -0
- package/static/vendor/fancybox/jquery.fancybox-thumbs.js +162 -0
- package/static/vendor/fancybox/jquery.fancybox.css +274 -0
- package/static/vendor/fancybox/jquery.fancybox.pack.js +46 -0
package/.editorconfig
ADDED
package/.gitattributes
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Auto detect text files and perform LF normalization
|
|
2
|
+
* text=auto
|
|
3
|
+
|
|
4
|
+
# Custom for Visual Studio
|
|
5
|
+
*.cs diff=csharp
|
|
6
|
+
*.sln merge=union
|
|
7
|
+
*.csproj merge=union
|
|
8
|
+
*.vbproj merge=union
|
|
9
|
+
*.fsproj merge=union
|
|
10
|
+
*.dbproj merge=union
|
|
11
|
+
|
|
12
|
+
# Standard to msysgit
|
|
13
|
+
*.doc diff=astextplain
|
|
14
|
+
*.DOC diff=astextplain
|
|
15
|
+
*.docx diff=astextplain
|
|
16
|
+
*.DOCX diff=astextplain
|
|
17
|
+
*.dot diff=astextplain
|
|
18
|
+
*.DOT diff=astextplain
|
|
19
|
+
*.pdf diff=astextplain
|
|
20
|
+
*.PDF diff=astextplain
|
|
21
|
+
*.rtf diff=astextplain
|
|
22
|
+
*.RTF diff=astextplain
|
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright (c) 2013-2014, psychobunny <psycho.bunny@hotmail.com>
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
|
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
package/lib/comments.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var NodeBB = require('./nodebb'),
|
|
4
|
+
User = NodeBB.User,
|
|
5
|
+
Plugins = NodeBB.Plugins,
|
|
6
|
+
db = NodeBB.db,
|
|
7
|
+
|
|
8
|
+
async = require('async'),
|
|
9
|
+
|
|
10
|
+
Comments = {};
|
|
11
|
+
|
|
12
|
+
Comments.addComment = function(imageId, uid, content, callback) {
|
|
13
|
+
db.incrObjectField('group-gallery', 'nextCommentId', function(err, nextCommentId) {
|
|
14
|
+
if (err) {
|
|
15
|
+
callback(err);
|
|
16
|
+
} else {
|
|
17
|
+
var comment = {
|
|
18
|
+
id: nextCommentId,
|
|
19
|
+
image: imageId,
|
|
20
|
+
uid: uid,
|
|
21
|
+
content: content,
|
|
22
|
+
deleted: 0,
|
|
23
|
+
timestamp: Date.now()
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
async.parallel([
|
|
27
|
+
function(next) {
|
|
28
|
+
db.setObject('group-gallery:comment:' + nextCommentId, comment, next);
|
|
29
|
+
},
|
|
30
|
+
function(next) {
|
|
31
|
+
db.sortedSetAdd('group-gallery:images:' + imageId + ':comments', comment.timestamp, nextCommentId, next)
|
|
32
|
+
}
|
|
33
|
+
], function(err) {
|
|
34
|
+
if (err) {
|
|
35
|
+
callback(err);
|
|
36
|
+
} else {
|
|
37
|
+
getComments([nextCommentId], function(err, comments) {
|
|
38
|
+
callback(err, comments);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
Comments.getComments = function(imageId, start, end, callback) {
|
|
47
|
+
db.getSortedSetRange('group-gallery:images:' + imageId + ':comments', start, end, function(err, ids) {
|
|
48
|
+
if (err || !ids || !ids.length) {
|
|
49
|
+
return callback(err, []);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getComments(ids, callback);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
Comments.getRawComments = function(ids, callback) {
|
|
57
|
+
var keys = ids.map(function(id) {
|
|
58
|
+
return 'group-gallery:comment:' + id;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
db.getObjects(keys, callback);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
function getComments(ids, callback) {
|
|
65
|
+
var keys = ids.map(function(id) {
|
|
66
|
+
return 'group-gallery:comment:' + id;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
db.getObjects(keys, function(err, comments) {
|
|
70
|
+
if (err) {
|
|
71
|
+
callback(err);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
var userData, uids = comments.map(function(c) {
|
|
76
|
+
return parseInt(c.deleted, 10) !== 1 ? parseInt(c.uid, 10) : null;
|
|
77
|
+
}).filter(function(u, index, self) {
|
|
78
|
+
return u === null ? false : self.indexOf(u) === index;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
User.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], function(err, usersData) {
|
|
82
|
+
if (err) {
|
|
83
|
+
return callback(err);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
comments = comments.map(function (comment, index) {
|
|
87
|
+
comment.id = ids[index];
|
|
88
|
+
return comment;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
async.map(comments, function(comment, next) {
|
|
92
|
+
if (parseInt(comment.deleted, 10) === 1) {
|
|
93
|
+
next();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
userData = usersData[uids.indexOf(parseInt(comment.uid))];
|
|
98
|
+
|
|
99
|
+
Comments.parse(comment.content, userData, function(err, s) {
|
|
100
|
+
comment.user = s.user;
|
|
101
|
+
comment.content = s.content;
|
|
102
|
+
|
|
103
|
+
next(null, comment);
|
|
104
|
+
});
|
|
105
|
+
}, function(err, comments) {
|
|
106
|
+
async.filter(comments, function(item, next) {
|
|
107
|
+
next(!!item);
|
|
108
|
+
}, function(result) {
|
|
109
|
+
callback(err, result);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Comments.parse = function(message, userData, callback) {
|
|
117
|
+
Plugins.fireHook('filter:parse.raw', message, function(err, parsed) {
|
|
118
|
+
callback(null, {
|
|
119
|
+
user: userData,
|
|
120
|
+
content: parsed
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
Comments.removeComment = function(uid, commentId, callback) {
|
|
126
|
+
async.parallel({
|
|
127
|
+
comment: function(next) {
|
|
128
|
+
db.getObject('group-gallery:comment:' + commentId, next);
|
|
129
|
+
},
|
|
130
|
+
isAdmin: function(next) {
|
|
131
|
+
User.isAdministrator(uid, next);
|
|
132
|
+
}
|
|
133
|
+
}, function(err, result) {
|
|
134
|
+
if (err) {
|
|
135
|
+
callback(err);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (parseInt(result.comment.uid, 10) === parseInt(uid, 10) || result.isAdmin) {
|
|
140
|
+
async.parallel([
|
|
141
|
+
function(next) {
|
|
142
|
+
db.delete('group-gallery:comment:' + commentId, next);
|
|
143
|
+
},
|
|
144
|
+
function(next) {
|
|
145
|
+
db.sortedSetRemove('group-gallery:images:' + result.comment.image + ':comments', commentId, next);
|
|
146
|
+
}
|
|
147
|
+
], callback);
|
|
148
|
+
} else {
|
|
149
|
+
callback(new Error('unauthorized'));
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
Comments.editComment = function(uid, commentId, content, callback) {
|
|
155
|
+
async.parallel({
|
|
156
|
+
comment: function(next) {
|
|
157
|
+
db.getObject('group-gallery:comment:' + commentId, next);
|
|
158
|
+
},
|
|
159
|
+
isAdmin: function(next) {
|
|
160
|
+
User.isAdministrator(uid, next);
|
|
161
|
+
}
|
|
162
|
+
}, function(err, result) {
|
|
163
|
+
if (err) {
|
|
164
|
+
callback(err);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (parseInt(result.comment.uit, 10) === parseInt(uid, 10) || result.isAdmin) {
|
|
169
|
+
db.setObjectField('group-gallery:comment:' + commentId, 'content', content, function(err) {
|
|
170
|
+
getComments([commentId], callback);
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
callback(new Error('unauthorized'));
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
module.exports = Comments;
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var packageInfo = require('../package.json'),
|
|
4
|
+
pluginInfo = require('../plugin.json'),
|
|
5
|
+
pluginId = pluginInfo.id.replace('nodebb-plugin-', ''),
|
|
6
|
+
|
|
7
|
+
NodeBB = require('./nodebb'),
|
|
8
|
+
Settings = NodeBB.Settings,
|
|
9
|
+
|
|
10
|
+
Config = {};
|
|
11
|
+
|
|
12
|
+
var adminDefaults = {
|
|
13
|
+
version: ''
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
Config.plugin = {
|
|
17
|
+
name: pluginInfo.name,
|
|
18
|
+
description: pluginInfo.description,
|
|
19
|
+
id: pluginId,
|
|
20
|
+
version: packageInfo.version,
|
|
21
|
+
icon: 'fa-picture-o'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
Config.adminSockets = {
|
|
25
|
+
sync: function() {
|
|
26
|
+
Config.global.sync();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
Config.init = function(callback) {
|
|
31
|
+
Config.global = new NodeBB.Settings(Config.plugin.id, Config.plugin.version, adminDefaults, function() {
|
|
32
|
+
var oldVersion = Config.global.get('version');
|
|
33
|
+
|
|
34
|
+
if (oldVersion < Config.plugin.version) {
|
|
35
|
+
Config.global.set('version', Config.plugin.version);
|
|
36
|
+
Config.global.persist(function() {
|
|
37
|
+
require('./upgrade').doUpgrade(oldVersion, Config.plugin.version, callback);
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
callback();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
Config.global = {};
|
|
46
|
+
|
|
47
|
+
module.exports = Config;
|
package/lib/gallery.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var NodeBB = require('./nodebb'),
|
|
4
|
+
|
|
5
|
+
async = require('async'),
|
|
6
|
+
|
|
7
|
+
Gallery = {};
|
|
8
|
+
|
|
9
|
+
Gallery.addImage = function(params, callback) {
|
|
10
|
+
if (!params || !params.group || !params.url || !params.uid) {
|
|
11
|
+
callback(new Error('invalid-data'));
|
|
12
|
+
} else {
|
|
13
|
+
var groupSlug = NodeBB.utils.slugify(params.group);
|
|
14
|
+
NodeBB.db.incrObjectField('group-gallery', 'nextImageId', function(err, nextImageId) {
|
|
15
|
+
var image = {
|
|
16
|
+
id: nextImageId,
|
|
17
|
+
group: groupSlug,
|
|
18
|
+
caption: params.caption || '',
|
|
19
|
+
uid: params.uid,
|
|
20
|
+
url: params.url,
|
|
21
|
+
timestamp: Date.now(),
|
|
22
|
+
viewcount: 0
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
async.parallel([
|
|
26
|
+
function(next) {
|
|
27
|
+
NodeBB.db.setObject('group-gallery:images:' + nextImageId, image, next);
|
|
28
|
+
},
|
|
29
|
+
function(next) {
|
|
30
|
+
NodeBB.db.sortedSetAdd('group-gallery:group:' + groupSlug + ':images', image.timestamp, nextImageId, next);
|
|
31
|
+
}
|
|
32
|
+
], function(err, result) {
|
|
33
|
+
getImages([nextImageId], callback);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
Gallery.removeImage = function(uid, imageId, callback) {
|
|
40
|
+
async.parallel({
|
|
41
|
+
image: function(next) {
|
|
42
|
+
NodeBB.db.getObject('group-gallery:images:' + imageId, next);
|
|
43
|
+
},
|
|
44
|
+
isAdmin: function(next) {
|
|
45
|
+
NodeBB.User.isAdministrator(uid, next);
|
|
46
|
+
}
|
|
47
|
+
}, function(err, result) {
|
|
48
|
+
if (err || !result.image) {
|
|
49
|
+
callback(err);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (parseInt(result.image.uid, 10) === parseInt(uid, 10) || result.isAdmin) {
|
|
54
|
+
async.parallel([
|
|
55
|
+
function(next) {
|
|
56
|
+
NodeBB.db.delete('group-gallery:images:' + imageId, next);
|
|
57
|
+
},
|
|
58
|
+
function(next) {
|
|
59
|
+
NodeBB.db.sortedSetRemove('group-gallery:group:' + result.image.group + ':images', imageId, next);
|
|
60
|
+
}
|
|
61
|
+
], callback);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
Gallery.getGroupImageCount = function(group, callback) {
|
|
67
|
+
if (!group) {
|
|
68
|
+
callback(new Error('invalid-data'), []);
|
|
69
|
+
} else {
|
|
70
|
+
group = NodeBB.utils.slugify(group);
|
|
71
|
+
|
|
72
|
+
NodeBB.db.sortedSetCard('group-gallery:group:' + group + ':images', function(err, result) {
|
|
73
|
+
callback(err, result ? result : 0);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
Gallery.getGroupImageCountByUid = function(group, uid, callback) {
|
|
79
|
+
if (!group || !uid || isNaN(parseInt(uid, 10))) {
|
|
80
|
+
callback(new Error('invalid-data'), []);
|
|
81
|
+
} else {
|
|
82
|
+
group = NodeBB.utils.slugify(group);
|
|
83
|
+
|
|
84
|
+
NodeBB.db.getSortedSetRange('group-gallery:group:' + group + ':images', 0, -1, function(err, result) {
|
|
85
|
+
async.filter(result, function(image, next) {
|
|
86
|
+
next(parseInt(image.uid, 10) === parseInt(uid, 10));
|
|
87
|
+
}, function(results) {
|
|
88
|
+
callback(null, results.length);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
Gallery.getImagesByGroupName = function(group, start, end, callback) {
|
|
95
|
+
if (!group) {
|
|
96
|
+
callback(new Error('invalid-data'), []);
|
|
97
|
+
} else {
|
|
98
|
+
group = NodeBB.utils.slugify(group);
|
|
99
|
+
start = parseInt(start, 10);
|
|
100
|
+
end = parseInt(end, 10);
|
|
101
|
+
|
|
102
|
+
NodeBB.db.getSortedSetRevRange('group-gallery:group:' + group + ':images',
|
|
103
|
+
isNaN(start) ? 0 : start, isNaN(end) ? -1 : end, function(err, ids) {
|
|
104
|
+
if (err) {
|
|
105
|
+
callback(err, []);
|
|
106
|
+
} else {
|
|
107
|
+
getImages(ids, callback);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
Gallery.getImagesByUid = function(group, uid, start, end, callback) {
|
|
115
|
+
if (!group || !uid || isNaN(parseInt(uid, 10))) {
|
|
116
|
+
callback(new Error('invalid-data'), []);
|
|
117
|
+
} else {
|
|
118
|
+
group = NodeBB.utils.slugify(group);
|
|
119
|
+
uid = parseInt(uid, 10);
|
|
120
|
+
start = parseInt(start, 10);
|
|
121
|
+
end = parseInt(end, 10);
|
|
122
|
+
|
|
123
|
+
NodeBB.db.getSortedSetRevRange('group-gallery:group:' + group + ':images',
|
|
124
|
+
isNaN(start) ? 0 : start, -1, function(err, ids) {
|
|
125
|
+
if (err) {
|
|
126
|
+
callback(err, []);
|
|
127
|
+
} else {
|
|
128
|
+
getImages(ids, function(err, images) {
|
|
129
|
+
async.filter(images, function(image, next) {
|
|
130
|
+
next(parseInt(image.uid, 10) === uid);
|
|
131
|
+
}, function(results) {
|
|
132
|
+
callback(null, results.splice(0, end + 1));
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
Gallery.getImagesByIds = function(ids, callback) {
|
|
142
|
+
if (!ids || !Array.isArray(ids)) {
|
|
143
|
+
callback(new Error('invalid-data'), []);
|
|
144
|
+
} else {
|
|
145
|
+
getImages(ids, callback);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
function getImages(ids, callback) {
|
|
150
|
+
var keys = ids.map(function(id) {
|
|
151
|
+
return 'group-gallery:images:' + id;
|
|
152
|
+
}), userFields = ['uid', 'username', 'userslug'], uids;
|
|
153
|
+
|
|
154
|
+
NodeBB.db.getObjects(keys, function(err, images) {
|
|
155
|
+
if (err) {
|
|
156
|
+
callback(err, []);
|
|
157
|
+
} else {
|
|
158
|
+
// Get a list of unique uids of the users
|
|
159
|
+
uids = images.map(function(i) {
|
|
160
|
+
return i.uid;
|
|
161
|
+
}).filter(function(uid, index, self) {
|
|
162
|
+
return self.indexOf(uid) === index;
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
NodeBB.User.getMultipleUserFields(uids, userFields, function(err, usersData) {
|
|
166
|
+
if (err) return callback(err, []);
|
|
167
|
+
|
|
168
|
+
async.map(images, function(image, next) {
|
|
169
|
+
NodeBB.db.sortedSetCard('group-gallery:images:' + image.id + ':comments', function(err, commentCount) {
|
|
170
|
+
image.author = usersData[uids.indexOf(parseInt(image.uid, 10))];
|
|
171
|
+
image.commentcount = commentCount || 0;
|
|
172
|
+
image.caption = image.caption || 'No caption';
|
|
173
|
+
|
|
174
|
+
next(null, image);
|
|
175
|
+
});
|
|
176
|
+
}, callback);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
Gallery.renameGroup = function(oldName, newName) {
|
|
183
|
+
async.parallel([
|
|
184
|
+
function(next) {
|
|
185
|
+
NodeBB.db.rename(
|
|
186
|
+
'group-gallery:group:' + NodeBB.utils.slugify(oldName) + ':images',
|
|
187
|
+
'group-gallery:group:' + NodeBB.utils.slugify(newName) + ':images',
|
|
188
|
+
next
|
|
189
|
+
);
|
|
190
|
+
},
|
|
191
|
+
function(next) {
|
|
192
|
+
NodeBB.db.rename(
|
|
193
|
+
'group-gallery:group:' + NodeBB.utils.slugify(oldName),
|
|
194
|
+
'group-gallery:group:' + NodeBB.utils.slugify(newName),
|
|
195
|
+
next
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
]);
|
|
199
|
+
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
Gallery.increaseViewCount = function(id, callback) {
|
|
203
|
+
NodeBB.db.incrObjectField('group-gallery:images:' + id, 'viewcount', callback);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
module.exports = Gallery;
|
package/lib/nodebb.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
(function(NodeBB) {
|
|
2
|
+
module.exports = {
|
|
3
|
+
// NodeBB modules
|
|
4
|
+
Settings: NodeBB.require('./src/settings'),
|
|
5
|
+
SocketIndex: NodeBB.require('./src/socket.io/index'),
|
|
6
|
+
SocketPlugins: NodeBB.require('./src/socket.io/plugins'),
|
|
7
|
+
SocketAdmin: NodeBB.require('./src/socket.io/admin').plugins,
|
|
8
|
+
User: NodeBB.require('./src/user'),
|
|
9
|
+
Groups: NodeBB.require('./src/groups'),
|
|
10
|
+
Plugins: NodeBB.require('./src/plugins'),
|
|
11
|
+
UploadsController: NodeBB.require('./src/controllers/uploads'),
|
|
12
|
+
ControllerHelpers: NodeBB.require('./src/controllers/helpers'),
|
|
13
|
+
Pagination: NodeBB.require('./src/pagination'),
|
|
14
|
+
db: NodeBB.require('./src/database'),
|
|
15
|
+
Templates: NodeBB.require('templates.js'),
|
|
16
|
+
utils: NodeBB.require('./public/src/utils'),
|
|
17
|
+
winston: NodeBB.require('winston')
|
|
18
|
+
}
|
|
19
|
+
})(require.main);
|
package/lib/sockets.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var NodeBB = require('./nodebb'),
|
|
4
|
+
|
|
5
|
+
Comments = require('./comments'),
|
|
6
|
+
Gallery = require('./gallery'),
|
|
7
|
+
|
|
8
|
+
async = require('async'),
|
|
9
|
+
S = require('string'),
|
|
10
|
+
|
|
11
|
+
Sockets = {};
|
|
12
|
+
|
|
13
|
+
Sockets.removeImage = function(socket, data, callback) {
|
|
14
|
+
if (socket.uid === 0 || !data || isNaN(parseInt(data.imageId, 10))) {
|
|
15
|
+
callback(new Error('invalid-data'), []);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Gallery.removeImage(socket.uid, data.imageId, function(err, result) {
|
|
20
|
+
if (err) {
|
|
21
|
+
callback(err);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
NodeBB.SocketIndex.server.sockets.emit('event:group-gallery.removeImage', data.imageId);
|
|
26
|
+
callback(null, true);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
Sockets.getComments = function(socket, data, callback) {
|
|
31
|
+
if (socket.uid === 0 || !data || isNaN(parseInt(data.imageId, 10))) {
|
|
32
|
+
callback(new Error('invalid-data'), []);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var start = 0, end = -1;
|
|
37
|
+
Comments.getComments(data.imageId, start, end, callback);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Sockets.addComment = function(socket, data, callback) {
|
|
41
|
+
if (socket.uid === 0 || !data || isNaN(parseInt(data.imageId, 10))) {
|
|
42
|
+
callback(new Error('invalid-data'));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var comment = S(data.comment).stripTags().trim().s;
|
|
47
|
+
if (comment.length) {
|
|
48
|
+
async.waterfall([
|
|
49
|
+
function(next) {
|
|
50
|
+
Gallery.getImagesByIds([data.imageId], next);
|
|
51
|
+
},
|
|
52
|
+
function(image, next) {
|
|
53
|
+
NodeBB.Groups.isMember(socket.uid, image.group, next);
|
|
54
|
+
},
|
|
55
|
+
function(isMember, next) {
|
|
56
|
+
Comments.addComment(data.imageId, socket.uid, comment, next);
|
|
57
|
+
}
|
|
58
|
+
], function(err, result) {
|
|
59
|
+
if (err) {
|
|
60
|
+
callback(err);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
NodeBB.SocketIndex.server.sockets.emit('event:group-gallery.newComment', result);
|
|
65
|
+
callback(null, result);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
Sockets.removeComment = function(socket, data, callback) {
|
|
71
|
+
if (socket.uid === 0 || !data || isNaN(parseInt(data.commentId, 10))) {
|
|
72
|
+
callback(new Error('invalid-data'));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Comments.removeComment(socket.uid, data.commentId, function(err, result) {
|
|
77
|
+
if (err) {
|
|
78
|
+
callback(err);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
NodeBB.SocketIndex.server.sockets.emit('event:group-gallery.removeComment', data.commentId);
|
|
83
|
+
callback(null, true);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
Sockets.editComment = function(socket, data, callback) {
|
|
88
|
+
if (socket.uid === 0 || !data || isNaN(parseInt(data.commentId, 10)) || !data.content) {
|
|
89
|
+
callback(new Error('invalid-data'));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Comments.editComment(socket.uid, data.commentId, data.content, function(err, result) {
|
|
94
|
+
if (err) {
|
|
95
|
+
callback(err);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
NodeBB.SocketIndex.server.sockets.emit('event:group-gallery.editComment', result);
|
|
100
|
+
callback(null, true);
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
Sockets.getRawComment = function(socket, data, callback) {
|
|
105
|
+
if (socket.uid === 0 || !data || isNaN(parseInt(data.commentId, 10))) {
|
|
106
|
+
callback(new Error('invalid-data'));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
Comments.getRawComments([data.commentId], callback);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
module.exports = Sockets;
|