function _addthis_services_list in AddThis 6.3
Returns an array of AddThis service codes and names.
2 calls to _addthis_services_list()
- addthis_config_form in ./
addthis.admin.inc - Return a form object for default AddThis settings.
- addthis_flush_services in ./
addthis.admin.inc - Flush the services cache.
File
- ./
addthis.admin.inc, line 229 - Configuration settings for AddThis.
Code
function _addthis_services_list() {
// json_decode() didn't exist before PHP 5.2.
if (!function_exists('json_decode')) {
return _addthis_services_retrieval_error();
}
// Retrieve the services table from the cache. If the cache is not set, get
// the list of services from AddThis and cache the results.
// See http://www.addthis.com/help/services-api
if (!($services_cache = cache_get('addthis:services'))) {
// Generate the service codes output and cache it.
$location = "http://cache.addthiscdn.com/services/v1/sharing.en.json";
$result = drupal_http_request($location);
if ($result->code == 200) {
$data = json_decode($result->data, TRUE);
$rows = array();
foreach ($data['data'] as $service) {
$rows[] = array(
0 => check_plain($service['code']),
1 => '<span class="addthis_service_icon icon_' . check_plain($service['code']) . '"></span> ' . check_plain($service['name']),
);
}
$services = l(t('Refresh this list.'), 'admin/settings/addthis/flush-services', array(
'query' => drupal_get_destination(),
));
$header = array(
t('Service code'),
t('Service'),
);
$services .= theme('table', $header, $rows);
cache_set('addthis:services', $services);
}
else {
// Couldn't retrieve the services list.
$services = _addthis_services_retrieval_error();
}
}
else {
// Use the cached services output.
$services = $services_cache->data;
}
return $services;
}