t('Share This Settings'), 'description' => t('Administer settings related to the Share This module.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('sharethis_admin_settings'), 'access arguments' => array('administer share'), 'type' => MENU_NORMAL_ITEM, ); return $items; } function sharethis_admin_settings() { $form['sharethis_this_onoff'] = array( '#type' => 'fieldset', '#title' => t('Master On/Off Switch'), '#description' => t('You can enable or disable the ShareThis module here.'), '#collapsible' => TRUE, '#collapsed' => FALSE ); $types = array(t('ShareThis Disabled'), 'sharethis_this' => t('ShareThis Enabled')); $form['sharethis_this_onoff']['sharethis_type'] = array( '#type' => 'radios', '#title' => t('Show ShareThis Interface'), '#description' => t('Determine wether or not to show the ShareThis interface. Setting this feature to "Disabled" will prevent the ShareThis links from appearing on your site.'), '#default_value' => variable_get('sharethis_type', 0), '#options' => $types ); // Share This $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' => taxonomy_form_all() ); } } $form['where_to_sharethis_sharethis_this']['sharethis_sharethis_this_where'] = array( '#type' => 'select', '#title' => t('Where to display'), '#default_value' => variable_get('sharethis_sharethis_this_where', 0), '#options' => array(t('Links'), 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) { //drupal_set_message(t('node->nid: '.$node->nid.'')); //drupal_set_message(t('node->path: '.$node->path.'')); switch ($op) { case 'view': switch (variable_get('sharethis_type', 0)) { case "sharethis_this": if (variable_get('sharethis_sharethis_this_where', 0) == '1') { static $share = 0; if (_sharethis_sharethis_this_show($node->type, $node->nid) && user_access('use share this')) { if ($share == '0') { $share++; drupal_set_html_head(variable_get('sharethis_sharethis_this_code', 0)); } if($node->path) { // customized for pages with node->path specified $node->content['sharethis_sharethis_this'] = array( '#value' => "", '#weight' => variable_get('sharethis_sharethis_weight', 0) ); } else { // the $node object doesn't contain a path, so it has to be built // using the node id for the default display of nodes without a custom path $node->content['sharethis_sharethis_this'] = array( '#value' => "", '#weight' => variable_get('sharethis_sharethis_weight', 0) ); } } } break; } break; } } /** * Implementation of hook_link(). */ function sharethis_link($type, $node = NULL, $teaser = FALSE) { global $base_path; //echo "
";print_r($node);echo ""; //drupal_set_message(t('node->nid: '.$node->nid.'')); switch (variable_get('sharethis_type', 0)) { case "sharethis_this": if (variable_get('sharethis_sharethis_this_where', 0) == '0') { static $share = 0; if (_sharethis_sharethis_this_show($node->type, $node->nid) && user_access('use share this')) { if ($share == '0') { $share++; drupal_set_html_head(variable_get('sharethis_sharethis_this_code', 0)); } if($node->path) { // customized for pages with node->path specified $links['sharethis_sharethis_this'] = array( 'title' => "", 'html' => TRUE, 'attributes' => array('id' => 'sharethis_'.$node->nid) ); } else { // the $node object doesn't contain a path, so it has to be built // using the node id for the default display of nodes without a custom path $links['sharethis_sharethis_this'] = array( 'title' => "", 'html' => TRUE, 'attributes' => array('id' => 'sharethis_'.$node->nid) ); } return $links; } } break; } } /** * Check if the service links should be displayed for the node type/category. */ function _sharethis_sharethis_this_show($type, $nid) { $links_show = FALSE; $node_type = in_array($type, variable_get('sharethis_sharethis_this_node_types', array()), TRUE); if (module_exists('taxonomy')) { $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 ($node_type || $category_type) { $links_show = TRUE; } return $links_show; }