Projet

Général

Profil

Paste
Télécharger (3,71 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / addthis / addthis_displays / addthis_displays.addthis.inc @ c12e7e6a

1
<?php
2

    
3
/**
4
 * @file
5
 * Implements AddThis markup functions.
6
 */
7

    
8
function addthis_displays_addthis_display_markup($display, $variables = NULL) {
9
  return NULL;
10
}
11

    
12
/**
13
 * Implements hook_addthis_display_markup__[display]().
14
 */
15
function addthis_displays_addthis_display_markup__addthis_basic_toolbox($options = array()) {
16
  $addthis = AddThis::getInstance();
17

    
18
  // Create a render array for the widget.
19
  $element = array(
20
    // Use #theme_wrappers to include the rendered children. Otherwise the
21
    // result is an empty element like <div></div>.
22
    '#theme' => 'addthis_wrapper',
23
    '#tag' => 'div',
24
    '#attributes' => array(
25
      'class' => array(
26
        'addthis_toolbox',
27
        'addthis_default_style',
28
        ($options['#display']['settings']['buttons_size'] == AddThis::CSS_32x32 ? AddThis::CSS_32x32 : NULL),
29
        $options['#display']['settings']['extra_css'],
30
      ),
31
    ),
32
  );
33
  $element['#attributes'] += $addthis->getAddThisAttributesMarkup($options);
34

    
35
  $services = trim($options['#display']['settings']['share_services']);
36
  $services = str_replace(' ', '', $services);
37
  $services = explode(',', $services);
38

    
39
  // All service elements
40
  $items = array();
41
  foreach ($services as $service) {
42
    $items[$service] = array(
43
      '#theme' => 'addthis_element',
44
      '#tag' => 'a',
45
      '#value' => '',
46
      '#attributes' => array(
47
        'href' => $addthis->getBaseBookmarkUrl(),
48
        'class' => array(
49
          'addthis_button_' . $service,
50
        ),
51
      ),
52
      '#addthis_service' => $service,
53
    );
54

    
55
    // Basic implementations of bubble counter orientation.
56
    // @todo Figure all the bubbles out and add them.
57
    //   Still missing: tweetme, hyves and stubleupon.
58
    //
59
    // @todo Fix a way to use addthis_bubble_style.
60
    //   There is a conflict now with using the class addthis_button_[service].
61
    //   You can't add this bubble style now.
62
    $orientation = ($options['#display']['settings']['counter_orientation'] == 'horizontal' ? TRUE : FALSE);
63
    switch ($service) {
64
      case 'facebook_like':
65
        $items[$service]['#attributes'] += array(
66
          'fb:like:layout' => ($orientation ? 'button_count' : 'box_count')
67
        );
68
        break;
69
      case 'google_plusone':
70
        $items[$service]['#attributes'] += array(
71
          'g:plusone:size' => ($orientation ? 'standard' : 'tall')
72
        );
73
        break;
74
      case 'tweet':
75
        $items[$service]['#attributes'] += array(
76
          'tw:count' => ($orientation ? 'horizontal' : 'vertical'),
77
          'tw:via' => AddThis::getInstance()->getTwitterVia(),
78
        );
79
        break;
80
    }
81
  }
82
  $element += $items;
83

    
84
  return $element;
85
}
86

    
87
/**
88
 * Implements hook_addthis_display_markup__[display]().
89
 */
90
function addthis_displays_addthis_display_markup__addthis_basic_button($options = array()) {
91

    
92
  $addthis = AddThis::getInstance();
93
  $settings = $options['#display']['settings'];
94

    
95
  $button_img = 'http://s7.addthis.com/static/btn/sm-share-en.gif';
96
  if (isset($settings['buttons_size']) && $settings['buttons_size'] == 'big') {
97
    $button_img = 'http://s7.addthis.com/static/btn/v2/lg-share-en.gif';
98
  }
99
  $button_img = $addthis->transformToSecureUrl($button_img);
100

    
101
  $extra_css = isset($settings['extra_css']) ? $settings['extra_css'] : '';
102
  $element = array(
103
    '#theme' => 'addthis_wrapper',
104
    '#tag' => 'a',
105
    '#attributes' => array(
106
      'class' => array(
107
        'addthis_button',
108
        $extra_css,
109
      ),
110
    ),
111
  );
112
  $element['#attributes'] += $addthis->getAddThisAttributesMarkup($options);
113

    
114
  // Create img button.
115
  $image = array(
116
    '#theme' => 'addthis_element',
117
    '#tag' => 'img',
118
    '#attributes' => array(
119
      'src' => $button_img,
120
      'alt' => t('Share page with AddThis'),
121
    ),
122
  );
123
  $element[] = $image;
124

    
125
  return $element;
126
}