[nodebb-plugin-blog-comments] Blog Commenting Engine (Ghost, Wordpress widget)

  • Plugin & Theme Dev

    I did a integration between forum.mysensors.org and my new open hardware sharing site https://www.openhardware.io using parts of the blog-comments plugin to allow commenting on each project.

    From the forum side: http://forum.mysensors.org/category/30/openhardware-io
    And from openhardware: https://www.openhardware.io/view/4/EasyNewbie-PCB-for-MySensors#tab-comments

    But as we have to keep title/tags in forum in-sync with the open-hardware-site I had to create a new endpoint which besides creating, also updates the post each time someone published changes. The publishing/update request is sent from our backend.

    Here is the interesting part of the code:

    Comments.publishProject = function(req, res, callback) {
    		var markdown = req.body.markdown,
    			title = req.body.title,
    			url = req.body.url,
    			commentID = req.body.id,
    			tags = req.body.tags,
    			uid = xxx;
    
                   if (req.body.token !== "XXXXXXXXXXXXXX") 
                          return res.json({error: "Unknown token"});
    		Comments.getTopicIDByCommentID(commentID, function(err, tid) {	
    
    			if (err || !tid) {
    				var hostUrls = (meta.config['blog-comments:url'] || '').split(','),
    					position = 0;
    
    				hostUrls.forEach(function(hostUrl, i) {
    					hostUrl = hostUrl.trim();
    					if (hostUrl[hostUrl.length - 1] === '/') {
    						hostUrl = hostUrl.substring(0, hostUrl.length - 1);
    					}
    
    					if (hostUrl === req.get('origin')) {
    						position = i;
    					}
    				});
    
    				var cid = meta.config['blog-comments:cid'].toString() || '';
    				cid = parseInt(cid.split(',')[position], 10) || parseInt(cid.split(',')[0], 10) || 1;
    				
    
    				topics.post({
    					uid: uid,
    					title: title,
    					content: markdown,
    					tags: tags,
    					req: req,
    					cid: cid
    				}, function(err, result) {
    					//console.log(err);
    					//console.log(err.stack);
    					if (!err && result && result.postData && result.postData.tid) {
    						posts.setPostField(result.postData.pid, 'blog-comments:url', url, function(err) {
    							if (err) {
    								return res.json({error: "Unable to post topic", result: result});		
    							}
    							
    							db.setObjectField('blog-comments', commentID, result.postData.tid);
    							res.redirect((req.header('Referer') || '/') + '#tabs-comments');
    						});
    					} else {
    						res.json({error: "Unable to post topic", result: result});
    					}
    				});
    			} else {
    				topics.getMainPost(tid, uid, function(err, post) {
    					if (err)
    						return res.json({ok:false});
    
    					var payload = {
    						title: title,
    						uid: uid,
    						pid: post.pid,
    						content: markdown,
    						tags: tags,
    						options: { tags: tags }
    					};
    					posts.edit(payload, function(err, returnData) {
    						if (err)
    							return res.json({ok:false});
    						//errorHandler.handle(err, res, returnData);
    						res.json({ok:true});
    					});
    
    				});
    
    			}
    		});
    
    	};
    

  • Just wanted to point out that there are compatibility issues with the ns-plugin-ns-points plugin. The following error is thrown when accessing any of the posts on Ghost

    error: TypeError: Cannot read property 'uid' of undefined
    at nodebbpath/node_modules/nodebb-plugin-ns-points/app/filters.js:68:36
    

    It worked once I disabled the points plugin.


  • @overlawled said:

    Just a heads up for anyone else using this with Wordpress. After the latest update the categoryID variable in comments.php of your theme isn't optional. If it isn't defined publishing doesn't work.

    @overlawled @Hưng-Thành-Nguyễn Could you try to set var categoryID = 0; or var categoryID = null;? Any falsy value should work.


  • I have tried to use the plugin on multiple ghost platforms and it only works with the first blog entry. Anything special needs to be done?


  • Is anyone still using this plugin successfully on WordPress? Just having issues on my end, configured everything as noted in the readme, but am not even getting the "Publish Post to NodeBB" button to show in WordPress. @psychobunny @julian


  • Made a little progress by deactivating the recommended WordPress JSON API plugin and installing/activating Jetpack's JSON plugin. Also uninstalled then reinstalled the NodeBB Blog Comments plugin.

    Now I'm seeing the "Publish Article to NodeBB" button, but when I hit it, I get the following error:

    Internal error.
    
    Oops! Looks like something went wrong!
    
    /comments/publish
    
    Unexpected end of input
    

    Any thoughts on where I should be looking for the missing } or whatever it could be?


  • I've checked the syntax in several of the files, such as library.js, wordpress.js, and everything looks fine there. Still not sure where this error is originating. @psychobunny


  • @julian @psychobunny If anyone could even point me in the direction of any freelance NodeBB devs who would have experience with this plugin, I'd really appreciate it. Trying to get this working by this evening to meet a deadline. Thanks!


  • @psychobunny Has no one else experienced this error?

    '''
    Internal error.

    Oops! Looks like something went wrong!

    /comments/publish

    Unexpected end of input
    '''

  • Admin

    What version of Wordpress, JSON API and Jetpack did you try using? I'll install them and see if I can figure out what's going on


  • @psychobunny Thank you so much for the response.

    WordPress: v4.4.1
    JSON API by Dan Phiffer: v1.1.1
    Jetpack (JSON API) : v3.9.1

    Also, didn't know if the path in the following line could be a possible issue for my install, as the wordpress.js file in my setup is actually located in /node_modules/nodebb-plugin-blog-comments/public/lib/wordpress.js (I tried switching this out just in case, but no luck. just thought I'd mention it).

    nbb.src = nodeBBURL + '/plugins/nodebb-plugin-blog-comments/lib/wordpress.js';
    

    Once again, truly appreciate your help on this.

  • Admin

    The latter is fine. I've never tried Jetpack before, and I imagine it's not immediately compatible if the variable names it returns in the API are slightly different from what we're expecting

    I'll try to see what's up with the JSON API first. If we can get the button to show up I don't think you'll encounter the second problem you mentioned


  • @psychobunny thank you very much.


  • @psychobunny if it would be helpful for me to share my ACP plugin settings as well as my comments.php config, just in case I'm missing something simple like syntax, let me know.

  • Admin

    Sure yes please. I haven't looked into it yet but I'll have a look tomorrow or later tonight


  • @psychobunny

    <?php
    if ( post_password_required() )
        return;
    ?>
    <span id="nodebb-comments-count"></span> Comments
    <a id="nodebb/comments"></a>
    <script type="text/javascript">
    var nodeBBURL = '//community.domain.com',
        articleID = '<?php echo the_ID(); ?>',
        categoryID = 5; // OPTIONAL. Forces a Category ID in NodeBB.
                         //  Omit it to fallback to specified IDs in the admin panel.
    
    (function() {
    var nbb = document.createElement('script'); nbb.type = 'text/javascript'; nbb.async = true;
    nbb.src = nodeBBURL + '/plugins/nodebb-plugin-blog-comments/lib/wordpress.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(nbb);
    })();
    </script>
    <noscript>Please enable JavaScript to view comments</noscript>
    

    Thank you so much again for your help. It's much appreciated.

  • Admin

    Your problem with the original JSON API was that the publish button didn't show up right?

    Could you reactivate that and then move the code above this line

    <?php
    if ( post_password_required() )
        return;
    ?>
    

    See this I'm willing to bet its false, and so the code below would never show up


  • @psychobunny I actually reactivated the original JSON API (and deactivated Jetpack's) prior to your last post, and the publish button was still showing. Don't know what I had done to screw it up the first time, but even without moving the code, it does show. (Still outputs the error, though).

    Moved all of the contents in comments.php above the code you mentioned, and still getting the same "Unexpected end of input" error. 😕


  • @psychobunny may be another silly thing to ask, but thought I'd give every piece of information I can, however irrelevant it may seem, just in case.

    I'm logged in as admin on both Wordpress and NodeBB, both accounts have the same name, etc. Didn't know if there were any stringent requirements with respect to these accounts needing to be identical in some way in order for the publishing to be authorized by NodeBB.


  • @psychobunny trying to think of any additional info I could provide regarding my setup or the error itself. Please let me know if I have yet to elaborate on some piece of info that could help in pinpointing the error.

Suggested Topics

  • 17
  • 2
  • 7
  • 3
  • 9
| |