Text cleanup.
[project/addthis.git] / addthis.module
1 <?php
2 /**
3 * @file
4 * Hook implementations for the AddThis-module. Most of the logic is defined
5 * in a separate AddThis-class to keep the .module-file clean.
6 */
7
8 module_load_include('inc', 'addthis', 'includes/addthis.block');
9 module_load_include('inc', 'addthis', 'includes/addthis.field');
10
11 /**
12 * Implements hook_hook_info().
13 *
14 * Define hook_addthis_display_markup in the addthis group so that
15 * $module.addthis.inc files will be included. See addthis.addthis.inc for
16 * examples of the hook implementation.
17 */
18 function addthis_hook_info() {
19 $hooks['addthis_display_markup'] = array(
20 'group' => 'addthis',
21 );
22 return $hooks;
23 }
24
25 /**
26 * Implements hook_help().
27 */
28 function addthis_help($path, $arg) {
29 switch ($path) {
30 case 'admin/help#addthis':
31 $output = '<h3>' . t('About') . '</h3>';
32 $output .= '<p>';
33 $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>.');
34 $output .= '</p>';
35 return $output;
36 }
37 }
38
39 /**
40 * Implements hook_filter_format_update().
41 */
42 function addthis_filter_format_update($format) {
43 field_cache_clear();
44 }
45
46 /**
47 * Implements hook_filter_format_disable().
48 */
49 function addthis_filter_format_disable($format) {
50 field_cache_clear();
51 }
52
53
54 /**
55 * Implements hook_menu().
56 */
57 function addthis_menu() {
58 $menu_items['admin/config/user-interface/addthis'] = array(
59 'title' => 'AddThis',
60 'description' => 'Configure AddThis settings.',
61 'page callback' => 'drupal_get_form',
62 'page arguments' => array('addthis_admin_settings_form'),
63 'access arguments' => array(AddThis::PERMISSION_ADMINISTER_ADDTHIS),
64 'type' => MENU_NORMAL_ITEM,
65 'file' => AddThis::ADMIN_INCLUDE_FILE,
66 );
67 return $menu_items;
68 }
69
70 /**
71 * Implements hook_permission().
72 */
73 function addthis_permission() {
74 return array(
75 AddThis::PERMISSION_ADMINISTER_ADDTHIS => array(
76 'title' => t('Administer AddThis'),
77 'description' => t('Perform maintenance tasks for AddThis.'),
78 ),
79 AddThis::PERMISSION_ADMINISTER_ADVANCED_ADDTHIS => array(
80 'title' => t('Administer advanced AddThis'),
81 'description' => t('Perform advanced maintenance tasks for AddThis.'),
82 ),
83 );
84 }
85
86 /**
87 * Implements hook_page_alter().
88 */
89 function addthis_page_alter(&$page) {
90 AddThis::getInstance()->addWidgetJs();
91 AddThis::getInstance()->addConfigurationOptionsJs();
92 }
93
94 /**
95 * Implements hook_form_FORM_ID_alter().
96 *
97 * Hide the instance fieldset because there aren't any values per instance.
98 */
99 function addthis_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
100 if ($form['#field']['type'] == AddThis::FIELD_TYPE && $form['#field']['type'] == AddThis::MODULE_NAME) {
101 $form['field']['#access'] = FALSE;
102 $form['instance']['required']['#access'] = FALSE;
103 $form['instance']['description']['#access'] = FALSE;
104 $form['instance']['default_value_widget']['#access'] = FALSE;
105 }
106 }
107
108 /**
109 * Implements hook_rdf_namespaces()
110 */
111 function addthis_rdf_namespaces() {
112 if (AddThis::getInstance()->isFacebookLikeCountSupportEnabled()) {
113 return array(
114 'fb' => 'http://www.facebook.com/2008/fbml',
115 );
116 }
117 return array();
118 }
119
120 /**
121 * Implements hook_theme().
122 */
123 function addthis_theme($existing, $type, $theme, $path) {
124 return array(
125 'addthis_wrapper' => array(
126 'render element' => 'addthis_wrapper',
127 ),
128 'addthis_element' => array(
129 'render element' => 'addthis_element',
130 ),
131 'addthis' => array(
132 'render element' => 'addthis',
133 ),
134 );
135 }
136
137 /**
138 * Implements hook_preprocess() for theme_addthis.
139 */
140 function template_preprocess_addthis(&$variables) {
141 if (isset($variables[0]) && count($variables) == 3) {
142 $variables['#display'] = $variables[0];
143 unset($variables[0]);
144 }
145 }
146
147 function theme_addthis($variables) {
148 $markup = AddThis::getInstance()->getDisplayMarkup($variables['#display']);
149 return render($markup);
150 }
151
152 function theme_addthis_wrapper($variables) {
153 $element = $variables['addthis_wrapper'];
154 $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>';
155 $children = element_children($element);
156
157 if (count($children) > 0) {
158 foreach ($children as $child) {
159 $output .= render($element[$child]);
160 }
161 }
162
163 $output .= '</' . $element['#tag'] . ">\n";
164 return $output;
165 }
166
167 /**
168 * Theme the elements that are created in the AddThis module. This is
169 * created with hook_addthis_element.
170 */
171 function theme_addthis_element($variables) {
172 $element = $variables['addthis_element'];
173
174 if (!isset($element['#value'])) {
175 return '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . " />\n";
176 }
177
178 $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>';
179 if (isset($element['#value_prefix'])) {
180 $output .= $element['#value_prefix'];
181 }
182 $output .= $element['#value'];
183 if (isset($element['#value_suffix'])) {
184 $output .= $element['#value_suffix'];
185 }
186 $output .= '</' . $element['#tag'] . ">\n";
187 return $output;
188 }