summaryrefslogtreecommitdiffstats
path: root/addthis.module
blob: a248ada3b1007a49237e6c83cd86bdef72ee0927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/**
 * @file
 * Hook implementations for the AddThis-module. Most of the logic is defined
 * in a separate AddThis-class to keep the .module-file clean.
 */

module_load_include('inc', 'addthis', 'includes/addthis.block');
module_load_include('inc', 'addthis', 'includes/addthis.field');

/**
 * Implements hook_hook_info().
 *
 * Define hook_addthis_display_markup in the addthis group so that
 * $module.addthis.inc files will be included. See addthis.addthis.inc for
 * examples of the hook implementation.
 */
function addthis_hook_info() {
  $hooks['addthis_display_markup'] = array(
    'group' => 'addthis',
  );
  return $hooks;
}

/**
 * Implements hook_help().
 */
function addthis_help($path, $arg) {
  switch ($path) {
    case 'admin/help#addthis':
      $output = '<h3>' . t('About') . '</h3>';
      $output .= '<p>';
      $output .= t('The AddThis module defines AddThis field type for the Field module. A AddThis field may contain a button, toolbox, sharecount or customized sharing tool using <a href="http://addthis.com/">AddThis.com</a>.');
      $output .= '</p>';
      return $output;
  }
}

/**
 * Implements hook_filter_format_update().
 */
function addthis_filter_format_update($format) {
  field_cache_clear();
}

/**
 * Implements hook_filter_format_disable().
 */
function addthis_filter_format_disable($format) {
  field_cache_clear();
}


/**
 * Implements hook_menu().
 */
function addthis_menu() {
  $menu_items['admin/config/user-interface/addthis'] = array(
    'title' => 'AddThis',
    'description' => 'Configure AddThis settings.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('addthis_admin_settings_form'),
    'access arguments' => array(AddThis::PERMISSION_ADMINISTER_ADDTHIS),
    'type' => MENU_NORMAL_ITEM,
    'file' => AddThis::ADMIN_INCLUDE_FILE,
  );
  return $menu_items;
}

/**
 * Implements hook_permission().
 */
function addthis_permission() {
  return array(
    AddThis::PERMISSION_ADMINISTER_ADDTHIS => array(
      'title' => t('Administer AddThis'),
      'description' => t('Perform maintenance tasks for AddThis.'),
    ),
    AddThis::PERMISSION_ADMINISTER_ADVANCED_ADDTHIS => array(
      'title' => t('Administer advanced AddThis'),
      'description' => t('Perform advanced maintenance tasks for AddThis.'),
    ),
  );
}

/**
 * Implements hook_page_alter().
 */
function addthis_page_alter(&$page) {
  AddThis::getInstance()->addWidgetJs();
  AddThis::getInstance()->addConfigurationOptionsJs();
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Hide the instance fieldset because there aren't any values per instance.
 */
function addthis_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#field']['type'] == AddThis::FIELD_TYPE && $form['#field']['type'] == AddThis::MODULE_NAME) {
    $form['field']['#access'] = FALSE;
    $form['instance']['required']['#access'] = FALSE;
    $form['instance']['description']['#access'] = FALSE;
    $form['instance']['default_value_widget']['#access'] = FALSE;
  }
}

/**
 * Implements hook_rdf_namespaces()
 */
function addthis_rdf_namespaces() {
  if (AddThis::getInstance()->isFacebookLikeCountSupportEnabled()) {
    return array(
      'fb' => 'http://www.facebook.com/2008/fbml',
    );
  }
  return array();
}

/**
 * Implements hook_theme().
 */
function addthis_theme($existing, $type, $theme, $path) {
  return array(
    'addthis_wrapper' => array(
      'render element' => 'addthis_wrapper',
    ),
    'addthis_element' => array(
      'render element' => 'addthis_element',
    ),
    'addthis' => array(
      'render element' => 'addthis',
    ),
  );
}

/**
 * Implements hook_preprocess() for theme_addthis.
 */
function template_preprocess_addthis(&$variables) {
  if (isset($variables[0]) && count($variables) == 3) {
    $variables['#display'] = $variables[0];
    unset($variables[0]);
  }
}

function theme_addthis($variables) {
  $markup = AddThis::getInstance()->getDisplayMarkup($variables['#display']);
  return render($markup);
}

function theme_addthis_wrapper($variables) {
  $element = $variables['addthis_wrapper'];
  $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>';
  $children = element_children($element);

  if (count($children) > 0) {
    foreach ($children as $child) {
      $output .= render($element[$child]);
    }
  }

  $output .= '</' . $element['#tag'] . ">\n";
  return $output;
}

/**
 * Theme the elements that are created in the AddThis module. This is
 * created with hook_addthis_element.
 */
function theme_addthis_element($variables) {
  $element = $variables['addthis_element'];

  if (!isset($element['#value'])) {
    return '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . " />\n";
  }

  $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>';
  if (isset($element['#value_prefix'])) {
    $output .= $element['#value_prefix'];
  }
  $output .= $element['#value'];
  if (isset($element['#value_suffix'])) {
    $output .= $element['#value_suffix'];
  }
  $output .= '</' . $element['#tag'] . ">\n";
  return $output;
}