Download & Extend

Manually embed social sharing button (including support for Panels)

Project:Janrain Engage (formerly RPX)
Version:7.x-2.x-dev
Component:User interface
Category:task
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Is it possible and how using display suite, panels or custom php etc? I love the functionality but I would like to place it in a mini panel most specifically.
thx

Comments

#1

Yes, it should be possible. You can paste Javascript for the embedded
Sign-In Widget to a node and do with it however you please.

Cheers,
George

#2

Been having a little play around with this but im definitely no php guy. Anyways, I got the button to show up in a mini panel by simply pasting the _rpx_share_button function in a custom php content and it shows the button but doesnt register the node title properly (the mini panel is within a node panel). I tried passing the node being viewed context but still nothing for the node title. Any ideas? Heres the function i pasted in custom php content pane:

<?php
$url
= (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . request_uri();

 
// Prepare arguments for RPXNOW.Social.Activity().
 
$args = array();
  foreach (array(
'label', 'message', 'linktext', 'title', 'summary') as $arg) {
   
$default = variable_get('rpx_default_'. $arg . '_nodes', constant('RPX_DEFAULT_' . strtoupper($arg) . '_NODES_STRING'));
   
$args[$arg] = variable_get('rpx_'. $arg . '_nodes_'. $node->type, $default);
   
// We disable sanitize for token_replace() to prevent it from encoding
    // apostrophes and such.
   
$args[$arg] = filter_xss(token_replace($args[$arg], array('node' => $node, 'user' => $user), array('clear' => TRUE, 'sanitize' => FALSE)));
  }

 
//
  // Pass node sharing info to social JS.
  //
 
$settings = array();
 
// Arguments for RPXNOW.Social.Activity().
 
$settings['rpx']['rpx-link-social-node-'. $node->nid]['post'] = array(
   
'label' => $args['label'],
   
'linktext' => $args['linktext'],
   
'link' => $url,
   
'comment' => $args['message'],
   
'summary' => text_summary(strip_tags($args['summary']), NULL, 128) . '...',
   
'title' => $args['title'],
  );
 
// Sharing cookie info (used in Rules integration).
 
if (module_exists('rpx_rules') && _rpx_event_enabled('rpx_social_cookie_set_node')) {
   
// For some reason this plugin is not added for Chrome (and maybe others).
   
drupal_add_library('system', 'jquery.cookie');

   
// Instruct social JS to set a cookie and trigger a page reload so that an
    // Engage social sharing Rules event can be fired.
   
$settings['rpx']['rpx-link-social-node-'.$node->nid]['cookie'] = array(
     
'type' => 'node',
     
'id' => $node->nid,
    );
  }
 
drupal_add_js($settings, 'setting');

 
rpx_js();
 
rpx_js_social();
  return
theme('rpx_share_button', array('node' => $node));
?>

#3

George,

I've received a few requests for this from people at Drupal Users' Group meetings. In particular, people want to be able to use the "Share" button in a Panel (http://drupal.org/project/panels).

I'm wondering if we can create a simple API that allows anyone to print the share button with a line or two of code. That would also solve the issue having the node context available.

Thoughts?

--Ben

#4

Title:Manually embed social sharing widget?» Manually embed social sharing widget (including support for Panels)

#5

Title:Manually embed social sharing widget (including support for Panels)» Manually embed social sharing button (including support for Panels)

Title adjustment, feel free to revert but I guess we are talking about the button.

#6

Category:support request» task

#7

This works with the details of the node. Use by pasting into a custom content pane or mini panel :)

<?php
if (arg(0) == 'node' && is_numeric(arg(1)) && ($node = node_load(arg(1)))) {
 
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . request_uri();
 
// Prepare arguments for RPXNOW.Social.Activity().
 
$args = array();
  foreach (array(
'label', 'message', 'linktext', 'title', 'summary') as $arg) {
   
$default = variable_get('rpx_default_'. $arg . '_nodes', constant('RPX_DEFAULT_' . strtoupper($arg) . '_NODES_STRING'));
   
$args[$arg] = variable_get('rpx_'. $arg . '_nodes_'. $node->type, $default);
   
// We disable sanitize for token_replace() to prevent it from encoding
    // apostrophes and such.
   
$args[$arg] = filter_xss(token_replace($args[$arg], array('node' => $node, 'user' => $user), array('clear' => TRUE, 'sanitize' => FALSE)));
  }

 
//
  // Pass node sharing info to social JS.
  //
 
$settings = array();
 
// Arguments for RPXNOW.Social.Activity().
 
$settings['rpx']['rpx-link-social-node-'. $node->nid]['post'] = array(
   
'label' => $args['label'],
   
'linktext' => $args['linktext'],
   
'link' => $url,
   
'comment' => $args['message'],
   
'summary' => text_summary(strip_tags($args['summary']), NULL, 128) . '...',
   
'title' => $args['title'],
  );
 
// Sharing cookie info (used in Rules integration).
 
if (module_exists('rpx_rules') && _rpx_event_enabled('rpx_social_cookie_set_node')) {
   
// For some reason this plugin is not added for Chrome (and maybe others).
   
drupal_add_library('system', 'jquery.cookie');

   
// Instruct social JS to set a cookie and trigger a page reload so that an
    // Engage social sharing Rules event can be fired.
   
$settings['rpx']['rpx-link-social-node-'.$node->nid]['cookie'] = array(
     
'type' => 'node',
     
'id' => $node->nid,
    );
  }
 
drupal_add_js($settings, 'setting');

 
rpx_js();
 
rpx_js_social();
  return
theme('rpx_share_button', array('node' => $node));
  }
?>

#8

+1

#9

Bumping this so that we can take a closer look.... George, what do you think about a simple API to do what is done in comment #7?

--Ben

#10

Tried out the code in #7 in a custom content panel, but I'm getting the following notice:

Notice: Undefined variable: user in eval() (line 11 of /Users/benkaplan/git/drupaldev/modules/php/php.module(74) : eval()'d code).

The share button is showing up (and the hover functions properly), but upon clicking nothing happens.

If we need to update the code for the latest 7.x-2.x-dev commits, we should do so and then document this.

--Ben

#11

Hey Ben,

I haven't checked this but judging from the error message, it seems
that you need to throw in a "global $user;" statement in that PHP snippet.

Hope this helps,
George

#12

Yeah, "global $user;" got rid of the notices. Thanks. Unfortunately, the share button still isn't clickable and doesn't launch the widget if you try to click.

Other ideas?

--Ben

#13

Hey Ben,

I've just tried creating a panel with the above code in it. It seems
to work - the widget is displayed when I click the buttons.

Cheers,
George

#14

Hmmm... I'll try again.

--Ben

#15

Hey George,

I tried that code again and for some reason it's working now! :-) Cool.

--Ben

#16

That's very good news Ben, we didn't get to this yet in our implementation, but we certainly will. Should we call this fixed or are we providing some sort of API as you suggested in #9 ?

#17

@rafamd: The code is kind of a workaround for now. An actual API (or even just a block) would be much, much better. So this issue should be left active until it can be properly addressed in a future release.

--Ben

#18

As a temporary solution I wrapped #7 plus #11 in a module so people can use the Social Sharing widget as a Drupal Block.

Have a look:
http://drupal.org/sandbox/s1l/1315560

It would be great if there was a clean API for the Social Sharing widget (and the Social Login icons), (+blocks) and all of these features would be integrated in the Janrain Engage module.

nobody click here