Discourse Working as Comment Engine Replacement for Drupal

(Craig Oda) #1

@tobiaseigen very cool organization that you’re working with at Kabissa. Great that you’re making progress with the use of Discourse as the comment engine for Drupal blogs. Would love to see you get that PHP module up and running. The OpenAid project looks awesome.

Continuing the discussion from Any experience with Drupal to Discourse integration?:

Issue with blog integration comments on Octopress homepage
Move blog embed settings to category settings and allow embedding multiple discourse in multiple other sites?
Import all entries from RSS in feed poll for embedded blog
Any experience with Drupal to Discourse integration?
(Tobias Eigen) #2

Thanks @codetricity :smile:

Here’s the code I used that works to embed discourse topic into a drupal post, which is a small tweak to @eviltrout’s Embedding Discourse in Static Sites recipe. This can be used in a block or (as it is now in this example) in the body of a post with php enabled. I’m not doing it sitewide yet but I don’t see why it shouldn’t work just fine.

<div id="discourse-comments"></div>

<script type="text/javascript">
  var discourseUrl = "http://discourse.kabissa.org/",
      discourseEmbedUrl = 'http://www.kabissa.org/<?php $my_nid = substr($_SERVER['REQUEST_URI'], 1); print $my_nid; ?>';

  (function() {
    var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
      d.src = discourseUrl + 'javascripts/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);

There appear to be many ways to get the canonical URL of a page in Drupal that have evolved over the years - here the comment in a huge thread over on drupal.org where I got the above. If there is a better way to do this let me know.

Onebox embedded content not appearing in discussions embedded in blog
(Tobias Eigen) #3

I just noticed a bug with my hack - putting the code in the post itself means that it might be displayed in wrong places, such as blog frontpage and category pages… this results in surprise topics being created in the forum which I did not realize. I thought only posts in the RSS feed get created as topics but it seems to also create them dynamically - so maybe there is no need for the rss feed.

can someone explain this functionality?

(Tobias Eigen) #4

I have an update on my progress with this - thanks @codetricity for logging into my discourse instance at http://discourse.kabissa.org and giving me encouragement! :smile:

Today I changed my setup so the code is no longer in the body of one or two posts but is in a block displayed alongside all blog posts. This is working fine. Older blog posts are getting their own discourse topics automagically when pages are accessed for the first time.

Some potential issues with this setup that I am going to have to monitor:

  1. The text of some topics created automagically in discourse is incorrect, including text from a sidebar that is irrelevant to the topic.
  2. There will be alot of topics in discourse that don’t need to be there. It seems to me that the topic should only be created in discourse when someone clicks the link to start a discussion about the blog post, not just when the page is accessed.
  3. I still need to explore options for handling old blog post comments from before. I will probably set them all to be read only and leave them in place, and set new posts to no longer accept comments through drupal.

(Craig Oda) #5

Thanks for all your work on this. to everyone else, the community that @tobiaseigen created is worth checking out because of the mission of the Kabissa project. It’s a great opportunity to check out what people are using the Internet for.

The Internet simply connects people. What we do with those connections is up to us.

The attraction of a platform like Discourse is that some small percentage of connected people will aspire to greatness. Granted, Drupal can work to connect people. However, forums have historically been a barrier to connection, not a finely made tool.

I wish I could help you solve these problems with Drupal, but it’s beyond my experience level.

(Tobias Eigen) #6

I have another drupal code snippet to share to make this embedding discourse in Drupal 6 sites work properly. This goes in the “page specific visibility settings” for the block. Below I included two screenshots as well to document how this works.

In Drupal 7 and newer this is not an issue since it’s possible to choose which content types a block is displayed on.

  // Only show if $match is true
  $match = false;
  // Which node types
  $types = array('blog');
  // Match current node type with array of types
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $nid = arg(1);
    $node = node_load(array('nid' => $nid));
    $type = $node->type;
    $match |= in_array($type, $types);
  return $match;
  1. Discourse embed code that goes into the block (described in earlier post above):

  2. PHP code to limit where the block is displayed that goes in the Page Specific visibility settings:

(Tobias Eigen) #7

I love this. :smiley: Agree with the sentiment deeply… it’s one of the reasons why I do what I do!

(Tobias Eigen) #8

FYI in case anyone is using this hack, I have two problems:

  1. the block is displaying when editing nodes as well as viewing them, which means that Discourse gets an error because the URL is behind a password. But it does not seem to have any other effect. Here’s an example log entry:

exception: 403 Forbidden
context: {“retry”=>true, “queue”=>“default”, “class”=>“Jobs::RetrieveTopic”, “args”=>[{“user_id”=>1, “embed_url”=>“http://www.kabissa.org/node/7028/edit”, “current_site_id”=>“default”}], “jid”=>“e38bc5898948c256864255dd”, “enqueued_at”=>1401213350.6770232, “error_message”=>“403 Forbidden”, “error_class”=>“OpenURI::HTTPError”, “failed_at”=>1401213351.6540828, “retry_count”=>14, “retried_at”=>1401304490.6297555}
backtrace: /usr/local/lib/ruby/2.0.0/open-uri.rb:353:in open_http' /usr/local/lib/ruby/2.0.0/open-uri.rb:709:inbuffer_open’
/usr/local/lib/ruby/2.0.0/open-uri.rb:210:in block in open_loop' /usr/local/lib/ruby/2.0.0/open-uri.rb:208:incatch’
/usr/local/lib/ruby/2.0.0/open-uri.rb:208:in open_loop' /usr/local/lib/ruby/2.0.0/open-uri.rb:149:inopen_uri’
/usr/local/lib/ruby/2.0.0/open-uri.rb:689:in open' /usr/local/lib/ruby/2.0.0/open-uri.rb:34:inopen’
/var/www/discourse/app/models/topic_embed.rb:76:in find_remote' /var/www/discourse/app/models/topic_embed.rb:103:inimport_remote’
/var/www/discourse/lib/topic_retriever.rb:52:in fetch_http' /var/www/discourse/lib/topic_retriever.rb:45:inperform_retrieve’
/var/www/discourse/lib/topic_retriever.rb:9:in retrieve' /var/www/discourse/app/jobs/regular/retrieve_topic.rb:17:inexecute’
/var/www/discourse/app/jobs/base.rb:131:in `block (2 levels) in perform’

The fix for this methinks is on the drupal side to use PHP to not display the block on pages that are private.

  1. occasionally I am seeing duplicate posts in Discourse for the same topic, presumably because the URL being passed to Discourse includes parameters and therefore Discourse thinks it’s a new, different post. Here’s an example of a duplicate showing the wacky URL:

This is a companion discussion topic for the original entry at http://www.kabissa.org/blog/african-round-table-discussion-civicrm?utm_content=buffer46d18&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer

The fix for this is probably also on the drupal side, to add code to the snippet that strips the parameters.

(colin avolve) #9

I am aware this is almost thread a year old, and could not find something more recent.

I am looking at Discourse (whose development I have followed for some time) as the thread title describes — to replace Drupal comments. Is there an update on the integration?

Ideally, I am looking for commenting to be undertaken on the same page as the blog post, and effectively there being no need for/users not leaving the site and going to the actual Discourse forum. In other words commenting would be seamless and remain in the blog post and the Discourse forum hidden/inaccessible.

As an extension, is there a script or guide for converting existing Drupal comments to Discourse posts (I am aware there is a forum import script for Drupal -> Discourse)

[still working through the conceptual for the site update, currently running Drupal 7.x]

(Tobias Eigen) #10

Hey, glad to see more Drupal folks considering Discourse.

You should look closely at the first post above. Nothing has changed about that. No way to contribute to comments without logging into Discourse.

(Dashamir Hoxha) #11

I think that the solution for both of these problems is to fix your Drupal code above. I wander whether you did it and how you did it.

(Dashamir Hoxha) #12

I tried the module Discourse Forum Integration | Drupal.org and I could make the SSO work almost easily. I haven’t tried yet the rest of functionality (especially embedding and seamless commenting).

(Tobias Eigen) #13

That drupal module doesn’t take care of embedding - you have to do it via the embed code as explained above. If you can improve on what I’ve done please share your work! :slight_smile:

It would be nice to see a drupal equivalent to wp-discourse which handles SSO and comment embeds very nicely.

(Dashamir Hoxha) #14

My usecase is a bit different and I don’t think that I am going to have those 2 problems that you mentioned. But I think that the first problem can be corrected like this:

if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2)!='edit') {

And for the second problem you can use the functions current_path() or request_path(), instead of substr($_SERVER['REQUEST_URI'], 1);

(UserXtreamz) #15

Hi @tobiaseigen I tried with above code in my website. When the user logged in discourse it will show all comments in my site through this code. But the user is not logged in at that time it’s not showing the
discourse comments in my site… I want to show the discourse comments in both cases(Login and Logout).
Is it possible solve using same method??

(Tobias Eigen) #16

it should show them… do you require login on your discourse to see discussions?

(UserXtreamz) #17

That option is enabled in my discourse that made tyhe problem .Now i corrected It.Thanks

(UserXtreamz) #18

If we are using this type code .Is it possible to integrate reply and comment section to our website.

Is it possible to integrate this portion to our website? Any option available for discourse to integrate reply and comment section to our Website?