diff --git a/sharethis.admin.inc b/sharethis.admin.inc index b6b7df0..4f85bd5 100644 --- a/sharethis.admin.inc +++ b/sharethis.admin.inc @@ -4,7 +4,7 @@ * Functionality for Share This administration. */ -/** + /** * This is the main configuration form for the admin page. */ function sharethis_configuration_form($form, &$form_state) { @@ -13,9 +13,7 @@ function sharethis_configuration_form($form, &$form_state) { $my_path = drupal_get_path('module', 'sharethis'); // Load the css and js for our module's configuration. drupal_add_css($my_path . '/ShareThisForm.css'); - // This is ShareThis's common library - has a serviceList of all the objects - // that are currently supported. - drupal_add_js('https://ws.sharethis.com/share5x/js/stcommon.js', 'external'); + drupal_add_js('https://ws.sharethis.com/share5x/js/stcommon.js', 'external'); //This is ShareThis's common library - has a serviceList of all the objects that are currently supported. drupal_add_js($my_path . '/ShareThisForm.js'); drupal_add_js($my_path . '/stlib_picker.js'); drupal_add_css($my_path . '/stlib_picker.css'); @@ -40,37 +38,15 @@ function sharethis_configuration_form($form, &$form_state) { } $service_string_markup = drupal_substr($service_string_markup, 0, -1); - // Create an array of node types. - $node_type_array = node_type_get_types(); - $node_type_options = array(); - foreach ($node_type_array as $k => $v) { - $node_type_options[$k] = $v->name; - } - // Figure out which nodeTypes are currently selected - $nodes_string = $current_options_array['nodeType']; - $nodes_selected = explode(",", $nodes_string); // Create the variables for publisher keys. $publisher = $current_options_array['publisherID']; // Create the variables for teasers. - $teaser = $current_options_array['viewMode'] == "1" ? TRUE : FALSE; $form = array(); $form['options'] = array( '#type' => 'fieldset', '#title' => t('Display'), ); - $form['options']['sharethis_widget_option'] = array( - '#options' => array( - 'st_multi' => t("Multi-Post Widget"), - 'st_direct' => t("Direct-Post Widget") - ), - '#default_value' => $widget_type, - '#type' => 'radios', - '#required' => TRUE, - '#title' => t("Choose a widget type:"), - '#prefix' => '
', - '#suffix' => '
' - ); $form['options']['sharethis_button_option'] = array( '#required' => TRUE, '#type' => 'radios', @@ -105,8 +81,14 @@ function sharethis_configuration_form($form, &$form_state) { 'Google Plus One:plusone' => t('Google Plus One'), 'Facebook Like:fblike' => t('Facebook Like'), ), - '#default_value' => variable_get('sharethis_option_extras', array()), + '#default_value' => $current_options_array['option_extras'], + ); + + $form['options']['sharethis_callesi'] = array( + '#type' => 'hidden', + '#default_value' => $current_options_array['sharethis_callesi'], ); + $form['additional_settings'] = array( '#type' => 'vertical_tabs', ); @@ -116,27 +98,7 @@ function sharethis_configuration_form($form, &$form_state) { '#group' => 'additional_settings', '#description' => t('Configure where the ShareThis widget should appear.'), ); - $form['context']['sharethis_node_option'] = array( - '#title' => t("Node types"), - '#description' => t('Select which nodes the ShareThis widget should appear on.'), - '#required' => TRUE, - '#type' => 'checkboxes', - '#options' => $node_type_options, - '#default_value' => $nodes_selected - ); - $form['context']['sharethis_teaser_option'] = array( - '#title' => t('Only full view'), - '#type' => 'checkbox', - '#default_value' => $teaser ? 1 : 0, - '#description' => t('When checked, will not show the widget on node teasers.'), - ); - $form['context']['sharethis_comments'] = array( - '#title' => t('Comments'), - '#type' => 'checkbox', - '#default_value' => variable_get('sharethis_comments', FALSE), - '#description' => t('Display ShareThis on comments.'), - '#access' => module_exists('comment'), - ); + $form['context']['sharethis_location'] = array( '#title' => t('Location'), '#type' => 'radios', @@ -146,7 +108,63 @@ function sharethis_configuration_form($form, &$form_state) { 'links' => t('Links area'), ), '#default_value' => variable_get('sharethis_location', 'content'), - '#description' => t('Choose where the ShareThis widget should appear. When selected to display as a block, you must choose which region to display the ShareThis block in from the Blocks administration.', array('@blocksadmin' => url('admin/structure/block'))), + ); + + // Add an information section for each location type, each dependent on the + // currently selected location. + foreach (array('links', 'content', 'block') as $location_type) { + $form['context'][$location_type]['#type'] = 'container'; + $form['context'][$location_type]['#states']['visible'][':input[name="sharethis_location"]'] = array('value' => $location_type); + } + + // Add help text for the 'content' location. + $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'))); + + // Add checkboxes for each view mode of each bundle. + $entity_info = entity_get_info('node'); + $modes = array(); + foreach ($entity_info['view modes'] as $mode => $mode_info) { + $modes[$mode] = $mode_info['label']; + } + // Get a list of content types and view modes + $view_modes_selected = $current_options_array['view_modes']; + foreach ($entity_info['bundles'] as $bundle => $bundle_info) { + $form['context']['links']['sharethis_' . $bundle . '_options'] = array( + '#title' => t('%label View Modes', array('%label' => $bundle_info['label'])), + '#description' => t('Select which view modes the ShareThis widget should appear on for %label nodes.', array('%label' => $bundle_info['label'])), + '#type' => 'checkboxes', + '#options' => $modes, + '#default_value' => $view_modes_selected[$bundle], + ); + } + + // Allow the user to choose which content types will have ShareThis added + // when using the 'Content' location. + $content_types = array(); + $enabled_content_types = $current_options_array['sharethis_node_types']; + 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', + '#default_value' => variable_get('sharethis_comments', FALSE), + '#description' => t('Display ShareThis on comments.'), + '#access' => module_exists('comment'), ); $form['context']['sharethis_weight'] = array( '#title' => t('Weight'), @@ -198,38 +216,65 @@ function sharethis_configuration_form($form, &$form_state) { '#description' => t('If disabled, the ShareThis widget will be displayed on click instead of hover.'), '#default_value' => variable_get('sharethis_option_onhover', TRUE), ); + $form['advanced']['sharethis_option_neworzero'] = array( + '#type' => 'checkbox', + '#title' => t('Display count "0" instead of "New"'), + '#description' => t('Display a zero (0) instead of "New" in the count for content not yet shared.'), + '#default_value' => variable_get('sharethis_option_neworzero', FALSE), + ); + $form['advanced']['sharethis_option_shorten'] = array( + '#type' => 'checkbox', + '#title' => t('Display short URL'), + '#description' => t('Display either the full or the shortened URL.'), + '#default_value' => variable_get('sharethis_option_shorten', TRUE), + ); + $form['advanced']['sharethis_cns'] = array( + '#title' => t('CopyNShare (?)'), + '#type' => 'checkboxes', + '#prefix' => '
', + '#suffix' => '
+

CopyNShare is the new ShareThis widget feature that enables you to track the shares that occur when a user copies and pastes your website\'s URL or Content.
+ Site URL - ShareThis adds a special #hashtag at the end of your address bar URL to keep track of where your content is being shared on the web.
+ Site Content - It enables the pasting of "See more: YourURL#SThashtag" after user copies-and-pastes text. When a user copies text within your site, a "See more: yourURL.com#SThashtag" will appear after the pasted text.
+ Please refer the CopyNShare FAQ for more details.

+
', + '#options' => array( + 'donotcopy' => t('Measure copy & shares of your site\'s Content'), + 'hashaddress' => t('Measure copy & shares of your site\'s URLs'), + ), + '#default_value' => $current_options_array['sharethis_cns'], + ); + + $form['#submit'][] = 'sharethis_configuration_form_submit'; return system_settings_form($form); } /** - * Form submission handler for sharethis_configuration_form(). + * Form validation handler for sharethis_configuration_form(). */ function sharethis_configuration_form_validate($form, &$form_state) { - // Additional filters for the service option input. + //Additional filters for the service option input - // Sanitize the publisher ID option. Since it's a text field, remove - // anything that resembles code. + // Sanitize the publisher ID option. Since it's a text field, remove anything that resembles code $form_state['values']['sharethis_service_option'] = filter_xss($form_state['values']['sharethis_service_option'], array()); - // Additional filters for the option extras input. + //Additional filters for the option extras input $form_state['values']['sharethis_option_extras'] = (isset($form_state['values']['sharethis_option_extras'])) ? $form_state['values']['sharethis_option_extras'] : array(); - // Implode the node options. - $form_state['values']['sharethis_node_option'] = implode(',', $form_state['values']['sharethis_node_option']); - - // Set a default value for the teaser option. - $form_state['values']['sharethis_teaser_option'] = (isset($form_state['values']['sharethis_teaser_option'])) ? $form_state['values']['sharethis_teaser_option'] : 0; - - // Sanitize the publisher ID option. Since it's a text field, remove - // anything that resembles code. + // Sanitize the publisher ID option. Since it's a text field, remove anything that resembles code $form_state['values']['sharethis_publisherID'] = filter_xss($form_state['values']['sharethis_publisherID'], array()); - // Ensure default value for twitter suffix. + if($form_state['values']['sharethis_callesi'] == 1){ + unset($form_state['values']['sharethis_cns']); + } + unset($form_state['values']['sharethis_callesi']); + + // Ensure default value for twitter suffix $form_state['values']['sharethis_twitter_suffix'] = (isset($form_state['values']['sharethis_twitter_suffix'])) ? $form_state['values']['sharethis_twitter_suffix'] : ''; - // Ensure default value for twitter handle. + // Ensure default value for twitter handle $form_state['values']['sharethis_twitter_handle'] = (isset($form_state['values']['sharethis_twitter_handle'])) ? $form_state['values']['sharethis_twitter_handle'] : ''; - // Ensure default value for twitter recommends. + // Ensure default value for twitter recommends $form_state['values']['sharethis_twitter_recommends'] = (isset($form_state['values']['sharethis_twitter_recommends'])) ? $form_state['values']['sharethis_twitter_recommends'] : ''; }