You are here

function sharethis_form in ShareThis 7

This is the main configuration form for the admin page.

1 string reference to 'sharethis_form'
sharethis_admin in ./sharethis.module
Implements hook_admin.

File

./sharethis.module, line 56
A module that adds one of the ShareThis widget to your website.

Code

function sharethis_form($form, &$form_state) {

  // First, setup variables we will need.
  // Get the path variables setup.
  $my_path = drupal_get_path('module', 'sharethis');
  $current_options_array = get_options_array();
  global $base_url;

  // Create the variables related to widget choice.
  $widget_type = $current_options_array['widget'];
  $widget_markup = "";
  if ($widget_type == "st_multi") {
    $widget_markup = "st_multi";
  }

  // Create the variables related to button choice.
  $button_choice = $current_options_array['buttons'];

  // Create the variables related to services chosen.
  $service_string = $current_options_array['services'];
  $service_string_markup = "";
  foreach (explode(",", $service_string) as $name => $string) {
    $key = explode(":", substr($string, 0, -1));
    $key = $key[1];
    $service_string_markup .= "\"" . $key . "\",";
  }
  $service_string_markup = 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('ShareThis Configuration Settings:'),
  );
  $form['options']['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' => '<div class="st_widgetContain"><div class="st_widgetPic ' . $widget_markup . '"><div class="st_widgetPicContain"><img src="' . $base_url . '/' . $my_path . '/img/widget.png"></img></div></div>',
    '#suffix' => '</div>',
  );
  $form['options']['button_option'] = array(
    '#required' => TRUE,
    '#type' => 'radios',
    '#options' => array(
      'stbc_large' => t("Large Chicklets"),
      'stbc_' => t("Small Chicklets"),
      'stbc_button' => t("Classic Buttons"),
      'stbc_vcount' => t("Vertical Counters"),
      'stbc_hcount' => t("Horizontal Counters"),
    ),
    '#default_value' => $button_choice,
    '#title' => t("Choose a button style:"),
    '#prefix' => '<div class="st_widgetContain"><div class="st_spriteCover"><img id="stb_sprite" class="st_buttonSelectSprite ' . $button_choice . '" src="' . $base_url . '/' . $my_path . '/img/preview_sprite.png"></img></div><div class="st_widgetPic"><img class="st_buttonSelectImage" src="' . $base_url . '/' . $my_path . '/img/preview_bg.png"></img></div>',
    '#suffix' => '</div>',
  );
  $form['options']['teaser_option'] = array(
    '#title' => t("Don't show the buttons in teaser view."),
    '#type' => 'checkbox',
    '#default_value' => $teaser ? 1 : 0,
  );
  $form['options']['service_option'] = array(
    '#description' => t("<b>Add</b> a service by selecting it on the right and clicking the <i>left arrow</i>.  <b>Remove</b> it by clicking the <i>right arrow</i>.<br /><b>Change the order</b> of services under \"Selected Services\" by using the <i>up</i> and <i>down</i> arrows."),
    '#required' => TRUE,
    '#type' => 'textfield',
    '#prefix' => '<div>',
    '#suffix' => '</div><div id="myPicker"></div><script type="text/javascript">stlib_picker.setupPicker($("#myPicker"), [' . $service_string_markup . '], drupal_st.serviceCallback);</script>',
    '#title' => t("Choose Your Services."),
    '#default_value' => t($service_string),
  );
  $form['options']['node_option'] = array(
    '#title' => t("Choose the node types you want to show the buttons on."),
    '#required' => TRUE,
    '#type' => 'checkboxes',
    '#options' => $node_type_options,
    '#default_value' => $nodes_selected,
  );
  $form['options']['publisherID'] = array(
    '#title' => t("Insert a publisher key (optional)."),
    '#description' => t("When you install the module, we create a random publisher key.  You can register the key with ShareThis by contacting customer support.  Otherwise, you can go to <a href='http://www.sharethis.com/account'>ShareThis</a> and create an account.<br />Your official publisher key can be found under 'My Account'.<br />It allows you to get detailed analytics about sharing done on your site."),
    '#type' => 'textfield',
    '#default_value' => $publisher,
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}