--- services/widget_services.admin.inc 2012-03-09 19:14:38.000000000 +0100 +++ services/widget_services.admin.inc 2012-03-09 18:12:41.947775000 +0100 @@ -213,5 +213,39 @@ ), ); + $form['pinterest_button'] = array( + '#type' => 'fieldset', + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#title' => t('Pinterest Button'), + ); + $form['pinterest_button']['service_links_pb_countlayout'] = array( + '#title' => t('Pin Count'), + '#type' => 'select', + '#default_value' => variable_get('service_links_pb_countlayout', 'horizontal'), + '#options' => array( + 'horizontal' => t('Horizontal'), + 'vertical' => t('Vertical'), + 'none' => t('No Count'), + ), + ); + $form['pinterest_button']['service_links_pb_mediatoken'] = array( + '#title' => t('Media parameter'), + '#type' => 'textfield', + '#default_value' => variable_get('service_links_pb_mediatoken', ''), + '#description' => t('Fill the media parameter with a token which will be evaluated by Token module.', array('@url' => 'http://www.drupal.org/project/token')), + '#size' => 40, + ); + if (module_exists('token')) { + $form['pinterest_button']['token_help'] = array( + '#type' => 'fieldset', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#title' => t('Token help'), + '#theme' => 'token_tree', + '#token_types' => array('node'), + ); + } + return system_settings_form($form); } --- services/widget_services.module 2012-03-09 19:14:38.000000000 +0100 +++ services/widget_services.module 2012-03-09 19:00:28.209580000 +0100 @@ -75,6 +75,20 @@ 'style' => SERVICE_LINKS_STYLE_EMPTY, 'callback' => 'ws_linkedin_share_button_data', ); + $links['pinterest_button'] = array( + 'name' => 'Pinterest', + 'link' => 'http://pinterest.com/pin/create/button/?url=&description=&media=', + 'icon' => 'pinterest.png', + 'description' => t('Pin It'), + 'javascript' => array( + //'http://assets.pinterest.com/js/pinit.js', + 'pinterest_button.js', + ), + 'style' => SERVICE_LINKS_STYLE_EMPTY, + 'attributes' => array('class' => array('pin-it-button')), + 'callback' => 'ws_pinterest_button_data', + 'preset' => 'ws_pinterest_button_tags', + ); return $links; } @@ -206,6 +220,46 @@ } /** + * Preset function for Pinterest Button, which fill the media tag. + */ +function ws_pinterest_button_tags(&$service, &$settings, $node = NULL) { + static $media_token; + + if (!isset($media_token)) { + $media_token = variable_get('service_links_pb_mediatoken', ''); + $settings['tag']['pinterest-media'] = ''; + } + + if (module_exists('token')) { + $settings['subst']['pinterest-media'] = token_replace($media_token, array('node' => $node)); + } + else { + $settings['subst']['pinterest-media'] = ''; + } +} + +/** + * Callback function for Pinterest Button. + */ +function ws_pinterest_button_data(&$service, $subst) { + static $pb_settings; + + if (!isset($pb_settings)) { + $pb_settings = array( + 'countlayout' => check_plain(variable_get('service_links_pb_countlayout', 'horizontal')), + ); + + drupal_add_js(array('ws_pb' => $pb_settings), 'setting'); + } + + $params = array( + 'media' => check_plain($subst['pinterest-media']), + ); + + $service['url'][1] = array_merge($service['url'][1], $params); +} + +/** * Implements hook_menu(). */ function widget_services_menu() {