diff --git a/.gitignore b/.gitignore index b6a6030307..2438ab09e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ dist/ yarn.lock npm-debug.log + sftp-config.json config.json jsconfig.json @@ -71,4 +72,4 @@ link-plugins.sh test.sh .docker/** -!**/.gitkeep \ No newline at end of file +!**/.gitkeep diff --git a/node_modules/nodebb-plugin-composer-default/.eslintrc b/node_modules/nodebb-plugin-composer-default/.eslintrc new file mode 100644 index 0000000000..74e8dc064a --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "nodebb/lib" +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/.gitattributes b/node_modules/nodebb-plugin-composer-default/.gitattributes new file mode 100644 index 0000000000..412eeda78d --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/node_modules/nodebb-plugin-composer-default/.jshintrc b/node_modules/nodebb-plugin-composer-default/.jshintrc new file mode 100644 index 0000000000..1981c254c5 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/.jshintrc @@ -0,0 +1,86 @@ +{ + // JSHint Default Configuration File (as on JSHint website) + // See http://jshint.com/docs/ for more details + + "maxerr" : 50, // {int} Maximum error before stopping + + // Enforcing + "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) + "camelcase" : false, // true: Identifiers must be in camelCase + "curly" : true, // true: Require {} for every new block or scope + "eqeqeq" : true, // true: Require triple equals (===) for comparison + "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty() + "immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` + "indent" : 4, // {int} Number of spaces to use for indentation + "latedef" : false, // true: Require variables/functions to be defined before being used + "newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()` + "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` + "noempty" : true, // true: Prohibit use of empty blocks + "nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment) + "plusplus" : false, // true: Prohibit use of `++` & `--` + "quotmark" : false, // Quotation mark consistency: + // false : do nothing (default) + // true : ensure whatever is used is consistent + // "single" : require single quotes + // "double" : require double quotes + "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) + "unused" : true, // true: Require all defined variables be used + "strict" : true, // true: Requires all functions run in ES5 Strict Mode + "trailing" : false, // true: Prohibit trailing whitespaces + "maxparams" : false, // {int} Max number of formal params allowed per function + "maxdepth" : false, // {int} Max depth of nested blocks (within functions) + "maxstatements" : false, // {int} Max number statements per function + "maxcomplexity" : false, // {int} Max cyclomatic complexity per function + "maxlen" : false, // {int} Max number of characters per line + + // Relaxing + "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) + "boss" : false, // true: Tolerate assignments where comparisons would be expected + "debug" : false, // true: Allow debugger statements e.g. browser breakpoints. + "eqnull" : false, // true: Tolerate use of `== null` + "es5" : false, // true: Allow ES5 syntax (ex: getters and setters) + "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`) + "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features) + // (ex: `for each`, multiple try/catch, function expression…) + "evil" : false, // true: Tolerate use of `eval` and `new Function()` + "expr" : false, // true: Tolerate `ExpressionStatement` as Programs + "funcscope" : false, // true: Tolerate defining variables inside control statements" + "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict') + "iterator" : false, // true: Tolerate using the `__iterator__` property + "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block + "laxbreak" : false, // true: Tolerate possibly unsafe line breakings + "laxcomma" : false, // true: Tolerate comma-first style coding + "loopfunc" : false, // true: Tolerate functions being defined in loops + "multistr" : false, // true: Tolerate multi-line strings + "proto" : false, // true: Tolerate using the `__proto__` property + "scripturl" : false, // true: Tolerate script-targeted URLs + "smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment + "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;` + "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation + "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;` + "validthis" : false, // true: Tolerate using this in a non-constructor function + + // Environments + "browser" : true, // Web Browser (window, document, etc) + "couch" : false, // CouchDB + "devel" : true, // Development/debugging (alert, confirm, etc) + "dojo" : false, // Dojo Toolkit + "jquery" : true, // jQuery + "mootools" : false, // MooTools + "node" : true, // Node.js + "nonstandard" : false, // Widely adopted globals (escape, unescape, etc) + "prototypejs" : false, // Prototype and Scriptaculous + "rhino" : false, // Rhino + "worker" : false, // Web Workers + "wsh" : false, // Windows Scripting Host + "yui" : false, // Yahoo User Interface + + // Legacy + "nomen" : false, // true: Prohibit dangling `_` in variables + "onevar" : false, // true: Allow only one `var` statement per function + "passfail" : false, // true: Stop on first error + "white" : false, // true: Check against strict whitespace and indentation rules + + // Custom Globals + "globals" : {} // additional predefined global variables +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/LICENSE b/node_modules/nodebb-plugin-composer-default/LICENSE new file mode 100644 index 0000000000..b8658d3aa1 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2016 NodeBB Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/README.md b/node_modules/nodebb-plugin-composer-default/README.md new file mode 100644 index 0000000000..7bcfff9aff --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/README.md @@ -0,0 +1,11 @@ +# Default Composer for NodeBB + +This plugin activates the default composer for NodeBB. It is activated by default, but can be swapped out as necessary. + +## Screenshots + +### Desktop +![Desktop Composer](screenshots/desktop.png?raw=true) + +### Mobile Devices +![Mobile Composer](screenshots/mobile.png?raw=true) \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/controllers.js b/node_modules/nodebb-plugin-composer-default/controllers.js new file mode 100644 index 0000000000..cef271849f --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/controllers.js @@ -0,0 +1,11 @@ +'use strict'; + +const Controllers = {}; + +Controllers.renderAdminPage = function (req, res) { + res.render('admin/plugins/composer-default', { + title: 'Composer (Default)', + }); +}; + +module.exports = Controllers; diff --git a/node_modules/nodebb-plugin-composer-default/library.js b/node_modules/nodebb-plugin-composer-default/library.js new file mode 100644 index 0000000000..c80eef1f5e --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/library.js @@ -0,0 +1,310 @@ +'use strict'; + +const url = require('url'); + +const nconf = require.main.require('nconf'); +const validator = require('validator'); + +const plugins = require.main.require('./src/plugins'); +const topics = require.main.require('./src/topics'); +const categories = require.main.require('./src/categories'); +const posts = require.main.require('./src/posts'); +const user = require.main.require('./src/user'); +const meta = require.main.require('./src/meta'); +const privileges = require.main.require('./src/privileges'); +const translator = require.main.require('./src/translator'); +const utils = require.main.require('./src/utils'); +const helpers = require.main.require('./src/controllers/helpers'); +const SocketPlugins = require.main.require('./src/socket.io/plugins'); +const socketMethods = require('./websockets'); + +const plugin = module.exports; + +plugin.socketMethods = socketMethods; + +plugin.init = async function (data) { + const { router } = data; + const routeHelpers = require.main.require('./src/routes/helpers'); + const controllers = require('./controllers'); + SocketPlugins.composer = socketMethods; + routeHelpers.setupAdminPageRoute(router, '/admin/plugins/composer-default', controllers.renderAdminPage); +}; + +plugin.appendConfig = async function (config) { + config['composer-default'] = await meta.settings.get('composer-default'); + return config; +}; + +plugin.addAdminNavigation = async function (header) { + header.plugins.push({ + route: '/plugins/composer-default', + icon: 'fa-edit', + name: 'Composer (Default)', + }); + return header; +}; + +plugin.addPrefetchTags = async function (hookData) { + const prefetch = [ + '/assets/src/modules/composer.js', '/assets/src/modules/composer/uploads.js', '/assets/src/modules/composer/drafts.js', + '/assets/src/modules/composer/tags.js', '/assets/src/modules/composer/categoryList.js', '/assets/src/modules/composer/resize.js', + '/assets/src/modules/composer/autocomplete.js', '/assets/templates/composer.tpl', + `/assets/language/${meta.config.defaultLang || 'en-GB'}/topic.json`, + `/assets/language/${meta.config.defaultLang || 'en-GB'}/modules.json`, + `/assets/language/${meta.config.defaultLang || 'en-GB'}/tags.json`, + ]; + + hookData.links = hookData.links.concat(prefetch.map(path => ({ + rel: 'prefetch', + href: `${nconf.get('relative_path') + path}?${meta.config['cache-buster']}`, + }))); + + return hookData; +}; + +plugin.getFormattingOptions = async function () { + const defaultVisibility = { + mobile: true, + desktop: true, + + // op or reply + main: true, + reply: true, + }; + let payload = { + defaultVisibility, + options: [ + { + name: 'tags', + title: '[[global:tags.tags]]', + className: 'fa fa-tags', + visibility: { + ...defaultVisibility, + desktop: false, + }, + }, + { + name: 'zen', + title: '[[modules:composer.zen-mode]]', + className: 'fa fa-arrows-alt', + visibility: defaultVisibility, + }, + ], + }; + if (parseInt(meta.config.allowTopicsThumbnail, 10) === 1) { + payload.options.push({ + name: 'thumbs', + title: '[[topic:composer.thumb-title]]', + className: 'fa fa-address-card-o', + badge: true, + visibility: { + ...defaultVisibility, + reply: false, + }, + }); + } + + payload = await plugins.hooks.fire('filter:composer.formatting', payload); + + payload.options.forEach((option) => { + option.visibility = { + ...defaultVisibility, + ...option.visibility || {}, + }; + }); + + return payload ? payload.options : null; +}; + +plugin.filterComposerBuild = async function (hookData) { + const { req } = hookData; + const { res } = hookData; + + if (req.query.p) { + try { + const a = url.parse(req.query.p, true, true); + return helpers.redirect(res, `/${(a.path || '').replace(/^\/*/, '')}`); + } catch (e) { + return helpers.redirect(res, '/'); + } + } else if (!req.query.pid && !req.query.tid && !req.query.cid) { + return helpers.redirect(res, '/'); + } + const [ + isMainPost, + postData, + topicData, + categoryData, + isAdmin, + isMod, + formatting, + tagWhitelist, + globalPrivileges, + canTagTopics, + canScheduleTopics, + ] = await Promise.all([ + posts.isMain(req.query.pid), + getPostData(req), + getTopicData(req), + categories.getCategoryFields(req.query.cid, [ + 'name', 'icon', 'color', 'bgColor', 'backgroundImage', 'imageClass', 'minTags', 'maxTags', + ]), + user.isAdministrator(req.uid), + isModerator(req), + plugin.getFormattingOptions(), + getTagWhitelist(req.query, req.uid), + privileges.global.get(req.uid), + canTag(req), + canSchedule(req), + ]); + + const isEditing = !!req.query.pid; + const isGuestPost = postData && parseInt(postData.uid, 10) === 0; + const save_id = utils.generateSaveId(req.uid); + const discardRoute = generateDiscardRoute(req, topicData); + const body = await generateBody(req, postData); + + let action = 'topics.post'; + let isMain = isMainPost; + if (req.query.tid) { + action = 'posts.reply'; + } else if (req.query.pid) { + action = 'posts.edit'; + } else { + isMain = true; + } + globalPrivileges['topics:tag'] = canTagTopics; + const cid = parseInt(req.query.cid, 10); + const topicTitle = topicData && topicData.title ? topicData.title.replace(/%/g, '%').replace(/,/g, ',') : validator.escape(String(req.query.title || '')); + return { + req: req, + res: res, + templateData: { + disabled: !req.query.pid && !req.query.tid && !req.query.cid, + pid: parseInt(req.query.pid, 10), + tid: parseInt(req.query.tid, 10), + cid: cid || (topicData ? topicData.cid : null), + action: action, + toPid: parseInt(req.query.toPid, 10), + discardRoute: discardRoute, + + resizable: false, + allowTopicsThumbnail: parseInt(meta.config.allowTopicsThumbnail, 10) === 1 && isMain, + + // can't use title property as that is used for page title + topicTitle: topicTitle, + titleLength: topicTitle ? topicTitle.length : 0, + topic: topicData, + thumb: topicData ? topicData.thumb : '', + body: body, + + isMain: isMain, + isTopicOrMain: !!req.query.cid || isMain, + maximumTitleLength: meta.config.maximumTitleLength, + maximumPostLength: meta.config.maximumPostLength, + minimumTagLength: meta.config.minimumTagLength || 3, + maximumTagLength: meta.config.maximumTagLength || 15, + tagWhitelist: tagWhitelist, + selectedCategory: cid ? categoryData : null, + minTags: categoryData.minTags, + maxTags: categoryData.maxTags, + + isTopic: !!req.query.cid, + isEditing: isEditing, + canSchedule: canScheduleTopics, + showHandleInput: meta.config.allowGuestHandles === 1 && + (req.uid === 0 || (isEditing && isGuestPost && (isAdmin || isMod))), + handle: postData ? postData.handle || '' : undefined, + formatting: formatting, + isAdminOrMod: isAdmin || isMod, + save_id: save_id, + privileges: globalPrivileges, + 'composer:showHelpTab': meta.config['composer:showHelpTab'] === 1, + }, + }; +}; + +function generateDiscardRoute(req, topicData) { + if (req.query.cid) { + return `${nconf.get('relative_path')}/category/${validator.escape(String(req.query.cid))}`; + } else if ((req.query.tid || req.query.pid)) { + if (topicData) { + return `${nconf.get('relative_path')}/topic/${topicData.slug}`; + } + return `${nconf.get('relative_path')}/`; + } +} + +async function generateBody(req, postData) { + let body = ''; + // Quoted reply + if (req.query.toPid && parseInt(req.query.quoted, 10) === 1 && postData) { + const username = await user.getUserField(postData.uid, 'username'); + const translated = await translator.translate(`[[modules:composer.user-said, ${username}]]`); + body = `${translated}\n` + + `> ${postData ? `${postData.content.replace(/\n/g, '\n> ')}\n\n` : ''}`; + } else if (req.query.body || req.query.content) { + body = validator.escape(String(req.query.body || req.query.content)); + } + body = postData ? postData.content : ''; + return translator.escape(body); +} + +async function getPostData(req) { + if (!req.query.pid && !req.query.toPid) { + return null; + } + + return await posts.getPostData(req.query.pid || req.query.toPid); +} + +async function getTopicData(req) { + if (req.query.tid) { + return await topics.getTopicData(req.query.tid); + } else if (req.query.pid) { + return await topics.getTopicDataByPid(req.query.pid); + } + return null; +} + +async function isModerator(req) { + if (!req.loggedIn) { + return false; + } + const cid = cidFromQuery(req.query); + return await user.isModerator(req.uid, cid); +} + +async function canTag(req) { + if (parseInt(req.query.cid, 10)) { + return await privileges.categories.can('topics:tag', req.query.cid, req.uid); + } + return true; +} + +async function canSchedule(req) { + if (parseInt(req.query.cid, 10)) { + return await privileges.categories.can('topics:schedule', req.query.cid, req.uid); + } + return false; +} + +async function getTagWhitelist(query, uid) { + const cid = await cidFromQuery(query); + const [tagWhitelist, isAdminOrMod] = await Promise.all([ + categories.getTagWhitelist([cid]), + privileges.categories.isAdminOrMod(cid, uid), + ]); + return categories.filterTagWhitelist(tagWhitelist[0], isAdminOrMod); +} + +async function cidFromQuery(query) { + if (query.cid) { + return query.cid; + } else if (query.tid) { + return await topics.getTopicField(query.tid, 'cid'); + } else if (query.pid) { + return await posts.getCidByPid(query.pid); + } + return null; +} diff --git a/node_modules/nodebb-plugin-composer-default/package.json b/node_modules/nodebb-plugin-composer-default/package.json new file mode 100644 index 0000000000..625184980c --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/package.json @@ -0,0 +1,43 @@ +{ + "name": "nodebb-plugin-composer-default", + "version": "10.2.36", + "description": "Default composer for NodeBB", + "main": "library.js", + "repository": { + "type": "git", + "url": "https://github.com/NodeBB/nodebb-plugin-composer-default" + }, + "scripts": { + "lint": "eslint ." + }, + "keywords": [ + "nodebb", + "plugin", + "composer", + "markdown" + ], + "author": { + "name": "NodeBB Team", + "email": "sales@nodebb.org" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/NodeBB/nodebb-plugin-composer-default/issues" + }, + "readmeFilename": "README.md", + "nbbpm": { + "compatibility": "^3.0.0" + }, + "dependencies": { + "@textcomplete/contenteditable": "^0.1.12", + "@textcomplete/core": "^0.1.12", + "@textcomplete/textarea": "^0.1.12", + "screenfull": "^5.0.2", + "validator": "^13.7.0" + }, + "devDependencies": { + "eslint": "^7.32.0", + "eslint-config-nodebb": "^0.0.1", + "eslint-plugin-import": "^2.23.4" + } +} diff --git a/node_modules/nodebb-plugin-composer-default/plugin.json b/node_modules/nodebb-plugin-composer-default/plugin.json new file mode 100644 index 0000000000..c75ef14259 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/plugin.json @@ -0,0 +1,35 @@ +{ + "id": "nodebb-plugin-composer-default", + "url": "https://github.com/NodeBB/nodebb-plugin-composer-default", + "library": "library.js", + "hooks": [ + { "hook": "static:app.load", "method": "init" }, + { "hook": "filter:config.get", "method": "appendConfig" }, + { "hook": "filter:composer.build", "method": "filterComposerBuild" }, + { "hook": "filter:admin.header.build", "method": "addAdminNavigation" }, + { "hook": "filter:meta.getLinkTags", "method": "addPrefetchTags" } + ], + "scss": [ + "./static/scss/composer.scss" + ], + "scripts": [ + "./static/lib/client.js", + "./node_modules/screenfull/dist/screenfull.js" + ], + "modules": { + "composer.js": "./static/lib/composer.js", + "composer/categoryList.js": "./static/lib/composer/categoryList.js", + "composer/controls.js": "./static/lib/composer/controls.js", + "composer/drafts.js": "./static/lib/composer/drafts.js", + "composer/formatting.js": "./static/lib/composer/formatting.js", + "composer/preview.js": "./static/lib/composer/preview.js", + "composer/resize.js": "./static/lib/composer/resize.js", + "composer/scheduler.js": "./static/lib/composer/scheduler.js", + "composer/tags.js": "./static/lib/composer/tags.js", + "composer/uploads.js": "./static/lib/composer/uploads.js", + "composer/autocomplete.js": "./static/lib/composer/autocomplete.js", + "composer/post-queue.js": "./static/lib/composer/post-queue.js", + "../admin/plugins/composer-default.js": "./static/lib/admin.js" + }, + "templates": "static/templates" +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/screenshots/desktop.png b/node_modules/nodebb-plugin-composer-default/screenshots/desktop.png new file mode 100644 index 0000000000..a6d4631e4e Binary files /dev/null and b/node_modules/nodebb-plugin-composer-default/screenshots/desktop.png differ diff --git a/node_modules/nodebb-plugin-composer-default/screenshots/mobile.png b/node_modules/nodebb-plugin-composer-default/screenshots/mobile.png new file mode 100644 index 0000000000..a50a01ea93 Binary files /dev/null and b/node_modules/nodebb-plugin-composer-default/screenshots/mobile.png differ diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/.eslintrc b/node_modules/nodebb-plugin-composer-default/static/lib/.eslintrc new file mode 100644 index 0000000000..9fc9d47e53 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/.eslintrc @@ -0,0 +1,6 @@ +{ + "extends": "nodebb/public", + "rules": { + "no-cond-assign": ["error", "except-parens"] + } +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/admin.js b/node_modules/nodebb-plugin-composer-default/static/lib/admin.js new file mode 100644 index 0000000000..cc693300ea --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/admin.js @@ -0,0 +1,15 @@ +'use strict'; + +define('admin/plugins/composer-default', ['settings'], function (Settings) { + const ACP = {}; + + ACP.init = function () { + Settings.load('composer-default', $('.composer-default-settings')); + + $('#save').on('click', function () { + Settings.save('composer-default', $('.composer-default-settings')); + }); + }; + + return ACP; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/client.js b/node_modules/nodebb-plugin-composer-default/static/lib/client.js new file mode 100644 index 0000000000..2b46e406b8 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/client.js @@ -0,0 +1,89 @@ +'use strict'; + +$(document).ready(function () { + $(window).on('action:app.load', function () { + require(['composer/drafts'], function (drafts) { + drafts.migrateGuest(); + drafts.loadOpen(); + }); + }); + + $(window).on('action:composer.topic.new', function (ev, data) { + if (config['composer-default'].composeRouteEnabled !== 'on') { + require(['composer'], function (composer) { + composer.newTopic({ + cid: data.cid, + title: data.title || '', + body: data.body || '', + tags: data.tags || [], + }); + }); + } else { + ajaxify.go( + 'compose?cid=' + data.cid + + (data.title ? '&title=' + encodeURIComponent(data.title) : '') + + (data.body ? '&body=' + encodeURIComponent(data.body) : '') + ); + } + }); + + $(window).on('action:composer.post.edit', function (ev, data) { + if (config['composer-default'].composeRouteEnabled !== 'on') { + require(['composer'], function (composer) { + composer.editPost({ pid: data.pid }); + }); + } else { + ajaxify.go('compose?pid=' + data.pid); + } + }); + + $(window).on('action:composer.post.new', function (ev, data) { + // backwards compatibility + data.body = data.body || data.text; + data.title = data.title || data.topicName; + if (config['composer-default'].composeRouteEnabled !== 'on') { + require(['composer'], function (composer) { + composer.newReply({ + tid: data.tid, + toPid: data.pid, + title: data.title, + body: data.body, + }); + }); + } else { + ajaxify.go( + 'compose?tid=' + data.tid + + (data.pid ? '&toPid=' + data.pid : '') + + (data.title ? '&title=' + encodeURIComponent(data.title) : '') + + (data.body ? '&body=' + encodeURIComponent(data.body) : '') + ); + } + }); + + $(window).on('action:composer.addQuote', function (ev, data) { + data.body = data.body || data.text; + data.title = data.title || data.topicName; + if (config['composer-default'].composeRouteEnabled !== 'on') { + require(['composer'], function (composer) { + var topicUUID = composer.findByTid(data.tid); + composer.addQuote({ + tid: data.tid, + toPid: data.pid, + selectedPid: data.selectedPid, + title: data.title, + username: data.username, + body: data.body, + uuid: topicUUID, + }); + }); + } else { + ajaxify.go('compose?tid=' + data.tid + '&toPid=' + data.pid + '"ed=1&username=' + data.username); + } + }); + + $(window).on('action:composer.enhance', function (ev, data) { + require(['composer'], function (composer) { + composer.enhance(data.container); + }); + }); +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer.js index 59fe13a262..1cde669fc6 100644 --- a/node_modules/nodebb-plugin-composer-default/static/lib/composer.js +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer.js @@ -654,6 +654,7 @@ define('composer', [ var thumbEl = postContainer.find('input#topic-thumb-url'); var onComposeRoute = postData.hasOwnProperty('template') && postData.template.compose === true; var annonymousTypeEl = postContainer.find('#anonymousDropdown'); + const submitBtn = postContainer.find('.composer-submit'); titleEl.val(titleEl.val().trim()); @@ -721,6 +722,7 @@ define('composer', [ tags: tags.getTags(post_uuid), timestamp: scheduler.getTimestamp(), annonymousType: annonymousTypeEl.val(), + }; } else if (action === 'posts.reply') { route = `/topics/${postData.tid}`; diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/autocomplete.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/autocomplete.js new file mode 100644 index 0000000000..ec2ce15d33 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/autocomplete.js @@ -0,0 +1,99 @@ +'use strict'; + +define('composer/autocomplete', [ + 'composer/preview', '@textcomplete/core', '@textcomplete/textarea', '@textcomplete/contenteditable', +], function (preview, { Textcomplete }, { TextareaEditor }, { ContenteditableEditor }) { + var autocomplete = { + _active: {}, + }; + + $(window).on('action:composer.discard', function (evt, data) { + if (autocomplete._active.hasOwnProperty(data.post_uuid)) { + autocomplete._active[data.post_uuid].destroy(); + delete autocomplete._active[data.post_uuid]; + } + }); + + autocomplete.init = function (postContainer, post_uuid) { + var element = postContainer.find('.write'); + var dropdownClass = 'composer-autocomplete-dropdown-' + post_uuid; + var timer; + + if (!element.length) { + /** + * Some composers do their own thing before calling autocomplete.init() again. + * One reason is because they want to override the textarea with their own element. + * In those scenarios, they don't specify the "write" class, and this conditional + * looks for that and stops the autocomplete init process. + */ + return; + } + + var data = { + element: element, + strategies: [], + options: { + style: { + 'z-index': 20000, + }, + className: dropdownClass + ' dropdown-menu textcomplete-dropdown', + }, + }; + + element.on('keyup', function () { + clearTimeout(timer); + timer = setTimeout(function () { + var dropdown = document.querySelector('.' + dropdownClass); + if (dropdown) { + var pos = dropdown.getBoundingClientRect(); + + var margin = parseFloat(dropdown.style.marginTop, 10) || 0; + + var offset = window.innerHeight + margin - 10 - pos.bottom; + dropdown.style.marginTop = Math.min(offset, 0) + 'px'; + } + }, 0); + }); + + $(window).trigger('composer:autocomplete:init', data); + + autocomplete._active[post_uuid] = autocomplete.setup(data); + + data.element.on('textComplete:select', function () { + preview.render(postContainer); + }); + }; + + // This is a generic method that is also used by the chat + autocomplete.setup = function ({ element, strategies, options }) { + const targetEl = element.get(0); + if (!targetEl) { + return; + } + var editor; + if (targetEl.nodeName === 'TEXTAREA' || targetEl.nodeName === 'INPUT') { + editor = new TextareaEditor(targetEl); + } else if (targetEl.nodeName === 'DIV' && targetEl.getAttribute('contenteditable') === 'true') { + editor = new ContenteditableEditor(targetEl); + } + if (!editor) { + throw new Error('unknown target element type'); + } + // yuku-t/textcomplete inherits directionality from target element itself + targetEl.setAttribute('dir', document.querySelector('html').getAttribute('data-dir')); + + var textcomplete = new Textcomplete(editor, strategies, { + dropdown: options, + }); + textcomplete.on('rendered', function () { + if (textcomplete.dropdown.items.length) { + // Activate the first item by default. + textcomplete.dropdown.items[0].activate(); + } + }); + + return textcomplete; + }; + + return autocomplete; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/categoryList.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/categoryList.js new file mode 100644 index 0000000000..79f5b7a46b --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/categoryList.js @@ -0,0 +1,115 @@ +'use strict'; + +define('composer/categoryList', [ + 'categorySelector', 'taskbar', 'api', +], function (categorySelector, taskbar, api) { + var categoryList = {}; + + var selector; + + categoryList.init = function (postContainer, postData) { + var listContainer = postContainer.find('.category-list-container'); + if (!listContainer.length) { + return; + } + + postContainer.on('action:composer.resize', function () { + toggleDropDirection(postContainer); + }); + + categoryList.updateTaskbar(postContainer, postData); + + selector = categorySelector.init(listContainer.find('[component="category-selector"]'), { + privilege: 'topics:create', + states: ['watching', 'tracking', 'notwatching', 'ignoring'], + onSelect: function (selectedCategory) { + if (postData.hasOwnProperty('cid')) { + changeCategory(postContainer, postData, selectedCategory); + } + }, + }); + if (!selector) { + return; + } + if (postData.cid && postData.category) { + selector.selectedCategory = { cid: postData.cid, name: postData.category.name }; + } else if (ajaxify.data.template.compose && ajaxify.data.selectedCategory) { + // separate composer route + selector.selectedCategory = { cid: ajaxify.data.cid, name: ajaxify.data.selectedCategory }; + } + + // this is the mobile category selector + postContainer.find('.category-name') + .translateHtml(selector.selectedCategory ? selector.selectedCategory.name : '[[modules:composer.select-category]]') + .on('click', function () { + categorySelector.modal({ + privilege: 'topics:create', + states: ['watching', 'tracking', 'notwatching', 'ignoring'], + openOnLoad: true, + showLinks: false, + onSubmit: function (selectedCategory) { + postContainer.find('.category-name').text(selectedCategory.name); + selector.selectCategory(selectedCategory.cid); + if (postData.hasOwnProperty('cid')) { + changeCategory(postContainer, postData, selectedCategory); + } + }, + }); + }); + + toggleDropDirection(postContainer); + }; + + function toggleDropDirection(postContainer) { + postContainer.find('.category-list-container [component="category-selector"]').toggleClass('dropup', postContainer.outerHeight() < $(window).height() / 2); + } + + categoryList.getSelectedCid = function () { + var selectedCategory; + if (selector) { + selectedCategory = selector.getSelectedCategory(); + } + return selectedCategory ? selectedCategory.cid : 0; + }; + + categoryList.updateTaskbar = function (postContainer, postData) { + if (parseInt(postData.cid, 10)) { + api.get(`/categories/${postData.cid}`, {}).then(function (category) { + updateTaskbarByCategory(postContainer, category); + }); + } + }; + + function updateTaskbarByCategory(postContainer, category) { + if (category) { + var uuid = postContainer.attr('data-uuid'); + taskbar.update('composer', uuid, { + image: category.backgroundImage, + color: category.color, + 'background-color': category.bgColor, + icon: category.icon && category.icon.slice(3), + }); + } + } + + async function changeCategory(postContainer, postData, selectedCategory) { + postData.cid = selectedCategory.cid; + const categoryData = await window.fetch(`${config.relative_path}/api/category/${selectedCategory.cid}`).then(r => r.json()); + postData.category = categoryData; + updateTaskbarByCategory(postContainer, categoryData); + require(['composer/scheduler', 'composer/tags', 'composer/post-queue'], function (scheduler, tags, postQueue) { + scheduler.onChangeCategory(categoryData); + tags.onChangeCategory(postContainer, postData, selectedCategory.cid, categoryData); + postQueue.onChangeCategory(postContainer, postData); + + $(window).trigger('action:composer.changeCategory', { + postContainer: postContainer, + postData: postData, + selectedCategory: selectedCategory, + categoryData: categoryData, + }); + }); + } + + return categoryList; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/controls.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/controls.js new file mode 100644 index 0000000000..bf393fc21a --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/controls.js @@ -0,0 +1,171 @@ +'use strict'; + +define('composer/controls', ['composer/preview'], function (preview) { + var controls = {}; + + /** ********************************************** */ + /* Rich Textarea Controls */ + /** ********************************************** */ + controls.insertIntoTextarea = function (textarea, value) { + var payload = { + context: this, + textarea: textarea, + value: value, + preventDefault: false, + }; + $(window).trigger('action:composer.insertIntoTextarea', payload); + + if (payload.preventDefault) { + return; + } + + var $textarea = $(payload.textarea); + var currentVal = $textarea.val(); + var postContainer = $textarea.parents('[component="composer"]'); + + $textarea.val( + currentVal.slice(0, payload.textarea.selectionStart) + + payload.value + + currentVal.slice(payload.textarea.selectionStart) + ); + + preview.render(postContainer); + }; + + controls.replaceSelectionInTextareaWith = function (textarea, value) { + var payload = { + context: this, + textarea: textarea, + value: value, + preventDefault: false, + }; + $(window).trigger('action:composer.replaceSelectionInTextareaWith', payload); + + if (payload.preventDefault) { + return; + } + + var $textarea = $(payload.textarea); + var currentVal = $textarea.val(); + var postContainer = $textarea.parents('[component="composer"]'); + + $textarea.val( + currentVal.slice(0, payload.textarea.selectionStart) + + payload.value + + currentVal.slice(payload.textarea.selectionEnd) + ); + + preview.render(postContainer); + }; + + controls.wrapSelectionInTextareaWith = function (textarea, leading, trailing) { + var payload = { + context: this, + textarea: textarea, + leading: leading, + trailing: trailing, + preventDefault: false, + }; + $(window).trigger('action:composer.wrapSelectionInTextareaWith', payload); + + if (payload.preventDefault) { + return; + } + + if (trailing === undefined) { + trailing = leading; + } + + var $textarea = $(textarea); + var currentVal = $textarea.val(); + + var matches = /^(\s*)([\s\S]*?)(\s*)$/.exec(currentVal.slice(textarea.selectionStart, textarea.selectionEnd)); + + if (!matches[2]) { + // selection is entirely whitespace + matches = [null, '', currentVal.slice(textarea.selectionStart, textarea.selectionEnd), '']; + } + + $textarea.val( + currentVal.slice(0, textarea.selectionStart) + + matches[1] + + leading + + matches[2] + + trailing + + matches[3] + + currentVal.slice(textarea.selectionEnd) + ); + + return [matches[1].length, matches[3].length]; + }; + + controls.updateTextareaSelection = function (textarea, start, end) { + var payload = { + context: this, + textarea: textarea, + start: start, + end: end, + preventDefault: false, + }; + $(window).trigger('action:composer.updateTextareaSelection', payload); + + if (payload.preventDefault) { + return; + } + + textarea.setSelectionRange(payload.start, payload.end); + $(payload.textarea).focus(); + }; + + controls.getBlockData = function (textareaEl, query, selectionStart) { + // Determines whether the cursor is sitting inside a block-type element (bold, italic, etc.) + var value = textareaEl.value; + query = query.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&'); + var regex = new RegExp(query, 'g'); + var match; + var matchIndices = []; + var payload; + + // Isolate the line the cursor is on + value = value.split('\n').reduce(function (memo, line) { + if (memo !== null) { + return memo; + } + + memo = selectionStart <= line.length ? line : null; + + if (memo === null) { + selectionStart -= (line.length + 1); + } + + return memo; + }, null); + + // Find query characters and determine return payload + while ((match = regex.exec(value)) !== null) { + matchIndices.push(match.index); + } + + payload = { + in: !!(matchIndices.reduce(function (memo, cur) { + if (selectionStart >= cur + 2) { + memo += 1; + } + + return memo; + }, 0) % 2), + atEnd: matchIndices.reduce(function (memo, cur) { + if (memo) { + return memo; + } + + return selectionStart === cur; + }, false), + }; + + payload.atEnd = payload.in ? payload.atEnd : false; + return payload; + }; + + return controls; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/drafts.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/drafts.js new file mode 100644 index 0000000000..5a23cd10dc --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/drafts.js @@ -0,0 +1,341 @@ +'use strict'; + +define('composer/drafts', ['api', 'alerts'], function (api, alerts) { + const drafts = {}; + const draftSaveDelay = 1000; + drafts.init = function (postContainer, postData) { + const draftIconEl = postContainer.find('.draft-icon'); + const uuid = postContainer.attr('data-uuid'); + function doSaveDraft() { + // check if composer is still around, + // it might have been gone by the time this timeout triggers + if (!$(`[component="composer"][data-uuid="${uuid}"]`).length) { + return; + } + + if (!postData.save_id) { + postData.save_id = utils.generateSaveId(app.user.uid); + } + // Post is modified, save to list of opened drafts + drafts.addToDraftList('available', postData.save_id); + drafts.addToDraftList('open', postData.save_id); + saveDraft(postContainer, draftIconEl, postData); + } + + postContainer.on('keyup', 'textarea, input.handle, input.title', utils.debounce(doSaveDraft, draftSaveDelay)); + postContainer.on('click', 'input[type="checkbox"]', utils.debounce(doSaveDraft, draftSaveDelay)); + postContainer.on('click', '[component="category/list"] [data-cid]', utils.debounce(doSaveDraft, draftSaveDelay)); + postContainer.on('itemAdded', '.tags', utils.debounce(doSaveDraft, draftSaveDelay)); + postContainer.on('thumb.uploaded', doSaveDraft); + + draftIconEl.on('animationend', function () { + $(this).toggleClass('active', false); + }); + + $(window).on('unload', function () { + // remove all drafts from the open list + const open = drafts.getList('open'); + if (open.length) { + open.forEach(save_id => drafts.removeFromDraftList('open', save_id)); + } + }); + + drafts.migrateGuest(); + drafts.migrateThumbs(...arguments); + }; + + function getStorage(uid) { + return parseInt(uid, 10) > 0 ? localStorage : sessionStorage; + } + + drafts.get = function (save_id) { + if (!save_id) { + return null; + } + const uid = save_id.split(':')[1]; + const storage = getStorage(uid); + try { + const draftJson = storage.getItem(save_id); + const draft = JSON.parse(draftJson) || null; + if (!draft) { + throw new Error(`can't parse draft json for ${save_id}`); + } + draft.save_id = save_id; + if (draft.timestamp) { + draft.timestampISO = utils.toISOString(draft.timestamp); + } + $(window).trigger('action:composer.drafts.get', { + save_id: save_id, + draft: draft, + storage: storage, + }); + return draft; + } catch (e) { + console.warn(`[composer/drafts] Could not get draft ${save_id}, removing`); + drafts.removeFromDraftList('available'); + drafts.removeFromDraftList('open'); + return null; + } + }; + + function saveDraft(postContainer, draftIconEl, postData) { + if (canSave(app.user.uid ? 'localStorage' : 'sessionStorage') && postData && postData.save_id && postContainer.length) { + const titleEl = postContainer.find('input.title'); + const title = titleEl && titleEl.length && titleEl.val(); + const raw = postContainer.find('textarea').val(); + const storage = getStorage(app.user.uid); + + if (raw.length || (title && title.length)) { + const draftData = { + save_id: postData.save_id, + action: postData.action, + text: raw, + uuid: postContainer.attr('data-uuid'), + timestamp: Date.now(), + }; + + if (postData.action === 'topics.post') { + // New topic only + const tags = postContainer.find('input.tags').val(); + draftData.tags = tags; + draftData.title = title; + draftData.cid = postData.cid; + } else if (postData.action === 'posts.reply') { + // new reply only + draftData.title = postData.title; + draftData.tid = postData.tid; + draftData.toPid = postData.toPid; + } else if (postData.action === 'posts.edit') { + draftData.pid = postData.pid; + draftData.title = title || postData.title; + } + if (!app.user.uid) { + draftData.handle = postContainer.find('input.handle').val(); + } + + // save all draft data into single item as json + storage.setItem(postData.save_id, JSON.stringify(draftData)); + + $(window).trigger('action:composer.drafts.save', { + storage: storage, + postData: postData, + postContainer: postContainer, + }); + draftIconEl.toggleClass('active', true); + } else { + drafts.removeDraft(postData.save_id); + } + } + } + + drafts.removeDraft = function (save_id) { + if (!save_id) { + return; + } + + // Remove save_id from list of open and available drafts + drafts.removeFromDraftList('available', save_id); + drafts.removeFromDraftList('open', save_id); + const uid = save_id.split(':')[1]; + const storage = getStorage(uid); + storage.removeItem(save_id); + + $(window).trigger('action:composer.drafts.remove', { + storage: storage, + save_id: save_id, + }); + }; + + drafts.getList = function (set) { + try { + const draftIds = localStorage.getItem(`drafts:${set}`); + return JSON.parse(draftIds) || []; + } catch (e) { + console.warn('[composer/drafts] Could not read list of available drafts'); + return []; + } + }; + + drafts.addToDraftList = function (set, save_id) { + if (!canSave(app.user.uid ? 'localStorage' : 'sessionStorage') || !save_id) { + return; + } + const list = drafts.getList(set); + if (!list.includes(save_id)) { + list.push(save_id); + localStorage.setItem('drafts:' + set, JSON.stringify(list)); + } + }; + + drafts.removeFromDraftList = function (set, save_id) { + if (!canSave(app.user.uid ? 'localStorage' : 'sessionStorage') || !save_id) { + return; + } + const list = drafts.getList(set); + if (list.includes(save_id)) { + list.splice(list.indexOf(save_id), 1); + localStorage.setItem('drafts:' + set, JSON.stringify(list)); + } + }; + + drafts.migrateGuest = function () { + // If any drafts are made while as guest, and user then logs in, assume control of those drafts + if (canSave('localStorage') && app.user.uid) { + // composer:: + const test = /^composer:\d+:\d$/; + const keys = Object.keys(sessionStorage).filter(function (key) { + return test.test(key); + }); + const migrated = new Set([]); + const renamed = keys.map(function (key) { + const parts = key.split(':'); + parts[1] = app.user.uid; + + migrated.add(parts.join(':')); + return parts.join(':'); + }); + + keys.forEach(function (key, idx) { + localStorage.setItem(renamed[idx], sessionStorage.getItem(key)); + sessionStorage.removeItem(key); + }); + + migrated.forEach(function (save_id) { + drafts.addToDraftList('available', save_id); + }); + + return migrated; + } + }; + + drafts.migrateThumbs = function (postContainer, postData) { + if (!app.uid) { + return; + } + + // If any thumbs were uploaded, migrate them to this new composer's uuid + const newUUID = postContainer.attr('data-uuid'); + const draft = drafts.get(postData.save_id); + + if (draft && draft.uuid) { + api.put(`/topics/${draft.uuid}/thumbs`, { + tid: newUUID, + }).then(() => { + require(['composer'], function (composer) { + composer.updateThumbCount(newUUID, postContainer); + }); + }); + } + }; + + drafts.listAvailable = function () { + const available = drafts.getList('available'); + return available.map(drafts.get).filter(Boolean); + }; + + drafts.getAvailableCount = function () { + return drafts.listAvailable().length; + }; + + drafts.open = function (save_id) { + if (!save_id) { + return; + } + const draft = drafts.get(save_id); + openComposer(save_id, draft); + }; + + drafts.loadOpen = function () { + if (ajaxify.data.template.login || ajaxify.data.template.register || (config.hasOwnProperty('openDraftsOnPageLoad') && !config.openDraftsOnPageLoad)) { + return; + } + // Load drafts if they were open + const available = drafts.getList('available'); + const open = drafts.getList('open'); + + if (available.length) { + // Deconstruct each save_id and open up composer + available.forEach(function (save_id) { + if (!save_id || open.includes(save_id)) { + return; + } + const draft = drafts.get(save_id); + if (!draft || (!draft.text && !draft.title)) { + drafts.removeFromDraftList('available', save_id); + drafts.removeFromDraftList('open', save_id); + return; + } + openComposer(save_id, draft); + }); + } + }; + + function openComposer(save_id, draft) { + const saveObj = save_id.split(':'); + const uid = saveObj[1]; + // Don't open other peoples' drafts + if (parseInt(app.user.uid, 10) !== parseInt(uid, 10)) { + return; + } + require(['composer'], function (composer) { + if (draft.action === 'topics.post') { + composer.newTopic({ + save_id: draft.save_id, + cid: draft.cid, + handle: app.user && app.user.uid ? undefined : utils.escapeHTML(draft.handle), + title: utils.escapeHTML(draft.title), + body: draft.text, + tags: String(draft.tags || '').split(','), + }); + } else if (draft.action === 'posts.reply') { + api.get('/topics/' + draft.tid, {}, function (err, topicObj) { + if (err) { + return alerts.error(err); + } + + composer.newReply({ + save_id: draft.save_id, + tid: draft.tid, + toPid: draft.toPid, + title: topicObj.title, + body: draft.text, + }); + }); + } else if (draft.action === 'posts.edit') { + composer.editPost({ + save_id: draft.save_id, + pid: draft.pid, + title: draft.title ? utils.escapeHTML(draft.title) : undefined, + body: draft.text, + }); + } + }); + } + + // Feature detection courtesy of: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API + function canSave(type) { + var storage; + try { + storage = window[type]; + var x = '__storage_test__'; + storage.setItem(x, x); + storage.removeItem(x); + return true; + } catch (e) { + return e instanceof DOMException && ( + // everything except Firefox + e.code === 22 || + // Firefox + e.code === 1014 || + // test name field too, because code might not be present + // everything except Firefox + e.name === 'QuotaExceededError' || + // Firefox + e.name === 'NS_ERROR_DOM_QUOTA_REACHED') && + // acknowledge QuotaExceededError only if there's something already stored + (storage && storage.length !== 0); + } + } + + return drafts; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/formatting.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/formatting.js new file mode 100644 index 0000000000..dca150fdd4 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/formatting.js @@ -0,0 +1,194 @@ +'use strict'; + +define('composer/formatting', [ + 'composer/preview', 'composer/resize', 'topicThumbs', 'screenfull', +], function (preview, resize, topicThumbs, screenfull) { + var formatting = {}; + + var formattingDispatchTable = { + picture: function () { + var postContainer = this; + postContainer.find('#files') + .attr('accept', 'image/*') + .click(); + }, + + upload: function () { + var postContainer = this; + postContainer.find('#files') + .attr('accept', '') + .click(); + }, + + thumbs: function () { + formatting.exitFullscreen(); + var postContainer = this; + require(['composer'], function (composer) { + const uuid = postContainer.get(0).getAttribute('data-uuid'); + const composerObj = composer.posts[uuid]; + + if (composerObj.action === 'topics.post' || (composerObj.action === 'posts.edit' && composerObj.isMain)) { + topicThumbs.modal.open({ id: uuid, pid: composerObj.pid }).then(() => { + postContainer.trigger('thumb.uploaded'); // toggle draft save + + // Update client-side with count + composer.updateThumbCount(uuid, postContainer); + }); + } + }); + }, + + tags: function () { + var postContainer = this; + postContainer.find('.tags-container').toggleClass('hidden'); + }, + + zen: function () { + var postContainer = this; + $(window).one('resize', function () { + function onResize() { + if (!screenfull.isFullscreen) { + app.toggleNavbar(true); + $('html').removeClass('zen-mode'); + resize.reposition(postContainer); + $(window).off('resize', onResize); + } + } + + if (screenfull.isFullscreen) { + app.toggleNavbar(false); + $('html').addClass('zen-mode'); + postContainer.find('.write').focus(); + + $(window).on('resize', onResize); + $(window).one('action:composer.topics.post action:composer.posts.reply action:composer.posts.edit action:composer.discard', screenfull.exit); + } + }); + + screenfull.toggle(postContainer.get(0)); + $(window).trigger('action:composer.fullscreen', { postContainer: postContainer }); + }, + }; + + var buttons = []; + + formatting.exitFullscreen = function () { + if (screenfull.isEnabled && screenfull.isFullscreen) { + screenfull.exit(); + } + }; + + formatting.addComposerButtons = function () { + const formattingBarEl = $('.formatting-bar'); + const fileForm = formattingBarEl.find('.formatting-group #fileForm'); + buttons.forEach((btn) => { + let markup = ``; + if (Array.isArray(btn.dropdownItems) && btn.dropdownItems.length) { + markup = generateFormattingDropdown(btn); + } else { + markup = ` +
  • + +
  • + `; + } + fileForm.before(markup); + }); + + const els = formattingBarEl.find('.formatting-group>li'); + els.tooltip({ + container: '#content', + animation: false, + trigger: 'manual', + }).on('mouseenter', function (ev) { + const target = $(ev.target); + const isDropdown = target.hasClass('dropdown-menu') || !!target.parents('.dropdown-menu').length; + if (!isDropdown) { + $(this).tooltip('show'); + } + }).on('click mouseleave', function () { + $(this).tooltip('hide'); + }); + }; + + function generateBadgetHtml(btn) { + let badgeHtml = ''; + if (btn.badge) { + badgeHtml = ``; + } + return badgeHtml; + } + + function generateFormattingDropdown(btn) { + const dropdownItemsHtml = btn.dropdownItems.map(function (btn) { + return ` +
  • + + ${btn.text} + ${generateBadgetHtml(btn)} + +
  • + `; + }); + return ` + + `; + } + + formatting.addButton = function (iconClass, onClick, title, name) { + name = name || iconClass.replace('fa fa-', ''); + formattingDispatchTable[name] = onClick; + buttons.push({ + name, + iconClass, + title, + }); + }; + + formatting.addDropdown = function (data) { + buttons.push({ + iconClass: data.iconClass, + title: data.title, + dropdownItems: data.dropdownItems, + }); + data.dropdownItems.forEach((btn) => { + if (btn.name && btn.onClick) { + formattingDispatchTable[btn.name] = btn.onClick; + } + }); + }; + + formatting.getDispatchTable = function () { + return formattingDispatchTable; + }; + + formatting.addButtonDispatch = function (name, onClick) { + formattingDispatchTable[name] = onClick; + }; + + formatting.addHandler = function (postContainer) { + postContainer.on('click', '.formatting-bar [data-format]', function (event) { + var format = $(this).attr('data-format'); + var textarea = $(this).parents('[component="composer"]').find('textarea')[0]; + + if (formattingDispatchTable.hasOwnProperty(format)) { + formattingDispatchTable[format].call( + postContainer, textarea, textarea.selectionStart, textarea.selectionEnd, event + ); + preview.render(postContainer); + } + }); + }; + + return formatting; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/post-queue.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/post-queue.js new file mode 100644 index 0000000000..2022430842 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/post-queue.js @@ -0,0 +1,25 @@ +'use strict'; + +define('composer/post-queue', [], function () { + const postQueue = {}; + + postQueue.showAlert = async function (postContainer, postData) { + const alertEl = postContainer.find('[component="composer/post-queue/alert"]') + if (!config.postQueue || app.user.isAdmin || app.user.isGlobalMod || app.user.isMod) { + alertEl.remove(); + return; + } + const shouldQueue = await socket.emit('plugins.composer.shouldQueue', { postData: postData }); + alertEl.toggleClass('show', shouldQueue); + alertEl.toggleClass('pe-none', !shouldQueue); + }; + + postQueue.onChangeCategory = async function (postContainer, postData) { + if (!config.postQueue) { + return; + } + postQueue.showAlert(postContainer, postData); + }; + + return postQueue; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/preview.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/preview.js new file mode 100644 index 0000000000..9074e6edc2 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/preview.js @@ -0,0 +1,105 @@ +'use strict'; + +define('composer/preview', ['hooks'], function (hooks) { + var preview = {}; + + preview.render = function (postContainer, callback) { + callback = callback || function () {}; + if (!postContainer.find('.preview-container').is(':visible')) { + return callback(); + } + + var textarea = postContainer.find('textarea'); + + socket.emit('plugins.composer.renderPreview', textarea.val(), function (err, preview) { + if (err) { + return; + } + preview = $('
    ' + preview + '
    '); + preview.find('img:not(.not-responsive)').addClass('img-fluid'); + postContainer.find('.preview').html(preview); + hooks.fire('action:composer.preview', { postContainer, preview }); + callback(); + }); + }; + + preview.matchScroll = function (postContainer) { + if (!postContainer.find('.preview-container').is(':visible')) { + return; + } + var textarea = postContainer.find('textarea'); + var preview = postContainer.find('.preview'); + + if (textarea.length && preview.length) { + var diff = textarea[0].scrollHeight - textarea.height(); + + if (diff === 0) { + return; + } + + var scrollPercent = textarea.scrollTop() / diff; + + preview.scrollTop(Math.max(preview[0].scrollHeight - preview.height(), 0) * scrollPercent); + } + }; + + preview.handleToggler = function ($postContainer) { + const postContainer = $postContainer.get(0); + preview.env = utils.findBootstrapEnvironment(); + const isMobile = ['xs', 'sm'].includes(preview.env); + const toggler = postContainer.querySelector('.formatting-bar [data-action="preview"]'); + const showText = toggler.querySelector('.show-text'); + const hideText = toggler.querySelector('.hide-text'); + const previewToggled = localStorage.getItem('composer:previewToggled'); + const hidePreviewOnOpen = config['composer-default'].hidePreviewOnOpen === 'on'; + let show = !isMobile && ( + ((previewToggled === null && !hidePreviewOnOpen) || previewToggled === 'true') + ); + const previewContainer = postContainer.querySelector('.preview-container'); + const writeContainer = postContainer.querySelector('.write-container'); + + if (!toggler) { + return; + } + + function togglePreview(show) { + if (isMobile) { + previewContainer.classList.toggle('hide', false); + writeContainer.classList.toggle('maximized', false); + + previewContainer.classList.toggle('d-none', !show); + previewContainer.classList.toggle('d-flex', show); + previewContainer.classList.toggle('w-100', show); + + writeContainer.classList.toggle('d-flex', !show); + writeContainer.classList.toggle('d-none', show); + writeContainer.classList.toggle('w-100', !show); + } else { + previewContainer.classList.toggle('hide', !show); + writeContainer.classList.toggle('w-50', show); + writeContainer.classList.toggle('w-100', !show); + localStorage.setItem('composer:previewToggled', show); + } + showText.classList.toggle('hide', show); + hideText.classList.toggle('hide', !show); + if (show) { + preview.render($postContainer); + } + preview.matchScroll($postContainer); + } + preview.toggle = togglePreview; + + toggler.addEventListener('click', (e) => { + if (e.button !== 0) { + return; + } + + show = !show; + togglePreview(show); + }); + + togglePreview(show); + }; + + return preview; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/resize.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/resize.js new file mode 100644 index 0000000000..5fa84f3a3f --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/resize.js @@ -0,0 +1,197 @@ + +'use strict'; + +define('composer/resize', ['taskbar'], function (taskbar) { + var resize = {}; + var oldRatio = 0; + var minimumRatio = 0.3; + var snapMargin = 0.05; + var smallMin = 768; + + var $body = $('body'); + var $window = $(window); + var $headerMenu = $('[component="navbar"]'); + const content = document.getElementById('content'); + + var header = $headerMenu[0]; + + function getSavedRatio() { + return localStorage.getItem('composer:resizeRatio') || 0.5; + } + + function saveRatio(ratio) { + localStorage.setItem('composer:resizeRatio', Math.min(ratio, 1)); + } + + function getBounds() { + var headerRect; + if (header) { + headerRect = header.getBoundingClientRect(); + } else { + // Mock data + headerRect = { bottom: 0 }; + } + + var headerBottom = Math.max(headerRect.bottom, 0); + + var rect = { + top: 0, + left: 0, + right: window.innerWidth, + bottom: window.innerHeight, + }; + + rect.width = rect.right; + rect.height = rect.bottom; + + rect.boundedTop = headerBottom; + rect.boundedHeight = rect.bottom - headerBottom; + + return rect; + } + + function doResize(postContainer, ratio) { + var bounds = getBounds(); + var elem = postContainer[0]; + var style = window.getComputedStyle(elem); + + // Adjust minimumRatio for shorter viewports + var minHeight = parseInt(style.getPropertyValue('min-height'), 10); + var adjustedMinimum = Math.max(minHeight / window.innerHeight, minimumRatio); + + if (bounds.width >= smallMin) { + const boundedDifference = (bounds.height - bounds.boundedHeight) / bounds.height; + ratio = Math.min(Math.max(ratio, adjustedMinimum + boundedDifference), 1); + + var top = ratio * bounds.boundedHeight / bounds.height; + elem.style.top = ((1 - top) * 100).toString() + '%'; + + // Add some extra space at the bottom of the body so that + // the user can still scroll to the last post w/ composer open + var rect = elem.getBoundingClientRect(); + content.style.paddingBottom = (rect.bottom - rect.top).toString() + 'px'; + } else { + elem.style.top = 0; + content.style.paddingBottom = 0; + } + + postContainer.ratio = ratio; + + taskbar.updateActive(postContainer.attr('data-uuid')); + } + + var resizeIt = doResize; + var raf = window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame; + + if (raf) { + resizeIt = function (postContainer, ratio) { + raf(function () { + doResize(postContainer, ratio); + + setTimeout(function () { + $window.trigger('action:composer.resize'); + postContainer.trigger('action:composer.resize'); + }, 0); + }); + }; + } + + resize.reposition = function (postContainer) { + var ratio = getSavedRatio(); + + if (ratio >= 1 - snapMargin) { + ratio = 1; + postContainer.addClass('maximized'); + } + + resizeIt(postContainer, ratio); + }; + + resize.maximize = function (postContainer, state) { + if (state) { + resizeIt(postContainer, 1); + } else { + resize.reposition(postContainer); + } + }; + + resize.handleResize = function (postContainer) { + var resizeOffset = 0; + var resizeBegin = 0; + var resizeEnd = 0; + var $resizer = postContainer.find('.resizer'); + var resizer = $resizer[0]; + + function resizeStart(e) { + var resizeRect = resizer.getBoundingClientRect(); + var resizeCenterY = (resizeRect.top + resizeRect.bottom) / 2; + + resizeOffset = (resizeCenterY - e.clientY) / 2; + resizeBegin = e.clientY; + + $window.on('mousemove', resizeAction); + $window.on('mouseup', resizeStop); + $body.on('touchmove', resizeTouchAction); + } + + function resizeAction(e) { + var position = e.clientY - resizeOffset; + var bounds = getBounds(); + var ratio = (bounds.height - position) / (bounds.boundedHeight); + + resizeIt(postContainer, ratio); + } + + function resizeStop(e) { + e.preventDefault(); + resizeEnd = e.clientY; + + postContainer.find('textarea').focus(); + $window.off('mousemove', resizeAction); + $window.off('mouseup', resizeStop); + $body.off('touchmove', resizeTouchAction); + + var position = resizeEnd - resizeOffset; + var bounds = getBounds(); + var ratio = (bounds.height - position) / (bounds.boundedHeight); + + if (resizeEnd - resizeBegin === 0 && postContainer.hasClass('maximized')) { + postContainer.removeClass('maximized'); + ratio = (!oldRatio || oldRatio >= 1 - snapMargin) ? 0.5 : oldRatio; + resizeIt(postContainer, ratio); + } else if (resizeEnd - resizeBegin === 0 || ratio >= 1 - snapMargin) { + resizeIt(postContainer, 1); + postContainer.addClass('maximized'); + oldRatio = ratio; + } else { + postContainer.removeClass('maximized'); + } + + saveRatio(ratio); + } + + function resizeTouchAction(e) { + e.preventDefault(); + resizeAction(e.touches[0]); + } + + $resizer + .on('mousedown', function (e) { + if (e.button !== 0) { + return; + } + + e.preventDefault(); + resizeStart(e); + }) + .on('touchstart', function (e) { + e.preventDefault(); + resizeStart(e.touches[0]); + }) + .on('touchend', resizeStop); + }; + + return resize; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/scheduler.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/scheduler.js new file mode 100644 index 0000000000..e238c33bdc --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/scheduler.js @@ -0,0 +1,201 @@ +'use strict'; + +define('composer/scheduler', ['benchpress', 'bootbox', 'alerts', 'translator'], function ( + Benchpress, + bootbox, + alerts, + translator +) { + const scheduler = {}; + const state = { + timestamp: 0, + open: false, + edit: false, + posts: {}, + }; + let displayBtnCons = []; + let displayBtns; + let cancelBtn; + let submitContainer; + let submitOptionsCon; + + const dropdownDisplayBtn = { + el: null, + defaultText: '', + activeText: '', + }; + + const submitBtn = { + el: null, + icon: null, + defaultText: '', + activeText: '', + }; + let dateInput; + let timeInput; + + $(window).on('action:composer.activate', handleOnActivate); + + scheduler.init = function ($postContainer, posts) { + state.timestamp = 0; + state.posts = posts; + + translator.translateKeys(['[[topic:composer.post-later]]', '[[modules:composer.change-schedule-date]]']).then((translated) => { + dropdownDisplayBtn.defaultText = translated[0]; + dropdownDisplayBtn.activeText = translated[1]; + }); + + displayBtnCons = $postContainer[0].querySelectorAll('.display-scheduler'); + displayBtns = $postContainer[0].querySelectorAll('.display-scheduler i'); + dropdownDisplayBtn.el = $postContainer[0].querySelector('.dropdown-item.display-scheduler'); + cancelBtn = $postContainer[0].querySelector('.dropdown-item.cancel-scheduling'); + submitContainer = $postContainer.find('[component="composer/submit/container"]'); + submitOptionsCon = $postContainer.find('[component="composer/submit/options/container"]'); + + submitBtn.el = $postContainer[0].querySelector('.composer-submit:not(.btn-sm)'); + submitBtn.icon = submitBtn.el.querySelector('i'); + submitBtn.defaultText = submitBtn.el.lastChild.textContent; + submitBtn.activeText = submitBtn.el.getAttribute('data-text-variant'); + + cancelBtn.addEventListener('click', cancelScheduling); + displayBtnCons.forEach(el => el.addEventListener('click', openModal)); + }; + + scheduler.getTimestamp = function () { + if (!scheduler.isActive() || isNaN(state.timestamp)) { + return 0; + } + return state.timestamp; + }; + + scheduler.isActive = function () { + return state.timestamp > 0; + }; + + scheduler.isOpen = function () { + return state.open; + }; + + scheduler.reset = function () { + state.timestamp = 0; + }; + + scheduler.onChangeCategory = function (categoryData) { + toggleDisplayButtons(categoryData.privileges['topics:schedule']); + toggleItems(false); + const optionsVisible = categoryData.privileges['topics:schedule'] || submitOptionsCon.attr('data-submit-options') > 0; + submitContainer.find('.composer-submit').toggleClass('rounded-1', !optionsVisible); + submitOptionsCon.toggleClass('hidden', !optionsVisible); + scheduler.reset(); + }; + + async function openModal() { + const html = await Benchpress.render('modals/topic-scheduler'); + bootbox.dialog({ + message: html, + title: '[[modules:composer.schedule-for]]', + className: 'topic-scheduler', + onShown: initModal, + onHidden: handleOnHidden, + onEscape: true, + buttons: { + cancel: { + label: state.timestamp ? '[[modules:composer.cancel-scheduling]]' : '[[modules:bootbox.cancel]]', + className: (state.timestamp ? 'btn-warning' : 'btn-outline-secondary') + (state.edit ? ' hidden' : ''), + callback: cancelScheduling, + }, + set: { + label: '[[modules:composer.set-schedule-date]]', + className: 'btn-primary', + callback: setTimestamp, + }, + }, + }); + } + + function initModal(ev) { + state.open = true; + const schedulerContainer = ev.target.querySelector('.datetime-picker'); + dateInput = schedulerContainer.querySelector('input[type="date"]'); + timeInput = schedulerContainer.querySelector('input[type="time"]'); + initDateTimeInputs(); + } + + function handleOnHidden() { + state.open = false; + } + + function handleOnActivate(ev, { post_uuid }) { + state.edit = false; + + const postData = state.posts[post_uuid]; + if (postData && postData.isMain && postData.timestamp > Date.now()) { + state.timestamp = postData.timestamp; + state.edit = true; + toggleItems(); + } + } + + function initDateTimeInputs() { + const d = new Date(); + // Update min. selectable date and time + const nowLocalISO = new Date(d.getTime() - (d.getTimezoneOffset() * 60000)).toJSON(); + dateInput.setAttribute('min', nowLocalISO.slice(0, 10)); + timeInput.setAttribute('min', nowLocalISO.slice(11, -8)); + + if (scheduler.isActive()) { + const scheduleDate = new Date(state.timestamp - (d.getTimezoneOffset() * 60000)).toJSON(); + dateInput.value = scheduleDate.slice(0, 10); + timeInput.value = scheduleDate.slice(11, -8); + } + } + + function setTimestamp() { + const bothFilled = dateInput.value && timeInput.value; + const timestamp = new Date(`${dateInput.value} ${timeInput.value}`).getTime(); + if (!bothFilled || isNaN(timestamp) || timestamp < Date.now()) { + state.timestamp = 0; + const message = timestamp < Date.now() ? '[[error:scheduling-to-past]]' : '[[error:invalid-schedule-date]]'; + alerts.alert({ + type: 'danger', + timeout: 3000, + title: '', + alert_id: 'post_error', + message, + }); + return false; + } + if (!state.timestamp) { + toggleItems(true); + } + state.timestamp = timestamp; + } + + function cancelScheduling() { + if (!state.timestamp) { + return; + } + toggleItems(false); + state.timestamp = 0; + } + + function toggleItems(active = true) { + displayBtns.forEach(btn => btn.classList.toggle('active', active)); + if (submitBtn.icon) { + submitBtn.icon.classList.toggle('fa-check', !active); + submitBtn.icon.classList.toggle('fa-clock-o', active); + } + if (dropdownDisplayBtn.el) { + dropdownDisplayBtn.el.textContent = active ? dropdownDisplayBtn.activeText : dropdownDisplayBtn.defaultText; + cancelBtn.classList.toggle('hidden', !active); + } + // Toggle submit button text + submitBtn.el.lastChild.textContent = active ? submitBtn.activeText : submitBtn.defaultText; + } + + function toggleDisplayButtons(show) { + displayBtnCons.forEach(btn => btn.classList.toggle('hidden', !show)); + } + + return scheduler; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/tags.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/tags.js new file mode 100644 index 0000000000..338e4546d2 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/tags.js @@ -0,0 +1,227 @@ + +'use strict'; + +define('composer/tags', ['alerts'], function (alerts) { + var tags = {}; + + var minTags; + var maxTags; + + tags.init = function (postContainer, postData) { + var tagEl = postContainer.find('.tags'); + if (!tagEl.length) { + return; + } + + minTags = ajaxify.data.hasOwnProperty('minTags') ? ajaxify.data.minTags : config.minimumTagsPerTopic; + maxTags = ajaxify.data.hasOwnProperty('maxTags') ? ajaxify.data.maxTags : config.maximumTagsPerTopic; + + tagEl.tagsinput({ + tagClass: 'badge bg-info rounded-1', + confirmKeys: [13, 44], + trimValue: true, + }); + var input = postContainer.find('.bootstrap-tagsinput input'); + + toggleTagInput(postContainer, postData, ajaxify.data); + + app.loadJQueryUI(function () { + input.autocomplete({ + delay: 100, + position: { my: 'left bottom', at: 'left top', collision: 'flip' }, + appendTo: postContainer.find('.bootstrap-tagsinput'), + open: function () { + $(this).autocomplete('widget').css('z-index', 20000); + }, + source: function (request, response) { + socket.emit('topics.autocompleteTags', { + query: request.term, + cid: postData.cid, + }, function (err, tags) { + if (err) { + return alerts.error(err); + } + if (tags) { + response(tags); + } + $('.ui-autocomplete a').attr('data-ajaxify', 'false'); + }); + }, + select: function (/* event, ui */) { + // when autocomplete is selected from the dropdown simulate a enter key down to turn it into a tag + triggerEnter(input); + }, + }); + + addTags(postData.tags, tagEl); + + tagEl.on('beforeItemAdd', function (event) { + var reachedMaxTags = maxTags && maxTags <= tags.getTags(postContainer.attr('data-uuid')).length; + var cleanTag = utils.cleanUpTag(event.item, config.maximumTagLength); + var different = cleanTag !== event.item; + event.cancel = different || + event.item.length < config.minimumTagLength || + event.item.length > config.maximumTagLength || + reachedMaxTags; + + if (event.item.length < config.minimumTagLength) { + return alerts.error('[[error:tag-too-short, ' + config.minimumTagLength + ']]'); + } else if (event.item.length > config.maximumTagLength) { + return alerts.error('[[error:tag-too-long, ' + config.maximumTagLength + ']]'); + } else if (reachedMaxTags) { + return alerts.error('[[error:too-many-tags, ' + maxTags + ']]'); + } + if (different) { + tagEl.tagsinput('add', cleanTag); + } + }); + + var skipAddCheck = false; + var skipRemoveCheck = false; + tagEl.on('itemRemoved', function (event) { + if (skipRemoveCheck) { + skipRemoveCheck = false; + return; + } + + if (!event.item) { + return; + } + socket.emit('topics.canRemoveTag', { tag: event.item }, function (err, allowed) { + if (err) { + return alerts.error(err); + } + if (!allowed) { + alerts.error('[[error:cant-remove-system-tag]]'); + skipAddCheck = true; + tagEl.tagsinput('add', event.item); + } + }); + }); + + tagEl.on('itemAdded', function (event) { + if (skipAddCheck) { + skipAddCheck = false; + return; + } + var cid = postData.hasOwnProperty('cid') ? postData.cid : ajaxify.data.cid; + socket.emit('topics.isTagAllowed', { tag: event.item, cid: cid || 0 }, function (err, allowed) { + if (err) { + return alerts.error(err); + } + if (!allowed) { + skipRemoveCheck = true; + return tagEl.tagsinput('remove', event.item); + } + $(window).trigger('action:tag.added', { cid: cid, tagEl: tagEl, tag: event.item }); + if (input.length) { + input.autocomplete('close'); + } + }); + }); + }); + + input.attr('tabIndex', tagEl.attr('tabIndex')); + input.on('blur', function () { + triggerEnter(input); + }); + + $('[component="composer/tag/dropdown"]').on('click', 'li', function () { + var tag = $(this).attr('data-tag'); + if (tag) { + addTags([tag], tagEl); + } + return false; + }); + }; + + tags.isEnoughTags = function (post_uuid) { + return tags.getTags(post_uuid).length >= minTags; + }; + + tags.minTagCount = function () { + return minTags; + }; + + tags.onChangeCategory = function (postContainer, postData, cid, categoryData) { + var tagDropdown = postContainer.find('[component="composer/tag/dropdown"]'); + if (!tagDropdown.length) { + return; + } + + toggleTagInput(postContainer, postData, categoryData); + tagDropdown.toggleClass('hidden', !categoryData.tagWhitelist || !categoryData.tagWhitelist.length); + if (categoryData.tagWhitelist) { + app.parseAndTranslate('composer', 'tagWhitelist', { tagWhitelist: categoryData.tagWhitelist }, function (html) { + tagDropdown.find('.dropdown-menu').html(html); + }); + } + }; + + function toggleTagInput(postContainer, postData, data) { + var tagEl = postContainer.find('.tags'); + var input = postContainer.find('.bootstrap-tagsinput input'); + if (!input.length) { + return; + } + + if (data.hasOwnProperty('minTags')) { + minTags = data.minTags; + } + if (data.hasOwnProperty('maxTags')) { + maxTags = data.maxTags; + } + + if (data.tagWhitelist && data.tagWhitelist.length) { + input.attr('readonly', ''); + input.attr('placeholder', ''); + + tagEl.tagsinput('items').slice().forEach(function (tag) { + if (data.tagWhitelist.indexOf(tag) === -1) { + tagEl.tagsinput('remove', tag); + } + }); + } else { + input.removeAttr('readonly'); + input.attr('placeholder', postContainer.find('input.tags').attr('placeholder')); + } + postContainer.find('.tags-container').toggleClass('haswhitelist', !!(data.tagWhitelist && data.tagWhitelist.length)); + postContainer.find('.tags-container').toggleClass('hidden', ( + data.privileges && data.privileges.hasOwnProperty('topics:tag') && !data.privileges['topics:tag']) || + (maxTags === 0 && !postData && !postData.tags && !postData.tags.length)); + + if (data.privileges && data.privileges.hasOwnProperty('topics:tag') && !data.privileges['topics:tag']) { + tagEl.tagsinput('removeAll'); + } + + $(window).trigger('action:tag.toggleInput', { + postContainer: postContainer, + tagWhitelist: data.tagWhitelist, + tagsInput: input, + }); + } + + function triggerEnter(input) { + // http://stackoverflow.com/a/3276819/583363 + var e = jQuery.Event('keypress'); + e.which = 13; + e.keyCode = 13; + setTimeout(function () { + input.trigger(e); + }, 100); + } + + function addTags(tags, tagEl) { + if (tags && tags.length) { + for (var i = 0; i < tags.length; ++i) { + tagEl.tagsinput('add', tags[i]); + } + } + } + + tags.getTags = function (post_uuid) { + return $('.composer[data-uuid="' + post_uuid + '"] .tags').tagsinput('items'); + }; + + return tags; +}); diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/composer/uploads.js b/node_modules/nodebb-plugin-composer-default/static/lib/composer/uploads.js new file mode 100644 index 0000000000..6da01db605 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/lib/composer/uploads.js @@ -0,0 +1,271 @@ +'use strict'; + +define('composer/uploads', [ + 'composer/preview', + 'composer/categoryList', + 'translator', + 'alerts', + 'uploadHelpers', + 'jquery-form', +], function (preview, categoryList, translator, alerts, uploadHelpers) { + var uploads = { + inProgress: {}, + }; + + var uploadingText = ''; + + uploads.initialize = function (post_uuid) { + initializeDragAndDrop(post_uuid); + initializePaste(post_uuid); + + addChangeHandlers(post_uuid); + addTopicThumbHandlers(post_uuid); + translator.translate('[[modules:composer.uploading, ' + 0 + '%]]', function (translated) { + uploadingText = translated; + }); + }; + + function addChangeHandlers(post_uuid) { + var postContainer = $('.composer[data-uuid="' + post_uuid + '"]'); + + postContainer.find('#files').on('change', function (e) { + var files = (e.target || {}).files || + ($(this).val() ? [{ name: $(this).val(), type: utils.fileMimeType($(this).val()) }] : null); + if (files) { + uploadContentFiles({ files: files, post_uuid: post_uuid, route: '/api/post/upload' }); + } + }); + } + + function addTopicThumbHandlers(post_uuid) { + var postContainer = $('.composer[data-uuid="' + post_uuid + '"]'); + + postContainer.on('click', '.topic-thumb-clear-btn', function (e) { + postContainer.find('input#topic-thumb-url').val('').trigger('change'); + resetInputFile(postContainer.find('input#topic-thumb-file')); + $(this).addClass('hide'); + e.preventDefault(); + }); + + postContainer.on('paste change keypress', 'input#topic-thumb-url', function () { + var urlEl = $(this); + setTimeout(function () { + var url = urlEl.val(); + if (url) { + postContainer.find('.topic-thumb-clear-btn').removeClass('hide'); + } else { + resetInputFile(postContainer.find('input#topic-thumb-file')); + postContainer.find('.topic-thumb-clear-btn').addClass('hide'); + } + postContainer.find('img.topic-thumb-preview').attr('src', url); + }, 100); + }); + } + + function resetInputFile($el) { + $el.wrap('
    ').closest('form').get(0).reset(); + $el.unwrap(); + } + + function initializeDragAndDrop(post_uuid) { + var postContainer = $('.composer[data-uuid="' + post_uuid + '"]'); + uploadHelpers.handleDragDrop({ + container: postContainer, + callback: function (upload) { + uploadContentFiles({ + files: upload.files, + post_uuid: post_uuid, + route: '/api/post/upload', + formData: upload.formData, + }); + }, + }); + } + + function initializePaste(post_uuid) { + var postContainer = $('.composer[data-uuid="' + post_uuid + '"]'); + uploadHelpers.handlePaste({ + container: postContainer, + callback: function (upload) { + uploadContentFiles({ + files: upload.files, + fileNames: upload.fileNames, + post_uuid: post_uuid, + route: '/api/post/upload', + formData: upload.formData, + }); + }, + }); + } + + function escapeRegExp(text) { + return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + } + + function insertText(str, index, insert) { + return str.slice(0, index) + insert + str.slice(index); + } + + function uploadContentFiles(params) { + var files = [...params.files]; + var post_uuid = params.post_uuid; + var postContainer = $('.composer[data-uuid="' + post_uuid + '"]'); + var textarea = postContainer.find('textarea'); + var text = textarea.val(); + var uploadForm = postContainer.find('#fileForm'); + var doneUploading = false; + uploadForm.attr('action', config.relative_path + params.route); + + var cid = categoryList.getSelectedCid(); + if (!cid && ajaxify.data.cid) { + cid = ajaxify.data.cid; + } + var i = 0; + var isImage = false; + for (i = 0; i < files.length; ++i) { + isImage = files[i].type.match(/image./); + if ((isImage && !app.user.privileges['upload:post:image']) || (!isImage && !app.user.privileges['upload:post:file'])) { + return alerts.error('[[error:no-privileges]]'); + } + } + + var filenameMapping = []; + let filesText = ''; + for (i = 0; i < files.length; ++i) { + // The filename map has datetime and iterator prepended so that they can be properly tracked even if the + // filenames are identical. + filenameMapping.push(i + '_' + Date.now() + '_' + (params.fileNames ? params.fileNames[i] : files[i].name)); + isImage = files[i].type.match(/image./); + + if (!app.user.isAdmin && files[i].size > parseInt(config.maximumFileSize, 10) * 1024) { + uploadForm[0].reset(); + return alerts.error('[[error:file-too-big, ' + config.maximumFileSize + ']]'); + } + filesText += (isImage ? '!' : '') + '[' + filenameMapping[i] + '](' + uploadingText + ') '; + } + + const cursorPosition = textarea.getCursorPosition(); + const textLen = text.length; + text = insertText(text, cursorPosition, filesText); + + if (uploadForm.length) { + postContainer.find('[data-action="post"]').prop('disabled', true); + } + textarea.val(text); + + $(window).trigger('action:composer.uploadStart', { + post_uuid: post_uuid, + files: filenameMapping.map(function (filename, i) { + return { + filename: filename.replace(/^\d+_\d{13}_/, ''), + isImage: /image./.test(files[i].type), + }; + }), + text: uploadingText, + }); + + uploadForm.off('submit').submit(function () { + function updateTextArea(filename, text, trim) { + var newFilename; + if (trim) { + newFilename = filename.replace(/^\d+_\d{13}_/, ''); + } + var current = textarea.val(); + var re = new RegExp(escapeRegExp(filename) + ']\\([^)]+\\)', 'g'); + textarea.val(current.replace(re, (newFilename || filename) + '](' + text + ')')); + + $(window).trigger('action:composer.uploadUpdate', { + post_uuid: post_uuid, + filename: filename, + text: text, + }); + } + + uploads.inProgress[post_uuid] = uploads.inProgress[post_uuid] || []; + uploads.inProgress[post_uuid].push(1); + + if (params.formData) { + params.formData.append('cid', cid); + } + + $(this).ajaxSubmit({ + headers: { + 'x-csrf-token': config.csrf_token, + }, + resetForm: true, + clearForm: true, + formData: params.formData, + data: { cid: cid }, + + error: function (xhr) { + doneUploading = true; + postContainer.find('[data-action="post"]').prop('disabled', false); + const errorMsg = onUploadError(xhr, post_uuid); + for (var i = 0; i < files.length; ++i) { + updateTextArea(filenameMapping[i], errorMsg, true); + } + preview.render(postContainer); + }, + + uploadProgress: function (event, position, total, percent) { + translator.translate('[[modules:composer.uploading, ' + percent + '%]]', function (translated) { + if (doneUploading) { + return; + } + for (var i = 0; i < files.length; ++i) { + updateTextArea(filenameMapping[i], translated); + } + }); + }, + + success: function (res) { + const uploads = res.response.images; + doneUploading = true; + if (uploads && uploads.length) { + for (var i = 0; i < uploads.length; ++i) { + uploads[i].filename = filenameMapping[i].replace(/^\d+_\d{13}_/, ''); + uploads[i].isImage = /image./.test(files[i].type); + updateTextArea(filenameMapping[i], uploads[i].url, true); + } + } + preview.render(postContainer); + textarea.prop('selectionEnd', cursorPosition + textarea.val().length - textLen); + textarea.focus(); + postContainer.find('[data-action="post"]').prop('disabled', false); + $(window).trigger('action:composer.upload', { + post_uuid: post_uuid, + files: uploads, + }); + }, + + complete: function () { + uploadForm[0].reset(); + uploads.inProgress[post_uuid].pop(); + }, + }); + + return false; + }); + + uploadForm.submit(); + } + + function onUploadError(xhr, post_uuid) { + var msg = (xhr.responseJSON && + (xhr.responseJSON.error || (xhr.responseJSON.status && xhr.responseJSON.status.message))) || + '[[error:parse-error]]'; + + if (xhr && xhr.status === 413) { + msg = xhr.statusText || 'Request Entity Too Large'; + } + alerts.error(msg); + $(window).trigger('action:composer.uploadError', { + post_uuid: post_uuid, + message: msg, + }); + return msg; + } + + return uploads; +}); + diff --git a/node_modules/nodebb-plugin-composer-default/static/scss/composer.scss b/node_modules/nodebb-plugin-composer-default/static/scss/composer.scss new file mode 100644 index 0000000000..e9157dc92d --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/scss/composer.scss @@ -0,0 +1,385 @@ +.composer { + background-color: var(--bs-body-bg); + color: var(--bs-body-color); + z-index: $zindex-dropdown; + visibility: hidden; + padding: 0; + position: fixed; + bottom: 0; + top: 0; + right: 0; + left: 0; + + .mobile-navbar { + position: static; + min-height: 40px; + margin: 0; + + .btn-group { + flex-shrink: 0; + } + + button { + font-size: 20px; + } + + display: flex; + + .category-name-container, .title { + text-align: center; + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; + flex-grow: 2; + font-size: 16px; + line-height: inherit; + padding: 9px 5px; + margin: 0; + } + } + + .title-container { + > div[data-component="composer/handle"] { + flex: 0.33; + } + + .category-list-container { + + [component="category-selector"] { + .category-dropdown-menu { + max-height: 300px; + } + } + } + + .category-list { + padding: 0 2rem; + } + + .action-bar { + .dropdown-menu:empty { + & ~ .dropdown-toggle { + display: none; + } + } + } + } + + .formatting-bar { + .spacer { + &:before { + content: ' | '; + color: $gray-200; + } + } + } + + .tags-container { + [component="composer/tag/dropdown"] { + .dropdown-menu { + max-height: 400px; + overflow-y: auto; + } + + > button { + border: 0; + } + } + // if picking tags from taglist dropdown hide the input + &.haswhitelist .bootstrap-tagsinput { + input { + display: none; + } + } + .bootstrap-tagsinput { + background: transparent; + flex-grow: 1; + border: 0; + padding: 0; + box-shadow: none; + max-height: 80px; + overflow: auto; + + input { + &::placeholder{ + color: $input-placeholder-color; + } + color: $body-color; + font-size: 16px; + width: 50%; + @include media-breakpoint-down(md) { + width: 100%; + } + + + height: 28px; + padding: 4px 6px; + } + + .ui-autocomplete { + max-height: 350px; + overflow-x: hidden; + overflow-y: auto; + } + } + } + + .resizer { + background: linear-gradient(transparent, var(--bs-body-bg)); + margin-left: calc($spacer * -0.5); + padding-left: $spacer; + + .trigger { + cursor: ns-resize; + + .handle { + border-top-left-radius: 50%; + border-top-right-radius: 50%; + border-bottom: 0 !important; + } + } + } + + .minimize { + display: none; + position: absolute; + top: 0px; + right: 10px; + height: 0; + + @include pointer; + + .trigger { + position: relative; + display: block; + top: -20px; + right: 0px; + margin: 0 auto; + margin-left: 20px; + line-height: 26px; + @include transition(filter .15s linear); + + &:hover { + filter: invert(100%); + } + + i { + width: 32px; + height: 32px; + background: #333; + border: 1px solid #333; + border-radius: 50%; + + position: relative; + + color: #FFF; + font-size: 16px; + + &:before { + position: relative; + top: 25%; + } + } + } + } + + &.reply { + .title-container { + display: none; + } + } + + &.resizable.maximized { + .resizer { + top: 0 !important; + background: transparent; + + .trigger { + height: $spacer * 0.5; + + .handle { + border-top-left-radius: 0%; + border-top-right-radius: 0%; + border-bottom-left-radius: 50%; + border-bottom-right-radius: 50%; + border-bottom: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color) !important; + } + + i { + &:before { + content: fa-content($fa-var-chevron-down); + } + } + } + } + } + + .draft-icon { + font-family: 'FontAwesome'; + color: $success; + opacity: 0; + + &::before { + content: fa-content($fa-var-save); + } + + &.active { + animation: draft-saved 3s ease; + } + } + + textarea { + resize: none; + } + + .preview { + padding: $input-padding-y $input-padding-x; + } +} + +.datetime-picker { + display: flex; + justify-content: center; + flex-direction: row; + min-width: 310px; + max-width: 310px; + margin: 0 auto; + + input { + flex: 3; + line-height: inherit; + } + + input + input { + border-left: none; + flex: 2; + } +} + +.modal.topic-scheduler { + z-index: 1070; + & + .modal-backdrop { + z-index: 1060; + } +} + +@keyframes draft-saved { + 0%, 100% { + opacity: 0; + } + + 15% { + opacity: 1; + } + + 30% { + opacity: 0.5; + } + + 45% { + opacity: 1; + } + + 85% { + opacity: 1; + } +} + +@keyframes pulse { + from { + transform: scale(1); + color: inherit; + } + 50% { + transform: scale(.9); + } + to { + transform: scale(1); + color: #00adff; + } +} + +@include media-breakpoint-down(lg) { + html.composing .composer { z-index: $zindex-modal; } +} + +@include media-breakpoint-down(sm) { + html.composing { + .composer { + height: 100%; + + .draft-icon { + position: absolute; + bottom: 1em; + right: 0em; + + &::after { + top: 7px; + } + } + + .preview-container { + max-width: initial; + } + } + + body { + padding-bottom: 0 !important; + } + } +} + +@include media-breakpoint-up(lg) { + html.composing { + .composer { + left: 15%; + width: 70%; + min-height: 400px; + + .resizer { + display: block; + } + + .minimize { + display: block; + } + } + } +} + +@include media-breakpoint-up(md) { + // without this formatting elements that are dropdowns are not visible on desktop. + // on mobile dropdowns use bottom-sheet and overflow is auto + .formatting-group { + overflow: visible!important; + } +} + +@import './zen-mode'; +@import './page-compose'; +@import './textcomplete'; + + +.skin-noskin, .skin-cosmo, .skin-flatly, +.skin-journal, .skin-litera, .skin-minty, .skin-pulse, +.skin-sandstone, .skin-sketchy, .skin-spacelab, .skin-united { + .composer { + color: var(--bs-secondary) !important; + background-color: var(--bs-light) !important; + } +} + +.skin-cerulean, .skin-lumen, .skin-lux, .skin-morph, +.skin-simplex, .skin-yeti, .skin-zephyr { + .composer { + color: var(--bs-body) !important; + background-color: var(--bs-light) !important; + } +} + +@include color-mode(dark) { + .skin-noskin .composer { + color: var(--bs-secondary)!important; + background-color: var(--bs-body-bg)!important; + } +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/scss/page-compose.scss b/node_modules/nodebb-plugin-composer-default/static/scss/page-compose.scss new file mode 100644 index 0000000000..2b2756f426 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/scss/page-compose.scss @@ -0,0 +1,35 @@ +.page-compose .composer { + z-index: initial; + position: static; + [data-action="hide"] { + display: none; + } + + @include media-breakpoint-down(md) { + .title-container { + flex-wrap: wrap; + } + .category-list-container { + [component="category-selector-selected"] > span { + display: inline!important; + } + width: 100%; + } + } +} + +.zen-mode .page-compose .composer { + position: absolute; +} +.page-compose { + &.skin-noskin, &.skin-cosmo, &.skin-flatly, + &.skin-journal, &.skin-litera, &.skin-minty, &.skin-pulse, + &.skin-sandstone, &.skin-sketchy, &.skin-spacelab, &.skin-united, + &.skin-cerulean, &.skin-lumen, &.skin-lux, &.skin-morph, + &.skin-simplex, &.skin-yeti, &.skin-zephyr { + .composer { + color: var(--bs-body-color) !important; + background-color: var(--bs-body-bg) !important; + } + } +} diff --git a/node_modules/nodebb-plugin-composer-default/static/scss/textcomplete.scss b/node_modules/nodebb-plugin-composer-default/static/scss/textcomplete.scss new file mode 100644 index 0000000000..7a4cad943a --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/scss/textcomplete.scss @@ -0,0 +1,26 @@ +.textcomplete-dropdown { + border: 1px solid $border-color; + background-color: $body-bg; + color: $body-color; + list-style: none; + padding: 0; + margin: 0; + + li { + margin: 0; + } + + .textcomplete-footer, .textcomplete-item { + border-top: 1px solid $border-color; + } + + .textcomplete-item { + padding: 2px 5px; + cursor: pointer; + + &:hover, &.active { + color: $dropdown-link-hover-color; + background-color: $dropdown-link-hover-bg; + } + } +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/scss/zen-mode.scss b/node_modules/nodebb-plugin-composer-default/static/scss/zen-mode.scss new file mode 100644 index 0000000000..b29340e8d3 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/scss/zen-mode.scss @@ -0,0 +1,51 @@ +html.zen-mode { + overflow: hidden; +} + +.zen-mode .composer { + &.resizable { + padding-top: 0; + } + + .composer-container { + padding-top: 5px; + } + + .tag-row { + display: none; + } + + .title-container .category-list-container { + margin-top: 3px; + } + + .write, .preview { + border: none; + outline: none; + } + + .resizer { + display: none; + } + + &.reply { + .title-container { + display: none; + } + } + + @include media-breakpoint-up(md) { + & { + padding-left: 15px; + padding-right: 15px; + } + .write-preview-container { + margin-bottom: 0; + + > div { + padding: 0; + margin: 0; + } + } + } +} \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/templates/admin/plugins/composer-default.tpl b/node_modules/nodebb-plugin-composer-default/static/templates/admin/plugins/composer-default.tpl new file mode 100644 index 0000000000..a7fa31ce59 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/templates/admin/plugins/composer-default.tpl @@ -0,0 +1,22 @@ +
    + + +
    +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    +
    + diff --git a/node_modules/nodebb-plugin-composer-default/static/templates/compose.tpl b/node_modules/nodebb-plugin-composer-default/static/templates/compose.tpl new file mode 100644 index 0000000000..9fb4300baf --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/templates/compose.tpl @@ -0,0 +1,27 @@ +
    +
    +
    + {{{ if pid }}} + + + {{{ end }}} + {{{ if tid }}} + + {{{ end }}} + {{{ if cid }}} + + {{{ end }}} + +
    + + + + + + + + {{{ if isTopicOrMain }}} + + {{{ end }}} +
    +
    diff --git a/node_modules/nodebb-plugin-composer-default/static/templates/composer.tpl b/node_modules/nodebb-plugin-composer-default/static/templates/composer.tpl new file mode 100644 index 0000000000..f4ee338c69 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/templates/composer.tpl @@ -0,0 +1,46 @@ +
    +
    + + +
    + + + + + + + {{{ if isTopicOrMain }}} + + {{{ end }}} + +
    [[topic:composer.drag-and-drop-images]]
    + +
    +
    +
    + +
    +
    +
    +
    +
    +
    diff --git a/node_modules/nodebb-plugin-composer-default/static/templates/modals/topic-scheduler.tpl b/node_modules/nodebb-plugin-composer-default/static/templates/modals/topic-scheduler.tpl new file mode 100644 index 0000000000..29736747c6 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/templates/modals/topic-scheduler.tpl @@ -0,0 +1,4 @@ +
    + + +
    \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-formatting.tpl b/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-formatting.tpl new file mode 100644 index 0000000000..941f06f2e4 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-formatting.tpl @@ -0,0 +1,75 @@ +
    +
      + {{{ each formatting }}} + {{{ if ./spacer }}} +
    • + {{{ else }}} + {{{ if (./visibility.desktop && ((isTopicOrMain && ./visibility.main) || (!isTopicOrMain && ./visibility.reply))) }}} + {{{ if ./dropdownItems.length }}} + + {{{ else }}} +
    • + +
    • + {{{ end }}} + {{{ end }}} + {{{ end }}} + {{{ end }}} + + {{{ if privileges.upload:post:image }}} +
    • + +
    • + {{{ end }}} + + {{{ if privileges.upload:post:file }}} +
    • + +
    • + {{{ end }}} + +
      + +
      +
    +
    + + + {{{ if composer:showHelpTab }}} + + {{{ end }}} +
    +
    + diff --git a/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-tags.tpl b/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-tags.tpl new file mode 100644 index 0000000000..e247403419 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-tags.tpl @@ -0,0 +1,17 @@ +
    +
    +
    + + + +
    + +
    +
    \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-title-container.tpl b/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-title-container.tpl new file mode 100644 index 0000000000..185393f285 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-title-container.tpl @@ -0,0 +1,46 @@ +
    + {{{ if isTopic }}} +
    + +
    + {{{ end }}} + + {{{ if showHandleInput }}} +
    + +
    + {{{ end }}} + +
    + {{{ if isTopicOrMain }}} + + {{{ else }}} + {{{ if isEditing }}}[[topic:composer.editing-in, "{topicTitle}"]]{{{ else }}}[[topic:composer.replying-to, "{topicTitle}"]]{{{ end }}} + {{{ end }}} + +
    + +
    + + +
    + +
    + + +
    +
    +
    +
    diff --git a/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-write-preview.tpl b/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-write-preview.tpl new file mode 100644 index 0000000000..37cefbd220 --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/static/templates/partials/composer-write-preview.tpl @@ -0,0 +1,10 @@ +
    +
    +
    [[modules:composer.post-queue-alert]]
    + + +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/node_modules/nodebb-plugin-composer-default/websockets.js b/node_modules/nodebb-plugin-composer-default/websockets.js new file mode 100644 index 0000000000..882dbb2b0d --- /dev/null +++ b/node_modules/nodebb-plugin-composer-default/websockets.js @@ -0,0 +1,94 @@ +'use strict'; + +const meta = require.main.require('./src/meta'); +const privileges = require.main.require('./src/privileges'); +const posts = require.main.require('./src/posts'); +const topics = require.main.require('./src/topics'); +const plugins = require.main.require('./src/plugins'); + +const Sockets = module.exports; + +Sockets.push = async function (socket, pid) { + const canRead = await privileges.posts.can('topics:read', pid, socket.uid); + if (!canRead) { + throw new Error('[[error:no-privileges]]'); + } + + const postData = await posts.getPostFields(pid, ['content', 'tid', 'uid', 'handle', 'timestamp']); + if (!postData && !postData.content) { + throw new Error('[[error:invalid-pid]]'); + } + + const [topic, tags, isMain] = await Promise.all([ + topics.getTopicDataByPid(pid), + topics.getTopicTags(postData.tid), + posts.isMain(pid), + ]); + + if (!topic) { + throw new Error('[[error:no-topic]]'); + } + + const result = await plugins.hooks.fire('filter:composer.push', { + pid: pid, + uid: postData.uid, + handle: parseInt(meta.config.allowGuestHandles, 10) ? postData.handle : undefined, + body: postData.content, + title: topic.title, + thumb: topic.thumb, + tags: tags, + isMain: isMain, + timestamp: postData.timestamp, + }); + return result; +}; + +Sockets.editCheck = async function (socket, pid) { + const isMain = await posts.isMain(pid); + return { titleEditable: isMain }; +}; + +Sockets.renderPreview = async function (socket, content) { + return await plugins.hooks.fire('filter:parse.raw', content); +}; + +Sockets.renderHelp = async function () { + const helpText = meta.config['composer:customHelpText'] || ''; + if (!meta.config['composer:showHelpTab']) { + throw new Error('help-hidden'); + } + + const parsed = await plugins.hooks.fire('filter:parse.raw', helpText); + if (meta.config['composer:allowPluginHelp'] && plugins.hooks.hasListeners('filter:composer.help')) { + return await plugins.hooks.fire('filter:composer.help', parsed) || helpText; + } + return helpText; +}; + +Sockets.getFormattingOptions = async function () { + return await require('./library').getFormattingOptions(); +}; + +Sockets.shouldQueue = async function (socket, data) { + if (!data || !data.postData) { + throw new Error('[[error:invalid-data]]'); + } + if (socket.uid <= 0) { + return false; + } + + let shouldQueue = false; + const { postData } = data; + if (postData.action === 'posts.reply') { + shouldQueue = await posts.shouldQueue(socket.uid, { + tid: postData.tid, + content: postData.content || '', + }); + } else if (postData.action === 'topics.post') { + shouldQueue = await posts.shouldQueue(socket.uid, { + cid: postData.cid, + content: postData.content || '', + }); + } + return shouldQueue; +}; diff --git a/public/language/en-GB/topic.json b/public/language/en-GB/topic.json index 9027774603..a2bf7d5690 100644 --- a/public/language/en-GB/topic.json +++ b/public/language/en-GB/topic.json @@ -189,7 +189,11 @@ "composer.replying-to": "Replying to %1", "composer.new-topic": "New Topic", "composer.editing-in": "Editing post in %1", - + "composer-anonymous-none": "None", + "composer-anonymous-student": "Student", + "composer-anonymous-all": "Everyone", + "composer.select-anonymous-type": "Annonymous type", + "composer.uploading": "uploading...", "composer.thumb-url-label": "Paste a topic thumbnail URL", "composer.thumb-title": "Add a thumbnail to this topic", diff --git a/src/posts/create.js b/src/posts/create.js index d541564c2e..342c2ece82 100644 --- a/src/posts/create.js +++ b/src/posts/create.js @@ -19,6 +19,7 @@ module.exports = function (Posts) { const content = data.content.toString(); const timestamp = data.timestamp || Date.now(); const isMain = data.isMain || false; + const { annonymousType } = data; if (!uid && parseInt(uid, 10) !== 0) { throw new Error('[[error:invalid-uid]]'); @@ -35,6 +36,7 @@ module.exports = function (Posts) { tid: tid, content: content, timestamp: timestamp, + annonymousType: annonymousType, }; if (data.toPid) {