diff --git a/sharethis.module b/sharethis.module index c10ac3d..91883e0 100644 --- a/sharethis.module +++ b/sharethis.module @@ -164,7 +164,12 @@ function sharethis_configuration_form($form, &$form_state) { } // Add help text for the 'content' location. - $form['context']['content']['#children'] = t('You must place the ShareThis links in the "Manage Display" section of each content type.'); + $form['context']['content']['help'] = array( + '#markup' => t('When using the Content location, you must place the ShareThis links in the Manage Display section of each content type.', array('@url' => url('admin/structure/types'))), + '#weight' => 10, + '#prefix' => '', + '#suffix' => '', + ); // Add help text for the 'block' location. $form['context']['block']['#children'] = t('You must choose which region to display the ShareThis block in from the Blocks administration.', array('@blocksadmin' => url('admin/structure/block'))); @@ -186,6 +191,20 @@ function sharethis_configuration_form($form, &$form_state) { ); } + // Allow the user to choose which content types will have ShareThis added + // when using the 'Content' location. + $content_types = array(); + $enabled_content_types = variable_get('sharethis_node_types', array()); + foreach($entity_info['bundles'] as $bundle => $bundle_info) { + $content_types[$bundle] = t($bundle_info['label']); + } + $form['context']['content']['sharethis_node_types'] = array( + '#title' => t('Node Types'), + '#description' => t('Select which node types the ShareThis widget should appear on.'), + '#type' => 'checkboxes', + '#options' => $content_types, + '#default_value' => $enabled_content_types, + ); $form['context']['sharethis_comments'] = array( '#title' => t('Comments'), '#type' => 'checkbox', @@ -353,30 +372,36 @@ function sharethis_node_view($node, $view_mode, $langcode) { // Check where we want to display the ShareThis widget. switch (variable_get('sharethis_location', 'content')) { case 'content': - $node->content['sharethis'] = array( - '#tag' => 'div', // Wrap it in a div. - '#type' => 'html_tag', - '#attributes' => array('class' => 'sharethis-buttons'), - '#value' => sharethis_get_button_HTML($data_options, $mPath, $mTitle), - '#weight' => intval(variable_get('sharethis_weight', 10)), - ); + $enabled_types = variable_get('sharethis_node_types', array()); + if (isset($enabled_types[$node->type]) && $enabled_types[$node->type]) { + $node->content['sharethis'] = array( + '#tag' => 'div', // Wrap it in a div. + '#type' => 'html_tag', + '#attributes' => array('class' => 'sharethis-buttons'), + '#value' => sharethis_get_button_HTML($data_options, $mPath, $mTitle), + '#weight' => intval(variable_get('sharethis_weight', 10)), + ); + } break; case 'links': - $links['sharethis'] = array( - 'html' => TRUE, - 'title' => sharethis_get_button_HTML($data_options, $mPath, $mTitle), - 'attributes' => array('class' => 'sharethis-buttons'), - ); - $node->content['links']['sharethis'] = array( - '#theme' => 'links', - '#links' => $links, - '#attributes' => array( - 'class' => array('links', 'inline'), - ), - '#tag' => 'div', // Wrap it in a div. - '#type' => 'html_tag', - '#weight' => intval(variable_get('sharethis_weight', 10)), - ); + $enabled_view_modes = variable_get('sharethis_' . $node->type . '_options', array()); + if (isset($enabled_view_modes[$view_mode]) && $enabled_view_modes[$view_mode]) { + $links['sharethis'] = array( + 'html' => TRUE, + 'title' => sharethis_get_button_HTML($data_options, $mPath, $mTitle), + 'attributes' => array('class' => 'sharethis-buttons'), + ); + $node->content['links']['sharethis'] = array( + '#theme' => 'links', + '#links' => $links, + '#attributes' => array( + 'class' => array('links', 'inline'), + ), + '#tag' => 'div', // Wrap it in a div. + '#type' => 'html_tag', + '#weight' => intval(variable_get('sharethis_weight', 10)), + ); + } break; } }