| Commit | Line | Data |
|---|---|---|
| 754744f1 | 1 | <?php |
| 680a3f59 | 2 | /** |
| 68bf8a8b | 3 | * @file |
| 49a81891 JP |
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. | |
| 68bf8a8b | 6 | */ |
| 680a3f59 | 7 | |
| 465ccab2 JP |
8 | module_load_include('inc', 'addthis', 'includes/addthis.block'); |
| 9 | module_load_include('inc', 'addthis', 'includes/addthis.field'); | |
| 211164bd | 10 | |
| 680a3f59 | 11 | /** |
| 8cc27624 JP |
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. | |
| b6608a16 MG |
17 | */ |
| 18 | function addthis_hook_info() { | |
| b6608a16 | 19 | $hooks['addthis_display_markup'] = array( |
| d8e50226 | 20 | 'group' => 'addthis', |
| b6608a16 MG |
21 | ); |
| 22 | return $hooks; | |
| 23 | } | |
| 24 | ||
| 25 | /** | |
| b3ac575e | 26 | * Implements hook_help(). |
| 680a3f59 | 27 | */ |
| b3ac575e VP |
28 | function addthis_help($path, $arg) { |
| 29 | switch ($path) { | |
| 30 | case 'admin/help#addthis': | |
| 591b038e | 31 | $output = '<h3>' . t('About') . '</h3>'; |
| 8cc27624 | 32 | $output .= '<p>'; |
| 8f6b399d | 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>.'); |
| 8cc27624 | 34 | $output .= '</p>'; |
| b3ac575e VP |
35 | return $output; |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | /** | |
| b3ac575e VP |
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(); | |
| d222a229 | 51 | } |
| 2422fd60 | 52 | |
| 7a62f979 JP |
53 | |
| 54 | /** | |
| 55 | * Implements hook_menu(). | |
| 56 | */ | |
| 57 | function addthis_menu() { | |
| 8cc27624 | 58 | $menu_items['admin/config/user-interface/addthis'] = array( |
| 7a62f979 JP |
59 | 'title' => 'AddThis', |
| 60 | 'description' => 'Configure AddThis settings.', | |
| 61 | 'page callback' => 'drupal_get_form', | |
| 62 | 'page arguments' => array('addthis_admin_settings_form'), | |
| 460f1e3c | 63 | 'access arguments' => array(AddThis::PERMISSION_ADMINISTER_ADDTHIS), |
| 7a62f979 | 64 | 'type' => MENU_NORMAL_ITEM, |
| 9268db58 | 65 | 'file' => AddThis::ADMIN_INCLUDE_FILE, |
| 7a62f979 | 66 | ); |
| 8cc27624 | 67 | return $menu_items; |
| 7a62f979 | 68 | } |
| 6fa6aaac JP |
69 | |
| 70 | /** | |
| 71 | * Implements hook_permission(). | |
| 72 | */ | |
| 73 | function addthis_permission() { | |
| 74 | return array( | |
| 460f1e3c | 75 | AddThis::PERMISSION_ADMINISTER_ADDTHIS => array( |
| 6fa6aaac JP |
76 | 'title' => t('Administer AddThis'), |
| 77 | 'description' => t('Perform maintenance tasks for AddThis.'), | |
| 78 | ), | |
| 460f1e3c JP |
79 | AddThis::PERMISSION_ADMINISTER_ADVANCED_ADDTHIS => array( |
| 80 | 'title' => t('Administer advanced AddThis'), | |
| 81 | 'description' => t('Perform advanced maintenance tasks for AddThis.'), | |
| 82 | ), | |
| 6fa6aaac JP |
83 | ); |
| 84 | } | |
| aea420e4 JP |
85 | |
| 86 | /** | |
| 87 | * Implements hook_page_alter(). | |
| 88 | */ | |
| 89 | function addthis_page_alter(&$page) { | |
| 4c82025d | 90 | AddThis::getInstance()->addWidgetJs(); |
| 2ee37e69 | 91 | AddThis::getInstance()->addConfigurationOptionsJs(); |
| aea420e4 | 92 | } |
| e0d5a8e5 JP |
93 | |
| 94 | /** | |
| 8cc27624 JP |
95 | * Implements hook_form_FORM_ID_alter(). |
| 96 | * | |
| 97 | * Hide the instance fieldset because there aren't any values per instance. | |
| e0d5a8e5 | 98 | */ |
| 8cc27624 JP |
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) { | |
| e0d5a8e5 JP |
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 | } | |
| 5b48493d JP |
107 | |
| 108 | /** | |
| f386c4cd MG |
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 | /** | |
| 8cc27624 | 121 | * Implements hook_theme(). |
| 5b48493d JP |
122 | */ |
| 123 | function addthis_theme($existing, $type, $theme, $path) { | |
| 124 | return array( | |
| 25b6bbc6 | 125 | 'addthis_wrapper' => array( |
| d8e50226 | 126 | 'render element' => 'addthis_wrapper', |
| 25b6bbc6 | 127 | ), |
| 5b48493d | 128 | 'addthis_element' => array( |
| d8e50226 | 129 | 'render element' => 'addthis_element', |
| 25b6bbc6 MG |
130 | ), |
| 131 | 'addthis' => array( | |
| d8e50226 MG |
132 | 'render element' => 'addthis', |
| 133 | ), | |
| 5b48493d JP |
134 | ); |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 8cc27624 | 138 | * Implements hook_preprocess() for theme_addthis. |
| 25b6bbc6 MG |
139 | */ |
| 140 | function template_preprocess_addthis(&$variables) { | |
| d87800e9 | 141 | if (isset($variables[0]) && count($variables) == 3) { |
| b6608a16 | 142 | $variables['#display'] = $variables[0]; |
| d87800e9 | 143 | unset($variables[0]); |
| 1784116b | 144 | } |
| 25b6bbc6 MG |
145 | } |
| 146 | ||
| 147 | function theme_addthis($variables) { | |
| b6608a16 MG |
148 | $markup = AddThis::getInstance()->getDisplayMarkup($variables['#display']); |
| 149 | return render($markup); | |
| 25b6bbc6 MG |
150 | } |
| 151 | ||
| 152 | function theme_addthis_wrapper($variables) { | |
| 25b6bbc6 | 153 | $element = $variables['addthis_wrapper']; |
| 25b6bbc6 | 154 | $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>'; |
| 25b6bbc6 | 155 | $children = element_children($element); |
| 8cc27624 | 156 | |
| 25b6bbc6 | 157 | if (count($children) > 0) { |
| 1784116b | 158 | foreach ($children as $child) { |
| 25b6bbc6 MG |
159 | $output .= render($element[$child]); |
| 160 | } | |
| 161 | } | |
| 8cc27624 | 162 | |
| 25b6bbc6 | 163 | $output .= '</' . $element['#tag'] . ">\n"; |
| 39839324 | 164 | return $output; |
| 25b6bbc6 MG |
165 | } |
| 166 | ||
| 167 | /** | |
| 5b48493d JP |
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) { | |
| 5b48493d JP |
172 | $element = $variables['addthis_element']; |
| 173 | ||
| 5b48493d JP |
174 | if (!isset($element['#value'])) { |
| 175 | return '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . " />\n"; | |
| 176 | } | |
| 8cc27624 JP |
177 | |
| 178 | $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>'; | |
| 179 | if (isset($element['#value_prefix'])) { | |
| 180 | $output .= $element['#value_prefix']; | |
| 5b48493d | 181 | } |
| 8cc27624 JP |
182 | $output .= $element['#value']; |
| 183 | if (isset($element['#value_suffix'])) { | |
| 184 | $output .= $element['#value_suffix']; | |
| 185 | } | |
| 186 | $output .= '</' . $element['#tag'] . ">\n"; | |
| 187 | return $output; | |
| 5b48493d | 188 | } |