Project

General

Profile

Paste
Download (4.63 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / addthis / addthis_displays / addthis_displays.addthis.inc @ 2c8c2b87

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
  // Add the widget script.
36
  $script_manager = AddThisScriptManager::getInstance();
37
  $script_manager->attachJsToElement($element);
38

    
39
  $services = trim($options['#display']['settings']['share_services']);
40
  $services = str_replace(' ', '', $services);
41
  $services = explode(',', $services);
42

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

    
59
    // Add individual counters.
60
    if (strpos($service, 'counter_') === 0) {
61
      $items[$service]['#attributes']['class'] = array("addthis_$service");
62
    }
63

    
64
    // Basic implementations of bubble counter orientation.
65
    // @todo Figure all the bubbles out and add them.
66
    //   Still missing: tweetme, hyves and stubleupon, google_plusone_badge.
67
    //
68
    $orientation = ($options['#display']['settings']['counter_orientation'] == 'horizontal' ? TRUE : FALSE);
69
    switch ($service) {
70
      case 'linkedin_counter':
71
          $items[$service]['#attributes'] += array(
72
            'li:counter' => ($orientation ? '' : 'top'),
73
          );
74
        break;
75
      case 'facebook_like':
76
        $items[$service]['#attributes'] += array(
77
          'fb:like:layout' => ($orientation ? 'button_count' : 'box_count')
78
        );
79
        break;
80
      case 'facebook_share':
81
        $items[$service]['#attributes'] += array(
82
          'fb:share:layout' => ($orientation ? 'button_count' : 'box_count')
83
        );
84
        break;
85
      case 'google_plusone':
86
        $items[$service]['#attributes'] += array(
87
          'g:plusone:size' => ($orientation ? 'standard' : 'tall')
88
        );
89
        break;
90
      case 'tweet':
91
        $items[$service]['#attributes'] += array(
92
          'tw:count' => ($orientation ? 'horizontal' : 'vertical'),
93
          'tw:via' => AddThis::getInstance()->getTwitterVia(),
94
        );
95
        break;
96
      case 'bubble_style':
97
        $items[$service]['#attributes']['class'] = array(
98
          'addthis_counter', 'addthis_bubble_style'
99
        );
100
        break;
101
      case 'pill_style':
102
        $items[$service]['#attributes']['class'] = array(
103
          'addthis_counter', 'addthis_pill_style'
104
        );
105
        break;
106
    }
107
  }
108
  $element += $items;
109

    
110
  return $element;
111
}
112

    
113
/**
114
 * Implements hook_addthis_display_markup__[display]().
115
 */
116
function addthis_displays_addthis_display_markup__addthis_basic_button($options = array()) {
117

    
118
  $addthis = AddThis::getInstance();
119
  $settings = $options['#display']['settings'];
120

    
121
  $button_img = 'http://s7.addthis.com/static/btn/sm-share-en.gif';
122
  if (isset($settings['buttons_size']) && $settings['buttons_size'] == 'big') {
123
    $button_img = 'http://s7.addthis.com/static/btn/v2/lg-share-en.gif';
124
  }
125
  $button_img = $addthis->transformToSecureUrl($button_img);
126

    
127
  $extra_css = isset($settings['extra_css']) ? $settings['extra_css'] : '';
128
  $element = array(
129
    '#theme' => 'addthis_wrapper',
130
    '#tag' => 'a',
131
    '#attributes' => array(
132
      'class' => array(
133
        'addthis_button',
134
        $extra_css,
135
      ),
136
    ),
137
  );
138
  $element['#attributes'] += $addthis->getAddThisAttributesMarkup($options);
139

    
140
  // Add the widget script.
141
  $script_manager = AddThisScriptManager::getInstance();
142
  $script_manager->attachJsToElement($element);
143

    
144
  // Create img button.
145
  $image = array(
146
    '#theme' => 'addthis_element',
147
    '#tag' => 'img',
148
    '#attributes' => array(
149
      'src' => $button_img,
150
      'alt' => t('Share page with AddThis'),
151
    ),
152
  );
153
  $element[] = $image;
154

    
155
  return $element;
156
}