The comments are being published to FB. I want created nodes to be posted as well. How do I do this?

CommentFileSizeAuthor
#13 fbconnect-nodepost.patch7.67 KBnicholas.alipaz

Comments

bryanb229’s picture

Also trying to do this any help would be great.

thaddeusmt’s picture

So, here are my code hacks to get this working (sorry for not providing a nice .patch file).

In fbconnect_form_alter, at the end, add a case for 'node edit' form like so:

<?php 
  //Facebook feed checkbox on node edit/create form.
  //only show this on the create new forms, not the edit forms
  if ($form_id == $form['#node']->type.'_node_form' && $form['nid']['#value'] == null && fbconnect_get_fbuid()) {
    $favicon = '<img src="http://wiki.developers.facebook.com/images/1/17/Connect_light_small_short.gif" />';
    $form['fbconnect_feed'] = array(
      '#type' => 'checkbox',
      '#title' => $favicon. t(' Publish To Facebook'),
      '#default_value' => 1,
      '#weight' => 0,
    );
  }
 ?>

Implement the nodeapi hook:

<?php
/***
* Implementation of hook_nodeapi
*/
function fbconnect_nodeapi(&$node, $op, $a3 = NULL, $page = FALSE) {
  if ($op == 'insert') { 
    //drupal_set_message('<pre>'.print_r($node, TRUE).'</pre>');
    $_SESSION['fbconnect_feed'] = array(
      'type'    => 'node',
      'title'   => $node->title,
      'nodeurl' => url('node/'.$node->nid, array('absolute' => TRUE)),
    );
  }
}
  ?>

And in fbconnect_render_js, after the case 'comment' : case, add a case for 'node' like so:

<?php
 case 'node' :
        $autopublish = 'false';
        $feed_js = array(
          'name'        => $feed['title'],
          'href'        => $feed['nodeurl'],
          'caption'     => t("{*actor*} created some content at !site", array("!site"=> $site)),
          'properties'  => array(
            t('read')     => array(
              'text'  => $feed['title'],
              'href'  => $feed['nodeurl'],
            ),
            t('visit')    => array(
              'text'  => $site,
              'href'  => $base_url,
            )
          ),
        );
        $action_links = array();
        break;
?>

This will need to be tweaked, but now if I'm logged in to Facebook I get the option to Publish to Facebook when creating a new node of any content type. This code does not show the Publish option when editing a node, only when creating a new one.

thaddeusmt’s picture

Correction to above: the nodeapi function needs to be this for the checkbox to work:

<?php
function fbconnect_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if ($op == 'validate' && $a3['fbconnect_feed']['#post']['fbconnect_feed']) { 
    $_SESSION['fbconnect_feed'] = array(
      'type'    => 'node',
      'title'   => $node->title,
      'nodeurl' => url('node/'.$node->nid, array('absolute' => TRUE)),
    );
  }
}
?>
tassoman’s picture

Would be possible to hook into login also?

John Doe logged into Site Name website.

Would be wonderful extend it by custom module to hook into wanted events. Or implement some integration with Rules module

harmonyhalo’s picture

Hi thaddeusmt, thanks for the additional info - i'm trying to get this to work but having no luck with the function fbconnect_form_alter
i'm wondering what i should use to wrap your hacks. i've tried
"function fbconnect_form_alter(&$form, $form_state, $form_id) {"
but that gives me a fatal error.
Any help would be much appreciated!
Thanks

/// edit ///

I found where to put this if anyone else is as clueless as me, the form_alter function is on or around line 162 of the fbconnect module

/// edit ///

finding where to put the code has helped the checkbox appear on nodes to allow publishing to facebook, though unfortunately it doesn't seem to be appearing in the feed.
the only error i can find in the logs that seems related to this snippet seems to be

"Undefined index: #node"
any ideas?

bryanb229’s picture

Thanks thaddeusmt!

You the man.

arcane’s picture

subscribing

harmonyhalo’s picture

Ok, upgrading to the latest stable Drupal 6.15 removes my above error message, so mad props to thaddeusmt for sorting this out!!
just one little question though, on the user's facebook wall it links to "www.sitename.com/node/" rather than "www.sitename.com/nodetitle/"
What do i need to change in the above to fix this?
Thanks for the major help!

deng17’s picture

Sorry for being a noob...but where can I find those files to edit? I'm not knowledgeable in PHP

harmonyhalo’s picture

* deng17 edit the .module file and follow thaddeusmt's instructions as to where to put each snippet...\

I'm finding this only works intermittently. strangely, it works all the time when submitting a comment, but when i upload a new node it's only sometimes that i get the dialogue to publish it on my wall.
I'd still love to hear if anyone has any ideas about how to link the facebook wall post back to my node which uses a url alias becaue now all i can do is link people back to my homepage rather than the posted content...
Thanks!

nicholas.alipaz’s picture

I will rework this as a patch a bit later, but I found the issue with the url not working properly:

Short answer, replace hook_nodeapi function with this

/***
* Implementation of hook_nodeapi
*/
function fbconnect_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if ($op == 'validate') {
    $_SESSION['fbconnect_feed']['submit'] = ($a3['fbconnect_feed']['#post']['fbconnect_feed']) ? true : false;
  }
  if ($op == 'insert' && $_SESSION['fbconnect_feed']['submit'] === true) {
    $_SESSION['fbconnect_feed'] = array(
      'type'    => 'node',
      'title'   => $node->title,
      'nodeurl' => url('node/'. $node->nid, array('absolute' => true)),
    );
  }
}

Long, the $node->nid is not available from within validate since the $node is not in the db yet. So we have to set our $_SESSION variable from within the 'insert'. I did a workaround that checks the checkbox value during validate and then sets the session inside of insert.

I will reuse most of what code is here and add some administration options to content types for allowing facebook posting to walls and etc.

nicholas.alipaz’s picture

Here is a reworked patch that should setup node/add/[content_type] to allow publishing content to facebook. It also adds an additional setting to each admin/content/node-type/[content_type] settings where one can enable/disable a particular content type as capable of publishing to facebook. Lastly, I changed hook_form_alter to be a switch since that is the more correct way to do it.

nicholas.alipaz’s picture

Status: Needs review » Active
StatusFileSize
new7.67 KB

forgot the patch. Here it is. It is patched against todays cvs HEAD 6.x-1.x-dev

nicholas.alipaz’s picture

Status: Active » Needs review

almost forgot... needs review

harmonyhalo’s picture

Wow that's great!
haven't applied the patch yet but i did input the modified code and it works great for linking directly to the node!
Thanks so much!
It still doesn't always bring up the publish to facebook window, but i'm guessing that's another issue :)

nicholas.alipaz’s picture

Status: Active » Needs review

changing this back to "needs review" since my patch "needs review"

deng17’s picture

Will this be added for the next version?

nicholas.alipaz’s picture

Version: 6.x-1.0-beta8 »

I am not the developer so I have no idea. If you would like it added in the next version then testing the patch is a great way to help.

changing the version to match the version of the module this was patched against.

nicholas.alipaz’s picture

Status: Needs review » Fixed

Marking as fixed since vectoroc seems to have committed the patch to the cvs #334574.

BenK’s picture

Just need to keep track of this thread... looking forward to testing.

nicholas.alipaz’s picture

BenK, it is actually in dev version of the module now. Just letting you know if you missed that part.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

henno.gous’s picture

Nicholas, I've installed the latest dev version, and I'm seeing the "publish to facebook" checkbox in my node creation form, but I'm not seeing my posts showing up on Facebook? Rechecked all my settings and I'm quite sure that my setup is configured correctly. Is this functionality confirmed as working in the dev version?

marcus178’s picture

I'm looking for something similar but rather than posting to the users wall I would like to post it on our Facebook Fan Page.

Is there a way to define where it posts too?

marcus178’s picture

Ok I've managed to add a page id field like

 $form['fbconnect_settings']['onoff'] = array(
        '#type' => 'checkbox',
        '#title' => t('Allow this content type to publish to facebook'),
        '#default_value' => variable_get('fbconnect_' . $form['#node_type']->type . '_onoff', 0),
      );
	  $form['fbconnect_settings']['pageid'] = array(
        '#type' => 'textfield',
        '#title' => t('Enter Facebook Page ID'),
		'#default_value' => variable_get('fbconnect_' . $form['#node_type']->type . '_pageid', 0),
       );

But not sure how I can use the value entered to post to the page rather than users wall.

nicholas.alipaz’s picture

henno.gous, if I recall there may be something wrong with the dev version. I know it is working if one simply applied the patch, but there seems to be something conflicting in the latest dev from what I can remember. I don't have time to look into it now.

marcus178, please open your own issue since what you are discussing is not really related. You want some new features.