Commit b09f0c05 authored by Philippe Mouchel's avatar Philippe Mouchel
Browse files

Define permission to access sharer toolbar

[refs #71131]
parent 95a79c81
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
*/ */
function sharer_toolbar_permission() { function sharer_toolbar_permission() {
return array( return array(
'access sharer toolbar' => array(
'title' => t('Access sharer toolbar'),
'description' => t('Choose who can acces sharers on front.'),
),
'admin sharer toolbar' => array( 'admin sharer toolbar' => array(
'title' => t('Administer sharer toolbar'), 'title' => t('Administer sharer toolbar'),
'description' => t('Choose which social sharer to be displayed and other stuffs.'), 'description' => t('Choose which social sharer to be displayed and other stuffs.'),
...@@ -120,42 +124,45 @@ function sharer_toolbar_sharer_toolbar_available_sharer() { ...@@ -120,42 +124,45 @@ function sharer_toolbar_sharer_toolbar_available_sharer() {
* Implements hook_process_node(). * Implements hook_process_node().
*/ */
function sharer_toolbar_process_node(&$variables) { function sharer_toolbar_process_node(&$variables) {
module_load_include('inc', 'sharer_toolbar');
$sharing_buttons = array();
// Get all active and available sharers // Default value for sharer toolbar
$active_sharers = variable_get('sharer_toolbar_sharers_configuration', array()); $variables['sharer_toolbar'] = NULL;
$available_sharers = _sharer_toolbar_get_available_sharers();
// Generate button if sharer is active // Generate only if user can access it
foreach ($active_sharers as $sid => &$sharer) { if (user_access('access sharer toolbar')) {
if ($sharer['status']) { module_load_include('inc', 'sharer_toolbar');
$sharing_buttons = array();
// Merge file configuration to complete database configuration // Get all active and available sharers
$sharer = array_merge($available_sharers[$sid], $sharer); $active_sharers = variable_get('sharer_toolbar_sharers_configuration', array());
$available_sharers = _sharer_toolbar_get_available_sharers();
// Transform URL // Generate button if sharer is active
_sharer_toolbar_generate_sharer_url($sharer['url'], $variables); foreach ($active_sharers as $sid => &$sharer) {
if ($sharer['status']) {
} // Merge file configuration to complete database configuration
$sharer = array_merge($available_sharers[$sid], $sharer);
// Transform URL
_sharer_toolbar_generate_sharer_url($sharer['url'], $variables);
}
// or unset before sending array to template // or unset before sending array to template
else { else {
unset($active_sharers[$sid]); unset($active_sharers[$sid]);
}
} }
}
// Add javascript feature // Add javascript feature
drupal_add_js(drupal_get_path('module', 'sharer_toolbar') . '/js/sharer-opener.js'); drupal_add_js(drupal_get_path('module', 'sharer_toolbar') . '/js/sharer-opener.js');
// Render HTML for sharer toolbar // Render HTML for sharer toolbar
if (!empty($active_sharers)) { if (!empty($active_sharers)) {
$variables['sharer_toolbar'] = theme('sharer_toolbar', array( $variables['sharer_toolbar'] = theme('sharer_toolbar', array(
'title' => variable_get('sharer_toolbar_title', 'Share'), 'title' => variable_get('sharer_toolbar_title', 'Share'),
'sharers' => $active_sharers, 'sharers' => $active_sharers,
)); ));
} }
else {
$variables['sharer_toolbar'] = NULL;
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment