You are here

function shariff_preprocess_shariff in Shariff Social Media Buttons 7

Implements hook_preprocess().

File

./shariff.module, line 346
Integrating Shariff library, providing settings form and block.

Code

function shariff_preprocess_shariff(&$variables, $hook) {

  // Set class.
  $variables['classes'] = 'shariff';
  $data_settings = array(
    'services',
    'shariff_theme',
    'orientation',
    'twitter_via',
    'referrer_track',
    'mail_url',
    'mail_subject',
    'mail_body',
    'backend_url',
    'flattr_category',
    'flattr_user',
    'media_url',
    'lang',
    'url',
    'title',
  );

  // Build data html.
  $data = array();
  foreach ($data_settings as $setting) {
    if (!empty($variables[$setting])) {
      switch ($setting) {
        case 'services':
          $value = '["' . implode('","', $variables[$setting]) . '"]';
          break;
        case 'referrer_track':
          $value = urlencode(check_plain($variables[$setting]));
          break;
        case 'backend_url':
        case 'url':
        case 'mail_url':
        case 'media_url':
          $value = check_url($variables[$setting]);
          break;
        case 'twitter_via':
        case 'mail_subject':
        case 'mail_body':
        case 'flattr_user':
        case 'flattr_category':
        case 'title':
        default:
          $value = check_plain($variables[$setting]);
          break;
        case 'shariff_theme':
          $value = $variables[$setting];
          $setting = 'theme';
          break;
        case 'lang':
          $value = $variables[$setting];
          break;
      }

      // Shariff requires data-attributes with dashes instead of underscores.
      $data['data-' . str_replace('_', '-', $setting)] = $value;
    }
  }
  $variables['data_html'] = drupal_attributes($data);

  // Load shariff library.
  $variant = variable_get('shariff_css', 'complete');
  libraries_load('shariff', $variant);
}