You are here

function qtip_clean_settings in qTip (Stylish jQuery Tooltips) 7.2

[qtip_clean_settings description]

Parameters

[type] $instance [description]:

boolean $encode [description]:

Return value

[type] [description]

2 calls to qtip_clean_settings()
qtip_clean_settings_multiple in ./qtip.module
[qtip_clean_settings_multiple description]
qtip_views_views_pre_render in modules/qtip_views/qtip_views.module
Implements hook_views_pre_render().

File

./qtip.module, line 652

Code

function qtip_clean_settings($instance, $encode = TRUE) {
  if (isset($instance->settings)) {
    $settings = $instance->settings;
  }
  else {
    $settings = $instance;
  }
  if (empty($settings)) {
    return;
  }

  //--- Items to handle individually before being processed in bulk

  // NONE SO FAR!
  foreach ($settings as $key => $setting) {

    // Remove all empty values from the setting section so that qTip will use it's default setting
    if (isset($settings[$key])) {
      $settings[$key] = array_filter($settings[$key]);
    }
    $events = '';

    // Convert 'event' arrays into strings since that is what qTip is expecting
    if (isset($setting['event'])) {
      foreach ($setting['event'] as $event_key => $value) {
        if ($value) {
          $events .= $event_key . ' ';
        }
      }
      $settings[$key]['event'] = $events;
    }
  }

  // If the tooltip position is not set (because it was removed before), set it to the most logical place
  if (!isset($settings['position']['my'])) {
    $qtip_position_map = array(
      'top left' => 'bottom right',
      'top center' => 'bottom center',
      'top right' => 'bottom left',
      'right top' => 'left bottom',
      'right center' => 'left center',
      'right bottom' => 'left top',
      'bottom right' => 'top left',
      'bottom center' => 'top center',
      'bottom left' => 'top right',
      'left bottom' => 'right top',
      'left center' => 'right center',
      'left top' => 'right bottom',
      'center' => 'bottom center',
    );
    $settings['position']['my'] = '';
    if (isset($settings['position']['at'])) {
      $settings['position']['my'] = $qtip_position_map[$settings['position']['at']];
    }
  }

  // Need to convert the checkbox value (0 or 1) to boolean equivilent
  isset($settings['position']['viewport']) ? $settings['position']['viewport'] = (bool) $settings['position']['viewport'] : ($settings['position']['viewport'] = FALSE);

  //--- Items to handle individually before being processed in bulk

  // We need to set an empty content.text container so that the qtip will be generated properly
  if (!isset($settings['content']['text'])) {
    $settings['content']['text'] = '';
  }
  if (module_exists('qtip_advanced')) {

    // Remove all empty values from position.adjust so that qTip will use it's default setting
    $settings['position']['adjust'] = array_filter($settings['position']['adjust']);
  }

  // Set the value of the tip to FALSE if it was removed in the bulk operations above
  // qTip needs style.tip = false if it is supposed to hide the tip because by default
  // it will display the tip. We don't want to set a checkbox for 'Hide tip' in the
  // administrative form because all of the other options are 'show'
  if (isset($settings['style']['tip']) && !$settings['style']['tip']['corner']) {
    $settings['style']['tip'] = FALSE;
  }
  else {
    $settings['style']['tip']['corner'] = TRUE;
  }

  // Set the tooltip value properly if it is explicitly set to a position
  if (isset($settings['style']['tip']['corner_position']) && !empty($settings['style']['tip']['corner_position'])) {
    $settings['style']['tip']['corner'] = $settings['style']['tip']['corner_position'];
  }

  // We need to remove the mimic setting if it is empty to avoid a jQuery error being thrown
  if (isset($settings['style']['tip']['mimic']) && empty($settings['style']['tip']['mimic'])) {
    unset($settings['style']['tip']['mimic']);
  }

  // Set an empty class variable if it's not already set
  if (!isset($settings['style']['classes'])) {
    $settings['style']['classes'] = '';
  }

  // If we are using a custom color scheme we need to push that class to the classes array
  if ($settings['style']['classes'] == 'qtip-custom' && $settings['style']['classes_custom'] != '') {
    $settings['style']['classes'] .= ' ' . $settings['style']['classes_custom'];
  }

  // We need to push the shadow and rounded corners classes to the classes array, if they exist
  isset($settings['style']['shadow']) && $settings['style']['shadow'] != FALSE ? $settings['style']['classes'] .= ' qtip-shadow' : '';
  isset($settings['style']['rounded_corners']) && $settings['style']['rounded_corners'] != FALSE ? $settings['style']['classes'] .= ' qtip-rounded' : '';

  // Handle the close button
  if (isset($settings['content']['button']) && isset($settings['miscellaneous']['button_title_text']) && !empty($settings['miscellaneous']['button_title_text'])) {
    $settings['content']['button'] = $settings['miscellaneous']['button_title_text'];
  }

  // Convert necessary values to integer equivilent
  isset($settings['style']['tip']['width']) ? $settings['style']['tip']['width'] = (int) $settings['style']['tip']['width'] : NULL;
  isset($settings['style']['tip']['height']) ? $settings['style']['tip']['height'] = (int) $settings['style']['tip']['height'] : NULL;
  isset($settings['style']['tip']['border']) ? $settings['style']['tip']['border'] = (int) $settings['style']['tip']['border'] : NULL;
  isset($settings['style']['tip']['offset']) ? $settings['style']['tip']['offset'] = (int) $settings['style']['tip']['offset'] : NULL;
  isset($settings['hide']['inactive']) ? $settings['hide']['inactive'] = (int) $settings['hide']['inactive'] : NULL;

  // 'solo' needs to be true, not 1
  if (!empty($settings['show']['solo'])) {
    $settings['show']['solo'] = true;
  }

  // Set the position target to follow mouse, if set
  if (!empty($settings['position']['target'])) {
    $settings['position']['target'] = 'mouse';
  }

  // Cleanup settings that do not need to be passed to js
  unset($settings['style']['tip']['corner_position']);
  unset($settings['style']['rounded_corners']);
  unset($settings['style']['shadow']);
  unset($settings['miscellaneous']);
  if ($encode) {
    return drupal_json_encode($settings);
  }
  return $settings;
}