You are here

function sharemessage_get_addthis_services in Share Message 7

Same name and namespace in other branches
  1. 8 sharemessage.module \sharemessage_get_addthis_services()

Load AddThis services.

2 calls to sharemessage_get_addthis_services()
sharemessage_addthis_settings in ./sharemessage.module
Implements hook_sytem_settings().
sharemessage_form in ./sharemessage.module
Share message form.

File

./sharemessage.module, line 566
New Sharing Module.

Code

function sharemessage_get_addthis_services() {
  global $language;
  $options =& drupal_static(__FUNCTION__);
  if (!isset($options)) {
    if ($cache = cache_get('sharemessage_addthis_services:' . $language->language)) {
      $options = $cache->data;
    }
    else {
      $json = sharemessage_get_services_json();
      $output = json_decode($json);
      if (!empty($output)) {
        $options = array(
          t('Common') => array(),
          t('Mail') => array(),
          t('Other') => array(),
        );
        foreach ($output->data as $service) {
          if (in_array($service->code, array(
            'facebook',
            'facebook_like',
            'twitter',
            'xing',
            'linkedin',
            'wordpress',
            'google_plusone_share',
          ))) {
            $options[t('Common')][$service->code] = $service->name;
          }
          elseif (in_array($service->code, array(
            'mail',
            'gmail',
            'yahoomail',
            'aolmail',
            'email',
            'mailto',
          ))) {
            $options[t('Mail')][$service->code] = $service->name;
          }
          else {
            $options[t('Other')][$service->code] = $service->name;
          }
        }

        // Tweet is not defined?
        $options[t('Common')]['tweet'] = t('Tweet');

        // Neither is Pinterest Follow.
        $options[t('Common')]['pinterest_follow'] = t('Pinterest follow');
        cache_set('sharemessage_addthis_services:' . $language->language, $options);
      }
      else {
        cache_clear_all('sharemessage_addthis_services:' . $language->language, 'cache', TRUE);
      }
    }
  }
  return $options;
}