'. 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')) { if (sharethis_add_js()) { $sharethis = sharethis_get_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')) { if (sharethis_add_js()) { $sharethis = sharethis_get_js($node->title, array( 'url' => url('node/'. $node->nid, array('absolute' => TRUE)), )); $links['sharethis_sharethis_this'] = array( 'title' => $sharethis, 'html' => TRUE, 'attributes' => array('id' => 'sharethis_'. $node->nid), ); 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; } /** * Adds the ShareThis JavaScript header code. * * @return * Whether or not the code was added. */ function sharethis_add_js() { static $added = FALSE; if ($added === FALSE) { $code = variable_get('sharethis_sharethis_this_code', 0); if (!empty($code)) { drupal_set_html_head($code); $added = TRUE; } } return $added; } /** * Creates the complete script tag to create SHARETHIS elements. * * See http://sharethis.com/publisher?type=stapi for the options available. */ function sharethis_get_js($title, $options = array()) { $options['title'] = $title; return "'; }