You are here

function service_links_get_links in Service links 6.2

Same name and namespace in other branches
  1. 7.2 service_links.module \service_links_get_links()

Discover all available service links by invoking hook_service_links().

Parameters

$services: If NULL, will retrieve all service link information. If an array is passed, will only obtain information for the given keyed links.

$reset: Resets the Service Links cache.

Return value

An array containing information for all the requested services.

5 calls to service_links_get_links()
service_links_admin_services in ./service_links.admin.inc
Menu callback administration settings for services links list.
service_links_displays_ds_fields in plugins/service_links_displays.module
Implementation of hook_ds_fields().
service_links_render in ./service_links.module
Function that render all the selected services.
service_links_render_some in ./service_links.module
This function render only the services requested by their id.
service_links_sprites_validate in plugins/service_links_sprites.module

File

./service_links.module, line 372
Adds social network links to the content.

Code

function service_links_get_links($services = NULL, $reset = FALSE) {
  static $links = NULL;
  if (!isset($links) || $reset) {

    // Retrieve the links from the cache.
    if (!$reset && ($cache = cache_get('service_links_get_links')) && !empty($cache->data)) {
      $links = $cache->data;
    }
    else {

      // Create the repository of links.
      $links = array();
      foreach (module_implements('service_links') as $module) {
        $module_links = module_invoke($module, 'service_links');
        foreach ($module_links as $name => $link) {
          $link['module'] = $module;
          $links[$name] = $link;
        }
      }

      // Allow alteration of the links.
      drupal_alter('service_links', $links);

      // Save the links in the cache.
      cache_set('service_links_get_links', $links);
    }
  }

  // If desired, return only the wanted services.
  if (isset($services)) {

    // Detect a manual request and populate the array correctly.
    if (is_numeric(key($services))) {
      $services = array_combine($services, array_fill(0, count($services), 1));
    }

    // Provide only the services requested.
    $services = array_merge($services, array_intersect_key($links, $services));

    // Remove the unknown services.
    $services = service_links_array_filter($services);
  }
  return isset($services) ? $services : $links;
}