Skip to content
  • 2 Votes
    3 Posts
    771 Views
    dogsD

    @gotwf I'm not sure it's been weeks ago I wrote this. 😄

    Maybe I did not find this or something didn't work for me. I can't tell you...

    Greets

  • 0 Votes
    1 Posts
    584 Views
    dogsD
    This is just a little snippet.

    This is about the question How can I add custom data to a post? a small tutorial

    How to add custom data permanently to a post It will be saved into the object:

    You need the following hook:

    { "hook": "filter:post.create", "method": "postCreate" }

    This hook is fired, when a Post is created. So it contains RAW Data.

    A filter:hook like "hook": "filter:post.create" can be edited before beeing proceeded.

    plugin.postCreate = function(data, callback){ // Edit data here callback(null, data); }

    You can access all Data you can work with via the data object.

    All those filter-hooks needs callbacks. The callback contains the modified / added / removed data.

    Whats inside the data object?

    The data object contains two main objects.

    this.post this.data post: { pid: 259, uid: 2, tid: 111, content: '### This is just a little snippet.', timestamp: 1617150411838 }, data: { uuid: '7277s31-6d23-43sa-1284-ad27e42yx879', title: 'How to add custom data to post serverside - in a nutshell', content: '### This is just a little snippet.', thumb: '', cid: '2', tags: [], uid: 2, req: { [...] }, timestamp: 1617150411838, fromQueue: false, tid: 111, ip: '111.123.2123.21', isMain: true } }

    With all the data you can work with. But only this.post is directly effected (lol) to the post Object.
    If you add data here. It will be attached to the post forever and you can access it any time. Even after plugin disable.

    So now add custom data:

    plugin.postCreate = function(data, callback){ // adds data **PERMANENT** to post // before any other procession -> RAW DATA (markdown) //data.post.myData = "directly effected to post you can work with it in next step"; //data.data.myData = "other data for other things I don't know"; var myData = {}; myData.name = "Schmock"; myData.signature = "raz0rn"; // Stick myData to post object data.post.myData = myData; // Debug? // console.log("POST CREATE", data); // finish the process() - passes on modified data callback(null, data); }

    So myData has added to post:

    post: { pid: 259, uid: 2, tid: 111, content: '### This is just a little snippet.', timestamp: 1617150411838, myData: { name = "Schmock", signature = "raz0rn", } }

    The data is stored. Everybody is happy.

    dance minions

    How to add dynamic data before render a post in template It wont be saved to the object. You can use this for dynamic things or logic before rendering the page.:

    You need the following hook:

    { "hook": "filter:topics.addPostData", "method": "addPostData" }

    This hook is fired before engine renders the template.
    It also needs a callback because its a filter-hook.

    plugin.addPostData = function(data, callback){ // modify data temporarily before it gets passed on to next step callback(null, data); }

    Same thing as above. Only the hook is different. And the data we are changing is temporarily.
    Data contains all data we can use for the dynamicness lol: .

    plugin.addPostData = function(data, callback){ // You can work with pre-parsed and already saved data .... // or put in something very flexible without saving to db like jquery-like dynamic etc etc // Debug? // console.log("addPostData?", data) var _posts = data.posts; _posts.forEach(function(post){ if(post.myData){ // add data to post if "myData" is there post.content = "THIS POST HAS MY OWN DATA -> CONTENT IS OVERWRITTEN"; } // this here affects all posts post.user.signature = "Ihr seid alle Schmocks!"; }); // Overwrite data and pass modified data on to the template engine data.posts = _posts; callback(null, data); }

    Now you can work with posts like a boss.

    Bildschirmfoto 2021-03-31 um 03.10.32.png

    dab

    Thanks and bye

    Important Note:

    Remind, that myData is available via API.

    https://nodebb.development.fail/api/topic/114/new-post

    returns your added data

    "content": "THIS POST AS MY OWN DATA -> CONTENT IS OVERWRITTEN", "myData": { "name": "Schmock", "signature": "raz0rn" }
  • 0 Votes
    5 Posts
    938 Views
    dogsD

    @pitaj Nice that was easy! Thank you 🙂

  • 0 Votes
    18 Posts
    2k Views
    barisB

    Yes you can use them inside the AMD module but keep in mind once you add an event listener on the window object it will be called everytime there is an action:ajaxify.end. If you don't want it triggered after you leave that page you need to turn it off with $(window).off('eventName', myMethod)

  • 0 Votes
    11 Posts
    1k Views
    Keng HerK

    @dogs
    Not sure if this is still relevant to you, but I followed your code and was getting the same results. The code wasn't firing despite having a console log in the theme.js file.

    Then I decided to click on the 'Clone widgets from...' and selected 'Categories'. After that all of the .tpl names showed up in the drop down. After that any changes to the theme.js file are firing as should.

    Make sure you build and restart. I am using the included GRUNT to make development faster. Cheers!

  • 2 Votes
    3 Posts
    780 Views
    dogsD

    @aleksei I read your topic: https://community.nodebb.org/topic/15252/execute-custom-js-on-infinite-scroll and saw you're dealing with C4D-Files. 😄

  • 1 Votes
    3 Posts
    687 Views
    dogsD

    @pitaj Thank you so much! That worked. 👍

  • 6 Votes
    3 Posts
    947 Views
    manolinoM

    @kadmy , sure: upload the file controls.png from the plugin folder \node_modules\bxslider\dist into NodeBB assets. The file looks like the bitmap below.

    controls.png
    Then change the LESS to

    .my-wrapper { box-shadow: none; border: none; .bx-prev { background: url(/assets/uploads/controls.png) no-repeat 0px -32px; } .bx-next { background: url(/assets/uploads/controls.png) no-repeat -43px -32px; } }

    This file contains the standard bxSlider. But you can use any other icon. Just upload it or point to the url of your preference.

    Please update to v0.1.2 for more fixes.

  • 0 Votes
    2 Posts
    510 Views
    barisB

    https://github.com/NodeBB/NodeBB/issues/9204

  • 0 Votes
    5 Posts
    903 Views
    dogsD

    @baris Thank you very much. This worked! 🙂

    €: I additionally use the hook

    $(window).on('action:ajaxify.start', function (ev, data) { $('div.topic-header-image').hide(); });

    so that the header container with the image is hiding immediatly and before ajaxify.end 👍

  • 0 Votes
    7 Posts
    1k Views
    dogsD

    @pitaj Many thanks for your effort 🙏

    Okay so I just npm link'ed my plugin again so I thought some file will be updated. But they weren't.

    Here is my full source code of libary.js:

    'use strict'; /* NodeBB Basic Plugin Libraries */ const controllers = require('./lib/controllers'); const plugin = {}; /* Third Party Libraries */ const Discord = require("discord.js"); const fs = require("fs"); // Nodebb Discord Bot const config = JSON.parse(fs.readFileSync("./utils/config.json", "utf-8")); var client = new Discord.Client(); let debug = true; plugin.init = function (params, callback, client) { myDebug("nodebb-discord-bot-started"); callback(); }; function myDebug(msg){ if(debug){ console.log(msg); } } module.exports = plugin; 2021-01-12T10:46:19.318Z [4567/4689] - error: Error: ENOENT: no such file or directory, open './utils/config.json' at Object.openSync (fs.js:462:3) at Object.readFileSync (fs.js:364:35) at Object.<anonymous> (/home/ubuntu/nodebb-linked-modules/nodebb-plugin-makesmart-discord-bot/library.js:15:30) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.Plugins.requireLibrary (/home/ubuntu/nodebb/src/plugins/index.js:70:39)

    I tried it with path again:

    // Nodebb Discord Bot var configpath = path.join(__dirname, 'utils', 'config.json'); const config = JSON.parse(fs.readFileSync(configpath, "utf-8")); var client = new Discord.Client();

    an suddenly ... it worked! o.O

    2021-01-12T10:51:15.711Z [4567/4765] - info: [api] Adding 2 route(s) to `api/v3/plugins` 2021-01-12T10:51:15.889Z [4567/4765] - info: Routes added 2021-01-12T10:51:15.933Z [4567/4765] - info: NodeBB Ready 2021-01-12T10:51:15.943Z [4567/4765] - info: Enabling 'trust proxy' 2021-01-12T10:51:15.972Z [4567/4765] - info: NodeBB is now listening on: 0.0.0.0:4567

    I think it was really because I ran npm link again. Funny.* I'm sorry. Most of the time, the problem is in front of the computer. 🙄

    But still a strange behavior in my opinion. Well ... Good to know for the future. @PitaJ as mentioned thank you for you effort. 🙏

    For any others having the same issue:

    Read the Stackoverflow Solution posted by @PitaJ right here If it still not work use npm link in ./nodebb again to refresh something in the plugin folder ...I dont know tbh ... 😄
  • 0 Votes
    1 Posts
    403 Views
    dogsD

    Hey!

    Is it possible to post as Guest via the write API?

    I tried to reply to a topic via:

    const bodyParameters = { _uid: 0, content: "It works!" };

    But it does not work. Is it possible to post as a Guest and set a username with the request or is it only possible to use the write api with a existing uid?

    Looking forward to your answers.

  • 0 Votes
    4 Posts
    869 Views
    dogsD

    I still have a question. Everything works fine at the moment. Send data from the client to the server isn't a problem now.

    But how can I emit a event to all connected clients serverside?

    Something e.g

    myPlugin.emit('plugins.publishMessage', {data: "Some data"}, function(err, result) { console.log(result); });

    After one hour spending searching different topics and some code I found the solution.

    Besides the custom clientside Sockets

    const myPluginSockets = require.main.require('./src/socket.io/plugins');

    you have to define the Server Sockets too

    const myPluginSockets = require.main.require('./src/socket.io/plugins'); const serverSockets = require.main.require('./src/socket.io');

    Now you can emit events from server side to the clients:

    serverSockets.server.sockets.emit('messageReceive', data);

    to receive the event clientside, you can use following in ur main.js file:

    socket.on('messageReceive', function(data){ console.log(data); });

    Client console output:
    {msg: "my message"}

    Maybe I'll write a little Tutorial on this because I am probably not the only one who does not understand it so easily.

  • 0 Votes
    3 Posts
    725 Views
    dogsD

    @PitaJ I want to display it on a existing page e.g on users profile page.

    What do I have to to, to add it to an existing route? E.g /user/pasib

    Could you give me some links, or a little example how I cant add a simple backend variable to the frontend. 🙂

    Thank you

  • 0 Votes
    2 Posts
    489 Views
    julianJ

    @pasib when you concatenated the object, it got stringified.

    Try console.log('test', postData); 🙂

  • 1 Votes
    11 Posts
    2k Views
    S

    @PitaJ said in Any tips for installing NodeBB on AWS Lightsail?:

    As long as Lightsail doesn't limit the capabilities of their VPS, I don't see why it would be any different from a normal install on Ubuntu.

    yeah, it's identical. LightSail ends up being exactly like a DO or Vultr.

  • 0 Votes
    5 Posts
    2k Views
    F

    Problem solved, for the record I have added all file on my GitHub: https://github.com/LM1LC3N7/Dockerfiles/blob/master/nodebb/README.md

  • 0 Votes
    4 Posts
    926 Views
    dogsD

    @Witzker

    Webserver in this case means
    PHP / MYSQL / Apache 2

    You would need node.js based Web-Environment

  • 0 Votes
    5 Posts
    654 Views
    PitaJP

    https://docs.nodebb.org/installing/os/ for installation instructions.

  • 12 Votes
    9 Posts
    1k Views
    dogsD

    Nice 👌🏼