diff --git a/.gitignore b/.gitignore index 4b322f31b1..70a23d76bc 100644 --- a/.gitignore +++ b/.gitignore @@ -75,4 +75,6 @@ link-plugins.sh test.sh .docker/** -!**/.gitkeep \ No newline at end of file +!**/.gitkeep +# stryker temp files +.stryker-tmp diff --git a/node_modules/nodebb-plugin-composer-default/.eslintrc b/node_modules/nodebb-plugin-composer-default/.eslintrc deleted file mode 100644 index 74e8dc064a..0000000000 --- a/node_modules/nodebb-plugin-composer-default/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "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 deleted file mode 100644 index 412eeda78d..0000000000 --- a/node_modules/nodebb-plugin-composer-default/.gitattributes +++ /dev/null @@ -1,22 +0,0 @@ -# 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 deleted file mode 100644 index 1981c254c5..0000000000 --- a/node_modules/nodebb-plugin-composer-default/.jshintrc +++ /dev/null @@ -1,86 +0,0 @@ -{ - // 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 deleted file mode 100644 index b8658d3aa1..0000000000 --- a/node_modules/nodebb-plugin-composer-default/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 7bcfff9aff..0000000000 --- a/node_modules/nodebb-plugin-composer-default/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# 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 deleted file mode 100644 index cef271849f..0000000000 --- a/node_modules/nodebb-plugin-composer-default/controllers.js +++ /dev/null @@ -1,11 +0,0 @@ -'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 deleted file mode 100644 index c80eef1f5e..0000000000 --- a/node_modules/nodebb-plugin-composer-default/library.js +++ /dev/null @@ -1,310 +0,0 @@ -'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 deleted file mode 100644 index 625184980c..0000000000 --- a/node_modules/nodebb-plugin-composer-default/package.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "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 deleted file mode 100644 index c75ef14259..0000000000 --- a/node_modules/nodebb-plugin-composer-default/plugin.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "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 deleted file mode 100644 index a6d4631e4e..0000000000 Binary files a/node_modules/nodebb-plugin-composer-default/screenshots/desktop.png and /dev/null differ diff --git a/node_modules/nodebb-plugin-composer-default/screenshots/mobile.png b/node_modules/nodebb-plugin-composer-default/screenshots/mobile.png deleted file mode 100644 index a50a01ea93..0000000000 Binary files a/node_modules/nodebb-plugin-composer-default/screenshots/mobile.png and /dev/null differ diff --git a/node_modules/nodebb-plugin-composer-default/static/lib/.eslintrc b/node_modules/nodebb-plugin-composer-default/static/lib/.eslintrc deleted file mode 100644 index 9fc9d47e53..0000000000 --- a/node_modules/nodebb-plugin-composer-default/static/lib/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "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 deleted file mode 100644 index cc693300ea..0000000000 --- a/node_modules/nodebb-plugin-composer-default/static/lib/admin.js +++ /dev/null @@ -1,15 +0,0 @@ -'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 deleted file mode 100644 index 2b46e406b8..0000000000 --- a/node_modules/nodebb-plugin-composer-default/static/lib/client.js +++ /dev/null @@ -1,89 +0,0 @@ -'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 deleted file mode 100644 index 5d789eb6a4..0000000000 --- a/node_modules/nodebb-plugin-composer-default/static/lib/composer.js +++ /dev/null @@ -1,899 +0,0 @@ -'use strict'; - -define('composer', [ - 'taskbar', - 'translator', - 'composer/uploads', - 'composer/formatting', - 'composer/drafts', - 'composer/tags', - 'composer/categoryList', - 'composer/preview', - 'composer/resize', - 'composer/autocomplete', - 'composer/scheduler', - 'composer/post-queue', - 'scrollStop', - 'topicThumbs', - 'api', - 'bootbox', - 'alerts', - 'hooks', - 'messages', - 'search', - 'screenfull', - -], function (taskbar, translator, uploads, formatting, drafts, tags, - categoryList, preview, resize, autocomplete, scheduler, postQueue, scrollStop, - topicThumbs, api, bootbox, alerts, hooks, messagesModule, search, screenfull) { - var composer = { - active: undefined, - posts: {}, - bsEnvironment: undefined, - formatting: undefined, - }; - // Added: - var isAnonymous = false; - - $(window).off('resize', onWindowResize).on('resize', onWindowResize); - onWindowResize(); - - $(window).on('action:composer.topics.post', function (ev, data) { - localStorage.removeItem('category:' + data.data.cid + ':bookmark'); - localStorage.removeItem('category:' + data.data.cid + ':bookmark:clicked'); - }); - - $(window).on('popstate', function () { - var env = utils.findBootstrapEnvironment(); - if (composer.active && (env === 'xs' || env === 'sm')) { - if (!composer.posts[composer.active].modified) { - composer.discard(composer.active); - if (composer.discardConfirm && composer.discardConfirm.length) { - composer.discardConfirm.modal('hide'); - delete composer.discardConfirm; - } - return; - } - - translator.translate('[[modules:composer.discard]]', function (translated) { - composer.discardConfirm = bootbox.confirm(translated, function (confirm) { - if (confirm) { - composer.discard(composer.active); - } else { - composer.posts[composer.active].modified = true; - } - }); - composer.posts[composer.active].modified = false; - }); - } - }); - - function removeComposerHistory() { - var env = composer.bsEnvironment; - if (ajaxify.data.template.compose === true || env === 'xs' || env === 'sm') { - history.back(); - } - } - - function onWindowResize() { - var env = utils.findBootstrapEnvironment(); - var isMobile = env === 'xs' || env === 'sm'; - - if (preview.toggle) { - if (preview.env !== env && isMobile) { - preview.env = env; - preview.toggle(false); - } - preview.env = env; - } - - if (composer.active !== undefined) { - resize.reposition($('.composer[data-uuid="' + composer.active + '"]')); - - if (!isMobile && window.location.pathname.startsWith(config.relative_path + '/compose')) { - /* - * If this conditional is met, we're no longer in mobile/tablet - * resolution but we've somehow managed to have a mobile - * composer load, so let's go back to the topic - */ - history.back(); - } else if (isMobile && !window.location.pathname.startsWith(config.relative_path + '/compose')) { - /* - * In this case, we're in mobile/tablet resolution but the composer - * that loaded was a regular composer, so let's fix the address bar - */ - mobileHistoryAppend(); - } - } - composer.bsEnvironment = env; - } - - function alreadyOpen(post) { - // If a composer for the same cid/tid/pid is already open, return the uuid, else return bool false - var type; - var id; - - if (post.hasOwnProperty('cid')) { - type = 'cid'; - } else if (post.hasOwnProperty('tid')) { - type = 'tid'; - } else if (post.hasOwnProperty('pid')) { - type = 'pid'; - } - - id = post[type]; - - // Find a match - for (var uuid in composer.posts) { - if (composer.posts[uuid].hasOwnProperty(type) && id === composer.posts[uuid][type]) { - return uuid; - } - } - - // No matches... - return false; - } - - function push(post) { - if (!post) { - return; - } - - var uuid = utils.generateUUID(); - var existingUUID = alreadyOpen(post); - - if (existingUUID) { - taskbar.updateActive(existingUUID); - return composer.load(existingUUID); - } - - var actionText = '[[topic:composer.new-topic]]'; - if (post.action === 'posts.reply') { - actionText = '[[topic:composer.replying-to]]'; - } else if (post.action === 'posts.edit') { - actionText = '[[topic:composer.editing-in]]'; - } - - translator.translate(actionText, function (translatedAction) { - taskbar.push('composer', uuid, { - title: translatedAction.replace('%1', '"' + post.title + '"'), - }); - }); - - composer.posts[uuid] = post; - composer.load(uuid); - } - - async function composerAlert(post_uuid, message) { - $('.composer[data-uuid="' + post_uuid + '"]').find('.composer-submit').removeAttr('disabled'); - - const { showAlert } = await hooks.fire('filter:composer.error', { post_uuid, message, showAlert: true }); - - if (showAlert) { - alerts.alert({ - type: 'danger', - timeout: 10000, - title: '', - message: message, - alert_id: 'post_error', - }); - } - } - - composer.findByTid = function (tid) { - // Iterates through the initialised composers and returns the uuid of the matching composer - for (var uuid in composer.posts) { - if (composer.posts.hasOwnProperty(uuid) && composer.posts[uuid].hasOwnProperty('tid') && parseInt(composer.posts[uuid].tid, 10) === parseInt(tid, 10)) { - return uuid; - } - } - - return null; - }; - - composer.addButton = function (iconClass, onClick, title) { - formatting.addButton(iconClass, onClick, title); - }; - - composer.newTopic = async (data) => { - let pushData = { - save_id: data.save_id, - action: 'topics.post', - cid: data.cid, - handle: data.handle, - title: data.title || '', - body: data.body || '', - tags: data.tags || [], - modified: !!((data.title && data.title.length) || (data.body && data.body.length)), - isMain: true, - isAnonymous: isAnonymous, - }; - - ({ pushData } = await hooks.fire('filter:composer.topic.push', { - data: data, - pushData: pushData, - })); - - push(pushData); - }; - - composer.addQuote = function (data) { - // tid, toPid, selectedPid, title, username, text, uuid - data.uuid = data.uuid || composer.active; - - var escapedTitle = (data.title || '') - .replace(/([\\`*_{}[\]()#+\-.!])/g, '\\$1') - .replace(/\[/g, '[') - .replace(/\]/g, ']') - .replace(/%/g, '%') - .replace(/,/g, ','); - - if (data.body) { - data.body = '> ' + data.body.replace(/\n/g, '\n> ') + '\n\n'; - } - var link = '[' + escapedTitle + '](' + config.relative_path + '/post/' + encodeURIComponent(data.selectedPid || data.toPid) + ')'; - if (data.uuid === undefined) { - if (data.title && (data.selectedPid || data.toPid)) { - composer.newReply({ - tid: data.tid, - toPid: data.toPid, - title: data.title, - body: '[[modules:composer.user-said-in, ' + data.username + ', ' + link + ']]\n' + data.body, - }); - } else { - composer.newReply({ - tid: data.tid, - toPid: data.toPid, - title: data.title, - body: '[[modules:composer.user-said, ' + data.username + ']]\n' + data.body, - }); - } - return; - } else if (data.uuid !== composer.active) { - // If the composer is not currently active, activate it - composer.load(data.uuid); - } - - var postContainer = $('.composer[data-uuid="' + data.uuid + '"]'); - var bodyEl = postContainer.find('textarea'); - var prevText = bodyEl.val(); - if (data.title && (data.selectedPid || data.toPid)) { - translator.translate('[[modules:composer.user-said-in, ' + data.username + ', ' + link + ']]\n', config.defaultLang, onTranslated); - } else { - translator.translate('[[modules:composer.user-said, ' + data.username + ']]\n', config.defaultLang, onTranslated); - } - - function onTranslated(translated) { - composer.posts[data.uuid].body = (prevText.length ? prevText + '\n\n' : '') + translated + data.body; - bodyEl.val(composer.posts[data.uuid].body); - focusElements(postContainer); - preview.render(postContainer); - } - }; - - composer.newReply = function (data) { - translator.translate(data.body, config.defaultLang, function (translated) { - push({ - save_id: data.save_id, - action: 'posts.reply', - tid: data.tid, - toPid: data.toPid, - title: data.title, - body: translated, - modified: !!(translated && translated.length), - isMain: false, - }); - }); - }; - - composer.editPost = function (data) { - // pid, text - socket.emit('plugins.composer.push', data.pid, function (err, postData) { - if (err) { - return alerts.error(err); - } - postData.save_id = data.save_id; - postData.action = 'posts.edit'; - postData.pid = data.pid; - postData.modified = false; - if (data.body) { - postData.body = data.body; - postData.modified = true; - } - if (data.title) { - postData.title = data.title; - postData.modified = true; - } - postData.isAnonymous = isAnonymous; - push(postData); - }); - }; - - composer.load = function (post_uuid) { - var postContainer = $('.composer[data-uuid="' + post_uuid + '"]'); - if (postContainer.length) { - activate(post_uuid); - resize.reposition(postContainer); - focusElements(postContainer); - onShow(); - } else if (composer.formatting) { - createNewComposer(post_uuid); - } else { - socket.emit('plugins.composer.getFormattingOptions', function (err, options) { - if (err) { - return alerts.error(err); - } - composer.formatting = options; - createNewComposer(post_uuid); - }); - } - }; - - composer.enhance = function (postContainer, post_uuid, postData) { - /* - This method enhances a composer container with client-side sugar (preview, etc) - Everything in here also applies to the /compose route - */ - - if (!post_uuid && !postData) { - post_uuid = utils.generateUUID(); - composer.posts[post_uuid] = ajaxify.data; - postData = ajaxify.data; - postContainer.attr('data-uuid', post_uuid); - } - - categoryList.init(postContainer, composer.posts[post_uuid]); - scheduler.init(postContainer, composer.posts); - - formatting.addHandler(postContainer); - formatting.addComposerButtons(); - preview.handleToggler(postContainer); - postQueue.showAlert(postContainer, postData); - uploads.initialize(post_uuid); - tags.init(postContainer, composer.posts[post_uuid]); - autocomplete.init(postContainer, post_uuid); - - postContainer.on('change', 'input, textarea', function () { - composer.posts[post_uuid].modified = true; - }); - - postContainer.on('click', '.composer-submit', function (e) { - e.preventDefault(); - e.stopPropagation(); // Other click events bring composer back to active state which is undesired on submit - - $(this).attr('disabled', true); - post(post_uuid); - }); - - require(['mousetrap'], function (mousetrap) { - mousetrap(postContainer.get(0)).bind('mod+enter', function () { - postContainer.find('.composer-submit').attr('disabled', true); - post(post_uuid); - }); - }); - - postContainer.find('.composer-discard').on('click', function (e) { - e.preventDefault(); - - if (!composer.posts[post_uuid].modified) { - composer.discard(post_uuid); - return removeComposerHistory(); - } - - formatting.exitFullscreen(); - - var btn = $(this).prop('disabled', true); - translator.translate('[[modules:composer.discard]]', function (translated) { - bootbox.confirm(translated, function (confirm) { - if (confirm) { - composer.discard(post_uuid); - removeComposerHistory(); - } - btn.prop('disabled', false); - }); - }); - }); - - postContainer.find('.composer-minimize, .minimize .trigger').on('click', function (e) { - e.preventDefault(); - e.stopPropagation(); - composer.minimize(post_uuid); - }); - - const textareaEl = postContainer.find('textarea'); - textareaEl.on('input propertychange', utils.debounce(function () { - preview.render(postContainer); - }, 250)); - - textareaEl.on('scroll', function () { - preview.matchScroll(postContainer); - }); - - drafts.init(postContainer, postData); - const draft = drafts.get(postData.save_id); - - preview.render(postContainer, function () { - preview.matchScroll(postContainer); - }); - - handleHelp(postContainer); - handleSearch(postContainer); - focusElements(postContainer); - if (postData.action === 'posts.edit') { - composer.updateThumbCount(post_uuid, postContainer); - } - - // Hide "zen mode" if fullscreen API is not enabled/available (ahem, iOS...) - if (!screenfull.isEnabled) { - $('[data-format="zen"]').parent().addClass('hidden'); - } - - hooks.fire('action:composer.enhanced', { postContainer, postData, draft }); - }; - - async function getSelectedCategory(postData) { - if (ajaxify.data.template.category && parseInt(postData.cid, 10) === parseInt(ajaxify.data.cid, 10)) { - // no need to load data if we are already on the category page - return ajaxify.data; - } else if (parseInt(postData.cid, 10)) { - return await api.get(`/api/category/${postData.cid}`, {}); - } - return null; - } - - async function createNewComposer(post_uuid) { - var postData = composer.posts[post_uuid]; - - var isTopic = postData ? postData.hasOwnProperty('cid') : false; - var isMain = postData ? !!postData.isMain : false; - var isEditing = postData ? !!postData.pid : false; - var isGuestPost = postData ? parseInt(postData.uid, 10) === 0 : false; - const isScheduled = postData.timestamp > Date.now(); - - // see - // https://github.com/NodeBB/NodeBB/issues/2994 and - // https://github.com/NodeBB/NodeBB/issues/1951 - // remove when 1951 is resolved - - var title = postData.title.replace(/%/g, '%').replace(/,/g, ','); - postData.category = await getSelectedCategory(postData); - const privileges = postData.category ? postData.category.privileges : ajaxify.data.privileges; - var data = { - topicTitle: title, - titleLength: title.length, - body: translator.escape(utils.escapeHTML(postData.body)), - mobile: composer.bsEnvironment === 'xs' || composer.bsEnvironment === 'sm', - resizable: true, - thumb: postData.thumb, - isTopicOrMain: isTopic || isMain, - maximumTitleLength: config.maximumTitleLength, - maximumPostLength: config.maximumPostLength, - minimumTagLength: config.minimumTagLength, - maximumTagLength: config.maximumTagLength, - 'composer:showHelpTab': config['composer:showHelpTab'], - isTopic: isTopic, - isEditing: isEditing, - canSchedule: !!(isMain && privileges && - ((privileges['topics:schedule'] && !isEditing) || (isScheduled && privileges.view_scheduled))), - showHandleInput: config.allowGuestHandles && - (app.user.uid === 0 || (isEditing && isGuestPost && app.user.isAdmin)), - handle: postData ? postData.handle || '' : undefined, - formatting: composer.formatting, - tagWhitelist: postData.category ? postData.category.tagWhitelist : ajaxify.data.tagWhitelist, - privileges: app.user.privileges, - selectedCategory: postData.category, - submitOptions: [ - // Add items using `filter:composer.create`, or just add them to the