'. t('Provides functionality to interface with the ShareThis web service.', array('@sharethis' => 'http://sharethis.com')); case 'admin/settings/sharethis': return '

'. t('Below provides the settings for interfacing with the ShareThis web service.', array('@sharethis' => 'http://sharethis.com')); } } /** * Implementation of hook_perm(). */ function sharethis_perm() { return array('administer share', 'use share this'); } /** * Implementation of hook_menu(). */ function sharethis_menu() { $items = array (); $items['admin/settings/sharethis'] = array( 'title' => t('ShareThis'), 'description' => t('Administer settings related to the ShareThis web service.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('sharethis_admin_settings'), 'access arguments' => array('administer share'), 'type' => MENU_NORMAL_ITEM, ); return $items; } /** * Menu callback; Settings administration. */ function sharethis_admin_settings() { $form['sharethis_this_settings'] = array( '#type' => 'fieldset', '#title' => t('ShareThis API Code (STAPI)'), '#description' => t('The following javascript code can be modified to enhance the appearance of your ShareThis popup, and to determine which Social Networking sites are displayed.'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $sharethis_code = ''; $form['sharethis_this_settings']['sharethis_sharethis_this_code'] = array( '#type' => 'textarea', '#title' => t('Share This Code'), '#description' => t('Javascript code provided by Share This. You can generate your own code !here.', array ('!here'=>l(t('here'), 'http://sharethis.com/publisher?type=stapi'))), '#default_value' => variable_get('sharethis_sharethis_this_code', $sharethis_code), ); $form['where_to_sharethis_sharethis_this'] = array( // Where to Share '#type' => 'fieldset', '#title' => t('Node Types & Positioning'), '#description' => t('Set the node types and categories you want to display links for.'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['where_to_sharethis_sharethis_this']['sharethis_sharethis_this_node_types'] = array( '#type'=>'checkboxes', '#title'=>t('Node types'), '#default_value' => variable_get('sharethis_sharethis_this_node_types', array()), '#options' => node_get_types('names'), ); if (module_exists('taxonomy')) { $terms = taxonomy_form_all(); if (!empty($terms)){ $form['where_to_sharethis_sharethis_this']['sharethis_sharethis_this_category_types'] = array( '#type' => 'select', '#multiple' => TRUE, '#title' => t('Categories'), '#default_value' => variable_get('sharethis_sharethis_this_category_types', array()), '#options' => $terms, ); } } $form['where_to_sharethis_sharethis_this']['sharethis_teaser'] = array( '#type' => 'checkbox', '#title' => t('Display in teaser view'), '#description' => t('If enabled, the ShareThis links will appear in node teasers. If disabled, they will only appear on the full node page.'), '#default_value' => variable_get('sharethis_teaser', 1), ); $form['where_to_sharethis_sharethis_this']['sharethis_sharethis_this_where'] = array( '#type' => 'select', '#title' => t('Where to display'), '#description' => t('Select where you would like the ShareThis link to appear.'), '#default_value' => variable_get('sharethis_sharethis_this_where', 'links'), '#options'=> array( 'links' => t('Links'), 'nodes' => t('Nodes'), ), ); $form['where_to_sharethis_sharethis_this']['sharethis_sharethis_weight'] = array( '#type' => 'weight', '#delta' => 10, '#description' => t('Only applies when node type display is selected.'), '#title' => t('Weight'), '#default_value' => variable_get('sharethis_sharethis_weight', 0), ); return system_settings_form($form); } /** * Implementation of hook_nodeapi(). */ function sharethis_nodeapi(& $node, $op, $teaser, $page) { switch ($op) { case 'view': if (!$teaser || variable_get('sharethis_teaser', 1)) { if (variable_get('sharethis_sharethis_this_where', 'links') == 'nodes') { if (_sharethis_sharethis_this_show($node->type, $node->nid) && user_access('use share this')) { // Create the ShareThis element. $sharethis = sharethis_add_js($node->title, array( 'url' => url('node/'. $node->nid, array('absolute' => TRUE)), )); $node->content['sharethis_sharethis_this'] = array( '#value' => $sharethis, '#weight' => variable_get('sharethis_sharethis_weight', 0), ); } } } break; } } /** * Implementation of hook_link(). */ function sharethis_link($type, $node = NULL, $teaser = FALSE) { if (!$teaser || variable_get('sharethis_teaser', 1)) { if (variable_get('sharethis_sharethis_this_where', 'links') == 'links') { if (_sharethis_sharethis_this_show($node->type, $node->nid) && user_access('use share this')) { // Create the ShareThis element. $sharethis = sharethis_add_js($node->title, array( 'url' => url('node/'. $node->nid, array('absolute' => TRUE)), )); $links['sharethis_sharethis_this'] = array( 'title' => $sharethis, 'html' => TRUE, ); return $links; } } } } /** * Check if the service links should be displayed for the node type/category. */ function _sharethis_sharethis_this_show($type, $nid) { // Check to see if the node type is to display the ShareThis. $node_type = in_array($type, variable_get('sharethis_sharethis_this_node_types', array()), TRUE); $category_type = FALSE; // Check to see if Taxonomy is enabled and the node has a vocabulary. if (module_exists('taxonomy') && isset($node->vid)) { $terms = taxonomy_node_get_terms($nid); foreach ($terms as $term) { $category_type = in_array($term->tid, variable_get('sharethis_sharethis_this_category_types', array()), FALSE); if ($category_type) { // Stop looping because we found that the category is to be displayed. break; } } } return $node_type || $category_type; } /** * Creates a ShareThis element, as well as adds all required JavaScript to the page. * * @param $title * The title of the document that is to be shared. * @param $options * See http://sharethis.com/developers/api/ for the options available. * @param $element * See http://sharethis.com/developers/api/ for the element options available. * @return * Returns the HTML to be placed inline where the ShareThis element will be shown. */ function sharethis_add_js($title, $options = array(), $element = array()) { // Be sure to add the ShareThis header code only once. static $sharethis_added = FALSE; if ($sharethis_added === FALSE) { // Register the Drupal ShareThis behaviors and tell them the ShareThis API URL. drupal_add_js(drupal_get_path('module', 'sharethis') . '/sharethis.js'); drupal_add_js(array('shareThisUrl' => sharethis_api_url()), 'setting'); // Flag that the JavaScript has been registered. $sharethis_added = TRUE; } // Track the ShareThis index ID. static $sharethis_id = 0; // Prepare the options by sending in the title, retrieve the ID and prepare the element. $options['title'] = $title; $id = 'sharethis_'. $sharethis_id++; if (empty($element)) { $element = array('button' => FALSE); } // Create and add the settings. $settings = array('shareThis' => array($id => array('id' => $id, 'options' => $options, 'element' => $element))); drupal_add_js($settings, 'setting'); // Create the ShareThis entry. return l(t('ShareThis'), '', array( 'attributes' => array('id' => $id), 'fragment' => $id, )); } /** * Retrieves the current ShareThis API URL without the ', '', $url); // Remove end $url = str_replace('#', '?', $url); // # switches to ? $url = str_replace('&', '&', $url); // Replace & with & return $cached = $url; }