You are here

function rrssb_settings in Ridiculously Responsive Social Sharing Buttons 7.2

Same name and namespace in other branches
  1. 8.2 rrssb.module \rrssb_settings()
  2. 7 rrssb.module \rrssb_settings()

Fetch buttons settings.

Parameters

boolean $all TRUE: Fetch all buttons. FALSE: only fetch enabled buttons.:

Return value

array Key is button name, value is an array of button config and settings merged. For config values, see hook_rrssb_buttons. Settings values are 'enabled', 'weight', 'username'.

3 calls to rrssb_settings()
rrssb_form in ./rrssb.module
Implements hook_form().
rrssb_gen_css in ./rrssb.module
Auto-generate CSS for buttons.
rrssb_get_buttons in ./rrssb.module
Returns a Drupal render array for the buttons.

File

./rrssb.module, line 570

Code

function rrssb_settings($all = FALSE) {

  // The 'all buttons' case is only used on the settings form, so performance isn't so important.
  // Do a static cache, but be careful to use a different entry.  Don't bother with a database cache.
  $buttons =& drupal_static($all ? __FUNCTION__ : __FUNCTION__ . '__all');
  if (isset($buttons)) {
    return $buttons;
  }
  if (!$all && ($cache = cache_get('rrssb_buttons'))) {
    $buttons = $cache->data;
    return $buttons;
  }

  // Get all buttons.
  $chosen = rrssb_get_chosen();
  $defaults = array(
    'enabled' => FALSE,
    'weight' => 0,
    'username' => '',
    'popup' => TRUE,
  );
  $buttons = module_invoke_all('rrssb_buttons');
  drupal_alter('rrssb_buttons', $buttons);
  $iconsDir = libraries_get_path('rrssb-plus') . '/icons';
  $follow = variable_get('rrssb_follow');

  // Set some defaults.
  foreach ($buttons as $name => &$button) {

    // Merge in the current config, with suitable defaults and checking.
    if (isset($chosen[$name])) {
      $button += $chosen[$name];
    }
    $button += $defaults;
    $button['username'] = check_plain($button['username']);
    if (!isset($button['svg'])) {

      // Read SVG from file.
      $svgfile = isset($button['svgfile']) ? $button['svgfile'] : "<icons>/{$name}.min.svg";
      $svgfile = str_replace('<icons>', $iconsDir, $svgfile);
      $button['svg'] = file_get_contents($svgfile);
    }
    if ($follow && isset($button['title_follow'])) {
      $button['text'] = $button['title_follow'];
    }

    // Default text to name.
    if (!isset($button['text'])) {
      $button['text'] = $name;
    }
  }

  // Sort buttons by configured weight.
  uasort($buttons, 'drupal_sort_weight');
  if (!$all) {

    // Filter to only include enabled ones with a URL configured.
    $key = $follow ? 'follow_url' : 'share_url';
    $buttons = array_filter($buttons, function ($button) use ($key) {
      return $button['enabled'] && isset($button[$key]);
    });
    cache_set('rrssb_buttons', $buttons);
  }
  return $buttons;
}