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

Front template for sharer toolbar

and add a label field, and edit default sharing URLs

[refs #70709]
parent fccc1149
......@@ -41,6 +41,12 @@ function sharer_toolbar_config_form($form, &$form_state) {
'#field_prefix' => '<i class="' . $icon_value . '"></i>',
);
// Textfield to hold sharer label.
$form['sharers'][$sid]['label'] = array(
'#type' => 'textfield',
'#default_value' => (isset($sharer_conf['label'])) ? $sharer_conf['label'] : $sharer['label'],
);
// Invisible field, but contains sort info (weights).
$form['sharers'][$sid]['weight'] = array(
'#type' => 'weight',
......
......@@ -82,5 +82,6 @@ function _sharer_toolbar_generate_sharer_url(&$sharer_url, $variables) {
$sharer_url = str_replace('[:shared_source:]', variable_get('site_name', ''), $sharer_url);
// Summary replacement
$sharer_url = str_replace('[:shared_summary:]', '', $sharer_url);
$truncate_summary = truncate_utf8(drupal_html_to_text($variables['node']->body[LANGUAGE_NONE][0]['safe_value']), 200, TRUE, $add_ellipsis = TRUE);
$sharer_url = str_replace('[:shared_summary:]', $truncate_summary, $sharer_url);
}
......@@ -41,10 +41,21 @@ function sharer_toolbar_menu() {
*/
function sharer_toolbar_theme($existing, $type, $theme, $path) {
return array(
// Sharer toolbar config form
'sharer_toolbar_config_form' => array(
'render element' => 'form',
'file' => 'sharer_toolbar.theme.inc',
),
// Sharer toolbar template
'sharer_toolbar' => array(
'variables' => array(
'sharers' => array(),
),
'template' => 'sharer-toolbar',
// 'path' => 'templates',
),
);
}
......@@ -63,6 +74,7 @@ function sharer_toolbar_sharer_toolbar_available_sharer() {
'name' => 'Facebook',
'icon_class' => 'icon-facebook',
'url' => 'https://www.facebook.com/sharer/sharer.php?u=[:shared_url:]',
'label' => 'Share on Facebook',
),
// Twitter sharer
......@@ -70,7 +82,8 @@ function sharer_toolbar_sharer_toolbar_available_sharer() {
'sid' => 'twitter',
'name' => 'Twitter',
'icon_class' => 'icon-twitter',
'url' => 'https://twitter.com/home?status=[:shared_message:]',
'url' => 'https://twitter.com/home?status=[:shared_summary:] [:shared_url:]',
'label' => 'Share on Twitter',
),
// Google Plus sharer
......@@ -79,6 +92,7 @@ function sharer_toolbar_sharer_toolbar_available_sharer() {
'name' => 'Google +',
'icon_class' => 'icon-googleplus',
'url' => 'https://plus.google.com/share?url=[:shared_url:]',
'label' => 'Share on Google+',
),
// Twitter sharer
......@@ -87,14 +101,17 @@ function sharer_toolbar_sharer_toolbar_available_sharer() {
'name' => 'LinkedIn',
'icon_class' => 'icon-linkedin',
'url' => 'https://www.linkedin.com/shareArticle?mini=true&url=[:shared_url:]&title=[:shared_title:]&summary=[:shared_summary:]&source=[:shared_source:]',
'label' => 'Share on LinkedIn',
),
// // Email sharer
// 'email' => array(
// 'sid' => 'email',
// 'name' => 'Email',
// 'icon_class' => 'icon-email',
// ),
// Email sharer
'email' => array(
'sid' => 'email',
'name' => 'Email',
'icon_class' => 'icon-email',
'url' => 'mailto:?subject=[:shared_title:]&body=[:shared_url:]',
'label' => 'Share by email',
),
);
}
......@@ -105,7 +122,6 @@ function sharer_toolbar_sharer_toolbar_available_sharer() {
function sharer_toolbar_preprocess_node(&$variables) {
module_load_include('inc', 'sharer_toolbar');
$sharing_buttons = array();
// dd($variables);
// Get all active and available sharers
$active_sharers = variable_get('sharer_toolbar_sharers_configuration', array());
......@@ -122,12 +138,26 @@ function sharer_toolbar_preprocess_node(&$variables) {
_sharer_toolbar_generate_sharer_url($sharer['url'], $variables);
// Generate button
$sharing_buttons[] = l('Partager sur ' . $sharer['name'], $sharer['url']);
// $ctnt = . t($sharer['label']);
// $sharing_buttons[$sid] = l($ctnt, $sharer['url'], array(
// 'html' => TRUE,
// 'attributes' => array(
// 'title' => $sharer['label'],
// ),
// ));
}
// or unset before sending array to template
else {
unset($active_sharers[$sid]);
}
}
// Add javascript feature
drupal_add_js(drupal_get_path('module', 'sharer_toolbar') . '/js/sharer-opener.js');
// Render HTML for sharer toolbar
$variables['sharer_toolbar'] = theme('sharer_toolbar', array(
'sharing_buttons' => $sharing_buttons,
'sharers' => $active_sharers,
));
}
......@@ -17,6 +17,7 @@ function theme_sharer_toolbar_config_form($variables) {
t('Status'),
t('Name'),
t('Icon class'),
t('Label'),
t('Weight'),
);
......@@ -30,6 +31,7 @@ function theme_sharer_toolbar_config_form($variables) {
drupal_render($form['sharers'][$sid]['status']),
drupal_render($form['sharers'][$sid]['name']),
drupal_render($form['sharers'][$sid]['icon_class']),
drupal_render($form['sharers'][$sid]['label']),
drupal_render($form['sharers'][$sid]['weight']),
),
'class' => array('draggable'),
......
Markdown is supported
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