Skip to content
This repository has been archived by the owner on Aug 6, 2022. It is now read-only.

II.6.g. Boards

Andrey Bogdanov edited this page Apr 7, 2016 · 8 revisions

Place your custom board files into the boards directory. One file may export one or several boards.

Simple examples

Example 1 (mu.js):

var Board = require("./board");

module.exports = new Board("mu", "Music");

Example 2 (mu.js):

var Board = require("./board");
var Tools = require("../helpers/tools");

module.exports = new Board("mov", Tools.translate("Movies"));

In the second example the board's title will be translatable. See: II.6.c. Translations.

Example 3: (multiple.js):

var Board = require("./board");

module.exports = [
    new Board("mu", "Music"),
    new Board("mov", "Movies"),
    new Board("tv", "TV series")
];

All three files will be automatically loaded by ololord.js.

Note: You may also add Board settings with the Board.defineSetting(name, defaultValue) method.

Board API

Board(id, title[, options])

Constructor.

  • id The string captcha engine identifier.
  • title Human-readable title. Either a string, or a result of Tools.translate.noop (translation object).
  • options Additional options:
  • defaultUserName The default user name used if not specified on post creation.
  • groupName The board group this board belongs to.
  • priority The priority of this board (uses to order boards in the navigation bar).

Example:

var board = new Board("echo", Tools.translate.noop("Boardsphere echo", "boardTitle"));

Board.customBoardInfoFields()

Must return a list of custom board information fields, which will be sent to clients through the III. REST API.

Example:

board.customBoardInfoFields = function() {
    return ["maxLinkLength"];
};

Board.isCaptchaEngineSupported(engineName)

This method is called when checking a captcha. engineName is normally a string captcha engine identifier.

Note: It is better to use configuration file to set captcha engines supported by the boards.

Board.isFileTypeSupported(fileType)

This method is called when checking if a file with with the MIME-type fileType may be attached to a post on the board.

Note: It is better to use configuration file to set file types supported by the boards.

Board.postExtraData(req, fields, files[, oldPost])

This method is called when a new post is added, or when an existing post is edited. It is used to get extra data from custom fields.

  • req The Express reuqest object.
  • fields Post form fields (Object).
  • files Post form files (Object). Specified when creating a new post only.
  • oldPost An object representing a post. Specified when editing an existing post only.

Example:

board.postExtraData = function(req, fields) {
    if (fields.thread)
        return Promise.resolve(null);
    var link = fields.link;
    var result = testLink(link);
    if (result)
        return Promise.reject(result);
    if (link.substr(0, 4) != "http")
        link = "http://" + link;
    return Promise.resolve(link);
};

Board.storeExtraData(postNumber, extraData)

Used to store post extra data in the database. May be overwritten to store complex data.

Board.loadExtraData(postNumber)

Used to load post extra data from the database. May be overwritten in conjunction with stroeExtraData to load complex data.

Board.removeExtraData(postNumber)

Used to remove post extra data from the database. May be overwritten in conjunction with stroeExtraData to remove complex data.

Board.apiRoutes()

Must return a list of objects representing Express routes. Each object must have the following fields:

  • method HTTP method (GET, POST, etc.). Normally GET.
  • path Route path relative to /api path.
  • handler Handler function (the req and res arguments will be passed to it).

Board.actionRoutes()

Must return a list of objects representing Express routes. Each object must have the following fields:

  • method HTTP method (GET, POST, etc.). Normally POST.
  • path Route path relative to /action path.
  • handler Handler function (the req and res arguments will be passed to it).

Board.extraScripts()

A list of extra scripts (JavaScript), that will be inserted into the page. The scripts may be specified using one of the following format:

  • { source: theSource } The src attribute of a script tag will be set to theSource exactly.
  • { fileName: theFileName } The src attribute of a script tag will be set to theFileName prefixed by the site path prefix (see I.4. Basic configuration) and the "js/" suffix.
  • { value: theValue } The value will be used as a raw script tag content.

An optional parameter noEmbed may be specified to prevent embedding the script into the page.

Board.extraStylesheets()

A list of extra stylesheets (CSS), that will be inserted into the page. The stylesheets may be specified using one of the following format:

  • { source: theSource } The href attribute of a link tag will be set to theSource exactly.
  • { fileName: theFileName } The href attribute of a link tag will be set to theFileName prefixed by the site path prefix (see I.4. Basic configuration) and the "js/" suffix.

An optional parameter noEmbed may be specified to prevent embedding the stylesheet into the page.

Board.testParameters(req, fields, files[, creatingThread])

Used to test post form values and files when creating a thread or a post.

Must return a resolving Promise if the parameters are OK, and a rejecting Promise with an error message (non-empty string) as a value otherwise.

  • req The Express reuqest object.
  • fields Post form fields (Object).
  • files Post form files (Object).

Note: This function is used to test custom parameters only. Common fields, such as post text or subject, as long as the files, are tested separately.

Board.addTranslations(translate)

May be used to add custom translations to the model.

translate is a function accepting two obligatory parameters: the translation source text and the disambiguation. The latter will be used as a translation identifier in the template. See: II.6.c. Postform rules and translations.

Board.customPostHeaderPart()

A method that is used to render custom post header data.

May return an Object with the fields named from 0 to 160 (step 10), and function values. Each function is called from within the template engine and is passed the following arguments:

  • it Model root.
  • thread Current thread model.
  • post Current post model.

Normally, controller.sync method is used to render the post header part.

Example:

board.customPostHeaderPart = function() {
    return {
        100: function(it, thread, post) {
            var model = merge.recursive(it, post.extraData || {
                likeCount: 0,
                dislikeCount: 0
            });
            model.thread = thread;
            model.post = post;
            return controller.sync("socPostHeaderPart", model);
        }
    };
};

Board.customPostBodyPart()

A method that is used to render custom post body data.

May return an Object with the fields named from 0 to 50 (step 10), and function values. Each function is called from within the template engine and is passed the following arguments:

  • it Model root.
  • thread Current thread model.
  • post Current post model.

Normally, controller.sync method is used to render the post header part.

Example:

board.customPostBodyPart = function() {
    return {
        20: function(it, thread, post) {
            if (!post.extraData)
                return "";
            var model = merge.recursive(it, post.extraData);
            model.thread = thread;
            model.post = post;
            return controller.sync("rpgPostBodyPart", model);
        }
    };
};

Note: Take a look at the boards/board.js file and other files in the boards directory for better understanding of how to create custom boards.

Clone this wiki locally